@solana-program/system 0.1.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 (64) hide show
  1. package/README.md +38 -0
  2. package/dist/src/index.js +1432 -0
  3. package/dist/src/index.js.map +1 -0
  4. package/dist/src/index.mjs +1320 -0
  5. package/dist/src/index.mjs.map +1 -0
  6. package/dist/types/src/generated/accounts/index.d.ts +9 -0
  7. package/dist/types/src/generated/accounts/index.d.ts.map +1 -0
  8. package/dist/types/src/generated/accounts/nonce.d.ts +38 -0
  9. package/dist/types/src/generated/accounts/nonce.d.ts.map +1 -0
  10. package/dist/types/src/generated/errors/index.d.ts +9 -0
  11. package/dist/types/src/generated/errors/index.d.ts.map +1 -0
  12. package/dist/types/src/generated/errors/system.d.ts +35 -0
  13. package/dist/types/src/generated/errors/system.d.ts.map +1 -0
  14. package/dist/types/src/generated/index.d.ts +14 -0
  15. package/dist/types/src/generated/index.d.ts.map +1 -0
  16. package/dist/types/src/generated/instructions/advanceNonceAccount.d.ts +58 -0
  17. package/dist/types/src/generated/instructions/advanceNonceAccount.d.ts.map +1 -0
  18. package/dist/types/src/generated/instructions/allocate.d.ts +51 -0
  19. package/dist/types/src/generated/instructions/allocate.d.ts.map +1 -0
  20. package/dist/types/src/generated/instructions/allocateWithSeed.d.ts +69 -0
  21. package/dist/types/src/generated/instructions/allocateWithSeed.d.ts.map +1 -0
  22. package/dist/types/src/generated/instructions/assign.d.ts +51 -0
  23. package/dist/types/src/generated/instructions/assign.d.ts.map +1 -0
  24. package/dist/types/src/generated/instructions/assignWithSeed.d.ts +65 -0
  25. package/dist/types/src/generated/instructions/assignWithSeed.d.ts.map +1 -0
  26. package/dist/types/src/generated/instructions/authorizeNonceAccount.d.ts +57 -0
  27. package/dist/types/src/generated/instructions/authorizeNonceAccount.d.ts.map +1 -0
  28. package/dist/types/src/generated/instructions/createAccount.d.ts +66 -0
  29. package/dist/types/src/generated/instructions/createAccount.d.ts.map +1 -0
  30. package/dist/types/src/generated/instructions/createAccountWithSeed.d.ts +79 -0
  31. package/dist/types/src/generated/instructions/createAccountWithSeed.d.ts.map +1 -0
  32. package/dist/types/src/generated/instructions/index.d.ts +21 -0
  33. package/dist/types/src/generated/instructions/index.d.ts.map +1 -0
  34. package/dist/types/src/generated/instructions/initializeNonceAccount.d.ts +62 -0
  35. package/dist/types/src/generated/instructions/initializeNonceAccount.d.ts.map +1 -0
  36. package/dist/types/src/generated/instructions/transferSol.d.ts +57 -0
  37. package/dist/types/src/generated/instructions/transferSol.d.ts.map +1 -0
  38. package/dist/types/src/generated/instructions/transferSolWithSeed.d.ts +71 -0
  39. package/dist/types/src/generated/instructions/transferSolWithSeed.d.ts.map +1 -0
  40. package/dist/types/src/generated/instructions/upgradeNonceAccount.d.ts +45 -0
  41. package/dist/types/src/generated/instructions/upgradeNonceAccount.d.ts.map +1 -0
  42. package/dist/types/src/generated/instructions/withdrawNonceAccount.d.ts +75 -0
  43. package/dist/types/src/generated/instructions/withdrawNonceAccount.d.ts.map +1 -0
  44. package/dist/types/src/generated/programs/index.d.ts +9 -0
  45. package/dist/types/src/generated/programs/index.d.ts.map +1 -0
  46. package/dist/types/src/generated/programs/system.d.ts +63 -0
  47. package/dist/types/src/generated/programs/system.d.ts.map +1 -0
  48. package/dist/types/src/generated/shared/index.d.ts +61 -0
  49. package/dist/types/src/generated/shared/index.d.ts.map +1 -0
  50. package/dist/types/src/generated/types/index.d.ts +10 -0
  51. package/dist/types/src/generated/types/index.d.ts.map +1 -0
  52. package/dist/types/src/generated/types/nonceState.d.ts +17 -0
  53. package/dist/types/src/generated/types/nonceState.d.ts.map +1 -0
  54. package/dist/types/src/generated/types/nonceVersion.d.ts +17 -0
  55. package/dist/types/src/generated/types/nonceVersion.d.ts.map +1 -0
  56. package/dist/types/src/index.d.ts +2 -0
  57. package/dist/types/src/index.d.ts.map +1 -0
  58. package/dist/types/test/_setup.d.ts +15 -0
  59. package/dist/types/test/_setup.d.ts.map +1 -0
  60. package/dist/types/test/initializeNonceAccount.test.d.ts +2 -0
  61. package/dist/types/test/initializeNonceAccount.test.d.ts.map +1 -0
  62. package/dist/types/test/transferSol.test.d.ts +2 -0
  63. package/dist/types/test/transferSol.test.d.ts.map +1 -0
  64. package/package.json +80 -0
@@ -0,0 +1,1320 @@
1
+ import { decodeAccount, assertAccountExists, fetchEncodedAccount, assertAccountsExist, fetchEncodedAccounts, BASE_ACCOUNT_SIZE } from '@solana/accounts';
2
+ import { getAddressEncoder, getAddressDecoder, isProgramDerivedAddress } from '@solana/addresses';
3
+ import { combineCodec, mapEncoder } from '@solana/codecs-core';
4
+ import { getScalarEnumEncoder, getScalarEnumDecoder, getStructEncoder, getStructDecoder } from '@solana/codecs-data-structures';
5
+ import { getU32Encoder, getU32Decoder, getU64Encoder, getU64Decoder } from '@solana/codecs-numbers';
6
+ import { AccountRole, upgradeRoleToSigner } from '@solana/instructions';
7
+ import { isTransactionSigner as isTransactionSigner$1 } from '@solana/signers';
8
+ import { getStringEncoder, getStringDecoder } from '@solana/codecs-strings';
9
+
10
+ // env-shim.ts
11
+ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
12
+ var NonceState = /* @__PURE__ */ ((NonceState3) => {
13
+ NonceState3[NonceState3["Uninitialized"] = 0] = "Uninitialized";
14
+ NonceState3[NonceState3["Initialized"] = 1] = "Initialized";
15
+ return NonceState3;
16
+ })(NonceState || {});
17
+ function getNonceStateEncoder() {
18
+ return getScalarEnumEncoder(NonceState, { size: getU32Encoder() });
19
+ }
20
+ function getNonceStateDecoder() {
21
+ return getScalarEnumDecoder(NonceState, { size: getU32Decoder() });
22
+ }
23
+ function getNonceStateCodec() {
24
+ return combineCodec(getNonceStateEncoder(), getNonceStateDecoder());
25
+ }
26
+ var NonceVersion = /* @__PURE__ */ ((NonceVersion3) => {
27
+ NonceVersion3[NonceVersion3["Legacy"] = 0] = "Legacy";
28
+ NonceVersion3[NonceVersion3["Current"] = 1] = "Current";
29
+ return NonceVersion3;
30
+ })(NonceVersion || {});
31
+ function getNonceVersionEncoder() {
32
+ return getScalarEnumEncoder(NonceVersion, { size: getU32Encoder() });
33
+ }
34
+ function getNonceVersionDecoder() {
35
+ return getScalarEnumDecoder(NonceVersion, { size: getU32Decoder() });
36
+ }
37
+ function getNonceVersionCodec() {
38
+ return combineCodec(getNonceVersionEncoder(), getNonceVersionDecoder());
39
+ }
40
+
41
+ // src/generated/accounts/nonce.ts
42
+ function getNonceAccountDataEncoder() {
43
+ return getStructEncoder([
44
+ ["version", getNonceVersionEncoder()],
45
+ ["state", getNonceStateEncoder()],
46
+ ["authority", getAddressEncoder()],
47
+ ["blockhash", getAddressEncoder()],
48
+ ["lamportsPerSignature", getU64Encoder()]
49
+ ]);
50
+ }
51
+ function getNonceAccountDataDecoder() {
52
+ return getStructDecoder([
53
+ ["version", getNonceVersionDecoder()],
54
+ ["state", getNonceStateDecoder()],
55
+ ["authority", getAddressDecoder()],
56
+ ["blockhash", getAddressDecoder()],
57
+ ["lamportsPerSignature", getU64Decoder()]
58
+ ]);
59
+ }
60
+ function getNonceAccountDataCodec() {
61
+ return combineCodec(
62
+ getNonceAccountDataEncoder(),
63
+ getNonceAccountDataDecoder()
64
+ );
65
+ }
66
+ function decodeNonce(encodedAccount) {
67
+ return decodeAccount(
68
+ encodedAccount,
69
+ getNonceAccountDataDecoder()
70
+ );
71
+ }
72
+ async function fetchNonce(rpc, address, config) {
73
+ const maybeAccount = await fetchMaybeNonce(rpc, address, config);
74
+ assertAccountExists(maybeAccount);
75
+ return maybeAccount;
76
+ }
77
+ async function fetchMaybeNonce(rpc, address, config) {
78
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
79
+ return decodeNonce(maybeAccount);
80
+ }
81
+ async function fetchAllNonce(rpc, addresses, config) {
82
+ const maybeAccounts = await fetchAllMaybeNonce(rpc, addresses, config);
83
+ assertAccountsExist(maybeAccounts);
84
+ return maybeAccounts;
85
+ }
86
+ async function fetchAllMaybeNonce(rpc, addresses, config) {
87
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
88
+ return maybeAccounts.map((maybeAccount) => decodeNonce(maybeAccount));
89
+ }
90
+ function getNonceSize() {
91
+ return 80;
92
+ }
93
+
94
+ // src/generated/errors/system.ts
95
+ var SystemProgramErrorCode = /* @__PURE__ */ ((SystemProgramErrorCode3) => {
96
+ SystemProgramErrorCode3[SystemProgramErrorCode3["ACCOUNT_ALREADY_IN_USE"] = 0] = "ACCOUNT_ALREADY_IN_USE";
97
+ SystemProgramErrorCode3[SystemProgramErrorCode3["RESULT_WITH_NEGATIVE_LAMPORTS"] = 1] = "RESULT_WITH_NEGATIVE_LAMPORTS";
98
+ SystemProgramErrorCode3[SystemProgramErrorCode3["INVALID_PROGRAM_ID"] = 2] = "INVALID_PROGRAM_ID";
99
+ SystemProgramErrorCode3[SystemProgramErrorCode3["INVALID_ACCOUNT_DATA_LENGTH"] = 3] = "INVALID_ACCOUNT_DATA_LENGTH";
100
+ SystemProgramErrorCode3[SystemProgramErrorCode3["MAX_SEED_LENGTH_EXCEEDED"] = 4] = "MAX_SEED_LENGTH_EXCEEDED";
101
+ SystemProgramErrorCode3[SystemProgramErrorCode3["ADDRESS_WITH_SEED_MISMATCH"] = 5] = "ADDRESS_WITH_SEED_MISMATCH";
102
+ SystemProgramErrorCode3[SystemProgramErrorCode3["NONCE_NO_RECENT_BLOCKHASHES"] = 6] = "NONCE_NO_RECENT_BLOCKHASHES";
103
+ SystemProgramErrorCode3[SystemProgramErrorCode3["NONCE_BLOCKHASH_NOT_EXPIRED"] = 7] = "NONCE_BLOCKHASH_NOT_EXPIRED";
104
+ SystemProgramErrorCode3[SystemProgramErrorCode3["NONCE_UNEXPECTED_BLOCKHASH_VALUE"] = 8] = "NONCE_UNEXPECTED_BLOCKHASH_VALUE";
105
+ return SystemProgramErrorCode3;
106
+ })(SystemProgramErrorCode || {});
107
+ var SystemProgramError = class extends Error {
108
+ name = "SystemProgramError";
109
+ code;
110
+ cause;
111
+ constructor(code, name, message, cause) {
112
+ super(`${name} (${code}): ${message}`);
113
+ this.code = code;
114
+ this.cause = cause;
115
+ }
116
+ };
117
+ var systemProgramErrorCodeMap;
118
+ if (__DEV__) {
119
+ systemProgramErrorCodeMap = {
120
+ [0 /* ACCOUNT_ALREADY_IN_USE */]: [
121
+ "AccountAlreadyInUse",
122
+ `an account with the same address already exists`
123
+ ],
124
+ [1 /* RESULT_WITH_NEGATIVE_LAMPORTS */]: [
125
+ "ResultWithNegativeLamports",
126
+ `account does not have enough SOL to perform the operation`
127
+ ],
128
+ [2 /* INVALID_PROGRAM_ID */]: [
129
+ "InvalidProgramId",
130
+ `cannot assign account to this program id`
131
+ ],
132
+ [3 /* INVALID_ACCOUNT_DATA_LENGTH */]: [
133
+ "InvalidAccountDataLength",
134
+ `cannot allocate account data of this length`
135
+ ],
136
+ [4 /* MAX_SEED_LENGTH_EXCEEDED */]: [
137
+ "MaxSeedLengthExceeded",
138
+ `length of requested seed is too long`
139
+ ],
140
+ [5 /* ADDRESS_WITH_SEED_MISMATCH */]: [
141
+ "AddressWithSeedMismatch",
142
+ `provided address does not match addressed derived from seed`
143
+ ],
144
+ [6 /* NONCE_NO_RECENT_BLOCKHASHES */]: [
145
+ "NonceNoRecentBlockhashes",
146
+ `advancing stored nonce requires a populated RecentBlockhashes sysvar`
147
+ ],
148
+ [7 /* NONCE_BLOCKHASH_NOT_EXPIRED */]: [
149
+ "NonceBlockhashNotExpired",
150
+ `stored nonce is still in recent_blockhashes`
151
+ ],
152
+ [8 /* NONCE_UNEXPECTED_BLOCKHASH_VALUE */]: [
153
+ "NonceUnexpectedBlockhashValue",
154
+ `specified nonce does not match stored nonce`
155
+ ]
156
+ };
157
+ }
158
+ function getSystemProgramErrorFromCode(code, cause) {
159
+ if (__DEV__) {
160
+ return new SystemProgramError(
161
+ code,
162
+ ...systemProgramErrorCodeMap[code],
163
+ cause
164
+ );
165
+ }
166
+ return new SystemProgramError(
167
+ code,
168
+ "Unknown",
169
+ "Error message not available in production bundles. Compile with __DEV__ set to true to see more information.",
170
+ cause
171
+ );
172
+ }
173
+ function expectSome(value) {
174
+ if (value == null) {
175
+ throw new Error("Expected a value but received null or undefined.");
176
+ }
177
+ return value;
178
+ }
179
+ function expectAddress(value) {
180
+ if (!value) {
181
+ throw new Error("Expected a Address.");
182
+ }
183
+ if (typeof value === "object" && "address" in value) {
184
+ return value.address;
185
+ }
186
+ if (Array.isArray(value)) {
187
+ return value[0];
188
+ }
189
+ return value;
190
+ }
191
+ function expectProgramDerivedAddress(value) {
192
+ if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) {
193
+ throw new Error("Expected a ProgramDerivedAddress.");
194
+ }
195
+ return value;
196
+ }
197
+ function expectTransactionSigner(value) {
198
+ if (!value || !isTransactionSigner(value)) {
199
+ throw new Error("Expected a TransactionSigner.");
200
+ }
201
+ return value;
202
+ }
203
+ function accountMetaWithDefault(account, role) {
204
+ if (account === void 0)
205
+ return void 0;
206
+ return typeof account === "string" ? { address: account, role } : account;
207
+ }
208
+ function getAccountMetasWithSigners(accounts, optionalAccountStrategy, programAddress) {
209
+ const accountMetas = {};
210
+ Object.keys(accounts).forEach((key) => {
211
+ const account = accounts[key];
212
+ if (!account.value) {
213
+ if (optionalAccountStrategy === "omitted")
214
+ return;
215
+ accountMetas[key] = {
216
+ address: programAddress,
217
+ role: AccountRole.READONLY
218
+ };
219
+ return;
220
+ }
221
+ const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;
222
+ accountMetas[key] = Object.freeze({
223
+ address: expectAddress(account.value),
224
+ role: isTransactionSigner(account.value) ? upgradeRoleToSigner(writableRole) : writableRole,
225
+ ...isTransactionSigner(account.value) ? { signer: account.value } : {}
226
+ });
227
+ });
228
+ return accountMetas;
229
+ }
230
+ function isTransactionSigner(value) {
231
+ return !!value && typeof value === "object" && "address" in value && isTransactionSigner$1(value);
232
+ }
233
+ function memcmp(data, bytes, offset) {
234
+ const slice = data.slice(offset, offset + bytes.length);
235
+ if (slice.length !== bytes.length)
236
+ return false;
237
+ return bytes.every((b, i) => b === slice[i]);
238
+ }
239
+
240
+ // src/generated/instructions/advanceNonceAccount.ts
241
+ function getAdvanceNonceAccountInstructionDataEncoder() {
242
+ return mapEncoder(
243
+ getStructEncoder([["discriminator", getU32Encoder()]]),
244
+ (value) => ({ ...value, discriminator: 4 })
245
+ );
246
+ }
247
+ function getAdvanceNonceAccountInstructionDataDecoder() {
248
+ return getStructDecoder([["discriminator", getU32Decoder()]]);
249
+ }
250
+ function getAdvanceNonceAccountInstructionDataCodec() {
251
+ return combineCodec(
252
+ getAdvanceNonceAccountInstructionDataEncoder(),
253
+ getAdvanceNonceAccountInstructionDataDecoder()
254
+ );
255
+ }
256
+ function getAdvanceNonceAccountInstruction(input) {
257
+ const programAddress = "11111111111111111111111111111111";
258
+ const accounts = {
259
+ nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
260
+ recentBlockhashesSysvar: {
261
+ value: input.recentBlockhashesSysvar ?? null,
262
+ isWritable: false
263
+ },
264
+ nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false }
265
+ };
266
+ if (!accounts.recentBlockhashesSysvar.value) {
267
+ accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
268
+ }
269
+ const accountMetas = getAccountMetasWithSigners(
270
+ accounts,
271
+ "programId",
272
+ programAddress
273
+ );
274
+ const instruction = getAdvanceNonceAccountInstructionRaw(
275
+ accountMetas,
276
+ programAddress
277
+ );
278
+ return instruction;
279
+ }
280
+ function getAdvanceNonceAccountInstructionRaw(accounts, programAddress = "11111111111111111111111111111111", remainingAccounts) {
281
+ return {
282
+ accounts: [
283
+ accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
284
+ accountMetaWithDefault(
285
+ accounts.recentBlockhashesSysvar ?? "SysvarRecentB1ockHashes11111111111111111111",
286
+ AccountRole.READONLY
287
+ ),
288
+ accountMetaWithDefault(
289
+ accounts.nonceAuthority,
290
+ AccountRole.READONLY_SIGNER
291
+ ),
292
+ ...remainingAccounts ?? []
293
+ ],
294
+ data: getAdvanceNonceAccountInstructionDataEncoder().encode({}),
295
+ programAddress
296
+ };
297
+ }
298
+ function parseAdvanceNonceAccountInstruction(instruction) {
299
+ if (instruction.accounts.length < 3) {
300
+ throw new Error("Not enough accounts");
301
+ }
302
+ let accountIndex = 0;
303
+ const getNextAccount = () => {
304
+ const accountMeta = instruction.accounts[accountIndex];
305
+ accountIndex += 1;
306
+ return accountMeta;
307
+ };
308
+ return {
309
+ programAddress: instruction.programAddress,
310
+ accounts: {
311
+ nonceAccount: getNextAccount(),
312
+ recentBlockhashesSysvar: getNextAccount(),
313
+ nonceAuthority: getNextAccount()
314
+ },
315
+ data: getAdvanceNonceAccountInstructionDataDecoder().decode(
316
+ instruction.data
317
+ )
318
+ };
319
+ }
320
+ function getAllocateInstructionDataEncoder() {
321
+ return mapEncoder(
322
+ getStructEncoder([
323
+ ["discriminator", getU32Encoder()],
324
+ ["space", getU64Encoder()]
325
+ ]),
326
+ (value) => ({ ...value, discriminator: 8 })
327
+ );
328
+ }
329
+ function getAllocateInstructionDataDecoder() {
330
+ return getStructDecoder([
331
+ ["discriminator", getU32Decoder()],
332
+ ["space", getU64Decoder()]
333
+ ]);
334
+ }
335
+ function getAllocateInstructionDataCodec() {
336
+ return combineCodec(
337
+ getAllocateInstructionDataEncoder(),
338
+ getAllocateInstructionDataDecoder()
339
+ );
340
+ }
341
+ function getAllocateInstruction(input) {
342
+ const programAddress = "11111111111111111111111111111111";
343
+ const accounts = {
344
+ newAccount: { value: input.newAccount ?? null, isWritable: true }
345
+ };
346
+ const args = { ...input };
347
+ const accountMetas = getAccountMetasWithSigners(
348
+ accounts,
349
+ "programId",
350
+ programAddress
351
+ );
352
+ const instruction = getAllocateInstructionRaw(
353
+ accountMetas,
354
+ args,
355
+ programAddress
356
+ );
357
+ return instruction;
358
+ }
359
+ function getAllocateInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
360
+ return {
361
+ accounts: [
362
+ accountMetaWithDefault(accounts.newAccount, AccountRole.WRITABLE_SIGNER),
363
+ ...remainingAccounts ?? []
364
+ ],
365
+ data: getAllocateInstructionDataEncoder().encode(args),
366
+ programAddress
367
+ };
368
+ }
369
+ function parseAllocateInstruction(instruction) {
370
+ if (instruction.accounts.length < 1) {
371
+ throw new Error("Not enough accounts");
372
+ }
373
+ let accountIndex = 0;
374
+ const getNextAccount = () => {
375
+ const accountMeta = instruction.accounts[accountIndex];
376
+ accountIndex += 1;
377
+ return accountMeta;
378
+ };
379
+ return {
380
+ programAddress: instruction.programAddress,
381
+ accounts: {
382
+ newAccount: getNextAccount()
383
+ },
384
+ data: getAllocateInstructionDataDecoder().decode(instruction.data)
385
+ };
386
+ }
387
+ function getAllocateWithSeedInstructionDataEncoder() {
388
+ return mapEncoder(
389
+ getStructEncoder([
390
+ ["discriminator", getU32Encoder()],
391
+ ["base", getAddressEncoder()],
392
+ ["seed", getStringEncoder()],
393
+ ["space", getU64Encoder()],
394
+ ["programAddress", getAddressEncoder()]
395
+ ]),
396
+ (value) => ({ ...value, discriminator: 9 })
397
+ );
398
+ }
399
+ function getAllocateWithSeedInstructionDataDecoder() {
400
+ return getStructDecoder([
401
+ ["discriminator", getU32Decoder()],
402
+ ["base", getAddressDecoder()],
403
+ ["seed", getStringDecoder()],
404
+ ["space", getU64Decoder()],
405
+ ["programAddress", getAddressDecoder()]
406
+ ]);
407
+ }
408
+ function getAllocateWithSeedInstructionDataCodec() {
409
+ return combineCodec(
410
+ getAllocateWithSeedInstructionDataEncoder(),
411
+ getAllocateWithSeedInstructionDataDecoder()
412
+ );
413
+ }
414
+ function getAllocateWithSeedInstruction(input) {
415
+ const programAddress = "11111111111111111111111111111111";
416
+ const accounts = {
417
+ newAccount: { value: input.newAccount ?? null, isWritable: true },
418
+ baseAccount: { value: input.baseAccount ?? null, isWritable: false }
419
+ };
420
+ const args = { ...input };
421
+ const accountMetas = getAccountMetasWithSigners(
422
+ accounts,
423
+ "programId",
424
+ programAddress
425
+ );
426
+ const instruction = getAllocateWithSeedInstructionRaw(
427
+ accountMetas,
428
+ args,
429
+ programAddress
430
+ );
431
+ return instruction;
432
+ }
433
+ function getAllocateWithSeedInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
434
+ return {
435
+ accounts: [
436
+ accountMetaWithDefault(accounts.newAccount, AccountRole.WRITABLE),
437
+ accountMetaWithDefault(accounts.baseAccount, AccountRole.READONLY_SIGNER),
438
+ ...remainingAccounts ?? []
439
+ ],
440
+ data: getAllocateWithSeedInstructionDataEncoder().encode(args),
441
+ programAddress
442
+ };
443
+ }
444
+ function parseAllocateWithSeedInstruction(instruction) {
445
+ if (instruction.accounts.length < 2) {
446
+ throw new Error("Not enough accounts");
447
+ }
448
+ let accountIndex = 0;
449
+ const getNextAccount = () => {
450
+ const accountMeta = instruction.accounts[accountIndex];
451
+ accountIndex += 1;
452
+ return accountMeta;
453
+ };
454
+ return {
455
+ programAddress: instruction.programAddress,
456
+ accounts: {
457
+ newAccount: getNextAccount(),
458
+ baseAccount: getNextAccount()
459
+ },
460
+ data: getAllocateWithSeedInstructionDataDecoder().decode(instruction.data)
461
+ };
462
+ }
463
+ function getAssignInstructionDataEncoder() {
464
+ return mapEncoder(
465
+ getStructEncoder([
466
+ ["discriminator", getU32Encoder()],
467
+ ["programAddress", getAddressEncoder()]
468
+ ]),
469
+ (value) => ({ ...value, discriminator: 1 })
470
+ );
471
+ }
472
+ function getAssignInstructionDataDecoder() {
473
+ return getStructDecoder([
474
+ ["discriminator", getU32Decoder()],
475
+ ["programAddress", getAddressDecoder()]
476
+ ]);
477
+ }
478
+ function getAssignInstructionDataCodec() {
479
+ return combineCodec(
480
+ getAssignInstructionDataEncoder(),
481
+ getAssignInstructionDataDecoder()
482
+ );
483
+ }
484
+ function getAssignInstruction(input) {
485
+ const programAddress = "11111111111111111111111111111111";
486
+ const accounts = {
487
+ account: { value: input.account ?? null, isWritable: true }
488
+ };
489
+ const args = { ...input };
490
+ const accountMetas = getAccountMetasWithSigners(
491
+ accounts,
492
+ "programId",
493
+ programAddress
494
+ );
495
+ const instruction = getAssignInstructionRaw(
496
+ accountMetas,
497
+ args,
498
+ programAddress
499
+ );
500
+ return instruction;
501
+ }
502
+ function getAssignInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
503
+ return {
504
+ accounts: [
505
+ accountMetaWithDefault(accounts.account, AccountRole.WRITABLE_SIGNER),
506
+ ...remainingAccounts ?? []
507
+ ],
508
+ data: getAssignInstructionDataEncoder().encode(args),
509
+ programAddress
510
+ };
511
+ }
512
+ function parseAssignInstruction(instruction) {
513
+ if (instruction.accounts.length < 1) {
514
+ throw new Error("Not enough accounts");
515
+ }
516
+ let accountIndex = 0;
517
+ const getNextAccount = () => {
518
+ const accountMeta = instruction.accounts[accountIndex];
519
+ accountIndex += 1;
520
+ return accountMeta;
521
+ };
522
+ return {
523
+ programAddress: instruction.programAddress,
524
+ accounts: {
525
+ account: getNextAccount()
526
+ },
527
+ data: getAssignInstructionDataDecoder().decode(instruction.data)
528
+ };
529
+ }
530
+ function getAssignWithSeedInstructionDataEncoder() {
531
+ return mapEncoder(
532
+ getStructEncoder([
533
+ ["discriminator", getU32Encoder()],
534
+ ["base", getAddressEncoder()],
535
+ ["seed", getStringEncoder()],
536
+ ["programAddress", getAddressEncoder()]
537
+ ]),
538
+ (value) => ({ ...value, discriminator: 10 })
539
+ );
540
+ }
541
+ function getAssignWithSeedInstructionDataDecoder() {
542
+ return getStructDecoder([
543
+ ["discriminator", getU32Decoder()],
544
+ ["base", getAddressDecoder()],
545
+ ["seed", getStringDecoder()],
546
+ ["programAddress", getAddressDecoder()]
547
+ ]);
548
+ }
549
+ function getAssignWithSeedInstructionDataCodec() {
550
+ return combineCodec(
551
+ getAssignWithSeedInstructionDataEncoder(),
552
+ getAssignWithSeedInstructionDataDecoder()
553
+ );
554
+ }
555
+ function getAssignWithSeedInstruction(input) {
556
+ const programAddress = "11111111111111111111111111111111";
557
+ const accounts = {
558
+ account: { value: input.account ?? null, isWritable: true },
559
+ baseAccount: { value: input.baseAccount ?? null, isWritable: false }
560
+ };
561
+ const args = { ...input };
562
+ const accountMetas = getAccountMetasWithSigners(
563
+ accounts,
564
+ "programId",
565
+ programAddress
566
+ );
567
+ const instruction = getAssignWithSeedInstructionRaw(
568
+ accountMetas,
569
+ args,
570
+ programAddress
571
+ );
572
+ return instruction;
573
+ }
574
+ function getAssignWithSeedInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
575
+ return {
576
+ accounts: [
577
+ accountMetaWithDefault(accounts.account, AccountRole.WRITABLE),
578
+ accountMetaWithDefault(accounts.baseAccount, AccountRole.READONLY_SIGNER),
579
+ ...remainingAccounts ?? []
580
+ ],
581
+ data: getAssignWithSeedInstructionDataEncoder().encode(args),
582
+ programAddress
583
+ };
584
+ }
585
+ function parseAssignWithSeedInstruction(instruction) {
586
+ if (instruction.accounts.length < 2) {
587
+ throw new Error("Not enough accounts");
588
+ }
589
+ let accountIndex = 0;
590
+ const getNextAccount = () => {
591
+ const accountMeta = instruction.accounts[accountIndex];
592
+ accountIndex += 1;
593
+ return accountMeta;
594
+ };
595
+ return {
596
+ programAddress: instruction.programAddress,
597
+ accounts: {
598
+ account: getNextAccount(),
599
+ baseAccount: getNextAccount()
600
+ },
601
+ data: getAssignWithSeedInstructionDataDecoder().decode(instruction.data)
602
+ };
603
+ }
604
+ function getAuthorizeNonceAccountInstructionDataEncoder() {
605
+ return mapEncoder(
606
+ getStructEncoder([
607
+ ["discriminator", getU32Encoder()],
608
+ ["newNonceAuthority", getAddressEncoder()]
609
+ ]),
610
+ (value) => ({ ...value, discriminator: 7 })
611
+ );
612
+ }
613
+ function getAuthorizeNonceAccountInstructionDataDecoder() {
614
+ return getStructDecoder([
615
+ ["discriminator", getU32Decoder()],
616
+ ["newNonceAuthority", getAddressDecoder()]
617
+ ]);
618
+ }
619
+ function getAuthorizeNonceAccountInstructionDataCodec() {
620
+ return combineCodec(
621
+ getAuthorizeNonceAccountInstructionDataEncoder(),
622
+ getAuthorizeNonceAccountInstructionDataDecoder()
623
+ );
624
+ }
625
+ function getAuthorizeNonceAccountInstruction(input) {
626
+ const programAddress = "11111111111111111111111111111111";
627
+ const accounts = {
628
+ nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
629
+ nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false }
630
+ };
631
+ const args = { ...input };
632
+ const accountMetas = getAccountMetasWithSigners(
633
+ accounts,
634
+ "programId",
635
+ programAddress
636
+ );
637
+ const instruction = getAuthorizeNonceAccountInstructionRaw(
638
+ accountMetas,
639
+ args,
640
+ programAddress
641
+ );
642
+ return instruction;
643
+ }
644
+ function getAuthorizeNonceAccountInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
645
+ return {
646
+ accounts: [
647
+ accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
648
+ accountMetaWithDefault(
649
+ accounts.nonceAuthority,
650
+ AccountRole.READONLY_SIGNER
651
+ ),
652
+ ...remainingAccounts ?? []
653
+ ],
654
+ data: getAuthorizeNonceAccountInstructionDataEncoder().encode(args),
655
+ programAddress
656
+ };
657
+ }
658
+ function parseAuthorizeNonceAccountInstruction(instruction) {
659
+ if (instruction.accounts.length < 2) {
660
+ throw new Error("Not enough accounts");
661
+ }
662
+ let accountIndex = 0;
663
+ const getNextAccount = () => {
664
+ const accountMeta = instruction.accounts[accountIndex];
665
+ accountIndex += 1;
666
+ return accountMeta;
667
+ };
668
+ return {
669
+ programAddress: instruction.programAddress,
670
+ accounts: {
671
+ nonceAccount: getNextAccount(),
672
+ nonceAuthority: getNextAccount()
673
+ },
674
+ data: getAuthorizeNonceAccountInstructionDataDecoder().decode(
675
+ instruction.data
676
+ )
677
+ };
678
+ }
679
+ function getCreateAccountInstructionDataEncoder() {
680
+ return mapEncoder(
681
+ getStructEncoder([
682
+ ["discriminator", getU32Encoder()],
683
+ ["lamports", getU64Encoder()],
684
+ ["space", getU64Encoder()],
685
+ ["programAddress", getAddressEncoder()]
686
+ ]),
687
+ (value) => ({ ...value, discriminator: 0 })
688
+ );
689
+ }
690
+ function getCreateAccountInstructionDataDecoder() {
691
+ return getStructDecoder([
692
+ ["discriminator", getU32Decoder()],
693
+ ["lamports", getU64Decoder()],
694
+ ["space", getU64Decoder()],
695
+ ["programAddress", getAddressDecoder()]
696
+ ]);
697
+ }
698
+ function getCreateAccountInstructionDataCodec() {
699
+ return combineCodec(
700
+ getCreateAccountInstructionDataEncoder(),
701
+ getCreateAccountInstructionDataDecoder()
702
+ );
703
+ }
704
+ function getCreateAccountInstruction(input) {
705
+ const programAddress = "11111111111111111111111111111111";
706
+ const accounts = {
707
+ payer: { value: input.payer ?? null, isWritable: true },
708
+ newAccount: { value: input.newAccount ?? null, isWritable: true }
709
+ };
710
+ const args = { ...input };
711
+ const byteDelta = [Number(args.space) + BASE_ACCOUNT_SIZE].reduce(
712
+ (a, b) => a + b,
713
+ 0
714
+ );
715
+ const accountMetas = getAccountMetasWithSigners(
716
+ accounts,
717
+ "programId",
718
+ programAddress
719
+ );
720
+ const instruction = getCreateAccountInstructionRaw(
721
+ accountMetas,
722
+ args,
723
+ programAddress
724
+ );
725
+ return Object.freeze({ ...instruction, byteDelta });
726
+ }
727
+ function getCreateAccountInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
728
+ return {
729
+ accounts: [
730
+ accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER),
731
+ accountMetaWithDefault(accounts.newAccount, AccountRole.WRITABLE_SIGNER),
732
+ ...remainingAccounts ?? []
733
+ ],
734
+ data: getCreateAccountInstructionDataEncoder().encode(args),
735
+ programAddress
736
+ };
737
+ }
738
+ function parseCreateAccountInstruction(instruction) {
739
+ if (instruction.accounts.length < 2) {
740
+ throw new Error("Not enough accounts");
741
+ }
742
+ let accountIndex = 0;
743
+ const getNextAccount = () => {
744
+ const accountMeta = instruction.accounts[accountIndex];
745
+ accountIndex += 1;
746
+ return accountMeta;
747
+ };
748
+ return {
749
+ programAddress: instruction.programAddress,
750
+ accounts: {
751
+ payer: getNextAccount(),
752
+ newAccount: getNextAccount()
753
+ },
754
+ data: getCreateAccountInstructionDataDecoder().decode(instruction.data)
755
+ };
756
+ }
757
+ function getCreateAccountWithSeedInstructionDataEncoder() {
758
+ return mapEncoder(
759
+ getStructEncoder([
760
+ ["discriminator", getU32Encoder()],
761
+ ["base", getAddressEncoder()],
762
+ ["seed", getStringEncoder()],
763
+ ["amount", getU64Encoder()],
764
+ ["space", getU64Encoder()],
765
+ ["programAddress", getAddressEncoder()]
766
+ ]),
767
+ (value) => ({ ...value, discriminator: 3 })
768
+ );
769
+ }
770
+ function getCreateAccountWithSeedInstructionDataDecoder() {
771
+ return getStructDecoder([
772
+ ["discriminator", getU32Decoder()],
773
+ ["base", getAddressDecoder()],
774
+ ["seed", getStringDecoder()],
775
+ ["amount", getU64Decoder()],
776
+ ["space", getU64Decoder()],
777
+ ["programAddress", getAddressDecoder()]
778
+ ]);
779
+ }
780
+ function getCreateAccountWithSeedInstructionDataCodec() {
781
+ return combineCodec(
782
+ getCreateAccountWithSeedInstructionDataEncoder(),
783
+ getCreateAccountWithSeedInstructionDataDecoder()
784
+ );
785
+ }
786
+ function getCreateAccountWithSeedInstruction(input) {
787
+ const programAddress = "11111111111111111111111111111111";
788
+ const accounts = {
789
+ payer: { value: input.payer ?? null, isWritable: true },
790
+ newAccount: { value: input.newAccount ?? null, isWritable: true },
791
+ baseAccount: { value: input.baseAccount ?? null, isWritable: false }
792
+ };
793
+ const args = { ...input };
794
+ const accountMetas = getAccountMetasWithSigners(
795
+ accounts,
796
+ "programId",
797
+ programAddress
798
+ );
799
+ const instruction = getCreateAccountWithSeedInstructionRaw(
800
+ accountMetas,
801
+ args,
802
+ programAddress
803
+ );
804
+ return instruction;
805
+ }
806
+ function getCreateAccountWithSeedInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
807
+ return {
808
+ accounts: [
809
+ accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER),
810
+ accountMetaWithDefault(accounts.newAccount, AccountRole.WRITABLE),
811
+ accountMetaWithDefault(accounts.baseAccount, AccountRole.READONLY_SIGNER),
812
+ ...remainingAccounts ?? []
813
+ ],
814
+ data: getCreateAccountWithSeedInstructionDataEncoder().encode(args),
815
+ programAddress
816
+ };
817
+ }
818
+ function parseCreateAccountWithSeedInstruction(instruction) {
819
+ if (instruction.accounts.length < 3) {
820
+ throw new Error("Not enough accounts");
821
+ }
822
+ let accountIndex = 0;
823
+ const getNextAccount = () => {
824
+ const accountMeta = instruction.accounts[accountIndex];
825
+ accountIndex += 1;
826
+ return accountMeta;
827
+ };
828
+ return {
829
+ programAddress: instruction.programAddress,
830
+ accounts: {
831
+ payer: getNextAccount(),
832
+ newAccount: getNextAccount(),
833
+ baseAccount: getNextAccount()
834
+ },
835
+ data: getCreateAccountWithSeedInstructionDataDecoder().decode(
836
+ instruction.data
837
+ )
838
+ };
839
+ }
840
+ function getInitializeNonceAccountInstructionDataEncoder() {
841
+ return mapEncoder(
842
+ getStructEncoder([
843
+ ["discriminator", getU32Encoder()],
844
+ ["nonceAuthority", getAddressEncoder()]
845
+ ]),
846
+ (value) => ({ ...value, discriminator: 6 })
847
+ );
848
+ }
849
+ function getInitializeNonceAccountInstructionDataDecoder() {
850
+ return getStructDecoder([
851
+ ["discriminator", getU32Decoder()],
852
+ ["nonceAuthority", getAddressDecoder()]
853
+ ]);
854
+ }
855
+ function getInitializeNonceAccountInstructionDataCodec() {
856
+ return combineCodec(
857
+ getInitializeNonceAccountInstructionDataEncoder(),
858
+ getInitializeNonceAccountInstructionDataDecoder()
859
+ );
860
+ }
861
+ function getInitializeNonceAccountInstruction(input) {
862
+ const programAddress = "11111111111111111111111111111111";
863
+ const accounts = {
864
+ nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
865
+ recentBlockhashesSysvar: {
866
+ value: input.recentBlockhashesSysvar ?? null,
867
+ isWritable: false
868
+ },
869
+ rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }
870
+ };
871
+ const args = { ...input };
872
+ if (!accounts.recentBlockhashesSysvar.value) {
873
+ accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
874
+ }
875
+ if (!accounts.rentSysvar.value) {
876
+ accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
877
+ }
878
+ const accountMetas = getAccountMetasWithSigners(
879
+ accounts,
880
+ "programId",
881
+ programAddress
882
+ );
883
+ const instruction = getInitializeNonceAccountInstructionRaw(
884
+ accountMetas,
885
+ args,
886
+ programAddress
887
+ );
888
+ return instruction;
889
+ }
890
+ function getInitializeNonceAccountInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
891
+ return {
892
+ accounts: [
893
+ accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
894
+ accountMetaWithDefault(
895
+ accounts.recentBlockhashesSysvar ?? "SysvarRecentB1ockHashes11111111111111111111",
896
+ AccountRole.READONLY
897
+ ),
898
+ accountMetaWithDefault(
899
+ accounts.rentSysvar ?? "SysvarRent111111111111111111111111111111111",
900
+ AccountRole.READONLY
901
+ ),
902
+ ...remainingAccounts ?? []
903
+ ],
904
+ data: getInitializeNonceAccountInstructionDataEncoder().encode(args),
905
+ programAddress
906
+ };
907
+ }
908
+ function parseInitializeNonceAccountInstruction(instruction) {
909
+ if (instruction.accounts.length < 3) {
910
+ throw new Error("Not enough accounts");
911
+ }
912
+ let accountIndex = 0;
913
+ const getNextAccount = () => {
914
+ const accountMeta = instruction.accounts[accountIndex];
915
+ accountIndex += 1;
916
+ return accountMeta;
917
+ };
918
+ return {
919
+ programAddress: instruction.programAddress,
920
+ accounts: {
921
+ nonceAccount: getNextAccount(),
922
+ recentBlockhashesSysvar: getNextAccount(),
923
+ rentSysvar: getNextAccount()
924
+ },
925
+ data: getInitializeNonceAccountInstructionDataDecoder().decode(
926
+ instruction.data
927
+ )
928
+ };
929
+ }
930
+ function getTransferSolInstructionDataEncoder() {
931
+ return mapEncoder(
932
+ getStructEncoder([
933
+ ["discriminator", getU32Encoder()],
934
+ ["amount", getU64Encoder()]
935
+ ]),
936
+ (value) => ({ ...value, discriminator: 2 })
937
+ );
938
+ }
939
+ function getTransferSolInstructionDataDecoder() {
940
+ return getStructDecoder([
941
+ ["discriminator", getU32Decoder()],
942
+ ["amount", getU64Decoder()]
943
+ ]);
944
+ }
945
+ function getTransferSolInstructionDataCodec() {
946
+ return combineCodec(
947
+ getTransferSolInstructionDataEncoder(),
948
+ getTransferSolInstructionDataDecoder()
949
+ );
950
+ }
951
+ function getTransferSolInstruction(input) {
952
+ const programAddress = "11111111111111111111111111111111";
953
+ const accounts = {
954
+ source: { value: input.source ?? null, isWritable: true },
955
+ destination: { value: input.destination ?? null, isWritable: true }
956
+ };
957
+ const args = { ...input };
958
+ const accountMetas = getAccountMetasWithSigners(
959
+ accounts,
960
+ "programId",
961
+ programAddress
962
+ );
963
+ const instruction = getTransferSolInstructionRaw(
964
+ accountMetas,
965
+ args,
966
+ programAddress
967
+ );
968
+ return instruction;
969
+ }
970
+ function getTransferSolInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
971
+ return {
972
+ accounts: [
973
+ accountMetaWithDefault(accounts.source, AccountRole.WRITABLE_SIGNER),
974
+ accountMetaWithDefault(accounts.destination, AccountRole.WRITABLE),
975
+ ...remainingAccounts ?? []
976
+ ],
977
+ data: getTransferSolInstructionDataEncoder().encode(args),
978
+ programAddress
979
+ };
980
+ }
981
+ function parseTransferSolInstruction(instruction) {
982
+ if (instruction.accounts.length < 2) {
983
+ throw new Error("Not enough accounts");
984
+ }
985
+ let accountIndex = 0;
986
+ const getNextAccount = () => {
987
+ const accountMeta = instruction.accounts[accountIndex];
988
+ accountIndex += 1;
989
+ return accountMeta;
990
+ };
991
+ return {
992
+ programAddress: instruction.programAddress,
993
+ accounts: {
994
+ source: getNextAccount(),
995
+ destination: getNextAccount()
996
+ },
997
+ data: getTransferSolInstructionDataDecoder().decode(instruction.data)
998
+ };
999
+ }
1000
+ function getTransferSolWithSeedInstructionDataEncoder() {
1001
+ return mapEncoder(
1002
+ getStructEncoder([
1003
+ ["discriminator", getU32Encoder()],
1004
+ ["amount", getU64Encoder()],
1005
+ ["fromSeed", getStringEncoder()],
1006
+ ["fromOwner", getAddressEncoder()]
1007
+ ]),
1008
+ (value) => ({ ...value, discriminator: 11 })
1009
+ );
1010
+ }
1011
+ function getTransferSolWithSeedInstructionDataDecoder() {
1012
+ return getStructDecoder([
1013
+ ["discriminator", getU32Decoder()],
1014
+ ["amount", getU64Decoder()],
1015
+ ["fromSeed", getStringDecoder()],
1016
+ ["fromOwner", getAddressDecoder()]
1017
+ ]);
1018
+ }
1019
+ function getTransferSolWithSeedInstructionDataCodec() {
1020
+ return combineCodec(
1021
+ getTransferSolWithSeedInstructionDataEncoder(),
1022
+ getTransferSolWithSeedInstructionDataDecoder()
1023
+ );
1024
+ }
1025
+ function getTransferSolWithSeedInstruction(input) {
1026
+ const programAddress = "11111111111111111111111111111111";
1027
+ const accounts = {
1028
+ source: { value: input.source ?? null, isWritable: true },
1029
+ baseAccount: { value: input.baseAccount ?? null, isWritable: false },
1030
+ destination: { value: input.destination ?? null, isWritable: true }
1031
+ };
1032
+ const args = { ...input };
1033
+ const accountMetas = getAccountMetasWithSigners(
1034
+ accounts,
1035
+ "programId",
1036
+ programAddress
1037
+ );
1038
+ const instruction = getTransferSolWithSeedInstructionRaw(
1039
+ accountMetas,
1040
+ args,
1041
+ programAddress
1042
+ );
1043
+ return instruction;
1044
+ }
1045
+ function getTransferSolWithSeedInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
1046
+ return {
1047
+ accounts: [
1048
+ accountMetaWithDefault(accounts.source, AccountRole.WRITABLE),
1049
+ accountMetaWithDefault(accounts.baseAccount, AccountRole.READONLY_SIGNER),
1050
+ accountMetaWithDefault(accounts.destination, AccountRole.WRITABLE),
1051
+ ...remainingAccounts ?? []
1052
+ ],
1053
+ data: getTransferSolWithSeedInstructionDataEncoder().encode(args),
1054
+ programAddress
1055
+ };
1056
+ }
1057
+ function parseTransferSolWithSeedInstruction(instruction) {
1058
+ if (instruction.accounts.length < 3) {
1059
+ throw new Error("Not enough accounts");
1060
+ }
1061
+ let accountIndex = 0;
1062
+ const getNextAccount = () => {
1063
+ const accountMeta = instruction.accounts[accountIndex];
1064
+ accountIndex += 1;
1065
+ return accountMeta;
1066
+ };
1067
+ return {
1068
+ programAddress: instruction.programAddress,
1069
+ accounts: {
1070
+ source: getNextAccount(),
1071
+ baseAccount: getNextAccount(),
1072
+ destination: getNextAccount()
1073
+ },
1074
+ data: getTransferSolWithSeedInstructionDataDecoder().decode(
1075
+ instruction.data
1076
+ )
1077
+ };
1078
+ }
1079
+ function getUpgradeNonceAccountInstructionDataEncoder() {
1080
+ return mapEncoder(
1081
+ getStructEncoder([["discriminator", getU32Encoder()]]),
1082
+ (value) => ({ ...value, discriminator: 12 })
1083
+ );
1084
+ }
1085
+ function getUpgradeNonceAccountInstructionDataDecoder() {
1086
+ return getStructDecoder([["discriminator", getU32Decoder()]]);
1087
+ }
1088
+ function getUpgradeNonceAccountInstructionDataCodec() {
1089
+ return combineCodec(
1090
+ getUpgradeNonceAccountInstructionDataEncoder(),
1091
+ getUpgradeNonceAccountInstructionDataDecoder()
1092
+ );
1093
+ }
1094
+ function getUpgradeNonceAccountInstruction(input) {
1095
+ const programAddress = "11111111111111111111111111111111";
1096
+ const accounts = {
1097
+ nonceAccount: { value: input.nonceAccount ?? null, isWritable: true }
1098
+ };
1099
+ const accountMetas = getAccountMetasWithSigners(
1100
+ accounts,
1101
+ "programId",
1102
+ programAddress
1103
+ );
1104
+ const instruction = getUpgradeNonceAccountInstructionRaw(
1105
+ accountMetas,
1106
+ programAddress
1107
+ );
1108
+ return instruction;
1109
+ }
1110
+ function getUpgradeNonceAccountInstructionRaw(accounts, programAddress = "11111111111111111111111111111111", remainingAccounts) {
1111
+ return {
1112
+ accounts: [
1113
+ accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
1114
+ ...remainingAccounts ?? []
1115
+ ],
1116
+ data: getUpgradeNonceAccountInstructionDataEncoder().encode({}),
1117
+ programAddress
1118
+ };
1119
+ }
1120
+ function parseUpgradeNonceAccountInstruction(instruction) {
1121
+ if (instruction.accounts.length < 1) {
1122
+ throw new Error("Not enough accounts");
1123
+ }
1124
+ let accountIndex = 0;
1125
+ const getNextAccount = () => {
1126
+ const accountMeta = instruction.accounts[accountIndex];
1127
+ accountIndex += 1;
1128
+ return accountMeta;
1129
+ };
1130
+ return {
1131
+ programAddress: instruction.programAddress,
1132
+ accounts: {
1133
+ nonceAccount: getNextAccount()
1134
+ },
1135
+ data: getUpgradeNonceAccountInstructionDataDecoder().decode(
1136
+ instruction.data
1137
+ )
1138
+ };
1139
+ }
1140
+ function getWithdrawNonceAccountInstructionDataEncoder() {
1141
+ return mapEncoder(
1142
+ getStructEncoder([
1143
+ ["discriminator", getU32Encoder()],
1144
+ ["withdrawAmount", getU64Encoder()]
1145
+ ]),
1146
+ (value) => ({ ...value, discriminator: 5 })
1147
+ );
1148
+ }
1149
+ function getWithdrawNonceAccountInstructionDataDecoder() {
1150
+ return getStructDecoder([
1151
+ ["discriminator", getU32Decoder()],
1152
+ ["withdrawAmount", getU64Decoder()]
1153
+ ]);
1154
+ }
1155
+ function getWithdrawNonceAccountInstructionDataCodec() {
1156
+ return combineCodec(
1157
+ getWithdrawNonceAccountInstructionDataEncoder(),
1158
+ getWithdrawNonceAccountInstructionDataDecoder()
1159
+ );
1160
+ }
1161
+ function getWithdrawNonceAccountInstruction(input) {
1162
+ const programAddress = "11111111111111111111111111111111";
1163
+ const accounts = {
1164
+ nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
1165
+ recipientAccount: {
1166
+ value: input.recipientAccount ?? null,
1167
+ isWritable: true
1168
+ },
1169
+ recentBlockhashesSysvar: {
1170
+ value: input.recentBlockhashesSysvar ?? null,
1171
+ isWritable: false
1172
+ },
1173
+ rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
1174
+ nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false }
1175
+ };
1176
+ const args = { ...input };
1177
+ if (!accounts.recentBlockhashesSysvar.value) {
1178
+ accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
1179
+ }
1180
+ if (!accounts.rentSysvar.value) {
1181
+ accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
1182
+ }
1183
+ const accountMetas = getAccountMetasWithSigners(
1184
+ accounts,
1185
+ "programId",
1186
+ programAddress
1187
+ );
1188
+ const instruction = getWithdrawNonceAccountInstructionRaw(
1189
+ accountMetas,
1190
+ args,
1191
+ programAddress
1192
+ );
1193
+ return instruction;
1194
+ }
1195
+ function getWithdrawNonceAccountInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
1196
+ return {
1197
+ accounts: [
1198
+ accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
1199
+ accountMetaWithDefault(accounts.recipientAccount, AccountRole.WRITABLE),
1200
+ accountMetaWithDefault(
1201
+ accounts.recentBlockhashesSysvar ?? "SysvarRecentB1ockHashes11111111111111111111",
1202
+ AccountRole.READONLY
1203
+ ),
1204
+ accountMetaWithDefault(
1205
+ accounts.rentSysvar ?? "SysvarRent111111111111111111111111111111111",
1206
+ AccountRole.READONLY
1207
+ ),
1208
+ accountMetaWithDefault(
1209
+ accounts.nonceAuthority,
1210
+ AccountRole.READONLY_SIGNER
1211
+ ),
1212
+ ...remainingAccounts ?? []
1213
+ ],
1214
+ data: getWithdrawNonceAccountInstructionDataEncoder().encode(args),
1215
+ programAddress
1216
+ };
1217
+ }
1218
+ function parseWithdrawNonceAccountInstruction(instruction) {
1219
+ if (instruction.accounts.length < 5) {
1220
+ throw new Error("Not enough accounts");
1221
+ }
1222
+ let accountIndex = 0;
1223
+ const getNextAccount = () => {
1224
+ const accountMeta = instruction.accounts[accountIndex];
1225
+ accountIndex += 1;
1226
+ return accountMeta;
1227
+ };
1228
+ return {
1229
+ programAddress: instruction.programAddress,
1230
+ accounts: {
1231
+ nonceAccount: getNextAccount(),
1232
+ recipientAccount: getNextAccount(),
1233
+ recentBlockhashesSysvar: getNextAccount(),
1234
+ rentSysvar: getNextAccount(),
1235
+ nonceAuthority: getNextAccount()
1236
+ },
1237
+ data: getWithdrawNonceAccountInstructionDataDecoder().decode(
1238
+ instruction.data
1239
+ )
1240
+ };
1241
+ }
1242
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
1243
+ function getSystemProgram() {
1244
+ return {
1245
+ name: "system",
1246
+ address: SYSTEM_PROGRAM_ADDRESS,
1247
+ getErrorFromCode(code, cause) {
1248
+ return getSystemProgramErrorFromCode(code, cause);
1249
+ }
1250
+ };
1251
+ }
1252
+ var SystemAccount = /* @__PURE__ */ ((SystemAccount2) => {
1253
+ SystemAccount2[SystemAccount2["Nonce"] = 0] = "Nonce";
1254
+ return SystemAccount2;
1255
+ })(SystemAccount || {});
1256
+ var SystemInstruction = /* @__PURE__ */ ((SystemInstruction2) => {
1257
+ SystemInstruction2[SystemInstruction2["CreateAccount"] = 0] = "CreateAccount";
1258
+ SystemInstruction2[SystemInstruction2["Assign"] = 1] = "Assign";
1259
+ SystemInstruction2[SystemInstruction2["TransferSol"] = 2] = "TransferSol";
1260
+ SystemInstruction2[SystemInstruction2["CreateAccountWithSeed"] = 3] = "CreateAccountWithSeed";
1261
+ SystemInstruction2[SystemInstruction2["AdvanceNonceAccount"] = 4] = "AdvanceNonceAccount";
1262
+ SystemInstruction2[SystemInstruction2["WithdrawNonceAccount"] = 5] = "WithdrawNonceAccount";
1263
+ SystemInstruction2[SystemInstruction2["InitializeNonceAccount"] = 6] = "InitializeNonceAccount";
1264
+ SystemInstruction2[SystemInstruction2["AuthorizeNonceAccount"] = 7] = "AuthorizeNonceAccount";
1265
+ SystemInstruction2[SystemInstruction2["Allocate"] = 8] = "Allocate";
1266
+ SystemInstruction2[SystemInstruction2["AllocateWithSeed"] = 9] = "AllocateWithSeed";
1267
+ SystemInstruction2[SystemInstruction2["AssignWithSeed"] = 10] = "AssignWithSeed";
1268
+ SystemInstruction2[SystemInstruction2["TransferSolWithSeed"] = 11] = "TransferSolWithSeed";
1269
+ SystemInstruction2[SystemInstruction2["UpgradeNonceAccount"] = 12] = "UpgradeNonceAccount";
1270
+ return SystemInstruction2;
1271
+ })(SystemInstruction || {});
1272
+ function identifySystemInstruction(instruction) {
1273
+ const data = instruction instanceof Uint8Array ? instruction : instruction.data;
1274
+ if (memcmp(data, getU32Encoder().encode(0), 0)) {
1275
+ return 0 /* CreateAccount */;
1276
+ }
1277
+ if (memcmp(data, getU32Encoder().encode(1), 0)) {
1278
+ return 1 /* Assign */;
1279
+ }
1280
+ if (memcmp(data, getU32Encoder().encode(2), 0)) {
1281
+ return 2 /* TransferSol */;
1282
+ }
1283
+ if (memcmp(data, getU32Encoder().encode(3), 0)) {
1284
+ return 3 /* CreateAccountWithSeed */;
1285
+ }
1286
+ if (memcmp(data, getU32Encoder().encode(4), 0)) {
1287
+ return 4 /* AdvanceNonceAccount */;
1288
+ }
1289
+ if (memcmp(data, getU32Encoder().encode(5), 0)) {
1290
+ return 5 /* WithdrawNonceAccount */;
1291
+ }
1292
+ if (memcmp(data, getU32Encoder().encode(6), 0)) {
1293
+ return 6 /* InitializeNonceAccount */;
1294
+ }
1295
+ if (memcmp(data, getU32Encoder().encode(7), 0)) {
1296
+ return 7 /* AuthorizeNonceAccount */;
1297
+ }
1298
+ if (memcmp(data, getU32Encoder().encode(8), 0)) {
1299
+ return 8 /* Allocate */;
1300
+ }
1301
+ if (memcmp(data, getU32Encoder().encode(9), 0)) {
1302
+ return 9 /* AllocateWithSeed */;
1303
+ }
1304
+ if (memcmp(data, getU32Encoder().encode(10), 0)) {
1305
+ return 10 /* AssignWithSeed */;
1306
+ }
1307
+ if (memcmp(data, getU32Encoder().encode(11), 0)) {
1308
+ return 11 /* TransferSolWithSeed */;
1309
+ }
1310
+ if (memcmp(data, getU32Encoder().encode(12), 0)) {
1311
+ return 12 /* UpgradeNonceAccount */;
1312
+ }
1313
+ throw new Error(
1314
+ "The provided instruction could not be identified as a system instruction."
1315
+ );
1316
+ }
1317
+
1318
+ export { NonceState, NonceVersion, SYSTEM_PROGRAM_ADDRESS, SystemAccount, SystemInstruction, SystemProgramError, SystemProgramErrorCode, accountMetaWithDefault, decodeNonce, expectAddress, expectProgramDerivedAddress, expectSome, expectTransactionSigner, fetchAllMaybeNonce, fetchAllNonce, fetchMaybeNonce, fetchNonce, getAccountMetasWithSigners, getAdvanceNonceAccountInstruction, getAdvanceNonceAccountInstructionDataCodec, getAdvanceNonceAccountInstructionDataDecoder, getAdvanceNonceAccountInstructionDataEncoder, getAdvanceNonceAccountInstructionRaw, getAllocateInstruction, getAllocateInstructionDataCodec, getAllocateInstructionDataDecoder, getAllocateInstructionDataEncoder, getAllocateInstructionRaw, getAllocateWithSeedInstruction, getAllocateWithSeedInstructionDataCodec, getAllocateWithSeedInstructionDataDecoder, getAllocateWithSeedInstructionDataEncoder, getAllocateWithSeedInstructionRaw, getAssignInstruction, getAssignInstructionDataCodec, getAssignInstructionDataDecoder, getAssignInstructionDataEncoder, getAssignInstructionRaw, getAssignWithSeedInstruction, getAssignWithSeedInstructionDataCodec, getAssignWithSeedInstructionDataDecoder, getAssignWithSeedInstructionDataEncoder, getAssignWithSeedInstructionRaw, getAuthorizeNonceAccountInstruction, getAuthorizeNonceAccountInstructionDataCodec, getAuthorizeNonceAccountInstructionDataDecoder, getAuthorizeNonceAccountInstructionDataEncoder, getAuthorizeNonceAccountInstructionRaw, getCreateAccountInstruction, getCreateAccountInstructionDataCodec, getCreateAccountInstructionDataDecoder, getCreateAccountInstructionDataEncoder, getCreateAccountInstructionRaw, getCreateAccountWithSeedInstruction, getCreateAccountWithSeedInstructionDataCodec, getCreateAccountWithSeedInstructionDataDecoder, getCreateAccountWithSeedInstructionDataEncoder, getCreateAccountWithSeedInstructionRaw, getInitializeNonceAccountInstruction, getInitializeNonceAccountInstructionDataCodec, getInitializeNonceAccountInstructionDataDecoder, getInitializeNonceAccountInstructionDataEncoder, getInitializeNonceAccountInstructionRaw, getNonceAccountDataCodec, getNonceAccountDataDecoder, getNonceAccountDataEncoder, getNonceSize, getNonceStateCodec, getNonceStateDecoder, getNonceStateEncoder, getNonceVersionCodec, getNonceVersionDecoder, getNonceVersionEncoder, getSystemProgram, getSystemProgramErrorFromCode, getTransferSolInstruction, getTransferSolInstructionDataCodec, getTransferSolInstructionDataDecoder, getTransferSolInstructionDataEncoder, getTransferSolInstructionRaw, getTransferSolWithSeedInstruction, getTransferSolWithSeedInstructionDataCodec, getTransferSolWithSeedInstructionDataDecoder, getTransferSolWithSeedInstructionDataEncoder, getTransferSolWithSeedInstructionRaw, getUpgradeNonceAccountInstruction, getUpgradeNonceAccountInstructionDataCodec, getUpgradeNonceAccountInstructionDataDecoder, getUpgradeNonceAccountInstructionDataEncoder, getUpgradeNonceAccountInstructionRaw, getWithdrawNonceAccountInstruction, getWithdrawNonceAccountInstructionDataCodec, getWithdrawNonceAccountInstructionDataDecoder, getWithdrawNonceAccountInstructionDataEncoder, getWithdrawNonceAccountInstructionRaw, identifySystemInstruction, isTransactionSigner, memcmp, parseAdvanceNonceAccountInstruction, parseAllocateInstruction, parseAllocateWithSeedInstruction, parseAssignInstruction, parseAssignWithSeedInstruction, parseAuthorizeNonceAccountInstruction, parseCreateAccountInstruction, parseCreateAccountWithSeedInstruction, parseInitializeNonceAccountInstruction, parseTransferSolInstruction, parseTransferSolWithSeedInstruction, parseUpgradeNonceAccountInstruction, parseWithdrawNonceAccountInstruction };
1319
+ //# sourceMappingURL=out.js.map
1320
+ //# sourceMappingURL=index.mjs.map