Skip to content

Commit

Permalink
refactor: use a single migration
Browse files Browse the repository at this point in the history
  • Loading branch information
rndquu committed Apr 9, 2024
1 parent 9181675 commit fc50358
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 99 deletions.
4 changes: 2 additions & 2 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"**/cspell.json",
"**/node_modules/**",
"packages/contracts/src/deprecated/*",
"packages/contracts/migrations/development/Deploy002_Governance.s.sol",
"packages/contracts/migrations/mainnet/Deploy002_Governance.s.sol"
"packages/contracts/migrations/development/Deploy001_Diamond_Dollar_Governance.s.sol",
"packages/contracts/migrations/mainnet/Deploy001_Diamond_Dollar_Governance.s.sol"
],
"readonly": true,
"useGitignore": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Script} from "forge-std/Script.sol";
import {UbiquityAlgorithmicDollarManager} from "../../src/deprecated/UbiquityAlgorithmicDollarManager.sol";
import {UbiquityGovernance} from "../../src/deprecated/UbiquityGovernance.sol";
import {Diamond, DiamondArgs} from "../../src/dollar/Diamond.sol";
import {UbiquityDollarToken} from "../../src/dollar/core/UbiquityDollarToken.sol";
import {AccessControlFacet} from "../../src/dollar/facets/AccessControlFacet.sol";
Expand Down Expand Up @@ -93,12 +95,16 @@ contract DiamondInit is Modifiers {
* - StakingFacet (staking is not a part of the initial deployment)
* - StakingFormulasFacet (staking is not a part of the initial deployment)
*/
contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {
contract Deploy001_Diamond_Dollar_Governance is Script, DiamondTestHelper {
// env variables
uint256 adminPrivateKey;
uint256 ownerPrivateKey;
uint256 initialDollarMintAmountWei;

// owner and admin addresses derived from private keys store in `.env` file
address adminAddress;
address ownerAddress;

// threshold in seconds when price feed response should be considered stale
uint256 CHAINLINK_PRICE_FEED_THRESHOLD;

Expand Down Expand Up @@ -126,6 +132,10 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {
// collateral ERC20 token used in UbiquityPoolFacet
IERC20 collateralToken;

// Governance token related contracts
UbiquityAlgorithmicDollarManager ubiquityAlgorithmicDollarManager;
UbiquityGovernance ubiquityGovernance;

// selectors for all of the facets
bytes4[] selectorsOfAccessControlFacet;
bytes4[] selectorsOfDiamondCutFacet;
Expand All @@ -142,8 +152,8 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {
"INITIAL_DOLLAR_MINT_AMOUNT_WEI"
);

address adminAddress = vm.addr(adminPrivateKey);
address ownerAddress = vm.addr(ownerPrivateKey);
adminAddress = vm.addr(adminPrivateKey);
ownerAddress = vm.addr(ownerPrivateKey);

//==================
// Before scripts
Expand Down Expand Up @@ -388,17 +398,22 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {
/**
* @notice Runs after the main `run()` method
*
* @dev Initializes oracle related contracts
* @dev Ubiquity protocol supports 2 oracles:
* @dev Initializes:
* - oracle related contracts
* - Governance token related contracts
*
* @dev Ubiquity protocol supports 4 oracles:
* 1. Curve's Dollar-3CRVLP metapool to fetch Dollar prices
* 2. Chainlink's price feed (used in UbiquityPool) to fetch collateral token prices in USD
* 3. Chainlink's price feed (used in UbiquityPool) to fetch ETH/USD price
* 4. Curve's Governance-WETH crypto pool to fetch Governance/ETH price
*
* There are 2 migrations (deployment scripts):
* 1. Development (for usage in testnet and local anvil instance forked from mainnet)
* 1. Development (for usage in testnet and local anvil instance)
* 2. Mainnet (for production usage in mainnet)
*
* Development migration deploys (for ease of debugging) mocks of:
* - Chainlink price feed contract
* - Chainlink collateral price feed contract
* - 3CRVLP ERC20 token
* - Curve's Dollar-3CRVLP metapool contract
*/
Expand Down Expand Up @@ -489,5 +504,33 @@ contract Deploy001_Diamond_Dollar is Script, DiamondTestHelper {

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

//===========================================
// Deploy UbiquityAlgorithmicDollarManager
//===========================================

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

ubiquityAlgorithmicDollarManager = new UbiquityAlgorithmicDollarManager(
ownerAddress
);

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

//=============================
// Deploy UbiquityGovernance
//=============================

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

ubiquityGovernance = new UbiquityGovernance(
address(ubiquityAlgorithmicDollarManager)
);

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

This file was deleted.

7 changes: 2 additions & 5 deletions packages/contracts/migrations/development/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
# load env variables
source .env

# Deploy001_Diamond_Dollar (deploys Diamond and Dollar contracts)
forge script migrations/development/Deploy001_Diamond_Dollar.s.sol:Deploy001_Diamond_Dollar --rpc-url $RPC_URL --broadcast -vvvv

# Deploy002_Governance (deploys Governance token)
forge script migrations/development/Deploy002_Governance.s.sol:Deploy002_Governance --rpc-url $RPC_URL --broadcast -vvvv
# Deploy001_Diamond_Dollar_Governance (deploys Diamond, Dollar and Governance related contracts)
forge script migrations/development/Deploy001_Diamond_Dollar_Governance.s.sol:Deploy001_Diamond_Dollar_Governance --rpc-url $RPC_URL --broadcast -vvvv
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ pragma solidity 0.8.19;

import {AggregatorV3Interface} from "@chainlink/interfaces/AggregatorV3Interface.sol";
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 {Deploy001_Diamond_Dollar_Governance as Deploy001_Diamond_Dollar_Governance_Development} from "../development/Deploy001_Diamond_Dollar_Governance.s.sol";
import {UbiquityAlgorithmicDollarManager} from "../../src/deprecated/UbiquityAlgorithmicDollarManager.sol";
import {UbiquityGovernance} from "../../src/deprecated/UbiquityGovernance.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
contract Deploy001_Diamond_Dollar is Deploy001_Diamond_Dollar_Development {
contract Deploy001_Diamond_Dollar_Governance is
Deploy001_Diamond_Dollar_Governance_Development
{
function run() public override {
// Run migration for testnet because "Deploy001_Diamond_Dollar" migration
// Run migration for testnet because "Deploy001_Diamond_Dollar_Governance" migration
// is identical both for testnet/development and mainnet
super.run();
}
Expand Down Expand Up @@ -42,23 +46,28 @@ contract Deploy001_Diamond_Dollar is Deploy001_Diamond_Dollar_Development {
/**
* @notice Runs after the main `run()` method
*
* @dev Initializes oracle related contracts
* @dev Initializes:
* - oracle related contracts
* - Governance token related contracts
*
* @dev We override `afterRun()` from `Deploy001_Diamond_Dollar_Development` because
* we need to use already deployed contracts while `Deploy001_Diamond_Dollar_Development`
* deploys all oracle related contracts from scratch for ease of debugging.
* @dev We override `afterRun()` from `Deploy001_Diamond_Dollar_Governance_Development` because
* we need to use already deployed contracts while `Deploy001_Diamond_Dollar_Governance_Development`
* deploys all oracle and Governance token related contracts from scratch for ease of debugging.
*
* @dev Ubiquity protocol supports 2 oracles:
* @dev Ubiquity protocol supports 4 oracles:
* 1. Curve's Dollar-3CRVLP metapool to fetch Dollar prices
* 2. Chainlink's price feed (used in UbiquityPool) to fetch collateral token prices in USD
* 3. Chainlink's price feed (used in UbiquityPool) to fetch ETH/USD price
* 4. Curve's Governance-WETH crypto pool to fetch Governance/ETH price
*
* There are 2 migrations (deployment scripts):
* 1. Development (for usage in testnet and local anvil instance forked from mainnet)
* 1. Development (for usage in testnet and local anvil instance)
* 2. Mainnet (for production usage in mainnet)
*
* Mainnet (i.e. production) migration uses already deployed contracts for:
* - Chainlink price feed contract
* - 3CRVLP ERC20 token
* - Chainlink collateral price feed contract
* - UbiquityAlgorithmicDollarManager contract
* - UbiquityGovernance token contract
*/
function afterRun() public override {
// read env variables
Expand Down Expand Up @@ -139,5 +148,23 @@ contract Deploy001_Diamond_Dollar is Deploy001_Diamond_Dollar_Development {

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

//==========================================
// UbiquityAlgorithmicDollarManager setup
//==========================================

// using already deployed (on mainnet) UbiquityAlgorithmicDollarManager
ubiquityAlgorithmicDollarManager = UbiquityAlgorithmicDollarManager(
0x4DA97a8b831C345dBe6d16FF7432DF2b7b776d98
);

//============================
// UbiquityGovernance setup
//============================

// using already deployed (on mainnet) Governance token
ubiquityGovernance = UbiquityGovernance(
0x4e38D89362f7e5db0096CE44ebD021c3962aA9a0
);
}
}
27 changes: 0 additions & 27 deletions packages/contracts/migrations/mainnet/Deploy002_Governance.s.sol

This file was deleted.

7 changes: 2 additions & 5 deletions packages/contracts/migrations/mainnet/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
# load env variables
source .env

# Deploy001_Diamond_Dollar (deploys Diamond and Dollar contracts)
forge script migrations/mainnet/Deploy001_Diamond_Dollar.s.sol:Deploy001_Diamond_Dollar --rpc-url $RPC_URL --broadcast -vvvv

# Deploy002_Governance (use already deployed Governance token)
forge script migrations/mainnet/Deploy002_Governance.s.sol:Deploy002_Governance --rpc-url $RPC_URL --broadcast -vvvv
# Deploy001_Diamond_Dollar_Governance (deploys Diamond, Dollar and Governance related contracts)
forge script migrations/mainnet/Deploy001_Diamond_Dollar_Governance.s.sol:Deploy001_Diamond_Dollar_Governance --rpc-url $RPC_URL --broadcast -vvvv

0 comments on commit fc50358

Please sign in to comment.