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

feat: Add stake migration tx #408

Merged
merged 4 commits into from
Mar 5, 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
4 changes: 2 additions & 2 deletions docs/api-docs/classes/bncclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ get open orders for an address

Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`address` | string | this.address! | binance address |
`address` | string | this.address! | bnb address |

**Returns:** *Promise‹object | never[]›*

Expand Down Expand Up @@ -465,7 +465,7 @@ Name | Type | Default | Description |

**Returns:** *Promise‹object | never[]›*

resolves with http response ([more details](https://docs.bnbchain.org/docs/beaconchain/develop/api-reference/dex-api/block-service/#apiv1txs))
resolves with http response ([more details](https://docs.binance.org/api-reference/dex-api/block-service.html#apiv1txs))
```js
// Example:
const client = new BncClient('https://testnet-api.binance.org')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bnb-chain/javascript-sdk",
"version": "0.0.0-development",
"version": "1.0.2",
"license": "Apache-2.0",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
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 = {
validator_src_addr: this.validator_src_addr,
validator_dst_addr: this.validator_dst_addr,
delegator_addr: this.delegator_addr,
refund_addr: this.refund_addr,
amount: { denom, amount: String(amount) },
}

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

getMsg() {
const data: StakeMigrationData = {
validator_src_addr: crypto.decodeAddress(this.validator_src_addr),
validator_dst_addr: Buffer.from(this.validator_dst_addr.slice(2), "hex"),
delegator_addr: Buffer.from(this.delegator_addr.slice(2), "hex"),
refund_addr: crypto.decodeAddress(this.refund_addr),
amount: this.amount,
aminoPrefix: AminoPrefix.MsgSideChainStakeMigration,
}

return data
}

static defaultMsg() {
return {
validator_src_addr: Buffer.from(""),
validator_dst_addr: Buffer.from(""),
delegator_addr: Buffer.from(""),
refund_addr: Buffer.from(""),
amount: [{ denom: "", amount: 0 }],
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
Loading