createPoolTokenMetadata static method

Future<List<TransactionInstruction>> createPoolTokenMetadata({
  1. required SolanaRPC rpc,
  2. required SolAddress stakePoolAddress,
  3. required SolAddress payer,
  4. required String name,
  5. required String symbol,
  6. required String uri,
})

Creates instructions required to create pool token metadata.

Implementation

static Future<List<TransactionInstruction>> createPoolTokenMetadata({
  required SolanaRPC rpc,
  required SolAddress stakePoolAddress,
  required SolAddress payer,
  required String name,
  required String symbol,
  required String uri,
}) async {
  final stakePool = await rpc
      .request(SolanaRPCGetStakePoolAccount(address: stakePoolAddress));
  if (stakePool == null) {
    throw const MessageException("Stake pool account does not found.");
  }

  final withdrawAuthority =
      StakePoolProgramUtils.findWithdrawAuthorityProgramAddress(
    stakePoolAddress: stakePoolAddress,
  );
  final tokenMetadata = StakePoolProgramUtils.findMetadataAddress(
      stakePoolMintAddress: stakePool.poolMint);
  final instructions = <TransactionInstruction>[];
  instructions.add(
    StakePoolProgram.createTokenMetadata(
        stakePool: stakePoolAddress,
        poolMint: stakePool.poolMint,
        payer: payer,
        manager: stakePool.manager,
        tokenMetadata: tokenMetadata.address,
        withdrawAuthority: withdrawAuthority.address,
        layout: StakePoolCreateTokenMetaDataLayout(
            name: name, uri: uri, symbol: symbol)),
  );

  return instructions;
}