Version Upgrade Guide

The Cetus CLMM core contract will undergo a mandatory upgrade in the near future. Upon completion:How to migrate to the latest version?

Why need to migrate?

Cetus has already updated to the new CLMM contract and will disable the old version of the CLMM contract. The following contracts will need to be updated simultaneously: integrate, stable farming, vault, aggregator, lp burn.

Clmm contract update details

This update introduces new methods for pool creation, with the primary change being mandatory liquidity provision for new pools. To create a new pool, you can use either:

  • pool_creator.create_pool_v2 on the cetus_clmm contract

  • pool_creator_v2.create_pool_v2 on the integrate contract

Note: The previous creation method factory.create_pool is permissioned, and factory.create_pool_with_liquidity is deprecated in this update. The pool_creator.create_pool_v2_by_creation_cap method is deprecated, please use pool_creator.create_pool_v2_with_creation_cap.

// cetus_clmm.pool_creator.create_pool_v2
        public fun create_pool_v2<CoinTypeA, CoinTypeB>(
        config: &GlobalConfig,
        pools: &mut Pools,
        tick_spacing: u32,
        initialize_price: u128,
        url: String,
        tick_lower_idx: u32,
        tick_upper_idx: u32,
        coin_a: Coin<CoinTypeA>,
        coin_b: Coin<CoinTypeB>,
        metadata_a: &CoinMetadata<CoinTypeA>,
        metadata_b: &CoinMetadata<CoinTypeB>,
        fix_amount_a: bool,
        clock: &Clock,
        ctx: &mut TxContext
): (Position, Coin<CoinTypeA>, Coin<CoinTypeB>) {}
  
// integrate.pool_creator_v2.create_pool_v2
public entry fun create_pool_v2<CoinTypeA, CoinTypeB>(
        config: &GlobalConfig,
        pools: &mut Pools,
        tick_spacing: u32,
        initialize_price: u128,
        url: String,
        tick_lower_idx: u32,
        tick_upper_idx: u32,
        coin_a: &mut Coin<CoinTypeA>,
        coin_b: &mut Coin<CoinTypeB>,
        metadata_a: &CoinMetadata<CoinTypeA>,
        metadata_b: &CoinMetadata<CoinTypeB>,
        fix_amount_a: bool,
        clock: &Clock,
        ctx: &mut TxContext
) {}

In these two methods, you can use the fix_amount_a parameter to control which coin amount remains fixed:

If fix_amount_a is true: The amount of coin_a will be fixed. You should provide the exact amount of coin_a you want to deposit, and the required amount of coin_b will be calculated automatically. If fix_amount_a is false: The amount of coin_b will be fixed. You should provide the exact amount of coin_b you want to deposit, and the required amount of coin_a will be calculated automatically.

There are two conditions for creating a pool. For regular tokens, the treasury cap owner does not impose any special requirements for creating pools associated with that token; anyone can create one. In this case, we have modified the original pool creation method to require only the addition of bidirectional liquidity at the time of pool creation.

In certain situations, coin issuers may wish to reclaim the ability to create pools. To accommodate this, the protocol implements a PoolCreationCap mechanism for coin issuers. Here's how it works:

Prerequisites:

  • You must hold the TreasuryCap of the coin

  • The TreasuryCap must not be frozen

  • Only one PoolCreationCap can be minted per coin

Steps to create a restricted pool:

  1. Mint a PoolCreationCap using your coin's TreasuryCap

  2. Register a pool by specifying: Quote coin and Tick spacing.

The protocol controls which quote coins and tick_spacing values are permitted for pool registration. Currently, only pools with the SUI-200 can be registered.

let pool_creator_cap = factory::mint_pool_creation_cap<T>(
    clmm_global_config,
    clmm_pools,
    &mut treasury_cap,
    ctx
);

factory::register_permission_pair<T, SUI>(
    clmm_global_config,
    clmm_pools,
    200,
    &pool_creator_cap,
    ctx
);


let (lp_position, return_coin_a, return_coin_b) = pool_creator::create_pool_v2_with_creation_cap<T, SUI>(
  clmm_global_config,
  clmm_pools,
  pool_creator_cap,
  200,
  current_sqrt_price,
  string::utf8(b""),
  coin_a,
  coin_b,
  metadata_a,
  metadata_b,
  is_fix_a,
  clk,
  ctx
);

Additionally, a new event CollectRewardV2Event has been added to the pool module. You can now use event to determine the type of reward to harvest

  1. Previous versions of the contract will be deprecated and no longer accessible

  2. All dependent protocols will require updates, including:

    1. Vaults

    2. StableFarming

    3. LPBurn

Please ensure all necessary preparations are made before the upgrade takes effect.

2. For SDK integrations

In both testnet and mainnet, we have set up default contract addresses. To integrate these changes, simply upgrade the cetus-sui-clmm-sdk package to version v5.1.10. Then, replace your current Cetus SDK initialization method with src/config/initCetusSDK.

You can refer to this Setting Up Configuration section to see the method for initializing the SDK.

Note: In version v5.1.8, the default CLMM and integrated contract published are not the latest versions.

More details can refer to via SDK.

3. For contract integrations

You can update the dependencies in your project's Move.toml

[package]
name= "cetus_example"
version = "0.0.1"

[dependencies]
CetusClmm = { git = "https://github.com/CetusProtocol/cetus-clmm-interface.git", subdir = "sui/cetus_clmm", rev = "mainnet-v1.25.0" override = true }

[address]
cetus_example = "0x0"
// don't need to define cetus_clmm duplicate

More contract details can refer to via Contract.

4. For aggregator integrations

The aggregator contract also needs to be upgraded to the latest version. In this new version, we have not only upgraded the dependent CLMM contract but also integrated several non-dex liquidity paths. The latest npm packge version is v0.3.11. More details can refer to Cetus Plus Aggregator.

Last updated