@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
package/dist/src/index.js CHANGED
@@ -201,10 +201,7 @@ function expectAddress(value) {
201
201
  function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
202
202
  return (account) => {
203
203
  if (!account.value) {
204
- return Object.freeze({
205
- address: programAddress,
206
- role: kit.AccountRole.READONLY
207
- });
204
+ return;
208
205
  }
209
206
  const writableRole = account.isWritable ? kit.AccountRole.WRITABLE : kit.AccountRole.READONLY;
210
207
  return Object.freeze({
@@ -255,17 +252,16 @@ function getAdvanceNonceAccountInstruction(input, config) {
255
252
  if (!accounts.recentBlockhashesSysvar.value) {
256
253
  accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
257
254
  }
258
- const getAccountMeta = getAccountMetaFactory(programAddress);
259
- const instruction = {
255
+ const getAccountMeta = getAccountMetaFactory();
256
+ return Object.freeze({
260
257
  accounts: [
261
258
  getAccountMeta(accounts.nonceAccount),
262
259
  getAccountMeta(accounts.recentBlockhashesSysvar),
263
260
  getAccountMeta(accounts.nonceAuthority)
264
261
  ],
265
- programAddress,
266
- data: getAdvanceNonceAccountInstructionDataEncoder().encode({})
267
- };
268
- return instruction;
262
+ data: getAdvanceNonceAccountInstructionDataEncoder().encode({}),
263
+ programAddress
264
+ });
269
265
  }
270
266
  function parseAdvanceNonceAccountInstruction(instruction) {
271
267
  if (instruction.accounts.length < 3) {
@@ -321,15 +317,14 @@ function getAllocateInstruction(input, config) {
321
317
  };
322
318
  const accounts = originalAccounts;
323
319
  const args = { ...input };
324
- const getAccountMeta = getAccountMetaFactory(programAddress);
325
- const instruction = {
320
+ const getAccountMeta = getAccountMetaFactory();
321
+ return Object.freeze({
326
322
  accounts: [getAccountMeta(accounts.newAccount)],
327
- programAddress,
328
323
  data: getAllocateInstructionDataEncoder().encode(
329
324
  args
330
- )
331
- };
332
- return instruction;
325
+ ),
326
+ programAddress
327
+ });
333
328
  }
334
329
  function parseAllocateInstruction(instruction) {
335
330
  if (instruction.accounts.length < 1) {
@@ -343,9 +338,7 @@ function parseAllocateInstruction(instruction) {
343
338
  };
344
339
  return {
345
340
  programAddress: instruction.programAddress,
346
- accounts: {
347
- newAccount: getNextAccount()
348
- },
341
+ accounts: { newAccount: getNextAccount() },
349
342
  data: getAllocateInstructionDataDecoder().decode(instruction.data)
350
343
  };
351
344
  }
@@ -388,18 +381,17 @@ function getAllocateWithSeedInstruction(input, config) {
388
381
  };
389
382
  const accounts = originalAccounts;
390
383
  const args = { ...input };
391
- const getAccountMeta = getAccountMetaFactory(programAddress);
392
- const instruction = {
384
+ const getAccountMeta = getAccountMetaFactory();
385
+ return Object.freeze({
393
386
  accounts: [
394
387
  getAccountMeta(accounts.newAccount),
395
388
  getAccountMeta(accounts.baseAccount)
396
389
  ],
397
- programAddress,
398
390
  data: getAllocateWithSeedInstructionDataEncoder().encode(
399
391
  args
400
- )
401
- };
402
- return instruction;
392
+ ),
393
+ programAddress
394
+ });
403
395
  }
404
396
  function parseAllocateWithSeedInstruction(instruction) {
405
397
  if (instruction.accounts.length < 2) {
@@ -413,10 +405,7 @@ function parseAllocateWithSeedInstruction(instruction) {
413
405
  };
414
406
  return {
415
407
  programAddress: instruction.programAddress,
416
- accounts: {
417
- newAccount: getNextAccount(),
418
- baseAccount: getNextAccount()
419
- },
408
+ accounts: { newAccount: getNextAccount(), baseAccount: getNextAccount() },
420
409
  data: getAllocateWithSeedInstructionDataDecoder().decode(instruction.data)
421
410
  };
422
411
  }
@@ -452,15 +441,14 @@ function getAssignInstruction(input, config) {
452
441
  };
453
442
  const accounts = originalAccounts;
454
443
  const args = { ...input };
455
- const getAccountMeta = getAccountMetaFactory(programAddress);
456
- const instruction = {
444
+ const getAccountMeta = getAccountMetaFactory();
445
+ return Object.freeze({
457
446
  accounts: [getAccountMeta(accounts.account)],
458
- programAddress,
459
447
  data: getAssignInstructionDataEncoder().encode(
460
448
  args
461
- )
462
- };
463
- return instruction;
449
+ ),
450
+ programAddress
451
+ });
464
452
  }
465
453
  function parseAssignInstruction(instruction) {
466
454
  if (instruction.accounts.length < 1) {
@@ -474,9 +462,7 @@ function parseAssignInstruction(instruction) {
474
462
  };
475
463
  return {
476
464
  programAddress: instruction.programAddress,
477
- accounts: {
478
- account: getNextAccount()
479
- },
465
+ accounts: { account: getNextAccount() },
480
466
  data: getAssignInstructionDataDecoder().decode(instruction.data)
481
467
  };
482
468
  }
@@ -517,18 +503,17 @@ function getAssignWithSeedInstruction(input, config) {
517
503
  };
518
504
  const accounts = originalAccounts;
519
505
  const args = { ...input };
520
- const getAccountMeta = getAccountMetaFactory(programAddress);
521
- const instruction = {
506
+ const getAccountMeta = getAccountMetaFactory();
507
+ return Object.freeze({
522
508
  accounts: [
523
509
  getAccountMeta(accounts.account),
524
510
  getAccountMeta(accounts.baseAccount)
525
511
  ],
526
- programAddress,
527
512
  data: getAssignWithSeedInstructionDataEncoder().encode(
528
513
  args
529
- )
530
- };
531
- return instruction;
514
+ ),
515
+ programAddress
516
+ });
532
517
  }
533
518
  function parseAssignWithSeedInstruction(instruction) {
534
519
  if (instruction.accounts.length < 2) {
@@ -542,10 +527,7 @@ function parseAssignWithSeedInstruction(instruction) {
542
527
  };
543
528
  return {
544
529
  programAddress: instruction.programAddress,
545
- accounts: {
546
- account: getNextAccount(),
547
- baseAccount: getNextAccount()
548
- },
530
+ accounts: { account: getNextAccount(), baseAccount: getNextAccount() },
549
531
  data: getAssignWithSeedInstructionDataDecoder().decode(instruction.data)
550
532
  };
551
533
  }
@@ -585,18 +567,17 @@ function getAuthorizeNonceAccountInstruction(input, config) {
585
567
  };
586
568
  const accounts = originalAccounts;
587
569
  const args = { ...input };
588
- const getAccountMeta = getAccountMetaFactory(programAddress);
589
- const instruction = {
570
+ const getAccountMeta = getAccountMetaFactory();
571
+ return Object.freeze({
590
572
  accounts: [
591
573
  getAccountMeta(accounts.nonceAccount),
592
574
  getAccountMeta(accounts.nonceAuthority)
593
575
  ],
594
- programAddress,
595
576
  data: getAuthorizeNonceAccountInstructionDataEncoder().encode(
596
577
  args
597
- )
598
- };
599
- return instruction;
578
+ ),
579
+ programAddress
580
+ });
600
581
  }
601
582
  function parseAuthorizeNonceAccountInstruction(instruction) {
602
583
  if (instruction.accounts.length < 2) {
@@ -660,18 +641,18 @@ function getCreateAccountInstruction(input, config) {
660
641
  (a, b) => a + b,
661
642
  0
662
643
  );
663
- const getAccountMeta = getAccountMetaFactory(programAddress);
664
- const instruction = {
644
+ const getAccountMeta = getAccountMetaFactory();
645
+ return Object.freeze({
665
646
  accounts: [
666
647
  getAccountMeta(accounts.payer),
667
648
  getAccountMeta(accounts.newAccount)
668
649
  ],
669
- programAddress,
650
+ byteDelta,
670
651
  data: getCreateAccountInstructionDataEncoder().encode(
671
652
  args
672
- )
673
- };
674
- return Object.freeze({ ...instruction, byteDelta });
653
+ ),
654
+ programAddress
655
+ });
675
656
  }
676
657
  function parseCreateAccountInstruction(instruction) {
677
658
  if (instruction.accounts.length < 2) {
@@ -685,10 +666,7 @@ function parseCreateAccountInstruction(instruction) {
685
666
  };
686
667
  return {
687
668
  programAddress: instruction.programAddress,
688
- accounts: {
689
- payer: getNextAccount(),
690
- newAccount: getNextAccount()
691
- },
669
+ accounts: { payer: getNextAccount(), newAccount: getNextAccount() },
692
670
  data: getCreateAccountInstructionDataDecoder().decode(instruction.data)
693
671
  };
694
672
  }
@@ -737,22 +715,21 @@ function getCreateAccountWithSeedInstruction(input, config) {
737
715
  };
738
716
  const accounts = originalAccounts;
739
717
  const args = { ...input };
740
- const getAccountMeta = getAccountMetaFactory(programAddress);
741
- const instruction = {
718
+ const getAccountMeta = getAccountMetaFactory();
719
+ return Object.freeze({
742
720
  accounts: [
743
721
  getAccountMeta(accounts.payer),
744
722
  getAccountMeta(accounts.newAccount),
745
723
  getAccountMeta(accounts.baseAccount)
746
- ],
747
- programAddress,
724
+ ].filter((x) => x !== void 0),
748
725
  data: getCreateAccountWithSeedInstructionDataEncoder().encode(
749
726
  args
750
- )
751
- };
752
- return instruction;
727
+ ),
728
+ programAddress
729
+ });
753
730
  }
754
731
  function parseCreateAccountWithSeedInstruction(instruction) {
755
- if (instruction.accounts.length < 3) {
732
+ if (instruction.accounts.length < 2) {
756
733
  throw new Error("Not enough accounts");
757
734
  }
758
735
  let accountIndex = 0;
@@ -761,12 +738,18 @@ function parseCreateAccountWithSeedInstruction(instruction) {
761
738
  accountIndex += 1;
762
739
  return accountMeta;
763
740
  };
741
+ let optionalAccountsRemaining = instruction.accounts.length - 2;
742
+ const getNextOptionalAccount = () => {
743
+ if (optionalAccountsRemaining === 0) return void 0;
744
+ optionalAccountsRemaining -= 1;
745
+ return getNextAccount();
746
+ };
764
747
  return {
765
748
  programAddress: instruction.programAddress,
766
749
  accounts: {
767
750
  payer: getNextAccount(),
768
751
  newAccount: getNextAccount(),
769
- baseAccount: getNextAccount()
752
+ baseAccount: getNextOptionalAccount()
770
753
  },
771
754
  data: getCreateAccountWithSeedInstructionDataDecoder().decode(
772
755
  instruction.data
@@ -819,19 +802,18 @@ function getInitializeNonceAccountInstruction(input, config) {
819
802
  if (!accounts.rentSysvar.value) {
820
803
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
821
804
  }
822
- const getAccountMeta = getAccountMetaFactory(programAddress);
823
- const instruction = {
805
+ const getAccountMeta = getAccountMetaFactory();
806
+ return Object.freeze({
824
807
  accounts: [
825
808
  getAccountMeta(accounts.nonceAccount),
826
809
  getAccountMeta(accounts.recentBlockhashesSysvar),
827
810
  getAccountMeta(accounts.rentSysvar)
828
811
  ],
829
- programAddress,
830
812
  data: getInitializeNonceAccountInstructionDataEncoder().encode(
831
813
  args
832
- )
833
- };
834
- return instruction;
814
+ ),
815
+ programAddress
816
+ });
835
817
  }
836
818
  function parseInitializeNonceAccountInstruction(instruction) {
837
819
  if (instruction.accounts.length < 3) {
@@ -888,18 +870,17 @@ function getTransferSolInstruction(input, config) {
888
870
  };
889
871
  const accounts = originalAccounts;
890
872
  const args = { ...input };
891
- const getAccountMeta = getAccountMetaFactory(programAddress);
892
- const instruction = {
873
+ const getAccountMeta = getAccountMetaFactory();
874
+ return Object.freeze({
893
875
  accounts: [
894
876
  getAccountMeta(accounts.source),
895
877
  getAccountMeta(accounts.destination)
896
878
  ],
897
- programAddress,
898
879
  data: getTransferSolInstructionDataEncoder().encode(
899
880
  args
900
- )
901
- };
902
- return instruction;
881
+ ),
882
+ programAddress
883
+ });
903
884
  }
904
885
  function parseTransferSolInstruction(instruction) {
905
886
  if (instruction.accounts.length < 2) {
@@ -913,10 +894,7 @@ function parseTransferSolInstruction(instruction) {
913
894
  };
914
895
  return {
915
896
  programAddress: instruction.programAddress,
916
- accounts: {
917
- source: getNextAccount(),
918
- destination: getNextAccount()
919
- },
897
+ accounts: { source: getNextAccount(), destination: getNextAccount() },
920
898
  data: getTransferSolInstructionDataDecoder().decode(instruction.data)
921
899
  };
922
900
  }
@@ -961,19 +939,18 @@ function getTransferSolWithSeedInstruction(input, config) {
961
939
  };
962
940
  const accounts = originalAccounts;
963
941
  const args = { ...input };
964
- const getAccountMeta = getAccountMetaFactory(programAddress);
965
- const instruction = {
942
+ const getAccountMeta = getAccountMetaFactory();
943
+ return Object.freeze({
966
944
  accounts: [
967
945
  getAccountMeta(accounts.source),
968
946
  getAccountMeta(accounts.baseAccount),
969
947
  getAccountMeta(accounts.destination)
970
948
  ],
971
- programAddress,
972
949
  data: getTransferSolWithSeedInstructionDataEncoder().encode(
973
950
  args
974
- )
975
- };
976
- return instruction;
951
+ ),
952
+ programAddress
953
+ });
977
954
  }
978
955
  function parseTransferSolWithSeedInstruction(instruction) {
979
956
  if (instruction.accounts.length < 3) {
@@ -1025,13 +1002,12 @@ function getUpgradeNonceAccountInstruction(input, config) {
1025
1002
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true }
1026
1003
  };
1027
1004
  const accounts = originalAccounts;
1028
- const getAccountMeta = getAccountMetaFactory(programAddress);
1029
- const instruction = {
1005
+ const getAccountMeta = getAccountMetaFactory();
1006
+ return Object.freeze({
1030
1007
  accounts: [getAccountMeta(accounts.nonceAccount)],
1031
- programAddress,
1032
- data: getUpgradeNonceAccountInstructionDataEncoder().encode({})
1033
- };
1034
- return instruction;
1008
+ data: getUpgradeNonceAccountInstructionDataEncoder().encode({}),
1009
+ programAddress
1010
+ });
1035
1011
  }
1036
1012
  function parseUpgradeNonceAccountInstruction(instruction) {
1037
1013
  if (instruction.accounts.length < 1) {
@@ -1045,9 +1021,7 @@ function parseUpgradeNonceAccountInstruction(instruction) {
1045
1021
  };
1046
1022
  return {
1047
1023
  programAddress: instruction.programAddress,
1048
- accounts: {
1049
- nonceAccount: getNextAccount()
1050
- },
1024
+ accounts: { nonceAccount: getNextAccount() },
1051
1025
  data: getUpgradeNonceAccountInstructionDataDecoder().decode(
1052
1026
  instruction.data
1053
1027
  )
@@ -1104,8 +1078,8 @@ function getWithdrawNonceAccountInstruction(input, config) {
1104
1078
  if (!accounts.rentSysvar.value) {
1105
1079
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
1106
1080
  }
1107
- const getAccountMeta = getAccountMetaFactory(programAddress);
1108
- const instruction = {
1081
+ const getAccountMeta = getAccountMetaFactory();
1082
+ return Object.freeze({
1109
1083
  accounts: [
1110
1084
  getAccountMeta(accounts.nonceAccount),
1111
1085
  getAccountMeta(accounts.recipientAccount),
@@ -1113,12 +1087,11 @@ function getWithdrawNonceAccountInstruction(input, config) {
1113
1087
  getAccountMeta(accounts.rentSysvar),
1114
1088
  getAccountMeta(accounts.nonceAuthority)
1115
1089
  ],
1116
- programAddress,
1117
1090
  data: getWithdrawNonceAccountInstructionDataEncoder().encode(
1118
1091
  args
1119
- )
1120
- };
1121
- return instruction;
1092
+ ),
1093
+ programAddress
1094
+ });
1122
1095
  }
1123
1096
  function parseWithdrawNonceAccountInstruction(instruction) {
1124
1097
  if (instruction.accounts.length < 5) {