From aaaf7fcf6e5ca1cadcd8cf79007688ba2737a3d9 Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Thu, 31 Oct 2024 19:10:36 -0400 Subject: [PATCH 1/3] Add ica-client client and address query methods --- packages/core/abstract.config.ts | 12 ++++++---- ...et-ibc-client-query-client-from-account.ts | 4 ++-- .../public/simulate-execute-remote-account.ts | 4 ++-- .../src/actions/account/wallet/execute.ts | 13 ++--------- packages/core/src/actions/index.ts | 6 +++++ .../get-ica-client-address-from-registry.ts | 21 +++++++++++++++++ ...t-ica-client-query-client-from-registry.ts | 23 +++++++++++++++++++ .../public/get-ica-client-query-client.ts | 15 ++++++++++++ packages/core/src/actions/public/types.ts | 1 + ...e-msg.ts => simulate-remote-cosmos-msg.ts} | 6 ++--- .../core/src/clients/decorators/public.ts | 8 +++---- .../hooks/public/use-simulate-remote-msg.ts | 10 +++++--- 12 files changed, 94 insertions(+), 29 deletions(-) create mode 100644 packages/core/src/actions/public/get-ica-client-address-from-registry.ts create mode 100644 packages/core/src/actions/public/get-ica-client-query-client-from-registry.ts create mode 100644 packages/core/src/actions/public/get-ica-client-query-client.ts rename packages/core/src/actions/{simulate-remote-msg.ts => simulate-remote-cosmos-msg.ts} (91%) diff --git a/packages/core/abstract.config.ts b/packages/core/abstract.config.ts index 6ca5a523..3fc5fef9 100644 --- a/packages/core/abstract.config.ts +++ b/packages/core/abstract.config.ts @@ -4,19 +4,23 @@ import { registry, vanilla } from '@abstract-money/cli/plugins' const contractsConfig = [ { name: 'account', - version: '0.24.1-beta.2', + version: '0.24.1', }, { name: 'registry', - version: '0.24.1-beta.2', + version: '0.24.1', }, { name: 'ans-host', - version: '0.24.1-beta.2', + version: '0.24.1', }, { name: 'ibc-client', - version: '0.24.1-beta.2', + version: '0.24.1', + }, + { + name: 'ica-client', + version: '0.24.1', }, ] diff --git a/packages/core/src/actions/account/public/get-ibc-client-query-client-from-account.ts b/packages/core/src/actions/account/public/get-ibc-client-query-client-from-account.ts index 0ff9817c..e7a59e89 100644 --- a/packages/core/src/actions/account/public/get-ibc-client-query-client-from-account.ts +++ b/packages/core/src/actions/account/public/get-ibc-client-query-client-from-account.ts @@ -5,7 +5,7 @@ import { getIbcClientQueryClient } from '../../public/get-ibc-client-query-clien import { CommonModuleNames } from '../../public/types' import { getModuleAddress } from './get-module-address' -export type GetIbcClientQueryClientParameters = { +export type GetIbcClientQueryClientFromAccountParameters = { accountId: RegistryTypes.AccountId cosmWasmClient: CosmWasmClient apiUrl: string @@ -22,7 +22,7 @@ export async function getIbcClientQueryClientFromAccount({ accountId, cosmWasmClient, apiUrl, -}: GetIbcClientQueryClientParameters) { +}: GetIbcClientQueryClientFromAccountParameters) { const ibcClientAddress = await getModuleAddress({ accountId, cosmWasmClient, diff --git a/packages/core/src/actions/account/public/simulate-execute-remote-account.ts b/packages/core/src/actions/account/public/simulate-execute-remote-account.ts index e7ea02d6..b4e1ea28 100644 --- a/packages/core/src/actions/account/public/simulate-execute-remote-account.ts +++ b/packages/core/src/actions/account/public/simulate-execute-remote-account.ts @@ -2,7 +2,7 @@ import { cosmosWasmExecuteMsg } from '@abstract-money/core' import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' import { AccountTypes, RegistryTypes } from '../../../codegen/abstract' import { CosmosMsgForEmpty } from '../../../codegen/abstract/cosmwasm-codegen/Account.types' -import { simulateRemoteMsg } from '../../simulate-remote-msg' +import { simulateRemoteCosmosMsg } from '../../simulate-remote-cosmos-msg' import { getRemoteAccounts } from './get-remote-accounts' export type SimulateExecuteRemoteAccountParameters = { @@ -46,7 +46,7 @@ export async function simulateExecuteRemoteAccount({ [], ) - return simulateRemoteMsg({ + return simulateRemoteCosmosMsg({ apiUrl, hostChainName, msgs: cosmosAccountMsg, diff --git a/packages/core/src/actions/account/wallet/execute.ts b/packages/core/src/actions/account/wallet/execute.ts index 49dfc46d..8c5015af 100644 --- a/packages/core/src/actions/account/wallet/execute.ts +++ b/packages/core/src/actions/account/wallet/execute.ts @@ -1,22 +1,13 @@ -import { - AccountExecuteMsgBuilder, - AccountMsgComposer, - AccountTypes, -} from '../../../codegen/abstract' -import { ModuleType } from '../../../codegen/gql/graphql' +import { AccountTypes } from '../../../codegen/abstract' import { MaybeArray } from '../../../types/utils' -import { executeOnModule } from './execute-on-module' import { BaseAccountWalletParameters } from './types' -import { AccountId } from '@abstract-money/core' import { toUtf8 } from '@cosmjs/encoding' import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx' import { CosmosMsgForEmpty } from '../../../codegen/abstract/cosmwasm-codegen/Account.types' import { WithCosmWasmSignOptions } from '../../../types/parameters' -import { abstractModuleId } from '../../../utils/modules/abstract-module-id' -import { encodeModuleMsg } from '../../../utils/modules/encode-module-msg' -import { CommonModuleNames } from '../../public/types' import { getAccountAddressFromApi } from '../public/get-account-address-from-api' + export type ExecuteParameters = Omit< WithCosmWasmSignOptions< BaseAccountWalletParameters & { diff --git a/packages/core/src/actions/index.ts b/packages/core/src/actions/index.ts index 578dcdc7..76641fe4 100644 --- a/packages/core/src/actions/index.ts +++ b/packages/core/src/actions/index.ts @@ -36,6 +36,12 @@ export * from './public/get-ans-host-address-from-registry' export * from './public/get-ans-host-query-client-from-api' export * from './public/get-ans-host-query-client-from-registry' export * from './public/get-ans-host-query-client' +export * from './public/get-ibc-client-query-client-from-registry' +export * from './public/get-ibc-client-address-from-registry' +export * from './public/get-ibc-client-query-client' +export * from './public/get-ica-client-query-client-from-registry' +export * from './public/get-ica-client-address-from-registry' +export * from './public/get-ica-client-query-client' export * from './public/get-ans-host-version-from-api' export * from './public/get-app-module-code-id-from-registry' export * from './public/get-cosm-wasm-client' diff --git a/packages/core/src/actions/public/get-ica-client-address-from-registry.ts b/packages/core/src/actions/public/get-ica-client-address-from-registry.ts new file mode 100644 index 00000000..a927c23f --- /dev/null +++ b/packages/core/src/actions/public/get-ica-client-address-from-registry.ts @@ -0,0 +1,21 @@ +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { getAbstractModuleAddressFromRegistry } from './get-abstract-module-address-from-registry' +import { CommonModuleNames } from './types' + +export type GetIcaClientAddressFromRegistryParameters = { + cosmWasmClient: CosmWasmClient + registryAddress: string + version?: string +} +export async function getIcaClientAddressFromRegistry({ + cosmWasmClient, + registryAddress, + version, +}: GetIcaClientAddressFromRegistryParameters) { + return getAbstractModuleAddressFromRegistry({ + moduleName: CommonModuleNames.ICA_CLIENT, + cosmWasmClient, + registryAddress, + version, + }) +} diff --git a/packages/core/src/actions/public/get-ica-client-query-client-from-registry.ts b/packages/core/src/actions/public/get-ica-client-query-client-from-registry.ts new file mode 100644 index 00000000..5cc42996 --- /dev/null +++ b/packages/core/src/actions/public/get-ica-client-query-client-from-registry.ts @@ -0,0 +1,23 @@ +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { getIcaClientAddressFromRegistry } from './get-ica-client-address-from-registry' +import { getIcaClientQueryClient } from './get-ica-client-query-client' + +export type GetIcaClientQueryClientFromRegistryParameters = { + cosmWasmClient: CosmWasmClient + registryAddress: string + version?: string +} + +export async function getIcaClientQueryClientFromRegistry({ + cosmWasmClient, + registryAddress, + version, +}: GetIcaClientQueryClientFromRegistryParameters) { + const icaClientAddress = await getIcaClientAddressFromRegistry({ + cosmWasmClient, + registryAddress, + version, + }) + + return getIcaClientQueryClient({ cosmWasmClient, icaClientAddress }) +} diff --git a/packages/core/src/actions/public/get-ica-client-query-client.ts b/packages/core/src/actions/public/get-ica-client-query-client.ts new file mode 100644 index 00000000..4ca175cf --- /dev/null +++ b/packages/core/src/actions/public/get-ica-client-query-client.ts @@ -0,0 +1,15 @@ +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' + +import { IcaClientQueryClient } from '../../codegen/abstract' + +export type GetIcaClientQueryClientParameters = { + cosmWasmClient: CosmWasmClient + icaClientAddress: string +} + +export function getIcaClientQueryClient({ + cosmWasmClient, + icaClientAddress, +}: GetIcaClientQueryClientParameters) { + return new IcaClientQueryClient(cosmWasmClient, icaClientAddress) +} diff --git a/packages/core/src/actions/public/types.ts b/packages/core/src/actions/public/types.ts index b5f1280a..a699b520 100644 --- a/packages/core/src/actions/public/types.ts +++ b/packages/core/src/actions/public/types.ts @@ -3,5 +3,6 @@ export enum CommonModuleNames { MODULE_FACTORY = 'module-factory', ANS_HOST = 'ans-host', IBC_CLIENT = 'ibc-client', + ICA_CLIENT = 'ica-client', IBC_HOST = 'ibc-host', } diff --git a/packages/core/src/actions/simulate-remote-msg.ts b/packages/core/src/actions/simulate-remote-cosmos-msg.ts similarity index 91% rename from packages/core/src/actions/simulate-remote-msg.ts rename to packages/core/src/actions/simulate-remote-cosmos-msg.ts index d8960922..2ffaebbe 100644 --- a/packages/core/src/actions/simulate-remote-msg.ts +++ b/packages/core/src/actions/simulate-remote-cosmos-msg.ts @@ -6,7 +6,7 @@ import { getCometClientFromApi } from './get-comet-client-from-api' import { getRegistryAddressFromApi } from './get-registry-address-from-api' import { getIbcHostAddressFromRegistry } from './public/get-ibc-host-address-from-registry' -export type SimulateRemoteMsgParameters = { +export type SimulateRemoteCosmosMsgParameters = { apiUrl: string hostChainName: string msgs: MaybeArray @@ -21,11 +21,11 @@ export type SimulateRemoteMsgParameters = { * @param msgs * @experimental */ -export async function simulateRemoteMsg({ +export async function simulateRemoteCosmosMsg({ apiUrl, hostChainName, msgs, -}: SimulateRemoteMsgParameters) { +}: SimulateRemoteCosmosMsgParameters) { // TODO: these queries could be combined const remoteVcAddress = await getRegistryAddressFromApi({ apiUrl, diff --git a/packages/core/src/clients/decorators/public.ts b/packages/core/src/clients/decorators/public.ts index e482c899..102395c3 100644 --- a/packages/core/src/clients/decorators/public.ts +++ b/packages/core/src/clients/decorators/public.ts @@ -15,7 +15,7 @@ import { getRegistryModuleData } from '../../actions/public/get-registry-module- import { getRegistryQueryClient } from '../../actions/public/get-registry-query-client' import { getRegistryQueryClientFromApi } from '../../actions/public/get-registry-query-client-from-api' import { getRemoteHostsFromApi } from '../../actions/public/get-remote-hosts-from-api' -import { simulateRemoteMsg } from '../../actions/simulate-remote-msg' +import { simulateRemoteCosmosMsg } from '../../actions/simulate-remote-cosmos-msg' import { ExtractAndPartializeParameters } from '../../types/parameters' type ExtractAndPartializeDecoratedParametersFromParameters< @@ -64,9 +64,9 @@ export type PublicActions = { ): ReturnType simulateRemoteMsg( parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof simulateRemoteMsg + typeof simulateRemoteCosmosMsg >, - ): ReturnType + ): ReturnType } export function publicActions( @@ -124,7 +124,7 @@ export function publicActions( ...extra, }), simulateRemoteMsg: ({ extra, ...parameters }) => - simulateRemoteMsg({ + simulateRemoteCosmosMsg({ cosmWasmClient, apiUrl, ...parameters, diff --git a/packages/react/src/hooks/public/use-simulate-remote-msg.ts b/packages/react/src/hooks/public/use-simulate-remote-msg.ts index d34e55ef..8fb8870c 100644 --- a/packages/react/src/hooks/public/use-simulate-remote-msg.ts +++ b/packages/react/src/hooks/public/use-simulate-remote-msg.ts @@ -6,18 +6,22 @@ import { UseMutationReturnType, } from '../../types/queries' -type SimulateRemoteMutation = Parameters[0] +type SimulateRemoteMutation = Parameters< + PublicClient['simulateRemoteCosmosMsg'] +>[0] export type UseSimulateRemoteMsgParameters = { chainName: string | undefined mutation?: UseMutationParameters< - Awaited>, + Awaited>, unknown, SimulateRemoteMutation > } -type SimulatedReturn = Awaited> +type SimulatedReturn = Awaited< + ReturnType +> /** * Simulate a message to be executed on a remote chain by the ibc host. From 16ddab9a4a8ed4e633972668e40516b7c45a2d2b Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Thu, 31 Oct 2024 19:37:04 -0400 Subject: [PATCH 2/3] Expose the ica client --- .../actions/get-simulation-result-from-api.ts | 2 +- .../src/clients/decorators/abstract-base.ts | 33 +++++++++++++------ .../core/src/clients/decorators/public.ts | 4 +-- packages/core/src/utils/cosmos/index.ts | 2 +- ...mulate-msgs.ts => simulate-cosmos-msgs.ts} | 1 - .../hooks/public/use-simulate-remote-msg.ts | 4 +-- 6 files changed, 29 insertions(+), 17 deletions(-) rename packages/core/src/utils/cosmos/{simulate-msgs.ts => simulate-cosmos-msgs.ts} (96%) diff --git a/packages/core/src/actions/get-simulation-result-from-api.ts b/packages/core/src/actions/get-simulation-result-from-api.ts index a6f16293..205102f2 100644 --- a/packages/core/src/actions/get-simulation-result-from-api.ts +++ b/packages/core/src/actions/get-simulation-result-from-api.ts @@ -1,6 +1,6 @@ import { AccountTypes } from '../codegen/abstract' import { MaybeArray } from '../types/utils' -import { simulateWasmCosmosMsgs } from '../utils/cosmos' +import { simulateWasmCosmosMsgs } from '../utils/cosmos/simulate-cosmos-msgs' import { getCometClientFromApi } from './get-comet-client-from-api' export type GetSimulationResultParameters = { diff --git a/packages/core/src/clients/decorators/abstract-base.ts b/packages/core/src/clients/decorators/abstract-base.ts index f3b7e092..a07e5c7c 100644 --- a/packages/core/src/clients/decorators/abstract-base.ts +++ b/packages/core/src/clients/decorators/abstract-base.ts @@ -1,4 +1,5 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { getIcaClientQueryClient } from 'src/actions/public/get-ica-client-query-client' import { getAbstractModuleAddressFromRegistry } from '../../actions/public/get-abstract-module-address-from-registry' import { getAccountQueryClient } from '../../actions/public/get-account-query-client' import { getAnsHostAddressFromRegistry } from '../../actions/public/get-ans-host-address-from-registry' @@ -34,16 +35,6 @@ export type AbstractBaseActions = { typeof getAnsHostQueryClient >, ): ReturnType - getIbcClientQueryClient( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getIbcClientQueryClient - >, - ): ReturnType - getAbstractModuleAddressFromRegistry( - parameters: ExtractAndPartializeDecoratedParametersFromParameters< - typeof getAbstractModuleAddressFromRegistry - >, - ): ReturnType getAnsHostAddressFromRegistry( parameters: ExtractAndPartializeDecoratedParametersFromParameters< typeof getAnsHostAddressFromRegistry @@ -54,6 +45,22 @@ export type AbstractBaseActions = { typeof getAnsHostQueryClientFromRegistry >, ): ReturnType + getIbcClientQueryClient( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getIbcClientQueryClient + >, + ): ReturnType + getIcaClientQueryClient( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getIcaClientQueryClient + >, + ): ReturnType + getAbstractModuleAddressFromRegistry( + parameters: ExtractAndPartializeDecoratedParametersFromParameters< + typeof getAbstractModuleAddressFromRegistry + >, + ): ReturnType + getRegistryModuleData( parameters: ExtractAndPartializeDecoratedParametersFromParameters< typeof getRegistryModuleData @@ -94,6 +101,12 @@ export function abstractBaseActions( ...parameters, ...extra, }), + getIcaClientQueryClient: ({ extra, ...parameters }) => + getIcaClientQueryClient({ + cosmWasmClient, + ...parameters, + ...extra, + }), getAbstractModuleAddressFromRegistry: ({ extra, ...parameters }) => getAbstractModuleAddressFromRegistry({ cosmWasmClient, diff --git a/packages/core/src/clients/decorators/public.ts b/packages/core/src/clients/decorators/public.ts index 102395c3..bffd290d 100644 --- a/packages/core/src/clients/decorators/public.ts +++ b/packages/core/src/clients/decorators/public.ts @@ -62,7 +62,7 @@ export type PublicActions = { typeof getSimulationResultFromApi >, ): ReturnType - simulateRemoteMsg( + simulateRemoteCosmosMsg( parameters: ExtractAndPartializeDecoratedParametersFromParameters< typeof simulateRemoteCosmosMsg >, @@ -123,7 +123,7 @@ export function publicActions( ...parameters, ...extra, }), - simulateRemoteMsg: ({ extra, ...parameters }) => + simulateRemoteCosmosMsg: ({ extra, ...parameters }) => simulateRemoteCosmosMsg({ cosmWasmClient, apiUrl, diff --git a/packages/core/src/utils/cosmos/index.ts b/packages/core/src/utils/cosmos/index.ts index 00396feb..787ad0dd 100644 --- a/packages/core/src/utils/cosmos/index.ts +++ b/packages/core/src/utils/cosmos/index.ts @@ -1,2 +1,2 @@ export * from './encoding' -export * from './simulate-msgs' +export * from './simulate-cosmos-msgs' diff --git a/packages/core/src/utils/cosmos/simulate-msgs.ts b/packages/core/src/utils/cosmos/simulate-cosmos-msgs.ts similarity index 96% rename from packages/core/src/utils/cosmos/simulate-msgs.ts rename to packages/core/src/utils/cosmos/simulate-cosmos-msgs.ts index f50c8a7c..c9f08a51 100644 --- a/packages/core/src/utils/cosmos/simulate-msgs.ts +++ b/packages/core/src/utils/cosmos/simulate-cosmos-msgs.ts @@ -1,4 +1,3 @@ -import { StargateClient } from '@abstract-money/cli/.tsup/declaration/_tsup-dts-aggregation' import { Registry } from '@cosmjs/proto-signing' import { QueryClient, diff --git a/packages/react/src/hooks/public/use-simulate-remote-msg.ts b/packages/react/src/hooks/public/use-simulate-remote-msg.ts index 8fb8870c..06f31eaf 100644 --- a/packages/react/src/hooks/public/use-simulate-remote-msg.ts +++ b/packages/react/src/hooks/public/use-simulate-remote-msg.ts @@ -42,10 +42,10 @@ export function useSimulateRemoteMsg({ }) return useMutation( - ['simulateRemoteMsg', chainName], + ['simulateRemoteCosmosMsg', chainName], ({ ...params }) => { if (!accountClient) throw new Error('accountClient is not defined') - return accountClient.simulateRemoteMsg({ + return accountClient.simulateRemoteCosmosMsg({ ...params, }) }, From a45d7d0fb3fef37805231d5715a1d288c966be72 Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Thu, 31 Oct 2024 19:37:42 -0400 Subject: [PATCH 3/3] Changeset --- .changeset/angry-sloths-cheer.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/angry-sloths-cheer.md diff --git a/.changeset/angry-sloths-cheer.md b/.changeset/angry-sloths-cheer.md new file mode 100644 index 00000000..b592506f --- /dev/null +++ b/.changeset/angry-sloths-cheer.md @@ -0,0 +1,6 @@ +--- +"@abstract-money/core": minor +"@abstract-money/react": minor +--- + +Expose the ICA Client