From 4da00bac06eab160c5c586f1daf9f4f8536626e8 Mon Sep 17 00:00:00 2001 From: StrathCole <7449529+StrathCole@users.noreply.github.com> Date: Thu, 30 May 2024 05:07:27 +0200 Subject: [PATCH] Add delegation msgs (#68) Add messages related to staking/delegation --- src/client/index.ts | 6 ++++ src/client/models/MsgBeginRedelegate.ts | 31 +++++++++++++++++++ src/client/models/MsgDelegate.ts | 30 ++++++++++++++++++ src/client/models/MsgUndelegate.ts | 30 ++++++++++++++++++ .../models/MsgWithdrawDelegatorRewards.ts | 31 +++++++++++++++++++ .../models/MsgWithdrawValidatorCommission.ts | 28 +++++++++++++++++ 6 files changed, 156 insertions(+) create mode 100644 src/client/models/MsgBeginRedelegate.ts create mode 100644 src/client/models/MsgDelegate.ts create mode 100644 src/client/models/MsgUndelegate.ts create mode 100644 src/client/models/MsgWithdrawDelegatorRewards.ts create mode 100644 src/client/models/MsgWithdrawValidatorCommission.ts diff --git a/src/client/index.ts b/src/client/index.ts index ac105d5b..9307c1bd 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -37,6 +37,12 @@ export { MsgIbcTransfer } from "./models/MsgIbcTransfer"; export { MsgOsmosisSinglePoolSwap } from "./models/MsgOsmosisSinglePoolSwap"; export { MsgSend } from "./models/MsgSend"; export { MsgSwapExactAmountIn } from "./models/MsgSwapExactAmountIn"; +export { MsgDelegate } from "./models/MsgDelegate"; +export { MsgUndelegate } from "./models/MsgUndelegate"; +export { MsgBeginRedelegate } from "./models/MsgBeginRedelegate"; +export { MsgWithdrawDelegatorRewards } from "./models/MsgWithdrawDelegatorRewards"; +export { MsgWithdrawValidatorCommission } from "./models/MsgWithdrawValidatorCommission"; + export { Secp256k1PubKey } from "./models/Secp256k1PubKey"; export { Tx, diff --git a/src/client/models/MsgBeginRedelegate.ts b/src/client/models/MsgBeginRedelegate.ts new file mode 100644 index 00000000..c4da3261 --- /dev/null +++ b/src/client/models/MsgBeginRedelegate.ts @@ -0,0 +1,31 @@ +import { PlainMessage } from "@bufbuild/protobuf"; +import { CosmosStakingV1beta1MsgBeginRedelegate as ProtoMsgBeginRedelegate } from "cosmes/protobufs"; + +import { DeepPrettify } from "../../typeutils/prettify"; +import { Adapter } from "./Adapter"; + +type Data = DeepPrettify>; + +export class MsgBeginRedelegate implements Adapter { + private readonly data: Data; + + constructor(data: Data) { + this.data = data; + } + + public toProto() { + return new ProtoMsgBeginRedelegate(this.data); + } + + public toAmino() { + return { + type: "cosmos-sdk/MsgBeginRedelegate", + value: { + delegator_address: this.data.delegatorAddress, + validator_src_address: this.data.validatorSrcAddress, + validator_dst_address: this.data.validatorDstAddress, + amount: this.data.amount, + }, + }; + } +} \ No newline at end of file diff --git a/src/client/models/MsgDelegate.ts b/src/client/models/MsgDelegate.ts new file mode 100644 index 00000000..df1d2d8d --- /dev/null +++ b/src/client/models/MsgDelegate.ts @@ -0,0 +1,30 @@ +import { PlainMessage } from "@bufbuild/protobuf"; +import { CosmosStakingV1beta1MsgDelegate as ProtoMsgDelegate } from "cosmes/protobufs"; + +import { DeepPrettify } from "../../typeutils/prettify"; +import { Adapter } from "./Adapter"; + +type Data = DeepPrettify>; + +export class MsgDelegate implements Adapter { + private readonly data: Data; + + constructor(data: Data) { + this.data = data; + } + + public toProto() { + return new ProtoMsgDelegate(this.data); + } + + public toAmino() { + return { + type: "cosmos-sdk/MsgDelegate", + value: { + delegator_address: this.data.delegatorAddress, + validator_address: this.data.validatorAddress, + amount: this.data.amount, + }, + }; + } +} \ No newline at end of file diff --git a/src/client/models/MsgUndelegate.ts b/src/client/models/MsgUndelegate.ts new file mode 100644 index 00000000..75c9f202 --- /dev/null +++ b/src/client/models/MsgUndelegate.ts @@ -0,0 +1,30 @@ +import { PlainMessage } from "@bufbuild/protobuf"; +import { CosmosStakingV1beta1MsgUndelegate as ProtoMsgUndelegate } from "cosmes/protobufs"; + +import { DeepPrettify } from "../../typeutils/prettify"; +import { Adapter } from "./Adapter"; + +type Data = DeepPrettify>; + +export class MsgUndelegate implements Adapter { + private readonly data: Data; + + constructor(data: Data) { + this.data = data; + } + + public toProto() { + return new ProtoMsgUndelegate(this.data); + } + + public toAmino() { + return { + type: "cosmos-sdk/MsgUndelegate", + value: { + delegator_address: this.data.delegatorAddress, + validator_address: this.data.validatorAddress, + amount: this.data.amount, + }, + }; + } +} \ No newline at end of file diff --git a/src/client/models/MsgWithdrawDelegatorRewards.ts b/src/client/models/MsgWithdrawDelegatorRewards.ts new file mode 100644 index 00000000..b992ddb1 --- /dev/null +++ b/src/client/models/MsgWithdrawDelegatorRewards.ts @@ -0,0 +1,31 @@ +import { PlainMessage } from "@bufbuild/protobuf"; +import { CosmosDistributionV1beta1MsgWithdrawDelegatorReward as ProtoMsgWithdrawDelegatorRewards } from "cosmes/protobufs"; + +import { DeepPrettify } from "../../typeutils/prettify"; +import { Adapter } from "./Adapter"; + +type Data = DeepPrettify>; + +export class MsgWithdrawDelegatorRewards implements Adapter { + private readonly data: Data; + private readonly isLegacy: boolean; + + constructor(data: Data, isLegacy = false) { + this.data = data; + this.isLegacy = isLegacy; + } + + public toProto() { + return new ProtoMsgWithdrawDelegatorRewards(this.data); + } + + public toAmino() { + return { + type: this.isLegacy ? "distribution/MsgWithdrawDelegationReward" : "cosmos-sdk/MsgWithdrawDelegationReward", + value: { + validator_address: this.data.validatorAddress, + delegator_address: this.data.delegatorAddress, + }, + }; + } +} \ No newline at end of file diff --git a/src/client/models/MsgWithdrawValidatorCommission.ts b/src/client/models/MsgWithdrawValidatorCommission.ts new file mode 100644 index 00000000..37e9821b --- /dev/null +++ b/src/client/models/MsgWithdrawValidatorCommission.ts @@ -0,0 +1,28 @@ +import { PlainMessage } from "@bufbuild/protobuf"; +import { CosmosDistributionV1beta1MsgWithdrawValidatorCommission as ProtoMsgWithdrawValidatorCommission } from "cosmes/protobufs"; + +import { DeepPrettify } from "../../typeutils/prettify"; +import { Adapter } from "./Adapter"; + +type Data = DeepPrettify>; + +export class MsgWithdrawValidatorCommission implements Adapter { + private readonly data: Data; + + constructor(data: Data) { + this.data = data; + } + + public toProto() { + return new ProtoMsgWithdrawValidatorCommission(this.data); + } + + public toAmino() { + return { + type: "cosmos-sdk/MsgWithdrawValidatorCommission", + value: { + validator_address: this.data.validatorAddress, + }, + }; + } +} \ No newline at end of file