From 22f6de7248bbf8385b197ab6f6f7d6a201e07025 Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:54:35 -0400 Subject: [PATCH] Pull out a base abstract client --- .../cosmwasm-codegen/Betting.client.ts | 174 ++++++------------ packages/core/src/actions/index.ts | 2 +- ...on.ts => get-ans-host-version-from-api.ts} | 2 +- .../clients/create-abstract-base-client.ts | 29 +++ .../clients/create-account-public-client.ts | 3 + .../clients/create-account-wallet-client.ts | 3 + .../core/src/clients/create-api-client.ts | 3 + .../core/src/clients/create-public-client.ts | 32 +++- .../core/src/clients/create-wallet-client.ts | 4 + .../src/clients/decorators/abstract-base.ts | 122 ++++++++++++ .../src/clients/decorators/account-public.ts | 4 + .../src/clients/decorators/account-wallet.ts | 3 + packages/core/src/clients/decorators/api.ts | 3 + .../core/src/clients/decorators/public.ts | 107 +---------- packages/core/src/clients/index.ts | 1 + 15 files changed, 267 insertions(+), 225 deletions(-) rename packages/core/src/actions/public/{get-ans-host-version.ts => get-ans-host-version-from-api.ts} (91%) create mode 100644 packages/core/src/clients/create-abstract-base-client.ts create mode 100644 packages/core/src/clients/decorators/abstract-base.ts diff --git a/examples/wagemos-cosmoskit-nextjs/src/_generated/cosmwasm-codegen/Betting.client.ts b/examples/wagemos-cosmoskit-nextjs/src/_generated/cosmwasm-codegen/Betting.client.ts index 87afe267..5137403b 100644 --- a/examples/wagemos-cosmoskit-nextjs/src/_generated/cosmwasm-codegen/Betting.client.ts +++ b/examples/wagemos-cosmoskit-nextjs/src/_generated/cosmwasm-codegen/Betting.client.ts @@ -6,97 +6,68 @@ import { CamelCasedProperties } from "type-fest"; import { SigningCosmWasmClient, ExecuteResult } from "@abstract-money/cli/cosmjs"; -import { AbstractQueryClient, AbstractAccountQueryClient, AbstractAccountClient, AppExecuteMsg, AppExecuteMsgFactory, AdapterExecuteMsg, AdapterExecuteMsgFactory, AbstractClient, AbstractAccountId } from "@abstract-money/core/legacy"; import { StdFee, Coin } from "@abstract-money/cli/cosmjs"; import { Decimal, InstantiateMsg, ExecuteMsg, AssetEntry, AccountTrace, ChainName, Uint128, AccountOdds, AccountId, Bet, AnsAsset, QueryMsg, MigrateMsg, Addr, BetsResponse, ConfigResponse, ListOddsResponse, RoundStatus, RoundsResponse, RoundResponse, OddsResponse } from "./Betting.types"; import { BettingQueryMsgBuilder, BettingExecuteMsgBuilder } from "./Betting.message-builder"; +import { AccountWalletClient, AccountPublicClient, AppExecuteMsg, AppExecuteMsgFactory } from "@abstract-money/core"; + export interface IBettingAppQueryClient { moduleId: string; - accountQueryClient: AbstractAccountQueryClient; + accountPublicClient: AccountPublicClient; _moduleAddress: string | undefined; - round: (params: CamelCasedProperties["round"]>) => Promise; - listRounds: (params: CamelCasedProperties["list_rounds"]>) => Promise; + round: () => Promise; odds: (params: CamelCasedProperties["odds"]>) => Promise; - listOdds: (params: CamelCasedProperties["list_odds"]>) => Promise; + listOdds: () => Promise; config: () => Promise; - bets: (params: CamelCasedProperties["bets"]>) => Promise; - connectSigningClient: (signingClient: SigningCosmWasmClient, address: string) => BettingAppClient; + bets: () => Promise; getAddress: () => Promise; } + export class BettingAppQueryClient implements IBettingAppQueryClient { - accountQueryClient: AbstractAccountQueryClient; + accountPublicClient: AccountPublicClient; moduleId: string; _moduleAddress: string | undefined; constructor({ - abstractQueryClient, - accountId, - managerAddress, - proxyAddress, - moduleId - }: { - abstractQueryClient: AbstractQueryClient; - accountId: AbstractAccountId; - managerAddress: string; - proxyAddress: string; + accountPublicClient, + moduleId + }: { + accountPublicClient: AccountPublicClient; moduleId: string; }) { - this.accountQueryClient = new AbstractAccountQueryClient({ - abstract: abstractQueryClient, - accountId, - managerAddress, - proxyAddress - }); + this.accountPublicClient = accountPublicClient; this.moduleId = moduleId; this.round = this.round.bind(this); - this.listRounds = this.listRounds.bind(this); this.odds = this.odds.bind(this); this.listOdds = this.listOdds.bind(this); this.config = this.config.bind(this); this.bets = this.bets.bind(this); } - round = async (params: CamelCasedProperties["round"]>): Promise => { - return this._query(BettingQueryMsgBuilder.round(params)); - }; - listRounds = async (params: CamelCasedProperties["list_rounds"]>): Promise => { - return this._query(BettingQueryMsgBuilder.listRounds(params)); + round = async (): Promise => { + return this._query(BettingQueryMsgBuilder.round()); }; odds = async (params: CamelCasedProperties["odds"]>): Promise => { return this._query(BettingQueryMsgBuilder.odds(params)); }; - listOdds = async (params: CamelCasedProperties["list_odds"]>): Promise => { - return this._query(BettingQueryMsgBuilder.listOdds(params)); + listOdds = async (): Promise => { + return this._query(BettingQueryMsgBuilder.listOdds()); }; config = async (): Promise => { return this._query(BettingQueryMsgBuilder.config()); }; - bets = async (params: CamelCasedProperties["bets"]>): Promise => { - return this._query(BettingQueryMsgBuilder.bets(params)); + bets = async (): Promise => { + return this._query(BettingQueryMsgBuilder.bets()); }; getAddress = async (): Promise => { if (!this._moduleAddress) { - const address = await this.accountQueryClient.getModuleAddress(this.moduleId); + const address = await this.accountPublicClient.getModuleAddress({ + id: this.moduleId + }); if (address === null) { throw new Error(`Module ${this.moduleId} not installed`); @@ -107,72 +78,50 @@ export class BettingAppQueryClient implements IBettingAppQueryClient { return this._moduleAddress!; }; - connectSigningClient = (signingClient: SigningCosmWasmClient, address: string): BettingAppClient => { - return new BettingAppClient({ - accountId: this.accountQueryClient.accountId, - managerAddress: this.accountQueryClient.managerAddress, - proxyAddress: this.accountQueryClient.proxyAddress, - moduleId: this.moduleId, - abstractClient: this.accountQueryClient.abstract.connectSigningClient(signingClient, address) - }); - }; _query = async (queryMsg: QueryMsg): Promise => { - return this.accountQueryClient.queryModule({ + return this.accountPublicClient.queryModule({ moduleId: this.moduleId, moduleType: "app", queryMsg }); }; } + export interface IBettingAppClient extends IBettingAppQueryClient { - accountClient: AbstractAccountClient; - createRound: (params: CamelCasedProperties["create_round"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; - register: (params: CamelCasedProperties["register"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + accountWalletClient: AccountWalletClient; + register: (fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise; updateAccounts: (params: CamelCasedProperties["update_accounts"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + }>["update_accounts"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise; placeBet: (params: CamelCasedProperties["place_bet"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; - distributeWinnings: (params: CamelCasedProperties["distribute_winnings"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + }>["place_bet"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise; + distributeWinnings: (fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise; closeRound: (params: CamelCasedProperties["close_round"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + }>["close_round"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise; updateConfig: (params: CamelCasedProperties["update_config"]>, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise; + }>["update_config"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise; } + export class BettingAppClient extends BettingAppQueryClient implements IBettingAppClient { - accountClient: AbstractAccountClient; + accountWalletClient: AccountWalletClient; constructor({ - abstractClient, - accountId, - managerAddress, - proxyAddress, - moduleId - }: { - abstractClient: AbstractClient; - accountId: AbstractAccountId; - managerAddress: string; - proxyAddress: string; + accountPublicClient, + accountWalletClient, + moduleId + }: { + accountPublicClient: AccountPublicClient; + accountWalletClient: AccountWalletClient; moduleId: string; }) { super({ - abstractQueryClient: abstractClient, - accountId, - managerAddress, - proxyAddress, + accountPublicClient, moduleId }); - this.accountClient = AbstractAccountClient.fromQueryClient(this.accountQueryClient, abstractClient); - this.createRound = this.createRound.bind(this); + this.accountWalletClient = accountWalletClient; this.register = this.register.bind(this); this.updateAccounts = this.updateAccounts.bind(this); this.placeBet = this.placeBet.bind(this); @@ -181,43 +130,36 @@ export class BettingAppClient extends BettingAppQueryClient implements IBettingA this.updateConfig = this.updateConfig.bind(this); } - createRound = async (params: CamelCasedProperties["create_round"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { - return this._execute(BettingExecuteMsgBuilder.createRound(params), fee, memo, _funds); - }; - register = async (params: CamelCasedProperties["register"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { - return this._execute(BettingExecuteMsgBuilder.register(params), fee, memo, _funds); + register = async (fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise => { + return this._execute(BettingExecuteMsgBuilder.register(), fee_, memo_, funds_); }; updateAccounts = async (params: CamelCasedProperties["update_accounts"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { - return this._execute(BettingExecuteMsgBuilder.updateAccounts(params), fee, memo, _funds); + }>["update_accounts"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise => { + return this._execute(BettingExecuteMsgBuilder.updateAccounts(params), fee_, memo_, funds_); }; placeBet = async (params: CamelCasedProperties["place_bet"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { - return this._execute(BettingExecuteMsgBuilder.placeBet(params), fee, memo, _funds); + }>["place_bet"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise => { + return this._execute(BettingExecuteMsgBuilder.placeBet(params), fee_, memo_, funds_); }; - distributeWinnings = async (params: CamelCasedProperties["distribute_winnings"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { - return this._execute(BettingExecuteMsgBuilder.distributeWinnings(params), fee, memo, _funds); + distributeWinnings = async (fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise => { + return this._execute(BettingExecuteMsgBuilder.distributeWinnings(), fee_, memo_, funds_); }; closeRound = async (params: CamelCasedProperties["close_round"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { - return this._execute(BettingExecuteMsgBuilder.closeRound(params), fee, memo, _funds); + }>["close_round"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise => { + return this._execute(BettingExecuteMsgBuilder.closeRound(params), fee_, memo_, funds_); }; updateConfig = async (params: CamelCasedProperties["update_config"]>, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { - return this._execute(BettingExecuteMsgBuilder.updateConfig(params), fee, memo, _funds); + }>["update_config"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise => { + return this._execute(BettingExecuteMsgBuilder.updateConfig(params), fee_, memo_, funds_); }; - _execute = async (msg: ExecuteMsg, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise => { + _execute = async (msg: ExecuteMsg, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise => { + const signingCwClient = await this.accountWalletClient.getSigningCosmWasmClient(); + const sender = await this.accountWalletClient.getSenderAddress(); const moduleMsg: AppExecuteMsg = AppExecuteMsgFactory.executeApp(msg); - return await this.accountClient.abstract.client.execute(this.accountClient.sender, await this.getAddress(), moduleMsg, fee, memo, _funds); + return await signingCwClient.execute(sender, await this.getAddress(), moduleMsg, fee_, memo_, funds_); }; -} \ No newline at end of file +} diff --git a/packages/core/src/actions/index.ts b/packages/core/src/actions/index.ts index 6d4db5d0..c105bf6c 100644 --- a/packages/core/src/actions/index.ts +++ b/packages/core/src/actions/index.ts @@ -36,7 +36,7 @@ export * from './public/get-ans-host-address-from-version-control' export * from './public/get-ans-host-query-client-from-api' export * from './public/get-ans-host-query-client-from-version-control' export * from './public/get-ans-host-query-client' -export * from './public/get-ans-host-version' +export * from './public/get-ans-host-version-from-api' export * from './public/get-app-module-code-id-from-version-control' export * from './public/get-cosm-wasm-client' export * from './public/get-account-query-client' diff --git a/packages/core/src/actions/public/get-ans-host-version.ts b/packages/core/src/actions/public/get-ans-host-version-from-api.ts similarity index 91% rename from packages/core/src/actions/public/get-ans-host-version.ts rename to packages/core/src/actions/public/get-ans-host-version-from-api.ts index 822e895b..47b26334 100644 --- a/packages/core/src/actions/public/get-ans-host-version.ts +++ b/packages/core/src/actions/public/get-ans-host-version-from-api.ts @@ -8,7 +8,7 @@ export type GetAnsHostVersionParameters = { version?: string } -export async function getAnsHostVersion({ +export async function getAnsHostVersionFromApi({ cosmWasmClient, apiUrl, version, diff --git a/packages/core/src/clients/create-abstract-base-client.ts b/packages/core/src/clients/create-abstract-base-client.ts new file mode 100644 index 00000000..f2bfc21c --- /dev/null +++ b/packages/core/src/clients/create-abstract-base-client.ts @@ -0,0 +1,29 @@ +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import type { Evaluate } from '../types/utils' +import { type Client, type ClientConfig, createClient } from './create-client' +import { + AbstractBaseActions, + abstractBaseActions, +} from './decorators/abstract-base' + +export type AbstractBaseClientConfig = ClientConfig & { + cosmWasmClient: CosmWasmClient +} + +export type AbstractBaseClient = Evaluate> + +export function createAbstractBaseClient( + parameters: AbstractBaseClientConfig, +): AbstractBaseClient { + const { + key = 'abstract-base', + name = 'Abstract Base Client', + cosmWasmClient, + } = parameters + const client = createClient({ + ...parameters, + key, + name, + }) + return client.extend(() => abstractBaseActions(cosmWasmClient)) +} diff --git a/packages/core/src/clients/create-account-public-client.ts b/packages/core/src/clients/create-account-public-client.ts index 6b3b6822..010b3ab1 100644 --- a/packages/core/src/clients/create-account-public-client.ts +++ b/packages/core/src/clients/create-account-public-client.ts @@ -16,6 +16,9 @@ export type AccountPublicClientConfig = PublicClientConfig & { accountId: VersionControlTypes.AccountId } +/** + * A query client for querying a specific account in the Abstract infrastructure. + */ export type AccountPublicClient = Evaluate> export function createAccountPublicClient( diff --git a/packages/core/src/clients/create-account-wallet-client.ts b/packages/core/src/clients/create-account-wallet-client.ts index 49ff6b05..8ef2569f 100644 --- a/packages/core/src/clients/create-account-wallet-client.ts +++ b/packages/core/src/clients/create-account-wallet-client.ts @@ -13,6 +13,9 @@ export type AccountWalletClientConfig = WalletClientConfig & { accountId: VersionControlTypes.AccountId } +/** + * A signing client interact with a specific account in the Abstract infrastructure. + */ export type AccountWalletClient = Evaluate< Client > diff --git a/packages/core/src/clients/create-api-client.ts b/packages/core/src/clients/create-api-client.ts index 55a6686a..8230957e 100644 --- a/packages/core/src/clients/create-api-client.ts +++ b/packages/core/src/clients/create-api-client.ts @@ -7,6 +7,9 @@ export type ApiClientConfig = ClientConfig & { apiUrl?: string } +/** + * A client to query the Abstract API. + */ export type ApiClient = Evaluate> export function createApiClient(parameters: ApiClientConfig): ApiClient { diff --git a/packages/core/src/clients/create-public-client.ts b/packages/core/src/clients/create-public-client.ts index 9e372302..29bd9e50 100644 --- a/packages/core/src/clients/create-public-client.ts +++ b/packages/core/src/clients/create-public-client.ts @@ -1,16 +1,27 @@ -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import type { Evaluate } from '../types/utils' import { ABSTRACT_API_URL } from '../utils' -import { ApiClientConfig, createApiClient } from './create-api-client' +import { + AbstractBaseClientConfig, + createAbstractBaseClient, +} from './create-abstract-base-client' +import { ApiClientConfig } from './create-api-client' import { type Client } from './create-client' +import { AbstractBaseActions } from './decorators/abstract-base' +import { apiActions } from './decorators/api' import { type PublicActions, publicActions } from './decorators/public' -export type PublicClientConfig = ApiClientConfig & { - cosmWasmClient: CosmWasmClient -} +export type PublicClientConfig = AbstractBaseClientConfig & ApiClientConfig -export type PublicClient = Evaluate> +/** + * A public client for querying the Abstract infrastructure via contract & API. + */ +export type PublicClient = Evaluate> +/** + * Create a public client to query the Abstract infrastructure. + * Public -> AbstractBase & Api + * @param parameters + */ export function createPublicClient( parameters: PublicClientConfig, ): PublicClient { @@ -20,10 +31,15 @@ export function createPublicClient( cosmWasmClient, apiUrl = ABSTRACT_API_URL, } = parameters - const client = createApiClient({ + const baseClient = createAbstractBaseClient({ ...parameters, key, name, }) - return client.extend(() => publicActions(cosmWasmClient, apiUrl)) + + // Note: this in theory should call createApiClient, but instead we extend the actions manually + + return baseClient + .extend(() => apiActions(apiUrl)) + .extend(() => publicActions(cosmWasmClient, apiUrl)) } diff --git a/packages/core/src/clients/create-wallet-client.ts b/packages/core/src/clients/create-wallet-client.ts index bef71ad6..baa1812e 100644 --- a/packages/core/src/clients/create-wallet-client.ts +++ b/packages/core/src/clients/create-wallet-client.ts @@ -12,6 +12,10 @@ export type WalletClientConfig = Omit & { export type WalletClient = Evaluate> +/** + * Create a signing client to interact with the Abstract infrastructure. + * @param parameters + */ export function createWalletClient( parameters: WalletClientConfig, ): WalletClient { diff --git a/packages/core/src/clients/decorators/abstract-base.ts b/packages/core/src/clients/decorators/abstract-base.ts new file mode 100644 index 00000000..b115c019 --- /dev/null +++ b/packages/core/src/clients/decorators/abstract-base.ts @@ -0,0 +1,122 @@ +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { getAbstractModuleAddressFromVersionControl } from '../../actions/public/get-abstract-module-address-from-version-control' +import { getAccountQueryClient } from '../../actions/public/get-account-query-client' +import { getAnsHostAddressFromVersionControl } from '../../actions/public/get-ans-host-address-from-version-control' +import { getAnsHostQueryClient } from '../../actions/public/get-ans-host-query-client' +import { getAnsHostQueryClientFromVersionControl } from '../../actions/public/get-ans-host-query-client-from-version-control' +import { getCosmWasmClient } from '../../actions/public/get-cosm-wasm-client' +import { getIbcClientQueryClient } from '../../actions/public/get-ibc-client-query-client' +import { getVersionControlModuleData } from '../../actions/public/get-version-control-module-data' +import { getVersionControlQueryClient } from '../../actions/public/get-version-control-query-client' +import { ExtractAndPartializeParameters } from '../../types/parameters' + +type ExtractAndPartializeDecoratedParametersFromParameters< + fn extends (payload: any) => any, +> = ExtractAndPartializeParameters + +/** + * Actions that query the chain for Abstract things directly using the {@link CosmWasmClient}. + */ +export type AbstractBaseActions = { + getCosmWasmClient(): ReturnType + getAccountQueryClient( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getAccountQueryClient + >, + ): ReturnType + getVersionControlQueryClient( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getVersionControlQueryClient + >, + ): ReturnType + getAnsHostQueryClient( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getAnsHostQueryClient + >, + ): ReturnType + getIbcClientQueryClient( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getIbcClientQueryClient + >, + ): ReturnType + getAbstractModuleAddressFromVersionControl( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getAbstractModuleAddressFromVersionControl + >, + ): ReturnType + getAnsHostAddressFromVersionControl( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getAnsHostAddressFromVersionControl + >, + ): ReturnType + getAnsHostQueryClientFromVersionControl( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getAnsHostQueryClientFromVersionControl + >, + ): ReturnType + getVersionControlModuleData( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getVersionControlModuleData + >, + ): ReturnType +} + +export function abstractBaseActions( + cosmWasmClient: CosmWasmClient, +): AbstractBaseActions { + return { + getCosmWasmClient: () => + getCosmWasmClient({ + cosmWasmClient, + }), + getAccountQueryClient: ({ extra, ...parameters }) => + getAccountQueryClient({ + cosmWasmClient, + ...parameters, + ...extra, + }), + getVersionControlQueryClient: ({ extra, ...parameters }) => + getVersionControlQueryClient({ + cosmWasmClient, + ...parameters, + ...extra, + }), + + getAnsHostQueryClient: ({ extra, ...parameters }) => + getAnsHostQueryClient({ + cosmWasmClient, + ...parameters, + ...extra, + }), + getIbcClientQueryClient: ({ extra, ...parameters }) => + getIbcClientQueryClient({ + cosmWasmClient, + ...parameters, + ...extra, + }), + getAbstractModuleAddressFromVersionControl: ({ extra, ...parameters }) => + getAbstractModuleAddressFromVersionControl({ + cosmWasmClient, + ...parameters, + ...extra, + }), + getAnsHostAddressFromVersionControl: ({ extra, ...parameters }) => + getAnsHostAddressFromVersionControl({ + cosmWasmClient, + ...parameters, + ...extra, + }), + getAnsHostQueryClientFromVersionControl: ({ extra, ...parameters }) => + getAnsHostQueryClientFromVersionControl({ + cosmWasmClient, + ...parameters, + ...extra, + }), + getVersionControlModuleData: ({ extra, ...parameters }) => + getVersionControlModuleData({ + cosmWasmClient, + ...parameters, + ...extra, + }), + } +} diff --git a/packages/core/src/clients/decorators/account-public.ts b/packages/core/src/clients/decorators/account-public.ts index df421f3f..122f89b1 100644 --- a/packages/core/src/clients/decorators/account-public.ts +++ b/packages/core/src/clients/decorators/account-public.ts @@ -25,6 +25,10 @@ type ExtractAndPartializeDecoratedParametersFromParameters< fn, 'cosmWasmClient' | 'accountId' | 'apiUrl' > + +/** + * The public query client actions for an Abstract account. + */ export type AccountPublicActions = { getAccountAddress( parameters?: ExtractAndPartializeDecoratedParametersFromParameters< diff --git a/packages/core/src/clients/decorators/account-wallet.ts b/packages/core/src/clients/decorators/account-wallet.ts index c984e94a..69526bca 100644 --- a/packages/core/src/clients/decorators/account-wallet.ts +++ b/packages/core/src/clients/decorators/account-wallet.ts @@ -30,6 +30,9 @@ type ExtractAndPartializeDecoratedParametersFromParameters< 'accountId' | 'signingCosmWasmClient' | 'apiUrl' | 'sender' > +/** + * The wallet (mutating) actions for an Abstract account. + */ export type AccountWalletActions = { claimNamespace( parameters: ExtractAndPartializeDecoratedParametersFromParameters< diff --git a/packages/core/src/clients/decorators/api.ts b/packages/core/src/clients/decorators/api.ts index 25c2cb44..fbf051c9 100644 --- a/packages/core/src/clients/decorators/api.ts +++ b/packages/core/src/clients/decorators/api.ts @@ -12,6 +12,9 @@ type ExtractAndPartializeDecoratedParametersFromParameters< fn extends (payload: any) => any, > = ExtractAndPartializeParameters +/** + * Query actions to be performed on the Abstract API. + */ export type ApiActions = { getAnsHostAddressFromApi( parameters: ExtractAndPartializeDecoratedParametersFromParameters< diff --git a/packages/core/src/clients/decorators/public.ts b/packages/core/src/clients/decorators/public.ts index a1935809..734305fc 100644 --- a/packages/core/src/clients/decorators/public.ts +++ b/packages/core/src/clients/decorators/public.ts @@ -8,7 +8,7 @@ import { getAnsHostAddressFromVersionControl } from '../../actions/public/get-an import { getAnsHostQueryClient } from '../../actions/public/get-ans-host-query-client' import { getAnsHostQueryClientFromApi } from '../../actions/public/get-ans-host-query-client-from-api' import { getAnsHostQueryClientFromVersionControl } from '../../actions/public/get-ans-host-query-client-from-version-control' -import { getAnsHostVersion } from '../../actions/public/get-ans-host-version' +import { getAnsHostVersionFromApi } from '../../actions/public/get-ans-host-version-from-api' import { getCosmWasmClient } from '../../actions/public/get-cosm-wasm-client' import { getIbcClientQueryClient } from '../../actions/public/get-ibc-client-query-client' import { getRemoteHostsFromApi } from '../../actions/public/get-remote-hosts-from-api' @@ -22,6 +22,10 @@ type ExtractAndPartializeDecoratedParametersFromParameters< fn extends (payload: any) => any, > = ExtractAndPartializeParameters +/** + * "Public" query actions available for the Abstract infrastructure. + * Also see {@link AbstractBaseActions} for more public query actions. + */ export type PublicActions = { getAccountsBaseAddresses( parameters: ExtractAndPartializeDecoratedParametersFromParameters< @@ -33,67 +37,26 @@ export type PublicActions = { typeof getAbstractModuleVersion >, ): ReturnType - getAbstractModuleAddressFromVersionControl( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getAbstractModuleAddressFromVersionControl - >, - ): ReturnType getAnsHostVersion( parameters?: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getAnsHostVersion - >, - ): ReturnType - getAnsHostAddressFromVersionControl( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getAnsHostAddressFromVersionControl + typeof getAnsHostVersionFromApi >, - ): ReturnType - getAnsHostQueryClientFromVersionControl( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getAnsHostQueryClientFromVersionControl - >, - ): ReturnType + ): ReturnType getAnsHostQueryClientFromApi( parameters?: ExtractAndPartializeDecoratedParametersFromParameters< typeof getAnsHostQueryClientFromApi >, ): ReturnType - getAnsHostQueryClient( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getAnsHostQueryClient - >, - ): ReturnType - getIbcClientQueryClient( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getIbcClientQueryClient - >, - ): ReturnType - getAccountQueryClient( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getAccountQueryClient - >, - ): ReturnType - getVersionControlModuleData( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getVersionControlModuleData - >, - ): ReturnType getVersionControlQueryClientFromApi( parameters?: ExtractAndPartializeDecoratedParametersFromParameters< typeof getVersionControlQueryClientFromApi >, ): ReturnType - getVersionControlQueryClient( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getVersionControlQueryClient - >, - ): ReturnType getRemoteHosts( parameters?: ExtractAndPartializeDecoratedParametersFromParameters< typeof getRemoteHostsFromApi >, ): ReturnType - getCosmWasmClient(): ReturnType getSimulationResult( parameters: ExtractAndPartializeDecoratedParametersFromParameters< typeof getSimulationResultFromApi @@ -118,12 +81,6 @@ export function publicActions( ...parameters, ...extra, }), - getAbstractModuleAddressFromVersionControl: ({ extra, ...parameters }) => - getAbstractModuleAddressFromVersionControl({ - cosmWasmClient, - ...parameters, - ...extra, - }), getAbstractModuleVersion: ({ extra, ...parameters }) => getAbstractModuleVersion({ cosmWasmClient, @@ -132,26 +89,12 @@ export function publicActions( ...extra, }), getAnsHostVersion: ({ extra, ...parameters } = {}) => - getAnsHostVersion({ + getAnsHostVersionFromApi({ apiUrl, cosmWasmClient, ...parameters, ...extra, }), - - getAnsHostAddressFromVersionControl: ({ extra, ...parameters }) => - getAnsHostAddressFromVersionControl({ - cosmWasmClient, - ...parameters, - ...extra, - }), - - getAnsHostQueryClientFromVersionControl: ({ extra, ...parameters }) => - getAnsHostQueryClientFromVersionControl({ - cosmWasmClient, - ...parameters, - ...extra, - }), getAnsHostQueryClientFromApi: ({ extra, ...parameters } = {}) => getAnsHostQueryClientFromApi({ cosmWasmClient, @@ -159,24 +102,6 @@ export function publicActions( ...parameters, ...extra, }), - getAnsHostQueryClient: ({ extra, ...parameters }) => - getAnsHostQueryClient({ - cosmWasmClient, - ...parameters, - ...extra, - }), - getIbcClientQueryClient: ({ extra, ...parameters }) => - getIbcClientQueryClient({ - cosmWasmClient, - ...parameters, - ...extra, - }), - getVersionControlModuleData: ({ extra, ...parameters }) => - getVersionControlModuleData({ - cosmWasmClient, - ...parameters, - ...extra, - }), getVersionControlQueryClientFromApi: ({ extra, ...parameters } = {}) => getVersionControlQueryClientFromApi({ cosmWasmClient, @@ -184,18 +109,6 @@ export function publicActions( ...parameters, ...extra, }), - getVersionControlQueryClient: ({ extra, ...parameters }) => - getVersionControlQueryClient({ - cosmWasmClient, - ...parameters, - ...extra, - }), - getAccountQueryClient: ({ extra, ...parameters }) => - getAccountQueryClient({ - cosmWasmClient, - ...parameters, - ...extra, - }), getRemoteHosts: ({ extra, ...parameters } = {}) => getRemoteHostsFromApi({ cosmWasmClient, @@ -203,10 +116,6 @@ export function publicActions( ...parameters, ...extra, }), - getCosmWasmClient: () => - getCosmWasmClient({ - cosmWasmClient, - }), getSimulationResult: ({ extra, ...parameters }) => getSimulationResultFromApi({ cosmWasmClient, diff --git a/packages/core/src/clients/index.ts b/packages/core/src/clients/index.ts index 6525dfa8..4ef65dd1 100644 --- a/packages/core/src/clients/index.ts +++ b/packages/core/src/clients/index.ts @@ -3,4 +3,5 @@ export * from './create-account-wallet-client' export * from './create-public-client' export * from './create-wallet-client' export * from './create-api-client' +export * from './create-abstract-base-client' export * from './create-client'