@solana-program/system 0.12.0 → 0.12.2

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 +7 -9
  2. package/dist/src/index.js +103 -6
  3. package/dist/src/index.js.map +1 -1
  4. package/dist/src/index.mjs +98 -8
  5. package/dist/src/index.mjs.map +1 -1
  6. package/dist/types/generated/instructions/advanceNonceAccount.d.ts +1 -1
  7. package/dist/types/generated/instructions/advanceNonceAccount.d.ts.map +1 -1
  8. package/dist/types/generated/instructions/allocate.d.ts +1 -1
  9. package/dist/types/generated/instructions/allocate.d.ts.map +1 -1
  10. package/dist/types/generated/instructions/allocateWithSeed.d.ts +1 -1
  11. package/dist/types/generated/instructions/allocateWithSeed.d.ts.map +1 -1
  12. package/dist/types/generated/instructions/assign.d.ts +1 -1
  13. package/dist/types/generated/instructions/assign.d.ts.map +1 -1
  14. package/dist/types/generated/instructions/assignWithSeed.d.ts +1 -1
  15. package/dist/types/generated/instructions/assignWithSeed.d.ts.map +1 -1
  16. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts +1 -1
  17. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts.map +1 -1
  18. package/dist/types/generated/instructions/createAccount.d.ts +1 -1
  19. package/dist/types/generated/instructions/createAccount.d.ts.map +1 -1
  20. package/dist/types/generated/instructions/createAccountAllowPrefund.d.ts +53 -0
  21. package/dist/types/generated/instructions/createAccountAllowPrefund.d.ts.map +1 -0
  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/index.d.ts +1 -0
  25. package/dist/types/generated/instructions/index.d.ts.map +1 -1
  26. package/dist/types/generated/instructions/initializeNonceAccount.d.ts +1 -1
  27. package/dist/types/generated/instructions/initializeNonceAccount.d.ts.map +1 -1
  28. package/dist/types/generated/instructions/transferSol.d.ts +1 -1
  29. package/dist/types/generated/instructions/transferSol.d.ts.map +1 -1
  30. package/dist/types/generated/instructions/transferSolWithSeed.d.ts +1 -1
  31. package/dist/types/generated/instructions/transferSolWithSeed.d.ts.map +1 -1
  32. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts +1 -1
  33. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts.map +1 -1
  34. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts +1 -1
  35. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts.map +1 -1
  36. package/dist/types/generated/programs/system.d.ts +8 -4
  37. package/dist/types/generated/programs/system.d.ts.map +1 -1
  38. package/package.json +31 -28
  39. package/src/generated/accounts/index.ts +9 -0
  40. package/src/generated/accounts/nonce.ts +139 -0
  41. package/src/generated/errors/index.ts +9 -0
  42. package/src/generated/errors/system.ts +77 -0
  43. package/src/generated/index.ts +13 -0
  44. package/src/generated/instructions/advanceNonceAccount.ts +186 -0
  45. package/src/generated/instructions/allocate.ts +148 -0
  46. package/src/generated/instructions/allocateWithSeed.ts +189 -0
  47. package/src/generated/instructions/assign.ts +145 -0
  48. package/src/generated/instructions/assignWithSeed.ts +177 -0
  49. package/src/generated/instructions/authorizeNonceAccount.ts +169 -0
  50. package/src/generated/instructions/createAccount.ts +184 -0
  51. package/src/generated/instructions/createAccountAllowPrefund.ts +212 -0
  52. package/src/generated/instructions/createAccountWithSeed.ts +221 -0
  53. package/src/generated/instructions/index.ts +22 -0
  54. package/src/generated/instructions/initializeNonceAccount.ts +202 -0
  55. package/src/generated/instructions/transferSol.ts +157 -0
  56. package/src/generated/instructions/transferSolWithSeed.ts +191 -0
  57. package/src/generated/instructions/upgradeNonceAccount.ts +135 -0
  58. package/src/generated/instructions/withdrawNonceAccount.ts +235 -0
  59. package/src/generated/programs/index.ts +9 -0
  60. package/src/generated/programs/system.ts +378 -0
  61. package/src/generated/types/index.ts +10 -0
  62. package/src/generated/types/nonceState.ts +37 -0
  63. package/src/generated/types/nonceVersion.ts +37 -0
  64. package/src/index.ts +1 -0
package/README.md CHANGED
@@ -4,23 +4,19 @@ A generated JavaScript library for the System program.
4
4
 
5
5
  ## Getting started
6
6
 
7
- To build and test your JavaScript client from the root of the repository, you may use the following command.
7
+ The JS client tests use [LiteSVM](https://github.com/LiteSVM/litesvm) in-process, so no local validator is needed. From the root of the repository:
8
8
 
9
9
  ```sh
10
- pnpm clients:js:test
10
+ make test-js-clients-js
11
11
  ```
12
12
 
13
- This will start a new local validator, if one is not already running, and run the tests for your JavaScript client.
13
+ This installs dependencies, builds the client, and runs the test suite.
14
14
 
15
- ## Available client scripts.
15
+ ## Available client scripts
16
16
 
17
- Alternatively, you can go into the client directory and run the tests directly.
17
+ Alternatively, you can go into the client directory and run the scripts directly.
18
18
 
19
19
  ```sh
20
- # Start the validator.
21
- pnpm validator:restart
22
-
23
- # Go into the client directory and run the tests.
24
20
  cd clients/js
25
21
  pnpm install
26
22
  pnpm build
@@ -35,3 +31,5 @@ pnpm lint:fix
35
31
  pnpm format
36
32
  pnpm format:fix
37
33
  ```
34
+
35
+ Equivalent `make` targets from the repo root are `make lint-js-clients-js` and `make format-check-js-clients-js`.
package/dist/src/index.js CHANGED
@@ -495,6 +495,85 @@ function parseCreateAccountInstruction(instruction) {
495
495
  data: getCreateAccountInstructionDataDecoder().decode(instruction.data)
496
496
  };
497
497
  }
498
+ var CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR = 13;
499
+ function getCreateAccountAllowPrefundDiscriminatorBytes() {
500
+ return kit.getU32Encoder().encode(CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR);
501
+ }
502
+ function getCreateAccountAllowPrefundInstructionDataEncoder() {
503
+ return kit.transformEncoder(
504
+ kit.getStructEncoder([
505
+ ["discriminator", kit.getU32Encoder()],
506
+ ["lamports", kit.getU64Encoder()],
507
+ ["space", kit.getU64Encoder()],
508
+ ["programAddress", kit.getAddressEncoder()]
509
+ ]),
510
+ (value) => ({
511
+ ...value,
512
+ discriminator: CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR,
513
+ lamports: value.lamports ?? 0
514
+ })
515
+ );
516
+ }
517
+ function getCreateAccountAllowPrefundInstructionDataDecoder() {
518
+ return kit.getStructDecoder([
519
+ ["discriminator", kit.getU32Decoder()],
520
+ ["lamports", kit.getU64Decoder()],
521
+ ["space", kit.getU64Decoder()],
522
+ ["programAddress", kit.getAddressDecoder()]
523
+ ]);
524
+ }
525
+ function getCreateAccountAllowPrefundInstructionDataCodec() {
526
+ return kit.combineCodec(
527
+ getCreateAccountAllowPrefundInstructionDataEncoder(),
528
+ getCreateAccountAllowPrefundInstructionDataDecoder()
529
+ );
530
+ }
531
+ function getCreateAccountAllowPrefundInstruction(input, config) {
532
+ const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
533
+ const originalAccounts = {
534
+ newAccount: { value: input.newAccount ?? null, isWritable: true },
535
+ payer: { value: input.payer ?? null, isWritable: true }
536
+ };
537
+ const accounts = originalAccounts;
538
+ const args = { ...input };
539
+ const byteDelta = [Number(args.space) + kit.BASE_ACCOUNT_SIZE].reduce((a, b) => a + b, 0);
540
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "omitted");
541
+ return Object.freeze({
542
+ accounts: [getAccountMeta("newAccount", accounts.newAccount), getAccountMeta("payer", accounts.payer)].filter(
543
+ (x) => x !== void 0
544
+ ),
545
+ byteDelta,
546
+ data: getCreateAccountAllowPrefundInstructionDataEncoder().encode(
547
+ args
548
+ ),
549
+ programAddress
550
+ });
551
+ }
552
+ function parseCreateAccountAllowPrefundInstruction(instruction) {
553
+ if (instruction.accounts.length < 1) {
554
+ throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
555
+ actualAccountMetas: instruction.accounts.length,
556
+ expectedAccountMetas: 1
557
+ });
558
+ }
559
+ let accountIndex = 0;
560
+ const getNextAccount = () => {
561
+ const accountMeta = instruction.accounts[accountIndex];
562
+ accountIndex += 1;
563
+ return accountMeta;
564
+ };
565
+ let optionalAccountsRemaining = instruction.accounts.length - 1;
566
+ const getNextOptionalAccount = () => {
567
+ if (optionalAccountsRemaining === 0) return void 0;
568
+ optionalAccountsRemaining -= 1;
569
+ return getNextAccount();
570
+ };
571
+ return {
572
+ programAddress: instruction.programAddress,
573
+ accounts: { newAccount: getNextAccount(), payer: getNextOptionalAccount() },
574
+ data: getCreateAccountAllowPrefundInstructionDataDecoder().decode(instruction.data)
575
+ };
576
+ }
498
577
  var CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR = 3;
499
578
  function getCreateAccountWithSeedDiscriminatorBytes() {
500
579
  return kit.getU32Encoder().encode(CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR);
@@ -917,6 +996,7 @@ var SystemInstruction = /* @__PURE__ */ ((SystemInstruction2) => {
917
996
  SystemInstruction2[SystemInstruction2["AssignWithSeed"] = 10] = "AssignWithSeed";
918
997
  SystemInstruction2[SystemInstruction2["TransferSolWithSeed"] = 11] = "TransferSolWithSeed";
919
998
  SystemInstruction2[SystemInstruction2["UpgradeNonceAccount"] = 12] = "UpgradeNonceAccount";
999
+ SystemInstruction2[SystemInstruction2["CreateAccountAllowPrefund"] = 13] = "CreateAccountAllowPrefund";
920
1000
  return SystemInstruction2;
921
1001
  })(SystemInstruction || {});
922
1002
  function identifySystemInstruction(instruction) {
@@ -960,6 +1040,9 @@ function identifySystemInstruction(instruction) {
960
1040
  if (kit.containsBytes(data, kit.getU32Encoder().encode(12), 0)) {
961
1041
  return 12 /* UpgradeNonceAccount */;
962
1042
  }
1043
+ if (kit.containsBytes(data, kit.getU32Encoder().encode(13), 0)) {
1044
+ return 13 /* CreateAccountAllowPrefund */;
1045
+ }
963
1046
  throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, {
964
1047
  instructionData: data,
965
1048
  programName: "system"
@@ -1047,6 +1130,13 @@ function parseSystemInstruction(instruction) {
1047
1130
  ...parseUpgradeNonceAccountInstruction(instruction)
1048
1131
  };
1049
1132
  }
1133
+ case 13 /* CreateAccountAllowPrefund */: {
1134
+ kit.assertIsInstructionWithAccounts(instruction);
1135
+ return {
1136
+ instructionType: 13 /* CreateAccountAllowPrefund */,
1137
+ ...parseCreateAccountAllowPrefundInstruction(instruction)
1138
+ };
1139
+ }
1050
1140
  default:
1051
1141
  throw new kit.SolanaError(kit.SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, {
1052
1142
  instructionType,
@@ -1056,8 +1146,7 @@ function parseSystemInstruction(instruction) {
1056
1146
  }
1057
1147
  function systemProgram() {
1058
1148
  return (client) => {
1059
- return {
1060
- ...client,
1149
+ return kit.extendClient(client, {
1061
1150
  system: {
1062
1151
  accounts: { nonce: programClientCore.addSelfFetchFunctions(client, getNonceCodec()) },
1063
1152
  instructions: {
@@ -1079,10 +1168,11 @@ function systemProgram() {
1079
1168
  allocateWithSeed: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getAllocateWithSeedInstruction(input)),
1080
1169
  assignWithSeed: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getAssignWithSeedInstruction(input)),
1081
1170
  transferSolWithSeed: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getTransferSolWithSeedInstruction(input)),
1082
- upgradeNonceAccount: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getUpgradeNonceAccountInstruction(input))
1171
+ upgradeNonceAccount: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getUpgradeNonceAccountInstruction(input)),
1172
+ createAccountAllowPrefund: (input) => programClientCore.addSelfPlanAndSendFunctions(client, getCreateAccountAllowPrefundInstruction(input))
1083
1173
  }
1084
1174
  }
1085
- };
1175
+ });
1086
1176
  };
1087
1177
  }
1088
1178
 
@@ -1097,7 +1187,7 @@ var SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES = 6;
1097
1187
  var SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED = 7;
1098
1188
  var SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE = 8;
1099
1189
  var systemErrorMessages;
1100
- if (process.env.NODE_ENV !== "production") {
1190
+ if (process.env["NODE_ENV"] !== "production") {
1101
1191
  systemErrorMessages = {
1102
1192
  [SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE]: `an account with the same address already exists`,
1103
1193
  [SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH]: `provided address does not match addressed derived from seed`,
@@ -1111,7 +1201,7 @@ if (process.env.NODE_ENV !== "production") {
1111
1201
  };
1112
1202
  }
1113
1203
  function getSystemErrorMessage(code) {
1114
- if (process.env.NODE_ENV !== "production") {
1204
+ if (process.env["NODE_ENV"] !== "production") {
1115
1205
  return systemErrorMessages[code];
1116
1206
  }
1117
1207
  return "Error message not available in production bundles.";
@@ -1126,6 +1216,7 @@ exports.ALLOCATE_WITH_SEED_DISCRIMINATOR = ALLOCATE_WITH_SEED_DISCRIMINATOR;
1126
1216
  exports.ASSIGN_DISCRIMINATOR = ASSIGN_DISCRIMINATOR;
1127
1217
  exports.ASSIGN_WITH_SEED_DISCRIMINATOR = ASSIGN_WITH_SEED_DISCRIMINATOR;
1128
1218
  exports.AUTHORIZE_NONCE_ACCOUNT_DISCRIMINATOR = AUTHORIZE_NONCE_ACCOUNT_DISCRIMINATOR;
1219
+ exports.CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR = CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR;
1129
1220
  exports.CREATE_ACCOUNT_DISCRIMINATOR = CREATE_ACCOUNT_DISCRIMINATOR;
1130
1221
  exports.CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR = CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR;
1131
1222
  exports.INITIALIZE_NONCE_ACCOUNT_DISCRIMINATOR = INITIALIZE_NONCE_ACCOUNT_DISCRIMINATOR;
@@ -1182,6 +1273,11 @@ exports.getAuthorizeNonceAccountInstruction = getAuthorizeNonceAccountInstructio
1182
1273
  exports.getAuthorizeNonceAccountInstructionDataCodec = getAuthorizeNonceAccountInstructionDataCodec;
1183
1274
  exports.getAuthorizeNonceAccountInstructionDataDecoder = getAuthorizeNonceAccountInstructionDataDecoder;
1184
1275
  exports.getAuthorizeNonceAccountInstructionDataEncoder = getAuthorizeNonceAccountInstructionDataEncoder;
1276
+ exports.getCreateAccountAllowPrefundDiscriminatorBytes = getCreateAccountAllowPrefundDiscriminatorBytes;
1277
+ exports.getCreateAccountAllowPrefundInstruction = getCreateAccountAllowPrefundInstruction;
1278
+ exports.getCreateAccountAllowPrefundInstructionDataCodec = getCreateAccountAllowPrefundInstructionDataCodec;
1279
+ exports.getCreateAccountAllowPrefundInstructionDataDecoder = getCreateAccountAllowPrefundInstructionDataDecoder;
1280
+ exports.getCreateAccountAllowPrefundInstructionDataEncoder = getCreateAccountAllowPrefundInstructionDataEncoder;
1185
1281
  exports.getCreateAccountDiscriminatorBytes = getCreateAccountDiscriminatorBytes;
1186
1282
  exports.getCreateAccountInstruction = getCreateAccountInstruction;
1187
1283
  exports.getCreateAccountInstructionDataCodec = getCreateAccountInstructionDataCodec;
@@ -1236,6 +1332,7 @@ exports.parseAllocateWithSeedInstruction = parseAllocateWithSeedInstruction;
1236
1332
  exports.parseAssignInstruction = parseAssignInstruction;
1237
1333
  exports.parseAssignWithSeedInstruction = parseAssignWithSeedInstruction;
1238
1334
  exports.parseAuthorizeNonceAccountInstruction = parseAuthorizeNonceAccountInstruction;
1335
+ exports.parseCreateAccountAllowPrefundInstruction = parseCreateAccountAllowPrefundInstruction;
1239
1336
  exports.parseCreateAccountInstruction = parseCreateAccountInstruction;
1240
1337
  exports.parseCreateAccountWithSeedInstruction = parseCreateAccountWithSeedInstruction;
1241
1338
  exports.parseInitializeNonceAccountInstruction = parseInitializeNonceAccountInstruction;