Table of Contents
Pool Factory Module
The Pool Factory is responsible for managing liquidity pool creation, configuration, and access control.
Pool Creation Functions
deploy_pool_and_mint
Copy public entry fun deploy_pool_and_mint < CoinTypeA , CoinTypeB , FeeType >(
pool_config: & mut PoolConfig ,
feeType: & Fee < FeeType >,
sqrt_price: u128 ,
positions: & mut Positions ,
coins_a: vector < Coin < CoinTypeA >>,
coins_b: vector < Coin < CoinTypeB >>,
tick_lower_index: u32 ,
tick_lower_index_is_neg: bool ,
tick_upper_index: u32 ,
tick_upper_index_is_neg: bool ,
amount_a_desired: u64 ,
amount_b_desired: u64 ,
amount_a_min: u64 ,
amount_b_min: u64 ,
recipient: address ,
deadline: u64 ,
clock: & Clock ,
versioned: & Versioned ,
ctx: & mut TxContext
) Function : Creates a new liquidity pool and simultaneously mints initial liquidity position
Parameters :
pool_config: Pool configuration object
feeType: Fee type configuration
sqrt_price: Square root of initial price
positions: Position manager
coins_a/coins_b: Tokens to be added
tick_lower/upper_index: Price range bounds
amount_a/b_desired: Desired token amounts to add
amount_a/b_min: Minimum token amounts to add
recipient: Recipient address
deadline: Transaction deadline
deploy_pool_and_mint_with_return_
Function : Creates pool and mints liquidity, returns NFT and remaining tokens
Returns : Position NFT, remaining coin A, remaining coin B, pool ID
deploy_pool
Function : Only creates a new liquidity pool without adding liquidity
get_pool_id
Function : Gets the pool ID for specified token pair and fee type
Returns : Pool ID (if exists)
The Pool module is the core of the CLMM protocol, responsible for handling liquidity, swaps, and price calculations.
Version Management Functions
version
Function : Gets current protocol version number
check_version
Function : Checks if protocol version matches
Flash Loan Functions
flash_swap
Function : Executes flash swap, returns receipt that needs to be repaid
flash_swap_partner
Function : Executes flash swap through partner
repay_flash_swap
Function : Repays flash swap, returns remaining tokens
repay_flash_swap_partner
Function : Repays partner flash swap
flash_swap_pay_amount
Function : Gets the amount that needs to be paid for flash swap
next_initialized_tick_within_one_word
Function : Finds next initialized tick within one word range
position_tick
Function : Calculates word position and bit index for position tick
get_tick
Function : Gets information for specified tick
get_position
Function : Gets position information
check_position_exists
Function : Checks if position exists
get_position_key_fix
Function : Generates unique identifier for position
get_position_key
Function : Generates position key from parameters
Pool State Query Functions
get_pool_fee
Function : Gets pool fee rate
get_pool_sqrt_price
Function : Gets pool's current sqrt price
get_pool_current_index
Function : Gets pool's current tick index
get_pool_liquidity
Function : Gets pool's current liquidity
get_pool_balance
Function : Gets pool's token balances
get_pool_info
Function : Gets complete pool information
Fee and Reward Query Functions
get_pool_fee_growth_global
Function : Gets global fee growth
get_position_fee_growth_inside_a
Function : Gets position's internal fee growth for token A
get_position_base_info
Function : Gets position's basic info (tick range and liquidity)
get_reward_info
Function : Gets reward information
Position Manager Module
The Position Manager is responsible for managing liquidity position minting, burning, and liquidity adjustments.
Liquidity Minting Functions
mint
Function : Mints new liquidity position
mint_with_return_
Function : Mints liquidity position and returns NFT and remaining tokens
Liquidity Burning Functions
burn
Function : Burns liquidity position and collects tokens
Liquidity Adjustment Functions
increase_liquidity
Function : Increases position's liquidity
increase_liquidity_with_return_
Function : Increases liquidity and returns remaining tokens
decrease_liquidity
Function : Decreases position's liquidity
decrease_liquidity_with_return_
Function : Decreases liquidity and returns tokens
Fee Collection Functions
collect
Function : Collects trading fees generated by position
collect_with_return_
Function : Collects fees and returns coin objects
Reward Collection Functions
collect_reward
Function : Collects position's reward tokens
collect_reward_with_return_
Function : Collects rewards and returns coin object
NFT Management Functions
burn_position_nft_with_return_
Function : Burns position NFT and returns tokens
burn_nft_collect_reward_with_return_
Function : Burns NFT and collects rewards
burn_nft_collect_fee_with_return_
Function : Burns NFT and collects fees
Query Functions
get_position_info
Function : Gets detailed position information
get_nft_minted
Function : Gets number of minted NFTs
burn_nft_directly
Function : Directly burns empty position NFT
Swap Router Module
The Swap Router provides token swapping functionality, supporting single-step and multi-step swaps.
Single-Step Swap Functions
swap_a_b
Function : Swaps token A for token B
swap_a_b_with_return_
Function : Swaps tokens and returns result tokens
swap_b_a
Function : Swaps token B for token A
swap_b_a_with_return_
Function : Swaps tokens and returns result tokens
Partner Swap Functions
swap_with_partner
Function : Swaps through partner with fee sharing
Multi-Step Swap Functions
swap_a_b_b_c
Function : Two-step swap: A → B → C
swap_a_b_b_c_with_return_
Function : Two-step swap and returns result tokens
swap_a_b_c_b
Function : Two-step swap: A → B → C (through different pools)
Reward Manager Module
The Reward Manager is responsible for managing liquidity mining reward systems.
Reward Initialization Functions
init_reward_v2
Function : Initializes pool reward system (requires reward manager role)
reset_reward_v2
Function : Resets reward configuration
Reward Management Functions
add_reward
Function : Adds reward tokens to reward pool
remove_reward
Function : Removes reward tokens from reward pool
set_reward_emissions_per_second
Function : Sets reward emission rate per second
Pool Fetcher Module
The Pool Fetcher provides pool state querying and calculation functionality.
Swap Calculation Functions
compute_swap_result
Function : Calculates swap result without executing actual swap
Tick Data Retrieval Functions
fetch_ticks
Function : Batch retrieves tick data, returns results through events
fetch_ticks_for_testing
Function : Testing function for tick data retrieval, returns results directly
Position NFT Module
The Position NFT module manages NFTs representing liquidity positions.
pool_id
Function : Gets pool ID corresponding to NFT
position_id
Function : Gets position ID corresponding to NFT
The Partner module manages the partner system and fee sharing.
Partner Management Functions
create_partner
Function : Creates new partner
update_ref_fee_rate
Function : Updates partner's fee sharing ratio
update_time_range
Function : Updates partner's valid time range
Fee Collection Functions
claim_ref_fee
Function : Claims partner fee sharing
claim_ref_fee_with_return_
Function : Claims fee sharing and returns coin object
Query Functions
get_ref_fee_rate
Function : Gets partner's fee sharing ratio
check_partner_valid
Function : Checks if partner is within valid period
get_claimable_balance
Function : Gets claimable fee balance
Usage Recommendations
Version Check : All pool operation functions check protocol version to ensure compatibility
Time Limits : Most transaction functions include deadline parameter to prevent malicious exploitation during network congestion
Slippage Protection : Swap and liquidity operations include min/max amount parameters for slippage protection
Permission Management : Sensitive operations require appropriate admin permissions, controlled through ACL system
Event Monitoring : Important operations emit events for frontend and analytics tools to monitor
This documentation covers all public interfaces of the Turbos CLMM protocol, providing developers with a complete integration guide.