diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index 46ff1524..6cc493a1 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -91,6 +91,18 @@ describe("SigningCosmWasmClient", () => { amount: coins(251200, "utest"), gas: "80000", }, + delegate: { + amount: coins(502400, "utest"), + gas: "160000", + }, + undelegate: { + amount: coins(502400, "utest"), + gas: "160000", + }, + withdraw: { + amount: coins(502400, "utest"), + gas: "160000", + }, }); }); @@ -130,6 +142,18 @@ describe("SigningCosmWasmClient", () => { amount: coins(2000, "ucosm"), gas: "80000", }, + delegate: { + amount: coins(4000, "ucosm"), + gas: "160000", + }, + undelegate: { + amount: coins(4000, "ucosm"), + gas: "160000", + }, + withdraw: { + amount: coins(4000, "ucosm"), + gas: "160000", + }, }); }); @@ -170,6 +194,18 @@ describe("SigningCosmWasmClient", () => { amount: coins(251200, "utest"), gas: "80000", }, + delegate: { + amount: coins(502400, "utest"), + gas: "160000", + }, + undelegate: { + amount: coins(502400, "utest"), + gas: "160000", + }, + withdraw: { + amount: coins(502400, "utest"), + gas: "160000", + }, }); }); }); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 26ea525c..02b0c765 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -38,6 +38,8 @@ import { logs, StdFee, } from "@cosmjs/stargate"; +import { MsgWithdrawDelegatorReward } from "@cosmjs/stargate/build/codec/cosmos/distribution/v1beta1/tx"; +import { MsgDelegate, MsgUndelegate } from "@cosmjs/stargate/build/codec/cosmos/staking/v1beta1/tx"; import { SignMode } from "@cosmjs/stargate/build/codec/cosmos/tx/signing/v1beta1/signing"; import { TxRaw } from "@cosmjs/stargate/build/codec/cosmos/tx/v1beta1/tx"; import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; @@ -332,6 +334,44 @@ export class SigningCosmWasmClient extends CosmWasmClient { return this.signAndBroadcast(senderAddress, [sendMsg], this.fees.send, memo); } + public async delegateTokens( + delegatorAddress: string, + validatorAddress: string, + amount: Coin, + memo = "", + ): Promise { + const delegateMsg = { + typeUrl: "/cosmos.staking.v1beta1.MsgDelegate", + value: MsgDelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }), + }; + return this.signAndBroadcast(delegatorAddress, [delegateMsg], this.fees.delegate, memo); + } + + public async undelegateTokens( + delegatorAddress: string, + validatorAddress: string, + amount: Coin, + memo = "", + ): Promise { + const undelegateMsg = { + typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate", + value: MsgUndelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }), + }; + return this.signAndBroadcast(delegatorAddress, [undelegateMsg], this.fees.undelegate, memo); + } + + public async withdrawRewards( + delegatorAddress: string, + validatorAddress: string, + memo = "", + ): Promise { + const withdrawMsg = { + typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", + value: MsgWithdrawDelegatorReward.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress }), + }; + return this.signAndBroadcast(delegatorAddress, [withdrawMsg], this.fees.withdraw, memo); + } + /** * Creates a transaction with the given messages, fee and memo. Then signs and broadcasts the transaction. *