bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 26쪽
ss` | Address which `msg.sender` want to transfer to |
| `_value` | `uint256` | Amount of tokens to be transferred |
Emits: Transfer
**<>Source code▼**
```vyper
@public
def transferFrom(_from : address, _to : address, _value : uint256) -> bool:
"""
@dev Transfer tokens from one address to another.
Note that while this function emits a Transfer event, this is not required as per the specification,
and other compliant implementations may not emit the event.
@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
"""
# NOTE: vyper does not allow underflows
# so the following subtraction would revert on insufficient balance
self.balanceOf[_from] -= _value
self.balanceOf[_to] += _value
if msg.sender != self.minter: # minter is allowed to transfer anything
# NOTE: vyper does not allow underflows
# so the following subtraction would revert on insufficient allowance
self.allowances[_from][msg.sender] -= _value
log.Transfer(_from, _to, _value)
return True
```
note
While this function emits a Transfer event, this is not required as per the specification, and other compliant implementations may not emit the event.
<a id="curvetokenapprove"></a>
### `CurveToken.approve`
CurveToken.approve(\_spender: address, \_value: uint256) → bool
Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`. Returns `True` on successful approvals.
| Input | Type | Description |
| --- | --- | --- |
| `_spender` | `address` | Address which will spend the funds |
| `_value` | `uint256` | Amount of tokens to be spent |
Emits: Approval
**<>Source code▼**
```vyper
@public
def approve(_spender : address, _value : uint256) -> bool:
"""
@dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
Beware that changing an allowance with this method brings the risk that someone may use both the old
and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
@param _spender The address which will spend the funds.
@param _value The amount of tokens to be spent.
"""
assert _value == 0 or self.allowances[msg.sender][_spender] == 0
self.allowances[msg.sender][_spender] = _value
log.Approval(msg.sender, _spender, _value)
return True
```
warning
Beware that changing an allowance with this method brings the risk that someone may use both the old and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this race condition is to first reduce the spender’s allowance to 0 and set the desired value afterwards (see this [GitHub issue](https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729)).
warning
For Curve LP Tokens V1 and V2, **non-zero to non-zero approvals are prohibited**. Instead, after every non-zero approval, the allowance for the spender must be reset to 0.
<a id="minter-methods"></a>
## Minter Methods
The following methods are only callable by the `minter` (private attribute).
note
For Curve Token V1, the `minter` attribute is not `public`.
<a id="curvetokenmint"></a>
### `CurveToken.mint`
CurveToken.mint(\_to: address, \_value: uint256)
This encapsulates the modification of balances such that the proper events are emitted.
| Input | Type | Description |
| --- | --- | --- |
| `_to` | `address` | Address that will receive the minted tokens |
| `_value` | `uint256` | Amount of tokens that will be minted |
Emits: Transfer
**<>Source code▼**
```vyper
@public
def mint(_to: address, _value: uint256):
"""
@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
assert _to != ZERO_ADDRESS
self.total_supply += _value
self.balanceOf[_to] += _value
log.Transfer(ZERO_ADDRESS, _to, _value)
```
<a id="curvetokenburn"></a>
### `CurveToken.burn`
CurveToken.burn(\_value: uint256)
Burn an amount of the token of `msg.sender`.
| Input | Type | Description |
| --- | --- | --- |
| `_value` | `uint256` | Token amount that will be burned |
Emits: Transfer
**<>Source code▼**
```vyper
@private
def _burn(_to: address, _value: uint256):
"""
@dev Internal function that burns an amount of the token of a given
account.
@param _to The account whose tokens will be burned.
@param _value The amount that will be burned.
"""
assert _to != ZERO_ADDRESS
self.total_supply -= _value
self.balanceOf[_to] -= _value
log.Transfer(_to, ZERO_ADDRESS, _value)
@public
def burn(_value: uint256):
"""
@dev Burn an amount of the token of msg.sender.
@param _value The amount that will be burned.
"""
assert msg.sender == self.minter, "Only minter is allowed to burn"
self._burn(msg.sender, _value)
```
<a id="curvetokenburnfrom"></a>
### `CurveToken.burnFrom`
CurveToken.burnFrom(\_to: address, \_value: uint256)
Burn an amount of the token from a given account.
| Input | Type | Description |
| --- | --- | --- |
| `_to` | `address` | Account whose tokens will be burned |
| `_value` | `uint256` | Token amount that will be burned |
Emits: Transfer
**<>Source code▼**
```vyper
@private
def _burn(_to: address, _value: uint256):
"""
@dev Internal function that burns an amount of the token of a given
account.
@param _to The account whose tokens will be burned.
@param _value The amount that will be burned.
"""
assert _to != ZERO_ADDRESS
self.total_supply -= _value
self.balanceOf[_to] -= _value
log.Transfer(_to, ZERO_ADDRESS, _value)
@public
def burnFrom(_to: address, _value: uint256):
"""
@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, "Only minter is allowed to burn"
self._burn(_to, _value)
```
<a id="curvetokenset_minter"></a>
### `CurveToken.set_minter`
CurveToken.set\_minter(\_minter: address)
Set a new minter for the token.
| Input | Type | Description |
| --- | --- | --- |
| `_minter` | `address` | Address of the new minter |
**<>Source code▼**
```vyper
@public
def set_minter(_minter: address):
assert msg.sender == self.minter
self.minter = _minter
```
---
# curve-token-v2
Source: [https://docs.curve.finance/developer/amm/legacy/stableswap/lp-tokens/curve-token-v2](https://docs.curve.finance/developer/amm/legacy/stableswap/lp-tokens/curve-token-v2)
The implementation for a Curve Token V2 may be viewed on [GitHub](https://github.com/curvefi/curve-contract/blob/master/contracts/tokens/CurveTokenV2.vy).
note
Compared to Curve Token v1, the following changes have been made to the API:
- `minter` attribute is public and therefore a `minter` getter has been generated
- `name` and `symbol` attributes can be set via `set_name`
- `mint` method returns `bool`
- `burnFrom` method returns `bool`
- `burn` method has been removed
warning
For Curve LP Tokens V1 and V2, non-zero to non-zero approvals are prohibited. Instead, after every non-zero approval, the allowance for the spender must be reset to `0`.
<a id="curvetokenminter"></a>
### `CurveToken.minter`
`CurveToken.minter() → address: view`
Getter for the address of the `minter` of the token.
**<>Source code▼**
```vyper
minter: public(address)
@external
def __init__(_name: String[64], _symbol: String[32], _decimals: uint256, _supply: uint256):
init_supply: uint256 = _supply * 10 **_decimals
self.name = _name
self.symbol = _symbol
self.decimals = _decimals
self.balanceOf[msg.sender] = init_supply
self.total_supply = init_supply
self.minter = msg.sender
log Transfer(ZERO_ADDRESS, msg.sender, init_supply)
```
**▶Example▼**
```shell
>>> lp_token.minter()
""
```
<a id="curvetokenset_name"></a>
### `CurveToken.set_name`
`CurveToken.set_name(_name: String[64], _symbol: String[32])`
Set the name and symbol of the token. This method can only be called by minter.
| Input | Type | Description |
| --- | --- | --- |
| `name` | `String[64]` | New name of token |
| `symbol` | `String[32]` | New symbol of token |
**<>Source code▼**
```vyper
@external
def set_name(_name: String[64], _symbol: String[32]):
assert Curve(self.minter).owner() == msg.sender
self.name = _name
self.symbol = _symbol
```
**▶Example▼**
```shell
>>> lp_token.minter()
todo: ""
```
<a id="curvetokenmint"></a>
### `CurveToken.mint`
`CurveToken.mint(_to: address, _value: uint256) → bool`
Mint an amount of the token and assign it to an account. This encapsulates the modification of balances such that the proper events are emitted. Returns `True` if not reverted.
| Input | Type | Description |
| --- | --- | --- |
| `_to` | `address` | Receiver of minted tokens |
| `_value` | `uint256` | Amount of tokens minted |
Emits: Transfer
**<>Source code▼**
```vyper
@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
assert _to != ZERO_ADDRESS
self.total_supply += _value
self.balanceOf[_to] += _value
log Transfer(ZERO_ADDRESS, _to, _value)
return True
```
**▶Example▼**
```shell
>>> lp_token.mint()
todo: ""
```
<a id="curvetokenburnfrom"></a>
### `CurveToken.burnFrom`
`CurveToken.burnFrom(_to: address, _value: uint256) → bool`
Burn an amount of the token from a given account. Returns `True` if not reverted.
| Input | Type | Description |
| --- | --- | --- |
| `_to` | `address` | Account whose tokens will be burned |
| `_value` | `uint256` | Amount that will be burned |
Emits: Transfer
**<>Source code▼**
```vyper
@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
assert _to != ZERO_ADDRESS
self.total_supply -= _value
self.balanceOf[_to] -= _value
log Transfer(_to, ZERO_ADDRESS, _value)
return True
```
**▶Example▼**
```shell
>>> lp_token.burnFrom()
todo: ""
```
---
# curve-token-v3
Source: [https://docs.curve.finance/developer/amm/legacy/stableswap/lp-tokens/curve-token-v3](https://docs.curve.finance/developer/amm/legacy/stableswap/lp-tokens/curve-token-v3)
The Curve Token V3 is more gas efficient than versions 1 and 2. The implementation for a Curve Token V3 may be viewed on [GitHub](https://github.com/curvefi/curve-contract/blob/master/contracts/tokens/CurveTokenV3.vy).
note
Compared to the Curve Token V2 API, there have been the following changes:
`increaseAllowance` and `decreaseAllowance` methods added to mitigate race conditions.
<a id="curvetokenincreaseallowance"></a>
### `CurveToken.increaseAllowance`
`CurveToken.increaseAllowance(_spender: address, _added_value: uint256) → bool`
Increase the allowance granted to `_spender` by the `msg.sender`.
This is alternative to `approve` that can be used as a mitigation for the potential race condition. Returns `True` if success.
| Input | Type | Description |
| --- | --- | --- |
| `_spender` | `address` | Account whose tokens will be burned |
| `_value` | `uint256` | Amount that will be burned |
Emits: Approval
**<>Source code▼**
```vyper
@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. This may be mitigated with the use of
{increaseAllowance} and {decreaseAllowance}.
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
@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
>>> lp_token.increaseAllowance()
todo: ""
```
<a id="curvetokendecreaseallowance"></a>
### `CurveToken.decreaseAllowance`
`CurveToken.decreaseAllowance(_spender: address, _subtracted_value: uint256) → bool`
Decrease the allowance granted to `_spender` by the `msg.sender`.
This is alternative to `approve` that can be used as a mitigation for the potential race condition. Returns `True` if success.
| Input | Type | Description |
| --- | --- | --- |
| `_spender` | `address` | Account whose tokens will be burned |
| `_added_value` | `uint256` | Amount that will be burned |
Emits: Approval
**<>Source code▼**
```vyper
@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. This may be mitigated with the use of
{increaseAllowance} and {decreaseAllowance}.
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
@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
>>> lp_token.decreaseAllowance()
todo: ""
```
---
# overview
Source: [https://docs.curve.finance/developer/amm/legacy/stableswap/lp-tokens/overview](https://docs.curve.finance/developer/amm/legacy/stableswap/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. Alternatively, if the LP token is supported by a metapool, the token may be deposited into the respective metapool in exchange for the metapool’s LP token (see here).
Currently, the following versions of Curve Stableswap LP tokens exist:
- [CurveTokenV1](https://github.com/curvefi/curve-contract/blob/master/contracts/tokens/CurveTokenV1.vy): LP token targetting Vyper [^0.1.0-beta.16](https://vyper.readthedocs.io/en/stable/release-notes.html#v0-1-0-beta-16)
- [CurveTokenV2](https://github.com/curvefi/curve-contract/blob/master/contracts/tokens/CurveTokenV2.vy): LP token targetting Vyper [^0.2.0](https://vyper.readthedocs.io/en/stable/release-notes.html#v0-2-1)
- [CurveTokenV3](https://github.com/curvefi/curve-contract/blob/master/contracts/tokens/CurveTokenV3.vy): LP token targetting Vyper [^0.2.0](https://vyper.readthedocs.io/en/stable/release-notes.html#v0-2-1)
todo: add hyperlink to deployment addresses
The version of each pool’s LP token can be found in the Deployment Addresses.
note
For older Curve pools the `token` attribute is not always `public` and a getter has not been explicitly implemented.
---
# Curve Stableswap Exchange: Overview
Source: [https://docs.curve.finance/developer/amm/legacy/stableswap/overview](https://docs.curve.finance/developer/amm/legacy/stableswap/overview)
Curve achieves extremely efficient stablecoin trades by implementing the Stableswap invariant, which has significantly lower slippage for stablecoin trades than many other prominent invariants (e.g., constant-product). Note that in this context stablecoins refers to tokens that are stable representations of one another. This includes, for example, USD-pegged stablecoins (like DAI and USDC), but also ETH and sETH (synthetic ETH) or different versions of wrapped BTC. For a detailed overview of the Stableswap invariant design, please read the official [Stableswap whitepaper](https://curve.fi/files/stableswap-paper.pdf).
A Curve pool is essentially a smart contract that implements the Stableswap invariant and therefore contains the logic for exchanging stable tokens. However, while all Curve pools implement the Stableswap invariant, they may come in different pool flavors.
In its simplest form, a Curve pool is an implementation of the Stableswap invariant with 2 or more tokens, which can be referred to as a plain pool. Alternative and more complex pool flavors include pools with lending functionality, so-called lending pools, as well as metapools, which are pools that allow for the exchange of one or more tokens with the tokens of one or more underlying base pools.
Curve also integrates with Synthetix to offer cross-asset swaps.
All exchange functionality that Curve supports, as well as noteworthy implementation details, are explained in technical depth in this section.
---
# admin-pool-settings
Source: [https://docs.curve.finance/developer/amm/legacy/stableswap/pools/admin-pool-settings](https://docs.curve.finance/developer/amm/legacy/stableswap/pools/admin-pool-settings)
<a id="overview"></a>
## Overview
The following are methods that may only be called by the pool admin (`owner`).
Additionally, some admin methods require a two-phase transaction process, whereby changes are committed in a first transaction and after a forced delay applied via a second transaction. The minimum delay after which a committed action can be applied is given by the constant pool attribute `admin_actions_delay`, which is set to 3 days.
<a id="pool-ownership-methods"></a>
## Pool Ownership Methods
<a id="stableswapcommit_transfer_ownership"></a>
### `StableSwap.commit_transfer_ownership`
Stableswap.commit\_transfer\_ownership(\_owner: address)
Initiate an ownership transfer of pool to `_owner`.
| Input | Type | Description |
| --- | --- | --- |
| `_owner` | `address` | Future owner of the pool contract |
Emits: CommitNewAdmin
**<>Source code▼**
```vyper
ADMIN_ACTIONS_DELAY: constant(uint256) = 3 * 86400
...
@external
def commit_transfer_ownership(_owner: address):
assert msg.sender == self.owner # dev: only owner
assert self.transfer_ownership_deadline == 0 # dev: active transfer
_deadline: uint256 = block.timestamp + ADMIN_ACTION프로젝트로 돌아가기