Skip to content

Commit

Permalink
feat: Add stake migration tx
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-ux committed Feb 26, 2024
1 parent aa9d28e commit 9a16f62
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/types/msg/stake/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./bscDelegateMsg"
export * from "./bscUndelegateMsg"
export * from "./bscRedelegateMsg"
export * from "./stakeMigrationMsg"
89 changes: 89 additions & 0 deletions src/types/msg/stake/stakeMigrationMsg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { BaseMsg, Msg, SignMsg, Coin } from ".."
import * as crypto from "../../../crypto"
import { AminoPrefix } from "../../tx"

export interface SignedStakeMigrationMsg extends SignMsg {
delegator_addr: string
validator_src_addr: string
validator_dst_addr: string
refund_addr: string
amount: Coin
}

export interface StakeMigrationData extends Msg {
validator_src_addr: Buffer
validator_dst_addr: Buffer
delegator_addr: Buffer
refund_addr: Buffer
amount: Coin
aminoPrefix: AminoPrefix
}

export class StakeMigrationMsg extends BaseMsg {
private delegator_addr: string
private validator_src_addr: string
private validator_dst_addr: string
private refund_addr: string
private amount: Coin

constructor({
delegator_addr,
validator_src_addr,
validator_dst_addr,
amount,
refund_addr,
}: {
delegator_addr: string
validator_src_addr: string
validator_dst_addr: string
amount: Coin
refund_addr: string
}) {
super()
this.delegator_addr = delegator_addr
this.validator_src_addr = validator_src_addr
this.validator_dst_addr = validator_dst_addr
this.amount = amount
this.refund_addr = refund_addr
}

getSignMsg() {
const { denom, amount } = this.amount
const signMsg: SignedStakeMigrationMsg = {
delegator_addr: this.delegator_addr,
validator_src_addr: this.validator_src_addr,
validator_dst_addr: this.validator_dst_addr,
amount: { denom, amount: String(amount) },
refund_addr: this.refund_addr,
}

return {
type: "cosmos-sdk/MsgSideChainStakeMigration",
value: signMsg,
}
}

getMsg() {
const data: StakeMigrationData = {
delegator_addr: crypto.decodeAddress(this.delegator_addr),
validator_src_addr: crypto.decodeAddress(this.validator_src_addr),
validator_dst_addr: crypto.decodeAddress(this.validator_dst_addr),
amount: this.amount,
refund_addr: crypto.decodeAddress(this.refund_addr),
aminoPrefix: AminoPrefix.MsgSideChainStakeMigration,
}

return data
}

static defaultMsg() {
return {
delegator_addr: Buffer.from(""),
validator_src_addr: Buffer.from(""),
validator_dst_addr: Buffer.from(""),
amount: [{ denom: "", amount: 0 }],
refund_addr: Buffer.from(""),
aminoPrefix: AminoPrefix.MsgSideChainStakeMigration,
}
}
}
1 change: 1 addition & 0 deletions src/types/tx/stdTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export enum AminoPrefix {
MsgSideChainDelegate = "E3A07FD2",
MsgSideChainRedelegate = "E3CED364",
MsgSideChainUndelegate = "514F7E0E",
MsgSideChainStakeMigration = "38589196",
Claim = "4E781C11",
ClaimMsg = "175A0521",
BindMsg = "B9AE640C",
Expand Down

0 comments on commit 9a16f62

Please sign in to comment.