1
0

associatedToken.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * This code was AUTOGENERATED using the kinobi library.
  3. * Please DO NOT EDIT THIS FILE, instead use visitors
  4. * to add features, then rerun kinobi to update it.
  5. *
  6. * @see https://github.com/kinobi-so/kinobi
  7. */
  8. import {
  9. containsBytes,
  10. getU8Encoder,
  11. type Address,
  12. type ReadonlyUint8Array,
  13. } from '@solana/web3.js';
  14. import {
  15. type ParsedCreateAssociatedTokenIdempotentInstruction,
  16. type ParsedCreateAssociatedTokenInstruction,
  17. type ParsedRecoverNestedAssociatedTokenInstruction,
  18. } from '../instructions';
  19. export const ASSOCIATED_TOKEN_PROGRAM_ADDRESS =
  20. 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>;
  21. export enum AssociatedTokenInstruction {
  22. CreateAssociatedToken,
  23. CreateAssociatedTokenIdempotent,
  24. RecoverNestedAssociatedToken,
  25. }
  26. export function identifyAssociatedTokenInstruction(
  27. instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array
  28. ): AssociatedTokenInstruction {
  29. const data = 'data' in instruction ? instruction.data : instruction;
  30. if (containsBytes(data, getU8Encoder().encode(0), 0)) {
  31. return AssociatedTokenInstruction.CreateAssociatedToken;
  32. }
  33. if (containsBytes(data, getU8Encoder().encode(1), 0)) {
  34. return AssociatedTokenInstruction.CreateAssociatedTokenIdempotent;
  35. }
  36. if (containsBytes(data, getU8Encoder().encode(2), 0)) {
  37. return AssociatedTokenInstruction.RecoverNestedAssociatedToken;
  38. }
  39. throw new Error(
  40. 'The provided instruction could not be identified as a associatedToken instruction.'
  41. );
  42. }
  43. export type ParsedAssociatedTokenInstruction<
  44. TProgram extends string = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
  45. > =
  46. | ({
  47. instructionType: AssociatedTokenInstruction.CreateAssociatedToken;
  48. } & ParsedCreateAssociatedTokenInstruction<TProgram>)
  49. | ({
  50. instructionType: AssociatedTokenInstruction.CreateAssociatedTokenIdempotent;
  51. } & ParsedCreateAssociatedTokenIdempotentInstruction<TProgram>)
  52. | ({
  53. instructionType: AssociatedTokenInstruction.RecoverNestedAssociatedToken;
  54. } & ParsedRecoverNestedAssociatedTokenInstruction<TProgram>);