Curve DAO 백서

Curve DAO

원문

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

S_DELAY self.transfer_ownership_deadline = _deadline self.future_owner = _owner log CommitNewAdmin(_deadline, _owner) ``` **▶Example▼** ```shell >>> pool.commit_transfer_ownership() todo: console output ``` note The ownership can not be transferred before `transfer_ownership_deadline`, which is the timestamp of the current block delayed by `ADMIN_ACTIONS_DELAY`. <a id="stableswapapply_transfer_ownership"></a> ### `StableSwap.apply_transfer_ownership` Stableswap.apply\_transfer\_ownership() Transfers ownership of the pool from current owner to the owner previously set via `commit_transfer_ownership`. Emits: NewAdmin **<>Source code▼** ```vyper @external def apply_transfer_ownership(): assert msg.sender == self.owner # dev: only owner assert block.timestamp >= self.transfer_ownership_deadline # dev: insufficient time assert self.transfer_ownership_deadline != 0 # dev: no active transfer self.transfer_ownership_deadline = 0 _owner: address = self.future_owner self.owner = _owner log NewAdmin(_owner) ``` **▶Example▼** ```shell >>> pool.apply_transfer_ownership() todo: log output ``` warning Pool ownership can only be transferred once. <a id="stableswaprevert_transfer_ownership"></a> ### `StableSwap.revert_transfer_ownership()` `StableSwap.revert_transfer_ownership()` Reverts any previously committed transfer of ownership. This method resets the `transfer_ownership_deadline` to `0`. **<>Source code▼** ```vyper @external def revert_transfer_ownership(): assert msg.sender == self.owner # dev: only owner self.transfer_ownership_deadline = 0 ``` **▶Example▼** ```shell >>> pool.revert_transfer_ownership() todo: log output ``` <a id="amplification-coefficient-admin-controls"></a> ## Amplification Coefficient Admin Controls The amplification coefficient `A` determines a pool’s tolerance for imbalance between the assets within it. A higher value means that trades will incur slippage sooner as the assets within the pool become imbalanced. note Within the pools, `A` is in fact implemented as `1 / A` and therefore a higher value implies that the pool will be more tolerant to slippage when imbalanced. The appropriate value for A 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 amplification coefficient 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="stableswapramp_a"></a> ### `StableSwap.ramp_A` `StableSwap.ramp_A(_future_A: uint256, _future_time: uint256)` Ramp `A` up or down by setting a new `A` to take effect at a future point in time. | Input | Type | Description | | --- | --- | --- | | `_future_A` | `uint256` | New future value of `A` | | `_future_time` | `uint256` | Timestamp at which new `A` should take effect | Emits: RampA **<>Source code▼** ```vyper MIN_RAMP_TIME: constant(uint256) = 86400 MAX_A_CHANGE: constant(uint256) = 10 MAX_A: constant(uint256) = 10 **6 ... @external def ramp_A(_future_A: uint256, _future_time: uint256): assert msg.sender == self.owner # dev: only owner assert block.timestamp >= self.initial_A_time + MIN_RAMP_TIME assert _future_time >= block.timestamp + MIN_RAMP_TIME # dev: insufficient time _initial_A: uint256 = self._A() _future_A_p: uint256 = _future_A * A_PRECISION assert _future_A > 0 and _future_A < MAX_A if _future_A_p < _initial_A: assert _future_A_p * MAX_A_CHANGE >= _initial_A else: assert _future_A_p <= _initial_A * MAX_A_CHANGE self.initial_A = _initial_A self.future_A = _future_A_p self.initial_A_time = block.timestamp self.future_A_time = _future_time log RampA(_initial_A, _future_A_p, block.timestamp, _future_time) ``` **▶Example▼** ```shell >>> pool.ramp_A() todo: log output ``` <a id="stableswapstop_ramp_a"></a> ### `StableSwap.stop_ramp_A` Stableswap.stop\_ramp\_A() Stop ramping `A` up or down and sets `A` to current `A`. Emits: StopRampA **<>Source code▼** ```vyper @external def stop_ramp_A(): assert msg.sender == self.owner # dev: only owner current_A: uint256 = self._A() self.initial_A = current_A self.future_A = current_A self.initial_A_time = block.timestamp self.future_A_time = block.timestamp # now (block.timestamp < t1) is always False, so we return saved A log StopRampA(current_A, block.timestamp) ``` **▶Example▼** ```shell >>> pool.stop_ramp_A() todo: log output ``` <a id="swap-fees-admin-controls"></a> ## Swap Fees Admin Controls todo: hyperlink to fee collection and distribution Curve pools charge fees on token swaps, where the fee may differ between pools. An admin fee is charged on the pool fee. For an overview of how fees are distributed, please refer to Fee Collection and Distribution. <a id="stableswapcommit_new_fee"></a> ### `StableSwap.commit_new_fee` `StableSwap.commit_new_fee(_new_fee: uint256, _new_admin_fee: uint256)` The method commits new fee params: these fees do not take immediate effect. | Input | Type | Description | | --- | --- | --- | | `_new_fee` | `uint256` | New pool fee | | `_new_admin_fee` | `uint256` | New admin fee (expressed as a percentage of the pool fee) | Emits: CommitNewFee **<>Source code▼** ```vyper MAX_ADMIN_FEE: constant(uint256) = 10 * 10 **9 MAX_FEE: constant(uint256) = 5 * 10 **9 ADMIN_ACTIONS_DELAY: constant(uint256) = 3 * 86400 @external def commit_new_fee(new_fee: uint256, new_admin_fee: uint256): assert msg.sender == self.owner # dev: only owner assert self.admin_actions_deadline == 0 # dev: active action assert new_fee <= MAX_FEE # dev: fee exceeds maximum assert new_admin_fee <= MAX_ADMIN_FEE # dev: admin fee exceeds maximum _deadline: uint256 = block.timestamp + ADMIN_ACTIONS_DELAY self.admin_actions_deadline = _deadline self.future_fee = new_fee self.future_admin_fee = new_admin_fee log CommitNewFee(_deadline, new_fee, new_admin_fee) ``` **▶Example▼** ```shell >>> pool.commit_new_fee() todo: log output ``` note Both the pool `fee` and the `admin_fee` are capped by the constants `MAX_FEE` and `MAX_ADMIN_FEE`, respectively. By default `MAX_FEE` is set at 50% and `MAX_ADMIN_FEE` at 100% (which is charged on the `MAX_FEE` amount). <a id="stableswapapply_new_fee"></a> ### `StableSwap.apply_new_fee` Stableswap.apply\_new\_fee() Apply the previously committed new pool and admin fees for the pool. Emits: NewFee **<>Source code▼** ```vyper @external def apply_new_fee(): assert msg.sender == self.owner # 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 _fee: uint256 = self.future_fee _admin_fee: uint256 = self.future_admin_fee self.fee = _fee self.admin_fee = _admin_fee log NewFee(_fee, _admin_fee) ``` **▶Example▼** ```shell >>> pool.commit_new_fee() todo: log output ``` note Unlike ownership transfers, pool and admin fees may be set more than once. <a id="stableswaprevert_new_parameters"></a> ### `StableSwap.revert_new_parameters` `StableSwap.revert_new_parameters()` Resets any previously committed new fees. **<>Source code▼** ```vyper @external def revert_new_parameters(): assert msg.sender == self.owner # dev: only owner self.admin_actions_deadline = 0 ``` **▶Example▼** ```shell >>> pool.revert_new_parameters() todo: log output ``` <a id="stableswapadmin_balances"></a> ### `StableSwap.admin_balances` `StableSwap.admin_balances(i: uint256) → uint256` Get the admin balance for a single coin in the pool. | Input | Type | Description | | --- | --- | --- | | `i` | `uint256` | Index of the coin to get admin balance for | **<>Source code▼** ```vyper @view @external def admin_balances(i: uint256) -> uint256: return ERC20(self.coins[i]).balanceOf(self) - self.balances[i] ``` **▶Example▼** ```shell >>> pool.admin_balances() todo: log output ``` <a id="stableswapwithdraw_admin_fees"></a> ### `StableSwap.withdraw_admin_fees` `StableSwap.withdraw_admin_fees()` Withdraws and transfers admin fees of the pool to the pool owner. ```vyper @external def withdraw_admin_fees(): assert msg.sender == self.owner # dev: only owner for i in range(N_COINS): c: address = self.coins[i] value: uint256 = ERC20(c).balanceOf(self) - self.balances[i] if value > 0: assert ERC20(c).transfer(msg.sender, value) ``` **▶Example▼** ```shell >>> pool.withdraw_admin_fees() todo: log output ``` <a id="stableswapdonate_admin_fees"></a> ### `StableSwap.donate_admin_fees` `StableSwap.donate_admin_fees()` Donate all admin fees to the pool’s liquidity providers. **<>Source code▼** ```vyper @external def donate_admin_fees(): assert msg.sender == self.owner # dev: only owner for i in range(N_COINS): self.balances[i] = ERC20(self.coins[i]).balanceOf(self) ``` **▶Example▼** ```shell >>> pool.donate_admin_fees() todo: log output ``` note Older Curve pools do not implement this method. <a id="kill-a-pool"></a> ## Kill a Pool <a id="stableswapkill_me"></a> ### `StableSwap.kill_me` `StableSwap.kill_me()` Pause a pool by setting the `is_killed` boolean flag to `True`. This disables the following pool functionality: - add\_liquidity - exchange - remove\_liquidity\_imbalance - remove\_liquidity\_one\_coin It is only possible for existing LPs to remove liquidity via `remove_liquidity` from a paused pool. **<>Source code▼** ```vyper @external @nonreentrant('lock') def add_liquidity(amounts: uint256[N_COINS], min_mint_amount: uint256) -> uint256: """ @notice Deposit coins into the pool @param amounts List of amounts of coins to deposit @param min_mint_amount Minimum amount of LP tokens to mint from the deposit @return Amount of LP tokens received by depositing """ assert not self.is_killed # dev: is killed ... @external @nonreentrant('lock') def exchange(i: int128, j: int128, dx: uint256, min_dy: uint256) -> uint256: """ @notice Perform an exchange between two coins @dev Index values can be found via the `coins` public getter method @param i Index value for the coin to send @param j Index valie of the coin to recieve @param dx Amount of `i` being exchanged @param min_dy Minimum amount of `j` to receive @return Actual amount of `j` received """ assert not self.is_killed # dev: is killed ... @external @nonreentrant('lock') def remove_liquidity_imbalance(amounts: uint256[N_COINS], max_burn_amount: uint256) -> uint256: """ @notice Withdraw coins from the pool in an imbalanced amount @param amounts List of amounts of underlying coins to withdraw @param max_burn_amount Maximum amount of LP token to burn in the withdrawal @return Actual amount of the LP token burned in the withdrawal """ assert not self.is_killed # dev: is killed ... @external @nonreentrant('lock') def remove_liquidity_one_coin(_token_amount: uint256, i: int128, _min_amount: uint256) -> uint256: """ @notice Withdraw a single coin from the pool @param _token_amount Amount of LP tokens to burn in the withdrawal @param i Index value of the coin to withdraw @param _min_amount Minimum amount of coin to receive @return Amount of coin received """ assert not self.is_killed # dev: is killed ... @external def kill_me(): assert msg.sender == self.owner # dev: only owner assert self.kill_deadline > block.timestamp # dev: deadline has passed self.is_killed = True ``` **▶Example▼** ```shell todo: add example ``` note Pools can only be killed within the first 30 days after deployment. <a id="stableswapunkill_me"></a> ### `StableSwap.unkill_me` Stableswap.unkill\_me Unpause a pool that was previously paused, re-enabling exchanges. **<>Source code▼** ```vyper @external def unkill_me(): assert msg.sender == self.owner # dev: only owner self.is_killed = False ``` **▶Example▼** ```shell todo: add example ``` --- # lending-pools Source: [https://docs.curve.finance/developer/amm/legacy/stableswap/pools/lending-pools](https://docs.curve.finance/developer/amm/legacy/stableswap/pools/lending-pools) <a id="overview"></a> ## Overview Curve pools may contain lending functionality, whereby the underlying tokens are lent out on other protocols (e.g., Compound or Yearn). Hence, the main difference to a plain pool is that a lending pool does not hold the underlying token itself, but a **wrapped**representation of it. Currently, Curve supports the following lending pools: `aave`: [Aave pool](https://www.curve.fi/aave), with lending on [Aave](https://www.aave.com/) `busd`: [BUSD](https://www.curve.fi/busd) pool, with lending on [yearn.finance](https://yearn.fi/) `compound`: [Compound](https://www.curve.fi/compound) pool, with lending on [Compound](https://compound.finance/) `ib`: [Iron Bank pool](https://curve.fi/ib), with lending on [Cream](https://yearn.fi/) `pax`: [PAX](https://curve.fi/pax) pool, with lending on [yearn.finance](https://yearn.fi/) `usdt`: [USDT pool](https://curve.fi/usdt), with lending on [Compound](https://www.curve.fi/compound) `y`: [Y pool](https://curve.fi/y), with lending on [yearn.finance](https://yearn.fi/) An example of a Curve lending pool is [Compound Pool](https://github.com/curvefi/curve-contract/tree/master/contracts/pools/compound), which contains the wrapped tokens `cDAI` and `cUSDC`, while the underlying tokens `DAI` and `USDC` are lent out on Compound. Liquidity providers of the Compound Pool therefore receive interest generated on Compound in addition to fees from token swaps in the pool. Implementation of lending pools may differ with respect to how wrapped tokens accrue interest. There are two main types of wrapped tokens that are used by lending pools: `cToken-style tokens`: These are tokens, such as interest-bearing cTokens on Compound (e.g., `cDAI`) or on yTokens on Yearn, where interest accrues as the rate of the token increases. `aToken-style tokens`: These are tokens, such as aTokens on AAVE (e.g., `aDAI`), where interest accrues as the balance of the token increases. The template source code for lending pools may be viewed on GitHub. Lending pools also implement the ABI from plain pools. Refer to the plan pools documentation for overlapping methods. <a id="pool-info-methods"></a> ## Pool Info Methods <a id="underlying_coins"></a> ### `underlying_coins` `StableSwap.underlying_coins(i: uint256) → address: view` Getter for the array of underlying coins within the pool. | Input | Type | Description | | --- | --- | --- | | `i` | `uint128` | Index of coin to swap from | **<>Source code▼** ```vyper underlying_coins: public(address[N_COINS]) ... @external def __init__( _owner: address, _coins: address[N_COINS], _underlying_coins: address[N_COINS], _pool_token: address, _A: uint256, _fee: uint256, _admin_fee: uint256 ): """ @notice Contract constructor @param _owner Contract owner address @param _coins Addresses of ERC20 contracts of wrapped coins @param _underlying_coins Addresses of ERC20 contracts of underlying coins @param _pool_token Address of the token representing LP share @param _A Amplification coefficient multiplied by n * (n - 1) @param _fee Fee to charge for exchanges @param _admin_fee Admin fee """ for i in range(N_COINS): assert _coins[i] != ZERO_ADDRESS assert _underlying_coins[i] != ZERO_ADDRESS # approve underlying coins for infinite transfers _response: Bytes[32] = raw_call( _underlying_coins[i], concat( method_id("approve(address,uint256)"), convert(_coins[i], bytes32), convert(MAX_UINT256, bytes32), ), max_outsize=32, ) if len(_response) > 0: assert convert(_response, bool) self.coins = _coins self.underlying_coins = _underlying_coins self.initial_A = _A * A_PRECISION self.future_A = _A * A_PRECISION self.fee = _fee self.admin_fee = _admin_fee self.owner = _owner self.kill_deadline = block.timestamp + KILL_DEADLINE_DT self.lp_token = _pool_token ``` **▶Example▼** ```shell >>> lending_pool.coins(0) '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643' >>> lending_pool.coins(1) '0x39AA39c021dfbaE8faC545936693aC917d5E7563' ``` <a id="exchange-methods"></a> ## Exchange Methods Like plain pools, lending pools have the `exchange` method. However, in the case of lending pools, calling `exchange` performs a swap between two wrapped tokens in the pool. For example, calling `exchange` on the Compound Pool, would result in a swap between the wrapped tokens `cDAI` and `cUSDC`. <a id="exchange_underlying"></a> ### `exchange_underlying` `StableSwap.exchange_underlying(i: int128, j: int128, dx: uint256, min_dy: uint256) → uint256` Perform an exchange between two underlying tokens. Index values can be found via the `underlying_coins` public getter method. Returns the actual amount of coin `j` received. | Input | Type | Description | | --- | --- | --- | | `i` | `int128` | Index value for the underlying coin to send | | `j` | `int128` | Index value of the underlying coin to receive | | `_dx` | `uint256` | Amount of `i` being exchanged | | `_min_dy` | `uint256` | Minimum amount of `j` to receive | Emits: TokenExchangeUnderlying **<>Source code▼** ```vyper @external @nonreentrant('lock') def exchange_underlying(i: int128, j: int128, dx: uint256, min_dy: uint256) -> uint256: """ @notice Perform an exchange between two underlying coins @dev Index values can be found via the `underlying_coins` public getter method @param i Index value for the underlying coin to send @param j Index valie of the underlying coin to recieve @param dx Amount of `i` being exchanged @param min_dy Minimum amount of `j` to receive @return Actual amount of `j` received """ dy: uint256 = self._exchange(i, j, dx) assert dy >= min_dy, "Exchange resulted in fewer coins than expected" u_coin_i: address = self.underlying_coins[i] lending_pool: address = self.aave_lending_pool # transfer underlying coin from msg.sender to self _response: Bytes[32] = raw_call( u_coin_i, concat( method_id("transferFrom(address,address,uint256)"), convert(msg.sender, bytes32), convert(self, bytes32), convert(dx, bytes32) ), max_outsize=32 ) if len(_response) != 0: assert convert(_response, bool) # deposit to aave lending pool raw_call( lending_pool, concat( method_id("deposit(address,uint256,address,uint16)"), convert(u_coin_i, bytes32), convert(dx, bytes32), convert(self, bytes32), convert(self.aave_referral, bytes32), ) ) # withdraw `j` underlying from lending pool and transfer to caller LendingPool(lending_pool).withdraw(self.underlying_coins[j], dy, msg.sender) log TokenExchangeUnderlying(msg.sender, i, dx, j, dy) return dy ``` **▶Example▼** ```shell >>> lending_pool.exchange_underlying() todo: console output ``` note Older Curve lending pools may not implement the same signature for `exchange_underlying`. For instance, Compound pool does not return anything for `exchange_underlying` and therefore costs more in terms of gas. <a id="addremove-liquidity-methods"></a> ## Add/Remove Liquidity Methods The function signatures for adding and removing liquidity to a lending pool are mostly the same as for a plain pool. However, for lending pools, liquidity is added and removed in the wrapped token, not the underlying. In order to be able to add and remove liquidity in the underlying token (e.g., remove DAI from Compound Pool instead of `cDAI`) there exists a `Deposit<POOL>.vy` contract (e.g., ([DepositCompound.vy](https://github.com/curvefi/curve-contract/blob/master/contracts/pools/compound/DepositCompound.vy)). warning Older Curve lending pools (e.g., Compound Pool) do not implement all plain pool methods for adding and removing liquidity. For instance, `remove_liquidity_one_coin` is not implemented by Compound Pool). Some newer pools (e.g., [IB](https://github.com/curvefi/curve-contract/blob/master/contracts/pools/ib/StableSwapIB.vy)) have a modified signature for `add_liquidity` and allow the caller to specify whether the deposite
프로젝트로 돌아가기