forked from cerc-io/cosmos-explorer
add chain specific inflation calc
This commit is contained in:
parent
026c2d2840
commit
9c660d8da2
27
chains/mainnet/nolus.json
Normal file
27
chains/mainnet/nolus.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"chain_name": "nolus",
|
||||||
|
"coingecko": "nolus",
|
||||||
|
"api": [
|
||||||
|
{"provider": "Nolus", "address": "https://pirin-cl.nolus.network:1317"},
|
||||||
|
{"provider": "LavenderFive", "address": "https://nolus-api.lavenderfive.com:443"},
|
||||||
|
{"provider": "Allnodes", "address": "https://nolus-rest.publicnode.com"}
|
||||||
|
],
|
||||||
|
"rpc": [
|
||||||
|
{"provider": "Nolus", "address": "https://pirin-cl.nolus.network:26657"},
|
||||||
|
{"provider": "LavenderFive", "address": "https://nolus-rpc.lavenderfive.com:443"},
|
||||||
|
{"provider": "Allnodes", "address": "https://nolus-rpc.publicnode.com:443"}
|
||||||
|
],
|
||||||
|
"snapshot_provider": "",
|
||||||
|
"sdk_version": "v0.47.6",
|
||||||
|
"coin_type": "118",
|
||||||
|
"min_tx_fee": "0",
|
||||||
|
"addr_prefix": "nolus",
|
||||||
|
"logo": "/logos/nolus.svg",
|
||||||
|
"assets": [{
|
||||||
|
"base": "unls",
|
||||||
|
"symbol": "NLS",
|
||||||
|
"exponent": "6",
|
||||||
|
"coingecko_id": "nolus",
|
||||||
|
"logo": "/logos/nolus.svg"
|
||||||
|
}]
|
||||||
|
}
|
@ -20,7 +20,7 @@ export class BaseRestClient<R extends AbstractRegistry> {
|
|||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
}
|
}
|
||||||
async request<T>(request: Request<T>, args: Record<string, any>, query = '', adapter?: (source: any) => T ) {
|
async request<T>(request: Request<T>, args: Record<string, any>, query = '', adapter?: (source: any) => Promise<T> ) {
|
||||||
let url = `${request.url.startsWith("http")?'':this.endpoint}${request.url}${query}`;
|
let url = `${request.url.startsWith("http")?'':this.endpoint}${request.url}${query}`;
|
||||||
Object.keys(args).forEach((k) => {
|
Object.keys(args).forEach((k) => {
|
||||||
url = url.replace(`{${k}}`, args[k] || '');
|
url = url.replace(`{${k}}`, args[k] || '');
|
||||||
|
26
src/libs/clients/nolus.ts
Normal file
26
src/libs/clients/nolus.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import type { RequestRegistry } from '@/libs/registry'
|
||||||
|
import { CosmosRestClient } from '@/libs/client';
|
||||||
|
import { useBlockchain } from '@/stores';
|
||||||
|
import { adapter } from '@/libs/registry'
|
||||||
|
|
||||||
|
// Blockchain Name
|
||||||
|
export const name = 'nolus';
|
||||||
|
|
||||||
|
// nolus custom request
|
||||||
|
export const requests: Partial<RequestRegistry> = {
|
||||||
|
mint_inflation: {
|
||||||
|
url: '/nolus/mint/v1beta1/annual_inflation',
|
||||||
|
adapter: async (data: any): Promise<any> => {
|
||||||
|
try {
|
||||||
|
const client = CosmosRestClient.newDefault(useBlockchain().endpoint.address)
|
||||||
|
const staking = await client.getStakingPool()
|
||||||
|
const inflation = Number(data.annual_inflation) / Number(staking.pool.bonded_tokens) || 0;
|
||||||
|
return { inflation: inflation.toString() };
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error in adapter:", error);
|
||||||
|
return { inflation: "0" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bank_supply_by_denom: { url: "/cosmos/bank/v1beta1/supply/by_denom?denom={denom}", adapter }
|
||||||
|
};
|
@ -2,7 +2,7 @@ import fetch from 'cross-fetch';
|
|||||||
|
|
||||||
export async function fetchData<T>(
|
export async function fetchData<T>(
|
||||||
url: string,
|
url: string,
|
||||||
adapter: (source: any) => T
|
adapter: (source: any) => Promise<T>
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
@ -45,7 +45,7 @@ import type { PaginatedTxs, Tx, TxResponse } from '@/types';
|
|||||||
import semver from 'semver'
|
import semver from 'semver'
|
||||||
export interface Request<T> {
|
export interface Request<T> {
|
||||||
url: string;
|
url: string;
|
||||||
adapter: (source: any) => T;
|
adapter: (source: any) => Promise<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AbstractRegistry {
|
export interface AbstractRegistry {
|
||||||
@ -154,7 +154,7 @@ export interface RequestRegistry extends AbstractRegistry {
|
|||||||
interchain_security_ccv_provider_validator_consumer_addr: Request<{consumer_address: string}>
|
interchain_security_ccv_provider_validator_consumer_addr: Request<{consumer_address: string}>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function adapter<T>(source: any): T {
|
export function adapter<T>(source: any): Promise<T> {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user