From dad40857666aec91f8acc527e0080f94abcd830c Mon Sep 17 00:00:00 2001 From: tokikuch Date: Fri, 8 Mar 2024 10:54:10 -0800 Subject: [PATCH 1/2] TxBuilder: Introduce TransactionBuilder.appTransfer (#101) This patch implements a new feature AppTransfer ([PIP-35](https://forum.pokt.network/t/pip-35-introduce-a-secure-way-to-transfer-a-staked-app-to-a-new-account/4806); introduced by https://github.com/pokt-network/pocket-core/pull/1585). --- packages/transaction-builder/README.md | 11 ++++ .../src/models/msgs/index.ts | 1 + .../src/models/msgs/msg-proto-app-transfer.ts | 62 +++++++++++++++++++ .../transaction-builder/src/tx-builder.ts | 16 ++++- .../tests/transactions.test.ts | 6 ++ 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 packages/transaction-builder/src/models/msgs/msg-proto-app-transfer.ts diff --git a/packages/transaction-builder/README.md b/packages/transaction-builder/README.md index 71f1543..98bd85b 100644 --- a/packages/transaction-builder/README.md +++ b/packages/transaction-builder/README.md @@ -137,6 +137,17 @@ Returns a `MsgProtoAppStake`: The unsigned App Stake message. | chains | `string[]` | Chains that the apps wants access to by staking POKT. Throughput will be equally divided through all chains. | | amount | `string` | Amount of uPOKT to stake. | +#### appTransfer({ appPubKey }): MsgProtoAppStake + +Builds a transaction message to transfer the slot of a staked app. +Signer must be an existing staked app to transfer the slot from. + +Returns a `MsgProtoAppTransfer`: The unsigned AppTransfer message + +|Param|Type|Description| +|--|--|--| +|appPubKey|`string`|Application public key to be transferred to| + #### appUnstake(address): MsgProtoAppUnstake Adds a MsgProtoAppUnstake TxMsg for this transaction. diff --git a/packages/transaction-builder/src/models/msgs/index.ts b/packages/transaction-builder/src/models/msgs/index.ts index 27c8870..8a59d15 100755 --- a/packages/transaction-builder/src/models/msgs/index.ts +++ b/packages/transaction-builder/src/models/msgs/index.ts @@ -1,4 +1,5 @@ export * from './msg-proto-app-stake' +export * from './msg-proto-app-transfer' export * from './msg-proto-app-unstake' export * from './msg-proto-node-stake' export * from './msg-proto-node-unjail' diff --git a/packages/transaction-builder/src/models/msgs/msg-proto-app-transfer.ts b/packages/transaction-builder/src/models/msgs/msg-proto-app-transfer.ts new file mode 100755 index 0000000..110ac28 --- /dev/null +++ b/packages/transaction-builder/src/models/msgs/msg-proto-app-transfer.ts @@ -0,0 +1,62 @@ +import { Buffer } from 'buffer' +import { MsgProtoStake } from '../proto/generated/tx-signer' +import { Any } from '../proto/generated/google/protobuf/any' +import { TxMsg } from './tx-msg' + +/** + * MsgProtoAppTransfer is a special case of MsgProtoAppStake where + * chains and amount are not set + */ +export class MsgProtoAppTransfer extends TxMsg { + public readonly KEY: string = '/x.apps.MsgProtoStake' + public readonly AMINO_KEY: string = 'apps/MsgAppStake' + public readonly pubKey: Buffer + + /** + * Constructor for this class + * @param {Buffer} pubKey - Application public key to be transferred to + */ + constructor(pubKey: string) { + super() + this.pubKey = Buffer.from(pubKey, 'hex') + } + + /** + * Converts an Msg Object to StdSignDoc + * @returns {object} - Msg type key value. + * @memberof MsgAppStake + */ + public toStdSignDocMsgObj(): object { + return { + type: this.AMINO_KEY, + value: { + chains: null, + pubkey: { + type: 'crypto/ed25519_public_key', + value: this.pubKey.toString('hex'), + }, + value: '0', + }, + } + } + + /** + * Converts an Msg Object for StdTx encoding + * @returns {any} - Msg type key value. + * @memberof MsgAppStake + */ + public toStdTxMsgObj(): any { + const data : MsgProtoStake = { + pubKey: this.pubKey, + chains: [], + value: '0', + } + + return Any.fromJSON({ + typeUrl: this.KEY, + value: Buffer.from(MsgProtoStake.encode(data).finish()).toString( + 'base64' + ), + }) + } +} diff --git a/packages/transaction-builder/src/tx-builder.ts b/packages/transaction-builder/src/tx-builder.ts index 30b8ecb..05f2768 100644 --- a/packages/transaction-builder/src/tx-builder.ts +++ b/packages/transaction-builder/src/tx-builder.ts @@ -1,6 +1,7 @@ import { Buffer } from 'buffer' import { MsgProtoAppStake, + MsgProtoAppTransfer, MsgProtoAppUnstake, MsgProtoNodeStakeTx, MsgProtoNodeUnjail, @@ -28,7 +29,6 @@ import { InvalidChainIDError, NoProviderError, NoSignerError } from './errors' import { AbstractBuilder } from './abstract-tx-builder' import { MsgProtoGovDAOTransfer } from './models/msgs/msg-proto-gov-dao-transfer' import { MsgProtoGovChangeParam } from './models/msgs/msg-proto-gov-change-param' -import { Upgrade } from './models/proto/generated/tx-signer' import { MsgProtoGovUpgrade } from './models/msgs/msg-proto-gov-upgrade' export type ChainID = 'mainnet' | 'testnet' | 'localnet' @@ -207,6 +207,20 @@ export class TransactionBuilder implements AbstractBuilder { return new MsgProtoAppStake(appPubKey, chains, amount) } + /** + * Builds a transaction message to transfer the slot of a staked app. + * Signer must be an existing staked app to transfer the slot from. + * @param {string} appPubKey - Application public key to be transferred to + * @returns {MsgProtoAppTransfer} - The unsigned AppTransfer message + */ + public appTransfer({ + appPubKey, + }: { + appPubKey: string + }): MsgProtoAppTransfer { + return new MsgProtoAppTransfer(appPubKey) + } + /** * Adds a MsgBeginAppUnstake TxMsg for this transaction * @param {string} address - Address of the Application to unstake for diff --git a/packages/transaction-builder/tests/transactions.test.ts b/packages/transaction-builder/tests/transactions.test.ts index f186746..b417f96 100644 --- a/packages/transaction-builder/tests/transactions.test.ts +++ b/packages/transaction-builder/tests/transactions.test.ts @@ -18,6 +18,7 @@ import { RawTxRequest } from '@pokt-foundation/pocketjs-types' import { MsgProtoGovUpgrade } from '../src/models/msgs/msg-proto-gov-upgrade' import { MsgProtoGovChangeParam } from '../src/models/msgs/msg-proto-gov-change-param' import { MsgProtoGovDAOTransfer } from '../src/models/msgs/msg-proto-gov-dao-transfer' +import { MsgProtoAppTransfer } from '../src/models/msgs/msg-proto-app-transfer' const PRIVATE_KEY = '1f8cbde30ef5a9db0a5a9d5eb40536fc9defc318b8581d543808b7504e0902bcb243b27bc9fbe5580457a46370ae5f03a6f6753633e51efdaf2cf534fdc26cc3' @@ -84,6 +85,11 @@ describe('TransactionBuilder Tests', () => { }) expect(appStakeMsg instanceof MsgProtoAppStake).toBe(true) + const appTransferMsg = transactionBuilder.appTransfer({ + appPubKey: (await KeyManager.createRandom()).getPublicKey(), + }) + expect(appTransferMsg instanceof MsgProtoAppTransfer).toBe(true) + const appUnstakeMsg = transactionBuilder.appUnstake(ADDRESS) expect(appUnstakeMsg instanceof MsgProtoAppUnstake).toBe(true) From 96809f5a49dff846ad71d22cbb014aa265c46ea3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 14:36:40 -0700 Subject: [PATCH 2/2] Chore(deps): bump undici from 5.0.0 to 5.26.2 (#93) Bumps [undici](https://github.com/nodejs/undici) from 5.0.0 to 5.26.2. - [Release notes](https://github.com/nodejs/undici/releases) - [Commits](https://github.com/nodejs/undici/compare/v5.0.0...v5.26.2) --- updated-dependencies: - dependency-name: undici dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- packages/provider/package.json | 2 +- pnpm-lock.yaml | 60 +++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/packages/provider/package.json b/packages/provider/package.json index 2fb9eb3..df79801 100644 --- a/packages/provider/package.json +++ b/packages/provider/package.json @@ -36,6 +36,6 @@ "@pokt-foundation/pocketjs-abstract-provider": "workspace:*", "abort-controller": "^3.0.0", "debug": "^4.3.3", - "undici": "^5.0.0" + "undici": "^5.26.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7892383..72a1814 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,7 +9,7 @@ importers: typescript: ^4.5.5 devDependencies: prettier: 2.5.1 - turbo: 1.10.1 + turbo: 1.10.15 typescript: 4.5.5 packages/abstract-provider: @@ -116,12 +116,12 @@ importers: prettier: ^2.5.1 ts-jest: ^27.1.3 typescript: ^4.5.5 - undici: ^5.0.0 + undici: ^5.26.2 dependencies: '@pokt-foundation/pocketjs-abstract-provider': link:../abstract-provider abort-controller: 3.0.0 debug: 4.3.3 - undici: 5.0.0 + undici: 5.26.2 devDependencies: '@pokt-foundation/pocketjs-types': link:../types '@types/jest': 27.4.0 @@ -1614,6 +1614,11 @@ packages: - supports-color dev: true + /@fastify/busboy/2.0.0: + resolution: {integrity: sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ==} + engines: {node: '>=14'} + dev: false + /@humanwhocodes/config-array/0.5.0: resolution: {integrity: sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==} engines: {node: '>=10.10.0'} @@ -6895,65 +6900,64 @@ packages: typescript: 4.5.5 dev: true - /turbo-darwin-64/1.10.1: - resolution: {integrity: sha512-isLLoPuAOMNsYovOq9BhuQOZWQuU13zYsW988KkkaA4OJqOn7qwa9V/KBYCJL8uVQqtG+/Y42J37lO8RJjyXuA==} + /turbo-darwin-64/1.10.15: + resolution: {integrity: sha512-Sik5uogjkRTe1XVP9TC2GryEMOJCaKE2pM/O9uLn4koQDnWKGcLQv+mDU+H+9DXvKLnJnKCD18OVRkwK5tdpoA==} cpu: [x64] os: [darwin] requiresBuild: true dev: true optional: true - /turbo-darwin-arm64/1.10.1: - resolution: {integrity: sha512-x1nloPR10fLElNCv17BKr0kCx/O5gse/UXAcVscMZH2tvRUtXrdBmut62uw2YU3J9hli2fszYjUWXkulVpQvFA==} + /turbo-darwin-arm64/1.10.15: + resolution: {integrity: sha512-xwqyFDYUcl2xwXyGPmHkmgnNm4Cy0oNzMpMOBGRr5x64SErS7QQLR4VHb0ubiR+VAb8M+ECPklU6vD1Gm+wekg==} cpu: [arm64] os: [darwin] requiresBuild: true dev: true optional: true - /turbo-linux-64/1.10.1: - resolution: {integrity: sha512-abV+ODCeOlz0503OZlHhPWdy3VwJZc1jObf1VQj7uQM+JqJ/kXbMyqJIMQVz+m7QJUFdferYPRxGhYT/NbYK7Q==} + /turbo-linux-64/1.10.15: + resolution: {integrity: sha512-dM07SiO3RMAJ09Z+uB2LNUSkPp3I1IMF8goH5eLj+d8Kkwoxd/+qbUZOj9RvInyxU/IhlnO9w3PGd3Hp14m/nA==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /turbo-linux-arm64/1.10.1: - resolution: {integrity: sha512-zRC3nZbHQ63tofOmbuySzEn1ROISWTkemYYr1L98rpmT5aVa0kERlGiYcfDwZh3cBso/Ylg/wxexRAaPzcCJYQ==} + /turbo-linux-arm64/1.10.15: + resolution: {integrity: sha512-MkzKLkKYKyrz4lwfjNXH8aTny5+Hmiu4SFBZbx+5C0vOlyp6fV5jZANDBvLXWiDDL4DSEAuCEK/2cmN6FVH1ow==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /turbo-windows-64/1.10.1: - resolution: {integrity: sha512-Irqz8IU+o7Q/5V44qatZBTunk+FQAOII1hZTsEU54ah62f9Y297K6/LSp+yncmVQOZlFVccXb6MDqcETExIQtA==} + /turbo-windows-64/1.10.15: + resolution: {integrity: sha512-3TdVU+WEH9ThvQGwV3ieX/XHebtYNHv9HARHauPwmVj3kakoALkpGxLclkHFBLdLKkqDvmHmXtcsfs6cXXRHJg==} cpu: [x64] os: [win32] requiresBuild: true dev: true optional: true - /turbo-windows-arm64/1.10.1: - resolution: {integrity: sha512-124IT15d2gyjC+NEn11pHOaVFvZDRHpxfF+LDUzV7YxfNIfV0mGkR3R/IyVXtQHOgqOdtQTbC4y411sm31+SEw==} + /turbo-windows-arm64/1.10.15: + resolution: {integrity: sha512-l+7UOBCbfadvPMYsX08hyLD+UIoAkg6ojfH+E8aud3gcA1padpjCJTh9gMpm3QdMbKwZteT5uUM+wyi6Rbbyww==} cpu: [arm64] os: [win32] requiresBuild: true dev: true optional: true - /turbo/1.10.1: - resolution: {integrity: sha512-wq0YeSv6P/eEDXOL42jkMUr+T4z34dM8mdHu5u6C6OOAq8JuLJ72F/v4EVR1JmY8icyTkFz10ICLV0haUUYhbQ==} + /turbo/1.10.15: + resolution: {integrity: sha512-mKKkqsuDAQy1wCCIjCdG+jOCwUflhckDMSRoeBPcIL/CnCl7c5yRDFe7SyaXloUUkt4tUR0rvNIhVCcT7YeQpg==} hasBin: true - requiresBuild: true optionalDependencies: - turbo-darwin-64: 1.10.1 - turbo-darwin-arm64: 1.10.1 - turbo-linux-64: 1.10.1 - turbo-linux-arm64: 1.10.1 - turbo-windows-64: 1.10.1 - turbo-windows-arm64: 1.10.1 + turbo-darwin-64: 1.10.15 + turbo-darwin-arm64: 1.10.15 + turbo-linux-64: 1.10.15 + turbo-linux-arm64: 1.10.15 + turbo-windows-64: 1.10.15 + turbo-windows-arm64: 1.10.15 dev: true /type-check/0.3.2: @@ -7012,9 +7016,11 @@ packages: which-boxed-primitive: 1.0.2 dev: true - /undici/5.0.0: - resolution: {integrity: sha512-VhUpiZ3No1DOPPQVQnsDZyfcbTTcHdcgWej1PdFnSvOeJmOVDgiOHkunJmBLfmjt4CqgPQddPVjSWW0dsTs5Yg==} - engines: {node: '>=12.18'} + /undici/5.26.2: + resolution: {integrity: sha512-a4PDLQgLTPHVzOK+x3F79/M4GtyYPl+aX9AAK7aQxpwxDwCqkeZCScy7Gk5kWT3JtdFq1uhO3uZJdLtHI4dK9A==} + engines: {node: '>=14.0'} + dependencies: + '@fastify/busboy': 2.0.0 dev: false /unfetch/4.2.0: