Interacting with InitiaDEX
Creating New Pools
InitiaDEX allows anyone to create a liquidity pool.
Parameter | Description |
---|---|
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 |
For more information on metadata, please refer to obtaining metadata.
How to Provide Liquidity
Provide Liquidity
provide_liquidity
enables the users to provide liquidity of both coin_a
and coin_b
in the specific pair. In order to maximize liquidity, the user should provide in resonation with the current ratio. The Move module interface is as follows:
pair
: The metadata or object address of pair.coin_a_amount_in
andcoin_b_amount_in
: Amount of token provided forcoin_a
andcoin_b
.min_liquidity
: Minimum amout of liquidity token to receive. In case that the actual value is smaller thanmin_liquidity
, the transaction will fail.
Single Asset Provide Liquidity
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:
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 thanmin_liquidity
, the transaction will fail.
How to Withdraw Liquidity
Withdraw Liquidity
withdraw_liquidity
allows users 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
andmin_coin_b_amount
: Minimum amout ofcoin_a
orcoin_b
to receive. In case that the actual value is smaller thanmin_coin_a_amount
ormin_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 thanmin_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. We can use MsgWhitelist to whitelist the LP token.
Delegate LP Tokens
After whitelisting the LP token, you can delegate your LP tokens to a validator. We 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:
- Create a pair
- Provide liquidity
- Whitelist LP
- Delegate LP tokens to the validator
- 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.
Was this page helpful?