associatedToken.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * This code was AUTOGENERATED using the Codama library.
  3. * Please DO NOT EDIT THIS FILE, instead use visitors
  4. * to add features, then rerun Codama to update it.
  5. *
  6. * @see https://github.com/codama-idl/codama
  7. */
  8. import {
  9. getAddressEncoder,
  10. getProgramDerivedAddress,
  11. type Address,
  12. type ProgramDerivedAddress,
  13. } from '@solana/kit';
  14. export type AssociatedTokenSeeds = {
  15. /** The wallet address of the associated token account. */
  16. owner: Address;
  17. /** The address of the token program to use. */
  18. tokenProgram: Address;
  19. /** The mint address of the associated token account. */
  20. mint: Address;
  21. };
  22. export async function findAssociatedTokenPda(
  23. seeds: AssociatedTokenSeeds,
  24. config: { programAddress?: Address | undefined } = {}
  25. ): Promise<ProgramDerivedAddress> {
  26. const {
  27. programAddress = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>,
  28. } = config;
  29. return await getProgramDerivedAddress({
  30. programAddress,
  31. seeds: [
  32. getAddressEncoder().encode(seeds.owner),
  33. getAddressEncoder().encode(seeds.tokenProgram),
  34. getAddressEncoder().encode(seeds.mint),
  35. ],
  36. });
  37. }