Sub-Adapters 5

Preview and test each sub adapter.

Abracadabra.money - Ethereum (abracadabra-ethereum)

Abracadabra.money - Fantom (abracadabra-fantom)

Abracadabra.money - Avalanche (abracadabra-avalanche)

Abracadabra.money - Binance (abracadabra-bsc)

Abracadabra.money - Arbitrum One (abracadabra-arbitrum-one)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Abracadabra Fees';
2export const version = '0.1.1';
3export const license = 'MIT';
4
5interface NetInfo {
6  subgraph: string;
7  blockchain: string;
8  protocolLaunch: string;
9}
10
11type DataResponse = {
12  startValue: [{
13    accrueInfoFeesEarned: number,
14    accrueInfoFeesWithdrawn: number
15  }]
16  endValue: [{
17    accrueInfoFeesEarned: number,
18    accrueInfoFeesWithdrawn: number
19  }]
20}
21
22const networks: { [network: string]: NetInfo } = {
23  ethereum: {
24    subgraph: 'ap0calyp/abracadabra-mainnet-fees',
25    blockchain: 'Ethereum',
26    protocolLaunch: '2021-06-04',
27  },
28  fantom: {
29    subgraph: 'ap0calyp/abracadabra-fantom-fees',
30    blockchain: 'Fantom',
31    protocolLaunch: '2021-05-27',
32  },
33  avalanche: {
34    subgraph: 'ap0calyp/abracadabra-avalanche-fees',
35    blockchain: 'Avalanche',
36    protocolLaunch: '2021-09-07',
37  },
38  bsc: {
39    subgraph: 'ap0calyp/abracadabra-binancesmartchain-fees',
40    blockchain: 'Binance',
41    protocolLaunch: '2021-11-20',
42  },
43  'arbitrum-one': {
44    subgraph: 'ap0calyp/abracadabra-arbitrum-fees',
45    blockchain: 'Arbitrum One',
46    protocolLaunch: '2021-09-16',
47  }
48}
49
50const graphQuery = 
51`query fees($startBlock: Int!, $endBlock: Int!) {
52    startValue: cauldronFees(block: { number: $startBlock }) {
53    accrueInfoFeesEarned
54    accrueInfoFeesWithdrawn
55    }
56    endValue: cauldronFees(block: { number: $endBlock }) {
57      accrueInfoFeesEarned
58      accrueInfoFeesWithdrawn
59    }
60  }`;
61
62function getFees(data: DataResponse): number {
63    const startFees = data.startValue.reduce((prev, curr) => {
64      return prev + Number(curr.accrueInfoFeesEarned) + Number(curr.accrueInfoFeesWithdrawn)
65    }, 0)
66
67    const endFees = data.endValue.reduce((prev, curr) => {
68      return prev + Number(curr.accrueInfoFeesEarned) + Number(curr.accrueInfoFeesWithdrawn)
69    }, 0)
70    return endFees - startFees;
71}
72
73export function setup(sdk: Context) {
74  const createFeeDataQuery = (subgraph: string, network: string) => async (date: string): Promise<number> => {
75    const tomorrow = sdk.date.offsetDaysFormatted(date, 1);
76    let variables: { startBlock: number, endBlock: number } = null;
77    try {
78      const startBlock = await sdk.chainData.getBlockNumber(date, network);
79      const endBlock = await sdk.chainData.getBlockNumber(tomorrow, network);
80      variables = { startBlock, endBlock };
81    } catch (error) {
82        throw Error(`Cannot locate block for ${date}`);
83    }
84
85    const data = await sdk.graph.query(subgraph, graphQuery, { variables });
86    if (data.startValue.length === 0 || data.endValue.length === 0) {
87      throw new Error(`No Abracadabra data found on ${date} from ${subgraph}`);
88    }
89    return getFees(data);
90  }
91
92  const createFeeRangeQuery = (subgraph: string, network: string) => async (startDate: string, endDate: string): Promise<number> => {
93    let variables: { startBlock: number, endBlock: number } = null;
94    try {
95      const startBlock = await sdk.chainData.getBlockNumber(startDate, network);
96      const endBlock = await sdk.chainData.getBlockNumber(endDate, network);
97      variables = { startBlock, endBlock };
98    } catch (error) {
99        throw Error(`Cannot locate block for ${startDate}`);
100    }
101    
102    const data = await sdk.graph.query(subgraph, graphQuery, { variables });
103
104    if (data.startValue.length === 0 || data.endValue.length === 0) {
105      throw new Error(`No Abracadabra data found between ${startDate} and ${endDate} from ${subgraph}`);
106    }
107
108    return getFees(data);
109
110  }
111
112  const bundle = 'abracadabra';
113
114  const metadata = {
115    category: 'lending',
116    name: 'Abracadabra.money',
117    shortName: 'Abracadabra',
118    description:
119      'Abracadabra.money is a lending platform that uses interest-bearing tokens (ibTKNs) as collateral to borrow a USD pegged stablecoin (Magic Internet Money - MIM), that can be used as any other traditional stablecoin.',
120    feeDescription:
121      'Borrow Fees, interest fees, and some liquidation fees are paid to holders of staked Spell.',
122    source: 'The Graph Protocol',
123    tokenTicker: 'SPELL',
124    tokenCoingecko: 'spell-token',
125    website: 'https://abracadabra.money',
126    icon: sdk.ipfs.getDataURILoader('QmR8XgrW7cGncTjPQJ2LBnoQHBFBRve7mN1PT6yLjrKX6s', 'image/png'),
127    protocolLaunch: '2020-05-27',
128  };
129
130  sdk.registerBundle(bundle, metadata);
131
132  Object.entries(networks).map(([network, { subgraph, blockchain, protocolLaunch }]: [string, NetInfo]) => {
133    sdk.register({
134      id: `${bundle}-${network}`,
135      bundle,
136      queries: {
137        oneDayTotalFees: createFeeDataQuery(subgraph, network),
138        oneDayProtocolFees: createFeeDataQuery(subgraph, network),
139        dateRangeTotalFees: createFeeRangeQuery(subgraph, network),
140        dateRangeProtocolFees: createFeeRangeQuery(subgraph, network),
141      },
142      metadata: {
143        ...metadata,
144        subtitle: blockchain,
145        blockchain,
146        protocolLaunch,
147      },
148    })
149  })
150}

It's something off?

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

Adapter Info

Version

0.1.1

License

MIT

IPFS CID

QmepmLhtmeFhZcEW2HhCAUg2QwRWbAs9rS3icbXB9JFbPU

CID (source)

QmXXT65SNc5DSNU8KTxA7pia7zse2X5cHPafR3KqL1ddWt

Collections

Author

mihal.eth