Skip to content

Commit

Permalink
Add delegation msgs (#68)
Browse files Browse the repository at this point in the history
Add messages related to staking/delegation
  • Loading branch information
StrathCole authored May 30, 2024
1 parent a48fa72 commit 4da00ba
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 31 additions & 0 deletions src/client/models/MsgBeginRedelegate.ts
Original file line number Diff line number Diff line change
@@ -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<PlainMessage<ProtoMsgBeginRedelegate>>;

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,
},
};
}
}
30 changes: 30 additions & 0 deletions src/client/models/MsgDelegate.ts
Original file line number Diff line number Diff line change
@@ -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<PlainMessage<ProtoMsgDelegate>>;

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,
},
};
}
}
30 changes: 30 additions & 0 deletions src/client/models/MsgUndelegate.ts
Original file line number Diff line number Diff line change
@@ -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<PlainMessage<ProtoMsgUndelegate>>;

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,
},
};
}
}
31 changes: 31 additions & 0 deletions src/client/models/MsgWithdrawDelegatorRewards.ts
Original file line number Diff line number Diff line change
@@ -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<PlainMessage<ProtoMsgWithdrawDelegatorRewards>>;

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,
},
};
}
}
28 changes: 28 additions & 0 deletions src/client/models/MsgWithdrawValidatorCommission.ts
Original file line number Diff line number Diff line change
@@ -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<PlainMessage<ProtoMsgWithdrawValidatorCommission>>;

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,
},
};
}
}

0 comments on commit 4da00ba

Please sign in to comment.