@solana-program/system 0.10.0 → 0.12.0

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 (40) hide show
  1. package/dist/src/index.js +369 -365
  2. package/dist/src/index.js.map +1 -1
  3. package/dist/src/index.mjs +369 -367
  4. package/dist/src/index.mjs.map +1 -1
  5. package/dist/types/generated/accounts/nonce.d.ts +3 -0
  6. package/dist/types/generated/accounts/nonce.d.ts.map +1 -1
  7. package/dist/types/generated/errors/system.d.ts.map +1 -1
  8. package/dist/types/generated/instructions/advanceNonceAccount.d.ts +1 -1
  9. package/dist/types/generated/instructions/advanceNonceAccount.d.ts.map +1 -1
  10. package/dist/types/generated/instructions/allocate.d.ts +1 -1
  11. package/dist/types/generated/instructions/allocate.d.ts.map +1 -1
  12. package/dist/types/generated/instructions/allocateWithSeed.d.ts +1 -1
  13. package/dist/types/generated/instructions/allocateWithSeed.d.ts.map +1 -1
  14. package/dist/types/generated/instructions/assign.d.ts +1 -1
  15. package/dist/types/generated/instructions/assign.d.ts.map +1 -1
  16. package/dist/types/generated/instructions/assignWithSeed.d.ts +1 -1
  17. package/dist/types/generated/instructions/assignWithSeed.d.ts.map +1 -1
  18. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts +1 -1
  19. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts.map +1 -1
  20. package/dist/types/generated/instructions/createAccount.d.ts +2 -2
  21. package/dist/types/generated/instructions/createAccount.d.ts.map +1 -1
  22. package/dist/types/generated/instructions/createAccountWithSeed.d.ts +1 -1
  23. package/dist/types/generated/instructions/createAccountWithSeed.d.ts.map +1 -1
  24. package/dist/types/generated/instructions/initializeNonceAccount.d.ts +1 -1
  25. package/dist/types/generated/instructions/initializeNonceAccount.d.ts.map +1 -1
  26. package/dist/types/generated/instructions/transferSol.d.ts +1 -1
  27. package/dist/types/generated/instructions/transferSol.d.ts.map +1 -1
  28. package/dist/types/generated/instructions/transferSolWithSeed.d.ts +1 -1
  29. package/dist/types/generated/instructions/transferSolWithSeed.d.ts.map +1 -1
  30. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts +1 -1
  31. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts.map +1 -1
  32. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts +1 -1
  33. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts.map +1 -1
  34. package/dist/types/generated/programs/system.d.ts +33 -2
  35. package/dist/types/generated/programs/system.d.ts.map +1 -1
  36. package/dist/types/generated/types/nonceState.d.ts.map +1 -1
  37. package/dist/types/generated/types/nonceVersion.d.ts.map +1 -1
  38. package/package.json +15 -27
  39. package/dist/types/generated/shared/index.d.ts +0 -50
  40. package/dist/types/generated/shared/index.d.ts.map +0 -1
package/dist/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var kit = require('@solana/kit');
4
+ var programClientCore = require('@solana/kit/program-client-core');
4
5
 
5
6
  // src/generated/accounts/nonce.ts
6
7
  var NonceState = /* @__PURE__ */ ((NonceState2) => {
@@ -55,10 +56,7 @@ function getNonceCodec() {
55
56
  return kit.combineCodec(getNonceEncoder(), getNonceDecoder());
56
57
  }
57
58
  function decodeNonce(encodedAccount) {
58
- return kit.decodeAccount(
59
- encodedAccount,
60
- getNonceDecoder()
61
- );
59
+ return kit.decodeAccount(encodedAccount, getNonceDecoder());
62
60
  }
63
61
  async function fetchNonce(rpc, address, config) {
64
62
  const maybeAccount = await fetchMaybeNonce(rpc, address, config);
@@ -81,183 +79,39 @@ async function fetchAllMaybeNonce(rpc, addresses, config) {
81
79
  function getNonceSize() {
82
80
  return 80;
83
81
  }
84
- var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
85
- var SystemAccount = /* @__PURE__ */ ((SystemAccount2) => {
86
- SystemAccount2[SystemAccount2["Nonce"] = 0] = "Nonce";
87
- return SystemAccount2;
88
- })(SystemAccount || {});
89
- var SystemInstruction = /* @__PURE__ */ ((SystemInstruction2) => {
90
- SystemInstruction2[SystemInstruction2["CreateAccount"] = 0] = "CreateAccount";
91
- SystemInstruction2[SystemInstruction2["Assign"] = 1] = "Assign";
92
- SystemInstruction2[SystemInstruction2["TransferSol"] = 2] = "TransferSol";
93
- SystemInstruction2[SystemInstruction2["CreateAccountWithSeed"] = 3] = "CreateAccountWithSeed";
94
- SystemInstruction2[SystemInstruction2["AdvanceNonceAccount"] = 4] = "AdvanceNonceAccount";
95
- SystemInstruction2[SystemInstruction2["WithdrawNonceAccount"] = 5] = "WithdrawNonceAccount";
96
- SystemInstruction2[SystemInstruction2["InitializeNonceAccount"] = 6] = "InitializeNonceAccount";
97
- SystemInstruction2[SystemInstruction2["AuthorizeNonceAccount"] = 7] = "AuthorizeNonceAccount";
98
- SystemInstruction2[SystemInstruction2["Allocate"] = 8] = "Allocate";
99
- SystemInstruction2[SystemInstruction2["AllocateWithSeed"] = 9] = "AllocateWithSeed";
100
- SystemInstruction2[SystemInstruction2["AssignWithSeed"] = 10] = "AssignWithSeed";
101
- SystemInstruction2[SystemInstruction2["TransferSolWithSeed"] = 11] = "TransferSolWithSeed";
102
- SystemInstruction2[SystemInstruction2["UpgradeNonceAccount"] = 12] = "UpgradeNonceAccount";
103
- return SystemInstruction2;
104
- })(SystemInstruction || {});
105
- function identifySystemInstruction(instruction) {
106
- const data = "data" in instruction ? instruction.data : instruction;
107
- if (kit.containsBytes(data, kit.getU32Encoder().encode(0), 0)) {
108
- return 0 /* CreateAccount */;
109
- }
110
- if (kit.containsBytes(data, kit.getU32Encoder().encode(1), 0)) {
111
- return 1 /* Assign */;
112
- }
113
- if (kit.containsBytes(data, kit.getU32Encoder().encode(2), 0)) {
114
- return 2 /* TransferSol */;
115
- }
116
- if (kit.containsBytes(data, kit.getU32Encoder().encode(3), 0)) {
117
- return 3 /* CreateAccountWithSeed */;
118
- }
119
- if (kit.containsBytes(data, kit.getU32Encoder().encode(4), 0)) {
120
- return 4 /* AdvanceNonceAccount */;
121
- }
122
- if (kit.containsBytes(data, kit.getU32Encoder().encode(5), 0)) {
123
- return 5 /* WithdrawNonceAccount */;
124
- }
125
- if (kit.containsBytes(data, kit.getU32Encoder().encode(6), 0)) {
126
- return 6 /* InitializeNonceAccount */;
127
- }
128
- if (kit.containsBytes(data, kit.getU32Encoder().encode(7), 0)) {
129
- return 7 /* AuthorizeNonceAccount */;
130
- }
131
- if (kit.containsBytes(data, kit.getU32Encoder().encode(8), 0)) {
132
- return 8 /* Allocate */;
133
- }
134
- if (kit.containsBytes(data, kit.getU32Encoder().encode(9), 0)) {
135
- return 9 /* AllocateWithSeed */;
136
- }
137
- if (kit.containsBytes(data, kit.getU32Encoder().encode(10), 0)) {
138
- return 10 /* AssignWithSeed */;
139
- }
140
- if (kit.containsBytes(data, kit.getU32Encoder().encode(11), 0)) {
141
- return 11 /* TransferSolWithSeed */;
142
- }
143
- if (kit.containsBytes(data, kit.getU32Encoder().encode(12), 0)) {
144
- return 12 /* UpgradeNonceAccount */;
145
- }
146
- throw new Error(
147
- "The provided instruction could not be identified as a system instruction."
148
- );
149
- }
150
-
151
- // src/generated/errors/system.ts
152
- var SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE = 0;
153
- var SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS = 1;
154
- var SYSTEM_ERROR__INVALID_PROGRAM_ID = 2;
155
- var SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH = 3;
156
- var SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED = 4;
157
- var SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH = 5;
158
- var SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES = 6;
159
- var SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED = 7;
160
- var SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE = 8;
161
- var systemErrorMessages;
162
- if (process.env.NODE_ENV !== "production") {
163
- systemErrorMessages = {
164
- [SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE]: `an account with the same address already exists`,
165
- [SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH]: `provided address does not match addressed derived from seed`,
166
- [SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH]: `cannot allocate account data of this length`,
167
- [SYSTEM_ERROR__INVALID_PROGRAM_ID]: `cannot assign account to this program id`,
168
- [SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED]: `length of requested seed is too long`,
169
- [SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED]: `stored nonce is still in recent_blockhashes`,
170
- [SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES]: `advancing stored nonce requires a populated RecentBlockhashes sysvar`,
171
- [SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE]: `specified nonce does not match stored nonce`,
172
- [SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS]: `account does not have enough SOL to perform the operation`
173
- };
174
- }
175
- function getSystemErrorMessage(code) {
176
- if (process.env.NODE_ENV !== "production") {
177
- return systemErrorMessages[code];
178
- }
179
- return "Error message not available in production bundles.";
180
- }
181
- function isSystemError(error, transactionMessage, code) {
182
- return kit.isProgramError(
183
- error,
184
- transactionMessage,
185
- SYSTEM_PROGRAM_ADDRESS,
186
- code
187
- );
188
- }
189
- function expectAddress(value) {
190
- if (!value) {
191
- throw new Error("Expected a Address.");
192
- }
193
- if (typeof value === "object" && "address" in value) {
194
- return value.address;
195
- }
196
- if (Array.isArray(value)) {
197
- return value[0];
198
- }
199
- return value;
200
- }
201
- function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
202
- return (account) => {
203
- if (!account.value) {
204
- return;
205
- }
206
- const writableRole = account.isWritable ? kit.AccountRole.WRITABLE : kit.AccountRole.READONLY;
207
- return Object.freeze({
208
- address: expectAddress(account.value),
209
- role: isTransactionSigner(account.value) ? kit.upgradeRoleToSigner(writableRole) : writableRole,
210
- ...isTransactionSigner(account.value) ? { signer: account.value } : {}
211
- });
212
- };
213
- }
214
- function isTransactionSigner(value) {
215
- return !!value && typeof value === "object" && "address" in value && kit.isTransactionSigner(value);
216
- }
217
-
218
- // src/generated/instructions/advanceNonceAccount.ts
219
82
  var ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR = 4;
220
83
  function getAdvanceNonceAccountDiscriminatorBytes() {
221
84
  return kit.getU32Encoder().encode(ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR);
222
85
  }
223
86
  function getAdvanceNonceAccountInstructionDataEncoder() {
224
- return kit.transformEncoder(
225
- kit.getStructEncoder([["discriminator", kit.getU32Encoder()]]),
226
- (value) => ({
227
- ...value,
228
- discriminator: ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR
229
- })
230
- );
87
+ return kit.transformEncoder(kit.getStructEncoder([["discriminator", kit.getU32Encoder()]]), (value) => ({
88
+ ...value,
89
+ discriminator: ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR
90
+ }));
231
91
  }
232
92
  function getAdvanceNonceAccountInstructionDataDecoder() {
233
93
  return kit.getStructDecoder([["discriminator", kit.getU32Decoder()]]);
234
94
  }
235
95
  function getAdvanceNonceAccountInstructionDataCodec() {
236
- return kit.combineCodec(
237
- getAdvanceNonceAccountInstructionDataEncoder(),
238
- getAdvanceNonceAccountInstructionDataDecoder()
239
- );
96
+ return kit.combineCodec(getAdvanceNonceAccountInstructionDataEncoder(), getAdvanceNonceAccountInstructionDataDecoder());
240
97
  }
241
98
  function getAdvanceNonceAccountInstruction(input, config) {
242
99
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
243
100
  const originalAccounts = {
244
101
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
245
- recentBlockhashesSysvar: {
246
- value: input.recentBlockhashesSysvar ?? null,
247
- isWritable: false
248
- },
102
+ recentBlockhashesSysvar: { value: input.recentBlockhashesSysvar ?? null, isWritable: false },
249
103
  nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false }
250
104
  };
251
105
  const accounts = originalAccounts;
252
106
  if (!accounts.recentBlockhashesSysvar.value) {
253
107
  accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
254
108
  }
255
- const getAccountMeta = getAccountMetaFactory();
109
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
256
110
  return Object.freeze({
257
111
  accounts: [
258
- getAccountMeta(accounts.nonceAccount),
259
- getAccountMeta(accounts.recentBlockhashesSysvar),
260
- getAccountMeta(accounts.nonceAuthority)
112
+ getAccountMeta("nonceAccount", accounts.nonceAccount),
113
+ getAccountMeta("recentBlockhashesSysvar", accounts.recentBlockhashesSysvar),
114
+ getAccountMeta("nonceAuthority", accounts.nonceAuthority)
261
115
  ],
262
116
  data: getAdvanceNonceAccountInstructionDataEncoder().encode({}),
263
117
  programAddress
@@ -265,7 +119,10 @@ function getAdvanceNonceAccountInstruction(input, config) {
265
119
  }
266
120
  function parseAdvanceNonceAccountInstruction(instruction) {
267
121
  if (instruction.accounts.length < 3) {
268
- throw new Error("Not enough accounts");
122
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
123
+ actualAccountMetas: instruction.accounts.length,
124
+ expectedAccountMetas: 3
125
+ });
269
126
  }
270
127
  let accountIndex = 0;
271
128
  const getNextAccount = () => {
@@ -280,9 +137,7 @@ function parseAdvanceNonceAccountInstruction(instruction) {
280
137
  recentBlockhashesSysvar: getNextAccount(),
281
138
  nonceAuthority: getNextAccount()
282
139
  },
283
- data: getAdvanceNonceAccountInstructionDataDecoder().decode(
284
- instruction.data
285
- )
140
+ data: getAdvanceNonceAccountInstructionDataDecoder().decode(instruction.data)
286
141
  };
287
142
  }
288
143
  var ALLOCATE_DISCRIMINATOR = 8;
@@ -305,30 +160,26 @@ function getAllocateInstructionDataDecoder() {
305
160
  ]);
306
161
  }
307
162
  function getAllocateInstructionDataCodec() {
308
- return kit.combineCodec(
309
- getAllocateInstructionDataEncoder(),
310
- getAllocateInstructionDataDecoder()
311
- );
163
+ return kit.combineCodec(getAllocateInstructionDataEncoder(), getAllocateInstructionDataDecoder());
312
164
  }
313
165
  function getAllocateInstruction(input, config) {
314
166
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
315
- const originalAccounts = {
316
- newAccount: { value: input.newAccount ?? null, isWritable: true }
317
- };
167
+ const originalAccounts = { newAccount: { value: input.newAccount ?? null, isWritable: true } };
318
168
  const accounts = originalAccounts;
319
169
  const args = { ...input };
320
- const getAccountMeta = getAccountMetaFactory();
170
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
321
171
  return Object.freeze({
322
- accounts: [getAccountMeta(accounts.newAccount)],
323
- data: getAllocateInstructionDataEncoder().encode(
324
- args
325
- ),
172
+ accounts: [getAccountMeta("newAccount", accounts.newAccount)],
173
+ data: getAllocateInstructionDataEncoder().encode(args),
326
174
  programAddress
327
175
  });
328
176
  }
329
177
  function parseAllocateInstruction(instruction) {
330
178
  if (instruction.accounts.length < 1) {
331
- throw new Error("Not enough accounts");
179
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
180
+ actualAccountMetas: instruction.accounts.length,
181
+ expectedAccountMetas: 1
182
+ });
332
183
  }
333
184
  let accountIndex = 0;
334
185
  const getNextAccount = () => {
@@ -368,10 +219,7 @@ function getAllocateWithSeedInstructionDataDecoder() {
368
219
  ]);
369
220
  }
370
221
  function getAllocateWithSeedInstructionDataCodec() {
371
- return kit.combineCodec(
372
- getAllocateWithSeedInstructionDataEncoder(),
373
- getAllocateWithSeedInstructionDataDecoder()
374
- );
222
+ return kit.combineCodec(getAllocateWithSeedInstructionDataEncoder(), getAllocateWithSeedInstructionDataDecoder());
375
223
  }
376
224
  function getAllocateWithSeedInstruction(input, config) {
377
225
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
@@ -381,21 +229,22 @@ function getAllocateWithSeedInstruction(input, config) {
381
229
  };
382
230
  const accounts = originalAccounts;
383
231
  const args = { ...input };
384
- const getAccountMeta = getAccountMetaFactory();
232
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
385
233
  return Object.freeze({
386
234
  accounts: [
387
- getAccountMeta(accounts.newAccount),
388
- getAccountMeta(accounts.baseAccount)
235
+ getAccountMeta("newAccount", accounts.newAccount),
236
+ getAccountMeta("baseAccount", accounts.baseAccount)
389
237
  ],
390
- data: getAllocateWithSeedInstructionDataEncoder().encode(
391
- args
392
- ),
238
+ data: getAllocateWithSeedInstructionDataEncoder().encode(args),
393
239
  programAddress
394
240
  });
395
241
  }
396
242
  function parseAllocateWithSeedInstruction(instruction) {
397
243
  if (instruction.accounts.length < 2) {
398
- throw new Error("Not enough accounts");
244
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
245
+ actualAccountMetas: instruction.accounts.length,
246
+ expectedAccountMetas: 2
247
+ });
399
248
  }
400
249
  let accountIndex = 0;
401
250
  const getNextAccount = () => {
@@ -429,30 +278,26 @@ function getAssignInstructionDataDecoder() {
429
278
  ]);
430
279
  }
431
280
  function getAssignInstructionDataCodec() {
432
- return kit.combineCodec(
433
- getAssignInstructionDataEncoder(),
434
- getAssignInstructionDataDecoder()
435
- );
281
+ return kit.combineCodec(getAssignInstructionDataEncoder(), getAssignInstructionDataDecoder());
436
282
  }
437
283
  function getAssignInstruction(input, config) {
438
284
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
439
- const originalAccounts = {
440
- account: { value: input.account ?? null, isWritable: true }
441
- };
285
+ const originalAccounts = { account: { value: input.account ?? null, isWritable: true } };
442
286
  const accounts = originalAccounts;
443
287
  const args = { ...input };
444
- const getAccountMeta = getAccountMetaFactory();
288
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
445
289
  return Object.freeze({
446
- accounts: [getAccountMeta(accounts.account)],
447
- data: getAssignInstructionDataEncoder().encode(
448
- args
449
- ),
290
+ accounts: [getAccountMeta("account", accounts.account)],
291
+ data: getAssignInstructionDataEncoder().encode(args),
450
292
  programAddress
451
293
  });
452
294
  }
453
295
  function parseAssignInstruction(instruction) {
454
296
  if (instruction.accounts.length < 1) {
455
- throw new Error("Not enough accounts");
297
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
298
+ actualAccountMetas: instruction.accounts.length,
299
+ expectedAccountMetas: 1
300
+ });
456
301
  }
457
302
  let accountIndex = 0;
458
303
  const getNextAccount = () => {
@@ -490,10 +335,7 @@ function getAssignWithSeedInstructionDataDecoder() {
490
335
  ]);
491
336
  }
492
337
  function getAssignWithSeedInstructionDataCodec() {
493
- return kit.combineCodec(
494
- getAssignWithSeedInstructionDataEncoder(),
495
- getAssignWithSeedInstructionDataDecoder()
496
- );
338
+ return kit.combineCodec(getAssignWithSeedInstructionDataEncoder(), getAssignWithSeedInstructionDataDecoder());
497
339
  }
498
340
  function getAssignWithSeedInstruction(input, config) {
499
341
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
@@ -503,21 +345,19 @@ function getAssignWithSeedInstruction(input, config) {
503
345
  };
504
346
  const accounts = originalAccounts;
505
347
  const args = { ...input };
506
- const getAccountMeta = getAccountMetaFactory();
348
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
507
349
  return Object.freeze({
508
- accounts: [
509
- getAccountMeta(accounts.account),
510
- getAccountMeta(accounts.baseAccount)
511
- ],
512
- data: getAssignWithSeedInstructionDataEncoder().encode(
513
- args
514
- ),
350
+ accounts: [getAccountMeta("account", accounts.account), getAccountMeta("baseAccount", accounts.baseAccount)],
351
+ data: getAssignWithSeedInstructionDataEncoder().encode(args),
515
352
  programAddress
516
353
  });
517
354
  }
518
355
  function parseAssignWithSeedInstruction(instruction) {
519
356
  if (instruction.accounts.length < 2) {
520
- throw new Error("Not enough accounts");
357
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
358
+ actualAccountMetas: instruction.accounts.length,
359
+ expectedAccountMetas: 2
360
+ });
521
361
  }
522
362
  let accountIndex = 0;
523
363
  const getNextAccount = () => {
@@ -541,10 +381,7 @@ function getAuthorizeNonceAccountInstructionDataEncoder() {
541
381
  ["discriminator", kit.getU32Encoder()],
542
382
  ["newNonceAuthority", kit.getAddressEncoder()]
543
383
  ]),
544
- (value) => ({
545
- ...value,
546
- discriminator: AUTHORIZE_NONCE_ACCOUNT_DISCRIMINATOR
547
- })
384
+ (value) => ({ ...value, discriminator: AUTHORIZE_NONCE_ACCOUNT_DISCRIMINATOR })
548
385
  );
549
386
  }
550
387
  function getAuthorizeNonceAccountInstructionDataDecoder() {
@@ -567,21 +404,22 @@ function getAuthorizeNonceAccountInstruction(input, config) {
567
404
  };
568
405
  const accounts = originalAccounts;
569
406
  const args = { ...input };
570
- const getAccountMeta = getAccountMetaFactory();
407
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
571
408
  return Object.freeze({
572
409
  accounts: [
573
- getAccountMeta(accounts.nonceAccount),
574
- getAccountMeta(accounts.nonceAuthority)
410
+ getAccountMeta("nonceAccount", accounts.nonceAccount),
411
+ getAccountMeta("nonceAuthority", accounts.nonceAuthority)
575
412
  ],
576
- data: getAuthorizeNonceAccountInstructionDataEncoder().encode(
577
- args
578
- ),
413
+ data: getAuthorizeNonceAccountInstructionDataEncoder().encode(args),
579
414
  programAddress
580
415
  });
581
416
  }
582
417
  function parseAuthorizeNonceAccountInstruction(instruction) {
583
418
  if (instruction.accounts.length < 2) {
584
- throw new Error("Not enough accounts");
419
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
420
+ actualAccountMetas: instruction.accounts.length,
421
+ expectedAccountMetas: 2
422
+ });
585
423
  }
586
424
  let accountIndex = 0;
587
425
  const getNextAccount = () => {
@@ -591,13 +429,8 @@ function parseAuthorizeNonceAccountInstruction(instruction) {
591
429
  };
592
430
  return {
593
431
  programAddress: instruction.programAddress,
594
- accounts: {
595
- nonceAccount: getNextAccount(),
596
- nonceAuthority: getNextAccount()
597
- },
598
- data: getAuthorizeNonceAccountInstructionDataDecoder().decode(
599
- instruction.data
600
- )
432
+ accounts: { nonceAccount: getNextAccount(), nonceAuthority: getNextAccount() },
433
+ data: getAuthorizeNonceAccountInstructionDataDecoder().decode(instruction.data)
601
434
  };
602
435
  }
603
436
  var CREATE_ACCOUNT_DISCRIMINATOR = 0;
@@ -624,10 +457,7 @@ function getCreateAccountInstructionDataDecoder() {
624
457
  ]);
625
458
  }
626
459
  function getCreateAccountInstructionDataCodec() {
627
- return kit.combineCodec(
628
- getCreateAccountInstructionDataEncoder(),
629
- getCreateAccountInstructionDataDecoder()
630
- );
460
+ return kit.combineCodec(getCreateAccountInstructionDataEncoder(), getCreateAccountInstructionDataDecoder());
631
461
  }
632
462
  function getCreateAccountInstruction(input, config) {
633
463
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
@@ -637,26 +467,21 @@ function getCreateAccountInstruction(input, config) {
637
467
  };
638
468
  const accounts = originalAccounts;
639
469
  const args = { ...input };
640
- const byteDelta = [Number(args.space) + kit.BASE_ACCOUNT_SIZE].reduce(
641
- (a, b) => a + b,
642
- 0
643
- );
644
- const getAccountMeta = getAccountMetaFactory();
470
+ const byteDelta = [Number(args.space) + kit.BASE_ACCOUNT_SIZE].reduce((a, b) => a + b, 0);
471
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
645
472
  return Object.freeze({
646
- accounts: [
647
- getAccountMeta(accounts.payer),
648
- getAccountMeta(accounts.newAccount)
649
- ],
473
+ accounts: [getAccountMeta("payer", accounts.payer), getAccountMeta("newAccount", accounts.newAccount)],
650
474
  byteDelta,
651
- data: getCreateAccountInstructionDataEncoder().encode(
652
- args
653
- ),
475
+ data: getCreateAccountInstructionDataEncoder().encode(args),
654
476
  programAddress
655
477
  });
656
478
  }
657
479
  function parseCreateAccountInstruction(instruction) {
658
480
  if (instruction.accounts.length < 2) {
659
- throw new Error("Not enough accounts");
481
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
482
+ actualAccountMetas: instruction.accounts.length,
483
+ expectedAccountMetas: 2
484
+ });
660
485
  }
661
486
  let accountIndex = 0;
662
487
  const getNextAccount = () => {
@@ -684,10 +509,7 @@ function getCreateAccountWithSeedInstructionDataEncoder() {
684
509
  ["space", kit.getU64Encoder()],
685
510
  ["programAddress", kit.getAddressEncoder()]
686
511
  ]),
687
- (value) => ({
688
- ...value,
689
- discriminator: CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR
690
- })
512
+ (value) => ({ ...value, discriminator: CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR })
691
513
  );
692
514
  }
693
515
  function getCreateAccountWithSeedInstructionDataDecoder() {
@@ -715,22 +537,23 @@ function getCreateAccountWithSeedInstruction(input, config) {
715
537
  };
716
538
  const accounts = originalAccounts;
717
539
  const args = { ...input };
718
- const getAccountMeta = getAccountMetaFactory();
540
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
719
541
  return Object.freeze({
720
542
  accounts: [
721
- getAccountMeta(accounts.payer),
722
- getAccountMeta(accounts.newAccount),
723
- getAccountMeta(accounts.baseAccount)
543
+ getAccountMeta("payer", accounts.payer),
544
+ getAccountMeta("newAccount", accounts.newAccount),
545
+ getAccountMeta("baseAccount", accounts.baseAccount)
724
546
  ].filter((x) => x !== void 0),
725
- data: getCreateAccountWithSeedInstructionDataEncoder().encode(
726
- args
727
- ),
547
+ data: getCreateAccountWithSeedInstructionDataEncoder().encode(args),
728
548
  programAddress
729
549
  });
730
550
  }
731
551
  function parseCreateAccountWithSeedInstruction(instruction) {
732
552
  if (instruction.accounts.length < 2) {
733
- throw new Error("Not enough accounts");
553
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
554
+ actualAccountMetas: instruction.accounts.length,
555
+ expectedAccountMetas: 2
556
+ });
734
557
  }
735
558
  let accountIndex = 0;
736
559
  const getNextAccount = () => {
@@ -746,14 +569,8 @@ function parseCreateAccountWithSeedInstruction(instruction) {
746
569
  };
747
570
  return {
748
571
  programAddress: instruction.programAddress,
749
- accounts: {
750
- payer: getNextAccount(),
751
- newAccount: getNextAccount(),
752
- baseAccount: getNextOptionalAccount()
753
- },
754
- data: getCreateAccountWithSeedInstructionDataDecoder().decode(
755
- instruction.data
756
- )
572
+ accounts: { payer: getNextAccount(), newAccount: getNextAccount(), baseAccount: getNextOptionalAccount() },
573
+ data: getCreateAccountWithSeedInstructionDataDecoder().decode(instruction.data)
757
574
  };
758
575
  }
759
576
  var INITIALIZE_NONCE_ACCOUNT_DISCRIMINATOR = 6;
@@ -766,10 +583,7 @@ function getInitializeNonceAccountInstructionDataEncoder() {
766
583
  ["discriminator", kit.getU32Encoder()],
767
584
  ["nonceAuthority", kit.getAddressEncoder()]
768
585
  ]),
769
- (value) => ({
770
- ...value,
771
- discriminator: INITIALIZE_NONCE_ACCOUNT_DISCRIMINATOR
772
- })
586
+ (value) => ({ ...value, discriminator: INITIALIZE_NONCE_ACCOUNT_DISCRIMINATOR })
773
587
  );
774
588
  }
775
589
  function getInitializeNonceAccountInstructionDataDecoder() {
@@ -788,10 +602,7 @@ function getInitializeNonceAccountInstruction(input, config) {
788
602
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
789
603
  const originalAccounts = {
790
604
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
791
- recentBlockhashesSysvar: {
792
- value: input.recentBlockhashesSysvar ?? null,
793
- isWritable: false
794
- },
605
+ recentBlockhashesSysvar: { value: input.recentBlockhashesSysvar ?? null, isWritable: false },
795
606
  rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }
796
607
  };
797
608
  const accounts = originalAccounts;
@@ -802,12 +613,12 @@ function getInitializeNonceAccountInstruction(input, config) {
802
613
  if (!accounts.rentSysvar.value) {
803
614
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
804
615
  }
805
- const getAccountMeta = getAccountMetaFactory();
616
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
806
617
  return Object.freeze({
807
618
  accounts: [
808
- getAccountMeta(accounts.nonceAccount),
809
- getAccountMeta(accounts.recentBlockhashesSysvar),
810
- getAccountMeta(accounts.rentSysvar)
619
+ getAccountMeta("nonceAccount", accounts.nonceAccount),
620
+ getAccountMeta("recentBlockhashesSysvar", accounts.recentBlockhashesSysvar),
621
+ getAccountMeta("rentSysvar", accounts.rentSysvar)
811
622
  ],
812
623
  data: getInitializeNonceAccountInstructionDataEncoder().encode(
813
624
  args
@@ -817,7 +628,10 @@ function getInitializeNonceAccountInstruction(input, config) {
817
628
  }
818
629
  function parseInitializeNonceAccountInstruction(instruction) {
819
630
  if (instruction.accounts.length < 3) {
820
- throw new Error("Not enough accounts");
631
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
632
+ actualAccountMetas: instruction.accounts.length,
633
+ expectedAccountMetas: 3
634
+ });
821
635
  }
822
636
  let accountIndex = 0;
823
637
  const getNextAccount = () => {
@@ -832,9 +646,7 @@ function parseInitializeNonceAccountInstruction(instruction) {
832
646
  recentBlockhashesSysvar: getNextAccount(),
833
647
  rentSysvar: getNextAccount()
834
648
  },
835
- data: getInitializeNonceAccountInstructionDataDecoder().decode(
836
- instruction.data
837
- )
649
+ data: getInitializeNonceAccountInstructionDataDecoder().decode(instruction.data)
838
650
  };
839
651
  }
840
652
  var TRANSFER_SOL_DISCRIMINATOR = 2;
@@ -857,10 +669,7 @@ function getTransferSolInstructionDataDecoder() {
857
669
  ]);
858
670
  }
859
671
  function getTransferSolInstructionDataCodec() {
860
- return kit.combineCodec(
861
- getTransferSolInstructionDataEncoder(),
862
- getTransferSolInstructionDataDecoder()
863
- );
672
+ return kit.combineCodec(getTransferSolInstructionDataEncoder(), getTransferSolInstructionDataDecoder());
864
673
  }
865
674
  function getTransferSolInstruction(input, config) {
866
675
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
@@ -870,21 +679,19 @@ function getTransferSolInstruction(input, config) {
870
679
  };
871
680
  const accounts = originalAccounts;
872
681
  const args = { ...input };
873
- const getAccountMeta = getAccountMetaFactory();
682
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
874
683
  return Object.freeze({
875
- accounts: [
876
- getAccountMeta(accounts.source),
877
- getAccountMeta(accounts.destination)
878
- ],
879
- data: getTransferSolInstructionDataEncoder().encode(
880
- args
881
- ),
684
+ accounts: [getAccountMeta("source", accounts.source), getAccountMeta("destination", accounts.destination)],
685
+ data: getTransferSolInstructionDataEncoder().encode(args),
882
686
  programAddress
883
687
  });
884
688
  }
885
689
  function parseTransferSolInstruction(instruction) {
886
690
  if (instruction.accounts.length < 2) {
887
- throw new Error("Not enough accounts");
691
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
692
+ actualAccountMetas: instruction.accounts.length,
693
+ expectedAccountMetas: 2
694
+ });
888
695
  }
889
696
  let accountIndex = 0;
890
697
  const getNextAccount = () => {
@@ -910,10 +717,7 @@ function getTransferSolWithSeedInstructionDataEncoder() {
910
717
  ["fromSeed", kit.addEncoderSizePrefix(kit.getUtf8Encoder(), kit.getU64Encoder())],
911
718
  ["fromOwner", kit.getAddressEncoder()]
912
719
  ]),
913
- (value) => ({
914
- ...value,
915
- discriminator: TRANSFER_SOL_WITH_SEED_DISCRIMINATOR
916
- })
720
+ (value) => ({ ...value, discriminator: TRANSFER_SOL_WITH_SEED_DISCRIMINATOR })
917
721
  );
918
722
  }
919
723
  function getTransferSolWithSeedInstructionDataDecoder() {
@@ -925,10 +729,7 @@ function getTransferSolWithSeedInstructionDataDecoder() {
925
729
  ]);
926
730
  }
927
731
  function getTransferSolWithSeedInstructionDataCodec() {
928
- return kit.combineCodec(
929
- getTransferSolWithSeedInstructionDataEncoder(),
930
- getTransferSolWithSeedInstructionDataDecoder()
931
- );
732
+ return kit.combineCodec(getTransferSolWithSeedInstructionDataEncoder(), getTransferSolWithSeedInstructionDataDecoder());
932
733
  }
933
734
  function getTransferSolWithSeedInstruction(input, config) {
934
735
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
@@ -939,22 +740,23 @@ function getTransferSolWithSeedInstruction(input, config) {
939
740
  };
940
741
  const accounts = originalAccounts;
941
742
  const args = { ...input };
942
- const getAccountMeta = getAccountMetaFactory();
743
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
943
744
  return Object.freeze({
944
745
  accounts: [
945
- getAccountMeta(accounts.source),
946
- getAccountMeta(accounts.baseAccount),
947
- getAccountMeta(accounts.destination)
746
+ getAccountMeta("source", accounts.source),
747
+ getAccountMeta("baseAccount", accounts.baseAccount),
748
+ getAccountMeta("destination", accounts.destination)
948
749
  ],
949
- data: getTransferSolWithSeedInstructionDataEncoder().encode(
950
- args
951
- ),
750
+ data: getTransferSolWithSeedInstructionDataEncoder().encode(args),
952
751
  programAddress
953
752
  });
954
753
  }
955
754
  function parseTransferSolWithSeedInstruction(instruction) {
956
755
  if (instruction.accounts.length < 3) {
957
- throw new Error("Not enough accounts");
756
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
757
+ actualAccountMetas: instruction.accounts.length,
758
+ expectedAccountMetas: 3
759
+ });
958
760
  }
959
761
  let accountIndex = 0;
960
762
  const getNextAccount = () => {
@@ -964,14 +766,8 @@ function parseTransferSolWithSeedInstruction(instruction) {
964
766
  };
965
767
  return {
966
768
  programAddress: instruction.programAddress,
967
- accounts: {
968
- source: getNextAccount(),
969
- baseAccount: getNextAccount(),
970
- destination: getNextAccount()
971
- },
972
- data: getTransferSolWithSeedInstructionDataDecoder().decode(
973
- instruction.data
974
- )
769
+ accounts: { source: getNextAccount(), baseAccount: getNextAccount(), destination: getNextAccount() },
770
+ data: getTransferSolWithSeedInstructionDataDecoder().decode(instruction.data)
975
771
  };
976
772
  }
977
773
  var UPGRADE_NONCE_ACCOUNT_DISCRIMINATOR = 12;
@@ -979,39 +775,34 @@ function getUpgradeNonceAccountDiscriminatorBytes() {
979
775
  return kit.getU32Encoder().encode(UPGRADE_NONCE_ACCOUNT_DISCRIMINATOR);
980
776
  }
981
777
  function getUpgradeNonceAccountInstructionDataEncoder() {
982
- return kit.transformEncoder(
983
- kit.getStructEncoder([["discriminator", kit.getU32Encoder()]]),
984
- (value) => ({
985
- ...value,
986
- discriminator: UPGRADE_NONCE_ACCOUNT_DISCRIMINATOR
987
- })
988
- );
778
+ return kit.transformEncoder(kit.getStructEncoder([["discriminator", kit.getU32Encoder()]]), (value) => ({
779
+ ...value,
780
+ discriminator: UPGRADE_NONCE_ACCOUNT_DISCRIMINATOR
781
+ }));
989
782
  }
990
783
  function getUpgradeNonceAccountInstructionDataDecoder() {
991
784
  return kit.getStructDecoder([["discriminator", kit.getU32Decoder()]]);
992
785
  }
993
786
  function getUpgradeNonceAccountInstructionDataCodec() {
994
- return kit.combineCodec(
995
- getUpgradeNonceAccountInstructionDataEncoder(),
996
- getUpgradeNonceAccountInstructionDataDecoder()
997
- );
787
+ return kit.combineCodec(getUpgradeNonceAccountInstructionDataEncoder(), getUpgradeNonceAccountInstructionDataDecoder());
998
788
  }
999
789
  function getUpgradeNonceAccountInstruction(input, config) {
1000
790
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
1001
- const originalAccounts = {
1002
- nonceAccount: { value: input.nonceAccount ?? null, isWritable: true }
1003
- };
791
+ const originalAccounts = { nonceAccount: { value: input.nonceAccount ?? null, isWritable: true } };
1004
792
  const accounts = originalAccounts;
1005
- const getAccountMeta = getAccountMetaFactory();
793
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
1006
794
  return Object.freeze({
1007
- accounts: [getAccountMeta(accounts.nonceAccount)],
795
+ accounts: [getAccountMeta("nonceAccount", accounts.nonceAccount)],
1008
796
  data: getUpgradeNonceAccountInstructionDataEncoder().encode({}),
1009
797
  programAddress
1010
798
  });
1011
799
  }
1012
800
  function parseUpgradeNonceAccountInstruction(instruction) {
1013
801
  if (instruction.accounts.length < 1) {
1014
- throw new Error("Not enough accounts");
802
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
803
+ actualAccountMetas: instruction.accounts.length,
804
+ expectedAccountMetas: 1
805
+ });
1015
806
  }
1016
807
  let accountIndex = 0;
1017
808
  const getNextAccount = () => {
@@ -1022,9 +813,7 @@ function parseUpgradeNonceAccountInstruction(instruction) {
1022
813
  return {
1023
814
  programAddress: instruction.programAddress,
1024
815
  accounts: { nonceAccount: getNextAccount() },
1025
- data: getUpgradeNonceAccountInstructionDataDecoder().decode(
1026
- instruction.data
1027
- )
816
+ data: getUpgradeNonceAccountInstructionDataDecoder().decode(instruction.data)
1028
817
  };
1029
818
  }
1030
819
  var WITHDRAW_NONCE_ACCOUNT_DISCRIMINATOR = 5;
@@ -1037,10 +826,7 @@ function getWithdrawNonceAccountInstructionDataEncoder() {
1037
826
  ["discriminator", kit.getU32Encoder()],
1038
827
  ["withdrawAmount", kit.getU64Encoder()]
1039
828
  ]),
1040
- (value) => ({
1041
- ...value,
1042
- discriminator: WITHDRAW_NONCE_ACCOUNT_DISCRIMINATOR
1043
- })
829
+ (value) => ({ ...value, discriminator: WITHDRAW_NONCE_ACCOUNT_DISCRIMINATOR })
1044
830
  );
1045
831
  }
1046
832
  function getWithdrawNonceAccountInstructionDataDecoder() {
@@ -1059,14 +845,8 @@ function getWithdrawNonceAccountInstruction(input, config) {
1059
845
  const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
1060
846
  const originalAccounts = {
1061
847
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
1062
- recipientAccount: {
1063
- value: input.recipientAccount ?? null,
1064
- isWritable: true
1065
- },
1066
- recentBlockhashesSysvar: {
1067
- value: input.recentBlockhashesSysvar ?? null,
1068
- isWritable: false
1069
- },
848
+ recipientAccount: { value: input.recipientAccount ?? null, isWritable: true },
849
+ recentBlockhashesSysvar: { value: input.recentBlockhashesSysvar ?? null, isWritable: false },
1070
850
  rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
1071
851
  nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false }
1072
852
  };
@@ -1078,24 +858,25 @@ function getWithdrawNonceAccountInstruction(input, config) {
1078
858
  if (!accounts.rentSysvar.value) {
1079
859
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
1080
860
  }
1081
- const getAccountMeta = getAccountMetaFactory();
861
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
1082
862
  return Object.freeze({
1083
863
  accounts: [
1084
- getAccountMeta(accounts.nonceAccount),
1085
- getAccountMeta(accounts.recipientAccount),
1086
- getAccountMeta(accounts.recentBlockhashesSysvar),
1087
- getAccountMeta(accounts.rentSysvar),
1088
- getAccountMeta(accounts.nonceAuthority)
864
+ getAccountMeta("nonceAccount", accounts.nonceAccount),
865
+ getAccountMeta("recipientAccount", accounts.recipientAccount),
866
+ getAccountMeta("recentBlockhashesSysvar", accounts.recentBlockhashesSysvar),
867
+ getAccountMeta("rentSysvar", accounts.rentSysvar),
868
+ getAccountMeta("nonceAuthority", accounts.nonceAuthority)
1089
869
  ],
1090
- data: getWithdrawNonceAccountInstructionDataEncoder().encode(
1091
- args
1092
- ),
870
+ data: getWithdrawNonceAccountInstructionDataEncoder().encode(args),
1093
871
  programAddress
1094
872
  });
1095
873
  }
1096
874
  function parseWithdrawNonceAccountInstruction(instruction) {
1097
875
  if (instruction.accounts.length < 5) {
1098
- throw new Error("Not enough accounts");
876
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
877
+ actualAccountMetas: instruction.accounts.length,
878
+ expectedAccountMetas: 5
879
+ });
1099
880
  }
1100
881
  let accountIndex = 0;
1101
882
  const getNextAccount = () => {
@@ -1112,11 +893,232 @@ function parseWithdrawNonceAccountInstruction(instruction) {
1112
893
  rentSysvar: getNextAccount(),
1113
894
  nonceAuthority: getNextAccount()
1114
895
  },
1115
- data: getWithdrawNonceAccountInstructionDataDecoder().decode(
1116
- instruction.data
1117
- )
896
+ data: getWithdrawNonceAccountInstructionDataDecoder().decode(instruction.data)
897
+ };
898
+ }
899
+
900
+ // src/generated/programs/system.ts
901
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
902
+ var SystemAccount = /* @__PURE__ */ ((SystemAccount2) => {
903
+ SystemAccount2[SystemAccount2["Nonce"] = 0] = "Nonce";
904
+ return SystemAccount2;
905
+ })(SystemAccount || {});
906
+ var SystemInstruction = /* @__PURE__ */ ((SystemInstruction2) => {
907
+ SystemInstruction2[SystemInstruction2["CreateAccount"] = 0] = "CreateAccount";
908
+ SystemInstruction2[SystemInstruction2["Assign"] = 1] = "Assign";
909
+ SystemInstruction2[SystemInstruction2["TransferSol"] = 2] = "TransferSol";
910
+ SystemInstruction2[SystemInstruction2["CreateAccountWithSeed"] = 3] = "CreateAccountWithSeed";
911
+ SystemInstruction2[SystemInstruction2["AdvanceNonceAccount"] = 4] = "AdvanceNonceAccount";
912
+ SystemInstruction2[SystemInstruction2["WithdrawNonceAccount"] = 5] = "WithdrawNonceAccount";
913
+ SystemInstruction2[SystemInstruction2["InitializeNonceAccount"] = 6] = "InitializeNonceAccount";
914
+ SystemInstruction2[SystemInstruction2["AuthorizeNonceAccount"] = 7] = "AuthorizeNonceAccount";
915
+ SystemInstruction2[SystemInstruction2["Allocate"] = 8] = "Allocate";
916
+ SystemInstruction2[SystemInstruction2["AllocateWithSeed"] = 9] = "AllocateWithSeed";
917
+ SystemInstruction2[SystemInstruction2["AssignWithSeed"] = 10] = "AssignWithSeed";
918
+ SystemInstruction2[SystemInstruction2["TransferSolWithSeed"] = 11] = "TransferSolWithSeed";
919
+ SystemInstruction2[SystemInstruction2["UpgradeNonceAccount"] = 12] = "UpgradeNonceAccount";
920
+ return SystemInstruction2;
921
+ })(SystemInstruction || {});
922
+ function identifySystemInstruction(instruction) {
923
+ const data = "data" in instruction ? instruction.data : instruction;
924
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(0), 0)) {
925
+ return 0 /* CreateAccount */;
926
+ }
927
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(1), 0)) {
928
+ return 1 /* Assign */;
929
+ }
930
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(2), 0)) {
931
+ return 2 /* TransferSol */;
932
+ }
933
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(3), 0)) {
934
+ return 3 /* CreateAccountWithSeed */;
935
+ }
936
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(4), 0)) {
937
+ return 4 /* AdvanceNonceAccount */;
938
+ }
939
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(5), 0)) {
940
+ return 5 /* WithdrawNonceAccount */;
941
+ }
942
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(6), 0)) {
943
+ return 6 /* InitializeNonceAccount */;
944
+ }
945
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(7), 0)) {
946
+ return 7 /* AuthorizeNonceAccount */;
947
+ }
948
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(8), 0)) {
949
+ return 8 /* Allocate */;
950
+ }
951
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(9), 0)) {
952
+ return 9 /* AllocateWithSeed */;
953
+ }
954
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(10), 0)) {
955
+ return 10 /* AssignWithSeed */;
956
+ }
957
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(11), 0)) {
958
+ return 11 /* TransferSolWithSeed */;
959
+ }
960
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(12), 0)) {
961
+ return 12 /* UpgradeNonceAccount */;
962
+ }
963
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, {
964
+ instructionData: data,
965
+ programName: "system"
966
+ });
967
+ }
968
+ function parseSystemInstruction(instruction) {
969
+ const instructionType = identifySystemInstruction(instruction);
970
+ switch (instructionType) {
971
+ case 0 /* CreateAccount */: {
972
+ kit.assertIsInstructionWithAccounts(instruction);
973
+ return { instructionType: 0 /* CreateAccount */, ...parseCreateAccountInstruction(instruction) };
974
+ }
975
+ case 1 /* Assign */: {
976
+ kit.assertIsInstructionWithAccounts(instruction);
977
+ return { instructionType: 1 /* Assign */, ...parseAssignInstruction(instruction) };
978
+ }
979
+ case 2 /* TransferSol */: {
980
+ kit.assertIsInstructionWithAccounts(instruction);
981
+ return { instructionType: 2 /* TransferSol */, ...parseTransferSolInstruction(instruction) };
982
+ }
983
+ case 3 /* CreateAccountWithSeed */: {
984
+ kit.assertIsInstructionWithAccounts(instruction);
985
+ return {
986
+ instructionType: 3 /* CreateAccountWithSeed */,
987
+ ...parseCreateAccountWithSeedInstruction(instruction)
988
+ };
989
+ }
990
+ case 4 /* AdvanceNonceAccount */: {
991
+ kit.assertIsInstructionWithAccounts(instruction);
992
+ return {
993
+ instructionType: 4 /* AdvanceNonceAccount */,
994
+ ...parseAdvanceNonceAccountInstruction(instruction)
995
+ };
996
+ }
997
+ case 5 /* WithdrawNonceAccount */: {
998
+ kit.assertIsInstructionWithAccounts(instruction);
999
+ return {
1000
+ instructionType: 5 /* WithdrawNonceAccount */,
1001
+ ...parseWithdrawNonceAccountInstruction(instruction)
1002
+ };
1003
+ }
1004
+ case 6 /* InitializeNonceAccount */: {
1005
+ kit.assertIsInstructionWithAccounts(instruction);
1006
+ return {
1007
+ instructionType: 6 /* InitializeNonceAccount */,
1008
+ ...parseInitializeNonceAccountInstruction(instruction)
1009
+ };
1010
+ }
1011
+ case 7 /* AuthorizeNonceAccount */: {
1012
+ kit.assertIsInstructionWithAccounts(instruction);
1013
+ return {
1014
+ instructionType: 7 /* AuthorizeNonceAccount */,
1015
+ ...parseAuthorizeNonceAccountInstruction(instruction)
1016
+ };
1017
+ }
1018
+ case 8 /* Allocate */: {
1019
+ kit.assertIsInstructionWithAccounts(instruction);
1020
+ return { instructionType: 8 /* Allocate */, ...parseAllocateInstruction(instruction) };
1021
+ }
1022
+ case 9 /* AllocateWithSeed */: {
1023
+ kit.assertIsInstructionWithAccounts(instruction);
1024
+ return {
1025
+ instructionType: 9 /* AllocateWithSeed */,
1026
+ ...parseAllocateWithSeedInstruction(instruction)
1027
+ };
1028
+ }
1029
+ case 10 /* AssignWithSeed */: {
1030
+ kit.assertIsInstructionWithAccounts(instruction);
1031
+ return {
1032
+ instructionType: 10 /* AssignWithSeed */,
1033
+ ...parseAssignWithSeedInstruction(instruction)
1034
+ };
1035
+ }
1036
+ case 11 /* TransferSolWithSeed */: {
1037
+ kit.assertIsInstructionWithAccounts(instruction);
1038
+ return {
1039
+ instructionType: 11 /* TransferSolWithSeed */,
1040
+ ...parseTransferSolWithSeedInstruction(instruction)
1041
+ };
1042
+ }
1043
+ case 12 /* UpgradeNonceAccount */: {
1044
+ kit.assertIsInstructionWithAccounts(instruction);
1045
+ return {
1046
+ instructionType: 12 /* UpgradeNonceAccount */,
1047
+ ...parseUpgradeNonceAccountInstruction(instruction)
1048
+ };
1049
+ }
1050
+ default:
1051
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, {
1052
+ instructionType,
1053
+ programName: "system"
1054
+ });
1055
+ }
1056
+ }
1057
+ function systemProgram() {
1058
+ return (client) => {
1059
+ return {
1060
+ ...client,
1061
+ system: {
1062
+ accounts: { nonce: programClientCore.addSelfFetchFunctions(client, getNonceCodec()) },
1063
+ instructions: {
1064
+ createAccount: (input) => programClientCore.addSelfPlanAndSendFunctions(
1065
+ client,
1066
+ getCreateAccountInstruction({ ...input, payer: input.payer ?? client.payer })
1067
+ ),
1068
+ assign: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getAssignInstruction(input)),
1069
+ transferSol: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getTransferSolInstruction(input)),
1070
+ createAccountWithSeed: (input) => programClientCore.addSelfPlanAndSendFunctions(
1071
+ client,
1072
+ getCreateAccountWithSeedInstruction({ ...input, payer: input.payer ?? client.payer })
1073
+ ),
1074
+ advanceNonceAccount: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getAdvanceNonceAccountInstruction(input)),
1075
+ withdrawNonceAccount: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getWithdrawNonceAccountInstruction(input)),
1076
+ initializeNonceAccount: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getInitializeNonceAccountInstruction(input)),
1077
+ authorizeNonceAccount: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getAuthorizeNonceAccountInstruction(input)),
1078
+ allocate: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getAllocateInstruction(input)),
1079
+ allocateWithSeed: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getAllocateWithSeedInstruction(input)),
1080
+ assignWithSeed: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getAssignWithSeedInstruction(input)),
1081
+ transferSolWithSeed: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getTransferSolWithSeedInstruction(input)),
1082
+ upgradeNonceAccount: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getUpgradeNonceAccountInstruction(input))
1083
+ }
1084
+ }
1085
+ };
1086
+ };
1087
+ }
1088
+
1089
+ // src/generated/errors/system.ts
1090
+ var SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE = 0;
1091
+ var SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS = 1;
1092
+ var SYSTEM_ERROR__INVALID_PROGRAM_ID = 2;
1093
+ var SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH = 3;
1094
+ var SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED = 4;
1095
+ var SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH = 5;
1096
+ var SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES = 6;
1097
+ var SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED = 7;
1098
+ var SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE = 8;
1099
+ var systemErrorMessages;
1100
+ if (process.env.NODE_ENV !== "production") {
1101
+ systemErrorMessages = {
1102
+ [SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE]: `an account with the same address already exists`,
1103
+ [SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH]: `provided address does not match addressed derived from seed`,
1104
+ [SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH]: `cannot allocate account data of this length`,
1105
+ [SYSTEM_ERROR__INVALID_PROGRAM_ID]: `cannot assign account to this program id`,
1106
+ [SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED]: `length of requested seed is too long`,
1107
+ [SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED]: `stored nonce is still in recent_blockhashes`,
1108
+ [SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES]: `advancing stored nonce requires a populated RecentBlockhashes sysvar`,
1109
+ [SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE]: `specified nonce does not match stored nonce`,
1110
+ [SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS]: `account does not have enough SOL to perform the operation`
1118
1111
  };
1119
1112
  }
1113
+ function getSystemErrorMessage(code) {
1114
+ if (process.env.NODE_ENV !== "production") {
1115
+ return systemErrorMessages[code];
1116
+ }
1117
+ return "Error message not available in production bundles.";
1118
+ }
1119
+ function isSystemError(error, transactionMessage, code) {
1120
+ return kit.isProgramError(error, transactionMessage, SYSTEM_PROGRAM_ADDRESS, code);
1121
+ }
1120
1122
 
1121
1123
  exports.ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR = ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR;
1122
1124
  exports.ALLOCATE_DISCRIMINATOR = ALLOCATE_DISCRIMINATOR;
@@ -1237,9 +1239,11 @@ exports.parseAuthorizeNonceAccountInstruction = parseAuthorizeNonceAccountInstru
1237
1239
  exports.parseCreateAccountInstruction = parseCreateAccountInstruction;
1238
1240
  exports.parseCreateAccountWithSeedInstruction = parseCreateAccountWithSeedInstruction;
1239
1241
  exports.parseInitializeNonceAccountInstruction = parseInitializeNonceAccountInstruction;
1242
+ exports.parseSystemInstruction = parseSystemInstruction;
1240
1243
  exports.parseTransferSolInstruction = parseTransferSolInstruction;
1241
1244
  exports.parseTransferSolWithSeedInstruction = parseTransferSolWithSeedInstruction;
1242
1245
  exports.parseUpgradeNonceAccountInstruction = parseUpgradeNonceAccountInstruction;
1243
1246
  exports.parseWithdrawNonceAccountInstruction = parseWithdrawNonceAccountInstruction;
1247
+ exports.systemProgram = systemProgram;
1244
1248
  //# sourceMappingURL=index.js.map
1245
1249
  //# sourceMappingURL=index.js.map