Skip to content

Add polytone simulation #167

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 2 commits into from
Jan 31, 2025
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
5 changes: 5 additions & 0 deletions .changeset/famous-llamas-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@abstract-money/core": patch
---

Add polytone simulation
2 changes: 1 addition & 1 deletion packages/core/src/actions/account/public/query-module.ts
Original file line number Diff line number Diff line change
@@ -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<
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/clients/decorators/abstract-base.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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'
import { getAnsHostQueryClient } from '../../actions/public/get-ans-host-query-client'
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'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/clients/decorators/account-public.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/polytone/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './predict-proxy-address'
export * from './predict-polytone-proxy-address'
export * from './simulate-polytone-voice-cosmos-msgs'
Original file line number Diff line number Diff line change
@@ -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<AccountTypes.CosmosMsgForEmpty>
}

/**
* 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,
)
}
Loading