From 544bb0b3e02ea407c87112ab50a817e7118b2e42 Mon Sep 17 00:00:00 2001 From: Pham Tu Date: Fri, 19 Jan 2024 14:56:35 +0700 Subject: [PATCH] add osmosis --- chains/mainnet/osmosis.json | 47 ++++++++++++ src/libs/client.ts | 88 +++++++++++----------- src/modules/[chain]/cosmwasm/WasmClient.ts | 6 ++ src/stores/useDashboard.ts | 2 +- src/types/common.ts | 6 +- 5 files changed, 102 insertions(+), 47 deletions(-) create mode 100644 chains/mainnet/osmosis.json diff --git a/chains/mainnet/osmosis.json b/chains/mainnet/osmosis.json new file mode 100644 index 00000000..975f23e6 --- /dev/null +++ b/chains/mainnet/osmosis.json @@ -0,0 +1,47 @@ +{ + "chain_name": "osmosis", + "coingecko": "osmosis", + "api": [ + "https://lcd.osmosis.zone", + "https://api-osmosis-ia.cosmosia.notional.ventures", + "https://osmosis-api.polkachu.com", + "https://lcd-osmosis.blockapsis.com" + ], + "rpc": [ + "https://rpc.osmosis.zone", + "https://rpc-osmosis-ia.cosmosia.notional.ventures:443", + "https://osmosis-rpc.polkachu.com:443", + "https://osmosis.validator.network:443", + "https://rpc-osmosis.blockapsis.com:443" + ], + "snapshot_provider": "", + "sdk_version": "0.46.1", + "coin_type": "118", + "min_tx_fee": "800", + "addr_prefix": "osmo", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png", + "theme_color": "#812cd6", + "assets": [ + { + "base": "uosmo", + "symbol": "OSMO", + "exponent": "6", + "coingecko_id": "osmosis", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png" + }, + { + "base": "uion", + "symbol": "ION", + "exponent": "6", + "coingecko_id": "ion", + "logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png" + }, + { + "base": "usomm", + "symbol": "SOMM", + "exponent": "6", + "coingecko_id": "somm", + "logo": "" + } + ] +} diff --git a/src/libs/client.ts b/src/libs/client.ts index 41014799..a4b54441 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -1,65 +1,64 @@ +import { DEFAULT, fetchData } from '@/libs'; +import { PageRequest } from '@/types'; import { + setupWasmExtension, + type WasmExtension, +} from '@cosmjs/cosmwasm-stargate'; +import { fromBase64 } from '@cosmjs/encoding'; +import type { DecodedTxRaw } from '@cosmjs/proto-signing'; +import { decodeTxRaw } from '@cosmjs/proto-signing'; +import { + createProtobufRpcClient, QueryClient, + setupAuthExtension, setupBankExtension, + setupDistributionExtension, + setupGovExtension, + setupIbcExtension, + setupMintExtension, + setupSlashingExtension, setupStakingExtension, setupTxExtension, + type AuthExtension, type BankExtension, - type StakingExtension, - type TxExtension, - type MintExtension, - setupMintExtension, + type DistributionExtension, type GovExtension, - setupGovExtension, type GovProposalId, type IbcExtension, - type AuthExtension, - type DistributionExtension, - setupIbcExtension, - setupSlashingExtension, - setupDistributionExtension, - createProtobufRpcClient, - setupAuthExtension, + type MintExtension, + type StakingExtension, + type TxExtension, } from '@cosmjs/stargate'; -import { - type WasmExtension, - setupWasmExtension, -} from '@cosmjs/cosmwasm-stargate'; -import type { Request } from './registry'; +import type { SlashingExtension } from '@cosmjs/stargate/build/modules'; +import type { BondStatusString } from '@cosmjs/stargate/build/modules/staking/queries'; +import { longify } from '@cosmjs/stargate/build/queryclient'; import { HttpClient, Tendermint37Client, - // Tendermint34Client, WebsocketClient, - type CometClient, type AbciQueryParams, + type CometClient, type QueryTag, - type TxSearchParams, type TxResponse, } from '@cosmjs/tendermint-rpc'; -import { DEFAULT, fetchData } from '@/libs'; -import { - type AbstractRegistry, - findApiProfileByChain, - findApiProfileBySDKVersion, - registryChainProfile, - registryVersionProfile, - withCustomRequest, - type RequestRegistry, -} from './registry'; import { buildQuery } from '@cosmjs/tendermint-rpc/build/tendermint37/requests'; -import { PageRequest } from '@/types'; -import type { BondStatusString } from '@cosmjs/stargate/build/modules/staking/queries'; -import type { ProposalStatus } from 'cosmjs-types/cosmos/gov/v1beta1/gov'; -import { fromBase64 } from '@cosmjs/encoding'; import { QueryAccountsResponse, QueryClientImpl as AuthQueryClientImpl, } from 'cosmjs-types/cosmos/auth/v1beta1/query'; import { - QueryVotesResponse, + QueryClientImpl as BankQueryClientImpl, + QueryParamsResponse as QueryBankParamsResponse, + QueryTotalSupplyResponse, +} from 'cosmjs-types/cosmos/bank/v1beta1/query'; +import type { ProposalStatus } from 'cosmjs-types/cosmos/gov/v1beta1/gov'; +import { QueryClientImpl as GovQueryClientImpl, QueryProposalsResponse, + QueryVotesResponse, } from 'cosmjs-types/cosmos/gov/v1beta1/query'; +import type { QueryValidatorDelegationsResponse } from 'cosmjs-types/cosmos/staking/v1beta1/query'; +import { QueryClientImpl as StakingQueryClientImpl } from 'cosmjs-types/cosmos/staking/v1beta1/query'; import { QueryAllContractStateResponse, QueryClientImpl as WasmQueryClientImpl, @@ -67,17 +66,16 @@ import { QueryContractsByCreatorResponse, QueryParamsResponse as QueryWasmParamsResponse, } from 'cosmjs-types/cosmwasm/wasm/v1/query'; +import type { Request } from './registry'; import { - QueryClientImpl as BankQueryClientImpl, - QueryParamsResponse as QueryBankParamsResponse, - QueryTotalSupplyResponse, -} from 'cosmjs-types/cosmos/bank/v1beta1/query'; -import type { SlashingExtension } from '@cosmjs/stargate/build/modules'; -import type { DecodedTxRaw } from '@cosmjs/proto-signing'; -import { decodeTxRaw } from '@cosmjs/proto-signing'; -import { longify } from '@cosmjs/stargate/build/queryclient'; -import type { QueryValidatorDelegationsResponse } from 'cosmjs-types/cosmos/staking/v1beta1/query'; -import { QueryClientImpl as StakingQueryClientImpl } from 'cosmjs-types/cosmos/staking/v1beta1/query'; + findApiProfileByChain, + findApiProfileBySDKVersion, + registryChainProfile, + registryVersionProfile, + withCustomRequest, + type AbstractRegistry, + type RequestRegistry, +} from './registry'; export type ExtraTxResponse = TxResponse & { txRaw: DecodedTxRaw; diff --git a/src/modules/[chain]/cosmwasm/WasmClient.ts b/src/modules/[chain]/cosmwasm/WasmClient.ts index fcbcfaa4..6c875833 100644 --- a/src/modules/[chain]/cosmwasm/WasmClient.ts +++ b/src/modules/[chain]/cosmwasm/WasmClient.ts @@ -12,6 +12,7 @@ import type { } from './types'; import { toAscii, toBase64 } from '@cosmjs/encoding'; import type { PageRequest } from '@/types'; +import { useBlockchain } from '@/stores'; export interface WasmRequestRegistry extends AbstractRegistry { cosmwasm_code: Request; @@ -68,6 +69,11 @@ export class WasmRestClient extends BaseRestClient { // if(!pr) pr = new PageRequest() // const query = `?${pr.toQueryString()}` // return this.request(this.registry.cosmwasm_code, {}, /*query*/); + const blockchain = useBlockchain(); + if (blockchain.chainName === 'osmosis') { + page?.setCountTotal(false); + } + const res = await this.queryClient.extra.listCode(page); return res; } diff --git a/src/stores/useDashboard.ts b/src/stores/useDashboard.ts index 989f94fc..c200daca 100644 --- a/src/stores/useDashboard.ts +++ b/src/stores/useDashboard.ts @@ -150,7 +150,7 @@ export function fromLocal(lc: LocalConfig): ChainConfig { { denom: x.symbol.toLowerCase(), exponent: Number(x.exponent) }, ], })); - conf.cosmwasmEnabled = lc.cosmwasm_enabled ?? false; + conf.cosmwasmEnabled = lc.cosmwasm_enabled ?? true; conf.versions = { cosmosSdk: lc.sdk_version, }; diff --git a/src/types/common.ts b/src/types/common.ts index 54f84ff0..26268630 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -46,7 +46,7 @@ export class PageRequest { toPagination() { const pagination = CosmosPageRequest.fromPartial({ key: this.key ? fromBase64(this.key) : undefined, - countTotal: true, + countTotal: this.count_total ?? true, offset: this.offset ? longify(this.offset) : undefined, limit: this.limit ? longify(this.limit) : undefined, reverse: this.reverse ?? true, @@ -58,6 +58,10 @@ export class PageRequest { if (page >= 1) this.offset = (page - 1) * this.limit; } + setCountTotal(count: boolean) { + this.count_total = count; + } + setPageSize(size: number) { this.limit = size; }