@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,184 @@
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
+ BASE_ACCOUNT_SIZE,
11
+ combineCodec,
12
+ getAddressDecoder,
13
+ getAddressEncoder,
14
+ getStructDecoder,
15
+ getStructEncoder,
16
+ getU32Decoder,
17
+ getU32Encoder,
18
+ getU64Decoder,
19
+ getU64Encoder,
20
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
21
+ SolanaError,
22
+ transformEncoder,
23
+ type AccountMeta,
24
+ type AccountSignerMeta,
25
+ type Address,
26
+ type FixedSizeCodec,
27
+ type FixedSizeDecoder,
28
+ type FixedSizeEncoder,
29
+ type Instruction,
30
+ type InstructionWithAccounts,
31
+ type InstructionWithData,
32
+ type ReadonlyUint8Array,
33
+ type TransactionSigner,
34
+ type WritableSignerAccount,
35
+ } from '@solana/kit';
36
+ import {
37
+ getAccountMetaFactory,
38
+ type InstructionWithByteDelta,
39
+ type ResolvedInstructionAccount,
40
+ } from '@solana/kit/program-client-core';
41
+ import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
42
+
43
+ export const CREATE_ACCOUNT_DISCRIMINATOR = 0;
44
+
45
+ export function getCreateAccountDiscriminatorBytes(): ReadonlyUint8Array {
46
+ return getU32Encoder().encode(CREATE_ACCOUNT_DISCRIMINATOR);
47
+ }
48
+
49
+ export type CreateAccountInstruction<
50
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
51
+ TAccountPayer extends string | AccountMeta<string> = string,
52
+ TAccountNewAccount extends string | AccountMeta<string> = string,
53
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
54
+ > = Instruction<TProgram> &
55
+ InstructionWithData<ReadonlyUint8Array> &
56
+ InstructionWithAccounts<
57
+ [
58
+ TAccountPayer extends string
59
+ ? WritableSignerAccount<TAccountPayer> & AccountSignerMeta<TAccountPayer>
60
+ : TAccountPayer,
61
+ TAccountNewAccount extends string
62
+ ? WritableSignerAccount<TAccountNewAccount> & AccountSignerMeta<TAccountNewAccount>
63
+ : TAccountNewAccount,
64
+ ...TRemainingAccounts,
65
+ ]
66
+ >;
67
+
68
+ export type CreateAccountInstructionData = {
69
+ discriminator: number;
70
+ lamports: bigint;
71
+ space: bigint;
72
+ programAddress: Address;
73
+ };
74
+
75
+ export type CreateAccountInstructionDataArgs = {
76
+ lamports: number | bigint;
77
+ space: number | bigint;
78
+ programAddress: Address;
79
+ };
80
+
81
+ export function getCreateAccountInstructionDataEncoder(): FixedSizeEncoder<CreateAccountInstructionDataArgs> {
82
+ return transformEncoder(
83
+ getStructEncoder([
84
+ ['discriminator', getU32Encoder()],
85
+ ['lamports', getU64Encoder()],
86
+ ['space', getU64Encoder()],
87
+ ['programAddress', getAddressEncoder()],
88
+ ]),
89
+ value => ({ ...value, discriminator: CREATE_ACCOUNT_DISCRIMINATOR }),
90
+ );
91
+ }
92
+
93
+ export function getCreateAccountInstructionDataDecoder(): FixedSizeDecoder<CreateAccountInstructionData> {
94
+ return getStructDecoder([
95
+ ['discriminator', getU32Decoder()],
96
+ ['lamports', getU64Decoder()],
97
+ ['space', getU64Decoder()],
98
+ ['programAddress', getAddressDecoder()],
99
+ ]);
100
+ }
101
+
102
+ export function getCreateAccountInstructionDataCodec(): FixedSizeCodec<
103
+ CreateAccountInstructionDataArgs,
104
+ CreateAccountInstructionData
105
+ > {
106
+ return combineCodec(getCreateAccountInstructionDataEncoder(), getCreateAccountInstructionDataDecoder());
107
+ }
108
+
109
+ export type CreateAccountInput<TAccountPayer extends string = string, TAccountNewAccount extends string = string> = {
110
+ payer: TransactionSigner<TAccountPayer>;
111
+ newAccount: TransactionSigner<TAccountNewAccount>;
112
+ lamports: CreateAccountInstructionDataArgs['lamports'];
113
+ space: CreateAccountInstructionDataArgs['space'];
114
+ programAddress: CreateAccountInstructionDataArgs['programAddress'];
115
+ };
116
+
117
+ export function getCreateAccountInstruction<
118
+ TAccountPayer extends string,
119
+ TAccountNewAccount extends string,
120
+ TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
121
+ >(
122
+ input: CreateAccountInput<TAccountPayer, TAccountNewAccount>,
123
+ config?: { programAddress?: TProgramAddress },
124
+ ): CreateAccountInstruction<TProgramAddress, TAccountPayer, TAccountNewAccount> & InstructionWithByteDelta {
125
+ // Program address.
126
+ const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
127
+
128
+ // Original accounts.
129
+ const originalAccounts = {
130
+ payer: { value: input.payer ?? null, isWritable: true },
131
+ newAccount: { value: input.newAccount ?? null, isWritable: true },
132
+ };
133
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
134
+
135
+ // Original args.
136
+ const args = { ...input };
137
+
138
+ // Bytes created or reallocated by the instruction.
139
+ const byteDelta: number = [Number(args.space) + BASE_ACCOUNT_SIZE].reduce((a, b) => a + b, 0);
140
+
141
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
142
+ return Object.freeze({
143
+ accounts: [getAccountMeta('payer', accounts.payer), getAccountMeta('newAccount', accounts.newAccount)],
144
+ byteDelta,
145
+ data: getCreateAccountInstructionDataEncoder().encode(args as CreateAccountInstructionDataArgs),
146
+ programAddress,
147
+ } as CreateAccountInstruction<TProgramAddress, TAccountPayer, TAccountNewAccount> & InstructionWithByteDelta);
148
+ }
149
+
150
+ export type ParsedCreateAccountInstruction<
151
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
152
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
153
+ > = {
154
+ programAddress: Address<TProgram>;
155
+ accounts: {
156
+ payer: TAccountMetas[0];
157
+ newAccount: TAccountMetas[1];
158
+ };
159
+ data: CreateAccountInstructionData;
160
+ };
161
+
162
+ export function parseCreateAccountInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(
163
+ instruction: Instruction<TProgram> &
164
+ InstructionWithAccounts<TAccountMetas> &
165
+ InstructionWithData<ReadonlyUint8Array>,
166
+ ): ParsedCreateAccountInstruction<TProgram, TAccountMetas> {
167
+ if (instruction.accounts.length < 2) {
168
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
169
+ actualAccountMetas: instruction.accounts.length,
170
+ expectedAccountMetas: 2,
171
+ });
172
+ }
173
+ let accountIndex = 0;
174
+ const getNextAccount = () => {
175
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
176
+ accountIndex += 1;
177
+ return accountMeta;
178
+ };
179
+ return {
180
+ programAddress: instruction.programAddress,
181
+ accounts: { payer: getNextAccount(), newAccount: getNextAccount() },
182
+ data: getCreateAccountInstructionDataDecoder().decode(instruction.data),
183
+ };
184
+ }
@@ -0,0 +1,221 @@
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
+ type WritableSignerAccount,
40
+ } from '@solana/kit';
41
+ import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
42
+ import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
43
+
44
+ export const CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR = 3;
45
+
46
+ export function getCreateAccountWithSeedDiscriminatorBytes(): ReadonlyUint8Array {
47
+ return getU32Encoder().encode(CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR);
48
+ }
49
+
50
+ export type CreateAccountWithSeedInstruction<
51
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
52
+ TAccountPayer extends string | AccountMeta<string> = string,
53
+ TAccountNewAccount extends string | AccountMeta<string> = string,
54
+ TAccountBaseAccount extends string | AccountMeta<string> | undefined = undefined,
55
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
56
+ > = Instruction<TProgram> &
57
+ InstructionWithData<ReadonlyUint8Array> &
58
+ InstructionWithAccounts<
59
+ [
60
+ TAccountPayer extends string
61
+ ? WritableSignerAccount<TAccountPayer> & AccountSignerMeta<TAccountPayer>
62
+ : TAccountPayer,
63
+ TAccountNewAccount extends string ? WritableAccount<TAccountNewAccount> : TAccountNewAccount,
64
+ ...(TAccountBaseAccount extends undefined
65
+ ? []
66
+ : [
67
+ TAccountBaseAccount extends string
68
+ ? ReadonlySignerAccount<TAccountBaseAccount> & AccountSignerMeta<TAccountBaseAccount>
69
+ : TAccountBaseAccount,
70
+ ]),
71
+ ...TRemainingAccounts,
72
+ ]
73
+ >;
74
+
75
+ export type CreateAccountWithSeedInstructionData = {
76
+ discriminator: number;
77
+ base: Address;
78
+ seed: string;
79
+ amount: bigint;
80
+ space: bigint;
81
+ programAddress: Address;
82
+ };
83
+
84
+ export type CreateAccountWithSeedInstructionDataArgs = {
85
+ base: Address;
86
+ seed: string;
87
+ amount: number | bigint;
88
+ space: number | bigint;
89
+ programAddress: Address;
90
+ };
91
+
92
+ export function getCreateAccountWithSeedInstructionDataEncoder(): Encoder<CreateAccountWithSeedInstructionDataArgs> {
93
+ return transformEncoder(
94
+ getStructEncoder([
95
+ ['discriminator', getU32Encoder()],
96
+ ['base', getAddressEncoder()],
97
+ ['seed', addEncoderSizePrefix(getUtf8Encoder(), getU64Encoder())],
98
+ ['amount', getU64Encoder()],
99
+ ['space', getU64Encoder()],
100
+ ['programAddress', getAddressEncoder()],
101
+ ]),
102
+ value => ({ ...value, discriminator: CREATE_ACCOUNT_WITH_SEED_DISCRIMINATOR }),
103
+ );
104
+ }
105
+
106
+ export function getCreateAccountWithSeedInstructionDataDecoder(): Decoder<CreateAccountWithSeedInstructionData> {
107
+ return getStructDecoder([
108
+ ['discriminator', getU32Decoder()],
109
+ ['base', getAddressDecoder()],
110
+ ['seed', addDecoderSizePrefix(getUtf8Decoder(), getU64Decoder())],
111
+ ['amount', getU64Decoder()],
112
+ ['space', getU64Decoder()],
113
+ ['programAddress', getAddressDecoder()],
114
+ ]);
115
+ }
116
+
117
+ export function getCreateAccountWithSeedInstructionDataCodec(): Codec<
118
+ CreateAccountWithSeedInstructionDataArgs,
119
+ CreateAccountWithSeedInstructionData
120
+ > {
121
+ return combineCodec(
122
+ getCreateAccountWithSeedInstructionDataEncoder(),
123
+ getCreateAccountWithSeedInstructionDataDecoder(),
124
+ );
125
+ }
126
+
127
+ export type CreateAccountWithSeedInput<
128
+ TAccountPayer extends string = string,
129
+ TAccountNewAccount extends string = string,
130
+ TAccountBaseAccount extends string = string,
131
+ > = {
132
+ payer: TransactionSigner<TAccountPayer>;
133
+ newAccount: Address<TAccountNewAccount>;
134
+ baseAccount?: TransactionSigner<TAccountBaseAccount>;
135
+ base: CreateAccountWithSeedInstructionDataArgs['base'];
136
+ seed: CreateAccountWithSeedInstructionDataArgs['seed'];
137
+ amount: CreateAccountWithSeedInstructionDataArgs['amount'];
138
+ space: CreateAccountWithSeedInstructionDataArgs['space'];
139
+ programAddress: CreateAccountWithSeedInstructionDataArgs['programAddress'];
140
+ };
141
+
142
+ export function getCreateAccountWithSeedInstruction<
143
+ TAccountPayer extends string,
144
+ TAccountNewAccount extends string,
145
+ TAccountBaseAccount extends string,
146
+ TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
147
+ >(
148
+ input: CreateAccountWithSeedInput<TAccountPayer, TAccountNewAccount, TAccountBaseAccount>,
149
+ config?: { programAddress?: TProgramAddress },
150
+ ): CreateAccountWithSeedInstruction<TProgramAddress, TAccountPayer, TAccountNewAccount, TAccountBaseAccount> {
151
+ // Program address.
152
+ const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
153
+
154
+ // Original accounts.
155
+ const originalAccounts = {
156
+ payer: { value: input.payer ?? null, isWritable: true },
157
+ newAccount: { value: input.newAccount ?? null, isWritable: true },
158
+ baseAccount: { value: input.baseAccount ?? null, isWritable: false },
159
+ };
160
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
161
+
162
+ // Original args.
163
+ const args = { ...input };
164
+
165
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
166
+ return Object.freeze({
167
+ accounts: [
168
+ getAccountMeta('payer', accounts.payer),
169
+ getAccountMeta('newAccount', accounts.newAccount),
170
+ getAccountMeta('baseAccount', accounts.baseAccount),
171
+ ].filter(<T>(x: T | undefined): x is T => x !== undefined),
172
+ data: getCreateAccountWithSeedInstructionDataEncoder().encode(args as CreateAccountWithSeedInstructionDataArgs),
173
+ programAddress,
174
+ } as CreateAccountWithSeedInstruction<TProgramAddress, TAccountPayer, TAccountNewAccount, TAccountBaseAccount>);
175
+ }
176
+
177
+ export type ParsedCreateAccountWithSeedInstruction<
178
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
179
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
180
+ > = {
181
+ programAddress: Address<TProgram>;
182
+ accounts: {
183
+ payer: TAccountMetas[0];
184
+ newAccount: TAccountMetas[1];
185
+ baseAccount?: TAccountMetas[2] | undefined;
186
+ };
187
+ data: CreateAccountWithSeedInstructionData;
188
+ };
189
+
190
+ export function parseCreateAccountWithSeedInstruction<
191
+ TProgram extends string,
192
+ TAccountMetas extends readonly AccountMeta[],
193
+ >(
194
+ instruction: Instruction<TProgram> &
195
+ InstructionWithAccounts<TAccountMetas> &
196
+ InstructionWithData<ReadonlyUint8Array>,
197
+ ): ParsedCreateAccountWithSeedInstruction<TProgram, TAccountMetas> {
198
+ if (instruction.accounts.length < 2) {
199
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
200
+ actualAccountMetas: instruction.accounts.length,
201
+ expectedAccountMetas: 2,
202
+ });
203
+ }
204
+ let accountIndex = 0;
205
+ const getNextAccount = () => {
206
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
207
+ accountIndex += 1;
208
+ return accountMeta;
209
+ };
210
+ let optionalAccountsRemaining = instruction.accounts.length - 2;
211
+ const getNextOptionalAccount = () => {
212
+ if (optionalAccountsRemaining === 0) return undefined;
213
+ optionalAccountsRemaining -= 1;
214
+ return getNextAccount();
215
+ };
216
+ return {
217
+ programAddress: instruction.programAddress,
218
+ accounts: { payer: getNextAccount(), newAccount: getNextAccount(), baseAccount: getNextOptionalAccount() },
219
+ data: getCreateAccountWithSeedInstructionDataDecoder().decode(instruction.data),
220
+ };
221
+ }
@@ -0,0 +1,21 @@
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
+ export * from './advanceNonceAccount';
10
+ export * from './allocate';
11
+ export * from './allocateWithSeed';
12
+ export * from './assign';
13
+ export * from './assignWithSeed';
14
+ export * from './authorizeNonceAccount';
15
+ export * from './createAccount';
16
+ export * from './createAccountWithSeed';
17
+ export * from './initializeNonceAccount';
18
+ export * from './transferSol';
19
+ export * from './transferSolWithSeed';
20
+ export * from './upgradeNonceAccount';
21
+ export * from './withdrawNonceAccount';
@@ -0,0 +1,202 @@
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
+ getAddressDecoder,
12
+ getAddressEncoder,
13
+ getStructDecoder,
14
+ getStructEncoder,
15
+ getU32Decoder,
16
+ getU32Encoder,
17
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
18
+ SolanaError,
19
+ transformEncoder,
20
+ type AccountMeta,
21
+ type Address,
22
+ type FixedSizeCodec,
23
+ type FixedSizeDecoder,
24
+ type FixedSizeEncoder,
25
+ type Instruction,
26
+ type InstructionWithAccounts,
27
+ type InstructionWithData,
28
+ type ReadonlyAccount,
29
+ type ReadonlyUint8Array,
30
+ type WritableAccount,
31
+ } from '@solana/kit';
32
+ import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
33
+ import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
34
+
35
+ export const INITIALIZE_NONCE_ACCOUNT_DISCRIMINATOR = 6;
36
+
37
+ export function getInitializeNonceAccountDiscriminatorBytes(): ReadonlyUint8Array {
38
+ return getU32Encoder().encode(INITIALIZE_NONCE_ACCOUNT_DISCRIMINATOR);
39
+ }
40
+
41
+ export type InitializeNonceAccountInstruction<
42
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
43
+ TAccountNonceAccount extends string | AccountMeta<string> = string,
44
+ TAccountRecentBlockhashesSysvar extends string | AccountMeta<string> =
45
+ 'SysvarRecentB1ockHashes11111111111111111111',
46
+ TAccountRentSysvar extends string | AccountMeta<string> = 'SysvarRent111111111111111111111111111111111',
47
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
48
+ > = Instruction<TProgram> &
49
+ InstructionWithData<ReadonlyUint8Array> &
50
+ InstructionWithAccounts<
51
+ [
52
+ TAccountNonceAccount extends string ? WritableAccount<TAccountNonceAccount> : TAccountNonceAccount,
53
+ TAccountRecentBlockhashesSysvar extends string
54
+ ? ReadonlyAccount<TAccountRecentBlockhashesSysvar>
55
+ : TAccountRecentBlockhashesSysvar,
56
+ TAccountRentSysvar extends string ? ReadonlyAccount<TAccountRentSysvar> : TAccountRentSysvar,
57
+ ...TRemainingAccounts,
58
+ ]
59
+ >;
60
+
61
+ export type InitializeNonceAccountInstructionData = { discriminator: number; nonceAuthority: Address };
62
+
63
+ export type InitializeNonceAccountInstructionDataArgs = { nonceAuthority: Address };
64
+
65
+ export function getInitializeNonceAccountInstructionDataEncoder(): FixedSizeEncoder<InitializeNonceAccountInstructionDataArgs> {
66
+ return transformEncoder(
67
+ getStructEncoder([
68
+ ['discriminator', getU32Encoder()],
69
+ ['nonceAuthority', getAddressEncoder()],
70
+ ]),
71
+ value => ({ ...value, discriminator: INITIALIZE_NONCE_ACCOUNT_DISCRIMINATOR }),
72
+ );
73
+ }
74
+
75
+ export function getInitializeNonceAccountInstructionDataDecoder(): FixedSizeDecoder<InitializeNonceAccountInstructionData> {
76
+ return getStructDecoder([
77
+ ['discriminator', getU32Decoder()],
78
+ ['nonceAuthority', getAddressDecoder()],
79
+ ]);
80
+ }
81
+
82
+ export function getInitializeNonceAccountInstructionDataCodec(): FixedSizeCodec<
83
+ InitializeNonceAccountInstructionDataArgs,
84
+ InitializeNonceAccountInstructionData
85
+ > {
86
+ return combineCodec(
87
+ getInitializeNonceAccountInstructionDataEncoder(),
88
+ getInitializeNonceAccountInstructionDataDecoder(),
89
+ );
90
+ }
91
+
92
+ export type InitializeNonceAccountInput<
93
+ TAccountNonceAccount extends string = string,
94
+ TAccountRecentBlockhashesSysvar extends string = string,
95
+ TAccountRentSysvar extends string = string,
96
+ > = {
97
+ nonceAccount: Address<TAccountNonceAccount>;
98
+ recentBlockhashesSysvar?: Address<TAccountRecentBlockhashesSysvar>;
99
+ rentSysvar?: Address<TAccountRentSysvar>;
100
+ nonceAuthority: InitializeNonceAccountInstructionDataArgs['nonceAuthority'];
101
+ };
102
+
103
+ export function getInitializeNonceAccountInstruction<
104
+ TAccountNonceAccount extends string,
105
+ TAccountRecentBlockhashesSysvar extends string,
106
+ TAccountRentSysvar extends string,
107
+ TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
108
+ >(
109
+ input: InitializeNonceAccountInput<TAccountNonceAccount, TAccountRecentBlockhashesSysvar, TAccountRentSysvar>,
110
+ config?: { programAddress?: TProgramAddress },
111
+ ): InitializeNonceAccountInstruction<
112
+ TProgramAddress,
113
+ TAccountNonceAccount,
114
+ TAccountRecentBlockhashesSysvar,
115
+ TAccountRentSysvar
116
+ > {
117
+ // Program address.
118
+ const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
119
+
120
+ // Original accounts.
121
+ const originalAccounts = {
122
+ nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
123
+ recentBlockhashesSysvar: { value: input.recentBlockhashesSysvar ?? null, isWritable: false },
124
+ rentSysvar: { value: input.rentSysvar ?? null, isWritable: false },
125
+ };
126
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
127
+
128
+ // Original args.
129
+ const args = { ...input };
130
+
131
+ // Resolve default values.
132
+ if (!accounts.recentBlockhashesSysvar.value) {
133
+ accounts.recentBlockhashesSysvar.value =
134
+ 'SysvarRecentB1ockHashes11111111111111111111' as Address<'SysvarRecentB1ockHashes11111111111111111111'>;
135
+ }
136
+ if (!accounts.rentSysvar.value) {
137
+ accounts.rentSysvar.value =
138
+ 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>;
139
+ }
140
+
141
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
142
+ return Object.freeze({
143
+ accounts: [
144
+ getAccountMeta('nonceAccount', accounts.nonceAccount),
145
+ getAccountMeta('recentBlockhashesSysvar', accounts.recentBlockhashesSysvar),
146
+ getAccountMeta('rentSysvar', accounts.rentSysvar),
147
+ ],
148
+ data: getInitializeNonceAccountInstructionDataEncoder().encode(
149
+ args as InitializeNonceAccountInstructionDataArgs,
150
+ ),
151
+ programAddress,
152
+ } as InitializeNonceAccountInstruction<
153
+ TProgramAddress,
154
+ TAccountNonceAccount,
155
+ TAccountRecentBlockhashesSysvar,
156
+ TAccountRentSysvar
157
+ >);
158
+ }
159
+
160
+ export type ParsedInitializeNonceAccountInstruction<
161
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
162
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
163
+ > = {
164
+ programAddress: Address<TProgram>;
165
+ accounts: {
166
+ nonceAccount: TAccountMetas[0];
167
+ recentBlockhashesSysvar: TAccountMetas[1];
168
+ rentSysvar: TAccountMetas[2];
169
+ };
170
+ data: InitializeNonceAccountInstructionData;
171
+ };
172
+
173
+ export function parseInitializeNonceAccountInstruction<
174
+ TProgram extends string,
175
+ TAccountMetas extends readonly AccountMeta[],
176
+ >(
177
+ instruction: Instruction<TProgram> &
178
+ InstructionWithAccounts<TAccountMetas> &
179
+ InstructionWithData<ReadonlyUint8Array>,
180
+ ): ParsedInitializeNonceAccountInstruction<TProgram, TAccountMetas> {
181
+ if (instruction.accounts.length < 3) {
182
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
183
+ actualAccountMetas: instruction.accounts.length,
184
+ expectedAccountMetas: 3,
185
+ });
186
+ }
187
+ let accountIndex = 0;
188
+ const getNextAccount = () => {
189
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
190
+ accountIndex += 1;
191
+ return accountMeta;
192
+ };
193
+ return {
194
+ programAddress: instruction.programAddress,
195
+ accounts: {
196
+ nonceAccount: getNextAccount(),
197
+ recentBlockhashesSysvar: getNextAccount(),
198
+ rentSysvar: getNextAccount(),
199
+ },
200
+ data: getInitializeNonceAccountInstructionDataDecoder().decode(instruction.data),
201
+ };
202
+ }