Metapool Factory
Metapool Factory: Deployer and Registry
The Factory
contract is used to deploy new MPOOL pools and to find existing ones. It is deployed to the mainnet at the following address
0x3DeFB1183e8931353A8407A89A0Bc864B018953A
Warning
Please carefully review the limitations of the factory prior to deploying a new pool. Deploying a pool using an incompatible token could result in permanent losses to liquidity providers and/or traders. Factory pools cannot be killed and tokens cannot be rescued from them!
Deploying a Pool
Factory.deploy_metapool
(_base_pool: address, _name: String[32], _symbol: String[10], _coin: address, _A: uint256, _fee: uint256) β address: nonpayable
Deploys a new metapool.
_base_pool
: Address of the base pool use within the new metapool._name
: Name of the new metapool._symbol
: Symbol for the new metapoolβs LP token. This value will be concatenated with the base pool symbol._coin
: Address of the coin being used in the metapool_A
: Amplification Coefficient_fee
: Trade Fee, given as an integer with 1e10 precision.
Returns the address of the newly deployed pool.
Note
After deploying a pool, you must also add initial liquidity before the pool can be used.
After deploying a pool, you must also add initial liquidity before the pool can be used.
Limitations
The token within the new pool must expose a
decimals
method and use a maximum of 18 decimal places.The tokenβs
transfer
andtransferFrom
methods must revert upon failure.Successful token transfers must move exactly the specified number of tokens between the sender and receiver. Tokens that take a fee upon a successful transfer may cause the pool to break or act in unexpected ways.
Token balances must not change without a transfer. Rebasing tokens are not supported!
Pools deployed by the factory cannot be paused or killed.
Pools deployed by the factory are not eligible for some rewards.
Base Pools
A metapool pairs a coin against the LP token of another pool. This other pool is referred to as the βbase poolβ. By using LP tokens, metapools allow swaps against any asset within their base pool, without diluting the base poolβs liquidity.
The factory allows deployment of metapools that use the following base pools:
3pool (USD denominated assets): 0x61bB2F4a4763114268a47fB990e633Cb40f045F8
It is possible to enable additional base pools through a DAO vote.
Choosing an Amplification Coefficient
The amplification co-efficient (βAβ) determines a poolβs tolerance for imbalance between the assets within it. A higher value means that trades will incure slippage sooner as the assets within the pool become imbalanced.
The appropriate value for A is dependent upon the type of coin being used within the pool. We recommend the following values:
Uncollateralized algorithmic stablecoins: 5-10
Non-redeemable, collateralized assets: 100
Redeemable assets: 200-400
It is possible to modify the amplification coefficient for a pool after it has been deployed. However, it requires a vote within the DAO and must reach a 15% quorum.
Trade fees
Our pools charge a fee for token exchanges and when adding or removing liquidity in an imbalanced manner.
For factory pools, the size of the fee is set at deployment. The minimum fee is 0.04% (represented as 4000000
). The maximum fee is 1% (100000000
). The fee cannot be changed after a pool has been deployed.
Finding Pools
The following getter methods are available for finding pools that were deployed via the factory:
Returns the total number of pools that have been deployed by the factory.
Returns the nβth entry in a zero-indexed array of deployed pools. Returns ZERO_ADDRESS when i is greater than the number of deployed pools.
Note that because factory-deployed pools are not killable, they also cannot be removed from the registry. For this reason the ordering of pools within this array will never change.
Finds a pool that allows for swaps between _from
and _to
. You can optionally include i
to get the i-th pool, when multiple pools exist for the given pairing.
The order of _from
and _to
does not affect the result.
Returns ZERO_ADDRESS
when swaps are not possible for the pair or i
exceeds the number of available pools.
Getting Pool Info
The factory has a similar API to that of the main Registry, which can be used to query information about existing pools.
Coins and Coin Info
Factory.get_n_coins
(pool: address) β uint256[2]: view
Get the number of coins and underlying coins within a pool.
Factory.get_coins
(pool: address) β address[2]: view
Get a list of the swappable coins within a pool.
Factory.get_underlying_coins
(pool: address) β address[8]: view
Get a list of the swappable underlying coins within a pool.
Factory.get_decimals
(pool: address) β uint256[8]: view
Get a list of decimal places for each coin within a pool.
Factory.get_underlying_decimals
(pool: address) β uint256[8]: view
Get a list of decimal places for each underlying coin within a pool.
For pools that do not involve lending, the return value is identical to Non-lending coins that still involve querying a rate are marked as having 0
decimals.
Factory.get_coin_indices
(pool: address, _from: address, _to: address) β (int128, int128, bool): view
Convert coin addresses into indices for use with pool methods.
Returns the index of _from
, index of _to
, and a boolean indicating if the coins are considered underlying in the given pool.
Based on the above call, we know:
the index of the coin we are swapping out of is
2
the index of the coin we are swapping into is
1
the coins are considered underlying, so we must call
exchange_underlying
From this information we can perform a token swap:
Balances and Rates
Factory.get_balances
(pool: address) β uint256[2]: view
Get available balances for each coin within a pool.
These values are not necessarily the same as calling Token.balanceOf(pool)
as the total balance also includes unclaimed admin fees.
Factory.get_underlying_balances
(pool: address) β uint256[8]: view
Get balances for each underlying coin within a pool.
Factory.get_admin_balances
(pool: address) β uint256[2]: view
Get the current admin balances (uncollected fees) for a pool.
Factory.get_rates
(pool: address) β uint256[2]: view
Get the exchange rates between coins and underlying coins within a pool, normalized to a 1e18
precision.
Last updated