Sunswap-Interfaces en
Sunswap-Interfaces en
by Sun team
v 1.0.4
Table of Contents
I. Backend API 3
1.1 Get access to API for all trading pairs 3
1
14. tokenToTokenTransferOutput 19
2.3.2.3 Contract event 20
1. TokenPurchase 20
2. TrxPurchase 20
3. AddLiquidity 21
4. RemoveLiquidity 21
2
I. Backend API
Parameters:
page_size : int, size of each page, max 500
page_num: int, number of the page, starting from 0
ver : take 1 for Sunswap1.0, take 2 for Sunswap1.5, take 3 for Sunswap 2.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
{ "data":
[{
"0_TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t": //key: ID of base and quote token
{
"quote_id": "0",// address of the quote token, 0 refers to TRX's id
"quote_name": "TRX", //quote token name
"quote_symbol": "TRX", // quote token symbol
"quote_decimal": "6", //precision of quote token
"base_id": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", // contract address of the
base token
"base_name": "Tether USD", // name of base_token, e.g. USDT
"base_symbol": "USDT", // symbol for base token
"base_decimal": "6", // precision of base token
"price": "37.450887374011593590", // price of the base_token, 1 USDT = 37.45
TRX at the moment
"quote_volume": "16928742252878", // total amount of quote_token traded in the
last 24 hours, unit : min unit of the quote_token
"base_volume": "452025130508" // total amount of base_token traded in the last 24
hours, unit: min unit of the base_token
}
}],
"total_num": 25, // total entries
"err_no":0,
"err_msg":""
"max_page_no": 5
}
Note:
Maximum number of requests to the API is 1 request per user per second
3
II. Smart Contract API
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
4
interface ISunswapFactory {
event NewExchange(address indexed token, address indexed exchange);
2.2.3 Exchange
interface ISunswapExchange {
5
external returns (uint256);
6
function tokenAddress() external view returns (address);
2.3.1 Factory
1. getExchange
Function description: Use TRC20 token to obtain the corresponding exchange address in
SunSwap.
Parameter description:
Parameter Type Description
Returns:
address Trading pair address in SunSwap
2. getToken
function getToken(address token) external view returns (address)
Function description: Use the exchange address in SunSwap to obtain the address of
TRC20 token.
Parameter description:
Parameter Type Description
7
Returns:
address TRC20 token address
1. createExchange
function createExchange(address token) external returns (address payable);
Function description: create SunSwap trading pair.Each TRC20 token creates only one
exchange address.
Parameter description:
Parameter Type Description
Returns:
address Trading pair address in SunSwap
1. NewExchange
event NewExchange(address indexed token, address indexed exchange);
Function description: The interface sends an event when creating trading pair with
createExchange.
Parameter description:
Parameter Type Description
2.3.2 Exchange
8
2.3.2.1 Query interface
1. getTrxToTokenInputPrice
Function description: To know the amount of TRC20 token available for purchase through
the amount of TRX sold
Parameter description:
Parameter Type Description
Returns:
uint256 amount of TRC20 token available to purchase
2. getTrxToTokenOutputPrice
Function description: To know the amount of TRX to be paid through the amount of TRC20
token bought
Parameter description:
Parameter Type Description
Returns:
uint256 Amount of TRX to be paid
3. getTokenToTrxInputPrice
Function description: To know the amount of TRX available for purchase through the amount
of TRC20 token sold
9
Parameter description:
Parameter Type Description
Returns:
uint256 amount of TRX available for purchase
4. getTokenToTrxOutputPrice
Function description: To know the amount of TRC20 token to be paid through the amount of
TRX bought
Parameter description:
Parameter Type Description
Returns:
uint256 Amount of TRC20 token to be paid
5. tokenAddress
Function description: Obtain the address of TRC20 tokens available for trade within this
trading pair in SunSwap
Returns:
address address of TRC20 token available to be traded in this trading pair
6. factoryAddress
10
Function description: Access the Factory contract address that creates the SunSwap trading
pairs
Returns:
address factory contract address for SunSwap
1. addLiquidity
Parameter description:
Add liquidity to the current exchange.Deduct callvalue and corresponding token and add
them into contracts.Then mint liquidity token as marker.
Approve before adding liquidity.
Parameter description:
Parameter Type Description
Returns:
uint256 Additional amount of liquidity token issued to callers
Note:
1). msg.value parameter is the callvalue that comes with the function call (namely amount of
TRX) and is not included on the parameter list of function signature. Other “msg.value”
below are defined as the same.
2. removeLiquidity
11
function removeLiquidity(uint256 amount, uint256 min_trx, uint256 min_tokens, uint256
deadline) external returns (uint256, uint256)
Function description: remove liquidity; transfer the amount of TRX and TRC20 token
removed to callers.
Parameter description:
Parameter Type Description
Returns:
uint256 Amount of TRX removed
3. trxToTokenSwapInput
Parameter description:
Parameter Type Description
deadline uint256 Unix timestamp; transaction will revert if exceeding this time
limit
msg.value uint256 Amount of TRX the user pays for buying token
Returns:
uint256 Amount of TRC20 token purchased
12
4. trxToTokenSwapOutput
Parameter description:
Parameter Type Description
deadline uint256 Unix timestamp; transaction will revert if exceeding this time
limit
msg.value uint256 Maximum amount that can be paid to buy the fixed amount of
token; calculated from the slippage
Returns:
uint256 Amount of TRX sold
5. tokenToTrxSwapOutput
Parameter description:
Parameter Type Description
max_tokens uint256 Maximum amount of token that can be deducted from the user
account; calculated from the slippage
deadline uint256 Unix timestamp; transaction will revert if exceeding this time
limit
Returns:
uint256 Amount of TRC20 token sold
13
6. tokenToTrxSwapInput
Parameter description:
Parameter Type Description
deadline uint256 Unix timestamp; transaction will revert if exceeding this time
limit
Returns:
uint256 Amount of TRX purchased
7. trxToTokenTransferInput
Function description: sell TRX to buy token (TRX is in a fixed amount)Then, transfer the
purchased token to the recipient address.
Parameter description:
Parameter Type Description
deadline uint256 Unix timestamp; transaction will revert if exceeding this time
limit
Returns:
uint256 Amount of TRC20 tokens purchased
14
8. trxToTokenTransferOutput
Function description: sell TRX and buy token; token is in a fixed amount. Then, transfer the
purchased token to the recipient address.
Parameter description:
Parameter Type Description
deadline uint256 Unix timestamp; transaction will revert if exceeding this time
limit
msg.value uint256 Maximum amount that can be paid to buy the fixed amount of
token, which is calculated from slippery percentage
Returns:
uint256 Amount of TRX sold
9. tokenToTrxTransferInput
Function description: sell tokens and buy TRX; token is in a fixed amount. Then, transfer the
purchased TRX to the recipient address.
Parameter description:
类型
deadline uint256 Unix timestamp; transaction will revert if exceeding this time
limit
15
msg.value uint256 Amount of TRX deposited when adding liquidity
Returns:
uint256 Amount of TRX purchased
10. tokenToTrxTransferOutput
Function description: sell tokens and buy TRX; TRX is in a fixed amount. Then, transfer the
purchased TRX to the recipient address.
Parameter description:
max_tokens uint256 Maximum amount of tokens that can be deducted from the user
account; calculated from the slippage
deadline uint256 Unix timestamp; transaction will revert if exceeding this time
limit
Returns:
uint256 Amount of TRC20 token sold
11. tokenToTokenSwapOutput
Function description: sell token1 and buy token2 (token2 is in a fixd amount).Since TRX
functions as intermediary, both token1 and token2 need to have exchange addresses.
Parameter description:
Parameter Type Description
16
max_tokens_sold uint256 Maximum amount of token1 that can be deducted from the user
account; calculated from the slippage
deadline uint256 unix timestamp; transaction will revert if exceeding this time limit
token_addr address Token2 contract address (not the exchange address, because
it is the token1 exchange address that is called, and the
contract will automatically fetch the exchange2 address
according to token2)
Returns:
uint256 Amount of token1 sold
12. tokenToTokenSwapInput
Function description: sell token1 and buy token2 (token1 is in a fixd amount).
Parameter description:
Returns:
uint256 Amount of token2 purchased
17
13. tokenToTokenTransferInput
Function description: sell token1 and buy token2 (token1 is in a fixd amount).Then, transfer
the purchased token2 to the recipient's address.
Parameter description:
Parameter Type Description
Returns:
uint256 Amount of token2 purchased
14. tokenToTokenTransferOutput
Function description: sell token1 and buy token2 (token2 is in a fixd amount).Then, transfer
the purchased token2 to the recipient's address.
Parameter description:
18
max_tokens_sold uint256 Maximum amount of token1 that can be deducted from the
user account; calculated from the slippage
deadline uint256 unix timestamp; transaction will revert if exceeding this time
limit
Returns:
uint256 Amount of token1 sold
1. TokenPurchase
Parameter description:
Parameter Type Description
2. TrxPurchase
19
Function description: trigger the event in tokenToTrxSwapInput, tokenToTrxTransferInput,
tokenToTrxSwapOutput, tokenToTrxTransferOutput, tokenToTokenSwapInput,
tokenToTokenTransferInput, tokenToTokenSwapOutput and tokenToTokenTransferOutput
Parameter description:
Parameter Type Description
3. AddLiquidity
Parameter description:
Parameter Type Description
4. RemoveLiquidity
Parameter description:
Parameter Type Description
20
trx_amount uint256 Amount of TRX removed
21