generated from codama-idl/renderers-demo
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathassociatedToken.ts
More file actions
51 lines (45 loc) · 2.14 KB
/
associatedToken.ts
File metadata and controls
51 lines (45 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
import { containsBytes, getU8Encoder, type Address, type ReadonlyUint8Array } from '@solana/kit';
import {
type ParsedCreateAssociatedTokenIdempotentInstruction,
type ParsedCreateAssociatedTokenInstruction,
type ParsedRecoverNestedAssociatedTokenInstruction,
} from '../instructions';
export const ASSOCIATED_TOKEN_PROGRAM_ADDRESS =
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>;
export enum AssociatedTokenInstruction {
CreateAssociatedToken,
CreateAssociatedTokenIdempotent,
RecoverNestedAssociatedToken,
}
export function identifyAssociatedTokenInstruction(
instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
): AssociatedTokenInstruction {
const data = 'data' in instruction ? instruction.data : instruction;
if (containsBytes(data, getU8Encoder().encode(0), 0)) {
return AssociatedTokenInstruction.CreateAssociatedToken;
}
if (containsBytes(data, getU8Encoder().encode(1), 0)) {
return AssociatedTokenInstruction.CreateAssociatedTokenIdempotent;
}
if (containsBytes(data, getU8Encoder().encode(2), 0)) {
return AssociatedTokenInstruction.RecoverNestedAssociatedToken;
}
throw new Error('The provided instruction could not be identified as a associatedToken instruction.');
}
export type ParsedAssociatedTokenInstruction<TProgram extends string = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'> =
| ({
instructionType: AssociatedTokenInstruction.CreateAssociatedToken;
} & ParsedCreateAssociatedTokenInstruction<TProgram>)
| ({
instructionType: AssociatedTokenInstruction.CreateAssociatedTokenIdempotent;
} & ParsedCreateAssociatedTokenIdempotentInstruction<TProgram>)
| ({
instructionType: AssociatedTokenInstruction.RecoverNestedAssociatedToken;
} & ParsedRecoverNestedAssociatedTokenInstruction<TProgram>);