-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathplugin.ts
More file actions
133 lines (128 loc) · 6.13 KB
/
Copy pathplugin.ts
File metadata and controls
133 lines (128 loc) · 6.13 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { ClientWithGetMinimumBalance, ClientWithPayer, extendClient, pipe } from '@solana/kit';
import { addSelfPlanAndSendFunctions, SelfPlanAndSendFunctions } from '@solana/kit/program-client-core';
import { getBatchInstruction } from './batch';
import {
CreateMintInstructionPlanConfig,
CreateMintInstructionPlanInput,
getCreateMintInstructionPlan,
} from './createMint';
import {
CreateTokenInstructionPlanConfig,
CreateTokenInstructionPlanInput,
getCreateTokenInstructionPlan,
} from './createToken';
import {
Token2022Plugin as GeneratedToken2022Plugin,
Token2022PluginInstructions as GeneratedToken2022PluginInstructions,
Token2022PluginRequirements as GeneratedToken2022PluginRequirements,
token2022Program as generatedToken2022Program,
} from './generated';
import {
getMintToATAInstructionPlanAsync,
MintToATAInstructionPlanAsyncInput,
MintToATAInstructionPlanConfig,
} from './mintToATA';
import {
getTransferCheckedWithTransferHookInstructionAsync,
TransferCheckedWithTransferHookInstructionAsyncConfig,
TransferCheckedWithTransferHookInstructionAsyncInput,
} from './transferHookExtraAccountMetas';
import {
getTransferToATAInstructionPlanAsync,
TransferToATAInstructionPlanAsyncInput,
TransferToATAInstructionPlanConfig,
} from './transferToATA';
import { MakeOptional } from './types';
export type Token2022PluginRequirements = GeneratedToken2022PluginRequirements &
ClientWithPayer &
ClientWithGetMinimumBalance;
export type Token2022Plugin = Omit<GeneratedToken2022Plugin, 'instructions'> & {
instructions: Token2022PluginInstructions;
};
export type Token2022PluginInstructions = Omit<GeneratedToken2022PluginInstructions, 'batch'> & {
/** Batch multiple instructions into one by using other token instructions as children. */
batch: (
instructions: Parameters<typeof getBatchInstruction>[0],
config?: Parameters<typeof getBatchInstruction>[1],
) => ReturnType<typeof getBatchInstruction> & SelfPlanAndSendFunctions;
/** Create a new token mint, optionally with extensions. */
createMint: (
input: MakeOptional<CreateMintInstructionPlanInput, 'payer'>,
config?: CreateMintInstructionPlanConfig,
) => ReturnType<typeof getCreateMintInstructionPlan> & SelfPlanAndSendFunctions;
/** Create a new token account, optionally with extensions. */
createToken: (
input: MakeOptional<CreateTokenInstructionPlanInput, 'payer'>,
config?: CreateTokenInstructionPlanConfig,
) => ReturnType<typeof getCreateTokenInstructionPlan> & SelfPlanAndSendFunctions;
/** Mint tokens to an owner's ATA (created if needed). */
mintToATA: (
input: MakeOptional<MintToATAInstructionPlanAsyncInput, 'payer'>,
config?: MintToATAInstructionPlanConfig,
) => ReturnType<typeof getMintToATAInstructionPlanAsync> & SelfPlanAndSendFunctions;
/** Transfer tokens to a recipient's ATA (created if needed). */
transferToATA: (
input: MakeOptional<TransferToATAInstructionPlanAsyncInput, 'payer'>,
config?: TransferToATAInstructionPlanConfig,
) => ReturnType<typeof getTransferToATAInstructionPlanAsync> & SelfPlanAndSendFunctions;
/** Transfer tokens, appending the extra accounts the mint's transfer hook needs (if any). */
transferCheckedWithTransferHook: (
input: TransferCheckedWithTransferHookInstructionAsyncInput,
config?: TransferCheckedWithTransferHookInstructionAsyncConfig,
) => ReturnType<typeof getTransferCheckedWithTransferHookInstructionAsync> & SelfPlanAndSendFunctions;
};
export function token2022Program() {
return <T extends Token2022PluginRequirements>(client: T) => {
return pipe(client, generatedToken2022Program(), c =>
extendClient(c, {
token2022: <Token2022Plugin>{
...c.token2022,
instructions: {
...c.token2022.instructions,
batch: (input, config) =>
addSelfPlanAndSendFunctions(client, getBatchInstruction(input, config)),
createMint: (input, config) =>
addSelfPlanAndSendFunctions(
client,
getCreateMintInstructionPlan(
client,
{ ...input, payer: input.payer ?? client.payer },
config,
),
),
createToken: (input, config) =>
addSelfPlanAndSendFunctions(
client,
getCreateTokenInstructionPlan(
client,
{ ...input, payer: input.payer ?? client.payer },
config,
),
),
mintToATA: (input, config) =>
addSelfPlanAndSendFunctions(
client,
getMintToATAInstructionPlanAsync(
{ ...input, payer: input.payer ?? client.payer },
config,
),
),
transferToATA: (input, config) =>
addSelfPlanAndSendFunctions(
client,
getTransferToATAInstructionPlanAsync(
{ ...input, payer: input.payer ?? client.payer },
config,
),
),
transferCheckedWithTransferHook: (input, config) =>
addSelfPlanAndSendFunctions(
client,
getTransferCheckedWithTransferHookInstructionAsync(client, input, config),
),
},
},
}),
);
};
}