Curve DAO 백서

Curve DAO

원문

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

alue` | `uint256` | Amount ot increase the allowance by | **<>Source code▼** ```vyper event Approval: _owner: indexed(address) _spender: indexed(address) _value: uint256 allowance: public(HashMap[address, HashMap[address, uint256]]) @external def increaseAllowance(_spender: address, _added_value: uint256) -> bool: """ @notice Increase the allowance granted to `_spender` by the caller @dev This is alternative to {approve} that can be used as a mitigation for the potential race condition @param _spender The address which will transfer the funds @param _added_value The amount of to increase the allowance @return bool success """ allowance: uint256 = self.allowance[msg.sender][_spender] + _added_value self.allowance[msg.sender][_spender] = allowance log Approval(msg.sender, _spender, allowance) return True ``` **▶Example▼** ```shell >>> LPTokenV5.increaseAllowance("todo") "todo" ``` <a id="decreaseallowance"></a> ### `decreaseAllowance` `LPTokenV5.decreaseAllowance(_spender: address, _subtracted_value: uint256) -> bool:` Function to decrease the allowance granted to `_spender`. Returns: True or False (`bool`). | Input | Type | Description | | --- | --- | --- | | `_spender` | `address` | Address to decrease the allowance of | | `_subtracted_value` | `uint256` | Amount ot decrease the allowance by | **<>Source code▼** ```vyper event Approval: _owner: indexed(address) _spender: indexed(address) _value: uint256 allowance: public(HashMap[address, HashMap[address, uint256]]) @external def decreaseAllowance(_spender: address, _subtracted_value: uint256) -> bool: """ @notice Decrease the allowance granted to `_spender` by the caller @dev This is alternative to {approve} that can be used as a mitigation for the potential race condition @param _spender The address which will transfer the funds @param _subtracted_value The amount of to decrease the allowance @return bool success """ allowance: uint256 = self.allowance[msg.sender][_spender] - _subtracted_value self.allowance[msg.sender][_spender] = allowance log Approval(msg.sender, _spender, allowance) return True ``` **▶Example▼** ```shell >>> LPTokenV5.allowance("todo") "todo" ``` <a id="minting-and-burning"></a> ## Minting and Burning LP Tokens are minted when users deposit funds into the liquidity pool. Upon calling the `add_liquidity` function on the pool, it triggers the `mint` function of the LP Token to mint the corresponding tokens. When liquidity is withdrawn using `remove_liquidity`, the LP tokens are burned through the `burnFrom` method. The logic for both minting and burning the tokens resides in the pool contract. <a id="mint"></a> ### `mint` `LPTokenV5.mint(_to: address, _value: uint256) -> bool:` Guarded Method This function is only callable by the `minter` of the contract, which is the liquidity pool. Function to mint `_value` LP Tokens and transfer them to `_to`. Returns: True (`bool`). Emits: `Transfer` | Input | Type | Description | | --- | --- | --- | | `_spender` | `address` | Address to decrease the allowance of | | `_subtracted_value` | `uint256` | Amount ot decrease the allowance by | **<>Source code▼** ```vyper event Transfer: _from: indexed(address) _to: indexed(address) _value: uint256 @external def mint(_to: address, _value: uint256) -> bool: """ @dev Mint an amount of the token and assigns it to an account. This encapsulates the modification of balances such that the proper events are emitted. @param _to The account that will receive the created tokens. @param _value The amount that will be created. """ assert msg.sender == self.minter self.totalSupply += _value self.balanceOf[_to] += _value log Transfer(ZERO_ADDRESS, _to, _value) return True ``` **▶Example▼** ```shell >>> LPTokenV5.mint("todo") "todo" ``` <a id="burnfrom"></a> ### `burnFrom` `LPTokenV5.burnFrom(_to: address, _value: uint256) -> bool:` Function to burn `_value` LP Tokens from `_to` and transfer them to `ZERO_ADDRESS`. Returns: True (`bool`). Emits: `Transfer` | Input | Type | Description | | --- | --- | --- | | `_spender` | `address` | Address to decrease the allowance of | | `_subtracted_value` | `uint256` | Amount ot decrease the allowance by | **<>Source code▼** ```vyper event Transfer: _from: indexed(address) _to: indexed(address) _value: uint256 @external def burnFrom(_to: address, _value: uint256) -> bool: """ @dev Burn an amount of the token from a given account. @param _to The account whose tokens will be burned. @param _value The amount that will be burned. """ assert msg.sender == self.minter self.totalSupply -= _value self.balanceOf[_to] -= _value log Transfer(_to, ZERO_ADDRESS, _value) return True ``` **▶Example▼** ```shell >>> LPTokenV5.burnFrom("todo") "todo" ``` <a id="initialize-method"></a> ## Initialize Method <a id="initialize"></a> ### `initialize` `LPTokenV5.initialize(_name: String[64], _symbol: String[32], _pool: address):` Function to initialize the LP Token and setting name (`_name`), symbol (`_symbol`) and the corresponding liquidity pool (`_pool`). This function triggers a transfer event, enabling block explorers to recognize the contract as an ERC20. Emits: `Transfer` | Input | Type | Description | | --- | --- | --- | | `_name` | `String[64]` | name of the lp token | | `_symbol` | `String[32]` | symbol of the lp token | | `_pool` | `address` | liquidity pool address | **<>Source code▼** ```vyper event Transfer: _from: indexed(address) _to: indexed(address) _value: uint256 @external def initialize(_name: String[64], _symbol: String[32], _pool: address): assert self.minter == ZERO_ADDRESS # dev: check that we call it from factory self.name = _name self.symbol = _symbol self.minter = _pool self.DOMAIN_SEPARATOR = keccak256( _abi_encode(EIP712_TYPEHASH, keccak256(_name), keccak256(VERSION), chain.id, self) ) # fire a transfer event so block explorers identify the contract as an ERC20 log Transfer(ZERO_ADDRESS, msg.sender, 0) ``` **▶Example▼** ```shell >>> LPTokenV5.initialize("todo") ``` --- # overview Source: [https://docs.curve.finance/developer/amm/legacy/cryptoswap/lp-tokens/overview](https://docs.curve.finance/developer/amm/legacy/cryptoswap/lp-tokens/overview) In exchange for depositing coins into a Curve pool, liquidity providers receive pool LP (liquidity pool) tokens. A Curve pool LP token is an ERC20 contract specific to the Curve pool. Hence, LP tokens are transferrable. Holders of pool LP tokens may deposit and stake the token into a pool’s liquidity gauge in order to receive CRV token rewards. info There might be some variations of LP Tokens, but the two listed above are the most recent implementations. For older Curve pools the token attribute \*\*`version`\*\*is not always public and a getter has not been explicitly implemented. --- # Source: [https://docs.curve.finance/developer/amm/legacy/cryptoswap/pools/admin-controls](https://docs.curve.finance/developer/amm/legacy/cryptoswap/pools/admin-controls) \*\*The following functions are admin-only functions.\*\*Pools created through the Factory are 'owned' by the factory **`admin`**(DAO). Ownership can be transferred only within the Factory contract, and this is done through the use of the \*\*`commit_transfer_ownership()`\*\*and \*\*`accept_transfer_ownership()`\*\*functions. <a id="parameter-controls"></a> ## Parameter Controls More informations about the parameters [here](https://docs.curve.finance/developer/amm/legacy/cryptoswap-overview.md). The appropriate value for `A` and `gamma` is dependent upon the type of coin being used within the pool, and is subject to optimisation and pool-parameter update based on the market history of the trading pair. It is possible to modify the parameters for a pool after it has been deployed. However, it requires a vote within the Curve DAO and must reach a 15% quorum. <a id="ramp_a_gamma"></a> ### `ramp_A_gamma` `CryptoSwap.ramp_A_gamma(future_A: uint256, future_gamma: uint256, future_time: uint256):` Guarded Method This function is only callable by the `admin` of the factory contract. Function to ramp A and gamma parameter values linearly. Emits: `RampAgamma` | Input | Type | Description | | --- | --- | --- | | `future_A` | `uint256` | future A value | | `future_gamma` | `uint256` | future gamma value | | `future_time` | `uint256` | timestamp at which the parameters are fully ramped | **<>Source code▼** ```vyper event RampAgamma: initial_A: uint256 future_A: uint256 initial_gamma: uint256 future_gamma: uint256 initial_time: uint256 future_time: uint256 @external def ramp_A_gamma(future_A: uint256, future_gamma: uint256, future_time: uint256): assert msg.sender == Factory(self.factory).admin() # dev: only owner assert block.timestamp > self.initial_A_gamma_time + (MIN_RAMP_TIME-1) assert future_time > block.timestamp + (MIN_RAMP_TIME-1) # dev: insufficient time A_gamma: uint256[2] = self._A_gamma() initial_A_gamma: uint256 = shift(A_gamma[0], 128) initial_A_gamma = bitwise_or(initial_A_gamma, A_gamma[1]) assert future_A > MIN_A-1 assert future_A < MAX_A+1 assert future_gamma > MIN_GAMMA-1 assert future_gamma < MAX_GAMMA+1 ratio: uint256 = 10**18 * future_A / A_gamma[0] assert ratio < 10**18 * MAX_A_CHANGE + 1 assert ratio > 10**18 / MAX_A_CHANGE - 1 ratio = 10**18 * future_gamma / A_gamma[1] assert ratio < 10**18 * MAX_A_CHANGE + 1 assert ratio > 10**18 / MAX_A_CHANGE - 1 self.initial_A_gamma = initial_A_gamma self.initial_A_gamma_time = block.timestamp future_A_gamma: uint256 = shift(future_A, 128) future_A_gamma = bitwise_or(future_A_gamma, future_gamma) self.future_A_gamma_time = future_time self.future_A_gamma = future_A_gamma log RampAgamma(A_gamma[0], future_A, A_gamma[1], future_gamma, block.timestamp, future_time) ``` **▶Example▼** ```shell >>> CryptoSwap.ramp_A_gamma(2700000, 1300000000000, 1693674492) ``` <a id="stop_ramp_a_gamma"></a> ### `stop_ramp_A_gamma` `CryptoSwap.stop_ramp_A_gamma():` Guarded Method This function is only callable by the `admin` of the factory contract. Function to immediately stop ramping A and gamma parameters and set them to the current value. Emits: `StopRampA` **<>Source code▼** ```vyper event StopRampA: current_A: uint256 current_gamma: uint256 time: uint256 @external def stop_ramp_A_gamma(): assert msg.sender == Factory(self.factory).admin() # dev: only owner A_gamma: uint256[2] = self._A_gamma() current_A_gamma: uint256 = shift(A_gamma[0], 128) current_A_gamma = bitwise_or(current_A_gamma, A_gamma[1]) self.initial_A_gamma = current_A_gamma self.future_A_gamma = current_A_gamma self.initial_A_gamma_time = block.timestamp self.future_A_gamma_time = block.timestamp # now (block.timestamp < t1) is always False, so we return saved A log StopRampA(A_gamma[0], A_gamma[1], block.timestamp) ``` **▶Example▼** ```shell >>> CryptoSwap.stop_ramp_A_gamma() ``` <a id="commit_new_parameters"></a> ### `commit_new_parameters` `CryptoSwap.commit_new_parameters(_new_mid_fee: uint256, _new_out_fee: uint256, _new_fee_gamma: uint256, _new_allowed_extra_profit: uint256, _new_adjustment_step: uint256, _new_ma_time: uint256):` Guarded Method This function is only callable by the `admin` of the factory contract. Function to commit new parameters. The new parameters do not take immedaite effect, they need to be applied first. Emits: `CommitNewParameters` | Input | Type | Description | | --- | --- | --- | | `_new_mid_fee` | `uint256` | new mid fee value | | `_new_out_fee` | `uint256` | new out fee value | | `_new_admin_fee` | `uint256` | new admin fee value | | `_new_fee_gamma` | `uint256` | new fee-gamma value | | `_new_allowed_extra_profit` | `uint256` | new allowed\_extra\_profit value | | `_new_adjustment_step` | `uint256` | new adjustment\_step value | | `_new_ma_time` | `uint256` | new ma\_time value | **<>Source code▼** ```vyper event CommitNewParameters: deadline: indexed(uint256) admin_fee: uint256 mid_fee: uint256 out_fee: uint256 fee_gamma: uint256 allowed_extra_profit: uint256 adjustment_step: uint256 ma_half_time: uint256 @external def commit_new_parameters( _new_mid_fee: uint256, _new_out_fee: uint256, _new_admin_fee: uint256, _new_fee_gamma: uint256, _new_allowed_extra_profit: uint256, _new_adjustment_step: uint256, _new_ma_half_time: uint256, ): assert msg.sender == Factory(self.factory).admin() # dev: only owner assert self.admin_actions_deadline == 0 # dev: active action new_mid_fee: uint256 = _new_mid_fee new_out_fee: uint256 = _new_out_fee new_admin_fee: uint256 = _new_admin_fee new_fee_gamma: uint256 = _new_fee_gamma new_allowed_extra_profit: uint256 = _new_allowed_extra_profit new_adjustment_step: uint256 = _new_adjustment_step new_ma_half_time: uint256 = _new_ma_half_time # Fees if new_out_fee < MAX_FEE+1: assert new_out_fee > MIN_FEE-1 # dev: fee is out of range else: new_out_fee = self.out_fee if new_mid_fee > MAX_FEE: new_mid_fee = self.mid_fee assert new_mid_fee <= new_out_fee # dev: mid-fee is too high if new_admin_fee > MAX_ADMIN_FEE: new_admin_fee = self.admin_fee # AMM parameters if new_fee_gamma < 10**18: assert new_fee_gamma > 0 # dev: fee_gamma out of range [1 .. 10**18] else: new_fee_gamma = self.fee_gamma if new_allowed_extra_profit > 10**18: new_allowed_extra_profit = self.allowed_extra_profit if new_adjustment_step > 10**18: new_adjustment_step = self.adjustment_step # MA if new_ma_half_time < 7*86400: assert new_ma_half_time > 0 # dev: MA time should be longer than 1 second else: new_ma_half_time = self.ma_half_time _deadline: uint256 = block.timestamp + ADMIN_ACTIONS_DELAY self.admin_actions_deadline = _deadline self.future_admin_fee = new_admin_fee self.future_mid_fee = new_mid_fee self.future_out_fee = new_out_fee self.future_fee_gamma = new_fee_gamma self.future_allowed_extra_profit = new_allowed_extra_profit self.future_adjustment_step = new_adjustment_step self.future_ma_half_time = new_ma_half_time log CommitNewParameters(_deadline, new_admin_fee, new_mid_fee, new_out_fee, new_fee_gamma, new_allowed_extra_profit, new_adjustment_step, new_ma_half_time) ``` **▶Example▼** ```shell >>> CryptoSwap.commit_new_parameters(20000000, 45000000, 50000000, 350000000000000, 100000000000, 100000000000, 1800) ``` <a id="apply_new_parameters"></a> ### `apply_new_parameters` `CryptoSwap.apply_new_parameters()` Guarded Method This function is only callable by the `admin` of the factory contract. Function to apply the parameters from [`commit_new_parameters`](https://docs.curve.finance/developer/amm/legacy/cryptoswap/pools/admin-controls.md#commit_new_parameters). Emits: `NewParameters` **<>Source code▼** ```vyper event NewParameters: admin_fee: uint256 mid_fee: uint256 out_fee: uint256 fee_gamma: uint256 allowed_extra_profit: uint256 adjustment_step: uint256 ma_half_time: uint256 @external @nonreentrant('lock') def apply_new_parameters(): assert msg.sender == Factory(self.factory).admin() # dev: only owner assert block.timestamp >= self.admin_actions_deadline # dev: insufficient time assert self.admin_actions_deadline != 0 # dev: no active action self.admin_actions_deadline = 0 admin_fee: uint256 = self.future_admin_fee if self.admin_fee != admin_fee: self._claim_admin_fees() self.admin_fee = admin_fee mid_fee: uint256 = self.future_mid_fee self.mid_fee = mid_fee out_fee: uint256 = self.future_out_fee self.out_fee = out_fee fee_gamma: uint256 = self.future_fee_gamma self.fee_gamma = fee_gamma allowed_extra_profit: uint256 = self.future_allowed_extra_profit self.allowed_extra_profit = allowed_extra_profit adjustment_step: uint256 = self.future_adjustment_step self.adjustment_step = adjustment_step ma_half_time: uint256 = self.future_ma_half_time self.ma_half_time = ma_half_time log NewParameters(admin_fee, mid_fee, out_fee, fee_gamma, allowed_extra_profit, adjustment_step, ma_half_time) ``` **▶Example▼** ```shell >>> CryptoSwap.apply_new_parameters() ``` <a id="revert_new_parameters"></a> ### `revert_new_parameters` `CryptoSwap.revert_new_parameters() -> address: view` Guarded Method This function is only callable by the `admin` of the factory contract. Function to revert the parameters changes. **<>Source code▼** ```vyper @external def revert_new_parameters(): assert msg.sender == Factory(self.factory).admin() # dev: only owner self.admin_actions_deadline = 0 ``` **▶Example▼** ```shell >>> CryptoSwap.revert_new_parameters() ``` <a id="admin-control-info-methods"></a> ## Admin Control Info Methods <a id="admin_actions_deadline"></a> ### `admin_actions_deadline` `CryptoSwap.admin_actions_deadline() -> uint256: view` Getter for the admin actions deadline. This is the deadline after which new parameter changes can be applied. When committing new changes, there is a three-day timespan after being able to apply them (`ADMIN_ACTIONS_DELAY`), otherwise the call will revert. Returns: timestamp (`uint256`). **<>Source code▼** ```vyper admin_actions_deadline: public(uint256) ADMIN_ACTIONS_DELAY: constant(uint256) = 3 * 86400 ``` **▶Example▼** ```shell >>> CryptoSwap.admin_actions_deadline() 0 ``` <a id="initial_a_gamma"></a> ### `initial_A_gamma` `CryptoSwap.initial_A_gamma() -> uint256:` Getter for the initial A/gamma. Returns: A/gamma (`uint256`). **<>Source code▼** ```vyper initial_A_gamma: public(uint256) ``` **▶Example▼** ```shell >>> CryptoSwap.initial_A_gamma() 581076037942835227425498917514114728328226821 ``` <a id="initial_a_gamma_time"></a> ### `initial_A_gamma_time` `CryptoSwap.initial_A_gamma_time() -> uint256:` Getter for the initial A/gamma time. Returns: A/gamma time (`uint256`). **<>Source code▼** ```vyper initial_A_gamma_time: public(uint256) ``` **▶Example▼** ```shell >>> CryptoSwap.initial_A_gamma_time() 0 ``` <a id="future_a_gamma"></a> ### `future_A_gamma` `CryptoSwap.future_A_gamma() -> uint256:` Getter for the future A/gamma. Returns: future A/gamma (`uint256`). **<>Source code▼** ```vyper future_A_gamma: public(uint256) ``` **▶Example▼** ```shell >>> CryptoSwap.future_A_gamma() 581076037942835227425498917514114728328226821 ``` <a id="future_a_gamma_time"></a> ### `future_A_gamma_time` `CryptoSwap.future_A_gamma_time() -> uint256:` Getter for the future A/gamma time. Returns: future A/gamma time (`uint256`). **<>Source code▼** ```vyper future_A_gamma_time: public(uint256) ``` **▶Example▼** ```shell >>> CryptoSwap.future_A_gamma_time() 0 ``` <a id="future_allowed_extra_profit"></a> ### `future_allowed_extra_profit` `CryptoSwap.future_allowed_extra_profit() -> uint256:` Getter for the future allowed extra profit. Returns: future allowed extra profit (`uint256`). **<>Source code▼** ```vyper future_allowed_extra_profit: public(uint256) ``` **▶Example▼** ```shell >>> CryptoSwap.future_allowed_extra_profit() 0 ``` <a id="future_adjustment_step"></a> ### `future_adjustment_step` `CryptoSwap.future_adjustment_step() -> uint256:` Getter for the future adjustment step. Returns: future adjustment step (`uint256`). **<>Source code▼** ```vyper future_adjustment_step: public(uint256) ``` **▶Example▼** ```shell >>> CryptoSwap.future_adjustment_step() 0 ``` --- # crypto-pool Source: [https://docs.curve.finance/developer/amm/legacy/cryptoswap/pools/crypto-pool](https://docs.curve.finance/developer/amm/legacy/cryptoswap/pools/crypto-pool) \*\*Crypto-Pools are exchange contracts containing two volatile (non-pegged) assets.\*\*These exchange contracts are deployed via the [CryptoSwap Factory](https://docs.curve.finance/developer/amm/legacy/factory/cryptoswap/overview.md). Unlike newer Factory contracts, which utilize blueprint contracts, the earlier versions did not have this feature at the time of their deployments. Instead, in these earlier versions, the exchange contract is created usin
프로젝트로 돌아가기