diff --git a/packages/cosmwasm/src/cosmosmsg.ts b/packages/cosmwasm/src/cosmosmsg.ts new file mode 100644 index 00000000..7cfc74c3 --- /dev/null +++ b/packages/cosmwasm/src/cosmosmsg.ts @@ -0,0 +1,77 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { Coin } from "@cosmjs/launchpad"; + +interface BankSendMsg { + readonly send: { + readonly from_address: string; + readonly to_address: string; + readonly amount: readonly Coin[]; + }; +} + +export interface BankMsg { + readonly bank: BankSendMsg; +} + +export interface CustomMsg { + readonly custom: Record; +} + +interface StakingDelegateMsg { + readonly delegate: { + readonly validator: string; + readonly amount: Coin; + }; +} + +interface StakingRedelegateMsg { + readonly redelgate: { + readonly src_validator: string; + readonly dst_validator: string; + readonly amount: Coin; + }; +} + +interface StakingUndelegateMsg { + readonly undelegate: { + readonly validator: string; + readonly amount: Coin; + }; +} + +interface StakingWithdrawMsg { + readonly withdraw: { + readonly validator: string; + readonly recipient?: string; + }; +} + +export interface StakingMsg { + readonly staking: StakingDelegateMsg | StakingRedelegateMsg | StakingUndelegateMsg | StakingWithdrawMsg; +} + +interface WasmExecuteMsg { + readonly execute: { + readonly contract_address: string; + readonly msg: any; + readonly send: readonly Coin[]; + }; +} + +interface WasmInstantiateMsg { + readonly instantiate: { + readonly code_id: string; + readonly msg: any; + readonly send: readonly Coin[]; + readonly label?: string; + }; +} + +export interface WasmMsg { + readonly wasm: WasmExecuteMsg | WasmInstantiateMsg; +} + +/** These definitions are derived from CosmWasm: + * https://github.com/CosmWasm/cosmwasm/blob/v0.12.0/packages/std/src/results/cosmos_msg.rs#L10-L23 + */ +export type CosmosMsg = BankMsg | CustomMsg | StakingMsg | WasmMsg; diff --git a/packages/cosmwasm/src/cw3cosmwasmclient.ts b/packages/cosmwasm/src/cw3cosmwasmclient.ts index 4a8e3879..933c9574 100644 --- a/packages/cosmwasm/src/cw3cosmwasmclient.ts +++ b/packages/cosmwasm/src/cw3cosmwasmclient.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad"; +import { CosmosMsg } from "./cosmosmsg"; import { Account } from "./cosmwasmclient"; import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient"; @@ -30,7 +31,7 @@ export interface ProposalResult { readonly id: number; readonly title: string; readonly description: string; - readonly msgs: ReadonlyArray>; + readonly msgs: readonly CosmosMsg[]; readonly expires: Expiration; readonly status: string; } @@ -163,7 +164,7 @@ export class Cw3CosmWasmClient extends SigningCosmWasmClient { public createMultisigProposal( title: string, description: string, - msgs: ReadonlyArray>, + msgs: readonly CosmosMsg[], earliest?: Expiration, latest?: Expiration, memo = "", diff --git a/packages/cosmwasm/src/index.ts b/packages/cosmwasm/src/index.ts index 7bc9232b..b90bf610 100644 --- a/packages/cosmwasm/src/index.ts +++ b/packages/cosmwasm/src/index.ts @@ -1,4 +1,5 @@ export { setupWasmExtension, WasmExtension } from "./lcdapi/wasm"; +export { BankMsg, CosmosMsg, CustomMsg, StakingMsg, WasmMsg } from "./cosmosmsg"; export { Account, Block, diff --git a/packages/cosmwasm/types/cosmosmsg.d.ts b/packages/cosmwasm/types/cosmosmsg.d.ts new file mode 100644 index 00000000..82b225ba --- /dev/null +++ b/packages/cosmwasm/types/cosmosmsg.d.ts @@ -0,0 +1,65 @@ +import { Coin } from "@cosmjs/launchpad"; +interface BankSendMsg { + readonly send: { + readonly from_address: string; + readonly to_address: string; + readonly amount: readonly Coin[]; + }; +} +export interface BankMsg { + readonly bank: BankSendMsg; +} +export interface CustomMsg { + readonly custom: Record; +} +interface StakingDelegateMsg { + readonly delegate: { + readonly validator: string; + readonly amount: Coin; + }; +} +interface StakingRedelegateMsg { + readonly redelgate: { + readonly src_validator: string; + readonly dst_validator: string; + readonly amount: Coin; + }; +} +interface StakingUndelegateMsg { + readonly undelegate: { + readonly validator: string; + readonly amount: Coin; + }; +} +interface StakingWithdrawMsg { + readonly withdraw: { + readonly validator: string; + readonly recipient?: string; + }; +} +export interface StakingMsg { + readonly staking: StakingDelegateMsg | StakingRedelegateMsg | StakingUndelegateMsg | StakingWithdrawMsg; +} +interface WasmExecuteMsg { + readonly execute: { + readonly contract_address: string; + readonly msg: any; + readonly send: readonly Coin[]; + }; +} +interface WasmInstantiateMsg { + readonly instantiate: { + readonly code_id: string; + readonly msg: any; + readonly send: readonly Coin[]; + readonly label?: string; + }; +} +export interface WasmMsg { + readonly wasm: WasmExecuteMsg | WasmInstantiateMsg; +} +/** These definitions are derived from CosmWasm: + * https://github.com/CosmWasm/cosmwasm/blob/v0.12.0/packages/std/src/results/cosmos_msg.rs#L10-L23 + */ +export declare type CosmosMsg = BankMsg | CustomMsg | StakingMsg | WasmMsg; +export {}; diff --git a/packages/cosmwasm/types/cw3cosmwasmclient.d.ts b/packages/cosmwasm/types/cw3cosmwasmclient.d.ts index b2391227..80ff14fc 100644 --- a/packages/cosmwasm/types/cw3cosmwasmclient.d.ts +++ b/packages/cosmwasm/types/cw3cosmwasmclient.d.ts @@ -1,4 +1,5 @@ import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad"; +import { CosmosMsg } from "./cosmosmsg"; import { Account } from "./cosmwasmclient"; import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient"; export declare type Expiration = @@ -24,7 +25,7 @@ export interface ProposalResult { readonly id: number; readonly title: string; readonly description: string; - readonly msgs: ReadonlyArray>; + readonly msgs: readonly CosmosMsg[]; readonly expires: Expiration; readonly status: string; } @@ -86,7 +87,7 @@ export declare class Cw3CosmWasmClient extends SigningCosmWasmClient { createMultisigProposal( title: string, description: string, - msgs: ReadonlyArray>, + msgs: readonly CosmosMsg[], earliest?: Expiration, latest?: Expiration, memo?: string, diff --git a/packages/cosmwasm/types/index.d.ts b/packages/cosmwasm/types/index.d.ts index 7bc9232b..b90bf610 100644 --- a/packages/cosmwasm/types/index.d.ts +++ b/packages/cosmwasm/types/index.d.ts @@ -1,4 +1,5 @@ export { setupWasmExtension, WasmExtension } from "./lcdapi/wasm"; +export { BankMsg, CosmosMsg, CustomMsg, StakingMsg, WasmMsg } from "./cosmosmsg"; export { Account, Block,