Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delegation msgs #68

Merged
merged 3 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
};
}
}
Loading