diff --git a/contracts/mellowpricefeed/MellowPriceFeed.sol b/contracts/mellowpricefeed/MellowPriceFeed.sol index 2871cd1..fbf473c 100644 --- a/contracts/mellowpricefeed/MellowPriceFeed.sol +++ b/contracts/mellowpricefeed/MellowPriceFeed.sol @@ -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. @@ -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; @@ -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. @@ -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; @@ -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 diff --git a/mainnet_chains.json b/mainnet_chains.json index 8bf1cac..489e6b5 100644 --- a/mainnet_chains.json +++ b/mainnet_chains.json @@ -8,6 +8,7 @@ "gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "0xa1aB70C0F3725AcA1D1e85Bd4402Dd2d5F6AFf19", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -24,6 +25,7 @@ "gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "0x955Ff4Cc738cDC009d2903196d1c94C8Cfb4D55d", "priceFeedImplementation": "0xfaC9d315b9b558e10eBdb0462aA42577aADe6601", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -40,6 +42,7 @@ "gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "0x09d43904C8ABd470df1B793df68904A9714558CF", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -56,6 +59,7 @@ "gasReceiver": "0x2d5d7d31F671F86C782533cc367F14109a082712", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "0xde471274F1B684476d341eB131224F389AD4A270", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", diff --git a/scripts/deployMellowPriceFeedImplementation.ts b/scripts/deployMellowPriceFeedImplementation.ts index 9661333..d0b9e4c 100644 --- a/scripts/deployMellowPriceFeedImplementation.ts +++ b/scripts/deployMellowPriceFeedImplementation.ts @@ -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()}`); } } diff --git a/testnet_chains.json b/testnet_chains.json index d57f5c5..67e9824 100644 --- a/testnet_chains.json +++ b/testnet_chains.json @@ -8,6 +8,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -24,6 +25,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "0x1A069010D7F572c97925E83a1298Df8f96893c60", "mellowPriceFeedImplementation": "", @@ -40,6 +42,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -56,6 +59,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -72,6 +76,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -88,6 +93,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -104,6 +110,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -120,6 +127,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -136,6 +144,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -151,6 +160,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "0x3DB6DF9EDfDcfE97D574Aa6f106C767051561Be2", "priceFeedQuotedImplementation": "0x2Babd8D4BCE072e78aA288c639Ef4516fCe26d89", "mellowPriceFeedImplementation": "", @@ -167,6 +177,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -183,6 +194,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "0x48B10B538B7E5af4CbFd93B1C4d36668e8F6F644", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -199,6 +211,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -215,6 +228,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "0x09d43904C8ABd470df1B793df68904A9714558CF", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -231,6 +245,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -247,6 +262,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -263,6 +279,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -279,6 +296,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "", @@ -295,6 +313,7 @@ "gasReceiver": "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", "ojoContract": "0x5BB3E85f91D08fe92a3D123EE35050b763D6E6A7", "create2Deployer": "0x98b2920d53612483f91f12ed7754e51b4a77919e", + "managedRatiosOracle": "", "priceFeedImplementation": "", "priceFeedQuotedImplementation": "", "mellowPriceFeedImplementation": "",