Sub-Adapters 1
Preview and test each sub adapter.
Osmosis (osmosis)
Metadata
- ID
- osmosis
- name
- "Osmosis" 
- category
- "dex" 
- icon
- description
- "Osmosis is an advanced AMM protocol built using the Cosmos SDK" 
- feeDescription
- "Trading fees are paid to liquidity providers" 
- source
- "Osmosis API" 
- tokenTicker
- "OSMO" 
- tokenCoingecko
- "osmosis" 
- website
- "https://osmosis.zone" 
- protocolLaunch
- "2021-06-24" 
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source. 
1export const name = 'Osmosis Fees & Issuance';
2export const version = '0.2.4';
3export const license = 'MIT';
4export const description = 'Fee data is pulled from the Osmosis indexer server, while issuance is calculated using the hardcoded issuance rate';
5
6const GENESIS_SUPPLY = 100_000_000;
7const GENESIS_TIME = '2021-06-18 18:00:00';
8const ISSUED_IN_FIRST_YEAR = 300_000_000;
9const MS_IN_YEAR = 365 * 24 * 60 * 60 * 1000;
10
11export function setup(sdk: Context) {
12  // Cache the API result, so we only need to request it once
13  let feeDataPromise: Promise<any> | null = null;
14  const getFeeData = () => {
15    if (!feeDataPromise) {
16      feeDataPromise = sdk.http.get('https://api-osmosis.imperator.co/fees/v1/total/historical');
17    }
18    return feeDataPromise;
19  }
20
21  const getOsmosisFee = async (date: string): Promise<number> => {
22    const data = await getFeeData();
23
24    for (const day of data) {
25      if (day.time === date) {
26        return day.fees_spent;
27      }
28    }
29    return 0;
30  }
31
32  // In the first year, there will be a total of 300 million tokens released.
33  // After 365 days, this will be cut by ⅓, and thus there will be a total of
34  // 200 million tokens released in Year 2. In Year 3, there will be a total
35  // of 133 million tokens released. And so on.
36  // https://medium.com/osmosis/osmo-token-distribution-ae27ea2bb4db
37  const getIssuance = async () => {
38    const price = await sdk.coinGecko.getCurrentPrice('osmosis');
39    return ISSUED_IN_FIRST_YEAR / 365 * price;
40  }
41
42  const getIssuanceRate = async () => {
43    const msSinceGenesis = (new Date()).getTime() - (new Date(GENESIS_TIME)).getTime();
44    const yearsSinceGenesis = msSinceGenesis / MS_IN_YEAR;
45    const supply = (yearsSinceGenesis * ISSUED_IN_FIRST_YEAR) + GENESIS_SUPPLY;
46    const issuanceRate = ISSUED_IN_FIRST_YEAR / supply;
47    return issuanceRate;
48  }
49
50  sdk.register({
51    id: 'osmosis',
52    queries: {
53      oneDayTotalFees: getOsmosisFee,
54      oneDayIssuanceUSD: getIssuance,
55      issuance7DayAvgUSD: getIssuance,
56      issuanceRateCurrent: getIssuanceRate,
57    },
58    metadata: {
59      name: 'Osmosis',
60      category: 'dex',
61      icon: sdk.ipfs.getDataURILoader('QmaPe4CFwjoN3orMzYUhrXYfYdsbpJn497i2bHJJjzEgPL', 'image/svg+xml'),
62      description: 'Osmosis is an advanced AMM protocol built using the Cosmos SDK',
63      feeDescription: 'Trading fees are paid to liquidity providers',
64      source: 'Osmosis API',
65      tokenTicker: 'OSMO',
66      tokenCoingecko: 'osmosis',
67      website: 'https://osmosis.zone',
68      protocolLaunch: '2021-06-24',
69    },
70  })
71}
72
It's something off?
Report it to the discussion board on Discord, we will take care of it.