Adapter

Balancer Fees

Sub-Adapters 4

Preview and test each sub adapter.

Balancer - Version 1 (balancer-v1)

Balancer - Version 2 (balancerv2)

Balancer - Polygon (balancerv2-polygon)

Balancer - Arbitrum (balancerv2-arbitrum)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Balancer Fees';
2export const version = '0.1.0';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6  async function getBalancerData(
7    date: string,
8    subgraphName: string,
9    chain = 'ethereum'
10  ): Promise<number> {
11    const todayBlock = await sdk.chainData.getBlockNumber(sdk.date.offsetDaysFormatted(date, 1), chain);
12    const yesterdayBlock = await sdk.chainData.getBlockNumber(date, chain);
13
14    const data = await sdk.graph.query(
15      `balancer-labs/${subgraphName}`,
16      `{
17        now: balancers(first: 1, block: {number: ${todayBlock}}) {
18          totalSwapFee
19        }
20        yesterday: balancers(first: 1, block: {number: ${yesterdayBlock}}) {
21          totalSwapFee
22        }
23      }`
24    );
25
26    return parseFloat(data.now[0].totalSwapFee) - parseFloat(data.yesterday[0].totalSwapFee);
27  };
28
29  const metadata = {
30    category: 'dex',
31    name: 'Balancer',
32    description: 'Balancer is a decentralized exchange & asset pool balancer.',
33    feeDescription: 'Trading fees are paid by traders to liquidity providers',
34    source: 'The Graph Protocol',
35    website: 'https://balancer.fi',
36    blockchain: 'Ethereum',
37    tokenLaunch: '2020-06-20',
38    tokenTicker: 'BAL',
39    tokenCoingecko: 'balancer',
40    icon: sdk.ipfs.getDataURILoader('Qmb3u8knknnGYyLBVrw5ZTqYUue2LC1zCkDWsfctBHJBHN', 'image/svg+xml'),
41    protocolLaunch: '2020-02-27',
42  };
43
44  sdk.register({
45    id: 'balancer-v1',
46    bundle: 'balancer',
47    queries: {
48      oneDayTotalFees: (date: string) => getBalancerData(date, 'balancer'),
49    },
50    metadata: {
51      ...metadata,
52      subtitle: 'Version 1',
53      protocolLaunch: '2020-02-27',
54    },
55  });
56
57  sdk.register({
58    id: 'balancerv2',
59    bundle: 'balancer',
60    queries: {
61      oneDayTotalFees: (date: string) => getBalancerData(date, 'balancer-v2'),
62    },
63    metadata: {
64      ...metadata,
65      subtitle: 'Version 2',
66      protocolLaunch: '2021-05-11',
67    },
68  });
69
70  sdk.register({
71    id: 'balancerv2-polygon',
72    bundle: 'balancer',
73    queries: {
74      oneDayTotalFees: (date: string) => getBalancerData(date, 'balancer-polygon-v2', 'polygon'),
75    },
76    metadata: {
77      ...metadata,
78      subtitle: 'Polygon',
79      blockchain: 'Polygon',
80      protocolLaunch: '2021-07-01',
81    },
82  });
83
84  sdk.register({
85    id: 'balancerv2-arbitrum', 
86    bundle: 'balancer',
87    queries: {
88      oneDayTotalFees: (date: string) => getBalancerData(date, 'balancer-arbitrum-v2', 'arbitrum-one'),
89    },
90    metadata: {
91      ...metadata,
92      subtitle: 'Arbitrum',
93      blockchain: 'Arbitrum One',
94      protocolLaunch: '2021-08-31',
95    },
96  });
97
98  sdk.registerBundle('balancer', metadata);
99}
100

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

QmREELxorZpAM7wnBEu2t5JtwBbJUXhfPHv91vjKNXv3xn

CID (source)

QmWb1kSMCtDMCGDkjrPnnEnxZhXJgQiFRP1tsbPrNFgHKw

Collections

fees

Author

mihal.eth