Sub-Adapters 1

Preview and test each sub adapter.

Compound (compound)

Metadata

ID
compound
icon
name

"Compound"

category

"app"

issuanceDescription

"COMP tokens are issued to borrowers and lenders."

website

"https://compound.finance"

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Compound Issuance';
2export const version = '0.2.0';
3export const license = 'MIT';
4
5const COMP = '0xc00e94cb662c3520282e6f5717214004a7f26888';
6const RESEVOIR = '0x2775b1c75658be0f640272ccb8c72ac986009e38';
7const COMPTROLER = '0x3d9819210a31b4961b30ef54be2aed79b9c9cd3b';
8const COMPTROLER_API = [
9  'function compRate() external view returns (uint256)',
10]
11
12export async function setup(sdk: Context) {
13  const getCompIssuance = async () => {
14    const today = sdk.date.formatDate(new Date())
15    const weekAgo = sdk.date.offsetDaysFormatted(today, -7)
16
17    const comptrolerContract = sdk.ethers.getContract(COMPTROLER, COMPTROLER_API)
18
19    const [compRate, todayBlock, weekAgoBlock, compPrice] = await Promise.all([
20      comptrolerContract.compRate(),
21      sdk.chainData.getBlockNumber(today),
22      sdk.chainData.getBlockNumber(weekAgo),
23      sdk.coinGecko.getCurrentPrice('compound-governance-token'),
24    ])
25
26    const compRateDecimal = compRate.toString() / 1e18
27    const compInLastWeek = compRateDecimal * (todayBlock - weekAgoBlock)
28
29    return compInLastWeek * compPrice
30  }
31
32  const getCompIssuanceRate = async () => {
33    const comptrolerContract = sdk.ethers.getContract(COMPTROLER, COMPTROLER_API)
34    const compToken = sdk.ethers.getERC20Contract(COMP)
35
36    const today = sdk.date.formatDate(new Date())
37    const yearAgo = sdk.date.offsetDaysFormatted(today, -365)
38
39    const [compRate, blockToday, blockYearAgo, supply, comptrolerBalance, resevoirBalance] = await Promise.all([
40      comptrolerContract.compRate(),
41      sdk.chainData.getBlockNumber(today),
42      sdk.chainData.getBlockNumber(yearAgo),
43      compToken.totalSupply(),
44      compToken.balanceOf(COMPTROLER),
45      compToken.balanceOf(RESEVOIR),
46    ])
47
48    const blocksInYear = blockToday - blockYearAgo
49
50    const adjustedSupply = (supply.toString() - comptrolerBalance.toString() - resevoirBalance.toString()) / 1e18
51    const issuanceRate = compRate * blocksInYear / 1e18 / adjustedSupply
52    return issuanceRate
53  }
54
55  sdk.register({
56    id: 'compound',
57    queries: {
58      issuance7DayAvgUSD: getCompIssuance,
59      issuanceRateCurrent: getCompIssuanceRate,
60    },
61    metadata: {
62      icon: sdk.ipfs.getDataURILoader('QmZpZsg829EnBxE2MPZykZpAfsxyRsu6EuGbtfTkf2EFNj', 'image/svg+xml'),
63      name: 'Compound',
64      category: 'app',
65      issuanceDescription: 'COMP tokens are issued to borrowers and lenders.',
66      website: 'https://compound.finance',
67    },
68  })
69}
70

It's something off?

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

Adapter Info

Version

0.2.0

License

MIT

IPFS CID

Qmdupb8cpuSUKEcqUgaCMWnGW84eoYBxRbEFfxhvhXmZPq

CID (source)

QmPEJzTbd5GBgqFkYo8xd6bMdcdq2BjcmPZdKP9ZakDZwE

Collections

Author

mihal.eth