Curve DAO 백서

Curve DAO

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 5쪽

od_ids: DynArray[bytes4, MAX_COINS] _oracles, # _oracles: DynArray[address, MAX_COINS] code_offset=3 ) length: uint256 = self.pool_count self.pool_list[length] = pool self.pool_count = length + 1 self.pool_data[pool].decimals = decimals self.pool_data[pool].n_coins = n_coins self.pool_data[pool].base_pool = empty(address) self.pool_data[pool].implementation = implementation self.pool_data[pool].asset_types = _asset_types for i in range(MAX_COINS): if i == n_coins: break coin: address = _coins[i] self.pool_data[pool].coins.append(coin) for j in range(i, i + MAX_COINS): if (j + 1) == n_coins: break swappable_coin: address = _coins[j + 1] key: uint256 = (convert(coin, uint256) ^ convert(swappable_coin, uint256)) length = self.market_counts[key] self.markets[key][length] = pool self.market_counts[key] = length + 1 log PlainPoolDeployed(_coins, _A, _fee, msg.sender) return pool ``` **▶Example▼** ```shell >>> Factory.deploy_plain_pool( "crvusd/USDT", # _name "crvusd-usdt", # _symbol [ # coins: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E", # crvusd "0xdAC17F958D2ee523a2206206994597C13D831ec7" # usdt ], 1500 # _A 1000000, # _fee 20000000000, # _offpeg_fee_multiplier 865, # _ma_exp_time 0, # _implementation_idx [0, 0], # _asset_types [b"", b""], # _method_ids ["0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000"] # _oracles ) 'returns address of the deployed plain pool' ``` <a id="deploy_metapool"></a> ### `deploy_metapool` *Parameter limitations when deploying a meta pool:* - Cannot pair against a token that is included in the base pool. - `_fee` ≤ 100000000 (1%). - `_offpeg_fee_multiplier` \* `_fee` ≤ `MAX_FEE` \* `FEE_DENOMINATOR`. - Valid implementation index. - Maximum of 18 decimals for a coin. `Factory.deploy_metapool(_base_pool: address, _name: String[32], _symbol: String[10], _coin: address, _A: uint256, _fee: uint256, _offpeg_fee_multiplier: uint256, _ma_exp_time: uint256, _implementation_idx: uint256, _asset_type: uint8, _method_id: bytes4, _oracle: address) -> address:` Function to deploy a stableswap-ng metapool. | Input | Type | Description | | --- | --- | --- | | `_base_pool` | `address` | Address of the base pool to pair the token with | | `_name` | `String[32]` | Name of the new metapool | | `_symbol` | `String[10]` | Symbol for the new metapool's LP token - will be concatenated with the base pool symbol | | `_coin` | `address` | Address of the coin being used in the metapool | | `_A` | `uint256` | Amplification coefficient | | `_fee` | `uint256` | Trade fee, given as an integer with `1e10` precision | | `_offpeg_fee_multiplier` | `uint256` | Off-peg multiplier | | `_ma_exp_time` | `uint256` | MA time; set as time\_in\_seconds / ln(2) | | `_implementation_idx` | `uint256` | Index of the implementation to use | | `_asset_type` | `uint8` | Asset type of the pool as an integer; more [here](https://docs.curve.finance/developer/amm/stableswap-ng/overview.md#supported-assets) | | `_method_id` | `bytes4` | First four bytes of the Keccak-256 hash of the function signatures of the oracle addresses that give rate oracles | | `_oracle` | `address` | Rate oracle address | Returns: Deployed metapool (`address`). Emits: `MetaPoolDeployed` Implementation ID There might be multiple metapool implementations. To query all available ones, see [above](https://docs.curve.finance/developer/amm/factory/stableswap-ng/overview.md#query-implementations). As of the current date (31.10.2023), there is only one metapool implementation available. Since the \*\*`_implementation_idx`\*\*starts at 0, users need to input "0" when deploying a pool. **<>Source code▼** ```vyper event MetaPoolDeployed: coin: address base_pool: address A: uint256 fee: uint256 deployer: address MAX_COINS: constant(uint256) = 8 MAX_FEE: constant(uint256) = 5 * 10 **9 FEE_DENOMINATOR: constant(uint256) = 10 **10 @external def deploy_metapool( _base_pool: address, _name: String[32], _symbol: String[10], _coin: address, _A: uint256, _fee: uint256, _offpeg_fee_multiplier: uint256, _ma_exp_time: uint256, _implementation_idx: uint256, _asset_type: uint8, _method_id: bytes4, _oracle: address, ) -> address: """ @notice Deploy a new metapool @param _base_pool Address of the base pool to use within the metapool @param _name Name of the new metapool @param _symbol Symbol for the new metapool - will be concatenated with the base pool symbol @param _coin Address of the coin being used in the metapool @param _A Amplification co-efficient - a higher value here means less tolerance for imbalance within the pool's assets. Suggested values include: * Uncollateralized algorithmic stablecoins: 5-10 * Non-redeemable, collateralized assets: 100 * Redeemable assets: 200-400 @param _fee Trade fee, given as an integer with 1e10 precision. The the maximum is 1% (100000000). 50% of the fee is distributed to veCRV holders. @param _ma_exp_time Averaging window of oracle. Set as time_in_seconds / ln(2) Example: for 10 minute EMA, _ma_exp_time is 600 / ln(2) ~= 866 @param _implementation_idx Index of the implementation to use @param _asset_type Asset type for token, as an integer @param _method_id First four bytes of the Keccak-256 hash of the function signatures of the oracle addresses that gives rate oracles. Calculated as: keccak(text=event_signature.replace(" ", ""))[:4] @param _oracle Rate oracle address. @return Address of the deployed pool """ assert not self.base_pool_assets[_coin], "Invalid asset: Cannot pair base pool asset with base pool's LP token" assert _fee <= 100000000, "Invalid fee" assert _offpeg_fee_multiplier * _fee <= MAX_FEE * FEE_DENOMINATOR base_pool_n_coins: uint256 = len(self.base_pool_data[_base_pool].coins) assert base_pool_n_coins != 0, "Base pool is not added" implementation: address = self.metapool_implementations[_implementation_idx] assert implementation != empty(address), "Invalid implementation index" # things break if a token has >18 decimals decimals: uint256 = ERC20(_coin).decimals() assert decimals < 19, "Max 18 decimals for coins" # combine _coins's _asset_type and basepool coins _asset_types: base_pool_asset_types: DynArray[uint8, MAX_COINS] = self.base_pool_data[_base_pool].asset_types asset_types: DynArray[uint8, MAX_COINS] = [_asset_type, 0] for i in range(0, MAX_COINS): if i == base_pool_n_coins: break asset_types.append(base_pool_asset_types[i]) _coins: DynArray[address, MAX_COINS] = [_coin, self.base_pool_data[_base_pool].lp_token] _rate_multipliers: DynArray[uint256, MAX_COINS] = [10 **(36 - decimals), 10 **18] _method_ids: DynArray[bytes4, MAX_COINS] = [_method_id, empty(bytes4)] _oracles: DynArray[address, MAX_COINS] = [_oracle, empty(address)] pool: address = create_from_blueprint( implementation, _name, # _name: String[32] _symbol, # _symbol: String[10] _A, # _A: uint256 _fee, # _fee: uint256 _offpeg_fee_multiplier, # _offpeg_fee_multiplier: uint256 _ma_exp_time, # _ma_exp_time: uint256 self.math_implementation, # _math_implementation: address _base_pool, # _base_pool: address _coins, # _coins: DynArray[address, MAX_COINS] self.base_pool_data[_base_pool].coins, # base_coins: DynArray[address, MAX_COINS] _rate_multipliers, # _rate_multipliers: DynArray[uint256, MAX_COINS] asset_types, # asset_types: DynArray[uint8, MAX_COINS] _method_ids, # _method_ids: DynArray[bytes4, MAX_COINS] _oracles, # _oracles: DynArray[address, MAX_COINS] code_offset=3 ) # add pool to pool_list length: uint256 = self.pool_count self.pool_list[length] = pool self.pool_count = length + 1 base_lp_token: address = self.base_pool_data[_base_pool].lp_token self.pool_data[pool].decimals = [decimals, 18, 0, 0, 0, 0, 0, 0] self.pool_data[pool].n_coins = 2 self.pool_data[pool].base_pool = _base_pool self.pool_data[pool].coins = [_coin, self.base_pool_data[_base_pool].lp_token] self.pool_data[pool].implementation = implementation is_finished: bool = False swappable_coin: address = empty(address) for i in range(MAX_COINS): if i < len(self.base_pool_data[_base_pool].coins): swappable_coin = self.base_pool_data[_base_pool].coins[i] else: is_finished = True swappable_coin = base_lp_token key: uint256 = (convert(_coin, uint256) ^ convert(swappable_coin, uint256)) length = self.market_counts[key] self.markets[key][length] = pool self.market_counts[key] = length + 1 if is_finished: break log MetaPoolDeployed(_coin, _base_pool, _A, _fee, msg.sender) return pool ``` **▶Example▼** ```shell >>> Factory.deploy_metapool( "0xbebc44782c7db0a1a60cb6fe97d0b483032ff1c7", # _base_pool "crvusd/3CRV", # _name "crvusd-3crv" # _symbol "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E", # _coin 1500 # _A 1000000, # _fee 20000000000, # _offpeg_fee_multiplier 865, # _ma_exp_time 0, # _implementation_idx 0, # _asset_type "b""", # _method_id "0x0000000000000000000000000000000000000000" # _oracle ) 'returns address of the deployed metapool' ``` * * * <a id="deploying-liquidity-gauges"></a> ## Deploying Liquidity Gauges Liquidity gauges for pools can also be deployed from this contract, but deploying gauges through a factory contract is only possible using the same factory contract that was used for deploying the pool. This feature is only available on the Ethereum mainnet, as liquidity gauges on sidechains need to be deployed through the [RootChainGaugeFactory](https://docs.curve.finance/developer/gauges/xchain-gauges/root-gauge-factory.md). <a id="deploy_gauge"></a> ### `deploy_gauge` `Factory.deploy_gauge(_pool: address) -> address:` Function to deploy a gauge. The Factory utilizes the `gauge_implementation` to create the contract from a blueprint. | Input | Type | Description | | --- | --- | --- | | `_pool` | `address` | Pool address to deploy the gauge for | Returns: deployed gauge (`address`). Emits: `LiquidityGaugeDeployed` **<>Source code▼** ```vyper event LiquidityGaugeDeployed: pool: address gauge: address @external def deploy_gauge(_pool: address) -> address: """ @notice Deploy a liquidity gauge for a factory pool @param _pool Factory pool address to deploy a gauge for @return Address of the deployed gauge """ assert self.pool_data[_pool].coins[0] != empty(address), "Unknown pool" assert self.pool_data[_pool].liquidity_gauge == empty(address), "Gauge already deployed" implementation: address = self.gauge_implementation assert implementation != empty(address), "Gauge implementation not set" gauge: address = create_from_blueprint(self.gauge_implementation, _pool, code_offset=3) self.pool_data[_pool].liquidity_gauge = gauge log LiquidityGaugeDeployed(_pool, gauge) return gauge ``` **▶Example▼** ```shell >>> Factory.deploy_gauge("0x36DfE783603522566C046Ba1Fa403C8c6F569220") 'returns address of the deployed gauge' ``` <a id="footnote-label"></a> ## Footnotes 1. The `gauge_implementation` is only relevant on Ethereum mainnet. Liquidity gauges on sidechains need to be deployed through the `RootChainGaugeFactory`. [↩](https://docs.curve.finance/developer/amm/factory/stableswap-ng/overview.md#user-content-fnref-1) 2. This only works for `pool_implementations` and `metapool_implementations`. For other the implementations, only a single contract can be set. [↩](https://docs.curve.finance/developer/amm/factory/stableswap-ng/overview.md#user-content-fnref-2) 3. This only works for `pool_implementations` and `metapool_implementations`. For other the implementations, only a single contract can be set. [↩](https://docs.curve.finance/developer/amm/factory/stableswap-ng/overview.md#user-content-fnref-3) --- # deployer-api Source: [https://docs.curve.finance/developer/amm/factory/tricrypto-ng/deployer-api](https://docs.curve.finance/developer/amm/factory/tricrypto-ng/deployer-api) <a id="liquidity-poolswarning"></a> ## Liquidity Pools:::warning The transaction will revert if the following requirements are not met. ::: <a id="deploy_pool"></a> ### `deploy_pool` The pool **deployment is permissionless**, but it must adhere to certain parameter limitations: | Parameter | Limitation | | --- | --- | | `A` | A\_min - 1 < A < A\_max + 1 | | `gamma` | gamma\_min - 1 < gamma < gamma\_max + 1 | | `mid_fee` | mid\_fee < fee\_max - 1; (mid\_fee can be 0) | | `out_fee` | out\_fee >= mid\_fee AND out\_fee < fee\_max - 1 | | `fee_gamma` | 0 < fee\_gamma < 10^18 + 1 | | `allowed_extra_profit` | allowed\_extra\_profit < 10^18 + 1 | | `adjustment_step` | 0 < adjustment\_step < 10^18 + 1 | | `ma_exp_time` | 86 < ma\_exp\_time < 872542 | | `initial_prices` | 10^6 < initial\_prices\[0\] and initial\_prices\[1\] < 10^30 | - Three coins; no duplicate coins possible. - \*\*`implementation_id`\*\*cannot be **`ZERO_ADDRESS`**. *With:* | Parameters | Value | | --- | --- | | n\_coins | 3 | | A\_multiplier | 10000 | | A\_min | n\_coins^n\_coins \* A\_multiplier = 270000 | | A\_max | 1000 \* A\_multiplier \* n\_coins^n\_coins = 270000000 | | gamma\_min | 10^10 = 10000000000 | | gamma\_max | 5 \* 10^16 = 50000000000000000 | | fee\_max | 10 \* 10^9 = 10000000000 | `Factory.deploy_pool(_name: String[64], _symbol: String[32], _coins: address[N_COINS], _weth: address, implementation_id: uint256, A: uint256, gamma: uint256, mid_fee: uint256, out_fee: uint256, fee_gamma: uint256, allowed_extra_profit: uint256, adjustment_step: uint256, ma_exp_time: uint256, initial_prices: uint256[N_COINS-1],) -> address:` Function to deploy a tricrypto pool. Returns: Deployed pool (`address`). Emits event: `TricryptoPoolDeployed` | Input | Type | Description | | --- | --- | --- | | `_name` | `String[64]` | Pool Name | | `_symbol` | `String[32]` | Pool Symbol | | `_coins` | `address[N_COINS]` | Included Coins | | `_weth` | `address` | WETH Address | | `implementation_id` | `uint256` | Index of Pool Implementation | | `A` | `uint256` | Amplification Factor | | `gamma` | `uint256` | Gamma | | `mid_fee` | `uint256` | Mid Fee | | `out_fee` | `uint256` | Out Fee | | `fee_gamma` | `uint256` | Fee Gamma | | `allowed_extra_profit` | `uint256` | Allowed Extra Profit | | `adjustment_step` | `uint256` | Adjustment Step | | `ma_exp_time` | `uint256` | Exponential Moving Average Time | | `initial_prices` | `uint256[N_COINS-1]` | Initial Prices | **<>Source code▼** ```vyper event TricryptoPoolDeployed: pool: address name: String[64] symbol: String[32] weth: address coins: address[N_COINS] math: address salt: bytes32 packed_precisions: uint256 packed_A_gamma: uint256 packed_fee_params: uint256 packed_rebalancing_params: uint256 packed_prices: uint256 deployer: address N_COINS: constant(uint256) = 3 A_MULTIPLIER: constant(uint256) = 10000 MAX_FEE: constant(uint256) = 10 * 10 **9 MIN_GAMMA: constant(uint256) = 10 **10 MAX_GAMMA: constant(uint256) = 5 * 10**16 MIN_A: constant(uint256) = N_COINS **N_COINS * A_MULTIPLIER / 100 MAX_A: constant(uint256) = 1000 * A_MULTIPLIER * N_COINS**N_COINS PRICE_SIZE: constant(uint128) = 256 / (N_COINS - 1) PRICE_MASK: constant(uint256) = 2**PRICE_SIZE - 1 @external def deploy_pool( _name: String[64], _symbol: String[32], _coins: address[N_COINS], _weth: address, implementation_id: uint256, A: uint256, gamma: uint256, mid_fee: uint256, out_fee: uint256, fee_gamma: uint256, allowed_extra_profit: uint256, adjustment_step: uint256, ma_exp_time: uint256, initial_prices: uint256[N_COINS-1], ) -> address: """ @notice Deploy a new pool @param _name Name of the new plain pool @param _symbol Symbol for the new plain pool - will be concatenated with factory symbol @return Address of the deployed pool """ pool_implementation: address = self.pool_implementations[implementation_id] assert pool_implementation != empty(address), "Pool implementation not set" # Validate parameters assert A > MIN_A-1 assert A < MAX_A+1 assert gamma > MIN_GAMMA-1 assert gamma < MAX_GAMMA+1 assert mid_fee < MAX_FEE-1 # mid_fee can be zero assert out_fee >= mid_fee assert out_fee < MAX_FEE-1 assert fee_gamma < 10**18+1 assert fee_gamma > 0 assert allowed_extra_profit < 10**18+1 assert adjustment_step < 10**18+1 assert adjustment_step > 0 assert ma_exp_time < 872542 # 7 * 24 * 60 * 60 / ln(2) assert ma_exp_time > 86 # 60 / ln(2) assert min(initial_prices[0], initial_prices[1]) > 10**6 assert max(initial_prices[0], initial_prices[1]) < 10**30 assert _coins[0] != _coins[1] and _coins[1] != _coins[2] and _coins[0] != _coins[2], "Duplicate coins" decimals: uint256[N_COINS] = empty(uint256[N_COINS]) precisions: uint256[N_COINS] = empty(uint256[N_COINS]) for i in range(N_COINS): d: uint256 = ERC20(_coins[i]).decimals() assert d < 19, "Max 18 decimals for coins" decimals[i] = d precisions[i] = 10**(18 - d) # pack precisions packed_precisions: uint256 = self._pack(precisions) # pack fees packed_fee_params: uint256 = self._pack( [mid_fee, out_fee, fee_gamma] ) # pack liquidity rebalancing params packed_rebalancing_params: uint256 = self._pack( [allowed_extra_profit, adjustment_step, ma_exp_time] ) # pack A_gamma packed_A_gamma: uint256 = A << 128 packed_A_gamma = packed_A_gamma | gamma # pack initial prices packed_prices: uint256 = 0 for k in range(N_COINS - 1): packed_prices = packed_prices << PRICE_SIZE p: uint256 = initial_prices[N_COINS - 2 - k] assert p < PRICE_MASK packed_prices = p | packed_prices # pool is an ERC20 implementation _salt: bytes32 = block.prevhash _math_implementation: address = self.math_implementation pool: address = create_from_blueprint( pool_implementation, _name, _symbol, _coins, _math_implementation, _weth, _salt, packed_precisions, packed_A_gamma, packed_fee_params, packed_rebalancing_params, packed_prices, code_offset=3 ) # populate pool data length: uint256 = self.pool_count self.pool_list[length] = pool self.pool_count = length + 1 self.pool_data[pool].decimals = decimals self.pool_data[pool].coins = _coins # add coins to market: self._add_coins_to_market(_coins[0], _coins[1], pool) self._add_coins_to_market(_coins[0], _coins[2], pool) self._add_coins_to_market(_coins[1], _coins[2], pool) log TricryptoPoolDeployed( pool, _name, _symbol, _weth, _coins, _math_implementation, _salt, packed_precisions, packed_A_gamma, packed_fee_params, packed_rebalancing_params, packed_prices, msg.sender, ) return pool ``` **▶Example▼** ```shell >>> TricryptoFactory.deploy_pool( _name: crv/weth/tbtc tripool, _symbol: crv-weth-tbtc, _coins: '0xD533a949740bb3306d119CC777fa900bA034cd52', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0x8dAEBADE922dF735c38C80C7eBD708Af50815fAa', _weth: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', implementation_id: 0, A: 2700000, gamma: 1300000000000, mid_fee: 2999999, out_fee: 80000000, fee_gamma: 350000000000000, allowed_extra_profit: 100000000000, adjustment_step: 100000000000, ma_exp_time: 600, initial_prices: todo, ) 'returns address of the deployed pool' ``` <a id="liquidity-gaugeinfo"></a> ## Liquidity Gauge:::info Liquidity gauges can only be successfully deployed from the same contract from which the pool was deployed! ::: <a id="deploy_gauge"></a> ### `deploy_gauge` `deploy_gauge(_pool: address) -> address` Deploy a liquidity gauge for a factory pool. The deployed gauge implementation is based on what the factory admin has set for `gauge_implementation`. | Input | Type | Description | | --- | --- | --- | | `_pool` | `address` | Pool address to deploy a gauge for | **<>Source code▼** ```vyper @external def deploy_gauge(_pool: address) -> address: """ @notice Deploy a liquidity gauge for a factory pool @param _pool Factory pool address to deploy a gauge for @return Address of the deployed gauge """ assert self.pool_data[_pool].coins[0] != ZERO_ADDRESS, "Unknown pool" assert self.pool_data[_pool].liquidity_gauge == ZERO_ADDRESS, "Gauge already deployed" implementation: address
프로젝트로 돌아가기