forked from compound-finance/comet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
889f0a2
commit 855456a
Showing
2 changed files
with
214 additions
and
3 deletions.
There are no files selected for viewing
211 changes: 211 additions & 0 deletions
211
deployments/mainnet/weth/migrations/1721989723_add_usdt_and_usdc_as_collaterals.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
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 USDT_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; | ||
const USDT_PRICE_FEED_ADDRESS = '0xEe9F2375b4bdF6387aa8265dD4FB8F16512A1d46'; | ||
|
||
const USDC_ADDRESS = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'; | ||
const USDC_PRICE_FEED_ADDRESS = '0x986b5E1e1755e3C2440e960477f25201B0a8bbD4'; | ||
|
||
const NEW_FACTORY_ADDRESS = '0x89128FE4Fc91038C13220E74991F9557F816c865'; | ||
|
||
export default migration('1721989723_add_usdt_and_usdc_as_collaterals', { | ||
async prepare(deploymentManager: DeploymentManager) { | ||
const _usdtScalingPriceFeed = await deploymentManager.deploy( | ||
'USDT:priceFeed', | ||
'pricefeeds/ScalingPriceFeed.sol', | ||
[ | ||
USDT_PRICE_FEED_ADDRESS, // USDT / ETH price feed | ||
8 // decimals | ||
] | ||
); | ||
|
||
const _usdcScalingPriceFeed = await deploymentManager.deploy( | ||
'USDC:priceFeed', | ||
'pricefeeds/ScalingPriceFeed.sol', | ||
[ | ||
USDC_PRICE_FEED_ADDRESS, // USDC / ETH price feed | ||
8 // decimals | ||
] | ||
); | ||
return { usdtScalingPriceFeed: _usdtScalingPriceFeed.address, usdcScalingPriceFeed: _usdcScalingPriceFeed.address }; | ||
}, | ||
|
||
async enact(deploymentManager: DeploymentManager, _, { usdtScalingPriceFeed, usdcScalingPriceFeed }) { | ||
|
||
const trace = deploymentManager.tracer(); | ||
|
||
const USDT = await deploymentManager.existing( | ||
'USDT', | ||
USDT_ADDRESS, | ||
'mainnet', | ||
'contracts/ERC20.sol:ERC20' | ||
); | ||
const usdtPricefeed = await deploymentManager.existing( | ||
'USDT:priceFeed', | ||
usdtScalingPriceFeed, | ||
'mainnet' | ||
); | ||
|
||
const USDC = await deploymentManager.existing( | ||
'USDC', | ||
USDC_ADDRESS, | ||
'mainnet', | ||
'contracts/ERC20.sol:ERC20' | ||
); | ||
const usdcPricefeed = await deploymentManager.existing( | ||
'USDC:priceFeed', | ||
usdcScalingPriceFeed, | ||
'mainnet' | ||
); | ||
|
||
const { | ||
governor, | ||
comet, | ||
cometAdmin, | ||
configurator, | ||
} = await deploymentManager.getContracts(); | ||
|
||
const usdtAssetConfig = { | ||
asset: USDT.address, | ||
priceFeed: usdtPricefeed.address, | ||
decimals: await USDT.decimals(), | ||
borrowCollateralFactor: exp(0.80, 18), | ||
liquidateCollateralFactor: exp(0.85, 18), | ||
liquidationFactor: exp(0.95, 18), | ||
supplyCap: exp(50_000_000, 6), | ||
}; | ||
|
||
const usdcAssetConfig = { | ||
asset: USDC.address, | ||
priceFeed: usdcPricefeed.address, | ||
decimals: 6, | ||
borrowCollateralFactor: exp(0.80, 18), | ||
liquidateCollateralFactor: exp(0.85, 18), | ||
liquidationFactor: exp(0.95, 18), | ||
supplyCap: exp(50_000_000, 6), | ||
}; | ||
|
||
const mainnetActions = [ | ||
// 1. Set new factory | ||
{ | ||
contract: configurator, | ||
signature: 'setFactory(address,address)', | ||
args: [comet.address, NEW_FACTORY_ADDRESS], | ||
}, | ||
// 2. Add USDT as asset | ||
{ | ||
contract: configurator, | ||
signature: 'addAsset(address,(address,address,uint8,uint64,uint64,uint64,uint128))', | ||
args: [comet.address, usdtAssetConfig], | ||
}, | ||
// 3. Add USDC as asset | ||
{ | ||
contract: configurator, | ||
signature: 'addAsset(address,(address,address,uint8,uint64,uint64,uint64,uint128))', | ||
args: [comet.address, usdcAssetConfig], | ||
}, | ||
// 4. Deploy and upgrade to a new version of Comet | ||
{ | ||
contract: cometAdmin, | ||
signature: 'deployAndUpgradeTo(address,address)', | ||
args: [configurator.address, comet.address], | ||
}, | ||
]; | ||
|
||
const description = 'DESCRIPTION'; | ||
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}.`); | ||
// second proposal | ||
}, | ||
|
||
async enacted(): Promise<boolean> { | ||
return false; | ||
}, | ||
|
||
async verify(deploymentManager: DeploymentManager) { | ||
const { comet, configurator } = await deploymentManager.getContracts(); | ||
|
||
const usdtAssetIndex = Number(await comet.numAssets()) - 2; | ||
const usdcAssetIndex = Number(await comet.numAssets()) - 1; | ||
|
||
const USDT = await deploymentManager.existing( | ||
'USDT', | ||
USDT_ADDRESS, | ||
'mainnet', | ||
'contracts/ERC20.sol:ERC20' | ||
); | ||
const usdtAssetConfig = { | ||
asset: USDT.address, | ||
priceFeed: '', | ||
decimals: await USDT.decimals(), | ||
borrowCollateralFactor: exp(0.80, 18), | ||
liquidateCollateralFactor: exp(0.85, 18), | ||
liquidationFactor: exp(0.95, 18), | ||
supplyCap: exp(50_000_000, 6), | ||
}; | ||
|
||
const USDC = await deploymentManager.existing( | ||
'USDC', | ||
USDC_ADDRESS, | ||
'mainnet', | ||
'contracts/ERC20.sol:ERC20' | ||
); | ||
const usdcAssetConfig = { | ||
asset: USDC.address, | ||
priceFeed: '', | ||
decimals: 6, | ||
borrowCollateralFactor: exp(0.80, 18), | ||
liquidateCollateralFactor: exp(0.85, 18), | ||
liquidationFactor: exp(0.95, 18), | ||
supplyCap: exp(50_000_000, 6), | ||
}; | ||
|
||
// 1. Compare USDT asset config with Comet and Configurator asset info | ||
const cometUsdtAssetInfo = await comet.getAssetInfo(usdtAssetIndex); | ||
expect(usdtAssetIndex).to.be.equal(cometUsdtAssetInfo.offset); | ||
expect(usdtAssetConfig.asset).to.be.equal(cometUsdtAssetInfo.asset); | ||
expect(exp(1, usdtAssetConfig.decimals)).to.be.equal(cometUsdtAssetInfo.scale); | ||
expect(usdtAssetConfig.borrowCollateralFactor).to.be.equal(cometUsdtAssetInfo.borrowCollateralFactor); | ||
expect(usdtAssetConfig.liquidateCollateralFactor).to.be.equal(cometUsdtAssetInfo.liquidateCollateralFactor); | ||
expect(usdtAssetConfig.liquidationFactor).to.be.equal(cometUsdtAssetInfo.liquidationFactor); | ||
expect(usdtAssetConfig.supplyCap).to.be.equal(cometUsdtAssetInfo.supplyCap); | ||
|
||
const configuratorUsdtAssetConfig = (await configurator.getConfiguration(comet.address)).assetConfigs[usdtAssetIndex]; | ||
expect(usdtAssetConfig.asset).to.be.equal(configuratorUsdtAssetConfig.asset); | ||
expect(usdtAssetConfig.decimals).to.be.equal(configuratorUsdtAssetConfig.decimals); | ||
expect(usdtAssetConfig.borrowCollateralFactor).to.be.equal(configuratorUsdtAssetConfig.borrowCollateralFactor); | ||
expect(usdtAssetConfig.liquidateCollateralFactor).to.be.equal(configuratorUsdtAssetConfig.liquidateCollateralFactor); | ||
expect(usdtAssetConfig.liquidationFactor).to.be.equal(configuratorUsdtAssetConfig.liquidationFactor); | ||
expect(usdtAssetConfig.supplyCap).to.be.equal(configuratorUsdtAssetConfig.supplyCap); | ||
|
||
// 2. Compare USDC asset config with Comet and Configurator asset info | ||
const cometUsdcAssetInfo = await comet.getAssetInfo(usdcAssetIndex); | ||
expect(usdcAssetIndex).to.be.equal(cometUsdcAssetInfo.offset); | ||
expect(usdcAssetConfig.asset).to.be.equal(cometUsdcAssetInfo.asset); | ||
expect(exp(1, usdcAssetConfig.decimals)).to.be.equal(cometUsdcAssetInfo.scale); | ||
expect(usdcAssetConfig.borrowCollateralFactor).to.be.equal(cometUsdcAssetInfo.borrowCollateralFactor); | ||
expect(usdcAssetConfig.liquidateCollateralFactor).to.be.equal(cometUsdcAssetInfo.liquidateCollateralFactor); | ||
expect(usdcAssetConfig.liquidationFactor).to.be.equal(cometUsdcAssetInfo.liquidationFactor); | ||
expect(usdcAssetConfig.supplyCap).to.be.equal(cometUsdcAssetInfo.supplyCap); | ||
|
||
const configuratorUsdcAssetConfig = (await configurator.getConfiguration(comet.address)).assetConfigs[usdcAssetIndex]; | ||
expect(usdcAssetConfig.asset).to.be.equal(configuratorUsdcAssetConfig.asset); | ||
expect(usdcAssetConfig.decimals).to.be.equal(configuratorUsdcAssetConfig.decimals); | ||
expect(usdcAssetConfig.borrowCollateralFactor).to.be.equal(configuratorUsdcAssetConfig.borrowCollateralFactor); | ||
expect(usdcAssetConfig.liquidateCollateralFactor).to.be.equal(configuratorUsdcAssetConfig.liquidateCollateralFactor); | ||
expect(usdcAssetConfig.liquidationFactor).to.be.equal(configuratorUsdcAssetConfig.liquidationFactor); | ||
expect(usdcAssetConfig.supplyCap).to.be.equal(configuratorUsdcAssetConfig.supplyCap); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters