Adapter

Trader Joe Fees

Trader Joe is a decentralized exchange on Avalanche

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.0';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6  const createFeeDataQuery = (feePercentage: number) => async (date: string): Promise<number> => {
7    const graphQuery = `query fees($date: Int!) {
8      dayDatas(where: { date: $date }) {
9        volumeUSD
10      }
11    }`;
12
13    const data = await sdk.graph.query(
14      'traderjoe-xyz/exchange',
15      graphQuery,
16      {
17        variables: {
18          date: sdk.date.dateToTimestamp(date),
19        },
20      }
21    );
22
23    if (data.dayDatas.length === 0) {
24      throw new Error(`No TraderJoe data found on ${date}`);
25    }
26
27    const oneDay = parseFloat(data.dayDatas[0].volumeUSD) * feePercentage;
28
29    return oneDay;
30  }
31
32  const createFeeRangeQuery = (feePercentage: number) => async (startDate: string, endDate: string): Promise<number> => {
33    const startBlock = await sdk.chainData.getBlockNumber(startDate, 'avalanche');
34    const endBlock = await sdk.chainData.getBlockNumber(endDate, 'avalanche');
35    
36    const graphQuery = `query fees($startBlock: Int!, $endBlock: Int!) {
37      startValue: factory(id: "0x9ad6c38be94206ca50bb0d90783181662f0cfa10", block: { number: $startBlock }) {
38        volumeUSD
39      }
40      endValue: factory(id: "0x9ad6c38be94206ca50bb0d90783181662f0cfa10", block: { number: $endBlock }) {
41        volumeUSD
42      }
43    }`;
44
45    const data = await sdk.graph.query(
46      'traderjoe-xyz/exchange',
47      graphQuery,
48      { variables: { startBlock, endBlock } }
49    );
50
51    const volumeDiff = data.endValue.volumeUSD - data.startValue.volumeUSD;
52    const fees = volumeDiff * feePercentage;
53    return fees;
54  }
55
56  sdk.register({
57    id: 'trader-joe',
58    queries: {
59      oneDayTotalFees: createFeeDataQuery(0.003),
60      oneDayProtocolFees: createFeeDataQuery(0.0005),
61      dateRangeTotalFees: createFeeRangeQuery(0.003),
62      dateRangeProtocolFees: createFeeRangeQuery(0.0005),
63    },
64    metadata: {
65      category: 'dex',
66      name: 'Trader Joe',
67      description: 'Trader Joe is a decentralized exchange on Avalanche',
68      feeDescription: 'Trading fees are paid by traders to liquidity providers and JOE stakers',
69      source: 'The Graph Protocol',
70      tokenTicker: 'JOE',
71      tokenCoingecko: 'joe',
72      website: 'https://traderjoexyz.com',
73      icon: sdk.ipfs.getDataURILoader('QmRd1TVZB5Q2h9dzcDsXHWkqEv8hFn65Lydv7Qq9tiWdje', 'image/png'),
74      protocolLaunch: '2021-06-29',
75      blockchain: 'Avalanche',
76    },
77  })
78}

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

QmcWy14kydi3AuCeEoFuzjzTMchp9ciVGTLjsCSP46NoiH

CID (source)

Qmb5eLFJJVQjsfAVHe6p6T26fJqMnBdehvbehF4DV9EaT4

Collections

Author

mihal.eth