Sub-Adapters 1

Preview and test each sub adapter.

Compound (compound)

Metadata

ID
compound
name

"Compound"

icon

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Compound Lending Rates';
2export const version = '0.0.1';
3export const license = 'MIT';
4
5const CTOKEN_ABI = [
6  'function supplyRatePerBlock() external view returns (uint)',
7];
8
9const blocksPerDay = 6570; // (13.15 seconds per block)
10const daysPerYear = 365;
11
12const markets: { [underlying: string]: string } = {
13  '0x6b175474e89094c44da98b954eedeac495271d0f': '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643', // Dai
14  '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': '0x39aa39c021dfbae8fac545936693ac917d5e7563', // USDC
15  '0xdac17f958d2ee523a2206206994597c13d831ec7': '0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9', // USDT
16}
17
18export function setup(sdk: Context) {
19  const getInterestRate = async (assetAddress: string): Promise<number> => {
20    const cToken = markets[assetAddress.toLowerCase()];
21    if (!cToken) {
22      return 0;
23    }
24
25    const contract = sdk.ethers.getContract(cToken, CTOKEN_ABI);
26
27    const supplyRate = await contract.supplyRatePerBlock();
28
29    const mantissa = 10 ** 18 // TODO: decimals
30
31    const apy = (Math.pow((supplyRate.toString() / mantissa * blocksPerDay + 1), daysPerYear)) - 1;
32
33    return apy;
34  }
35
36  sdk.register({
37    id: 'compound',
38    queries: {
39      apyCurrent: getInterestRate,
40    },
41    metadata: {
42      name: 'Compound',
43      icon: sdk.ipfs.getDataURILoader('QmZpZsg829EnBxE2MPZykZpAfsxyRsu6EuGbtfTkf2EFNj', 'image/svg+xml'),
44    },
45  });
46}
47

It's something off?

Report it to the discussion board on Discord, we will take care of it.

Adapter Info

Version

0.0.1

License

MIT

IPFS CID

QmSLyWMVq3rRmsDxerA8nrgvdoPnh8h6bKR1WdBgvFMxWQ

CID (source)

QmeDwt1k8eonUGFQuYF3sS5zkKhNtLSeV8yTMPzbmK2sdJ

Author

mihal.eth