Sub-Adapters 1
Preview and test each sub adapter.
Compound (compound)
Metadata
- ID
- compound
- name
"Compound"
- icon
- category
"lending"
- description
"Compound is an open borrowing & lending protocol."
- feeDescription
"Interest fees are paid from borrowers to lenders."
- blockchain
"Ethereum"
- source
"Compound API"
- website
"https://compound.finance"
- tokenTicker
"COMP"
- tokenCoingecko
"compound-governance-token"
- tokenLaunch
"2020-06-22"
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Compound Fees';
2export const version = '0.1.2';
3export const license = 'MIT';
4
5const sum = (a: number, b: number) => a + b;
6
7export function setup(sdk: Context) {
8 const getCompoundFees = async (date: string): Promise<number> => {
9 const startTimestamp = sdk.date.dateToTimestamp(date);
10 const endTimestamp = startTimestamp + 86400;
11
12 const assetJson = await sdk.http.get('https://api.compound.finance/api/v2/ctoken');
13
14 const interestByAsset: number[] = await Promise.all(
15 assetJson.cToken.map(
16 async (asset: any): Promise<number> => {
17 const json = await sdk.http.get(`https://api.compound.finance/api/v2/market_history/graph?asset=${asset.token_address}&min_block_timestamp=${startTimestamp}&max_block_timestamp=${endTimestamp}&num_buckets=1`);
18
19 if (json.total_borrows_history.length === 0) {
20 return 0;
21 }
22
23 const dailyInterest =
24 (json.total_borrows_history[0].total.value *
25 json.prices_usd[0].price.value *
26 json.borrow_rates[0].rate) /
27 365;
28
29 return dailyInterest || 0;
30 }
31 )
32 );
33
34 const oneDay = interestByAsset.reduce(sum, 0);
35
36 return oneDay;
37 }
38
39 sdk.register({
40 id: 'compound',
41 queries: {
42 oneDayTotalFees: getCompoundFees,
43 },
44 metadata: {
45 name: 'Compound',
46 icon: sdk.ipfs.getDataURILoader('QmZpZsg829EnBxE2MPZykZpAfsxyRsu6EuGbtfTkf2EFNj', 'image/svg+xml'),
47 category: 'lending',
48 description: 'Compound is an open borrowing & lending protocol.',
49 feeDescription: 'Interest fees are paid from borrowers to lenders.',
50 blockchain: 'Ethereum',
51 source: 'Compound API',
52 website: 'https://compound.finance',
53 tokenTicker: 'COMP',
54 tokenCoingecko: 'compound-governance-token',
55 tokenLaunch: '2020-06-22',
56 },
57 });
58}
59
It's something off?
Report it to the discussion board on Discord, we will take care of it.