Adapter

Helium - Issuance

Calculate issuance rate and total USD issuance using Helium API

Sub-Adapters 1

Preview and test each sub adapter.

Helium (helium)

Metadata

ID
helium
name

"Helium"

icon
protocolLaunch

"2019-07-29"

category

"blockchain"

description

"Helium is a decentralized machine network powered by a physical blockchain"

issuanceDescription

"Transaction rewards are minted and paid to miners."

blockchain

"Helium"

source

"Helium API"

website

"https://www.helium.com/"

tokenTicker

"HNT"

tokenCoingecko

"helium"

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Helium - Issuance';
2export const version = '0.0.1';
3export const license = 'MIT';
4export const description = 'Calculate issuance rate and total USD issuance using Helium API';
5export const changeLog = 'Initial commit';
6
7export function setup(sdk: Context) {
8  // Helper functions, could be in sdk
9  function daysAgo(days: number) {
10    const startDate = new Date(Date.now() - (86400 * 1000 * days))
11    const month = (startDate.getMonth() + 1).toString().padStart(2, '0')
12    const day = startDate.getDate().toString().padStart(2, '0')
13    const startDateString = `${startDate.getFullYear()}-${month}-${day}`
14    return startDateString
15  }
16
17  const getRewards = async (startDate: string, endDate: string): Promise<any> => {
18    // Doc: https://docs.helium.com/api/blockchain/validators/
19    // Fetch can fail if date range is too spread
20    const min_time = startDate + 'T00:00:00Z'
21    const max_time = endDate + 'T00:00:00Z'
22    const url = `https://api.helium.io/v1/validators/rewards/sum?min_time=${min_time}&max_time=${max_time}&bucket=day`
23    const data = await sdk.http.get(url)
24    return data.data.total; // In helium units
25  }
26
27  const getHeliumIssuanceData = async () => {
28    const today = daysAgo(0)
29    const totalRewards = await getRewards(daysAgo(7), today);
30    const hntPrice = await sdk.coinGecko.getHistoricalPrice('helium', today)
31    const issuance = totalRewards * hntPrice / 7
32    return issuance;
33  };
34
35  const getInflationRateFromSupply = async () => {
36    const rewards_thisWeek = await getRewards(daysAgo(8), daysAgo(0)); // 7 days, inclusive
37    const supply = await sdk.http.get('https://api.helium.io/v1/stats/token_supply?format=raw')
38    // sdk.log(rewards_thisWeek, supply)
39    const rate = (rewards_thisWeek / supply) * (365 / 7);
40    return rate;
41  }
42
43  sdk.register({
44    id: 'helium',
45    queries: {
46      issuance7DayAvgUSD: getHeliumIssuanceData,
47      issuanceRateCurrent: getInflationRateFromSupply,
48    },
49    metadata: {
50      name: 'Helium',
51      icon: sdk.ipfs.getDataURILoader('QmYNpjeXeZhKGQ7PPw4Fy4LwPJLhZ3PYXWenhmSKRvSnvf', 'image/webp'),
52      protocolLaunch: '2019-07-29',
53      category: 'blockchain',
54      description: 'Helium is a decentralized machine network powered by a physical blockchain',
55      issuanceDescription: 'Transaction rewards are minted and paid to miners.',
56      blockchain: 'Helium',
57      source: 'Helium API',
58      website: 'https://www.helium.com/',
59      tokenTicker: 'HNT',
60      tokenCoingecko: 'helium',
61    },
62  })
63}
64
65
66
67

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

QmZ8pPkL8Tdh9wgKGNbxB5qubRrGxNPmuDyQqfpmzVa5yz

CID (source)

QmZ5BCmU5Sv96qHdLmu3v641N25ARQwA6ho8yrZyLRvb6j

Collections

Author

jochemla.sismo.eth