Sub-Adapters 1
Preview and test each sub adapter.
Lyra (lyra)
Metadata
- ID
- lyra
- name
- "Lyra" 
- icon
- category
- "dex" 
- description
- "Lyra is a decentralized exchange on the Optimism L2." 
- feeDescription
- "Trading fees are paid by traders to Lyra liquidity providers." 
- blockchain
- "Optimism" 
- source
- "The Graph Protocol" 
- website
- "https://lyra.finance" 
- protocolLaunch
- "2022-05-01" 
- tokenTicker
- "LYRA" 
- tokenCoingecko
- "lyra-finance" 
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source. 
1export const name = 'Lyra Fees';
2export const version = '0.0.3';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6  const getOneDayTotalFees = 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('https://subgraph.satsuma-prod.com/lyra/optimism-mainnet/api', {
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('https://subgraph.satsuma-prod.com/lyra/optimism-mainnet/api', 
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  sdk.register({
92    id: 'lyra',
93    queries: {
94      oneDayTotalFees: getOneDayTotalFees,
95    },
96    metadata: {
97      name: 'Lyra',
98      icon: sdk.ipfs.getDataURILoader('QmP11N7n6rQT3WWLmgUWksYrEZsRMrfy6NiiP7vjNEhr8P', 'image/png'),
99      category: 'dex',
100      description: 'Lyra is a decentralized exchange on the Optimism L2.',
101      feeDescription: 'Trading fees are paid by traders to Lyra liquidity providers.',
102      blockchain: 'Optimism',
103      source: 'The Graph Protocol',
104      website: 'https://lyra.finance',
105      protocolLaunch: '2022-05-01', // Data should be available from this date, onwards
106      tokenTicker: 'LYRA',
107      tokenCoingecko: 'lyra-finance', // The CoinGecko API ID
108    },
109  })
110}
111
It's something off?
Report it to the discussion board on Discord, we will take care of it.