@solana-program/system 0.15.0 → 0.16.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 (56) hide show
  1. package/dist/src/index.js +125 -35
  2. package/dist/src/index.js.map +1 -1
  3. package/dist/src/index.mjs +125 -35
  4. package/dist/src/index.mjs.map +1 -1
  5. package/dist/types/generated/accounts/nonce.d.ts +7 -7
  6. package/dist/types/generated/accounts/nonce.d.ts.map +1 -1
  7. package/dist/types/generated/errors/system.d.ts +4 -2
  8. package/dist/types/generated/errors/system.d.ts.map +1 -1
  9. package/dist/types/generated/instructions/advanceNonceAccount.d.ts +3 -1
  10. package/dist/types/generated/instructions/advanceNonceAccount.d.ts.map +1 -1
  11. package/dist/types/generated/instructions/allocate.d.ts +3 -1
  12. package/dist/types/generated/instructions/allocate.d.ts.map +1 -1
  13. package/dist/types/generated/instructions/allocateWithSeed.d.ts +6 -4
  14. package/dist/types/generated/instructions/allocateWithSeed.d.ts.map +1 -1
  15. package/dist/types/generated/instructions/assign.d.ts +5 -3
  16. package/dist/types/generated/instructions/assign.d.ts.map +1 -1
  17. package/dist/types/generated/instructions/assignWithSeed.d.ts +6 -4
  18. package/dist/types/generated/instructions/assignWithSeed.d.ts.map +1 -1
  19. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts +5 -3
  20. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts.map +1 -1
  21. package/dist/types/generated/instructions/createAccount.d.ts +5 -3
  22. package/dist/types/generated/instructions/createAccount.d.ts.map +1 -1
  23. package/dist/types/generated/instructions/createAccountAllowPrefund.d.ts +5 -3
  24. package/dist/types/generated/instructions/createAccountAllowPrefund.d.ts.map +1 -1
  25. package/dist/types/generated/instructions/createAccountWithSeed.d.ts +6 -4
  26. package/dist/types/generated/instructions/createAccountWithSeed.d.ts.map +1 -1
  27. package/dist/types/generated/instructions/initializeNonceAccount.d.ts +5 -3
  28. package/dist/types/generated/instructions/initializeNonceAccount.d.ts.map +1 -1
  29. package/dist/types/generated/instructions/transferSol.d.ts +3 -1
  30. package/dist/types/generated/instructions/transferSol.d.ts.map +1 -1
  31. package/dist/types/generated/instructions/transferSolWithSeed.d.ts +5 -3
  32. package/dist/types/generated/instructions/transferSolWithSeed.d.ts.map +1 -1
  33. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts +3 -1
  34. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts.map +1 -1
  35. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts +3 -1
  36. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts.map +1 -1
  37. package/dist/types/generated/programs/system.d.ts +46 -16
  38. package/dist/types/generated/programs/system.d.ts.map +1 -1
  39. package/package.json +5 -5
  40. package/src/generated/accounts/nonce.ts +17 -8
  41. package/src/generated/errors/system.ts +5 -1
  42. package/src/generated/instructions/advanceNonceAccount.ts +3 -2
  43. package/src/generated/instructions/allocate.ts +3 -2
  44. package/src/generated/instructions/allocateWithSeed.ts +6 -4
  45. package/src/generated/instructions/assign.ts +5 -3
  46. package/src/generated/instructions/assignWithSeed.ts +9 -3
  47. package/src/generated/instructions/authorizeNonceAccount.ts +5 -3
  48. package/src/generated/instructions/createAccount.ts +5 -3
  49. package/src/generated/instructions/createAccountAllowPrefund.ts +5 -3
  50. package/src/generated/instructions/createAccountWithSeed.ts +6 -4
  51. package/src/generated/instructions/initializeNonceAccount.ts +5 -3
  52. package/src/generated/instructions/transferSol.ts +3 -2
  53. package/src/generated/instructions/transferSolWithSeed.ts +9 -3
  54. package/src/generated/instructions/upgradeNonceAccount.ts +3 -2
  55. package/src/generated/instructions/withdrawNonceAccount.ts +3 -2
  56. package/src/generated/programs/system.ts +119 -28
@@ -22,6 +22,7 @@ import {
22
22
  type FixedSizeCodec,
23
23
  type FixedSizeDecoder,
24
24
  type FixedSizeEncoder,
25
+ type HasAddress,
25
26
  type Instruction,
26
27
  type InstructionWithAccounts,
27
28
  type InstructionWithData,
@@ -66,7 +67,7 @@ export type InitializeNonceAccountInstruction<
66
67
 
67
68
  export type InitializeNonceAccountInstructionData = { discriminator: number; nonceAuthority: Address };
68
69
 
69
- export type InitializeNonceAccountInstructionDataArgs = { nonceAuthority: Address };
70
+ export type InitializeNonceAccountInstructionDataArgs = { nonceAuthority: Address | HasAddress };
70
71
 
71
72
  export function getInitializeNonceAccountInstructionDataEncoder(): FixedSizeEncoder<InitializeNonceAccountInstructionDataArgs> {
72
73
  return transformEncoder(
@@ -113,7 +114,7 @@ export function getInitializeNonceAccountInstruction<
113
114
  TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
114
115
  >(
115
116
  input: InitializeNonceAccountInput<TAccountNonceAccount, TAccountRecentBlockhashesSysvar, TAccountRentSysvar>,
116
- config?: { programAddress?: TProgramAddress },
117
+ config?: { programAddress?: TProgramAddress | { readonly address: TProgramAddress } },
117
118
  ): InitializeNonceAccountInstruction<
118
119
  TProgramAddress,
119
120
  ResolvedInstructionAccountMeta<TAccountNonceAccount, InstructionAccountInputAddress<TAccountNonceAccount>>,
@@ -124,7 +125,8 @@ export function getInitializeNonceAccountInstruction<
124
125
  ResolvedInstructionAccountMeta<TAccountRentSysvar, InstructionAccountInputAddress<TAccountRentSysvar>>
125
126
  > {
126
127
  // Program address.
127
- const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
128
+ const programAddressInput = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
129
+ const programAddress = typeof programAddressInput === 'string' ? programAddressInput : programAddressInput.address;
128
130
 
129
131
  // Account meta helper.
130
132
  const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
@@ -106,14 +106,15 @@ export function getTransferSolInstruction<
106
106
  TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
107
107
  >(
108
108
  input: TransferSolInput<TAccountSource, TAccountDestination>,
109
- config?: { programAddress?: TProgramAddress },
109
+ config?: { programAddress?: TProgramAddress | { readonly address: TProgramAddress } },
110
110
  ): TransferSolInstruction<
111
111
  TProgramAddress,
112
112
  ResolvedInstructionAccountMeta<TAccountSource, InstructionAccountInputAddress<TAccountSource>>,
113
113
  ResolvedInstructionAccountMeta<TAccountDestination, InstructionAccountInputAddress<TAccountDestination>>
114
114
  > {
115
115
  // Program address.
116
- const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
116
+ const programAddressInput = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
117
+ const programAddress = typeof programAddressInput === 'string' ? programAddressInput : programAddressInput.address;
117
118
 
118
119
  // Account meta helper.
119
120
  const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
@@ -29,6 +29,7 @@ import {
29
29
  type Codec,
30
30
  type Decoder,
31
31
  type Encoder,
32
+ type HasAddress,
32
33
  type Instruction,
33
34
  type InstructionWithAccounts,
34
35
  type InstructionWithData,
@@ -78,7 +79,11 @@ export type TransferSolWithSeedInstructionData = {
78
79
  fromOwner: Address;
79
80
  };
80
81
 
81
- export type TransferSolWithSeedInstructionDataArgs = { amount: number | bigint; fromSeed: string; fromOwner: Address };
82
+ export type TransferSolWithSeedInstructionDataArgs = {
83
+ amount: number | bigint;
84
+ fromSeed: string;
85
+ fromOwner: Address | HasAddress;
86
+ };
82
87
 
83
88
  export function getTransferSolWithSeedInstructionDataEncoder(): Encoder<TransferSolWithSeedInstructionDataArgs> {
84
89
  return transformEncoder(
@@ -128,7 +133,7 @@ export function getTransferSolWithSeedInstruction<
128
133
  TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
129
134
  >(
130
135
  input: TransferSolWithSeedInput<TAccountSource, TAccountBaseAccount, TAccountDestination>,
131
- config?: { programAddress?: TProgramAddress },
136
+ config?: { programAddress?: TProgramAddress | { readonly address: TProgramAddress } },
132
137
  ): TransferSolWithSeedInstruction<
133
138
  TProgramAddress,
134
139
  ResolvedInstructionAccountMeta<TAccountSource, InstructionAccountInputAddress<TAccountSource>>,
@@ -136,7 +141,8 @@ export function getTransferSolWithSeedInstruction<
136
141
  ResolvedInstructionAccountMeta<TAccountDestination, InstructionAccountInputAddress<TAccountDestination>>
137
142
  > {
138
143
  // Program address.
139
- const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
144
+ const programAddressInput = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
145
+ const programAddress = typeof programAddressInput === 'string' ? programAddressInput : programAddressInput.address;
140
146
 
141
147
  // Account meta helper.
142
148
  const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
@@ -85,13 +85,14 @@ export function getUpgradeNonceAccountInstruction<
85
85
  TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
86
86
  >(
87
87
  input: UpgradeNonceAccountInput<TAccountNonceAccount>,
88
- config?: { programAddress?: TProgramAddress },
88
+ config?: { programAddress?: TProgramAddress | { readonly address: TProgramAddress } },
89
89
  ): UpgradeNonceAccountInstruction<
90
90
  TProgramAddress,
91
91
  ResolvedInstructionAccountMeta<TAccountNonceAccount, InstructionAccountInputAddress<TAccountNonceAccount>>
92
92
  > {
93
93
  // Program address.
94
- const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
94
+ const programAddressInput = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
95
+ const programAddress = typeof programAddressInput === 'string' ? programAddressInput : programAddressInput.address;
95
96
 
96
97
  // Account meta helper.
97
98
  const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
@@ -136,7 +136,7 @@ export function getWithdrawNonceAccountInstruction<
136
136
  TAccountRentSysvar,
137
137
  TAccountNonceAuthority
138
138
  >,
139
- config?: { programAddress?: TProgramAddress },
139
+ config?: { programAddress?: TProgramAddress | { readonly address: TProgramAddress } },
140
140
  ): WithdrawNonceAccountInstruction<
141
141
  TProgramAddress,
142
142
  ResolvedInstructionAccountMeta<TAccountNonceAccount, InstructionAccountInputAddress<TAccountNonceAccount>>,
@@ -149,7 +149,8 @@ export function getWithdrawNonceAccountInstruction<
149
149
  ResolvedInstructionAccountMeta<TAccountNonceAuthority, InstructionAccountInputAddress<TAccountNonceAuthority>>
150
150
  > {
151
151
  // Program address.
152
- const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
152
+ const programAddressInput = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
153
+ const programAddress = typeof programAddressInput === 'string' ? programAddressInput : programAddressInput.address;
153
154
 
154
155
  // Account meta helper.
155
156
  const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
@@ -22,6 +22,7 @@ import {
22
22
  type ExtendedClient,
23
23
  type GetAccountInfoApi,
24
24
  type GetMultipleAccountsApi,
25
+ type HasAddress,
25
26
  type Instruction,
26
27
  type InstructionWithData,
27
28
  type ReadonlyUint8Array,
@@ -298,39 +299,59 @@ export type SystemPluginAccounts = { nonce: ReturnType<typeof getNonceCodec> & S
298
299
  export type SystemPluginInstructions = {
299
300
  createAccount: (
300
301
  input: MakeOptional<CreateAccountInput, 'payer'>,
302
+ config?: { programAddress?: Address | HasAddress },
301
303
  ) => ReturnType<typeof getCreateAccountInstruction> & SelfPlanAndSendFunctions;
302
- assign: (input: AssignInput) => ReturnType<typeof getAssignInstruction> & SelfPlanAndSendFunctions;
303
- transferSol: (input: TransferSolInput) => ReturnType<typeof getTransferSolInstruction> & SelfPlanAndSendFunctions;
304
+ assign: (
305
+ input: AssignInput,
306
+ config?: { programAddress?: Address | HasAddress },
307
+ ) => ReturnType<typeof getAssignInstruction> & SelfPlanAndSendFunctions;
308
+ transferSol: (
309
+ input: TransferSolInput,
310
+ config?: { programAddress?: Address | HasAddress },
311
+ ) => ReturnType<typeof getTransferSolInstruction> & SelfPlanAndSendFunctions;
304
312
  createAccountWithSeed: (
305
313
  input: MakeOptional<CreateAccountWithSeedInput, 'payer'>,
314
+ config?: { programAddress?: Address | HasAddress },
306
315
  ) => ReturnType<typeof getCreateAccountWithSeedInstruction> & SelfPlanAndSendFunctions;
307
316
  advanceNonceAccount: (
308
317
  input: AdvanceNonceAccountInput,
318
+ config?: { programAddress?: Address | HasAddress },
309
319
  ) => ReturnType<typeof getAdvanceNonceAccountInstruction> & SelfPlanAndSendFunctions;
310
320
  withdrawNonceAccount: (
311
321
  input: WithdrawNonceAccountInput,
322
+ config?: { programAddress?: Address | HasAddress },
312
323
  ) => ReturnType<typeof getWithdrawNonceAccountInstruction> & SelfPlanAndSendFunctions;
313
324
  initializeNonceAccount: (
314
325
  input: InitializeNonceAccountInput,
326
+ config?: { programAddress?: Address | HasAddress },
315
327
  ) => ReturnType<typeof getInitializeNonceAccountInstruction> & SelfPlanAndSendFunctions;
316
328
  authorizeNonceAccount: (
317
329
  input: AuthorizeNonceAccountInput,
330
+ config?: { programAddress?: Address | HasAddress },
318
331
  ) => ReturnType<typeof getAuthorizeNonceAccountInstruction> & SelfPlanAndSendFunctions;
319
- allocate: (input: AllocateInput) => ReturnType<typeof getAllocateInstruction> & SelfPlanAndSendFunctions;
332
+ allocate: (
333
+ input: AllocateInput,
334
+ config?: { programAddress?: Address | HasAddress },
335
+ ) => ReturnType<typeof getAllocateInstruction> & SelfPlanAndSendFunctions;
320
336
  allocateWithSeed: (
321
337
  input: AllocateWithSeedInput,
338
+ config?: { programAddress?: Address | HasAddress },
322
339
  ) => ReturnType<typeof getAllocateWithSeedInstruction> & SelfPlanAndSendFunctions;
323
340
  assignWithSeed: (
324
341
  input: AssignWithSeedInput,
342
+ config?: { programAddress?: Address | HasAddress },
325
343
  ) => ReturnType<typeof getAssignWithSeedInstruction> & SelfPlanAndSendFunctions;
326
344
  transferSolWithSeed: (
327
345
  input: TransferSolWithSeedInput,
346
+ config?: { programAddress?: Address | HasAddress },
328
347
  ) => ReturnType<typeof getTransferSolWithSeedInstruction> & SelfPlanAndSendFunctions;
329
348
  upgradeNonceAccount: (
330
349
  input: UpgradeNonceAccountInput,
350
+ config?: { programAddress?: Address | HasAddress },
331
351
  ) => ReturnType<typeof getUpgradeNonceAccountInstruction> & SelfPlanAndSendFunctions;
332
352
  createAccountAllowPrefund: (
333
353
  input: CreateAccountAllowPrefundInput,
354
+ config?: { programAddress?: Address | HasAddress },
334
355
  ) => ReturnType<typeof getCreateAccountAllowPrefundInstruction> & SelfPlanAndSendFunctions;
335
356
  };
336
357
 
@@ -339,42 +360,112 @@ export type SystemPluginRequirements = ClientWithRpc<GetAccountInfoApi & GetMult
339
360
  ClientWithTransactionPlanning &
340
361
  ClientWithTransactionSending;
341
362
 
342
- export function systemProgram() {
363
+ export function systemProgram(config: { programAddress?: Address | HasAddress } = {}) {
343
364
  return <T extends SystemPluginRequirements>(client: T): ExtendedClient<T, { system: SystemPlugin }> => {
344
365
  return extendClient(client, {
345
366
  system: <SystemPlugin>{
346
367
  accounts: { nonce: addSelfFetchFunctions(client, getNonceCodec()) },
347
368
  instructions: {
348
- createAccount: input =>
369
+ createAccount: (input, instructionConfig) =>
349
370
  addSelfPlanAndSendFunctions(
350
371
  client,
351
- getCreateAccountInstruction({ ...input, payer: input.payer ?? client.payer }),
372
+ getCreateAccountInstruction(
373
+ { ...input, payer: input.payer ?? client.payer },
374
+ { programAddress: instructionConfig?.programAddress ?? config.programAddress },
375
+ ),
352
376
  ),
353
- assign: input => addSelfPlanAndSendFunctions(client, getAssignInstruction(input)),
354
- transferSol: input => addSelfPlanAndSendFunctions(client, getTransferSolInstruction(input)),
355
- createAccountWithSeed: input =>
377
+ assign: (input, instructionConfig) =>
356
378
  addSelfPlanAndSendFunctions(
357
379
  client,
358
- getCreateAccountWithSeedInstruction({ ...input, payer: input.payer ?? client.payer }),
380
+ getAssignInstruction(input, {
381
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
382
+ }),
383
+ ),
384
+ transferSol: (input, instructionConfig) =>
385
+ addSelfPlanAndSendFunctions(
386
+ client,
387
+ getTransferSolInstruction(input, {
388
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
389
+ }),
390
+ ),
391
+ createAccountWithSeed: (input, instructionConfig) =>
392
+ addSelfPlanAndSendFunctions(
393
+ client,
394
+ getCreateAccountWithSeedInstruction(
395
+ { ...input, payer: input.payer ?? client.payer },
396
+ { programAddress: instructionConfig?.programAddress ?? config.programAddress },
397
+ ),
398
+ ),
399
+ advanceNonceAccount: (input, instructionConfig) =>
400
+ addSelfPlanAndSendFunctions(
401
+ client,
402
+ getAdvanceNonceAccountInstruction(input, {
403
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
404
+ }),
405
+ ),
406
+ withdrawNonceAccount: (input, instructionConfig) =>
407
+ addSelfPlanAndSendFunctions(
408
+ client,
409
+ getWithdrawNonceAccountInstruction(input, {
410
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
411
+ }),
412
+ ),
413
+ initializeNonceAccount: (input, instructionConfig) =>
414
+ addSelfPlanAndSendFunctions(
415
+ client,
416
+ getInitializeNonceAccountInstruction(input, {
417
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
418
+ }),
419
+ ),
420
+ authorizeNonceAccount: (input, instructionConfig) =>
421
+ addSelfPlanAndSendFunctions(
422
+ client,
423
+ getAuthorizeNonceAccountInstruction(input, {
424
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
425
+ }),
426
+ ),
427
+ allocate: (input, instructionConfig) =>
428
+ addSelfPlanAndSendFunctions(
429
+ client,
430
+ getAllocateInstruction(input, {
431
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
432
+ }),
433
+ ),
434
+ allocateWithSeed: (input, instructionConfig) =>
435
+ addSelfPlanAndSendFunctions(
436
+ client,
437
+ getAllocateWithSeedInstruction(input, {
438
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
439
+ }),
440
+ ),
441
+ assignWithSeed: (input, instructionConfig) =>
442
+ addSelfPlanAndSendFunctions(
443
+ client,
444
+ getAssignWithSeedInstruction(input, {
445
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
446
+ }),
447
+ ),
448
+ transferSolWithSeed: (input, instructionConfig) =>
449
+ addSelfPlanAndSendFunctions(
450
+ client,
451
+ getTransferSolWithSeedInstruction(input, {
452
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
453
+ }),
454
+ ),
455
+ upgradeNonceAccount: (input, instructionConfig) =>
456
+ addSelfPlanAndSendFunctions(
457
+ client,
458
+ getUpgradeNonceAccountInstruction(input, {
459
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
460
+ }),
461
+ ),
462
+ createAccountAllowPrefund: (input, instructionConfig) =>
463
+ addSelfPlanAndSendFunctions(
464
+ client,
465
+ getCreateAccountAllowPrefundInstruction(input, {
466
+ programAddress: instructionConfig?.programAddress ?? config.programAddress,
467
+ }),
359
468
  ),
360
- advanceNonceAccount: input =>
361
- addSelfPlanAndSendFunctions(client, getAdvanceNonceAccountInstruction(input)),
362
- withdrawNonceAccount: input =>
363
- addSelfPlanAndSendFunctions(client, getWithdrawNonceAccountInstruction(input)),
364
- initializeNonceAccount: input =>
365
- addSelfPlanAndSendFunctions(client, getInitializeNonceAccountInstruction(input)),
366
- authorizeNonceAccount: input =>
367
- addSelfPlanAndSendFunctions(client, getAuthorizeNonceAccountInstruction(input)),
368
- allocate: input => addSelfPlanAndSendFunctions(client, getAllocateInstruction(input)),
369
- allocateWithSeed: input =>
370
- addSelfPlanAndSendFunctions(client, getAllocateWithSeedInstruction(input)),
371
- assignWithSeed: input => addSelfPlanAndSendFunctions(client, getAssignWithSeedInstruction(input)),
372
- transferSolWithSeed: input =>
373
- addSelfPlanAndSendFunctions(client, getTransferSolWithSeedInstruction(input)),
374
- upgradeNonceAccount: input =>
375
- addSelfPlanAndSendFunctions(client, getUpgradeNonceAccountInstruction(input)),
376
- createAccountAllowPrefund: input =>
377
- addSelfPlanAndSendFunctions(client, getCreateAccountAllowPrefundInstruction(input)),
378
469
  },
379
470
  identifyInstruction: identifySystemInstruction,
380
471
  parseInstruction: parseSystemInstruction,