Sub-Adapters 2

Preview and test each sub adapter.

Lyra - Optimism (lyra-optimism)

Lyra - Arbitrum (lyra-arbitrum)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Lyra Fees';
2export const version = '0.1.0';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6  const getOneDayTotalFees = (subgraph: string,) => async (date: string): Promise<number> => {
7    const startTimestamp = Math.floor(sdk.date.dateToTimestamp(date));
8    const nextDayDate = sdk.date.offsetDaysFormatted(date, 1);
9    const endTimestamp = Math.floor(sdk.date.dateToTimestamp(nextDayDate));
10    const now = new Date();
11    const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate());
12    const startOfDateTimestamp = startOfDay.getTime() / 1000;
13
14    if (startTimestamp > startOfDateTimestamp) {
15      return null // return null if querying current date
16    }
17
18    const marketsQuery = `query markets($first: Int) {
19      markets (first: $first) {
20        id 
21        name
22      }  
23    }
24    `
25
26    const marketsData = await sdk.http.post(subgraph, {
27      "query": `{\n  markets (first: 1000) {\n        id \n        name\n      }\n}`});
28
29    const query = `query marketVolumeAndFeesSnapshots(
30      $market: String!, $endTimestamp: Int!, $period: Int!
31      ) {
32        marketVolumeAndFeesSnapshots(first: 1, orderBy: timestamp, orderDirection: desc, where: {
33          market: $market, 
34          timestamp_lte: $endTimestamp, 
35          period_gte: $period
36        }) {
37          id
38          timestamp
39          period
40          premiumVolume
41          notionalVolume
42          totalPremiumVolume
43          totalNotionalVolume
44          spotPriceFees
45          optionPriceFees
46          vegaFees
47          varianceFees
48          deltaCutoffFees
49          liquidatorFees
50          smLiquidationFees
51          lpLiquidationFees
52        }
53      }
54    `;
55
56    const data = await Promise.all(marketsData.data.markets.map(async (marketData) => {
57      const endOfDaySnapshot = await sdk.http.post(subgraph, 
58      {"query":`
59        {
60          \n  
61          marketVolumeAndFeesSnapshots(first: 1, 
62          orderBy: timestamp, 
63          orderDirection: desc, 
64          where: {\n          
65          market: \"${marketData.id}", \n          
66          timestamp_lte: ${endTimestamp}, \n          
67          period_gte: 86400\n        }) 
68          {\n          id\n          timestamp\n          period\n          premiumVolume\n          notionalVolume\n          totalPremiumVolume\n          totalNotionalVolume\n          spotPriceFees\n          optionPriceFees\n          vegaFees\n          varianceFees\n          deltaCutoffFees\n          liquidatorFees\n          smLiquidationFees\n          lpLiquidationFees\n        }\n}`});
69      return {
70        end: endOfDaySnapshot.data.marketVolumeAndFeesSnapshots[0]
71      }
72    })) as any
73
74    const feesByMarket = data.map((marketData) => {
75      let fees = 0
76      const endOfDaySnapshot = marketData.end
77      if (endOfDaySnapshot) {
78        const endOfDayFees = (parseInt(endOfDaySnapshot.deltaCutoffFees)
79        + parseInt(endOfDaySnapshot.lpLiquidationFees)
80        + parseInt(endOfDaySnapshot.optionPriceFees)
81        + parseInt(endOfDaySnapshot.spotPriceFees)
82        + parseInt(endOfDaySnapshot.vegaFees)
83        + parseInt(endOfDaySnapshot.varianceFees))/Math.pow(10, 18)
84        fees += Math.max(0, endOfDayFees)
85      }
86      return fees
87    })
88    return feesByMarket.reduce((total, marketFees) => total + marketFees, 0);
89  }
90
91  const metadata = {
92    name: 'Lyra',
93    icon: sdk.ipfs.getDataURILoader('QmP11N7n6rQT3WWLmgUWksYrEZsRMrfy6NiiP7vjNEhr8P', 'image/png'),
94    category: 'dex',
95    description: 'Lyra is a decentralized options protocol.',
96    feeDescription: 'Trading fees are paid by traders to Lyra liquidity providers.',
97    blockchain: 'Optimism',
98    source: 'Satsuma',
99    website: 'https://lyra.finance',
100    protocolLaunch: '2022-05-01', // Data should be available from this date, onwards
101    tokenTicker: 'LYRA',
102    tokenCoingecko: 'lyra-finance', // The CoinGecko API ID
103  }
104  sdk.register({
105    id: 'lyra-optimism',
106    queries: {
107      oneDayTotalFees: getOneDayTotalFees('https://subgraph.satsuma-prod.com/sw9vuxiQey3c/lyra/optimism-mainnet/api'),
108    },
109    metadata: {
110      ...metadata,
111      bundle: 'lyra',
112      subtitle: 'Optimism',
113    },
114  })
115
116  sdk.register({
117    id: 'lyra-arbitrum',
118    queries: {
119      oneDayTotalFees: getOneDayTotalFees('https://subgraph.satsuma-prod.com/sw9vuxiQey3c/lyra/arbitrum-mainnet/api'),
120    },
121    metadata: {
122      ...metadata,
123      bundle: 'lyra',
124      subtitle: 'Arbitrum',
125      blockchain: 'Arbitrum',
126      protocolLaunch: '2023-02-02',
127    },
128  })
129
130  sdk.registerBundle('lyra', metadata);
131}
132

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

QmVY6e5bR1hYNPgutGgkoehCi6eHDW8xo4twebiuyMgUeX

CID (source)

QmW1uNAju96mSADBfxLBrmJymHpmwcZoaJVpozSoEVgCfT

Collections

Author

0x31EF419d4a2f3fE4F09f4Fc8296057B8278aA060