Adapter

MakerDAO

MakerDAO is the protocol that issues the Dai stablecoin using loans.

Sub-Adapters 1

Preview and test each sub adapter.

MakerDAO (maker)

Metadata

ID
maker
name

"MakerDAO"

icon
protocolLaunch

"2019-11-15"

category

"lending"

description

"MakerDAO is the protocol that issues the Dai stablecoin using loans."

feeDescription

"Stability fees are accrued by borrowers and are used to buy & burn MKR."

blockchain

"Ethereum"

source

"The Graph Protocol"

tokenTicker

"MKR"

tokenCoingecko

"maker"

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'MakerDAO';
2export const version = '0.1.0';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6  const getFees = async (startDate: string, endDate: string): Promise<number> => {
7    const startBlock = await sdk.chainData.getBlockNumber(startDate);
8    const endBlock = await sdk.chainData.getBlockNumber(endDate);
9
10    const data = await sdk.graph.query(
11      'protofire/maker-protocol',
12      `query fees($startBlock: Int!, $endBlock: Int!){
13        start: collateralTypes(block: {number: $startBlock}) {
14          id
15          totalDebt
16          stabilityFee
17        }
18        end: collateralTypes(block: {number: $endBlock}) {
19          id
20          totalDebt
21          stabilityFee
22        }
23      }`,
24      {
25        variables: {
26          startBlock,
27          endBlock,
28        }
29      },
30    );
31    const startDebts: any = {};
32
33    for (const collateral of data.end) {
34      startDebts[collateral.id] = parseFloat(collateral.totalDebt);
35    }
36    let totalFees = 0;
37    for (const collateral of data.start) {
38      if (startDebts[collateral.id]) {
39        const secondsBetweenDates = sdk.date.dateToTimestamp(endDate) - sdk.date.dateToTimestamp(startDate);
40        const feesInDay = Math.pow(collateral.stabilityFee, secondsBetweenDates) - 1;
41        const avgDebt = (startDebts[collateral.id] + parseFloat(collateral.totalDebt)) * 0.5;
42        totalFees += avgDebt * feesInDay;
43      }
44    }
45
46    return totalFees;
47  }
48
49  const getOneDayFees = (date: string) => {
50    const nextDay = sdk.date.offsetDaysFormatted(date, 1);
51    return getFees(date, nextDay);
52  }
53
54  sdk.register({
55    id: 'maker',
56    queries: {
57      oneDayTotalFees: getOneDayFees,
58      oneDayProtocolFees: getOneDayFees,
59      dateRangeTotalFees: getFees,
60      dateRangeProtocolFees: getFees,
61    },
62    metadata: {
63      name: 'MakerDAO',
64      icon: sdk.ipfs.getDataURILoader('QmNuxELX7oWXJtJKveaCFDC7niZ4APtkWgPn1NZm2FLSJV', 'image/svg+xml'),
65      protocolLaunch: '2019-11-15',
66      category: 'lending',
67      description: 'MakerDAO is the protocol that issues the Dai stablecoin using loans.',
68      feeDescription: 'Stability fees are accrued by borrowers and are used to buy & burn MKR.',
69      blockchain: 'Ethereum',
70      source: 'The Graph Protocol',
71      tokenTicker: 'MKR',
72      tokenCoingecko: 'maker',
73    },
74  })
75}

It's something off?

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

Adapter Info

Version

0.1.0

License

MIT

IPFS CID

QmaXQPr8RhGvDzvdfDwKChRqkjDcu5E96Mm6zew2D8eNBa

CID (source)

QmX9Gr5KxDPS8tAfzXvBPhH3LUWpqtcP5cL9J52Ghuy1JQ

Collections

Author

mihal.eth