Skip to content

Expose ICA Client retrieval #138

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

Merged
merged 3 commits into from
Nov 1, 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
6 changes: 6 additions & 0 deletions .changeset/angry-sloths-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@abstract-money/core": minor
"@abstract-money/react": minor
---

Expose the ICA Client
12 changes: 8 additions & 4 deletions packages/core/abstract.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +22,7 @@ export async function getIbcClientQueryClientFromAccount({
accountId,
cosmWasmClient,
apiUrl,
}: GetIbcClientQueryClientParameters) {
}: GetIbcClientQueryClientFromAccountParameters) {
const ibcClientAddress = await getModuleAddress({
accountId,
cosmWasmClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -46,7 +46,7 @@ export async function simulateExecuteRemoteAccount({
[],
)

return simulateRemoteMsg({
return simulateRemoteCosmosMsg({
apiUrl,
hostChainName,
msgs: cosmosAccountMsg,
Expand Down
13 changes: 2 additions & 11 deletions packages/core/src/actions/account/wallet/execute.ts
Original file line number Diff line number Diff line change
@@ -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 & {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
})
}
Original file line number Diff line number Diff line change
@@ -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 })
}
15 changes: 15 additions & 0 deletions packages/core/src/actions/public/get-ica-client-query-client.ts
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions packages/core/src/actions/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountTypes.CosmosMsgForEmpty>
Expand All @@ -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,
Expand Down
33 changes: 23 additions & 10 deletions packages/core/src/clients/decorators/abstract-base.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -34,16 +35,6 @@ export type AbstractBaseActions = {
typeof getAnsHostQueryClient
>,
): ReturnType<typeof getAnsHostQueryClient>
getIbcClientQueryClient(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof getIbcClientQueryClient
>,
): ReturnType<typeof getIbcClientQueryClient>
getAbstractModuleAddressFromRegistry(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof getAbstractModuleAddressFromRegistry
>,
): ReturnType<typeof getAbstractModuleAddressFromRegistry>
getAnsHostAddressFromRegistry(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof getAnsHostAddressFromRegistry
Expand All @@ -54,6 +45,22 @@ export type AbstractBaseActions = {
typeof getAnsHostQueryClientFromRegistry
>,
): ReturnType<typeof getAnsHostQueryClientFromRegistry>
getIbcClientQueryClient(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof getIbcClientQueryClient
>,
): ReturnType<typeof getIbcClientQueryClient>
getIcaClientQueryClient(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof getIcaClientQueryClient
>,
): ReturnType<typeof getIcaClientQueryClient>
getAbstractModuleAddressFromRegistry(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof getAbstractModuleAddressFromRegistry
>,
): ReturnType<typeof getAbstractModuleAddressFromRegistry>

getRegistryModuleData(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof getRegistryModuleData
Expand Down Expand Up @@ -94,6 +101,12 @@ export function abstractBaseActions(
...parameters,
...extra,
}),
getIcaClientQueryClient: ({ extra, ...parameters }) =>
getIcaClientQueryClient({
cosmWasmClient,
...parameters,
...extra,
}),
getAbstractModuleAddressFromRegistry: ({ extra, ...parameters }) =>
getAbstractModuleAddressFromRegistry({
cosmWasmClient,
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/clients/decorators/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -62,11 +62,11 @@ export type PublicActions = {
typeof getSimulationResultFromApi
>,
): ReturnType<typeof getSimulationResultFromApi>
simulateRemoteMsg(
simulateRemoteCosmosMsg(
parameters: ExtractAndPartializeDecoratedParametersFromParameters<
typeof simulateRemoteMsg
typeof simulateRemoteCosmosMsg
>,
): ReturnType<typeof simulateRemoteMsg>
): ReturnType<typeof simulateRemoteCosmosMsg>
}

export function publicActions(
Expand Down Expand Up @@ -123,8 +123,8 @@ export function publicActions(
...parameters,
...extra,
}),
simulateRemoteMsg: ({ extra, ...parameters }) =>
simulateRemoteMsg({
simulateRemoteCosmosMsg: ({ extra, ...parameters }) =>
simulateRemoteCosmosMsg({
cosmWasmClient,
apiUrl,
...parameters,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/cosmos/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './encoding'
export * from './simulate-msgs'
export * from './simulate-cosmos-msgs'
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { StargateClient } from '@abstract-money/cli/.tsup/declaration/_tsup-dts-aggregation'
import { Registry } from '@cosmjs/proto-signing'
import {
QueryClient,
Expand Down
14 changes: 9 additions & 5 deletions packages/react/src/hooks/public/use-simulate-remote-msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import {
UseMutationReturnType,
} from '../../types/queries'

type SimulateRemoteMutation = Parameters<PublicClient['simulateRemoteMsg']>[0]
type SimulateRemoteMutation = Parameters<
PublicClient['simulateRemoteCosmosMsg']
>[0]

export type UseSimulateRemoteMsgParameters = {
chainName: string | undefined
mutation?: UseMutationParameters<
Awaited<ReturnType<PublicClient['simulateRemoteMsg']>>,
Awaited<ReturnType<PublicClient['simulateRemoteCosmosMsg']>>,
unknown,
SimulateRemoteMutation
>
}

type SimulatedReturn = Awaited<ReturnType<PublicClient['simulateRemoteMsg']>>
type SimulatedReturn = Awaited<
ReturnType<PublicClient['simulateRemoteCosmosMsg']>
>

/**
* Simulate a message to be executed on a remote chain by the ibc host.
Expand All @@ -38,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,
})
},
Expand Down
Loading