Skip to content

Commit

Permalink
Mainnet ETH Deployment
Browse files Browse the repository at this point in the history
* Update Github Actions to include mainnet-eth
* ETH-base bulker scenario
* WstETHPriceFeed + tests (#600)
* Non-ETH and ETH bulker scenarios (all actions in one txn)
* Mainnet WETH Bulker (#611)
* Add a supply cap constraint and set initial caps to 0 for cWETHv3
* Update the collateral params based on Gauntlet recommendations (#628)
 https://hackmd.io/wncIvkFTReWUe2AMMK2ezA?view
* Price feeds for WETH deployment + Bulker changes for OZ audit (#625)
 This PR implements and modifies price feeds to support the upcoming WETH deployment. The favored plan so far is to use ETH-denominated price feeds as opposed to USD price feeds, but stick with using 8 decimals for prices to avoid having to change the `Comet` and `Configurator` implementations.
 This would require:
  - A new wrapper price feed (`ScalingPriceFeed.sol`) that scales prices up or down to 8 decimals
  - A new `ConstantPriceFeed` that always returns 1e8 for the `WETH` base asset, since should always hold a 1:1 value with ETH
  - Modifications to the `WstETHPriceFeed` to return prices in terms of ETH instead of USD

 This is an alternative approach to #626, which is a more complex change but could be a better long-term solution.
 *Note: This PR also now contains the changes from #634 and #635, which address some suggestions made by OZ for their audit of `WstETHPriceFeed` and `Bulker`.*
  • Loading branch information
jflatow committed Dec 19, 2022
1 parent 7435a05 commit 4db8aca
Show file tree
Hide file tree
Showing 43 changed files with 1,740 additions and 270 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/enact-migration.yaml
Expand Up @@ -22,7 +22,7 @@ on:
description: Simulate
no_enacted:
type: boolean
description: Do not write Enacted
description: Do not write Enacted
run_id:
description: Run ID for Artifact
eth_pk:
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Seacrest
uses: hayesgm/seacrest@v1
with:
ethereum_url: "${{ fromJSON('{\"fuji\":\"https://api.avax-test.network/ext/bc/C/rpc\",\"kovan\":\"https://kovan-eth.compound.finance\",\"mainnet\":\"https://mainnet-eth.compound.finance\",\"goerli\":\"https://goerli.infura.io/v3/$INFURA_KEY\",\"mumbai\":\"https://polygon-mumbai.infura.io/v3/$INFURA_KEY\"}')[inputs.network] }}"
ethereum_url: "${{ fromJSON('{\"fuji\":\"https://api.avax-test.network/ext/bc/C/rpc\",\"kovan\":\"https://kovan.infura.io/v3/$INFURA_KEY\",\"mainnet\":\"https://mainnet.infura.io/v3/$INFURA_KEY\",\"goerli\":\"https://goerli.infura.io/v3/$INFURA_KEY\",\"mumbai\":\"https://polygon-mumbai.infura.io/v3/$INFURA_KEY\"}')[inputs.network] }}"
port: 8585
if: github.event.inputs.eth_pk == ''

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prepare-migration.yaml
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Seacrest
uses: hayesgm/seacrest@v1
with:
ethereum_url: "${{ fromJSON('{\"fuji\":\"https://api.avax-test.network/ext/bc/C/rpc\",\"kovan\":\"https://kovan-eth.compound.finance\",\"mainnet\":\"https://mainnet-eth.compound.finance\",\"goerli\":\"https://goerli.infura.io/v3/$INFURA_KEY\",\"mumbai\":\"https://polygon-mumbai.infura.io/v3/$INFURA_KEY\"}')[inputs.network] }}"
ethereum_url: "${{ fromJSON('{\"fuji\":\"https://api.avax-test.network/ext/bc/C/rpc\",\"kovan\":\"https://kovan.infura.io/v3/$INFURA_KEY\",\"mainnet\":\"https://mainnet.infura.io/v3/$INFURA_KEY\",\"goerli\":\"https://goerli.infura.io/v3/$INFURA_KEY\",\"mumbai\":\"https://polygon-mumbai.infura.io/v3/$INFURA_KEY\"}')[inputs.network] }}"
port: 8585
if: github.event.inputs.eth_pk == ''

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-scenarios.yaml
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
bases: [ development, mainnet, goerli, fuji, mumbai ]
bases: [ development, mainnet, mainnet-weth, goerli, fuji, mumbai ]
name: Run scenarios
env:
ETHERSCAN_KEY: ${{ secrets.ETHERSCAN_KEY }}
Expand Down
153 changes: 0 additions & 153 deletions contracts/Bulker.sol

This file was deleted.

8 changes: 4 additions & 4 deletions contracts/Comet.sol
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.15;

import "./CometMainInterface.sol";
import "./ERC20.sol";
import "./vendor/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./IPriceFeed.sol";

/**
* @title Compound's Comet Contract
Expand Down Expand Up @@ -144,7 +144,7 @@ contract Comet is CometMainInterface {
if (config.storeFrontPriceFactor > FACTOR_SCALE) revert BadDiscount();
if (config.assetConfigs.length > MAX_ASSETS) revert TooManyAssets();
if (config.baseMinForRewards == 0) revert BadMinimum();
if (AggregatorV3Interface(config.baseTokenPriceFeed).decimals() != PRICE_FEED_DECIMALS) revert BadDecimals();
if (IPriceFeed(config.baseTokenPriceFeed).decimals() != PRICE_FEED_DECIMALS) revert BadDecimals();

// Copy configuration
unchecked {
Expand Down Expand Up @@ -240,7 +240,7 @@ contract Comet is CometMainInterface {
}

// Sanity check price feed and asset decimals
if (AggregatorV3Interface(priceFeed).decimals() != PRICE_FEED_DECIMALS) revert BadDecimals();
if (IPriceFeed(priceFeed).decimals() != PRICE_FEED_DECIMALS) revert BadDecimals();
if (ERC20(asset).decimals() != decimals_) revert BadDecimals();

// Ensure collateral factors are within range
Expand Down Expand Up @@ -471,7 +471,7 @@ contract Comet is CometMainInterface {
* @return The price, scaled by `PRICE_SCALE`
*/
function getPrice(address priceFeed) override public view returns (uint256) {
(, int price, , , ) = AggregatorV3Interface(priceFeed).latestRoundData();
(, int price, , , ) = IPriceFeed(priceFeed).latestRoundData();
if (price <= 0) revert BadPrice();
return uint256(price);
}
Expand Down
1 change: 0 additions & 1 deletion contracts/CometCore.sol
Expand Up @@ -4,7 +4,6 @@ pragma solidity 0.8.15;
import "./CometConfiguration.sol";
import "./CometStorage.sol";
import "./CometMath.sol";
import "./vendor/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

abstract contract CometCore is CometConfiguration, CometStorage, CometMath {
struct AssetInfo {
Expand Down
45 changes: 45 additions & 0 deletions contracts/ConstantPriceFeed.sol
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

import "./IPriceFeed.sol";

contract ConstantPriceFeed is IPriceFeed {
/// @notice Version of the price feed
uint public constant override version = 1;

/// @notice Description of the price feed
string public constant description = "Constant price feed";

/// @notice Number of decimals for returned prices
uint8 public immutable override decimals;

/// @notice The constant price
int public immutable constantPrice;

/**
* @notice Construct a new scaling price feed
* @param decimals_ The number of decimals for the returned prices
**/
constructor(uint8 decimals_, int256 constantPrice_) {
decimals = decimals_;
constantPrice = constantPrice_;
}

/**
* @notice Price for the latest round
* @return roundId Round id from the underlying price feed
* @return answer Latest price for the asset (will always be a constant price)
* @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() external view returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
) {
return (0, constantPrice, block.timestamp, block.timestamp, 0);
}
}
14 changes: 14 additions & 0 deletions contracts/IERC20NonStandard.sol
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

/**
* @title IERC20NonStandard
* @dev Version of ERC20 with no return values for `transfer` and `transferFrom`
* See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
*/
interface IERC20NonStandard {
function approve(address spender, uint256 amount) external;
function transfer(address to, uint256 value) external;
function transferFrom(address from, address to, uint256 value) external;
function balanceOf(address account) external view returns (uint256);
}
25 changes: 25 additions & 0 deletions contracts/IPriceFeed.sol
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

/**
* @dev Interface for price feeds used by Comet
* Note This is Chainlink's AggregatorV3Interface, but without the `getRoundData` function.
*/
interface IPriceFeed {
function decimals() external view returns (uint8);

function description() external view returns (string memory);

function version() external view returns (uint256);

function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
23 changes: 23 additions & 0 deletions contracts/IWstETH.sol
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

import "./ERC20.sol";

/**
* @dev Interface for interacting with WstETH contract
* Note Not a comprehensive interface
*/
interface IWstETH is ERC20 {
function stETH() external returns (address);

function wrap(uint256 _stETHAmount) external returns (uint256);
function unwrap(uint256 _wstETHAmount) external returns (uint256);

function receive() external payable;

function getWstETHByStETH(uint256 _stETHAmount) external view returns (uint256);
function getStETHByWstETH(uint256 _wstETHAmount) external view returns (uint256);

function stEthPerToken() external view returns (uint256);
function tokensPerStEth() external view returns (uint256);
}

0 comments on commit 4db8aca

Please sign in to comment.