Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add chain specific getMintInflation func #534

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions chains/mainnet/nolus.json
Original file line number Diff line number Diff line change
@@ -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"
}]
}
2 changes: 1 addition & 1 deletion src/libs/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class BaseRestClient<R extends AbstractRegistry> {
this.endpoint = endpoint;
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}`;
Object.keys(args).forEach((k) => {
url = url.replace(`{${k}}`, args[k] || '');
Expand Down
6 changes: 3 additions & 3 deletions src/libs/clients/evmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ function proposalAdapter(p: any): GovProposal {
}

export const requests: Partial<RequestRegistry> = {
mint_inflation: { url: '/evmos/inflation/v1/inflation_rate', adapter: (data: any) => ({inflation: (Number(data.inflation_rate || 0)/ 100 ).toFixed(2)}) },
mint_inflation: { url: '/evmos/inflation/v1/inflation_rate', adapter: async (data: any) => ({inflation: (Number(data.inflation_rate || 0)/ 100 ).toFixed(2)}) },
gov_params_voting: { url: '/cosmos/gov/v1/params/voting', adapter },
gov_params_tally: { url: '/cosmos/gov/v1/params/tallying', adapter },
gov_params_deposit: { url: '/cosmos/gov/v1/params/deposit', adapter },
gov_proposals: { url: '/cosmos/gov/v1/proposals', adapter: (source: any): PaginatedProposals => {
gov_proposals: { url: '/cosmos/gov/v1/proposals', adapter: async (source: any): Promise<PaginatedProposals> => {
const proposals = source.proposals.map((p:any) => proposalAdapter(p))
return {
proposals,
Expand All @@ -34,7 +34,7 @@ export const requests: Partial<RequestRegistry> = {
}},
gov_proposals_proposal_id: {
url: '/cosmos/gov/v1/proposals/{proposal_id}',
adapter: (source: any): {proposal: GovProposal} => {
adapter: async (source: any): Promise<{proposal: GovProposal}> => {
return {
proposal: proposalAdapter(source.proposal)
}
Expand Down
26 changes: 26 additions & 0 deletions src/libs/clients/nolus.ts
Original file line number Diff line number Diff line change
@@ -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 }
};
6 changes: 3 additions & 3 deletions src/libs/clients/osmosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ function proposalAdapter(p: any): GovProposal {
export const requests: Partial<RequestRegistry> = {
mint_inflation: {
url: `https://public-osmosis-api.numia.xyz/apr?start_date=${new Date(new Date().getTime() - 186400*1000).toISOString().split('T')[0]}&end_date=${new Date().toISOString().split('T')[0]}`,
adapter: (data: any) => {
adapter: async (data: any) => {
const [first] = data
return {inflation: String(Number(first?.apr|| "0")/100.0)}
}
},
gov_params_voting: { url: '/cosmos/gov/v1/params/voting', adapter },
gov_params_tally: { url: '/cosmos/gov/v1/params/tallying', adapter },
gov_params_deposit: { url: '/cosmos/gov/v1/params/deposit', adapter },
gov_proposals: { url: '/cosmos/gov/v1/proposals', adapter: (source: any): PaginatedProposals => {
gov_proposals: { url: '/cosmos/gov/v1/proposals', adapter: async (source: any): Promise<PaginatedProposals> => {
const proposals = source.proposals.map((p:any) => proposalAdapter(p))
return {
proposals,
Expand All @@ -43,7 +43,7 @@ export const requests: Partial<RequestRegistry> = {
}},
gov_proposals_proposal_id: {
url: '/cosmos/gov/v1/proposals/{proposal_id}',
adapter: (source: any): {proposal: GovProposal} => {
adapter: async (source: any): Promise<{proposal: GovProposal}> => {
return {
proposal: proposalAdapter(source.proposal)
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/clients/v0.46.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const requests: Partial<RequestRegistry> = {
gov_params_voting: { url: '/cosmos/gov/v1/params/voting', adapter },
gov_params_tally: { url: '/cosmos/gov/v1/params/tallying', adapter },
gov_params_deposit: { url: '/cosmos/gov/v1/params/deposit', adapter },
gov_proposals: { url: '/cosmos/gov/v1/proposals', adapter: (source: any): PaginatedProposals => {
gov_proposals: { url: '/cosmos/gov/v1/proposals', adapter: async (source: any): Promise<PaginatedProposals> => {
const proposals = source.proposals.map((p:any) => proposalAdapter(p))
return {
proposals,
Expand All @@ -42,7 +42,7 @@ export const requests: Partial<RequestRegistry> = {
}},
gov_proposals_proposal_id: {
url: '/cosmos/gov/v1/proposals/{proposal_id}',
adapter: (source: any): {proposal: GovProposal} => {
adapter: async (source: any): Promise<{proposal: GovProposal}> => {
return {
proposal: proposalAdapter(source.proposal)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fetch from 'cross-fetch';

export async function fetchData<T>(
url: string,
adapter: (source: any) => T
adapter: (source: any) => Promise<T>
): Promise<T> {
const response = await fetch(url);
if (!response.ok) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import type { PaginatedTxs, Tx, TxResponse } from '@/types';
import semver from 'semver'
export interface Request<T> {
url: string;
adapter: (source: any) => T;
adapter: (source: any) => Promise<T>;
}

export interface AbstractRegistry {
Expand Down Expand Up @@ -154,7 +154,7 @@ export interface RequestRegistry extends AbstractRegistry {
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;
}

Expand Down
Loading