Skip to content
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

C4: #35 #32, fixes rETH / cbETH / ankrETH ref unit and adds soft default checks #899

Merged
merged 12 commits into from
Aug 22, 2023
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}
tbrent marked this conversation as resolved.
Show resolved Hide resolved
}

/// @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 |
tbrent marked this conversation as resolved.
Show resolved Hide resolved

### 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
tbrent marked this conversation as resolved.
Show resolved Hide resolved
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}
tbrent marked this conversation as resolved.
Show resolved Hide resolved
}

/// @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",
tbrent marked this conversation as resolved.
Show resolved Hide resolved
"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