Sub-Adapters 1
Preview and test each sub adapter.
Trader Joe (trader-joe)
Metadata
- ID
- trader-joe
- category
"dex"
- name
"Trader Joe"
- description
"Trader Joe is a decentralized exchange on Avalanche"
- feeDescription
"Trading fees are paid by traders to liquidity providers and JOE stakers"
- source
"The Graph Protocol"
- tokenTicker
"JOE"
- tokenCoingecko
"joe"
- website
"https://traderjoexyz.com"
- icon
- protocolLaunch
"2021-06-29"
- blockchain
"Avalanche"
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Trader Joe Fees';
2export const version = '0.1.1';
3export const license = 'MIT';
4
5const SEC_IN_DAY = 86400;
6
7export function setup(sdk: Context) {
8 const createFeeDataQuery = (feePercentage: number) => async (date: string): Promise<number> => {
9 const dateId = Math.floor(sdk.date.dateToTimestamp(date) / SEC_IN_DAY);
10
11 const graphQuery = `query fees($dateId: Int!, $nextDay: Int!) {
12 dayData(id: $dateId) {
13 volumeUSD
14 }
15 nextDay: dayData(id: $nextDay) {
16 volumeUSD
17 }
18 }`;
19
20 const data = await sdk.graph.query(
21 'traderjoe-xyz/exchange',
22 graphQuery,
23 { dateId, nextDay: dateId + 1 },
24 );
25
26 if (!data.nextDay) {
27 return null;
28 }
29
30 const oneDay = parseFloat(data.dayData.volumeUSD) * feePercentage;
31
32 return oneDay;
33 }
34
35 const createFeeRangeQuery = (feePercentage: number) => async (startDate: string, endDate: string): Promise<number> => {
36 const startBlock = await sdk.chainData.getBlockNumber(startDate, 'avalanche');
37 const endBlock = await sdk.chainData.getBlockNumber(endDate, 'avalanche');
38
39 const graphQuery = `query fees($startBlock: Int!, $endBlock: Int!) {
40 startValue: factory(id: "0x9ad6c38be94206ca50bb0d90783181662f0cfa10", block: { number: $startBlock }) {
41 volumeUSD
42 }
43 endValue: factory(id: "0x9ad6c38be94206ca50bb0d90783181662f0cfa10", block: { number: $endBlock }) {
44 volumeUSD
45 }
46 }`;
47
48 const data = await sdk.graph.query(
49 'traderjoe-xyz/exchange',
50 graphQuery,
51 { variables: { startBlock, endBlock } }
52 );
53
54 const volumeDiff = data.endValue.volumeUSD - data.startValue.volumeUSD;
55 const fees = volumeDiff * feePercentage;
56 return fees;
57 }
58
59 sdk.register({
60 id: 'trader-joe',
61 queries: {
62 oneDayTotalFees: createFeeDataQuery(0.003),
63 oneDayProtocolFees: createFeeDataQuery(0.0005),
64 dateRangeTotalFees: createFeeRangeQuery(0.003),
65 dateRangeProtocolFees: createFeeRangeQuery(0.0005),
66 },
67 metadata: {
68 category: 'dex',
69 name: 'Trader Joe',
70 description: 'Trader Joe is a decentralized exchange on Avalanche',
71 feeDescription: 'Trading fees are paid by traders to liquidity providers and JOE stakers',
72 source: 'The Graph Protocol',
73 tokenTicker: 'JOE',
74 tokenCoingecko: 'joe',
75 website: 'https://traderjoexyz.com',
76 icon: sdk.ipfs.getDataURILoader('QmRd1TVZB5Q2h9dzcDsXHWkqEv8hFn65Lydv7Qq9tiWdje', 'image/png'),
77 protocolLaunch: '2021-06-29',
78 blockchain: 'Avalanche',
79 },
80 })
81}
It's something off?
Report it to the discussion board on Discord, we will take care of it.