@solana-program/system 0.8.0 → 0.9.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 (43) hide show
  1. package/dist/src/index.js +83 -110
  2. package/dist/src/index.js.map +1 -1
  3. package/dist/src/index.mjs +83 -110
  4. package/dist/src/index.mjs.map +1 -1
  5. package/dist/types/generated/accounts/index.d.ts +2 -2
  6. package/dist/types/generated/accounts/nonce.d.ts +2 -2
  7. package/dist/types/generated/errors/index.d.ts +2 -2
  8. package/dist/types/generated/errors/system.d.ts +2 -2
  9. package/dist/types/generated/index.d.ts +2 -2
  10. package/dist/types/generated/instructions/advanceNonceAccount.d.ts +2 -2
  11. package/dist/types/generated/instructions/advanceNonceAccount.d.ts.map +1 -1
  12. package/dist/types/generated/instructions/allocate.d.ts +2 -2
  13. package/dist/types/generated/instructions/allocate.d.ts.map +1 -1
  14. package/dist/types/generated/instructions/allocateWithSeed.d.ts +2 -2
  15. package/dist/types/generated/instructions/allocateWithSeed.d.ts.map +1 -1
  16. package/dist/types/generated/instructions/assign.d.ts +2 -2
  17. package/dist/types/generated/instructions/assign.d.ts.map +1 -1
  18. package/dist/types/generated/instructions/assignWithSeed.d.ts +2 -2
  19. package/dist/types/generated/instructions/assignWithSeed.d.ts.map +1 -1
  20. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts +2 -2
  21. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts.map +1 -1
  22. package/dist/types/generated/instructions/createAccount.d.ts +2 -2
  23. package/dist/types/generated/instructions/createAccount.d.ts.map +1 -1
  24. package/dist/types/generated/instructions/createAccountWithSeed.d.ts +8 -6
  25. package/dist/types/generated/instructions/createAccountWithSeed.d.ts.map +1 -1
  26. package/dist/types/generated/instructions/index.d.ts +2 -2
  27. package/dist/types/generated/instructions/initializeNonceAccount.d.ts +2 -2
  28. package/dist/types/generated/instructions/initializeNonceAccount.d.ts.map +1 -1
  29. package/dist/types/generated/instructions/transferSol.d.ts +2 -2
  30. package/dist/types/generated/instructions/transferSol.d.ts.map +1 -1
  31. package/dist/types/generated/instructions/transferSolWithSeed.d.ts +2 -2
  32. package/dist/types/generated/instructions/transferSolWithSeed.d.ts.map +1 -1
  33. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts +2 -2
  34. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts.map +1 -1
  35. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts +2 -2
  36. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts.map +1 -1
  37. package/dist/types/generated/programs/index.d.ts +2 -2
  38. package/dist/types/generated/programs/system.d.ts +2 -2
  39. package/dist/types/generated/shared/index.d.ts +2 -2
  40. package/dist/types/generated/types/index.d.ts +2 -2
  41. package/dist/types/generated/types/nonceState.d.ts +2 -2
  42. package/dist/types/generated/types/nonceVersion.d.ts +2 -2
  43. package/package.json +4 -4
@@ -199,10 +199,7 @@ function expectAddress(value) {
199
199
  function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
200
200
  return (account) => {
201
201
  if (!account.value) {
202
- return Object.freeze({
203
- address: programAddress,
204
- role: AccountRole.READONLY
205
- });
202
+ return;
206
203
  }
207
204
  const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;
208
205
  return Object.freeze({
@@ -253,17 +250,16 @@ function getAdvanceNonceAccountInstruction(input, config) {
253
250
  if (!accounts.recentBlockhashesSysvar.value) {
254
251
  accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
255
252
  }
256
- const getAccountMeta = getAccountMetaFactory(programAddress);
257
- const instruction = {
253
+ const getAccountMeta = getAccountMetaFactory();
254
+ return Object.freeze({
258
255
  accounts: [
259
256
  getAccountMeta(accounts.nonceAccount),
260
257
  getAccountMeta(accounts.recentBlockhashesSysvar),
261
258
  getAccountMeta(accounts.nonceAuthority)
262
259
  ],
263
- programAddress,
264
- data: getAdvanceNonceAccountInstructionDataEncoder().encode({})
265
- };
266
- return instruction;
260
+ data: getAdvanceNonceAccountInstructionDataEncoder().encode({}),
261
+ programAddress
262
+ });
267
263
  }
268
264
  function parseAdvanceNonceAccountInstruction(instruction) {
269
265
  if (instruction.accounts.length < 3) {
@@ -319,15 +315,14 @@ function getAllocateInstruction(input, config) {
319
315
  };
320
316
  const accounts = originalAccounts;
321
317
  const args = { ...input };
322
- const getAccountMeta = getAccountMetaFactory(programAddress);
323
- const instruction = {
318
+ const getAccountMeta = getAccountMetaFactory();
319
+ return Object.freeze({
324
320
  accounts: [getAccountMeta(accounts.newAccount)],
325
- programAddress,
326
321
  data: getAllocateInstructionDataEncoder().encode(
327
322
  args
328
- )
329
- };
330
- return instruction;
323
+ ),
324
+ programAddress
325
+ });
331
326
  }
332
327
  function parseAllocateInstruction(instruction) {
333
328
  if (instruction.accounts.length < 1) {
@@ -341,9 +336,7 @@ function parseAllocateInstruction(instruction) {
341
336
  };
342
337
  return {
343
338
  programAddress: instruction.programAddress,
344
- accounts: {
345
- newAccount: getNextAccount()
346
- },
339
+ accounts: { newAccount: getNextAccount() },
347
340
  data: getAllocateInstructionDataDecoder().decode(instruction.data)
348
341
  };
349
342
  }
@@ -386,18 +379,17 @@ function getAllocateWithSeedInstruction(input, config) {
386
379
  };
387
380
  const accounts = originalAccounts;
388
381
  const args = { ...input };
389
- const getAccountMeta = getAccountMetaFactory(programAddress);
390
- const instruction = {
382
+ const getAccountMeta = getAccountMetaFactory();
383
+ return Object.freeze({
391
384
  accounts: [
392
385
  getAccountMeta(accounts.newAccount),
393
386
  getAccountMeta(accounts.baseAccount)
394
387
  ],
395
- programAddress,
396
388
  data: getAllocateWithSeedInstructionDataEncoder().encode(
397
389
  args
398
- )
399
- };
400
- return instruction;
390
+ ),
391
+ programAddress
392
+ });
401
393
  }
402
394
  function parseAllocateWithSeedInstruction(instruction) {
403
395
  if (instruction.accounts.length < 2) {
@@ -411,10 +403,7 @@ function parseAllocateWithSeedInstruction(instruction) {
411
403
  };
412
404
  return {
413
405
  programAddress: instruction.programAddress,
414
- accounts: {
415
- newAccount: getNextAccount(),
416
- baseAccount: getNextAccount()
417
- },
406
+ accounts: { newAccount: getNextAccount(), baseAccount: getNextAccount() },
418
407
  data: getAllocateWithSeedInstructionDataDecoder().decode(instruction.data)
419
408
  };
420
409
  }
@@ -450,15 +439,14 @@ function getAssignInstruction(input, config) {
450
439
  };
451
440
  const accounts = originalAccounts;
452
441
  const args = { ...input };
453
- const getAccountMeta = getAccountMetaFactory(programAddress);
454
- const instruction = {
442
+ const getAccountMeta = getAccountMetaFactory();
443
+ return Object.freeze({
455
444
  accounts: [getAccountMeta(accounts.account)],
456
- programAddress,
457
445
  data: getAssignInstructionDataEncoder().encode(
458
446
  args
459
- )
460
- };
461
- return instruction;
447
+ ),
448
+ programAddress
449
+ });
462
450
  }
463
451
  function parseAssignInstruction(instruction) {
464
452
  if (instruction.accounts.length < 1) {
@@ -472,9 +460,7 @@ function parseAssignInstruction(instruction) {
472
460
  };
473
461
  return {
474
462
  programAddress: instruction.programAddress,
475
- accounts: {
476
- account: getNextAccount()
477
- },
463
+ accounts: { account: getNextAccount() },
478
464
  data: getAssignInstructionDataDecoder().decode(instruction.data)
479
465
  };
480
466
  }
@@ -515,18 +501,17 @@ function getAssignWithSeedInstruction(input, config) {
515
501
  };
516
502
  const accounts = originalAccounts;
517
503
  const args = { ...input };
518
- const getAccountMeta = getAccountMetaFactory(programAddress);
519
- const instruction = {
504
+ const getAccountMeta = getAccountMetaFactory();
505
+ return Object.freeze({
520
506
  accounts: [
521
507
  getAccountMeta(accounts.account),
522
508
  getAccountMeta(accounts.baseAccount)
523
509
  ],
524
- programAddress,
525
510
  data: getAssignWithSeedInstructionDataEncoder().encode(
526
511
  args
527
- )
528
- };
529
- return instruction;
512
+ ),
513
+ programAddress
514
+ });
530
515
  }
531
516
  function parseAssignWithSeedInstruction(instruction) {
532
517
  if (instruction.accounts.length < 2) {
@@ -540,10 +525,7 @@ function parseAssignWithSeedInstruction(instruction) {
540
525
  };
541
526
  return {
542
527
  programAddress: instruction.programAddress,
543
- accounts: {
544
- account: getNextAccount(),
545
- baseAccount: getNextAccount()
546
- },
528
+ accounts: { account: getNextAccount(), baseAccount: getNextAccount() },
547
529
  data: getAssignWithSeedInstructionDataDecoder().decode(instruction.data)
548
530
  };
549
531
  }
@@ -583,18 +565,17 @@ function getAuthorizeNonceAccountInstruction(input, config) {
583
565
  };
584
566
  const accounts = originalAccounts;
585
567
  const args = { ...input };
586
- const getAccountMeta = getAccountMetaFactory(programAddress);
587
- const instruction = {
568
+ const getAccountMeta = getAccountMetaFactory();
569
+ return Object.freeze({
588
570
  accounts: [
589
571
  getAccountMeta(accounts.nonceAccount),
590
572
  getAccountMeta(accounts.nonceAuthority)
591
573
  ],
592
- programAddress,
593
574
  data: getAuthorizeNonceAccountInstructionDataEncoder().encode(
594
575
  args
595
- )
596
- };
597
- return instruction;
576
+ ),
577
+ programAddress
578
+ });
598
579
  }
599
580
  function parseAuthorizeNonceAccountInstruction(instruction) {
600
581
  if (instruction.accounts.length < 2) {
@@ -658,18 +639,18 @@ function getCreateAccountInstruction(input, config) {
658
639
  (a, b) => a + b,
659
640
  0
660
641
  );
661
- const getAccountMeta = getAccountMetaFactory(programAddress);
662
- const instruction = {
642
+ const getAccountMeta = getAccountMetaFactory();
643
+ return Object.freeze({
663
644
  accounts: [
664
645
  getAccountMeta(accounts.payer),
665
646
  getAccountMeta(accounts.newAccount)
666
647
  ],
667
- programAddress,
648
+ byteDelta,
668
649
  data: getCreateAccountInstructionDataEncoder().encode(
669
650
  args
670
- )
671
- };
672
- return Object.freeze({ ...instruction, byteDelta });
651
+ ),
652
+ programAddress
653
+ });
673
654
  }
674
655
  function parseCreateAccountInstruction(instruction) {
675
656
  if (instruction.accounts.length < 2) {
@@ -683,10 +664,7 @@ function parseCreateAccountInstruction(instruction) {
683
664
  };
684
665
  return {
685
666
  programAddress: instruction.programAddress,
686
- accounts: {
687
- payer: getNextAccount(),
688
- newAccount: getNextAccount()
689
- },
667
+ accounts: { payer: getNextAccount(), newAccount: getNextAccount() },
690
668
  data: getCreateAccountInstructionDataDecoder().decode(instruction.data)
691
669
  };
692
670
  }
@@ -735,22 +713,21 @@ function getCreateAccountWithSeedInstruction(input, config) {
735
713
  };
736
714
  const accounts = originalAccounts;
737
715
  const args = { ...input };
738
- const getAccountMeta = getAccountMetaFactory(programAddress);
739
- const instruction = {
716
+ const getAccountMeta = getAccountMetaFactory();
717
+ return Object.freeze({
740
718
  accounts: [
741
719
  getAccountMeta(accounts.payer),
742
720
  getAccountMeta(accounts.newAccount),
743
721
  getAccountMeta(accounts.baseAccount)
744
- ],
745
- programAddress,
722
+ ].filter((x) => x !== void 0),
746
723
  data: getCreateAccountWithSeedInstructionDataEncoder().encode(
747
724
  args
748
- )
749
- };
750
- return instruction;
725
+ ),
726
+ programAddress
727
+ });
751
728
  }
752
729
  function parseCreateAccountWithSeedInstruction(instruction) {
753
- if (instruction.accounts.length < 3) {
730
+ if (instruction.accounts.length < 2) {
754
731
  throw new Error("Not enough accounts");
755
732
  }
756
733
  let accountIndex = 0;
@@ -759,12 +736,18 @@ function parseCreateAccountWithSeedInstruction(instruction) {
759
736
  accountIndex += 1;
760
737
  return accountMeta;
761
738
  };
739
+ let optionalAccountsRemaining = instruction.accounts.length - 2;
740
+ const getNextOptionalAccount = () => {
741
+ if (optionalAccountsRemaining === 0) return void 0;
742
+ optionalAccountsRemaining -= 1;
743
+ return getNextAccount();
744
+ };
762
745
  return {
763
746
  programAddress: instruction.programAddress,
764
747
  accounts: {
765
748
  payer: getNextAccount(),
766
749
  newAccount: getNextAccount(),
767
- baseAccount: getNextAccount()
750
+ baseAccount: getNextOptionalAccount()
768
751
  },
769
752
  data: getCreateAccountWithSeedInstructionDataDecoder().decode(
770
753
  instruction.data
@@ -817,19 +800,18 @@ function getInitializeNonceAccountInstruction(input, config) {
817
800
  if (!accounts.rentSysvar.value) {
818
801
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
819
802
  }
820
- const getAccountMeta = getAccountMetaFactory(programAddress);
821
- const instruction = {
803
+ const getAccountMeta = getAccountMetaFactory();
804
+ return Object.freeze({
822
805
  accounts: [
823
806
  getAccountMeta(accounts.nonceAccount),
824
807
  getAccountMeta(accounts.recentBlockhashesSysvar),
825
808
  getAccountMeta(accounts.rentSysvar)
826
809
  ],
827
- programAddress,
828
810
  data: getInitializeNonceAccountInstructionDataEncoder().encode(
829
811
  args
830
- )
831
- };
832
- return instruction;
812
+ ),
813
+ programAddress
814
+ });
833
815
  }
834
816
  function parseInitializeNonceAccountInstruction(instruction) {
835
817
  if (instruction.accounts.length < 3) {
@@ -886,18 +868,17 @@ function getTransferSolInstruction(input, config) {
886
868
  };
887
869
  const accounts = originalAccounts;
888
870
  const args = { ...input };
889
- const getAccountMeta = getAccountMetaFactory(programAddress);
890
- const instruction = {
871
+ const getAccountMeta = getAccountMetaFactory();
872
+ return Object.freeze({
891
873
  accounts: [
892
874
  getAccountMeta(accounts.source),
893
875
  getAccountMeta(accounts.destination)
894
876
  ],
895
- programAddress,
896
877
  data: getTransferSolInstructionDataEncoder().encode(
897
878
  args
898
- )
899
- };
900
- return instruction;
879
+ ),
880
+ programAddress
881
+ });
901
882
  }
902
883
  function parseTransferSolInstruction(instruction) {
903
884
  if (instruction.accounts.length < 2) {
@@ -911,10 +892,7 @@ function parseTransferSolInstruction(instruction) {
911
892
  };
912
893
  return {
913
894
  programAddress: instruction.programAddress,
914
- accounts: {
915
- source: getNextAccount(),
916
- destination: getNextAccount()
917
- },
895
+ accounts: { source: getNextAccount(), destination: getNextAccount() },
918
896
  data: getTransferSolInstructionDataDecoder().decode(instruction.data)
919
897
  };
920
898
  }
@@ -959,19 +937,18 @@ function getTransferSolWithSeedInstruction(input, config) {
959
937
  };
960
938
  const accounts = originalAccounts;
961
939
  const args = { ...input };
962
- const getAccountMeta = getAccountMetaFactory(programAddress);
963
- const instruction = {
940
+ const getAccountMeta = getAccountMetaFactory();
941
+ return Object.freeze({
964
942
  accounts: [
965
943
  getAccountMeta(accounts.source),
966
944
  getAccountMeta(accounts.baseAccount),
967
945
  getAccountMeta(accounts.destination)
968
946
  ],
969
- programAddress,
970
947
  data: getTransferSolWithSeedInstructionDataEncoder().encode(
971
948
  args
972
- )
973
- };
974
- return instruction;
949
+ ),
950
+ programAddress
951
+ });
975
952
  }
976
953
  function parseTransferSolWithSeedInstruction(instruction) {
977
954
  if (instruction.accounts.length < 3) {
@@ -1023,13 +1000,12 @@ function getUpgradeNonceAccountInstruction(input, config) {
1023
1000
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true }
1024
1001
  };
1025
1002
  const accounts = originalAccounts;
1026
- const getAccountMeta = getAccountMetaFactory(programAddress);
1027
- const instruction = {
1003
+ const getAccountMeta = getAccountMetaFactory();
1004
+ return Object.freeze({
1028
1005
  accounts: [getAccountMeta(accounts.nonceAccount)],
1029
- programAddress,
1030
- data: getUpgradeNonceAccountInstructionDataEncoder().encode({})
1031
- };
1032
- return instruction;
1006
+ data: getUpgradeNonceAccountInstructionDataEncoder().encode({}),
1007
+ programAddress
1008
+ });
1033
1009
  }
1034
1010
  function parseUpgradeNonceAccountInstruction(instruction) {
1035
1011
  if (instruction.accounts.length < 1) {
@@ -1043,9 +1019,7 @@ function parseUpgradeNonceAccountInstruction(instruction) {
1043
1019
  };
1044
1020
  return {
1045
1021
  programAddress: instruction.programAddress,
1046
- accounts: {
1047
- nonceAccount: getNextAccount()
1048
- },
1022
+ accounts: { nonceAccount: getNextAccount() },
1049
1023
  data: getUpgradeNonceAccountInstructionDataDecoder().decode(
1050
1024
  instruction.data
1051
1025
  )
@@ -1102,8 +1076,8 @@ function getWithdrawNonceAccountInstruction(input, config) {
1102
1076
  if (!accounts.rentSysvar.value) {
1103
1077
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
1104
1078
  }
1105
- const getAccountMeta = getAccountMetaFactory(programAddress);
1106
- const instruction = {
1079
+ const getAccountMeta = getAccountMetaFactory();
1080
+ return Object.freeze({
1107
1081
  accounts: [
1108
1082
  getAccountMeta(accounts.nonceAccount),
1109
1083
  getAccountMeta(accounts.recipientAccount),
@@ -1111,12 +1085,11 @@ function getWithdrawNonceAccountInstruction(input, config) {
1111
1085
  getAccountMeta(accounts.rentSysvar),
1112
1086
  getAccountMeta(accounts.nonceAuthority)
1113
1087
  ],
1114
- programAddress,
1115
1088
  data: getWithdrawNonceAccountInstructionDataEncoder().encode(
1116
1089
  args
1117
- )
1118
- };
1119
- return instruction;
1090
+ ),
1091
+ programAddress
1092
+ });
1120
1093
  }
1121
1094
  function parseWithdrawNonceAccountInstruction(instruction) {
1122
1095
  if (instruction.accounts.length < 5) {