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
9 changes: 0 additions & 9 deletions clients/js/.prettierrc.json

This file was deleted.

122 changes: 61 additions & 61 deletions clients/js/package.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
{
"name": "@solana-program/compute-budget",
"version": "0.11.0",
"description": "JavaScript client for the Compute Budget program",
"sideEffects": false,
"module": "./dist/src/index.mjs",
"main": "./dist/src/index.js",
"types": "./dist/types/index.d.ts",
"type": "commonjs",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/src/index.mjs",
"require": "./dist/src/index.js"
}
},
"files": [
"./dist/src",
"./dist/types"
],
"scripts": {
"build": "rimraf dist && tsup && tsc -p ./tsconfig.declarations.json",
"build:docs": "typedoc",
"dev": "vitest",
"test": "vitest run",
"lint": "eslint --ext js,ts,tsx src",
"lint:fix": "eslint --fix --ext js,ts,tsx src",
"format": "prettier --check src test",
"format:fix": "prettier --write src test",
"prepublishOnly": "pnpm build"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/solana-program/compute-budget.git"
},
"bugs": {
"url": "https://github.com/solana-program/compute-budget/issues"
},
"homepage": "https://github.com/solana-program/compute-budget#readme",
"peerDependencies": {
"@solana/kit": "^5.0"
},
"devDependencies": {
"@solana/eslint-config-solana": "^3.0.3",
"@solana/kit": "^5.0",
"@types/node": "^24",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"eslint": "^8.57.0",
"prettier": "^3.3.3",
"rimraf": "^5.0.5",
"tsup": "^8.1.2",
"typedoc": "^0.25.12",
"typescript": "^5.5.3",
"vitest": "^3.1.3"
},
"packageManager": "pnpm@9.1.0"
"name": "@solana-program/compute-budget",
"version": "0.11.0",
"description": "JavaScript client for the Compute Budget program",
"sideEffects": false,
"module": "./dist/src/index.mjs",
"main": "./dist/src/index.js",
"types": "./dist/types/index.d.ts",
"type": "commonjs",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/src/index.mjs",
"require": "./dist/src/index.js"
}
},
"files": [
"./dist/src",
"./dist/types"
],
"scripts": {
"build": "rimraf dist && tsup && tsc -p ./tsconfig.declarations.json",
"build:docs": "typedoc",
"dev": "vitest",
"test": "vitest run",
"lint": "eslint --ext js,ts,tsx src",
"lint:fix": "eslint --fix --ext js,ts,tsx src",
"format": "prettier --check src test",
"format:fix": "prettier --write src test",
"prepublishOnly": "pnpm build"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/solana-program/compute-budget.git"
},
"bugs": {
"url": "https://github.com/solana-program/compute-budget/issues"
},
"homepage": "https://github.com/solana-program/compute-budget#readme",
"peerDependencies": {
"@solana/kit": "^5.0"
},
"devDependencies": {
"@solana/eslint-config-solana": "^3.0.3",
"@solana/kit": "^5.0",
"@types/node": "^24",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"eslint": "^8.57.0",
"prettier": "^3.3.3",
"rimraf": "^5.0.5",
"tsup": "^8.1.2",
"typedoc": "^0.25.12",
"typescript": "^5.5.3",
"vitest": "^3.1.3"
},
"packageManager": "pnpm@9.1.0"
}
58 changes: 25 additions & 33 deletions clients/js/src/estimateAndSetComputeLimit.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import { BaseTransactionMessage, TransactionMessageWithFeePayer } from '@solana/kit';
import { MAX_COMPUTE_UNIT_LIMIT, PROVISORY_COMPUTE_UNIT_LIMIT } from './constants';
import {
BaseTransactionMessage,
TransactionMessageWithFeePayer,
} from '@solana/kit';
import {
MAX_COMPUTE_UNIT_LIMIT,
PROVISORY_COMPUTE_UNIT_LIMIT,
} from './constants';
import {
EstimateComputeUnitLimitFactoryFunction,
EstimateComputeUnitLimitFactoryFunctionConfig,
EstimateComputeUnitLimitFactoryFunction,
EstimateComputeUnitLimitFactoryFunctionConfig,
} from './estimateComputeLimitInternal';
import { getSetComputeUnitLimitInstructionIndexAndUnits } from './internal';
import { updateOrAppendSetComputeUnitLimitInstruction } from './setComputeLimit';

type EstimateAndUpdateProvisoryComputeUnitLimitFactoryFunction = <
TTransactionMessage extends BaseTransactionMessage &
TransactionMessageWithFeePayer,
TTransactionMessage extends BaseTransactionMessage & TransactionMessageWithFeePayer,
>(
transactionMessage: TTransactionMessage,
config?: EstimateComputeUnitLimitFactoryFunctionConfig
transactionMessage: TTransactionMessage,
config?: EstimateComputeUnitLimitFactoryFunctionConfig,
) => Promise<TTransactionMessage>;

/**
Expand All @@ -40,26 +33,25 @@ type EstimateAndUpdateProvisoryComputeUnitLimitFactoryFunction = <
* @see {@link estimateAndUpdateProvisoryComputeUnitLimitFactory}
*/
export function estimateAndUpdateProvisoryComputeUnitLimitFactory(
estimateComputeUnitLimit: EstimateComputeUnitLimitFactoryFunction
estimateComputeUnitLimit: EstimateComputeUnitLimitFactoryFunction,
): EstimateAndUpdateProvisoryComputeUnitLimitFactoryFunction {
return async function fn(transactionMessage, config) {
const instructionDetails =
getSetComputeUnitLimitInstructionIndexAndUnits(transactionMessage);
return async function fn(transactionMessage, config) {
const instructionDetails = getSetComputeUnitLimitInstructionIndexAndUnits(transactionMessage);

// If the transaction message already has a compute unit limit instruction
// which is set to a specific value — i.e. not 0 or the maximum limit —
// we don't need to estimate the compute unit limit.
if (
instructionDetails &&
instructionDetails.units !== PROVISORY_COMPUTE_UNIT_LIMIT &&
instructionDetails.units !== MAX_COMPUTE_UNIT_LIMIT
) {
return transactionMessage;
}
// If the transaction message already has a compute unit limit instruction
// which is set to a specific value — i.e. not 0 or the maximum limit —
// we don't need to estimate the compute unit limit.
if (
instructionDetails &&
instructionDetails.units !== PROVISORY_COMPUTE_UNIT_LIMIT &&
instructionDetails.units !== MAX_COMPUTE_UNIT_LIMIT
) {
return transactionMessage;
}

return updateOrAppendSetComputeUnitLimitInstruction(
await estimateComputeUnitLimit(transactionMessage, config),
transactionMessage
);
};
return updateOrAppendSetComputeUnitLimitInstruction(
await estimateComputeUnitLimit(transactionMessage, config),
transactionMessage,
);
};
}
25 changes: 11 additions & 14 deletions clients/js/src/estimateComputeLimit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
estimateComputeUnitLimit,
EstimateComputeUnitLimitFactoryConfig,
EstimateComputeUnitLimitFactoryFunction,
estimateComputeUnitLimit,
EstimateComputeUnitLimitFactoryConfig,
EstimateComputeUnitLimitFactoryFunction,
} from './estimateComputeLimitInternal';

/**
Expand Down Expand Up @@ -65,16 +65,13 @@ import {
* ```
*/
export function estimateComputeUnitLimitFactory({
rpc,
rpc,
}: EstimateComputeUnitLimitFactoryConfig): EstimateComputeUnitLimitFactoryFunction {
return async function estimateComputeUnitLimitFactoryFunction(
transactionMessage,
config
) {
return await estimateComputeUnitLimit({
...config,
rpc,
transactionMessage,
});
};
return async function estimateComputeUnitLimitFactoryFunction(transactionMessage, config) {
return await estimateComputeUnitLimit({
...config,
rpc,
transactionMessage,
});
};
}
Loading