Skip to content

Instantly share code, notes, and snippets.

@ajb413
Last active January 20, 2021 01:22
Show Gist options
  • Save ajb413/d14f36b5b11bea99818d051120dea500 to your computer and use it in GitHub Desktop.
Save ajb413/d14f36b5b11bea99818d051120dea500 to your computer and use it in GitHub Desktop.
Get COMP accrued for an account on mainnet using Compound.js (https://github.com/compound-finance/compound-js)
const Compound = require('@compound-finance/compound-js');
const provider = 'https://mainnet.infura.io/v3/' + process.env.infuraApiKey;
// mainnet
const CompoundLens = Compound.util.getAddress(Compound.CompoundLens);
const LensAbi = Compound.util.getAbi(Compound.CompoundLens);
const COMP = Compound.util.getAddress(Compound.COMP);
const Comptroller = Compound.util.getAddress(Compound.Comptroller);
const me = '0xa0df350d2637096571F7A701CBc1C5fdE30dF76A';
(async function() {
let metadata = await Compound.eth.read(
CompoundLens,
'getCompBalanceMetadataExt',
[ COMP, Comptroller, me ],
{ provider, abi: LensAbi }
);
console.log('allocated', +metadata.allocated.toString() / 1e18);
})().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment