From c99757c4cae81f0b6970552d2c630be2957c41af Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 08:09:01 +0100 Subject: [PATCH 01/11] remove generalized meta strategies that we are not intendint to deploy any time soon --- contracts/contracts/proxies/Proxies.sol | 28 --------------- .../deploy/101_convex_alusd_meta_strategy.js | 22 ------------ .../deploy/102_convex_musd_meta_strategy.js | 22 ------------ .../deploy/103_convex_usdd_meta_strategy.js | 22 ------------ .../deploy/104_convex_busd_meta_strategy.js | 22 ------------ .../strategies/generalized-meta.fork-test.js | 34 ------------------- contracts/test/vault/vault.fork-test.js | 3 -- contracts/utils/constants.js | 10 ------ 8 files changed, 163 deletions(-) delete mode 100644 contracts/deploy/101_convex_alusd_meta_strategy.js delete mode 100644 contracts/deploy/102_convex_musd_meta_strategy.js delete mode 100644 contracts/deploy/103_convex_usdd_meta_strategy.js delete mode 100644 contracts/deploy/104_convex_busd_meta_strategy.js diff --git a/contracts/contracts/proxies/Proxies.sol b/contracts/contracts/proxies/Proxies.sol index a2e959a6b7..965bb2c034 100644 --- a/contracts/contracts/proxies/Proxies.sol +++ b/contracts/contracts/proxies/Proxies.sol @@ -80,34 +80,6 @@ contract ConvexOUSDMetaStrategyProxy is InitializeGovernedUpgradeabilityProxy { } -/** - * @notice ConvexalUSDMetaStrategyProxy delegates calls to a ConvexalGeneralizedMetaStrategy implementation - */ -contract ConvexalUSDMetaStrategyProxy is InitializeGovernedUpgradeabilityProxy { - -} - -/** - * @notice ConvexmUSDMetaStrategyProxy delegates calls to a ConvexalGeneralizedMetaStrategy implementation - */ -contract ConvexmUSDMetaStrategyProxy is InitializeGovernedUpgradeabilityProxy { - -} - -/** - * @notice ConvexUSDDMetaStrategyProxy delegates calls to a ConvexalGeneralizedMetaStrategy implementation - */ -contract ConvexUSDDMetaStrategyProxy is InitializeGovernedUpgradeabilityProxy { - -} - -/** - * @notice ConvexBUSDMetaStrategyProxy delegates calls to a ConvexalGeneralizedMetaStrategy implementation - */ -contract ConvexBUSDMetaStrategyProxy is InitializeGovernedUpgradeabilityProxy { - -} - /** * @notice ConvexLUSDMetaStrategyProxy delegates calls to a ConvexalGeneralizedMetaStrategy implementation */ diff --git a/contracts/deploy/101_convex_alusd_meta_strategy.js b/contracts/deploy/101_convex_alusd_meta_strategy.js deleted file mode 100644 index 4533ce442b..0000000000 --- a/contracts/deploy/101_convex_alusd_meta_strategy.js +++ /dev/null @@ -1,22 +0,0 @@ -const generalizedConvexStratDeployment = require("../utils/generalizedConvexStratDeployment"); -const { alusdMetapoolLPCRVPid } = require("../utils/constants"); - -module.exports = generalizedConvexStratDeployment({ - deployName: "101_convex_alusd_meta_strategy", - forceDeploy: false, - mainTokenName: "Alchemix USD", - mainTokenSymbol: "alUSD", - rewardTokenNames: ["CVX", "CRV"], - assets: ["DAI", "USDC", "USDT"], - pTokens: ["ThreePoolToken", "ThreePoolToken", "ThreePoolToken"], - platformAddress: ["ThreePool"], - cvxDepositorAddress: "0xF403C135812408BFbE8713b5A23a04b3D48AAE31", - metapoolAddress: "0x43b4FdFD4Ff969587185cDB6f0BD875c5Fc83f8c", - metapoolLPToken: "0x43b4FdFD4Ff969587185cDB6f0BD875c5Fc83f8c", - mainTokenAddress: "0xBC6DA0FE9aD5f3b0d58160288917AA56653660E9", // Alchemix USD - cvxRewardStakerAddress: "0x02E2151D4F351881017ABdF2DD2b51150841d5B3", - cvxDepositorPTokenId: alusdMetapoolLPCRVPid, // 36 - redeployVault: false, - deployStrategyImplementation: true, - skipMainnetDeploy: true, -}); diff --git a/contracts/deploy/102_convex_musd_meta_strategy.js b/contracts/deploy/102_convex_musd_meta_strategy.js deleted file mode 100644 index 04fa433a4b..0000000000 --- a/contracts/deploy/102_convex_musd_meta_strategy.js +++ /dev/null @@ -1,22 +0,0 @@ -const generalizedConvexStratDeployment = require("../utils/generalizedConvexStratDeployment"); -const { musdMetapoolLPCRVPid } = require("../utils/constants"); - -module.exports = generalizedConvexStratDeployment({ - deployName: "102_convex_musd_meta_strategy", - forceDeploy: false, - mainTokenName: "mStable USD", - mainTokenSymbol: "mUSD", - rewardTokenNames: ["CVX", "CRV"], - assets: ["DAI", "USDC", "USDT"], - pTokens: ["ThreePoolToken", "ThreePoolToken", "ThreePoolToken"], - platformAddress: ["ThreePool"], - cvxDepositorAddress: "0xF403C135812408BFbE8713b5A23a04b3D48AAE31", - metapoolAddress: "0x8474DdbE98F5aA3179B3B3F5942D724aFcdec9f6", - metapoolLPToken: "0x1aef73d49dedc4b1778d0706583995958dc862e6", - mainTokenAddress: "0xe2f2a5c287993345a840db3b0845fbc70f5935a5", // mStable USD - cvxRewardStakerAddress: "0xDBFa6187C79f4fE4Cda20609E75760C5AaE88e52", - cvxDepositorPTokenId: musdMetapoolLPCRVPid, // 14 - redeployVault: false, - deployStrategyImplementation: false, - skipMainnetDeploy: true, -}); diff --git a/contracts/deploy/103_convex_usdd_meta_strategy.js b/contracts/deploy/103_convex_usdd_meta_strategy.js deleted file mode 100644 index c03375d157..0000000000 --- a/contracts/deploy/103_convex_usdd_meta_strategy.js +++ /dev/null @@ -1,22 +0,0 @@ -const generalizedConvexStratDeployment = require("../utils/generalizedConvexStratDeployment"); -const { usddMetapoolLPCRVPid } = require("../utils/constants"); - -module.exports = generalizedConvexStratDeployment({ - deployName: "103_convex_usdd_meta_strategy", - forceDeploy: false, - mainTokenName: "USDD", - mainTokenSymbol: "USDD", - rewardTokenNames: ["CVX", "CRV"], - assets: ["DAI", "USDC", "USDT"], - pTokens: ["ThreePoolToken", "ThreePoolToken", "ThreePoolToken"], - platformAddress: ["ThreePool"], - cvxDepositorAddress: "0xF403C135812408BFbE8713b5A23a04b3D48AAE31", - metapoolAddress: "0xe6b5CC1B4b47305c58392CE3D359B10282FC36Ea", - metapoolLPToken: "0xe6b5CC1B4b47305c58392CE3D359B10282FC36Ea", - mainTokenAddress: "0x0c10bf8fcb7bf5412187a595ab97a3609160b5c6", // USDD - cvxRewardStakerAddress: "0x7D475cc8A5E0416f0e63042547aDB94ca7045A5b", - cvxDepositorPTokenId: usddMetapoolLPCRVPid, // 96 - redeployVault: false, - deployStrategyImplementation: false, - skipMainnetDeploy: true, -}); diff --git a/contracts/deploy/104_convex_busd_meta_strategy.js b/contracts/deploy/104_convex_busd_meta_strategy.js deleted file mode 100644 index e2266fc4fa..0000000000 --- a/contracts/deploy/104_convex_busd_meta_strategy.js +++ /dev/null @@ -1,22 +0,0 @@ -const generalizedConvexStratDeployment = require("../utils/generalizedConvexStratDeployment"); -const { busdMetapoolLPCRVPid } = require("../utils/constants"); - -module.exports = generalizedConvexStratDeployment({ - deployName: "104_convex_busd_meta_strategy", - forceDeploy: false, - mainTokenName: "Binance USD", - mainTokenSymbol: "BUSD", - rewardTokenNames: ["CVX", "CRV"], - assets: ["DAI", "USDC", "USDT"], - pTokens: ["ThreePoolToken", "ThreePoolToken", "ThreePoolToken"], - platformAddress: ["ThreePool"], - cvxDepositorAddress: "0xF403C135812408BFbE8713b5A23a04b3D48AAE31", - metapoolAddress: "0x4807862AA8b2bF68830e4C8dc86D0e9A998e085a", - metapoolLPToken: "0x4807862AA8b2bF68830e4C8dc86D0e9A998e085a", - mainTokenAddress: "0x4fabb145d64652a948d72533023f6e7a623c7c53", // BUSD - cvxRewardStakerAddress: "0xbD223812d360C9587921292D0644D18aDb6a2ad0", - cvxDepositorPTokenId: busdMetapoolLPCRVPid, // 34 - redeployVault: false, - deployStrategyImplementation: false, - skipMainnetDeploy: true, -}); diff --git a/contracts/test/strategies/generalized-meta.fork-test.js b/contracts/test/strategies/generalized-meta.fork-test.js index 819b0d2ded..287b361d83 100644 --- a/contracts/test/strategies/generalized-meta.fork-test.js +++ b/contracts/test/strategies/generalized-meta.fork-test.js @@ -11,40 +11,6 @@ const { } = require("../_metastrategies-fixtures"); const metastrategies = [ - { - token: "alUSD", - metapoolAddress: "0x43b4FdFD4Ff969587185cDB6f0BD875c5Fc83f8c", - lpToken: "0x43b4FdFD4Ff969587185cDB6f0BD875c5Fc83f8c", - metastrategyProxyName: "ConvexalUSDMetaStrategyProxy", - rewardPoolAddress: "0x02E2151D4F351881017ABdF2DD2b51150841d5B3", - skipMewTest: false, - }, - { - token: "mUSD", - metapoolAddress: "0x8474DdbE98F5aA3179B3B3F5942D724aFcdec9f6", - lpToken: "0x1aef73d49dedc4b1778d0706583995958dc862e6", - metastrategyProxyName: "ConvexmUSDMetaStrategyProxy", - rewardPoolAddress: "0xDBFa6187C79f4fE4Cda20609E75760C5AaE88e52", - // metapool implementation wont allow tilting of the pools the way this test does it - // and then withdrawing liquidity - skipMewTest: false, - }, - { - token: "USDD", - metapoolAddress: "0xe6b5CC1B4b47305c58392CE3D359B10282FC36Ea", - lpToken: "0xe6b5CC1B4b47305c58392CE3D359B10282FC36Ea", - metastrategyProxyName: "ConvexUSDDMetaStrategyProxy", - rewardPoolAddress: "0x7D475cc8A5E0416f0e63042547aDB94ca7045A5b", - skipMewTest: false, - }, - { - token: "BUSD", - metapoolAddress: "0x4807862AA8b2bF68830e4C8dc86D0e9A998e085a", - lpToken: "0x4807862AA8b2bF68830e4C8dc86D0e9A998e085a", - metastrategyProxyName: "ConvexBUSDMetaStrategyProxy", - rewardPoolAddress: "0xbD223812d360C9587921292D0644D18aDb6a2ad0", - skipMewTest: false, - }, { token: "LUSD", metapoolAddress: "0xEd279fDD11cA84bEef15AF5D39BB4d4bEE23F0cA", diff --git a/contracts/test/vault/vault.fork-test.js b/contracts/test/vault/vault.fork-test.js index c42bb214a6..c43b4763e0 100644 --- a/contracts/test/vault/vault.fork-test.js +++ b/contracts/test/vault/vault.fork-test.js @@ -234,9 +234,6 @@ forkOnlyDescribe("ForkTest: Vault", function () { "0x5A4eEe58744D1430876d5cA93cAB5CcB763C037D", // Morpho MetaStrategy // TODO: Hard-code these after deploy "0x050c4FcA28725d975c2896682eBD2905D2E58E84", // alUSD MetaStrategy - "0xdF58F78cebbb2A60740eD2f86cDf0545a485102F", // mUSD MetaStrategy - "0xB262b69d1dB3dc092C73384B8553DA3d00e93682", // USDD MetaStrategy - "0xD2001BaF4E726dAfd6589D5c7bf8C74d59E48438", // BUSD MetaStrategy "0xA27A68886fb6dB6e6E41910695FE913d4b2BB254", // LUSD MetaStrategy ]; diff --git a/contracts/utils/constants.js b/contracts/utils/constants.js index 7adc640d91..7a9e208767 100644 --- a/contracts/utils/constants.js +++ b/contracts/utils/constants.js @@ -1,11 +1,6 @@ const threeCRVPid = 9; const metapoolLPCRVPid = 56; -const musdMetapoolLPCRVPid = 14; -const fraxMetapoolLPCRVPid = 32; const lusdMetapoolLPCRVPid = 33; -const busdMetapoolLPCRVPid = 34; -const alusdMetapoolLPCRVPid = 36; -const usddMetapoolLPCRVPid = 96; const { BigNumber } = require("ethers"); const MAX_UINT256 = BigNumber.from( "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" @@ -14,12 +9,7 @@ const MAX_UINT256 = BigNumber.from( module.exports = { threeCRVPid, metapoolLPCRVPid, - musdMetapoolLPCRVPid, - fraxMetapoolLPCRVPid, lusdMetapoolLPCRVPid, - alusdMetapoolLPCRVPid, - usddMetapoolLPCRVPid, - busdMetapoolLPCRVPid, MAX_UINT256, }; From 720742a9196f5773f990f7ac323c208ce91e4b62 Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 08:08:13 +0100 Subject: [PATCH 02/11] add the ability to execute (generalized strategy) proposals in fork test environment --- .../deploy/045_convex_lusd_meta_strategy.js | 1 + contracts/utils/deploy.js | 19 +++++++++++++++++++ .../utils/generalizedConvexStratDeployment.js | 2 ++ 3 files changed, 22 insertions(+) diff --git a/contracts/deploy/045_convex_lusd_meta_strategy.js b/contracts/deploy/045_convex_lusd_meta_strategy.js index 13ed88d3f8..fa10851ff6 100644 --- a/contracts/deploy/045_convex_lusd_meta_strategy.js +++ b/contracts/deploy/045_convex_lusd_meta_strategy.js @@ -19,4 +19,5 @@ module.exports = generalizedConvexStratDeployment({ redeployVault: false, deployStrategyImplementation: true, skipMainnetDeploy: false, + proposalId: 41 // just set to false if no proposal id yet }); diff --git a/contracts/utils/deploy.js b/contracts/utils/deploy.js index af3e290fc6..40b5d8a567 100644 --- a/contracts/utils/deploy.js +++ b/contracts/utils/deploy.js @@ -371,6 +371,25 @@ function deploymentWithProposal(opts, fn) { } }; } + + if (forceDeploy && isForkTest && proposalId) { + /** Just for context of this fork test change the id of the deployment script. This is required + * in circumstances when: + * - the deployment script has already been run on the mainnet + * - proposal has been either "Queued" or is still "New" + * - all the deployment artifacts and migration information is already present in the repo + * + * Problem: as part of normal deployment procedure we want to be able to simulate the + * execution of a proposal and run all the for tests on top of (after) the proposal execution. But + * since deployment artifacts are already present and migration file has already been updated + * the hardhat deploy will skip the deployment file (ignoring any force deploy/`skip` flags. + * Skipping the deployment file disables us to identify the New/Queued proposal id and executing it. + * + * For that reason for that specific circumstance change the id of deployment as a workaround so that + * Hardhat doesn't identify it as a separate deployment. + */ + main.id = `${deployName}_force` + } return main; } diff --git a/contracts/utils/generalizedConvexStratDeployment.js b/contracts/utils/generalizedConvexStratDeployment.js index 9193e5b7aa..c63843d7d7 100644 --- a/contracts/utils/generalizedConvexStratDeployment.js +++ b/contracts/utils/generalizedConvexStratDeployment.js @@ -21,12 +21,14 @@ module.exports = ({ // we only need to deploy the implementation contract for first time & when it changes deployStrategyImplementation, skipMainnetDeploy, + proposalId }) => { return deploymentWithProposal( { deployName, forceDeploy, forceSkip: isMainnet && skipMainnetDeploy, + proposalId }, async ({ assetAddresses, From d3925af51661a7363f1154b664cf1add9066a95f Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 11:18:13 +0100 Subject: [PATCH 03/11] prettier --- contracts/deploy/045_convex_lusd_meta_strategy.js | 2 +- contracts/utils/deploy.js | 14 +++++++------- .../utils/generalizedConvexStratDeployment.js | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/contracts/deploy/045_convex_lusd_meta_strategy.js b/contracts/deploy/045_convex_lusd_meta_strategy.js index fa10851ff6..aa11c73f02 100644 --- a/contracts/deploy/045_convex_lusd_meta_strategy.js +++ b/contracts/deploy/045_convex_lusd_meta_strategy.js @@ -19,5 +19,5 @@ module.exports = generalizedConvexStratDeployment({ redeployVault: false, deployStrategyImplementation: true, skipMainnetDeploy: false, - proposalId: 41 // just set to false if no proposal id yet + proposalId: 41, // just set to false if no proposal id yet }); diff --git a/contracts/utils/deploy.js b/contracts/utils/deploy.js index 40b5d8a567..ffc9dbd4b0 100644 --- a/contracts/utils/deploy.js +++ b/contracts/utils/deploy.js @@ -374,21 +374,21 @@ function deploymentWithProposal(opts, fn) { if (forceDeploy && isForkTest && proposalId) { /** Just for context of this fork test change the id of the deployment script. This is required - * in circumstances when: + * in circumstances when: * - the deployment script has already been run on the mainnet * - proposal has been either "Queued" or is still "New" * - all the deployment artifacts and migration information is already present in the repo - * - * Problem: as part of normal deployment procedure we want to be able to simulate the + * + * Problem: as part of normal deployment procedure we want to be able to simulate the * execution of a proposal and run all the for tests on top of (after) the proposal execution. But * since deployment artifacts are already present and migration file has already been updated - * the hardhat deploy will skip the deployment file (ignoring any force deploy/`skip` flags. + * the hardhat deploy will skip the deployment file (ignoring any force deploy/`skip` flags. * Skipping the deployment file disables us to identify the New/Queued proposal id and executing it. - * + * * For that reason for that specific circumstance change the id of deployment as a workaround so that - * Hardhat doesn't identify it as a separate deployment. + * Hardhat doesn't identify it as a separate deployment. */ - main.id = `${deployName}_force` + main.id = `${deployName}_force`; } return main; } diff --git a/contracts/utils/generalizedConvexStratDeployment.js b/contracts/utils/generalizedConvexStratDeployment.js index c63843d7d7..4efa003aad 100644 --- a/contracts/utils/generalizedConvexStratDeployment.js +++ b/contracts/utils/generalizedConvexStratDeployment.js @@ -21,14 +21,14 @@ module.exports = ({ // we only need to deploy the implementation contract for first time & when it changes deployStrategyImplementation, skipMainnetDeploy, - proposalId + proposalId, }) => { return deploymentWithProposal( { deployName, forceDeploy, forceSkip: isMainnet && skipMainnetDeploy, - proposalId + proposalId, }, async ({ assetAddresses, From 9549babf0b7690957c3844e6f91989ec2dde0670 Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 12:23:15 +0100 Subject: [PATCH 04/11] exchange alUSD for LUSD in unit tests and fix unit tests --- ...Metapool.sol => MockCurveLUSDMetapool.sol} | 4 +- .../curve/{MockalUSD.sol => MockLUSD.sol} | 4 +- contracts/deploy/000_mock.js | 2 +- contracts/deploy/001_core.js | 78 +++++++++---------- contracts/test/_fixture.js | 42 +++++----- contracts/test/helpers.js | 8 +- contracts/test/strategies/generalized-meta.js | 38 ++++----- contracts/utils/addresses.js | 3 +- 8 files changed, 91 insertions(+), 88 deletions(-) rename contracts/contracts/mocks/curve/{MockCurvealUSDMetapool.sol => MockCurveLUSDMetapool.sol} (65%) rename contracts/contracts/mocks/curve/{MockalUSD.sol => MockLUSD.sol} (51%) diff --git a/contracts/contracts/mocks/curve/MockCurvealUSDMetapool.sol b/contracts/contracts/mocks/curve/MockCurveLUSDMetapool.sol similarity index 65% rename from contracts/contracts/mocks/curve/MockCurvealUSDMetapool.sol rename to contracts/contracts/mocks/curve/MockCurveLUSDMetapool.sol index ed10ba8e55..324193a0fe 100644 --- a/contracts/contracts/mocks/curve/MockCurvealUSDMetapool.sol +++ b/contracts/contracts/mocks/curve/MockCurveLUSDMetapool.sol @@ -4,9 +4,9 @@ pragma solidity ^0.8.0; import { MockCurveAbstractMetapool } from "./MockCurveAbstractMetapool.sol"; import "../MintableERC20.sol"; -contract MockCurvealUSDMetapool is MockCurveAbstractMetapool { +contract MockCurveLUSDMetapool is MockCurveAbstractMetapool { constructor(address[2] memory _coins) - ERC20("Curve.fi Factory USD Metapool: alUSD", "ALUSD3CRV-f") + ERC20("Curve.fi Factory USD Metapool: LUSD", "LUSD3CRV-f") { coins = _coins; } diff --git a/contracts/contracts/mocks/curve/MockalUSD.sol b/contracts/contracts/mocks/curve/MockLUSD.sol similarity index 51% rename from contracts/contracts/mocks/curve/MockalUSD.sol rename to contracts/contracts/mocks/curve/MockLUSD.sol index 4685774903..d97952f4b4 100644 --- a/contracts/contracts/mocks/curve/MockalUSD.sol +++ b/contracts/contracts/mocks/curve/MockLUSD.sol @@ -3,6 +3,6 @@ pragma solidity ^0.8.0; import "../MintableERC20.sol"; -contract MockalUSD is MintableERC20 { - constructor() ERC20("alUSD", "alUSD Token") {} +contract MockLUSD is MintableERC20 { + constructor() ERC20("LUSD", "Liquity Token") {} } diff --git a/contracts/deploy/000_mock.js b/contracts/deploy/000_mock.js index a2d8c3be38..ee6306d48b 100644 --- a/contracts/deploy/000_mock.js +++ b/contracts/deploy/000_mock.js @@ -227,7 +227,7 @@ const deployMocks = async ({ getNamedAccounts, deployments }) => { args: [[dai.address, usdc.address, usdt.address], threePoolToken.address], }); - await deploy("MockalUSD", { + await deploy("MockLUSD", { from: deployerAddr, }); diff --git a/contracts/deploy/001_core.js b/contracts/deploy/001_core.js index 22896e3487..3b533f1812 100644 --- a/contracts/deploy/001_core.js +++ b/contracts/deploy/001_core.js @@ -14,7 +14,7 @@ const { } = require("../utils/deploy"); const { metapoolLPCRVPid, - alusdMetapoolLPCRVPid, + lusdMetapoolLPCRVPid, } = require("../utils/constants"); /** @@ -301,45 +301,45 @@ const deployConvexStrategy = async () => { }; /** - * Deploys a Convex Generalized Meta Strategy with alUSD token configuration + * Deploys a Convex Generalized Meta Strategy with LUSD token configuration */ -const deployConvexalUSDMetaStrategy = async () => { +const deployConvexLUSDMetaStrategy = async () => { const assetAddresses = await getAssetAddresses(deployments); const { deployerAddr, governorAddr } = await getNamedAccounts(); // Signers const sDeployer = await ethers.provider.getSigner(deployerAddr); const sGovernor = await ethers.provider.getSigner(governorAddr); - await deployWithConfirmation("ConvexalUSDMetaStrategyProxy"); - const cConvexalUSDMetaStrategyProxy = await ethers.getContract( - "ConvexalUSDMetaStrategyProxy" + await deployWithConfirmation("ConvexLUSDMetaStrategyProxy"); + const cConvexLUSDMetaStrategyProxy = await ethers.getContract( + "ConvexLUSDMetaStrategyProxy" ); - const dConvexalUSDMetaStrategy = await deployWithConfirmation( + const dConvexLUSDMetaStrategy = await deployWithConfirmation( "ConvexGeneralizedMetaStrategy" ); - const cConvexalUSDMetaStrategy = await ethers.getContractAt( + const cConvexLUSDMetaStrategy = await ethers.getContractAt( "ConvexGeneralizedMetaStrategy", - cConvexalUSDMetaStrategyProxy.address + cConvexLUSDMetaStrategyProxy.address ); await withConfirmation( - cConvexalUSDMetaStrategyProxy["initialize(address,address,bytes)"]( - dConvexalUSDMetaStrategy.address, + cConvexLUSDMetaStrategyProxy["initialize(address,address,bytes)"]( + dConvexLUSDMetaStrategy.address, deployerAddr, [] ) ); - log("Initialized ConvexalUSDMetaStrategyProxy"); + log("Initialized ConvexLUSDMetaStrategyProxy"); // Initialize Strategies const cVaultProxy = await ethers.getContract("VaultProxy"); const mockBooster = await ethers.getContract("MockBooster"); const mockRewardPool = await ethers.getContract("MockRewardPool"); - const alUsd = await ethers.getContract("MockalUSD"); + const LUSD = await ethers.getContract("MockLUSD"); await withConfirmation( - cConvexalUSDMetaStrategy + cConvexLUSDMetaStrategy .connect(sDeployer) [ "initialize(address[],address[],address[],(address,address,address,address,address,address,address,uint256))" @@ -355,32 +355,32 @@ const deployConvexalUSDMetaStrategy = async () => { assetAddresses.ThreePool, cVaultProxy.address, mockBooster.address, // _cvxDepositorAddress, - assetAddresses.ThreePoolalUSDMetapool, // metapool address, - alUsd.address, // alUsd + assetAddresses.ThreePoolLUSDMetapool, // metapool address, + LUSD.address, // LUSD mockRewardPool.address, // _cvxRewardStakerAddress, - assetAddresses.alUSDMetapoolToken, // metapoolLpToken - alusdMetapoolLPCRVPid, // _cvxDepositorPTokenId + assetAddresses.LUSDMetapoolToken, // metapoolLpToken + lusdMetapoolLPCRVPid, // _cvxDepositorPTokenId ] ) ); - log("Initialized ConvexalUSDMetaStrategy"); + log("Initialized ConvexLUSDMetaStrategy"); await withConfirmation( - cConvexalUSDMetaStrategy.connect(sDeployer).transferGovernance(governorAddr) + cConvexLUSDMetaStrategy.connect(sDeployer).transferGovernance(governorAddr) ); - log(`ConvexalUSDMetaStrategy transferGovernance(${governorAddr}) called`); + log(`ConvexLUSDMetaStrategy transferGovernance(${governorAddr}) called`); // On Mainnet the governance transfer gets executed separately, via the // multi-sig wallet. On other networks, this migration script can claim // governance by the governor. if (!isMainnet) { await withConfirmation( - cConvexalUSDMetaStrategy + cConvexLUSDMetaStrategy .connect(sGovernor) // Claim governance with governor .claimGovernance() ); - log("Claimed governance for ConvexalUSDMetaStrategy"); + log("Claimed governance for ConvexLUSDMetaStrategy"); } - return cConvexalUSDMetaStrategy; + return cConvexLUSDMetaStrategy; }; /** @@ -614,17 +614,17 @@ const configureStrategies = async (harvesterProxy) => { metaStrategy.connect(sGovernor).setHarvesterAddress(harvesterProxy.address) ); - const alUSDMetaStrategyProxy = await ethers.getContract( - "ConvexalUSDMetaStrategyProxy" + const LUSDMetaStrategyProxy = await ethers.getContract( + "ConvexLUSDMetaStrategyProxy" ); - const alUSDMetaStrategy = await ethers.getContractAt( + const LUSDMetaStrategy = await ethers.getContractAt( "ConvexGeneralizedMetaStrategy", - alUSDMetaStrategyProxy.address + LUSDMetaStrategyProxy.address ); await withConfirmation( - alUSDMetaStrategy - .connect(sGovernor) - .setHarvesterAddress(harvesterProxy.address) + LUSDMetaStrategy.connect(sGovernor).setHarvesterAddress( + harvesterProxy.address + ) ); const threePoolProxy = await ethers.getContract("ThreePoolStrategyProxy"); @@ -823,20 +823,20 @@ const deployCurveMetapoolMocks = async () => { }; // deploy curve metapool mocks -const deployCurvealUSDMetapoolMocks = async () => { +const deployCurveLUSDMetapoolMocks = async () => { const { deployerAddr } = await hre.getNamedAccounts(); const assetAddresses = await getAssetAddresses(deployments); - const alUsd = await ethers.getContract("MockalUSD"); + const LUSD = await ethers.getContract("MockLUSD"); - await hre.deployments.deploy("MockCurvealUSDMetapool", { + await hre.deployments.deploy("MockCurveLUSDMetapool", { from: deployerAddr, - args: [[alUsd.address, assetAddresses.ThreePoolToken]], + args: [[LUSD.address, assetAddresses.ThreePoolToken]], }); - const alUSDMetapoolToken = await ethers.getContract("MockCurvealUSDMetapool"); + const LUSDMetapoolToken = await ethers.getContract("MockCurveLUSDMetapool"); const mockBooster = await ethers.getContract("MockBooster"); - await mockBooster.setPool(alusdMetapoolLPCRVPid, alUSDMetapoolToken.address); + await mockBooster.setPool(lusdMetapoolLPCRVPid, LUSDMetapoolToken.address); }; // Deploy the Flipper trading contract @@ -967,13 +967,13 @@ const main = async () => { await deployOracles(); await deployCore(); await deployCurveMetapoolMocks(); - await deployCurvealUSDMetapoolMocks(); + await deployCurveLUSDMetapoolMocks(); await deployCompoundStrategy(); await deployAaveStrategy(); await deployThreePoolStrategy(); await deployConvexStrategy(); await deployConvexOUSDMetaStrategy(); - await deployConvexalUSDMetaStrategy(); + await deployConvexLUSDMetaStrategy(); const harvesterProxy = await deployHarvester(); await configureVault(harvesterProxy); await configureStrategies(harvesterProxy); diff --git a/contracts/test/_fixture.js b/contracts/test/_fixture.js index 9f3de3212f..cf958ed325 100644 --- a/contracts/test/_fixture.js +++ b/contracts/test/_fixture.js @@ -131,7 +131,7 @@ async function defaultFixture() { aaveIncentivesController, mockNonRebasing, mockNonRebasingTwo, - alUSD; + LUSD; let chainlinkOracleFeedDAI, chainlinkOracleFeedUSDT, @@ -146,7 +146,7 @@ async function defaultFixture() { morpho, morphoCompoundStrategy, morphoLens, - alUSDMetapoolToken, + LUSDMetapoolToken, threePoolGauge, aaveAddressProvider, uniswapPairOUSD_USDT, @@ -155,8 +155,8 @@ async function defaultFixture() { cvx, cvxBooster, cvxRewardPool, - alUSDMetaStrategyProxy, - alUSDMetaStrategy; + LUSDMetaStrategyProxy, + LUSDMetaStrategy; if (isFork) { usdt = await ethers.getContractAt(usdtAbi, addresses.mainnet.USDT); @@ -169,7 +169,7 @@ async function defaultFixture() { crv = await ethers.getContractAt(erc20Abi, addresses.mainnet.CRV); cvx = await ethers.getContractAt(erc20Abi, addresses.mainnet.CVX); ogn = await ethers.getContractAt(erc20Abi, addresses.mainnet.OGN); - alUSD = await ethers.getContractAt(erc20Abi, addresses.mainnet.alUSD); + LUSD = await ethers.getContractAt(erc20Abi, addresses.mainnet.LUSD); aave = await ethers.getContractAt(erc20Abi, addresses.mainnet.Aave); morpho = await ethers.getContractAt(morphoAbi, addresses.mainnet.Morpho); morphoLens = await ethers.getContractAt( @@ -208,7 +208,7 @@ async function defaultFixture() { tusd = await ethers.getContract("MockTUSD"); usdc = await ethers.getContract("MockUSDC"); ogn = await ethers.getContract("MockOGN"); - alUSD = await ethers.getContract("MockalUSD"); + LUSD = await ethers.getContract("MockLUSD"); ogv = await ethers.getContract("MockOGV"); nonStandardToken = await ethers.getContract("MockNonStandardToken"); @@ -223,7 +223,7 @@ async function defaultFixture() { threePool = await ethers.getContract("MockCurvePool"); threePoolToken = await ethers.getContract("Mock3CRV"); metapoolToken = await ethers.getContract("MockCurveMetapool"); - alUSDMetapoolToken = await ethers.getContract("MockCurvealUSDMetapool"); + LUSDMetapoolToken = await ethers.getContract("MockCurveLUSDMetapool"); threePoolGauge = await ethers.getContract("MockCurveGauge"); cvxBooster = await ethers.getContract("MockBooster"); cvxRewardPool = await ethers.getContract("MockRewardPool"); @@ -273,12 +273,12 @@ async function defaultFixture() { flipper = await ethers.getContract("Flipper"); - alUSDMetaStrategyProxy = await ethers.getContract( - "ConvexalUSDMetaStrategyProxy" + LUSDMetaStrategyProxy = await ethers.getContract( + "ConvexLUSDMetaStrategyProxy" ); - alUSDMetaStrategy = await ethers.getContractAt( + LUSDMetaStrategy = await ethers.getContractAt( "ConvexGeneralizedMetaStrategy", - alUSDMetaStrategyProxy.address + LUSDMetaStrategyProxy.address ); } if (!isFork) { @@ -358,7 +358,7 @@ async function defaultFixture() { tusd, usdc, ogn, - alUSD, + LUSD, ogv, rewardsSource, nonStandardToken, @@ -380,11 +380,11 @@ async function defaultFixture() { metapoolToken, morpho, morphoLens, - alUSDMetapoolToken, + LUSDMetapoolToken, threePoolStrategy, convexStrategy, OUSDmetaStrategy, - alUSDMetaStrategy, + LUSDMetaStrategy, morphoCompoundStrategy, cvx, cvxBooster, @@ -840,9 +840,9 @@ async function withImpersonatedAccount(address, cb) { } /** - * Configure a Vault with only the alUSD Generalized Meta strategy. + * Configure a Vault with only the LUSD Generalized Meta strategy. */ -async function convexalUSDMetaVaultFixture() { +async function convexLUSDMetaVaultFixture() { const fixture = await loadFixture(defaultFixture); const { governorAddr } = await getNamedAccounts(); @@ -851,24 +851,24 @@ async function convexalUSDMetaVaultFixture() { // Add Convex Meta strategy await fixture.vault .connect(sGovernor) - .approveStrategy(fixture.alUSDMetaStrategy.address); + .approveStrategy(fixture.LUSDMetaStrategy.address); await fixture.harvester .connect(sGovernor) - .setSupportedStrategy(fixture.alUSDMetaStrategy.address, true); + .setSupportedStrategy(fixture.LUSDMetaStrategy.address, true); await fixture.vault .connect(sGovernor) .setAssetDefaultStrategy( fixture.usdt.address, - fixture.alUSDMetaStrategy.address + fixture.LUSDMetaStrategy.address ); await fixture.vault .connect(sGovernor) .setAssetDefaultStrategy( fixture.usdc.address, - fixture.alUSDMetaStrategy.address + fixture.LUSDMetaStrategy.address ); return fixture; } @@ -1125,7 +1125,7 @@ module.exports = { convexVaultFixture, convexMetaVaultFixture, convexGeneralizedMetaForkedFixture, - convexalUSDMetaVaultFixture, + convexLUSDMetaVaultFixture, morphoCompoundFixture, aaveVaultFixture, hackedVaultFixture, diff --git a/contracts/test/helpers.js b/contracts/test/helpers.js index 99b5a46971..8af72071c3 100644 --- a/contracts/test/helpers.js +++ b/contracts/test/helpers.js @@ -337,12 +337,12 @@ const getAssetAddresses = async (deployments) => { * metapool is not yet deployed. Just return without metapool info if it is not * yet available. */ - addressMap.ThreePoolalUSDMetapool = ( - await deployments.get("MockCurvealUSDMetapool") + addressMap.ThreePoolLUSDMetapool = ( + await deployments.get("MockCurveLUSDMetapool") ).address; // token is implemented by the same contract as the metapool - addressMap.alUSDMetapoolToken = ( - await deployments.get("MockCurvealUSDMetapool") + addressMap.LUSDMetapoolToken = ( + await deployments.get("MockCurveLUSDMetapool") ).address; } catch (e) { // do nothing diff --git a/contracts/test/strategies/generalized-meta.js b/contracts/test/strategies/generalized-meta.js index fa80223a3e..2287d19b69 100644 --- a/contracts/test/strategies/generalized-meta.js +++ b/contracts/test/strategies/generalized-meta.js @@ -1,6 +1,6 @@ const { expect } = require("chai"); const { utils } = require("ethers"); -const { convexalUSDMetaVaultFixture } = require("../_fixture"); +const { convexLUSDMetaVaultFixture } = require("../_fixture"); const { daiUnits, @@ -11,7 +11,7 @@ const { isFork, } = require("../helpers"); -describe("Convex 3pool/Generalized (alUSD) Meta Strategy", function () { +describe("Convex 3pool/Generalized (LUSD) Meta Strategy", function () { if (isFork) { this.timeout(0); } @@ -23,8 +23,8 @@ describe("Convex 3pool/Generalized (alUSD) Meta Strategy", function () { governor, crv, cvx, - alUSDMetaStrategy, - alUSDMetapoolToken, + LUSDMetaStrategy, + LUSDMetapoolToken, cvxBooster, usdt, usdc, @@ -39,7 +39,7 @@ describe("Convex 3pool/Generalized (alUSD) Meta Strategy", function () { }; beforeEach(async function () { - const fixture = await loadFixture(convexalUSDMetaVaultFixture); + const fixture = await loadFixture(convexLUSDMetaVaultFixture); anna = fixture.anna; vault = fixture.vault; harvester = fixture.harvester; @@ -47,8 +47,8 @@ describe("Convex 3pool/Generalized (alUSD) Meta Strategy", function () { governor = fixture.governor; crv = fixture.crv; cvx = fixture.cvx; - alUSDMetaStrategy = fixture.alUSDMetaStrategy; - alUSDMetapoolToken = fixture.alUSDMetapoolToken; + LUSDMetaStrategy = fixture.LUSDMetaStrategy; + LUSDMetapoolToken = fixture.LUSDMetapoolToken; cvxBooster = fixture.cvxBooster; usdt = fixture.usdt; usdc = fixture.usdc; @@ -63,7 +63,7 @@ describe("Convex 3pool/Generalized (alUSD) Meta Strategy", function () { await expect(anna).to.have.a.balanceOf("30000", ousd); await expect(cvxBooster).has.an.approxBalanceOf( "30000", - alUSDMetapoolToken + LUSDMetapoolToken ); }); @@ -74,7 +74,7 @@ describe("Convex 3pool/Generalized (alUSD) Meta Strategy", function () { await expect(anna).to.have.a.balanceOf("50000", ousd); await expect(cvxBooster).has.an.approxBalanceOf( "50000", - alUSDMetapoolToken + LUSDMetapoolToken ); }); @@ -109,20 +109,22 @@ describe("Convex 3pool/Generalized (alUSD) Meta Strategy", function () { // Anna sends her OUSD directly to Strategy await ousd .connect(anna) - .transfer(alUSDMetaStrategy.address, ousdUnits("8.0")); + .transfer(LUSDMetaStrategy.address, ousdUnits("8.0")); // Anna asks Governor for help - await alUSDMetaStrategy - .connect(governor) - .transferToken(ousd.address, ousdUnits("8.0")); + await LUSDMetaStrategy.connect(governor).transferToken( + ousd.address, + ousdUnits("8.0") + ); await expect(governor).has.a.balanceOf("8.0", ousd); }); it("Should not allow transfer of arbitrary token by non-Governor", async () => { // Naughty Anna await expect( - alUSDMetaStrategy - .connect(anna) - .transferToken(ousd.address, ousdUnits("8.0")) + LUSDMetaStrategy.connect(anna).transferToken( + ousd.address, + ousdUnits("8.0") + ) ).to.be.revertedWith("Caller is not the Governor"); }); }); @@ -131,7 +133,7 @@ describe("Convex 3pool/Generalized (alUSD) Meta Strategy", function () { it("Should allow the strategist to call harvest for a specific strategy", async () => { // prettier-ignore await harvester - .connect(governor)["harvest(address)"](alUSDMetaStrategy.address); + .connect(governor)["harvest(address)"](LUSDMetaStrategy.address); }); it("Should collect reward tokens using collect rewards on all strategies", async () => { @@ -156,7 +158,7 @@ describe("Convex 3pool/Generalized (alUSD) Meta Strategy", function () { await harvester.connect(governor)[ // eslint-disable-next-line "harvest(address)" - ](alUSDMetaStrategy.address); + ](LUSDMetaStrategy.address); await expect(await crv.balanceOf(harvester.address)).to.be.equal( utils.parseUnits("2", 18) diff --git a/contracts/utils/addresses.js b/contracts/utils/addresses.js index da190a683a..89abcb6fee 100644 --- a/contracts/utils/addresses.js +++ b/contracts/utils/addresses.js @@ -57,7 +57,8 @@ addresses.mainnet.CVXRewardsPool = "0x7D536a737C13561e0D2Decf1152a653B4e615158"; addresses.mainnet.openOracle = "0x922018674c12a7f0d394ebeef9b58f186cde13c1"; // OGN addresses.mainnet.OGN = "0x8207c1ffc5b6804f6024322ccf34f29c3541ae26"; -addresses.mainnet.alUSD = "0xBC6DA0FE9aD5f3b0d58160288917AA56653660E9"; +// LUSD +addresses.mainnet.LUSD = "0x5f98805A4E8be255a32880FDeC7F6728C6568bA0"; // OGV addresses.mainnet.OGV = "0x9c354503C38481a7A7a51629142963F98eCC12D0"; // veOGV From 6caf02069285802c3a13dd3ee885799fd2257b31 Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 16:48:56 +0100 Subject: [PATCH 05/11] add utlity to handle proposals on forked node more automatically --- .../deploy/045_convex_lusd_meta_strategy.js | 1 - contracts/tasks/governance.js | 2 +- contracts/utils/deploy.js | 142 +++++++++++++----- 3 files changed, 105 insertions(+), 40 deletions(-) diff --git a/contracts/deploy/045_convex_lusd_meta_strategy.js b/contracts/deploy/045_convex_lusd_meta_strategy.js index aa11c73f02..bf59b333e7 100644 --- a/contracts/deploy/045_convex_lusd_meta_strategy.js +++ b/contracts/deploy/045_convex_lusd_meta_strategy.js @@ -3,7 +3,6 @@ const { lusdMetapoolLPCRVPid } = require("../utils/constants"); module.exports = generalizedConvexStratDeployment({ deployName: "045_convex_lusd_meta_strategy", - forceDeploy: false, mainTokenName: "Liquity USD", mainTokenSymbol: "LUSD", rewardTokenNames: ["CVX", "CRV"], diff --git a/contracts/tasks/governance.js b/contracts/tasks/governance.js index 04e2683e25..d5a8ab18f4 100644 --- a/contracts/tasks/governance.js +++ b/contracts/tasks/governance.js @@ -76,7 +76,7 @@ async function executeOnFork(taskArguments) { ? Number(taskArguments.gaslimit) : null; console.log("Enqueueing and executing proposal", proposalId); - await executeProposalOnFork(proposalId, gasLimit); + await executeProposalOnFork({ proposalId, executeGasLimit: gasLimit }); } async function proposal(taskArguments, hre) { diff --git a/contracts/utils/deploy.js b/contracts/utils/deploy.js index ffc9dbd4b0..0ceea8dca4 100644 --- a/contracts/utils/deploy.js +++ b/contracts/utils/deploy.js @@ -182,7 +182,11 @@ const executeProposal = async (proposalArgs, description, opts = {}) => { * @param {Number} proposalId * @returns {Promise} */ -const executeProposalOnFork = async (proposalId, executeGasLimit = null) => { +const executeProposalOnFork = async ({ + proposalId, + executeGasLimit = null, + skipQueue = false, +}) => { if (!isFork) throw new Error("Can only be used on Fork"); // Get the guardian of the governor and impersonate it. @@ -192,12 +196,14 @@ const executeProposalOnFork = async (proposalId, executeGasLimit = null) => { const governor = await ethers.getContract("Governor"); - //First enqueue the proposal, then execute it. - await withConfirmation( - governor.connect(sGuardian).queue(proposalId, await getTxOpts()) - ); + if (!skipQueue) { + //First enqueue the proposal, then execute it. + await withConfirmation( + governor.connect(sGuardian).queue(proposalId, await getTxOpts()) + ); - log(`Proposal ${proposalId} queued`); + log(`Proposal ${proposalId} queued`); + } log("Advancing time by 48 hours + 1 second for TimeLock delay."); await advanceTime(172801); @@ -273,6 +279,57 @@ const sanityCheck = async () => { } }; +/** + * When in forked/fork test environment we want special handling of possibly active proposals: + * - if node is forked below the proposal block number deploy the migration file + * - if node is forked after the proposal block number check the status of proposal: + * - if proposal executed skip deployment + * - if proposal New / Queued execute it and skip deployment + * + * @returns bool -> when true the hardhat deployment is skipped + */ +const handlePossiblyActiveProposal = async ( + proposalId, + deployName, + governor +) => { + if (isFork && proposalId) { + const proposalCount = Number((await governor.proposalCount()).toString()); + // proposal has not yet been submitted on the forked node (with current block height) + if (proposalCount < proposalId) { + // execute the whole deployment normally + console.log( + `Proposal ${deployName} not yet submitted at this block height. Continue deploy.` + ); + return false; + } + + const proposalState = ["New", "Queue", "Expired", "Executed"][ + await governor.state(proposalId) + ]; + + if (["New", "Queue"].includes(proposalState)) { + console.log( + `Found proposal id: ${proposalId} on forked network. Executing proposal containing deployment of: ${deployName}` + ); + + // Skip queue if proposal is already queued + await executeProposalOnFork({ + proposalId, + skipQueue: proposalState === "Queue", + }); + // deployment ran, nothing else to do here + return true; + } else if (proposalState === "Executed") { + console.log(`Proposal ${deployName} already executed. Nothing to do.`); + // proposal has already been executed nothing to do here + return true; + } + } + + return false; +}; + /** * Shortcut to create a deployment for hardhat to use * @param {Object} options for deployment @@ -295,21 +352,10 @@ function deploymentWithProposal(opts, fn) { const { governorAddr } = await getNamedAccounts(); const governor = await ethers.getContractAt("Governor", governorAddr); - if (isFork) { - if (proposalId) { - const proposalState = ["New", "Queue", "Expired", "Executed"][ - await governor.state(proposalId) - ]; - - if (["New", "Queue"].includes(proposalState)) { - console.log( - `Found proposal id: ${proposalId} on forked network. Executing proposal containing deployment of: ${deployName}` - ); - await executeProposalOnFork(proposalId); - // deployment ran, nothing else to do here - return; - } - } + // proposal has either been already executed on forked node or just been executed + // no use of running the deploy script to create another + if (await handlePossiblyActiveProposal(proposalId, deployName, governor)) { + return; } await sanityCheck(); @@ -354,6 +400,7 @@ function deploymentWithProposal(opts, fn) { console.log(`${deployName} deploy done.`); return true; }; + main.id = deployName; main.dependencies = dependencies; if (forceSkip) { @@ -361,19 +408,7 @@ function deploymentWithProposal(opts, fn) { } else if (forceDeploy) { main.skip = () => false; } else { - main.skip = () => { - if (isFork) { - const networkName = isForkTest ? "hardhat" : "localhost"; - const migrations = require(`./../deployments/${networkName}/.migrations.json`); - return Boolean(migrations[deployName]); - } else { - return !isMainnet || isSmokeTest || isFork; - } - }; - } - - if (forceDeploy && isForkTest && proposalId) { - /** Just for context of this fork test change the id of the deployment script. This is required + /** Just for context of fork env change the id of the deployment script. This is required * in circumstances when: * - the deployment script has already been run on the mainnet * - proposal has been either "Queued" or is still "New" @@ -382,13 +417,44 @@ function deploymentWithProposal(opts, fn) { * Problem: as part of normal deployment procedure we want to be able to simulate the * execution of a proposal and run all the for tests on top of (after) the proposal execution. But * since deployment artifacts are already present and migration file has already been updated - * the hardhat deploy will skip the deployment file (ignoring any force deploy/`skip` flags. + * the hardhat deploy will skip the deployment file (ignoring even the force deploy/`skip` flags. * Skipping the deployment file disables us to identify the New/Queued proposal id and executing it. * - * For that reason for that specific circumstance change the id of deployment as a workaround so that - * Hardhat doesn't identify it as a separate deployment. + * For that reason for any deployment ran on fork with proposalId we change the id of deployment + * as a workaround so that Hardhat executes it. If proposal has already been executed the + * `runDeployment` function will exit without applying the deployment. + * + * And we can not package this inside of `skip` function since without this workaround it + * doesn't even get evaluated. */ - main.id = `${deployName}_force`; + if (isFork && proposalId) { + main.id = `${deployName}_force`; + } + + main.skip = async () => { + if (isFork) { + const networkName = isForkTest ? "hardhat" : "localhost"; + const migrations = require(`./../deployments/${networkName}/.migrations.json`); + const currentBlock = await ethers.provider.getBlockNumber(); + const block = await ethers.provider.getBlockNumber(currentBlock); + + if (proposalId) { + return false; + } else { + const skip = migrations[deployName] < currentBlock; + if (!skip) { + console.log( + ```Deploy ${deployName} has no proposal id and is deployed on the mainnet + with block number: ${migrations[deployName]} which is higher than forked + node block: ${currentBlock}. Applying migration.``` + ); + } + return skip; + } + } else { + return !isMainnet || isSmokeTest || isFork; + } + }; } return main; } From a8b69c346bd0d79519d08af18b1ab9f37852097a Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 16:53:21 +0100 Subject: [PATCH 06/11] remove alusd reference --- contracts/test/vault/vault.fork-test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/test/vault/vault.fork-test.js b/contracts/test/vault/vault.fork-test.js index c43b4763e0..991fa80af1 100644 --- a/contracts/test/vault/vault.fork-test.js +++ b/contracts/test/vault/vault.fork-test.js @@ -233,7 +233,6 @@ forkOnlyDescribe("ForkTest: Vault", function () { "0x89Eb88fEdc50FC77ae8a18aAD1cA0ac27f777a90", // OUSD MetaStrategy "0x5A4eEe58744D1430876d5cA93cAB5CcB763C037D", // Morpho MetaStrategy // TODO: Hard-code these after deploy - "0x050c4FcA28725d975c2896682eBD2905D2E58E84", // alUSD MetaStrategy "0xA27A68886fb6dB6e6E41910695FE913d4b2BB254", // LUSD MetaStrategy ]; From 9949640a64f355870010b4ab04d2fab9e99718a2 Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 16:55:32 +0100 Subject: [PATCH 07/11] better comments --- contracts/utils/deploy.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/contracts/utils/deploy.js b/contracts/utils/deploy.js index 0ceea8dca4..80dea435c3 100644 --- a/contracts/utils/deploy.js +++ b/contracts/utils/deploy.js @@ -313,20 +313,22 @@ const handlePossiblyActiveProposal = async ( `Found proposal id: ${proposalId} on forked network. Executing proposal containing deployment of: ${deployName}` ); - // Skip queue if proposal is already queued + // skip queue if proposal is already queued await executeProposalOnFork({ proposalId, skipQueue: proposalState === "Queue", }); - // deployment ran, nothing else to do here + + // proposal executed skip deployment return true; } else if (proposalState === "Executed") { console.log(`Proposal ${deployName} already executed. Nothing to do.`); - // proposal has already been executed nothing to do here + // proposal has already been executed skip deployment return true; } } + // run deployment return false; }; From 4cc2a79c93ef45b58f8db42dacab1a4ab8c1bd7f Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 16:56:52 +0100 Subject: [PATCH 08/11] better comment --- contracts/utils/deploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/utils/deploy.js b/contracts/utils/deploy.js index 80dea435c3..bb42a2267c 100644 --- a/contracts/utils/deploy.js +++ b/contracts/utils/deploy.js @@ -420,7 +420,7 @@ function deploymentWithProposal(opts, fn) { * execution of a proposal and run all the for tests on top of (after) the proposal execution. But * since deployment artifacts are already present and migration file has already been updated * the hardhat deploy will skip the deployment file (ignoring even the force deploy/`skip` flags. - * Skipping the deployment file disables us to identify the New/Queued proposal id and executing it. + * Skipping the deployment file prevents us to identify the New/Queued proposal id and executing it. * * For that reason for any deployment ran on fork with proposalId we change the id of deployment * as a workaround so that Hardhat executes it. If proposal has already been executed the From 1e3332da1a9576f83c731a4686f8ca089540f017 Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 17:17:41 +0100 Subject: [PATCH 09/11] simplify --- contracts/utils/deploy.js | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/contracts/utils/deploy.js b/contracts/utils/deploy.js index bb42a2267c..b4c30c3cd7 100644 --- a/contracts/utils/deploy.js +++ b/contracts/utils/deploy.js @@ -434,25 +434,8 @@ function deploymentWithProposal(opts, fn) { } main.skip = async () => { - if (isFork) { - const networkName = isForkTest ? "hardhat" : "localhost"; - const migrations = require(`./../deployments/${networkName}/.migrations.json`); - const currentBlock = await ethers.provider.getBlockNumber(); - const block = await ethers.provider.getBlockNumber(currentBlock); - - if (proposalId) { - return false; - } else { - const skip = migrations[deployName] < currentBlock; - if (!skip) { - console.log( - ```Deploy ${deployName} has no proposal id and is deployed on the mainnet - with block number: ${migrations[deployName]} which is higher than forked - node block: ${currentBlock}. Applying migration.``` - ); - } - return skip; - } + if (isFork && proposalId) { + return false; } else { return !isMainnet || isSmokeTest || isFork; } From 19e87435362f76fa52987f464e776e897c51fbb2 Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 17:19:43 +0100 Subject: [PATCH 10/11] update LUSD address --- contracts/test/vault/vault.fork-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/test/vault/vault.fork-test.js b/contracts/test/vault/vault.fork-test.js index 991fa80af1..dd4a6434f1 100644 --- a/contracts/test/vault/vault.fork-test.js +++ b/contracts/test/vault/vault.fork-test.js @@ -233,7 +233,7 @@ forkOnlyDescribe("ForkTest: Vault", function () { "0x89Eb88fEdc50FC77ae8a18aAD1cA0ac27f777a90", // OUSD MetaStrategy "0x5A4eEe58744D1430876d5cA93cAB5CcB763C037D", // Morpho MetaStrategy // TODO: Hard-code these after deploy - "0xA27A68886fb6dB6e6E41910695FE913d4b2BB254", // LUSD MetaStrategy + "0x7A192DD9Cc4Ea9bdEdeC9992df74F1DA55e60a19", // LUSD MetaStrategy ]; for (const s of strategies) { From 8b4059ac3be5d77d6032876d57540c09d3508853 Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Wed, 4 Jan 2023 17:20:05 +0100 Subject: [PATCH 11/11] correct placement --- contracts/test/vault/vault.fork-test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/test/vault/vault.fork-test.js b/contracts/test/vault/vault.fork-test.js index dd4a6434f1..b56ff66ab7 100644 --- a/contracts/test/vault/vault.fork-test.js +++ b/contracts/test/vault/vault.fork-test.js @@ -232,8 +232,9 @@ forkOnlyDescribe("ForkTest: Vault", function () { "0xEA2Ef2e2E5A749D4A66b41Db9aD85a38Aa264cb3", // Convex "0x89Eb88fEdc50FC77ae8a18aAD1cA0ac27f777a90", // OUSD MetaStrategy "0x5A4eEe58744D1430876d5cA93cAB5CcB763C037D", // Morpho MetaStrategy - // TODO: Hard-code these after deploy "0x7A192DD9Cc4Ea9bdEdeC9992df74F1DA55e60a19", // LUSD MetaStrategy + // TODO: Hard-code these after deploy + //"0x7A192DD9Cc4Ea9bdEdeC9992df74F1DA55e60a19", // LUSD MetaStrategy ]; for (const s of strategies) {