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 V3 Overview
      • 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
  • Smart Routing Calculation Service Interface
  • Example
  1. DEVELOPERS
  2. Swap
  3. Smart Router

Calculation Service

SUN.io Smart Routing Calculation Service implements full graph search on SunSwap V1, SunSwap V2, SunSwap V3, PSM, and SunCurve by building contract mirrors on the server. It sorts the paths based on the amount of tokens exchanged and returns the top three paths that yield the most tokens to the user.

Smart Routing Calculation Service URL: https://rot.endjgfsv.link/swap/router

Smart Routing Calculation Service Interface

  • Name: https://rot.endjgfsv.link/swap/router

  • Type: GET

  • Parameters:

Name
Description

fromToken

fromToken address

toToken

toToken address

amountIn

Amount of tokens to exchange (excluding precision)

typeList

Available exchange types (PSM,CURVE,CURVE_COMBINATION,WTRX,SUNSWAP_V1,SUNSWAP_V2,SUNSWAP_V3)

  • Return Values:

Name
Description

amountIn

Input token amount (excluding precision)

amountOut

Amount of tokens that can be exchanged through routing calculation (excluding precision)

inUsd

Input token price in USD

outUsd

Output token price in USD

impact

Price impact

fee

Transaction fee

tokens

Token addresses in the path from fromToken to toToken

symbols

Token symbols in the path from fromToken to toToken

poolFees

Fee rates of pools in the path from fromToken to toToken (non-SunSwap V3 versions show 0)

poolVersions

Versions of pools in the path from fromToken to toToken

stepAmountsOut

Amount of tokens exchanged at each pool in the path from fromToken to toToken

Example

  • Input the token address to be exchanged, amount, and available pool types. (This example gets the optimal three paths for exchanging TRX for USDJ)

    • WTRX mainnet contract address: TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR

    • USDJ mainnet contract address: TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT

curl 'https://rot.endjgfsv.link/swap/router?fromToken=TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR&toToken=TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT&amountIn=1000000&typeList=PSM,CURVE,CURVE_COMBINATION,WTRX,SUNSWAP_V1,SUNSWAP_V2,SUNSWAP_V3'
  • Output of the three optimal paths

{"code":0,"message":"SUCCESS","data":[{"amountIn":"1.000000","amountOut":"0.252282433556701500","inUsd":"0.276802258980479257000000","outUsd":"0.270738460358453539548814862165406000","impact":"-0.008024","fee":"0.003000","tokens":["TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR","TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT"],"symbols":["WTRX","USDJ"],"poolFees":["0","0"],"poolVersions":["v2"],"stepAmountsOut":["0.252282433556701500"]},{"amountIn":"1.000000","amountOut":"0.258697110088580272","inUsd":"0.276802258980479257000000","outUsd":"0.277622410316657953560576225558013888","impact":"-0.004841","fee":"0.006388","tokens":["TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR","TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8","TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t","TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT"],"symbols":["WTRX","USDC","USDT","USDJ"],"poolFees":["0","0","0","0"],"poolVersions":["v2","v2","oldusdcpool"],"stepAmountsOut":["0.286989","0.278653","0.258697110088580272"]},{"amountIn":"1.000000","amountOut":"0.258697110088580272","inUsd":"0.276802258980479257000000","outUsd":"0.277622410316657953560576225558013888","impact":"-0.004841","fee":"0.006388","tokens":["TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR","TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8","TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t","TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT"],"symbols":["WTRX","USDC","USDT","USDJ"],"poolFees":["0","0","0","0"],"poolVersions":["v2","v2","old3pool"],"stepAmountsOut":["0.286989","0.278653","0.258697110088580272"]}]}
PreviousContractNextExchange Functions