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

Cleanup: CR Oracle (remove caching, clean deprecated deposits) #923

Merged
merged 31 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a463101
Add proposal to cleanup CR
eswak Jun 20, 2022
96f2ff9
add rai psm & tokemak removal from cr oracle
eswak Jun 20, 2022
c569aea
remove ETH tokemak from CR config
eswak Jun 20, 2022
2efdec7
Merge branch 'develop' into feat/cleanup-cr-oracle
Jun 20, 2022
b09225c
Add OA deprecation
kryptoklob Jun 20, 2022
7e0ef13
remove tokemak e2e test
eswak Jun 21, 2022
a967025
more deprecations
eswak Jun 21, 2022
b3f52bc
Merge branch 'feat/cleanup-cr-oracle' of github.com:fei-protocol/fei-…
eswak Jun 21, 2022
5d4354b
fix e2e tests
eswak Jun 21, 2022
728295d
merge base branch & resolve conflicts
eswak Jun 21, 2022
7ce645c
Undo role removal
kryptoklob Jun 21, 2022
d67b769
Merge pull request #924 from fei-protocol/feat/cleanup-optimistic-app…
Joeysantoro Jun 21, 2022
445ac74
make dai skimmer functional (& skim)
eswak Jun 22, 2022
d3c5d1a
Revert "make dai skimmer functional (& skim)"
eswak Jun 22, 2022
d374afc
feat: revoke permissions from ops timelock
thomas-waite Jun 22, 2022
58ec850
feat: deprecate ops optimistic timelock, remove old e2es
thomas-waite Jun 22, 2022
41ef078
Merge branch 'feat/cleanup-cr-oracle' into deprecate-ops-timelock
thomas-waite Jun 22, 2022
08037b9
refactor: consolidate into one proposal
thomas-waite Jun 22, 2022
fca2fbf
feat: reduce parralelism to match num tests
thomas-waite Jun 22, 2022
a33988a
Merge pull request #926 from fei-protocol/deprecate-ops-timelock
thomas-waite Jun 22, 2022
d05ea86
Merge remote-tracking branch 'origin/develop' into feat/cleanup-cr-or…
eswak Jun 24, 2022
95f7ddd
Merge branch 'feat/cleanup-cr-oracle' of github.com:fei-protocol/fei-…
eswak Jun 24, 2022
226a0ba
Tom review & update proposal title/description
eswak Jun 24, 2022
ff45733
deploy tip_117
eswak Jun 24, 2022
c556ef4
update block after deploy
eswak Jun 24, 2022
e9876c2
pull out of aave deposit to eth psm before deprecating
eswak Jun 24, 2022
6345fba
fix tip_115 check (block update)
eswak Jun 24, 2022
dcc5516
fix/deprecate turbo & oa e2e tests
eswak Jun 24, 2022
024b2eb
docs: flesh out proposal description
thomas-waite Jun 24, 2022
786c800
feat: readd aave eth as safe address and to CR
thomas-waite Jun 24, 2022
27a23ff
refactor: set aave eth as not deprecated
thomas-waite Jun 24, 2022
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
e2e-test:
working_directory: ~/repo
executor: nodeimage
parallelism: 20
parallelism: 19
steps:
- attach_workspace:
at: ./
Expand Down
2 changes: 1 addition & 1 deletion block.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15004720
15018600
2 changes: 1 addition & 1 deletion proposals/dao/tip_115.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const validate: ValidateUpgradeFunc = async (addresses, oldContracts, contracts,
expect(await contracts.rariInfraFeiTimelock.beneficiary()).to.be.equal(addresses.tribalCouncilTimelock);
expect(await contracts.rariInfraTribeTimelock.beneficiary()).to.be.equal(addresses.tribalCouncilTimelock);
expect(await contracts.rariTimelockFeiOldLens.balance()).to.be.equal('3178504756468797564687976');
expect(await contracts.tribalCouncilTimelockFeiLens.balance()).to.be.equal('0');
expect(await contracts.tribalCouncilTimelockFeiLens.balance()).to.be.equal('42905768215167745773610059');
expect(await contracts.rariTimelockFeiOldLens.balanceReportedIn()).to.be.equal(addresses.fei);
expect(await contracts.tribalCouncilTimelockFeiLens.balanceReportedIn()).to.be.equal(addresses.fei);
expect(await contracts.namedStaticPCVDepositWrapper.numDeposits()).to.be.equal('0');
Expand Down
143 changes: 143 additions & 0 deletions proposals/dao/tip_117.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { ethers } from 'hardhat';
import { expect } from 'chai';
import {
DeployUpgradeFunc,
NamedAddresses,
SetupUpgradeFunc,
TeardownUpgradeFunc,
ValidateUpgradeFunc,
PcvStats
} from '@custom-types/types';
import { getImpersonatedSigner, overwriteChainlinkAggregator, time, expectRevert } from '@test/helpers';
import { forceEth } from '@test/integration/setup/utils';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { BigNumber, Contract } from 'ethers';

let pcvStatsBefore: PcvStats;
let ethPrice8Decimals: string;

const fipNumber = 'cr_oracle_cleanup';

// Do any deployments
// This should exclusively include new contract deployments
const deploy: DeployUpgradeFunc = async (deployAddress: string, addresses: NamedAddresses, logging: boolean) => {
// Deploy composite VOLT*1 oracle
// This is needed because the VOLT OraclePassthrough does not have a paused() method
const compositeOracleFactory = await ethers.getContractFactory('CompositeOracle');
const voltOracle = await compositeOracleFactory.deploy(
addresses.core,
addresses.oneConstantOracle,
addresses.voltOraclePassthrough,
false
);
await voltOracle.deployed();
logging && console.log(`voltOracle: ${voltOracle.address}`);

return {
voltOracle
};
};

// 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) => {
// 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
ethPrice8Decimals = Math.round((await contracts.chainlinkEthUsdOracleWrapper.read())[0].toString() / 1e10).toString();
await overwriteChainlinkAggregator(addresses.chainlinkEthUsdOracle, ethPrice8Decimals, '8');

// read pcvStats before proposal execution
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) => {
// display pcvStats
console.log('----------------------------------------------------');
console.log(' pcvStatsBefore.protocolControlledValue [M]e18 ', Number(pcvStatsBefore.protocolControlledValue) / 1e24);
console.log(' pcvStatsBefore.userCirculatingFei [M]e18 ', Number(pcvStatsBefore.userCirculatingFei) / 1e24);
console.log(' pcvStatsBefore.protocolEquity [M]e18 ', Number(pcvStatsBefore.protocolEquity) / 1e24);
const pcvStatsAfter: PcvStats = await contracts.collateralizationOracle.pcvStats();
console.log('----------------------------------------------------');
console.log(' pcvStatsAfter.protocolControlledValue [M]e18 ', Number(pcvStatsAfter.protocolControlledValue) / 1e24);
console.log(' pcvStatsAfter.userCirculatingFei [M]e18 ', Number(pcvStatsAfter.userCirculatingFei) / 1e24);
console.log(' pcvStatsAfter.protocolEquity [M]e18 ', Number(pcvStatsAfter.protocolEquity) / 1e24);
console.log('----------------------------------------------------');
const pcvDiff: BigNumber = pcvStatsAfter.protocolControlledValue.sub(pcvStatsBefore.protocolControlledValue);
const cFeiDiff: BigNumber = pcvStatsAfter.userCirculatingFei.sub(pcvStatsBefore.userCirculatingFei);
const eqDiff: BigNumber = pcvStatsAfter.protocolEquity.sub(pcvStatsBefore.protocolEquity);
console.log(' PCV diff [M]e18 ', Number(pcvDiff) / 1e24);
console.log(' Circ FEI diff [M]e18 ', Number(cFeiDiff) / 1e24);
console.log(' Equity diff [M]e18 ', Number(eqDiff) / 1e24);
console.log('----------------------------------------------------');

// check the updated references
expect(await contracts.pcvEquityMinter.collateralizationOracle()).to.be.equal(addresses.collateralizationOracle);
expect(await contracts.tribeReserveStabilizer.collateralizationOracle()).to.be.equal(
addresses.collateralizationOracle
);

// check the pcv equity minter value with new CR oracle
// 65M$ equity at 20% APR is 250k$ per week
const mintAmount: BigNumber = await contracts.pcvEquityMinter.mintAmount();
expect(mintAmount).to.be.at.least(ethers.constants.WeiPerEther.mul('50000'));
expect(mintAmount).to.be.at.most(ethers.constants.WeiPerEther.mul('500000'));

// mock a very low ETH price to check activation of the TRIBE reserve stabilizer
// 50$ / ETH
expect(await contracts.tribeReserveStabilizer.isCollateralizationBelowThreshold()).to.be.false;
await overwriteChainlinkAggregator(addresses.chainlinkEthUsdOracle, '5000000000', '8');
// also mock TRIBE price to be 0.125$ (it's a composite oracle between ETH/USD and TRIBE/ETH)
await overwriteChainlinkAggregator(addresses.chainlinkTribeEthOracle, '2500000000000000', '18');
expect(await contracts.tribeReserveStabilizer.isCollateralizationBelowThreshold()).to.be.true;
expect(await contracts.tribeReserveStabilizer.isTimeStarted()).to.be.false;
await contracts.tribeReserveStabilizer.startOracleDelayCountdown();
await time.increase(await contracts.tribeReserveStabilizer.duration());

const pcvStatsLowEth: PcvStats = await contracts.collateralizationOracle.pcvStats();
expect(pcvStatsLowEth.protocolEquity).to.be.at.most('0');

// check the pcv equity minter when FEI is undercollateralized
await expectRevert(contracts.pcvEquityMinter.mintAmount(), 'PCVEquityMinter: Equity is nonpositive');

// simulate a tribe reserve stabilizer trigger
const amountFei: BigNumber = ethers.constants.WeiPerEther.mul('40000000'); // redeem 40M FEI
const feiHolderSigner: SignerWithAddress = await getImpersonatedSigner(addresses.feiTribePair);
await forceEth(addresses.feiTribePair);
await contracts.fei.connect(feiHolderSigner).approve(addresses.tribeReserveStabilizer, amountFei);
await contracts.tribeReserveStabilizer.connect(feiHolderSigner).exchangeFei(amountFei);

// back in positive equity
const pcvStatsLowEth2: PcvStats = await contracts.collateralizationOracle.pcvStats();
expect(pcvStatsLowEth2.protocolEquity).to.be.at.least('0');

// restore ETH price
await overwriteChainlinkAggregator(addresses.chainlinkEthUsdOracle, ethPrice8Decimals, '8');

// unpause pcv equity minter and mint a buyback cycle
const daoSigner: SignerWithAddress = await getImpersonatedSigner(contracts.feiDAOTimelock.address);
await forceEth(contracts.feiDAOTimelock.address);
await contracts.pcvEquityMinter.connect(daoSigner).unpause();
await contracts.pcvEquityMinter.mint(); // no revert = ok, auction started
// fast-forward time so that e2e tests are not bricked
await time.increase(await contracts.tribeReserveStabilizer.duration());
await contracts.tribeReserveStabilizer.resetOracleDelayCountdown();

////// Ops optimistic timelock deprecation validation /////////
expect(await contracts.core.hasRole(ethers.utils.id('METAGOVERNANCE_VOTE_ADMIN'), addresses.opsOptimisticTimelock)).to
.be.false;
expect(await contracts.core.hasRole(ethers.utils.id('METAGOVERNANCE_TOKEN_STAKING'), addresses.opsOptimisticTimelock))
.to.be.false;
expect(await contracts.core.hasRole(ethers.utils.id('ORACLE_ADMIN_ROLE'), addresses.opsOptimisticTimelock)).to.be
.false;
};

export { deploy, setup, teardown, validate };
Loading