Skip to main content

Creating New Pools

InitiaDEX allows anyone to create a liquidity pool.
ParameterDescription
nameName of the trading pair and the corresponding LP Token
symbolSymbol for the LP Token
swap_fee_rateFee rate applied to swaps
coin_a_weight and coin_b_weightBalancer weights for the respective coins
coin_a_metadata and coin_b_metadataMetadata for each coin in the pair
coin_a_amount and coin_b_amountInitial amounts for each coin
For more information on metadata, please refer to obtaining metadata.

How to Provide Liquidity

Provide Liquidity

provide_liquidity enables you to provide liquidity of both coin_a and coin_b in the specific pair. To maximize the LP tokens received and minimize slippage, provide liquidity in proportion with the current ratio. The Move module interface is as follows:
  • 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 amount of liquidity token to receive. In case that the actual value is smaller than min_liquidity, the transaction will fail.

Single Asset Provide Liquidity

Instead of providing both tokens in a pair, you can provide liquidity using only one token. Internally, half of the token is swapped to the other token in the pair to provide liquidity, which may result in fees and slippage. The Move function interface is as follows:
  • 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 amount of liquidity token to receive. In case that the actual value is smaller than min_liquidity, the transaction will fail.

How to Withdraw Liquidity

Withdraw Liquidity

withdraw_liquidity allows you to provide liquidity tokens and receive coin_a and coin_b. The Move module interface is as follows:
  • pair: The metadata or object address of pair.
  • liquidity: Amount of liquidity token.
  • min_coin_a_amount and min_coin_b_amount : Minimum amount 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.

How to Swap Pair

Swap Simulation

swap_simulation is a view function to estimate the return value of said swap.
  • pair: The metadata or object address of pair.
  • offer_metadata: Metadata of offered coin.
  • offer_amount: Amount of offered coin.

Swap

The Move module interface for swap function is as follows:
  • pair: The metadata or object address of pair.
  • offer_coin: Metadata of offered coin.
  • offer_coin_amount: Amount of offered coin.
  • min_return: Minimum return amount of coin. In case that the actual value is smaller than min_return, the transaction will fail.

How to Delegate LP Tokens

Whitelist a Pair

To delegate your LP tokens to a validator, you need to whitelist the LP token first. You can use MsgWhitelist to whitelist the LP token.
proposal.json

Delegate LP Tokens

After whitelisting the LP token, you can delegate your LP tokens to a validator. You can use MsgDelegate to delegate LP tokens.

Example Code

The following example demonstrates the above functions in a single script using InitiaJS. The script includes the following steps:
  1. Create a pair
  2. Provide liquidity
  3. Whitelist LP
  4. Delegate LP tokens to the validator
  5. Withdraw rewards from the validator
To run the script, you need to install the following packages:
Also, we assume:
  • Local Initia node is running on http://localhost:1317.
  • The user and validator share the same mnemonic for simplicity.