Skip to content

Commit

Permalink
managed ratio oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Oct 11, 2024
1 parent 182974b commit 6226480
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
20 changes: 13 additions & 7 deletions contracts/mellowpricefeed/MellowPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.20;

import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "../mellow-lrt/interfaces/IVault.sol";
import "../mellow-lrt/interfaces/oracles/IManagedRatiosOracle.sol";

/// @title Contract for retreiving a Mellow LRT Vault's exchange rate value with chainlink's AggregatorV3Interface
/// implemented.
Expand All @@ -15,7 +15,9 @@ contract MellowPriceFeed is Initializable, AggregatorV3Interface {

string private priceFeedQuote;

IVault public vault;
IManagedRatiosOracle public managedRatiosOracle;

address public vault;

uint80 constant DEFAULT_ROUND = 1;

Expand All @@ -25,6 +27,10 @@ contract MellowPriceFeed is Initializable, AggregatorV3Interface {

error GetRoundDataCanBeOnlyCalledWithLatestRound(uint80 requestedRoundId);

constructor(address managedRatiosOracle_) {
managedRatiosOracle = IManagedRatiosOracle(managedRatiosOracle_);
}

/// @notice Initialize clone of this contract.
/// @dev This function is used in place of a constructor in proxy contracts.
/// @param _vault Address of Mellow LRT vault.
Expand All @@ -37,7 +43,7 @@ contract MellowPriceFeed is Initializable, AggregatorV3Interface {
string calldata _priceFeedBase,
string calldata _priceFeedQuote
) external initializer {
vault = IVault(_vault);
vault = _vault;
priceFeedDecimals = _priceFeedDecimals;
priceFeedBase = _priceFeedBase;
priceFeedQuote = _priceFeedQuote;
Expand Down Expand Up @@ -105,15 +111,15 @@ contract MellowPriceFeed is Initializable, AggregatorV3Interface {
) {
roundId = latestRound();

IVault.ProcessWithdrawalsStack memory processWithdrawalsStack = vault.calculateStack();
uint128[] memory ratiosX96 = managedRatiosOracle.getTargetRatiosX96(vault, true);

answer = 0;
if (processWithdrawalsStack.totalSupply != 0) {
answer = int256(processWithdrawalsStack.totalValue) * 1e18 / int256(processWithdrawalsStack.totalSupply);
if (ratiosX96.length != 0) {
answer = int256(uint256(ratiosX96[0])) * 1e18 / int256(managedRatiosOracle.Q96());
}

// These values are equal after chainlink’s OCR update
startedAt = processWithdrawalsStack.timestamp;
startedAt = block.timestamp;
updatedAt = startedAt;

// roundId is always equal to answeredInRound
Expand Down
4 changes: 4 additions & 0 deletions mainnet_chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "0xa1aB70C0F3725AcA1D1e85Bd4402Dd2d5F6AFf19",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -24,6 +25,7 @@
"gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "0x955Ff4Cc738cDC009d2903196d1c94C8Cfb4D55d",
"priceFeedImplementation": "0xfaC9d315b9b558e10eBdb0462aA42577aADe6601",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -40,6 +42,7 @@
"gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "0x09d43904C8ABd470df1B793df68904A9714558CF",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -56,6 +59,7 @@
"gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "0xde471274F1B684476d341eB131224F389AD4A270",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand Down
2 changes: 1 addition & 1 deletion scripts/deployMellowPriceFeedImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function main() {
console.log(`${chain.name} wallet balance: ${ethers.formatEther(balance.toString())} ${chain.tokenSymbol}`);

const mellowPriceFeedFactory = new ethers.ContractFactory(MellowPriceFeed.abi, MellowPriceFeed.bytecode, wallet)
const mellowPriceFeed = await mellowPriceFeedFactory.deploy()
const mellowPriceFeed = await mellowPriceFeedFactory.deploy(chain.managedRatiosOracle)
console.log(`${chain.name}, address: ${await mellowPriceFeed.getAddress()}`);
}
}
Expand Down
19 changes: 19 additions & 0 deletions testnet_chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -24,6 +25,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "0x1A069010D7F572c97925E83a1298Df8f96893c60",
"mellowPriceFeedImplementation": "",
Expand All @@ -40,6 +42,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -56,6 +59,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -72,6 +76,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -88,6 +93,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -104,6 +110,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -120,6 +127,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -136,6 +144,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -151,6 +160,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "0x3DB6DF9EDfDcfE97D574Aa6f106C767051561Be2",
"priceFeedQuotedImplementation": "0x2Babd8D4BCE072e78aA288c639Ef4516fCe26d89",
"mellowPriceFeedImplementation": "",
Expand All @@ -167,6 +177,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -183,6 +194,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "0x48B10B538B7E5af4CbFd93B1C4d36668e8F6F644",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -199,6 +211,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -215,6 +228,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "0x09d43904C8ABd470df1B793df68904A9714558CF",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -231,6 +245,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -247,6 +262,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -263,6 +279,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -279,6 +296,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand All @@ -295,6 +313,7 @@
"gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6",
"ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7",
"create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e",
"managedRatiosOracle": "",
"priceFeedImplementation": "",
"priceFeedQuotedImplementation": "",
"mellowPriceFeedImplementation": "",
Expand Down

0 comments on commit 6226480

Please sign in to comment.