Sub-Adapters 1
Preview and test each sub adapter.
Avalanche (avalanche)
Metadata
- ID
- avalanche
- name
"Avalanche"
- icon
- category
"l1"
- description
"Avalanche is a platform for inter-connected blockchains."
- feeDescription
"Transaction fees are burned."
- source
"Ava Labs"
- website
"https://avalabs.org"
- tokenTicker
"AVAX"
- tokenCoingecko
"avalanche-2"
- protocolLaunch
"2020-09-22"
- tokenLaunch
"2020-09-22"
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Avalanche Issuance & Staked Value';
2export const version = '0.1.0';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6 const getSupply = async () => {
7 const supply = await sdk.http.post('https://api.avax.network/ext/P', {
8 "jsonrpc": "2.0",
9 "method": "platform.getCurrentSupply",
10 "params": {},
11 "id": 1
12 })
13 return supply.result.supply / 1e9;
14 }
15
16 const getCurrentValidators = async () => {
17 const validators = await sdk.http.post('https://api.avax.network/ext/P', {
18 jsonrpc: "2.0",
19 method: "platform.getCurrentValidators",
20 params: {},
21 id: 1
22 });
23
24 return validators.result.validators;
25 }
26
27 const getOneDayIssuance = async (): Promise<number> => {
28 const validators = await getCurrentValidators();
29
30 let totalAvaxPerDay = 0;
31
32 const handleValidator = (validator: any) => {
33 const periodInSec = validator.endTime - validator.startTime;
34 const periodInDays = periodInSec / (24 * 60 * 60);
35 const avaPerDay = validator.potentialReward / periodInDays;
36 totalAvaxPerDay += avaPerDay;
37 }
38
39 for (const validator of validators) {
40 handleValidator(validator);
41 for (const delegator of validator.delegators || []) {
42 handleValidator(delegator);
43 }
44 }
45 return totalAvaxPerDay / 1e9
46 }
47
48 const getIssuanceUSD7Day = async () => {
49 const [price, oneDayIncrease] = await Promise.all([
50 sdk.coinGecko.getCurrentPrice('avalanche-2'),
51 getOneDayIssuance(),
52 ])
53
54 return price * oneDayIncrease;
55 }
56
57 const getInflationRate = async () => {
58 const [supply, oneDayIncrease] = await Promise.all([
59 getSupply(),
60 getOneDayIssuance(),
61 ])
62
63 return (oneDayIncrease / supply) * 365
64 }
65
66 const getStakedAVAXUSD = async () => {
67 const [validators, avaxPrice] = await Promise.all([
68 getCurrentValidators(),
69 sdk.coinGecko.getCurrentPrice('avalanche-2'),
70 ]);
71
72 let totalAvaxStaked = 0;
73
74 const handleValidator = (validator: any) => {
75 totalAvaxStaked += validator.stakeAmount / 1e9;
76 }
77
78 for (const validator of validators) {
79 handleValidator(validator);
80 for (const delegator of validator.delegators || []) {
81 handleValidator(delegator);
82 }
83 }
84
85 return totalAvaxStaked * avaxPrice;
86 }
87
88 sdk.register({
89 id: 'avalanche',
90 queries: {
91 issuance7DayAvgUSD: getIssuanceUSD7Day,
92 issuanceRateCurrent: getInflationRate,
93 stakedAssetsUSD: getStakedAVAXUSD,
94 },
95 metadata: {
96 name: 'Avalanche',
97 icon: sdk.ipfs.getDataURILoader('QmcWreeBT5HuurXsc5LbdDphmXUY3T4YrfnXvqt6y2no68', 'image/svg+xml'),
98 category: 'l1',
99 description: 'Avalanche is a platform for inter-connected blockchains.',
100 feeDescription: 'Transaction fees are burned.',
101 source: 'Ava Labs',
102 website: 'https://avalabs.org',
103 tokenTicker: 'AVAX',
104 tokenCoingecko: 'avalanche-2',
105 protocolLaunch: '2020-09-22',
106 tokenLaunch: '2020-09-22',
107 },
108 })
109}
110
It's something off?
Report it to the discussion board on Discord, we will take care of it.