diff --git a/chains/mainnet/oraibtc.json b/chains/mainnet/oraibtc.json index 9069c212..82526fa5 100644 --- a/chains/mainnet/oraibtc.json +++ b/chains/mainnet/oraibtc.json @@ -12,6 +12,7 @@ "provider": "Oraichain" } ], + "cosmwasm_enabled": false, "sdk_version": "0.42.6", "coin_type": "118", "min_tx_fee": "800", diff --git a/chains/mainnet/oraichain.json b/chains/mainnet/oraichain.json index c6e612d8..ed3c33e0 100644 --- a/chains/mainnet/oraichain.json +++ b/chains/mainnet/oraichain.json @@ -8,6 +8,7 @@ } ], "rpc": [{ "provider": "Oraichain", "address": "https://rpc.orai.io" }], + "cosmwasm_enabled": true, "sdk_version": "0.45.16", "coin_type": "118", "min_tx_fee": "800", diff --git a/src/libs/client.ts b/src/libs/client.ts index a13977a6..b6783276 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -17,11 +17,12 @@ import { type IbcExtension, setupIbcExtension, setupSlashingExtension, + setupDistributionExtension, } from '@cosmjs/stargate'; import { HttpClient, Tendermint37Client, - Tendermint34Client, + // Tendermint34Client, WebsocketClient, type CometClient, } from '@cosmjs/tendermint-rpc'; @@ -39,7 +40,11 @@ import { } from './registry'; import { buildQuery } from '@cosmjs/tendermint-rpc/build/tendermint37/requests'; import { PageRequest, type Coin } from '@/types'; -import type { SlashingExtension } from '@cosmjs/stargate/build/modules'; +import type { + DistributionExtension, + SlashingExtension, +} from '@cosmjs/stargate/build/modules'; +import type { BondStatusString } from '@cosmjs/stargate/build/modules/staking/queries'; export class BaseRestClient { endpoint: string; @@ -54,6 +59,7 @@ export class BaseRestClient { GovExtension & IbcExtension & SlashingExtension & + DistributionExtension & TxExtension; constructor(endpoint: string, registry: R) { @@ -78,6 +84,7 @@ export class BaseRestClient { setupGovExtension, setupIbcExtension, setupSlashingExtension, + setupDistributionExtension, setupTxExtension ); } @@ -188,31 +195,63 @@ export class CosmosRestClient extends BaseRestClient { } // Distribution Module async getDistributionParams() { - return this.request(this.registry.distribution_params, {}); + // return this.request(this.registry.distribution_params, {}); + const res = await this.queryClient.distribution.params(); + console.log(res); + return res; } async getDistributionCommunityPool() { - return this.request(this.registry.distribution_community_pool, {}); + // return this.request(this.registry.distribution_community_pool, {}); + const res = await this.queryClient.distribution.communityPool(); + console.log(res); + return res; } async getDistributionDelegatorRewards(delegator_addr: string) { - return this.request(this.registry.distribution_delegator_rewards, { - delegator_addr, - }); + // return this.request(this.registry.distribution_delegator_rewards, { + // delegator_addr, + // }); + const res = await this.queryClient.distribution.delegationTotalRewards( + delegator_addr + ); + console.log(res); + return res; } async getDistributionValidatorCommission(validator_address: string) { - return this.request(this.registry.distribution_validator_commission, { - validator_address, - }); + // return this.request(this.registry.distribution_validator_commission, { + // validator_address, + // }); + const res = await this.queryClient.distribution.validatorCommission( + validator_address + ); + console.log(res); + return res; } async getDistributionValidatorOutstandingRewards(validator_address: string) { - return this.request( - this.registry.distribution_validator_outstanding_rewards, - { validator_address } + // return this.request( + // this.registry.distribution_validator_outstanding_rewards, + // { validator_address } + // ); + const res = await this.queryClient.distribution.validatorOutstandingRewards( + validator_address ); + console.log(res); + return res; } - async getDistributionValidatorSlashes(validator_address: string) { - return this.request(this.registry.distribution_validator_slashes, { + async getDistributionValidatorSlashes( + validator_address: string, + starting_height: number, + ending_height: number + ) { + // return this.request(this.registry.distribution_validator_slashes, { + // validator_address, + // }); + const res = await this.queryClient.distribution.validatorSlashes( validator_address, - }); + starting_height, + ending_height + ); + console.log(res); + return res; } // Slashing async getSlashingParams() { @@ -273,22 +312,26 @@ export class CosmosRestClient extends BaseRestClient { return this.request(this.registry.gov_proposals_deposits, { proposal_id }); } async getGovProposalTally(proposal_id: string) { - return this.request( - this.registry.gov_proposals_tally, - { proposal_id }, - undefined, - (source: any) => { - return { - tally: { - yes: source.tally.yes || source.tally.yes_count, - abstain: source.tally.abstain || source.tally.abstain_count, - no: source.tally.no || source.tally.no_count, - no_with_veto: - source.tally.no_with_veto || source.tally.no_with_veto_count, - }, - }; - } - ); + const res = await this.queryClient.gov.tally(proposal_id); + console.log(res); + return res; + + // return this.request( + // this.registry.gov_proposals_tally, + // { proposal_id }, + // undefined, + // (source: any) => { + // return { + // tally: { + // yes: source.tally.yes || source.tally.yes_count, + // abstain: source.tally.abstain || source.tally.abstain_count, + // no: source.tally.no || source.tally.no_count, + // no_with_veto: + // source.tally.no_with_veto || source.tally.no_with_veto_count, + // }, + // }; + // } + // ); } async getGovProposalVotes(proposal_id: string, page?: PageRequest) { if (!page) page = new PageRequest(); @@ -362,8 +405,7 @@ export class CosmosRestClient extends BaseRestClient { return res; // return this.request(this.registry.staking_pool, {}); } - async getStakingValidators(status: string, limit = 200) { - // @ts-ignore + async getStakingValidators(status: BondStatusString, limit = 200) { const res = await this.queryClient.staking.validators(status); console.log(status, res); return res; diff --git a/src/libs/registry.ts b/src/libs/registry.ts index 1378ad27..628f3d0e 100644 --- a/src/libs/registry.ts +++ b/src/libs/registry.ts @@ -42,7 +42,7 @@ import type { Validator, } from '@/types/staking'; import type { PaginatedTxs, Tx, TxResponse } from '@/types'; -import semver from 'semver' +import semver from 'semver'; export interface Request { url: string; adapter: (source: any) => T; @@ -75,10 +75,10 @@ export interface RequestRegistry extends AbstractRegistry { distribution_community_pool: Request<{ pool: Coin[] }>; distribution_delegator_rewards: Request<{ rewards: { - validator_address: string, - reward: Coin[] - }[], - total: Coin[] + validator_address: string; + reward: Coin[]; + }[]; + total: Coin[]; }>; mint_inflation: Request<{ inflation: string }>; @@ -90,7 +90,7 @@ export interface RequestRegistry extends AbstractRegistry { }>; mint_annual_provisions: Request<{ annual_provisions: string }>; - slashing_params: Request<{params: SlashingParam}>; + slashing_params: Request<{ params: SlashingParam }>; slashing_signing_info: Request; gov_params_voting: Request; @@ -124,7 +124,7 @@ export interface RequestRegistry extends AbstractRegistry { base_tendermint_validatorsets_latest: Request; base_tendermint_validatorsets_height: Request; - params: Request<{param: any}>; + params: Request<{ param: any }>; tx_txs: Request; tx_txs_block: Request; @@ -151,7 +151,9 @@ export interface RequestRegistry extends AbstractRegistry { ibc_core_connection_connections: Request; ibc_core_connection_connections_connection_id: Request; ibc_core_connection_connections_connection_id_client_state: Request; - 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(source: any): T { @@ -174,16 +176,20 @@ export const VERSION_REGISTRY: ApiProfileRegistry = {}; // ChainName Profile Registory export const NAME_REGISTRY: ApiProfileRegistry = {}; -export function registryVersionProfile(version: string, requests: RequestRegistry) { - VERSION_REGISTRY[version] = requests +export function registryVersionProfile( + version: string, + requests: RequestRegistry +) { + VERSION_REGISTRY[version] = requests; } -export function registryChainProfile(version: string, requests: RequestRegistry) { - NAME_REGISTRY[version] = requests +export function registryChainProfile( + version: string, + requests: RequestRegistry +) { + NAME_REGISTRY[version] = requests; } -export function findApiProfileByChain( - name: string, -): RequestRegistry { +export function findApiProfileByChain(name: string): RequestRegistry { const url = NAME_REGISTRY[name]; // if (!url) { // throw new Error(`Unsupported version or name: ${name}`); @@ -192,12 +198,11 @@ export function findApiProfileByChain( } export function findApiProfileBySDKVersion( - version: string, + version: string ): RequestRegistry | undefined { let closestVersion: string | null = null; - for (const k in VERSION_REGISTRY) { - const key = k.replace('v', "") + const key = k.replace('v', ''); // console.log(semver.gt(key, version), semver.gte(version, key), key, version) if (semver.lte(key, version)) { if (!closestVersion || semver.gt(key, closestVersion)) { diff --git a/src/modules/[chain]/account/[address].vue b/src/modules/[chain]/account/[address].vue index efb7e027..ad91fdc2 100644 --- a/src/modules/[chain]/account/[address].vue +++ b/src/modules/[chain]/account/[address].vue @@ -81,13 +81,15 @@ const totalValue = computed(() => { }); unbonding.value?.forEach((x) => { x.entries?.forEach((y) => { - value += format.tokenValueNumber({amount: y.balance, denom: stakingStore.params.bond_denom}); + value += format.tokenValueNumber({ + amount: y.balance, + denom: stakingStore.params.bond_denom, + }); }); }); return format.formatNumber(value, '0,0.00'); }); - function loadAccount(address: string) { blockchain.rpc.getAuthAccount(address).then((x) => { account.value = x.account; @@ -113,7 +115,7 @@ function loadAccount(address: string) { }); }); - const receivedQuery = `?&pagination.reverse=true&events=coin_received.receiver='${address}'&pagination.limit=5`; + const receivedQuery = `?&pagination.reverse=true&events=coin_received.receiver='${address}'&pagination.limit=5`; blockchain.rpc.getTxs(receivedQuery, {}).then((x) => { recentReceived.value = x.tx_responses; }); @@ -123,11 +125,16 @@ function updateEvent() { loadAccount(props.address); } -function mapAmount(events:{type: string, attributes: {key: string, value: string}[]}[]) { - if(!events) return [] - return events.find(x => x.type==='coin_received')?.attributes - .filter(x => x.key === 'YW1vdW50'|| x.key === `amount`) - .map(x => x.key==='amount'? x.value : String.fromCharCode(...fromBase64(x.value))) +function mapAmount( + events: { type: string; attributes: { key: string; value: string }[] }[] +) { + if (!events) return []; + return events + .find((x) => x.type === 'coin_received') + ?.attributes.filter((x) => x.key === 'YW1vdW50' || x.key === `amount`) + .map((x) => + x.key === 'amount' ? x.value : String.fromCharCode(...fromBase64(x.value)) + ); }