Skip to content

Commit

Permalink
C4: #35 #32, fix underlyingToRef value of RETH and CBETH
Browse files Browse the repository at this point in the history
  • Loading branch information
jankjr committed Aug 17, 2023
1 parent 99d9db7 commit d7f9211
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules/
reports
typechain/
scripts/addresses/31337*
.eslintcache

.openzeppelin/unknown-*.json
.env
Expand Down
12 changes: 6 additions & 6 deletions contracts/plugins/assets/cbeth/CBETHCollateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contracts/plugins/assets/cbeth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 7 additions & 9 deletions contracts/plugins/assets/rocket-eth/RethCollateral.sol
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const deployCollateral = async (
}

const chainlinkDefaultAnswer = bn('1600e8')
const refPerTokChainlinkDefaultAnswer = fp('1')
const refPerTokChainlinkDefaultAnswer = fp('1.04027709')

type Fixture<T> = () => Promise<T>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const deployCollateral = async (opts: RethCollateralOpts = {}): Promise<T
}

const chainlinkDefaultAnswer = bn('1600e8')
const refPerTokChainlinkDefaultAnswer = fp('1')
const refPerTokChainlinkDefaultAnswer = fp('1.0859')

type Fixture<T> = () => Promise<T>

Expand Down

0 comments on commit d7f9211

Please sign in to comment.