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

Bean UI - Update Price Button with ETH TWA price #679

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/sdk/src/constants/abi/Ecosystem/UsdOracle.json
Original file line number Diff line number Diff line change
@@ -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"}]
1 change: 1 addition & 0 deletions projects/sdk/src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion projects/sdk/src/lib/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import {
BeanstalkPrice__factory,
BeanstalkPrice,
Math,
Math__factory
Math__factory,
UsdOracle,
UsdOracle__factory,
} from "src/constants/generated";
import { BaseContract } from "ethers";

Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion projects/ui/src/components/Nav/Buttons/PriceButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ const PriceButton: FC<ButtonProps> = ({ ...props }) => {
<div>{beanTokenData.deltaB.gte(0) && '+'}{displayBN(beanTokenData.deltaB, true)}</div>
</Box>
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
<div>ETH Price:</div>
<div>Instantaneous ETH Price:</div>
<div>${tokenPrices.eth?.toFixed(2) || 0}</div>
</Box>
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
<div>Time-Weighted ETH Price:</div>
<div>${tokenPrices["ETH-TWA"]?.toFixed(2) || 0}</div>
</Box>
</Box>
</div>
</>
Expand Down
25 changes: 14 additions & 11 deletions projects/ui/src/hooks/beanstalk/useDataFeedTokenPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -60,8 +59,8 @@ export default function useDataFeedTokenPrices() {
usdtPriceDecimals,
usdcPriceData,
usdcPriceDecimals,
ethPriceData,
ethPriceDecimals,
ethPrice,
ethPriceTWA,
crv3Price,
] = await Promise.all([
daiPriceFeed.latestRoundData(),
Expand All @@ -70,8 +69,8 @@ export default function useDataFeedTokenPrices() {
usdtPriceFeed.decimals(),
usdcPriceFeed.latestRoundData(),
usdcPriceFeed.decimals(),
ethPriceFeed.latestRoundData(),
ethPriceFeed.decimals(),
ethPriceFeed.getEthUsdPrice(),
ethPriceFeed.getEthUsdTwa(3600),
crv3Pool.get_virtual_price(),
]);

Expand Down Expand Up @@ -102,14 +101,18 @@ export default function useDataFeedTokenPrices() {
usdcPriceDecimals
);
}
if (ethPriceData && ethPriceDecimals) {
if (ethPrice && ethPriceTWA) {
priceDataCache[eth.address] = getBNResult(
ethPriceData.answer,
ethPriceDecimals
ethPrice,
6
);
priceDataCache[weth.address] = getBNResult(
ethPriceData.answer,
ethPriceDecimals
ethPrice,
6
);
priceDataCache["ETH-TWA"] = getBNResult(
ethPriceTWA,
6
);
}
if (crv3Price) {
Expand Down
Loading