Skip to content

Commit

Permalink
docs: add solana flow comments
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Apr 17, 2024
1 parent 14bc463 commit 15db4a1
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/screens/staking/lib/staking_sdk/wallet_operations/solana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,29 @@ export const stakeAmountSolana = async ({

const amountToStake = amountBN.times(LAMPORTS_PER_SOL).toNumber();

const newTx = StakeProgram.createAccount({
const createAccountTx = StakeProgram.createAccount({
authorized: new Authorized(accountKey, accountKey),
fromPubkey: accountKey,
lamports: amountToStake,
stakePubkey: stakeKeyPair.publicKey,
});

newTx.recentBlockhash = (info as any).blockhash;
newTx.feePayer = accountKey;
createAccountTx.recentBlockhash = (info as any).blockhash;
createAccountTx.feePayer = accountKey;

newTx.sign(stakeKeyPair);
// This specific transaction has to be signed also by the stake account
// key pair (and also by the wallet) to be able to broadcast it by the
// wallets. Because the wallet account is the authorized pub key, the
// other transactions can be signed just by the wallet.
createAccountTx.sign(stakeKeyPair);

const stakeAccountResult = await wallet.signAndSendTransaction(newTx);
const stakeAccountResult =
await wallet.signAndSendTransaction(createAccountTx);

// eslint-disable-next-line no-console
console.log("debug: solana.ts: result", stakeAccountResult);

// Wait some time for the nodes to be able to find the account
await new Promise((resolve) => setTimeout(resolve, 10000));

const newInfo = await stakingClient.stake(
Expand All @@ -322,18 +328,17 @@ export const stakeAmountSolana = async ({
amount,
);

const newTx2 = StakeProgram.delegate({
const activateStakeTx = StakeProgram.delegate({
authorizedPubkey: accountKey,
stakePubkey: stakeKeyPair.publicKey,
votePubkey: new PublicKey(validatorAddress),
});

newTx2.recentBlockhash = (newInfo as any).blockhash;
newTx2.feePayer = accountKey;

// newTx2.sign(stakeKeyPair);
activateStakeTx.recentBlockhash = (newInfo as any).blockhash;
activateStakeTx.feePayer = accountKey;

const stakeAccountResult2 = await wallet.signAndSendTransaction(newTx2);
const stakeAccountResult2 =
await wallet.signAndSendTransaction(activateStakeTx);

// eslint-disable-next-line no-console
console.log("debug: solana.ts: result", stakeAccountResult2);
Expand Down

0 comments on commit 15db4a1

Please sign in to comment.