Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
},
"homepage": "https://github.com/solana-program/token#readme",
"peerDependencies": {
"@solana/kit": "^2.1.0"
"@solana/kit": "^3.0"
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@solana-program/system": "^0.6.1",
"@solana-program/system": "^0.8.0",
"@solana/eslint-config-solana": "^3.0.3",
"@solana/kit": "^2.1.0",
"@types/node": "^20",
"@solana/kit": "^3.0",
"@types/node": "^24",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"ava": "^6.1.3",
Expand Down
1,235 changes: 356 additions & 879 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions clients/js/src/generated/accounts/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import {
getU8Encoder,
type Account,
type Address,
type Codec,
type Decoder,
type EncodedAccount,
type Encoder,
type FetchAccountConfig,
type FetchAccountsConfig,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
type MaybeAccount,
type MaybeEncodedAccount,
type Option,
Expand Down Expand Up @@ -75,7 +75,7 @@ export type MintArgs = {
freezeAuthority: OptionOrNullable<Address>;
};

export function getMintEncoder(): Encoder<MintArgs> {
export function getMintEncoder(): FixedSizeEncoder<MintArgs> {
return getStructEncoder([
[
'mintAuthority',
Expand All @@ -97,7 +97,7 @@ export function getMintEncoder(): Encoder<MintArgs> {
]);
}

export function getMintDecoder(): Decoder<Mint> {
export function getMintDecoder(): FixedSizeDecoder<Mint> {
return getStructDecoder([
[
'mintAuthority',
Expand All @@ -119,7 +119,7 @@ export function getMintDecoder(): Decoder<Mint> {
]);
}

export function getMintCodec(): Codec<MintArgs, Mint> {
export function getMintCodec(): FixedSizeCodec<MintArgs, Mint> {
return combineCodec(getMintEncoder(), getMintDecoder());
}

Expand Down
12 changes: 6 additions & 6 deletions clients/js/src/generated/accounts/multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import {
getU8Encoder,
type Account,
type Address,
type Codec,
type Decoder,
type EncodedAccount,
type Encoder,
type FetchAccountConfig,
type FetchAccountsConfig,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
type MaybeAccount,
type MaybeEncodedAccount,
} from '@solana/kit';
Expand All @@ -48,7 +48,7 @@ export type Multisig = {

export type MultisigArgs = Multisig;

export function getMultisigEncoder(): Encoder<MultisigArgs> {
export function getMultisigEncoder(): FixedSizeEncoder<MultisigArgs> {
return getStructEncoder([
['m', getU8Encoder()],
['n', getU8Encoder()],
Expand All @@ -57,7 +57,7 @@ export function getMultisigEncoder(): Encoder<MultisigArgs> {
]);
}

export function getMultisigDecoder(): Decoder<Multisig> {
export function getMultisigDecoder(): FixedSizeDecoder<Multisig> {
return getStructDecoder([
['m', getU8Decoder()],
['n', getU8Decoder()],
Expand All @@ -66,7 +66,7 @@ export function getMultisigDecoder(): Decoder<Multisig> {
]);
}

export function getMultisigCodec(): Codec<MultisigArgs, Multisig> {
export function getMultisigCodec(): FixedSizeCodec<MultisigArgs, Multisig> {
return combineCodec(getMultisigEncoder(), getMultisigDecoder());
}

Expand Down
12 changes: 6 additions & 6 deletions clients/js/src/generated/accounts/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import {
getU64Encoder,
type Account,
type Address,
type Codec,
type Decoder,
type EncodedAccount,
type Encoder,
type FetchAccountConfig,
type FetchAccountsConfig,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
type MaybeAccount,
type MaybeEncodedAccount,
type Option,
Expand Down Expand Up @@ -97,7 +97,7 @@ export type TokenArgs = {
closeAuthority: OptionOrNullable<Address>;
};

export function getTokenEncoder(): Encoder<TokenArgs> {
export function getTokenEncoder(): FixedSizeEncoder<TokenArgs> {
return getStructEncoder([
['mint', getAddressEncoder()],
['owner', getAddressEncoder()],
Expand Down Expand Up @@ -128,7 +128,7 @@ export function getTokenEncoder(): Encoder<TokenArgs> {
]);
}

export function getTokenDecoder(): Decoder<Token> {
export function getTokenDecoder(): FixedSizeDecoder<Token> {
return getStructDecoder([
['mint', getAddressDecoder()],
['owner', getAddressDecoder()],
Expand Down Expand Up @@ -159,7 +159,7 @@ export function getTokenDecoder(): Decoder<Token> {
]);
}

export function getTokenCodec(): Codec<TokenArgs, Token> {
export function getTokenCodec(): FixedSizeCodec<TokenArgs, Token> {
return combineCodec(getTokenEncoder(), getTokenDecoder());
}

Expand Down
43 changes: 22 additions & 21 deletions clients/js/src/generated/instructions/amountToUiAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ import {
getU8Decoder,
getU8Encoder,
transformEncoder,
type AccountMeta,
type Address,
type Codec,
type Decoder,
type Encoder,
type IAccountMeta,
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
type Instruction,
type InstructionWithAccounts,
type InstructionWithData,
type ReadonlyAccount,
type ReadonlyUint8Array,
} from '@solana/kit';
import { TOKEN_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
Expand All @@ -36,11 +37,11 @@ export function getAmountToUiAmountDiscriminatorBytes() {

export type AmountToUiAmountInstruction<
TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
TAccountMint extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
TAccountMint extends string | AccountMeta<string> = string,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountMint extends string
? ReadonlyAccount<TAccountMint>
Expand All @@ -60,7 +61,7 @@ export type AmountToUiAmountInstructionDataArgs = {
amount: number | bigint;
};

export function getAmountToUiAmountInstructionDataEncoder(): Encoder<AmountToUiAmountInstructionDataArgs> {
export function getAmountToUiAmountInstructionDataEncoder(): FixedSizeEncoder<AmountToUiAmountInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
Expand All @@ -70,14 +71,14 @@ export function getAmountToUiAmountInstructionDataEncoder(): Encoder<AmountToUiA
);
}

export function getAmountToUiAmountInstructionDataDecoder(): Decoder<AmountToUiAmountInstructionData> {
export function getAmountToUiAmountInstructionDataDecoder(): FixedSizeDecoder<AmountToUiAmountInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['amount', getU64Decoder()],
]);
}

export function getAmountToUiAmountInstructionDataCodec(): Codec<
export function getAmountToUiAmountInstructionDataCodec(): FixedSizeCodec<
AmountToUiAmountInstructionDataArgs,
AmountToUiAmountInstructionData
> {
Expand Down Expand Up @@ -129,7 +130,7 @@ export function getAmountToUiAmountInstruction<

export type ParsedAmountToUiAmountInstruction<
TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
Expand All @@ -141,19 +142,19 @@ export type ParsedAmountToUiAmountInstruction<

export function parseAmountToUiAmountInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
TAccountMetas extends readonly AccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>
): ParsedAmountToUiAmountInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 1) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts![accountIndex]!;
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
accountIndex += 1;
return accountMeta;
};
Expand Down
55 changes: 28 additions & 27 deletions clients/js/src/generated/instructions/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ import {
getU8Decoder,
getU8Encoder,
transformEncoder,
type AccountMeta,
type AccountSignerMeta,
type Address,
type Codec,
type Decoder,
type Encoder,
type IAccountMeta,
type IAccountSignerMeta,
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
type Instruction,
type InstructionWithAccounts,
type InstructionWithData,
type ReadonlyAccount,
type ReadonlySignerAccount,
type ReadonlyUint8Array,
type TransactionSigner,
type WritableAccount,
} from '@solana/kit';
Expand All @@ -41,13 +42,13 @@ export function getApproveDiscriminatorBytes() {

export type ApproveInstruction<
TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
TAccountSource extends string | IAccountMeta<string> = string,
TAccountDelegate extends string | IAccountMeta<string> = string,
TAccountOwner extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
TAccountSource extends string | AccountMeta<string> = string,
TAccountDelegate extends string | AccountMeta<string> = string,
TAccountOwner extends string | AccountMeta<string> = string,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountSource extends string
? WritableAccount<TAccountSource>
Expand All @@ -73,7 +74,7 @@ export type ApproveInstructionDataArgs = {
amount: number | bigint;
};

export function getApproveInstructionDataEncoder(): Encoder<ApproveInstructionDataArgs> {
export function getApproveInstructionDataEncoder(): FixedSizeEncoder<ApproveInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
Expand All @@ -83,14 +84,14 @@ export function getApproveInstructionDataEncoder(): Encoder<ApproveInstructionDa
);
}

export function getApproveInstructionDataDecoder(): Decoder<ApproveInstructionData> {
export function getApproveInstructionDataDecoder(): FixedSizeDecoder<ApproveInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['amount', getU64Decoder()],
]);
}

export function getApproveInstructionDataCodec(): Codec<
export function getApproveInstructionDataCodec(): FixedSizeCodec<
ApproveInstructionDataArgs,
ApproveInstructionData
> {
Expand Down Expand Up @@ -128,7 +129,7 @@ export function getApproveInstruction<
TAccountSource,
TAccountDelegate,
(typeof input)['owner'] extends TransactionSigner<TAccountOwner>
? ReadonlySignerAccount<TAccountOwner> & IAccountSignerMeta<TAccountOwner>
? ReadonlySignerAccount<TAccountOwner> & AccountSignerMeta<TAccountOwner>
: TAccountOwner
> {
// Program address.
Expand All @@ -149,7 +150,7 @@ export function getApproveInstruction<
const args = { ...input };

// Remaining accounts.
const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map(
const remainingAccounts: AccountMeta[] = (args.multiSigners ?? []).map(
(signer) => ({
address: signer.address,
role: AccountRole.READONLY_SIGNER,
Expand All @@ -174,7 +175,7 @@ export function getApproveInstruction<
TAccountSource,
TAccountDelegate,
(typeof input)['owner'] extends TransactionSigner<TAccountOwner>
? ReadonlySignerAccount<TAccountOwner> & IAccountSignerMeta<TAccountOwner>
? ReadonlySignerAccount<TAccountOwner> & AccountSignerMeta<TAccountOwner>
: TAccountOwner
>;

Expand All @@ -183,7 +184,7 @@ export function getApproveInstruction<

export type ParsedApproveInstruction<
TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
Expand All @@ -199,19 +200,19 @@ export type ParsedApproveInstruction<

export function parseApproveInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
TAccountMetas extends readonly AccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>
): ParsedApproveInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 3) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts![accountIndex]!;
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
accountIndex += 1;
return accountMeta;
};
Expand Down
Loading