@solana-program/system 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +7 -9
  2. package/dist/src/index.js +4 -5
  3. package/dist/src/index.js.map +1 -1
  4. package/dist/src/index.mjs +5 -6
  5. package/dist/src/index.mjs.map +1 -1
  6. package/dist/types/generated/instructions/advanceNonceAccount.d.ts +1 -1
  7. package/dist/types/generated/instructions/advanceNonceAccount.d.ts.map +1 -1
  8. package/dist/types/generated/instructions/allocate.d.ts +1 -1
  9. package/dist/types/generated/instructions/allocate.d.ts.map +1 -1
  10. package/dist/types/generated/instructions/allocateWithSeed.d.ts +1 -1
  11. package/dist/types/generated/instructions/allocateWithSeed.d.ts.map +1 -1
  12. package/dist/types/generated/instructions/assign.d.ts +1 -1
  13. package/dist/types/generated/instructions/assign.d.ts.map +1 -1
  14. package/dist/types/generated/instructions/assignWithSeed.d.ts +1 -1
  15. package/dist/types/generated/instructions/assignWithSeed.d.ts.map +1 -1
  16. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts +1 -1
  17. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts.map +1 -1
  18. package/dist/types/generated/instructions/createAccount.d.ts +1 -1
  19. package/dist/types/generated/instructions/createAccount.d.ts.map +1 -1
  20. package/dist/types/generated/instructions/createAccountWithSeed.d.ts +1 -1
  21. package/dist/types/generated/instructions/createAccountWithSeed.d.ts.map +1 -1
  22. package/dist/types/generated/instructions/initializeNonceAccount.d.ts +1 -1
  23. package/dist/types/generated/instructions/initializeNonceAccount.d.ts.map +1 -1
  24. package/dist/types/generated/instructions/transferSol.d.ts +1 -1
  25. package/dist/types/generated/instructions/transferSol.d.ts.map +1 -1
  26. package/dist/types/generated/instructions/transferSolWithSeed.d.ts +1 -1
  27. package/dist/types/generated/instructions/transferSolWithSeed.d.ts.map +1 -1
  28. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts +1 -1
  29. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts.map +1 -1
  30. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts +1 -1
  31. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts.map +1 -1
  32. package/dist/types/generated/programs/system.d.ts +1 -1
  33. package/dist/types/generated/programs/system.d.ts.map +1 -1
  34. package/package.json +31 -28
  35. package/src/generated/accounts/index.ts +9 -0
  36. package/src/generated/accounts/nonce.ts +139 -0
  37. package/src/generated/errors/index.ts +9 -0
  38. package/src/generated/errors/system.ts +77 -0
  39. package/src/generated/index.ts +13 -0
  40. package/src/generated/instructions/advanceNonceAccount.ts +186 -0
  41. package/src/generated/instructions/allocate.ts +148 -0
  42. package/src/generated/instructions/allocateWithSeed.ts +189 -0
  43. package/src/generated/instructions/assign.ts +145 -0
  44. package/src/generated/instructions/assignWithSeed.ts +177 -0
  45. package/src/generated/instructions/authorizeNonceAccount.ts +169 -0
  46. package/src/generated/instructions/createAccount.ts +184 -0
  47. package/src/generated/instructions/createAccountWithSeed.ts +221 -0
  48. package/src/generated/instructions/index.ts +21 -0
  49. package/src/generated/instructions/initializeNonceAccount.ts +202 -0
  50. package/src/generated/instructions/transferSol.ts +157 -0
  51. package/src/generated/instructions/transferSolWithSeed.ts +191 -0
  52. package/src/generated/instructions/upgradeNonceAccount.ts +135 -0
  53. package/src/generated/instructions/withdrawNonceAccount.ts +235 -0
  54. package/src/generated/programs/index.ts +9 -0
  55. package/src/generated/programs/system.ts +355 -0
  56. package/src/generated/types/index.ts +10 -0
  57. package/src/generated/types/nonceState.ts +37 -0
  58. package/src/generated/types/nonceVersion.ts +37 -0
  59. package/src/index.ts +1 -0
@@ -0,0 +1,235 @@
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
+
9
+ import {
10
+ combineCodec,
11
+ getStructDecoder,
12
+ getStructEncoder,
13
+ getU32Decoder,
14
+ getU32Encoder,
15
+ getU64Decoder,
16
+ getU64Encoder,
17
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
18
+ SolanaError,
19
+ transformEncoder,
20
+ type AccountMeta,
21
+ type AccountSignerMeta,
22
+ type Address,
23
+ type FixedSizeCodec,
24
+ type FixedSizeDecoder,
25
+ type FixedSizeEncoder,
26
+ type Instruction,
27
+ type InstructionWithAccounts,
28
+ type InstructionWithData,
29
+ type ReadonlyAccount,
30
+ type ReadonlySignerAccount,
31
+ type ReadonlyUint8Array,
32
+ type TransactionSigner,
33
+ type WritableAccount,
34
+ } from '@solana/kit';
35
+ import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
36
+ import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
37
+
38
+ export const WITHDRAW_NONCE_ACCOUNT_DISCRIMINATOR = 5;
39
+
40
+ export function getWithdrawNonceAccountDiscriminatorBytes(): ReadonlyUint8Array {
41
+ return getU32Encoder().encode(WITHDRAW_NONCE_ACCOUNT_DISCRIMINATOR);
42
+ }
43
+
44
+ export type WithdrawNonceAccountInstruction<
45
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
46
+ TAccountNonceAccount extends string | AccountMeta<string> = string,
47
+ TAccountRecipientAccount extends string | AccountMeta<string> = string,
48
+ TAccountRecentBlockhashesSysvar extends string | AccountMeta<string> =
49
+ 'SysvarRecentB1ockHashes11111111111111111111',
50
+ TAccountRentSysvar extends string | AccountMeta<string> = 'SysvarRent111111111111111111111111111111111',
51
+ TAccountNonceAuthority extends string | AccountMeta<string> = string,
52
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
53
+ > = Instruction<TProgram> &
54
+ InstructionWithData<ReadonlyUint8Array> &
55
+ InstructionWithAccounts<
56
+ [
57
+ TAccountNonceAccount extends string ? WritableAccount<TAccountNonceAccount> : TAccountNonceAccount,
58
+ TAccountRecipientAccount extends string
59
+ ? WritableAccount<TAccountRecipientAccount>
60
+ : TAccountRecipientAccount,
61
+ TAccountRecentBlockhashesSysvar extends string
62
+ ? ReadonlyAccount<TAccountRecentBlockhashesSysvar>
63
+ : TAccountRecentBlockhashesSysvar,
64
+ TAccountRentSysvar extends string ? ReadonlyAccount<TAccountRentSysvar> : TAccountRentSysvar,
65
+ TAccountNonceAuthority extends string
66
+ ? ReadonlySignerAccount<TAccountNonceAuthority> & AccountSignerMeta<TAccountNonceAuthority>
67
+ : TAccountNonceAuthority,
68
+ ...TRemainingAccounts,
69
+ ]
70
+ >;
71
+
72
+ export type WithdrawNonceAccountInstructionData = { discriminator: number; withdrawAmount: bigint };
73
+
74
+ export type WithdrawNonceAccountInstructionDataArgs = { withdrawAmount: number | bigint };
75
+
76
+ export function getWithdrawNonceAccountInstructionDataEncoder(): FixedSizeEncoder<WithdrawNonceAccountInstructionDataArgs> {
77
+ return transformEncoder(
78
+ getStructEncoder([
79
+ ['discriminator', getU32Encoder()],
80
+ ['withdrawAmount', getU64Encoder()],
81
+ ]),
82
+ value => ({ ...value, discriminator: WITHDRAW_NONCE_ACCOUNT_DISCRIMINATOR }),
83
+ );
84
+ }
85
+
86
+ export function getWithdrawNonceAccountInstructionDataDecoder(): FixedSizeDecoder<WithdrawNonceAccountInstructionData> {
87
+ return getStructDecoder([
88
+ ['discriminator', getU32Decoder()],
89
+ ['withdrawAmount', getU64Decoder()],
90
+ ]);
91
+ }
92
+
93
+ export function getWithdrawNonceAccountInstructionDataCodec(): FixedSizeCodec<
94
+ WithdrawNonceAccountInstructionDataArgs,
95
+ WithdrawNonceAccountInstructionData
96
+ > {
97
+ return combineCodec(
98
+ getWithdrawNonceAccountInstructionDataEncoder(),
99
+ getWithdrawNonceAccountInstructionDataDecoder(),
100
+ );
101
+ }
102
+
103
+ export type WithdrawNonceAccountInput<
104
+ TAccountNonceAccount extends string = string,
105
+ TAccountRecipientAccount extends string = string,
106
+ TAccountRecentBlockhashesSysvar extends string = string,
107
+ TAccountRentSysvar extends string = string,
108
+ TAccountNonceAuthority extends string = string,
109
+ > = {
110
+ nonceAccount: Address<TAccountNonceAccount>;
111
+ recipientAccount: Address<TAccountRecipientAccount>;
112
+ recentBlockhashesSysvar?: Address<TAccountRecentBlockhashesSysvar>;
113
+ rentSysvar?: Address<TAccountRentSysvar>;
114
+ nonceAuthority: TransactionSigner<TAccountNonceAuthority>;
115
+ withdrawAmount: WithdrawNonceAccountInstructionDataArgs['withdrawAmount'];
116
+ };
117
+
118
+ export function getWithdrawNonceAccountInstruction<
119
+ TAccountNonceAccount extends string,
120
+ TAccountRecipientAccount extends string,
121
+ TAccountRecentBlockhashesSysvar extends string,
122
+ TAccountRentSysvar extends string,
123
+ TAccountNonceAuthority extends string,
124
+ TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
125
+ >(
126
+ input: WithdrawNonceAccountInput<
127
+ TAccountNonceAccount,
128
+ TAccountRecipientAccount,
129
+ TAccountRecentBlockhashesSysvar,
130
+ TAccountRentSysvar,
131
+ TAccountNonceAuthority
132
+ >,
133
+ config?: { programAddress?: TProgramAddress },
134
+ ): WithdrawNonceAccountInstruction<
135
+ TProgramAddress,
136
+ TAccountNonceAccount,
137
+ TAccountRecipientAccount,
138
+ TAccountRecentBlockhashesSysvar,
139
+ TAccountRentSysvar,
140
+ TAccountNonceAuthority
141
+ > {
142
+ // Program address.
143
+ const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
144
+
145
+ // Original accounts.
146
+ const originalAccounts = {
147
+ nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
148
+ recipientAccount: { value: input.recipientAccount ?? null, isWritable: true },
149
+ recentBlockhashesSysvar: { value: input.recentBlockhashesSysvar ?? null, isWritable: false },
150
+ rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
151
+ nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false },
152
+ };
153
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
154
+
155
+ // Original args.
156
+ const args = { ...input };
157
+
158
+ // Resolve default values.
159
+ if (!accounts.recentBlockhashesSysvar.value) {
160
+ accounts.recentBlockhashesSysvar.value =
161
+ 'SysvarRecentB1ockHashes11111111111111111111' as Address<'SysvarRecentB1ockHashes11111111111111111111'>;
162
+ }
163
+ if (!accounts.rentSysvar.value) {
164
+ accounts.rentSysvar.value =
165
+ 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>;
166
+ }
167
+
168
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
169
+ return Object.freeze({
170
+ accounts: [
171
+ getAccountMeta('nonceAccount', accounts.nonceAccount),
172
+ getAccountMeta('recipientAccount', accounts.recipientAccount),
173
+ getAccountMeta('recentBlockhashesSysvar', accounts.recentBlockhashesSysvar),
174
+ getAccountMeta('rentSysvar', accounts.rentSysvar),
175
+ getAccountMeta('nonceAuthority', accounts.nonceAuthority),
176
+ ],
177
+ data: getWithdrawNonceAccountInstructionDataEncoder().encode(args as WithdrawNonceAccountInstructionDataArgs),
178
+ programAddress,
179
+ } as WithdrawNonceAccountInstruction<
180
+ TProgramAddress,
181
+ TAccountNonceAccount,
182
+ TAccountRecipientAccount,
183
+ TAccountRecentBlockhashesSysvar,
184
+ TAccountRentSysvar,
185
+ TAccountNonceAuthority
186
+ >);
187
+ }
188
+
189
+ export type ParsedWithdrawNonceAccountInstruction<
190
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
191
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
192
+ > = {
193
+ programAddress: Address<TProgram>;
194
+ accounts: {
195
+ nonceAccount: TAccountMetas[0];
196
+ recipientAccount: TAccountMetas[1];
197
+ recentBlockhashesSysvar: TAccountMetas[2];
198
+ rentSysvar: TAccountMetas[3];
199
+ nonceAuthority: TAccountMetas[4];
200
+ };
201
+ data: WithdrawNonceAccountInstructionData;
202
+ };
203
+
204
+ export function parseWithdrawNonceAccountInstruction<
205
+ TProgram extends string,
206
+ TAccountMetas extends readonly AccountMeta[],
207
+ >(
208
+ instruction: Instruction<TProgram> &
209
+ InstructionWithAccounts<TAccountMetas> &
210
+ InstructionWithData<ReadonlyUint8Array>,
211
+ ): ParsedWithdrawNonceAccountInstruction<TProgram, TAccountMetas> {
212
+ if (instruction.accounts.length < 5) {
213
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
214
+ actualAccountMetas: instruction.accounts.length,
215
+ expectedAccountMetas: 5,
216
+ });
217
+ }
218
+ let accountIndex = 0;
219
+ const getNextAccount = () => {
220
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
221
+ accountIndex += 1;
222
+ return accountMeta;
223
+ };
224
+ return {
225
+ programAddress: instruction.programAddress,
226
+ accounts: {
227
+ nonceAccount: getNextAccount(),
228
+ recipientAccount: getNextAccount(),
229
+ recentBlockhashesSysvar: getNextAccount(),
230
+ rentSysvar: getNextAccount(),
231
+ nonceAuthority: getNextAccount(),
232
+ },
233
+ data: getWithdrawNonceAccountInstructionDataDecoder().decode(instruction.data),
234
+ };
235
+ }
@@ -0,0 +1,9 @@
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
+
9
+ export * from './system';
@@ -0,0 +1,355 @@
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
+
9
+ import {
10
+ assertIsInstructionWithAccounts,
11
+ containsBytes,
12
+ extendClient,
13
+ getU32Encoder,
14
+ SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
15
+ SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
16
+ SolanaError,
17
+ type Address,
18
+ type ClientWithPayer,
19
+ type ClientWithRpc,
20
+ type ClientWithTransactionPlanning,
21
+ type ClientWithTransactionSending,
22
+ type GetAccountInfoApi,
23
+ type GetMultipleAccountsApi,
24
+ type Instruction,
25
+ type InstructionWithData,
26
+ type ReadonlyUint8Array,
27
+ } from '@solana/kit';
28
+ import {
29
+ addSelfFetchFunctions,
30
+ addSelfPlanAndSendFunctions,
31
+ type SelfFetchFunctions,
32
+ type SelfPlanAndSendFunctions,
33
+ } from '@solana/kit/program-client-core';
34
+ import { getNonceCodec, type Nonce, type NonceArgs } from '../accounts';
35
+ import {
36
+ getAdvanceNonceAccountInstruction,
37
+ getAllocateInstruction,
38
+ getAllocateWithSeedInstruction,
39
+ getAssignInstruction,
40
+ getAssignWithSeedInstruction,
41
+ getAuthorizeNonceAccountInstruction,
42
+ getCreateAccountInstruction,
43
+ getCreateAccountWithSeedInstruction,
44
+ getInitializeNonceAccountInstruction,
45
+ getTransferSolInstruction,
46
+ getTransferSolWithSeedInstruction,
47
+ getUpgradeNonceAccountInstruction,
48
+ getWithdrawNonceAccountInstruction,
49
+ parseAdvanceNonceAccountInstruction,
50
+ parseAllocateInstruction,
51
+ parseAllocateWithSeedInstruction,
52
+ parseAssignInstruction,
53
+ parseAssignWithSeedInstruction,
54
+ parseAuthorizeNonceAccountInstruction,
55
+ parseCreateAccountInstruction,
56
+ parseCreateAccountWithSeedInstruction,
57
+ parseInitializeNonceAccountInstruction,
58
+ parseTransferSolInstruction,
59
+ parseTransferSolWithSeedInstruction,
60
+ parseUpgradeNonceAccountInstruction,
61
+ parseWithdrawNonceAccountInstruction,
62
+ type AdvanceNonceAccountInput,
63
+ type AllocateInput,
64
+ type AllocateWithSeedInput,
65
+ type AssignInput,
66
+ type AssignWithSeedInput,
67
+ type AuthorizeNonceAccountInput,
68
+ type CreateAccountInput,
69
+ type CreateAccountWithSeedInput,
70
+ type InitializeNonceAccountInput,
71
+ type ParsedAdvanceNonceAccountInstruction,
72
+ type ParsedAllocateInstruction,
73
+ type ParsedAllocateWithSeedInstruction,
74
+ type ParsedAssignInstruction,
75
+ type ParsedAssignWithSeedInstruction,
76
+ type ParsedAuthorizeNonceAccountInstruction,
77
+ type ParsedCreateAccountInstruction,
78
+ type ParsedCreateAccountWithSeedInstruction,
79
+ type ParsedInitializeNonceAccountInstruction,
80
+ type ParsedTransferSolInstruction,
81
+ type ParsedTransferSolWithSeedInstruction,
82
+ type ParsedUpgradeNonceAccountInstruction,
83
+ type ParsedWithdrawNonceAccountInstruction,
84
+ type TransferSolInput,
85
+ type TransferSolWithSeedInput,
86
+ type UpgradeNonceAccountInput,
87
+ type WithdrawNonceAccountInput,
88
+ } from '../instructions';
89
+
90
+ export const SYSTEM_PROGRAM_ADDRESS = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
91
+
92
+ export enum SystemAccount {
93
+ Nonce,
94
+ }
95
+
96
+ export enum SystemInstruction {
97
+ CreateAccount,
98
+ Assign,
99
+ TransferSol,
100
+ CreateAccountWithSeed,
101
+ AdvanceNonceAccount,
102
+ WithdrawNonceAccount,
103
+ InitializeNonceAccount,
104
+ AuthorizeNonceAccount,
105
+ Allocate,
106
+ AllocateWithSeed,
107
+ AssignWithSeed,
108
+ TransferSolWithSeed,
109
+ UpgradeNonceAccount,
110
+ }
111
+
112
+ export function identifySystemInstruction(
113
+ instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
114
+ ): SystemInstruction {
115
+ const data = 'data' in instruction ? instruction.data : instruction;
116
+ if (containsBytes(data, getU32Encoder().encode(0), 0)) {
117
+ return SystemInstruction.CreateAccount;
118
+ }
119
+ if (containsBytes(data, getU32Encoder().encode(1), 0)) {
120
+ return SystemInstruction.Assign;
121
+ }
122
+ if (containsBytes(data, getU32Encoder().encode(2), 0)) {
123
+ return SystemInstruction.TransferSol;
124
+ }
125
+ if (containsBytes(data, getU32Encoder().encode(3), 0)) {
126
+ return SystemInstruction.CreateAccountWithSeed;
127
+ }
128
+ if (containsBytes(data, getU32Encoder().encode(4), 0)) {
129
+ return SystemInstruction.AdvanceNonceAccount;
130
+ }
131
+ if (containsBytes(data, getU32Encoder().encode(5), 0)) {
132
+ return SystemInstruction.WithdrawNonceAccount;
133
+ }
134
+ if (containsBytes(data, getU32Encoder().encode(6), 0)) {
135
+ return SystemInstruction.InitializeNonceAccount;
136
+ }
137
+ if (containsBytes(data, getU32Encoder().encode(7), 0)) {
138
+ return SystemInstruction.AuthorizeNonceAccount;
139
+ }
140
+ if (containsBytes(data, getU32Encoder().encode(8), 0)) {
141
+ return SystemInstruction.Allocate;
142
+ }
143
+ if (containsBytes(data, getU32Encoder().encode(9), 0)) {
144
+ return SystemInstruction.AllocateWithSeed;
145
+ }
146
+ if (containsBytes(data, getU32Encoder().encode(10), 0)) {
147
+ return SystemInstruction.AssignWithSeed;
148
+ }
149
+ if (containsBytes(data, getU32Encoder().encode(11), 0)) {
150
+ return SystemInstruction.TransferSolWithSeed;
151
+ }
152
+ if (containsBytes(data, getU32Encoder().encode(12), 0)) {
153
+ return SystemInstruction.UpgradeNonceAccount;
154
+ }
155
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, {
156
+ instructionData: data,
157
+ programName: 'system',
158
+ });
159
+ }
160
+
161
+ export type ParsedSystemInstruction<TProgram extends string = '11111111111111111111111111111111'> =
162
+ | ({ instructionType: SystemInstruction.CreateAccount } & ParsedCreateAccountInstruction<TProgram>)
163
+ | ({ instructionType: SystemInstruction.Assign } & ParsedAssignInstruction<TProgram>)
164
+ | ({ instructionType: SystemInstruction.TransferSol } & ParsedTransferSolInstruction<TProgram>)
165
+ | ({ instructionType: SystemInstruction.CreateAccountWithSeed } & ParsedCreateAccountWithSeedInstruction<TProgram>)
166
+ | ({ instructionType: SystemInstruction.AdvanceNonceAccount } & ParsedAdvanceNonceAccountInstruction<TProgram>)
167
+ | ({ instructionType: SystemInstruction.WithdrawNonceAccount } & ParsedWithdrawNonceAccountInstruction<TProgram>)
168
+ | ({
169
+ instructionType: SystemInstruction.InitializeNonceAccount;
170
+ } & ParsedInitializeNonceAccountInstruction<TProgram>)
171
+ | ({ instructionType: SystemInstruction.AuthorizeNonceAccount } & ParsedAuthorizeNonceAccountInstruction<TProgram>)
172
+ | ({ instructionType: SystemInstruction.Allocate } & ParsedAllocateInstruction<TProgram>)
173
+ | ({ instructionType: SystemInstruction.AllocateWithSeed } & ParsedAllocateWithSeedInstruction<TProgram>)
174
+ | ({ instructionType: SystemInstruction.AssignWithSeed } & ParsedAssignWithSeedInstruction<TProgram>)
175
+ | ({ instructionType: SystemInstruction.TransferSolWithSeed } & ParsedTransferSolWithSeedInstruction<TProgram>)
176
+ | ({ instructionType: SystemInstruction.UpgradeNonceAccount } & ParsedUpgradeNonceAccountInstruction<TProgram>);
177
+
178
+ export function parseSystemInstruction<TProgram extends string>(
179
+ instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
180
+ ): ParsedSystemInstruction<TProgram> {
181
+ const instructionType = identifySystemInstruction(instruction);
182
+ switch (instructionType) {
183
+ case SystemInstruction.CreateAccount: {
184
+ assertIsInstructionWithAccounts(instruction);
185
+ return { instructionType: SystemInstruction.CreateAccount, ...parseCreateAccountInstruction(instruction) };
186
+ }
187
+ case SystemInstruction.Assign: {
188
+ assertIsInstructionWithAccounts(instruction);
189
+ return { instructionType: SystemInstruction.Assign, ...parseAssignInstruction(instruction) };
190
+ }
191
+ case SystemInstruction.TransferSol: {
192
+ assertIsInstructionWithAccounts(instruction);
193
+ return { instructionType: SystemInstruction.TransferSol, ...parseTransferSolInstruction(instruction) };
194
+ }
195
+ case SystemInstruction.CreateAccountWithSeed: {
196
+ assertIsInstructionWithAccounts(instruction);
197
+ return {
198
+ instructionType: SystemInstruction.CreateAccountWithSeed,
199
+ ...parseCreateAccountWithSeedInstruction(instruction),
200
+ };
201
+ }
202
+ case SystemInstruction.AdvanceNonceAccount: {
203
+ assertIsInstructionWithAccounts(instruction);
204
+ return {
205
+ instructionType: SystemInstruction.AdvanceNonceAccount,
206
+ ...parseAdvanceNonceAccountInstruction(instruction),
207
+ };
208
+ }
209
+ case SystemInstruction.WithdrawNonceAccount: {
210
+ assertIsInstructionWithAccounts(instruction);
211
+ return {
212
+ instructionType: SystemInstruction.WithdrawNonceAccount,
213
+ ...parseWithdrawNonceAccountInstruction(instruction),
214
+ };
215
+ }
216
+ case SystemInstruction.InitializeNonceAccount: {
217
+ assertIsInstructionWithAccounts(instruction);
218
+ return {
219
+ instructionType: SystemInstruction.InitializeNonceAccount,
220
+ ...parseInitializeNonceAccountInstruction(instruction),
221
+ };
222
+ }
223
+ case SystemInstruction.AuthorizeNonceAccount: {
224
+ assertIsInstructionWithAccounts(instruction);
225
+ return {
226
+ instructionType: SystemInstruction.AuthorizeNonceAccount,
227
+ ...parseAuthorizeNonceAccountInstruction(instruction),
228
+ };
229
+ }
230
+ case SystemInstruction.Allocate: {
231
+ assertIsInstructionWithAccounts(instruction);
232
+ return { instructionType: SystemInstruction.Allocate, ...parseAllocateInstruction(instruction) };
233
+ }
234
+ case SystemInstruction.AllocateWithSeed: {
235
+ assertIsInstructionWithAccounts(instruction);
236
+ return {
237
+ instructionType: SystemInstruction.AllocateWithSeed,
238
+ ...parseAllocateWithSeedInstruction(instruction),
239
+ };
240
+ }
241
+ case SystemInstruction.AssignWithSeed: {
242
+ assertIsInstructionWithAccounts(instruction);
243
+ return {
244
+ instructionType: SystemInstruction.AssignWithSeed,
245
+ ...parseAssignWithSeedInstruction(instruction),
246
+ };
247
+ }
248
+ case SystemInstruction.TransferSolWithSeed: {
249
+ assertIsInstructionWithAccounts(instruction);
250
+ return {
251
+ instructionType: SystemInstruction.TransferSolWithSeed,
252
+ ...parseTransferSolWithSeedInstruction(instruction),
253
+ };
254
+ }
255
+ case SystemInstruction.UpgradeNonceAccount: {
256
+ assertIsInstructionWithAccounts(instruction);
257
+ return {
258
+ instructionType: SystemInstruction.UpgradeNonceAccount,
259
+ ...parseUpgradeNonceAccountInstruction(instruction),
260
+ };
261
+ }
262
+ default:
263
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, {
264
+ instructionType: instructionType as string,
265
+ programName: 'system',
266
+ });
267
+ }
268
+ }
269
+
270
+ export type SystemPlugin = { accounts: SystemPluginAccounts; instructions: SystemPluginInstructions };
271
+
272
+ export type SystemPluginAccounts = { nonce: ReturnType<typeof getNonceCodec> & SelfFetchFunctions<NonceArgs, Nonce> };
273
+
274
+ export type SystemPluginInstructions = {
275
+ createAccount: (
276
+ input: MakeOptional<CreateAccountInput, 'payer'>,
277
+ ) => ReturnType<typeof getCreateAccountInstruction> & SelfPlanAndSendFunctions;
278
+ assign: (input: AssignInput) => ReturnType<typeof getAssignInstruction> & SelfPlanAndSendFunctions;
279
+ transferSol: (input: TransferSolInput) => ReturnType<typeof getTransferSolInstruction> & SelfPlanAndSendFunctions;
280
+ createAccountWithSeed: (
281
+ input: MakeOptional<CreateAccountWithSeedInput, 'payer'>,
282
+ ) => ReturnType<typeof getCreateAccountWithSeedInstruction> & SelfPlanAndSendFunctions;
283
+ advanceNonceAccount: (
284
+ input: AdvanceNonceAccountInput,
285
+ ) => ReturnType<typeof getAdvanceNonceAccountInstruction> & SelfPlanAndSendFunctions;
286
+ withdrawNonceAccount: (
287
+ input: WithdrawNonceAccountInput,
288
+ ) => ReturnType<typeof getWithdrawNonceAccountInstruction> & SelfPlanAndSendFunctions;
289
+ initializeNonceAccount: (
290
+ input: InitializeNonceAccountInput,
291
+ ) => ReturnType<typeof getInitializeNonceAccountInstruction> & SelfPlanAndSendFunctions;
292
+ authorizeNonceAccount: (
293
+ input: AuthorizeNonceAccountInput,
294
+ ) => ReturnType<typeof getAuthorizeNonceAccountInstruction> & SelfPlanAndSendFunctions;
295
+ allocate: (input: AllocateInput) => ReturnType<typeof getAllocateInstruction> & SelfPlanAndSendFunctions;
296
+ allocateWithSeed: (
297
+ input: AllocateWithSeedInput,
298
+ ) => ReturnType<typeof getAllocateWithSeedInstruction> & SelfPlanAndSendFunctions;
299
+ assignWithSeed: (
300
+ input: AssignWithSeedInput,
301
+ ) => ReturnType<typeof getAssignWithSeedInstruction> & SelfPlanAndSendFunctions;
302
+ transferSolWithSeed: (
303
+ input: TransferSolWithSeedInput,
304
+ ) => ReturnType<typeof getTransferSolWithSeedInstruction> & SelfPlanAndSendFunctions;
305
+ upgradeNonceAccount: (
306
+ input: UpgradeNonceAccountInput,
307
+ ) => ReturnType<typeof getUpgradeNonceAccountInstruction> & SelfPlanAndSendFunctions;
308
+ };
309
+
310
+ export type SystemPluginRequirements = ClientWithRpc<GetAccountInfoApi & GetMultipleAccountsApi> &
311
+ ClientWithPayer &
312
+ ClientWithTransactionPlanning &
313
+ ClientWithTransactionSending;
314
+
315
+ export function systemProgram() {
316
+ return <T extends SystemPluginRequirements>(client: T): Omit<T, 'system'> & { system: SystemPlugin } => {
317
+ return extendClient(client, {
318
+ system: <SystemPlugin>{
319
+ accounts: { nonce: addSelfFetchFunctions(client, getNonceCodec()) },
320
+ instructions: {
321
+ createAccount: input =>
322
+ addSelfPlanAndSendFunctions(
323
+ client,
324
+ getCreateAccountInstruction({ ...input, payer: input.payer ?? client.payer }),
325
+ ),
326
+ assign: input => addSelfPlanAndSendFunctions(client, getAssignInstruction(input)),
327
+ transferSol: input => addSelfPlanAndSendFunctions(client, getTransferSolInstruction(input)),
328
+ createAccountWithSeed: input =>
329
+ addSelfPlanAndSendFunctions(
330
+ client,
331
+ getCreateAccountWithSeedInstruction({ ...input, payer: input.payer ?? client.payer }),
332
+ ),
333
+ advanceNonceAccount: input =>
334
+ addSelfPlanAndSendFunctions(client, getAdvanceNonceAccountInstruction(input)),
335
+ withdrawNonceAccount: input =>
336
+ addSelfPlanAndSendFunctions(client, getWithdrawNonceAccountInstruction(input)),
337
+ initializeNonceAccount: input =>
338
+ addSelfPlanAndSendFunctions(client, getInitializeNonceAccountInstruction(input)),
339
+ authorizeNonceAccount: input =>
340
+ addSelfPlanAndSendFunctions(client, getAuthorizeNonceAccountInstruction(input)),
341
+ allocate: input => addSelfPlanAndSendFunctions(client, getAllocateInstruction(input)),
342
+ allocateWithSeed: input =>
343
+ addSelfPlanAndSendFunctions(client, getAllocateWithSeedInstruction(input)),
344
+ assignWithSeed: input => addSelfPlanAndSendFunctions(client, getAssignWithSeedInstruction(input)),
345
+ transferSolWithSeed: input =>
346
+ addSelfPlanAndSendFunctions(client, getTransferSolWithSeedInstruction(input)),
347
+ upgradeNonceAccount: input =>
348
+ addSelfPlanAndSendFunctions(client, getUpgradeNonceAccountInstruction(input)),
349
+ },
350
+ },
351
+ });
352
+ };
353
+ }
354
+
355
+ type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
@@ -0,0 +1,10 @@
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
+
9
+ export * from './nonceState';
10
+ export * from './nonceVersion';
@@ -0,0 +1,37 @@
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
+
9
+ import {
10
+ combineCodec,
11
+ getEnumDecoder,
12
+ getEnumEncoder,
13
+ getU32Decoder,
14
+ getU32Encoder,
15
+ type FixedSizeCodec,
16
+ type FixedSizeDecoder,
17
+ type FixedSizeEncoder,
18
+ } from '@solana/kit';
19
+
20
+ export enum NonceState {
21
+ Uninitialized,
22
+ Initialized,
23
+ }
24
+
25
+ export type NonceStateArgs = NonceState;
26
+
27
+ export function getNonceStateEncoder(): FixedSizeEncoder<NonceStateArgs> {
28
+ return getEnumEncoder(NonceState, { size: getU32Encoder() });
29
+ }
30
+
31
+ export function getNonceStateDecoder(): FixedSizeDecoder<NonceState> {
32
+ return getEnumDecoder(NonceState, { size: getU32Decoder() });
33
+ }
34
+
35
+ export function getNonceStateCodec(): FixedSizeCodec<NonceStateArgs, NonceState> {
36
+ return combineCodec(getNonceStateEncoder(), getNonceStateDecoder());
37
+ }
@@ -0,0 +1,37 @@
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
+
9
+ import {
10
+ combineCodec,
11
+ getEnumDecoder,
12
+ getEnumEncoder,
13
+ getU32Decoder,
14
+ getU32Encoder,
15
+ type FixedSizeCodec,
16
+ type FixedSizeDecoder,
17
+ type FixedSizeEncoder,
18
+ } from '@solana/kit';
19
+
20
+ export enum NonceVersion {
21
+ Legacy,
22
+ Current,
23
+ }
24
+
25
+ export type NonceVersionArgs = NonceVersion;
26
+
27
+ export function getNonceVersionEncoder(): FixedSizeEncoder<NonceVersionArgs> {
28
+ return getEnumEncoder(NonceVersion, { size: getU32Encoder() });
29
+ }
30
+
31
+ export function getNonceVersionDecoder(): FixedSizeDecoder<NonceVersion> {
32
+ return getEnumDecoder(NonceVersion, { size: getU32Decoder() });
33
+ }
34
+
35
+ export function getNonceVersionCodec(): FixedSizeCodec<NonceVersionArgs, NonceVersion> {
36
+ return combineCodec(getNonceVersionEncoder(), getNonceVersionDecoder());
37
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './generated';