From fe7960869581cbaeefa6088c77c37b07f58ed0f0 Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Mon, 15 Jul 2024 12:21:49 +0300 Subject: [PATCH] feat: add migration --- .../1721034240_add_wsteth_as_collateral.ts | 191 ++++++++++++++++++ deployments/base/usdc/relations.ts | 11 +- hardhat.config.ts | 2 +- src/deploy/index.ts | 6 +- 4 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 deployments/base/usdc/migrations/1721034240_add_wsteth_as_collateral.ts diff --git a/deployments/base/usdc/migrations/1721034240_add_wsteth_as_collateral.ts b/deployments/base/usdc/migrations/1721034240_add_wsteth_as_collateral.ts new file mode 100644 index 000000000..af667bff2 --- /dev/null +++ b/deployments/base/usdc/migrations/1721034240_add_wsteth_as_collateral.ts @@ -0,0 +1,191 @@ +import { expect } from 'chai'; +import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager'; +import { migration } from '../../../../plugins/deployment_manager/Migration'; +import { calldata, exp, proposal } from '../../../../src/deploy'; +import { utils } from 'ethers'; + +const WSTETH_ADDRESS = '0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452'; +const WSTETH_STETH_PRICE_FEED_ADDRESS = '0xB88BAc61a4Ca37C43a3725912B1f472c9A5bc061'; +const STETH_ETH_PRICE_FEED_ADDRESS = '0xf586d0728a47229e747d824a939000Cf21dEF5A0'; +let newPriceFeedAddress: string; + +export default migration('1721034240_add_wsteth_as_collateral.ts', { + async prepare(deploymentManager: DeploymentManager) { + const _wstETHToETHPriceFeed = await deploymentManager.deploy( + 'wstETH:priceFeed', + 'pricefeeds/MultiplicativePriceFeed.sol', + [ + WSTETH_STETH_PRICE_FEED_ADDRESS, // wstETH / stETH price feed + STETH_ETH_PRICE_FEED_ADDRESS, // stETH / ETH price feed + 8, // decimals + 'wstETH / ETH price feed' // description + ] + ); + const _wstETHScalingPriceFeed = await deploymentManager.deploy( + 'wstETH:scalingPriceFeed', + 'pricefeeds/MultiplicativePriceFeed.sol', + [ + _wstETHToETHPriceFeed.address, // wstETH / ETH price feed + (await deploymentManager.fromDep('WETH:priceFeed', 'base', 'usdc')).address, // ETH / USD price feed + 8, // decimals + 'wstETH / USD price feed' // description + ] + ); + return { wstETHScalingPriceFeed: _wstETHScalingPriceFeed.address }; + }, + + enact: async ( + deploymentManager: DeploymentManager, + govDeploymentManager: DeploymentManager, + { wstETHScalingPriceFeed } + ) => { + const trace = deploymentManager.tracer(); + + const wstETH = await deploymentManager.existing( + 'wstETH', + WSTETH_ADDRESS, + 'base', + 'contracts/ERC20.sol:ERC20' + ); + const wstETHPricefeed = await deploymentManager.existing( + 'wstETH:priceFeed', + wstETHScalingPriceFeed, + 'base' + ); + + const { + bridgeReceiver, + comet, + cometAdmin, + configurator, + } = await deploymentManager.getContracts(); + + const { governor, baseL1CrossDomainMessenger } = await govDeploymentManager.getContracts(); + + const newAssetConfig = { + asset: wstETH.address, + priceFeed: wstETHPricefeed.address, + decimals: await wstETH.decimals(), + borrowCollateralFactor: exp(0.80, 18), + liquidateCollateralFactor: exp(0.85, 18), + liquidationFactor: exp(0.90, 18), + supplyCap: exp(700, 18), + }; + + newPriceFeedAddress = wstETHPricefeed.address; + + const addAssetCalldata = await calldata( + configurator.populateTransaction.addAsset(comet.address, newAssetConfig) + ); + const deployAndUpgradeToCalldata = utils.defaultAbiCoder.encode( + ['address', 'address'], + [configurator.address, comet.address] + ); + + const l2ProposalData = utils.defaultAbiCoder.encode( + ['address[]', 'uint256[]', 'string[]', 'bytes[]'], + [ + [configurator.address, cometAdmin.address], + [0, 0], + [ + 'addAsset(address,(address,address,uint8,uint64,uint64,uint64,uint128))', + 'deployAndUpgradeTo(address,address)', + ], + [addAssetCalldata, deployAndUpgradeToCalldata], + ] + ); + + const mainnetActions = [ + // Send the proposal to the L2 bridge + { + contract: baseL1CrossDomainMessenger, + signature: 'sendMessage(address,bytes,uint32)', + args: [bridgeReceiver.address, l2ProposalData, 3_000_000] + }, + ]; + + const description = '# Add wstETH as collateral into cUSDCv3 on Base\n\n## Proposal summary\n\nCompound Growth Program [AlphaGrowth] proposes to add wstETH into cUSDCv3 on Base network. This proposal takes the governance steps recommended and necessary to update a Compound III USDC market on Base. Simulations have confirmed the market’s readiness, as much as possible, using the [Comet scenario suite](https://github.com/compound-finance/comet/tree/main/scenario). The new parameters include setting the risk parameters based off of the [recommendations from Gauntlet](https://www.comp.xyz/t/gauntlet-wsteth-and-ezeth-asset-listing/5404/1).\n\nFurther detailed information can be found on the corresponding [proposal pull request](https://github.com/compound-finance/comet/pull/889) and [forum discussion](https://www.comp.xyz/t/gauntlet-wsteth-and-ezeth-asset-listing/5404).\n\n\n## Proposal Actions\n\nThe first proposal action adds wstETH to the USDC Comet on Base. This sends the encoded `addAsset` and `deployAndUpgradeTo` calls across the bridge to the governance receiver on Base.'; + const txn = await govDeploymentManager.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 { + return false; + }, + + async verify(deploymentManager: DeploymentManager) { + const { comet, configurator } = await deploymentManager.getContracts(); + + const wstETHAssetIndex = Number(await comet.numAssets()) - 1; + + const wstETHAssetConfig = { + asset: WSTETH_ADDRESS, + priceFeed: newPriceFeedAddress, + decimals: 18, + borrowCollateralFactor: exp(0.80, 18), + liquidateCollateralFactor: exp(0.85, 18), + liquidationFactor: exp(0.90, 18), + supplyCap: exp(700, 18), + }; + + // 1. Compare proposed asset config with Comet asset info + const wstETHAssetInfo = await comet.getAssetInfoByAddress( + WSTETH_ADDRESS + ); + expect(wstETHAssetIndex).to.be.equal(wstETHAssetInfo.offset); + expect(wstETHAssetConfig.asset).to.be.equal(wstETHAssetInfo.asset); + expect(wstETHAssetConfig.priceFeed).to.be.equal( + wstETHAssetInfo.priceFeed + ); + expect(exp(1, wstETHAssetConfig.decimals)).to.be.equal( + wstETHAssetInfo.scale + ); + expect(wstETHAssetConfig.borrowCollateralFactor).to.be.equal( + wstETHAssetInfo.borrowCollateralFactor + ); + expect(wstETHAssetConfig.liquidateCollateralFactor).to.be.equal( + wstETHAssetInfo.liquidateCollateralFactor + ); + expect(wstETHAssetConfig.liquidationFactor).to.be.equal( + wstETHAssetInfo.liquidationFactor + ); + expect(wstETHAssetConfig.supplyCap).to.be.equal( + wstETHAssetInfo.supplyCap + ); + + // 2. Compare proposed asset config with Configurator asset config + const configuratorWstETHAssetConfig = ( + await configurator.getConfiguration(comet.address) + ).assetConfigs[wstETHAssetIndex]; + expect(wstETHAssetConfig.asset).to.be.equal( + configuratorWstETHAssetConfig.asset + ); + expect(wstETHAssetConfig.priceFeed).to.be.equal( + configuratorWstETHAssetConfig.priceFeed + ); + expect(wstETHAssetConfig.decimals).to.be.equal( + configuratorWstETHAssetConfig.decimals + ); + expect(wstETHAssetConfig.borrowCollateralFactor).to.be.equal( + configuratorWstETHAssetConfig.borrowCollateralFactor + ); + expect(wstETHAssetConfig.liquidateCollateralFactor).to.be.equal( + configuratorWstETHAssetConfig.liquidateCollateralFactor + ); + expect(wstETHAssetConfig.liquidationFactor).to.be.equal( + configuratorWstETHAssetConfig.liquidationFactor + ); + expect(wstETHAssetConfig.supplyCap).to.be.equal( + configuratorWstETHAssetConfig.supplyCap + ); + }, +}); diff --git a/deployments/base/usdc/relations.ts b/deployments/base/usdc/relations.ts index 31819114d..5a4805d34 100644 --- a/deployments/base/usdc/relations.ts +++ b/deployments/base/usdc/relations.ts @@ -24,5 +24,14 @@ export default { slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' } } - } + }, + + OssifiableProxy: { + artifact: 'contracts/ERC20.sol:ERC20', + delegates: { + field: { + slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' + } + } + }, }; \ No newline at end of file diff --git a/hardhat.config.ts b/hardhat.config.ts index 180b8b4d5..8ac2f187f 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -122,7 +122,7 @@ const networkConfigs: NetworkConfig[] = [ { network: 'base', chainId: 8453, - url: `https://clean-spring-wind.base-mainnet.discover.quiknode.pro/${QUICKNODE_KEY}`, + url: `https://fluent-prettiest-scion.base-mainnet.quiknode.pro/${QUICKNODE_KEY}`, }, { network: 'arbitrum', diff --git a/src/deploy/index.ts b/src/deploy/index.ts index f912c38bf..4f2cf8b32 100644 --- a/src/deploy/index.ts +++ b/src/deploy/index.ts @@ -115,7 +115,11 @@ export const WHALES = { ], base: [ '0x6D3c5a4a7aC4B1428368310E4EC3bB1350d01455', // USDbC whale - '0x07CFA5Df24fB17486AF0CBf6C910F24253a674D3' // cbETH whale TODO: need to update this whale, not enough + '0x07CFA5Df24fB17486AF0CBf6C910F24253a674D3', // cbETH whale TODO: need to update this whale, not enough + '0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb', // cbETH whale + '0x3bf93770f2d4a794c3d9EBEfBAeBAE2a8f09A5E5', // cbETH whale + '0xcf3D55c10DB69f28fD1A75Bd73f3D8A2d9c595ad', // cbETH whale + '0xb125E6687d4313864e53df431d5425969c15Eb2F', // cbETH whale ], scroll: [ '0xaaaaAAAACB71BF2C8CaE522EA5fa455571A74106' // USDC whale