-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add mETH as collateral to USDT market on Mainnet #918
Open
MishaShWoof
wants to merge
19
commits into
compound-finance:main
Choose a base branch
from
woof-software:woof-software/add-meth-to-mainnet-usdt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d940b1a
feat: add migration and type fix
MishaShWoof 06a6d43
Merge branch 'main' into woof-software/add-meth-to-mainnet-usdt
EviLord032 fe9a21c
fix: update pr link
MishaShWoof 69f9891
fix: working workflow
MishaShWoof 9ce23e4
fix: additional workflow fixes
MishaShWoof 91b09eb
fix: final fix to workflow
MishaShWoof 51d804b
fix: relations
MishaShWoof 8e8749a
update versions and fix one relation
MishaShWoof b9ab002
Merge branch 'woof-software/workflow-version-update' of github.com:wo…
MishaShWoof 7268d09
Merge branch 'main' of github.com:woof-software/comet into woof-softw…
MishaShWoof 279e034
feat: contracts
MishaShWoof 4be0acb
Merge branch 'woof-software/meth-price-feed' of github.com:woof-softw…
MishaShWoof 3cff00d
fix: audit
MishaShWoof 99b05ed
Merge branch 'woof-software/meth-price-feed' of github.com:woof-softw…
MishaShWoof 4d8684f
fix: update
MishaShWoof 74d0d33
Merge branch 'main' into woof-software/add-meth-to-mainnet-usdt
MishaShWoof 05bc49c
fix: comment fix
MishaShWoof 4adceb5
Merge branch 'woof-software/meth-price-feed' of github.com:woof-softw…
MishaShWoof a0ac515
Merge branch 'woof-software/add-meth-to-mainnet-usdt' of https://gith…
MishaShWoof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,99 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.15; | ||
|
||
import "../vendor/mantle/IRateProvider.sol"; | ||
import "../IPriceFeed.sol"; | ||
|
||
/** | ||
* @title mETH Scaling price feed | ||
* @notice A custom price feed that scales up or down the price received from an underlying Renzo mETH / ETH exchange rate price feed and returns the result | ||
* @author Compound | ||
*/ | ||
contract METHExchangeRatePriceFeed is IPriceFeed { | ||
/** Custom errors **/ | ||
error InvalidInt256(); | ||
error BadDecimals(); | ||
|
||
/// @notice Version of the price feed | ||
uint public constant VERSION = 1; | ||
|
||
/// @notice Description of the price feed | ||
string public description; | ||
|
||
/// @notice Number of decimals for returned prices | ||
uint8 public immutable override decimals; | ||
|
||
/// @notice mETH price feed where prices are fetched from | ||
address public immutable underlyingPriceFeed; | ||
|
||
/// @notice Whether or not the price should be upscaled | ||
bool internal immutable shouldUpscale; | ||
|
||
/// @notice The amount to upscale or downscale the price by | ||
int256 internal immutable rescaleFactor; | ||
|
||
/** | ||
* @notice Construct a new mETH scaling price feed | ||
* @param mETHRateProvider The address of the underlying price feed to fetch prices from | ||
* @param decimals_ The number of decimals for the returned prices | ||
**/ | ||
constructor(address mETHRateProvider, uint8 decimals_, string memory description_) { | ||
underlyingPriceFeed = mETHRateProvider; | ||
if (decimals_ > 18) revert BadDecimals(); | ||
decimals = decimals_; | ||
description = description_; | ||
|
||
uint8 mETHRateProviderDecimals = 18; | ||
// Note: Solidity does not allow setting immutables in if/else statements | ||
shouldUpscale = mETHRateProviderDecimals < decimals_ ? true : false; | ||
rescaleFactor = (shouldUpscale | ||
? signed256(10 ** (decimals_ - mETHRateProviderDecimals)) | ||
: signed256(10 ** (mETHRateProviderDecimals - decimals_)) | ||
); | ||
} | ||
Comment on lines
+40
to
+53
Check warning Code scanning / Semgrep OSS Semgrep Finding: compound.solidity.missing-constructor-sanity-checks
There're no sanity checks for the constructor argument mETHRateProvider.
Comment on lines
+40
to
+53
Check notice Code scanning / Semgrep OSS Semgrep Finding: rules.solidity.performance.non-payable-constructor
Consider making costructor payable to save gas.
|
||
|
||
/** | ||
* @notice Price for the latest round | ||
* @return roundId Round id from the underlying price feed | ||
* @return answer Latest price for the asset in terms of ETH | ||
* @return startedAt Timestamp when the round was started; passed on from underlying price feed | ||
* @return updatedAt Timestamp when the round was last updated; passed on from underlying price feed | ||
* @return answeredInRound Round id in which the answer was computed; passed on from underlying price feed | ||
**/ | ||
function latestRoundData() override external view returns ( | ||
uint80 roundId, | ||
int256 answer, | ||
uint256 startedAt, | ||
uint256 updatedAt, | ||
uint80 answeredInRound | ||
) { | ||
// https://etherscan.io/address/0xe3cBd06D7dadB3F4e6557bAb7EdD924CD1489E8f#readProxyContract#F19 | ||
// rate = 1 mETH in ETH | ||
uint256 rate = IRateProvider(underlyingPriceFeed).mETHToETH(1e18); | ||
// protocol uses only the answer value. Other data fields are not provided by the underlying pricefeed and are not used in Comet protocol | ||
return (1, scalePrice(signed256(rate)), block.timestamp, block.timestamp, 1); | ||
} | ||
|
||
function signed256(uint256 n) internal pure returns (int256) { | ||
if (n > uint256(type(int256).max)) revert InvalidInt256(); | ||
return int256(n); | ||
} | ||
|
||
function scalePrice(int256 price) internal view returns (int256) { | ||
int256 scaledPrice; | ||
if (shouldUpscale) { | ||
scaledPrice = price * rescaleFactor; | ||
} else { | ||
scaledPrice = price / rescaleFactor; | ||
} | ||
return scaledPrice; | ||
} | ||
|
||
/** | ||
* @notice Price for the latest round | ||
* @return The version of the price feed contract | ||
**/ | ||
function version() external pure returns (uint256) { | ||
return VERSION; | ||
} | ||
} |
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,6 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.15; | ||
|
||
interface IRateProvider { | ||
function mETHToETH(uint256) external view returns (uint256); | ||
} |
145 changes: 145 additions & 0 deletions
145
deployments/mainnet/usdt/migrations/1726138937_add_meth_collateral.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,145 @@ | ||
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 METH_ADDRESS = '0xd5F7838F5C461fefF7FE49ea5ebaF7728bB0ADfa'; | ||
const METH_EXCHANGE_RATE_PROVIDER_ADDRESS = '0xe3cBd06D7dadB3F4e6557bAb7EdD924CD1489E8f'; | ||
let newPriceFeedAddress: string; | ||
|
||
export default migration('1726138937_add_meth_collateral', { | ||
async prepare(deploymentManager: DeploymentManager) { | ||
const _mETHToETHPriceFeed = await deploymentManager.deploy( | ||
'mETH:priceFeedToETH', | ||
'pricefeeds/METHExchangeRatePriceFeed.sol', | ||
[ | ||
METH_EXCHANGE_RATE_PROVIDER_ADDRESS, // mETH / ETH price feed | ||
8, // decimals | ||
'mETH/ETH exchange rate', // description | ||
] | ||
); | ||
const ethToUSDPriceFeed = await deploymentManager.fromDep('WETH:priceFeed', 'mainnet', 'usdt'); | ||
|
||
const _mETHPriceFeed = await deploymentManager.deploy( | ||
'mETH:priceFeed', | ||
'pricefeeds/MultiplicativePriceFeed.sol', | ||
[ | ||
_mETHToETHPriceFeed.address, // mETH / ETH price feed | ||
ethToUSDPriceFeed.address, // ETH / USD price feed | ||
8, // decimals | ||
'wstETH / ETH price feed' // description | ||
] | ||
); | ||
return { mETHPriceFeedAddress: _mETHPriceFeed.address }; | ||
}, | ||
|
||
async enact(deploymentManager: DeploymentManager, _, { mETHPriceFeedAddress }) { | ||
|
||
const trace = deploymentManager.tracer(); | ||
|
||
const mETH = await deploymentManager.existing( | ||
'mETH', | ||
METH_ADDRESS, | ||
'mainnet', | ||
'contracts/ERC20.sol:ERC20' | ||
); | ||
const mEthPriceFeed = await deploymentManager.existing( | ||
'mETH:priceFeed', | ||
mETHPriceFeedAddress, | ||
'mainnet' | ||
); | ||
|
||
newPriceFeedAddress = mEthPriceFeed.address; | ||
|
||
const { | ||
governor, | ||
comet, | ||
cometAdmin, | ||
configurator, | ||
} = await deploymentManager.getContracts(); | ||
|
||
const mETHAssetConfig = { | ||
asset: mETH.address, | ||
priceFeed: mEthPriceFeed.address, | ||
decimals: await mETH.decimals(), | ||
borrowCollateralFactor: exp(0.8, 18), | ||
liquidateCollateralFactor: exp(0.85, 18), | ||
liquidationFactor: exp(0.95, 18), | ||
supplyCap: exp(4000, 18), | ||
}; | ||
|
||
const mainnetActions = [ | ||
// 1. Add mETH as asset | ||
{ | ||
contract: configurator, | ||
signature: 'addAsset(address,(address,address,uint8,uint64,uint64,uint64,uint128))', | ||
args: [comet.address, mETHAssetConfig], | ||
}, | ||
// 2. Deploy and upgrade to a new version of Comet | ||
{ | ||
contract: cometAdmin, | ||
signature: 'deployAndUpgradeTo(address,address)', | ||
args: [configurator.address, comet.address], | ||
}, | ||
]; | ||
|
||
const description = '# Add mETH as collateral into cUSDTv3 on Mainnet\n\n## Proposal summary\n\nCompound Growth Program [AlphaGrowth] proposes to add mETH into cUSDTv3 on Ethereum network. This proposal takes the governance steps recommended and necessary to update a Compound III USDT 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-meth-market-on-ethereum/5647/5).\n\nFurther detailed information can be found on the corresponding [proposal pull request](https://github.com/compound-finance/comet/pull/918) and [forum discussion](https://www.comp.xyz/t/add-meth-market-on-ethereum/5647).\n\n\n## Proposal Actions\n\nThe first action adds mETH 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 mETHAssetIndex = Number(await comet.numAssets()) - 1; | ||
|
||
const mETH = await deploymentManager.existing( | ||
'mETH', | ||
METH_ADDRESS, | ||
'mainnet', | ||
'contracts/ERC20.sol:ERC20' | ||
); | ||
const mETHAssetConfig = { | ||
asset: mETH.address, | ||
priceFeed: newPriceFeedAddress, | ||
decimals: await mETH.decimals(), | ||
borrowCollateralFactor: exp(0.8, 18), | ||
liquidateCollateralFactor: exp(0.85, 18), | ||
liquidationFactor: exp(0.95, 18), | ||
supplyCap: exp(4000, 18), | ||
}; | ||
|
||
// 1. Compare mETH asset config with Comet and Configurator asset info | ||
const cometMETHAssetInfo = await comet.getAssetInfoByAddress(METH_ADDRESS); | ||
expect(mETHAssetIndex).to.be.equal(cometMETHAssetInfo.offset); | ||
expect(mETHAssetConfig.asset).to.be.equal(cometMETHAssetInfo.asset); | ||
expect(mETHAssetConfig.priceFeed).to.be.equal(cometMETHAssetInfo.priceFeed); | ||
expect(exp(1, mETHAssetConfig.decimals)).to.be.equal(cometMETHAssetInfo.scale); | ||
expect(mETHAssetConfig.borrowCollateralFactor).to.be.equal(cometMETHAssetInfo.borrowCollateralFactor); | ||
expect(mETHAssetConfig.liquidateCollateralFactor).to.be.equal(cometMETHAssetInfo.liquidateCollateralFactor); | ||
expect(mETHAssetConfig.liquidationFactor).to.be.equal(cometMETHAssetInfo.liquidationFactor); | ||
expect(mETHAssetConfig.supplyCap).to.be.equal(cometMETHAssetInfo.supplyCap); | ||
|
||
const configuratorMETHAssetConfig = (await configurator.getConfiguration(comet.address)).assetConfigs[mETHAssetIndex]; | ||
expect(mETHAssetConfig.asset).to.be.equal(configuratorMETHAssetConfig.asset); | ||
expect(mETHAssetConfig.priceFeed).to.be.equal(configuratorMETHAssetConfig.priceFeed); | ||
expect(mETHAssetConfig.decimals).to.be.equal(configuratorMETHAssetConfig.decimals); | ||
expect(mETHAssetConfig.borrowCollateralFactor).to.be.equal(configuratorMETHAssetConfig.borrowCollateralFactor); | ||
expect(mETHAssetConfig.liquidateCollateralFactor).to.be.equal(configuratorMETHAssetConfig.liquidateCollateralFactor); | ||
expect(mETHAssetConfig.liquidationFactor).to.be.equal(configuratorMETHAssetConfig.liquidationFactor); | ||
expect(mETHAssetConfig.supplyCap).to.be.equal(configuratorMETHAssetConfig.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
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: compound.solidity.missing-constructor-sanity-checks