@solana-program/system 0.12.0 → 0.12.2

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 (64) hide show
  1. package/README.md +7 -9
  2. package/dist/src/index.js +103 -6
  3. package/dist/src/index.js.map +1 -1
  4. package/dist/src/index.mjs +98 -8
  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/createAccountAllowPrefund.d.ts +53 -0
  21. package/dist/types/generated/instructions/createAccountAllowPrefund.d.ts.map +1 -0
  22. package/dist/types/generated/instructions/createAccountWithSeed.d.ts +1 -1
  23. package/dist/types/generated/instructions/createAccountWithSeed.d.ts.map +1 -1
  24. package/dist/types/generated/instructions/index.d.ts +1 -0
  25. package/dist/types/generated/instructions/index.d.ts.map +1 -1
  26. package/dist/types/generated/instructions/initializeNonceAccount.d.ts +1 -1
  27. package/dist/types/generated/instructions/initializeNonceAccount.d.ts.map +1 -1
  28. package/dist/types/generated/instructions/transferSol.d.ts +1 -1
  29. package/dist/types/generated/instructions/transferSol.d.ts.map +1 -1
  30. package/dist/types/generated/instructions/transferSolWithSeed.d.ts +1 -1
  31. package/dist/types/generated/instructions/transferSolWithSeed.d.ts.map +1 -1
  32. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts +1 -1
  33. package/dist/types/generated/instructions/upgradeNonceAccount.d.ts.map +1 -1
  34. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts +1 -1
  35. package/dist/types/generated/instructions/withdrawNonceAccount.d.ts.map +1 -1
  36. package/dist/types/generated/programs/system.d.ts +8 -4
  37. package/dist/types/generated/programs/system.d.ts.map +1 -1
  38. package/package.json +31 -28
  39. package/src/generated/accounts/index.ts +9 -0
  40. package/src/generated/accounts/nonce.ts +139 -0
  41. package/src/generated/errors/index.ts +9 -0
  42. package/src/generated/errors/system.ts +77 -0
  43. package/src/generated/index.ts +13 -0
  44. package/src/generated/instructions/advanceNonceAccount.ts +186 -0
  45. package/src/generated/instructions/allocate.ts +148 -0
  46. package/src/generated/instructions/allocateWithSeed.ts +189 -0
  47. package/src/generated/instructions/assign.ts +145 -0
  48. package/src/generated/instructions/assignWithSeed.ts +177 -0
  49. package/src/generated/instructions/authorizeNonceAccount.ts +169 -0
  50. package/src/generated/instructions/createAccount.ts +184 -0
  51. package/src/generated/instructions/createAccountAllowPrefund.ts +212 -0
  52. package/src/generated/instructions/createAccountWithSeed.ts +221 -0
  53. package/src/generated/instructions/index.ts +22 -0
  54. package/src/generated/instructions/initializeNonceAccount.ts +202 -0
  55. package/src/generated/instructions/transferSol.ts +157 -0
  56. package/src/generated/instructions/transferSolWithSeed.ts +191 -0
  57. package/src/generated/instructions/upgradeNonceAccount.ts +135 -0
  58. package/src/generated/instructions/withdrawNonceAccount.ts +235 -0
  59. package/src/generated/programs/index.ts +9 -0
  60. package/src/generated/programs/system.ts +378 -0
  61. package/src/generated/types/index.ts +10 -0
  62. package/src/generated/types/nonceState.ts +37 -0
  63. package/src/generated/types/nonceVersion.ts +37 -0
  64. 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,212 @@
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_ALLOW_PREFUND_DISCRIMINATOR = 13;
44
+
45
+ export function getCreateAccountAllowPrefundDiscriminatorBytes(): ReadonlyUint8Array {
46
+ return getU32Encoder().encode(CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR);
47
+ }
48
+
49
+ export type CreateAccountAllowPrefundInstruction<
50
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
51
+ TAccountNewAccount extends string | AccountMeta<string> = string,
52
+ TAccountPayer extends string | AccountMeta<string> | undefined = undefined,
53
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
54
+ > = Instruction<TProgram> &
55
+ InstructionWithData<ReadonlyUint8Array> &
56
+ InstructionWithAccounts<
57
+ [
58
+ TAccountNewAccount extends string
59
+ ? WritableSignerAccount<TAccountNewAccount> & AccountSignerMeta<TAccountNewAccount>
60
+ : TAccountNewAccount,
61
+ ...(TAccountPayer extends undefined
62
+ ? []
63
+ : [
64
+ TAccountPayer extends string
65
+ ? WritableSignerAccount<TAccountPayer> & AccountSignerMeta<TAccountPayer>
66
+ : TAccountPayer,
67
+ ]),
68
+ ...TRemainingAccounts,
69
+ ]
70
+ >;
71
+
72
+ export type CreateAccountAllowPrefundInstructionData = {
73
+ discriminator: number;
74
+ lamports: bigint;
75
+ space: bigint;
76
+ programAddress: Address;
77
+ };
78
+
79
+ export type CreateAccountAllowPrefundInstructionDataArgs = {
80
+ lamports?: number | bigint;
81
+ space: number | bigint;
82
+ programAddress: Address;
83
+ };
84
+
85
+ export function getCreateAccountAllowPrefundInstructionDataEncoder(): FixedSizeEncoder<CreateAccountAllowPrefundInstructionDataArgs> {
86
+ return transformEncoder(
87
+ getStructEncoder([
88
+ ['discriminator', getU32Encoder()],
89
+ ['lamports', getU64Encoder()],
90
+ ['space', getU64Encoder()],
91
+ ['programAddress', getAddressEncoder()],
92
+ ]),
93
+ value => ({
94
+ ...value,
95
+ discriminator: CREATE_ACCOUNT_ALLOW_PREFUND_DISCRIMINATOR,
96
+ lamports: value.lamports ?? 0,
97
+ }),
98
+ );
99
+ }
100
+
101
+ export function getCreateAccountAllowPrefundInstructionDataDecoder(): FixedSizeDecoder<CreateAccountAllowPrefundInstructionData> {
102
+ return getStructDecoder([
103
+ ['discriminator', getU32Decoder()],
104
+ ['lamports', getU64Decoder()],
105
+ ['space', getU64Decoder()],
106
+ ['programAddress', getAddressDecoder()],
107
+ ]);
108
+ }
109
+
110
+ export function getCreateAccountAllowPrefundInstructionDataCodec(): FixedSizeCodec<
111
+ CreateAccountAllowPrefundInstructionDataArgs,
112
+ CreateAccountAllowPrefundInstructionData
113
+ > {
114
+ return combineCodec(
115
+ getCreateAccountAllowPrefundInstructionDataEncoder(),
116
+ getCreateAccountAllowPrefundInstructionDataDecoder(),
117
+ );
118
+ }
119
+
120
+ export type CreateAccountAllowPrefundInput<
121
+ TAccountNewAccount extends string = string,
122
+ TAccountPayer extends string = string,
123
+ > = {
124
+ newAccount: TransactionSigner<TAccountNewAccount>;
125
+ payer?: TransactionSigner<TAccountPayer>;
126
+ lamports?: CreateAccountAllowPrefundInstructionDataArgs['lamports'];
127
+ space: CreateAccountAllowPrefundInstructionDataArgs['space'];
128
+ programAddress: CreateAccountAllowPrefundInstructionDataArgs['programAddress'];
129
+ };
130
+
131
+ export function getCreateAccountAllowPrefundInstruction<
132
+ TAccountNewAccount extends string,
133
+ TAccountPayer extends string,
134
+ TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
135
+ >(
136
+ input: CreateAccountAllowPrefundInput<TAccountNewAccount, TAccountPayer>,
137
+ config?: { programAddress?: TProgramAddress },
138
+ ): CreateAccountAllowPrefundInstruction<TProgramAddress, TAccountNewAccount, TAccountPayer> & InstructionWithByteDelta {
139
+ // Program address.
140
+ const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
141
+
142
+ // Original accounts.
143
+ const originalAccounts = {
144
+ newAccount: { value: input.newAccount ?? null, isWritable: true },
145
+ payer: { value: input.payer ?? null, isWritable: true },
146
+ };
147
+ const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
148
+
149
+ // Original args.
150
+ const args = { ...input };
151
+
152
+ // Bytes created or reallocated by the instruction.
153
+ const byteDelta: number = [Number(args.space) + BASE_ACCOUNT_SIZE].reduce((a, b) => a + b, 0);
154
+
155
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
156
+ return Object.freeze({
157
+ accounts: [getAccountMeta('newAccount', accounts.newAccount), getAccountMeta('payer', accounts.payer)].filter(
158
+ <T>(x: T | undefined): x is T => x !== undefined,
159
+ ),
160
+ byteDelta,
161
+ data: getCreateAccountAllowPrefundInstructionDataEncoder().encode(
162
+ args as CreateAccountAllowPrefundInstructionDataArgs,
163
+ ),
164
+ programAddress,
165
+ } as CreateAccountAllowPrefundInstruction<TProgramAddress, TAccountNewAccount, TAccountPayer> &
166
+ InstructionWithByteDelta);
167
+ }
168
+
169
+ export type ParsedCreateAccountAllowPrefundInstruction<
170
+ TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
171
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
172
+ > = {
173
+ programAddress: Address<TProgram>;
174
+ accounts: {
175
+ newAccount: TAccountMetas[0];
176
+ payer?: TAccountMetas[1] | undefined;
177
+ };
178
+ data: CreateAccountAllowPrefundInstructionData;
179
+ };
180
+
181
+ export function parseCreateAccountAllowPrefundInstruction<
182
+ TProgram extends string,
183
+ TAccountMetas extends readonly AccountMeta[],
184
+ >(
185
+ instruction: Instruction<TProgram> &
186
+ InstructionWithAccounts<TAccountMetas> &
187
+ InstructionWithData<ReadonlyUint8Array>,
188
+ ): ParsedCreateAccountAllowPrefundInstruction<TProgram, TAccountMetas> {
189
+ if (instruction.accounts.length < 1) {
190
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
191
+ actualAccountMetas: instruction.accounts.length,
192
+ expectedAccountMetas: 1,
193
+ });
194
+ }
195
+ let accountIndex = 0;
196
+ const getNextAccount = () => {
197
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
198
+ accountIndex += 1;
199
+ return accountMeta;
200
+ };
201
+ let optionalAccountsRemaining = instruction.accounts.length - 1;
202
+ const getNextOptionalAccount = () => {
203
+ if (optionalAccountsRemaining === 0) return undefined;
204
+ optionalAccountsRemaining -= 1;
205
+ return getNextAccount();
206
+ };
207
+ return {
208
+ programAddress: instruction.programAddress,
209
+ accounts: { newAccount: getNextAccount(), payer: getNextOptionalAccount() },
210
+ data: getCreateAccountAllowPrefundInstructionDataDecoder().decode(instruction.data),
211
+ };
212
+ }
@@ -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,22 @@
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 './createAccountAllowPrefund';
17
+ export * from './createAccountWithSeed';
18
+ export * from './initializeNonceAccount';
19
+ export * from './transferSol';
20
+ export * from './transferSolWithSeed';
21
+ export * from './upgradeNonceAccount';
22
+ export * from './withdrawNonceAccount';