From 794d87a2658a7dedbca3c44d7db787b78dbc9a8f Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 17 Nov 2020 13:51:31 +0100 Subject: [PATCH] cosmwasm: Add Cw3CosmWasmClient class --- packages/cosmwasm/src/cw3cosmwasmclient.ts | 76 +++++++++++++++++++ .../cosmwasm/types/cw3cosmwasmclient.d.ts | 38 ++++++++++ 2 files changed, 114 insertions(+) create mode 100644 packages/cosmwasm/src/cw3cosmwasmclient.ts create mode 100644 packages/cosmwasm/types/cw3cosmwasmclient.d.ts diff --git a/packages/cosmwasm/src/cw3cosmwasmclient.ts b/packages/cosmwasm/src/cw3cosmwasmclient.ts new file mode 100644 index 00000000..5252ed50 --- /dev/null +++ b/packages/cosmwasm/src/cw3cosmwasmclient.ts @@ -0,0 +1,76 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad"; + +import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient"; + +export type Expiration = + | { + readonly at_height: number; + } + | { + readonly at_time: number; + }; + +export enum Vote { + Yes = "yes", + No = "no", + Abstain = "abstain", + Veto = "veto", +} + +export class Cw3CosmWasmClient extends SigningCosmWasmClient { + private readonly cw3ContractAddress: string; + + public constructor( + apiUrl: string, + senderAddress: string, + signer: OfflineSigner, + cw3ContractAddress: string, + gasPrice?: GasPrice, + gasLimits?: Partial>, + broadcastMode?: BroadcastMode, + ) { + super(apiUrl, senderAddress, signer, gasPrice, gasLimits, broadcastMode); + this.cw3ContractAddress = cw3ContractAddress; + } + + public createMultisigProposal( + title: string, + description: string, + msgs: ReadonlyArray>, + earliest?: Expiration, + latest?: Expiration, + memo = "", + ): Promise { + const handleMsg = { + propose: { + title: title, + description: description, + msgs: msgs, + earliest: earliest, + latest: latest, + }, + }; + return this.execute(this.cw3ContractAddress, handleMsg, memo); + } + + public voteMultisigProposal(proposalId: number, vote: Vote, memo = ""): Promise { + const handleMsg = { + vote: { + proposal_id: proposalId, + vote: vote, + }, + }; + return this.execute(this.cw3ContractAddress, handleMsg, memo); + } + + public executeMultisigProposal(proposalId: number, memo = ""): Promise { + const handleMsg = { execute: { proposal_id: proposalId } }; + return this.execute(this.cw3ContractAddress, handleMsg, memo); + } + + public closeMultisigProposal(proposalId: number, memo = ""): Promise { + const handleMsg = { close: { proposal_id: proposalId } }; + return this.execute(this.cw3ContractAddress, handleMsg, memo); + } +} diff --git a/packages/cosmwasm/types/cw3cosmwasmclient.d.ts b/packages/cosmwasm/types/cw3cosmwasmclient.d.ts new file mode 100644 index 00000000..c30b639b --- /dev/null +++ b/packages/cosmwasm/types/cw3cosmwasmclient.d.ts @@ -0,0 +1,38 @@ +import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad"; +import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient"; +export declare type Expiration = + | { + readonly at_height: number; + } + | { + readonly at_time: number; + }; +export declare enum Vote { + Yes = "yes", + No = "no", + Abstain = "abstain", + Veto = "veto", +} +export declare class Cw3CosmWasmClient extends SigningCosmWasmClient { + private readonly cw3ContractAddress; + constructor( + apiUrl: string, + senderAddress: string, + signer: OfflineSigner, + cw3ContractAddress: string, + gasPrice?: GasPrice, + gasLimits?: Partial>, + broadcastMode?: BroadcastMode, + ); + createMultisigProposal( + title: string, + description: string, + msgs: ReadonlyArray>, + earliest?: Expiration, + latest?: Expiration, + memo?: string, + ): Promise; + voteMultisigProposal(proposalId: number, vote: Vote, memo?: string): Promise; + executeMultisigProposal(proposalId: number, memo?: string): Promise; + closeMultisigProposal(proposalId: number, memo?: string): Promise; +}