### Fetch Pools Example Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/factory.md Retrieves a paginated list of pools from the global registry. Use an empty vector for `start` to fetch the first page. ```move let pools_info = factory::fetch_pools(&pools_registry, vector[], 100); ``` -------------------------------- ### Create Partner Example Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/partner.md Example of creating a new partner with a 5% fee rate for one year. Ensure the recipient address is valid and the time window is correctly calculated. ```move // Create partner earning 5% of swap fees for one year let start = clock::timestamp_ms(&clock) / 1000; let end = start + (365 * 24 * 60 * 60); // 1 year later partner::create_partner( &config, &mut partners, utf8(b"my_partner"), 500, // 5% = 500/10000 start, end, recipient_address, &clock, &ctx ); ``` -------------------------------- ### Open Position Example Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/pool.md Example of how to open a new liquidity position within a specified tick range in a pool. ```move let position = pool::open_position( &config, &mut pool, 1000, 2000, ctx ); ``` -------------------------------- ### Example: Set Roles for Address Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/config.md Demonstrates how to grant an address both the pool manager and fee tier manager roles using a bitmask. This example requires an AdminCap and a mutable GlobalConfig. ```move // Give address pool manager and fee tier manager roles let roles = (1 << 0) | (1 << 1); // ACL_POOL_MANAGER | ACL_FEE_TIER_MANAGER config::set_roles(&admin_cap, &mut config, member_address, roles); ``` -------------------------------- ### Get Partner Start Time Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/partner.md Retrieves the Unix timestamp in seconds when the partner's fee earning period begins. ```move public fun start_time(partner: &Partner): u64 ``` -------------------------------- ### Update Partner Fee Rate Example Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/partner.md Example of updating an existing partner's fee rate to 8%. The new rate must be within the allowed range (0-10000). ```move // Update partner to earn 8% of swap fees partner::update_ref_fee_rate(&config, &mut partner, 800, &ctx); ``` -------------------------------- ### Example: Using rewarder_index Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Demonstrates how to use the `rewarder_index` function to retrieve and use a rewarder's index if it exists. ```move let opt_idx = rewarder::rewarder_index(&manager); if (option::is_some(&opt_idx)) { let idx = option::extract(&mut opt_idx); // Use rewarder at index idx }; ``` -------------------------------- ### Example: Claiming Fees and Joining Coins Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/partner.md Demonstrates how to claim fees using `claim_ref_fee_coin` and then merge the claimed coin with an existing coin object. ```move let claimed = partner::claim_ref_fee_coin( &config, &partner_cap, &mut partner, &ctx ); coin::join(&mut my_coin, claimed); ``` -------------------------------- ### Initialize Permission System and Whitelists Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/factory.md Initializes the permission system and whitelists. This function should be called only once during the initial setup of the protocol. ```move public fun init_manager_and_whitelist( config: &GlobalConfig, pools: &mut Pools, ctx: &mut TxContext, ) ``` -------------------------------- ### Flash Swap Example Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/README.md Illustrates how to execute a flash swap, perform custom arbitrage logic with the borrowed funds, and then repay the swap with the exact amounts. ```move // 1. Execute flash swap let (out_balance, in_balance, receipt) = pool::flash_swap( &config, &mut pool, true, // Swap A → B true, // by_amount_in 100, // Input amount of COIN_A 0, // No price limit &clock ); // 2. Do arbitrage or other operation with out_balance // ... custom logic ... // 3. Repay the swap pool::repay_flash_swap( &config, &mut pool, in_balance, // Repay with exact amount out_balance, // Return output receipt ); ``` -------------------------------- ### Get Position Description Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the description for a given position NFT. ```move public fun description(position_nft: &Position): String ``` -------------------------------- ### Fetch Positions Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/pool.md Retrieves position information starting at given IDs. Requires the Pool object, a vector of starting position IDs, and a limit for the number of positions to fetch. ```move public fun fetch_positions( pool: &Pool, start: vector, limit: u64, ): vector ``` -------------------------------- ### Flash Swap Example Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/README.md Illustrates how to execute a flash swap for arbitrage or other operations. This involves initiating the flash swap, performing custom logic with the borrowed assets, and then repaying the swap. ```APIDOC ## Flash Swap Example ### Description Illustrates how to execute a flash swap for arbitrage or other operations. This involves initiating the flash swap, performing custom logic with the borrowed assets, and then repaying the swap. ### Usage 1. **Execute flash swap** ```move let (out_balance, in_balance, receipt) = pool::flash_swap( &config, &mut pool, true, // Swap A → B true, // by_amount_in 100, // Input amount of COIN_A 0, // No price limit &clock ); ``` 2. **Do arbitrage or other operation with out_balance** ```move // ... custom logic ... ``` 3. **Repay the swap** ```move pool::repay_flash_swap( &config, &mut pool, in_balance, // Repay with exact amount out_balance, // Return output receipt ); ``` ``` -------------------------------- ### Example: Deposit Rewards Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Demonstrates how to deposit reward tokens into the global vault. It converts a reward coin into a balance and then calls the deposit_reward function. ```move let balance = coin::into_balance(reward_coin); let new_total = rewarder::deposit_reward( &config, &mut vault, balance ); ``` -------------------------------- ### Get Package Version Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/config.md Retrieves the current version of the package. Returns a u64 representing the version constant. ```move public fun package_version(): u64 ``` -------------------------------- ### Role Bitmask Example Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/configuration.md Demonstrates how to create a bitmask for member roles by combining individual role flags. The combined value represents multiple permissions. ```move let pool_manager = 1 << 0; // = 1 let fee_tier_mgr = 1 << 1; // = 2 let combined = pool_manager | fee_tier_mgr; // = 3 config::set_roles(&admin_cap, &mut config, my_address, combined); ``` -------------------------------- ### Fetch All Pools Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Retrieves a list of all pools, with options for pagination using start IDs and a limit. ```move public fun fetch_pools(pools: &Pools, start: vector, limit: u64): vector ``` -------------------------------- ### info_fee_growth_inside Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets fee growth tracking in PositionInfo. ```APIDOC ## info_fee_growth_inside ### Description Gets fee growth tracking in PositionInfo. ### Signature ```move public fun info_fee_growth_inside(info: &PositionInfo): (u128, u128) ``` ### Returns Tuple of (fee_growth_a, fee_growth_b) ``` -------------------------------- ### Get Partner Name Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/partner.md Retrieves the name of a partner. ```move public fun name(partner: &Partner): String ``` -------------------------------- ### Time Configuration with Unix Timestamps Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/configuration.md Sets start and end times for protocol operations using Unix timestamps in seconds. Ensure duration is correctly calculated. ```move let start = 1000000000u64; // Some Unix timestamp let duration_seconds = 365 * 24 * 60 * 60; // One year let end = start + duration_seconds; ``` -------------------------------- ### Compute Swap Step Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/math.md Calculates the result of a single swap step, including input and output amounts, the next price, and fees. This example assumes a swap from token A to token B by amount in. ```move // Compute swap result let (amount_in, amount_out, next_price, fee) = clmm_math::compute_swap_step( current_price, target_price, liquidity, input_amount, fee_rate, true, // A to B true // by amount in ); ``` -------------------------------- ### Fetch Multiple Positions Information Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves information for multiple positions based on provided starting IDs and a limit. ```move public fun fetch_positions( manager: &PositionManager, start: vector, limit: u64, ): vector ``` -------------------------------- ### Get Position URL Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Retrieves the URL associated with a liquidity position. ```move public fun url(position: &Position): String ``` -------------------------------- ### Create New ACL Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Initializes a new Access Control List (ACL) structure. This is the starting point for managing permissions. ```move public fun new(ctx: &mut TxContext): ACL ``` -------------------------------- ### Example: Add Pool Manager Role Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/config.md Illustrates adding the pool manager role (role ID 0) to a specific address. This operation requires admin capability and a mutable global configuration. ```move config::add_role(&admin_cap, &mut config, member, 0); // Add pool manager role ``` -------------------------------- ### Get Global Points Growth Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Retrieves the global accumulator for points growth across all liquidity. ```move public fun points_growth_global(manager: &RewarderManager): u128 ``` -------------------------------- ### Get Rewards Array from PositionInfo Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the array of PositionReward structs from PositionInfo. ```move public fun info_rewards(info: &PositionInfo): &vector ``` -------------------------------- ### Check Add Liquidity Status Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/restore.md Example of checking the 'add_liquidity' status flag within the 'add_liquidity' method to ensure the operation is permitted. ```move assert!(is_allow_add_liquidity(pool), EOperationNotPermitted); ``` -------------------------------- ### Get Global Rewards Growth Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Fetches the global reward growth values for all rewarders, ordered to match the `rewarders()` output. ```move public fun rewards_growth_global(manager: &RewarderManager): vector ``` -------------------------------- ### Get Partner Balances Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/partner.md Retrieves a reference to the Bag containing all accumulated fees for a partner. ```move public fun balances(partner: &Partner): &Bag ``` -------------------------------- ### Get Fee Growth Inside from PositionInfo Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the fee growth tracking (fee_growth_a, fee_growth_b) within the position's range from PositionInfo. ```move public fun info_fee_growth_inside(info: &PositionInfo): (u128, u128) ``` -------------------------------- ### Get Liquidity by Amount Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/math.md Calculates the required liquidity for a given amount of tokens. Use this when you know the exact amount of one token you want to swap. ```move public fun get_liquidity_by_amount( lower_index: I32, upper_index: I32, _current_tick_index: I32, current_sqrt_price: u128, amount: u64, is_fixed_a: bool, ): (u128, u64, u64) ``` -------------------------------- ### Get Points Growth Inside from PositionInfo Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the points growth within the position's range from PositionInfo. ```move public fun info_points_growth_inside(info: &PositionInfo): u128 ``` -------------------------------- ### Verify coins are in correct order for pool creation Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/factory.md Checks if the two coin types are in the correct lexicographical order (A > B) required for pool creation. This ensures consistency and prevents errors during pool setup. ```move public fun is_right_order(): bool ``` -------------------------------- ### Fetch Ticks Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/pool.md Retrieves ticks from the pool starting at specified indices. Requires the Pool object, a vector of starting tick indices, and a limit for the number of ticks to fetch. ```move public fun fetch_ticks( pool: &Pool, start: vector, limit: u64, ): vector ``` -------------------------------- ### Get Protocol Fee Rate Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/config.md Retrieves the current protocol fee rate applied to all swaps. ```move public fun get_protocol_fee_rate(global_config: &GlobalConfig): u64 ``` -------------------------------- ### Usage Pattern: Create and Use Partner Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/partner.md Illustrates the typical workflow for creating a partner and then performing swaps that involve partner fees. This includes setting up the partner and then using it in a flash swap. ```move // Create partner partner::create_partner( &config, &mut partners, utf8(b"my_partner"), 500, // 5% start_ts, end_ts, partner_addr, &clock, &ctx ); // Later, do swaps with partner fees going to partner account let (out_a, out_b, receipt) = pool::flash_swap_with_partner( &config, &mut pool, &partner, true, // A to B true, // by_amount_in 100, 0, &clock ); // ... complete swap ... pool::repay_flash_swap_with_partner( &config, &mut pool, &mut partner, payment_a, payment_b, receipt ); // Partner claims fees let claimed = partner::claim_ref_fee_coin( &config, &partner_cap, &mut partner, &ctx ); ``` -------------------------------- ### Get Amount by Liquidity Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/math.md Calculates the amounts of token A and token B that can be obtained from a given liquidity amount. This is useful for understanding the output of providing liquidity. ```move public fun get_amount_by_liquidity( tick_lower: I32, tick_upper: I32, current_tick_index: I32, current_sqrt_price: u128, liquidity: u128, round_up: bool, ): (u64, u64) ``` -------------------------------- ### description Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets the position description. ```APIDOC ## description ### Description Gets the position description. ### Signature ```move public fun description(position_nft: &Position): String ``` ``` -------------------------------- ### name Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets the position name. ```APIDOC ## name ### Description Gets the position name. ### Signature ```move public fun name(position_nft: &Position): String ``` ``` -------------------------------- ### Get Partner Fee Rate Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/partner.md Retrieves the configured fee rate for a partner. The fee rate is expressed as a fraction of 10,000. ```move public fun ref_fee_rate(partner: &Partner): u64 ``` -------------------------------- ### Get Access Control List Reference Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/config.md Obtains a reference to the Access Control List (ACL) object. Requires a GlobalConfig parameter. ```move public fun acl(config: &GlobalConfig): &acl::ACL ``` -------------------------------- ### Basic Liquidity Provision Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/README.md Demonstrates the steps for providing liquidity, including opening a position within a specified tick range, adding liquidity by fixing one token's amount, and repaying the operation. It also shows how to collect fees periodically. ```move // 1. Open a position in a tick range let position = pool::open_position( &config, &mut pool, 1000, // Lower tick 2000, // Upper tick ctx ); // 2. Add liquidity by specifying amount of one token let receipt = pool::add_liquidity_fix_coin( &config, &mut pool, &mut position, 1000000, // 1M of COIN_A true, // Fix token A amount &clock ); // 3. Provide required token amounts to complete the operation let (amount_a, amount_b) = pool::add_liquidity_pay_amount(&receipt); let balance_a = coin::into_balance(coin_a_payment); // Prepare token A let balance_b = coin::into_balance(coin_b_payment); // Prepare token B pool::repay_add_liquidity( &config, &mut pool, balance_a, balance_b, receipt ); // 4. Collect fees periodically let (fee_a, fee_b) = pool::collect_fee( &config, &mut pool, &position, true // Recalculate fees ); ``` -------------------------------- ### index Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets the position index. ```APIDOC ## index ### Description Gets the position index. ### Signature ```move public fun index(position_nft: &Position): u64 ``` ``` -------------------------------- ### borrow_position_info Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets information about a specific position. ```APIDOC ## borrow_position_info ### Description Gets information about a specific position. ### Signature ```move public fun borrow_position_info( manager: &PositionManager, position_id: ID, ): &PositionInfo ``` ### Parameters #### Path Parameters - **manager** (&PositionManager) - Required - Position manager - **position_id** (ID) - Required - Position to query ### Returns Reference to PositionInfo ``` -------------------------------- ### rewards_amount_owned Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets reward amounts for all rewarders. ```APIDOC ## rewards_amount_owned ### Description Gets reward amounts for all rewarders. ### Signature ```move public fun rewards_amount_owned( manager: &PositionManager, position_id: ID, ): vector ``` ### Parameters #### Path Parameters - **manager** (&PositionManager) - Required - Position manager - **position_id** (ID) - Required - Position to query ### Returns Vector of reward amounts for each rewarder ``` -------------------------------- ### Get Rewarder's Emissions Per Second Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Retrieves the emission rate for a rewarder, represented as a fixed-point number with a 64-bit decimal. ```move public fun emissions_per_second(rewarder: &Rewarder): u128 ``` -------------------------------- ### Retrieve All Fee Tiers Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/config.md Returns a reference to a map containing all configured fee tiers. This function is useful for inspecting the current fee tier setup. ```move public fun fee_tiers(config: &GlobalConfig): &VecMap ``` -------------------------------- ### info_rewards Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets reward array from PositionInfo. ```APIDOC ## info_rewards ### Description Gets reward array from PositionInfo. ### Signature ```move public fun info_rewards(info: &PositionInfo): &vector ``` ``` -------------------------------- ### Calculate Liquidity and Token Amounts Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/math.md Demonstrates how to calculate liquidity from token amounts and subsequently determine the required token amounts based on liquidity and current market conditions. Assumes token A to B direction. ```move // Calculate liquidity from token amounts let tick_lower = i32::from_u32(1000); let tick_upper = i32::from_u32(2000); let price_lower = tick_math::get_sqrt_price_at_tick(tick_lower); let price_upper = tick_math::get_sqrt_price_at_tick(tick_upper); let liquidity_a = clmm_math::get_liquidity_from_a( price_lower, price_upper, 1000000, // 1M of token A true ); // Calculate required token amounts let (amount_a, amount_b) = clmm_math::get_amount_by_liquidity( tick_lower, tick_upper, current_tick, current_price, liquidity_a, true ); ``` -------------------------------- ### info_points_owned Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets accumulated points from PositionInfo. ```APIDOC ## info_points_owned ### Description Gets accumulated points from PositionInfo. ### Signature ```move public fun info_points_owned(info: &PositionInfo): u128 ``` ``` -------------------------------- ### init_manager_and_whitelist Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/factory.md Initializes the permission system and whitelists. This function is intended to be called only once during the system's initialization. ```APIDOC ## init_manager_and_whitelist ### Description Initializes permission system and whitelists (called once during init). ### Method Public function (Move) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **config** (&GlobalConfig) - Yes - Global configuration - **pools** (&mut Pools) - Yes - Pools registry - **ctx** (&mut TxContext) - Yes - Transaction context ``` -------------------------------- ### Initialize Rewarder and Update Emission Rate Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Demonstrates the initialization of a rewarder for a new reward token and setting its emission rate. Use this when setting up rewards for a new token or adjusting the emission. ```move // Initialize rewarder for a new reward token pool::initialize_rewarder(&config, &mut pool, &ctx); // Set emission rate to 1000 tokens per second let emission = 1000u128 << 64; pool::update_emission( &config, &mut pool, &vault, emission, &clock, &ctx ); ``` -------------------------------- ### info_fee_owned Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets uncollected fees from PositionInfo. ```APIDOC ## info_fee_owned ### Description Gets uncollected fees from PositionInfo. ### Signature ```move public fun info_fee_owned(info: &PositionInfo): (u64, u64) ``` ### Returns Tuple of (fee_a, fee_b) ``` -------------------------------- ### url Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets the position metadata URL. ```APIDOC ## url ### Description Gets the position metadata URL. ### Signature ```move public fun url(position_nft: &Position): String ``` ``` -------------------------------- ### liquidity Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets the current liquidity of a position. ```APIDOC ## liquidity ### Description Gets the current liquidity of a position. ### Signature ```move public fun liquidity(position_nft: &Position): u128 ``` ### Returns Current liquidity amount ``` -------------------------------- ### start_time Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/partner.md Retrieves the Unix timestamp in seconds when the partner's fee earning period begins. ```APIDOC ## start_time ### Description Gets the fee earning start time. ### Method `public fun start_time` ### Parameters #### Path Parameters - **partner** (&Partner) - Required - Partner object to query ### Returns Unix timestamp in seconds ``` -------------------------------- ### Create a new pool with initial liquidity provision (v3) Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/factory.md An enhanced function to create a pool and simultaneously provide initial liquidity. It returns the created position NFT and any remaining coins. ```move public fun create_pool_v3_( config: &GlobalConfig, pools: &mut Pools, tick_spacing: u32, initialize_price: u128, url: String, tick_lower_idx: u32, tick_upper_idx: u32, coin_a: Coin, coin_b: Coin, amount_a: u64, amount_b: u64, fix_amount_a: bool, clock: &Clock, ctx: &mut TxContext, ): (Position, Coin, Coin) ``` -------------------------------- ### info_points_growth_inside Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets points growth in position range. ```APIDOC ## info_points_growth_inside ### Description Gets points growth in position range. ### Signature ```move public fun info_points_growth_inside(info: &PositionInfo): u128 ``` ``` -------------------------------- ### Basic Liquidity Provision Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/README.md Demonstrates the process of providing liquidity to a concentrated liquidity market maker pool. This includes opening a position within a specific price range, adding liquidity by fixing one token amount, and collecting fees. ```APIDOC ## Basic Liquidity Provision ### Description Demonstrates the process of providing liquidity to a concentrated liquidity market maker pool. This includes opening a position within a specific price range, adding liquidity by fixing one token amount, and collecting fees. ### Usage 1. **Open a position in a tick range** ```move let position = pool::open_position( &config, &mut pool, 1000, // Lower tick 2000, // Upper tick ctx ); ``` 2. **Add liquidity by specifying amount of one token** ```move let receipt = pool::add_liquidity_fix_coin( &config, &mut pool, &mut position, 1000000, // 1M of COIN_A true, // Fix token A amount &clock ); ``` 3. **Provide required token amounts to complete the operation** ```move let (amount_a, amount_b) = pool::add_liquidity_pay_amount(&receipt); let balance_a = coin::into_balance(coin_a_payment); // Prepare token A let balance_b = coin::into_balance(coin_b_payment); // Prepare token B pool::repay_add_liquidity( &config, &mut pool, balance_a, balance_b, receipt ); ``` 4. **Collect fees periodically** ```move let (fee_a, fee_b) = pool::collect_fee( &config, &mut pool, &position, true // Recalculate fees ); ``` ``` -------------------------------- ### fee_tiers Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/config.md Gets the map of all configured fee tiers. ```APIDOC ## fee_tiers ### Description Gets the map of all configured fee tiers. ### Method Not applicable (Move function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **config** (&GlobalConfig) - Yes - Global configuration ### Returns Reference to VecMap of fee tiers ``` -------------------------------- ### Initialize and Update Rewarder Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/README.md Demonstrates the initialization of a rewarder for a pool and updating its emission rate. The emission rate is specified in a fixed-point format with a 64-bit decimal. ```move pool::initialize_rewarder( &config, &mut pool, &ctx ); // 2. Update emission rate (1000 tokens per second) let emission = 1000u128 << 64; // Fixed-point with 64-bit decimal pool::update_emission( &config, &mut pool, &vault, emission, &clock, &ctx ); ``` -------------------------------- ### Get Position Name Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Retrieves the name of a liquidity position. ```move public fun name(position: &Position): String ``` -------------------------------- ### Execute Flash Loan Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/pool.md Executes a flash loan of a specified token with a fee. Requires a GlobalConfig, Pool, a boolean indicating which token to loan, and the amount. Returns the loaned balance, an empty balance, and a receipt that must be repaid with fees. ```move public fun flash_loan( config: &GlobalConfig, pool: &mut Pool, loan_a: bool, amount: u64, ): (Balance, Balance, FlashLoanReceipt) ``` -------------------------------- ### reward_coin Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Accessor to get the coin type of a specific rewarder. ```APIDOC ## reward_coin ### Description Gets the coin type of a rewarder. ### Method (Not specified, likely a contract function call) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **rewarder** (&Rewarder) - Yes - Rewarder ### Request Example (Not specified) ### Response #### Success Response - **TypeName** - Coin type of the rewarder #### Response Example (Not specified) ``` -------------------------------- ### last_update_time Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Gets the timestamp of the last settlement operation in seconds. ```APIDOC ## last_update_time ### Description Gets the last settlement timestamp. ### Method (Not specified, likely a contract function call) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **manager** (&RewarderManager) - Yes - Rewarder manager ### Request Example (Not specified) ### Response #### Success Response - **u64** - Last update timestamp in seconds #### Response Example (Not specified) ``` -------------------------------- ### Create New Partner Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Creates a new partner entry with specified details including fee rate, time bounds, and recipient address. Requires transaction context. ```move public fun create_partner( config: &GlobalConfig, partners: &mut Partners, name: String, ref_fee_rate: u64, start_time: u64, end_time: u64, recipient: address, clock: &Clock, ctx: &mut TxContext, ) ``` -------------------------------- ### get_fee_rate Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/config.md Gets the fee rate for a specific tick spacing. ```APIDOC ## get_fee_rate ### Description Gets the fee rate for a specific tick spacing. ### Method Not applicable (Move function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **tick_spacing** (u32) - Yes - Tick spacing - **global_config** (&GlobalConfig) - Yes - Global configuration ### Returns Fee rate for this spacing (denominator: 1,000,000), or 0 if not found ``` -------------------------------- ### Get Position Index Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Retrieves the index of a specific liquidity position. ```move public fun index(position: &Position): u64 ``` -------------------------------- ### Calculate Next Sqrt Price (Token A Input) Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/math.md Calculates the next square root price after a swap of token A, assuming the provided amount is an input. Requires current sqrt price, liquidity, and amount. ```move public fun get_next_sqrt_price_a_up( sqrt_price: u128, liquidity: u128, amount: u64, by_amount_input: bool, ): u128 ``` -------------------------------- ### Get Position Name Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the name associated with a position NFT. ```move public fun name(position_nft: &Position): String ``` -------------------------------- ### Get Position Index Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the index of a given position NFT. ```move public fun index(position_nft: &Position): u64 ``` -------------------------------- ### Pool Creator Module Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Provides utilities for creating new liquidity pools. ```APIDOC ## Create pool with creation cap ### Description Creates a new liquidity pool using a creation capability, specifying tick ranges and initial price. ### Signature `public fun create_pool_v2_with_creation_cap(config: &GlobalConfig, pools: &mut Pools, cap: &PoolCreationCap, tick_spacing: u32, initialize_price: u128, url: String, tick_lower_idx: u32, tick_upper_idx: u32, coin_a: Coin, coin_b: Coin, metadata_a: &CoinMetadata, metadata_b: &CoinMetadata, fix_amount_a: bool, clock: &Clock, ctx: &mut TxContext): (Position, Coin, Coin)` ``` ```APIDOC ## Create pool ### Description Creates a new liquidity pool with specified parameters, including tick ranges and initial price. ### Signature `public fun create_pool_v2(config: &GlobalConfig, pools: &mut Pools, tick_spacing: u32, initialize_price: u128, url: String, tick_lower_idx: u32, tick_upper_idx: u32, coin_a: Coin, coin_b: Coin, metadata_a: &CoinMetadata, metadata_b: &CoinMetadata, fix_amount_a: bool, clock: &Clock, ctx: &mut TxContext): (Position, Coin, Coin)` ``` -------------------------------- ### inited_rewards_count Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Gets the number of initialized rewarders associated with a specific position. ```APIDOC ## inited_rewards_count ### Description Gets the number of initialized rewarders for a position. ### Function Signature ```move public fun inited_rewards_count( manager: &PositionManager, position_id: ID, ): u64 ``` ### Parameters #### Path Parameters - **manager** (&PositionManager) - Yes - Position manager - **position_id** (ID) - Yes - Position to query ### Returns Count of rewarders that have been initialized ``` -------------------------------- ### Factory Module API Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/MANIFEST.md Documentation for the Factory module, covering pool creation, coin management, permission system, and pool registry. ```APIDOC ## Factory Module API Reference ### Description Documentation for the Factory module, which handles the creation of new pools, management of coin assets, the permission system, and the registry of all created pools. ### Module Location api-reference/factory.md ### Key Features - Pool Creation - Coin Management - Permission System - Pool Registry ``` -------------------------------- ### Calculate Next Sqrt Price (Token B Input) Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/math.md Calculates the next square root price after a swap of token B, assuming the provided amount is an input. Requires current sqrt price, liquidity, and amount. ```move public fun get_next_sqrt_price_b_down( sqrt_price: u128, liquidity: u128, amount: u64, by_amount_input: bool, ): u128 ``` -------------------------------- ### growth_global Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Accessor to get the global growth accumulator for a specific rewarder. ```APIDOC ## growth_global ### Description Gets the global growth accumulator of a rewarder. ### Method (Not specified, likely a contract function call) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **rewarder** (&Rewarder) - Yes - Rewarder ### Request Example (Not specified) ### Response #### Success Response - **u128** - Global growth accumulator of the rewarder #### Response Example (Not specified) ``` -------------------------------- ### Get Accumulated Points from PositionInfo Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the accumulated points for a position from PositionInfo. ```move public fun info_points_owned(info: &PositionInfo): u128 ``` -------------------------------- ### Mint Pool Creation Capability by Admin Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/factory.md Creates a PoolCreationCap using admin permissions. Requires the fee tier manager role for the transaction context. ```move public fun mint_pool_creation_cap_by_admin( config: &GlobalConfig, pools: &mut Pools, ctx: &mut TxContext, ): PoolCreationCap ``` -------------------------------- ### Get Position Metadata URL Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the URL for the metadata of a position NFT. ```move public fun url(position_nft: &Position): String ``` -------------------------------- ### Rewarder Emission Rate Calculation Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/configuration.md Explains how to calculate token emission rates per second per unit liquidity using fixed-point arithmetic. The value is represented as `value >> 64`. ```move 1 token/second = 1 << 64 0.5 tokens/second = (1 << 64) / 2 100 tokens/second = 100 << 64 ``` -------------------------------- ### Create Pool with Creation Cap Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Creates a new liquidity pool using a creation cap, specifying detailed parameters for coins, price, and tick ranges. Returns the created position and any leftover coins. ```move public fun create_pool_v2_with_creation_cap( config: &GlobalConfig, pools: &mut Pools, cap: &PoolCreationCap, tick_spacing: u32, initialize_price: u128, url: String, tick_lower_idx: u32, tick_upper_idx: u32, coin_a: Coin, coin_b: Coin, metadata_a: &CoinMetadata, metadata_b: &CoinMetadata, fix_amount_a: bool, clock: &Clock, ctx: &mut TxContext, ): (Position, Coin, Coin) ``` -------------------------------- ### Get Minimum Tick Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Returns the minimum tick index allowed in the CLMM system. ```move public fun min_tick(): i32::I32 ``` -------------------------------- ### Get Maximum Tick Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Returns the maximum tick index allowed in the CLMM system. ```move public fun max_tick(): i32::I32 ``` -------------------------------- ### create_pool_v3 Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/factory.md An enhanced function to create a new pool and provide initial liquidity simultaneously. It requires a global configuration, pools registry, tick spacing, initial price, and details for the initial liquidity provision. ```APIDOC ## create_pool_v3 ### Description Enhanced pool creation with initial liquidity provision. ### Method N/A (Move function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **config** (&GlobalConfig) - Required - Global configuration - **pools** (&mut Pools) - Required - Pools registry - **tick_spacing** (u32) - Required - Tick spacing - **initialize_price** (u128) - Required - Initial sqrt price - **url** (String) - Required - Pool metadata URL - **tick_lower_idx** (u32) - Required - Lower tick bound - **tick_upper_idx** (u32) - Required - Upper tick bound - **coin_a** (Coin) - Required - Token A to seed pool - **coin_b** (Coin) - Required - Token B to seed pool - **amount_a** (u64) - Required - Amount of token A - **amount_b** (u64) - Required - Amount of token B - **fix_amount_a** (bool) - Required - true to fix A amount, false for B - **clock** (&Clock) - Required - Sui clock - **ctx** (&mut TxContext) - Required - Transaction context ### Returns - **(Position, Coin, Coin)** - Tuple of (position_nft, remaining_coin_a, remaining_coin_b) **Note:** Creates pool and initial position in one transaction ``` -------------------------------- ### Calculate Next Sqrt Price from Output Amount Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/math.md Calculates the next square root price given an output amount and the swap direction (A to B or B to A). Requires current sqrt price and liquidity. ```move public fun get_next_sqrt_price_from_output( sqrt_price: u128, liquidity: u128, amount: u64, a_to_b: bool, ): u128 ``` -------------------------------- ### Get Pool ID from Position Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Extracts the pool identifier from a given position object. ```move public fun pool_id(position: &Position): ID ``` -------------------------------- ### new Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Creates an empty rewarder manager for a pool. This function initializes a new RewarderManager with no active rewarders. ```APIDOC ## new ### Description Creates an empty rewarder manager for a pool. ### Returns New RewarderManager with no active rewarders ### Signature ```move public fun new(): RewarderManager ``` ``` -------------------------------- ### Get Position Liquidity Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the current liquidity amount for a given position NFT. ```move public fun liquidity(position_nft: &Position): u128 ``` -------------------------------- ### Get Last Update Time Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Fetches the timestamp of the last settlement operation in seconds. ```move public fun last_update_time(manager: &RewarderManager): u64 ``` -------------------------------- ### Create a new pool with given configuration Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/factory.md Creates a new liquidity pool with specified coin types, tick spacing, and initial price. This function requires the caller to have the pool manager role and the pair to be permitted. ```move public fun create_pool( pools: &mut Pools, config: &GlobalConfig, tick_spacing: u32, initialize_price: u128, url: String, clock: &Clock, ctx: &mut TxContext, ) ``` -------------------------------- ### Initialize Rewarder Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/pool.md Initializes a rewarder for a specific reward token within a pool. Requires global configuration and a mutable pool reference. ```move public fun initialize_rewarder( config: &GlobalConfig, pool: &mut Pool, ctx: &TxContext, ) ``` -------------------------------- ### Get Upper Tick Index of Position Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Retrieves the upper tick index from a position object. ```move public fun tick_upper_index(position: &Position): I32 ``` -------------------------------- ### flash_swap Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/pool.md Executes a flash swap, allowing for token exchange with deferred settlement. The user must repay the borrowed amount along with any fees using the `repay_flash_swap` function. ```APIDOC ## flash_swap ### Description Executes a flash swap allowing token exchange with deferred settlement. The user must repay the borrowed amount along with any fees using the `repay_flash_swap` function. ### Method Public Function ### Endpoint N/A (Move Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response - **(Balance, Balance, FlashSwapReceipt)** - A tuple containing the output balance, input balance or refund, and a flash swap receipt. #### Response Example N/A **Throws:** EWrongSqrtPriceLimit if price limit violated, EAmountOutIsZero if no output ``` -------------------------------- ### Get Lower Tick Index of Position Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Retrieves the lower tick index from a position object. ```move public fun tick_lower_index(position: &Position): I32 ``` -------------------------------- ### Execute Flash Swap Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/pool.md Executes a flash swap for token exchange with deferred settlement. Requires a GlobalConfig, Pool, swap parameters, and a Clock. Returns balances and a receipt that must be repaid. ```move public fun flash_swap( config: &GlobalConfig, pool: &mut Pool, a2b: bool, by_amount_in: bool, amount: u64, sqrt_price_limit: u128, clock: &Clock, ): (Balance, Balance, FlashSwapReceipt) ``` -------------------------------- ### Get Uncollected Fees from PositionInfo Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/position.md Retrieves the uncollected fees (fee_a, fee_b) for a position from PositionInfo. ```move public fun info_fee_owned(info: &PositionInfo): (u64, u64) ``` -------------------------------- ### Get Rewarder's Global Growth Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Accesses the global growth accumulator specific to a rewarder. ```move public fun growth_global(rewarder: &Rewarder): u128 ``` -------------------------------- ### Calculate Next Sqrt Price from Input Amount Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/math.md Calculates the next square root price given an input amount and the swap direction (A to B or B to A). Requires current sqrt price and liquidity. ```move public fun get_next_sqrt_price_from_input( sqrt_price: u128, liquidity: u128, amount: u64, a_to_b: bool, ): u128 ``` -------------------------------- ### Get Total Points Released Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Returns the total accumulated points that have been released to liquidity providers. ```move public fun points_released(manager: &RewarderManager): u128 ``` -------------------------------- ### Create Pool Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/packages/cetus_clmm/README.md Creates a new liquidity pool with specified parameters for coins, price, and tick ranges. Returns the created position and any leftover coins. This version does not use a creation cap. ```move public fun create_pool_v2( config: &GlobalConfig, pools: &mut Pools, tick_spacing: u32, initialize_price: u128, url: String, tick_lower_idx: u32, tick_upper_idx: u32, coin_a: Coin, coin_b: Coin, metadata_a: &CoinMetadata, metadata_b: &CoinMetadata, fix_amount_a: bool, clock: &Clock, ctx: &mut TxContext, ): (Position, Coin, Coin) ``` -------------------------------- ### fee_rate_denominator Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/math.md Gets the fee rate denominator constant. This is used as the denominator for fee rate percentages. ```APIDOC ## fee_rate_denominator ### Description Gets the fee rate denominator constant. ### Returns - u64: 1,000,000 ``` -------------------------------- ### flash_loan Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/pool.md Executes a flash loan of a specified token, including fees. The borrowed amount and fees must be repaid using the `repay_flash_loan` function. ```APIDOC ## flash_loan ### Description Executes a flash loan of a specified token, including fees. The borrowed amount and fees must be repaid using the `repay_flash_loan` function. ### Method Public Function ### Endpoint N/A (Move Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response - **(Balance, Balance, FlashLoanReceipt)** - A tuple containing the loaned balance, an empty balance, and a flash loan receipt. #### Response Example N/A **Returns:** Triple of (loaned_balance, empty_balance, receipt) - receipt must be repaid with fees ``` -------------------------------- ### Get Rewarder's Reward Coin Type Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/api-reference/rewarder.md Accesses the specific coin type that a rewarder distributes. ```move public fun reward_coin(rewarder: &Rewarder): TypeName ``` -------------------------------- ### Partner Module API Source: https://github.com/cetusprotocol/cetus-contracts/blob/main/_autodocs/MANIFEST.md Documentation for the Partner module, covering partner creation, fee rates, time windows, and fee claiming. ```APIDOC ## Partner Module API Reference ### Description Documentation for the Partner module, which governs partner-related functionalities including partner creation, setting fee rates, managing time windows, and claiming fees. ### Module Location api-reference/partner.md ### Key Features - Partner Creation - Fee Rates - Time Windows - Fee Claiming ```