@solana-program/system 0.1.3 → 0.3.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 (47) hide show
  1. package/dist/src/index.cjs +414 -678
  2. package/dist/src/index.cjs.map +1 -1
  3. package/dist/src/index.js +281 -530
  4. package/dist/src/index.js.map +1 -1
  5. package/dist/types/src/generated/accounts/nonce.d.ts +12 -16
  6. package/dist/types/src/generated/accounts/nonce.d.ts.map +1 -1
  7. package/dist/types/src/generated/errors/system.d.ts +20 -27
  8. package/dist/types/src/generated/errors/system.d.ts.map +1 -1
  9. package/dist/types/src/generated/index.d.ts +0 -1
  10. package/dist/types/src/generated/index.d.ts.map +1 -1
  11. package/dist/types/src/generated/instructions/advanceNonceAccount.d.ts +6 -25
  12. package/dist/types/src/generated/instructions/advanceNonceAccount.d.ts.map +1 -1
  13. package/dist/types/src/generated/instructions/allocate.d.ts +6 -20
  14. package/dist/types/src/generated/instructions/allocate.d.ts.map +1 -1
  15. package/dist/types/src/generated/instructions/allocateWithSeed.d.ts +6 -26
  16. package/dist/types/src/generated/instructions/allocateWithSeed.d.ts.map +1 -1
  17. package/dist/types/src/generated/instructions/assign.d.ts +6 -20
  18. package/dist/types/src/generated/instructions/assign.d.ts.map +1 -1
  19. package/dist/types/src/generated/instructions/assignWithSeed.d.ts +6 -25
  20. package/dist/types/src/generated/instructions/assignWithSeed.d.ts.map +1 -1
  21. package/dist/types/src/generated/instructions/authorizeNonceAccount.d.ts +6 -23
  22. package/dist/types/src/generated/instructions/authorizeNonceAccount.d.ts.map +1 -1
  23. package/dist/types/src/generated/instructions/createAccount.d.ts +6 -25
  24. package/dist/types/src/generated/instructions/createAccount.d.ts.map +1 -1
  25. package/dist/types/src/generated/instructions/createAccountWithSeed.d.ts +6 -30
  26. package/dist/types/src/generated/instructions/createAccountWithSeed.d.ts.map +1 -1
  27. package/dist/types/src/generated/instructions/initializeNonceAccount.d.ts +6 -25
  28. package/dist/types/src/generated/instructions/initializeNonceAccount.d.ts.map +1 -1
  29. package/dist/types/src/generated/instructions/transferSol.d.ts +6 -23
  30. package/dist/types/src/generated/instructions/transferSol.d.ts.map +1 -1
  31. package/dist/types/src/generated/instructions/transferSolWithSeed.d.ts +6 -28
  32. package/dist/types/src/generated/instructions/transferSolWithSeed.d.ts.map +1 -1
  33. package/dist/types/src/generated/instructions/upgradeNonceAccount.d.ts +6 -18
  34. package/dist/types/src/generated/instructions/upgradeNonceAccount.d.ts.map +1 -1
  35. package/dist/types/src/generated/instructions/withdrawNonceAccount.d.ts +6 -32
  36. package/dist/types/src/generated/instructions/withdrawNonceAccount.d.ts.map +1 -1
  37. package/dist/types/src/generated/programs/system.d.ts +1 -5
  38. package/dist/types/src/generated/programs/system.d.ts.map +1 -1
  39. package/dist/types/src/generated/shared/index.d.ts +2 -13
  40. package/dist/types/src/generated/shared/index.d.ts.map +1 -1
  41. package/dist/types/src/generated/types/nonceState.d.ts +1 -1
  42. package/dist/types/src/generated/types/nonceState.d.ts.map +1 -1
  43. package/dist/types/src/generated/types/nonceVersion.d.ts +1 -1
  44. package/dist/types/src/generated/types/nonceVersion.d.ts.map +1 -1
  45. package/dist/types/test/_setup.d.ts +5 -5
  46. package/dist/types/test/_setup.d.ts.map +1 -1
  47. package/package.json +13 -22
package/dist/src/index.js CHANGED
@@ -1,8 +1,4 @@
1
- import { decodeAccount, assertAccountExists, fetchEncodedAccount, assertAccountsExist, fetchEncodedAccounts, BASE_ACCOUNT_SIZE } from '@solana/accounts';
2
- import { getAddressEncoder, getAddressDecoder, isProgramDerivedAddress } from '@solana/addresses';
3
- import { getScalarEnumEncoder, getU32Encoder, getScalarEnumDecoder, getU32Decoder, combineCodec, getStructEncoder, getU64Encoder, getStructDecoder, getU64Decoder, mapEncoder, getStringEncoder, getStringDecoder } from '@solana/codecs';
4
- import { AccountRole, upgradeRoleToSigner } from '@solana/instructions';
5
- import { isTransactionSigner as isTransactionSigner$1 } from '@solana/signers';
1
+ import { getEnumEncoder, getU32Encoder, getEnumDecoder, getU32Decoder, combineCodec, getStructEncoder, getAddressEncoder, getU64Encoder, getStructDecoder, getAddressDecoder, getU64Decoder, decodeAccount, assertAccountExists, fetchEncodedAccount, assertAccountsExist, fetchEncodedAccounts, containsBytes, transformEncoder, addEncoderSizePrefix, getUtf8Encoder, addDecoderSizePrefix, getUtf8Decoder, BASE_ACCOUNT_SIZE, AccountRole, upgradeRoleToSigner, isTransactionSigner as isTransactionSigner$1 } from '@solana/web3.js';
6
2
 
7
3
  // env-shim.ts
8
4
  var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
@@ -12,10 +8,10 @@ var NonceState = /* @__PURE__ */ ((NonceState3) => {
12
8
  return NonceState3;
13
9
  })(NonceState || {});
14
10
  function getNonceStateEncoder() {
15
- return getScalarEnumEncoder(NonceState, { size: getU32Encoder() });
11
+ return getEnumEncoder(NonceState, { size: getU32Encoder() });
16
12
  }
17
13
  function getNonceStateDecoder() {
18
- return getScalarEnumDecoder(NonceState, { size: getU32Decoder() });
14
+ return getEnumDecoder(NonceState, { size: getU32Decoder() });
19
15
  }
20
16
  function getNonceStateCodec() {
21
17
  return combineCodec(getNonceStateEncoder(), getNonceStateDecoder());
@@ -26,17 +22,17 @@ var NonceVersion = /* @__PURE__ */ ((NonceVersion3) => {
26
22
  return NonceVersion3;
27
23
  })(NonceVersion || {});
28
24
  function getNonceVersionEncoder() {
29
- return getScalarEnumEncoder(NonceVersion, { size: getU32Encoder() });
25
+ return getEnumEncoder(NonceVersion, { size: getU32Encoder() });
30
26
  }
31
27
  function getNonceVersionDecoder() {
32
- return getScalarEnumDecoder(NonceVersion, { size: getU32Decoder() });
28
+ return getEnumDecoder(NonceVersion, { size: getU32Decoder() });
33
29
  }
34
30
  function getNonceVersionCodec() {
35
31
  return combineCodec(getNonceVersionEncoder(), getNonceVersionDecoder());
36
32
  }
37
33
 
38
34
  // src/generated/accounts/nonce.ts
39
- function getNonceAccountDataEncoder() {
35
+ function getNonceEncoder() {
40
36
  return getStructEncoder([
41
37
  ["version", getNonceVersionEncoder()],
42
38
  ["state", getNonceStateEncoder()],
@@ -45,7 +41,7 @@ function getNonceAccountDataEncoder() {
45
41
  ["lamportsPerSignature", getU64Encoder()]
46
42
  ]);
47
43
  }
48
- function getNonceAccountDataDecoder() {
44
+ function getNonceDecoder() {
49
45
  return getStructDecoder([
50
46
  ["version", getNonceVersionDecoder()],
51
47
  ["state", getNonceStateDecoder()],
@@ -54,16 +50,13 @@ function getNonceAccountDataDecoder() {
54
50
  ["lamportsPerSignature", getU64Decoder()]
55
51
  ]);
56
52
  }
57
- function getNonceAccountDataCodec() {
58
- return combineCodec(
59
- getNonceAccountDataEncoder(),
60
- getNonceAccountDataDecoder()
61
- );
53
+ function getNonceCodec() {
54
+ return combineCodec(getNonceEncoder(), getNonceDecoder());
62
55
  }
63
56
  function decodeNonce(encodedAccount) {
64
57
  return decodeAccount(
65
58
  encodedAccount,
66
- getNonceAccountDataDecoder()
59
+ getNonceDecoder()
67
60
  );
68
61
  }
69
62
  async function fetchNonce(rpc, address, config) {
@@ -89,89 +82,100 @@ function getNonceSize() {
89
82
  }
90
83
 
91
84
  // src/generated/errors/system.ts
92
- var SystemProgramErrorCode = /* @__PURE__ */ ((SystemProgramErrorCode3) => {
93
- SystemProgramErrorCode3[SystemProgramErrorCode3["ACCOUNT_ALREADY_IN_USE"] = 0] = "ACCOUNT_ALREADY_IN_USE";
94
- SystemProgramErrorCode3[SystemProgramErrorCode3["RESULT_WITH_NEGATIVE_LAMPORTS"] = 1] = "RESULT_WITH_NEGATIVE_LAMPORTS";
95
- SystemProgramErrorCode3[SystemProgramErrorCode3["INVALID_PROGRAM_ID"] = 2] = "INVALID_PROGRAM_ID";
96
- SystemProgramErrorCode3[SystemProgramErrorCode3["INVALID_ACCOUNT_DATA_LENGTH"] = 3] = "INVALID_ACCOUNT_DATA_LENGTH";
97
- SystemProgramErrorCode3[SystemProgramErrorCode3["MAX_SEED_LENGTH_EXCEEDED"] = 4] = "MAX_SEED_LENGTH_EXCEEDED";
98
- SystemProgramErrorCode3[SystemProgramErrorCode3["ADDRESS_WITH_SEED_MISMATCH"] = 5] = "ADDRESS_WITH_SEED_MISMATCH";
99
- SystemProgramErrorCode3[SystemProgramErrorCode3["NONCE_NO_RECENT_BLOCKHASHES"] = 6] = "NONCE_NO_RECENT_BLOCKHASHES";
100
- SystemProgramErrorCode3[SystemProgramErrorCode3["NONCE_BLOCKHASH_NOT_EXPIRED"] = 7] = "NONCE_BLOCKHASH_NOT_EXPIRED";
101
- SystemProgramErrorCode3[SystemProgramErrorCode3["NONCE_UNEXPECTED_BLOCKHASH_VALUE"] = 8] = "NONCE_UNEXPECTED_BLOCKHASH_VALUE";
102
- return SystemProgramErrorCode3;
103
- })(SystemProgramErrorCode || {});
104
- var SystemProgramError = class extends Error {
105
- name = "SystemProgramError";
106
- code;
107
- cause;
108
- constructor(code, name, message, cause) {
109
- super(`${name} (${code}): ${message}`);
110
- this.code = code;
111
- this.cause = cause;
112
- }
113
- };
114
- var systemProgramErrorCodeMap;
85
+ var SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE = 0;
86
+ var SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS = 1;
87
+ var SYSTEM_ERROR__INVALID_PROGRAM_ID = 2;
88
+ var SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH = 3;
89
+ var SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED = 4;
90
+ var SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH = 5;
91
+ var SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES = 6;
92
+ var SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED = 7;
93
+ var SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE = 8;
94
+ var systemErrorMessages;
115
95
  if (__DEV__) {
116
- systemProgramErrorCodeMap = {
117
- [0 /* ACCOUNT_ALREADY_IN_USE */]: [
118
- "AccountAlreadyInUse",
119
- `an account with the same address already exists`
120
- ],
121
- [1 /* RESULT_WITH_NEGATIVE_LAMPORTS */]: [
122
- "ResultWithNegativeLamports",
123
- `account does not have enough SOL to perform the operation`
124
- ],
125
- [2 /* INVALID_PROGRAM_ID */]: [
126
- "InvalidProgramId",
127
- `cannot assign account to this program id`
128
- ],
129
- [3 /* INVALID_ACCOUNT_DATA_LENGTH */]: [
130
- "InvalidAccountDataLength",
131
- `cannot allocate account data of this length`
132
- ],
133
- [4 /* MAX_SEED_LENGTH_EXCEEDED */]: [
134
- "MaxSeedLengthExceeded",
135
- `length of requested seed is too long`
136
- ],
137
- [5 /* ADDRESS_WITH_SEED_MISMATCH */]: [
138
- "AddressWithSeedMismatch",
139
- `provided address does not match addressed derived from seed`
140
- ],
141
- [6 /* NONCE_NO_RECENT_BLOCKHASHES */]: [
142
- "NonceNoRecentBlockhashes",
143
- `advancing stored nonce requires a populated RecentBlockhashes sysvar`
144
- ],
145
- [7 /* NONCE_BLOCKHASH_NOT_EXPIRED */]: [
146
- "NonceBlockhashNotExpired",
147
- `stored nonce is still in recent_blockhashes`
148
- ],
149
- [8 /* NONCE_UNEXPECTED_BLOCKHASH_VALUE */]: [
150
- "NonceUnexpectedBlockhashValue",
151
- `specified nonce does not match stored nonce`
152
- ]
96
+ systemErrorMessages = {
97
+ [SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE]: `an account with the same address already exists`,
98
+ [SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH]: `provided address does not match addressed derived from seed`,
99
+ [SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH]: `cannot allocate account data of this length`,
100
+ [SYSTEM_ERROR__INVALID_PROGRAM_ID]: `cannot assign account to this program id`,
101
+ [SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED]: `length of requested seed is too long`,
102
+ [SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED]: `stored nonce is still in recent_blockhashes`,
103
+ [SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES]: `advancing stored nonce requires a populated RecentBlockhashes sysvar`,
104
+ [SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE]: `specified nonce does not match stored nonce`,
105
+ [SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS]: `account does not have enough SOL to perform the operation`
153
106
  };
154
107
  }
155
- function getSystemProgramErrorFromCode(code, cause) {
108
+ function getSystemErrorMessage(code) {
156
109
  if (__DEV__) {
157
- return new SystemProgramError(
158
- code,
159
- ...systemProgramErrorCodeMap[code],
160
- cause
161
- );
110
+ return systemErrorMessages[code];
162
111
  }
163
- return new SystemProgramError(
164
- code,
165
- "Unknown",
166
- "Error message not available in production bundles. Compile with __DEV__ set to true to see more information.",
167
- cause
168
- );
112
+ return "Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.";
169
113
  }
170
- function expectSome(value) {
171
- if (value == null) {
172
- throw new Error("Expected a value but received null or undefined.");
114
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
115
+ var SystemAccount = /* @__PURE__ */ ((SystemAccount2) => {
116
+ SystemAccount2[SystemAccount2["Nonce"] = 0] = "Nonce";
117
+ return SystemAccount2;
118
+ })(SystemAccount || {});
119
+ var SystemInstruction = /* @__PURE__ */ ((SystemInstruction2) => {
120
+ SystemInstruction2[SystemInstruction2["CreateAccount"] = 0] = "CreateAccount";
121
+ SystemInstruction2[SystemInstruction2["Assign"] = 1] = "Assign";
122
+ SystemInstruction2[SystemInstruction2["TransferSol"] = 2] = "TransferSol";
123
+ SystemInstruction2[SystemInstruction2["CreateAccountWithSeed"] = 3] = "CreateAccountWithSeed";
124
+ SystemInstruction2[SystemInstruction2["AdvanceNonceAccount"] = 4] = "AdvanceNonceAccount";
125
+ SystemInstruction2[SystemInstruction2["WithdrawNonceAccount"] = 5] = "WithdrawNonceAccount";
126
+ SystemInstruction2[SystemInstruction2["InitializeNonceAccount"] = 6] = "InitializeNonceAccount";
127
+ SystemInstruction2[SystemInstruction2["AuthorizeNonceAccount"] = 7] = "AuthorizeNonceAccount";
128
+ SystemInstruction2[SystemInstruction2["Allocate"] = 8] = "Allocate";
129
+ SystemInstruction2[SystemInstruction2["AllocateWithSeed"] = 9] = "AllocateWithSeed";
130
+ SystemInstruction2[SystemInstruction2["AssignWithSeed"] = 10] = "AssignWithSeed";
131
+ SystemInstruction2[SystemInstruction2["TransferSolWithSeed"] = 11] = "TransferSolWithSeed";
132
+ SystemInstruction2[SystemInstruction2["UpgradeNonceAccount"] = 12] = "UpgradeNonceAccount";
133
+ return SystemInstruction2;
134
+ })(SystemInstruction || {});
135
+ function identifySystemInstruction(instruction) {
136
+ const data = instruction instanceof Uint8Array ? instruction : instruction.data;
137
+ if (containsBytes(data, getU32Encoder().encode(0), 0)) {
138
+ return 0 /* CreateAccount */;
173
139
  }
174
- return value;
140
+ if (containsBytes(data, getU32Encoder().encode(1), 0)) {
141
+ return 1 /* Assign */;
142
+ }
143
+ if (containsBytes(data, getU32Encoder().encode(2), 0)) {
144
+ return 2 /* TransferSol */;
145
+ }
146
+ if (containsBytes(data, getU32Encoder().encode(3), 0)) {
147
+ return 3 /* CreateAccountWithSeed */;
148
+ }
149
+ if (containsBytes(data, getU32Encoder().encode(4), 0)) {
150
+ return 4 /* AdvanceNonceAccount */;
151
+ }
152
+ if (containsBytes(data, getU32Encoder().encode(5), 0)) {
153
+ return 5 /* WithdrawNonceAccount */;
154
+ }
155
+ if (containsBytes(data, getU32Encoder().encode(6), 0)) {
156
+ return 6 /* InitializeNonceAccount */;
157
+ }
158
+ if (containsBytes(data, getU32Encoder().encode(7), 0)) {
159
+ return 7 /* AuthorizeNonceAccount */;
160
+ }
161
+ if (containsBytes(data, getU32Encoder().encode(8), 0)) {
162
+ return 8 /* Allocate */;
163
+ }
164
+ if (containsBytes(data, getU32Encoder().encode(9), 0)) {
165
+ return 9 /* AllocateWithSeed */;
166
+ }
167
+ if (containsBytes(data, getU32Encoder().encode(10), 0)) {
168
+ return 10 /* AssignWithSeed */;
169
+ }
170
+ if (containsBytes(data, getU32Encoder().encode(11), 0)) {
171
+ return 11 /* TransferSolWithSeed */;
172
+ }
173
+ if (containsBytes(data, getU32Encoder().encode(12), 0)) {
174
+ return 12 /* UpgradeNonceAccount */;
175
+ }
176
+ throw new Error(
177
+ "The provided instruction could not be identified as a system instruction."
178
+ );
175
179
  }
176
180
  function expectAddress(value) {
177
181
  if (!value) {
@@ -185,58 +189,29 @@ function expectAddress(value) {
185
189
  }
186
190
  return value;
187
191
  }
188
- function expectProgramDerivedAddress(value) {
189
- if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) {
190
- throw new Error("Expected a ProgramDerivedAddress.");
191
- }
192
- return value;
193
- }
194
- function expectTransactionSigner(value) {
195
- if (!value || !isTransactionSigner(value)) {
196
- throw new Error("Expected a TransactionSigner.");
197
- }
198
- return value;
199
- }
200
- function accountMetaWithDefault(account, role) {
201
- if (account === void 0)
202
- return void 0;
203
- return typeof account === "string" ? { address: account, role } : account;
204
- }
205
- function getAccountMetasWithSigners(accounts, optionalAccountStrategy, programAddress) {
206
- const accountMetas = {};
207
- Object.keys(accounts).forEach((key) => {
208
- const account = accounts[key];
192
+ function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
193
+ return (account) => {
209
194
  if (!account.value) {
210
- if (optionalAccountStrategy === "omitted")
211
- return;
212
- accountMetas[key] = {
195
+ return Object.freeze({
213
196
  address: programAddress,
214
197
  role: AccountRole.READONLY
215
- };
216
- return;
198
+ });
217
199
  }
218
200
  const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;
219
- accountMetas[key] = Object.freeze({
201
+ return Object.freeze({
220
202
  address: expectAddress(account.value),
221
203
  role: isTransactionSigner(account.value) ? upgradeRoleToSigner(writableRole) : writableRole,
222
204
  ...isTransactionSigner(account.value) ? { signer: account.value } : {}
223
205
  });
224
- });
225
- return accountMetas;
206
+ };
226
207
  }
227
208
  function isTransactionSigner(value) {
228
209
  return !!value && typeof value === "object" && "address" in value && isTransactionSigner$1(value);
229
210
  }
230
- function memcmp(data, bytes, offset) {
231
- const slice = data.slice(offset, offset + bytes.length);
232
- if (slice.length !== bytes.length)
233
- return false;
234
- return bytes.every((b, i) => b === slice[i]);
235
- }
236
211
 
237
212
  // src/generated/instructions/advanceNonceAccount.ts
238
213
  function getAdvanceNonceAccountInstructionDataEncoder() {
239
- return mapEncoder(
214
+ return transformEncoder(
240
215
  getStructEncoder([["discriminator", getU32Encoder()]]),
241
216
  (value) => ({ ...value, discriminator: 4 })
242
217
  );
@@ -251,8 +226,8 @@ function getAdvanceNonceAccountInstructionDataCodec() {
251
226
  );
252
227
  }
253
228
  function getAdvanceNonceAccountInstruction(input) {
254
- const programAddress = "11111111111111111111111111111111";
255
- const accounts = {
229
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
230
+ const originalAccounts = {
256
231
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
257
232
  recentBlockhashesSysvar: {
258
233
  value: input.recentBlockhashesSysvar ?? null,
@@ -260,37 +235,21 @@ function getAdvanceNonceAccountInstruction(input) {
260
235
  },
261
236
  nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false }
262
237
  };
238
+ const accounts = originalAccounts;
263
239
  if (!accounts.recentBlockhashesSysvar.value) {
264
240
  accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
265
241
  }
266
- const accountMetas = getAccountMetasWithSigners(
267
- accounts,
268
- "programId",
269
- programAddress
270
- );
271
- const instruction = getAdvanceNonceAccountInstructionRaw(
272
- accountMetas,
273
- programAddress
274
- );
275
- return instruction;
276
- }
277
- function getAdvanceNonceAccountInstructionRaw(accounts, programAddress = "11111111111111111111111111111111", remainingAccounts) {
278
- return {
242
+ const getAccountMeta = getAccountMetaFactory(programAddress);
243
+ const instruction = {
279
244
  accounts: [
280
- accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
281
- accountMetaWithDefault(
282
- accounts.recentBlockhashesSysvar ?? "SysvarRecentB1ockHashes11111111111111111111",
283
- AccountRole.READONLY
284
- ),
285
- accountMetaWithDefault(
286
- accounts.nonceAuthority,
287
- AccountRole.READONLY_SIGNER
288
- ),
289
- ...remainingAccounts ?? []
245
+ getAccountMeta(accounts.nonceAccount),
246
+ getAccountMeta(accounts.recentBlockhashesSysvar),
247
+ getAccountMeta(accounts.nonceAuthority)
290
248
  ],
291
- data: getAdvanceNonceAccountInstructionDataEncoder().encode({}),
292
- programAddress
249
+ programAddress,
250
+ data: getAdvanceNonceAccountInstructionDataEncoder().encode({})
293
251
  };
252
+ return instruction;
294
253
  }
295
254
  function parseAdvanceNonceAccountInstruction(instruction) {
296
255
  if (instruction.accounts.length < 3) {
@@ -315,7 +274,7 @@ function parseAdvanceNonceAccountInstruction(instruction) {
315
274
  };
316
275
  }
317
276
  function getAllocateInstructionDataEncoder() {
318
- return mapEncoder(
277
+ return transformEncoder(
319
278
  getStructEncoder([
320
279
  ["discriminator", getU32Encoder()],
321
280
  ["space", getU64Encoder()]
@@ -336,32 +295,21 @@ function getAllocateInstructionDataCodec() {
336
295
  );
337
296
  }
338
297
  function getAllocateInstruction(input) {
339
- const programAddress = "11111111111111111111111111111111";
340
- const accounts = {
298
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
299
+ const originalAccounts = {
341
300
  newAccount: { value: input.newAccount ?? null, isWritable: true }
342
301
  };
302
+ const accounts = originalAccounts;
343
303
  const args = { ...input };
344
- const accountMetas = getAccountMetasWithSigners(
345
- accounts,
346
- "programId",
347
- programAddress
348
- );
349
- const instruction = getAllocateInstructionRaw(
350
- accountMetas,
351
- args,
352
- programAddress
353
- );
354
- return instruction;
355
- }
356
- function getAllocateInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
357
- return {
358
- accounts: [
359
- accountMetaWithDefault(accounts.newAccount, AccountRole.WRITABLE_SIGNER),
360
- ...remainingAccounts ?? []
361
- ],
362
- data: getAllocateInstructionDataEncoder().encode(args),
363
- programAddress
304
+ const getAccountMeta = getAccountMetaFactory(programAddress);
305
+ const instruction = {
306
+ accounts: [getAccountMeta(accounts.newAccount)],
307
+ programAddress,
308
+ data: getAllocateInstructionDataEncoder().encode(
309
+ args
310
+ )
364
311
  };
312
+ return instruction;
365
313
  }
366
314
  function parseAllocateInstruction(instruction) {
367
315
  if (instruction.accounts.length < 1) {
@@ -382,11 +330,11 @@ function parseAllocateInstruction(instruction) {
382
330
  };
383
331
  }
384
332
  function getAllocateWithSeedInstructionDataEncoder() {
385
- return mapEncoder(
333
+ return transformEncoder(
386
334
  getStructEncoder([
387
335
  ["discriminator", getU32Encoder()],
388
336
  ["base", getAddressEncoder()],
389
- ["seed", getStringEncoder()],
337
+ ["seed", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
390
338
  ["space", getU64Encoder()],
391
339
  ["programAddress", getAddressEncoder()]
392
340
  ]),
@@ -397,7 +345,7 @@ function getAllocateWithSeedInstructionDataDecoder() {
397
345
  return getStructDecoder([
398
346
  ["discriminator", getU32Decoder()],
399
347
  ["base", getAddressDecoder()],
400
- ["seed", getStringDecoder()],
348
+ ["seed", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
401
349
  ["space", getU64Decoder()],
402
350
  ["programAddress", getAddressDecoder()]
403
351
  ]);
@@ -409,34 +357,25 @@ function getAllocateWithSeedInstructionDataCodec() {
409
357
  );
410
358
  }
411
359
  function getAllocateWithSeedInstruction(input) {
412
- const programAddress = "11111111111111111111111111111111";
413
- const accounts = {
360
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
361
+ const originalAccounts = {
414
362
  newAccount: { value: input.newAccount ?? null, isWritable: true },
415
363
  baseAccount: { value: input.baseAccount ?? null, isWritable: false }
416
364
  };
365
+ const accounts = originalAccounts;
417
366
  const args = { ...input };
418
- const accountMetas = getAccountMetasWithSigners(
419
- accounts,
420
- "programId",
421
- programAddress
422
- );
423
- const instruction = getAllocateWithSeedInstructionRaw(
424
- accountMetas,
425
- args,
426
- programAddress
427
- );
428
- return instruction;
429
- }
430
- function getAllocateWithSeedInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
431
- return {
367
+ const getAccountMeta = getAccountMetaFactory(programAddress);
368
+ const instruction = {
432
369
  accounts: [
433
- accountMetaWithDefault(accounts.newAccount, AccountRole.WRITABLE),
434
- accountMetaWithDefault(accounts.baseAccount, AccountRole.READONLY_SIGNER),
435
- ...remainingAccounts ?? []
370
+ getAccountMeta(accounts.newAccount),
371
+ getAccountMeta(accounts.baseAccount)
436
372
  ],
437
- data: getAllocateWithSeedInstructionDataEncoder().encode(args),
438
- programAddress
373
+ programAddress,
374
+ data: getAllocateWithSeedInstructionDataEncoder().encode(
375
+ args
376
+ )
439
377
  };
378
+ return instruction;
440
379
  }
441
380
  function parseAllocateWithSeedInstruction(instruction) {
442
381
  if (instruction.accounts.length < 2) {
@@ -458,7 +397,7 @@ function parseAllocateWithSeedInstruction(instruction) {
458
397
  };
459
398
  }
460
399
  function getAssignInstructionDataEncoder() {
461
- return mapEncoder(
400
+ return transformEncoder(
462
401
  getStructEncoder([
463
402
  ["discriminator", getU32Encoder()],
464
403
  ["programAddress", getAddressEncoder()]
@@ -479,32 +418,21 @@ function getAssignInstructionDataCodec() {
479
418
  );
480
419
  }
481
420
  function getAssignInstruction(input) {
482
- const programAddress = "11111111111111111111111111111111";
483
- const accounts = {
421
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
422
+ const originalAccounts = {
484
423
  account: { value: input.account ?? null, isWritable: true }
485
424
  };
425
+ const accounts = originalAccounts;
486
426
  const args = { ...input };
487
- const accountMetas = getAccountMetasWithSigners(
488
- accounts,
489
- "programId",
490
- programAddress
491
- );
492
- const instruction = getAssignInstructionRaw(
493
- accountMetas,
494
- args,
495
- programAddress
496
- );
497
- return instruction;
498
- }
499
- function getAssignInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
500
- return {
501
- accounts: [
502
- accountMetaWithDefault(accounts.account, AccountRole.WRITABLE_SIGNER),
503
- ...remainingAccounts ?? []
504
- ],
505
- data: getAssignInstructionDataEncoder().encode(args),
506
- programAddress
427
+ const getAccountMeta = getAccountMetaFactory(programAddress);
428
+ const instruction = {
429
+ accounts: [getAccountMeta(accounts.account)],
430
+ programAddress,
431
+ data: getAssignInstructionDataEncoder().encode(
432
+ args
433
+ )
507
434
  };
435
+ return instruction;
508
436
  }
509
437
  function parseAssignInstruction(instruction) {
510
438
  if (instruction.accounts.length < 1) {
@@ -525,11 +453,11 @@ function parseAssignInstruction(instruction) {
525
453
  };
526
454
  }
527
455
  function getAssignWithSeedInstructionDataEncoder() {
528
- return mapEncoder(
456
+ return transformEncoder(
529
457
  getStructEncoder([
530
458
  ["discriminator", getU32Encoder()],
531
459
  ["base", getAddressEncoder()],
532
- ["seed", getStringEncoder()],
460
+ ["seed", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
533
461
  ["programAddress", getAddressEncoder()]
534
462
  ]),
535
463
  (value) => ({ ...value, discriminator: 10 })
@@ -539,7 +467,7 @@ function getAssignWithSeedInstructionDataDecoder() {
539
467
  return getStructDecoder([
540
468
  ["discriminator", getU32Decoder()],
541
469
  ["base", getAddressDecoder()],
542
- ["seed", getStringDecoder()],
470
+ ["seed", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
543
471
  ["programAddress", getAddressDecoder()]
544
472
  ]);
545
473
  }
@@ -550,34 +478,25 @@ function getAssignWithSeedInstructionDataCodec() {
550
478
  );
551
479
  }
552
480
  function getAssignWithSeedInstruction(input) {
553
- const programAddress = "11111111111111111111111111111111";
554
- const accounts = {
481
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
482
+ const originalAccounts = {
555
483
  account: { value: input.account ?? null, isWritable: true },
556
484
  baseAccount: { value: input.baseAccount ?? null, isWritable: false }
557
485
  };
486
+ const accounts = originalAccounts;
558
487
  const args = { ...input };
559
- const accountMetas = getAccountMetasWithSigners(
560
- accounts,
561
- "programId",
562
- programAddress
563
- );
564
- const instruction = getAssignWithSeedInstructionRaw(
565
- accountMetas,
566
- args,
567
- programAddress
568
- );
569
- return instruction;
570
- }
571
- function getAssignWithSeedInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
572
- return {
488
+ const getAccountMeta = getAccountMetaFactory(programAddress);
489
+ const instruction = {
573
490
  accounts: [
574
- accountMetaWithDefault(accounts.account, AccountRole.WRITABLE),
575
- accountMetaWithDefault(accounts.baseAccount, AccountRole.READONLY_SIGNER),
576
- ...remainingAccounts ?? []
491
+ getAccountMeta(accounts.account),
492
+ getAccountMeta(accounts.baseAccount)
577
493
  ],
578
- data: getAssignWithSeedInstructionDataEncoder().encode(args),
579
- programAddress
494
+ programAddress,
495
+ data: getAssignWithSeedInstructionDataEncoder().encode(
496
+ args
497
+ )
580
498
  };
499
+ return instruction;
581
500
  }
582
501
  function parseAssignWithSeedInstruction(instruction) {
583
502
  if (instruction.accounts.length < 2) {
@@ -599,7 +518,7 @@ function parseAssignWithSeedInstruction(instruction) {
599
518
  };
600
519
  }
601
520
  function getAuthorizeNonceAccountInstructionDataEncoder() {
602
- return mapEncoder(
521
+ return transformEncoder(
603
522
  getStructEncoder([
604
523
  ["discriminator", getU32Encoder()],
605
524
  ["newNonceAuthority", getAddressEncoder()]
@@ -620,37 +539,25 @@ function getAuthorizeNonceAccountInstructionDataCodec() {
620
539
  );
621
540
  }
622
541
  function getAuthorizeNonceAccountInstruction(input) {
623
- const programAddress = "11111111111111111111111111111111";
624
- const accounts = {
542
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
543
+ const originalAccounts = {
625
544
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
626
545
  nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false }
627
546
  };
547
+ const accounts = originalAccounts;
628
548
  const args = { ...input };
629
- const accountMetas = getAccountMetasWithSigners(
630
- accounts,
631
- "programId",
632
- programAddress
633
- );
634
- const instruction = getAuthorizeNonceAccountInstructionRaw(
635
- accountMetas,
636
- args,
637
- programAddress
638
- );
639
- return instruction;
640
- }
641
- function getAuthorizeNonceAccountInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
642
- return {
549
+ const getAccountMeta = getAccountMetaFactory(programAddress);
550
+ const instruction = {
643
551
  accounts: [
644
- accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
645
- accountMetaWithDefault(
646
- accounts.nonceAuthority,
647
- AccountRole.READONLY_SIGNER
648
- ),
649
- ...remainingAccounts ?? []
552
+ getAccountMeta(accounts.nonceAccount),
553
+ getAccountMeta(accounts.nonceAuthority)
650
554
  ],
651
- data: getAuthorizeNonceAccountInstructionDataEncoder().encode(args),
652
- programAddress
555
+ programAddress,
556
+ data: getAuthorizeNonceAccountInstructionDataEncoder().encode(
557
+ args
558
+ )
653
559
  };
560
+ return instruction;
654
561
  }
655
562
  function parseAuthorizeNonceAccountInstruction(instruction) {
656
563
  if (instruction.accounts.length < 2) {
@@ -674,7 +581,7 @@ function parseAuthorizeNonceAccountInstruction(instruction) {
674
581
  };
675
582
  }
676
583
  function getCreateAccountInstructionDataEncoder() {
677
- return mapEncoder(
584
+ return transformEncoder(
678
585
  getStructEncoder([
679
586
  ["discriminator", getU32Encoder()],
680
587
  ["lamports", getU64Encoder()],
@@ -699,38 +606,29 @@ function getCreateAccountInstructionDataCodec() {
699
606
  );
700
607
  }
701
608
  function getCreateAccountInstruction(input) {
702
- const programAddress = "11111111111111111111111111111111";
703
- const accounts = {
609
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
610
+ const originalAccounts = {
704
611
  payer: { value: input.payer ?? null, isWritable: true },
705
612
  newAccount: { value: input.newAccount ?? null, isWritable: true }
706
613
  };
614
+ const accounts = originalAccounts;
707
615
  const args = { ...input };
708
616
  const byteDelta = [Number(args.space) + BASE_ACCOUNT_SIZE].reduce(
709
617
  (a, b) => a + b,
710
618
  0
711
619
  );
712
- const accountMetas = getAccountMetasWithSigners(
713
- accounts,
714
- "programId",
715
- programAddress
716
- );
717
- const instruction = getCreateAccountInstructionRaw(
718
- accountMetas,
719
- args,
720
- programAddress
721
- );
722
- return Object.freeze({ ...instruction, byteDelta });
723
- }
724
- function getCreateAccountInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
725
- return {
620
+ const getAccountMeta = getAccountMetaFactory(programAddress);
621
+ const instruction = {
726
622
  accounts: [
727
- accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER),
728
- accountMetaWithDefault(accounts.newAccount, AccountRole.WRITABLE_SIGNER),
729
- ...remainingAccounts ?? []
623
+ getAccountMeta(accounts.payer),
624
+ getAccountMeta(accounts.newAccount)
730
625
  ],
731
- data: getCreateAccountInstructionDataEncoder().encode(args),
732
- programAddress
626
+ programAddress,
627
+ data: getCreateAccountInstructionDataEncoder().encode(
628
+ args
629
+ )
733
630
  };
631
+ return Object.freeze({ ...instruction, byteDelta });
734
632
  }
735
633
  function parseCreateAccountInstruction(instruction) {
736
634
  if (instruction.accounts.length < 2) {
@@ -752,11 +650,11 @@ function parseCreateAccountInstruction(instruction) {
752
650
  };
753
651
  }
754
652
  function getCreateAccountWithSeedInstructionDataEncoder() {
755
- return mapEncoder(
653
+ return transformEncoder(
756
654
  getStructEncoder([
757
655
  ["discriminator", getU32Encoder()],
758
656
  ["base", getAddressEncoder()],
759
- ["seed", getStringEncoder()],
657
+ ["seed", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
760
658
  ["amount", getU64Encoder()],
761
659
  ["space", getU64Encoder()],
762
660
  ["programAddress", getAddressEncoder()]
@@ -768,7 +666,7 @@ function getCreateAccountWithSeedInstructionDataDecoder() {
768
666
  return getStructDecoder([
769
667
  ["discriminator", getU32Decoder()],
770
668
  ["base", getAddressDecoder()],
771
- ["seed", getStringDecoder()],
669
+ ["seed", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
772
670
  ["amount", getU64Decoder()],
773
671
  ["space", getU64Decoder()],
774
672
  ["programAddress", getAddressDecoder()]
@@ -781,36 +679,27 @@ function getCreateAccountWithSeedInstructionDataCodec() {
781
679
  );
782
680
  }
783
681
  function getCreateAccountWithSeedInstruction(input) {
784
- const programAddress = "11111111111111111111111111111111";
785
- const accounts = {
682
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
683
+ const originalAccounts = {
786
684
  payer: { value: input.payer ?? null, isWritable: true },
787
685
  newAccount: { value: input.newAccount ?? null, isWritable: true },
788
686
  baseAccount: { value: input.baseAccount ?? null, isWritable: false }
789
687
  };
688
+ const accounts = originalAccounts;
790
689
  const args = { ...input };
791
- const accountMetas = getAccountMetasWithSigners(
792
- accounts,
793
- "programId",
794
- programAddress
795
- );
796
- const instruction = getCreateAccountWithSeedInstructionRaw(
797
- accountMetas,
798
- args,
799
- programAddress
800
- );
801
- return instruction;
802
- }
803
- function getCreateAccountWithSeedInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
804
- return {
690
+ const getAccountMeta = getAccountMetaFactory(programAddress);
691
+ const instruction = {
805
692
  accounts: [
806
- accountMetaWithDefault(accounts.payer, AccountRole.WRITABLE_SIGNER),
807
- accountMetaWithDefault(accounts.newAccount, AccountRole.WRITABLE),
808
- accountMetaWithDefault(accounts.baseAccount, AccountRole.READONLY_SIGNER),
809
- ...remainingAccounts ?? []
693
+ getAccountMeta(accounts.payer),
694
+ getAccountMeta(accounts.newAccount),
695
+ getAccountMeta(accounts.baseAccount)
810
696
  ],
811
- data: getCreateAccountWithSeedInstructionDataEncoder().encode(args),
812
- programAddress
697
+ programAddress,
698
+ data: getCreateAccountWithSeedInstructionDataEncoder().encode(
699
+ args
700
+ )
813
701
  };
702
+ return instruction;
814
703
  }
815
704
  function parseCreateAccountWithSeedInstruction(instruction) {
816
705
  if (instruction.accounts.length < 3) {
@@ -835,7 +724,7 @@ function parseCreateAccountWithSeedInstruction(instruction) {
835
724
  };
836
725
  }
837
726
  function getInitializeNonceAccountInstructionDataEncoder() {
838
- return mapEncoder(
727
+ return transformEncoder(
839
728
  getStructEncoder([
840
729
  ["discriminator", getU32Encoder()],
841
730
  ["nonceAuthority", getAddressEncoder()]
@@ -856,8 +745,8 @@ function getInitializeNonceAccountInstructionDataCodec() {
856
745
  );
857
746
  }
858
747
  function getInitializeNonceAccountInstruction(input) {
859
- const programAddress = "11111111111111111111111111111111";
860
- const accounts = {
748
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
749
+ const originalAccounts = {
861
750
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
862
751
  recentBlockhashesSysvar: {
863
752
  value: input.recentBlockhashesSysvar ?? null,
@@ -865,6 +754,7 @@ function getInitializeNonceAccountInstruction(input) {
865
754
  },
866
755
  rentSysvar: { value: input.rentSysvar ?? null, isWritable: false }
867
756
  };
757
+ const accounts = originalAccounts;
868
758
  const args = { ...input };
869
759
  if (!accounts.recentBlockhashesSysvar.value) {
870
760
  accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
@@ -872,35 +762,19 @@ function getInitializeNonceAccountInstruction(input) {
872
762
  if (!accounts.rentSysvar.value) {
873
763
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
874
764
  }
875
- const accountMetas = getAccountMetasWithSigners(
876
- accounts,
877
- "programId",
878
- programAddress
879
- );
880
- const instruction = getInitializeNonceAccountInstructionRaw(
881
- accountMetas,
882
- args,
883
- programAddress
884
- );
885
- return instruction;
886
- }
887
- function getInitializeNonceAccountInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
888
- return {
765
+ const getAccountMeta = getAccountMetaFactory(programAddress);
766
+ const instruction = {
889
767
  accounts: [
890
- accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
891
- accountMetaWithDefault(
892
- accounts.recentBlockhashesSysvar ?? "SysvarRecentB1ockHashes11111111111111111111",
893
- AccountRole.READONLY
894
- ),
895
- accountMetaWithDefault(
896
- accounts.rentSysvar ?? "SysvarRent111111111111111111111111111111111",
897
- AccountRole.READONLY
898
- ),
899
- ...remainingAccounts ?? []
768
+ getAccountMeta(accounts.nonceAccount),
769
+ getAccountMeta(accounts.recentBlockhashesSysvar),
770
+ getAccountMeta(accounts.rentSysvar)
900
771
  ],
901
- data: getInitializeNonceAccountInstructionDataEncoder().encode(args),
902
- programAddress
772
+ programAddress,
773
+ data: getInitializeNonceAccountInstructionDataEncoder().encode(
774
+ args
775
+ )
903
776
  };
777
+ return instruction;
904
778
  }
905
779
  function parseInitializeNonceAccountInstruction(instruction) {
906
780
  if (instruction.accounts.length < 3) {
@@ -925,7 +799,7 @@ function parseInitializeNonceAccountInstruction(instruction) {
925
799
  };
926
800
  }
927
801
  function getTransferSolInstructionDataEncoder() {
928
- return mapEncoder(
802
+ return transformEncoder(
929
803
  getStructEncoder([
930
804
  ["discriminator", getU32Encoder()],
931
805
  ["amount", getU64Encoder()]
@@ -946,34 +820,25 @@ function getTransferSolInstructionDataCodec() {
946
820
  );
947
821
  }
948
822
  function getTransferSolInstruction(input) {
949
- const programAddress = "11111111111111111111111111111111";
950
- const accounts = {
823
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
824
+ const originalAccounts = {
951
825
  source: { value: input.source ?? null, isWritable: true },
952
826
  destination: { value: input.destination ?? null, isWritable: true }
953
827
  };
828
+ const accounts = originalAccounts;
954
829
  const args = { ...input };
955
- const accountMetas = getAccountMetasWithSigners(
956
- accounts,
957
- "programId",
958
- programAddress
959
- );
960
- const instruction = getTransferSolInstructionRaw(
961
- accountMetas,
962
- args,
963
- programAddress
964
- );
965
- return instruction;
966
- }
967
- function getTransferSolInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
968
- return {
830
+ const getAccountMeta = getAccountMetaFactory(programAddress);
831
+ const instruction = {
969
832
  accounts: [
970
- accountMetaWithDefault(accounts.source, AccountRole.WRITABLE_SIGNER),
971
- accountMetaWithDefault(accounts.destination, AccountRole.WRITABLE),
972
- ...remainingAccounts ?? []
833
+ getAccountMeta(accounts.source),
834
+ getAccountMeta(accounts.destination)
973
835
  ],
974
- data: getTransferSolInstructionDataEncoder().encode(args),
975
- programAddress
836
+ programAddress,
837
+ data: getTransferSolInstructionDataEncoder().encode(
838
+ args
839
+ )
976
840
  };
841
+ return instruction;
977
842
  }
978
843
  function parseTransferSolInstruction(instruction) {
979
844
  if (instruction.accounts.length < 2) {
@@ -995,11 +860,11 @@ function parseTransferSolInstruction(instruction) {
995
860
  };
996
861
  }
997
862
  function getTransferSolWithSeedInstructionDataEncoder() {
998
- return mapEncoder(
863
+ return transformEncoder(
999
864
  getStructEncoder([
1000
865
  ["discriminator", getU32Encoder()],
1001
866
  ["amount", getU64Encoder()],
1002
- ["fromSeed", getStringEncoder()],
867
+ ["fromSeed", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
1003
868
  ["fromOwner", getAddressEncoder()]
1004
869
  ]),
1005
870
  (value) => ({ ...value, discriminator: 11 })
@@ -1009,7 +874,7 @@ function getTransferSolWithSeedInstructionDataDecoder() {
1009
874
  return getStructDecoder([
1010
875
  ["discriminator", getU32Decoder()],
1011
876
  ["amount", getU64Decoder()],
1012
- ["fromSeed", getStringDecoder()],
877
+ ["fromSeed", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
1013
878
  ["fromOwner", getAddressDecoder()]
1014
879
  ]);
1015
880
  }
@@ -1020,36 +885,27 @@ function getTransferSolWithSeedInstructionDataCodec() {
1020
885
  );
1021
886
  }
1022
887
  function getTransferSolWithSeedInstruction(input) {
1023
- const programAddress = "11111111111111111111111111111111";
1024
- const accounts = {
888
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
889
+ const originalAccounts = {
1025
890
  source: { value: input.source ?? null, isWritable: true },
1026
891
  baseAccount: { value: input.baseAccount ?? null, isWritable: false },
1027
892
  destination: { value: input.destination ?? null, isWritable: true }
1028
893
  };
894
+ const accounts = originalAccounts;
1029
895
  const args = { ...input };
1030
- const accountMetas = getAccountMetasWithSigners(
1031
- accounts,
1032
- "programId",
1033
- programAddress
1034
- );
1035
- const instruction = getTransferSolWithSeedInstructionRaw(
1036
- accountMetas,
1037
- args,
1038
- programAddress
1039
- );
1040
- return instruction;
1041
- }
1042
- function getTransferSolWithSeedInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
1043
- return {
896
+ const getAccountMeta = getAccountMetaFactory(programAddress);
897
+ const instruction = {
1044
898
  accounts: [
1045
- accountMetaWithDefault(accounts.source, AccountRole.WRITABLE),
1046
- accountMetaWithDefault(accounts.baseAccount, AccountRole.READONLY_SIGNER),
1047
- accountMetaWithDefault(accounts.destination, AccountRole.WRITABLE),
1048
- ...remainingAccounts ?? []
899
+ getAccountMeta(accounts.source),
900
+ getAccountMeta(accounts.baseAccount),
901
+ getAccountMeta(accounts.destination)
1049
902
  ],
1050
- data: getTransferSolWithSeedInstructionDataEncoder().encode(args),
1051
- programAddress
903
+ programAddress,
904
+ data: getTransferSolWithSeedInstructionDataEncoder().encode(
905
+ args
906
+ )
1052
907
  };
908
+ return instruction;
1053
909
  }
1054
910
  function parseTransferSolWithSeedInstruction(instruction) {
1055
911
  if (instruction.accounts.length < 3) {
@@ -1074,7 +930,7 @@ function parseTransferSolWithSeedInstruction(instruction) {
1074
930
  };
1075
931
  }
1076
932
  function getUpgradeNonceAccountInstructionDataEncoder() {
1077
- return mapEncoder(
933
+ return transformEncoder(
1078
934
  getStructEncoder([["discriminator", getU32Encoder()]]),
1079
935
  (value) => ({ ...value, discriminator: 12 })
1080
936
  );
@@ -1089,30 +945,18 @@ function getUpgradeNonceAccountInstructionDataCodec() {
1089
945
  );
1090
946
  }
1091
947
  function getUpgradeNonceAccountInstruction(input) {
1092
- const programAddress = "11111111111111111111111111111111";
1093
- const accounts = {
948
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
949
+ const originalAccounts = {
1094
950
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true }
1095
951
  };
1096
- const accountMetas = getAccountMetasWithSigners(
1097
- accounts,
1098
- "programId",
1099
- programAddress
1100
- );
1101
- const instruction = getUpgradeNonceAccountInstructionRaw(
1102
- accountMetas,
1103
- programAddress
1104
- );
1105
- return instruction;
1106
- }
1107
- function getUpgradeNonceAccountInstructionRaw(accounts, programAddress = "11111111111111111111111111111111", remainingAccounts) {
1108
- return {
1109
- accounts: [
1110
- accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
1111
- ...remainingAccounts ?? []
1112
- ],
1113
- data: getUpgradeNonceAccountInstructionDataEncoder().encode({}),
1114
- programAddress
952
+ const accounts = originalAccounts;
953
+ const getAccountMeta = getAccountMetaFactory(programAddress);
954
+ const instruction = {
955
+ accounts: [getAccountMeta(accounts.nonceAccount)],
956
+ programAddress,
957
+ data: getUpgradeNonceAccountInstructionDataEncoder().encode({})
1115
958
  };
959
+ return instruction;
1116
960
  }
1117
961
  function parseUpgradeNonceAccountInstruction(instruction) {
1118
962
  if (instruction.accounts.length < 1) {
@@ -1135,7 +979,7 @@ function parseUpgradeNonceAccountInstruction(instruction) {
1135
979
  };
1136
980
  }
1137
981
  function getWithdrawNonceAccountInstructionDataEncoder() {
1138
- return mapEncoder(
982
+ return transformEncoder(
1139
983
  getStructEncoder([
1140
984
  ["discriminator", getU32Encoder()],
1141
985
  ["withdrawAmount", getU64Encoder()]
@@ -1156,8 +1000,8 @@ function getWithdrawNonceAccountInstructionDataCodec() {
1156
1000
  );
1157
1001
  }
1158
1002
  function getWithdrawNonceAccountInstruction(input) {
1159
- const programAddress = "11111111111111111111111111111111";
1160
- const accounts = {
1003
+ const programAddress = SYSTEM_PROGRAM_ADDRESS;
1004
+ const originalAccounts = {
1161
1005
  nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
1162
1006
  recipientAccount: {
1163
1007
  value: input.recipientAccount ?? null,
@@ -1170,6 +1014,7 @@ function getWithdrawNonceAccountInstruction(input) {
1170
1014
  rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
1171
1015
  nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false }
1172
1016
  };
1017
+ const accounts = originalAccounts;
1173
1018
  const args = { ...input };
1174
1019
  if (!accounts.recentBlockhashesSysvar.value) {
1175
1020
  accounts.recentBlockhashesSysvar.value = "SysvarRecentB1ockHashes11111111111111111111";
@@ -1177,40 +1022,21 @@ function getWithdrawNonceAccountInstruction(input) {
1177
1022
  if (!accounts.rentSysvar.value) {
1178
1023
  accounts.rentSysvar.value = "SysvarRent111111111111111111111111111111111";
1179
1024
  }
1180
- const accountMetas = getAccountMetasWithSigners(
1181
- accounts,
1182
- "programId",
1183
- programAddress
1184
- );
1185
- const instruction = getWithdrawNonceAccountInstructionRaw(
1186
- accountMetas,
1187
- args,
1188
- programAddress
1189
- );
1190
- return instruction;
1191
- }
1192
- function getWithdrawNonceAccountInstructionRaw(accounts, args, programAddress = "11111111111111111111111111111111", remainingAccounts) {
1193
- return {
1025
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1026
+ const instruction = {
1194
1027
  accounts: [
1195
- accountMetaWithDefault(accounts.nonceAccount, AccountRole.WRITABLE),
1196
- accountMetaWithDefault(accounts.recipientAccount, AccountRole.WRITABLE),
1197
- accountMetaWithDefault(
1198
- accounts.recentBlockhashesSysvar ?? "SysvarRecentB1ockHashes11111111111111111111",
1199
- AccountRole.READONLY
1200
- ),
1201
- accountMetaWithDefault(
1202
- accounts.rentSysvar ?? "SysvarRent111111111111111111111111111111111",
1203
- AccountRole.READONLY
1204
- ),
1205
- accountMetaWithDefault(
1206
- accounts.nonceAuthority,
1207
- AccountRole.READONLY_SIGNER
1208
- ),
1209
- ...remainingAccounts ?? []
1028
+ getAccountMeta(accounts.nonceAccount),
1029
+ getAccountMeta(accounts.recipientAccount),
1030
+ getAccountMeta(accounts.recentBlockhashesSysvar),
1031
+ getAccountMeta(accounts.rentSysvar),
1032
+ getAccountMeta(accounts.nonceAuthority)
1210
1033
  ],
1211
- data: getWithdrawNonceAccountInstructionDataEncoder().encode(args),
1212
- programAddress
1034
+ programAddress,
1035
+ data: getWithdrawNonceAccountInstructionDataEncoder().encode(
1036
+ args
1037
+ )
1213
1038
  };
1039
+ return instruction;
1214
1040
  }
1215
1041
  function parseWithdrawNonceAccountInstruction(instruction) {
1216
1042
  if (instruction.accounts.length < 5) {
@@ -1236,82 +1062,7 @@ function parseWithdrawNonceAccountInstruction(instruction) {
1236
1062
  )
1237
1063
  };
1238
1064
  }
1239
- var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
1240
- function getSystemProgram() {
1241
- return {
1242
- name: "system",
1243
- address: SYSTEM_PROGRAM_ADDRESS,
1244
- getErrorFromCode(code, cause) {
1245
- return getSystemProgramErrorFromCode(code, cause);
1246
- }
1247
- };
1248
- }
1249
- var SystemAccount = /* @__PURE__ */ ((SystemAccount2) => {
1250
- SystemAccount2[SystemAccount2["Nonce"] = 0] = "Nonce";
1251
- return SystemAccount2;
1252
- })(SystemAccount || {});
1253
- var SystemInstruction = /* @__PURE__ */ ((SystemInstruction2) => {
1254
- SystemInstruction2[SystemInstruction2["CreateAccount"] = 0] = "CreateAccount";
1255
- SystemInstruction2[SystemInstruction2["Assign"] = 1] = "Assign";
1256
- SystemInstruction2[SystemInstruction2["TransferSol"] = 2] = "TransferSol";
1257
- SystemInstruction2[SystemInstruction2["CreateAccountWithSeed"] = 3] = "CreateAccountWithSeed";
1258
- SystemInstruction2[SystemInstruction2["AdvanceNonceAccount"] = 4] = "AdvanceNonceAccount";
1259
- SystemInstruction2[SystemInstruction2["WithdrawNonceAccount"] = 5] = "WithdrawNonceAccount";
1260
- SystemInstruction2[SystemInstruction2["InitializeNonceAccount"] = 6] = "InitializeNonceAccount";
1261
- SystemInstruction2[SystemInstruction2["AuthorizeNonceAccount"] = 7] = "AuthorizeNonceAccount";
1262
- SystemInstruction2[SystemInstruction2["Allocate"] = 8] = "Allocate";
1263
- SystemInstruction2[SystemInstruction2["AllocateWithSeed"] = 9] = "AllocateWithSeed";
1264
- SystemInstruction2[SystemInstruction2["AssignWithSeed"] = 10] = "AssignWithSeed";
1265
- SystemInstruction2[SystemInstruction2["TransferSolWithSeed"] = 11] = "TransferSolWithSeed";
1266
- SystemInstruction2[SystemInstruction2["UpgradeNonceAccount"] = 12] = "UpgradeNonceAccount";
1267
- return SystemInstruction2;
1268
- })(SystemInstruction || {});
1269
- function identifySystemInstruction(instruction) {
1270
- const data = instruction instanceof Uint8Array ? instruction : instruction.data;
1271
- if (memcmp(data, getU32Encoder().encode(0), 0)) {
1272
- return 0 /* CreateAccount */;
1273
- }
1274
- if (memcmp(data, getU32Encoder().encode(1), 0)) {
1275
- return 1 /* Assign */;
1276
- }
1277
- if (memcmp(data, getU32Encoder().encode(2), 0)) {
1278
- return 2 /* TransferSol */;
1279
- }
1280
- if (memcmp(data, getU32Encoder().encode(3), 0)) {
1281
- return 3 /* CreateAccountWithSeed */;
1282
- }
1283
- if (memcmp(data, getU32Encoder().encode(4), 0)) {
1284
- return 4 /* AdvanceNonceAccount */;
1285
- }
1286
- if (memcmp(data, getU32Encoder().encode(5), 0)) {
1287
- return 5 /* WithdrawNonceAccount */;
1288
- }
1289
- if (memcmp(data, getU32Encoder().encode(6), 0)) {
1290
- return 6 /* InitializeNonceAccount */;
1291
- }
1292
- if (memcmp(data, getU32Encoder().encode(7), 0)) {
1293
- return 7 /* AuthorizeNonceAccount */;
1294
- }
1295
- if (memcmp(data, getU32Encoder().encode(8), 0)) {
1296
- return 8 /* Allocate */;
1297
- }
1298
- if (memcmp(data, getU32Encoder().encode(9), 0)) {
1299
- return 9 /* AllocateWithSeed */;
1300
- }
1301
- if (memcmp(data, getU32Encoder().encode(10), 0)) {
1302
- return 10 /* AssignWithSeed */;
1303
- }
1304
- if (memcmp(data, getU32Encoder().encode(11), 0)) {
1305
- return 11 /* TransferSolWithSeed */;
1306
- }
1307
- if (memcmp(data, getU32Encoder().encode(12), 0)) {
1308
- return 12 /* UpgradeNonceAccount */;
1309
- }
1310
- throw new Error(
1311
- "The provided instruction could not be identified as a system instruction."
1312
- );
1313
- }
1314
1065
 
1315
- export { NonceState, NonceVersion, SYSTEM_PROGRAM_ADDRESS, SystemAccount, SystemInstruction, SystemProgramError, SystemProgramErrorCode, accountMetaWithDefault, decodeNonce, expectAddress, expectProgramDerivedAddress, expectSome, expectTransactionSigner, fetchAllMaybeNonce, fetchAllNonce, fetchMaybeNonce, fetchNonce, getAccountMetasWithSigners, getAdvanceNonceAccountInstruction, getAdvanceNonceAccountInstructionDataCodec, getAdvanceNonceAccountInstructionDataDecoder, getAdvanceNonceAccountInstructionDataEncoder, getAdvanceNonceAccountInstructionRaw, getAllocateInstruction, getAllocateInstructionDataCodec, getAllocateInstructionDataDecoder, getAllocateInstructionDataEncoder, getAllocateInstructionRaw, getAllocateWithSeedInstruction, getAllocateWithSeedInstructionDataCodec, getAllocateWithSeedInstructionDataDecoder, getAllocateWithSeedInstructionDataEncoder, getAllocateWithSeedInstructionRaw, getAssignInstruction, getAssignInstructionDataCodec, getAssignInstructionDataDecoder, getAssignInstructionDataEncoder, getAssignInstructionRaw, getAssignWithSeedInstruction, getAssignWithSeedInstructionDataCodec, getAssignWithSeedInstructionDataDecoder, getAssignWithSeedInstructionDataEncoder, getAssignWithSeedInstructionRaw, getAuthorizeNonceAccountInstruction, getAuthorizeNonceAccountInstructionDataCodec, getAuthorizeNonceAccountInstructionDataDecoder, getAuthorizeNonceAccountInstructionDataEncoder, getAuthorizeNonceAccountInstructionRaw, getCreateAccountInstruction, getCreateAccountInstructionDataCodec, getCreateAccountInstructionDataDecoder, getCreateAccountInstructionDataEncoder, getCreateAccountInstructionRaw, getCreateAccountWithSeedInstruction, getCreateAccountWithSeedInstructionDataCodec, getCreateAccountWithSeedInstructionDataDecoder, getCreateAccountWithSeedInstructionDataEncoder, getCreateAccountWithSeedInstructionRaw, getInitializeNonceAccountInstruction, getInitializeNonceAccountInstructionDataCodec, getInitializeNonceAccountInstructionDataDecoder, getInitializeNonceAccountInstructionDataEncoder, getInitializeNonceAccountInstructionRaw, getNonceAccountDataCodec, getNonceAccountDataDecoder, getNonceAccountDataEncoder, getNonceSize, getNonceStateCodec, getNonceStateDecoder, getNonceStateEncoder, getNonceVersionCodec, getNonceVersionDecoder, getNonceVersionEncoder, getSystemProgram, getSystemProgramErrorFromCode, getTransferSolInstruction, getTransferSolInstructionDataCodec, getTransferSolInstructionDataDecoder, getTransferSolInstructionDataEncoder, getTransferSolInstructionRaw, getTransferSolWithSeedInstruction, getTransferSolWithSeedInstructionDataCodec, getTransferSolWithSeedInstructionDataDecoder, getTransferSolWithSeedInstructionDataEncoder, getTransferSolWithSeedInstructionRaw, getUpgradeNonceAccountInstruction, getUpgradeNonceAccountInstructionDataCodec, getUpgradeNonceAccountInstructionDataDecoder, getUpgradeNonceAccountInstructionDataEncoder, getUpgradeNonceAccountInstructionRaw, getWithdrawNonceAccountInstruction, getWithdrawNonceAccountInstructionDataCodec, getWithdrawNonceAccountInstructionDataDecoder, getWithdrawNonceAccountInstructionDataEncoder, getWithdrawNonceAccountInstructionRaw, identifySystemInstruction, isTransactionSigner, memcmp, parseAdvanceNonceAccountInstruction, parseAllocateInstruction, parseAllocateWithSeedInstruction, parseAssignInstruction, parseAssignWithSeedInstruction, parseAuthorizeNonceAccountInstruction, parseCreateAccountInstruction, parseCreateAccountWithSeedInstruction, parseInitializeNonceAccountInstruction, parseTransferSolInstruction, parseTransferSolWithSeedInstruction, parseUpgradeNonceAccountInstruction, parseWithdrawNonceAccountInstruction };
1066
+ export { NonceState, NonceVersion, SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE, SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH, SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH, SYSTEM_ERROR__INVALID_PROGRAM_ID, SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED, SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED, SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES, SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE, SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS, SYSTEM_PROGRAM_ADDRESS, SystemAccount, SystemInstruction, decodeNonce, fetchAllMaybeNonce, fetchAllNonce, fetchMaybeNonce, fetchNonce, getAdvanceNonceAccountInstruction, getAdvanceNonceAccountInstructionDataCodec, getAdvanceNonceAccountInstructionDataDecoder, getAdvanceNonceAccountInstructionDataEncoder, getAllocateInstruction, getAllocateInstructionDataCodec, getAllocateInstructionDataDecoder, getAllocateInstructionDataEncoder, getAllocateWithSeedInstruction, getAllocateWithSeedInstructionDataCodec, getAllocateWithSeedInstructionDataDecoder, getAllocateWithSeedInstructionDataEncoder, getAssignInstruction, getAssignInstructionDataCodec, getAssignInstructionDataDecoder, getAssignInstructionDataEncoder, getAssignWithSeedInstruction, getAssignWithSeedInstructionDataCodec, getAssignWithSeedInstructionDataDecoder, getAssignWithSeedInstructionDataEncoder, getAuthorizeNonceAccountInstruction, getAuthorizeNonceAccountInstructionDataCodec, getAuthorizeNonceAccountInstructionDataDecoder, getAuthorizeNonceAccountInstructionDataEncoder, getCreateAccountInstruction, getCreateAccountInstructionDataCodec, getCreateAccountInstructionDataDecoder, getCreateAccountInstructionDataEncoder, getCreateAccountWithSeedInstruction, getCreateAccountWithSeedInstructionDataCodec, getCreateAccountWithSeedInstructionDataDecoder, getCreateAccountWithSeedInstructionDataEncoder, getInitializeNonceAccountInstruction, getInitializeNonceAccountInstructionDataCodec, getInitializeNonceAccountInstructionDataDecoder, getInitializeNonceAccountInstructionDataEncoder, getNonceCodec, getNonceDecoder, getNonceEncoder, getNonceSize, getNonceStateCodec, getNonceStateDecoder, getNonceStateEncoder, getNonceVersionCodec, getNonceVersionDecoder, getNonceVersionEncoder, getSystemErrorMessage, getTransferSolInstruction, getTransferSolInstructionDataCodec, getTransferSolInstructionDataDecoder, getTransferSolInstructionDataEncoder, getTransferSolWithSeedInstruction, getTransferSolWithSeedInstructionDataCodec, getTransferSolWithSeedInstructionDataDecoder, getTransferSolWithSeedInstructionDataEncoder, getUpgradeNonceAccountInstruction, getUpgradeNonceAccountInstructionDataCodec, getUpgradeNonceAccountInstructionDataDecoder, getUpgradeNonceAccountInstructionDataEncoder, getWithdrawNonceAccountInstruction, getWithdrawNonceAccountInstructionDataCodec, getWithdrawNonceAccountInstructionDataDecoder, getWithdrawNonceAccountInstructionDataEncoder, identifySystemInstruction, parseAdvanceNonceAccountInstruction, parseAllocateInstruction, parseAllocateWithSeedInstruction, parseAssignInstruction, parseAssignWithSeedInstruction, parseAuthorizeNonceAccountInstruction, parseCreateAccountInstruction, parseCreateAccountWithSeedInstruction, parseInitializeNonceAccountInstruction, parseTransferSolInstruction, parseTransferSolWithSeedInstruction, parseUpgradeNonceAccountInstruction, parseWithdrawNonceAccountInstruction };
1316
1067
  //# sourceMappingURL=out.js.map
1317
1068
  //# sourceMappingURL=index.js.map