8000 Add sdeUSD to cUSDSv3 on Mainnet by MishaShWoof · Pull Request #994 · compound-finance/comet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add sdeUSD to cUSDSv3 on Mainnet #994

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/enact-migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:
GOV_NETWORK_PROVIDER: ${{ fromJSON('["", "http://localhost:8685"]')[github.event.inputs.eth_pk == '' && env.GOV_NETWORK != ''] }}
GOV_NETWORK: ${{ env.GOV_NETWORK }}
REMOTE_ACCOUNTS: ${{ fromJSON('["", "true"]')[github.event.inputs.eth_pk == ''] }}
if: github.event.inputs.impersonateAccount != '' && github.event.inputs.with_deploy == 'false'
if: github.event.inputs.impersonateAccount != '' && github.event.inputs.with_deploy == 'false' && github.event.inputs.run_id == ''
- name: Commit changes
if: ${{ github.event.inputs.simulate == 'false' }}
run: |
Expand Down
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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 SDEUSD_ADDRESS = '0x5C5b196aBE0d54485975D1Ec29617D42D9198326';
const SDEUSD_TO_USD_PRICE_FEED = '0xE4829421ae79f2F44716cCbbb40751cd6Be3d483';

export default migration('1750348269_add_sdeusd_collateral', {
async prepare() {
return {};
},

async enact(deploymentManager: DeploymentManager) {
const trace = deploymentManager.tracer();

const sdeUSD = await deploymentManager.existing(
'sdeUSD',
SDEUSD_ADDRESS,
'mainnet',
'contracts/ERC20.sol:ERC20'
);

const sdeUSDPriceFeed = await deploymentManager.existing(
'sdeUSD:priceFeed',
SDEUSD_TO_USD_PRICE_FEED,
'mainnet'
);

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

const sdeUSDAssetConfig = {
asset: sdeUSD.address,
priceFeed: sdeUSDPriceFeed.address,
decimals: await sdeUSD.decimals(),
borrowCollateralFactor: exp(0.88, 18),
liquidateCollateralFactor: exp(0.90, 18),
liquidationFactor: exp(0.94, 18),
supplyCap: exp(5_000_000, 18),
};

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

const description = '# Add sdeUSD as collateral into cUSDSv3 on Mainnet\n\n## Proposal summary\n\nWOOF! proposes to add sdeUSD into cUSDSv3 on Ethereum network. This proposal takes the governance steps recommended and necessary to update a Compound III USDS 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/add-collateral-deusd-sdeusd-staked-on-usdc-usds-usdt-on-mainnet/6112/6).\n\nFurther detailed information can be found on the corresponding [proposal pull request](https://github.com/compound-finance/comet/pull/994) and [forum discussion](https://www.comp.xyz/t/add-collateral-deusd-sdeusd-staked-on-usdc-usds-usdt-on-mainnet/6112).\n\n\n## Proposal Actions\n\nThe first action adds sdeUSD 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(): Promise<boolean> {
return false;
},

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

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

const sdeUSD = await deploymentManager.existing(
'sdeUSD',
SDEUSD_ADDRESS,
'mainnet',
'contracts/ERC20.sol:ERC20'
);
const deUSDAssetConfig = {
asset: sdeUSD.address,
priceFeed: SDEUSD_TO_USD_PRICE_FEED,
decimals: 18n,
borrowCollateralFactor: exp(0.88, 18),
liquidateCollateralFactor: exp(0.90, 18),
liquidationFactor: exp(0.94, 18),
supplyCap: exp(5_000_000, 18),
};

// 1. Compare sdeUSD asset config with Comet and Configurator asset info
const cometSdeUSDAssetInfo = await comet.getAssetInfoByAddress(SDEUSD_ADDRESS);
expect(sdeUSDAssetIndex).to.be.equal(cometSdeUSDAssetInfo.offset);
expect(deUSDAssetConfig.asset).to.be.equal(cometSdeUSDAssetInfo.asset);
expect(deUSDAssetConfig.priceFeed).to.be.equal(cometSdeUSDAssetInfo.priceFeed);
expect(exp(1, deUSDAssetConfig.decimals)).to.be.equal(cometSdeUSDAssetInfo.scale);
expect(deUSDAssetConfig.borrowCollateralFactor).to.be.equal(cometSdeUSDAssetInfo.borrowCollateralFactor);
expect(deUSDAssetConfig.liquidateCollateralFactor).to.be.equal(cometSdeUSDAssetInfo.liquidateCollateralFactor);
expect(deUSDAssetConfig.liquidationFactor).to.be.equal(cometSdeUSDAssetInfo.liquidationFactor);
expect(deUSDAssetConfig.supplyCap).to.be.equal(cometSdeUSDAssetInfo.supplyCap);

const configuratorSdeUSDAssetConfig = (await configurator.getConfiguration(comet.address)).assetConfigs[sdeUSDAssetIndex];
expect(deUSDAssetConfig.asset).to.be.equal(configuratorSdeUSDAssetConfig.asset);
expect(deUSDAssetConfig.priceFeed).to.be.equal(configuratorSdeUSDAssetConfig.priceFeed);
expect(deUSDAssetConfig.decimals).to.be.equal(configuratorSdeUSDAssetConfig.decimals);
expect(deUSDAssetConfig.borrowCollateralFactor).to.be.equal(configuratorSdeUSDAssetConfig.borrowCollateralFactor);
expect(deUSDAssetConfig.liquidateCollateralFactor).t 8000 o.be.equal(configuratorSdeUSDAssetConfig.liquidateCollateralFactor);
expect(deUSDAssetConfig.liquidationFactor).to.be.equal(configuratorSdeUSDAssetConfig.liquidationFactor);
expect(deUSDAssetConfig.supplyCap).to.be.equal(configuratorSdeUSDAssetConfig.supplyCap);
},
});
8 changes: 8 additions & 0 deletions deployments/mainnet/usds/relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ export default {
}
}
},
UUPSProxy: {
artifact: 'contracts/ERC20.sol:ERC20',
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
}
}
},
};
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const {
SCROLLSCAN_KEY,
ANKR_KEY,
_TENDERLY_KEY_RONIN,
MNEMONIC = 'myth like bonus scare over problem client lizard pioneer submit female collect',
MNEMONIC = 'myth like woof scare over problem client lizard pioneer submit female collect',
REPORT_GAS = 'false',
NETWORK_PROVIDER = '',
GOV_NETWORK_PROVIDER = '',
Expand Down Expand Up @@ -111,7 +111,7 @@ interface NetworkConfig {
gasPrice?: number | 'auto';
}

const networkConfigs: NetworkConfig[] = [
export const networkConfigs: NetworkConfig[] = [
{
network: 'mainnet',
chainId: 1,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@
"repository": "git@github.com:compound-finance/comet.git",
"resolutions": {
"mocha": "^9.1.3"
}
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
48 changes: 31 additions & 17 deletions plugins/import/etherscan.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
import axios from 'axios';
import { networkConfigs } from '../../hardhat.config';

export interface Result {
status: string;
message: string;
result: string;
}

// Updated because of Etherscan V2 update. Not tested and could lead to issues
export function getEtherscanApiUrl(network: string): string {
let host = {
rinkeby: 'api-rinkeby.etherscan.io',
ropsten: 'api-ropsten.etherscan.io',
sepolia: 'api-sepolia.etherscan.io',
mainnet: 'api.etherscan.io',
fuji: 'api-testnet.snowtrace.io',
avalanche: 'api.snowtrace.io',
polygon: 'api.polygonscan.com',
arbitrum: 'api.arbiscan.io',
base: 'api.basescan.org',
optimism: 'api-optimistic.etherscan.io',
mantle: 'api.mantlescan.xyz',
'ronin': 'explorer-kintsugi.roninchain.com/v2/2020',
scroll: 'api.scrollscan.com'
}[network];
// let host = {
// rinkeby: 'api-rinkeby.etherscan.io',
// ropsten: 'api-ropsten.etherscan.io',
// sepolia: 'api-sepolia.etherscan.io',
// mainnet: 'api.etherscan.io',
// fuji: 'api-testnet.snowtrace.io',
// avalanche: 'api.snowtrace.io',
// polygon: 'api.polygonscan.com',
// arbitrum: 'api.arbiscan.io',
// base: 'api.basescan.org',
// optimism: 'api-optimistic.etherscan.io',
// mantle: 'api.mantlescan.xyz',
// 'ronin': 'explorer-kintsugi.roninchain.com/v2/2020',
// scroll: 'api.scrollscan.com'
// }[network];

if (!host) {
// if (!host) {
// throw new Error(`Unknown etherscan API host for network ${network}`);
// }

const chainId = networkConfigs.find(config => config.network.toLowerCase() === network.toLowerCase())?.chainId;

if (!chainId) {
throw new Error(`Unknown etherscan API host for network ${network}`);
}

return `https://${host}/api`;
if (network === 'avalanche') {
return `https://api.snowtrace.io/api`;
} else if (network === 'fuji') {
return `https://api-testnet.snowtrace.io/api`;
}

return `https://api.etherscan.io/v2/api?chainid=${chainId}`;
}

export function getEtherscanUrl(network: string): string {
Expand Down
8 changes: 4 additions & 4 deletions plugins/import/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ async function scrapeContractCreationCodeFromEtherscanApi(network: string, addre
address,
apikey: getEtherscanApiKey(network)
};
const url = `${getEtherscanApiUrl(network)}?${paramString(params)}`;
const debugUrl = `${getEtherscanApiUrl(network)}?${paramString({ ...params, ...{ apikey: '[API_KEY]' } })}`;
const url = `${getEtherscanApiUrl(network)}&${paramString(params)}`;
const debugUrl = `${getEtherscanApiUrl(network)}&${paramString({ ...params, ...{ apikey: '[API_KEY]' } })}`;

debug(`Attempting to pull Contract Creation code from API at ${debugUrl}`);
const result = await get(url, {});
Expand Down Expand Up @@ -328,8 +328,8 @@ async function pullFirstTransactionForContractFromEtherscan(network: string, add
sort: 'asc',
apikey: getEtherscanApiKey(network)
};
const url = `${getEtherscanApiUrl(network)}?${paramString(params)}`;
const debugUrl = `${getEtherscanApiUrl(network)}?${paramString({ ...params, ...{ apikey: '[API_KEY]' } })}`;
const url = `${getEtherscanApiUrl(network)}&${paramString(params)}`;
const debugUrl = `${getEtherscanApiUrl(network)}&${paramString({ ...params, ...{ apikey: '[API_KEY]' } })}`;

debug(`Attempting to pull Contract Creation code from first tx at ${debugUrl}`);
const result = await get(url, {});
Expand Down
33 changes: 29 additions & 4 deletions scenario/BulkerScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ async function hasNativeAsCollateralOrBase(ctx: CometContext): Promise<boolean>
}
}

async function getNativeCollateralIndex(ctx: CometContext): Promise<number> {
if(!(await hasNativeAsCollateralOrBase(ctx)))
throw new Error('No native token collateral found');
const comet = await ctx.getComet();
const bulker = await ctx.getBulker();
const wrappedNativeToken = await bulker.wrappedNativeToken();
if ((await comet.baseToken()).toLowerCase() === wrappedNativeToken.toLowerCase())
throw new Error('Native token is base token, not collateral');
const numAssets = await comet.numAssets();
for (let i = 0; i < numAssets; i++) {
const { asset } = await comet.getAssetInfo(i);
if (asset.toLowerCase() === wrappedNativeToken.toLowerCase()) {
return i;
}
}
}

scenario(
'Comet#bulker > (non-WETH base) all non-reward actions in one txn for single asset',
{
Expand Down Expand Up @@ -100,8 +117,12 @@ scenario(
const baseIndexScale = (await comet.baseIndexScale()).toBigInt();
const baseSupplyIndex = (await comet.totalsBasic()).baseSupplyIndex.toBigInt();
const baseTransferred = getExpectedBaseBalance(toTransferBase, baseIndexScale, baseSupplyIndex);
expect(await comet.collateralBalanceOf(albert.address, collateralAsset.address)).to.be.equal(toSupplyCollateral);
if (await hasNativeAsCollateralOrBase(context)) expect(await comet.collateralBalanceOf(albert.address, wrappedNativeToken)).to.be.equal(toSupplyEth - toWithdrawEth);
if(await getNativeCollateralIndex(context) === 0)
expect(await comet.collateralBalanceOf(albert.address, collateralAsset.address)).to.be.equal(toSupplyCollateral + toSupplyEth - toWithdrawEth);
else{
expect(await comet.collateralBalanceOf(albert.address, collateralAsset.address)).to.be.equal(toSupplyCollateral);
if (await hasNativeAsCollateralOrBase(context)) expect(await comet.collateralBalanceOf(albert.address, wrappedNativeToken)).to.be.equal(toSupplyEth - toWithdrawEth);
}
expect(await baseAsset.balanceOf(albert.address)).to.be.equal(toBorrowBase);
expectBase((await comet.balanceOf(betty.address)).toBigInt(), baseTransferred);
expectBase((await comet.borrowBalanceOf(albert.address)).toBigInt(), toBorrowBase + toTransferBase);
Expand Down Expand Up @@ -386,9 +407,13 @@ scenario(
const baseIndexScale = (await comet.baseIndexScale()).toBigInt();
const baseSupplyIndex = (await comet.totalsBasic()).baseSupplyIndex.toBigInt();
const baseTransferred = getExpectedBaseBalance(toTransferBase, baseIndexScale, baseSupplyIndex);
expect(await comet.collateralBalanceOf(albert.address, collateralAsset.address)).to.be.equal(toSupplyCollateral);
if(await getNativeCollateralIndex(context) === 0)
expect(await comet.collateralBalanceOf(albert.address, collateralAsset.address)).to.be.equal(toSupplyCollateral + toSupplyEth - toWithdrawEth);
else{
expect(await comet.collateralBalanceOf(albert.address, collateralAsset.address)).to.be.equal(toSupplyCollateral);
if (await hasNativeAsCollateralOrBase(context)) expect(await comet.collateralBalanceOf(albert.address, wrappedNativeToken)).to.be.equal(toSupplyEth - toWithdrawEth);
}
expect(await baseAsset.balanceOf(albert.address)).to.be.equal(toBorrowBase);
if (await hasNativeAsCollateralOrBase(context)) expect(await comet.collateralBalanceOf(albert.address, wrappedNativeToken)).to.be.equal(toSupplyEth - toWithdrawEth);
expect(await albert.getErc20Balance(rewardTokenAddress)).to.be.equal(expectedFinalRewardBalance);
expectBase((await comet.balanceOf(betty.address)).toBigInt(), baseTransferred);
expectBase((await comet.borrowBalanceOf(albert.address)).toBigInt(), toBorrowBase + toTransferBase);
Expand Down
0