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"]}]}