Curve Functions
Get Liquidity Information
coins
function coins(
uint256 i,
).call()
Description: Get the liquidity pool token address
Contract: Pool
Parameters:
i
uint256
The i-th token in the stable pool
Return Value: The i-th token address in the liquidity pool
Example: Get the token address of i=0 in TUSD-USDT
const curve_con = await tronWeb.contract(curveAbi, config.nile.tusdusdt2pool)
// const coins_ = await curve_con.coins(1).call()
// console.log(tronWeb.address.fromHex(coins_))
const coins_0 = await curve_con.coins(0).call()
console.log(tronWeb.address.fromHex(coins_0))
Return
TRz7J6dD2QWxBoumfYt4b3FaiRG23pXfop
balances
function balances(
uint256 i,
).call()
Description: Get the liquidity size of the i-th token in the liquidity pool
Contract: Pool
Parameters:
i
uint256
The i-th token in the stable pool
Return Value: The liquidity size of the i-th token in the liquidity pool
Example: Get the token liquidity size of i=0 in TUSD-USDT
const curve_con = await tronWeb.contract(curveAbi, config.nile.tusdusdt2pool)
const balances_ = await curve_con.balances(0).call()
console.log(balances_.toString())
// const balances_ = await curve_con.balances(1).call()
// console.log(balances_.toString())
Return
54296382252095928708770
A
function A().call()
Description: Get the amplification coefficient A of the pool.
Contract: Pool
Parameters: None
Return Value: Amplification coefficient A
Example: Get the amplification coefficient A of the TUSD-USDT pool
const curve_con = await tronWeb.contract(curveAbi, config.nile.tusdusdt2pool)
const A_ = await curve_con.A().call()
console.log(A_.toString())
Return
50
token
function token().call()
Description: Get the LP Token address of the liquidity pool
Contract: Pool
Parameters: None
Return Value: LP Token address
Example: Get the LP Token address of TUSD-USDT pool
const curve_con = await tronWeb.contract(curveAbi, config.nile.tusdusdt2pool)
const lp_token_ = await curve_con.token().call()
console.log(tronWeb.address.fromHex(lp_token_))
Retrun
TNfQAtu6egpgxsRXwYAS8JygUMqN7aEgZh
Add/Remove Liquidity
addLiquidity
function addLiquidity(
uint256[2] amounts,
uint256 min_mint_amount,
).send()
Description: Add liquidity to the pool
Contract: Pool
Parameters:
amounts
uint256[2]
The amounts of tokens to add to the pool
min_mint_amount
uint256
The minimum amount of LP tokens to mint
Return Value: Transaction hash
Example: Add liquidity to the TUSD-USDT pool
const curve_con = await tronWeb.contract(curveAbi, config.nile.tusdusdt2pool)
const add_liquidity_ = await curve_con.add_liquidity([100, 100], 1).send()
console.log(add_liquidity_)
removeLiquidity
function removeLiquidity(
uint256 amount,
uint256[2] min_amounts,
).send()
Description: Remove liquidity from the pool
Contract: Pool
Parameters:
amount
uint256
The amount of LP tokens to burn
min_amounts
uint256[2]
The minimum amounts of tokens to receive
Return Value: Transaction hash
Example: Remove liquidity from the TUSD-USDT pool
const curve_con = await tronWeb.contract(curveAbi, config.nile.tusdusdt2pool)
const remove_liquidity_ = await curve_con.remove_liquidity(1000000000000,[1, 1]).send()
console.log(remove_liquidity_)
Execute Exchange
get_dy
function get_dy(
uint128 i,
uint128 j,
uint256 dx
).call()
Description: Get the amount of Token that can be exchanged, without actually executing the exchange
Contract: Pool
Parameters:
i
uint128
The index of the token to sell
j
uint128
The index of the token to buy
dx
uint256
The amount of the token to sell
Return Value: The amount of the token that can be received
Example: TUSD-USDT pool, sell the i-th token, buy the j-th token
const curve_con = await tronWeb.contract(curveAbi, config.nile.tusdusdt2pool)
const get_dy_ = await curve_con.get_dy(1, 0, 100).call()
console.log(get_dy_.toString())
exchange
function exchange(
uint128 i,
uint128 j,
uint256 dx,
uint256 min_dy,
).send()
Description: Exchange tokens in the pool
Contract: Pool
Parameters:
i
uint128
The index of the token to sell
j
uint128
The index of the token to buy
dx
uint256
The amount of the token to sell
min_dy
uint256
The minimum amount of the token to receive
Return Value: Transaction hash
Example: TUSD-USDT pool, sell the i-th token, buy the j-th token
const curve_con = await tronWeb.contract(curveAbi, config.nile.tusdusdt2pool)
const exchange_ = await curve_con.exchange(1, 0, 100, 1).send()
console.log(exchange_)
Last updated