@solana-program/system 0.12.0 → 0.12.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.
Files changed (59) hide show
  1. package/README.md +7 -9
  2. package/dist/src/index.js +4 -5
  3. package/dist/src/index.js.map +1 -1
  4. package/dist/src/index.mjs +5 -6
  5. package/dist/src/index.mjs.map +1 -1
  6. package/dist/types/generated/instructions/advanceNonceAccount.d.ts +1 -1
  7. package/dist/types/generated/instructions/advanceNonceAccount.d.ts.map +1 -1
  8. package/dist/types/generated/instructions/allocate.d.ts +1 -1
  9. package/dist/types/generated/instructions/allocate.d.ts.map +1 -1
  10. package/dist/types/generated/instructions/allocateWithSeed.d.ts +1 -1
  11. package/dist/types/generated/instructions/allocateWithSeed.d.ts.map +1 -1
  12. package/dist/types/generated/instructions/assign.d.ts +1 -1
  13. package/dist/types/generated/instructions/assign.d.ts.map +1 -1
  14. package/dist/types/generated/instructions/assignWithSeed.d.ts +1 -1
  15. package/dist/types/generated/instructions/assignWithSeed.d.ts.map +1 -1
  16. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts +1 -1
  17. package/dist/types/generated/instructions/authorizeNonceAccount.d.ts.map +1 -1
  18. package/dist/types/generated/instructions/createAccount.d.ts +1 -1
  19. package/dist/types/generated/instructions/createAccount.d.ts.map +1 -1
  20. package/dist/types/generated/instructions/createAccountWithSeed.d.ts +1 -1
  21. package/dist/types/generated/instructions/createAccountWithSeed.d.ts.map +1 -1
  22. package/dist/types/generated/instructions/initializeNonceAccount.d.ts +1 -1
  23. package/dist/types/generated/instructions/initializeNonceAccount.d.ts.map +1 -1
  24. package/dist/types/generated/instructions/transferSol.d.ts +1 -1
  25. package/dist/types/generated/instructions/transferSol.d.ts.map +1 -1
  26. package/dist/types/generated/instructions/transferSolWithSeed.d.ts +1 -1
  27. package/dist/types/generated/instructions/transferSolWithSeed.d.ts.map +1 -1
  28. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts +1 -1
  29. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts.map +1 -1
  30. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts +1 -1
  31. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts.map +1 -1
  32. package/dist/types/generated/programs/system.d.ts +1 -1
  33. package/dist/types/generated/programs/system.d.ts.map +1 -1
  34. package/package.json +31 -28
  35. package/src/generated/accounts/index.ts +9 -0
  36. package/src/generated/accounts/nonce.ts +139 -0
  37. package/src/generated/errors/index.ts +9 -0
  38. package/src/generated/errors/system.ts +77 -0
  39. package/src/generated/index.ts +13 -0
  40. package/src/generated/instructions/advanceNonceAccount.ts +186 -0
  41. package/src/generated/instructions/allocate.ts +148 -0
  42. package/src/generated/instructions/allocateWithSeed.ts +189 -0
  43. package/src/generated/instructions/assign.ts +145 -0
  44. package/src/generated/instructions/assignWithSeed.ts +177 -0
  45. package/src/generated/instructions/authorizeNonceAccount.ts +169 -0
  46. package/src/generated/instructions/createAccount.ts +184 -0
  47. package/src/generated/instructions/createAccountWithSeed.ts +221 -0
  48. package/src/generated/instructions/index.ts +21 -0
  49. package/src/generated/instructions/initializeNonceAccount.ts +202 -0
  50. package/src/generated/instructions/transferSol.ts +157 -0
  51. package/src/generated/instructions/transferSolWithSeed.ts +191 -0
  52. package/src/generated/instructions/upgradeNonceAccount.ts +135 -0
  53. package/src/generated/instructions/withdrawNonceAccount.ts +235 -0
  54. package/src/generated/programs/index.ts +9 -0
  55. package/src/generated/programs/system.ts +355 -0
  56. package/src/generated/types/index.ts +10 -0
  57. package/src/generated/types/nonceState.ts +37 -0
  58. package/src/generated/types/nonceVersion.ts +37 -0
  59. package/src/index.ts +1 -0
@@ -0,0 +1,157 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ combineCodec,
11
+ getStructDecoder,
12
+ getStructEncoder,
13
+ getU32Decoder,
14
+ getU32Encoder,
15
+ getU64Decoder,
16
+ getU64Encoder,
17
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
18
+ SolanaError,
19
+ transformEncoder,
20
+ type AccountMeta,
21
+ type AccountSignerMeta,
22
+ type Address,
23
+ type FixedSizeCodec,
24
+ type FixedSizeDecoder,
25
+ type FixedSizeEncoder,
26
+ type Instruction,
27
+ type InstructionWithAccounts,
28
+ type InstructionWithData,
29
+ type ReadonlyUint8Array,
30
+ type TransactionSigner,
31
+ type WritableAccount,
32
+ type WritableSignerAccount,
33
+ } from '@solana/kit';
34
+ import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
35
+ import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
36
+
37
+ export const TRANSFER_SOL_DISCRIMINATOR = 2;
38
+
39
+ export function getTransferSolDiscriminatorBytes(): ReadonlyUint8Array {
40
+ return getU32Encoder().encode(TRANSFER_SOL_DISCRIMINATOR);
41
+ }
42
+
43
+ export type TransferSolInstruction<
44
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
45
+ TAccountSource extends string | AccountMeta<string> = string,
46
+ TAccountDestination extends string | AccountMeta<string> = string,
47
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
48
+ > = Instruction<TProgram> &
49
+ InstructionWithData<ReadonlyUint8Array> &
50
+ InstructionWithAccounts<
51
+ [
52
+ TAccountSource extends string
53
+ ? WritableSignerAccount<TAccountSource> & AccountSignerMeta<TAccountSource>
54
+ : TAccountSource,
55
+ TAccountDestination extends string ? WritableAccount<TAccountDestination> : TAccountDestination,
56
+ ...TRemainingAccounts,
57
+ ]
58
+ >;
59
+
60
+ export type TransferSolInstructionData = { discriminator: number; amount: bigint };
61
+
62
+ export type TransferSolInstructionDataArgs = { amount: number | bigint };
63
+
64
+ export function getTransferSolInstructionDataEncoder(): FixedSizeEncoder<TransferSolInstructionDataArgs> {
65
+ return transformEncoder(
66
+ getStructEncoder([
67
+ ['discriminator', getU32Encoder()],
68
+ ['amount', getU64Encoder()],
69
+ ]),
70
+ value => ({ ...value, discriminator: TRANSFER_SOL_DISCRIMINATOR }),
71
+ );
72
+ }
73
+
74
+ export function getTransferSolInstructionDataDecoder(): FixedSizeDecoder<TransferSolInstructionData> {
75
+ return getStructDecoder([
76
+ ['discriminator', getU32Decoder()],
77
+ ['amount', getU64Decoder()],
78
+ ]);
79
+ }
80
+
81
+ export function getTransferSolInstructionDataCodec(): FixedSizeCodec<
82
+ TransferSolInstructionDataArgs,
83
+ TransferSolInstructionData
84
+ > {
85
+ return combineCodec(getTransferSolInstructionDataEncoder(), getTransferSolInstructionDataDecoder());
86
+ }
87
+
88
+ export type TransferSolInput<TAccountSource extends string = string, TAccountDestination extends string = string> = {
89
+ source: TransactionSigner<TAccountSource>;
90
+ destination: Address<TAccountDestination>;
91
+ amount: TransferSolInstructionDataArgs['amount'];
92
+ };
93
+
94
+ export function getTransferSolInstruction<
95
+ TAccountSource extends string,
96
+ TAccountDestination extends string,
97
+ TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
98
+ >(
99
+ input: TransferSolInput<TAccountSource, TAccountDestination>,
100
+ config?: { programAddress?: TProgramAddress },
101
+ ): TransferSolInstruction<TProgramAddress, TAccountSource, TAccountDestination> {
102
+ // Program address.
103
+ const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
104
+
105
+ // Original accounts.
106
+ const originalAccounts = {
107
+ source: { value: input.source ?? null, isWritable: true },
108
+ destination: { value: input.destination ?? null, isWritable: true },
109
+ };
110
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
111
+
112
+ // Original args.
113
+ const args = { ...input };
114
+
115
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
116
+ return Object.freeze({
117
+ accounts: [getAccountMeta('source', accounts.source), getAccountMeta('destination', accounts.destination)],
118
+ data: getTransferSolInstructionDataEncoder().encode(args as TransferSolInstructionDataArgs),
119
+ programAddress,
120
+ } as TransferSolInstruction<TProgramAddress, TAccountSource, TAccountDestination>);
121
+ }
122
+
123
+ export type ParsedTransferSolInstruction<
124
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
125
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
126
+ > = {
127
+ programAddress: Address<TProgram>;
128
+ accounts: {
129
+ source: TAccountMetas[0];
130
+ destination: TAccountMetas[1];
131
+ };
132
+ data: TransferSolInstructionData;
133
+ };
134
+
135
+ export function parseTransferSolInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(
136
+ instruction: Instruction<TProgram> &
137
+ InstructionWithAccounts<TAccountMetas> &
138
+ InstructionWithData<ReadonlyUint8Array>,
139
+ ): ParsedTransferSolInstruction<TProgram, TAccountMetas> {
140
+ if (instruction.accounts.length < 2) {
141
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
142
+ actualAccountMetas: instruction.accounts.length,
143
+ expectedAccountMetas: 2,
144
+ });
145
+ }
146
+ let accountIndex = 0;
147
+ const getNextAccount = () => {
148
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
149
+ accountIndex += 1;
150
+ return accountMeta;
151
+ };
152
+ return {
153
+ programAddress: instruction.programAddress,
154
+ accounts: { source: getNextAccount(), destination: getNextAccount() },
155
+ data: getTransferSolInstructionDataDecoder().decode(instruction.data),
156
+ };
157
+ }
@@ -0,0 +1,191 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ addDecoderSizePrefix,
11
+ addEncoderSizePrefix,
12
+ combineCodec,
13
+ getAddressDecoder,
14
+ getAddressEncoder,
15
+ getStructDecoder,
16
+ getStructEncoder,
17
+ getU32Decoder,
18
+ getU32Encoder,
19
+ getU64Decoder,
20
+ getU64Encoder,
21
+ getUtf8Decoder,
22
+ getUtf8Encoder,
23
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
24
+ SolanaError,
25
+ transformEncoder,
26
+ type AccountMeta,
27
+ type AccountSignerMeta,
28
+ type Address,
29
+ type Codec,
30
+ type Decoder,
31
+ type Encoder,
32
+ type Instruction,
33
+ type InstructionWithAccounts,
34
+ type InstructionWithData,
35
+ type ReadonlySignerAccount,
36
+ type ReadonlyUint8Array,
37
+ type TransactionSigner,
38
+ type WritableAccount,
39
+ } from '@solana/kit';
40
+ import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
41
+ import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
42
+
43
+ export const TRANSFER_SOL_WITH_SEED_DISCRIMINATOR = 11;
44
+
45
+ export function getTransferSolWithSeedDiscriminatorBytes(): ReadonlyUint8Array {
46
+ return getU32Encoder().encode(TRANSFER_SOL_WITH_SEED_DISCRIMINATOR);
47
+ }
48
+
49
+ export type TransferSolWithSeedInstruction<
50
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
51
+ TAccountSource extends string | AccountMeta<string> = string,
52
+ TAccountBaseAccount extends string | AccountMeta<string> = string,
53
+ TAccountDestination extends string | AccountMeta<string> = string,
54
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
55
+ > = Instruction<TProgram> &
56
+ InstructionWithData<ReadonlyUint8Array> &
57
+ InstructionWithAccounts<
58
+ [
59
+ TAccountSource extends string ? WritableAccount<TAccountSource> : TAccountSource,
60
+ TAccountBaseAccount extends string
61
+ ? ReadonlySignerAccount<TAccountBaseAccount> & AccountSignerMeta<TAccountBaseAccount>
62
+ : TAccountBaseAccount,
63
+ TAccountDestination extends string ? WritableAccount<TAccountDestination> : TAccountDestination,
64
+ ...TRemainingAccounts,
65
+ ]
66
+ >;
67
+
68
+ export type TransferSolWithSeedInstructionData = {
69
+ discriminator: number;
70
+ amount: bigint;
71
+ fromSeed: string;
72
+ fromOwner: Address;
73
+ };
74
+
75
+ export type TransferSolWithSeedInstructionDataArgs = { amount: number | bigint; fromSeed: string; fromOwner: Address };
76
+
77
+ export function getTransferSolWithSeedInstructionDataEncoder(): Encoder<TransferSolWithSeedInstructionDataArgs> {
78
+ return transformEncoder(
79
+ getStructEncoder([
80
+ ['discriminator', getU32Encoder()],
81
+ ['amount', getU64Encoder()],
82
+ ['fromSeed', addEncoderSizePrefix(getUtf8Encoder(), getU64Encoder())],
83
+ ['fromOwner', getAddressEncoder()],
84
+ ]),
85
+ value => ({ ...value, discriminator: TRANSFER_SOL_WITH_SEED_DISCRIMINATOR }),
86
+ );
87
+ }
88
+
89
+ export function getTransferSolWithSeedInstructionDataDecoder(): Decoder<TransferSolWithSeedInstructionData> {
90
+ return getStructDecoder([
91
+ ['discriminator', getU32Decoder()],
92
+ ['amount', getU64Decoder()],
93
+ ['fromSeed', addDecoderSizePrefix(getUtf8Decoder(), getU64Decoder())],
94
+ ['fromOwner', getAddressDecoder()],
95
+ ]);
96
+ }
97
+
98
+ export function getTransferSolWithSeedInstructionDataCodec(): Codec<
99
+ TransferSolWithSeedInstructionDataArgs,
100
+ TransferSolWithSeedInstructionData
101
+ > {
102
+ return combineCodec(getTransferSolWithSeedInstructionDataEncoder(), getTransferSolWithSeedInstructionDataDecoder());
103
+ }
104
+
105
+ export type TransferSolWithSeedInput<
106
+ TAccountSource extends string = string,
107
+ TAccountBaseAccount extends string = string,
108
+ TAccountDestination extends string = string,
109
+ > = {
110
+ source: Address<TAccountSource>;
111
+ baseAccount: TransactionSigner<TAccountBaseAccount>;
112
+ destination: Address<TAccountDestination>;
113
+ amount: TransferSolWithSeedInstructionDataArgs['amount'];
114
+ fromSeed: TransferSolWithSeedInstructionDataArgs['fromSeed'];
115
+ fromOwner: TransferSolWithSeedInstructionDataArgs['fromOwner'];
116
+ };
117
+
118
+ export function getTransferSolWithSeedInstruction<
119
+ TAccountSource extends string,
120
+ TAccountBaseAccount extends string,
121
+ TAccountDestination extends string,
122
+ TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
123
+ >(
124
+ input: TransferSolWithSeedInput<TAccountSource, TAccountBaseAccount, TAccountDestination>,
125
+ config?: { programAddress?: TProgramAddress },
126
+ ): TransferSolWithSeedInstruction<TProgramAddress, TAccountSource, TAccountBaseAccount, TAccountDestination> {
127
+ // Program address.
128
+ const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
129
+
130
+ // Original accounts.
131
+ const originalAccounts = {
132
+ source: { value: input.source ?? null, isWritable: true },
133
+ baseAccount: { value: input.baseAccount ?? null, isWritable: false },
134
+ destination: { value: input.destination ?? null, isWritable: true },
135
+ };
136
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
137
+
138
+ // Original args.
139
+ const args = { ...input };
140
+
141
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
142
+ return Object.freeze({
143
+ accounts: [
144
+ getAccountMeta('source', accounts.source),
145
+ getAccountMeta('baseAccount', accounts.baseAccount),
146
+ getAccountMeta('destination', accounts.destination),
147
+ ],
148
+ data: getTransferSolWithSeedInstructionDataEncoder().encode(args as TransferSolWithSeedInstructionDataArgs),
149
+ programAddress,
150
+ } as TransferSolWithSeedInstruction<TProgramAddress, TAccountSource, TAccountBaseAccount, TAccountDestination>);
151
+ }
152
+
153
+ export type ParsedTransferSolWithSeedInstruction<
154
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
155
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
156
+ > = {
157
+ programAddress: Address<TProgram>;
158
+ accounts: {
159
+ source: TAccountMetas[0];
160
+ baseAccount: TAccountMetas[1];
161
+ destination: TAccountMetas[2];
162
+ };
163
+ data: TransferSolWithSeedInstructionData;
164
+ };
165
+
166
+ export function parseTransferSolWithSeedInstruction<
167
+ TProgram extends string,
168
+ TAccountMetas extends readonly AccountMeta[],
169
+ >(
170
+ instruction: Instruction<TProgram> &
171
+ InstructionWithAccounts<TAccountMetas> &
172
+ InstructionWithData<ReadonlyUint8Array>,
173
+ ): ParsedTransferSolWithSeedInstruction<TProgram, TAccountMetas> {
174
+ if (instruction.accounts.length < 3) {
175
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
176
+ actualAccountMetas: instruction.accounts.length,
177
+ expectedAccountMetas: 3,
178
+ });
179
+ }
180
+ let accountIndex = 0;
181
+ const getNextAccount = () => {
182
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
183
+ accountIndex += 1;
184
+ return accountMeta;
185
+ };
186
+ return {
187
+ programAddress: instruction.programAddress,
188
+ accounts: { source: getNextAccount(), baseAccount: getNextAccount(), destination: getNextAccount() },
189
+ data: getTransferSolWithSeedInstructionDataDecoder().decode(instruction.data),
190
+ };
191
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ combineCodec,
11
+ getStructDecoder,
12
+ getStructEncoder,
13
+ getU32Decoder,
14
+ getU32Encoder,
15
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
16
+ SolanaError,
17
+ transformEncoder,
18
+ type AccountMeta,
19
+ type Address,
20
+ type FixedSizeCodec,
21
+ type FixedSizeDecoder,
22
+ type FixedSizeEncoder,
23
+ type Instruction,
24
+ type InstructionWithAccounts,
25
+ type InstructionWithData,
26
+ type ReadonlyUint8Array,
27
+ type WritableAccount,
28
+ } from '@solana/kit';
29
+ import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
30
+ import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
31
+
32
+ export const UPGRADE_NONCE_ACCOUNT_DISCRIMINATOR = 12;
33
+
34
+ export function getUpgradeNonceAccountDiscriminatorBytes(): ReadonlyUint8Array {
35
+ return getU32Encoder().encode(UPGRADE_NONCE_ACCOUNT_DISCRIMINATOR);
36
+ }
37
+
38
+ export type UpgradeNonceAccountInstruction<
39
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
40
+ TAccountNonceAccount extends string | AccountMeta<string> = string,
41
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
42
+ > = Instruction<TProgram> &
43
+ InstructionWithData<ReadonlyUint8Array> &
44
+ InstructionWithAccounts<
45
+ [
46
+ TAccountNonceAccount extends string ? WritableAccount<TAccountNonceAccount> : TAccountNonceAccount,
47
+ ...TRemainingAccounts,
48
+ ]
49
+ >;
50
+
51
+ export type UpgradeNonceAccountInstructionData = { discriminator: number };
52
+
53
+ export type UpgradeNonceAccountInstructionDataArgs = {};
54
+
55
+ export function getUpgradeNonceAccountInstructionDataEncoder(): FixedSizeEncoder<UpgradeNonceAccountInstructionDataArgs> {
56
+ return transformEncoder(getStructEncoder([['discriminator', getU32Encoder()]]), value => ({
57
+ ...value,
58
+ discriminator: UPGRADE_NONCE_ACCOUNT_DISCRIMINATOR,
59
+ }));
60
+ }
61
+
62
+ export function getUpgradeNonceAccountInstructionDataDecoder(): FixedSizeDecoder<UpgradeNonceAccountInstructionData> {
63
+ return getStructDecoder([['discriminator', getU32Decoder()]]);
64
+ }
65
+
66
+ export function getUpgradeNonceAccountInstructionDataCodec(): FixedSizeCodec<
67
+ UpgradeNonceAccountInstructionDataArgs,
68
+ UpgradeNonceAccountInstructionData
69
+ > {
70
+ return combineCodec(getUpgradeNonceAccountInstructionDataEncoder(), getUpgradeNonceAccountInstructionDataDecoder());
71
+ }
72
+
73
+ export type UpgradeNonceAccountInput<TAccountNonceAccount extends string = string> = {
74
+ nonceAccount: Address<TAccountNonceAccount>;
75
+ };
76
+
77
+ export function getUpgradeNonceAccountInstruction<
78
+ TAccountNonceAccount extends string,
79
+ TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
80
+ >(
81
+ input: UpgradeNonceAccountInput<TAccountNonceAccount>,
82
+ config?: { programAddress?: TProgramAddress },
83
+ ): UpgradeNonceAccountInstruction<TProgramAddress, TAccountNonceAccount> {
84
+ // Program address.
85
+ const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
86
+
87
+ // Original accounts.
88
+ const originalAccounts = { nonceAccount: { value: input.nonceAccount ?? null, isWritable: true } };
89
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
90
+
91
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
92
+ return Object.freeze({
93
+ accounts: [getAccountMeta('nonceAccount', accounts.nonceAccount)],
94
+ data: getUpgradeNonceAccountInstructionDataEncoder().encode({}),
95
+ programAddress,
96
+ } as UpgradeNonceAccountInstruction<TProgramAddress, TAccountNonceAccount>);
97
+ }
98
+
99
+ export type ParsedUpgradeNonceAccountInstruction<
100
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
101
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
102
+ > = {
103
+ programAddress: Address<TProgram>;
104
+ accounts: {
105
+ nonceAccount: TAccountMetas[0];
106
+ };
107
+ data: UpgradeNonceAccountInstructionData;
108
+ };
109
+
110
+ export function parseUpgradeNonceAccountInstruction<
111
+ TProgram extends string,
112
+ TAccountMetas extends readonly AccountMeta[],
113
+ >(
114
+ instruction: Instruction<TProgram> &
115
+ InstructionWithAccounts<TAccountMetas> &
116
+ InstructionWithData<ReadonlyUint8Array>,
117
+ ): ParsedUpgradeNonceAccountInstruction<TProgram, TAccountMetas> {
118
+ if (instruction.accounts.length < 1) {
119
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
120
+ actualAccountMetas: instruction.accounts.length,
121
+ expectedAccountMetas: 1,
122
+ });
123
+ }
124
+ let accountIndex = 0;
125
+ const getNextAccount = () => {
126
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
127
+ accountIndex += 1;
128
+ return accountMeta;
129
+ };
130
+ return {
131
+ programAddress: instruction.programAddress,
132
+ accounts: { nonceAccount: getNextAccount() },
133
+ data: getUpgradeNonceAccountInstructionDataDecoder().decode(instruction.data),
134
+ };
135
+ }