SPLTokenSwapProgram.swap constructor

SPLTokenSwapProgram.swap({
  1. required SolAddress tokenSwap,
  2. required SolAddress authority,
  3. required SolAddress userTransferAuthority,
  4. required SolAddress userSource,
  5. required SolAddress poolSource,
  6. required SolAddress poolDestination,
  7. required SolAddress userDestination,
  8. required SolAddress poolMint,
  9. required SolAddress feeAccount,
  10. required SolAddress sourceMint,
  11. required SolAddress destinationMint,
  12. required SolAddress sourceTokenProgramId,
  13. required SolAddress destinationTokenProgramId,
  14. required SolAddress poolTokenProgramId,
  15. required SPLTokenSwapSwapLayout layout,
  16. required SolAddress swapProgramId,
  17. SolAddress? hostFeeAccount,
})

Swap the tokens in the pool.

Implementation

factory SPLTokenSwapProgram.swap({
  /// Token-swap
  required SolAddress tokenSwap,

  /// swap authority
  required SolAddress authority,

  /// user transfer authority
  required SolAddress userTransferAuthority,

  /// token_(A|B) SOURCE Account, amount is transferable by
  /// user transfer authority,
  required SolAddress userSource,

  /// token_(A|B) Base Account to swap INTO.  Must be the
  /// SOURCE token.
  required SolAddress poolSource,

  /// token_(A|B) Base Account to swap FROM.  Must be the
  /// DESTINATION token.
  required SolAddress poolDestination,

  /// token_(A|B) DESTINATION Account assigned to USER as
  /// the owner.
  required SolAddress userDestination,

  /// Pool token mint, to generate trading fees
  required SolAddress poolMint,

  /// Fee account, to receive trading fees
  required SolAddress feeAccount,

  /// Token (A|B) SOURCE mint
  required SolAddress sourceMint,

  /// Token (A|B) DESTINATION mint
  required SolAddress destinationMint,

  /// Token (A|B) SOURCE program id
  required SolAddress sourceTokenProgramId,

  /// Token (A|B) DESTINATION program id
  required SolAddress destinationTokenProgramId,

  /// Pool Token program id
  required SolAddress poolTokenProgramId,
  required SPLTokenSwapSwapLayout layout,
  required SolAddress swapProgramId,

  /// Host fee account to receive additional
  /// trading fees
  SolAddress? hostFeeAccount,
}) {
  return SPLTokenSwapProgram(
      layout: layout,
      keys: [
        tokenSwap.toReadOnly(),
        authority.toReadOnly(),
        userTransferAuthority.toSigner(),
        userSource.toWritable(),
        poolSource.toWritable(),
        poolDestination.toWritable(),
        userDestination.toWritable(),
        poolMint.toWritable(),
        feeAccount.toWritable(),
        sourceMint.toReadOnly(),
        destinationMint.toReadOnly(),
        sourceTokenProgramId.toReadOnly(),
        destinationTokenProgramId.toReadOnly(),
        poolTokenProgramId.toReadOnly(),
        if (hostFeeAccount != null) hostFeeAccount.toWritable()
      ],
      programId: swapProgramId);
}