Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OA tx : Balancer pfei accounting fix + remove PCVDeposits with bad debts #776

Merged
merged 15 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/pcv/balancer/BalancerPool2Lens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ contract BalancerPool2Lens is IPCVDepositBalances {
}
if (feiInPair) {
uint256 otherReserves = _getIdealReserves(balances, prices, weights, j);
otherReserves = (otherReserves * bptsOwned) / totalSupply;
thomas-waite marked this conversation as resolved.
Show resolved Hide resolved
return (reserves, otherReserves);
}
return (reserves, 0);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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=14723389; 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",
Expand Down
125 changes: 125 additions & 0 deletions proposals/dao/oa_cr_fix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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
addresses.balancerFeiWethPool, // 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...`);

// 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();
};

// 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);

// display pcvStats
console.log('----------------------------------------------------');
thomas-waite marked this conversation as resolved.
Show resolved Hide resolved
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('----------------------------------------------------');
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('----------------------------------------------------');
};

export { deploy, setup, teardown, validate };
34 changes: 34 additions & 0 deletions proposals/description/oa_cr_fix.ts
Original file line number Diff line number Diff line change
@@ -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}'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now is a good time to rethink our naming conventions. The arbitrary suffix "fixed" is not a super scalable convention.

If it has the same ABI I'd prefer making the fixed one called balancerLensBpt30Fei70Weth and naming the old one "old" or
"v1" or something

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah would prefer version numbers over "fixed"

Reminds me of how I used to name files in folders for school assignments. "Assignment1Fixed", "Assignment1FixedFinal", "Assignment1FixedFinalFinalSubmitThis.doc"

Copy link
Contributor Author

@eswak eswak May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed the old one to balancerLensBpt30Fei70WethOld and use the balancerLensBpt30Fei70Weth name for the new one.

description: 'Update B-70WETH-30FEI Lens'
},
{
target: 'collateralizationOracle',
values: '0',
method: 'removeDeposits(address[])',
eswak marked this conversation as resolved.
Show resolved Hide resolved
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;
17 changes: 3 additions & 14 deletions protocol-configuration/collateralizationOracle.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
const collateralizationAddresses = {
fei: [
'feiOATimelockWrapper',
'rariPool8FeiPCVDepositWrapper',
'rariPool6FeiPCVDepositWrapper',
'rariPool19FeiPCVDepositWrapper',
'rariPool24FeiPCVDepositWrapper',
'rariPool25FeiPCVDepositWrapper',
'rariPool27FeiPCVDepositWrapper',
'rariPool18FeiPCVDepositWrapper',
'rariPool90FeiPCVDepositWrapper',
'aaveFeiPCVDepositWrapper',
'rariPool79FeiPCVDepositWrapper',
Expand All @@ -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'],
Expand All @@ -38,10 +28,9 @@ const collateralizationAddresses = {
'uniswapPCVDeposit',
'ethTokemakPCVDeposit',
'ethPSM',
'rariPool146EthPCVDeposit',
'wethDepositWrapper',
'balancerDepositFeiWeth',
'balancerLensBpt30Fei70Weth',
'balancerLensBpt30Fei70WethFixed',
'balancerLensVeBalWeth'
],
dpi: ['rariPool19DpiPCVDepositWrapper', 'dpiDepositWrapper'],
Expand Down
41 changes: 11 additions & 30 deletions protocol-configuration/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const dependencies: DependencyMap = {
'liquityFusePoolLusdPCVDeposit',
'poolPartyFeiPCVDeposit',
'rariTimelock',
'rariPool146EthPCVDeposit',
'rariPool18FeiPCVDeposit',
'rariPool19DpiPCVDeposit',
'rariPool19FeiPCVDeposit',
Expand Down Expand Up @@ -405,17 +404,14 @@ const dependencies: DependencyMap = {
poolPartyFeiPCVDeposit: {
contractDependencies: ['core', 'fei']
},
rariPool146EthPCVDeposit: {
contractDependencies: ['core', 'rariPool146Eth']
},
rariPool146Comptroller: {
contractDependencies: ['rariPool146FuseAdmin', 'rariPool146Eth']
},
rariPool146FuseAdmin: {
contractDependencies: ['rariPool146Comptroller']
},
rariPool146Eth: {
contractDependencies: ['rariPool146Comptroller', 'rariPool146EthPCVDeposit']
contractDependencies: ['rariPool146Comptroller']
},
rariPool18FeiPCVDeposit: {
contractDependencies: ['core', 'fei']
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -594,9 +585,6 @@ const dependencies: DependencyMap = {
feiOATimelockWrapper: {
contractDependencies: ['collateralizationOracle']
},
rariPool18FeiPCVDepositWrapper: {
contractDependencies: ['collateralizationOracle']
},
rariPool19DpiPCVDepositWrapper: {
contractDependencies: ['collateralizationOracle']
},
Expand All @@ -609,9 +597,6 @@ const dependencies: DependencyMap = {
rariPool25FeiPCVDepositWrapper: {
contractDependencies: ['collateralizationOracle']
},
rariPool27FeiPCVDepositWrapper: {
contractDependencies: ['collateralizationOracle']
},
rariPool31FeiPCVDepositWrapper: {
contractDependencies: ['collateralizationOracle', 'rariPool31FeiPCVDeposit']
},
Expand All @@ -636,9 +621,6 @@ const dependencies: DependencyMap = {
rariPool22FeiPCVDepositWrapper: {
contractDependencies: ['collateralizationOracle', 'rariPool22FeiPCVDeposit']
},
rariPool8FeiPCVDepositWrapper: {
contractDependencies: ['collateralizationOracle']
},
rariPool9RaiPCVDepositWrapper: {
contractDependencies: ['collateralizationOracle']
},
Expand Down Expand Up @@ -684,7 +666,7 @@ const dependencies: DependencyMap = {
'uniswapPCVDeposit',
'balancerDepositBalWeth',
'balancerDepositFeiWeth',
'balancerLensBpt30Fei70Weth',
'balancerLensBpt30Fei70WethFixed',
'balancerLensVeBalBal',
'balancerLensVeBalWeth'
]
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -928,7 +915,7 @@ const dependencies: DependencyMap = {
contractDependencies: ['rariPool8MasterOracle']
},
rariPool8Dai: {
contractDependencies: ['rariPool8Comptroller', 'rariPool8DaiIrm', 'rariPool8DaiPCVDeposit']
thomas-waite marked this conversation as resolved.
Show resolved Hide resolved
contractDependencies: ['rariPool8Comptroller', 'rariPool8DaiIrm']
},
rariPool8DaiIrm: {
contractDependencies: ['rariPool8Dai']
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -1068,7 +1049,7 @@ const dependencies: DependencyMap = {
balancerLensVeBalWeth: {
contractDependencies: ['balUsdCompositeOracle', 'chainlinkEthUsdOracleWrapper']
},
balancerLensBpt30Fei70Weth: {
balancerLensBpt30Fei70WethFixed: {
contractDependencies: ['oneConstantOracle', 'chainlinkEthUsdOracleWrapper']
},
pcvGuardian: {
Expand Down
Loading