SUN.io Docs
SUN.ioSunPump
  • SUN.io Overview
    • Get Started(TRON)
      • Create a Wallet
      • TRON Network Token Standards
      • Connect Your Wallet to SUN.io
    • Risks
    • Whitepaper
    • Terms of Service
    • Privacy Policy
    • Announcement
  • GET START
    • Exchange
      • Token Swaps
        • How to authorize a token?
        • How to exchange tokens?
        • How to check my recent transaction history?
        • How to view 24h price trend of a pair ?
      • Stablecoin Pool
        • Stablecoin pool overview
        • How to swap stablecoins?
        • How to provide liquidity for a stablecoin pool?
        • How to withdraw liquidity from a stablecoin pool?
        • How to check the liquidity you have provided?
      • Smart Router
      • Trading Fee
        • Claim Fee Rewards
      • Liquidity Pool
        • How to create a trading pair?
        • How to add liquidity?
        • How to remove liquidity?
        • How to calculate the ratio of tokens to be added to/removed from the pool?
        • How to record a new token?
        • What's the initial price for creating a fund pool?
      • Token Lists
    • Mining Pool
      • Mining Rules of SUN.io
      • How to participate in liquidity mining?
      • How to earn liquidity mining rewards?
      • How to exit liquidity mining?
      • How to calculate the boost rate of LP mining pool?
      • How to lock SUN?
      • How to vote?
      • How to reset votes?
      • Intelligent Boost Mining Pool
        • How to participate in Fixed Staking?
        • How to stake more assets in Fixed Staking?
        • How to extend duration in Fixed Staking?
        • How to make an early withdrawal in Fixed Staking?
        • How to claim rewards in Fixed Staking?
      • Farm
      • Ended Farming Pools
    • SunPump
      • 🌞 How to Participate?
      • 🚀 How to Launch?
      • 💡 Token Details
      • 👤 Personal Profile
      • 🏦 Service Fees
      • How to Use DLive Streaming on SunPump
    • SunPump Referral
      • How to Join
      • Rules
      • FAQ
    • PSM
      • How to swap between USDD and other stablecoins at 1:1 ratio in PSM?
    • Tokenomics
      • SUN Tokenomics
        • Buyback & Burning of the SUN Token
      • veSUN
      • Airdrop
  • GOVERNANCE
    • SUN DAO Governance
    • Participating Governance
      • Proposal
        • SUN DAO Forum
        • How to get more votes?
        • Create Proposal
        • How to vote on the SUN DAO?
        • SUN DAO proposal
      • Governance Rights
        • Weight
        • veSUN
  • DEVELOPERS
    • Swap
      • StableSwap Overview
      • SunSwap Overview
        • SunSwap V1
          • V1 Contract
          • V1 Functions
        • SunSwap V2
          • V2 Contract
          • V2 Functions
      • SunSwap V3 Overview
        • V3 Contract
        • V3 Functions
      • Smart Router
        • Contract
        • Calculation Service
        • Exchange Functions
        • Detailed Development Steps
    • Mining
      • Smart Mining V1
      • Smart Mining V2
      • Governance Mining
    • Sunpump
      • Sunpump Contracts
    • Github
    • Contracts and ABIs
  • FAQ
    • How to use Sun.io in TronLink Mobile?
    • How is price determined?
    • What tokens are supported for swap?
    • Why does my exchange fail?
    • Detailed Explanation of SUN.io Platform Energy Subsidies
Powered by GitBook
On this page
  • Get Liquidity Information
  • getExchange
  • Add/Remove Liquidity
  • addLiquidity
  • removeLiquidity
  • Execute Exchange
  • trxToTokenSwapInput
  • tokenToTrxSwapInput
  • trxToTokenSwapOutput
  • tokenToTrxSwapOutput
  • trxToTokenTransferInput
  • tokenToTrxTransferInput
  • tokenToTokenSwapInput
  1. DEVELOPERS
  2. Swap
  3. SunSwap Overview
  4. SunSwap V1

V1 Functions

Get Liquidity Information

getExchange

function getExchange(
    address token,
).call()
  • Description: Get liquidity pool address

  • Calling Contract: Factory

  • Parameters:

Parameter Name
Type
Description

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:

Parameter Name
Type
Description

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:

Parameter Name
Type
Description

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:

Parameter Name
Type
Description

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:

Parameter Name
Type
Description

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:

Parameter Name
Type
Description

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:

Parameter Name
Type
Description

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:

Parameter Name
Type
Description

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:

Parameter Name
Type
Description

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:

Parameter Name
Type
Description

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)
PreviousV1 ContractNextSunSwap V2

Last updated 1 day ago