@lido-sdk/react
Version:
This project is being slowly deprecated and may not receive further updates. Check out [modern Lido SDK](https://github.com/lidofinance/lido-ethereum-sdk/pulls) to access latest functionality. It is actively maintained and is built for interacting with Li
23 lines (20 loc) • 1.01 kB
JavaScript
import { __awaiter } from '../node_modules/tslib/tslib.es6.js';
import { BigNumber } from '@ethersproject/bignumber';
import { getAggregatorContract } from '@lido-sdk/contracts';
import { getAggregatorAddress, CHAINS } from '@lido-sdk/constants';
import { divide } from '@lido-sdk/helpers';
import { useSDK } from './useSDK.js';
import { useLidoSWR } from './useLidoSWR.js';
const useEthPrice = (config) => {
const { providerMainnetRpc } = useSDK();
const address = getAggregatorAddress(CHAINS.Mainnet);
const aggregatorContract = getAggregatorContract(address, providerMainnetRpc);
return useLidoSWR(['lido-swr:eth-price', aggregatorContract], () => __awaiter(void 0, void 0, void 0, function* () {
const [decimals, latestAnswer] = yield Promise.all([
aggregatorContract.decimals(),
aggregatorContract.latestAnswer(),
]);
return divide(latestAnswer, BigNumber.from(10).pow(decimals));
}), config);
};
export { useEthPrice };