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
        • Contract
        • 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
  • Read functions
  • getPool
  • slot0
  • tokenOfOwnerByIndex
  • positions
  • Write functions
  • exactInput
  • increaseLiquidity
  • decreaseLiquidity
  • collect
  1. DEVELOPERS
  2. Swap
  3. SunSwap V3 Overview

Functions

Read functions

getPool

function getPool(
    address tokenA,
    address tokenB,
    uint24 fee,
).call()
  • Description: Get the liquidity address

  • Contract to call: Factory

  • Parameters:

Parameter Name
Type
Description

tokenA

address

The contract address of one token

tokenB

address

The contract address of the other token

fee

uint24

The pool's liquidity fee rate multiplied by 1,000,000

  • Return value: The address of the pool

  • Example: Find the V3 liquidity address for TRX/USDT with a fee rate of 0.05%

const factory_v3 = await tronWeb.contract(V3factoryAbi, "TLJWAScHZ4Qmk1axyKMzrnoYuu2pSLer")
const pooladderss_ = await factory_v3.getPool("TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf", "TYsb")
console.log(tronWeb.address.fromHex(pooladderss_))
  • Return

TPypbNIrRZ6FX735BY2wtKLdpnkLPoGiAo

slot0

function slot0().call()
  • Description: Get information about the pool

  • Contract to call: Pool contract (can be obtained through factory, see getPool())

  • Parameters: None

  • Return value:

Field Name
Description

sqrtPriceX96

Square root of the current price (Q64.96 format), needs to be decoded to get the real price

tick

Current tick index (related to price)

observationIndex

Current observation data index, used for time-weighted average price (TWAP) calculation

observationCardinality

Current number of available observation points

observationCardinalityNext

Expected number of observation points in the future (used for capacity expansion)

feeProtocol

The pool's fee configuration (protocol level)

unlocked

Indicates whether the pool is locked (used to prevent re-entrancy attacks)

  • Example: Query information about the TRX/USDT-0.05 pool on the main network

const contract_pool = await tronWeb.contract(poolAbi, "TSUUVjysXV8YqHytSNjfkNXnnB49QDvZpx")
const slot0_ = await contract_pool.slot0().call()
console.log(slot0_)
  • Return

[
  BigNumber { _hex: '0x84b4ff29997c28cc5848ed8d', _isBigNumber: true },
  -13142,
  0,
  1,
  1,
  0,
  true,
  sqrtPriceX96: BigNumber { _hex: '0x84b4ff29997c28cc5848ed8d', _isBigNumber: true },
  tick: -13142,
  observationIndex: 0,
  observationCardinality: 1,
  observationCardinalityNext: 1,
  feeProtocol: 0,
  unlocked: true
]

tokenOfOwnerByIndex

function tokenOfOwnerByIndex(
    address owner,
    uint256 index,
).call()
  • Description: Get the tokenId corresponding to the user's index

  • Contract to call: NonfungiblePositionManager contract

  • Parameters:

Parameter Name
Type
Description

owner

address

User's address

index

uint256

The user's nth liquidity position

  • Return value: tokenId

  • Example

const contract_Nonfungible = await tronWeb.contract(NonfungiblePositionManagerAbi, 'TLSWrv7eC1AZCXkRjpqMZUmvgd99cj7pPF')
const tokenId_ = await contract_Nonfungible.tokenOfOwnerByIndex('TXXXXXXXXXXXXXXXXXXXXXX',0).call();
console.log(tokenId_)
  • Return

BigNumber { _hex: '0x0207', _isBigNumber: true }

positions

function positions(
    uint256 tokenId,
).call()
  • Description: Get the liquidity corresponding to the user's tokenId

  • Contract to call: NonfungiblePositionManager contract

  • Parameters:

Parameter Name
Type
Description

tokenId

uint256

The user's token ID

  • Return value:

Field Name
Description

nonce

operator

Address authorized for the tokenId

token0

Address of token0 in the pool

token1

Address of token1 in the pool

fee

Pool fee rate

tickLower

Minimum value of the selected position

tickUpper

Maximum value of the selected position

liquidity

Liquidity

feeGrowthInside0LastX128

feeGrowthInside1LastX128

Fee growth of the total position up to the last operation on a single position

tokensOwed0

tokensOwed1

How many uncollected tokens the position owes as of the last calculation

  • Example

const contract_Nonfungible = await tronWeb.contract(NonfungiblePositionManagerAbi, 'TLSWrv7eC1AZCXkRjpqMZUmvgd99cj7pPF')
const pos = await contract_Nonfungible.positions(1).call()
console.log(pos_)
  • Return

[
  BigNumber { _hex: '0x00', _isBigNumber: true },
  '410000000000000000000000000000000000000000',
  '4138d5a8e87a4bcc2f822786a9b1134a3b7836e382',
  '41646dc03a0884cd4b5254297a04a58a56499f242d',
  3000,
  -283380,
  -269520,
  BigNumber { _hex: '0x134c8d6d899dd330', _isBigNumber: true },
  BigNumber { _hex: '0x00', _isBigNumber: true },
  BigNumber { _hex: '0x01bf24ecb68662e15f15eebe', _isBigNumber: true },
  BigNumber { _hex: '0x00', _isBigNumber: true },
  BigNumber { _hex: '0x00', _isBigNumber: true },
  nonce: BigNumber { _hex: '0x00', _isBigNumber: true },
  operator: '410000000000000000000000000000000000000000',
  token0: '4138d5a8e87a4bcc2f822786a9b1134a3b7836e382',
  token1: '41646dc03a0884cd4b5254297a04a58a56499f242d',
  fee: 3000,
  tickLower: -283380,
  tickUpper: -269520,
  liquidity: BigNumber { _hex: '0x134c8d6d899dd330', _isBigNumber: true },
  feeGrowthInside0LastX128: BigNumber { _hex: '0x00', _isBigNumber: true },
  feeGrowthInside1LastX128: BigNumber { _hex: '0x01bf24ecb68662e15f15eebe', _isBigNumber: true },
  tokensOwed0: BigNumber { _hex: '0x00', _isBigNumber: true },
  tokensOwed1: BigNumber { _hex: '0x00', _isBigNumber: true }
]

Write functions

exactInput

function exactInput(
    ExactInputParams,
).send()
  • Description: Execute an exchange transaction

  • Contract to call: SwapRouter

  • Parameters:

struct ExactInputParams {
    bytes path;          // Encoded transaction path (e.g., tokenIn -> fee -> tokenOut)
    address recipient;   // Recipient address
    uint256 deadline;    // Transaction deadline
}
  • Return value: Transaction hash

  • Example

const contract_swap = await tronWeb.contract(V3swaprouterAbi, config.nile.routerV3)
const exactInput_res = await contract_swap.exactInput(['0xe518c608a37e2a262050e10be0c9d03'])
console.log(exactInput_res)

Note: The encoding of the transaction path is too complex, it is recommended that developers use smart routing for exchange transactions.

increaseLiquidity

function increaseLiquidity(
    IncreaseLiquidityParams,
).send()
  • Description: Used to add liquidity

  • Contract to call: NonfungiblePositionManager

  • Parameters:

struct IncreaseLiquidityParams {
    uint256 tokenId;           // NFT ID of an existing position
    uint256 amount0Desired;    // Desired amount of token0 to invest
    uint256 amount1Desired;    // Desired amount of token1 to invest
    uint256 amount0Min;        // Minimum acceptable amount of token0 (for slippage protection)
    uint256 amount1Min;        // Minimum acceptable amount of token1 (for slippage protection)
    uint256 deadline;          // Deadline
}
  • Return value: Transaction hash

  • Example

const contract_Nonfungible = await tronWeb.contract(NonfungiblePositionManagerAbi, config.nile.NonfungiblePositionManager)
const increase_L = await contract_Nonfungible.increaseLiquidity([1, 10, 10, 0, 0, Math.floor(Date.now() / 1000) + 60 * 20])
console.log(increase_L)

decreaseLiquidity

function decreaseLiquidity(
    DecreaseLiquidityParams,
).send()
  • Description: Used to remove liquidity

  • Contract to call: NonfungiblePositionManager

  • Parameters:

struct DecreaseLiquidityParams {
    uint256 tokenId;        // NFT ID of the position
    uint128 liquidity;      // Amount of liquidity to remove
    uint256 amount0Min;     // Minimum acceptable amount of token0 (for slippage protection)
    uint256 amount1Min;     // Minimum acceptable amount of token1 (for slippage protection)
    uint256 deadline;       // Deadline
}
  • Return value: Transaction hash

  • Example

const contract_Nonfungible = await tronWeb.contract(NonfungiblePositionManagerAbi, config.nile.NonfungiblePositionManager)
const derease_L = await contract_Nonfungible.decreaseLiquidity([1, 5228703, 0, 0, Math.floor(Date.now() / 1000) + 60 * 20])
console.log(derease_L)

collect

function collect(
    CollectParams,
).send()
  • Description: Used to collect rewards

  • Contract to call: NonfungiblePositionManager

  • Parameters:

struct CollectParams {
    uint256 tokenId;       // NFT ID of the position
    address recipient;     // Reward receiving address
    uint128 amount0Max;    // Maximum amount of token0 to extract (usually set to maximum value)
    uint128 amount1Max;    // Maximum amount of token1 to extract (usually set to maximum value)
}
  • Return value: Transaction hash

  • Example

const contract_Nonfungible = await tronWeb.contract(NonfungiblePositionManagerAbi, config.nile.NonfungiblePositionManager)
const collect_t = await contract_Nonfungible.collect([1, 'TXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'])
console.log(collect_t)
PreviousContractNextSmart Router

Last updated 1 day ago