@solana-program/system 0.8.0 → 0.8.1

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.
@@ -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,7 +250,7 @@ function getAdvanceNonceAccountInstruction(input, config) {
253
250
  if (!accounts.recentBlockhashesSysvar.value) {
254
251
  accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
255
252
  }
256
- const getAccountMeta = getAccountMetaFactory(programAddress);
253
+ const getAccountMeta = getAccountMetaFactory();
257
254
  const instruction = {
258
255
  accounts: [
259
256
  getAccountMeta(accounts.nonceAccount),
@@ -319,7 +316,7 @@ function getAllocateInstruction(input, config) {
319
316
  };
320
317
  const accounts = originalAccounts;
321
318
  const args = { ...input };
322
- const getAccountMeta = getAccountMetaFactory(programAddress);
319
+ const getAccountMeta = getAccountMetaFactory();
323
320
  const instruction = {
324
321
  accounts: [getAccountMeta(accounts.newAccount)],
325
322
  programAddress,
@@ -386,7 +383,7 @@ function getAllocateWithSeedInstruction(input, config) {
386
383
  };
387
384
  const accounts = originalAccounts;
388
385
  const args = { ...input };
389
- const getAccountMeta = getAccountMetaFactory(programAddress);
386
+ const getAccountMeta = getAccountMetaFactory();
390
387
  const instruction = {
391
388
  accounts: [
392
389
  getAccountMeta(accounts.newAccount),
@@ -450,7 +447,7 @@ function getAssignInstruction(input, config) {
450
447
  };
451
448
  const accounts = originalAccounts;
452
449
  const args = { ...input };
453
- const getAccountMeta = getAccountMetaFactory(programAddress);
450
+ const getAccountMeta = getAccountMetaFactory();
454
451
  const instruction = {
455
452
  accounts: [getAccountMeta(accounts.account)],
456
453
  programAddress,
@@ -515,7 +512,7 @@ function getAssignWithSeedInstruction(input, config) {
515
512
  };
516
513
  const accounts = originalAccounts;
517
514
  const args = { ...input };
518
- const getAccountMeta = getAccountMetaFactory(programAddress);
515
+ const getAccountMeta = getAccountMetaFactory();
519
516
  const instruction = {
520
517
  accounts: [
521
518
  getAccountMeta(accounts.account),
@@ -583,7 +580,7 @@ function getAuthorizeNonceAccountInstruction(input, config) {
583
580
  };
584
581
  const accounts = originalAccounts;
585
582
  const args = { ...input };
586
- const getAccountMeta = getAccountMetaFactory(programAddress);
583
+ const getAccountMeta = getAccountMetaFactory();
587
584
  const instruction = {
588
585
  accounts: [
589
586
  getAccountMeta(accounts.nonceAccount),
@@ -658,7 +655,7 @@ function getCreateAccountInstruction(input, config) {
658
655
  (a, b) => a + b,
659
656
  0
660
657
  );
661
- const getAccountMeta = getAccountMetaFactory(programAddress);
658
+ const getAccountMeta = getAccountMetaFactory();
662
659
  const instruction = {
663
660
  accounts: [
664
661
  getAccountMeta(accounts.payer),
@@ -735,13 +732,13 @@ function getCreateAccountWithSeedInstruction(input, config) {
735
732
  };
736
733
  const accounts = originalAccounts;
737
734
  const args = { ...input };
738
- const getAccountMeta = getAccountMetaFactory(programAddress);
735
+ const getAccountMeta = getAccountMetaFactory();
739
736
  const instruction = {
740
737
  accounts: [
741
738
  getAccountMeta(accounts.payer),
742
739
  getAccountMeta(accounts.newAccount),
743
740
  getAccountMeta(accounts.baseAccount)
744
- ],
741
+ ].filter((x) => x !== void 0),
745
742
  programAddress,
746
743
  data: getCreateAccountWithSeedInstructionDataEncoder().encode(
747
744
  args
@@ -750,7 +747,7 @@ function getCreateAccountWithSeedInstruction(input, config) {
750
747
  return instruction;
751
748
  }
752
749
  function parseCreateAccountWithSeedInstruction(instruction) {
753
- if (instruction.accounts.length < 3) {
750
+ if (instruction.accounts.length < 2) {
754
751
  throw new Error("Not enough accounts");
755
752
  }
756
753
  let accountIndex = 0;
@@ -759,12 +756,18 @@ function parseCreateAccountWithSeedInstruction(instruction) {
759
756
  accountIndex += 1;
760
757
  return accountMeta;
761
758
  };
759
+ let optionalAccountsRemaining = instruction.accounts.length - 2;
760
+ const getNextOptionalAccount = () => {
761
+ if (optionalAccountsRemaining === 0) return void 0;
762
+ optionalAccountsRemaining -= 1;
763
+ return getNextAccount();
764
+ };
762
765
  return {
763
766
  programAddress: instruction.programAddress,
764
767
  accounts: {
765
768
  payer: getNextAccount(),
766
769
  newAccount: getNextAccount(),
767
- baseAccount: getNextAccount()
770
+ baseAccount: getNextOptionalAccount()
768
771
  },
769
772
  data: getCreateAccountWithSeedInstructionDataDecoder().decode(
770
773
  instruction.data
@@ -817,7 +820,7 @@ function getInitializeNonceAccountInstruction(input, config) {
817
820
  if (!accounts.rentSysvar.value) {
818
821
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
819
822
  }
820
- const getAccountMeta = getAccountMetaFactory(programAddress);
823
+ const getAccountMeta = getAccountMetaFactory();
821
824
  const instruction = {
822
825
  accounts: [
823
826
  getAccountMeta(accounts.nonceAccount),
@@ -886,7 +889,7 @@ function getTransferSolInstruction(input, config) {
886
889
  };
887
890
  const accounts = originalAccounts;
888
891
  const args = { ...input };
889
- const getAccountMeta = getAccountMetaFactory(programAddress);
892
+ const getAccountMeta = getAccountMetaFactory();
890
893
  const instruction = {
891
894
  accounts: [
892
895
  getAccountMeta(accounts.source),
@@ -959,7 +962,7 @@ function getTransferSolWithSeedInstruction(input, config) {
959
962
  };
960
963
  const accounts = originalAccounts;
961
964
  const args = { ...input };
962
- const getAccountMeta = getAccountMetaFactory(programAddress);
965
+ const getAccountMeta = getAccountMetaFactory();
963
966
  const instruction = {
964
967
  accounts: [
965
968
  getAccountMeta(accounts.source),
@@ -1023,7 +1026,7 @@ function getUpgradeNonceAccountInstruction(input, config) {
1023
1026
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true }
1024
1027
  };
1025
1028
  const accounts = originalAccounts;
1026
- const getAccountMeta = getAccountMetaFactory(programAddress);
1029
+ const getAccountMeta = getAccountMetaFactory();
1027
1030
  const instruction = {
1028
1031
  accounts: [getAccountMeta(accounts.nonceAccount)],
1029
1032
  programAddress,
@@ -1102,7 +1105,7 @@ function getWithdrawNonceAccountInstruction(input, config) {
1102
1105
  if (!accounts.rentSysvar.value) {
1103
1106
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
1104
1107
  }
1105
- const getAccountMeta = getAccountMetaFactory(programAddress);
1108
+ const getAccountMeta = getAccountMetaFactory();
1106
1109
  const instruction = {
1107
1110
  accounts: [
1108
1111
  getAccountMeta(accounts.nonceAccount),