From df2c2039ec45c20fe5ec5e8bdb14c2799bf105ff Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Thu, 12 Sep 2024 13:34:54 +0300 Subject: [PATCH 01/10] feat: new migration with custom price feed --- .../pricefeeds/METHExchangeRatePriceFeed.sol | 99 +++++++++++++ contracts/vendor/mantle/IRateProvider.sol | 6 + .../1726085857_add_meth_collateral.ts | 133 ++++++++++++++++++ scenario/constraints/ProposalConstraint.ts | 6 +- 4 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 contracts/pricefeeds/METHExchangeRatePriceFeed.sol create mode 100644 contracts/vendor/mantle/IRateProvider.sol create mode 100644 deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts diff --git a/contracts/pricefeeds/METHExchangeRatePriceFeed.sol b/contracts/pricefeeds/METHExchangeRatePriceFeed.sol new file mode 100644 index 000000000..f8868ca9c --- /dev/null +++ b/contracts/pricefeeds/METHExchangeRatePriceFeed.sol @@ -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_)) + ); + } + + /** + * @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; + } +} diff --git a/contracts/vendor/mantle/IRateProvider.sol b/contracts/vendor/mantle/IRateProvider.sol new file mode 100644 index 000000000..d6e994837 --- /dev/null +++ b/contracts/vendor/mantle/IRateProvider.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.15; + +interface IRateProvider { + function mETHToETH(uint256) external view returns (uint256); +} diff --git a/deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts b/deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts new file mode 100644 index 000000000..d0e5ae02c --- /dev/null +++ b/deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts @@ -0,0 +1,133 @@ +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('1726085857_add_meth_collateral', { + async prepare(deploymentManager: DeploymentManager) { + const _mETHScalingPriceFeed = await deploymentManager.deploy( + 'mETH:priceFeed', + 'pricefeeds/METHExchangeRatePriceFeed.sol', + [ + METH_EXCHANGE_RATE_PROVIDER_ADDRESS, // mETH / ETH price feed + 8, // decimals + 'mETH/ETH exchange rate', // description + ] + ); + return { mETHScalingPriceFeed: _mETHScalingPriceFeed.address }; + }, + + async enact(deploymentManager: DeploymentManager, _, { mETHScalingPriceFeed }) { + + const trace = deploymentManager.tracer(); + + const mETH = await deploymentManager.existing( + 'mETH', + METH_ADDRESS, + 'mainnet', + 'contracts/ERC20.sol:ERC20' + ); + const mEthPriceFeed = await deploymentManager.existing( + 'mETH:priceFeed', + mETHScalingPriceFeed, + '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.88, 18), + liquidateCollateralFactor: exp(0.9, 18), + liquidationFactor: exp(0.95, 18), + supplyCap: exp(5000, 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 cWETHv3 on Mainnet\n\n## Proposal summary\n\nCompound Growth Program [AlphaGrowth] proposes to add mETH 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/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/916) 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 { + 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.88, 18), + liquidateCollateralFactor: exp(0.9, 18), + liquidationFactor: exp(0.95, 18), + supplyCap: exp(5000, 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); + }, +}); diff --git a/scenario/constraints/ProposalConstraint.ts b/scenario/constraints/ProposalConstraint.ts index f1b9fa204..36d792478 100644 --- a/scenario/constraints/ProposalConstraint.ts +++ b/scenario/constraints/ProposalConstraint.ts @@ -62,9 +62,9 @@ export class ProposalConstraint implements StaticConstra ); } - // temporary hack to skip proposal 281 - if (proposal.id.eq(281)) { - console.log('Skipping proposal 281'); + // temporary hack to skip proposal 329 + if (proposal.id.eq(329)) { + console.log('Skipping proposal 329'); continue; } From d3df56fd5599bf0d9ee603a69ea29522b58bc6b1 Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Fri, 13 Sep 2024 11:05:31 +0300 Subject: [PATCH 02/10] fix: description pr link --- .../mainnet/weth/migrations/1726085857_add_meth_collateral.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts b/deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts index d0e5ae02c..fc3452c43 100644 --- a/deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts +++ b/deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts @@ -71,7 +71,7 @@ export default migration('1726085857_add_meth_collateral', { }, ]; - const description = '# Add mETH as collateral into cWETHv3 on Mainnet\n\n## Proposal summary\n\nCompound Growth Program [AlphaGrowth] proposes to add mETH 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/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/916) 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 description = '# Add mETH as collateral into cWETHv3 on Mainnet\n\n## Proposal summary\n\nCompound Growth Program [AlphaGrowth] proposes to add mETH 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/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/919) 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))) From cb5d61b4c81c2be20b4500186ae93adcfc973f16 Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Fri, 13 Sep 2024 15:20:40 +0300 Subject: [PATCH 03/10] fix: update workflow --- .github/workflows/deploy-market.yaml | 2 +- .github/workflows/prepare-migration.yaml | 2 +- .github/workflows/run-scenarios.yaml | 2 +- .github/workflows/run-unit-tests.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-market.yaml b/.github/workflows/deploy-market.yaml index 5de6eb684..eb1b1d90b 100644 --- a/.github/workflows/deploy-market.yaml +++ b/.github/workflows/deploy-market.yaml @@ -77,7 +77,7 @@ jobs: NETWORK_PROVIDER: ${{ fromJSON('["", "http://localhost:8585"]')[github.event.inputs.eth_pk == ''] }} REMOTE_ACCOUNTS: ${{ fromJSON('["", "true"]')[github.event.inputs.eth_pk == ''] }} - - uses: actions/upload-artifact@v2 # upload test results + - uses: actions/upload-artifact@v4 # upload test results if: success() || failure() # run this step even if previous step failed with: name: ${{ github.event.inputs.network }}-${{ github.event.inputs.deployment }}-verify-args diff --git a/.github/workflows/prepare-migration.yaml b/.github/workflows/prepare-migration.yaml index c27bc569e..1bbaa6646 100644 --- a/.github/workflows/prepare-migration.yaml +++ b/.github/workflows/prepare-migration.yaml @@ -77,7 +77,7 @@ jobs: NETWORK_PROVIDER: ${{ fromJSON('["", "http://localhost:8585"]')[github.event.inputs.eth_pk == ''] }} REMOTE_ACCOUNTS: ${{ fromJSON('["", "true"]')[github.event.inputs.eth_pk == ''] }} - - uses: actions/upload-artifact@v2 # upload test results + - uses: actions/upload-artifact@v4 # upload test results if: success() || failure() # run this step even if previous step failed with: name: ${{ github.event.inputs.network }}-${{ github.event.inputs.deployment }}-${{ github.event.inputs.migration }} diff --git a/.github/workflows/run-scenarios.yaml b/.github/workflows/run-scenarios.yaml index 0fecdd98c..6ae46e623 100644 --- a/.github/workflows/run-scenarios.yaml +++ b/.github/workflows/run-scenarios.yaml @@ -54,7 +54,7 @@ jobs: - name: Run scenarios run: yarn scenario --bases ${{ matrix.bases }} - - uses: actions/upload-artifact@v2 # upload scenario results + - uses: actions/upload-artifact@v4 # upload scenario results if: success() || failure() # run this step even if previous step failed with: name: scenario-results diff --git a/.github/workflows/run-unit-tests.yaml b/.github/workflows/run-unit-tests.yaml index d198e156e..849ae43b8 100644 --- a/.github/workflows/run-unit-tests.yaml +++ b/.github/workflows/run-unit-tests.yaml @@ -34,7 +34,7 @@ jobs: - name: Run tests run: yarn test - - uses: actions/upload-artifact@v2 # upload test results + - uses: actions/upload-artifact@v4 # upload test results if: success() || failure() # run this step even if previous step failed with: name: test-results From bc0d707a4dbac5a690646f91ac37d0ae339f36d2 Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Fri, 13 Sep 2024 15:42:11 +0300 Subject: [PATCH 04/10] fix: additional workflow update --- .github/workflows/deploy-market.yaml | 4 ++-- .github/workflows/enact-migration.yaml | 4 ++-- .github/workflows/prepare-migration.yaml | 4 ++-- .github/workflows/run-contract-linter.yaml | 4 ++-- .github/workflows/run-coverage.yaml | 4 ++-- .github/workflows/run-eslint.yaml | 4 ++-- .github/workflows/run-forge-tests.yaml | 2 +- .github/workflows/run-gas-profiler.yaml | 4 ++-- .github/workflows/run-scenarios.yaml | 6 +++--- .github/workflows/run-slither.yaml | 4 ++-- .github/workflows/run-unit-tests.yaml | 4 ++-- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/deploy-market.yaml b/.github/workflows/deploy-market.yaml index eb1b1d90b..fe6e35024 100644 --- a/.github/workflows/deploy-market.yaml +++ b/.github/workflows/deploy-market.yaml @@ -53,9 +53,9 @@ jobs: if: github.event.inputs.eth_pk == '' - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: '16' diff --git a/.github/workflows/enact-migration.yaml b/.github/workflows/enact-migration.yaml index f3a5e4524..b3202dbed 100644 --- a/.github/workflows/enact-migration.yaml +++ b/.github/workflows/enact-migration.yaml @@ -85,9 +85,9 @@ jobs: if: github.event.inputs.eth_pk == '' && env.GOV_NETWORK != '' - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: '16' diff --git a/.github/workflows/prepare-migration.yaml b/.github/workflows/prepare-migration.yaml index 1bbaa6646..9d6206a18 100644 --- a/.github/workflows/prepare-migration.yaml +++ b/.github/workflows/prepare-migration.yaml @@ -53,9 +53,9 @@ jobs: if: github.event.inputs.eth_pk == '' - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: '16' diff --git a/.github/workflows/run-contract-linter.yaml b/.github/workflows/run-contract-linter.yaml index b027b58fb..2513cc18c 100644 --- a/.github/workflows/run-contract-linter.yaml +++ b/.github/workflows/run-contract-linter.yaml @@ -15,11 +15,11 @@ jobs: LINEASCAN_KEY: ${{ secrets.LINEASCAN_KEY }} OPTIMISMSCAN_KEY: ${{ secrets.OPTIMISMSCAN_KEY }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: '16' diff --git a/.github/workflows/run-coverage.yaml b/.github/workflows/run-coverage.yaml index e2272a9d5..b28829b56 100644 --- a/.github/workflows/run-coverage.yaml +++ b/.github/workflows/run-coverage.yaml @@ -18,9 +18,9 @@ jobs: OPTIMISMSCAN_KEY: ${{ secrets.OPTIMISMSCAN_KEY }} steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: cache: 'yarn' node-version: '16' diff --git a/.github/workflows/run-eslint.yaml b/.github/workflows/run-eslint.yaml index 9763d45d4..1961fec4c 100644 --- a/.github/workflows/run-eslint.yaml +++ b/.github/workflows/run-eslint.yaml @@ -16,9 +16,9 @@ jobs: OPTIMISMSCAN_KEY: ${{ secrets.OPTIMISMSCAN_KEY }} steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: cache: 'yarn' node-version: '16' diff --git a/.github/workflows/run-forge-tests.yaml b/.github/workflows/run-forge-tests.yaml index 069a30bdb..6a10f7523 100644 --- a/.github/workflows/run-forge-tests.yaml +++ b/.github/workflows/run-forge-tests.yaml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive diff --git a/.github/workflows/run-gas-profiler.yaml b/.github/workflows/run-gas-profiler.yaml index d2418ad42..d49ba9152 100644 --- a/.github/workflows/run-gas-profiler.yaml +++ b/.github/workflows/run-gas-profiler.yaml @@ -17,9 +17,9 @@ jobs: OPTIMISMSCAN_KEY: ${{ secrets.OPTIMISMSCAN_KEY }} steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: '16' diff --git a/.github/workflows/run-scenarios.yaml b/.github/workflows/run-scenarios.yaml index 6ae46e623..b651c8880 100644 --- a/.github/workflows/run-scenarios.yaml +++ b/.github/workflows/run-scenarios.yaml @@ -22,17 +22,17 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: cache: 'yarn' node-version: '16' - name: Cache Deployments - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | deployments/*/.contracts diff --git a/.github/workflows/run-slither.yaml b/.github/workflows/run-slither.yaml index 3c80df49e..2ca5a871d 100644 --- a/.github/workflows/run-slither.yaml +++ b/.github/workflows/run-slither.yaml @@ -8,9 +8,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: '16' diff --git a/.github/workflows/run-unit-tests.yaml b/.github/workflows/run-unit-tests.yaml index 849ae43b8..49779a40f 100644 --- a/.github/workflows/run-unit-tests.yaml +++ b/.github/workflows/run-unit-tests.yaml @@ -16,9 +16,9 @@ jobs: OPTIMISMSCAN_KEY: ${{ secrets.OPTIMISMSCAN_KEY }} steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: '16' From 269830574ae3342d84e3e18d53b2d362be228ebd Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Fri, 13 Sep 2024 16:32:45 +0300 Subject: [PATCH 05/10] fix: final fix to workflow --- .github/workflows/run-scenarios.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-scenarios.yaml b/.github/workflows/run-scenarios.yaml index b651c8880..c2b7adcce 100644 --- a/.github/workflows/run-scenarios.yaml +++ b/.github/workflows/run-scenarios.yaml @@ -57,7 +57,7 @@ jobs: - uses: actions/upload-artifact@v4 # upload scenario results if: success() || failure() # run this step even if previous step failed with: - name: scenario-results + name: scenario-results-${{ matrix.bases }} path: scenario-results.json - uses: dorny/test-reporter@v1 From 09245054f6b58691a1a6bb3b4ab4584490db70a4 Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Fri, 13 Sep 2024 17:04:44 +0300 Subject: [PATCH 06/10] fix: relations --- deployments/optimism/weth/relations.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/deployments/optimism/weth/relations.ts b/deployments/optimism/weth/relations.ts index e88708f5d..45457356a 100644 --- a/deployments/optimism/weth/relations.ts +++ b/deployments/optimism/weth/relations.ts @@ -56,14 +56,4 @@ export default { WBTC: { artifact: 'contracts/ERC20.sol:ERC20' }, - - // weETH - TransparentUpgradeableProxy: { - artifact: 'contracts/ERC20.sol:ERC20', - delegates: { - field: { - slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' - } - } - }, }; From 279e0345ab8572e7a88dc718ec492794d310bd1f Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Thu, 26 Sep 2024 13:28:01 +0300 Subject: [PATCH 07/10] feat: contracts --- .../pricefeeds/METHExchangeRatePriceFeed.sol | 99 +++++++++++++++++++ contracts/vendor/mantle/IRateProvider.sol | 6 ++ 2 files changed, 105 insertions(+) create mode 100644 contracts/pricefeeds/METHExchangeRatePriceFeed.sol create mode 100644 contracts/vendor/mantle/IRateProvider.sol diff --git a/contracts/pricefeeds/METHExchangeRatePriceFeed.sol b/contracts/pricefeeds/METHExchangeRatePriceFeed.sol new file mode 100644 index 000000000..f8868ca9c --- /dev/null +++ b/contracts/pricefeeds/METHExchangeRatePriceFeed.sol @@ -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_)) + ); + } + + /** + * @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; + } +} diff --git a/contracts/vendor/mantle/IRateProvider.sol b/contracts/vendor/mantle/IRateProvider.sol new file mode 100644 index 000000000..d6e994837 --- /dev/null +++ b/contracts/vendor/mantle/IRateProvider.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.15; + +interface IRateProvider { + function mETHToETH(uint256) external view returns (uint256); +} From 3cff00db694b92dfe34cf68a35baa854288cbde3 Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Tue, 12 Nov 2024 17:17:14 +0200 Subject: [PATCH 08/10] fix: audit --- contracts/pricefeeds/METHExchangeRatePriceFeed.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/pricefeeds/METHExchangeRatePriceFeed.sol b/contracts/pricefeeds/METHExchangeRatePriceFeed.sol index f8868ca9c..61b264aff 100644 --- a/contracts/pricefeeds/METHExchangeRatePriceFeed.sol +++ b/contracts/pricefeeds/METHExchangeRatePriceFeed.sol @@ -15,7 +15,7 @@ contract METHExchangeRatePriceFeed is IPriceFeed { error BadDecimals(); /// @notice Version of the price feed - uint public constant VERSION = 1; + uint internal constant VERSION = 1; /// @notice Description of the price feed string public description; @@ -67,7 +67,6 @@ contract METHExchangeRatePriceFeed is IPriceFeed { 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 @@ -90,7 +89,7 @@ contract METHExchangeRatePriceFeed is IPriceFeed { } /** - * @notice Price for the latest round + * @notice Get the version of the price feed contract * @return The version of the price feed contract **/ function version() external pure returns (uint256) { From 3bf687958f3794e4b2966ea72bd2ca2e6ffa595d Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Tue, 12 Nov 2024 18:44:38 +0200 Subject: [PATCH 09/10] fix: update timestamp --- ...add_meth_collateral.ts => 1731429132_add_meth_collateral.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename deployments/mainnet/weth/migrations/{1726085857_add_meth_collateral.ts => 1731429132_add_meth_collateral.ts} (99%) diff --git a/deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts b/deployments/mainnet/weth/migrations/1731429132_add_meth_collateral.ts similarity index 99% rename from deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts rename to deployments/mainnet/weth/migrations/1731429132_add_meth_collateral.ts index fc3452c43..c07111501 100644 --- a/deployments/mainnet/weth/migrations/1726085857_add_meth_collateral.ts +++ b/deployments/mainnet/weth/migrations/1731429132_add_meth_collateral.ts @@ -7,7 +7,7 @@ const METH_ADDRESS = '0xd5F7838F5C461fefF7FE49ea5ebaF7728bB0ADfa'; const METH_EXCHANGE_RATE_PROVIDER_ADDRESS = '0xe3cBd06D7dadB3F4e6557bAb7EdD924CD1489E8f'; let newPriceFeedAddress: string; -export default migration('1726085857_add_meth_collateral', { +export default migration('1731429132_add_meth_collateral', { async prepare(deploymentManager: DeploymentManager) { const _mETHScalingPriceFeed = await deploymentManager.deploy( 'mETH:priceFeed', From 05bc49c0d8a8aa687536752016835683a777e3d0 Mon Sep 17 00:00:00 2001 From: Mikhailo Shabodyash Date: Wed, 13 Nov 2024 10:51:02 +0200 Subject: [PATCH 10/10] fix: comment fix --- contracts/pricefeeds/METHExchangeRatePriceFeed.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/pricefeeds/METHExchangeRatePriceFeed.sol b/contracts/pricefeeds/METHExchangeRatePriceFeed.sol index 61b264aff..b97f475d6 100644 --- a/contracts/pricefeeds/METHExchangeRatePriceFeed.sol +++ b/contracts/pricefeeds/METHExchangeRatePriceFeed.sol @@ -6,7 +6,7 @@ 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 + * @notice A custom price feed that scales up or down the price received from an underlying Mantle mETH / ETH exchange rate price feed and returns the result * @author Compound */ contract METHExchangeRatePriceFeed is IPriceFeed {