Quickstart
Installation
To use the Mira DEX SDK, you need to have the following dependencies installed:
Setup
To start using the SDK, you need to instantiate the MiraAmm
or ReadonlyMiraAmm
classes by providing the appropriate parameters like Account
for signing transactions or Provider
for read-only operations.
Example Setup
Data types
PoolId
Identifier of a pool. Consists of two assets and a boolean flag indicating whether the pool is stable.
MiraAmm Class
The MiraAmm class is used for building transaction requests to interact with the AMM.
Methods
id
- Returns the AMM contract ID.
addLiquidity
- Adds liquidity to an existing pool.
poolId
: ID of the pool.amount0Desired
: Desired amount of token 0.amount1Desired
: Desired amount of token 1.amount0Min
: Minimum amount of token 0.amount1Min
: Minimum amount of token 1.deadline
: Deadline block for the transaction.
The function will add two assets to the pool in the same proportion as the existing reserves in the pool. Desired and min amounts specify the amount of each asset to add. The actual amounts would be as close as possible to the desired amounts, not exceeding them and more than the min amounts.
createPoolAndAddLiquidity
- Creates a new pool and adds liquidity in a single transaction.
token0Contract
,token1Contract
: Contract addresses for the tokens.token0SubId
,token1SubId
: Sub ids of the tokens within the context of provided contracts.isStable
: Whether the pool is stable or volatile.amount0Desired
,amount1Desired
: Desired amounts of token 0 and token 1.deadline
: Deadline block for the transaction.
The same as addLiquidity
but creates a new pool. The pool is created with the provided tokens and the desired amounts. The function will throw an error if the pool already exists.
r
emoveLiquidity
- Removes liquidity from a pool.
poolId
: ID of the pool.liquidity
: Number of LP tokens to exchange for liquidity.amount0Min
,amount1Min
: Minimum numbers of tokens to receive from the pool.deadline
: Deadline block for the transaction.
Exchanges LP tokens for the underlying assets. The LP tokens are burned, and the assets are transferred to the user.
swapExactInput
- Performs a swap where the exact input amount is known.
amountIn
: Number of input tokens.assetIn
: Asset ID of the input token.amountOutMin
: Minimum number of output tokens.pools
: List of pools to route the swap.deadline
: Deadline block for the transaction.
Performs the swap specifying the exact number of input tokens. Supports multi-hop swaps if several pools are provided.
swapExactOutput
- Performs a swap where the exact output amount is known.
amountOut
: Desired output amount.assetOut
: Asset ID of the output token.amountInMax
: Maximum number of input tokens.pools
: List of pools to route the swap.deadline
: Deadline block for the transaction.
Performs the swap specifying the exact number of output tokens. Supports multi-hop swaps if several pools are provided.
ReadonlyMiraAmm Class
The ReadonlyMiraAmm
class is used for reading information from the AMM.
Methods
id
- Returns the AMM contract ID.
ammMetadata
- Fetches metadata for the AMM contract, including fees and owner details.
poolMetadata
- Fetches metadata for a specific pool.
poolId
: ID of the pool.
lpAssetInfo
- Fetches LP token asset info such as name, symbol, and total supply.
totalAssets
- Returns the total number of LP tokens created within the AMM. This number equals to the number of creates pools.
getLiquidityPosition
- Fetches the position corresponding to the number of LP tokens for a specific pool.
poolId
: ID of the pool.lpTokensAmount
: Number of LP tokens.
getOtherTokenToAddLiquidity
- Calculates the required amount of the second asset in a token pair based on the provided amount of the first asset. Returns the corresponding amount needed for the second asset to add to the pool.
poolId
: ID of the pool.isFirstToken
: whether theamount
corresponds to the first asset in the pool or to the second.amount
: Number of tokens of one of the assets of the pool.
previewSwapExactInput
- Calculates the output result of a swap operation with the exact input amount routed through the provided pools.
assetIdIn
: Asset ID of the input token.assetAmountIn
: Number of input tokens.pools
: List of pools to route the swap.
previewSwapExactOutput
- Calculates the amount of the input token to perform a swap operation routed through the provided pools to receive the specified output number of tokens.
assetIdOut
: Asset ID of the output token.assetAmountOut
: Number of output tokens.pools
: List of pools to route the swap.
Contrubutors
Contributions are welcome. Feel free to open a pull request or an issue on the GitHub repository.
Last updated