From 81b5ae2bcd74c65b18c6cb2f28732d39e53f0420 Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Thu, 5 May 2022 11:02:42 +0200 Subject: [PATCH 01/11] Fix BalancerPool2Lens pfei accounting --- contracts/pcv/balancer/BalancerPool2Lens.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/pcv/balancer/BalancerPool2Lens.sol b/contracts/pcv/balancer/BalancerPool2Lens.sol index ec9d45f4a..64a356451 100644 --- a/contracts/pcv/balancer/BalancerPool2Lens.sol +++ b/contracts/pcv/balancer/BalancerPool2Lens.sol @@ -119,6 +119,7 @@ contract BalancerPool2Lens is IPCVDepositBalances { } if (feiInPair) { uint256 otherReserves = _getIdealReserves(balances, prices, weights, j); + otherReserves = (otherReserves * bptsOwned) / totalSupply; return (reserves, otherReserves); } return (reserves, 0); From 41af6de97f87c81cb320f6dc7d9a23982838447b Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Thu, 5 May 2022 11:04:42 +0200 Subject: [PATCH 02/11] add oa_cr_fix proposal --- proposals/dao/oa_cr_fix.ts | 200 +++++++++++++++++++++++++++ proposals/description/oa_cr_fix.ts | 34 +++++ test/integration/proposals_config.ts | 63 +-------- 3 files changed, 240 insertions(+), 57 deletions(-) create mode 100644 proposals/dao/oa_cr_fix.ts create mode 100644 proposals/description/oa_cr_fix.ts diff --git a/proposals/dao/oa_cr_fix.ts b/proposals/dao/oa_cr_fix.ts new file mode 100644 index 000000000..ad29cc75c --- /dev/null +++ b/proposals/dao/oa_cr_fix.ts @@ -0,0 +1,200 @@ +import hre, { ethers, artifacts } from 'hardhat'; +import { expect } from 'chai'; +import { + DeployUpgradeFunc, + NamedAddresses, + SetupUpgradeFunc, + TeardownUpgradeFunc, + ValidateUpgradeFunc +} from '@custom-types/types'; +import { ZERO_ADDRESS, overwriteChainlinkAggregator } from '@test/helpers'; + +const fipNumber = 'oa_cr_fix'; +let pcvStatsBefore; + +// Do any deployments +// This should exclusively include new contract deployments +const deploy: DeployUpgradeFunc = async (deployAddress: string, addresses: NamedAddresses, logging: boolean) => { + // Deploy lens to report B-30FEI-70WETH as WETH and protocol-owned FEI + // (The new contract contains a fix) + const balancerPool2LensFactory = await ethers.getContractFactory('BalancerPool2Lens'); + const balancerLensBpt30Fei70WethFixed = await balancerPool2LensFactory.deploy( + addresses.gaugeLensBpt30Fei70WethGauge, // address _depositAddress + addresses.wethERC20, // address _token + '0x90291319f1d4ea3ad4db0dd8fe9e12baf749e845', // IWeightedPool _pool + addresses.chainlinkEthUsdOracleWrapper, // IOracle _reportedOracle + addresses.oneConstantOracle, // IOracle _otherOracle + false, // bool _feiIsReportedIn + true // bool _feiIsOther + ); + await balancerLensBpt30Fei70WethFixed.deployTransaction.wait(); + logging && console.log('balancerLensBpt30Fei70WethFixed: ', balancerLensBpt30Fei70WethFixed.address); + + return { + balancerLensBpt30Fei70WethFixed + }; +}; + +// Do any setup necessary for running the test. +// This could include setting up Hardhat to impersonate accounts, +// ensuring contracts have a specific state, etc. +const setup: SetupUpgradeFunc = async (addresses, oldContracts, contracts, logging) => { + console.log(`Setup of ${fipNumber} : reading CR oracle...`); + pcvStatsBefore = await contracts.collateralizationOracle.pcvStats(); + + // make sure oracle of B.AMM is fresh + // set Chainlink ETHUSD to a fixed 3,000$ value + await overwriteChainlinkAggregator(addresses.chainlinkEthUsdOracle, '300000000000', '8'); +}; + +// Tears down any changes made in setup() that need to be +// cleaned up before doing any validation checks. +const teardown: TeardownUpgradeFunc = async (addresses, oldContracts, contracts, logging) => { + console.log(`No actions to complete in teardown for fip${fipNumber}`); +}; + +// Run any validations required on the fip using mocha or console logging +// IE check balances, check state of contracts, etc. +const validate: ValidateUpgradeFunc = async (addresses, oldContracts, contracts, logging) => { + // Check the removed PCV Deposits + expect(await contracts.collateralizationOracle.depositToToken(addresses.rariPool8FeiPCVDepositWrapper)).to.be.equal( + ZERO_ADDRESS + ); + expect(await contracts.collateralizationOracle.depositToToken(addresses.rariPool8DaiPCVDeposit)).to.be.equal( + ZERO_ADDRESS + ); + expect(await contracts.collateralizationOracle.depositToToken(addresses.rariPool8LusdPCVDeposit)).to.be.equal( + ZERO_ADDRESS + ); + expect(await contracts.collateralizationOracle.depositToToken(addresses.rariPool18FeiPCVDepositWrapper)).to.be.equal( + ZERO_ADDRESS + ); + expect(await contracts.collateralizationOracle.depositToToken(addresses.rariPool27FeiPCVDepositWrapper)).to.be.equal( + ZERO_ADDRESS + ); + expect(await contracts.collateralizationOracle.depositToToken(addresses.rariPool146EthPCVDeposit)).to.be.equal( + ZERO_ADDRESS + ); + expect(await contracts.collateralizationOracle.depositToToken(addresses.convexPoolPCVDepositWrapper)).to.be.equal( + ZERO_ADDRESS + ); + + // Check the lens swap + expect(await contracts.collateralizationOracle.depositToToken(addresses.balancerLensBpt30Fei70Weth)).to.be.equal( + ZERO_ADDRESS + ); + expect(await contracts.collateralizationOracle.depositToToken(addresses.balancerLensBpt30Fei70WethFixed)).to.be.equal( + addresses.weth + ); + + // Check the new lens returned values + const balance = (await contracts.balancerLensBpt30Fei70WethFixed.balance()) / 1e18; + const resistantBalanceAndFei = await contracts.balancerLensBpt30Fei70WethFixed.resistantBalanceAndFei(); + const resistantBalance = resistantBalanceAndFei[0] / 1e18; + const resistantFei = resistantBalanceAndFei[1] / 1e18; + expect(balance).to.be.at.least(14000); + expect(balance).to.be.at.most(16000); + expect(resistantBalance).to.be.at.least(14000); + expect(resistantBalance).to.be.at.most(16000); + expect(resistantFei).to.be.at.least(17e6); + expect(resistantFei).to.be.at.most(20e6); + + // Check pcvStats + console.log('----------------------------------------------------'); + console.log('pcvStatsBefore.protocolControlledValue [M]e18 ', pcvStatsBefore.protocolControlledValue / 1e24); + console.log('pcvStatsBefore.userCirculatingFei [M]e18 ', pcvStatsBefore.userCirculatingFei / 1e24); + console.log('pcvStatsBefore.protocolEquity [M]e18 ', pcvStatsBefore.protocolEquity / 1e24); + const pcvStatsAfter = await contracts.collateralizationOracle.pcvStats(); + console.log('----------------------------------------------------'); + console.log('pcvStatsAfter.protocolControlledValue [M]e18 ', pcvStatsAfter.protocolControlledValue / 1e24); + console.log('pcvStatsAfter.userCirculatingFei [M]e18 ', pcvStatsAfter.userCirculatingFei / 1e24); + console.log('pcvStatsAfter.protocolEquity [M]e18 ', pcvStatsAfter.protocolEquity / 1e24); + console.log('----------------------------------------------------'); + console.log( + 'PCV diff [M]e18 ', + pcvStatsAfter.protocolControlledValue.sub(pcvStatsBefore.protocolControlledValue) / 1e24 + ); + console.log('Circ FEI diff [M]e18 ', pcvStatsAfter.userCirculatingFei.sub(pcvStatsBefore.userCirculatingFei) / 1e24); + console.log('Equity diff [M]e18 ', pcvStatsAfter.protocolEquity.sub(pcvStatsBefore.protocolEquity) / 1e24); + console.log('----------------------------------------------------'); + console.log('Removed PCV Deposit resistant balance :'); + console.log( + 'rariPool8FeiPCVDepositWrapper [M]e18 ', + (await contracts.rariPool8FeiPCVDepositWrapper.resistantBalanceAndFei())[0] / 1e24 + ); + console.log( + 'rariPool8DaiPCVDeposit [M]e18 ', + (await contracts.rariPool8DaiPCVDeposit.resistantBalanceAndFei())[0] / 1e24 + ); + console.log( + 'rariPool8LusdPCVDeposit [M]e18 ', + (await contracts.rariPool8LusdPCVDeposit.resistantBalanceAndFei())[0] / 1e24 + ); + console.log( + 'rariPool18FeiPCVDepositWrapper [M]e18 ', + (await contracts.rariPool18FeiPCVDepositWrapper.resistantBalanceAndFei())[0] / 1e24 + ); + console.log( + 'rariPool27FeiPCVDepositWrapper [M]e18 ', + (await contracts.rariPool27FeiPCVDepositWrapper.resistantBalanceAndFei())[0] / 1e24 + ); + console.log( + 'rariPool146EthPCVDeposit [M]e18 ', + ((await contracts.rariPool146EthPCVDeposit.resistantBalanceAndFei())[0] * 3000) / 1e24 + ); + console.log( + 'convexPoolPCVDepositWrapper [M]e18 ', + (await contracts.convexPoolPCVDepositWrapper.resistantBalanceAndFei())[0] / 1e24 + ); + console.log('----------------------------------------------------'); + console.log('Removed PCV Deposit resistant fei :'); + console.log( + 'rariPool8FeiPCVDepositWrapper [M]e18 ', + (await contracts.rariPool8FeiPCVDepositWrapper.resistantBalanceAndFei())[1] / 1e24 + ); + console.log( + 'rariPool8DaiPCVDeposit [M]e18 ', + (await contracts.rariPool8DaiPCVDeposit.resistantBalanceAndFei())[1] / 1e24 + ); + console.log( + 'rariPool8LusdPCVDeposit [M]e18 ', + (await contracts.rariPool8LusdPCVDeposit.resistantBalanceAndFei())[1] / 1e24 + ); + console.log( + 'rariPool18FeiPCVDepositWrapper [M]e18 ', + (await contracts.rariPool18FeiPCVDepositWrapper.resistantBalanceAndFei())[1] / 1e24 + ); + console.log( + 'rariPool27FeiPCVDepositWrapper [M]e18 ', + (await contracts.rariPool27FeiPCVDepositWrapper.resistantBalanceAndFei())[1] / 1e24 + ); + console.log( + 'rariPool146EthPCVDeposit [M]e18 ', + (await contracts.rariPool146EthPCVDeposit.resistantBalanceAndFei())[1] / 1e24 + ); + console.log( + 'convexPoolPCVDepositWrapper [M]e18 ', + (await contracts.convexPoolPCVDepositWrapper.resistantBalanceAndFei())[1] / 1e24 + ); + console.log('----------------------------------------------------'); + console.log( + 'old lens balance [M]e18 ', + ((await contracts.balancerLensBpt30Fei70Weth.resistantBalanceAndFei())[0] * 3000) / 1e24 + ); + console.log( + 'old lens fei [M]e18 ', + (await contracts.balancerLensBpt30Fei70Weth.resistantBalanceAndFei())[1] / 1e24 + ); + console.log( + 'new lens balance [M]e18 ', + ((await contracts.balancerLensBpt30Fei70WethFixed.resistantBalanceAndFei())[0] * 3000) / 1e24 + ); + console.log( + 'new lens fei [M]e18 ', + (await contracts.balancerLensBpt30Fei70WethFixed.resistantBalanceAndFei())[1] / 1e24 + ); + + // Check the lens swap +}; + +export { deploy, setup, teardown, validate }; diff --git a/proposals/description/oa_cr_fix.ts b/proposals/description/oa_cr_fix.ts new file mode 100644 index 000000000..2b45fea25 --- /dev/null +++ b/proposals/description/oa_cr_fix.ts @@ -0,0 +1,34 @@ +import { ProposalDescription } from '@custom-types/types'; + +const fip_x: ProposalDescription = { + title: 'OA CR Fixes', + commands: [ + { + target: 'collateralizationOracle', + values: '0', + method: 'swapDeposit(address,address)', + arguments: ['{balancerLensBpt30Fei70Weth}', '{balancerLensBpt30Fei70WethFixed}'], + description: 'Update B-70WETH-30FEI Lens' + }, + { + target: 'collateralizationOracle', + values: '0', + method: 'removeDeposits(address[])', + arguments: [ + [ + '{rariPool8FeiPCVDepositWrapper}', // Fuse Pool 8 FEI + '{rariPool8DaiPCVDeposit}', // Fuse Pool 8 DAI + '{rariPool8LusdPCVDeposit}', // Fuse Pool 8 LUSD + '{rariPool18FeiPCVDepositWrapper}', // Fuse Pool 18 FEI + '{rariPool27FeiPCVDepositWrapper}', // Fuse Pool 27 FEI + '{rariPool146EthPCVDeposit}', // Fuse Pool 146 ETH + '{convexPoolPCVDepositWrapper}' // Fuse Pool 156 FEI + ] + ], + description: 'Remove PCV Deposits with bad debt' + } + ], + description: 'Fix Collateralization Oracle config after the Fuse May 2022 hack.' +}; + +export default fip_x; diff --git a/test/integration/proposals_config.ts b/test/integration/proposals_config.ts index 4f0f1de8e..b8674d65c 100644 --- a/test/integration/proposals_config.ts +++ b/test/integration/proposals_config.ts @@ -1,8 +1,6 @@ import { ProposalCategory, ProposalsConfigMap } from '@custom-types/types'; -import fip_82 from '@proposals/description/fip_82'; -import fip_98 from '@proposals/description/fip_98'; -import fip_99 from '@proposals/description/fip_99'; +import oa_cr_fix from '@proposals/description/oa_cr_fix'; // import fip_xx_proposal from '@proposals/description/fip_xx'; @@ -18,63 +16,14 @@ const proposals: ProposalsConfigMap = { category: ProposalCategory.DAO } */ - fip_82: { - deploy: false, // deploy flag for whether to run deploy action during e2e tests or use mainnet state + oa_cr_fix: { + deploy: true, // deploy flag for whether to run deploy action during e2e tests or use mainnet state totalValue: 0, // amount of ETH to send to DAO execution - proposal: fip_82, // full proposal file, imported from '@proposals/description/fip_xx.ts' + proposal: oa_cr_fix, // full proposal file, imported from '@proposals/description/fip_xx.ts' proposalId: '', - affectedContractSignoff: [ - 'roleBastion', - 'podFactory', - 'podExecutor', - 'nopeDAO', - 'governanceMetadataRegistry', - 'core', - 'tribe', - 'feiDAOTimelock', - 'tribalCouncilTimelock', - 'tribalCouncilSafe', - 'podAdminGateway' - ], + affectedContractSignoff: [], deprecatedContractSignoff: [], - category: ProposalCategory.DAO - }, - fip_98: { - deploy: false, - proposalId: '47738997083165992958921925097327638388915944734650384828020246684763693471048', - affectedContractSignoff: [ - 'fei', - 'feiDAOTimelock', - 'voltFeiSwapContract', - 'collateralizationOracle', - 'volt', - 'voltOracle', - 'voltDepositWrapper', - 'pcvGuardian', - 'turboFusePCVDeposit' - ], - deprecatedContractSignoff: [], - category: ProposalCategory.DAO, - totalValue: 0, - proposal: fip_98 - }, - fip_99: { - deploy: false, - proposalId: null, - affectedContractSignoff: [ - 'collateralizationOracle', - 'ratioPCVControllerV2', - 'rariPool9RaiPCVDeposit', - 'aaveRaiPCVDeposit', - 'raiPCVDripController', - 'raiPriceBoundPSM', - 'pcvGuardian', - 'core' - ], - deprecatedContractSignoff: [], - category: ProposalCategory.DAO, - totalValue: 0, - proposal: fip_99 + category: ProposalCategory.OA } }; From 87031b0787a3ee240daa0f48ec7e1b4e3eafb065 Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Fri, 6 May 2022 10:30:25 +0200 Subject: [PATCH 03/11] Deploy lens & fix console logs/oracle mock --- package.json | 2 +- proposals/dao/oa_cr_fix.ts | 106 +++--------------- .../collateralizationOracle.ts | 2 +- protocol-configuration/mainnetAddresses.ts | 5 + test/integration/proposals_config.ts | 2 +- 5 files changed, 23 insertions(+), 94 deletions(-) diff --git a/package.json b/package.json index 180360149..db4beee2d 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "console:ropsten": "npx hardhat console --network ropsten", "clean": "forge clean && rm -rf artifacts", "test": "forge test --no-match-contract IntegrationTest", - "test:integration": "FORK_BLOCK=14516592; forge test --fork-url https://eth-mainnet.alchemyapi.io/v2/$MAINNET_ALCHEMY_API_KEY --fork-block-number $FORK_BLOCK --match-contract IntegrationTest", + "test:integration": "FORK_BLOCK=14722484; forge test --fork-url https://eth-mainnet.alchemyapi.io/v2/$MAINNET_ALCHEMY_API_KEY --fork-block-number $FORK_BLOCK --match-contract IntegrationTest", "test:integration:latest": "forge test --fork-url https://eth-mainnet.alchemyapi.io/v2/$MAINNET_ALCHEMY_API_KEY --match-contract IntegrationTest", "test:hardhat": "npx hardhat test", "test:hardhat:dependencies": "LOGGING=true NO_RESET=true npx hardhat test test/integration/tests/dependencies.ts", diff --git a/proposals/dao/oa_cr_fix.ts b/proposals/dao/oa_cr_fix.ts index ad29cc75c..7410d4592 100644 --- a/proposals/dao/oa_cr_fix.ts +++ b/proposals/dao/oa_cr_fix.ts @@ -42,9 +42,11 @@ const setup: SetupUpgradeFunc = async (addresses, oldContracts, contracts, loggi console.log(`Setup of ${fipNumber} : reading CR oracle...`); pcvStatsBefore = await contracts.collateralizationOracle.pcvStats(); + const ethPrice = (await contracts.chainlinkEthUsdOracleWrapper.read())[0].toString() / 1e10; + // make sure oracle of B.AMM is fresh // set Chainlink ETHUSD to a fixed 3,000$ value - await overwriteChainlinkAggregator(addresses.chainlinkEthUsdOracle, '300000000000', '8'); + await overwriteChainlinkAggregator(addresses.chainlinkEthUsdOracle, Math.round(ethPrice), '8'); }; // Tears down any changes made in setup() that need to be @@ -101,100 +103,22 @@ const validate: ValidateUpgradeFunc = async (addresses, oldContracts, contracts, // Check pcvStats console.log('----------------------------------------------------'); - console.log('pcvStatsBefore.protocolControlledValue [M]e18 ', pcvStatsBefore.protocolControlledValue / 1e24); - console.log('pcvStatsBefore.userCirculatingFei [M]e18 ', pcvStatsBefore.userCirculatingFei / 1e24); - console.log('pcvStatsBefore.protocolEquity [M]e18 ', pcvStatsBefore.protocolEquity / 1e24); + console.log(' pcvStatsBefore.protocolControlledValue [M]e18 ', pcvStatsBefore.protocolControlledValue / 1e24); + console.log(' pcvStatsBefore.userCirculatingFei [M]e18 ', pcvStatsBefore.userCirculatingFei / 1e24); + console.log(' pcvStatsBefore.protocolEquity [M]e18 ', pcvStatsBefore.protocolEquity / 1e24); const pcvStatsAfter = await contracts.collateralizationOracle.pcvStats(); console.log('----------------------------------------------------'); - console.log('pcvStatsAfter.protocolControlledValue [M]e18 ', pcvStatsAfter.protocolControlledValue / 1e24); - console.log('pcvStatsAfter.userCirculatingFei [M]e18 ', pcvStatsAfter.userCirculatingFei / 1e24); - console.log('pcvStatsAfter.protocolEquity [M]e18 ', pcvStatsAfter.protocolEquity / 1e24); - console.log('----------------------------------------------------'); - console.log( - 'PCV diff [M]e18 ', - pcvStatsAfter.protocolControlledValue.sub(pcvStatsBefore.protocolControlledValue) / 1e24 - ); - console.log('Circ FEI diff [M]e18 ', pcvStatsAfter.userCirculatingFei.sub(pcvStatsBefore.userCirculatingFei) / 1e24); - console.log('Equity diff [M]e18 ', pcvStatsAfter.protocolEquity.sub(pcvStatsBefore.protocolEquity) / 1e24); - console.log('----------------------------------------------------'); - console.log('Removed PCV Deposit resistant balance :'); - console.log( - 'rariPool8FeiPCVDepositWrapper [M]e18 ', - (await contracts.rariPool8FeiPCVDepositWrapper.resistantBalanceAndFei())[0] / 1e24 - ); - console.log( - 'rariPool8DaiPCVDeposit [M]e18 ', - (await contracts.rariPool8DaiPCVDeposit.resistantBalanceAndFei())[0] / 1e24 - ); - console.log( - 'rariPool8LusdPCVDeposit [M]e18 ', - (await contracts.rariPool8LusdPCVDeposit.resistantBalanceAndFei())[0] / 1e24 - ); - console.log( - 'rariPool18FeiPCVDepositWrapper [M]e18 ', - (await contracts.rariPool18FeiPCVDepositWrapper.resistantBalanceAndFei())[0] / 1e24 - ); - console.log( - 'rariPool27FeiPCVDepositWrapper [M]e18 ', - (await contracts.rariPool27FeiPCVDepositWrapper.resistantBalanceAndFei())[0] / 1e24 - ); - console.log( - 'rariPool146EthPCVDeposit [M]e18 ', - ((await contracts.rariPool146EthPCVDeposit.resistantBalanceAndFei())[0] * 3000) / 1e24 - ); - console.log( - 'convexPoolPCVDepositWrapper [M]e18 ', - (await contracts.convexPoolPCVDepositWrapper.resistantBalanceAndFei())[0] / 1e24 - ); + console.log(' pcvStatsAfter.protocolControlledValue [M]e18 ', pcvStatsAfter.protocolControlledValue / 1e24); + console.log(' pcvStatsAfter.userCirculatingFei [M]e18 ', pcvStatsAfter.userCirculatingFei / 1e24); + console.log(' pcvStatsAfter.protocolEquity [M]e18 ', pcvStatsAfter.protocolEquity / 1e24); console.log('----------------------------------------------------'); - console.log('Removed PCV Deposit resistant fei :'); - console.log( - 'rariPool8FeiPCVDepositWrapper [M]e18 ', - (await contracts.rariPool8FeiPCVDepositWrapper.resistantBalanceAndFei())[1] / 1e24 - ); - console.log( - 'rariPool8DaiPCVDeposit [M]e18 ', - (await contracts.rariPool8DaiPCVDeposit.resistantBalanceAndFei())[1] / 1e24 - ); - console.log( - 'rariPool8LusdPCVDeposit [M]e18 ', - (await contracts.rariPool8LusdPCVDeposit.resistantBalanceAndFei())[1] / 1e24 - ); - console.log( - 'rariPool18FeiPCVDepositWrapper [M]e18 ', - (await contracts.rariPool18FeiPCVDepositWrapper.resistantBalanceAndFei())[1] / 1e24 - ); - console.log( - 'rariPool27FeiPCVDepositWrapper [M]e18 ', - (await contracts.rariPool27FeiPCVDepositWrapper.resistantBalanceAndFei())[1] / 1e24 - ); - console.log( - 'rariPool146EthPCVDeposit [M]e18 ', - (await contracts.rariPool146EthPCVDeposit.resistantBalanceAndFei())[1] / 1e24 - ); - console.log( - 'convexPoolPCVDepositWrapper [M]e18 ', - (await contracts.convexPoolPCVDepositWrapper.resistantBalanceAndFei())[1] / 1e24 - ); + const pcvDiff = pcvStatsAfter.protocolControlledValue.sub(pcvStatsBefore.protocolControlledValue); + const cFeiDiff = pcvStatsAfter.userCirculatingFei.sub(pcvStatsBefore.userCirculatingFei); + const eqDiff = pcvStatsAfter.protocolEquity.sub(pcvStatsBefore.protocolEquity); + console.log(' PCV diff [M]e18 ', pcvDiff / 1e24); + console.log(' Circ FEI diff [M]e18 ', cFeiDiff / 1e24); + console.log(' Equity diff [M]e18 ', eqDiff / 1e24); console.log('----------------------------------------------------'); - console.log( - 'old lens balance [M]e18 ', - ((await contracts.balancerLensBpt30Fei70Weth.resistantBalanceAndFei())[0] * 3000) / 1e24 - ); - console.log( - 'old lens fei [M]e18 ', - (await contracts.balancerLensBpt30Fei70Weth.resistantBalanceAndFei())[1] / 1e24 - ); - console.log( - 'new lens balance [M]e18 ', - ((await contracts.balancerLensBpt30Fei70WethFixed.resistantBalanceAndFei())[0] * 3000) / 1e24 - ); - console.log( - 'new lens fei [M]e18 ', - (await contracts.balancerLensBpt30Fei70WethFixed.resistantBalanceAndFei())[1] / 1e24 - ); - - // Check the lens swap }; export { deploy, setup, teardown, validate }; diff --git a/protocol-configuration/collateralizationOracle.ts b/protocol-configuration/collateralizationOracle.ts index 94dc4861a..04a1eef3f 100644 --- a/protocol-configuration/collateralizationOracle.ts +++ b/protocol-configuration/collateralizationOracle.ts @@ -41,7 +41,7 @@ const collateralizationAddresses = { 'rariPool146EthPCVDeposit', 'wethDepositWrapper', 'balancerDepositFeiWeth', - 'balancerLensBpt30Fei70Weth', + 'balancerLensBpt30Fei70WethFixed', 'balancerLensVeBalWeth' ], dpi: ['rariPool19DpiPCVDepositWrapper', 'dpiDepositWrapper'], diff --git a/protocol-configuration/mainnetAddresses.ts b/protocol-configuration/mainnetAddresses.ts index f4f6076cb..1f9b803a7 100644 --- a/protocol-configuration/mainnetAddresses.ts +++ b/protocol-configuration/mainnetAddresses.ts @@ -394,6 +394,11 @@ const MainnetAddresses: MainnetAddresses = { balancerLensBpt30Fei70Weth: { artifactName: 'BalancerPool2Lens', address: '0xb31F75550e97A2C4c7AC8d4355032B8AE8b9584D', + category: AddressCategory.Deprecated + }, + balancerLensBpt30Fei70WethFixed: { + artifactName: 'BalancerPool2Lens', + address: '0x673f7DFA863b611dE657759aEDE629b260F4E682', category: AddressCategory.PCV }, balancerLensVeBalBal: { diff --git a/test/integration/proposals_config.ts b/test/integration/proposals_config.ts index b8674d65c..8f04f34f3 100644 --- a/test/integration/proposals_config.ts +++ b/test/integration/proposals_config.ts @@ -17,7 +17,7 @@ const proposals: ProposalsConfigMap = { } */ oa_cr_fix: { - deploy: true, // deploy flag for whether to run deploy action during e2e tests or use mainnet state + deploy: false, // deploy flag for whether to run deploy action during e2e tests or use mainnet state totalValue: 0, // amount of ETH to send to DAO execution proposal: oa_cr_fix, // full proposal file, imported from '@proposals/description/fip_xx.ts' proposalId: '', From 7bc539a46064fc2319757ef5a6a0e6ed04ceb77d Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Fri, 6 May 2022 14:43:25 +0200 Subject: [PATCH 04/11] update fork block --- hardhat.config.ts | 2 +- proposals/dao/oa_cr_fix.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 65d68c995..ef418e371 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -57,7 +57,7 @@ export default { forking: enableMainnetForking ? { url: `https://eth-mainnet.alchemyapi.io/v2/${mainnetAlchemyApiKey}`, - blockNumber: 14714028 // Thursday, May 5th + blockNumber: 14722484 // Friday, May 6th } : undefined }, diff --git a/proposals/dao/oa_cr_fix.ts b/proposals/dao/oa_cr_fix.ts index 7410d4592..48ac334cc 100644 --- a/proposals/dao/oa_cr_fix.ts +++ b/proposals/dao/oa_cr_fix.ts @@ -40,13 +40,13 @@ const deploy: DeployUpgradeFunc = async (deployAddress: string, addresses: Named // ensuring contracts have a specific state, etc. const setup: SetupUpgradeFunc = async (addresses, oldContracts, contracts, logging) => { console.log(`Setup of ${fipNumber} : reading CR oracle...`); - pcvStatsBefore = await contracts.collateralizationOracle.pcvStats(); - - const ethPrice = (await contracts.chainlinkEthUsdOracleWrapper.read())[0].toString() / 1e10; // make sure oracle of B.AMM is fresh // set Chainlink ETHUSD to a fixed 3,000$ value + const ethPrice = (await contracts.chainlinkEthUsdOracleWrapper.read())[0].toString() / 1e10; await overwriteChainlinkAggregator(addresses.chainlinkEthUsdOracle, Math.round(ethPrice), '8'); + + pcvStatsBefore = await contracts.collateralizationOracle.pcvStats(); }; // Tears down any changes made in setup() that need to be From 62fdc24ea1fee9987080e6cb7c31e2a2c63e5997 Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Fri, 6 May 2022 17:46:11 +0200 Subject: [PATCH 05/11] update dependencies file --- proposals/dao/oa_cr_fix.ts | 7 ++-- .../collateralizationOracle.ts | 15 +------ protocol-configuration/dependencies.ts | 41 +++++-------------- protocol-configuration/mainnetAddresses.ts | 18 ++++---- test/integration/proposals_config.ts | 13 +++++- test/integration/tests/dependencies.ts | 5 ++- 6 files changed, 41 insertions(+), 58 deletions(-) diff --git a/proposals/dao/oa_cr_fix.ts b/proposals/dao/oa_cr_fix.ts index 48ac334cc..cf8a64958 100644 --- a/proposals/dao/oa_cr_fix.ts +++ b/proposals/dao/oa_cr_fix.ts @@ -41,11 +41,12 @@ const deploy: DeployUpgradeFunc = async (deployAddress: string, addresses: Named const setup: SetupUpgradeFunc = async (addresses, oldContracts, contracts, logging) => { console.log(`Setup of ${fipNumber} : reading CR oracle...`); - // make sure oracle of B.AMM is fresh - // set Chainlink ETHUSD to a fixed 3,000$ value + // make sure ETH oracle is fresh (for B.AMM not to revert, etc) + // Read Chainlink ETHUSD price & override chainlink storage to make it a fresh value const ethPrice = (await contracts.chainlinkEthUsdOracleWrapper.read())[0].toString() / 1e10; await overwriteChainlinkAggregator(addresses.chainlinkEthUsdOracle, Math.round(ethPrice), '8'); + // read pcvStats pcvStatsBefore = await contracts.collateralizationOracle.pcvStats(); }; @@ -101,7 +102,7 @@ const validate: ValidateUpgradeFunc = async (addresses, oldContracts, contracts, expect(resistantFei).to.be.at.least(17e6); expect(resistantFei).to.be.at.most(20e6); - // Check pcvStats + // display pcvStats console.log('----------------------------------------------------'); console.log(' pcvStatsBefore.protocolControlledValue [M]e18 ', pcvStatsBefore.protocolControlledValue / 1e24); console.log(' pcvStatsBefore.userCirculatingFei [M]e18 ', pcvStatsBefore.userCirculatingFei / 1e24); diff --git a/protocol-configuration/collateralizationOracle.ts b/protocol-configuration/collateralizationOracle.ts index 04a1eef3f..b1f93bb8a 100644 --- a/protocol-configuration/collateralizationOracle.ts +++ b/protocol-configuration/collateralizationOracle.ts @@ -1,13 +1,10 @@ const collateralizationAddresses = { fei: [ 'feiOATimelockWrapper', - 'rariPool8FeiPCVDepositWrapper', 'rariPool6FeiPCVDepositWrapper', 'rariPool19FeiPCVDepositWrapper', 'rariPool24FeiPCVDepositWrapper', 'rariPool25FeiPCVDepositWrapper', - 'rariPool27FeiPCVDepositWrapper', - 'rariPool18FeiPCVDepositWrapper', 'rariPool90FeiPCVDepositWrapper', 'aaveFeiPCVDepositWrapper', 'rariPool79FeiPCVDepositWrapper', @@ -16,18 +13,11 @@ const collateralizationAddresses = { 'rariPool128FeiPCVDepositWrapper', 'rariPool22FeiPCVDepositWrapper', 'feiBuybackLensNoFee', - 'convexPoolPCVDepositWrapper', 'compoundPCVDepositWrapper', 'turboFusePCVDeposit' ], - lusd: [ - 'liquityFusePoolLusdPCVDeposit', - 'rariPool7LusdPCVDeposit', - 'bammDeposit', - 'lusdPSM', - 'rariPool8LusdPCVDeposit' - ], - dai: ['compoundDaiPCVDepositWrapper', 'daiFixedPricePSM', 'rariPool8DaiPCVDeposit'], + lusd: ['liquityFusePoolLusdPCVDeposit', 'rariPool7LusdPCVDeposit', 'bammDeposit', 'lusdPSM'], + dai: ['compoundDaiPCVDepositWrapper', 'daiFixedPricePSM'], usd: ['namedStaticPCVDepositWrapper', 'd3poolCurvePCVDeposit', 'd3poolConvexPCVDeposit'], bal: ['balancerDepositBalWeth', 'balancerLensVeBalBal'], cream: ['creamDepositWrapper'], @@ -38,7 +28,6 @@ const collateralizationAddresses = { 'uniswapPCVDeposit', 'ethTokemakPCVDeposit', 'ethPSM', - 'rariPool146EthPCVDeposit', 'wethDepositWrapper', 'balancerDepositFeiWeth', 'balancerLensBpt30Fei70WethFixed', diff --git a/protocol-configuration/dependencies.ts b/protocol-configuration/dependencies.ts index 95e70277b..3b8ff9669 100644 --- a/protocol-configuration/dependencies.ts +++ b/protocol-configuration/dependencies.ts @@ -73,7 +73,6 @@ const dependencies: DependencyMap = { 'liquityFusePoolLusdPCVDeposit', 'poolPartyFeiPCVDeposit', 'rariTimelock', - 'rariPool146EthPCVDeposit', 'rariPool18FeiPCVDeposit', 'rariPool19DpiPCVDeposit', 'rariPool19FeiPCVDeposit', @@ -405,9 +404,6 @@ const dependencies: DependencyMap = { poolPartyFeiPCVDeposit: { contractDependencies: ['core', 'fei'] }, - rariPool146EthPCVDeposit: { - contractDependencies: ['core', 'rariPool146Eth'] - }, rariPool146Comptroller: { contractDependencies: ['rariPool146FuseAdmin', 'rariPool146Eth'] }, @@ -415,7 +411,7 @@ const dependencies: DependencyMap = { contractDependencies: ['rariPool146Comptroller'] }, rariPool146Eth: { - contractDependencies: ['rariPool146Comptroller', 'rariPool146EthPCVDeposit'] + contractDependencies: ['rariPool146Comptroller'] }, rariPool18FeiPCVDeposit: { contractDependencies: ['core', 'fei'] @@ -523,23 +519,18 @@ const dependencies: DependencyMap = { 'feiBuybackLens', 'feiLusdLens', 'feiOATimelockWrapper', - 'rariPool18FeiPCVDepositWrapper', 'rariPool19DpiPCVDepositWrapper', 'rariPool19FeiPCVDepositWrapper', 'rariPool24FeiPCVDepositWrapper', 'rariPool25FeiPCVDepositWrapper', - 'rariPool27FeiPCVDepositWrapper', 'rariPool31FeiPCVDepositWrapper', 'rariPool6FeiPCVDepositWrapper', - 'rariPool8FeiPCVDepositWrapper', 'rariPool9RaiPCVDepositWrapper', 'rariPool90FeiPCVDepositWrapper', 'rariPool79FeiPCVDepositWrapper', 'rariPool72FeiPCVDepositWrapper', 'rariPool128FeiPCVDepositWrapper', 'rariPool22FeiPCVDepositWrapper', - 'rariPool8LusdPCVDeposit', - 'rariPool8DaiPCVDeposit', 'voltFusePCVDeposit', 'voltOracle', 'turboFusePCVDeposit', @@ -594,9 +585,6 @@ const dependencies: DependencyMap = { feiOATimelockWrapper: { contractDependencies: ['collateralizationOracle'] }, - rariPool18FeiPCVDepositWrapper: { - contractDependencies: ['collateralizationOracle'] - }, rariPool19DpiPCVDepositWrapper: { contractDependencies: ['collateralizationOracle'] }, @@ -609,9 +597,6 @@ const dependencies: DependencyMap = { rariPool25FeiPCVDepositWrapper: { contractDependencies: ['collateralizationOracle'] }, - rariPool27FeiPCVDepositWrapper: { - contractDependencies: ['collateralizationOracle'] - }, rariPool31FeiPCVDepositWrapper: { contractDependencies: ['collateralizationOracle', 'rariPool31FeiPCVDeposit'] }, @@ -636,9 +621,6 @@ const dependencies: DependencyMap = { rariPool22FeiPCVDepositWrapper: { contractDependencies: ['collateralizationOracle', 'rariPool22FeiPCVDeposit'] }, - rariPool8FeiPCVDepositWrapper: { - contractDependencies: ['collateralizationOracle'] - }, rariPool9RaiPCVDepositWrapper: { contractDependencies: ['collateralizationOracle'] }, @@ -684,7 +666,7 @@ const dependencies: DependencyMap = { 'uniswapPCVDeposit', 'balancerDepositBalWeth', 'balancerDepositFeiWeth', - 'balancerLensBpt30Fei70Weth', + 'balancerLensBpt30Fei70WethFixed', 'balancerLensVeBalBal', 'balancerLensVeBalWeth' ] @@ -725,7 +707,12 @@ const dependencies: DependencyMap = { contractDependencies: ['core', 'chainlinkEthUsdOracleWrapper', 'chainlinkCREAMEthOracle', 'collateralizationOracle'] }, oneConstantOracle: { - contractDependencies: ['core', 'collateralizationOracle', 'balancerDepositFeiWeth', 'balancerLensBpt30Fei70Weth'] + contractDependencies: [ + 'core', + 'collateralizationOracle', + 'balancerDepositFeiWeth', + 'balancerLensBpt30Fei70WethFixed' + ] }, tribeUsdCompositeOracle: { contractDependencies: [ @@ -928,7 +915,7 @@ const dependencies: DependencyMap = { contractDependencies: ['rariPool8MasterOracle'] }, rariPool8Dai: { - contractDependencies: ['rariPool8Comptroller', 'rariPool8DaiIrm', 'rariPool8DaiPCVDeposit'] + contractDependencies: ['rariPool8Comptroller', 'rariPool8DaiIrm'] }, rariPool8DaiIrm: { contractDependencies: ['rariPool8Dai'] @@ -1008,14 +995,8 @@ const dependencies: DependencyMap = { delayedPCVMoverWethUniToBal: { contractDependencies: ['core', 'ratioPCVControllerV2'] }, - rariPool8DaiPCVDeposit: { - contractDependencies: ['rariPool8Dai', 'collateralizationOracle'] - }, - rariPool8LusdPCVDeposit: { - contractDependencies: ['rariPool8Lusd', 'collateralizationOracle'] - }, rariPool8Lusd: { - contractDependencies: ['rariPool8LusdPCVDeposit', 'rariPool8Comptroller'] + contractDependencies: ['rariPool8Comptroller'] }, timelock: { contractDependencies: ['feiDAOTimelock'] @@ -1068,7 +1049,7 @@ const dependencies: DependencyMap = { balancerLensVeBalWeth: { contractDependencies: ['balUsdCompositeOracle', 'chainlinkEthUsdOracleWrapper'] }, - balancerLensBpt30Fei70Weth: { + balancerLensBpt30Fei70WethFixed: { contractDependencies: ['oneConstantOracle', 'chainlinkEthUsdOracleWrapper'] }, pcvGuardian: { diff --git a/protocol-configuration/mainnetAddresses.ts b/protocol-configuration/mainnetAddresses.ts index d0962effb..aa1d575f8 100644 --- a/protocol-configuration/mainnetAddresses.ts +++ b/protocol-configuration/mainnetAddresses.ts @@ -224,7 +224,7 @@ const MainnetAddresses: MainnetAddresses = { rariPool18FeiPCVDeposit: { artifactName: 'ERC20CompoundPCVDeposit', address: '0x5A8CB4556e5D5935Af06beab8292905f48131479', - category: AddressCategory.PCV_V1 + category: AddressCategory.Deprecated }, rariPool22FeiPCVDeposit: { artifactName: 'ERC20CompoundPCVDeposit', @@ -249,7 +249,7 @@ const MainnetAddresses: MainnetAddresses = { rariPool27FeiPCVDeposit: { artifactName: 'ERC20CompoundPCVDeposit', address: '0x91f50E3183a8CC30D2A981C3aFA85A2Bf6691c67', - category: AddressCategory.PCV_V1 + category: AddressCategory.Deprecated }, rariPool128FeiPCVDeposit: { artifactName: 'ERC20CompoundPCVDeposit', @@ -504,22 +504,22 @@ const MainnetAddresses: MainnetAddresses = { rariPool146EthPCVDeposit: { artifactName: 'EthCompoundPCVDeposit', address: '0xC68412B72e68c30D4E6c0854b439CBBe957146e4', - category: AddressCategory.PCV + category: AddressCategory.Deprecated }, rariPool8DaiPCVDeposit: { artifactName: 'ERC20CompoundPCVDeposit', address: '0x9CC46aB5A714f7cd24C59f33C5769039B5872491', - category: AddressCategory.PCV + category: AddressCategory.Deprecated }, rariPool8LusdPCVDeposit: { artifactName: 'ERC20CompoundPCVDeposit', address: '0xF846eE6E8EE9A6fbf51c7c65105CAbc041c048ad', - category: AddressCategory.PCV + category: AddressCategory.Deprecated }, rariPool18FeiPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', address: '0x07F2DD7E6A78D96c08D0a8212f4097dCC129d629', - category: AddressCategory.PCV + category: AddressCategory.Deprecated }, rariPool19DpiPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', @@ -549,7 +549,7 @@ const MainnetAddresses: MainnetAddresses = { rariPool27FeiPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', address: '0xe2e35097638F0Ff2EeCA2EF70F352Be37431945f', - category: AddressCategory.PCV + category: AddressCategory.Deprecated }, rariPool6FeiPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', @@ -564,7 +564,7 @@ const MainnetAddresses: MainnetAddresses = { rariPool8FeiPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', address: '0xD6598a23418c7FEf7c0Dc863265515B623B720F9', - category: AddressCategory.PCV + category: AddressCategory.Deprecated }, rariPool9FeiPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', @@ -1979,7 +1979,7 @@ const MainnetAddresses: MainnetAddresses = { convexPoolPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', address: '0x1370CA8655C255948d6c6110066d78680601B7c2', - category: AddressCategory.PCV + category: AddressCategory.Deprecated }, compoundPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', diff --git a/test/integration/proposals_config.ts b/test/integration/proposals_config.ts index 2c6b81452..e3988c24e 100644 --- a/test/integration/proposals_config.ts +++ b/test/integration/proposals_config.ts @@ -52,8 +52,17 @@ const proposals: ProposalsConfigMap = { totalValue: 0, // amount of ETH to send to DAO execution proposal: oa_cr_fix, // full proposal file, imported from '@proposals/description/fip_xx.ts' proposalId: '', - affectedContractSignoff: [], - deprecatedContractSignoff: [], + affectedContractSignoff: ['collateralizationOracle', 'balancerLensBpt30Fei70WethFixed'], + deprecatedContractSignoff: [ + 'balancerLensBpt30Fei70Weth', + 'rariPool8FeiPCVDepositWrapper', + 'rariPool8DaiPCVDeposit', + 'rariPool8LusdPCVDeposit', + 'rariPool18FeiPCVDepositWrapper', + 'rariPool27FeiPCVDepositWrapper', + 'rariPool146EthPCVDeposit', + 'convexPoolPCVDepositWrapper' + ], category: ProposalCategory.OA } }; diff --git a/test/integration/tests/dependencies.ts b/test/integration/tests/dependencies.ts index bfced5e5a..ce25a9cd3 100644 --- a/test/integration/tests/dependencies.ts +++ b/test/integration/tests/dependencies.ts @@ -112,7 +112,10 @@ describe('e2e-dependencies', function () { // addresses[deposit] may be undefined if a deposit is added to the // dependencies and permissions/collateralizationOracle files, but // is not yet deployed on the mainnet (i.e. in mainnetAddresses.ts). - expect(addresses[deposit].category).to.not.be.equal('Deprecated'); + expect(addresses[deposit].category).to.not.be.equal( + 'Deprecated', + 'Deposit [' + deposit + '] is in collateralizationoracle.ts and has AddressCategory.Deprecated' + ); } } } From 73ba60d3254a73c2c56ef56069bdb24862ec0687 Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Mon, 9 May 2022 17:16:20 +0200 Subject: [PATCH 06/11] use addresses.balancerFeiWethPool instead of hardcoded addr --- proposals/dao/oa_cr_fix.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/dao/oa_cr_fix.ts b/proposals/dao/oa_cr_fix.ts index cf8a64958..926c70597 100644 --- a/proposals/dao/oa_cr_fix.ts +++ b/proposals/dao/oa_cr_fix.ts @@ -21,7 +21,7 @@ const deploy: DeployUpgradeFunc = async (deployAddress: string, addresses: Named const balancerLensBpt30Fei70WethFixed = await balancerPool2LensFactory.deploy( addresses.gaugeLensBpt30Fei70WethGauge, // address _depositAddress addresses.wethERC20, // address _token - '0x90291319f1d4ea3ad4db0dd8fe9e12baf749e845', // IWeightedPool _pool + addresses.balancerFeiWethPool, // IWeightedPool _pool addresses.chainlinkEthUsdOracleWrapper, // IOracle _reportedOracle addresses.oneConstantOracle, // IOracle _otherOracle false, // bool _feiIsReportedIn From 8e95be4ed62ecbe6eede91ed5e1dc1c53047aad6 Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Mon, 9 May 2022 17:18:36 +0200 Subject: [PATCH 07/11] Add BalancerPool2Lens unit tests --- .../pcv/balancer/BalancerPool2Lens.test.ts | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 test/unit/pcv/balancer/BalancerPool2Lens.test.ts diff --git a/test/unit/pcv/balancer/BalancerPool2Lens.test.ts b/test/unit/pcv/balancer/BalancerPool2Lens.test.ts new file mode 100644 index 000000000..b65261f4c --- /dev/null +++ b/test/unit/pcv/balancer/BalancerPool2Lens.test.ts @@ -0,0 +1,115 @@ +import { getAddresses, getImpersonatedSigner, getCore, expectApproxAbs } from '@test/helpers'; +import chai, { expect } from 'chai'; +import CBN from 'chai-bn'; +import { ethers } from 'hardhat'; +import { Signer } from 'ethers'; +import { + BalancerPool2Lens, + MockERC20, + MockOracle, + MockVault, + MockPCVDepositV2, + MockWeightedPool +} from '@custom-types/contracts'; + +before(async () => { + chai.use(CBN(ethers.BigNumber)); +}); + +const toBN = ethers.BigNumber.from; + +describe('BalancerPool2Lens', function () { + let userAddress: string; + let pool: MockWeightedPool; + let vault: MockVault; + let token: MockERC20; + let oracle1: MockOracle; + let oracle2: MockOracle; + let deposit: MockPCVDepositV2; + let lens: BalancerPool2Lens; + + const impersonatedSigners: { [key: string]: Signer } = {}; + + before(async () => { + const addresses = await getAddresses(); + + // add any addresses you want to impersonate here + const impersonatedAddresses = [addresses.userAddress]; + + for (const address of impersonatedAddresses) { + impersonatedSigners[address] = await getImpersonatedSigner(address); + } + }); + + beforeEach(async function () { + ({ userAddress } = await getAddresses()); + + token = await (await ethers.getContractFactory('MockERC20')).deploy(); + const tokenB = await (await ethers.getContractFactory('MockERC20')).deploy(); + + vault = await (await ethers.getContractFactory('MockVault')).deploy([token.address, tokenB.address], userAddress); + + await vault.setBalances([ethers.constants.WeiPerEther.mul(20), ethers.constants.WeiPerEther.mul(30000)]); + + pool = await ethers.getContractAt('MockWeightedPool', await vault._pool()); + + const core = await getCore(); + deposit = await ( + await ethers.getContractFactory('MockPCVDepositV2') + ).deploy( + core.address, + pool.address, + 10000, // deposit reports 10000 LP tokens + 0 + ); + + await pool.mint(pool.address, 89999); + await pool.mint(deposit.address, 10000); + + // set weights to 70%, 30% + await pool.updateWeightsGradually(0, 0, [ + ethers.constants.WeiPerEther.div(100).mul(70), + ethers.constants.WeiPerEther.div(100).mul(30) + ]); + await pool.mockSetNormalizedWeights([ + ethers.constants.WeiPerEther.div(100).mul(70), + ethers.constants.WeiPerEther.div(100).mul(30) + ]); + + oracle1 = await (await ethers.getContractFactory('MockOracle')).deploy('3500'); + oracle2 = await (await ethers.getContractFactory('MockOracle')).deploy('1'); + + lens = await ( + await ethers.getContractFactory('BalancerPool2Lens') + ).deploy(deposit.address, token.address, pool.address, oracle1.address, oracle2.address, false, true); + }); + + // pool contains 20 tokenA, 30,000 tokenB + // tokenA price 3,500 $, tokenB price 1 $ + // -> pool contains 70,000$, 30,000$ + // pool weight 70% tokenA, 30% tokenB (currently balanced) + // userAddress owns 10% of the pool (10,000 / 100,000) + + it('initial state', async function () { + expect(await lens.balanceReportedIn()).to.be.equal(token.address); + expect(await lens.pool()).to.be.equal(pool.address); + expect(await lens.balancerVault()).to.be.equal(vault.address); + expect(await lens.feiInPair()).to.be.true; + expect(await lens.feiIsReportedIn()).to.be.false; + expect(await lens.reportedOracle()).to.be.equal(oracle1.address); + expect(await lens.otherOracle()).to.be.equal(oracle2.address); + + expect(await pool.balanceOf(pool.address)).to.be.equal('90000'); + expect(await pool.balanceOf(deposit.address)).to.be.equal('10000'); + }); + + it('balance', async function () { + expectApproxAbs(await lens.balance(), ethers.constants.WeiPerEther.mul('2'), '1'); + }); + + it('resistantBalanceAndFei', async function () { + const balances = await lens.resistantBalanceAndFei(); + expectApproxAbs(balances[0], ethers.constants.WeiPerEther.mul('2'), '1'); + expectApproxAbs(balances[1], ethers.constants.WeiPerEther.mul('3000'), '1'); + }); +}); From c6a7e5e228ef1c0f7a92f4d41f4297e45dc37172 Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Tue, 10 May 2022 10:20:59 +0200 Subject: [PATCH 08/11] Remove pool 90 FEI (float protocol) from accounting --- proposals/dao/oa_cr_fix.ts | 3 +++ proposals/description/oa_cr_fix.ts | 1 + protocol-configuration/collateralizationOracle.ts | 1 - protocol-configuration/dependencies.ts | 9 --------- protocol-configuration/mainnetAddresses.ts | 4 ++-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/proposals/dao/oa_cr_fix.ts b/proposals/dao/oa_cr_fix.ts index 926c70597..588660dc7 100644 --- a/proposals/dao/oa_cr_fix.ts +++ b/proposals/dao/oa_cr_fix.ts @@ -75,6 +75,9 @@ const validate: ValidateUpgradeFunc = async (addresses, oldContracts, contracts, expect(await contracts.collateralizationOracle.depositToToken(addresses.rariPool27FeiPCVDepositWrapper)).to.be.equal( ZERO_ADDRESS ); + expect(await contracts.collateralizationOracle.depositToToken(addresses.rariPool90FeiPCVDepositWrapper)).to.be.equal( + ZERO_ADDRESS + ); expect(await contracts.collateralizationOracle.depositToToken(addresses.rariPool146EthPCVDeposit)).to.be.equal( ZERO_ADDRESS ); diff --git a/proposals/description/oa_cr_fix.ts b/proposals/description/oa_cr_fix.ts index 2b45fea25..afce4dbd9 100644 --- a/proposals/description/oa_cr_fix.ts +++ b/proposals/description/oa_cr_fix.ts @@ -21,6 +21,7 @@ const fip_x: ProposalDescription = { '{rariPool8LusdPCVDeposit}', // Fuse Pool 8 LUSD '{rariPool18FeiPCVDepositWrapper}', // Fuse Pool 18 FEI '{rariPool27FeiPCVDepositWrapper}', // Fuse Pool 27 FEI + '{rariPool90FeiPCVDepositWrapper}', // Fuse Pool 90 FEI '{rariPool146EthPCVDeposit}', // Fuse Pool 146 ETH '{convexPoolPCVDepositWrapper}' // Fuse Pool 156 FEI ] diff --git a/protocol-configuration/collateralizationOracle.ts b/protocol-configuration/collateralizationOracle.ts index b1f93bb8a..cf204906f 100644 --- a/protocol-configuration/collateralizationOracle.ts +++ b/protocol-configuration/collateralizationOracle.ts @@ -5,7 +5,6 @@ const collateralizationAddresses = { 'rariPool19FeiPCVDepositWrapper', 'rariPool24FeiPCVDepositWrapper', 'rariPool25FeiPCVDepositWrapper', - 'rariPool90FeiPCVDepositWrapper', 'aaveFeiPCVDepositWrapper', 'rariPool79FeiPCVDepositWrapper', 'rariPool31FeiPCVDepositWrapper', diff --git a/protocol-configuration/dependencies.ts b/protocol-configuration/dependencies.ts index 3b8ff9669..f4f8bb13f 100644 --- a/protocol-configuration/dependencies.ts +++ b/protocol-configuration/dependencies.ts @@ -89,7 +89,6 @@ const dependencies: DependencyMap = { 'rariPool7FeiPCVDeposit', 'rariPool7LusdPCVDeposit', 'rariPool8FeiPCVDeposit', - 'rariPool90FeiPCVDeposit', 'rariPool91FeiPCVDeposit', 'rariPool9FeiPCVDeposit', 'rariPool9RaiPCVDeposit', @@ -168,7 +167,6 @@ const dependencies: DependencyMap = { 'rariPool79FeiPCVDeposit', 'rariPool7FeiPCVDeposit', 'rariPool8FeiPCVDeposit', - 'rariPool90FeiPCVDeposit', 'rariPool91FeiPCVDeposit', 'rariPool9FeiPCVDeposit', 'restrictedPermissions', @@ -461,9 +459,6 @@ const dependencies: DependencyMap = { rariPool8FeiPCVDeposit: { contractDependencies: ['core', 'rariPool8Fei', 'fei'] }, - rariPool90FeiPCVDeposit: { - contractDependencies: ['core', 'fei', 'rariPool90FeiPCVDepositWrapper'] - }, rariPool91FeiPCVDeposit: { contractDependencies: ['core', 'fei'] }, @@ -526,7 +521,6 @@ const dependencies: DependencyMap = { 'rariPool31FeiPCVDepositWrapper', 'rariPool6FeiPCVDepositWrapper', 'rariPool9RaiPCVDepositWrapper', - 'rariPool90FeiPCVDepositWrapper', 'rariPool79FeiPCVDepositWrapper', 'rariPool72FeiPCVDepositWrapper', 'rariPool128FeiPCVDepositWrapper', @@ -603,9 +597,6 @@ const dependencies: DependencyMap = { rariPool6FeiPCVDepositWrapper: { contractDependencies: ['collateralizationOracle'] }, - rariPool90FeiPCVDepositWrapper: { - contractDependencies: ['collateralizationOracle', 'rariPool90FeiPCVDeposit'] - }, rariPool79FeiPCVDepositWrapper: { contractDependencies: ['collateralizationOracle', 'rariPool79FeiPCVDeposit'] }, diff --git a/protocol-configuration/mainnetAddresses.ts b/protocol-configuration/mainnetAddresses.ts index aa1d575f8..cbd6b5bb4 100644 --- a/protocol-configuration/mainnetAddresses.ts +++ b/protocol-configuration/mainnetAddresses.ts @@ -314,7 +314,7 @@ const MainnetAddresses: MainnetAddresses = { rariPool90FeiPCVDeposit: { artifactName: 'ERC20CompoundPCVDeposit', address: '0x61d26126D2F8A44b41c1D8E1B1F276551DC8EEc6', - category: AddressCategory.PCV_V1 + category: AddressCategory.Deprecated }, rariPool91FeiPCVDeposit: { artifactName: 'ERC20CompoundPCVDeposit', @@ -584,7 +584,7 @@ const MainnetAddresses: MainnetAddresses = { rariPool90FeiPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', address: '0xec54148CbC47bFF8FCc5e04e5E8083aDb8aF9aD9', - category: AddressCategory.PCV + category: AddressCategory.Deprecated }, rariPool91FeiPCVDepositWrapper: { artifactName: 'PCVDepositWrapper', From e34eed9d3b6ba0c8c5f007a4667d31cd9cef18a5 Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Tue, 10 May 2022 12:07:06 +0200 Subject: [PATCH 09/11] Rename fixed contract --- proposals/dao/oa_cr_fix.ts | 16 ++++++++-------- .../collateralizationOracle.ts | 2 +- protocol-configuration/dependencies.ts | 11 +++-------- protocol-configuration/mainnetAddresses.ts | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/proposals/dao/oa_cr_fix.ts b/proposals/dao/oa_cr_fix.ts index 588660dc7..2b610682d 100644 --- a/proposals/dao/oa_cr_fix.ts +++ b/proposals/dao/oa_cr_fix.ts @@ -18,7 +18,7 @@ const deploy: DeployUpgradeFunc = async (deployAddress: string, addresses: Named // Deploy lens to report B-30FEI-70WETH as WETH and protocol-owned FEI // (The new contract contains a fix) const balancerPool2LensFactory = await ethers.getContractFactory('BalancerPool2Lens'); - const balancerLensBpt30Fei70WethFixed = await balancerPool2LensFactory.deploy( + const balancerLensBpt30Fei70Weth = await balancerPool2LensFactory.deploy( addresses.gaugeLensBpt30Fei70WethGauge, // address _depositAddress addresses.wethERC20, // address _token addresses.balancerFeiWethPool, // IWeightedPool _pool @@ -27,11 +27,11 @@ const deploy: DeployUpgradeFunc = async (deployAddress: string, addresses: Named false, // bool _feiIsReportedIn true // bool _feiIsOther ); - await balancerLensBpt30Fei70WethFixed.deployTransaction.wait(); - logging && console.log('balancerLensBpt30Fei70WethFixed: ', balancerLensBpt30Fei70WethFixed.address); + await balancerLensBpt30Fei70Weth.deployTransaction.wait(); + logging && console.log('balancerLensBpt30Fei70Weth: ', balancerLensBpt30Fei70Weth.address); return { - balancerLensBpt30Fei70WethFixed + balancerLensBpt30Fei70Weth }; }; @@ -86,16 +86,16 @@ const validate: ValidateUpgradeFunc = async (addresses, oldContracts, contracts, ); // Check the lens swap - expect(await contracts.collateralizationOracle.depositToToken(addresses.balancerLensBpt30Fei70Weth)).to.be.equal( + expect(await contracts.collateralizationOracle.depositToToken(addresses.balancerLensBpt30Fei70WethOld)).to.be.equal( ZERO_ADDRESS ); - expect(await contracts.collateralizationOracle.depositToToken(addresses.balancerLensBpt30Fei70WethFixed)).to.be.equal( + expect(await contracts.collateralizationOracle.depositToToken(addresses.balancerLensBpt30Fei70Weth)).to.be.equal( addresses.weth ); // Check the new lens returned values - const balance = (await contracts.balancerLensBpt30Fei70WethFixed.balance()) / 1e18; - const resistantBalanceAndFei = await contracts.balancerLensBpt30Fei70WethFixed.resistantBalanceAndFei(); + const balance = (await contracts.balancerLensBpt30Fei70Weth.balance()) / 1e18; + const resistantBalanceAndFei = await contracts.balancerLensBpt30Fei70Weth.resistantBalanceAndFei(); const resistantBalance = resistantBalanceAndFei[0] / 1e18; const resistantFei = resistantBalanceAndFei[1] / 1e18; expect(balance).to.be.at.least(14000); diff --git a/protocol-configuration/collateralizationOracle.ts b/protocol-configuration/collateralizationOracle.ts index cf204906f..4aee61f78 100644 --- a/protocol-configuration/collateralizationOracle.ts +++ b/protocol-configuration/collateralizationOracle.ts @@ -29,7 +29,7 @@ const collateralizationAddresses = { 'ethPSM', 'wethDepositWrapper', 'balancerDepositFeiWeth', - 'balancerLensBpt30Fei70WethFixed', + 'balancerLensBpt30Fei70Weth', 'balancerLensVeBalWeth' ], dpi: ['rariPool19DpiPCVDepositWrapper', 'dpiDepositWrapper'], diff --git a/protocol-configuration/dependencies.ts b/protocol-configuration/dependencies.ts index f4f8bb13f..ae915e100 100644 --- a/protocol-configuration/dependencies.ts +++ b/protocol-configuration/dependencies.ts @@ -657,7 +657,7 @@ const dependencies: DependencyMap = { 'uniswapPCVDeposit', 'balancerDepositBalWeth', 'balancerDepositFeiWeth', - 'balancerLensBpt30Fei70WethFixed', + 'balancerLensBpt30Fei70Weth', 'balancerLensVeBalBal', 'balancerLensVeBalWeth' ] @@ -698,12 +698,7 @@ const dependencies: DependencyMap = { contractDependencies: ['core', 'chainlinkEthUsdOracleWrapper', 'chainlinkCREAMEthOracle', 'collateralizationOracle'] }, oneConstantOracle: { - contractDependencies: [ - 'core', - 'collateralizationOracle', - 'balancerDepositFeiWeth', - 'balancerLensBpt30Fei70WethFixed' - ] + contractDependencies: ['core', 'collateralizationOracle', 'balancerDepositFeiWeth', 'balancerLensBpt30Fei70Weth'] }, tribeUsdCompositeOracle: { contractDependencies: [ @@ -1040,7 +1035,7 @@ const dependencies: DependencyMap = { balancerLensVeBalWeth: { contractDependencies: ['balUsdCompositeOracle', 'chainlinkEthUsdOracleWrapper'] }, - balancerLensBpt30Fei70WethFixed: { + balancerLensBpt30Fei70Weth: { contractDependencies: ['oneConstantOracle', 'chainlinkEthUsdOracleWrapper'] }, pcvGuardian: { diff --git a/protocol-configuration/mainnetAddresses.ts b/protocol-configuration/mainnetAddresses.ts index cbd6b5bb4..c34a0562e 100644 --- a/protocol-configuration/mainnetAddresses.ts +++ b/protocol-configuration/mainnetAddresses.ts @@ -396,12 +396,12 @@ const MainnetAddresses: MainnetAddresses = { address: '0xa8E388a1f19f2b33Be8bf2cCeC43641C10b4D1e5', category: AddressCategory.External // not really External, but not PCV }, - balancerLensBpt30Fei70Weth: { + balancerLensBpt30Fei70WethOld: { artifactName: 'BalancerPool2Lens', address: '0xb31F75550e97A2C4c7AC8d4355032B8AE8b9584D', category: AddressCategory.Deprecated }, - balancerLensBpt30Fei70WethFixed: { + balancerLensBpt30Fei70Weth: { artifactName: 'BalancerPool2Lens', address: '0x673f7DFA863b611dE657759aEDE629b260F4E682', category: AddressCategory.PCV From 8e51078bd72f1bb5018b7f765e62880d5f56f986 Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Tue, 10 May 2022 12:18:40 +0200 Subject: [PATCH 10/11] Rename old deposit in proposal --- proposals/description/oa_cr_fix.ts | 2 +- test/integration/proposals_config.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/proposals/description/oa_cr_fix.ts b/proposals/description/oa_cr_fix.ts index afce4dbd9..302941f97 100644 --- a/proposals/description/oa_cr_fix.ts +++ b/proposals/description/oa_cr_fix.ts @@ -7,7 +7,7 @@ const fip_x: ProposalDescription = { target: 'collateralizationOracle', values: '0', method: 'swapDeposit(address,address)', - arguments: ['{balancerLensBpt30Fei70Weth}', '{balancerLensBpt30Fei70WethFixed}'], + arguments: ['{balancerLensBpt30Fei70WethOld}', '{balancerLensBpt30Fei70Weth}'], description: 'Update B-70WETH-30FEI Lens' }, { diff --git a/test/integration/proposals_config.ts b/test/integration/proposals_config.ts index 14289335b..98de8c380 100644 --- a/test/integration/proposals_config.ts +++ b/test/integration/proposals_config.ts @@ -52,9 +52,9 @@ const proposals: ProposalsConfigMap = { totalValue: 0, // amount of ETH to send to DAO execution proposal: oa_cr_fix, // full proposal file, imported from '@proposals/description/fip_xx.ts' proposalId: '', - affectedContractSignoff: ['collateralizationOracle', 'balancerLensBpt30Fei70WethFixed'], + affectedContractSignoff: ['collateralizationOracle', 'balancerLensBpt30Fei70Weth'], deprecatedContractSignoff: [ - 'balancerLensBpt30Fei70Weth', + 'balancerLensBpt30Fei70WethOld', 'rariPool8FeiPCVDepositWrapper', 'rariPool8DaiPCVDeposit', 'rariPool8LusdPCVDeposit', From ad9e18d41b147c2dd4a8dc2f2320ff4c8cd05496 Mon Sep 17 00:00:00 2001 From: Erwan Beauvois Date: Tue, 10 May 2022 14:23:08 +0200 Subject: [PATCH 11/11] update boundaries for lens check --- proposals/dao/oa_cr_fix.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/proposals/dao/oa_cr_fix.ts b/proposals/dao/oa_cr_fix.ts index 2b610682d..f86f04563 100644 --- a/proposals/dao/oa_cr_fix.ts +++ b/proposals/dao/oa_cr_fix.ts @@ -98,12 +98,13 @@ const validate: ValidateUpgradeFunc = async (addresses, oldContracts, contracts, const resistantBalanceAndFei = await contracts.balancerLensBpt30Fei70Weth.resistantBalanceAndFei(); const resistantBalance = resistantBalanceAndFei[0] / 1e18; const resistantFei = resistantBalanceAndFei[1] / 1e18; + // 15.86k ETH, 16.3M FEI on 2022-05-10 expect(balance).to.be.at.least(14000); - expect(balance).to.be.at.most(16000); + expect(balance).to.be.at.most(18000); expect(resistantBalance).to.be.at.least(14000); - expect(resistantBalance).to.be.at.most(16000); - expect(resistantFei).to.be.at.least(17e6); - expect(resistantFei).to.be.at.most(20e6); + expect(resistantBalance).to.be.at.most(18000); + expect(resistantFei).to.be.at.least(10e6); + expect(resistantFei).to.be.at.most(25e6); // display pcvStats console.log('----------------------------------------------------');