Skip to content

Commit

Permalink
feat: deploy metapool in mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
rndquu committed Mar 28, 2024
1 parent 27613ce commit f395120
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 39 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ COLLATERAL_TOKEN_ADDRESS="0x5f98805A4E8be255a32880FDeC7F6728C6568bA0"
# - testnet/anvil: deploys LUSD/USD chainlink price feed from scratch
COLLATERAL_TOKEN_CHAINLINK_PRICE_FEED_ADDRESS="0x3D7aE7E594f2f2091Ad8798313450130d0Aba3a0"

# Curve metapool address (Dollar-3CRVLP).
# By default set to the old Dollar-3CRV metapool which is about to be redeployed when
# new Dollar token is deployed.
# - mainnet: uses old Dollar-3CRVLP address
# - testnet/anvil: deploys metapool from scratch
CURVE_DOLLAR_METAPOOL_ADDRESS="0x20955CB69Ae1515962177D164dfC9522feef567E"

# Dollar amount in wei minted initially to provide liquidity to the Dollar-3CRV metapool
# By default set to 25k Dollar tokens
INITIAL_DOLLAR_MINT_AMOUNT_WEI="25000000000000000000000"
Expand All @@ -117,12 +110,6 @@ OWNER_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f
# - testnet: https://ethereum-sepolia.publicnode.com
# - mainnet: https://eth.ubq.fi/v1/mainnet
RPC_URL="http://127.0.0.1:8545"

# 3CRV LP token address (which you get if you deposit to Curve's TriPool (DAI/USDC/USDT)).
# By default set to 3CRV LP token address from mainnet.
# - mainet: uses values set in TOKEN_3CRV_ADDRESS
# - testnet/anvil: deploys 3CRV LP token from scratch
TOKEN_3CRV_ADDRESS="0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490"
```

We provide an `.env.example` file pre-set with recommend testing environment variables but you are free to modify or experiment with different values on your local branch.
Expand Down
13 changes: 0 additions & 13 deletions packages/contracts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ COLLATERAL_TOKEN_ADDRESS="0x5f98805A4E8be255a32880FDeC7F6728C6568bA0"
# - testnet/anvil: deploys LUSD/USD chainlink price feed from scratch
COLLATERAL_TOKEN_CHAINLINK_PRICE_FEED_ADDRESS="0x3D7aE7E594f2f2091Ad8798313450130d0Aba3a0"

# Curve metapool address (Dollar-3CRVLP).
# By default set to the old Dollar-3CRV metapool which is about to be redeployed when
# new Dollar token is deployed.
# - mainnet: uses old Dollar-3CRVLP address
# - testnet/anvil: deploys metapool from scratch
CURVE_DOLLAR_METAPOOL_ADDRESS="0x20955CB69Ae1515962177D164dfC9522feef567E"

# Dollar amount in wei minted initially to provide liquidity to the Dollar-3CRV metapool
# By default set to 25k Dollar tokens
INITIAL_DOLLAR_MINT_AMOUNT_WEI="25000000000000000000000"
Expand All @@ -36,9 +29,3 @@ OWNER_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f
# - testnet: https://ethereum-sepolia.publicnode.com
# - mainnet: https://eth.ubq.fi/v1/mainnet
RPC_URL="http://127.0.0.1:8545"

# 3CRV LP token address (which you get if you deposit to Curve's TriPool (DAI/USDC/USDT)).
# By default set to 3CRV LP token address from mainnet.
# - mainet: uses value set in TOKEN_3CRV_ADDRESS
# - testnet/anvil: deploys 3CRV LP token from scratch
TOKEN_3CRV_ADDRESS="0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {Deploy001_Diamond_Dollar as Deploy001_Diamond_Dollar_Development} from "../development/Deploy001_Diamond_Dollar.s.sol";
import {ManagerFacet} from "../../src/dollar/facets/ManagerFacet.sol";
import {UbiquityPoolFacet} from "../../src/dollar/facets/UbiquityPoolFacet.sol";
import {ICurveStableSwapFactoryNG} from "../../src/dollar/interfaces/ICurveStableSwapFactoryNG.sol";
import {ICurveStableSwapMetaNG} from "../../src/dollar/interfaces/ICurveStableSwapMetaNG.sol";

/// @notice Migration contract
Expand Down Expand Up @@ -64,10 +65,6 @@ contract Deploy001_Diamond_Dollar is Deploy001_Diamond_Dollar_Development {
address chainlinkPriceFeedAddress = vm.envAddress(
"COLLATERAL_TOKEN_CHAINLINK_PRICE_FEED_ADDRESS"
);
address token3CrvAddress = vm.envAddress("TOKEN_3CRV_ADDRESS");
address curveDollarMetapoolAddress = vm.envAddress(
"CURVE_DOLLAR_METAPOOL_ADDRESS"
);

//=======================================
// Chainlink LUSD/USD price feed setup
Expand Down Expand Up @@ -101,24 +98,44 @@ contract Deploy001_Diamond_Dollar is Deploy001_Diamond_Dollar_Development {
// stop sending admin transactions
vm.stopBroadcast();

//=========================================
// Curve's Dollar-3CRVLP metapool deploy
//=========================================

// start sending owner transactions
vm.startBroadcast(ownerPrivateKey);

// deploy Curve Dollar-3CRV metapool
address curveDollarMetaPoolAddress = ICurveStableSwapFactoryNG(
0x6A8cbed756804B16E05E741eDaBd5cB544AE21bf
).deploy_metapool(
0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7, // Curve 3pool (DAI-USDT-USDC) address
"Dollar/3CRV", // pool name
"Dollar3CRV", // LP token symbol
address(dollarToken), // main token
100, // amplification coefficient
40000000, // trade fee, 0.04%
20000000000, // off-peg fee multiplier
2597, // moving average time value, 2597 = 1800 seconds
0, // metapool implementation index
0, // asset type
"", // method id for oracle asset type (not applicable for Dollar)
address(0) // token oracle address (not applicable for Dollar)
);

// stop sending owner transactions
vm.stopBroadcast();

//========================================
// Curve's Dollar-3CRVLP metapool setup
//========================================

// start sending admin transactions
vm.startBroadcast(adminPrivateKey);

// init 3CRV token
curveTriPoolLpToken = IERC20(token3CrvAddress);

// init Dollar-3CRVLP Curve metapool
curveDollarMetaPool = ICurveStableSwapMetaNG(
curveDollarMetapoolAddress
);

// set curve's metapool in manager facet
ManagerFacet managerFacet = ManagerFacet(address(diamond));
managerFacet.setStableSwapMetaPoolAddress(address(curveDollarMetaPool));
managerFacet.setStableSwapMetaPoolAddress(curveDollarMetaPoolAddress);

// stop sending admin transactions
vm.stopBroadcast();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";

/**
* @notice Factory allows the permissionless deployment of up to
* eight-coin plain pools (ex: DAI-USDT-USDC) and metapools (ex: USDT-3CRV).
* Liquidity pool and LP token share the same contract.
*/
interface ICurveStableSwapFactoryNG {
/**
* @notice Deploys a stableswap NG metapool
* @param _base_pool Address of the base pool to pair the token with. For tripool (DAI-USDT-USDC) use its pool
* address at 0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7.
* @param _name Name of the new metapool, ex: `Dollar/3CRV`
* @param _symbol Symbol for the new metapool’s LP token - will be concatenated with the base pool symbol, ex: `Dollar3CRV`
* @param _coin Address of the coin being used in the metapool, ex: use Dollar token address
* @param _A Amplification coefficient. If set to 0 then bonding curve acts like Uniswap. Any >0 value
* makes the bonding curve to swap at 1:1 constant price, the more `_A` the longer the constant price period.
* Curve recommends set it to 100 for crypto collateralizard stablecoins. This parameter can be updated later.
* @param _fee Trade fee, given as an integer with 1e10 precision, ex: 40000000 = 0.04% fee
* @param _offpeg_fee_multiplier Off-peg multiplier. Curve recommends set it to `20000000000`. This parameter can be updated
* later. More info: https://docs.curve.fi/stableswap-exchange/stableswap-ng/pools/overview/#dynamic-fees
* @param _ma_exp_time MA time; set as time_in_seconds / ln(2), ex: 866 = 600 seconds, 2597 = 1800 seconds.
* This parameter can be updated later.
* @param _implementation_idx Index of the metapool implementation to use. Can be retrieved
* via `ICurveStableSwapFactoryNG.metapool_implementations()`. There is only 1 metapool implementation right now
* so use index `0`.
* @param _asset_type Asset type of the pool as an integer. Available asset type indexes:
* - 0: Standard ERC20 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)
* Dollar is a standard ERC20 token so we should use asset type with index `0`.
* @param _method_id First four bytes of the Keccak-256 hash of the function signatures of
* the oracle addresses that give rate oracles. This is applied only to asset type `1` (Oracle).
* For Dollar token deployment set empty.
* @param _oracle Rate oracle address. This is applied only to asset type `1` (Oracle).
* For Dollar token deployment set empty address.
* @return Deployed metapool address
*/
function deploy_metapool(
address _base_pool,
string memory _name,
string memory _symbol,
address _coin,
uint256 _A,
uint256 _fee,
uint256 _offpeg_fee_multiplier,
uint256 _ma_exp_time,
uint256 _implementation_idx,
uint8 _asset_type,
bytes4 _method_id,
address _oracle
) external returns (address);
}

0 comments on commit f395120

Please sign in to comment.