diff --git a/chains/mainnet/nolus.json b/chains/mainnet/nolus.json new file mode 100644 index 00000000..81bdd484 --- /dev/null +++ b/chains/mainnet/nolus.json @@ -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" + }] +} diff --git a/src/libs/client.ts b/src/libs/client.ts index 359ac486..75423eb1 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -20,7 +20,7 @@ export class BaseRestClient { this.endpoint = endpoint; this.registry = registry; } - async request(request: Request, args: Record, query = '', adapter?: (source: any) => T ) { + async request(request: Request, args: Record, query = '', adapter?: (source: any) => Promise ) { let url = `${request.url.startsWith("http")?'':this.endpoint}${request.url}${query}`; Object.keys(args).forEach((k) => { url = url.replace(`{${k}}`, args[k] || ''); diff --git a/src/libs/clients/nolus.ts b/src/libs/clients/nolus.ts new file mode 100644 index 00000000..b318a037 --- /dev/null +++ b/src/libs/clients/nolus.ts @@ -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 = { + mint_inflation: { + url: '/nolus/mint/v1beta1/annual_inflation', + adapter: async (data: any): Promise => { + 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 } +}; diff --git a/src/libs/http.ts b/src/libs/http.ts index 0c134fa8..8334d647 100644 --- a/src/libs/http.ts +++ b/src/libs/http.ts @@ -2,7 +2,7 @@ import fetch from 'cross-fetch'; export async function fetchData( url: string, - adapter: (source: any) => T + adapter: (source: any) => Promise ): Promise { const response = await fetch(url); if (!response.ok) { diff --git a/src/libs/registry.ts b/src/libs/registry.ts index 1378ad27..f65edfcf 100644 --- a/src/libs/registry.ts +++ b/src/libs/registry.ts @@ -45,7 +45,7 @@ import type { PaginatedTxs, Tx, TxResponse } from '@/types'; import semver from 'semver' export interface Request { url: string; - adapter: (source: any) => T; + adapter: (source: any) => Promise; } export interface AbstractRegistry { @@ -154,7 +154,7 @@ export interface RequestRegistry extends AbstractRegistry { interchain_security_ccv_provider_validator_consumer_addr: Request<{consumer_address: string}> } -export function adapter(source: any): T { +export function adapter(source: any): Promise { return source; }