Skip to content

Commit

Permalink
get gas measurements, fix ftoken/ctoken vault gas. (#960)
Browse files Browse the repository at this point in the history
Co-authored-by: Taylor Brent <[email protected]>
  • Loading branch information
pmckelvy1 and tbrent authored Oct 7, 2023
1 parent faefb75 commit fccf5de
Show file tree
Hide file tree
Showing 36 changed files with 773 additions and 303 deletions.
4 changes: 3 additions & 1 deletion contracts/plugins/assets/compoundv2/CTokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ contract CTokenWrapper is RewardableERC20Wrapper {
// === Overrides ===

function _claimAssetRewards() internal virtual override {
comptroller.claimComp(address(this));
address[] memory cTokens = new address[](1);
cTokens[0] = address(underlying);
comptroller.claimComp(address(this), cTokens);
}

// No overrides of _deposit()/_withdraw() necessary: no staking required
Expand Down
2 changes: 1 addition & 1 deletion contracts/plugins/assets/compoundv2/ICToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface ICToken is IERC20Metadata {

interface IComptroller {
/// Claim comp for an account, to an account
function claimComp(address account) external;
function claimComp(address account, address[] memory cTokens) external;

/// @return The address for COMP token
function getCompAddress() external view returns (address);
Expand Down
4 changes: 3 additions & 1 deletion contracts/plugins/mocks/CTokenWrapperMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ contract CTokenWrapperMock is ERC20Mock, IRewardable {
revert("reverting claim rewards");
}
uint256 oldBal = comp.balanceOf(msg.sender);
comptroller.claimComp(msg.sender);
address[] memory cTokens = new address[](1);
cTokens[0] = address(underlying);
comptroller.claimComp(msg.sender, cTokens);
emit RewardsClaimed(IERC20(address(comp)), comp.balanceOf(msg.sender) - oldBal);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/plugins/mocks/ComptrollerMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract ComptrollerMock is IComptroller {
compBalances[recipient] = amount;
}

function claimComp(address holder) external {
function claimComp(address holder, address[] memory) external {
// Mint amount and update internal balances
if (address(compToken) != address(0)) {
uint256 amount = compBalances[holder];
Expand Down
24 changes: 12 additions & 12 deletions scripts/addresses/mainnet-3.0.0/1-tmp-assets-collateral.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"aUSDT": "0xe39188ddd4eb27d1d25f5f58cc6a5fd9228eedef",
"aBUSD": "0xeB1A036E83aD95f0a28d0c8E2F20bf7f1B299F05",
"aUSDP": "0x0d61Ce1801A460eB683b5ed1b6C7965d31b769Fd",
"cDAI": "0x440A634DdcFb890BCF8b0Bf07Ef2AaBB37dd5F8C",
"cUSDC": "0x50a9d529EA175CdE72525Eaa809f5C3c47dAA1bB",
"cUSDT": "0x5757fF814da66a2B4f9D11d48570d742e246CfD9",
"cUSDP": "0x99bD63BF7e2a69822cD73A82d42cF4b5501e5E50",
"cWBTC": "0x688c95461d611Ecfc423A8c87caCE163C6B40384",
"cETH": "0x357d4dB0c2179886334cC33B8528048F7E1D3Fe3",
"cDAI": "0x33A8d92B2BE84755441C2b6e39715c4b8938242c",
"cUSDC": "0x073F98792ef4c00bB5f11B1F64f13cB25Cde0d8D",
"cUSDT": "0x0EEa20c426EcE7D3dA5b73946bb1626697aA7c59",
"cUSDP": "0xA7eCF508CdF5a88ae93b899DE4fcACcB43112Ce8",
"cWBTC": "0xa570BF93FC51406809dBf52aB898913541C91C20",
"cETH": "0xeC12e8412a7AE4598d754f4016D487c269719856",
"WBTC": "0x87A959e0377C68A50b08a91ae5ab3aFA7F41ACA4",
"WETH": "0x6B87142C7e6cA80aa3E6ead0351673C45c8990e3",
"EURT": "0xEBD07CE38e2f46031c982136012472A4D24AE070",
Expand Down Expand Up @@ -65,12 +65,12 @@
"aUSDT": "0x21fe646D1Ed0733336F2D4d9b2FE67790a6099D9",
"aBUSD": "0xe639d53Aa860757D7fe9cD4ebF9C8b92b8DedE7D",
"aUSDP": "0x80A574cC2B369dc496af6655f57a16a4f180BfAF",
"cDAI": "0x3043be171e846c33D5f06864Cc045d9Fc799aF52",
"cUSDC": "0xf579F9885f1AEa0d3F8bE0F18AfED28c92a43022",
"cUSDT": "0x4Be33630F92661afD646081BC29079A38b879aA0",
"cUSDP": "0xF69c995129CC16d0F577C303091a400cC1879fFa",
"cWBTC": "0xF2A309bc36A504c772B416a4950d5d0021219745",
"cETH": "0xbF6E8F64547Bdec55bc3FBb0664722465FCC2F0F",
"cDAI": "0xD048934408bb0e39F23c7ff5C1ac5F773D16D2df",
"cUSDC": "0x1c21E28F6cd7C4Be734cb60f9c6451484803924d",
"cUSDT": "0xD971Fd59e90E836eCF2b8adE76374102025084A1",
"cUSDP": "0xbe7B053E820c5FBe70a0f075DA0C931aD8816e4F",
"cWBTC": "0xb120c3429900DDF665b34882d7685e39BB01897B",
"cETH": "0xd0cb758e918ac6973a2959343ECa4F333d8d25B1",
"WBTC": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
"WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"EURT": "0xC581b735A1688071A1746c968e0798D642EDE491",
Expand Down
1 change: 1 addition & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async function main() {
'phase2-assets/assets/deploy_crv.ts',
'phase2-assets/assets/deploy_cvx.ts',
'phase2-assets/2_deploy_collateral.ts',
'phase2-assets/collaterals/deploy_compound_v2_collateral.ts',
'phase2-assets/collaterals/deploy_lido_wsteth_collateral.ts',
'phase2-assets/collaterals/deploy_rocket_pool_reth_collateral.ts',
'phase2-assets/collaterals/deploy_flux_finance_collateral.ts',
Expand Down
236 changes: 0 additions & 236 deletions scripts/deployment/phase2-assets/2_deploy_collateral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,242 +445,6 @@ async function main() {
const btcOracleError = fp('0.005') // 0.5%
const combinedBTCWBTCError = combinedError(wbtcOracleError, btcOracleError)

/*** Compound V2 not available in Base L2s */
if (!baseL2Chains.includes(hre.network.name)) {
/******** Deploy CToken Fiat Collateral - cDAI **************************/
const CTokenFactory = await ethers.getContractFactory('CTokenWrapper')
const cDai = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cDAI!)

const cDaiVault = await CTokenFactory.deploy(
networkConfig[chainId].tokens.cDAI!,
`${await cDai.name()} Vault`,
`${await cDai.symbol()}-VAULT`,
networkConfig[chainId].COMPTROLLER!
)

await cDaiVault.deployed()

console.log(
`Deployed Vault for cDAI on ${hre.network.name} (${chainId}): ${cDaiVault.address} `
)

const { collateral: cDaiCollateral } = await hre.run('deploy-ctoken-fiat-collateral', {
priceTimeout: priceTimeout.toString(),
priceFeed: networkConfig[chainId].chainlinkFeeds.DAI,
oracleError: fp('0.0025').toString(), // 0.25%
cToken: cDaiVault.address,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: fp('0.0125').toString(), // 1.25%
delayUntilDefault: bn('86400').toString(), // 24h
revenueHiding: revenueHiding.toString(),
})
collateral = <ICollateral>await ethers.getContractAt('ICollateral', cDaiCollateral)
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

assetCollDeployments.collateral.cDAI = cDaiCollateral
assetCollDeployments.erc20s.cDAI = cDaiVault.address
deployedCollateral.push(cDaiCollateral.toString())

fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2))

/******** Deploy CToken Fiat Collateral - cUSDC **************************/
const cUsdc = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cUSDC!)

const cUsdcVault = await CTokenFactory.deploy(
networkConfig[chainId].tokens.cUSDC!,
`${await cUsdc.name()} Vault`,
`${await cUsdc.symbol()}-VAULT`,
networkConfig[chainId].COMPTROLLER!
)

await cUsdcVault.deployed()

console.log(
`Deployed Vault for cUSDC on ${hre.network.name} (${chainId}): ${cUsdcVault.address} `
)

const { collateral: cUsdcCollateral } = await hre.run('deploy-ctoken-fiat-collateral', {
priceTimeout: priceTimeout.toString(),
priceFeed: networkConfig[chainId].chainlinkFeeds.USDC,
oracleError: fp('0.0025').toString(), // 0.25%
cToken: cUsdcVault.address,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: fp('0.0125').toString(), // 1.25%
delayUntilDefault: bn('86400').toString(), // 24h
revenueHiding: revenueHiding.toString(),
})
collateral = <ICollateral>await ethers.getContractAt('ICollateral', cUsdcCollateral)
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

assetCollDeployments.collateral.cUSDC = cUsdcCollateral
assetCollDeployments.erc20s.cUSDC = cUsdcVault.address
deployedCollateral.push(cUsdcCollateral.toString())

fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2))

/******** Deploy CToken Fiat Collateral - cUSDT **************************/
const cUsdt = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cUSDT!)

const cUsdtVault = await CTokenFactory.deploy(
networkConfig[chainId].tokens.cUSDT!,
`${await cUsdt.name()} Vault`,
`${await cUsdt.symbol()}-VAULT`,
networkConfig[chainId].COMPTROLLER!
)

await cUsdtVault.deployed()

console.log(
`Deployed Vault for cUSDT on ${hre.network.name} (${chainId}): ${cUsdtVault.address} `
)

const { collateral: cUsdtCollateral } = await hre.run('deploy-ctoken-fiat-collateral', {
priceTimeout: priceTimeout.toString(),
priceFeed: networkConfig[chainId].chainlinkFeeds.USDT,
oracleError: fp('0.0025').toString(), // 0.25%
cToken: cUsdtVault.address,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: fp('0.0125').toString(), // 1.25%
delayUntilDefault: bn('86400').toString(), // 24h
revenueHiding: revenueHiding.toString(),
})
collateral = <ICollateral>await ethers.getContractAt('ICollateral', cUsdtCollateral)
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

assetCollDeployments.collateral.cUSDT = cUsdtCollateral
assetCollDeployments.erc20s.cUSDT = cUsdtVault.address
deployedCollateral.push(cUsdtCollateral.toString())

fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2))

/******** Deploy CToken Fiat Collateral - cUSDP **************************/
const cUsdp = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cUSDP!)

const cUsdpVault = await CTokenFactory.deploy(
networkConfig[chainId].tokens.cUSDP!,
`${await cUsdp.name()} Vault`,
`${await cUsdp.symbol()}-VAULT`,
networkConfig[chainId].COMPTROLLER!
)

await cUsdpVault.deployed()

console.log(
`Deployed Vault for cUSDP on ${hre.network.name} (${chainId}): ${cUsdpVault.address} `
)

const { collateral: cUsdpCollateral } = await hre.run('deploy-ctoken-fiat-collateral', {
priceTimeout: priceTimeout.toString(),
priceFeed: networkConfig[chainId].chainlinkFeeds.USDP,
oracleError: fp('0.01').toString(), // 1%
cToken: cUsdpVault.address,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr
targetName: hre.ethers.utils.formatBytes32String('USD'),
defaultThreshold: fp('0.02').toString(), // 2%
delayUntilDefault: bn('86400').toString(), // 24h
revenueHiding: revenueHiding.toString(),
})
collateral = <ICollateral>await ethers.getContractAt('ICollateral', cUsdpCollateral)
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

assetCollDeployments.collateral.cUSDP = cUsdpCollateral
assetCollDeployments.erc20s.cUSDP = cUsdpVault.address
deployedCollateral.push(cUsdpCollateral.toString())

fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2))

/******** Deploy CToken Non-Fiat Collateral - cWBTC **************************/
const cWBTC = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cWBTC!)

const cWBTCVault = await CTokenFactory.deploy(
networkConfig[chainId].tokens.cWBTC!,
`${await cWBTC.name()} Vault`,
`${await cWBTC.symbol()}-VAULT`,
networkConfig[chainId].COMPTROLLER!
)

await cWBTCVault.deployed()

console.log(
`Deployed Vault for cWBTC on ${hre.network.name} (${chainId}): ${cWBTCVault.address} `
)

const { collateral: cWBTCCollateral } = await hre.run('deploy-ctoken-nonfiat-collateral', {
priceTimeout: priceTimeout.toString(),
referenceUnitFeed: networkConfig[chainId].chainlinkFeeds.WBTC,
targetUnitFeed: networkConfig[chainId].chainlinkFeeds.BTC,
combinedOracleError: combinedBTCWBTCError.toString(),
cToken: cWBTCVault.address,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24 hr
targetUnitOracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr
targetName: hre.ethers.utils.formatBytes32String('BTC'),
defaultThreshold: fp('0.01').add(combinedBTCWBTCError).toString(), // ~3.5%
delayUntilDefault: bn('86400').toString(), // 24h
revenueHiding: revenueHiding.toString(),
})
collateral = <ICollateral>await ethers.getContractAt('ICollateral', cWBTCCollateral)
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

assetCollDeployments.collateral.cWBTC = cWBTCCollateral
assetCollDeployments.erc20s.cWBTC = cWBTCVault.address
deployedCollateral.push(cWBTCCollateral.toString())

fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2))

/******** Deploy CToken Self-Referential Collateral - cETH **************************/
const cETH = await ethers.getContractAt('IERC20Metadata', networkConfig[chainId].tokens.cETH!)

const cETHVault = await CTokenFactory.deploy(
networkConfig[chainId].tokens.cETH!,
`${await cETH.name()} Vault`,
`${await cETH.symbol()}-VAULT`,
networkConfig[chainId].COMPTROLLER!
)

await cETHVault.deployed()

console.log(
`Deployed Vault for cETH on ${hre.network.name} (${chainId}): ${cETHVault.address} `
)

const { collateral: cETHCollateral } = await hre.run(
'deploy-ctoken-selfreferential-collateral',
{
priceTimeout: priceTimeout.toString(),
priceFeed: networkConfig[chainId].chainlinkFeeds.ETH,
oracleError: fp('0.005').toString(), // 0.5%
cToken: cETHVault.address,
maxTradeVolume: fp('1e6').toString(), // $1m,
oracleTimeout: oracleTimeout(chainId, '3600').toString(), // 1 hr
targetName: hre.ethers.utils.formatBytes32String('ETH'),
revenueHiding: revenueHiding.toString(),
referenceERC20Decimals: '18',
}
)
collateral = <ICollateral>await ethers.getContractAt('ICollateral', cETHCollateral)
await (await collateral.refresh()).wait()
expect(await collateral.status()).to.equal(CollateralStatus.SOUND)

assetCollDeployments.collateral.cETH = cETHCollateral
assetCollDeployments.erc20s.cETH = cETHVault.address
deployedCollateral.push(cETHCollateral.toString())

fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2))
}

/******** Deploy Non-Fiat Collateral - wBTC **************************/
if (
networkConfig[chainId].tokens.WBTC &&
Expand Down
Loading

0 comments on commit fccf5de

Please sign in to comment.