initialize static method

TransactionInstruction initialize({
  1. required Pubkey stakePoolAddress,
  2. required Pubkey manager,
  3. required Pubkey staker,
  4. Pubkey? withdrawAuthority,
  5. required Pubkey validatorList,
  6. required Pubkey reserveStake,
  7. required Pubkey poolMint,
  8. required Pubkey managerFeeAccount,
  9. Pubkey? depositAuthority,
  10. required Fee fee,
  11. required Fee withdrawalFee,
  12. required Fee depositFee,
  13. required u8 referralFee,
  14. required u32 maxValidators,
})

Initializes a new StakePool.

Keys:

  • [w] stakePoolAddress - New StakePool to create.
  • [s] manager - Manager.
  • [] staker - Staker.
  • [] withdrawAuthority - Stake pool withdraw authority.
  • [w] validatorList - Uninitialized validator stake list storage account.
  • [] reserveStake - Reserve stake account must be initialized, have zero balance, and staker / withdrawer authority set to pool withdraw authority.
  • [] poolMint - Pool token mint. Must have zero supply, owned by withdraw authority.
  • [] managerFeeAccount - Pool account to deposit the generated fee for manager.
  • [] depositAuthority - (Optional) Deposit authority that must sign all deposits. Defaults to the program address generated using findDepositAuthorityProgramAddress, making deposits permissionless.

Data:

  • fee - Fee assessed as percentage of perceived rewards.
  • withdrawalFee - Fee charged per withdrawal as percentage of withdrawal.
  • depositFee - Fee charged per deposit as percentage of deposit.
  • referralFee - Percentage 0-100 of deposit_fee that goes to referrer.
  • maxValidators - Maximum expected number of validators.

Implementation

static TransactionInstruction initialize({
  // Keys
  required final Pubkey stakePoolAddress,
  required final Pubkey manager,
  required final Pubkey staker,
  final Pubkey? withdrawAuthority,
  required final Pubkey validatorList,
  required final Pubkey reserveStake,
  required final Pubkey poolMint,
  required final Pubkey managerFeeAccount,
  final Pubkey? depositAuthority,
  // Data
  required final Fee fee,
  required final Fee withdrawalFee,
  required final Fee depositFee,
  required final u8 referralFee,
  required final u32 maxValidators,
}) {
  // 0. `[w]` New StakePool to create.
  // 1. `[s]` Manager
  // 2. `[]` Staker
  // 3. `[]` Stake pool withdraw authority
  // 4. `[w]` Uninitialized validator stake list storage account
  // 5. `[]` Reserve stake account must be initialized, have zero balance,
  //     and staker / withdrawer authority set to pool withdraw authority.
  // 6. `[]` Pool token mint. Must have zero supply, owned by withdraw authority.
  // 7. `[]` Pool account to deposit the generated fee for manager.
  // 8. `[]` Token program id
  // 9. `[]` (Optional) Deposit authority that must sign all deposits. Defaults to the program
  //    address generated using `findDepositAuthorityProgramAddress`, making deposits
  //    permissionless.
  final List<AccountMeta> keys = [
    AccountMeta.writable(stakePoolAddress),
    AccountMeta.signer(manager),
    AccountMeta(staker),
    AccountMeta(withdrawAuthority ?? findWithdrawAuthorityProgramAddress(stakePoolAddress).pubkey),
    AccountMeta.writable(validatorList),
    AccountMeta(reserveStake),
    AccountMeta(poolMint),
    AccountMeta(managerFeeAccount),
    AccountMeta(TokenProgram.programId),
    if (depositAuthority != null)
      AccountMeta(depositAuthority),
  ];

  final BorshStructCodec feeCodec = borsh.struct(Fee.codec.schema);
  final List<Iterable<int>> data = [
    feeCodec.encode(fee.toJson()),
    feeCodec.encode(withdrawalFee.toJson()),
    feeCodec.encode(depositFee.toJson()),
    borsh.u8.encode(referralFee),
    borsh.u32.encode(maxValidators),
  ];

  return _instance.createTransactionIntruction(
    StakePoolInstruction.initialize,
    keys: keys,
    data: data,
  );
}