bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 2쪽
er_to`\*\*Traditional Factories such as the regular [stableswap](https://docs.curve.finance/developer/amm/legacy/factory/stableswap/deployer-api.md) or [cryptoswap](https://docs.curve.finance/developer/amm/legacy/factory/cryptoswap/deployer-api.md) utilize Vyper's [`create_forwarder_to`](https://docs.vyperlang.org/en/stable/built-in-functions.html?highlight=create_forwarder_to#chain-interaction) function (renamed to `create_minimal_proxy_to` in Vyper version 0.3.4) to deploy liquidity pools, LP tokens, and gauges.
- \*\*`Blueprint Contracts`\*\*Newer factories utilize blueprint contracts as outlined in [EIP-5202](https://eips.ethereum.org/EIPS/eip-5202). The corresponding contracts are directly created from their blueprint implementations, which has become the preferred method for all newly deployed factories.
* * *
<a id="fee-receiver"></a>
## Fee Receiver
Users interacting with liquidity pools, such as for exchanging tokens, are required to pay fees. Each factory contains a universal `fee_receiver` variable, where all fees from pools deployed through that factory are collected. This address can usually be changed by the `owner` of the factory via a `set_fee_receiver` function, which is typically the Curve DAO. Therefore, to change the fee receiver address, an approved on-chain vote must pass.
<a id="fee_receiver"></a>
### `fee_receiver`
`PoolFactory.fee_receiver() -> address: view`
Getter for the address where the accrued admin fees are collected.
Returns: fee receiver (`address`).
**<>Source code▼**
```vyper
# fee receiver for all pools
fee_receiver: public(address)
```
**▶Example▼**
```shell
>>> PoolFactory.fee_receiver()
'0xa2Bcd1a4Efbd04B63cd03f5aFf2561106ebCCE00'
```
<a id="set_fee_receiver"></a>
### `set_fee_receiver`
`PoolFactory.set_fee_receiver(_fee_receiver: address)`
Guarded Method
This function is only callable by the `admin` of the contract.
Function to set a new fee receiver address.
| Input | Type | Description |
| --- | --- | --- |
| `_fee_receiver` | `address` | Address set as the new fee receiver. |
**<>Source code▼**
```vyper
# fee receiver for all pools:
fee_receiver: public(address)
@external
def set_fee_receiver(_fee_receiver: address):
"""
@notice Set fee receiver
@param _fee_receiver Address that fees are sent to
"""
assert msg.sender == self.admin, "dev: admin only"
log UpdateFeeReceiver(self.fee_receiver, _fee_receiver)
self.fee_receiver = _fee_receiver
```
* * *
<a id="contract-ownership"></a>
## Contract Ownership
Each Factory is controlled by an `admin`, which is typically set to the DAO; thus, any changes to the contract require approval by the Curve DAO.
The contracts utilize the classic two-step ownership model found within Curve contracts. Ownership can be transferred by first committing to the transfer of ownership via `commit_transfer_ownership`. This transfer must then be accepted by the `future_admin` through the `accept_transfer_ownership` function.
Some Factory contracts are indirectly owned by the DAO through a proxy contract.
<a id="admin"></a>
### `admin`
`PoolFactory.admin() -> address: view`
Getter for the current admin of the Factory.
Returns: admin (`address`).
**<>Source code▼**
```vyper
admin: public(address)
```
**▶Example▼**
```shell
>>> Factory.admin()
'0x40907540d8a6C65c637785e8f8B742ae6b0b9968'
```
<a id="future_admin"></a>
### `future_admin`
`PoolFactory.future_admin() -> address: view`
Getter for the future admin of the Factory.
Returns: future admin (`address`).
**<>Source code▼**
```vyper
future_admin: public(address)
```
**▶Example▼**
```shell
>>> PoolFactory.future_admin()
'0x0000000000000000000000000000000000000000'
```
<a id="commit_transfer_ownership"></a>
### `commit_transfer_ownership`
`PoolFactory.commit_transfer_ownership(_addr: address)`
Guarded Method
This function is only callable by the `admin` of the contract.
This function commits a transfer of ownership by setting `_addr` as the `future_admin` of the contract. These changes must then be applied by the `future_admin` itself through the `accept_transfer_ownership` function.
| Input | Type | Description |
| --- | --- | --- |
| `_addr` | `address` | Address to transfer ownership to. |
**<>Source code▼**
```vyper
admin: public(address)
future_admin: public(address)
@external
def commit_transfer_ownership(_addr: address):
"""
@notice Transfer ownership of this contract to `addr`
@param _addr Address of the new owner
"""
assert msg.sender == self.admin, "dev: admin only"
self.future_admin = _addr
```
<a id="accept_transfer_ownership"></a>
### `accept_transfer_ownership`
`PoolFactory.accept_transfer_ownership():`
Guarded Method
This function is only callable by the `future_admin` of the contract.
Function to accept the ownership transfer.
Emits: `TransferOwnership`
**<>Source code▼**
```vyper
event TransferOwnership:
_old_owner: address
_new_owner: address
admin: public(address)
future_admin: public(address)
@external
def accept_transfer_ownership():
"""
@notice Accept a pending ownership transfer
@dev Only callable by the new owner
"""
assert msg.sender == self.future_admin, "dev: future admin only"
log TransferOwnership(self.admin, msg.sender)
self.admin = msg.sender
```
---
# Stableswap-NG Factory: Deployer API
Source: [https://docs.curve.finance/developer/amm/factory/stableswap-ng/deployer-api](https://docs.curve.finance/developer/amm/factory/stableswap-ng/deployer-api)
<a id="name-and-symbol"></a>
## Name and Symbol
The input values of `_name` or `_symbol` are obviously non-trivial for the performance of the pool. These parameters should visualize, what kind of tokens are included in the pool.
```shell
_name = "rETH/wETH Pool"
_symbol = "rETH/wETH"
```
* * *
<a id="coins_coins-includes-all-tokens-included-in-the-pool-as-a-dynarray"></a>
## Coins`_coins` includes all tokens included in the pool as a `DynArray`.
```shell
_coins = ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xae78736Cd615f374D3085123A210448E74Fc6393"]
```
* * *
<a id="a-fee-off-peg-fee-multiplier-and-ma-exp-time"></a>
## A, Fee, Off-Peg Fee Multiplier, and MA-Exp-Time
- `_A` represents the amplification coefficient of the pool, signifying its density.
- `_fee` is referred to as the "base fee."
- The `offpeg_fee_multiplier` parameter enables the system to dynamically adjust fees according to the pool's state.
- `ma_exp_time` denotes the time window for the moving average oracle.
*Recommended Parameters*:
| Parameter | Fiat-Redeemable Stablecoin | Crypto-Collateralized Stablecoin |
| --- | --- | --- |
| `A` | 200 | 100 |
| `fee` | 0.04% | 0.04% |
| `offpeg_fee_multiplier` | 2 | 2 |
| `ma_exp_time` | 866 | 866 |
```shell
_A = 200
_fee = 4000000 # 0.0001 or 0.01%
_offpeg_fee_multiplier = 20000000000 # 5 or 500%
_ma_exp_time = 866 # ~600 seconds
```
Parameter Precision
The precision of `_fee` and `_offpeg_fee_multiplier` is 1e10.
The time window of the moving average exponential oracle is calculated using `time_in_seconds / ln(2)`.
* * *
<a id="implemention-id"></a>
## Implemention ID
Pools are **created from implementation contracts**(blueprints). These contracts are added to the Factory and must be choosen when deploying a pool.
warning
The Factory can have **multiple plain- and meta-pool implementations**. If there are multiple implementations for a plain or meta-pool, it's important to understand the differences and determine which one is suitable.
Additionally, implementation contracts are **upgradable**. They can either be replaced or have additional implementation contracts set. Please always make sure to check the most recent ones.
To query the factory-specific implementations:
```shell
>>> Factory.pool_implementation(0)
'0xDCc91f930b42619377C200BA05b7513f2958b202'
>>> Factory.metapool_implementation(0)
'0xede71F77d7c900dCA5892720E76316C6E575F0F7'
```
* * *
<a id="assets-types"></a>
## Assets Types
Stableswap-NG infrastructure supports pools with the following asset types:
| Asset Type | Description |
| --- | --- |
| `0` | **Standard ERC-20**token with no additional features |
| `1` | **Oracle**\- token with rate oracle (e.g. wstETH) |
| `2` | **Rebasing**\- token with rebase (e.g. stETH) |
| `3` | **ERC4626**\- token with *`convertToAssets`* method (e.g. sDAI) |
*Consequently, supported tokens include:*
- ERC-20 support for return `True/revert`, `True/False` or `None`
- ERC-20 tokens can have *arbitrary decimals (≤18)*
- ERC-20 tokens that *rebase* (either positive or fee on transfer)
- ERC-20 tokens that have a *rate oracle* (e.g. wstETH, cbETH) Oracle precision must be $10^{18}$
- ERC-4626 tokens with *arbitrary percision* (≤18) of Vault token and underlying asset
warning
- \*\*`ERC20:`\*\*Users are advised to do careful due-diligence on ERC20 tokens that they interact with, as this contract **cannot differentiate between harmless and malicious**ERC20 tokens.
- \*\*`Oracle:`\*\*When using tokens with oracles, its important to know that they **may be controlled externally by an EOA**.
- \*\*`Rebasing:`\*\*Users and Integrators are advised to understand how the AMM contract works with rebasing balances.
- \*\*`ERC4626:`\*\*Some ERC4626 implementations **may be susceptible to Donation/Inflation attacks**. Users are advised to proceed with caution.
Choosing asset types can sometimes be quite tricky. Asset types should be seen more as information for the AMM on **how to treat the assets under the hood**.
info
Let's consider the example of [rmETH/mETH](https://etherscan.io/address/0xdd4316c777a2295d899ba7ad92e0efa699865f43).
- [mETH](https://etherscan.io/address/0xd5F7838F5C461fefF7FE49ea5ebaF7728bB0ADfa) is a token with a rate oracle (the underlying asset is ETH). The rate can be fetched by reading the `mETHToETH` method within the [staking contract](https://etherscan.io/address/0xe3cBd06D7dadB3F4e6557bAb7EdD924CD1489E8f).
- rmETH is a rebasing token.
Because the deployer wants rmETH and mETH to trade as close to 1:1 as possible, they need to treat mETH like a regular ERC-20 token (asset type 0), instead of a rate oraclized token (asset type 1).
```shell
_asset_types = [0, 2] # coin(0) = asset type 0; coin(1) = asset type 2
```
* * *
<a id="method-ids-and-rate-oracles"></a>
## Method IDs and Rate Oracles
`method_ids` and `_oracles` are required for rate oracles to function. ERC-4626 does not need either of these. The sole requirement for those is to have a `convertToAssets` method.
info
When deploying pools that include coins not requiring a rate oracle, \*\*`b""`\*\*or \*\*`0x00000000`\*\*should be included in the `_methods_id` array and the \*\*`ZERO_ADDRESS`\*\*should be used in the `_oracles` array as placeholders for each coin.
- `_method_ids` is the first four bytes of the Keccak-256 hash of the function signatures of the oracle addresses that give rate oracles.
As an example, lets look at the [rETH](https://etherscan.io/token/0xae78736cd615f374d3085123a210448e74fc6393) token. The relevant function which returns the rate is `getExchangeRate`, the according first four bytes of the Keccak-256 hash of the functions signature is therefore `0xe6aa216c`. When calculating, its always important to include `"()"`, as they will change the bytes.
```shell
getExchangeRate -> "0xb2fc0e3e" # wrong
getExchangeRate() -> "0xe6aa216c" # correct
```
[Method ID Calculator](https://piyolab.github.io/playground/ethereum/getEncodedFunctionSignature/)
- `_oracles` is simply the contract address which provides the rate oracle function.
The input values are `DynArrays` with the length of tokens in the pool. Therefore, a rETH/wETH pool would have the following input values:
```shell
_method_id = [b"", "0xe6aa216c"]
_oracles = ["0x0000000000000000000000000000000000000000", "0xae78736cd615f374d3085123a210448e74fc6393"]
```
<a id="examples"></a>
### Examples
| Pool | Asset Types | Method ID's | Rate Oracle |
| --- | --- | --- | --- |
| [mkUSD/USDC](https://etherscan.io/tx/0xf980b4a4194694913af231de69ab4593f5e0fcdc) | `[0, 0]` | `['0x00000000', '0x00000000']` | `['0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000']` |
| [FRAX/sDAI](https://etherscan.io/tx/0xce6431d21e3fb1036ce9973a3312368ed96f5ce7) | `[0, 3]` | `['0x00000000', '0x00000000']` | `['0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000']` |
| [wETH/rETH](https://etherscan.io/tx/0x9efe1a1cbd6ca51ee8319afc4573d253c3b732af) | `[0 , 1]` | `['0x00000000', '0xe6aa216c']` | `['0x0000000000000000000000000000000000000000', '0xae78736Cd615f374D3085123A210448E74Fc6393']` |
| [rmETH/mETH](https://etherscan.io/address/0xdd4316c777a2295d899ba7ad92e0efa699865f43) | `[2 , 0]` | `['0x00000000', '0x00000000']` | `['0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000']` |
* * *
<a id="deploying-plain--and-metapools"></a>
## Deploying Plain- and Metapools
<a id="deploy_plain_pool"></a>
### `deploy_plain_pool`
*Parameter limitations when deploying a plain pool:*
- Minimum of 2 and maximum of 8 coins.
- All coin arrays should be the same length.
- `_fee` ≤ 100000000 (1%).
- `_offpeg_fee_multiplier` \* `_fee` ≤ `MAX_FEE` \* `FEE_DENOMINATOR`.
- Maximum of 18 decimals for a coin.
- No duplicate coins.
- Valid implementation index.
`Factory.deploy_plain_pool(_name: String[32], _symbol: String[10], _coins: DynArray[address, MAX_COINS], _A: uint256, _fee: uint256, _offpeg_fee_multiplier: uint256, _ma_exp_time: uint256, _implementation_idx: uint256, _asset_types: DynArray[uint8, MAX_COINS], _method_ids: DynArray[bytes4, MAX_COINS], _oracles: DynArray[address, MAX_COINS], ) -> address:`
Function to deploy a stableswap-ng plain pool. The pool is created from a blueprint contract.
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` | `DynArray[address, MAX_COINS]` | Array 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 |
| `_offpeg_fee_multiplier` | `uint256` | Off-peg fee multiplier |
| `_ma_exp_time` | `uint256` | MA time; set as time\_in\_seconds / ln(2) |
| `_implementation_idx` | `uint256` | Index of the implementation to use |
| `_asset_types` | `DynArray[uint8, MAX_COINS]` | Asset type of the pool as an integer; more [here](https://docs.curve.finance/developer/amm/stableswap-ng/overview.md#supported-assets) |
| `_method_ids` | `DynArray[bytes4, MAX_COINS]` | Array of first four bytes of the Keccak-256 hash of the function signatures of the oracle addresses that give rate oracles |
| `_oracles` | `DynArray[address, MAX_COINS]` | Array of rate oracle addresses |
Implementation ID
There might be multiple pool implementations. To query all available ones, see [here](https://docs.curve.finance/developer/amm/factory/stableswap-ng/overview.md#query-implementations). As of the current date (31.10.2023), there is only one pool implementation available. Since the `_implementation_idx` starts at 0, users need to input "0" when deploying a pool.
**<>Source code▼**
```vyper
event PlainPoolDeployed:
coins: DynArray[address, MAX_COINS]
A: uint256
fee: uint256
deployer: address
MAX_COINS: constant(uint256) = 8
MAX_FEE: constant(uint256) = 5 * 10 **9
FEE_DENOMINATOR: constant(uint256) = 10 **10
@external
def deploy_plain_pool(
_name: String[32],
_symbol: String[10],
_coins: DynArray[address, MAX_COINS],
_A: uint256,
_fee: uint256,
_offpeg_fee_multiplier: uint256,
_ma_exp_time: uint256,
_implementation_idx: uint256,
_asset_types: DynArray[uint8, MAX_COINS],
_method_ids: DynArray[bytes4, MAX_COINS],
_oracles: DynArray[address, MAX_COINS],
) -> 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
maximum is 1% (100000000). 50% of the fee is distributed to veCRV holders.
@param _ma_exp_time Averaging window of oracle. Set as time_in_seconds / ln(2)
Example: for 10 minute EMA, _ma_exp_time is 600 / ln(2) ~= 866
@param _implementation_idx Index of the implementation to use
@param _asset_types Asset types for pool, as an integer
@param _method_ids Array of first four bytes of the Keccak-256 hash of the function signatures
of the oracle addresses that gives rate oracles.
Calculated as: keccak(text=event_signature.replace(" ", ""))[:4]
@param _oracles Array of rate oracle addresses.
@return Address of the deployed pool
"""
assert len(_coins) >= 2 # dev: pool needs to have at least two coins!
assert len(_coins) == len(_method_ids) # dev: All coin arrays should be same length
assert len(_coins) == len(_oracles) # dev: All coin arrays should be same length
assert len(_coins) == len(_asset_types) # dev: All coin arrays should be same length
assert _fee <= 100000000, "Invalid fee"
assert _offpeg_fee_multiplier * _fee <= MAX_FEE * FEE_DENOMINATOR
n_coins: uint256 = len(_coins)
_rate_multipliers: DynArray[uint256, MAX_COINS] = empty(DynArray[uint256, MAX_COINS])
decimals: DynArray[uint256, MAX_COINS] = empty(DynArray[uint256, MAX_COINS])
for i in range(MAX_COINS):
if i == n_coins:
break
coin: address = _coins[i]
decimals.append(ERC20(coin).decimals())
assert decimals[i] < 19, "Max 18 decimals for coins"
_rate_multipliers.append(10 **(36 - decimals[i]))
for j in range(i, i + MAX_COINS):
if (j + 1) == n_coins:
break
assert coin != _coins[j+1], "Duplicate coins"
implementation: address = self.pool_implementations[_implementation_idx]
assert implementation != empty(address), "Invalid implementation index"
pool: address = create_from_blueprint(
implementation,
_name, # _name: String[32]
_symbol, # _symbol: String[10]
_A, # _A: uint256
_fee, # _fee: uint256
_offpeg_fee_multiplier, # _offpeg_fee_multiplier: uint256
_ma_exp_time, # _ma_exp_time: uint256
_coins, # _coins: DynArray[address, MAX_COINS]
_rate_multipliers, # _rate_multipliers: DynArray[uint256, MAX_COINS]
_asset_types, # _asset_types: DynArray[uint8, MAX_COINS]
_method_ids, # _method_ids: DynArray[bytes4, MAX_COINS]
_oracles, # _oracles: DynArray[address, MAX_COINS]
code_offset=3
)
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 = empty(address)
self.pool_data[pool].implementation = implementation
self.pool_data[pool].asset_types = _asset_types
for i in range(MAX_COINS):
if i == n_coins:
break
coin: address = _coins[i]
self.pool_data[pool].coins.append(coin)
for j in range(i, i + MAX_COINS):
if (j + 1) == n_coins:
break
swappable_coin: address = _coins[j + 1]
key: uint256 = (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(
"crvusd/USDT", # _name
"crvusd-usdt", # _symbol
[ # coins:
"0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E", # crvusd
"0xdAC17F958D2ee523a2206206994597C13D831ec7" # usdt
],
1500 # _A
1000000, #프로젝트로 돌아가기