From c56e627449440c90a94474227f2efdf8aafc6836 Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Fri, 31 Jan 2025 11:51:08 -0500 Subject: [PATCH 1/2] Add polytone simulation --- .../actions/account/public/query-module.ts | 2 +- .../src/clients/decorators/abstract-base.ts | 2 +- .../src/clients/decorators/account-public.ts | 2 +- packages/core/src/utils/polytone/index.ts | 3 +- ...=> predict-polytone-proxy-address.test.ts} | 0 ...s.ts => predict-polytone-proxy-address.ts} | 0 .../simulate-polytone-voice-cosmos-msgs.ts | 54 +++++++++++++++++++ 7 files changed, 59 insertions(+), 4 deletions(-) rename packages/core/src/utils/polytone/{predict-proxy-address.test.ts => predict-polytone-proxy-address.test.ts} (100%) rename packages/core/src/utils/polytone/{predict-proxy-address.ts => predict-polytone-proxy-address.ts} (100%) create mode 100644 packages/core/src/utils/polytone/simulate-polytone-voice-cosmos-msgs.ts diff --git a/packages/core/src/actions/account/public/query-module.ts b/packages/core/src/actions/account/public/query-module.ts index 95a70a71..5f15fcad 100644 --- a/packages/core/src/actions/account/public/query-module.ts +++ b/packages/core/src/actions/account/public/query-module.ts @@ -1,7 +1,7 @@ import { ContractMsg } from '@abstract-money/core' import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { ModuleType, wrapModuleQueryMsg } from 'src/utils/modules' import { RegistryTypes } from '../../../codegen/abstract' +import { ModuleType, wrapModuleQueryMsg } from '../../../utils/modules' import { getModuleAddress } from './get-module-address' export type QueryModuleParameters< diff --git a/packages/core/src/clients/decorators/abstract-base.ts b/packages/core/src/clients/decorators/abstract-base.ts index a07e5c7c..3e447cc4 100644 --- a/packages/core/src/clients/decorators/abstract-base.ts +++ b/packages/core/src/clients/decorators/abstract-base.ts @@ -1,5 +1,4 @@ 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' @@ -7,6 +6,7 @@ import { getAnsHostQueryClient } from '../../actions/public/get-ans-host-query-c import { getAnsHostQueryClientFromRegistry } from '../../actions/public/get-ans-host-query-client-from-registry' import { getCosmWasmClient } from '../../actions/public/get-cosm-wasm-client' import { getIbcClientQueryClient } from '../../actions/public/get-ibc-client-query-client' +import { getIcaClientQueryClient } from '../../actions/public/get-ica-client-query-client' import { getRegistryModuleData } from '../../actions/public/get-registry-module-data' import { getRegistryQueryClient } from '../../actions/public/get-registry-query-client' import { ExtractAndPartializeParameters } from '../../types/parameters' diff --git a/packages/core/src/clients/decorators/account-public.ts b/packages/core/src/clients/decorators/account-public.ts index 5fb51f84..0f72c682 100644 --- a/packages/core/src/clients/decorators/account-public.ts +++ b/packages/core/src/clients/decorators/account-public.ts @@ -1,6 +1,5 @@ import { ContractMsg } from '@abstract-money/core' import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' -import { queryModule } from 'src/actions/account/public/query-module' import { getAccountAddressFromApi } from '../../actions/account/public/get-account-address-from-api' import { getAccountId } from '../../actions/account/public/get-account-id' import { getAccountQueryClientFromApi } from '../../actions/account/public/get-account-query-client-from-api' @@ -15,6 +14,7 @@ import { getRemoteAccountIds } from '../../actions/account/public/get-remote-acc import { getRemoteAccounts } from '../../actions/account/public/get-remote-accounts' import { getSubAccountIds } from '../../actions/account/public/get-sub-account-ids' import { getSubAccountSequences } from '../../actions/account/public/get-sub-account-sequences' +import { queryModule } from '../../actions/account/public/query-module' import { simulateExecuteRemote } from '../../actions/account/public/simulate-execute-remote' import { simulateExecuteRemoteAccount } from '../../actions/account/public/simulate-execute-remote-account' import { RegistryTypes } from '../../codegen/abstract/index' diff --git a/packages/core/src/utils/polytone/index.ts b/packages/core/src/utils/polytone/index.ts index 8a220863..0e93c7e9 100644 --- a/packages/core/src/utils/polytone/index.ts +++ b/packages/core/src/utils/polytone/index.ts @@ -1 +1,2 @@ -export * from './predict-proxy-address' +export * from './predict-polytone-proxy-address' +export * from './simulate-polytone-voice-cosmos-msgs' diff --git a/packages/core/src/utils/polytone/predict-proxy-address.test.ts b/packages/core/src/utils/polytone/predict-polytone-proxy-address.test.ts similarity index 100% rename from packages/core/src/utils/polytone/predict-proxy-address.test.ts rename to packages/core/src/utils/polytone/predict-polytone-proxy-address.test.ts diff --git a/packages/core/src/utils/polytone/predict-proxy-address.ts b/packages/core/src/utils/polytone/predict-polytone-proxy-address.ts similarity index 100% rename from packages/core/src/utils/polytone/predict-proxy-address.ts rename to packages/core/src/utils/polytone/predict-polytone-proxy-address.ts diff --git a/packages/core/src/utils/polytone/simulate-polytone-voice-cosmos-msgs.ts b/packages/core/src/utils/polytone/simulate-polytone-voice-cosmos-msgs.ts new file mode 100644 index 00000000..5c249c56 --- /dev/null +++ b/packages/core/src/utils/polytone/simulate-polytone-voice-cosmos-msgs.ts @@ -0,0 +1,54 @@ +import { cosmosWasmExecuteMsg, jsonToBinary } from '@abstract-money/core' +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { AccountTypes } from '../../codegen/abstract' +import { MaybeArray } from '../../types/utils' +import { simulateWasmCosmosMsgs } from '../cosmos' + +export type SimulatePolytoneCosmosMsgParameters = { + hostCosmWasmClient: CosmWasmClient + controllerSender: string + controllerNoteAddress: string + hostVoiceAddress: string + hostVoiceConnectionId: `connection-${string}` + msgs: MaybeArray +} + +/** + * Simulate messages to be executed on a the host polytone voice chain. + * @param msgs + * @experimental + */ +export async function simulatePolytoneVoiceCosmosMsgs({ + hostCosmWasmClient, + hostVoiceAddress, + controllerNoteAddress, + controllerSender, + hostVoiceConnectionId, + msgs, +}: SimulatePolytoneCosmosMsgParameters) { + const voiceMsg = cosmosWasmExecuteMsg( + hostVoiceAddress, + { + rx: { + connection_id: hostVoiceConnectionId, + counterparty_port: `wasm.${controllerNoteAddress}`, + data: jsonToBinary({ + sender: controllerSender, + msg: { + execute: { + msgs: Array.isArray(msgs) ? msgs : [msgs], + }, + }, + }), + }, + }, + [], + ) + + return await simulateWasmCosmosMsgs( + // biome-ignore lint/complexity/useLiteralKeys: private + hostCosmWasmClient['cometClient'], + [voiceMsg], + hostVoiceAddress, + ) +} From bf492684b7839de8222643e226d0165514793134 Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Fri, 31 Jan 2025 11:51:50 -0500 Subject: [PATCH 2/2] Add polytone simulation --- .changeset/famous-llamas-sleep.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/famous-llamas-sleep.md diff --git a/.changeset/famous-llamas-sleep.md b/.changeset/famous-llamas-sleep.md new file mode 100644 index 00000000..41df1129 --- /dev/null +++ b/.changeset/famous-llamas-sleep.md @@ -0,0 +1,5 @@ +--- +"@abstract-money/core": patch +--- + +Add polytone simulation