cosmwasm-stargate: Add SigningCosmWasmClient staking methods
This commit is contained in:
parent
4d486a6307
commit
c99dcfc50a
@ -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",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -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<BroadcastTxResponse> {
|
||||
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<BroadcastTxResponse> {
|
||||
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<BroadcastTxResponse> {
|
||||
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.
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user