Adapter

Cosmos

The Cosmos network consists of many independent, parallel blockchains, each powered by classical Byzantine fault-tolerant (BFT) consensus protocols.

Sub-Adapters 1

Preview and test each sub adapter.

Cosmos (atom)

Metadata

ID
atom
name

"Cosmos"

icon
protocolLaunch

"2019-03-13"

category

"blockchain"

description

"The Cosmos network consists of many independent, parallel blockchains, each powered by classical Byzantine fault-tolerant (BFT) consensus protocols."

feeDescription

"Transaction fees are paid by users to miners."

blockchain

"Cosmos"

source

"Cosmos API"

website

"http://cosmos.network/"

tokenTicker

"ATOM"

tokenCoingecko

"cosmos"

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Cosmos';
2export const version = '0.0.1';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6  const getFees = async (startDate: string, endDate: string): Promise<any> => {
7    // Doc: https://cosmoscan.net/cosmos/network-charts
8    const from_timestamp = sdk.date.dateToTimestamp(startDate)
9    const to_timestamp = sdk.date.dateToTimestamp(endDate) + 1
10    const url = `https://api.cosmoscan.net/transactions/fee/agg?by=day&from=${from_timestamp}&to=${to_timestamp}`
11    // sdk.log(url)
12
13    const data = await sdk.http.get(url)
14
15    const totalFeesAtom = data.map(el => parseFloat(el.value)).reduce((acc, cur) => acc + cur, 0)
16    const atomPrice = await sdk.coinGecko.getHistoricalPrice('cosmos', endDate)
17    sdk.log(data, atomPrice, totalFeesAtom)
18    const totalFees = totalFeesAtom * atomPrice
19    return totalFees;
20  }
21
22  const getOneDayFees = (date: string) => {
23    const nextDay = sdk.date.offsetDaysFormatted(date, 1);
24    return getFees(date, nextDay);
25  }
26
27  sdk.register({
28    id: 'atom',
29    queries: {
30      oneDayTotalFees: getOneDayFees,
31      oneDayProtocolFees: getOneDayFees,
32      dateRangeTotalFees: getFees,
33      dateRangeProtocolFees: getFees,
34    },
35    metadata: {
36      name: 'Cosmos',
37      icon: sdk.ipfs.getDataURILoader('QmRPHkVuUWdkmFXEJwP6qUYK6qiRizAiMNQb99J7F8qH6p', 'image/webp'),
38      protocolLaunch: '2019-03-13',
39      category: 'blockchain',
40      description: 'The Cosmos network consists of many independent, parallel blockchains, each powered by classical Byzantine fault-tolerant (BFT) consensus protocols.',
41      feeDescription: 'Transaction fees are paid by users to miners.',
42      blockchain: 'Cosmos',
43      source: 'Cosmos API',
44      website: 'http://cosmos.network/',
45      tokenTicker: 'ATOM',
46      tokenCoingecko: 'cosmos',
47    },
48  })
49}

It's something off?

Report it to the discussion board on Discord, we will take care of it.

Adapter Info

Version

0.0.1

License

MIT

IPFS CID

Qmd2ruJH1nH2fGaAZY2KR1vEQwpm66fnGXBw4QLDt49T3L

CID (source)

QmSCv3jJeC33C5qxtm9SVKhxZQxt7HeTRZoBKoXhsaoTgH

Author

jochemla.sismo.eth