Skip to content

Commit

Permalink
feat: migration to update price feed
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaShWoof committed Sep 30, 2024
1 parent 001a437 commit 801f595
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { expect } from 'chai';
import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager';
import { migration } from '../../../../plugins/deployment_manager/Migration';
import { exp, proposal } from '../../../../src/deploy';

const WSTETH_ADDRESS = '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0';
const constantPriceFeedAddress = '0x72e9B6F907365d76C6192aD49C0C5ba356b7Fa48';

export default migration('1727727546_change_base_price_feed', {
async prepare() {
return {};
},

enact: async (deploymentManager: DeploymentManager) => {
const trace = deploymentManager.tracer();
const {
governor,
comet,
cometAdmin,
configurator
} = await deploymentManager.getContracts();


const mainnetActions = [
// 1. Add weETH as asset
{
contract: configurator,
signature: 'setBaseTokenPriceFeed(address,address)',
args: [comet.address, constantPriceFeedAddress],
},
// 2. Deploy and upgrade to a new version of Comet
{
contract: cometAdmin,
signature: 'deployAndUpgradeTo(address,address)',
args: [configurator.address, comet.address],
},
];

const description = '# Update price feed in cWstETHv3 on Ethereum\n\n## Proposal summary\n\nCompound Growth Program [AlphaGrowth] proposes to update wstETH price feed in cWstETHv3 market on Ethereum to constant price feed as it is intended to be.\n\n\n## Proposal Actions\n\nThe first proposal action updates price feed for wstETH.\n\nThe second action deploys and upgrades Comet to a new version.';
const txn = await deploymentManager.retry(async () =>
trace(
await governor.propose(...(await proposal(mainnetActions, description)))
)
);

const event = txn.events.find(
(event) => event.event === 'ProposalCreated'
);
const [proposalId] = event.args;
trace(`Created proposal ${proposalId}.`);
},

async enacted(): Promise<boolean> {
return false;
},

async verify(deploymentManager: DeploymentManager) {
const { comet, configurator } = await deploymentManager.getContracts();

// 1. Compare proposed asset config with Comet asset info
const basePriceFeed = await comet.baseTokenPriceFeed();

expect(basePriceFeed).to.eq(constantPriceFeedAddress);
expect(await comet.getPrice(basePriceFeed)).to.eq(exp(1, 8));

// 2. Compare proposed asset config with Configurator asset config
const basePriceFeedFromConfigurator = (
await configurator.getConfiguration(comet.address)
).baseTokenPriceFeed;

expect(basePriceFeedFromConfigurator).to.eq(constantPriceFeedAddress);
},
});
14 changes: 12 additions & 2 deletions scenario/constraints/MigrationConstraint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StaticConstraint, Solution, World, debug } from '../../plugins/scenario';
import { CometContext, MigrationData } from '../context/CometContext';
import { Migration, loadMigrations, Actions } from '../../plugins/deployment_manager/Migration';
import { modifiedPaths, subsets } from '../utils';
import { modifiedPaths } from '../utils';
import { DeploymentManager } from '../../plugins/deployment_manager';
import { impersonateAddress } from '../../plugins/scenario/utils';
import { exp } from '../../test/helpers';
Expand All @@ -22,7 +22,17 @@ export class MigrationConstraint<T extends CometContext> implements StaticConstr
async solve(world: World) {
const label = `[${world.base.name}] {MigrationConstraint}`;
const solutions: Solution<T>[] = [];
const migrationPaths = [...subsets(await getMigrations(world))];
const migrations = await getMigrations(world);

// remove enacted migrations
for(let i = 0; i < migrations.length; i++) {
if (await isEnacted(migrations[i].actions, world.deploymentManager, world.deploymentManager)) {
migrations.splice(i, 1);
i--;
}
}

const migrationPaths = [migrations];

for (const migrationList of migrationPaths) {
if (migrationList.length == 0 && migrationPaths.length > 1) {
Expand Down

0 comments on commit 801f595

Please sign in to comment.