Skip to content

Commit

Permalink
Add ETHx as collateral to WETH market on Mainnet (#901)
Browse files Browse the repository at this point in the history
Co-authored-by: dmitriy-woof-software <[email protected]>
Co-authored-by: Dmitriy Babenko <[email protected]>
Co-authored-by: GitHub Actions Bot <>
  • Loading branch information
3 people authored Nov 15, 2024
1 parent 9ee48e5 commit 5714ef9
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
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 ETHX_ADDRESS = '0xA35b1B31Ce002FBF2058D22F30f95D405200A15b';
const ETHX_PRICE_FEED_ADDRESS = '0xdd487947c579af433AeeF038Bf1573FdBB68d2d3';

export default migration('1730466050_add_ethx_as_collaterals', {
async prepare(deploymentManager: DeploymentManager) {
const _ETHxScalingPriceFeed = await deploymentManager.deploy(
'ETHx:priceFeed',
'pricefeeds/ScalingPriceFeed.sol',
[
ETHX_PRICE_FEED_ADDRESS, // ETHx / ETH price feed
8 // decimals
],
true
);

return { ETHxScalingPriceFeed: _ETHxScalingPriceFeed.address };
},

async enact(deploymentManager: DeploymentManager, _, { ETHxScalingPriceFeed }) {

const trace = deploymentManager.tracer();

const ETHx = await deploymentManager.existing(
'ETHx',
ETHX_ADDRESS,
'mainnet',
'contracts/ERC20.sol:ERC20'
);
const ETHxPricefeed = await deploymentManager.existing(
'ETHx:priceFeed',
ETHxScalingPriceFeed,
'mainnet'
);

const {
governor,
comet,
cometAdmin,
configurator,
} = await deploymentManager.getContracts();

const ETHxAssetConfig = {
asset: ETHx.address,
priceFeed: ETHxPricefeed.address,
decimals: await ETHx.decimals(),
borrowCollateralFactor: exp(0.85, 18),
liquidateCollateralFactor: exp(0.90, 18),
liquidationFactor: exp(0.95, 18),
supplyCap: exp(2_100, 18),
};

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

const description = '# Add ETHx as collaterals into cWETHv3 on Mainnet\n\n## Proposal summary\n\nCompound Growth Program [AlphaGrowth] proposes to add ETHx into cWETHv3 on Ethereum network. This proposal takes the governance steps recommended and necessary to update a Compound III WETH market on Ethereum. 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 on the [recommendations from Gauntlet](https://www.comp.xyz/t/listing-ethx-on-compound/4730/21).\n\nFurther detailed information can be found on the corresponding [proposal pull request](https://github.com/compound-finance/comet/pull/901) and [forum discussion](https://www.comp.xyz/t/listing-ethx-on-compound/4730).\n\n\n## Price feed\n\nExchange rate price feed of ETHx/ETH was provided by Chainlink team. The address of pricefeed that is used is 0xdd487947c579af433AeeF038Bf1573FdBB68d2d3\n\n\n## Proposal Actions\n\nThe first proposal action adds ETHx asset as collateral with corresponding configurations.\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(deploymentManager: DeploymentManager): Promise<boolean> {
return true;
},

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

const ETHxAssetIndex = Number(await comet.numAssets()) - 1;

const ETHx = await deploymentManager.existing(
'ETHx',
ETHX_ADDRESS,
'mainnet',
'contracts/ERC20.sol:ERC20'
);
const ETHxAssetConfig = {
asset: ETHx.address,
priceFeed: '',
decimals: await ETHx.decimals(),
borrowCollateralFactor: exp(0.85, 18),
liquidateCollateralFactor: exp(0.90, 18),
liquidationFactor: exp(0.95, 18),
supplyCap: exp(2_100, 18),
};

// 1. Compare ETHx asset config with Comet and Configurator asset info
const cometETHxAssetInfo = await comet.getAssetInfo(ETHxAssetIndex);
expect(ETHxAssetIndex).to.be.equal(cometETHxAssetInfo.offset);
expect(ETHxAssetConfig.asset).to.be.equal(cometETHxAssetInfo.asset);
expect(exp(1, ETHxAssetConfig.decimals)).to.be.equal(cometETHxAssetInfo.scale);
expect(ETHxAssetConfig.borrowCollateralFactor).to.be.equal(cometETHxAssetInfo.borrowCollateralFactor);
expect(ETHxAssetConfig.liquidateCollateralFactor).to.be.equal(cometETHxAssetInfo.liquidateCollateralFactor);
expect(ETHxAssetConfig.liquidationFactor).to.be.equal(cometETHxAssetInfo.liquidationFactor);
expect(ETHxAssetConfig.supplyCap).to.be.equal(cometETHxAssetInfo.supplyCap);

const configuratorETHxAssetConfig = (await configurator.getConfiguration(comet.address)).assetConfigs[ETHxAssetIndex];
expect(ETHxAssetConfig.asset).to.be.equal(configuratorETHxAssetConfig.asset);
expect(ETHxAssetConfig.decimals).to.be.equal(configuratorETHxAssetConfig.decimals);
expect(ETHxAssetConfig.borrowCollateralFactor).to.be.equal(configuratorETHxAssetConfig.borrowCollateralFactor);
expect(ETHxAssetConfig.liquidateCollateralFactor).to.be.equal(configuratorETHxAssetConfig.liquidateCollateralFactor);
expect(ETHxAssetConfig.liquidationFactor).to.be.equal(configuratorETHxAssetConfig.liquidationFactor);
expect(ETHxAssetConfig.supplyCap).to.be.equal(configuratorETHxAssetConfig.supplyCap);
},
});
2 changes: 1 addition & 1 deletion scenario/LiquidationBotScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ scenario(
const [initialNumAbsorbs, initialNumAbsorbed] = await comet.liquidatorPoints(betty.address);

const borrowCapacity = await borrowCapacityForAsset(comet, albert, 0);
const borrowAmount = (borrowCapacity.mul(getConfigForScenario(_context).liquidationDenominator)).div(100n);
const borrowAmount = (borrowCapacity.mul(getConfigForScenario(_context).liquidationNumerator)).div(100n);

await albert.withdrawAsset({
asset: baseToken,
Expand Down
7 changes: 6 additions & 1 deletion scenario/utils/scenarioHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ const config = {
liquidationBase1: 1000,
liquidationAsset: 200,
liquidationDenominator: 90,
liquidationNumerator: 90,
rewardsAsset: 10000,
rewardsBase: 1000,
transferBase: 1000,
transferAsset: 5000,
interestSeconds: 110
interestSeconds: 110,
};

export function getConfigForScenario(ctx: CometContext) {
Expand Down Expand Up @@ -42,6 +43,10 @@ export function getConfigForScenario(ctx: CometContext) {
config.interestSeconds = 70;
}

if (ctx.world.base.network === 'mainnet' && ctx.world.base.deployment === 'weth') {
config.liquidationNumerator = 60;
}

if (ctx.world.base.network === 'mainnet' && ctx.world.base.deployment === 'usds') {
config.liquidationAsset = 100;
}
Expand Down

0 comments on commit 5714ef9

Please sign in to comment.