From d4dcdb7da3467066224d6bdfa474fab4f6ae34b1 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Sat, 4 Nov 2023 22:52:18 -0300 Subject: [PATCH 1/3] Updated Price Button with ETH TWA price --- .../constants/abi/Ecosystem/UsdOracle.json | 1 + projects/sdk/src/constants/addresses.ts | 1 + projects/sdk/src/lib/contracts.ts | 7 +++++- .../components/Nav/Buttons/PriceButton.tsx | 6 ++++- .../hooks/beanstalk/useDataFeedTokenPrices.ts | 25 +++++++++++-------- 5 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 projects/sdk/src/constants/abi/Ecosystem/UsdOracle.json diff --git a/projects/sdk/src/constants/abi/Ecosystem/UsdOracle.json b/projects/sdk/src/constants/abi/Ecosystem/UsdOracle.json new file mode 100644 index 0000000000..26b9ffd1a6 --- /dev/null +++ b/projects/sdk/src/constants/abi/Ecosystem/UsdOracle.json @@ -0,0 +1 @@ +[{"inputs":[],"name":"getEthUsdPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lookback","type":"uint256"}],"name":"getEthUsdTwa","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getUsdPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/projects/sdk/src/constants/addresses.ts b/projects/sdk/src/constants/addresses.ts index f68b14e68b..4329c267df 100644 --- a/projects/sdk/src/constants/addresses.ts +++ b/projects/sdk/src/constants/addresses.ts @@ -15,6 +15,7 @@ export const addresses = { DEPOT: Address.make("0xDEb0f00071497a5cc9b4A6B96068277e57A82Ae2"), PIPELINE: Address.make("0xb1bE0000C6B3C62749b5F0c92480146452D15423"), ROOT: Address.make("0x77700005BEA4DE0A78b956517f099260C2CA9a26"), + USD_ORACLE: Address.make("0x1aa19ed7DfC555E4644c9353Ad383c33024855F7"), // ---------------------------------------- // BeaNFT Contracts diff --git a/projects/sdk/src/lib/contracts.ts b/projects/sdk/src/lib/contracts.ts index 708d8f99f6..b27d281786 100644 --- a/projects/sdk/src/lib/contracts.ts +++ b/projects/sdk/src/lib/contracts.ts @@ -27,7 +27,9 @@ import { BeanstalkPrice__factory, BeanstalkPrice, Math, - Math__factory + Math__factory, + UsdOracle, + UsdOracle__factory, } from "src/constants/generated"; import { BaseContract } from "ethers"; @@ -58,6 +60,7 @@ export class Contracts { public readonly depot: Depot; // temp public readonly root: Root; public readonly math: Math; + public readonly usdOracle: UsdOracle; public readonly curve: CurveContracts; @@ -75,6 +78,7 @@ export class Contracts { const depotAddress = sdk.addresses.DEPOT.get(sdk.chainId); const mathAddress = sdk.addresses.MATH.get(sdk.chainId); const rootAddress = sdk.addresses.ROOT.get(sdk.chainId); + const usdOracleAddress = sdk.addresses.USD_ORACLE.get(sdk.chainId); const beancrv3Address = sdk.addresses.BEAN_CRV3.get(sdk.chainId); const pool3Address = sdk.addresses.POOL3.get(sdk.chainId); @@ -93,6 +97,7 @@ export class Contracts { this.depot = Depot__factory.connect(depotAddress, sdk.providerOrSigner); this.math = Math__factory.connect(mathAddress, sdk.providerOrSigner); this.root = Root__factory.connect(rootAddress, sdk.providerOrSigner); + this.usdOracle = UsdOracle__factory.connect(usdOracleAddress, sdk.providerOrSigner); const beanCrv3 = CurveMetaPool__factory.connect(beancrv3Address, sdk.providerOrSigner); const pool3 = Curve3Pool__factory.connect(pool3Address, sdk.providerOrSigner); diff --git a/projects/ui/src/components/Nav/Buttons/PriceButton.tsx b/projects/ui/src/components/Nav/Buttons/PriceButton.tsx index 109357a3fb..5548a190e7 100644 --- a/projects/ui/src/components/Nav/Buttons/PriceButton.tsx +++ b/projects/ui/src/components/Nav/Buttons/PriceButton.tsx @@ -75,7 +75,11 @@ const PriceButton: FC = ({ ...props }) => {
{beanTokenData.deltaB.gte(0) && '+'}{displayBN(beanTokenData.deltaB, true)}
-
ETH Price:
+
Instantaneous ETH Price:
+
${tokenPrices["ETH-instant"]?.toFixed(2) || 0}
+
+ +
Time-Weighted ETH Price:
${tokenPrices.eth?.toFixed(2) || 0}
diff --git a/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts b/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts index c34b66eb95..284bd439f1 100644 --- a/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts +++ b/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts @@ -9,7 +9,6 @@ import { DAI_CHAINLINK_ADDRESSES, USDT_CHAINLINK_ADDRESSES, USDC_CHAINLINK_ADDRESSES, - ETH_CHAINLINK_ADDRESS, } from '../../constants/addresses'; import { useAggregatorV3Contract } from '~/hooks/ledger/useContract'; import { AppState } from '../../state/index'; @@ -41,7 +40,7 @@ export default function useDataFeedTokenPrices() { const daiPriceFeed = useAggregatorV3Contract(DAI_CHAINLINK_ADDRESSES); const usdtPriceFeed = useAggregatorV3Contract(USDT_CHAINLINK_ADDRESSES); const usdcPriceFeed = useAggregatorV3Contract(USDC_CHAINLINK_ADDRESSES); - const ethPriceFeed = useAggregatorV3Contract(ETH_CHAINLINK_ADDRESS); + const ethPriceFeed = sdk.contracts.usdOracle; const crv3Pool = sdk.contracts.curve.pools.pool3; const getChainToken = useGetChainToken(); const dispatch = useDispatch(); @@ -60,8 +59,8 @@ export default function useDataFeedTokenPrices() { usdtPriceDecimals, usdcPriceData, usdcPriceDecimals, - ethPriceData, - ethPriceDecimals, + ethPrice, + ethPriceTWA, crv3Price, ] = await Promise.all([ daiPriceFeed.latestRoundData(), @@ -70,8 +69,8 @@ export default function useDataFeedTokenPrices() { usdtPriceFeed.decimals(), usdcPriceFeed.latestRoundData(), usdcPriceFeed.decimals(), - ethPriceFeed.latestRoundData(), - ethPriceFeed.decimals(), + ethPriceFeed.getEthUsdPrice(), + ethPriceFeed.getEthUsdTwa(900), crv3Pool.get_virtual_price(), ]); @@ -102,14 +101,18 @@ export default function useDataFeedTokenPrices() { usdcPriceDecimals ); } - if (ethPriceData && ethPriceDecimals) { + if (ethPrice && ethPriceTWA) { priceDataCache[eth.address] = getBNResult( - ethPriceData.answer, - ethPriceDecimals + ethPriceTWA, + 6 ); priceDataCache[weth.address] = getBNResult( - ethPriceData.answer, - ethPriceDecimals + ethPriceTWA, + 6 + ); + priceDataCache["ETH-instant"] = getBNResult( + ethPrice, + 6 ); } if (crv3Price) { From fc0b078da1b9be471636b830c41c5831d3e8f5e0 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Sat, 4 Nov 2023 23:09:48 -0300 Subject: [PATCH 2/3] Tweaked parameters --- projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts b/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts index 284bd439f1..0f9feb272c 100644 --- a/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts +++ b/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts @@ -70,7 +70,7 @@ export default function useDataFeedTokenPrices() { usdcPriceFeed.latestRoundData(), usdcPriceFeed.decimals(), ethPriceFeed.getEthUsdPrice(), - ethPriceFeed.getEthUsdTwa(900), + ethPriceFeed.getEthUsdTwa(1800), crv3Pool.get_virtual_price(), ]); From 413076c99ebdf81fae087b991eafc5f105055442 Mon Sep 17 00:00:00 2001 From: uncoolzero <107518216+uncoolzero@users.noreply.github.com> Date: Sun, 5 Nov 2023 01:24:30 -0300 Subject: [PATCH 3/3] Tweaked Parameters --- projects/ui/src/components/Nav/Buttons/PriceButton.tsx | 4 ++-- .../ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/ui/src/components/Nav/Buttons/PriceButton.tsx b/projects/ui/src/components/Nav/Buttons/PriceButton.tsx index 5548a190e7..a6ff74a208 100644 --- a/projects/ui/src/components/Nav/Buttons/PriceButton.tsx +++ b/projects/ui/src/components/Nav/Buttons/PriceButton.tsx @@ -76,11 +76,11 @@ const PriceButton: FC = ({ ...props }) => {
Instantaneous ETH Price:
-
${tokenPrices["ETH-instant"]?.toFixed(2) || 0}
+
${tokenPrices.eth?.toFixed(2) || 0}
Time-Weighted ETH Price:
-
${tokenPrices.eth?.toFixed(2) || 0}
+
${tokenPrices["ETH-TWA"]?.toFixed(2) || 0}
diff --git a/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts b/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts index 0f9feb272c..5dacabadd7 100644 --- a/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts +++ b/projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts @@ -70,7 +70,7 @@ export default function useDataFeedTokenPrices() { usdcPriceFeed.latestRoundData(), usdcPriceFeed.decimals(), ethPriceFeed.getEthUsdPrice(), - ethPriceFeed.getEthUsdTwa(1800), + ethPriceFeed.getEthUsdTwa(3600), crv3Pool.get_virtual_price(), ]); @@ -103,15 +103,15 @@ export default function useDataFeedTokenPrices() { } if (ethPrice && ethPriceTWA) { priceDataCache[eth.address] = getBNResult( - ethPriceTWA, + ethPrice, 6 ); priceDataCache[weth.address] = getBNResult( - ethPriceTWA, + ethPrice, 6 ); - priceDataCache["ETH-instant"] = getBNResult( - ethPrice, + priceDataCache["ETH-TWA"] = getBNResult( + ethPriceTWA, 6 ); }