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

docs: add solana flow comments #208

Merged
merged 1 commit into from
Apr 17, 2024
Merged
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
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
Loading