🌊Pool Manager
The Pool Manager is a contract that handles liquidity pools in the MANTRA DEX. The contract facilitates the creation and management of various types of liquidity pools, liquidity provision, token swaps, and multi-hop operations across different pools.
The Pool Manager enables permissionless creation of liquidity pools, requiring a fee to prevent spam. It supports multiple pools for the same asset pair, each with a unique identifier. Users can provide liquidity, perform swaps, and execute multi-hop operations across different pools.
Pool types
There are two types of pools supported by the Pool Manager, constant product (xyk) and stableswaps.
XYK Pool
The xyk pool is based on a constant product invariant:
Where X and Y are the reserves for each token in the pool, while k is a constant. The product of the number of tokens on each side of the pool should remain constant across trading operations. With X being the current balance of the pool's source asset and Y being that of the target asset:
To determine the value of the ask asset ∆y given the trader's offered asset ∆x:
The market price is calculated by dividing the number of pool's target token into the source asset (also called the pool ratio).
The spread between the executed and the expected trade is:
The deeper the pool the smaller the spread.
Stableswap
The stableswap pool implements the StableSwap curve described by the Curve protocol @ https://curve.fi/files/stableswap-paper.pdf.
It is possible to create a stableswap pool with 2-4 assets in it, and it is designed to have a low slippage for stable assets, making it ideal for stablecoin trading.
Instantiate
Instantiates an instance of the pool manager contract
fee_collector_addr
String
The fee collector contract address.
farm_manager_addr
String
The farm manager contract address.
pool_creation_fee
Coin
How much it costs to create a pool.
ExecuteMsg
CreatePool
Creates a new pool with the provided assets, their decimals for calculation fees, pool type and the identifier for a pool.
Creation of pools in the pool manager is permissionless, but a fee must be paid to create a pool which is specified in the contract configuration. Additionally, the user creating the pool must pay the token factory fee to create a subdenom, since the pool manager uses the token factory to issue the LP tokens.
All pools and their information are stored in the pool manager contract on the POOLS
map, and any amount of pools with any variation of assets can be created.
For example, two or more pools with the assets uom
and uusdc
can be created at anytime with different pool identifiers. A good example is two pools, same assets different pool types (stableswap vs constant product) however any variation is possible.
The contract will assign a prefix to the pool identifier. If the user creates a pool without specifying a custom identifier, the contract will assign the prefix p.
, followed by a number. For example, p.1
, p.2
, etc. On the other hand, if the user specifies a custom identifier, the contract will use the prefix o.
, followed by the custom identifier. For example, o.my_pool
.
asset_denoms
Vec<String>
The asset denoms for the pool.
asset_decimals
Vec<u8>
The decimals for the given asset denoms, provided in the same order as asset_denoms
.
pool_fees
PoolFee
The fees for the pool.
pool_type
PoolType
The type of pool to create. It can be either constant product or stableswap.
pool_identifier
Option<String>
The identifier for the pool. If not set, a number (pool counter) will be assigned as pool id.
ProvideLiquidity
Provides liquidity to the pool specified by the pool_identifier
. Liquidity balances are stored on a per-pool basis in order to not double count the assets of other pools with the same assets.
If lock_position_identifier
is provided, the LP tokens will be locked in the farm manager for the specified duration.
Otherwise, the LP tokens will be sent to the receiver address.
The amount of liquidity to be provided is determined by the amount of assets provided in info.funds
. If only one asset is provided then a single sided liquidity provision will be attempted.
Note: It's only possible to lock an LP position in the farm for the same user providing the liquidity, and not do it on behalf of another user.
slippage_tolerance
Option<Decimal>
A percentage value representing the acceptable slippage for the operation. When provided, if the slippage exceeds this value, the liquidity provision will not be executed.
max_spread
Option<Decimal>
The decimals for the given asset denoms, provided in the same order as asset_denoms
. The maximum allowable spread between the bid and ask prices for the pool. When provided, if the spread exceeds this value, the liquidity provision will not be executed.
receiver
Option<String>
The receiver of the LP.
pool_identifier
String
The identifier for the pool to provide liquidity for.
unlocking_duration
Option<u64>
The amount of time in seconds to unlock tokens if taking part on the farms. If not passed, the tokens will not be locked and the LP tokens will be returned to the user.
lock_position_identifier
Option<String>
The identifier of the position to lock the LP tokens in the farm manager, if any.
Swap
Swaps an offer asset to another asset in the pool specified by the pool_identifier
. By providing a pool identifier when performing a swap, only the desired asset need be specified in the swap message The amount to be swapped is provided in info.funds
ask_asset_denom
String
The return asset of the swap.
belief_price
Option<Decimal>
The belief price of the swap.
max_spread
Option<Decimal>
The maximum spread to incur when performing the swap. If the spread exceeds this value, the swap will not be executed.
receiver
Option<String>
The recipient of the output tokens. If not provided, the tokens will be sent to the sender of the message.
pool_identifier
String
The identifier for the pool to swap in.
WithdrawLiquidity
Withdraws liquidity from the pool specified by the pool_identifier
. A withdrawal of liquidity will result in the burning of any LP tokens that are returned as a part of the withdrawal. The LP token should be sent in the transaction.
pool_identifier
String
The identifier for the pool to withdraw from.
ExecuteSwapOperations
Execute multiple SwapOperations
to allow for multi-hop swaps. The routes are to be computed off-chain and passed in to the contract.
operations
Vec<SwapOperation>
The operations that should be performed in sequence. The amount in each swap will be the output from the previous swap. The first swap will use whatever funds are sent in the [MessageInfo
].
minimum_receive
Option<Uint128>
The minimum amount of the output (i.e., final swap operation token) required for the message to succeed.
receiver
Option<String>
The (optional) recipient of the output tokens. If left unspecified, tokens will be sent to the sender of the message.
max_spread
Option<Decimal>
The (optional) maximum spread to incur when performing any swap. Maximum 50%. If left unspecified, it will use the default max spread value from the contract.
UpdateConfig
Updates the configuration of the contract. If a field is not specified (i.e., set to None
), it will not be modified.
fee_collector_addr
Option<String>
The new fee collector contract address.
farm_manager_addr
Option<String>
The new farm manager contract address.
pool_creation_fee
Option<Coin>
The new fee that must be paid when a pool is created.
feature_toggle
Option<FeatureToggle>
The new feature toggles of the contract, allowing fine-tuned control over which operations are allowed.
UpdateOwnership(::cw_ownable::Action)
Implements cw_ownable
. Updates the contract's ownership. ::cw_ownable::Action
can be TransferOwnership
, AcceptOwnership
and RenounceOwnership
.
Note: This is a cw_ownable
message.
Propose to transfer the contract's ownership to another account, optionally with an expiry time. Can only be called by the contract's current owner. Any existing pending ownership transfer is overwritten.
new_owner
String
The new owner proposed,
expiry
Option<Expiration>
Optional expiration time parameter.
QueryMsg
Config
Returns the configuration of the contract.
AssetDecimals
Retrieves the decimals for the given asset in a specific pool.
pool_identifier
String
The pool identifier to do the query for.
denom
String
The queried denom in the given pool_identifier.
Simulation
Simulates a swap.
offer_asset
Coin
The offer asset to swap.
ask_asset_denom
String
The ask asset denom to get.
pool_identifier
String
The pool identifier to swap in.
ReverseSimulation
Simulates a reverse swap.
ask_asset
Coin
The ask asset to get after the swap.
offer_asset_denom
String
The offer asset denom to input.
pool_identifier
String
The pool identifier to swap in.
SimulateSwapOperations
Simulates swap operations.
offer_amount
Uint128
The amount to swap.
operations
Vec<SwapOperation>
The operations to perform.
ReverseSimulateSwapOperations
Simulates reverse swap operations.
ask_amount
Uint128
The amount to get after the swap.
operations
Vec<SwapOperation>
The operations to perform.
Pools
Retrieves the pool information for the given pool identifier or all pools.
pool_identifier
Option<String>
An optional parameter specifying the pool identifier to do the query for. If not provided, it will return all pools based on the pagination parameters.
start_after
Option<String>
An optional parameter specifying what pool (identifier) to start searching after.
limit
Option<u32>
The amount of pools to return. If unspecified, will default to a value specified by the contract.
Ownership
Returns the ownership of the contract.
Note: This is a cw_ownable
query.
MigrateMsg
Message to migrate the contract to a new code ID.
Last updated