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
6 changes: 3 additions & 3 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
},
"homepage": "https://github.com/solana-program/compute-budget#readme",
"peerDependencies": {
"@solana/kit": "^2.1.0"
"@solana/kit": "^3.0"
},
"devDependencies": {
"@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",
"eslint": "^8.57.0",
Expand Down
717 changes: 376 additions & 341 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions clients/js/src/estimateAndSetComputeLimit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
CompilableTransactionMessage,
ITransactionMessageWithFeePayer,
TransactionMessage,
BaseTransactionMessage,
TransactionMessageWithFeePayer,
} from '@solana/kit';
import {
MAX_COMPUTE_UNIT_LIMIT,
Expand All @@ -15,9 +14,8 @@ import { getSetComputeUnitLimitInstructionIndexAndUnits } from './internal';
import { updateOrAppendSetComputeUnitLimitInstruction } from './setComputeLimit';

type EstimateAndUpdateProvisoryComputeUnitLimitFactoryFunction = <
TTransactionMessage extends
| CompilableTransactionMessage
| (TransactionMessage & ITransactionMessageWithFeePayer),
TTransactionMessage extends BaseTransactionMessage &
TransactionMessageWithFeePayer,
>(
transactionMessage: TTransactionMessage,
config?: EstimateComputeUnitLimitFactoryFunctionConfig
Expand Down
21 changes: 8 additions & 13 deletions clients/js/src/estimateComputeLimitInternal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {
BaseTransactionMessage,
Commitment,
CompilableTransactionMessage,
compileTransaction,
getBase64EncodedWireTransaction,
isDurableNonceTransaction,
isSolanaError,
ITransactionMessageWithFeePayer,
isTransactionMessageWithDurableNonceLifetime,
pipe,
Rpc,
SimulateTransactionApi,
Expand All @@ -14,21 +13,18 @@ import {
SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT,
SolanaError,
Transaction,
TransactionMessage,
TransactionMessageWithFeePayer,
} from '@solana/kit';
import { updateOrAppendSetComputeUnitLimitInstruction } from './setComputeLimit';
import { MAX_COMPUTE_UNIT_LIMIT } from './constants';
import { fillMissingTransactionMessageLifetimeUsingProvisoryBlockhash } from './internalMoveToKit';

export type EstimateComputeUnitLimitFactoryConfig = Readonly<{
/** An object that supports the {@link SimulateTransactionApi} of the Solana RPC API */
rpc: Rpc<SimulateTransactionApi>;
}>;

export type EstimateComputeUnitLimitFactoryFunction = (
transactionMessage:
| CompilableTransactionMessage
| (TransactionMessage & ITransactionMessageWithFeePayer),
transactionMessage: BaseTransactionMessage & TransactionMessageWithFeePayer,
config?: EstimateComputeUnitLimitFactoryFunctionConfig
) => Promise<number>;

Expand All @@ -54,9 +50,8 @@ type EstimateComputeUnitLimitConfig =
EstimateComputeUnitLimitFactoryFunctionConfig &
Readonly<{
rpc: Rpc<SimulateTransactionApi>;
transactionMessage:
| CompilableTransactionMessage
| (TransactionMessage & ITransactionMessageWithFeePayer);
transactionMessage: BaseTransactionMessage &
TransactionMessageWithFeePayer;
}>;

/**
Expand Down Expand Up @@ -120,10 +115,10 @@ export async function estimateComputeUnitLimit({
transactionMessage,
...configs
}: EstimateComputeUnitLimitConfig): Promise<number> {
const replaceRecentBlockhash = !isDurableNonceTransaction(transactionMessage);
const replaceRecentBlockhash =
!isTransactionMessageWithDurableNonceLifetime(transactionMessage);
const transaction = pipe(
transactionMessage,
fillMissingTransactionMessageLifetimeUsingProvisoryBlockhash,
(m) =>
updateOrAppendSetComputeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT, m),
compileTransaction
Expand Down
31 changes: 16 additions & 15 deletions clients/js/src/generated/instructions/requestHeapFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ 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 ReadonlyUint8Array,
} from '@solana/kit';
import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '../programs';

Expand All @@ -34,10 +35,10 @@ export function getRequestHeapFrameDiscriminatorBytes() {

export type RequestHeapFrameInstruction<
TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<TRemainingAccounts>;
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<TRemainingAccounts>;

export type RequestHeapFrameInstructionData = {
discriminator: number;
Expand All @@ -56,7 +57,7 @@ export type RequestHeapFrameInstructionDataArgs = {
bytes: number;
};

export function getRequestHeapFrameInstructionDataEncoder(): Encoder<RequestHeapFrameInstructionDataArgs> {
export function getRequestHeapFrameInstructionDataEncoder(): FixedSizeEncoder<RequestHeapFrameInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
Expand All @@ -66,14 +67,14 @@ export function getRequestHeapFrameInstructionDataEncoder(): Encoder<RequestHeap
);
}

export function getRequestHeapFrameInstructionDataDecoder(): Decoder<RequestHeapFrameInstructionData> {
export function getRequestHeapFrameInstructionDataDecoder(): FixedSizeDecoder<RequestHeapFrameInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['bytes', getU32Decoder()],
]);
}

export function getRequestHeapFrameInstructionDataCodec(): Codec<
export function getRequestHeapFrameInstructionDataCodec(): FixedSizeCodec<
RequestHeapFrameInstructionDataArgs,
RequestHeapFrameInstructionData
> {
Expand Down Expand Up @@ -118,7 +119,7 @@ export type ParsedRequestHeapFrameInstruction<
};

export function parseRequestHeapFrameInstruction<TProgram extends string>(
instruction: IInstruction<TProgram> & IInstructionWithData<Uint8Array>
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>
): ParsedRequestHeapFrameInstruction<TProgram> {
return {
programAddress: instruction.programAddress,
Expand Down
31 changes: 16 additions & 15 deletions clients/js/src/generated/instructions/requestUnits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ 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 ReadonlyUint8Array,
} from '@solana/kit';
import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '../programs';

Expand All @@ -34,10 +35,10 @@ export function getRequestUnitsDiscriminatorBytes() {

export type RequestUnitsInstruction<
TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<TRemainingAccounts>;
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<TRemainingAccounts>;

export type RequestUnitsInstructionData = {
discriminator: number;
Expand All @@ -54,7 +55,7 @@ export type RequestUnitsInstructionDataArgs = {
additionalFee: number;
};

export function getRequestUnitsInstructionDataEncoder(): Encoder<RequestUnitsInstructionDataArgs> {
export function getRequestUnitsInstructionDataEncoder(): FixedSizeEncoder<RequestUnitsInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
Expand All @@ -65,15 +66,15 @@ export function getRequestUnitsInstructionDataEncoder(): Encoder<RequestUnitsIns
);
}

export function getRequestUnitsInstructionDataDecoder(): Decoder<RequestUnitsInstructionData> {
export function getRequestUnitsInstructionDataDecoder(): FixedSizeDecoder<RequestUnitsInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['units', getU32Decoder()],
['additionalFee', getU32Decoder()],
]);
}

export function getRequestUnitsInstructionDataCodec(): Codec<
export function getRequestUnitsInstructionDataCodec(): FixedSizeCodec<
RequestUnitsInstructionDataArgs,
RequestUnitsInstructionData
> {
Expand Down Expand Up @@ -119,7 +120,7 @@ export type ParsedRequestUnitsInstruction<
};

export function parseRequestUnitsInstruction<TProgram extends string>(
instruction: IInstruction<TProgram> & IInstructionWithData<Uint8Array>
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>
): ParsedRequestUnitsInstruction<TProgram> {
return {
programAddress: instruction.programAddress,
Expand Down
31 changes: 16 additions & 15 deletions clients/js/src/generated/instructions/setComputeUnitLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ 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 ReadonlyUint8Array,
} from '@solana/kit';
import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '../programs';

Expand All @@ -34,10 +35,10 @@ export function getSetComputeUnitLimitDiscriminatorBytes() {

export type SetComputeUnitLimitInstruction<
TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<TRemainingAccounts>;
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<TRemainingAccounts>;

export type SetComputeUnitLimitInstructionData = {
discriminator: number;
Expand All @@ -50,7 +51,7 @@ export type SetComputeUnitLimitInstructionDataArgs = {
units: number;
};

export function getSetComputeUnitLimitInstructionDataEncoder(): Encoder<SetComputeUnitLimitInstructionDataArgs> {
export function getSetComputeUnitLimitInstructionDataEncoder(): FixedSizeEncoder<SetComputeUnitLimitInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
Expand All @@ -63,14 +64,14 @@ export function getSetComputeUnitLimitInstructionDataEncoder(): Encoder<SetCompu
);
}

export function getSetComputeUnitLimitInstructionDataDecoder(): Decoder<SetComputeUnitLimitInstructionData> {
export function getSetComputeUnitLimitInstructionDataDecoder(): FixedSizeDecoder<SetComputeUnitLimitInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['units', getU32Decoder()],
]);
}

export function getSetComputeUnitLimitInstructionDataCodec(): Codec<
export function getSetComputeUnitLimitInstructionDataCodec(): FixedSizeCodec<
SetComputeUnitLimitInstructionDataArgs,
SetComputeUnitLimitInstructionData
> {
Expand Down Expand Up @@ -115,7 +116,7 @@ export type ParsedSetComputeUnitLimitInstruction<
};

export function parseSetComputeUnitLimitInstruction<TProgram extends string>(
instruction: IInstruction<TProgram> & IInstructionWithData<Uint8Array>
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>
): ParsedSetComputeUnitLimitInstruction<TProgram> {
return {
programAddress: instruction.programAddress,
Expand Down
31 changes: 16 additions & 15 deletions clients/js/src/generated/instructions/setComputeUnitPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ 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 ReadonlyUint8Array,
} from '@solana/kit';
import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '../programs';

Expand All @@ -34,10 +35,10 @@ export function getSetComputeUnitPriceDiscriminatorBytes() {

export type SetComputeUnitPriceInstruction<
TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<TRemainingAccounts>;
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<TRemainingAccounts>;

export type SetComputeUnitPriceInstructionData = {
discriminator: number;
Expand All @@ -50,7 +51,7 @@ export type SetComputeUnitPriceInstructionDataArgs = {
microLamports: number | bigint;
};

export function getSetComputeUnitPriceInstructionDataEncoder(): Encoder<SetComputeUnitPriceInstructionDataArgs> {
export function getSetComputeUnitPriceInstructionDataEncoder(): FixedSizeEncoder<SetComputeUnitPriceInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
Expand All @@ -63,14 +64,14 @@ export function getSetComputeUnitPriceInstructionDataEncoder(): Encoder<SetCompu
);
}

export function getSetComputeUnitPriceInstructionDataDecoder(): Decoder<SetComputeUnitPriceInstructionData> {
export function getSetComputeUnitPriceInstructionDataDecoder(): FixedSizeDecoder<SetComputeUnitPriceInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['microLamports', getU64Decoder()],
]);
}

export function getSetComputeUnitPriceInstructionDataCodec(): Codec<
export function getSetComputeUnitPriceInstructionDataCodec(): FixedSizeCodec<
SetComputeUnitPriceInstructionDataArgs,
SetComputeUnitPriceInstructionData
> {
Expand Down Expand Up @@ -115,7 +116,7 @@ export type ParsedSetComputeUnitPriceInstruction<
};

export function parseSetComputeUnitPriceInstruction<TProgram extends string>(
instruction: IInstruction<TProgram> & IInstructionWithData<Uint8Array>
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>
): ParsedSetComputeUnitPriceInstruction<TProgram> {
return {
programAddress: instruction.programAddress,
Expand Down
Loading