InitiaDEX stands as a pivotal component of the Initia blockchain, functioning as a native decentralized exchange (DEX) constructed on Layer 1 using the Move programming language. As an essential part of the Omnitia ecosystem, InitiaDEX not only facilitates trading but also significantly enhances liquidity and interoperability between Layer 1 and various Layer 2 networks. For more information about InitiaDEX, please refer to this section.
Interacting with InitiaDEX
Create a Trading Pair
InitiaDEX allows anyone to create a custom trading pair. The Move Function Interface is as follows:
public entry fun create_pair_script( creator:&signer, name:String, symbol:String, swap_fee_rate:Decimal128, coin_a_weight:Decimal128, coin_b_weight:Decimal128, coin_a_metadata:Object<Metadata>, coin_b_metadata:Object<Metadata>, coin_a_amount:u64, coin_b_amount:u64,)
name: Name of the trading pair and the corresponding LP Token.
symbol: Symbol for the LP Token.
swap_fee_rate: Fee rate applied to swaps.
coin_a_weight and coin_b_weight: Balancer weights for the respective coins.
coin_a_metadata and coin_b_metadata: Metadata for each coin in the pair.
coin_a_amount and coin_b_amount: Initial amounts for each coin.
provide_liquidity allows the users to provide liquidity of both coin_a and coin_b in the said pair. In order to maximize liquidity, the user should provide in resonation with the current ratio. The Move module interface is as follows:
public entry fun provide_liquidity_script( account:&signer, pair:Object<Config>, coin_a_amount_in:u64, coin_b_amount_in:u64, min_liquidity:Option<u64>)
pair: The metadata or object address of pair.
coin_a_amount_in and coin_b_amount_in: Amount of token provided for coin_a and coin_b
min_liquidity: Minimum amout of liquidity token to receive. In case that the actual value is smaller than min_liquidity, the transaction will fail.
Instead of creating a pair, the user can provide a pool of only one token. Internally, the token will be swapped to another token and provide liquidity, so there can be fee and slippage in occurance. The Move function interface is as follows:
public entry fun single_asset_provide_liquidity_script( account:&signer, pair:Object<Config>, provide_coin:Object<Metadata>, amount_in:u64, min_liquidity:Option<u64>)
pair: The metadata or object address of pair.
provide_coin: The metadata of the provided coin.
amount_in: The amount of provided coin.
min_liquidity: Minimum amout of liquidity token to receive. In case that the actual value is smaller than min_liquidity, the transaction will fail.
withdraw_liquidity allows users to provide liquidity tokens and receive coin_a and coin_b. The Move module interface is as follows:
public entry fun withdraw_liquidity_script( account:&signer, pair:Object<Config>, liquidity:u64, min_coin_a_amount:Option<u64>, min_coin_b_amount:Option<u64>,)
pair: The metadata or object address of pair.
liquidity: Amount of liquidity token.
min_coin_a_amount and min_coin_b_amount : Minimum amout of coin_a or coin_b to receive. In case that the actual value is smaller than min_coin_a_amount or min_coin_b_amount, the transaction will fail.
The provided examples illustrate the practical steps necessary to interact with InitiaDEX, demonstrating its versatility and user-friendliness within the Initia blockchain ecosystem. By detailing how to create trading pairs, provide liquidity, and perform transactions like swaps and withdrawals, users are equipped with the tools needed to effectively engage with the decentralized exchange. The use of the Move programming language ensures secure and efficient execution of these operations, reflecting the platform’s commitment to fostering a reliable and scalable trading environment. For developers and traders alike, understanding and utilizing these examples can significantly enhance their ability to customize and optimize their interactions with InitiaDEX, leveraging the full potential of decentralized finance on this innovative platform.