bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 45쪽
he assets within the pool become 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. This can be done via the `ramp_A` function. See [admin controls](https://docs.curve.finance/developer/amm/stableswap-ng/pools/plainpool.md#ramp_a).
When a ramping of A has been initialized, the process can be stopped by calling the function [`stop_ramp_A()`](https://docs.curve.finance/developer/amm/stableswap-ng/pools/plainpool.md#stop_ramp_a).
<a id="a"></a>
### `A`
`StableSwap.A() -> uint256:`
Getter for the amplification coefficient A.
Returns: A (`uint256`).
**<>Source code▼**
```vyper
A_PRECISION: constant(uint256) = 100
MAX_A: constant(uint256) = 10 **6
MAX_A_CHANGE: constant(uint256) = 10
initial_A: public(uint256)
future_A: public(uint256)
initial_A_time: public(uint256)
future_A_time: public(uint256)
@view
@external
def A() -> uint256:
return self._A() / A_PRECISION
@view
@internal
def _A() -> uint256:
"""
Handle ramping A up or down
"""
t1: uint256 = self.future_A_time
A1: uint256 = self.future_A
if block.timestamp < t1:
A0: uint256 = self.initial_A
t0: uint256 = self.initial_A_time
# Expressions in uint256 cannot have negative numbers, thus "if"
if A1 > A0:
return A0 + (A1 - A0) * (block.timestamp - t0) / (t1 - t0)
else:
return A0 - (A0 - A1) * (block.timestamp - t0) / (t1 - t0)
else: # when t1 == 0 or block.timestamp >= t1
return A1
```
**▶Example▼**
```shell
>>> StableSwap.A()
500
```
<a id="a_precise"></a>
### `A_precise`
`StableSwap.A_precise() -> uint256:`
Getter for the precise A value, which is not divided by `A_PRECISION` unlike `A()`.
Returns: precise A (`uint256`).
**<>Source code▼**
```vyper
A_PRECISION: constant(uint256) = 100
MAX_A: constant(uint256) = 10 **6
MAX_A_CHANGE: constant(uint256) = 10
initial_A: public(uint256)
future_A: public(uint256)
initial_A_time: public(uint256)
future_A_time: public(uint256)
@view
@external
def A_precise() -> uint256:
return self._A()
@view
@internal
def _A() -> uint256:
"""
Handle ramping A up or down
"""
t1: uint256 = self.future_A_time
A1: uint256 = self.future_A
if block.timestamp < t1:
A0: uint256 = self.initial_A
t0: uint256 = self.initial_A_time
# Expressions in uint256 cannot have negative numbers, thus "if"
if A1 > A0:
return A0 + (A1 - A0) * (block.timestamp - t0) / (t1 - t0)
else:
return A0 - (A0 - A1) * (block.timestamp - t0) / (t1 - t0)
else: # when t1 == 0 or block.timestamp >= t1
return A1
```
**▶Example▼**
```shell
>>> StableSwap.A_precise()
50000
```
<a id="initial_a"></a>
### `initial_A`
`StableSwap.initial_A() -> uint256: view`
Getter for the initial A value.
Returns: initial A (`uint256`).
**<>Source code▼**
```vyper
A_PRECISION: constant(uint256) = 100
MAX_A: constant(uint256) = 10 **6
MAX_A_CHANGE: constant(uint256) = 10
initial_A: public(uint256)
future_A: public(uint256)
initial_A_time: public(uint256)
future_A_time: public(uint256)
@external
def ramp_A(_future_A: uint256, _future_time: uint256):
assert msg.sender == factory.admin() # 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
>>> StableSwap.initial_A()
50000
```
<a id="future_a"></a>
### `future_A`
`StableSwap.future_A() -> uint256: view`
Getter for the future A value. This value is adjusted when ramping A.
Returns: future A (`uint256`).
**<>Source code▼**
```vyper
A_PRECISION: constant(uint256) = 100
MAX_A: constant(uint256) = 10 **6
MAX_A_CHANGE: constant(uint256) = 10
initial_A: public(uint256)
future_A: public(uint256)
initial_A_time: public(uint256)
future_A_time: public(uint256)
@external
def ramp_A(_future_A: uint256, _future_time: uint256):
assert msg.sender == factory.admin() # 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
>>> StableSwap.future_A()
50000
```
<a id="initial_a_time"></a>
### `initial_A_time`
`StableSwap.initial_A_time() -> uint256: view`
Getter for the initial A time. This is the timestamp when ramping A was initialized.
Returns: initial A time (`uint256`).
**<>Source code▼**
```vyper
A_PRECISION: constant(uint256) = 100
MAX_A: constant(uint256) = 10 **6
MAX_A_CHANGE: constant(uint256) = 10
initial_A: public(uint256)
future_A: public(uint256)
initial_A_time: public(uint256)
future_A_time: public(uint256)
@external
def ramp_A(_future_A: uint256, _future_time: uint256):
assert msg.sender == factory.admin() # 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
>>> StableSwap.initial_A_time()
0
```
<a id="future_a_time"></a>
### `future_A_time`
`StableSwap.future_A_time() -> uint256: view`
Getter for the future A time. This is the timestamp when ramping A should be finished.
Returns: future A time (`uint256`).
**<>Source code▼**
```vyper
A_PRECISION: constant(uint256) = 100
MAX_A: constant(uint256) = 10 **6
MAX_A_CHANGE: constant(uint256) = 10
initial_A: public(uint256)
future_A: public(uint256)
initial_A_time: public(uint256)
future_A_time: public(uint256)
@external
def ramp_A(_future_A: uint256, _future_time: uint256):
assert msg.sender == factory.admin() # 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
>>> StableSwap.future_A_time()
0
```
* * *
<a id="contract-info-methods"></a>
## Contract Info Methods
<a id="coins"></a>
### `coins`
`StableSwap.coins(arg0: uint256) -> addresss: view`
Getter for the coin at index `arg0` within the pool.
Returns: coin (`address`).
**<>Source code▼**
```vyper
coins: public(immutable(DynArray[address, MAX_COINS]))
@external
def __init__(
_name: String[32],
_symbol: String[10],
_A: uint256,
_fee: uint256,
_offpeg_fee_multiplier: uint256,
_ma_exp_time: uint256,
_coins: DynArray[address, MAX_COINS],
_rate_multipliers: DynArray[uint256, MAX_COINS],
_asset_types: DynArray[uint8, MAX_COINS],
_method_ids: DynArray[bytes4, MAX_COINS],
_oracles: DynArray[address, MAX_COINS],
):
...
coins = _coins
...
```
**▶Example▼**
```shell
>>> StableSwap.coins(0)
'0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'
>>> StableSwap.coins(1)
'0x0E573Ce2736Dd9637A0b21058352e1667925C7a8'
```
<a id="balances"></a>
### `balances`
`StableSwap.balances(i: uint256) -> uint256:`
Getter for the current balance of coin `i` within the pool.
Returns: coin balance (`uint256`).
| Input | Type | Description |
| --- | --- | --- |
| `i` | `uint256` | Index value of the coin. |
**<>Source code▼**
```vyper
@view
@external
def balances(i: uint256) -> uint256:
"""
@notice Get the current balance of a coin within the
pool, less the accrued admin fees
@param i Index value for the coin to query balance of
@return Token balance
"""
return self._balances()[i]
@view
@internal
def _balances() -> DynArray[uint256, MAX_COINS]:
"""
@notice Calculates the pool's balances _excluding_ the admin's balances.
@dev If the pool contains rebasing tokens, this method ensures LPs keep all
rebases and admin only claims swap fees. This also means that, since
admin's balances are stored in an array and not inferred from read balances,
the fees in the rebasing token that the admin collects is immune to
slashing events.
"""
result: DynArray[uint256, MAX_COINS] = empty(DynArray[uint256, MAX_COINS])
balances_i: uint256 = 0
for i in range(MAX_COINS_128):
if i == N_COINS_128:
break
if POOL_IS_REBASING_IMPLEMENTATION:
balances_i = ERC20(coins[i]).balanceOf(self) - self.admin_balances[i]
else:
balances_i = self.stored_balances[i] - self.admin_balances[i]
result.append(balances_i)
return result
```
**▶Example▼**
```shell
>>> StableSwap.balances(0)
1156160050449617680048138
>>> StableSwap.balances(1)
1052703857609
```
<a id="get_balances"></a>
### `get_balances`
`StableSwap.get_balances() -> DynArray[uint256, MAX_COINS]:`
Getter for an array with all coin balances in the pool.
Returns: coin balances (`DynArray[uint256, MAX_COINS]`).
**<>Source code▼**
```vyper
@view
@external
def get_balances() -> DynArray[uint256, MAX_COINS]:
return self._balances()
@view
@internal
def _balances() -> DynArray[uint256, MAX_COINS]:
"""
@notice Calculates the pool's balances _excluding_ the admin's balances.
@dev If the pool contains rebasing tokens, this method ensures LPs keep all
rebases and admin only claims swap fees. This also means that, since
admin's balances are stored in an array and not inferred from read balances,
the fees in the rebasing token that the admin collects is immune to
slashing events.
"""
result: DynArray[uint256, MAX_COINS] = empty(DynArray[uint256, MAX_COINS])
balances_i: uint256 = 0
for i in range(MAX_COINS_128):
if i == N_COINS_128:
break
if POOL_IS_REBASING_IMPLEMENTATION:
balances_i = ERC20(coins[i]).balanceOf(self) - self.admin_balances[i]
else:
balances_i = self.stored_balances[i] - self.admin_balances[i]
result.append(balances_i)
return result
```
**▶Example▼**
```shell
>>> StableSwap.get_balances()
[1156160050449617680048138, 1052703857609]
```
note
The returned values do not take admin fees into account.
<a id="n_coins"></a>
### `N_COINS`
`StableSwap.N_COINS() -> uint256: view`
Getter for the total number of coins in the pool.
Returns: number of coins (`uint256`).
info
There can be a maximum of 8 coins per pool due to `MAX_COINS = 8`.
**<>Source code▼**
```vyper
MAX_COINS: constant(uint256) = 8 # max coins is 8 in the factory
N_COINS: public(immutable(uint256))
@external
def __init__(
_name: String[32],
_symbol: String[10],
_A: uint256,
_fee: uint256,
_offpeg_fee_multiplier: uint256,
_ma_exp_time: uint256,
_coins: DynArray[address, MAX_COINS],
_rate_multipliers: DynArray[uint256, MAX_COINS],
_asset_types: DynArray[uint8, MAX_COINS],
_method_ids: DynArray[bytes4, MAX_COINS],
_oracles: DynArray[address, MAX_COINS],
):
...
coins = _coins
__n_coins: uint256 = len(_coins)
N_COINS = __n_coins
N_COINS_128 = convert(__n_coins, int128)
...
```
**▶Example▼**
```shell
>>> StableSwap.N_COINS()
2
```
<a id="totalsupply"></a>
### `totalSupply`
`StableSwap.totalSupply() -> uint256:`
Getter for the total supply of the LP token.
Returns: total supply (`uint256`).
**<>Source code▼**
```vyper
total_supply: uint256
@view
@external
@nonreentrant('lock')
def totalSupply() -> uint256:
"""
@notice The total supply of pool LP tokens
@return self.total_supply, 18 decimals.
"""
return self.total_supply
```
**▶Example▼**
```shell
>>> StableSwap.totalSupply()
2208717767450789394892159
```
* * *
<a id="lp-token"></a>
## LP Token
**Pool and LP tokens are the same smart contract.** The pool itself acts as an LP Token. When coins are deposited into a Curve pool, the depositor receives pool LP (liquidity provider) tokens in return. Each Curve pool has its unique ERC20 contract representing these LP tokens, making them transferable. Holding these LP tokens allows for their deposit and staking in the pool's liquidity gauge, earning CRV token rewards. Additionally, if a metapool supports the LP token, it can be deposited there to receive the metapool's distinct LP tokens.
<a id="transfer"></a>
### `transfer`
`StableSwap.transfer(_to : address, _value : uint256) -> bool:`
Function to transfer `_value` tokens to `_to`.
Returns: true (`bool`).
Emits: `Transfer`
| Input | Type | Description |
| --- | --- | --- |
| `_to` | `address` | address to transfer token to |
| `_value` | `uint256` | amount of tokens to transfer |
**<>Source code▼**
```vyper
event Transfer:
sender: indexed(address)
receiver: indexed(address)
value: uint256
@external
def transfer(_to : address, _value : uint256) -> bool:
"""
@dev Transfer token for a specified address
@param _to The address to transfer to.
@param _value The amount to be transferred.
"""
self._transfer(msg.sender, _to, _value)
return True
@internal
def _transfer(_from: address, _to: address, _value: uint256):
# # NOTE: vyper does not allow underflows
# # so the following subtraction would revert on insufficient balance
self.balanceOf[_from] -= _value
self.balanceOf[_to] += _value
log Transfer(_from, _to, _value)
```
<a id="transferfrom"></a>
### `transferFrom`
`StableSwap.transferFrom(_from : address, _to : address, _value : uint256) -> bool:`
Function to transfer `_value` tokens from `_from` to `_to`.
Returns: true (`bool`).
Emits: `Transfer`
| Input | Type | Description |
| --- | --- | --- |
| `_from` | `address` | address to transfer token from |
| `_to` | `address` | address to transfer token to |
| `_value` | `uint256` | amount of tokens to transfer |
**<>Source code▼**
```vyper
event Transfer:
sender: indexed(address)
receiver: indexed(address)
value: uint256
@external
def transferFrom(_from : address, _to : address, _value : uint256) -> bool:
"""
@dev Transfer tokens from one address to another.
@param _from address The address which you want to send tokens from
@param _to address The address which you want to transfer to
@param _value uint256 the amount of tokens to be transferred
"""
self._transfer(_from, _to, _value)
_allowance: uint256 = self.allowance[_from][msg.sender]
if _allowance != max_value(uint256):
self.allowance[_from][msg.sender] = _allowance - _value
return True
@internal
def _transfer(_from: address, _to: address, _value: uint256):
# # NOTE: vyper does not allow underflows
# # so the following subtraction would revert on insufficient balance
self.balanceOf[_from] -= _value
self.balanceOf[_to] += _value
log Transfer(_from, _to, _value)
```
<a id="allowance"></a>
### `allowance`
`StableSwap.allowance(arg0: address, arg1: address) -> uint256: view`
Getter method to check the allowance of `arg0` for funds of `arg1`.
Returns: allowed amount (`uint256`).
| Input | Type | Description |
| --- | --- | --- |
| `arg0` | `address` | Address of the spender |
| `arg1` | `address` | Address of the token owner |
**<>Source code▼**
```vyper
allowance: public(HashMap[address, HashMap[address, uint256]])
```
<a id="approve"></a>
### `approve`
`StableSwap.approve(_spender : address, _value : uint256) -> bool:`
Function to approve `_spender` to transfer `_value` of tokens on behalf of `msg.sender`
Returns: true (`bool`).
Emits: `Approval`
| Input | Type | Description |
| --- | --- | --- |
| `_spender` | `address` | Address of the approved spender |
| `_value` | `uint256` | Amount of tokens to approve |
**<>Source code▼**
```vyper
event Approval:
owner: indexed(address)
spender: indexed(address)
value: uint256
@external
def approve(_spender : address, _value : uint256) -> bool:
"""
@notice Approve the passed address to transfer the specified amount of
tokens on behalf of msg.sender
@dev Beware that changing an allowance via this method brings the risk that
someone may use both the old and new allowance by unfortunate transaction
ordering: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
@param _spender The address which will transfer the funds
@param _value The amount of tokens that may be transferred
@return bool success
"""
self.allowance[msg.sender][_spender] = _value
log Approval(msg.sender, _spender, _value)
return True
```
<a id="permit"></a>
### `permit`
`StableSwap.permit(_owner: address, _spender: address, _value: uint256, _deadline: uint256, _v: uint8, _r: bytes32, _s: bytes32) -> bool:`
Function to permit `spender` to spend up to `_value` amount of `_owner`'s tokens via a signature.
Returns: true (`bool`).
Emits: `Approval`
| Input | Type | Description |
| --- | --- | --- |
| `_owner` | `address` | Account which generated the signature and is granting an allowance |
| `_spender` | `address` | Account which will be granted an allowance |
| `_value` | `uint256` | Amount to approve |
| `_deadline` | `uint256` | Deadline by which signature must be submitted |
| `_v` | `uint8` | The last byte of the ECDSA signature |
| `_r` | `bytes32` | The first 32 bytes of the ECDSA signature |
| `_s` | `bytes32` | The second 32 bytes of the ECDSA signature |
**<>Source code▼**
```vyper
event Approval:
owner: indexed(address)
spender: indexed(address)
value: uint256
@external
def permit(
_owner: address,
_spender: address,
_value: uint256,
_deadline: uint256,
_v: uint8,
_r: bytes32,
_s: bytes32
) -> bool:
"""
@notice Approves spender by owner's signature to expend owner's tokens.
See https://eips.ethereum.org/EIPS/eip-2612.
@dev Inspired by https://github.com/yearn/yearn-vaults/blob/main/contracts/Vault.vy#L753-L793
@dev Supports smart contract wallets which implement ERC1271
https://eips.ethereum.org/EIPS/eip-1271
@param _owner The address which is a source of funds and has signed the Permit.
@param _spender The address which is allowed to spend the funds.
@param _value The amount of tokens to be spent.
@param _deadline The timestamp after which the Permit is no longer valid.
@param _v The bytes[64] of the valid secp256k1 signature of permit by owner
@param _r The bytes[0:32] of the valid secp256k1 signature of permit by owner
@param _s The bytes[32:64] of the valid secp256k1 signature of permit by owner
@return True, if transaction completes successfully
"""
assert _owner != empty(address)
assert block.timestamp <= _deadline
nonce: uint256 = self.nonces[_owner]
digest: bytes32 = keccak256(
concat(
b"\x19\x01",
self._domain_separator(),
keccak256(_abi_encode(EIP2612_TYPEHASH, _owner, _spender, _value, nonce, _deadline))
)
)
if _owner.is_contract:
sig: Bytes[65] = concat(_abi_encode(_r, _s),프로젝트로 돌아가기