Skip to content

Commit 86f1e9a

Browse files
authored
Upgrade JS client to Kit v3 (#86)
1 parent 3fff4ce commit 86f1e9a

39 files changed

+1259
-1823
lines changed

clients/js/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
},
4343
"homepage": "https://github.com/solana-program/token#readme",
4444
"peerDependencies": {
45-
"@solana/kit": "^2.1.0"
45+
"@solana/kit": "^3.0"
4646
},
4747
"devDependencies": {
4848
"@ava/typescript": "^4.1.0",
49-
"@solana-program/system": "^0.6.1",
49+
"@solana-program/system": "^0.8.0",
5050
"@solana/eslint-config-solana": "^3.0.3",
51-
"@solana/kit": "^2.1.0",
52-
"@types/node": "^20",
51+
"@solana/kit": "^3.0",
52+
"@types/node": "^24",
5353
"@typescript-eslint/eslint-plugin": "^7.16.1",
5454
"@typescript-eslint/parser": "^7.16.1",
5555
"ava": "^6.1.3",

clients/js/pnpm-lock.yaml

Lines changed: 356 additions & 879 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/js/src/generated/accounts/mint.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import {
2929
getU8Encoder,
3030
type Account,
3131
type Address,
32-
type Codec,
33-
type Decoder,
3432
type EncodedAccount,
35-
type Encoder,
3633
type FetchAccountConfig,
3734
type FetchAccountsConfig,
35+
type FixedSizeCodec,
36+
type FixedSizeDecoder,
37+
type FixedSizeEncoder,
3838
type MaybeAccount,
3939
type MaybeEncodedAccount,
4040
type Option,
@@ -75,7 +75,7 @@ export type MintArgs = {
7575
freezeAuthority: OptionOrNullable<Address>;
7676
};
7777

78-
export function getMintEncoder(): Encoder<MintArgs> {
78+
export function getMintEncoder(): FixedSizeEncoder<MintArgs> {
7979
return getStructEncoder([
8080
[
8181
'mintAuthority',
@@ -97,7 +97,7 @@ export function getMintEncoder(): Encoder<MintArgs> {
9797
]);
9898
}
9999

100-
export function getMintDecoder(): Decoder<Mint> {
100+
export function getMintDecoder(): FixedSizeDecoder<Mint> {
101101
return getStructDecoder([
102102
[
103103
'mintAuthority',
@@ -119,7 +119,7 @@ export function getMintDecoder(): Decoder<Mint> {
119119
]);
120120
}
121121

122-
export function getMintCodec(): Codec<MintArgs, Mint> {
122+
export function getMintCodec(): FixedSizeCodec<MintArgs, Mint> {
123123
return combineCodec(getMintEncoder(), getMintDecoder());
124124
}
125125

clients/js/src/generated/accounts/multisig.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import {
2525
getU8Encoder,
2626
type Account,
2727
type Address,
28-
type Codec,
29-
type Decoder,
3028
type EncodedAccount,
31-
type Encoder,
3229
type FetchAccountConfig,
3330
type FetchAccountsConfig,
31+
type FixedSizeCodec,
32+
type FixedSizeDecoder,
33+
type FixedSizeEncoder,
3434
type MaybeAccount,
3535
type MaybeEncodedAccount,
3636
} from '@solana/kit';
@@ -48,7 +48,7 @@ export type Multisig = {
4848

4949
export type MultisigArgs = Multisig;
5050

51-
export function getMultisigEncoder(): Encoder<MultisigArgs> {
51+
export function getMultisigEncoder(): FixedSizeEncoder<MultisigArgs> {
5252
return getStructEncoder([
5353
['m', getU8Encoder()],
5454
['n', getU8Encoder()],
@@ -57,7 +57,7 @@ export function getMultisigEncoder(): Encoder<MultisigArgs> {
5757
]);
5858
}
5959

60-
export function getMultisigDecoder(): Decoder<Multisig> {
60+
export function getMultisigDecoder(): FixedSizeDecoder<Multisig> {
6161
return getStructDecoder([
6262
['m', getU8Decoder()],
6363
['n', getU8Decoder()],
@@ -66,7 +66,7 @@ export function getMultisigDecoder(): Decoder<Multisig> {
6666
]);
6767
}
6868

69-
export function getMultisigCodec(): Codec<MultisigArgs, Multisig> {
69+
export function getMultisigCodec(): FixedSizeCodec<MultisigArgs, Multisig> {
7070
return combineCodec(getMultisigEncoder(), getMultisigDecoder());
7171
}
7272

clients/js/src/generated/accounts/token.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import {
2525
getU64Encoder,
2626
type Account,
2727
type Address,
28-
type Codec,
29-
type Decoder,
3028
type EncodedAccount,
31-
type Encoder,
3229
type FetchAccountConfig,
3330
type FetchAccountsConfig,
31+
type FixedSizeCodec,
32+
type FixedSizeDecoder,
33+
type FixedSizeEncoder,
3434
type MaybeAccount,
3535
type MaybeEncodedAccount,
3636
type Option,
@@ -97,7 +97,7 @@ export type TokenArgs = {
9797
closeAuthority: OptionOrNullable<Address>;
9898
};
9999

100-
export function getTokenEncoder(): Encoder<TokenArgs> {
100+
export function getTokenEncoder(): FixedSizeEncoder<TokenArgs> {
101101
return getStructEncoder([
102102
['mint', getAddressEncoder()],
103103
['owner', getAddressEncoder()],
@@ -128,7 +128,7 @@ export function getTokenEncoder(): Encoder<TokenArgs> {
128128
]);
129129
}
130130

131-
export function getTokenDecoder(): Decoder<Token> {
131+
export function getTokenDecoder(): FixedSizeDecoder<Token> {
132132
return getStructDecoder([
133133
['mint', getAddressDecoder()],
134134
['owner', getAddressDecoder()],
@@ -159,7 +159,7 @@ export function getTokenDecoder(): Decoder<Token> {
159159
]);
160160
}
161161

162-
export function getTokenCodec(): Codec<TokenArgs, Token> {
162+
export function getTokenCodec(): FixedSizeCodec<TokenArgs, Token> {
163163
return combineCodec(getTokenEncoder(), getTokenDecoder());
164164
}
165165

clients/js/src/generated/instructions/amountToUiAmount.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ import {
1515
getU8Decoder,
1616
getU8Encoder,
1717
transformEncoder,
18+
type AccountMeta,
1819
type Address,
19-
type Codec,
20-
type Decoder,
21-
type Encoder,
22-
type IAccountMeta,
23-
type IInstruction,
24-
type IInstructionWithAccounts,
25-
type IInstructionWithData,
20+
type FixedSizeCodec,
21+
type FixedSizeDecoder,
22+
type FixedSizeEncoder,
23+
type Instruction,
24+
type InstructionWithAccounts,
25+
type InstructionWithData,
2626
type ReadonlyAccount,
27+
type ReadonlyUint8Array,
2728
} from '@solana/kit';
2829
import { TOKEN_PROGRAM_ADDRESS } from '../programs';
2930
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
@@ -36,11 +37,11 @@ export function getAmountToUiAmountDiscriminatorBytes() {
3637

3738
export type AmountToUiAmountInstruction<
3839
TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
39-
TAccountMint extends string | IAccountMeta<string> = string,
40-
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
41-
> = IInstruction<TProgram> &
42-
IInstructionWithData<Uint8Array> &
43-
IInstructionWithAccounts<
40+
TAccountMint extends string | AccountMeta<string> = string,
41+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
42+
> = Instruction<TProgram> &
43+
InstructionWithData<ReadonlyUint8Array> &
44+
InstructionWithAccounts<
4445
[
4546
TAccountMint extends string
4647
? ReadonlyAccount<TAccountMint>
@@ -60,7 +61,7 @@ export type AmountToUiAmountInstructionDataArgs = {
6061
amount: number | bigint;
6162
};
6263

63-
export function getAmountToUiAmountInstructionDataEncoder(): Encoder<AmountToUiAmountInstructionDataArgs> {
64+
export function getAmountToUiAmountInstructionDataEncoder(): FixedSizeEncoder<AmountToUiAmountInstructionDataArgs> {
6465
return transformEncoder(
6566
getStructEncoder([
6667
['discriminator', getU8Encoder()],
@@ -70,14 +71,14 @@ export function getAmountToUiAmountInstructionDataEncoder(): Encoder<AmountToUiA
7071
);
7172
}
7273

73-
export function getAmountToUiAmountInstructionDataDecoder(): Decoder<AmountToUiAmountInstructionData> {
74+
export function getAmountToUiAmountInstructionDataDecoder(): FixedSizeDecoder<AmountToUiAmountInstructionData> {
7475
return getStructDecoder([
7576
['discriminator', getU8Decoder()],
7677
['amount', getU64Decoder()],
7778
]);
7879
}
7980

80-
export function getAmountToUiAmountInstructionDataCodec(): Codec<
81+
export function getAmountToUiAmountInstructionDataCodec(): FixedSizeCodec<
8182
AmountToUiAmountInstructionDataArgs,
8283
AmountToUiAmountInstructionData
8384
> {
@@ -129,7 +130,7 @@ export function getAmountToUiAmountInstruction<
129130

130131
export type ParsedAmountToUiAmountInstruction<
131132
TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
132-
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
133+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
133134
> = {
134135
programAddress: Address<TProgram>;
135136
accounts: {
@@ -141,19 +142,19 @@ export type ParsedAmountToUiAmountInstruction<
141142

142143
export function parseAmountToUiAmountInstruction<
143144
TProgram extends string,
144-
TAccountMetas extends readonly IAccountMeta[],
145+
TAccountMetas extends readonly AccountMeta[],
145146
>(
146-
instruction: IInstruction<TProgram> &
147-
IInstructionWithAccounts<TAccountMetas> &
148-
IInstructionWithData<Uint8Array>
147+
instruction: Instruction<TProgram> &
148+
InstructionWithAccounts<TAccountMetas> &
149+
InstructionWithData<ReadonlyUint8Array>
149150
): ParsedAmountToUiAmountInstruction<TProgram, TAccountMetas> {
150151
if (instruction.accounts.length < 1) {
151152
// TODO: Coded error.
152153
throw new Error('Not enough accounts');
153154
}
154155
let accountIndex = 0;
155156
const getNextAccount = () => {
156-
const accountMeta = instruction.accounts![accountIndex]!;
157+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
157158
accountIndex += 1;
158159
return accountMeta;
159160
};

clients/js/src/generated/instructions/approve.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ import {
1616
getU8Decoder,
1717
getU8Encoder,
1818
transformEncoder,
19+
type AccountMeta,
20+
type AccountSignerMeta,
1921
type Address,
20-
type Codec,
21-
type Decoder,
22-
type Encoder,
23-
type IAccountMeta,
24-
type IAccountSignerMeta,
25-
type IInstruction,
26-
type IInstructionWithAccounts,
27-
type IInstructionWithData,
22+
type FixedSizeCodec,
23+
type FixedSizeDecoder,
24+
type FixedSizeEncoder,
25+
type Instruction,
26+
type InstructionWithAccounts,
27+
type InstructionWithData,
2828
type ReadonlyAccount,
2929
type ReadonlySignerAccount,
30+
type ReadonlyUint8Array,
3031
type TransactionSigner,
3132
type WritableAccount,
3233
} from '@solana/kit';
@@ -41,13 +42,13 @@ export function getApproveDiscriminatorBytes() {
4142

4243
export type ApproveInstruction<
4344
TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
44-
TAccountSource extends string | IAccountMeta<string> = string,
45-
TAccountDelegate extends string | IAccountMeta<string> = string,
46-
TAccountOwner extends string | IAccountMeta<string> = string,
47-
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
48-
> = IInstruction<TProgram> &
49-
IInstructionWithData<Uint8Array> &
50-
IInstructionWithAccounts<
45+
TAccountSource extends string | AccountMeta<string> = string,
46+
TAccountDelegate extends string | AccountMeta<string> = string,
47+
TAccountOwner extends string | AccountMeta<string> = string,
48+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
49+
> = Instruction<TProgram> &
50+
InstructionWithData<ReadonlyUint8Array> &
51+
InstructionWithAccounts<
5152
[
5253
TAccountSource extends string
5354
? WritableAccount<TAccountSource>
@@ -73,7 +74,7 @@ export type ApproveInstructionDataArgs = {
7374
amount: number | bigint;
7475
};
7576

76-
export function getApproveInstructionDataEncoder(): Encoder<ApproveInstructionDataArgs> {
77+
export function getApproveInstructionDataEncoder(): FixedSizeEncoder<ApproveInstructionDataArgs> {
7778
return transformEncoder(
7879
getStructEncoder([
7980
['discriminator', getU8Encoder()],
@@ -83,14 +84,14 @@ export function getApproveInstructionDataEncoder(): Encoder<ApproveInstructionDa
8384
);
8485
}
8586

86-
export function getApproveInstructionDataDecoder(): Decoder<ApproveInstructionData> {
87+
export function getApproveInstructionDataDecoder(): FixedSizeDecoder<ApproveInstructionData> {
8788
return getStructDecoder([
8889
['discriminator', getU8Decoder()],
8990
['amount', getU64Decoder()],
9091
]);
9192
}
9293

93-
export function getApproveInstructionDataCodec(): Codec<
94+
export function getApproveInstructionDataCodec(): FixedSizeCodec<
9495
ApproveInstructionDataArgs,
9596
ApproveInstructionData
9697
> {
@@ -128,7 +129,7 @@ export function getApproveInstruction<
128129
TAccountSource,
129130
TAccountDelegate,
130131
(typeof input)['owner'] extends TransactionSigner<TAccountOwner>
131-
? ReadonlySignerAccount<TAccountOwner> & IAccountSignerMeta<TAccountOwner>
132+
? ReadonlySignerAccount<TAccountOwner> & AccountSignerMeta<TAccountOwner>
132133
: TAccountOwner
133134
> {
134135
// Program address.
@@ -149,7 +150,7 @@ export function getApproveInstruction<
149150
const args = { ...input };
150151

151152
// Remaining accounts.
152-
const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map(
153+
const remainingAccounts: AccountMeta[] = (args.multiSigners ?? []).map(
153154
(signer) => ({
154155
address: signer.address,
155156
role: AccountRole.READONLY_SIGNER,
@@ -174,7 +175,7 @@ export function getApproveInstruction<
174175
TAccountSource,
175176
TAccountDelegate,
176177
(typeof input)['owner'] extends TransactionSigner<TAccountOwner>
177-
? ReadonlySignerAccount<TAccountOwner> & IAccountSignerMeta<TAccountOwner>
178+
? ReadonlySignerAccount<TAccountOwner> & AccountSignerMeta<TAccountOwner>
178179
: TAccountOwner
179180
>;
180181

@@ -183,7 +184,7 @@ export function getApproveInstruction<
183184

184185
export type ParsedApproveInstruction<
185186
TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
186-
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
187+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
187188
> = {
188189
programAddress: Address<TProgram>;
189190
accounts: {
@@ -199,19 +200,19 @@ export type ParsedApproveInstruction<
199200

200201
export function parseApproveInstruction<
201202
TProgram extends string,
202-
TAccountMetas extends readonly IAccountMeta[],
203+
TAccountMetas extends readonly AccountMeta[],
203204
>(
204-
instruction: IInstruction<TProgram> &
205-
IInstructionWithAccounts<TAccountMetas> &
206-
IInstructionWithData<Uint8Array>
205+
instruction: Instruction<TProgram> &
206+
InstructionWithAccounts<TAccountMetas> &
207+
InstructionWithData<ReadonlyUint8Array>
207208
): ParsedApproveInstruction<TProgram, TAccountMetas> {
208209
if (instruction.accounts.length < 3) {
209210
// TODO: Coded error.
210211
throw new Error('Not enough accounts');
211212
}
212213
let accountIndex = 0;
213214
const getNextAccount = () => {
214-
const accountMeta = instruction.accounts![accountIndex]!;
215+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
215216
accountIndex += 1;
216217
return accountMeta;
217218
};

0 commit comments

Comments
 (0)