From 9a16f62170775b4605cd6e848794af170dd24202 Mon Sep 17 00:00:00 2001 From: robot-ux Date: Mon, 26 Feb 2024 12:59:42 +0800 Subject: [PATCH 1/4] feat: Add stake migration tx --- src/types/msg/stake/index.ts | 1 + src/types/msg/stake/stakeMigrationMsg.ts | 89 ++++++++++++++++++++++++ src/types/tx/stdTx.ts | 1 + 3 files changed, 91 insertions(+) create mode 100644 src/types/msg/stake/stakeMigrationMsg.ts diff --git a/src/types/msg/stake/index.ts b/src/types/msg/stake/index.ts index 09963b77..a0b7572e 100644 --- a/src/types/msg/stake/index.ts +++ b/src/types/msg/stake/index.ts @@ -1,3 +1,4 @@ export * from "./bscDelegateMsg" export * from "./bscUndelegateMsg" export * from "./bscRedelegateMsg" +export * from "./stakeMigrationMsg" diff --git a/src/types/msg/stake/stakeMigrationMsg.ts b/src/types/msg/stake/stakeMigrationMsg.ts new file mode 100644 index 00000000..455d10f3 --- /dev/null +++ b/src/types/msg/stake/stakeMigrationMsg.ts @@ -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, + } + } +} diff --git a/src/types/tx/stdTx.ts b/src/types/tx/stdTx.ts index 0ee89441..45fe9ad8 100644 --- a/src/types/tx/stdTx.ts +++ b/src/types/tx/stdTx.ts @@ -65,6 +65,7 @@ export enum AminoPrefix { MsgSideChainDelegate = "E3A07FD2", MsgSideChainRedelegate = "E3CED364", MsgSideChainUndelegate = "514F7E0E", + MsgSideChainStakeMigration = "38589196", Claim = "4E781C11", ClaimMsg = "175A0521", BindMsg = "B9AE640C", From 5cd0cedfd3bef642d3f8dc73891cb522a86b6e68 Mon Sep 17 00:00:00 2001 From: robot-ux Date: Wed, 28 Feb 2024 13:45:27 +0800 Subject: [PATCH 2/4] update msg --- src/types/msg/stake/stakeMigrationMsg.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/msg/stake/stakeMigrationMsg.ts b/src/types/msg/stake/stakeMigrationMsg.ts index 455d10f3..3f2db512 100644 --- a/src/types/msg/stake/stakeMigrationMsg.ts +++ b/src/types/msg/stake/stakeMigrationMsg.ts @@ -65,9 +65,9 @@ export class StakeMigrationMsg extends BaseMsg { getMsg() { const data: StakeMigrationData = { - delegator_addr: crypto.decodeAddress(this.delegator_addr), + delegator_addr: Buffer.from(this.delegator_addr.slice(2), "hex"), validator_src_addr: crypto.decodeAddress(this.validator_src_addr), - validator_dst_addr: crypto.decodeAddress(this.validator_dst_addr), + validator_dst_addr: Buffer.from(this.validator_dst_addr.slice(2), "hex"), amount: this.amount, refund_addr: crypto.decodeAddress(this.refund_addr), aminoPrefix: AminoPrefix.MsgSideChainStakeMigration, From 583bc3194c5d884f37a608ab876d308d38c8566d Mon Sep 17 00:00:00 2001 From: robot-ux Date: Wed, 28 Feb 2024 15:04:08 +0800 Subject: [PATCH 3/4] v1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cff2169a..d8f2f1c0 100644 --- a/package.json +++ b/package.json @@ -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", From 442286ac2923fdfd7cb4fb2299f722ec263c714c Mon Sep 17 00:00:00 2001 From: robot-ux Date: Wed, 28 Feb 2024 15:09:17 +0800 Subject: [PATCH 4/4] Fix the order of message structure --- docs/api-docs/classes/bncclient.md | 4 ++-- src/types/msg/stake/stakeMigrationMsg.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/api-docs/classes/bncclient.md b/docs/api-docs/classes/bncclient.md index 2379a5c4..4c7336e7 100644 --- a/docs/api-docs/classes/bncclient.md +++ b/docs/api-docs/classes/bncclient.md @@ -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[]›* @@ -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') diff --git a/src/types/msg/stake/stakeMigrationMsg.ts b/src/types/msg/stake/stakeMigrationMsg.ts index 3f2db512..cdfbc5ed 100644 --- a/src/types/msg/stake/stakeMigrationMsg.ts +++ b/src/types/msg/stake/stakeMigrationMsg.ts @@ -50,11 +50,11 @@ export class StakeMigrationMsg extends BaseMsg { 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) }, + delegator_addr: this.delegator_addr, refund_addr: this.refund_addr, + amount: { denom, amount: String(amount) }, } return { @@ -65,11 +65,11 @@ export class StakeMigrationMsg extends BaseMsg { getMsg() { const data: StakeMigrationData = { - delegator_addr: Buffer.from(this.delegator_addr.slice(2), "hex"), validator_src_addr: crypto.decodeAddress(this.validator_src_addr), validator_dst_addr: Buffer.from(this.validator_dst_addr.slice(2), "hex"), - amount: this.amount, + delegator_addr: Buffer.from(this.delegator_addr.slice(2), "hex"), refund_addr: crypto.decodeAddress(this.refund_addr), + amount: this.amount, aminoPrefix: AminoPrefix.MsgSideChainStakeMigration, } @@ -78,11 +78,11 @@ export class StakeMigrationMsg extends BaseMsg { static defaultMsg() { return { - delegator_addr: Buffer.from(""), validator_src_addr: Buffer.from(""), validator_dst_addr: Buffer.from(""), - amount: [{ denom: "", amount: 0 }], + delegator_addr: Buffer.from(""), refund_addr: Buffer.from(""), + amount: [{ denom: "", amount: 0 }], aminoPrefix: AminoPrefix.MsgSideChainStakeMigration, } }