Skip to content

Instantly share code, notes, and snippets.

@ajb413
Created October 20, 2023 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajb413/385d23e6930f01d9ff3af5b23b8b7169 to your computer and use it in GitHub Desktop.
Save ajb413/385d23e6930f01d9ff3af5b23b8b7169 to your computer and use it in GitHub Desktop.
Find out the price feed information for each asset supported by Compound Comet
const ethers = require('ethers'); // v5
const providerUrl = process.env.POLYGON_PROVIDER_URL;
(async () => {
const provider = new ethers.providers.JsonRpcProvider(providerUrl);
const cometAddress = '0xF25212E676D1F7F89Cd72fFEe66158f541246445';
const cometAbi = [
'function getAssetInfo(uint8 i) public view returns (uint8 offset, address asset, address priceFeed, uint64 scale, uint64 borrowCollateralFactor, uint64 liquidateCollateralFactor, uint64 liquidationFactor, uint128 supplyCap)',
'function baseToken() public view returns (address)',
'function baseTokenPriceFeed() public view returns (address)',
];
const comet = new ethers.Contract(cometAddress, cometAbi, provider);
const erc20Abi = [
'function symbol() public view returns (string)'
];
const baseToken = await comet.callStatic.baseToken();
const baseTokenPriceFeed = await comet.callStatic.baseTokenPriceFeed();
const _token = new ethers.Contract(baseToken, erc20Abi, provider);
const _symbol = await _token.callStatic.symbol();
console.log('Base Asset Info:');
console.log(_symbol, baseToken, baseTokenPriceFeed);
console.log('Collateral Asset Info:');
let i = 0;
while (true) {
try {
const assetInfo = await comet.callStatic.getAssetInfo(i);
const asset = assetInfo.asset;
const priceFeed = assetInfo.priceFeed;
const token = new ethers.Contract(asset, erc20Abi, provider);
const symbol = await token.callStatic.symbol();
console.log(i, symbol, asset, priceFeed);
i++;
} catch(e) {
// console.error(e);
process.exit();
}
}
})().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment