Sunswapv2-Interfaces en
Sunswapv2-Interfaces en
0 Interface Documentation
-- Sun Team
v 1.0.4
Table of Contents
I. Backend API 3
1.1 Access all trading pairs 3
II. Smart Contract Interface 4
2.1 Smart contract address 4
2.2 List of contract interfaces 4
2.2.1 TRC20 token 4
2.2.2 Factory 5
2.2.3 ISunswapV2Router 5
2.3 Description of contract interfaces 7
2.3.1 Factory 7
2.3.1.1 Query interface 7
1. getPair 7
2. allPairs 8
3. allPairsLength 8
2.3.1.2 Modification interface 9
1. createPair 9
2.3.1.3 Contract event 9
1. PairCreated 9
2.3.2 Router 10
2.3.2.1 Query interface 10
1. factory 10
2. WETH 10
2.3.2.2 Modification interface 11
1. addLiquidity 11
2. addLiquidityETH 12
3. removeLiquidity 13
4. removeLiquidityETH 14
5. removeLiquidityWithPermit 15
6. removeLiquidityETHWithPermit 17
7. removeLiquidityETHSupportingFeeOnTransferTokens 18
8. removeLiquidityETHWithPermitSupportingFeeOnTransferTokens 19
9. swapExactTokensForTokens 20
10. swapExactETHForTokens 21
11. swapTokensForExactETH 22
12. swapExactTokensForETH 23
13. swapETHForExactTokens 24
14. swapExactTokensForTokensSupportingFeeOnTransferTokens 25
15. swapExactETHForTokensSupportingFeeOnTransferTokens 26
16. swapExactTokensForETHSupportingFeeOnTransferTokens 27
I. Backend API
Parameters:
page_size : int, size of each page, max 500
page_num: int, number of the page, starting from 0
token_address: optional; return only the data containing the specific token address
orderBy: optional; return the data ordered by the specific item (price, quote_volume or
base_volume)
desc: optional; true = decreasing order; false = increasing order
Return format:
{
"data": [{
"TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR_TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6tf":
//key: ids of base_token and quote_token
{
"quote_id": "TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR",
"quote_decimal": "6", //precision of quote_token
"quote_name": "Wrapped TRX", //name of quote_token
"quote_symbol": "WTRX", //symbol of quote_token
"base_id": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", //address of base_token
"base_decimal": "6", //precision of base_token
"base_name": "Tether USD", //name of base_token
"base_symbol": "USDT", //symbol of base_token
"price": "0.938196997790940827", //price of quote_token, calculated in base_token
"quote_volume": "0", //total amount of quote_token traded in the last 24 hours
(minimum unit)
"base_volume": "0" //total amount of base_token traded in the last 24 hours
(minimum unit)
}
}],
"err_msg": "",
"err_no": 0,
"total_num": 143 //total number of entries
}
II. Smart Contract Interface
interface ITRC20 {
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
2.2.2 Factory
interface ISunswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
2.2.3 ISunswapV2Router
interface ISunswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint
deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path,
address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path,
address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint
deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint
amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint
amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[]
memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[]
memory amounts);
}
2.3.1 Factory
1. getPair
function getPair(address tokenA, address tokenB) external view returns (address pair);
Function description: Use tokenA and tokenB to acquire the corresponding pair address.
Parameter description:
Returns:
address Trading pair address
2. allPairs
Function description: Return the address of the trading pair N (0-indexed) created by the
factory contract. If the corresponding index has not been created, return the zero address
(0x00000000000000000000000000000000000000000000000000000000000000000000).
Parameter description:
Returns:
address Trading pair address
3. allPairsLength
Function description: Return the number of trading pairs created via the factory contract.
Returns:
uint Total number of
trading pairs
2.3.1.2 Modification interface
1. createPair
Function description: Create a pair address for tokenA and tokenB when their corresponding
trading pair does not exist.
Parameter description:
Returns:
address Trading pair address
1. PairCreated
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
Function description: The interface sends an event when creating trading pair with
createPair.
Parameter description:
index uint The final uint log value for the first trading
pair created is 1, the value for the second pair
is 2, and so on.
2.3.2 Router
1. factory
Returns:
address factory contract address
2. WETH
Returns:
address WTRX contract address
2.3.2.2 Modification interface
1. addLiquidity
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
Function description:
Add liquidity to the TRC-20 ⇄ TRC-20 pool, and then mint liquidity tokens as markers.
Approve before adding liquidity.
Parameter description:
Returns:
amountA uint256 Amount of tokenA sent to the pool
2. addLiquidityETH
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
Function description:
Add liquidity to the TRC-20 ⇄ WTRX pool with TRX, and then mint liquidity tokens as
markers.
Parameter description:
Returns:
amountToken uint256 Amount of token sent to the pool
3. removeLiquidity
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
Function description:
Remove liquidity from the TRC-20 ⇄ TRC-20 pool. Approval is needed before the removal of
liquidity.
Parameter description:
Returns:
amountA uint256 Amount of tokenA received
4. removeLiquidityETH
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
Function description:
Remove liquidity from the TRC-20 ⇄ WTRX pool and convert WTRX into TRX. Approval is
Parameter description:
Returns:
amountToken uint256 Amount of token received
5. removeLiquidityWithPermit
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
Function description:
Remove liquidity from the TRC-20 ⇄ TRC-20 pool. Approval is not needed when removing
Parameter description:
Returns:
amountA uint256 Amount of tokenA received
amountB uint256 Amount of tokenB received
6. removeLiquidityETHWithPermit
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
Function description:
Remove liquidity from the TRC-20 ⇄ WTRX pool and convert WTRX into TRX. Approval is
not needed when removing liquidity due to the existence of permit.
Parameter description:
Returns:
amountToken uint256 Amount of tokens received
7. removeLiquidityETHSupportingFeeOnTransferTokens
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
Function description:
Remove liquidity from the TRC-20 ⇄ WTRX pool and convert WTRX into TRX. This function
is applicable to tokens that charge transfer fees (or deflationary tokens). Approval is needed
Parameter description:
Returns:
amountETH uint256 Amount of TRX received
8. removeLiquidityETHWithPermitSupportingFeeOnTransferTokens
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
Function description:
Remove liquidity from the TRC-20 ⇄ WTRX pool and convert WTRX into TRX. This function
is applicable to tokens that charge transfer fees. Approval is not needed when removing
Parameter description:
Returns:
amountETH uint256 Amount of TRX received
9. swapExactTokensForTokens
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
Function description:
This parameter is used to swap a specified amount of the input token into the maximum
amount of the output token possible. The first element of the parameter path is the address
of the input token and the last element is that of the output token. Any elements in between
Parameter description:
Parameter Type Description
Returns:
amounts uint256[] Amount of the input token and all consequent output
memory token
10. swapExactETHForTokens
function swapExactETHForTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable returns (uint[] memory amounts);
Function description:
This parameter is used to swap a specified amount of TRX into the maximum amount of the
output token possible. The first element of the parameter path is the WTRX address and the
last element is that of the output token. Any elements in between represent the trading pairs.
Parameter description:
Parameter Type Description
Returns:
amounts uint256[] Amount of the input token and all consequent output
memory token
11. swapTokensForExactETH
function swapTokensForExactETH(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
Function description:
This parameter is used to swap the minimum amount of input token possible into a specific
amount of TRX. The first element of the parameter path is the address of the input token,
and the last element the WTRX address. Any elements in between represent the pairs to be
traded. Approval is needed before the swap. If the to address is a smart contract, it has to be
able to receive TRX.
Parameter description:
Returns:
amounts uint256[] Amount of the input token and all consequent output
memory token
12. swapExactTokensForETH
function swapExactTokensForETH(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
Function description:
This parameter is used to swap a specified amount of input token into the maximum amount
of TRX possible. The first element of the parameter path is the address of the input token,
and the last element the WTRX address. Any elements in between represent the pairs to be
traded. If the to address is a smart contract, it has to be able to receive TRX.
Parameter description:
Returns:
amounts uint256[] Amount of the input token and all consequent output
memory token
13. swapETHForExactTokens
function swapETHForExactTokens(
uint amountOut,
address[] calldata path,
address to,
uint deadline
) external payable returns (uint[] memory amounts);
Function description:
This parameter is used to swap the minimum amount of input token possible into a specific
amount of TRX. The first element of the parameter path is the WTRX address and the last
element is that of the output token. Any elements in between represent the trading pairs. If
Parameter description:
Returns:
amounts uint256[] Amount of the input token and all consequent output
memory token
14. swapExactTokensForTokensSupportingFeeOnTransferTokens
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
Parameter description:
This parameter is used to swap a specified amount of the input token into the maximum
amount of the output token possible. The first element of the parameter path is the address
of the input token, and the last element that of the output token. Any elements in between
represent the pairs to be traded. This function is applicable to tokens that charge transfer
fees. Approval is needed before the swap.
Parameter description:
15. swapExactETHForTokensSupportingFeeOnTransferTokens
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
Parameter description:
This parameter is used to swap a specified amount of TRX into the maximum amount of the
output token possible. The first element of the parameter path is the WTRX address, and the
last element that of the output token. Any elements in between represent the pairs to be
traded.This function is applicable to tokens that charge transfer fees (or deflationary tokens).
Parameter description:
16. swapExactTokensForETHSupportingFeeOnTransferTokens
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
Parameter description:
This parameter is used to swap a specified amount of input token into the maximum amount
of TRX possible. The first element of the parameter path is the address of the input token,
and the last element the WTRX address. Any elements in between represent the pairs to be
traded. This function is applicable to tokens that charge transfer fees (or deflationary
tokens). If the to address is a smart contract, it has to be able to receive TRX.
Parameter description: