Smart Contract
Smart Contract
We use a BCS (Binary Canonical Serialization) stream to interact with V2, V3, and Stable pool hooks on Aptos. This documentation provides an overview of the serialization and transaction building process using the Aptos SDK in JavaScript/TypeScript.
📚 Table of Contents
Smart Contract Addresses
Use the following addresses to interact with the smart contract:
View Address
0xf5840b576a3a6a42464814bc32ae1160c50456fb885c62be389b817e75b2a385
Router Address
0x487e905f899ccb6d46fdaec56ba1e0c4cf119862a16c409904b8c78fab1f5e8a
Use this value when referencing routerAddress in your transactions and viewAddress in your view.
Interaction
Before interacting with the smart contracts, you must:
Import required classes such as
SerializerandAccountAddressfrom the Aptos SDK.Initialize a serializer instance before sending any transaction data.
Create Pool
Function
AMM
📝 Parameters
poolType
u8
Pool type (2 = V2)
ser.serializeU8(2);
assets
vector<address>
List of coin types (2 addresses)
ser.serializeVector([AccountAddress.fromString(coinA), AccountAddress.fromString(coinB)]);
fee
u64
Fee in basis points (bps)
ser.serializeU64(fee);
e.g. 3000 = 0.3%
💡 Example
CLMM
📝 Parameters
poolType
u8
Pool type (3 = V3)
ser.serializeU8(3);
assets
vector<address>
List of coin types (2 addresses)
ser.serializeVector([AccountAddress.fromString(coinA), AccountAddress.fromString(coinB)]);
fee
u64
Fee in basis points (bps)
ser.serializeU64(fee);
e.g. 3000 = 0.3%
sqrtPrice
u128
Initial square root price for the pool.
ser.serializeU128(sqrtPrice);
💡 Example
Stable
📝 Parameters
poolType
u8
Pool type (4 = Stable)
ser.serializeU8(4);
assets
vector<address>
List of coin types (max 4 addresses)
ser.serializeVector([AccountAddress.fromString(coinA), AccountAddress.fromString(coinB)]);
fee
u64
Fee in basis points (bps)
ser.serializeU64(fee);
e.g. 3000 = 0.3%
amp
u256
Amplification factor. Value must be between 100 and 1000.
ser.serializeU256(amp);
offPegMultiplier
u256
off peg multiplier.
ser.serializeU256(offpeg_fee_multiplier);
💡 Example
Add Liquidity
Function
AMM
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positionAddr
address or Option<address>
Address of existing position or None to create new
AccountAddress.fromString(positionAddr).serialize(ser); or ser.serializeOption(null);
amountA
u64
Desired amount of token A
ser.serializeU64(amountA);
amountB
u64
Desired amount of token B
ser.serializeU64(amountB);
minAmountA
u64
Minimum amount of token A (slippage protection)
ser.serializeU64(0);
minAmountB
u64
Minimum amount of token B (slippage protection)
ser.serializeU64(0);
💡 Example
CLMM
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positionAddr
address or Option<address>
Address of existing position or None to create new
AccountAddress.fromString(positionAddr).serialize(ser); or ser.serializeOption(null);
amountA
u64
Desired amount of token A
ser.serializeU64(amountA);
amountB
u64
Desired amount of token B
ser.serializeU64(amountB);
fixedAmountA
bool
if true then its expect amountA to be fixed.
ser.serializeBool(fixed_amount_a);
lowerTick
u64
Lower Tick
ser.serializeU64(lower_tick);
upperTick
u64
Upper Tick
ser.serializeU64(upper_tick);
💡 Example
Stable
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positionAddr
address or Option<address>
Address of existing position or None to create new
AccountAddress.fromString(positionAddr).serialize(ser); or ser.serializeOption(null);
amounts
vector<u256>
desired amounts for each coin with maximum 4 coins.
ser.serializeVector(amounts.map(amount => new U256(amount)));
minMintAmount
u256
The minimum LP amount
ser.serializeU256(min_mint_amount);
💡 Example
Create Pool And Add Liquidity
Function
AMM
📝 Parameters
poolType
u8
Pool type (2 = V2)
ser.serializeU8(2);
assets
vector<address>
List of coin address (2 addresses)
ser.serializeVector([AccountAddress.fromString(coinA), AccountAddress.fromString(coinB)]);
fee
u64
Fee in basis points (bps)
ser.serializeU64(fee);
e.g. 3000 = 0.3%
positionAddr
address or Option<address>
Address of existing position or None to create new
AccountAddress.fromString(positionAddr).serialize(ser); or ser.serializeOption(null);
amountA
u64
Desired amount of token A
ser.serializeU64(amountA);
amountB
u64
Desired amount of token B
ser.serializeU64(amountB);
minAmountA
u64
Minimum amount of token A (slippage protection)
ser.serializeU64(0);
minAmountB
u64
Minimum amount of token B (slippage protection)
ser.serializeU64(0);
💡 Example
CLMM
📝 Parameters
poolType
u8
Pool type (3 = V3)
ser.serializeU8(3);
assets
vector<address>
List of coin address (2 addresses)
ser.serializeVector([AccountAddress.fromString(coinA), AccountAddress.fromString(coinB)]);
fee
u64
Fee in basis points (bps)
ser.serializeU64(fee);
e.g. 3000 = 0.3%
sqrtPrice
u128
Initial square root price for the pool.
ser.serializeU128(sqrtPrice);
amountA
u64
Desired amount of token A
ser.serializeU64(amountA);
amountB
u64
Desired amount of token B
ser.serializeU64(amountB);
fixedAmountA
bool
if true then its expect amountA to be fixed.
ser.serializeBool(fixed_amount_a);
lowerTick
u64
Lower Tick
ser.serializeU64(lower_tick);
upperTick
u64
Upper Tick
ser.serializeU64(upper_tick);
💡 Example
Stable
📝 Parameters
poolType
u8
Pool type (4 = Stable)
ser.serializeU8(4);
assets
vector<address>
List of coin address (max 4 addresses)
ser.serializeVector([AccountAddress.fromString(coinA), AccountAddress.fromString(coinB)]);
fee
u64
Fee in basis points (bps)
ser.serializeU64(fee);
e.g. 3000 = 0.3%
amp
u256
Amplification factor. Value must be between 100 and 1000.
ser.serializeU256(amp);
offPegMultiplier
u256
off peg multiplier.
ser.serializeU256(offpeg_fee_multiplier);
amounts
vector<u256>
desired amounts for each coin with maximum 4 coins.
ser.serializeVector(amounts.map(amount => new U256(amount)));
minMintAmount
u256
The minimum LP amount
ser.serializeU256(min_mint_amount);
💡 Example
Swap
Function
AMM
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
aToB
bool
Set to true when swapping from token0 to token1 in the pool.
ser.serializeBool(aToB);
fixedAmountIn
bool
Indicates whether the input amount will remain fixed during the swap.
ser.serializeBool(fixed_amount_in);
amountIn
u64
Quantity of input tokens to swap
ser.serializeU64(amountIn);
amountOutMin
u64
Minimum quantity of output tokens expected from the swap,
ser.serializeU64(amountOutMin);
💡 Example
CLMM
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
aToB
bool
Set to true when swapping from token0 to token1 in the pool.
ser.serializeBool(aToB);
fixedAmountIn
bool
Indicates whether the input amount will remain fixed during the swap.
ser.serializeBool(fixed_amount_in);
amountIn
u64
Quantity of input tokens to swap
ser.serializeU64(amountIn);
amountOutMin
u64
Minimum quantity of output tokens expected from the swap,
ser.serializeU64(amountOutMin);
targetSqrtPrice
u128
target square root price after swap.
ser.serializeU128(target_sqrt_price);
💡 Example
Stable
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
tokenIn
u64
token index in.
ser.serializeU64(tokenIn);
tokenOut
u64
token index out.
ser.serializeU64(tokenOut);
amountIn
u256
amount in.
ser.serializeU256(amountIn);
minAmountOut
u256
min amount out,
ser.serializeU256(min_amount_out);
💡 Example
Remove Liquidity
Function
AMM
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positionAddr
address
Address of existing position
ser.serialize(AccountAddress.fromString(positionAddr));
burnedShares
u128
Amount of liquidity provider (LP) tokens or shares to burn/remove from the pool
ser.serializeU128(burnedShares);
minAmountA
u64
Minimum token A amounts to receive when removing liquidity.
ser.serializeU64(minAmountA);
minAmountB
u64
Minimum token B amounts to receive when removing liquidity.
ser.serializeU64(minAmountB);
💡 Example
CLMM
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positionAddr
address
Address of existing position
ser.serialize(AccountAddress.fromString(positionAddr));
burnedShares
u128
Amount of liquidity provider (LP) tokens or shares to burn/remove from the pool
ser.serializeU128(burnedShares);
minAmountA
u64
Minimum token A amounts to receive when removing liquidity.
ser.serializeU64(minAmountA);
minAmountB
u64
Minimum token B amounts to receive when removing liquidity.
ser.serializeU64(minAmountB);
💡 Example
Stable
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positionAddr
address
Address of existing position
ser.serialize(AccountAddress.fromString(positionAddr));
Type
u8
1 : remove liquidity one coin, 2 : remove liquidity imbalance, 3 : remove liquidity ratio
ser.serializeU8(3)
burnedShare
u256
Amount of liquidity provider (LP) tokens or shares to burn/remove from the pool
ser.serializeU256(shares);
minAmounts
vector<u256>
Minimum token amounts to receive when removing liquidity.
ser.serializeVector(amounts.map(amount => new U256(amount)));
💡 Example
Remove Multi Liquidity
Function
AMM
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positions.length
u64
Total number of positions
ser.serializeU64(positions.length);
positions.positionAddress
address
Address of existing position
ser.serialize(AccountAddress.fromString(position.positionAddr));
positions.burnedShares
u128
Amount of liquidity provider (LP) tokens or shares to burn/remove from the pool
ser.serializeU128(position.burnedShares);
positions.minAmountA
u64
Minimum token A amounts to receive when removing liquidity.
ser.serializeU64(position.minAmountA);
positions.minAmountB
u64
Minimum token B amounts to receive when removing liquidity.
ser.serializeU64(position.minAmountB);
💡 Example
CLMM
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positions.length
u64
Total number of positions
ser.serializeU64(positions.length);
positions.positionAddress
address
Address of existing position
ser.serialize(AccountAddress.fromString(position.positionAddr));
positions.burnedShares
u128
Amount of liquidity provider (LP) tokens or shares to burn/remove from the pool
ser.serializeU128(position.burnedShares);
positions.minAmountA
u64
Minimum token A amounts to receive when removing liquidity.
ser.serializeU64(position.minAmountA);
positions.minAmountB
u64
Minimum token B amounts to receive when removing liquidity.
ser.serializeU64(position.minAmountB);
💡 Example
Stable
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positions.length
u64
Total number of positions
ser.serializeU64(positions.length);
positions.positionAddr
address
Address of existing position
ser.serialize(AccountAddress.fromString(position.positionAddr))
positions.type
u8
1 : remove liquidity one coin, 2 : remove liquidity imbalance, 3 : remove liquidity ratio
ser.serializeU8(position.type);
positions.burnedShare
u256
Amount of liquidity provider (LP) tokens or shares to burn/remove from the pool
ser.serializeU128(position.burnedShare);
positions.minAmounts
vector<u256>
Minimum token amounts to receive when removing liquidity.
ser.serializeVector(position.minAmounts.map(amount => new U256(amount)));
💡 Example
Collect Fee
Function
CLMM
📝 Parameters
poolId
address
Address of the pool
ser.serialize(AccountAddress.fromString(poolId));
positionAddress
address
Address of existing position
AccountAddress.fromString(positionAddr).serialize(ser);
💡 Example
🚀 Submitting the Transaction
Once all arguments are serialized, submit the transaction using the Aptos SDK:
View
This documentation provides read-only access to key on-chain data across multiple pool types, including pool state, user positions, swap simulations, and reward campaigns. It is intended for developers and integrators to support analytics, UI rendering, and off-chain logic without modifying blockchain state.
Example Usage
To interact with the View API, you can use the views module provided by the aptos framework. This module contains read-only functions that allow you to query various aspects of the AMM, CLMM, and Stable pools without modifying the on-chain state.
Example usage in JavaScript:
AMM View API
The views::amm_views module provides a collection of read-only view functions designed to interact with and retrieve information from AMM (Automated Market Maker) pools. These functions are useful for frontend queries and off-chain data display.
📊 Reserves & Shares
Function reserve_a(pool_addr: address): u64
Returns the reserve amount of token A in the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function reserve_b(pool_addr: address): u64
Returns the reserve amount of token B in the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function total_shares(pool_addr: address): u128
Returns the total number of LP shares for the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
🧾 Positions
Function get_positions(pool_addr: address): vector<amm::amm::Position>
Returns all positions in a given pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function get_position(pool_addr: address, position_idx: u64): amm::amm::Position
Returns the position information for a specific index.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Index of the position within the pool.
💡 Example
Function position_shares(pool_addr: address, position_idx: u64): u128
Returns the number of shares owned by the position.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Index of the position within the pool.
💡 Example
💸 Fees
Function fee_rate(pool_addr: address): u64
Returns the fee rate for the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function fee_rate_denominator(): u64
Returns the denominator used to calculate the fee percentage.
💡 Example
➕ Liquidity Calculations
Function
calc_optimal_lp_amount(desired_amount_a: u64, desired_amount_b: u64, min_amount_a: u64, min_amount_b: u64)
Calculates optimal token amounts to add liquidity while maintaining ratio.
Params
desired_amount_a: u64desired_amount_b: u64min_amount_a: u64min_amount_b: u64
💡 Example
Function compute_lp_from_shares(pool_addr: address, shares: u128): (u64, u64)
Calculates the equivalent amounts of token A and B from given LP shares.
Params
pool_addr:address– Pool unique identifier.shares:u128– Number of LP shares to convert.
💡 Example
🔁 Swap Calculations
Function compute_amount_out(pool_addr: address, amount_in: u64, a2b: bool): u64
Returns the estimated output token amount for a given input and direction.
Params
pool_addr:address– Pool unique identifier.amount_in:u64– Amount of input token.a2b:bool– Direction of swap (true: A to B,false: B to A).
💡 Example
Function compute_amount_in(pool_addr: address, amount_out: u64, a2b: bool): u64
Returns the required input token amount to receive a specific output.
Params
pool_addr:address– Pool unique identifier.amount_out:u64– Desired output token amount.a2b:bool– Direction of swap (true: A to B,false: B to A).
💡 Example
🎯 Campaign Views
Function calculate_pending_rewards(pool_addr: address, position_idx: u64): vector<CampaignReward>
Returns pending campaign rewards for a specific position.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Index of the position within the pool.
💡 Example
Function get_campaign_token(pool_addr: address, campaign_idx: u64): address
Returns the reward token address used in a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Index of the campaign.
💡 Example
Function get_campaign_rate_per_second(pool_addr: address, campaign_idx: u64): u64
Returns the emission rate per second for the campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Index of the campaign.
💡 Example
Function get_campaign_total_rewards(pool_addr: address, campaign_idx: u64): u64
Returns the total rewards allocated to a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Index of the campaign.
💡 Example
Function get_campaign_total_distributed(pool_addr: address, campaign_idx: u64): u64
Returns the total rewards already distributed in a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Index of the campaign.
💡 Example
Function get_campaign_start_time(pool_addr: address, campaign_idx: u64): u64
Campaign start timestamp (in seconds).
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Index of the campaign.
💡 Example
Function get_campaign_end_time(pool_addr: address, campaign_idx: u64): u64
Returns the end timestamp of a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Index of the campaign.
💡 Example
Function get_campaign_is_active(pool_addr: address, campaign_idx: u64): bool
Returns true if the campaign is currently active.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Index of the campaign.
💡 Example
Function get_campaign_remaining_rewards(pool_addr: address, campaign_idx: u64): u64
Returns the remaining undistributed rewards for a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Index of the campaign.
💡 Example
Function get_pool_campaigns_count(pool_addr: address): u64
Returns the total number of campaigns associated with a pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
CLMM View API
This module contains read-only view functions for accessing the on-chain state of CLMM (Concentrated Liquidity Market Maker) pools, positions, and campaigns. All methods are non-mutating and safe to call for off-chain querying.
Pool-Level Views
Function current_sqrt_price(pool_addr: address): u128
Returns the current square root price of the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function reserve_a(pool_addr: address): u64
Returns the current reserve amount of token A in the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function reserve_b(pool_addr: address): u64
Returns the current reserve amount of token B in the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function liquidity(pool_addr: address): u128
Returns the total liquidity currently in the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function current_tick_idx(pool_addr: address): u64
Returns the current tick index for the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Position-Level Views
Function get_positions(pool_addr: address): vector<clmm::clmm::Position>
Fetches all position objects within the specified pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function get_position(pool_addr: address, position_idx: u64): clmm::clmm::Position
Fetches a specific position by index from the pool.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Index of the position within the pool.
💡 Example
Function position_liquidity(pool_addr: address, position_idx: u64): u128
Returns the amount of liquidity in a specific position.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Position index.
💡 Example
Function position_tick_idxs(pool_addr: address, position_idx: u64): (u64, u64)
Returns the tick lower and upper indices for a position.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Position index.
💡 Example
Function position_fee_growth_inside(pool_addr: address, position_idx: u64): (u128, u128)
Returns the fee growth inside the tick range of a position.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Position index.
💡 Example
Function position_fee_owed(pool_addr: address, position_idx: u64): (u64, u64)
Returns the amount of fees owed to a position.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Position index.
💡 Example
Fee Views
Function fee_rate(pool_addr: address): u64
Returns the fee rate of the pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Function fee_denominator(): u64
Returns the fixed denominator used in fee calculation.
💡 Example
Swap Simulation
Function
calculate_swap_result(pool_addr: address, a2b: bool, fixed_amount_in: bool, amount: u64): clmm::clmm::CalculatedSwapResult
Simulates a swap and returns the expected result.
Params
pool_addr:address– Pool unique identifier.a2b:bool– Direction of the swap (true: A to B,false: B to A).fixed_amount_in:bool– Whether the input amount is fixed.amount:u64– The amount to swap.
💡 Example
Liquidity Calculations
Function get_amount_by_liquidity(...): (u64, u64)
Returns the token amounts (A, B) corresponding to a given liquidity amount.
Params
tick_lower_index:u64– Lower bound of tick range.tick_upper_index:u64– Upper bound of tick range.current_tick_index:u64– Current tick index.current_sqrt_price:u128– Current square root price.liquidity:u128– Amount of liquidity.round_up:bool– Whether to round up in calculation.
💡 Example
Function
get_amount_by_liquidity_of(pool_addr: address, position_idx: u64, liquidity: u128, round_up: bool): (u64, u64)
Returns the token amounts (A, B) corresponding to a given liquidity amount in a specific position.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Index of the position.liquidity:u128– Amount of liquidity.round_up:bool– Whether to round up in calculation.
💡 Example
Function get_liquidity_by_amount(...): (u128, u64, u64)
Returns the liquidity and actual token amounts (A, B) that can be provided with a given token amount.
Params
tick_lower_index:u64– Lower tick index.tick_upper_index:u64– Upper tick index.current_tick_index:u64– Current tick index.current_sqrt_price:u128– Current square root price.amount:u64– The fixed token amount.is_fixed_a:bool– Whether the fixed amount is token A.
💡 Example
Function
get_liquidity_by_amount_of(pool_addr: address, tick_lower_index: u64, tick_upper_index: u64, amount: u64, is_fixed_a: bool): (u128, u64, u64)
Returns the liquidity and actual token amounts (A, B) that can be provided with a given token amount in a specific position.
Params
pool_addr:address– Pool unique identifier.tick_lower_index:u64– Lower tick index.tick_upper_index:u64– Upper tick index.amount:u64– The fixed token amount.is_fixed_a:bool– Whether the fixed amount is token A.
💡 Example
Function get_position_fee_owned(pool_addr: address, position_idx: u64): (u128, u64, u64)
Returns the total fees owed to a position, including fee growth and amounts.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Index of the position.
💡 Example
Campaign Views
Function calculate_pending_rewards(pool_addr: address, position_idx: u64): vector<clmm::clmm::CampaignReward>
Calculates pending rewards for a specific position in a campaign.
Params
pool_addr:address– Pool unique identifier.position_idx:u64– Position index.
💡 Example
Function get_campaign_token(pool_addr: address, campaign_idx: u64): address
Returns the reward token address of a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Campaign index.
💡 Example
Function get_campaign_rate_per_second(pool_addr: address, campaign_idx: u64): u64
Returns the reward rate (tokens per second) of a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Campaign index.
💡 Example
Function get_campaign_total_rewards(pool_addr: address, campaign_idx: u64): u64
Returns the total allocated rewards for a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Campaign index.
💡 Example
Function get_campaign_total_distributed(pool_addr: address, campaign_idx: u64): u64
Returns the total amount of rewards distributed so far.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Campaign index.
💡 Example
Function get_campaign_start_time(pool_addr: address, campaign_idx: u64): u64
Returns the start timestamp of a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Campaign index.
💡 Example
Function get_campaign_end_time(pool_addr: address, campaign_idx: u64): u64
Returns the end timestamp of a campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Campaign index.
💡 Example
Function get_campaign_is_active(pool_addr: address, campaign_idx: u64): bool
Returns whether the campaign is currently active.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Campaign index.
💡 Example
Function get_campaign_remaining_rewards(pool_addr: address, campaign_idx: u64): u64
Returns the remaining undistributed rewards for the campaign.
Params
pool_addr:address– Pool unique identifier.campaign_idx:u64– Campaign index.
💡 Example
Function get_pool_campaigns_count(pool_addr: address): u64
Returns the total number of campaigns associated with a pool.
Params
pool_addr:address– Pool unique identifier.
💡 Example
Stable View API
This module provides read-only view functions for accessing on-chain data related to Stable Pools. It allows querying pool state, user positions, swap simulations, and reward campaigns without modifying blockchain state.
Function n_coins(pool_addr: address): u64
returns the number of coins in the pool.
Params
pool_addr:address– The address of the pool.
💡 Example
Function rate_multipliers(pool_addr: address): vector<u256>
returns the rate multipliers for each coin in the pool.
Params
pool_addr:address– The address of the pool.
💡 Example
Function stored_balances(pool_addr: address): vector<u256>
returns the stored balances of each coin in the pool.
Params
pool_addr:address– The address of the pool.
💡 Example
Function initial_a(pool_addr: address): u256
returns the initial amplification coefficient (A) of the pool.
Params
pool_addr:address– The address of the pool.
💡 Example
Function future_a(pool_addr: address): u256
returns the future amplification coefficient (A) of the pool.
Params
pool_addr:address– The address of the pool.
💡 Example
Function initial_a_time(pool_addr: address): u64
returns the timestamp when the initial amplification coefficient (A) was set.
Params
pool_addr:address– The address of the pool.
💡 Example
Function future_a_time(pool_addr: address): u64
returns the timestamp when the future amplification coefficient (A) will be set.
Params
pool_addr:address– The address of the pool.
💡 Example
Function total_shares(pool_addr: address): u256
returns the total number of LP shares for the pool.
Params
pool_addr:address– The address of the pool.
💡 Example
Function fee_rate(pool_addr: address): u256
returns the fee rate for the pool.
Params
pool_addr:address– The address of the pool.
💡 Example
Function fee_denominator(): u256
returns the denominator used to calculate the fee percentage.
💡 Example
Function dynamic_fee(pool_addr: address, i: u64, j: u64): u256
returns the dynamic fee rate for a specific coin pair in the pool.
Params
pool_addr:address– The address of the pool.i:u64– The index of the first coin.j:u64– The index of the second coin.
💡 Example
Function get_positions(pool_addr: address): vector<stable::stable::Position>
returns all positions in a given pool.
Params
pool_addr:address– The address of the pool.
💡 Example
Function get_position(pool_addr: address, position_idx: u64): stable::stable::Position
returns the position information for a specific index.
Params
pool_addr:address– The address of the pool.position_idx:u64– The index of the position within the pool.
💡 Example
Function position_shares(pool_addr: address, position_idx: u64): u256
returns the number of shares owned by the position.
Params
pool_addr:address– The address of the pool.position_idx:u64– The index of the position within the pool.
💡 Example
Function get_dx(pool_addr: address, i: u64, j: u64, dy: u256): u256
this function calculates the required input amount (dx) for a given output amount (dy) in a specific coin pair.
Params
pool_addr:address– The address of the pool.i:u64– The index of the first coin.j:u64– The index of the second coin.dy:u256– The output amount for the second coin.
💡 Example
Function get_dy(pool_addr: address, i: u64, j: u64, dx: u256): u256
this function calculates the output amount (dy) for a given input amount (dx) in a specific coin pair.
Params
pool_addr:address– The address of the pool.i:u64– The index of the first coin.j:u64– The index of the second coin.dx:u256– The input amount for the first coin.
💡 Example
Function calc_token_amount(pool_addr: address, amounts: vector<u256>, is_deposit: bool): u256
this function calculates the amount of LP shares to mint or burn based on the provided token amounts.
Params
pool_addr:address– The address of the pool.amounts:vector<u256>– The amounts of each coin to deposit or withdraw.is_deposit:bool– Whether the operation is a deposit (true) or withdrawal (false).
💡 Example
Function calc_withdraw_one_coin(pool_addr: address, burn_amount: u256, i: u64): u256
this function calculates the amount of a specific coin to withdraw when burning LP shares.
Params
pool_addr:address– The address of the pool.burn_amount:u256– The amount of LP shares to burn.i:u64– The index of the coin to withdraw.
💡 Example
Function calc_ratio_amounts(pool_addr: address, liquidity: u256): vector<u256>
this function calculates the amounts of each coin based on a given liquidity ratio.
Params
pool_addr:address– The address of the pool.liquidity:u256– The liquidity ratio to use for the calculation.
💡 Example
Function
calculate_pending_rewards(pool_addr: address, position_idx: u64): vector<stable::stable::CampaignReward>
this function calculates pending campaign rewards for a specific position in a stable pool.
Params
pool_addr:address– The address of the pool.position_idx:u64– The index of the position within the pool.
💡 Example
Function get_campaign_token(pool_addr: address, campaign_idx: u64): address
returns the reward token address used in a campaign.
Params
pool_addr:address– The address of the pool.campaign_idx:u64– The index of the campaign.
💡 Example
Function get_campaign_rate_per_second(pool_addr: address, campaign_idx: u64): u64
returns the emission rate per second for the campaign.
Params
pool_addr:address– The address of the pool.campaign_idx:u64– The index of the campaign.
💡 Example
Function get_campaign_total_rewards(pool_addr: address, campaign_idx: u64): u64
returns the total rewards allocated to a campaign.
Params
pool_addr:address– The address of the pool.campaign_idx:u64– The index of the campaign.
💡 Example
Function get_campaign_total_distributed(pool_addr: address, campaign_idx: u64): u64
returns the total rewards already distributed in a campaign.
Params
pool_addr:address– The address of the pool.campaign_idx:u64– The index of the campaign.
💡 Example
Function get_campaign_start_time(pool_addr: address, campaign_idx: u64): u64
returns the start timestamp of a campaign.
Params
pool_addr:address– The address of the pool.campaign_idx:u64– The index of the campaign.
💡 Example
Function get_campaign_end_time(pool_addr: address, campaign_idx: u64): u64
returns the end timestamp of a campaign.
Params
pool_addr:address– The address of the pool.campaign_idx:u64– The index of the campaign.
💡 Example
Function get_campaign_is_active(pool_addr: address, campaign_idx: u64): bool
returns whether the campaign is currently active.
Params
pool_addr:address– The address of the pool.campaign_idx:u64– The index of the campaign.
💡 Example
Function get_campaign_remaining_rewards(pool_addr: address, campaign_idx: u64): u64
returns the remaining undistributed rewards for a campaign.
Params
pool_addr:address– The address of the pool.campaign_idx:u64– The index of the campaign.
💡 Example
Function get_pool_campaigns_count(pool_addr: address): u64
returns the total number of campaigns associated with a pool.
Params
pool_addr:address– The address of the pool.
💡 Example
TAPP View API
This documentation provides read-only access to on-chain data for TAPP protocol integrations, including pool metadata, position details, and calculated incentives. These functions help developers query reward information and render pool/position data in applications without requiring transactions.
Function get_pool_metas(): vector<tapp::hook_factory::PoolMeta>
Returns metadata for all TAPP pools.
Params
(no parameters)
💡 Example
Function get_pool_meta(pool_addr: address): tapp::hook_factory::PoolMeta
Returns metadata for a specific TAPP pool.
Params
pool_addr:address– The address of the TAPP pool.
💡 Example
Function get_position_meta(position_addr: address): tapp::position::PositionMeta
Returns metadata for a specific TAPP position.
Params
position_addr:address– The address of the TAPP position.
💡 Example
Function
calc_incentives(user_address: address, pool_addr: address, position_idx: u64): vector<tapp::hook_factory::IncentiveReward>
Calculates incentives for a specific user position in a TAPP pool.
Params
user_address:address– The address of the user.pool_addr:address– The address of the TAPP pool.position_idx:u64– The index of the position within the pool.
💡 Example
Function
calc_incentives_batch(user_address: address, pool_addrs: vector<address>, position_indices: vector<u64>): vector<vector<tapp::hook_factory::IncentiveReward>>
Calculates incentives for multiple user positions across multiple TAPP pools in a single call. This is more efficient than calling calc_incentives individually for each position.
Params
user_address:address– The address of the user.pool_addrs:vector<address>– A vector of TAPP pool addresses.position_indices:vector<u64>– A vector of position indices corresponding to each pool address.
💡 Example
📌 Fee Guide
100
0.01%
Low volume, tight spread
500
0.05%
Standard for stables
3000
0.3%
Normal volatile pairs
10000
1%
Exotic or risky tokens
Last updated