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
2,930 changes: 1,199 additions & 1,731 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"homepage": "https://github.com/solana-program/program-metadata#readme",
"license": "MIT",
"peerDependencies": {
"@solana/kit": "^6.0.0"
"@solana/kit": "^6.4.0"
},
"dependencies": {
"@iarna/toml": "^2.2.5",
Expand All @@ -60,7 +60,7 @@
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@solana/eslint-config-solana": "^3.0.3",
"@solana/kit": "^6.0.0",
"@solana/kit": "^6.4.0",
"@types/node": "^24",
"@types/pako": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^7.16.1",
Expand Down
790 changes: 431 additions & 359 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions clients/js/src/generated/errors/programMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type ProgramMetadataError =
| typeof PROGRAM_METADATA_ERROR__NOT_EXECUTABLE_ACCOUNT;

let programMetadataErrorMessages: Record<ProgramMetadataError, string> | undefined;
if (process.env.NODE_ENV !== 'production') {
if (process.env['NODE_ENV'] !== 'production') {
programMetadataErrorMessages = {
[PROGRAM_METADATA_ERROR__IMMUTABLE_METADATA_ACCOUNT]: `The metadata account is immutable`,
[PROGRAM_METADATA_ERROR__INVALID_DATA_LENGTH]: `The account data length is invalid`,
Expand All @@ -44,7 +44,7 @@ if (process.env.NODE_ENV !== 'production') {
}

export function getProgramMetadataErrorMessage(code: ProgramMetadataError): string {
if (process.env.NODE_ENV !== 'production') {
if (process.env['NODE_ENV'] !== 'production') {
return (programMetadataErrorMessages as Record<ProgramMetadataError, string>)[code];
}

Expand Down
24 changes: 14 additions & 10 deletions clients/js/src/generated/instructions/allocate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
getU8Decoder,
getU8Encoder,
none,
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
SolanaError,
transformEncoder,
type AccountMeta,
type AccountSignerMeta,
Expand All @@ -33,13 +35,13 @@ import {
type TransactionSigner,
type WritableAccount,
} from '@solana/kit';
import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
import { PROGRAM_METADATA_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
import { getSeedDecoder, getSeedEncoder, type Seed, type SeedArgs } from '../types';

export const ALLOCATE_DISCRIMINATOR = 7;

export function getAllocateDiscriminatorBytes() {
export function getAllocateDiscriminatorBytes(): ReadonlyUint8Array {
return getU8Encoder().encode(ALLOCATE_DISCRIMINATOR);
}

Expand Down Expand Up @@ -147,7 +149,7 @@ export function getAllocateInstruction<
programData: { value: input.programData ?? null, isWritable: false },
system: { value: input.system ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;

// Original args.
const args = { ...input };
Expand All @@ -160,11 +162,11 @@ export function getAllocateInstruction<
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.buffer),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.program),
getAccountMeta(accounts.programData),
getAccountMeta(accounts.system),
getAccountMeta('buffer', accounts.buffer),
getAccountMeta('authority', accounts.authority),
getAccountMeta('program', accounts.program),
getAccountMeta('programData', accounts.programData),
getAccountMeta('system', accounts.system),
],
data: getAllocateInstructionDataEncoder().encode(args as AllocateInstructionDataArgs),
programAddress,
Expand Down Expand Up @@ -204,8 +206,10 @@ export function parseAllocateInstruction<TProgram extends string, TAccountMetas
InstructionWithData<ReadonlyUint8Array>,
): ParsedAllocateInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
// TODO: Coded error.
throw new Error('Not enough accounts');
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 5,
});
}
let accountIndex = 0;
const getNextAccount = () => {
Expand Down
24 changes: 14 additions & 10 deletions clients/js/src/generated/instructions/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
getStructEncoder,
getU8Decoder,
getU8Encoder,
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
SolanaError,
transformEncoder,
type AccountMeta,
type AccountSignerMeta,
Expand All @@ -28,12 +30,12 @@ import {
type TransactionSigner,
type WritableAccount,
} from '@solana/kit';
import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
import { PROGRAM_METADATA_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const CLOSE_DISCRIMINATOR = 6;

export function getCloseDiscriminatorBytes() {
export function getCloseDiscriminatorBytes(): ReadonlyUint8Array {
return getU8Encoder().encode(CLOSE_DISCRIMINATOR);
}

Expand Down Expand Up @@ -127,16 +129,16 @@ export function getCloseInstruction<
programData: { value: input.programData ?? null, isWritable: false },
destination: { value: input.destination ?? null, isWritable: true },
};
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.account),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.program),
getAccountMeta(accounts.programData),
getAccountMeta(accounts.destination),
getAccountMeta('account', accounts.account),
getAccountMeta('authority', accounts.authority),
getAccountMeta('program', accounts.program),
getAccountMeta('programData', accounts.programData),
getAccountMeta('destination', accounts.destination),
],
data: getCloseInstructionDataEncoder().encode({}),
programAddress,
Expand Down Expand Up @@ -176,8 +178,10 @@ export function parseCloseInstruction<TProgram extends string, TAccountMetas ext
InstructionWithData<ReadonlyUint8Array>,
): ParsedCloseInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
// TODO: Coded error.
throw new Error('Not enough accounts');
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 5,
});
}
let accountIndex = 0;
const getNextAccount = () => {
Expand Down
22 changes: 13 additions & 9 deletions clients/js/src/generated/instructions/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
getU16Encoder,
getU8Decoder,
getU8Encoder,
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
SolanaError,
transformEncoder,
type AccountMeta,
type AccountSignerMeta,
Expand All @@ -30,12 +32,12 @@ import {
type TransactionSigner,
type WritableAccount,
} from '@solana/kit';
import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
import { PROGRAM_METADATA_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const EXTEND_DISCRIMINATOR = 8;

export function getExtendDiscriminatorBytes() {
export function getExtendDiscriminatorBytes(): ReadonlyUint8Array {
return getU8Encoder().encode(EXTEND_DISCRIMINATOR);
}

Expand Down Expand Up @@ -129,18 +131,18 @@ export function getExtendInstruction<
program: { value: input.program ?? null, isWritable: false },
programData: { value: input.programData ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;

// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.account),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.program),
getAccountMeta(accounts.programData),
getAccountMeta('account', accounts.account),
getAccountMeta('authority', accounts.authority),
getAccountMeta('program', accounts.program),
getAccountMeta('programData', accounts.programData),
],
data: getExtendInstructionDataEncoder().encode(args as ExtendInstructionDataArgs),
programAddress,
Expand Down Expand Up @@ -171,8 +173,10 @@ export function parseExtendInstruction<TProgram extends string, TAccountMetas ex
InstructionWithData<ReadonlyUint8Array>,
): ParsedExtendInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 4) {
// TODO: Coded error.
throw new Error('Not enough accounts');
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 4,
});
}
let accountIndex = 0;
const getNextAccount = () => {
Expand Down
51 changes: 30 additions & 21 deletions clients/js/src/generated/instructions/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
getU8Decoder,
getU8Encoder,
none,
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
SolanaError,
transformEncoder,
type AccountMeta,
type AccountSignerMeta,
Expand All @@ -35,9 +37,14 @@ import {
type TransactionSigner,
type WritableAccount,
} from '@solana/kit';
import {
getAccountMetaFactory,
getAddressFromResolvedInstructionAccount,
getNonNullResolvedInstructionInput,
type ResolvedInstructionAccount,
} from '@solana/kit/program-client-core';
import { findCanonicalPda, findNonCanonicalPda } from '../pdas';
import { PROGRAM_METADATA_PROGRAM_ADDRESS } from '../programs';
import { expectAddress, expectSome, getAccountMetaFactory, type ResolvedAccount } from '../shared';
import {
getCompressionDecoder,
getCompressionEncoder,
Expand All @@ -63,7 +70,7 @@ import {

export const INITIALIZE_DISCRIMINATOR = 1;

export function getInitializeDiscriminatorBytes() {
export function getInitializeDiscriminatorBytes(): ReadonlyUint8Array {
return getU8Encoder().encode(INITIALIZE_DISCRIMINATOR);
}

Expand Down Expand Up @@ -202,7 +209,7 @@ export async function getInitializeInstructionAsync<
programData: { value: input.programData ?? null, isWritable: false },
system: { value: input.system ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;

// Original args.
const args = { ...input };
Expand All @@ -211,14 +218,14 @@ export async function getInitializeInstructionAsync<
if (!accounts.metadata.value) {
if (accounts.programData.value) {
accounts.metadata.value = await findCanonicalPda({
program: expectAddress(accounts.program.value),
seed: expectSome(args.seed),
program: getAddressFromResolvedInstructionAccount('program', accounts.program.value),
seed: getNonNullResolvedInstructionInput('seed', args.seed),
});
} else {
accounts.metadata.value = await findNonCanonicalPda({
program: expectAddress(accounts.program.value),
authority: expectAddress(accounts.authority.value),
seed: expectSome(args.seed),
program: getAddressFromResolvedInstructionAccount('program', accounts.program.value),
authority: getAddressFromResolvedInstructionAccount('authority', accounts.authority.value),
seed: getNonNullResolvedInstructionInput('seed', args.seed),
});
}
}
Expand All @@ -229,11 +236,11 @@ export async function getInitializeInstructionAsync<
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.metadata),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.program),
getAccountMeta(accounts.programData),
getAccountMeta(accounts.system),
getAccountMeta('metadata', accounts.metadata),
getAccountMeta('authority', accounts.authority),
getAccountMeta('program', accounts.program),
getAccountMeta('programData', accounts.programData),
getAccountMeta('system', accounts.system),
],
data: getInitializeInstructionDataEncoder().encode(args as InitializeInstructionDataArgs),
programAddress,
Expand Down Expand Up @@ -301,7 +308,7 @@ export function getInitializeInstruction<
programData: { value: input.programData ?? null, isWritable: false },
system: { value: input.system ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;

// Original args.
const args = { ...input };
Expand All @@ -314,11 +321,11 @@ export function getInitializeInstruction<
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.metadata),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.program),
getAccountMeta(accounts.programData),
getAccountMeta(accounts.system),
getAccountMeta('metadata', accounts.metadata),
getAccountMeta('authority', accounts.authority),
getAccountMeta('program', accounts.program),
getAccountMeta('programData', accounts.programData),
getAccountMeta('system', accounts.system),
],
data: getInitializeInstructionDataEncoder().encode(args as InitializeInstructionDataArgs),
programAddress,
Expand Down Expand Up @@ -358,8 +365,10 @@ export function parseInitializeInstruction<TProgram extends string, TAccountMeta
InstructionWithData<ReadonlyUint8Array>,
): ParsedInitializeInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
// TODO: Coded error.
throw new Error('Not enough accounts');
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 5,
});
}
let accountIndex = 0;
const getNextAccount = () => {
Expand Down
Loading
Loading