redelegate static method

Future<List<TransactionInstruction>> redelegate({
  1. required SolanaRPC connection,
  2. required SolAddress stakePoolAddress,
  3. required SolAddress sourceVoteAccount,
  4. required BigInt sourceTransientStakeSeed,
  5. required SolAddress destinationVoteAccount,
  6. required BigInt destinationTransientStakeSeed,
  7. required BigInt ephemeralStakeSeed,
  8. required BigInt lamports,
})

Creates instructions required to redelegate stake.

Implementation

static Future<List<TransactionInstruction>> redelegate({
  required SolanaRPC connection,
  required SolAddress stakePoolAddress,
  required SolAddress sourceVoteAccount,
  required BigInt sourceTransientStakeSeed,
  required SolAddress destinationVoteAccount,
  required BigInt destinationTransientStakeSeed,
  required BigInt ephemeralStakeSeed,
  required BigInt lamports,
}) async {
  final stakePool = await connection
      .request(SolanaRPCGetStakePoolAccount(address: stakePoolAddress));
  if (stakePool == null) {
    throw const MessageException("Stake pool account does not found.");
  }

  final stakePoolWithdrawAuthority =
      StakePoolProgramUtils.findWithdrawAuthorityProgramAddress(
    stakePoolAddress: stakePoolAddress,
  );

  final sourceValidatorStake = StakePoolProgramUtils.findStakeProgramAddress(
    voteAccountAddress: sourceVoteAccount,
    stakePoolAddress: stakePoolAddress,
  );

  final sourceTransientStake =
      StakePoolProgramUtils.findTransientStakeProgramAddress(
    voteAccountAddress: sourceVoteAccount,
    stakePoolAddress: stakePoolAddress,
    seed: sourceTransientStakeSeed,
  );

  final destinationValidatorStake =
      StakePoolProgramUtils.findStakeProgramAddress(
    voteAccountAddress: destinationVoteAccount,
    stakePoolAddress: stakePoolAddress,
  );

  final destinationTransientStake =
      StakePoolProgramUtils.findTransientStakeProgramAddress(
    voteAccountAddress: destinationVoteAccount,
    stakePoolAddress: stakePoolAddress,
    seed: destinationTransientStakeSeed,
  );
  final ephemeralStake =
      StakePoolProgramUtils.findEphemeralStakeProgramAddress(
    stakePoolAddress: stakePoolAddress,
    seed: ephemeralStakeSeed,
  );

  final instructions = <TransactionInstruction>[];

  instructions.add(
    StakePoolProgram.redelegate(
        stakePool: stakePool.address,
        staker: stakePool.staker,
        validatorList: stakePool.validatorList,
        reserveStake: stakePool.reserveStake,
        stakePoolWithdrawAuthority: stakePoolWithdrawAuthority.address,
        ephemeralStake: ephemeralStake.address,
        sourceValidatorStake: sourceValidatorStake.address,
        sourceTransientStake: sourceTransientStake.address,
        destinationValidatorStake: destinationValidatorStake.address,
        destinationTransientStake: destinationTransientStake.address,
        validator: destinationVoteAccount,
        layout: StakePoolReDelegateLayout(
            lamports: lamports,
            sourceTransientStakeSeed: sourceTransientStakeSeed,
            ephemeralStakeSeed: ephemeralStakeSeed,
            destinationTransientStakeSeed: destinationTransientStakeSeed)),
  );

  return instructions;
}