diff --git a/.gitignore b/.gitignore index 13c0e3771..511f53f5e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ node_modules/ reports typechain/ scripts/addresses/31337* +.eslintcache .openzeppelin/unknown-*.json .env diff --git a/contracts/plugins/assets/cbeth/CBETHCollateral.sol b/contracts/plugins/assets/cbeth/CBETHCollateral.sol index 40ee822e3..58dccd688 100644 --- a/contracts/plugins/assets/cbeth/CBETHCollateral.sol +++ b/contracts/plugins/assets/cbeth/CBETHCollateral.sol @@ -2,8 +2,9 @@ pragma solidity 0.8.19; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; -import { _safeWrap } from "../../../libraries/Fixed.sol"; -import "../AppreciatingFiatCollateral.sol"; +import { CEIL, FixLib, _safeWrap } from "../../../libraries/Fixed.sol"; +import { AggregatorV3Interface, OracleLib } from "../OracleLib.sol"; +import { CollateralConfig, AppreciatingFiatCollateral } from "../AppreciatingFiatCollateral.sol"; interface CBEth is IERC20Metadata { function mint(address account, uint256 amount) external returns (bool); @@ -50,17 +51,16 @@ contract CBEthCollateral is AppreciatingFiatCollateral { uint192 pegPrice ) { + uint192 spotRefPrTok = refPerTokChainlinkFeed.price(refPerTokChainlinkTimeout); // {UoA/tok} = {UoA/ref} * {ref/tok} - uint192 p = chainlinkFeed.price(oracleTimeout).mul( - refPerTokChainlinkFeed.price(refPerTokChainlinkTimeout) - ); + uint192 p = chainlinkFeed.price(oracleTimeout).mul(spotRefPrTok); uint192 err = p.mul(oracleError, CEIL); high = p + err; low = p - err; // assert(low <= high); obviously true just by inspection - pegPrice = targetPerRef(); // {target/ref} ETH/ETH is always 1 + pegPrice = _underlyingRefPerTok().div(spotRefPrTok); // {target/ref} } /// @return {ref/tok} Actual quantity of whole reference units per whole collateral tokens diff --git a/contracts/plugins/assets/cbeth/README.md b/contracts/plugins/assets/cbeth/README.md index fe74735ca..bc2342535 100644 --- a/contracts/plugins/assets/cbeth/README.md +++ b/contracts/plugins/assets/cbeth/README.md @@ -10,7 +10,7 @@ This plugin allows `CBETH` holders to use their tokens as collateral in the Rese | tok | ref | target | UoA | | ----- | --- | ------ | --- | -| cbeth | ETH | ETH | ETH | +| cbeth | ETH | ETH | USD | ### Functions diff --git a/contracts/plugins/assets/rocket-eth/RethCollateral.sol b/contracts/plugins/assets/rocket-eth/RethCollateral.sol index 42888b93d..ce1b004e3 100644 --- a/contracts/plugins/assets/rocket-eth/RethCollateral.sol +++ b/contracts/plugins/assets/rocket-eth/RethCollateral.sol @@ -1,11 +1,10 @@ // SPDX-License-Identifier: BlueOak-1.0.0 pragma solidity 0.8.19; -import "@openzeppelin/contracts/utils/math/Math.sol"; -import "../../../libraries/Fixed.sol"; -import "../AppreciatingFiatCollateral.sol"; -import "../OracleLib.sol"; -import "./vendor/IReth.sol"; +import { CEIL, FixLib, _safeWrap } from "../../../libraries/Fixed.sol"; +import { AggregatorV3Interface, OracleLib } from "../OracleLib.sol"; +import { CollateralConfig, AppreciatingFiatCollateral } from "../AppreciatingFiatCollateral.sol"; +import { IReth } from "./vendor/IReth.sol"; /** * @title RethCollateral @@ -49,17 +48,16 @@ contract RethCollateral is AppreciatingFiatCollateral { uint192 pegPrice ) { + uint192 spotRefPrTok = refPerTokChainlinkFeed.price(refPerTokChainlinkTimeout); // {UoA/tok} = {UoA/ref} * {ref/tok} - uint192 p = chainlinkFeed.price(oracleTimeout).mul( - refPerTokChainlinkFeed.price(refPerTokChainlinkTimeout) - ); + uint192 p = chainlinkFeed.price(oracleTimeout).mul(spotRefPrTok); uint192 err = p.mul(oracleError, CEIL); high = p + err; low = p - err; // assert(low <= high); obviously true just by inspection - pegPrice = targetPerRef(); // {target/ref} ETH/ETH is always 1 + pegPrice = _underlyingRefPerTok().div(spotRefPrTok); // {target/ref} } /// @return {ref/tok} Quantity of whole reference units per whole collateral tokens diff --git a/package.json b/package.json index 976df23cc..3fb99d3b6 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "test:coverage": "PROTO_IMPL=1 hardhat coverage --testfiles 'test/{libraries,plugins,scenario}/*.test.ts test/*.test.ts'", "test:unit:coverage": "PROTO_IMPL=1 SLOW= hardhat coverage --testfiles 'test/*.test.ts test/libraries/*.test.ts test/plugins/*.test.ts'", "eslint": "eslint test/", - "lint": "bash tools/lint && eslint test/", + "lint": "bash tools/lint && eslint test/ --cache", "prettier": "prettier --ignore-path .gitignore --loglevel warn --write \"./**/*.{js,ts,sol,json,md}\"", "size": "hardhat size-contracts", "slither": "python3 tools/slither.py", diff --git a/test/plugins/individual-collateral/cbeth/CBETHCollateral.test.ts b/test/plugins/individual-collateral/cbeth/CBETHCollateral.test.ts index 60473286f..639a96f6f 100644 --- a/test/plugins/individual-collateral/cbeth/CBETHCollateral.test.ts +++ b/test/plugins/individual-collateral/cbeth/CBETHCollateral.test.ts @@ -66,7 +66,7 @@ export const deployCollateral = async ( } const chainlinkDefaultAnswer = bn('1600e8') -const refPerTokChainlinkDefaultAnswer = fp('1') +const refPerTokChainlinkDefaultAnswer = fp('1.04027709') type Fixture = () => Promise diff --git a/test/plugins/individual-collateral/rocket-eth/RethCollateralTestSuite.test.ts b/test/plugins/individual-collateral/rocket-eth/RethCollateralTestSuite.test.ts index 21b019a34..85a3fca8b 100644 --- a/test/plugins/individual-collateral/rocket-eth/RethCollateralTestSuite.test.ts +++ b/test/plugins/individual-collateral/rocket-eth/RethCollateralTestSuite.test.ts @@ -97,7 +97,7 @@ export const deployCollateral = async (opts: RethCollateralOpts = {}): Promise = () => Promise