Skip to content

Commit

Permalink
Merge pull request #920 from rndquu/refactor/testnet-deploy-collateral
Browse files Browse the repository at this point in the history
refactor(migration): deploy collateral in testnet
  • Loading branch information
rndquu authored Mar 28, 2024
2 parents 59ccb55 + ec549d1 commit 501e69f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 13 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ ADMIN_PRIVATE_KEY="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b7

# Collateral token address (used in UbiquityPoolFacet, allows users to mint/redeem Dollars in exchange for collateral token).
# By default set to LUSD address in ethereum mainnet.
# - mainnet/anvil(forked from mainnet): 0x5f98805A4E8be255a32880FDeC7F6728C6568bA0 (LUSD)
# - testnet: 0x3e622317f8C93f7328350cF0B56d9eD4C620C5d6 (DAI)
# NOTICE: LUSD token is not deployed to sepolia testnet so we use DAI instead which is deployed to testnet
# - mainnet: 0x5f98805A4E8be255a32880FDeC7F6728C6568bA0 (LUSD)
# - testnet/anvil: deploys collateral ERC20 token from scratch
COLLATERAL_TOKEN_ADDRESS="0x5f98805A4E8be255a32880FDeC7F6728C6568bA0"

# Collateral token price feed address from chainlink.
Expand Down
5 changes: 2 additions & 3 deletions packages/contracts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ ADMIN_PRIVATE_KEY="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b7

# Collateral token address (used in UbiquityPoolFacet, allows users to mint/redeem Dollars in exchange for collateral token).
# By default set to LUSD address in ethereum mainnet.
# - mainnet/anvil(forked from mainnet): 0x5f98805A4E8be255a32880FDeC7F6728C6568bA0 (LUSD)
# - testnet: 0x3e622317f8C93f7328350cF0B56d9eD4C620C5d6 (DAI)
# NOTICE: LUSD token is not deployed to sepolia testnet so we use DAI instead which is deployed to testnet
# - mainnet: 0x5f98805A4E8be255a32880FDeC7F6728C6568bA0 (LUSD)
# - testnet/anvil: deploys collateral ERC20 token from scratch
COLLATERAL_TOKEN_ADDRESS="0x5f98805A4E8be255a32880FDeC7F6728C6568bA0"

# Collateral token price feed address from chainlink.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {
// env variables
uint256 adminPrivateKey;
uint256 ownerPrivateKey;
address collateralTokenAddress;

// threshold in seconds when price feed response should be considered stale
uint256 CHAINLINK_PRICE_FEED_THRESHOLD;
Expand All @@ -123,6 +122,9 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {
IERC20 curveTriPoolLpToken; // Curve's 3CRV-LP token
ICurveStableSwapMetaNG curveDollarMetaPool; // Curve's Dollar-3CRVLP metapool

// collateral ERC20 token used in UbiquityPoolFacet
IERC20 collateralToken;

// selectors for all of the facets
bytes4[] selectorsOfAccessControlFacet;
bytes4[] selectorsOfDiamondCutFacet;
Expand All @@ -135,7 +137,6 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {
// read env variables
adminPrivateKey = vm.envUint("ADMIN_PRIVATE_KEY");
ownerPrivateKey = vm.envUint("OWNER_PRIVATE_KEY");
collateralTokenAddress = vm.envAddress("COLLATERAL_TOKEN_ADDRESS");

address adminAddress = vm.addr(adminPrivateKey);
address ownerAddress = vm.addr(ownerPrivateKey);
Expand Down Expand Up @@ -265,6 +266,18 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {
// stop sending admin transactions
vm.stopBroadcast();

//==========================
// Collateral token setup
//==========================

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

initCollateral();

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

//=========================
// UbiquiPoolFacet setup
//=========================
Expand All @@ -278,8 +291,9 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {

// add collateral token (users can mint/redeem Dollars in exchange for collateral)
uint256 poolCeiling = 10_000e18; // max 10_000 of collateral tokens is allowed

ubiquityPoolFacet.addCollateralToken(
collateralTokenAddress, // collateral token address
address(collateralToken), // collateral token address
address(chainLinkPriceFeedLusd), // chainlink LUSD/USD price feed address
poolCeiling // pool ceiling amount
);
Expand Down Expand Up @@ -343,6 +357,26 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {
vm.stopBroadcast();
}

/**
* @notice Initializes collateral token
*
* @dev Collateral token is different for mainnet and development:
* - mainnet: uses LUSD address from `COLLATERAL_TOKEN_ADDRESS` env variables
* - development: deploys mocked ERC20 token from scratch
*/
function initCollateral() public virtual {
//=================================
// Collateral ERC20 token deploy
//=================================

// deploy ERC20 mock token for ease of debugging
collateralToken = new MockERC20(
"Collateral test token",
"CLT_TEST",
18
);
}

/**
* @notice Initializes oracle related contracts
*
Expand Down Expand Up @@ -398,7 +432,7 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {

// set price feed address and threshold in seconds
ubiquityPoolFacet.setCollateralChainLinkPriceFeed(
collateralTokenAddress, // collateral token address
address(collateralToken), // collateral token address
address(chainLinkPriceFeedLusd), // price feed address
CHAINLINK_PRICE_FEED_THRESHOLD // price feed staleness threshold in seconds
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ contract Deploy001_Diamond_Dollar is Deploy001_Diamond_Dollar_Development {
super.run();
}

/**
* @notice Initializes collateral token
*
* @dev Collateral token is different for mainnet and development:
* - mainnet: uses LUSD address from `COLLATERAL_TOKEN_ADDRESS` env variables
* - development: deploys mocked ERC20 token from scratch
*/
function initCollateral() public override {
// read env variables
address collateralTokenAddress = vm.envAddress(
"COLLATERAL_TOKEN_ADDRESS"
);

//=================================
// Collateral ERC20 token setup
//=================================

// use existing LUSD contract for mainnet
collateralToken = IERC20(collateralTokenAddress);
}

/**
* @notice Initializes oracle related contracts
*
Expand Down Expand Up @@ -67,7 +88,7 @@ contract Deploy001_Diamond_Dollar is Deploy001_Diamond_Dollar_Development {

// set price feed
ubiquityPoolFacet.setCollateralChainLinkPriceFeed(
collateralTokenAddress, // collateral token address
address(collateralToken), // collateral token address
address(chainLinkPriceFeedLusd), // price feed address
CHAINLINK_PRICE_FEED_THRESHOLD // price feed staleness threshold in seconds
);
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test:slither": "slither . --compile-force-framework foundry",
"test:echidna": "echidna-test . --config echidna.config.yml",
"test:coverage": "forge coverage",
"start:anvil": "anvil --fork-url https://eth.ubq.fi/v1/mainnet --chain-id 31337",
"start:anvil": "anvil --fork-url https://mainnet.gateway.tenderly.co --chain-id 31337",
"prebuild": "run-p clean",
"deploy:development": "migrations/development/deploy.sh",
"deploy:mainnet": "migrations/mainnet/deploy.sh",
Expand Down
10 changes: 9 additions & 1 deletion packages/contracts/src/dollar/mocks/MockERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ pragma solidity 0.8.19;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockERC20 is ERC20 {
uint8 internal __decimals;

constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) ERC20(_name, _symbol) {}
) ERC20(_name, _symbol) {
__decimals = _decimals;
}

function mint(address to, uint256 value) public virtual {
_mint(to, value);
Expand All @@ -17,4 +21,8 @@ contract MockERC20 is ERC20 {
function burn(address from, uint256 value) public virtual {
_burn(from, value);
}

function decimals() public view virtual override returns (uint8) {
return __decimals;
}
}

0 comments on commit 501e69f

Please sign in to comment.