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
11 changes: 6 additions & 5 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,23 @@
"homepage": "https://github.com/solana-program/program-metadata#readme",
"license": "MIT",
"peerDependencies": {
"@solana/kit": "^2.1.0"
"@solana/kit": "^3.0"
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"@solana-program/compute-budget": "^0.7.0",
"@solana-program/system": "^0.7.0",
"@solana-program/compute-budget": "^0.9.0",
"@solana-program/system": "^0.8.0",
"commander": "^13.0.0",
"p-limit": "^7.1.1",
"pako": "^2.1.0",
"picocolors": "^1.1.1",
"yaml": "^2.7.0"
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@solana/eslint-config-solana": "^3.0.3",
"@solana/kit": "^2.1.0",
"@types/node": "^22",
"@solana/kit": "^3.0",
"@types/node": "^24",
"@types/pako": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
Expand Down
736 changes: 397 additions & 339 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions clients/js/src/cli/commands/close-buffer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Address } from '@solana/kit';
import { Address, sequentialInstructionPlan } from '@solana/kit';
import { fetchMaybeBuffer, getCloseInstruction } from '../../generated';
import { sequentialInstructionPlan } from '../../instructionPlans';
import { bufferArgument } from '../arguments';
import { logCommand, logErrorAndExit } from '../logs';
import { GlobalOptions } from '../options';
Expand Down
3 changes: 1 addition & 2 deletions clients/js/src/cli/commands/close.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Address } from '@solana/kit';
import { Address, sequentialInstructionPlan } from '@solana/kit';
import { getCloseInstruction, Seed } from '../../generated';
import { sequentialInstructionPlan } from '../../instructionPlans';
import { programArgument, seedArgument } from '../arguments';
import {
GlobalOptions,
Expand Down
5 changes: 3 additions & 2 deletions clients/js/src/cli/commands/list-buffers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Address,
Base64EncodedBytes,
getAddressEncoder,
getBase64Decoder,
GetProgramAccountsMemcmpFilter,
Expand Down Expand Up @@ -74,7 +75,7 @@ function getDiscriminatorFilter(): GetProgramAccountsMemcmpFilter {
AccountDiscriminator.Buffer,
getAccountDiscriminatorEncoder().encode,
getBase64Decoder().decode
),
) as Base64EncodedBytes,
encoding: 'base64',
offset: DISCRIMINATOR_OFFSET,
},
Expand All @@ -90,7 +91,7 @@ function getAuthorityFilter(
authority,
getAddressEncoder().encode,
getBase64Decoder().decode
),
) as Base64EncodedBytes,
encoding: 'base64',
offset: AUTHORITY_OFFSET,
},
Expand Down
3 changes: 1 addition & 2 deletions clients/js/src/cli/commands/remove-authority.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Address } from '@solana/kit';
import { Address, sequentialInstructionPlan } from '@solana/kit';
import { getSetAuthorityInstruction, Seed } from '../../generated';
import { sequentialInstructionPlan } from '../../instructionPlans';
import { getPdaDetails } from '../../internals';
import { programArgument, seedArgument } from '../arguments';
import { GlobalOptions } from '../options';
Expand Down
3 changes: 1 addition & 2 deletions clients/js/src/cli/commands/set-authority.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Address } from '@solana/kit';
import { Address, sequentialInstructionPlan } from '@solana/kit';
import { getSetAuthorityInstruction, Seed } from '../../generated';
import { sequentialInstructionPlan } from '../../instructionPlans';
import { getPdaDetails } from '../../internals';
import { programArgument, seedArgument } from '../arguments';
import { logCommand } from '../logs';
Expand Down
3 changes: 1 addition & 2 deletions clients/js/src/cli/commands/set-buffer-authority.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Address } from '@solana/kit';
import { Address, sequentialInstructionPlan } from '@solana/kit';
import { getSetAuthorityInstruction } from '../../generated';
import { sequentialInstructionPlan } from '../../instructionPlans';
import { bufferArgument } from '../arguments';
import { logCommand } from '../logs';
import {
Expand Down
3 changes: 1 addition & 2 deletions clients/js/src/cli/commands/set-immutable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Address } from '@solana/kit';
import { Address, sequentialInstructionPlan } from '@solana/kit';
import { getSetImmutableInstruction, Seed } from '../../generated';
import { sequentialInstructionPlan } from '../../instructionPlans';
import { programArgument, seedArgument } from '../arguments';
import { logCommand } from '../logs';
import {
Expand Down
56 changes: 36 additions & 20 deletions clients/js/src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ import {
Account,
Address,
address,
BaseTransactionMessage,
Commitment,
CompilableTransactionMessage,
compileTransaction,
createKeyPairSignerFromBytes,
createNoopSigner,
createSolanaRpc,
createSolanaRpcSubscriptions,
getAllSingleTransactionPlans,
getTransactionEncoder,
InstructionPlan,
MessageSigner,
pipe,
Rpc,
RpcSubscriptions,
setTransactionMessageLifetimeUsingBlockhash,
SolanaRpcApi,
SolanaRpcSubscriptionsApi,
TransactionMessageWithFeePayer,
TransactionPlan,
TransactionPlanExecutor,
TransactionPlanner,
TransactionSigner,
} from '@solana/kit';
import { Command } from 'commander';
import picocolors from 'picocolors';
import { parse as parseYaml } from 'yaml';
import { Buffer, DataSource, fetchBuffer, Format, Seed } from '../generated';
import {
createDefaultTransactionPlanExecutor,
createDefaultTransactionPlanner,
getAllSingleTransactionPlans,
getSetComputeUnitLimitInstructionIndex,
InstructionPlan,
TransactionPlan,
TransactionPlanExecutor,
TransactionPlanner,
} from '../instructionPlans';
import { getPdaDetails, PdaDetails } from '../internals';
createDefaultTransactionPlannerAndExecutor,
getPdaDetails,
PdaDetails,
} from '../internals';
import {
decodeData,
packDirectData,
Expand All @@ -55,6 +55,11 @@ import {
RpcOption,
WriteOptions,
} from './options';
import {
COMPUTE_BUDGET_PROGRAM_ADDRESS,
ComputeBudgetInstruction,
identifyComputeBudgetInstruction,
} from '@solana-program/compute-budget';

const LOCALHOST_URL = 'http://127.0.0.1:8899';
const DATA_SOURCE_OPTIONS =
Expand Down Expand Up @@ -85,14 +90,12 @@ export async function getClient(options: GlobalOptions): Promise<Client> {
options,
readonlyClient.configs
);
const planner = createDefaultTransactionPlanner({
feePayer: payer,
computeUnitPrice: options.priorityFees,
});
const executor = createDefaultTransactionPlanExecutor({
const { planner, executor } = createDefaultTransactionPlannerAndExecutor({
priorityFees: options.priorityFees,
payer,
rpc: readonlyClient.rpc,
rpcSubscriptions: readonlyClient.rpcSubscriptions,
parallelChunkSize: 5,
concurrency: 5,
});
const planAndExecute = async (instructionPlan: InstructionPlan) => {
const transactionPlan = await planner(instructionPlan);
Expand Down Expand Up @@ -129,8 +132,8 @@ async function exportTransactionPlan(
for (let i = 0; i < singleTransactions.length; i++) {
const transaction = pipe(
singleTransactions[i].message,
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
removeComputeUnitLimitInstruction,
(m) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),
(m) => removeComputeUnitLimitInstruction(m),
compileTransaction
);
const encodedTransaction = decodeData(
Expand All @@ -143,7 +146,8 @@ async function exportTransactionPlan(
}

function removeComputeUnitLimitInstruction<
TTransactionMessage extends CompilableTransactionMessage,
TTransactionMessage extends BaseTransactionMessage &
TransactionMessageWithFeePayer,
>(message: TTransactionMessage): TTransactionMessage {
const index = getSetComputeUnitLimitInstructionIndex(message);
if (index === -1) return message;
Expand All @@ -153,6 +157,18 @@ function removeComputeUnitLimitInstruction<
};
}

export function getSetComputeUnitLimitInstructionIndex(
transactionMessage: BaseTransactionMessage
) {
return transactionMessage.instructions.findIndex((ix) => {
return (
ix.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS &&
identifyComputeBudgetInstruction(ix.data as Uint8Array) ===
ComputeBudgetInstruction.SetComputeUnitLimit
);
});
}

async function executeTransactionPlan(
transactionPlan: TransactionPlan,
executor: TransactionPlanExecutor
Expand Down
6 changes: 2 additions & 4 deletions clients/js/src/createBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
Account,
Address,
Lamports,
parallelInstructionPlan,
ReadonlyUint8Array,
sequentialInstructionPlan,
TransactionSigner,
} from '@solana/kit';
import {
Expand All @@ -14,10 +16,6 @@ import {
getWriteInstruction,
PROGRAM_METADATA_PROGRAM_ADDRESS,
} from './generated';
import {
parallelInstructionPlan,
sequentialInstructionPlan,
} from './instructionPlans';
import { getAccountSize, getWriteInstructionPlan } from './utils';

export function getCreateBufferInstructionPlan(input: {
Expand Down
25 changes: 12 additions & 13 deletions clients/js/src/createMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { getTransferSolInstruction } from '@solana-program/system';
import {
Account,
Address,
GetAccountInfoApi,
GetMinimumBalanceForRentExemptionApi,
InstructionPlan,
Lamports,
parallelInstructionPlan,
ReadonlyUint8Array,
Rpc,
sequentialInstructionPlan,
TransactionPlanner,
TransactionSigner,
} from '@solana/kit';
import {
Expand All @@ -19,16 +24,9 @@ import {
PROGRAM_METADATA_PROGRAM_ADDRESS,
} from './generated';
import {
createDefaultTransactionPlanExecutor,
InstructionPlan,
isValidInstructionPlan,
parallelInstructionPlan,
sequentialInstructionPlan,
TransactionPlanner,
} from './instructionPlans';
import {
getDefaultTransactionPlannerAndExecutor,
createDefaultTransactionPlannerAndExecutor,
getPdaDetails,
isValidInstructionPlan,
REALLOC_LIMIT,
} from './internals';
import {
Expand All @@ -41,14 +39,15 @@ import {

export async function createMetadata(
input: MetadataInput & {
rpc: Rpc<GetMinimumBalanceForRentExemptionApi> &
Parameters<typeof createDefaultTransactionPlanExecutor>[0]['rpc'];
rpc: Rpc<GetAccountInfoApi & GetMinimumBalanceForRentExemptionApi> &
Parameters<typeof createDefaultTransactionPlannerAndExecutor>[0]['rpc'];
rpcSubscriptions: Parameters<
typeof createDefaultTransactionPlanExecutor
typeof createDefaultTransactionPlannerAndExecutor
>[0]['rpcSubscriptions'];
}
): Promise<MetadataResponse> {
const { planner, executor } = getDefaultTransactionPlannerAndExecutor(input);
const { planner, executor } =
createDefaultTransactionPlannerAndExecutor(input);
const [{ programData, isCanonical, metadata }, buffer] = await Promise.all([
getPdaDetails(input),
input.buffer
Expand Down
43 changes: 22 additions & 21 deletions clients/js/src/generated/instructions/allocate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ import {
getU8Encoder,
none,
transformEncoder,
type AccountMeta,
type AccountSignerMeta,
type Address,
type Codec,
type Decoder,
type Encoder,
type IAccountMeta,
type IAccountSignerMeta,
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type Instruction,
type InstructionWithAccounts,
type InstructionWithData,
type Option,
type OptionOrNullable,
type ReadonlyAccount,
type ReadonlySignerAccount,
type ReadonlyUint8Array,
type TransactionSigner,
type WritableAccount,
} from '@solana/kit';
Expand All @@ -49,24 +50,24 @@ export function getAllocateDiscriminatorBytes() {

export type AllocateInstruction<
TProgram extends string = typeof PROGRAM_METADATA_PROGRAM_ADDRESS,
TAccountBuffer extends string | IAccountMeta<string> = string,
TAccountAuthority extends string | IAccountMeta<string> = string,
TAccountProgram extends string | IAccountMeta<string> = string,
TAccountProgramData extends string | IAccountMeta<string> = string,
TAccountBuffer extends string | AccountMeta<string> = string,
TAccountAuthority extends string | AccountMeta<string> = string,
TAccountProgram extends string | AccountMeta<string> = string,
TAccountProgramData extends string | AccountMeta<string> = string,
TAccountSystem extends
| string
| IAccountMeta<string> = '11111111111111111111111111111111',
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
| AccountMeta<string> = '11111111111111111111111111111111',
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountBuffer extends string
? WritableAccount<TAccountBuffer>
: TAccountBuffer,
TAccountAuthority extends string
? ReadonlySignerAccount<TAccountAuthority> &
IAccountSignerMeta<TAccountAuthority>
AccountSignerMeta<TAccountAuthority>
: TAccountAuthority,
TAccountProgram extends string
? ReadonlyAccount<TAccountProgram>
Expand Down Expand Up @@ -220,7 +221,7 @@ export function getAllocateInstruction<

export type ParsedAllocateInstruction<
TProgram extends string = typeof PROGRAM_METADATA_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
Expand All @@ -240,19 +241,19 @@ export type ParsedAllocateInstruction<

export function parseAllocateInstruction<
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>
): ParsedAllocateInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
// 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