V1 Functions
Get Liquidity Information
getExchange
function getExchange(
address token,
).call()
Description: Get liquidity pool address
Calling Contract: Factory
Parameters:
token
address
Token address
Return Value: Pool address
Example: Find the TRX/USDT pool address
const factory_v1 = await tronWeb.contract(V1factoryAbi, config.nile.routerV1)
const exchangeaddress_ = await factory_v1.getExchange(config.nile.usdtToken).call()
console.log(tronWeb.address.fromHex(exchangeaddress_)) //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb
Return:
TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb
Add/Remove Liquidity
addLiquidity
function addLiquidity(
uint256 min_liquidity,
uint256 max_tokens,
uint256 deadline,
).send()
Description: add liquidity
Calling Contract: pool
Parameters:
min_liquidity
uint256
Minimum expected liquidity to receive
max_tokens
uint256
Maximum amount to add as liquidity
deadline
uint256
Unix timestamp after which the transaction will revert
Return Value: hash
Example: Add liquidity to the TUSD/USDT pool
const swap_v1 = await tronWeb.contract(V1Abi, "TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb") //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb is the exchange pool address
const addLiquidity_t = await swap_v1.addLiquidity(10,10000, Math.floor(Date.now() / 1000 + 86400)).send({callValue:100})
console.log(addLiquidity_t)
removeLiquidity
function removeLiquidity(
uint256 amount,
uint256 min_trx,
uint256 min_tokens,
uint256 deadline,
).send()
Description: remove liquidity
Calling Contract: pool
Parameters:
amount
uint256
Amount of liquidity to remove
min_trx
uint256
Minimum expected amount of TRX to receive
min_tokens
uint256
Minimum expected amount of Token to receive
deadline
uint256
Unix timestamp after which the transaction will revert
Return Value: hash
Example: Remove liquidity from the TUSD/USDT pool
const swap_v1 = await tronWeb.contract(V1Abi, "TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb") //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb is the exchange pool address
const removeLiquidity_t = await swap_v1.removeLiquidity(500,1, 1,Math.floor(Date.now() / 1000 + 86400)).send()
console.log(removeLiquidity_t)
Execute Exchange
trxToTokenSwapInput
function trxToTokenSwapInput(
uint256 min_tokens,
uint256 deadline,
).send()
Description: Sell TRX to buy Token (specify the amount of TRX to sell)
Calling Contract: pool
Parameters:
min_tokens
uint256
Minimum expected purchase amount
deadline
uint256
Unix timestamp after which the transaction will revert
Return Value: hash
Example: Sell TRX to Buy USDT
const swap_v1 = await tronWeb.contract(V1Abi, "TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb") //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb is the exchange pool address
const trxToTokenSwapInput_t = await swap_v1.trxToTokenSwapInput(10, Math.floor(Date.now() / 1000 + 86400)).send({callValue:1})
console.log(trxToTokenSwapInput_t)
tokenToTrxSwapInput
function tokenToTrxSwapInput(
uint256 tokens_sold,
uint256 min_trx,
uint256 deadline,
).send()
Description: Sell Token to buy TRX (specify the amount of Token to sell)
Calling Contract: pool
Parameters:
tokens_sold
uint256
Amount of tokens sold
min_trx
uint256
Minimum expected amount of TRX to purchase
deadline
uint256
Unix timestamp after which the transaction will revert
Return Value: hash
Example: Sell USDT to Buy TRX
const swap_v1 = await tronWeb.contract(V1Abi, "TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb") //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb is the exchange pool address
const tokenToTrxSwapInput_t = await swap_v1.tokenToTrxSwapInput(1000000, 1, Math.floor(Date.now() / 1000 + 86400)).send() // minTRX cannot be 0
console.log(tokenToTrxSwapInput_t)
trxToTokenSwapOutput
function trxToTokenSwapOutput(
uint256 tokens_bought,
uint256 deadline,
).send()
Description: Sell TRX to buy Token (specify the amount of Token to buy)
Calling Contract: pool
Parameters:
tokens_bought
uint256
Amount of tokens bought
deadline
uint256
Unix timestamp after which the transaction will revert
Return Value: hash
Example: Sell TRX to Buy Token
const swap_v1 = await tronWeb.contract(V1Abi, "TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb") //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb is the exchange pool address
const trxToTokenSwapOutput_t = await swap_v1.trxToTokenSwapOutput(10, Math.floor(Date.now() / 1000 + 86400)).send({callValue:100})
console.log(trxToTokenSwapOutput_t)
tokenToTrxSwapOutput
function tokenToTrxSwapOutput(
uint256 trx_bought,
uint256 max_tokens,
uint256 deadline,
).send()
Description: Sell Token to buy TRX (specify the amount of TRX to buy)
Calling Contract: pool
Parameters:
trx_bought
uint256
Amount of TRX bought
max_tokens
uint256
Maximum amount of tokens to sell
deadline
uint256
Unix timestamp after which the transaction will revert
Return Value: hash
Example: Sell Token to Buy TRX
const swap_v1 = await tronWeb.contract(V1Abi, "TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb") //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb is the exchange pool address
const tokenToTrxSwapOutput_t = await swap_v1.tokenToTrxSwapOutput(100, 100000000, Math.floor(Date.now() / 1000 + 86400)).send()
console.log(tokenToTrxSwapOutput_t)
trxToTokenTransferInput
function trxToTokenTransferInput(
uint256 min_tokens,
uint256 deadline,
address recipient,
).send()
Description: Sell TRX to buy Token (specify recipient address)
Calling Contract: pool
Parameters:
min_tokens
uint256
Minimum expected purchase amount
deadline
uint256
Unix timestamp after which the transaction will revert
recipient
address
Recipient address
Return Value: hash
Example: Sell TRX to Buy Token
const swap_v1 = await tronWeb.contract(V1Abi, "TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb") //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb is the exchange pool address
const trxToTokenTransferInput_t = await swap_v1.trxToTokenTransferInput(10, Math.floor(Date.now() / 1000 + 86400), "TXXXXXXXXXXXXXXXXXX").send({callValue:1})
console.log(trxToTokenTransferInput_t)
tokenToTrxTransferInput
function trxToTokenTransferInput(
uint256 tokens_sold,
uint256 min_trx,
uint256 deadline,
address recipient,
).send()
Description: Sell Token to buy TRX (specify recipient address)
Calling Contract: pool
Parameters:
tokens_sold
uint256
Amount of tokens sold
min_trx
uint256
Minimum expected amount of TRX to receive
deadline
uint256
Unix timestamp after which the transaction will revert
recipient
address
Recipient address
Return Value: hash
Example: Sell Token to Buy TRX
const swap_v1 = await tronWeb.contract(V1Abi, "TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb") //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb is the exchange pool address
const tokenToTrxTransferInput_t = await swap_v1.tokenToTrxTransferInput(100000, 1, Math.floor(Date.now() / 1000 + 1000), "TXXXXXXXXXXXXXXXXXX").send() //minTRX cannot be 0
console.log(tokenToTrxTransferInput_t)
tokenToTokenSwapInput
function tokenToTokenSwapInput(
uint256 tokens_sold,
uint256 min_tokens_bought,
uint256 min_trx_bought,
uint256 deadline,
address token_addr,
).send()
Description: Sell Token to buy Token (bridged via TRX)
Calling Contract: pool
Parameters:
tokens_sold
uint256
Amount of tokens sold
min_tokens_bought
uint256
Minimum expected amount of tokens to receive
min_trx_bought
uint256
Minimum expected amount of TRX to receive
deadline
uint256
Unix timestamp after which the transaction will revert
token_addr
address
Address of the token to buy
Return Value: hash
Example: Sell USDT to Buy SUN
const swap_v1 = await tronWeb.contract(V1Abi, "TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb") //TKxUU8588Zdt44Ues3p62gULLXtgTJ2CGb is the exchange pool address
const tokenToTokenSwapInput_t = await swap_v1.tokenToTokenSwapInput(1000000, 1, 1, Math.floor(Date.now() / 1000 + 86400), config.nile.sunToken).send()
console.log(tokenToTokenSwapInput_t)
Last updated