@contractjs/aave-v3
Version:
A TypeScript utility library for Aave V3 contracts.
42 lines • 1.36 kB
JavaScript
import { oracleAbi } from "./constants/abis";
import { priceOracleAddressOn } from "./aaveV3Utils";
/**
* Get the price of an asset in USD
* @param asset - The address of the asset
* @returns The price of the asset in USD
*/
export const getAssetPrice = async (asset, publicClient) => {
if (!publicClient.chain) {
throw new Error("Public client chain is not set");
}
const priceOracleAddress = priceOracleAddressOn(publicClient.chain);
const price = await publicClient.readContract({
address: priceOracleAddress,
abi: oracleAbi,
functionName: 'getAssetPrice',
args: [asset],
});
return price;
};
/**
* Get the price of multiple assets in USD
* @param assets - The addresses of the assets
* @returns The prices of the assets in USD
*/
export const getAssetsPrices = async (assets, publicClient) => {
if (!publicClient.chain) {
throw new Error("Public client chain is not set");
}
const priceOracleAddress = priceOracleAddressOn(publicClient.chain);
const prices = await publicClient.readContract({
address: priceOracleAddress,
abi: oracleAbi,
functionName: 'getAssetsPrices',
args: [assets],
});
return prices.map((price, index) => ({
asset: assets[index],
price,
}));
};
//# sourceMappingURL=priceOracle.js.map