Sub-Adapters 1
Preview and test each sub adapter.
Synthetix - Ethereum (synthetix-mainnet)
Metadata
- ID
- synthetix-mainnet
- icon
- category
"dex"
- name
"Synthetix"
- description
"The Synthetix Exchange is a decentralized exchange for trading synthetic assets"
- feeDescription
"Trading fees are paid by users to SNX stakers"
- blockchain
"Ethereum"
- source
"The Graph Protocol"
- tokenTicker
"SNX"
- tokenCoingecko
"havven"
- protocolLaunch
"2018-06-08"
- subtitle
"Ethereum"
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Synthetix';
2export const version = '0.1.1';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6 const getFees = async (subgraph: string, chain: string, startDate: string, endDate: string) => {
7 const [startDateBlock, endDateBlock] = await Promise.all([
8 sdk.chainData.getBlockNumber(startDate, chain),
9 sdk.chainData.getBlockNumber(endDate, chain),
10 ]);
11
12 const data = await sdk.graph.query(
13 subgraph,
14 `query fees($startDateBlock: Int!, $endDateBlock: Int!){
15 start: total(id: "mainnet", block: {number: $startDateBlock}) {
16 totalFeesGeneratedInUSD
17 }
18 end: total(id: "mainnet", block: {number: $endDateBlock}) {
19 totalFeesGeneratedInUSD
20 }
21 }`,
22 {
23 variables: {
24 startDateBlock,
25 endDateBlock,
26 },
27 }
28 );
29 const fees =
30 parseFloat(data.end.totalFeesGeneratedInUSD) - parseFloat(data.start.totalFeesGeneratedInUSD);
31
32 return fees;
33 };
34
35 const getRangeQuery = (subgraph: string, chain: string) => (startDate: string, endDate: string) => {
36 return getFees(subgraph, chain, startDate, endDate);
37 }
38
39 const getOneDayQuery = (subgraph: string, chain: string) => async (date: string) => {
40 const nextDay = sdk.date.offsetDaysFormatted(date, 1);
41 return getFees(subgraph, chain, date, nextDay);
42 }
43
44 const metadata = {
45 icon: sdk.ipfs.getDataURILoader('QmYPqFXTqYcynD5hT9sZbsoPZXbvjSfL7WWQPL7EwYAyE5', 'image/svg+xml'),
46 category: 'dex',
47 name: 'Synthetix',
48 description: 'The Synthetix Exchange is a decentralized exchange for trading synthetic assets',
49 feeDescription: 'Trading fees are paid by users to SNX stakers',
50 blockchain: 'Ethereum',
51 source: 'The Graph Protocol',
52 tokenTicker: 'SNX',
53 tokenCoingecko: 'havven',
54 protocolLaunch: '2018-06-08',
55 };
56
57 sdk.register({
58 id: 'synthetix-mainnet',
59 bundle: 'synthetix',
60 queries: {
61 oneDayTotalFees: getOneDayQuery('synthetixio-team/synthetix-exchanges', 'ethereum'),
62 oneDayProtocolFees: getOneDayQuery('synthetixio-team/synthetix-exchanges', 'ethereum'),
63 dateRangeTotalFees: getRangeQuery('synthetixio-team/synthetix-exchanges', 'ethereum'),
64 dateRangeProtocolFees: getRangeQuery('synthetixio-team/synthetix-exchanges', 'ethereum'),
65 },
66 metadata: {
67 ...metadata,
68 subtitle: 'Ethereum',
69 },
70 });
71
72 // Subgraph is down at the moment
73 // sdk.register({
74 // id: 'synthetix-optimism',
75 // bundle: 'synthetix',
76 // queries: {
77 // oneDayTotalFees: getOneDayQuery('synthetixio-team/optimism-exchanges', 'optimism'),
78 // oneDayProtocolFees: getOneDayQuery('synthetixio-team/optimism-exchanges', 'optimism'),
79 // dateRangeTotalFees: getRangeQuery('synthetixio-team/optimism-exchanges', 'ethereum'),
80 // dateRangeProtocolFees: getRangeQuery('synthetixio-team/optimism-exchanges', 'ethereum'),
81 // },
82 // metadata: {
83 // ...metadata,
84 // subtitle: 'Optimism',
85 // blockchain: 'Optimism',
86 // protocolLaunch: '2021-07-30',
87 // },
88 // });
89
90 sdk.registerBundle('synthetix', metadata);
91}
It's something off?
Report it to the discussion board on Discord, we will take care of it.