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

TxBuilder: TransactionBuilder.nodeStake takes rewardDelegators #102

Merged
merged 2 commits into from
Mar 11, 2024

Conversation

msmania
Copy link
Contributor

@msmania msmania commented Feb 20, 2024

This patch implements a new feature Reward Delegators (PIP-32; introduced by pokt-network/pocket-core#1581).

@msmania msmania added the enhancement New feature or request label Feb 20, 2024
@msmania msmania self-assigned this Feb 20, 2024
@msmania msmania marked this pull request as draft February 20, 2024 17:03
@msmania msmania changed the base branch from toshi/base to main March 11, 2024 02:28
@msmania msmania marked this pull request as ready for review March 11, 2024 02:30
@msmania
Copy link
Contributor Author

msmania commented Mar 11, 2024

Here's the sample code to add delegators. Tx is this. Will update README.md in a follow-up patch.

import "dotenv/config";
import { JsonRpcProvider } from "@pokt-foundation/pocketjs-provider";
import { KeyManager } from "@pokt-foundation/pocketjs-signer";
import { TransactionBuilder } from "@pokt-foundation/pocketjs-transaction-builder";

const PoktEndpoint = process.env.POKT_ENDPOINT;
const TxSignerKey = process.env.SIGNER_PRIVATE_KEY;

async function main() {
  const provider = new JsonRpcProvider({
    rpcUrl: PoktEndpoint,
    dispatchers: [PoktEndpoint],
  });

  const height = await provider.getBlockNumber();
  console.log(height);

  const txSigner = await KeyManager.fromPrivateKey(TxSignerKey);
  const transactionBuilder = new TransactionBuilder({
    provider,
    signer: txSigner,
    chainID: "testnet",
  });
  const sendMsg = transactionBuilder.nodeStake({
    amount: "16000000000",
    chains: ["0001", "0002"],
    serviceURL: new URL("https://poktt1698102386.c0d3r.org:443"),
    outputAddress: "fc1c79e7efecf89f071ebb2ba7c6f5a98dcdfc3c",
    rewardDelegators: {
      "fc1c79e7efecf89f071ebb2ba7c6f5a98dcdfc3c": 30,
      "54751ae3431c015a6e24d711c9d1ed4e5a276479": 40,
    }
  });
  const txResponse = await transactionBuilder.submit({
    memo: "via PocketJS",
    txMsg: sendMsg,
  });
  console.log(txResponse.txHash);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

@nodiesBlade
Copy link
Contributor

nodiesBlade commented Mar 11, 2024

Here's the sample code to add delegators. Tx is this. Will update README.md in a follow-up patch.

import "dotenv/config";
import { JsonRpcProvider } from "@pokt-foundation/pocketjs-provider";
import { KeyManager } from "@pokt-foundation/pocketjs-signer";
import { TransactionBuilder } from "@pokt-foundation/pocketjs-transaction-builder";

const PoktEndpoint = process.env.POKT_ENDPOINT;
const TxSignerKey = process.env.SIGNER_PRIVATE_KEY;

async function main() {
  const provider = new JsonRpcProvider({
    rpcUrl: PoktEndpoint,
    dispatchers: [PoktEndpoint],
  });

  const height = await provider.getBlockNumber();
  console.log(height);

  const txSigner = await KeyManager.fromPrivateKey(TxSignerKey);
  const transactionBuilder = new TransactionBuilder({
    provider,
    signer: txSigner,
    chainID: "testnet",
  });
  const sendMsg = transactionBuilder.nodeStake({
    amount: "16000000000",
    chains: ["0001", "0002"],
    serviceURL: new URL("https://poktt1698102386.c0d3r.org:443"),
    outputAddress: "fc1c79e7efecf89f071ebb2ba7c6f5a98dcdfc3c",
    rewardDelegators: {
      "fc1c79e7efecf89f071ebb2ba7c6f5a98dcdfc3c": 30,
      "54751ae3431c015a6e24d711c9d1ed4e5a276479": 40,
    }
  });
  const txResponse = await transactionBuilder.submit({
    memo: "via PocketJS",
    txMsg: sendMsg,
  });
  console.log(txResponse.txHash);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

Can you provide an example without delegators (basically before the addition as its an optional param).


As well, if a user doesn't specify delegators and there are existing delegators within a node stake, does that remove the delegators or keep it the same?

Example, are these two the same:

(is this even valid?)

  const sendMsg = transactionBuilder.nodeStake({
    amount: "16000000000",
    chains: ["0001", "0002"],
    serviceURL: new URL("https://poktt1698102386.c0d3r.org:443"),
    outputAddress: "fc1c79e7efecf89f071ebb2ba7c6f5a98dcdfc3c",
    rewardDelegators: {})
    const sendMsg = transactionBuilder.nodeStake({
    amount: "16000000000",
    chains: ["0001", "0002"],
    serviceURL: new URL("https://poktt1698102386.c0d3r.org:443"),
    outputAddress: "fc1c79e7efecf89f071ebb2ba7c6f5a98dcdfc3c")

@msmania
Copy link
Contributor Author

msmania commented Mar 11, 2024

Can you provide an example without delegators (basically before the addition as its an optional param).

As well, if a user doesn't specify delegators and there are existing delegators within a node stake, does that remove the delegators or keep it the same?

Example, are these two the same:

(is this even valid?)

  const sendMsg = transactionBuilder.nodeStake({
    amount: "16000000000",
    chains: ["0001", "0002"],
    serviceURL: new URL("https://poktt1698102386.c0d3r.org:443"),
    outputAddress: "fc1c79e7efecf89f071ebb2ba7c6f5a98dcdfc3c",
    rewardDelegators: {})
    const sendMsg = transactionBuilder.nodeStake({
    amount: "16000000000",
    chains: ["0001", "0002"],
    serviceURL: new URL("https://poktt1698102386.c0d3r.org:443"),
    outputAddress: "fc1c79e7efecf89f071ebb2ba7c6f5a98dcdfc3c")

Good question.

If we do rewardDelegators: {}, tx submission fails due to verification failure before transaction fee is deducted.

To stake without delegators or remove the current delegators, you just omit rewardDelegators or specify a falsy value like undefined or null. I updated the comment on nodeStake about it.

In a follow-up patch, I'll add both scenarios, to add/remove delegators.

Copy link
Contributor

@nodiesBlade nodiesBlade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. As mentioned in other PR's and Discord, we will do a regression test of basic transactions of transfer, app stake/transfer, and staking using jsonrpcprovider and the webprovider to ensure all the commits did not affect functionality

@msmania msmania merged commit 2d1a815 into pokt-network:main Mar 11, 2024
2 of 3 checks passed
@msmania msmania deleted the toshi/reward-delegators branch March 11, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants