Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaShWoof committed Jun 12, 2024
1 parent a74fed6 commit cb2cd93
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 18 deletions.
89 changes: 89 additions & 0 deletions contracts/pricefeeds/ReverseMultiplicativePriceFeed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

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

/**
* @title Multiplicative price feed
* @notice A custom price feed that multiplies the prices from two price feeds and returns the result
* @author Compound
*/
contract ReverseMultiplicativePriceFeed is IPriceFeed {
/** Custom errors **/
error BadDecimals();
error InvalidInt256();

/// @notice Version of the price feed
uint public constant VERSION = 1;

/// @notice Description of the price feed
string public override description;

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

/// @notice Chainlink price feed A
address public immutable priceFeedA;

/// @notice Chainlink price feed B
address public immutable priceFeedB;

/// @notice Combined scale of the two underlying Chainlink price feeds
int public immutable priceFeedAScalling;

/// @notice Scale of this price feed
int public immutable priceFeedScale;

/**
* @notice Construct a new multiplicative price feed
* @param priceFeedA_ The address of the first price feed to fetch prices from
* @param priceFeedB_ The address of the second price feed to fetch prices from that should be reversed
* @param decimals_ The number of decimals for the returned prices
* @param description_ The description of the price feed
**/
constructor(address priceFeedA_, address priceFeedB_, uint8 decimals_, string memory description_) {
priceFeedA = priceFeedA_;
priceFeedB = priceFeedB_;
uint8 priceFeedADecimals = AggregatorV3Interface(priceFeedA_).decimals();
priceFeedAScalling = signed256(10 ** (priceFeedADecimals));

if (decimals_ > 18) revert BadDecimals();
decimals = decimals_;
description = description_;
priceFeedScale = int256(10 ** decimals);
}

Check warning

Code scanning / Semgrep OSS

There're no sanity checks for the constructor argument description_. Warning

There're no sanity checks for the constructor argument description_.

Check warning

Code scanning / Semgrep OSS

There're no sanity checks for the constructor argument priceFeedA_. Warning

There're no sanity checks for the constructor argument priceFeedA_.

Check warning

Code scanning / Semgrep OSS

There're no sanity checks for the constructor argument priceFeedB_. Warning

There're no sanity checks for the constructor argument priceFeedB_.

Check warning

Code scanning / Semgrep OSS

Consider making costructor payable to save gas. Warning

Consider making costructor payable to save gas.

/**
* @notice Calculates the latest round data using data from the two price feeds
* @return roundId Round id from price feed B
* @return answer Latest price
* @return startedAt Timestamp when the round was started; passed on from price feed B
* @return updatedAt Timestamp when the round was last updated; passed on from price feed B
* @return answeredInRound Round id in which the answer was computed; passed on from price feed B
* @dev Note: Only the `answer` really matters for downstream contracts that use this price feed (e.g. Comet)
**/
function latestRoundData() override external view returns (uint80, int256, uint256, uint256, uint80) {
(, int256 priceA, , , ) = AggregatorV3Interface(priceFeedA).latestRoundData();
(uint80 roundId_, int256 priceB, uint256 startedAt_, uint256 updatedAt_, uint80 answeredInRound_) = AggregatorV3Interface(priceFeedB).latestRoundData();

if (priceA <= 0 || priceB <= 0) return (roundId_, 0, startedAt_, updatedAt_, answeredInRound_);

// int256 price = priceA * priceB * priceFeedScale / combinedScale;
int256 price = priceA * int256(10**(AggregatorV3Interface(priceFeedB).decimals())) * priceFeedScale / priceB / priceFeedAScalling;
return (roundId_, price, startedAt_, updatedAt_, answeredInRound_);
}

function signed256(uint256 n) internal pure returns (int256) {
if (n > uint256(type(int256).max)) revert InvalidInt256();
return int256(n);
}

/**
* @notice Price for the latest round
* @return The version of the price feed contract
**/
function version() external pure returns (uint256) {
return VERSION;
}
}
36 changes: 18 additions & 18 deletions deployments/optimism/weth/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"baseTokenAddress": "0x4200000000000000000000000000000000000006",
"borrowMin": "0.1e18",
"pauseGuardian": "0x3fFd6c073a4ba24a113B18C8F373569640916A45",
"storeFrontPriceFactor": 0.5,
"storeFrontPriceFactor": 0.7,
"targetReserves": "5000e18",
"rates": {
"supplyKink": 0.9,
"supplySlopeLow": 0.0283824,
"supplySlopeHigh": 0.6066567706,
"supplyKink": 0.85,
"supplySlopeLow": 0.014,
"supplySlopeHigh": 1,
"supplyBase": 0,
"borrowKink": 0.9,
"borrowSlopeLow": 0.05171500002,
"borrowSlopeHigh": 0.5171500339,
"borrowBase": 0.009945209674
"borrowKink": 0.85,
"borrowSlopeLow": 0.014,
"borrowSlopeHigh": 1,
"borrowBase": 0.01
},
"tracking": {
"indexScale": "1e15",
Expand All @@ -27,26 +27,26 @@
"wstETH": {
"address": "0x1F32b1c2345538c0c6f582fCB022739c4A194Ebb",
"decimals": "18",
"borrowCF": 0.90,
"borrowCF": 0.88,
"liquidateCF": 0.93,
"liquidationFactor": 0.95,
"liquidationFactor": 0.97,
"supplyCap": "0e18"
},
"rETH": {
"address": "0x9Bcef72be871e61ED4fBbc7630889beE758eb81D",
"decimals": "18",
"borrowCF": 0.90,
"liquidateCF": 0.93,
"liquidationFactor": 0.95,
"liquidationFactor": 0.97,
"supplyCap": "0e18"
},
"cbETH": {
"address": "0xadDb6A0412DE1BA0F936DCaeb8Aaa24578dcF3B2",
"decimals": "18",
"borrowCF": 0.90,
"liquidateCF": 0.93,
"liquidationFactor": 0.95,
"supplyCap": "0e18"
"WBTC": {
"address": "0x68f180fcCe6836688e9084f035309E29Bf0A2095",
"decimals": "8",
"borrowCF": 0.80,
"liquidateCF": 0.85,
"liquidationFactor": 0.90,
"supplyCap": "0e8"
}
}
}
Expand Down

0 comments on commit cb2cd93

Please sign in to comment.