Curve DAO 백서

Curve DAO

원문

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

ry symbol Other parameters need some description @return Address of the deployed pool """ # 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 > MIN_FEE-1 assert mid_fee < MAX_FEE-1 assert out_fee >= mid_fee assert out_fee < MAX_FEE-1 assert admin_fee < 10**18+1 assert allowed_extra_profit < 10**16+1 assert fee_gamma < 10**18+1 assert fee_gamma > 0 assert adjustment_step < 10**18+1 assert adjustment_step > 0 assert ma_half_time < 7 * 86400 assert ma_half_time > 0 assert initial_price > 10**6 assert initial_price < 10**30 assert _coins[0] != _coins[1], "Duplicate coins" decimals: uint256[2] = empty(uint256[2]) for i in range(2): d: uint256 = ERC20(_coins[i]).decimals() assert d < 19, "Max 18 decimals for coins" decimals[i] = d precisions: uint256 = (18 - decimals[0]) + shift(18 - decimals[1], 8) name: String[64] = concat("Curve.fi Factory Crypto Pool: ", _name) symbol: String[32] = concat(_symbol, "-f") token: address = create_forwarder_to(self.token_implementation) pool: address = create_forwarder_to(self.pool_implementation) Token(token).initialize(name, symbol, pool) CryptoPool(pool).initialize( A, gamma, mid_fee, out_fee, allowed_extra_profit, fee_gamma, adjustment_step, admin_fee, ma_half_time, initial_price, token, _coins, precisions) length: uint256 = self.pool_count self.pool_list[length] = pool self.pool_count = length + 1 self.pool_data[pool].token = token self.pool_data[pool].decimals = shift(decimals[0], 8) + decimals[1] self.pool_data[pool].coins = _coins key: uint256 = bitwise_xor(convert(_coins[0], uint256), convert(_coins[1], uint256)) length = self.market_counts[key] self.markets[key][length] = pool self.market_counts[key] = length + 1 log CryptoPoolDeployed( token, _coins, A, gamma, mid_fee, out_fee, allowed_extra_profit, fee_gamma, adjustment_step, admin_fee, ma_half_time, initial_price, msg.sender) return pool ``` **▶Example▼** ```shell >>> CryptoFactory.deploy_pool( _name: crv/weth crypto pool, _symbol: crv/eth, _coins: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xD533a949740bb3306d119CC777fa900bA034cd52", A: 20000000, gamma: 10000000000000000, mid_fee: 3000000, out_fee: 45000000, allowed_extra_profit: 10000000000, fee_gamma: 300000000000000000, adjustment_step: 5500000000000, admin_fee: 5000000000, ma_half_time: 600, initial_price: 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` Function to deploy a liquidity gauge for a factory pool. The deployed gauge is created from the `gauge_implementation`. Emits: `LiquidityGaugeDeployed` | Input | Type | Description | | --- | --- | --- | | `_pool` | `address` | Factory pool address to deploy a gauge for | **<>Source code▼** ```vyper event LiquidityGaugeDeployed: pool: address token: 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] != ZERO_ADDRESS, "Unknown pool" assert self.pool_data[_pool].liquidity_gauge == ZERO_ADDRESS, "Gauge already deployed" gauge: address = create_forwarder_to(self.gauge_implementation) token: address = self.pool_data[_pool].token LiquidityGauge(gauge).initialize(token) self.pool_data[_pool].liquidity_gauge = gauge log LiquidityGaugeDeployed(_pool, token, gauge) return gauge ``` **▶Example▼** ```shell Factory.deploy_gauge('0x...') 'returns address of the deployed gauge' ``` --- # implementations Source: [https://docs.curve.finance/developer/amm/legacy/factory/cryptoswap/implementations](https://docs.curve.finance/developer/amm/legacy/factory/cryptoswap/implementations) **The CryptoSwap Factory makes use of the `create_forwarder_to` function to deploy its contracts from the implementations.**:::warning \*\*Implementation contracts are upgradable.\*\*They can either be replaced, or additional implementation contracts can be added. Therefore, please always make sure to check the most recent ones. ::: It utilizes three different implementations: - **`pool_implementation`**, containing a contract that is used to deploy the pools. - **`token_implementation`**, containing a contract that is used to deploy LP tokens. - **`gauge_implementation`**, containing a blueprint contract that is used when deploying gauges for pools. <a id="query-implementations"></a> ## Query Implementations <a id="pool_implementations"></a> ### `pool_implementations` `Factory.pool_implementations() -> address: view` Getter for the pool implementation contract. Returns: pool implementation (`address`). **<>Source code▼** ```vyper pool_implementation: public(address) ``` **▶Example▼** ```shell >>> Factory.pool_implementations() '0xa85461AFc2DEEC01bDA23b5cd267d51F765fba10' ``` <a id="token_implementation"></a> ### `token_implementation` `Factory.token_implementation() -> address: view` Getter for the token implementation contract. Returns: token implementation (`address`). **<>Source code▼** ```vyper token_implementation: public(address) ``` **▶Example▼** ```shell >>> Factory.token_implementation() '0xc08550A4cc5333f40e593eCc4C4724808085D304' ``` <a id="gauge_implementation"></a> ### `gauge_implementation` `Factory.gauge_implementation() -> address: view` Getter for the gauge implementation contract. Returns: gauge implementation (`address`). **<>Source code▼** ```vyper gauge_implementation: public(address) ``` **▶Example▼** ```shell >>> Factory.gauge_implementation() '0xdc892358d55d5Ae1Ec47a531130D62151EBA36E5' ``` <a id="set-new-implementation"></a> ## Set New Implementation *New implementations can be set via these admin-only functions:* <a id="set_pool_implementation"></a> ### `set_pool_implementation` `Factory.set_pool_implementation(_pool_implementation: address):` Guarded Method This function is only callable by the `admin` of the contract. Function to set a new pool implementation contract. Emits event: `UpdatePoolImplementation` | Input | Type | Description | | --- | --- | --- | | `_pool_implementation` | `address` | New pool implementation | **<>Source code▼** ```vyper event UpdatePoolImplementation: _old_pool_implementation: address _new_pool_implementation: address pool_implementation: public(address) @external def set_pool_implementation(_pool_implementation: address): """ @notice Set pool implementation @dev Set to ZERO_ADDRESS to prevent deployment of new pools @param _pool_implementation Address of the new pool implementation """ assert msg.sender == self.admin # dev: admin only log UpdatePoolImplementation(self.pool_implementation, _pool_implementation) self.pool_implementation = _pool_implementation ``` **▶Example▼** ```shell >>> Factory.set_pool_implementation("todo") 'todo' ``` <a id="set_token_implementation"></a> ### `set_token_implementation` `Factory.set_token_implementation(_token_implementation: address):` Guarded Method This function is only callable by the `admin` of the contract. Function to set a new token implementation contract. Emits event: `UpdateTokenImplementation` | Input | Type | Description | | --- | --- | --- | | `_token_implementation` | `address` | New token implementation | **<>Source code▼** ```vyper event UpdateTokenImplementation: _old_token_implementation: address _new_token_implementation: address token_implementation: public(address) @external def set_token_implementation(_token_implementation: address): """ @notice Set token implementation @dev Set to ZERO_ADDRESS to prevent deployment of new pools @param _token_implementation Address of the new token implementation """ assert msg.sender == self.admin # dev: admin only log UpdateTokenImplementation(self.token_implementation, _token_implementation) self.token_implementation = _token_implementation ``` **▶Example▼** ```shell >>> Factory.set_token_implementation("todo") 'todo' ``` <a id="set_gauge_implementation"></a> ### `set_gauge_implementation` `Factory.set_fee_receiver(_fee_receiver: address):` Guarded Method This function is only callable by the `admin` of the contract. Function to set a new gauge implementation contract. Emits event: `UpdateGaugeImplementation` | Input | Type | Description | | --- | --- | --- | | `_gauge_implementation` | `address` | New gauge implementation | **<>Source code▼** ```vyper event UpdateGaugeImplementation: _old_gauge_implementation: address _new_gauge_implementation: address gauge_implementation: public(address) @external def set_gauge_implementation(_gauge_implementation: address): """ @notice Set gauge implementation @dev Set to ZERO_ADDRESS to prevent deployment of new gauges @param _gauge_implementation Address of the new token implementation """ assert msg.sender == self.admin # dev: admin-only function log UpdateGaugeImplementation(self.gauge_implementation, _gauge_implementation) self.gauge_implementation = _gauge_implementation ``` **▶Example▼** ```shell >>> Factory.set_gauge_implementation("todo") 'todo' ``` --- # overview Source: [https://docs.curve.finance/developer/amm/legacy/factory/cryptoswap/overview](https://docs.curve.finance/developer/amm/legacy/factory/cryptoswap/overview) The [CryptoSwap](https://docs.curve.finance/developer/amm/stableswap-ng/overview.md) Factory allows the permissionless deployment of two-coin volatile asset pools, LP tokens, and liquidity gauges. **Liquidity pool and LP token share the same contract.**:::deploy\[Contract Source & Deployment\] **CryptoSwap Factory**contract is deployed to the Ethereum mainnet at: [0xf18056bbd320e96a48e3fbf8bc061322531aac99](https://etherscan.io/address/0xf18056bbd320e96a48e3fbf8bc061322531aac99#code). A list of all deployed contracts can be found [here](https://docs.curve.finance/developer/deployments.md). ::: <a id="implementations"></a> ## Implementations More on [implementations](https://docs.curve.finance/developer/amm/legacy/factory/cryptoswap/implementations.md). --- # deployer-api Source: [https://docs.curve.finance/developer/amm/legacy/factory/stableswap/deployer-api](https://docs.curve.finance/developer/amm/legacy/factory/stableswap/deployer-api) <a id="liquidity-poolswarning"></a> ## Liquidity Pools:::warning Transaction will fail if the requirements are not met. ::: <a id="deploy_plain_pool"></a> ### `deploy_plain_pool` The pool **deployment is permissionless**, but it must adhere to certain parameter limitations: | Parameter | Limitation | | --- | --- | | `_fee` | 4000000 (0.04%) ≤ `_fee` ≤ 100000000 (1%) | - Valid **`_implementation_idx`**(cannot be **`ZERO_ADDRESS`**). - Minimum of 2 coins and maximum of 4 coins. - Cannot pair with a coin which is included in a basepool. - If paired against plain ETH (0xE...EeE), ETH must be the first coin of the pool (**`_coins[0] = plain ETH`**). - Maximum of 18 decimals for the coins. - No duplicate coins. `Factory.deploy_plain_pool(_name: String[32], _symbol: String[10], _coins: address[4], _A: uint256, _fee: uint256, _asset_type: uint256 = 0, _implementation_idx: uint256 = 0) → address: nonpayable` Function to deploy a plain pool. Returns: Deployed pool (`address`). Emits: `PlainPoolDeployed` | Input | Type | Description | | --- | --- | --- | | `_name` | `String[32]` | Name of the new plain pool | | `_symbol` | `String[10]` | Symbol for the new pool’s LP token. This value will be concatenated with the factory symbol | | `_coins` | `address[4]` | List of addresses of the coins being used in the pool | | `_A` | `uint256` | Amplification coefficient | | `_fee` | `uint256` | Trade fee, given as an integer with `1e10` precision | | `_asset_type` | `uint256` | Asset type of the pool as an integer. 0 = `USD`, 1 = `ETH`, 2 = `BTC`, 3 = Other | | `_implementation_idx` | `uint256` | Index of the implementation to use. All possible implementations for a pool of N\_COINS can be publicly accessed via `plain_implementations(N_COINS)` | **<>Source code▼** ```vyper event PlainPoolDeployed: coins: address[MAX_PLAIN_COINS] A: uint256 fee: uint256 deployer: address MAX_PLAIN_COINS: constant(int128) = 4 # max coins in a plain pool @external def deploy_plain_pool( _name: String[32], _symbol: String[10], _coins: address[MAX_PLAIN_COINS], _A: uint256, _fee: uint256, _asset_type: uint256 = 0, _implementation_idx: uint256 = 0, ) -> address: """ @notice Deploy a new plain pool @param _name Name of the new plain pool @param _symbol Symbol for the new plain pool - will be concatenated with factory symbol @param _coins List of addresses of the coins being used in the pool. @param _A Amplification co-efficient - a lower 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 minimum fee is 0.04% (4000000), the maximum is 1% (100000000). 50% of the fee is distributed to veCRV holders. @param _asset_type Asset type for pool, as an integer 0 = USD, 1 = ETH, 2 = BTC, 3 = Other @param _implementation_idx Index of the implementation to use. All possible implementations for a pool of N_COINS can be publicly accessed via `plain_implementations(N_COINS)` @return Address of the deployed pool """ # fee must be between 0.04% and 1% assert _fee >= 4000000 and _fee <= 100000000, "Invalid fee" n_coins: uint256 = MAX_PLAIN_COINS rate_multipliers: uint256[MAX_PLAIN_COINS] = empty(uint256[MAX_PLAIN_COINS]) decimals: uint256[MAX_PLAIN_COINS] = empty(uint256[MAX_PLAIN_COINS]) for i in range(MAX_PLAIN_COINS): coin: address = _coins[i] if coin == ZERO_ADDRESS: assert i > 1, "Insufficient coins" n_coins = i break assert self.base_pool_assets[coin] == False, "Invalid asset, deploy a metapool" if _coins[i] == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE: assert i == 0, "ETH must be first coin" decimals[0] = 18 else: decimals[i] = ERC20(coin).decimals() assert decimals[i] < 19, "Max 18 decimals for coins" rate_multipliers[i] = 10 **(36 - decimals[i]) for x in range(i, i+MAX_PLAIN_COINS): if x+1 == MAX_PLAIN_COINS: break if _coins[x+1] == ZERO_ADDRESS: break assert coin != _coins[x+1], "Duplicate coins" implementation: address = self.plain_implementations[n_coins][_implementation_idx] assert implementation != ZERO_ADDRESS, "Invalid implementation index" pool: address = create_forwarder_to(implementation) CurvePlainPool(pool).initialize(_name, _symbol, _coins, rate_multipliers, _A, _fee) 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 = ZERO_ADDRESS self.pool_data[pool].implementation = implementation if _asset_type != 0: self.pool_data[pool].asset_type = _asset_type for i in range(MAX_PLAIN_COINS): coin: address = _coins[i] if coin == ZERO_ADDRESS: break self.pool_data[pool].coins[i] = coin raw_call( coin, concat( method_id("approve(address,uint256)"), convert(pool, bytes32), convert(MAX_UINT256, bytes32) ) ) for j in range(MAX_PLAIN_COINS): if i < j: swappable_coin: address = _coins[j] key: uint256 = bitwise_xor(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( _name: "alUSD-crvUSD", _symbol: "alcrvUSD", _coins: ['0xbc6da0fe9ad5f3b0d58160288917aa56653660e9', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'], _A: 200, _fee: 4000000, _asset_type: 0, _implementation_idx: 0, ) 'returns address of deployed pool' ``` <a id="deploy_metapool"></a> ### `deploy_metapool` Limitations when deploying meta pools: | Parameter | Limitation | | --- | --- | | `_fee` | 4000000 (0.04%) ≤ `_fee` ≤ 100000000 (0.1%) | - Valid **`_implementation_idx`**(cannot be **`ZERO_ADDRESS`**). - Maximum of 18 decimals for the coins. `Factory.deploy_metapool(_base_pool: address, _name: String[32], _symbol: String[10], _coin: address, _A: uint256, _fee: uint256, _implementation_idx: uint256 = 0) -> address:` Function to deploy a metapool. Returns: Deployed metapool (`address`). Emits: `MetaPoolDeployed` | 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. This value 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 | | `_implementation_idx` | `uint256` | Index of the implementation to use. All possible implementations for a pool of N\_COINS can be publicly accessed via `plain_implementations(N_COINS)` | **<>Source code▼** ```vyper event MetaPoolDeployed: coin: address base_pool: address A: uint256 fee: uint256 deployer: address @external def deploy_metapool( _base_pool: address, _name: String[32], _symbol: String[10], _coin: address, _A: uint256, _fee: uint256, _implementation_idx: uint256 = 0, ) -> 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 minimum fee is 0.04% (4000000), the maximum is 1% (100000000). 50% of the fee is distributed to veCRV holders. @param _implementation_idx Index of the implementation to use. All possible implementations for a BASE_POOL can be publicly accessed via `metapool_implementations(BASE_POOL)` @return Address of the deployed pool """ # fee must be between 0.04% and 1% assert _fee >= 4000000 and _fee <= 100000000, "Invalid fee" implementation: address = self.base_pool_data[_base_pool].implementations[_implementation_idx] assert implementation != ZERO_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" pool: address = create_forwarder_to(implementation) CurvePool(pool).initialize(_name, _symbol, _coin, 10 **(36 - decimals), _A, _fee) ERC20(_coin).approve(pool, MAX_UINT256) # 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, 0, 0, 0] self.pool_data[pool].n_coins = 2 self.pool_data[pool].base_pool = _base_pool self.pool_data[pool].coins[0] = _coin self.pool_data[pool].coins[1] = self.base_pool_data[_base_pool].lp_token self.pool_data[pool].implementation = implementation is_finished: bool = False for i in rang
프로젝트로 돌아가기