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
4 changes: 2 additions & 2 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
},
"homepage": "https://github.com/solana-program/compute-budget#readme",
"peerDependencies": {
"@solana/kit": "^6.0.0"
"@solana/kit": "^6.1.0"
},
"devDependencies": {
"@solana/eslint-config-solana": "^3.0.3",
"@solana/kit": "^6.0.0",
"@solana/kit": "^6.1.0",
"@types/node": "^24",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
Expand Down
678 changes: 364 additions & 314 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

69 changes: 67 additions & 2 deletions clients/js/src/generated/programs/computeBudget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
import {
containsBytes,
getU8Encoder,
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
SolanaError,
type Address,
type ClientWithTransactionPlanning,
type ClientWithTransactionSending,
type Instruction,
type InstructionWithData,
type ReadonlyUint8Array,
} from '@solana/kit';
import { addSelfPlanAndSendFunctions, type SelfPlanAndSendFunctions } from '@solana/kit/program-client-core';
import {
getRequestHeapFrameInstruction,
getRequestUnitsInstruction,
getSetComputeUnitLimitInstruction,
getSetComputeUnitPriceInstruction,
getSetLoadedAccountsDataSizeLimitInstruction,
parseRequestHeapFrameInstruction,
parseRequestUnitsInstruction,
parseSetComputeUnitLimitInstruction,
Expand All @@ -25,6 +36,11 @@ import {
type ParsedSetComputeUnitLimitInstruction,
type ParsedSetComputeUnitPriceInstruction,
type ParsedSetLoadedAccountsDataSizeLimitInstruction,
type RequestHeapFrameInput,
type RequestUnitsInput,
type SetComputeUnitLimitInput,
type SetComputeUnitPriceInput,
type SetLoadedAccountsDataSizeLimitInput,
} from '../instructions';

export const COMPUTE_BUDGET_PROGRAM_ADDRESS =
Expand Down Expand Up @@ -57,7 +73,10 @@ export function identifyComputeBudgetInstruction(
if (containsBytes(data, getU8Encoder().encode(4), 0)) {
return ComputeBudgetInstruction.SetLoadedAccountsDataSizeLimit;
}
throw new Error('The provided instruction could not be identified as a computeBudget instruction.');
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, {
instructionData: data,
programName: 'computeBudget',
});
}

export type ParsedComputeBudgetInstruction<TProgram extends string = 'ComputeBudget111111111111111111111111111111'> =
Expand Down Expand Up @@ -109,6 +128,52 @@ export function parseComputeBudgetInstruction<TProgram extends string>(
};
}
default:
throw new Error(`Unrecognized instruction type: ${instructionType as string}`);
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, {
instructionType: instructionType as string,
programName: 'computeBudget',
});
}
}

export type ComputeBudgetPlugin = { instructions: ComputeBudgetPluginInstructions };

export type ComputeBudgetPluginInstructions = {
requestUnits: (
input: RequestUnitsInput,
) => ReturnType<typeof getRequestUnitsInstruction> & SelfPlanAndSendFunctions;
requestHeapFrame: (
input: RequestHeapFrameInput,
) => ReturnType<typeof getRequestHeapFrameInstruction> & SelfPlanAndSendFunctions;
setComputeUnitLimit: (
input: SetComputeUnitLimitInput,
) => ReturnType<typeof getSetComputeUnitLimitInstruction> & SelfPlanAndSendFunctions;
setComputeUnitPrice: (
input: SetComputeUnitPriceInput,
) => ReturnType<typeof getSetComputeUnitPriceInstruction> & SelfPlanAndSendFunctions;
setLoadedAccountsDataSizeLimit: (
input: SetLoadedAccountsDataSizeLimitInput,
) => ReturnType<typeof getSetLoadedAccountsDataSizeLimitInstruction> & SelfPlanAndSendFunctions;
};

export type ComputeBudgetPluginRequirements = ClientWithTransactionPlanning & ClientWithTransactionSending;

export function computeBudgetProgram() {
return <T extends ComputeBudgetPluginRequirements>(client: T) => {
return {
...client,
computeBudget: <ComputeBudgetPlugin>{
instructions: {
requestUnits: input => addSelfPlanAndSendFunctions(client, getRequestUnitsInstruction(input)),
requestHeapFrame: input =>
addSelfPlanAndSendFunctions(client, getRequestHeapFrameInstruction(input)),
setComputeUnitLimit: input =>
addSelfPlanAndSendFunctions(client, getSetComputeUnitLimitInstruction(input)),
setComputeUnitPrice: input =>
addSelfPlanAndSendFunctions(client, getSetComputeUnitPriceInstruction(input)),
setLoadedAccountsDataSizeLimit: input =>
addSelfPlanAndSendFunctions(client, getSetLoadedAccountsDataSizeLimitInstruction(input)),
},
},
};
};
}
125 changes: 0 additions & 125 deletions clients/js/src/generated/shared/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion clients/js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inlineSources": false,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down
3 changes: 2 additions & 1 deletion clients/js/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
__VERSION__: `"${env.npm_package_version}"`,
},
test: {
// ...
environment: 'node',
testTimeout: 15000,
},
});
8 changes: 1 addition & 7 deletions codama.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
"scripts": {
"js": {
"from": "@codama/renderers-js",
"args": [
"clients/js/src/generated",
{
"packageFolder": "clients/js",
"syncPackageJson": true
}
]
"args": ["clients/js", { "kitImportStrategy": "rootOnly" }]
},
"rust": {
"from": "@codama/renderers-rust",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"template:upgrade": "zx ./scripts/upgrade-template.mjs"
},
"devDependencies": {
"@codama/renderers-js": "^1.6",
"@codama/renderers-js": "^2.0.2",
"@codama/renderers-rust": "~1.0",
"@iarna/toml": "^2.2.5",
"@solana/prettier-config-solana": "0.0.6",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.