diff --git a/clients/js/.prettierrc.json b/clients/js/.prettierrc.json deleted file mode 100644 index 254c729..0000000 --- a/clients/js/.prettierrc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "semi": true, - "singleQuote": true, - "trailingComma": "es5", - "useTabs": false, - "tabWidth": 2, - "arrowParens": "always", - "printWidth": 80 -} diff --git a/clients/js/package.json b/clients/js/package.json index f442bfd..134e80e 100644 --- a/clients/js/package.json +++ b/clients/js/package.json @@ -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" } diff --git a/clients/js/src/estimateAndSetComputeLimit.ts b/clients/js/src/estimateAndSetComputeLimit.ts index 1cb97d1..da4e6e7 100644 --- a/clients/js/src/estimateAndSetComputeLimit.ts +++ b/clients/js/src/estimateAndSetComputeLimit.ts @@ -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; /** @@ -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, + ); + }; } diff --git a/clients/js/src/estimateComputeLimit.ts b/clients/js/src/estimateComputeLimit.ts index bfe5e48..918ed9f 100644 --- a/clients/js/src/estimateComputeLimit.ts +++ b/clients/js/src/estimateComputeLimit.ts @@ -1,7 +1,7 @@ import { - estimateComputeUnitLimit, - EstimateComputeUnitLimitFactoryConfig, - EstimateComputeUnitLimitFactoryFunction, + estimateComputeUnitLimit, + EstimateComputeUnitLimitFactoryConfig, + EstimateComputeUnitLimitFactoryFunction, } from './estimateComputeLimitInternal'; /** @@ -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, + }); + }; } diff --git a/clients/js/src/estimateComputeLimitInternal.ts b/clients/js/src/estimateComputeLimitInternal.ts index 65a51a9..9b1c398 100644 --- a/clients/js/src/estimateComputeLimitInternal.ts +++ b/clients/js/src/estimateComputeLimitInternal.ts @@ -1,57 +1,55 @@ import { - BaseTransactionMessage, - Commitment, - compileTransaction, - getBase64EncodedWireTransaction, - isSolanaError, - isTransactionMessageWithDurableNonceLifetime, - pipe, - Rpc, - SimulateTransactionApi, - Slot, - SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, - SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, - SolanaError, - Transaction, - TransactionMessageWithFeePayer, + BaseTransactionMessage, + Commitment, + compileTransaction, + getBase64EncodedWireTransaction, + isSolanaError, + isTransactionMessageWithDurableNonceLifetime, + pipe, + Rpc, + SimulateTransactionApi, + Slot, + SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, + SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, + SolanaError, + Transaction, + TransactionMessageWithFeePayer, } from '@solana/kit'; import { updateOrAppendSetComputeUnitLimitInstruction } from './setComputeLimit'; import { MAX_COMPUTE_UNIT_LIMIT } from './constants'; export type EstimateComputeUnitLimitFactoryConfig = Readonly<{ - /** An object that supports the {@link SimulateTransactionApi} of the Solana RPC API */ - rpc: Rpc; + /** An object that supports the {@link SimulateTransactionApi} of the Solana RPC API */ + rpc: Rpc; }>; export type EstimateComputeUnitLimitFactoryFunction = ( - transactionMessage: BaseTransactionMessage & TransactionMessageWithFeePayer, - config?: EstimateComputeUnitLimitFactoryFunctionConfig + transactionMessage: BaseTransactionMessage & TransactionMessageWithFeePayer, + config?: EstimateComputeUnitLimitFactoryFunctionConfig, ) => Promise; export type EstimateComputeUnitLimitFactoryFunctionConfig = { - abortSignal?: AbortSignal; - /** - * Compute the estimate as of the highest slot that has reached this level of commitment. - * - * @defaultValue Whichever default is applied by the underlying {@link RpcApi} in use. For - * example, when using an API created by a `createSolanaRpc*()` helper, the default commitment - * is `"confirmed"` unless configured otherwise. Unmitigated by an API layer on the client, the - * default commitment applied by the server is `"finalized"`. - */ - commitment?: Commitment; - /** - * Prevents accessing stale data by enforcing that the RPC node has processed transactions up to - * this slot - */ - minContextSlot?: Slot; + abortSignal?: AbortSignal; + /** + * Compute the estimate as of the highest slot that has reached this level of commitment. + * + * @defaultValue Whichever default is applied by the underlying {@link RpcApi} in use. For + * example, when using an API created by a `createSolanaRpc*()` helper, the default commitment + * is `"confirmed"` unless configured otherwise. Unmitigated by an API layer on the client, the + * default commitment applied by the server is `"finalized"`. + */ + commitment?: Commitment; + /** + * Prevents accessing stale data by enforcing that the RPC node has processed transactions up to + * this slot + */ + minContextSlot?: Slot; }; -type EstimateComputeUnitLimitConfig = - EstimateComputeUnitLimitFactoryFunctionConfig & +type EstimateComputeUnitLimitConfig = EstimateComputeUnitLimitFactoryFunctionConfig & Readonly<{ - rpc: Rpc; - transactionMessage: BaseTransactionMessage & - TransactionMessageWithFeePayer; + rpc: Rpc; + transactionMessage: BaseTransactionMessage & TransactionMessageWithFeePayer; }>; /** @@ -112,81 +110,61 @@ type EstimateComputeUnitLimitConfig = * > compute unit budget. */ export async function estimateComputeUnitLimit({ - transactionMessage, - ...configs -}: EstimateComputeUnitLimitConfig): Promise { - const replaceRecentBlockhash = - !isTransactionMessageWithDurableNonceLifetime(transactionMessage); - const transaction = pipe( transactionMessage, - (m) => - updateOrAppendSetComputeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT, m), - compileTransaction - ); + ...configs +}: EstimateComputeUnitLimitConfig): Promise { + const replaceRecentBlockhash = !isTransactionMessageWithDurableNonceLifetime(transactionMessage); + const transaction = pipe( + transactionMessage, + m => updateOrAppendSetComputeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT, m), + compileTransaction, + ); - return await simulateTransactionAndGetConsumedUnits({ - transaction, - replaceRecentBlockhash, - ...configs, - }); + return await simulateTransactionAndGetConsumedUnits({ + transaction, + replaceRecentBlockhash, + ...configs, + }); } -type SimulateTransactionAndGetConsumedUnitsConfig = Omit< - EstimateComputeUnitLimitConfig, - 'transactionMessage' -> & - Readonly<{ replaceRecentBlockhash?: boolean; transaction: Transaction }>; +type SimulateTransactionAndGetConsumedUnitsConfig = Omit & + Readonly<{ replaceRecentBlockhash?: boolean; transaction: Transaction }>; async function simulateTransactionAndGetConsumedUnits({ - abortSignal, - rpc, - transaction, - ...simulateConfig + abortSignal, + rpc, + transaction, + ...simulateConfig }: SimulateTransactionAndGetConsumedUnitsConfig): Promise { - const wireTransactionBytes = getBase64EncodedWireTransaction(transaction); + const wireTransactionBytes = getBase64EncodedWireTransaction(transaction); - try { - const { - value: { err: transactionError, unitsConsumed }, - } = await rpc - .simulateTransaction(wireTransactionBytes, { - ...simulateConfig, - encoding: 'base64', - sigVerify: false, - }) - .send({ abortSignal }); - if (unitsConsumed == null) { - // This should never be hit, because all RPCs should support `unitsConsumed` by now. - throw new SolanaError( - SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT - ); - } - // FIXME(https://github.com/anza-xyz/agave/issues/1295): The simulation response returns - // compute units as a u64, but the `SetComputeLimit` instruction only accepts a u32. Until - // this changes, downcast it. - const downcastUnitsConsumed = - unitsConsumed > 4_294_967_295n ? 4_294_967_295 : Number(unitsConsumed); - if (transactionError) { - throw new SolanaError( - SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, - { - cause: transactionError, - unitsConsumed: downcastUnitsConsumed, + try { + const { + value: { err: transactionError, unitsConsumed }, + } = await rpc + .simulateTransaction(wireTransactionBytes, { + ...simulateConfig, + encoding: 'base64', + sigVerify: false, + }) + .send({ abortSignal }); + if (unitsConsumed == null) { + // This should never be hit, because all RPCs should support `unitsConsumed` by now. + throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT); } - ); + // FIXME(https://github.com/anza-xyz/agave/issues/1295): The simulation response returns + // compute units as a u64, but the `SetComputeLimit` instruction only accepts a u32. Until + // this changes, downcast it. + const downcastUnitsConsumed = unitsConsumed > 4_294_967_295n ? 4_294_967_295 : Number(unitsConsumed); + if (transactionError) { + throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, { + cause: transactionError, + unitsConsumed: downcastUnitsConsumed, + }); + } + return downcastUnitsConsumed; + } catch (e) { + if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT)) throw e; + throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, { cause: e }); } - return downcastUnitsConsumed; - } catch (e) { - if ( - isSolanaError( - e, - SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT - ) - ) - throw e; - throw new SolanaError( - SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, - { cause: e } - ); - } } diff --git a/clients/js/src/generated/instructions/requestHeapFrame.ts b/clients/js/src/generated/instructions/requestHeapFrame.ts index 2f78c8e..0de0781 100644 --- a/clients/js/src/generated/instructions/requestHeapFrame.ts +++ b/clients/js/src/generated/instructions/requestHeapFrame.ts @@ -7,120 +7,108 @@ */ import { - combineCodec, - getStructDecoder, - getStructEncoder, - getU32Decoder, - getU32Encoder, - getU8Decoder, - getU8Encoder, - transformEncoder, - type AccountMeta, - type Address, - type FixedSizeCodec, - type FixedSizeDecoder, - type FixedSizeEncoder, - type Instruction, - type InstructionWithAccounts, - type InstructionWithData, - type ReadonlyUint8Array, + combineCodec, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyUint8Array, } from '@solana/kit'; import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '../programs'; export const REQUEST_HEAP_FRAME_DISCRIMINATOR = 1; export function getRequestHeapFrameDiscriminatorBytes() { - return getU8Encoder().encode(REQUEST_HEAP_FRAME_DISCRIMINATOR); + return getU8Encoder().encode(REQUEST_HEAP_FRAME_DISCRIMINATOR); } export type RequestHeapFrameInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, - TRemainingAccounts extends readonly AccountMeta[] = [], -> = Instruction & - InstructionWithData & - InstructionWithAccounts; + TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & InstructionWithData & InstructionWithAccounts; export type RequestHeapFrameInstructionData = { - discriminator: number; - /** - * Requested transaction-wide program heap size in bytes. - * Must be multiple of 1024. Applies to each program, including CPIs. - */ - bytes: number; + discriminator: number; + /** + * Requested transaction-wide program heap size in bytes. + * Must be multiple of 1024. Applies to each program, including CPIs. + */ + bytes: number; }; export type RequestHeapFrameInstructionDataArgs = { - /** - * Requested transaction-wide program heap size in bytes. - * Must be multiple of 1024. Applies to each program, including CPIs. - */ - bytes: number; + /** + * Requested transaction-wide program heap size in bytes. + * Must be multiple of 1024. Applies to each program, including CPIs. + */ + bytes: number; }; export function getRequestHeapFrameInstructionDataEncoder(): FixedSizeEncoder { - return transformEncoder( - getStructEncoder([ - ['discriminator', getU8Encoder()], - ['bytes', getU32Encoder()], - ]), - (value) => ({ ...value, discriminator: REQUEST_HEAP_FRAME_DISCRIMINATOR }) - ); + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['bytes', getU32Encoder()], + ]), + value => ({ ...value, discriminator: REQUEST_HEAP_FRAME_DISCRIMINATOR }), + ); } export function getRequestHeapFrameInstructionDataDecoder(): FixedSizeDecoder { - return getStructDecoder([ - ['discriminator', getU8Decoder()], - ['bytes', getU32Decoder()], - ]); + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['bytes', getU32Decoder()], + ]); } export function getRequestHeapFrameInstructionDataCodec(): FixedSizeCodec< - RequestHeapFrameInstructionDataArgs, - RequestHeapFrameInstructionData + RequestHeapFrameInstructionDataArgs, + RequestHeapFrameInstructionData > { - return combineCodec( - getRequestHeapFrameInstructionDataEncoder(), - getRequestHeapFrameInstructionDataDecoder() - ); + return combineCodec(getRequestHeapFrameInstructionDataEncoder(), getRequestHeapFrameInstructionDataDecoder()); } export type RequestHeapFrameInput = { - bytes: RequestHeapFrameInstructionDataArgs['bytes']; + bytes: RequestHeapFrameInstructionDataArgs['bytes']; }; -export function getRequestHeapFrameInstruction< - TProgramAddress extends Address = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, ->( - input: RequestHeapFrameInput, - config?: { programAddress?: TProgramAddress } +export function getRequestHeapFrameInstruction( + input: RequestHeapFrameInput, + config?: { programAddress?: TProgramAddress }, ): RequestHeapFrameInstruction { - // Program address. - const programAddress = - config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; + // Program address. + const programAddress = config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; - // Original args. - const args = { ...input }; + // Original args. + const args = { ...input }; - return Object.freeze({ - data: getRequestHeapFrameInstructionDataEncoder().encode( - args as RequestHeapFrameInstructionDataArgs - ), - programAddress, - } as RequestHeapFrameInstruction); + return Object.freeze({ + data: getRequestHeapFrameInstructionDataEncoder().encode(args as RequestHeapFrameInstructionDataArgs), + programAddress, + } as RequestHeapFrameInstruction); } -export type ParsedRequestHeapFrameInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, -> = { - programAddress: Address; - data: RequestHeapFrameInstructionData; +export type ParsedRequestHeapFrameInstruction = { + programAddress: Address; + data: RequestHeapFrameInstructionData; }; export function parseRequestHeapFrameInstruction( - instruction: Instruction & InstructionWithData + instruction: Instruction & InstructionWithData, ): ParsedRequestHeapFrameInstruction { - return { - programAddress: instruction.programAddress, - data: getRequestHeapFrameInstructionDataDecoder().decode(instruction.data), - }; + return { + programAddress: instruction.programAddress, + data: getRequestHeapFrameInstructionDataDecoder().decode(instruction.data), + }; } diff --git a/clients/js/src/generated/instructions/requestUnits.ts b/clients/js/src/generated/instructions/requestUnits.ts index cff56a5..abc4f43 100644 --- a/clients/js/src/generated/instructions/requestUnits.ts +++ b/clients/js/src/generated/instructions/requestUnits.ts @@ -7,118 +7,109 @@ */ import { - combineCodec, - getStructDecoder, - getStructEncoder, - getU32Decoder, - getU32Encoder, - getU8Decoder, - getU8Encoder, - transformEncoder, - type AccountMeta, - type Address, - type FixedSizeCodec, - type FixedSizeDecoder, - type FixedSizeEncoder, - type Instruction, - type InstructionWithAccounts, - type InstructionWithData, - type ReadonlyUint8Array, + combineCodec, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyUint8Array, } from '@solana/kit'; import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '../programs'; export const REQUEST_UNITS_DISCRIMINATOR = 0; export function getRequestUnitsDiscriminatorBytes() { - return getU8Encoder().encode(REQUEST_UNITS_DISCRIMINATOR); + return getU8Encoder().encode(REQUEST_UNITS_DISCRIMINATOR); } export type RequestUnitsInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, - TRemainingAccounts extends readonly AccountMeta[] = [], -> = Instruction & - InstructionWithData & - InstructionWithAccounts; + TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & InstructionWithData & InstructionWithAccounts; export type RequestUnitsInstructionData = { - discriminator: number; - /** Units to request for transaction-wide compute. */ - units: number; - /** Prioritization fee lamports. */ - additionalFee: number; + discriminator: number; + /** Units to request for transaction-wide compute. */ + units: number; + /** Prioritization fee lamports. */ + additionalFee: number; }; export type RequestUnitsInstructionDataArgs = { - /** Units to request for transaction-wide compute. */ - units: number; - /** Prioritization fee lamports. */ - additionalFee: number; + /** Units to request for transaction-wide compute. */ + units: number; + /** Prioritization fee lamports. */ + additionalFee: number; }; export function getRequestUnitsInstructionDataEncoder(): FixedSizeEncoder { - return transformEncoder( - getStructEncoder([ - ['discriminator', getU8Encoder()], - ['units', getU32Encoder()], - ['additionalFee', getU32Encoder()], - ]), - (value) => ({ ...value, discriminator: REQUEST_UNITS_DISCRIMINATOR }) - ); + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['units', getU32Encoder()], + ['additionalFee', getU32Encoder()], + ]), + value => ({ ...value, discriminator: REQUEST_UNITS_DISCRIMINATOR }), + ); } export function getRequestUnitsInstructionDataDecoder(): FixedSizeDecoder { - return getStructDecoder([ - ['discriminator', getU8Decoder()], - ['units', getU32Decoder()], - ['additionalFee', getU32Decoder()], - ]); + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['units', getU32Decoder()], + ['additionalFee', getU32Decoder()], + ]); } export function getRequestUnitsInstructionDataCodec(): FixedSizeCodec< - RequestUnitsInstructionDataArgs, - RequestUnitsInstructionData + RequestUnitsInstructionDataArgs, + RequestUnitsInstructionData > { - return combineCodec( - getRequestUnitsInstructionDataEncoder(), - getRequestUnitsInstructionDataDecoder() - ); + return combineCodec(getRequestUnitsInstructionDataEncoder(), getRequestUnitsInstructionDataDecoder()); } export type RequestUnitsInput = { - units: RequestUnitsInstructionDataArgs['units']; - additionalFee: RequestUnitsInstructionDataArgs['additionalFee']; + units: RequestUnitsInstructionDataArgs['units']; + additionalFee: RequestUnitsInstructionDataArgs['additionalFee']; }; -export function getRequestUnitsInstruction< - TProgramAddress extends Address = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, ->( - input: RequestUnitsInput, - config?: { programAddress?: TProgramAddress } +export function getRequestUnitsInstruction( + input: RequestUnitsInput, + config?: { programAddress?: TProgramAddress }, ): RequestUnitsInstruction { - // Program address. - const programAddress = - config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; + // Program address. + const programAddress = config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; - // Original args. - const args = { ...input }; + // Original args. + const args = { ...input }; - return Object.freeze({ - data: getRequestUnitsInstructionDataEncoder().encode( - args as RequestUnitsInstructionDataArgs - ), - programAddress, - } as RequestUnitsInstruction); + return Object.freeze({ + data: getRequestUnitsInstructionDataEncoder().encode(args as RequestUnitsInstructionDataArgs), + programAddress, + } as RequestUnitsInstruction); } -export type ParsedRequestUnitsInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, -> = { programAddress: Address; data: RequestUnitsInstructionData }; +export type ParsedRequestUnitsInstruction = { + programAddress: Address; + data: RequestUnitsInstructionData; +}; export function parseRequestUnitsInstruction( - instruction: Instruction & InstructionWithData + instruction: Instruction & InstructionWithData, ): ParsedRequestUnitsInstruction { - return { - programAddress: instruction.programAddress, - data: getRequestUnitsInstructionDataDecoder().decode(instruction.data), - }; + return { + programAddress: instruction.programAddress, + data: getRequestUnitsInstructionDataDecoder().decode(instruction.data), + }; } diff --git a/clients/js/src/generated/instructions/setComputeUnitLimit.ts b/clients/js/src/generated/instructions/setComputeUnitLimit.ts index ee81097..81ec2d6 100644 --- a/clients/js/src/generated/instructions/setComputeUnitLimit.ts +++ b/clients/js/src/generated/instructions/setComputeUnitLimit.ts @@ -7,119 +7,104 @@ */ import { - combineCodec, - getStructDecoder, - getStructEncoder, - getU32Decoder, - getU32Encoder, - getU8Decoder, - getU8Encoder, - transformEncoder, - type AccountMeta, - type Address, - type FixedSizeCodec, - type FixedSizeDecoder, - type FixedSizeEncoder, - type Instruction, - type InstructionWithAccounts, - type InstructionWithData, - type ReadonlyUint8Array, + combineCodec, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyUint8Array, } from '@solana/kit'; import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '../programs'; export const SET_COMPUTE_UNIT_LIMIT_DISCRIMINATOR = 2; export function getSetComputeUnitLimitDiscriminatorBytes() { - return getU8Encoder().encode(SET_COMPUTE_UNIT_LIMIT_DISCRIMINATOR); + return getU8Encoder().encode(SET_COMPUTE_UNIT_LIMIT_DISCRIMINATOR); } export type SetComputeUnitLimitInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, - TRemainingAccounts extends readonly AccountMeta[] = [], -> = Instruction & - InstructionWithData & - InstructionWithAccounts; + TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & InstructionWithData & InstructionWithAccounts; export type SetComputeUnitLimitInstructionData = { - discriminator: number; - /** Transaction-wide compute unit limit. */ - units: number; + discriminator: number; + /** Transaction-wide compute unit limit. */ + units: number; }; export type SetComputeUnitLimitInstructionDataArgs = { - /** Transaction-wide compute unit limit. */ - units: number; + /** Transaction-wide compute unit limit. */ + units: number; }; export function getSetComputeUnitLimitInstructionDataEncoder(): FixedSizeEncoder { - return transformEncoder( - getStructEncoder([ - ['discriminator', getU8Encoder()], - ['units', getU32Encoder()], - ]), - (value) => ({ - ...value, - discriminator: SET_COMPUTE_UNIT_LIMIT_DISCRIMINATOR, - }) - ); + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['units', getU32Encoder()], + ]), + value => ({ ...value, discriminator: SET_COMPUTE_UNIT_LIMIT_DISCRIMINATOR }), + ); } export function getSetComputeUnitLimitInstructionDataDecoder(): FixedSizeDecoder { - return getStructDecoder([ - ['discriminator', getU8Decoder()], - ['units', getU32Decoder()], - ]); + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['units', getU32Decoder()], + ]); } export function getSetComputeUnitLimitInstructionDataCodec(): FixedSizeCodec< - SetComputeUnitLimitInstructionDataArgs, - SetComputeUnitLimitInstructionData + SetComputeUnitLimitInstructionDataArgs, + SetComputeUnitLimitInstructionData > { - return combineCodec( - getSetComputeUnitLimitInstructionDataEncoder(), - getSetComputeUnitLimitInstructionDataDecoder() - ); + return combineCodec(getSetComputeUnitLimitInstructionDataEncoder(), getSetComputeUnitLimitInstructionDataDecoder()); } export type SetComputeUnitLimitInput = { - units: SetComputeUnitLimitInstructionDataArgs['units']; + units: SetComputeUnitLimitInstructionDataArgs['units']; }; export function getSetComputeUnitLimitInstruction< - TProgramAddress extends Address = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, + TProgramAddress extends Address = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, >( - input: SetComputeUnitLimitInput, - config?: { programAddress?: TProgramAddress } + input: SetComputeUnitLimitInput, + config?: { programAddress?: TProgramAddress }, ): SetComputeUnitLimitInstruction { - // Program address. - const programAddress = - config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; + // Program address. + const programAddress = config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; - // Original args. - const args = { ...input }; + // Original args. + const args = { ...input }; - return Object.freeze({ - data: getSetComputeUnitLimitInstructionDataEncoder().encode( - args as SetComputeUnitLimitInstructionDataArgs - ), - programAddress, - } as SetComputeUnitLimitInstruction); + return Object.freeze({ + data: getSetComputeUnitLimitInstructionDataEncoder().encode(args as SetComputeUnitLimitInstructionDataArgs), + programAddress, + } as SetComputeUnitLimitInstruction); } -export type ParsedSetComputeUnitLimitInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, -> = { - programAddress: Address; - data: SetComputeUnitLimitInstructionData; +export type ParsedSetComputeUnitLimitInstruction = { + programAddress: Address; + data: SetComputeUnitLimitInstructionData; }; export function parseSetComputeUnitLimitInstruction( - instruction: Instruction & InstructionWithData + instruction: Instruction & InstructionWithData, ): ParsedSetComputeUnitLimitInstruction { - return { - programAddress: instruction.programAddress, - data: getSetComputeUnitLimitInstructionDataDecoder().decode( - instruction.data - ), - }; + return { + programAddress: instruction.programAddress, + data: getSetComputeUnitLimitInstructionDataDecoder().decode(instruction.data), + }; } diff --git a/clients/js/src/generated/instructions/setComputeUnitPrice.ts b/clients/js/src/generated/instructions/setComputeUnitPrice.ts index 7d05803..add6f7e 100644 --- a/clients/js/src/generated/instructions/setComputeUnitPrice.ts +++ b/clients/js/src/generated/instructions/setComputeUnitPrice.ts @@ -7,119 +7,104 @@ */ import { - combineCodec, - getStructDecoder, - getStructEncoder, - getU64Decoder, - getU64Encoder, - getU8Decoder, - getU8Encoder, - transformEncoder, - type AccountMeta, - type Address, - type FixedSizeCodec, - type FixedSizeDecoder, - type FixedSizeEncoder, - type Instruction, - type InstructionWithAccounts, - type InstructionWithData, - type ReadonlyUint8Array, + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyUint8Array, } from '@solana/kit'; import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '../programs'; export const SET_COMPUTE_UNIT_PRICE_DISCRIMINATOR = 3; export function getSetComputeUnitPriceDiscriminatorBytes() { - return getU8Encoder().encode(SET_COMPUTE_UNIT_PRICE_DISCRIMINATOR); + return getU8Encoder().encode(SET_COMPUTE_UNIT_PRICE_DISCRIMINATOR); } export type SetComputeUnitPriceInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, - TRemainingAccounts extends readonly AccountMeta[] = [], -> = Instruction & - InstructionWithData & - InstructionWithAccounts; + TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & InstructionWithData & InstructionWithAccounts; export type SetComputeUnitPriceInstructionData = { - discriminator: number; - /** Transaction compute unit price used for prioritization fees. */ - microLamports: bigint; + discriminator: number; + /** Transaction compute unit price used for prioritization fees. */ + microLamports: bigint; }; export type SetComputeUnitPriceInstructionDataArgs = { - /** Transaction compute unit price used for prioritization fees. */ - microLamports: number | bigint; + /** Transaction compute unit price used for prioritization fees. */ + microLamports: number | bigint; }; export function getSetComputeUnitPriceInstructionDataEncoder(): FixedSizeEncoder { - return transformEncoder( - getStructEncoder([ - ['discriminator', getU8Encoder()], - ['microLamports', getU64Encoder()], - ]), - (value) => ({ - ...value, - discriminator: SET_COMPUTE_UNIT_PRICE_DISCRIMINATOR, - }) - ); + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['microLamports', getU64Encoder()], + ]), + value => ({ ...value, discriminator: SET_COMPUTE_UNIT_PRICE_DISCRIMINATOR }), + ); } export function getSetComputeUnitPriceInstructionDataDecoder(): FixedSizeDecoder { - return getStructDecoder([ - ['discriminator', getU8Decoder()], - ['microLamports', getU64Decoder()], - ]); + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['microLamports', getU64Decoder()], + ]); } export function getSetComputeUnitPriceInstructionDataCodec(): FixedSizeCodec< - SetComputeUnitPriceInstructionDataArgs, - SetComputeUnitPriceInstructionData + SetComputeUnitPriceInstructionDataArgs, + SetComputeUnitPriceInstructionData > { - return combineCodec( - getSetComputeUnitPriceInstructionDataEncoder(), - getSetComputeUnitPriceInstructionDataDecoder() - ); + return combineCodec(getSetComputeUnitPriceInstructionDataEncoder(), getSetComputeUnitPriceInstructionDataDecoder()); } export type SetComputeUnitPriceInput = { - microLamports: SetComputeUnitPriceInstructionDataArgs['microLamports']; + microLamports: SetComputeUnitPriceInstructionDataArgs['microLamports']; }; export function getSetComputeUnitPriceInstruction< - TProgramAddress extends Address = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, + TProgramAddress extends Address = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, >( - input: SetComputeUnitPriceInput, - config?: { programAddress?: TProgramAddress } + input: SetComputeUnitPriceInput, + config?: { programAddress?: TProgramAddress }, ): SetComputeUnitPriceInstruction { - // Program address. - const programAddress = - config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; + // Program address. + const programAddress = config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; - // Original args. - const args = { ...input }; + // Original args. + const args = { ...input }; - return Object.freeze({ - data: getSetComputeUnitPriceInstructionDataEncoder().encode( - args as SetComputeUnitPriceInstructionDataArgs - ), - programAddress, - } as SetComputeUnitPriceInstruction); + return Object.freeze({ + data: getSetComputeUnitPriceInstructionDataEncoder().encode(args as SetComputeUnitPriceInstructionDataArgs), + programAddress, + } as SetComputeUnitPriceInstruction); } -export type ParsedSetComputeUnitPriceInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, -> = { - programAddress: Address; - data: SetComputeUnitPriceInstructionData; +export type ParsedSetComputeUnitPriceInstruction = { + programAddress: Address; + data: SetComputeUnitPriceInstructionData; }; export function parseSetComputeUnitPriceInstruction( - instruction: Instruction & InstructionWithData + instruction: Instruction & InstructionWithData, ): ParsedSetComputeUnitPriceInstruction { - return { - programAddress: instruction.programAddress, - data: getSetComputeUnitPriceInstructionDataDecoder().decode( - instruction.data - ), - }; + return { + programAddress: instruction.programAddress, + data: getSetComputeUnitPriceInstructionDataDecoder().decode(instruction.data), + }; } diff --git a/clients/js/src/generated/instructions/setLoadedAccountsDataSizeLimit.ts b/clients/js/src/generated/instructions/setLoadedAccountsDataSizeLimit.ts index b84d520..3df16c4 100644 --- a/clients/js/src/generated/instructions/setLoadedAccountsDataSizeLimit.ts +++ b/clients/js/src/generated/instructions/setLoadedAccountsDataSizeLimit.ts @@ -7,121 +7,101 @@ */ import { - combineCodec, - getStructDecoder, - getStructEncoder, - getU32Decoder, - getU32Encoder, - getU8Decoder, - getU8Encoder, - transformEncoder, - type AccountMeta, - type Address, - type FixedSizeCodec, - type FixedSizeDecoder, - type FixedSizeEncoder, - type Instruction, - type InstructionWithAccounts, - type InstructionWithData, - type ReadonlyUint8Array, + combineCodec, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyUint8Array, } from '@solana/kit'; import { COMPUTE_BUDGET_PROGRAM_ADDRESS } from '../programs'; export const SET_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_DISCRIMINATOR = 4; export function getSetLoadedAccountsDataSizeLimitDiscriminatorBytes() { - return getU8Encoder().encode( - SET_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_DISCRIMINATOR - ); + return getU8Encoder().encode(SET_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_DISCRIMINATOR); } export type SetLoadedAccountsDataSizeLimitInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, - TRemainingAccounts extends readonly AccountMeta[] = [], -> = Instruction & - InstructionWithData & - InstructionWithAccounts; + TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & InstructionWithData & InstructionWithAccounts; -export type SetLoadedAccountsDataSizeLimitInstructionData = { - discriminator: number; - accountDataSizeLimit: number; -}; +export type SetLoadedAccountsDataSizeLimitInstructionData = { discriminator: number; accountDataSizeLimit: number }; -export type SetLoadedAccountsDataSizeLimitInstructionDataArgs = { - accountDataSizeLimit: number; -}; +export type SetLoadedAccountsDataSizeLimitInstructionDataArgs = { accountDataSizeLimit: number }; export function getSetLoadedAccountsDataSizeLimitInstructionDataEncoder(): FixedSizeEncoder { - return transformEncoder( - getStructEncoder([ - ['discriminator', getU8Encoder()], - ['accountDataSizeLimit', getU32Encoder()], - ]), - (value) => ({ - ...value, - discriminator: SET_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_DISCRIMINATOR, - }) - ); + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['accountDataSizeLimit', getU32Encoder()], + ]), + value => ({ ...value, discriminator: SET_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_DISCRIMINATOR }), + ); } export function getSetLoadedAccountsDataSizeLimitInstructionDataDecoder(): FixedSizeDecoder { - return getStructDecoder([ - ['discriminator', getU8Decoder()], - ['accountDataSizeLimit', getU32Decoder()], - ]); + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['accountDataSizeLimit', getU32Decoder()], + ]); } export function getSetLoadedAccountsDataSizeLimitInstructionDataCodec(): FixedSizeCodec< - SetLoadedAccountsDataSizeLimitInstructionDataArgs, - SetLoadedAccountsDataSizeLimitInstructionData + SetLoadedAccountsDataSizeLimitInstructionDataArgs, + SetLoadedAccountsDataSizeLimitInstructionData > { - return combineCodec( - getSetLoadedAccountsDataSizeLimitInstructionDataEncoder(), - getSetLoadedAccountsDataSizeLimitInstructionDataDecoder() - ); + return combineCodec( + getSetLoadedAccountsDataSizeLimitInstructionDataEncoder(), + getSetLoadedAccountsDataSizeLimitInstructionDataDecoder(), + ); } export type SetLoadedAccountsDataSizeLimitInput = { - accountDataSizeLimit: SetLoadedAccountsDataSizeLimitInstructionDataArgs['accountDataSizeLimit']; + accountDataSizeLimit: SetLoadedAccountsDataSizeLimitInstructionDataArgs['accountDataSizeLimit']; }; export function getSetLoadedAccountsDataSizeLimitInstruction< - TProgramAddress extends Address = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, + TProgramAddress extends Address = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, >( - input: SetLoadedAccountsDataSizeLimitInput, - config?: { programAddress?: TProgramAddress } + input: SetLoadedAccountsDataSizeLimitInput, + config?: { programAddress?: TProgramAddress }, ): SetLoadedAccountsDataSizeLimitInstruction { - // Program address. - const programAddress = - config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; + // Program address. + const programAddress = config?.programAddress ?? COMPUTE_BUDGET_PROGRAM_ADDRESS; - // Original args. - const args = { ...input }; + // Original args. + const args = { ...input }; - return Object.freeze({ - data: getSetLoadedAccountsDataSizeLimitInstructionDataEncoder().encode( - args as SetLoadedAccountsDataSizeLimitInstructionDataArgs - ), - programAddress, - } as SetLoadedAccountsDataSizeLimitInstruction); + return Object.freeze({ + data: getSetLoadedAccountsDataSizeLimitInstructionDataEncoder().encode( + args as SetLoadedAccountsDataSizeLimitInstructionDataArgs, + ), + programAddress, + } as SetLoadedAccountsDataSizeLimitInstruction); } export type ParsedSetLoadedAccountsDataSizeLimitInstruction< - TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, -> = { - programAddress: Address; - data: SetLoadedAccountsDataSizeLimitInstructionData; -}; + TProgram extends string = typeof COMPUTE_BUDGET_PROGRAM_ADDRESS, +> = { programAddress: Address; data: SetLoadedAccountsDataSizeLimitInstructionData }; -export function parseSetLoadedAccountsDataSizeLimitInstruction< - TProgram extends string, ->( - instruction: Instruction & InstructionWithData +export function parseSetLoadedAccountsDataSizeLimitInstruction( + instruction: Instruction & InstructionWithData, ): ParsedSetLoadedAccountsDataSizeLimitInstruction { - return { - programAddress: instruction.programAddress, - data: getSetLoadedAccountsDataSizeLimitInstructionDataDecoder().decode( - instruction.data - ), - }; + return { + programAddress: instruction.programAddress, + data: getSetLoadedAccountsDataSizeLimitInstructionDataDecoder().decode(instruction.data), + }; } diff --git a/clients/js/src/generated/programs/computeBudget.ts b/clients/js/src/generated/programs/computeBudget.ts index 73823df..cbeab96 100644 --- a/clients/js/src/generated/programs/computeBudget.ts +++ b/clients/js/src/generated/programs/computeBudget.ts @@ -6,70 +6,57 @@ * @see https://github.com/codama-idl/codama */ +import { containsBytes, getU8Encoder, type Address, type ReadonlyUint8Array } from '@solana/kit'; import { - containsBytes, - getU8Encoder, - type Address, - type ReadonlyUint8Array, -} from '@solana/kit'; -import { - type ParsedRequestHeapFrameInstruction, - type ParsedRequestUnitsInstruction, - type ParsedSetComputeUnitLimitInstruction, - type ParsedSetComputeUnitPriceInstruction, - type ParsedSetLoadedAccountsDataSizeLimitInstruction, + type ParsedRequestHeapFrameInstruction, + type ParsedRequestUnitsInstruction, + type ParsedSetComputeUnitLimitInstruction, + type ParsedSetComputeUnitPriceInstruction, + type ParsedSetLoadedAccountsDataSizeLimitInstruction, } from '../instructions'; export const COMPUTE_BUDGET_PROGRAM_ADDRESS = - 'ComputeBudget111111111111111111111111111111' as Address<'ComputeBudget111111111111111111111111111111'>; + 'ComputeBudget111111111111111111111111111111' as Address<'ComputeBudget111111111111111111111111111111'>; export enum ComputeBudgetInstruction { - RequestUnits, - RequestHeapFrame, - SetComputeUnitLimit, - SetComputeUnitPrice, - SetLoadedAccountsDataSizeLimit, + RequestUnits, + RequestHeapFrame, + SetComputeUnitLimit, + SetComputeUnitPrice, + SetLoadedAccountsDataSizeLimit, } export function identifyComputeBudgetInstruction( - instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, ): ComputeBudgetInstruction { - const data = 'data' in instruction ? instruction.data : instruction; - if (containsBytes(data, getU8Encoder().encode(0), 0)) { - return ComputeBudgetInstruction.RequestUnits; - } - if (containsBytes(data, getU8Encoder().encode(1), 0)) { - return ComputeBudgetInstruction.RequestHeapFrame; - } - if (containsBytes(data, getU8Encoder().encode(2), 0)) { - return ComputeBudgetInstruction.SetComputeUnitLimit; - } - if (containsBytes(data, getU8Encoder().encode(3), 0)) { - return ComputeBudgetInstruction.SetComputeUnitPrice; - } - if (containsBytes(data, getU8Encoder().encode(4), 0)) { - return ComputeBudgetInstruction.SetLoadedAccountsDataSizeLimit; - } - throw new Error( - 'The provided instruction could not be identified as a computeBudget instruction.' - ); + const data = 'data' in instruction ? instruction.data : instruction; + if (containsBytes(data, getU8Encoder().encode(0), 0)) { + return ComputeBudgetInstruction.RequestUnits; + } + if (containsBytes(data, getU8Encoder().encode(1), 0)) { + return ComputeBudgetInstruction.RequestHeapFrame; + } + if (containsBytes(data, getU8Encoder().encode(2), 0)) { + return ComputeBudgetInstruction.SetComputeUnitLimit; + } + if (containsBytes(data, getU8Encoder().encode(3), 0)) { + return ComputeBudgetInstruction.SetComputeUnitPrice; + } + if (containsBytes(data, getU8Encoder().encode(4), 0)) { + return ComputeBudgetInstruction.SetLoadedAccountsDataSizeLimit; + } + throw new Error('The provided instruction could not be identified as a computeBudget instruction.'); } -export type ParsedComputeBudgetInstruction< - TProgram extends string = 'ComputeBudget111111111111111111111111111111', -> = - | ({ - instructionType: ComputeBudgetInstruction.RequestUnits; - } & ParsedRequestUnitsInstruction) - | ({ - instructionType: ComputeBudgetInstruction.RequestHeapFrame; - } & ParsedRequestHeapFrameInstruction) - | ({ - instructionType: ComputeBudgetInstruction.SetComputeUnitLimit; - } & ParsedSetComputeUnitLimitInstruction) - | ({ - instructionType: ComputeBudgetInstruction.SetComputeUnitPrice; - } & ParsedSetComputeUnitPriceInstruction) - | ({ - instructionType: ComputeBudgetInstruction.SetLoadedAccountsDataSizeLimit; - } & ParsedSetLoadedAccountsDataSizeLimitInstruction); +export type ParsedComputeBudgetInstruction = + | ({ instructionType: ComputeBudgetInstruction.RequestUnits } & ParsedRequestUnitsInstruction) + | ({ instructionType: ComputeBudgetInstruction.RequestHeapFrame } & ParsedRequestHeapFrameInstruction) + | ({ + instructionType: ComputeBudgetInstruction.SetComputeUnitLimit; + } & ParsedSetComputeUnitLimitInstruction) + | ({ + instructionType: ComputeBudgetInstruction.SetComputeUnitPrice; + } & ParsedSetComputeUnitPriceInstruction) + | ({ + instructionType: ComputeBudgetInstruction.SetLoadedAccountsDataSizeLimit; + } & ParsedSetLoadedAccountsDataSizeLimitInstruction); diff --git a/clients/js/src/generated/shared/index.ts b/clients/js/src/generated/shared/index.ts index 83a3183..7380d8c 100644 --- a/clients/js/src/generated/shared/index.ts +++ b/clients/js/src/generated/shared/index.ts @@ -7,15 +7,15 @@ */ import { - AccountRole, - isProgramDerivedAddress, - isTransactionSigner as kitIsTransactionSigner, - type AccountMeta, - type AccountSignerMeta, - type Address, - type ProgramDerivedAddress, - type TransactionSigner, - upgradeRoleToSigner, + AccountRole, + isProgramDerivedAddress, + isTransactionSigner as kitIsTransactionSigner, + type AccountMeta, + type AccountSignerMeta, + type Address, + type ProgramDerivedAddress, + type TransactionSigner, + upgradeRoleToSigner, } from '@solana/kit'; /** @@ -23,10 +23,10 @@ import { * @internal */ export function expectSome(value: T | null | undefined): T { - if (value === null || value === undefined) { - throw new Error('Expected a value but received null or undefined.'); - } - return value; + if (value === null || value === undefined) { + throw new Error('Expected a value but received null or undefined.'); + } + return value; } /** @@ -34,23 +34,18 @@ export function expectSome(value: T | null | undefined): T { * @internal */ export function expectAddress( - value: - | Address - | ProgramDerivedAddress - | TransactionSigner - | null - | undefined + value: Address | ProgramDerivedAddress | TransactionSigner | null | undefined, ): Address { - if (!value) { - throw new Error('Expected a Address.'); - } - if (typeof value === 'object' && 'address' in value) { - return value.address; - } - if (Array.isArray(value)) { - return value[0] as Address; - } - return value as Address; + if (!value) { + throw new Error('Expected a Address.'); + } + if (typeof value === 'object' && 'address' in value) { + return value.address; + } + if (Array.isArray(value)) { + return value[0] as Address; + } + return value as Address; } /** @@ -58,17 +53,12 @@ export function expectAddress( * @internal */ export function expectProgramDerivedAddress( - value: - | Address - | ProgramDerivedAddress - | TransactionSigner - | null - | undefined + value: Address | ProgramDerivedAddress | TransactionSigner | null | undefined, ): ProgramDerivedAddress { - if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) { - throw new Error('Expected a ProgramDerivedAddress.'); - } - return value; + if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) { + throw new Error('Expected a ProgramDerivedAddress.'); + } + return value; } /** @@ -76,17 +66,12 @@ export function expectProgramDerivedAddress( * @internal */ export function expectTransactionSigner( - value: - | Address - | ProgramDerivedAddress - | TransactionSigner - | null - | undefined + value: Address | ProgramDerivedAddress | TransactionSigner | null | undefined, ): TransactionSigner { - if (!value || !isTransactionSigner(value)) { - throw new Error('Expected a TransactionSigner.'); - } - return value; + if (!value || !isTransactionSigner(value)) { + throw new Error('Expected a TransactionSigner.'); + } + return value; } /** @@ -94,19 +79,15 @@ export function expectTransactionSigner( * @internal */ export type ResolvedAccount< - T extends string = string, - U extends - | Address - | ProgramDerivedAddress - | TransactionSigner - | null = - | Address - | ProgramDerivedAddress - | TransactionSigner - | null, + T extends string = string, + U extends Address | ProgramDerivedAddress | TransactionSigner | null = + | Address + | ProgramDerivedAddress + | TransactionSigner + | null, > = { - isWritable: boolean; - value: U; + isWritable: boolean; + value: U; }; /** @@ -114,51 +95,31 @@ export type ResolvedAccount< * @internal */ export type InstructionWithByteDelta = { - byteDelta: number; + byteDelta: number; }; /** * Get account metas and signers from resolved accounts. * @internal */ -export function getAccountMetaFactory( - programAddress: Address, - optionalAccountStrategy: 'omitted' | 'programId' -) { - return ( - account: ResolvedAccount - ): AccountMeta | AccountSignerMeta | undefined => { - if (!account.value) { - if (optionalAccountStrategy === 'omitted') return; - return Object.freeze({ - address: programAddress, - role: AccountRole.READONLY, - }); - } +export function getAccountMetaFactory(programAddress: Address, optionalAccountStrategy: 'omitted' | 'programId') { + return (account: ResolvedAccount): AccountMeta | AccountSignerMeta | undefined => { + if (!account.value) { + if (optionalAccountStrategy === 'omitted') return; + return Object.freeze({ address: programAddress, role: AccountRole.READONLY }); + } - const writableRole = account.isWritable - ? AccountRole.WRITABLE - : AccountRole.READONLY; - return Object.freeze({ - address: expectAddress(account.value), - role: isTransactionSigner(account.value) - ? upgradeRoleToSigner(writableRole) - : writableRole, - ...(isTransactionSigner(account.value) ? { signer: account.value } : {}), - }); - }; + const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY; + return Object.freeze({ + address: expectAddress(account.value), + role: isTransactionSigner(account.value) ? upgradeRoleToSigner(writableRole) : writableRole, + ...(isTransactionSigner(account.value) ? { signer: account.value } : {}), + }); + }; } export function isTransactionSigner( - value: - | Address - | ProgramDerivedAddress - | TransactionSigner + value: Address | ProgramDerivedAddress | TransactionSigner, ): value is TransactionSigner { - return ( - !!value && - typeof value === 'object' && - 'address' in value && - kitIsTransactionSigner(value) - ); + return !!value && typeof value === 'object' && 'address' in value && kitIsTransactionSigner(value); } diff --git a/clients/js/src/internal.ts b/clients/js/src/internal.ts index ccb6f5e..bfa13cc 100644 --- a/clients/js/src/internal.ts +++ b/clients/js/src/internal.ts @@ -1,17 +1,17 @@ import { - BaseTransactionMessage, - getU32Decoder, - getU64Decoder, - Instruction, - MicroLamports, - ReadonlyUint8Array, + BaseTransactionMessage, + getU32Decoder, + getU64Decoder, + Instruction, + MicroLamports, + ReadonlyUint8Array, } from '@solana/kit'; import { - COMPUTE_BUDGET_PROGRAM_ADDRESS, - ComputeBudgetInstruction, - identifyComputeBudgetInstruction, - SetComputeUnitLimitInstruction, - SetComputeUnitPriceInstruction, + COMPUTE_BUDGET_PROGRAM_ADDRESS, + ComputeBudgetInstruction, + identifyComputeBudgetInstruction, + SetComputeUnitLimitInstruction, + SetComputeUnitPriceInstruction, } from './generated'; /** @@ -19,43 +19,36 @@ import { * and its set limit, if any. */ export function getSetComputeUnitLimitInstructionIndexAndUnits( - transactionMessage: BaseTransactionMessage + transactionMessage: BaseTransactionMessage, ): { index: number; units: number } | null { - const index = getSetComputeUnitLimitInstructionIndex(transactionMessage); - if (index < 0) { - return null; - } + const index = getSetComputeUnitLimitInstructionIndex(transactionMessage); + if (index < 0) { + return null; + } - const units = getU32Decoder().decode( - transactionMessage.instructions[index].data as ReadonlyUint8Array, - 1 - ); + const units = getU32Decoder().decode(transactionMessage.instructions[index].data as ReadonlyUint8Array, 1); - return { index, units }; + return { index, units }; } /** * Finds the index of the first `SetComputeUnitLimit` instruction in a transaction message, if any. */ -export function getSetComputeUnitLimitInstructionIndex( - transactionMessage: BaseTransactionMessage -) { - return transactionMessage.instructions.findIndex( - isSetComputeUnitLimitInstruction - ); +export function getSetComputeUnitLimitInstructionIndex(transactionMessage: BaseTransactionMessage) { + return transactionMessage.instructions.findIndex(isSetComputeUnitLimitInstruction); } /** * Checks if the given instruction is a `SetComputeUnitLimit` instruction. */ export function isSetComputeUnitLimitInstruction( - instruction: Instruction + instruction: Instruction, ): instruction is SetComputeUnitLimitInstruction { - return ( - instruction.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS && - identifyComputeBudgetInstruction(instruction.data as Uint8Array) === - ComputeBudgetInstruction.SetComputeUnitLimit - ); + return ( + instruction.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS && + identifyComputeBudgetInstruction(instruction.data as Uint8Array) === + ComputeBudgetInstruction.SetComputeUnitLimit + ); } /** @@ -63,41 +56,37 @@ export function isSetComputeUnitLimitInstruction( * and its set micro-lamports, if any. */ export function getSetComputeUnitPriceInstructionIndexAndMicroLamports( - transactionMessage: BaseTransactionMessage + transactionMessage: BaseTransactionMessage, ): { index: number; microLamports: MicroLamports } | null { - const index = getSetComputeUnitPriceInstructionIndex(transactionMessage); - if (index < 0) { - return null; - } + const index = getSetComputeUnitPriceInstructionIndex(transactionMessage); + if (index < 0) { + return null; + } - const microLamports = getU64Decoder().decode( - transactionMessage.instructions[index].data as ReadonlyUint8Array, - 1 - ) as MicroLamports; + const microLamports = getU64Decoder().decode( + transactionMessage.instructions[index].data as ReadonlyUint8Array, + 1, + ) as MicroLamports; - return { index, microLamports }; + return { index, microLamports }; } /** * Finds the index of the first `SetComputeUnitPrice` instruction in a transaction message, if any. */ -export function getSetComputeUnitPriceInstructionIndex( - transactionMessage: BaseTransactionMessage -) { - return transactionMessage.instructions.findIndex( - isSetComputeUnitPriceInstruction - ); +export function getSetComputeUnitPriceInstructionIndex(transactionMessage: BaseTransactionMessage) { + return transactionMessage.instructions.findIndex(isSetComputeUnitPriceInstruction); } /** * Checks if the given instruction is a `SetComputeUnitPrice` instruction. */ export function isSetComputeUnitPriceInstruction( - instruction: Instruction + instruction: Instruction, ): instruction is SetComputeUnitPriceInstruction { - return ( - instruction.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS && - identifyComputeBudgetInstruction(instruction.data as Uint8Array) === - ComputeBudgetInstruction.SetComputeUnitPrice - ); + return ( + instruction.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS && + identifyComputeBudgetInstruction(instruction.data as Uint8Array) === + ComputeBudgetInstruction.SetComputeUnitPrice + ); } diff --git a/clients/js/src/setComputeLimit.ts b/clients/js/src/setComputeLimit.ts index 689ff42..f07f27c 100644 --- a/clients/js/src/setComputeLimit.ts +++ b/clients/js/src/setComputeLimit.ts @@ -1,7 +1,4 @@ -import { - appendTransactionMessageInstruction, - BaseTransactionMessage, -} from '@solana/kit'; +import { appendTransactionMessageInstruction, BaseTransactionMessage } from '@solana/kit'; import { PROVISORY_COMPUTE_UNIT_LIMIT } from './constants'; import { getSetComputeUnitLimitInstruction } from './generated'; import { getSetComputeUnitLimitInstructionIndexAndUnits } from './internal'; @@ -20,14 +17,13 @@ import { getSetComputeUnitLimitInstructionIndexAndUnits } from './internal'; * ); * ``` */ -export function fillProvisorySetComputeUnitLimitInstruction< - TTransactionMessage extends BaseTransactionMessage, ->(transactionMessage: TTransactionMessage) { - return updateOrAppendSetComputeUnitLimitInstruction( - (previousUnits) => - previousUnits === null ? PROVISORY_COMPUTE_UNIT_LIMIT : previousUnits, - transactionMessage - ); +export function fillProvisorySetComputeUnitLimitInstruction( + transactionMessage: TTransactionMessage, +) { + return updateOrAppendSetComputeUnitLimitInstruction( + previousUnits => (previousUnits === null ? PROVISORY_COMPUTE_UNIT_LIMIT : previousUnits), + transactionMessage, + ); } /** @@ -48,35 +44,32 @@ export function fillProvisorySetComputeUnitLimitInstruction< * ); * ``` */ -export function updateOrAppendSetComputeUnitLimitInstruction< - TTransactionMessage extends BaseTransactionMessage, ->( - units: number | ((previousUnits: number | null) => number), - transactionMessage: TTransactionMessage +export function updateOrAppendSetComputeUnitLimitInstruction( + units: number | ((previousUnits: number | null) => number), + transactionMessage: TTransactionMessage, ): TTransactionMessage { - const getUnits = (previousUnits: number | null): number => - typeof units === 'function' ? units(previousUnits) : units; - const instructionDetails = - getSetComputeUnitLimitInstructionIndexAndUnits(transactionMessage); + const getUnits = (previousUnits: number | null): number => + typeof units === 'function' ? units(previousUnits) : units; + const instructionDetails = getSetComputeUnitLimitInstructionIndexAndUnits(transactionMessage); - if (!instructionDetails) { - return appendTransactionMessageInstruction( - getSetComputeUnitLimitInstruction({ units: getUnits(null) }), - transactionMessage - ) as unknown as TTransactionMessage; - } + if (!instructionDetails) { + return appendTransactionMessageInstruction( + getSetComputeUnitLimitInstruction({ units: getUnits(null) }), + transactionMessage, + ) as unknown as TTransactionMessage; + } - const { index, units: previousUnits } = instructionDetails; - const newUnits = getUnits(previousUnits); - if (newUnits === previousUnits) { - return transactionMessage; - } + const { index, units: previousUnits } = instructionDetails; + const newUnits = getUnits(previousUnits); + if (newUnits === previousUnits) { + return transactionMessage; + } - const newInstruction = getSetComputeUnitLimitInstruction({ units: newUnits }); - const newInstructions = [...transactionMessage.instructions]; - newInstructions.splice(index, 1, newInstruction); - return Object.freeze({ - ...transactionMessage, - instructions: newInstructions, - }); + const newInstruction = getSetComputeUnitLimitInstruction({ units: newUnits }); + const newInstructions = [...transactionMessage.instructions]; + newInstructions.splice(index, 1, newInstruction); + return Object.freeze({ + ...transactionMessage, + instructions: newInstructions, + }); } diff --git a/clients/js/src/setComputePrice.ts b/clients/js/src/setComputePrice.ts index 2a2e47a..2eb5397 100644 --- a/clients/js/src/setComputePrice.ts +++ b/clients/js/src/setComputePrice.ts @@ -1,8 +1,4 @@ -import { - appendTransactionMessageInstruction, - BaseTransactionMessage, - MicroLamports, -} from '@solana/kit'; +import { appendTransactionMessageInstruction, BaseTransactionMessage, MicroLamports } from '@solana/kit'; import { getSetComputeUnitPriceInstruction } from './generated'; import { getSetComputeUnitPriceInstructionIndexAndMicroLamports } from './internal'; @@ -18,13 +14,14 @@ import { getSetComputeUnitPriceInstructionIndexAndMicroLamports } from './intern * ); * ``` */ -export function setTransactionMessageComputeUnitPrice< - TTransactionMessage extends BaseTransactionMessage, ->(microLamports: number | bigint, transactionMessage: TTransactionMessage) { - return appendTransactionMessageInstruction( - getSetComputeUnitPriceInstruction({ microLamports }), - transactionMessage - ); +export function setTransactionMessageComputeUnitPrice( + microLamports: number | bigint, + transactionMessage: TTransactionMessage, +) { + return appendTransactionMessageInstruction( + getSetComputeUnitPriceInstruction({ microLamports }), + transactionMessage, + ); } /** @@ -45,45 +42,36 @@ export function setTransactionMessageComputeUnitPrice< * ); * ``` */ -export function updateOrAppendSetComputeUnitPriceInstruction< - TTransactionMessage extends BaseTransactionMessage, ->( - microLamports: - | MicroLamports - | ((previousMicroLamports: MicroLamports | null) => MicroLamports), - transactionMessage: TTransactionMessage +export function updateOrAppendSetComputeUnitPriceInstruction( + microLamports: MicroLamports | ((previousMicroLamports: MicroLamports | null) => MicroLamports), + transactionMessage: TTransactionMessage, ): TTransactionMessage { - const getMicroLamports = ( - previousMicroLamports: MicroLamports | null - ): MicroLamports => - typeof microLamports === 'function' - ? microLamports(previousMicroLamports) - : microLamports; - const instructionDetails = - getSetComputeUnitPriceInstructionIndexAndMicroLamports(transactionMessage); + const getMicroLamports = (previousMicroLamports: MicroLamports | null): MicroLamports => + typeof microLamports === 'function' ? microLamports(previousMicroLamports) : microLamports; + const instructionDetails = getSetComputeUnitPriceInstructionIndexAndMicroLamports(transactionMessage); - if (!instructionDetails) { - return appendTransactionMessageInstruction( - getSetComputeUnitPriceInstruction({ - microLamports: getMicroLamports(null), - }), - transactionMessage - ) as unknown as TTransactionMessage; - } + if (!instructionDetails) { + return appendTransactionMessageInstruction( + getSetComputeUnitPriceInstruction({ + microLamports: getMicroLamports(null), + }), + transactionMessage, + ) as unknown as TTransactionMessage; + } - const { index, microLamports: previousMicroLamports } = instructionDetails; - const newMicroLamports = getMicroLamports(previousMicroLamports); - if (newMicroLamports === previousMicroLamports) { - return transactionMessage; - } + const { index, microLamports: previousMicroLamports } = instructionDetails; + const newMicroLamports = getMicroLamports(previousMicroLamports); + if (newMicroLamports === previousMicroLamports) { + return transactionMessage; + } - const newInstruction = getSetComputeUnitPriceInstruction({ - microLamports: newMicroLamports, - }); - const newInstructions = [...transactionMessage.instructions]; - newInstructions.splice(index, 1, newInstruction); - return Object.freeze({ - ...transactionMessage, - instructions: newInstructions, - }); + const newInstruction = getSetComputeUnitPriceInstruction({ + microLamports: newMicroLamports, + }); + const newInstructions = [...transactionMessage.instructions]; + newInstructions.splice(index, 1, newInstruction); + return Object.freeze({ + ...transactionMessage, + instructions: newInstructions, + }); } diff --git a/clients/js/test/_setup.ts b/clients/js/test/_setup.ts index bea93c9..a65280d 100644 --- a/clients/js/test/_setup.ts +++ b/clients/js/test/_setup.ts @@ -1,79 +1,70 @@ import { - BaseTransactionMessage, - Commitment, - Rpc, - RpcSubscriptions, - SolanaRpcApi, - SolanaRpcSubscriptionsApi, - TransactionMessageWithBlockhashLifetime, - TransactionMessageWithFeePayer, - TransactionSigner, - airdropFactory, - assertIsSendableTransaction, - createSolanaRpc, - createSolanaRpcSubscriptions, - createTransactionMessage, - generateKeyPairSigner, - getSignatureFromTransaction, - lamports, - pipe, - sendAndConfirmTransactionFactory, - setTransactionMessageFeePayerSigner, - setTransactionMessageLifetimeUsingBlockhash, - signTransactionMessageWithSigners, + BaseTransactionMessage, + Commitment, + Rpc, + RpcSubscriptions, + SolanaRpcApi, + SolanaRpcSubscriptionsApi, + TransactionMessageWithBlockhashLifetime, + TransactionMessageWithFeePayer, + TransactionSigner, + airdropFactory, + assertIsSendableTransaction, + createSolanaRpc, + createSolanaRpcSubscriptions, + createTransactionMessage, + generateKeyPairSigner, + getSignatureFromTransaction, + lamports, + pipe, + sendAndConfirmTransactionFactory, + setTransactionMessageFeePayerSigner, + setTransactionMessageLifetimeUsingBlockhash, + signTransactionMessageWithSigners, } from '@solana/kit'; type Client = { - rpc: Rpc; - rpcSubscriptions: RpcSubscriptions; + rpc: Rpc; + rpcSubscriptions: RpcSubscriptions; }; export const createDefaultSolanaClient = (): Client => { - const rpc = createSolanaRpc('http://127.0.0.1:8899'); - const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900'); - return { rpc, rpcSubscriptions }; + const rpc = createSolanaRpc('http://127.0.0.1:8899'); + const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900'); + return { rpc, rpcSubscriptions }; }; -export const generateKeyPairSignerWithSol = async ( - client: Client, - putativeLamports: bigint = 1_000_000_000n -) => { - const signer = await generateKeyPairSigner(); - await airdropFactory(client)({ - recipientAddress: signer.address, - lamports: lamports(putativeLamports), - commitment: 'confirmed', - }); - return signer; +export const generateKeyPairSignerWithSol = async (client: Client, putativeLamports: bigint = 1_000_000_000n) => { + const signer = await generateKeyPairSigner(); + await airdropFactory(client)({ + recipientAddress: signer.address, + lamports: lamports(putativeLamports), + commitment: 'confirmed', + }); + return signer; }; -export const createDefaultTransaction = async ( - client: Client, - feePayer: TransactionSigner -) => { - const { value: latestBlockhash } = await client.rpc - .getLatestBlockhash() - .send(); - return pipe( - createTransactionMessage({ version: 0 }), - (tx) => setTransactionMessageFeePayerSigner(feePayer, tx), - (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx) - ); +export const createDefaultTransaction = async (client: Client, feePayer: TransactionSigner) => { + const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send(); + return pipe( + createTransactionMessage({ version: 0 }), + tx => setTransactionMessageFeePayerSigner(feePayer, tx), + tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), + ); }; export const signAndSendTransaction = async ( - client: Client, - transactionMessage: BaseTransactionMessage & - TransactionMessageWithFeePayer & - TransactionMessageWithBlockhashLifetime, - commitment: Commitment = 'confirmed' + client: Client, + transactionMessage: BaseTransactionMessage & + TransactionMessageWithFeePayer & + TransactionMessageWithBlockhashLifetime, + commitment: Commitment = 'confirmed', ) => { - const signedTransaction = - await signTransactionMessageWithSigners(transactionMessage); - const signature = getSignatureFromTransaction(signedTransaction); - assertIsSendableTransaction(signedTransaction); - await sendAndConfirmTransactionFactory(client)(signedTransaction, { - commitment, - }); - return signature; + const signedTransaction = await signTransactionMessageWithSigners(transactionMessage); + const signature = getSignatureFromTransaction(signedTransaction); + assertIsSendableTransaction(signedTransaction); + await sendAndConfirmTransactionFactory(client)(signedTransaction, { + commitment, + }); + return signature; }; diff --git a/clients/js/test/estimateAndSetComputeLimit.test.ts b/clients/js/test/estimateAndSetComputeLimit.test.ts index 2d0c07e..f6493a7 100644 --- a/clients/js/test/estimateAndSetComputeLimit.test.ts +++ b/clients/js/test/estimateAndSetComputeLimit.test.ts @@ -1,148 +1,145 @@ import { - Address, - BaseTransactionMessage, - Rpc, - SimulateTransactionApi, - TransactionMessageWithFeePayer, + Address, + BaseTransactionMessage, + Rpc, + SimulateTransactionApi, + TransactionMessageWithFeePayer, } from '@solana/kit'; import { beforeEach, describe, expect, it, Mock, vi } from 'vitest'; import { - estimateAndUpdateProvisoryComputeUnitLimitFactory, - estimateComputeUnitLimitFactory, - getSetComputeUnitLimitInstruction, - MAX_COMPUTE_UNIT_LIMIT, - PROVISORY_COMPUTE_UNIT_LIMIT, + estimateAndUpdateProvisoryComputeUnitLimitFactory, + estimateComputeUnitLimitFactory, + getSetComputeUnitLimitInstruction, + MAX_COMPUTE_UNIT_LIMIT, + PROVISORY_COMPUTE_UNIT_LIMIT, } from '../src'; const FOREVER_PROMISE = new Promise(() => { - /* never resolve */ + /* never resolve */ }); describe('estimateAndUpdateProvisoryComputeUnitLimitFactory', () => { - let sendSimulateTransactionRequest: Mock; - let mockTransactionMessage: BaseTransactionMessage & - TransactionMessageWithFeePayer; - let rpc: Rpc; - let simulateTransaction: Mock; - - beforeEach(() => { - mockTransactionMessage = { - feePayer: { - address: '7U8VWgTUucttJPt5Bbkt48WknWqRGBfstBt8qqLHnfPT' as Address, - }, - instructions: [], - version: 0, - }; - sendSimulateTransactionRequest = vi.fn().mockReturnValue(FOREVER_PROMISE); - simulateTransaction = vi.fn().mockReturnValue({ - send: sendSimulateTransactionRequest, + let sendSimulateTransactionRequest: Mock; + let mockTransactionMessage: BaseTransactionMessage & TransactionMessageWithFeePayer; + let rpc: Rpc; + let simulateTransaction: Mock; + + beforeEach(() => { + mockTransactionMessage = { + feePayer: { + address: '7U8VWgTUucttJPt5Bbkt48WknWqRGBfstBt8qqLHnfPT' as Address, + }, + instructions: [], + version: 0, + }; + sendSimulateTransactionRequest = vi.fn().mockReturnValue(FOREVER_PROMISE); + simulateTransaction = vi.fn().mockReturnValue({ + send: sendSimulateTransactionRequest, + }); + rpc = { simulateTransaction }; }); - rpc = { simulateTransaction }; - }); - it('appends a new SetComputeUnitLimit instruction if missing', async () => { - expect.assertions(1); - sendSimulateTransactionRequest.mockResolvedValue({ - value: { unitsConsumed: 42n }, + it('appends a new SetComputeUnitLimit instruction if missing', async () => { + expect.assertions(1); + sendSimulateTransactionRequest.mockResolvedValue({ + value: { unitsConsumed: 42n }, + }); + const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( + estimateComputeUnitLimitFactory({ rpc }), + ); + + const updatedTransactionMessage = await estimateAndUpdate(mockTransactionMessage); + + expect(updatedTransactionMessage).toEqual({ + ...mockTransactionMessage, + instructions: [getSetComputeUnitLimitInstruction({ units: 42 })], + }); }); - const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( - estimateComputeUnitLimitFactory({ rpc }) - ); - const updatedTransactionMessage = await estimateAndUpdate( - mockTransactionMessage - ); - - expect(updatedTransactionMessage).toEqual({ - ...mockTransactionMessage, - instructions: [getSetComputeUnitLimitInstruction({ units: 42 })], - }); - }); - - it('updates the SetComputeUnitLimit instruction if set to PROVISORY_COMPUTE_UNIT_LIMIT', async () => { - expect.assertions(1); - sendSimulateTransactionRequest.mockResolvedValue({ - value: { unitsConsumed: 42n }, - }); - const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( - estimateComputeUnitLimitFactory({ rpc }) - ); - - const updatedTransactionMessage = await estimateAndUpdate({ - ...mockTransactionMessage, - instructions: [ - getSetComputeUnitLimitInstruction({ - units: PROVISORY_COMPUTE_UNIT_LIMIT, - }), - ], - }); - - expect(updatedTransactionMessage).toEqual({ - ...mockTransactionMessage, - instructions: [getSetComputeUnitLimitInstruction({ units: 42 })], - }); - }); - - it('updates the SetComputeUnitLimit instruction if set to MAX_COMPUTE_UNIT_LIMIT', async () => { - expect.assertions(1); - sendSimulateTransactionRequest.mockResolvedValue({ - value: { unitsConsumed: 42n }, + it('updates the SetComputeUnitLimit instruction if set to PROVISORY_COMPUTE_UNIT_LIMIT', async () => { + expect.assertions(1); + sendSimulateTransactionRequest.mockResolvedValue({ + value: { unitsConsumed: 42n }, + }); + const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( + estimateComputeUnitLimitFactory({ rpc }), + ); + + const updatedTransactionMessage = await estimateAndUpdate({ + ...mockTransactionMessage, + instructions: [ + getSetComputeUnitLimitInstruction({ + units: PROVISORY_COMPUTE_UNIT_LIMIT, + }), + ], + }); + + expect(updatedTransactionMessage).toEqual({ + ...mockTransactionMessage, + instructions: [getSetComputeUnitLimitInstruction({ units: 42 })], + }); }); - const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( - estimateComputeUnitLimitFactory({ rpc }) - ); - - const updatedTransactionMessage = await estimateAndUpdate({ - ...mockTransactionMessage, - instructions: [ - getSetComputeUnitLimitInstruction({ - units: MAX_COMPUTE_UNIT_LIMIT, - }), - ], - }); - - expect(updatedTransactionMessage).toEqual({ - ...mockTransactionMessage, - instructions: [getSetComputeUnitLimitInstruction({ units: 42 })], - }); - }); - - it('does not update the SetComputeUnitLimit instruction if set to an explicit value', async () => { - expect.assertions(1); - sendSimulateTransactionRequest.mockResolvedValue({ - value: { unitsConsumed: 42n }, - }); - const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( - estimateComputeUnitLimitFactory({ rpc }) - ); - const updatedTransactionMessage = await estimateAndUpdate({ - ...mockTransactionMessage, - instructions: [getSetComputeUnitLimitInstruction({ units: 123456 })], + it('updates the SetComputeUnitLimit instruction if set to MAX_COMPUTE_UNIT_LIMIT', async () => { + expect.assertions(1); + sendSimulateTransactionRequest.mockResolvedValue({ + value: { unitsConsumed: 42n }, + }); + const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( + estimateComputeUnitLimitFactory({ rpc }), + ); + + const updatedTransactionMessage = await estimateAndUpdate({ + ...mockTransactionMessage, + instructions: [ + getSetComputeUnitLimitInstruction({ + units: MAX_COMPUTE_UNIT_LIMIT, + }), + ], + }); + + expect(updatedTransactionMessage).toEqual({ + ...mockTransactionMessage, + instructions: [getSetComputeUnitLimitInstruction({ units: 42 })], + }); }); - expect(updatedTransactionMessage).toEqual({ - ...mockTransactionMessage, - instructions: [getSetComputeUnitLimitInstruction({ units: 123456 })], + it('does not update the SetComputeUnitLimit instruction if set to an explicit value', async () => { + expect.assertions(1); + sendSimulateTransactionRequest.mockResolvedValue({ + value: { unitsConsumed: 42n }, + }); + const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( + estimateComputeUnitLimitFactory({ rpc }), + ); + + const updatedTransactionMessage = await estimateAndUpdate({ + ...mockTransactionMessage, + instructions: [getSetComputeUnitLimitInstruction({ units: 123456 })], + }); + + expect(updatedTransactionMessage).toEqual({ + ...mockTransactionMessage, + instructions: [getSetComputeUnitLimitInstruction({ units: 123456 })], + }); }); - }); - - it('can be aborted', () => { - const abortController = new AbortController(); - const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( - estimateComputeUnitLimitFactory({ rpc }) - ); - estimateAndUpdate(mockTransactionMessage, { - abortSignal: abortController.signal, - }).catch(() => {}); - - expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ - abortSignal: expect.objectContaining({ aborted: false }), - }); - abortController.abort(); - expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ - abortSignal: expect.objectContaining({ aborted: true }), + it('can be aborted', () => { + const abortController = new AbortController(); + const estimateAndUpdate = estimateAndUpdateProvisoryComputeUnitLimitFactory( + estimateComputeUnitLimitFactory({ rpc }), + ); + + estimateAndUpdate(mockTransactionMessage, { + abortSignal: abortController.signal, + }).catch(() => {}); + + expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ + abortSignal: expect.objectContaining({ aborted: false }), + }); + abortController.abort(); + expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ + abortSignal: expect.objectContaining({ aborted: true }), + }); }); - }); }); diff --git a/clients/js/test/estimateComputeLimitInternal.test.ts b/clients/js/test/estimateComputeLimitInternal.test.ts index bf61555..886eaf6 100644 --- a/clients/js/test/estimateComputeLimitInternal.test.ts +++ b/clients/js/test/estimateComputeLimitInternal.test.ts @@ -1,291 +1,272 @@ import { - AccountRole, - Address, - BaseTransactionMessage, - Blockhash, - compileTransaction, - Nonce, - Rpc, - SimulateTransactionApi, - SOLANA_ERROR__INSTRUCTION_ERROR__INSUFFICIENT_FUNDS, - SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, - SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, - SolanaError, - TransactionError, - TransactionMessageWithFeePayer, + AccountRole, + Address, + BaseTransactionMessage, + Blockhash, + compileTransaction, + Nonce, + Rpc, + SimulateTransactionApi, + SOLANA_ERROR__INSTRUCTION_ERROR__INSUFFICIENT_FUNDS, + SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, + SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, + SolanaError, + TransactionError, + TransactionMessageWithFeePayer, } from '@solana/kit'; import { beforeEach, describe, expect, it, Mock, vi } from 'vitest'; -import { - getSetComputeUnitLimitInstruction, - MAX_COMPUTE_UNIT_LIMIT, -} from '../src'; +import { getSetComputeUnitLimitInstruction, MAX_COMPUTE_UNIT_LIMIT } from '../src'; import { estimateComputeUnitLimit } from '../src/estimateComputeLimitInternal'; // Spy on the `compileTransaction` function. -vi.mock('@solana/kit', async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - compileTransaction: vi.fn(actual.compileTransaction), - }; +vi.mock('@solana/kit', async importOriginal => { + const actual = await importOriginal(); + return { + ...actual, + compileTransaction: vi.fn(actual.compileTransaction), + }; }); const FOREVER_PROMISE = new Promise(() => { - /* never resolve */ + /* never resolve */ }); const MOCK_BLOCKHASH_LIFETIME_CONSTRAINT = { - blockhash: 'GNtuHnNyW68wviopST3ki37Afv7LPphxfSwiHAkX5Q9H' as Blockhash, - lastValidBlockHeight: 0n, + blockhash: 'GNtuHnNyW68wviopST3ki37Afv7LPphxfSwiHAkX5Q9H' as Blockhash, + lastValidBlockHeight: 0n, } as const; describe('estimateComputeUnitLimit', () => { - let sendSimulateTransactionRequest: Mock; - let mockTransactionMessage: BaseTransactionMessage & - TransactionMessageWithFeePayer; - let rpc: Rpc; - let simulateTransaction: Mock; - - beforeEach(() => { - mockTransactionMessage = { - feePayer: { - address: '7U8VWgTUucttJPt5Bbkt48WknWqRGBfstBt8qqLHnfPT' as Address, - }, - instructions: [], - version: 0, - }; - sendSimulateTransactionRequest = vi.fn().mockReturnValue(FOREVER_PROMISE); - simulateTransaction = vi.fn().mockReturnValue({ - send: sendSimulateTransactionRequest, - }); - rpc = { simulateTransaction }; - }); - - it('aborts the `simulateTransaction` request when aborted', () => { - const abortController = new AbortController(); - const transactionMessage = { - ...mockTransactionMessage, - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }; - estimateComputeUnitLimit({ - abortSignal: abortController.signal, - rpc, - transactionMessage, - }).catch(() => {}); - - expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ - abortSignal: expect.objectContaining({ aborted: false }), + let sendSimulateTransactionRequest: Mock; + let mockTransactionMessage: BaseTransactionMessage & TransactionMessageWithFeePayer; + let rpc: Rpc; + let simulateTransaction: Mock; + + beforeEach(() => { + mockTransactionMessage = { + feePayer: { + address: '7U8VWgTUucttJPt5Bbkt48WknWqRGBfstBt8qqLHnfPT' as Address, + }, + instructions: [], + version: 0, + }; + sendSimulateTransactionRequest = vi.fn().mockReturnValue(FOREVER_PROMISE); + simulateTransaction = vi.fn().mockReturnValue({ + send: sendSimulateTransactionRequest, + }); + rpc = { simulateTransaction }; }); - abortController.abort(); - expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ - abortSignal: expect.objectContaining({ aborted: true }), + + it('aborts the `simulateTransaction` request when aborted', () => { + const abortController = new AbortController(); + const transactionMessage = { + ...mockTransactionMessage, + lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, + }; + estimateComputeUnitLimit({ + abortSignal: abortController.signal, + rpc, + transactionMessage, + }).catch(() => {}); + + expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ + abortSignal: expect.objectContaining({ aborted: false }), + }); + abortController.abort(); + expect(sendSimulateTransactionRequest).toHaveBeenCalledWith({ + abortSignal: expect.objectContaining({ aborted: true }), + }); }); - }); - it('passes the expected basic input to the simulation request', () => { - const transactionMessage = { - ...mockTransactionMessage, - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }; - estimateComputeUnitLimit({ - commitment: 'finalized', - minContextSlot: 42n, - rpc, - transactionMessage, - }).catch(() => {}); - - expect(simulateTransaction).toHaveBeenCalledWith( - expect.any(String), - expect.objectContaining({ - commitment: 'finalized', - encoding: 'base64', - minContextSlot: 42n, - sigVerify: false, - }) - ); - }); - - it('appends a set compute unit limit instruction when one does not exist', () => { - const transactionMessage = { - ...mockTransactionMessage, // No `SetComputeUnitLimit` instruction - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }; + it('passes the expected basic input to the simulation request', () => { + const transactionMessage = { + ...mockTransactionMessage, + lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, + }; + estimateComputeUnitLimit({ + commitment: 'finalized', + minContextSlot: 42n, + rpc, + transactionMessage, + }).catch(() => {}); + + expect(simulateTransaction).toHaveBeenCalledWith( + expect.any(String), + expect.objectContaining({ + commitment: 'finalized', + encoding: 'base64', + minContextSlot: 42n, + sigVerify: false, + }), + ); + }); - estimateComputeUnitLimit({ - rpc, - transactionMessage, - }).catch(() => {}); - - expect(compileTransaction).toHaveBeenCalledWith({ - ...transactionMessage, - instructions: [ - ...transactionMessage.instructions, - getSetComputeUnitLimitInstruction({ units: MAX_COMPUTE_UNIT_LIMIT }), - ], + it('appends a set compute unit limit instruction when one does not exist', () => { + const transactionMessage = { + ...mockTransactionMessage, // No `SetComputeUnitLimit` instruction + lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, + }; + + estimateComputeUnitLimit({ + rpc, + transactionMessage, + }).catch(() => {}); + + expect(compileTransaction).toHaveBeenCalledWith({ + ...transactionMessage, + instructions: [ + ...transactionMessage.instructions, + getSetComputeUnitLimitInstruction({ units: MAX_COMPUTE_UNIT_LIMIT }), + ], + }); }); - }); - it('replaces the existing set compute unit limit instruction when one exists', () => { - const mockInstruction = { - programAddress: '4Kk4nA3F2nWHCcuyT8nR6oF7HQUQHmmzAVD5k8FQPKB2' as Address, - }; - const transactionMessage = { - ...mockTransactionMessage, - instructions: [ - mockInstruction, - getSetComputeUnitLimitInstruction({ units: 1234 }), - mockInstruction, - ], - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }; + it('replaces the existing set compute unit limit instruction when one exists', () => { + const mockInstruction = { + programAddress: '4Kk4nA3F2nWHCcuyT8nR6oF7HQUQHmmzAVD5k8FQPKB2' as Address, + }; + const transactionMessage = { + ...mockTransactionMessage, + instructions: [mockInstruction, getSetComputeUnitLimitInstruction({ units: 1234 }), mockInstruction], + lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, + }; + + estimateComputeUnitLimit({ + rpc, + transactionMessage, + }).catch(() => {}); + + expect(compileTransaction).toHaveBeenCalledWith( + expect.objectContaining({ + instructions: [ + mockInstruction, + getSetComputeUnitLimitInstruction({ units: MAX_COMPUTE_UNIT_LIMIT }), + mockInstruction, + ], + }), + ); + }); - estimateComputeUnitLimit({ - rpc, - transactionMessage, - }).catch(() => {}); - - expect(compileTransaction).toHaveBeenCalledWith( - expect.objectContaining({ - instructions: [ - mockInstruction, - getSetComputeUnitLimitInstruction({ units: MAX_COMPUTE_UNIT_LIMIT }), - mockInstruction, - ], - }) - ); - }); - - it('does not ask for a replacement blockhash when the transaction message is a durable nonce transaction', () => { - const transactionMessage = { - ...mockTransactionMessage, - instructions: [ - { - accounts: [ - { - address: - '7wJFRFuAE9x5Ptnz2VoBWsfecTCfuuM2sQCpECGypnTU' as Address, - role: AccountRole.WRITABLE, - }, - { - address: 'SysvarRecentB1ockHashes11111111111111111111' as Address, - role: AccountRole.READONLY, - }, - { - address: - 'HzMoc78z1VNNf9nwD4Czt6CDYEb9LVD8KsVGP46FEmyJ' as Address, - role: AccountRole.READONLY_SIGNER, + it('does not ask for a replacement blockhash when the transaction message is a durable nonce transaction', () => { + const transactionMessage = { + ...mockTransactionMessage, + instructions: [ + { + accounts: [ + { + address: '7wJFRFuAE9x5Ptnz2VoBWsfecTCfuuM2sQCpECGypnTU' as Address, + role: AccountRole.WRITABLE, + }, + { + address: 'SysvarRecentB1ockHashes11111111111111111111' as Address, + role: AccountRole.READONLY, + }, + { + address: 'HzMoc78z1VNNf9nwD4Czt6CDYEb9LVD8KsVGP46FEmyJ' as Address, + role: AccountRole.READONLY_SIGNER, + }, + ], + data: new Uint8Array([4, 0, 0, 0]), + programAddress: '11111111111111111111111111111111' as Address, + }, + ], + lifetimeConstraint: { + nonce: 'BzAqD6382v5r1pcELoi8HWrBDV4dSL9NGemMn2JYAhxc' as Nonce, }, - ], - data: new Uint8Array([4, 0, 0, 0]), - programAddress: '11111111111111111111111111111111' as Address, - }, - ], - lifetimeConstraint: { - nonce: 'BzAqD6382v5r1pcELoi8HWrBDV4dSL9NGemMn2JYAhxc' as Nonce, - }, - }; - estimateComputeUnitLimit({ rpc, transactionMessage }).catch(() => {}); - - expect(simulateTransaction).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ replaceRecentBlockhash: false }) - ); - }); - - it('asks for a replacement blockhash even when the transaction message has a blockhash lifetime', () => { - const transactionMessage = { - ...mockTransactionMessage, - lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, - }; - estimateComputeUnitLimit({ rpc, transactionMessage }).catch(() => {}); - - expect(simulateTransaction).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ replaceRecentBlockhash: true }) - ); - }); - - it('asks for a replacement blockhash when the transaction message has no lifetime', () => { - estimateComputeUnitLimit({ - rpc, - transactionMessage: mockTransactionMessage, - }).catch(() => {}); - - expect(simulateTransaction).toHaveBeenCalledWith( - expect.anything(), - expect.objectContaining({ replaceRecentBlockhash: true }) - ); - }); - - it('returns the estimated compute units on success', async () => { - expect.assertions(1); - sendSimulateTransactionRequest.mockResolvedValue({ - value: { unitsConsumed: 42n }, + }; + estimateComputeUnitLimit({ rpc, transactionMessage }).catch(() => {}); + + expect(simulateTransaction).toHaveBeenCalledWith( + expect.anything(), + expect.objectContaining({ replaceRecentBlockhash: false }), + ); }); - const estimatePromise = estimateComputeUnitLimit({ - rpc, - transactionMessage: mockTransactionMessage, + it('asks for a replacement blockhash even when the transaction message has a blockhash lifetime', () => { + const transactionMessage = { + ...mockTransactionMessage, + lifetimeConstraint: MOCK_BLOCKHASH_LIFETIME_CONSTRAINT, + }; + estimateComputeUnitLimit({ rpc, transactionMessage }).catch(() => {}); + + expect(simulateTransaction).toHaveBeenCalledWith( + expect.anything(), + expect.objectContaining({ replaceRecentBlockhash: true }), + ); }); - await expect(estimatePromise).resolves.toBe(42); - }); + it('asks for a replacement blockhash when the transaction message has no lifetime', () => { + estimateComputeUnitLimit({ + rpc, + transactionMessage: mockTransactionMessage, + }).catch(() => {}); - it('caps the estimated compute units to MAX_COMPUTE_UNITS of 1.4M', async () => { - expect.assertions(1); - sendSimulateTransactionRequest.mockResolvedValue({ - value: { unitsConsumed: 1400000n /* MAX_COMPUTE_UNITS */ }, + expect(simulateTransaction).toHaveBeenCalledWith( + expect.anything(), + expect.objectContaining({ replaceRecentBlockhash: true }), + ); }); - const estimatePromise = estimateComputeUnitLimit({ - rpc, - transactionMessage: mockTransactionMessage, - }); + it('returns the estimated compute units on success', async () => { + expect.assertions(1); + sendSimulateTransactionRequest.mockResolvedValue({ + value: { unitsConsumed: 42n }, + }); - await expect(estimatePromise).resolves.toBe(1400000); - }); + const estimatePromise = estimateComputeUnitLimit({ + rpc, + transactionMessage: mockTransactionMessage, + }); - it('throws with the transaction error as cause when the transaction fails in simulation', async () => { - expect.assertions(1); - const transactionError: TransactionError = 'AccountNotFound'; - sendSimulateTransactionRequest.mockResolvedValue({ - value: { err: transactionError, unitsConsumed: 42n }, + await expect(estimatePromise).resolves.toBe(42); }); - const estimatePromise = estimateComputeUnitLimit({ - rpc, - transactionMessage: mockTransactionMessage, + it('caps the estimated compute units to MAX_COMPUTE_UNITS of 1.4M', async () => { + expect.assertions(1); + sendSimulateTransactionRequest.mockResolvedValue({ + value: { unitsConsumed: 1400000n /* MAX_COMPUTE_UNITS */ }, + }); + + const estimatePromise = estimateComputeUnitLimit({ + rpc, + transactionMessage: mockTransactionMessage, + }); + + await expect(estimatePromise).resolves.toBe(1400000); }); - await expect(estimatePromise).rejects.toThrow( - new SolanaError( - SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, - { - cause: transactionError, - unitsConsumed: 42, - } - ) - ); - }); - - it('throws with the cause when simulation fails', async () => { - expect.assertions(1); - const simulationError = new SolanaError( - SOLANA_ERROR__INSTRUCTION_ERROR__INSUFFICIENT_FUNDS, - { index: 42 } - ); - sendSimulateTransactionRequest.mockRejectedValue(simulationError); - - const estimatePromise = estimateComputeUnitLimit({ - rpc, - transactionMessage: mockTransactionMessage, + it('throws with the transaction error as cause when the transaction fails in simulation', async () => { + expect.assertions(1); + const transactionError: TransactionError = 'AccountNotFound'; + sendSimulateTransactionRequest.mockResolvedValue({ + value: { err: transactionError, unitsConsumed: 42n }, + }); + + const estimatePromise = estimateComputeUnitLimit({ + rpc, + transactionMessage: mockTransactionMessage, + }); + + await expect(estimatePromise).rejects.toThrow( + new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, { + cause: transactionError, + unitsConsumed: 42, + }), + ); }); - await expect(estimatePromise).rejects.toThrow( - new SolanaError( - SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, - { cause: simulationError } - ) - ); - }); + it('throws with the cause when simulation fails', async () => { + expect.assertions(1); + const simulationError = new SolanaError(SOLANA_ERROR__INSTRUCTION_ERROR__INSUFFICIENT_FUNDS, { index: 42 }); + sendSimulateTransactionRequest.mockRejectedValue(simulationError); + + const estimatePromise = estimateComputeUnitLimit({ + rpc, + transactionMessage: mockTransactionMessage, + }); + + await expect(estimatePromise).rejects.toThrow( + new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, { cause: simulationError }), + ); + }); }); diff --git a/clients/js/test/setComputeUnitLimit.test.ts b/clients/js/test/setComputeUnitLimit.test.ts index c2c1869..e389940 100644 --- a/clients/js/test/setComputeUnitLimit.test.ts +++ b/clients/js/test/setComputeUnitLimit.test.ts @@ -2,27 +2,27 @@ import { appendTransactionMessageInstruction, pipe } from '@solana/kit'; import { expect, test } from 'vitest'; import { getSetComputeUnitLimitInstruction } from '../src'; import { - createDefaultSolanaClient, - createDefaultTransaction, - generateKeyPairSignerWithSol, - signAndSendTransaction, + createDefaultSolanaClient, + createDefaultTransaction, + generateKeyPairSignerWithSol, + signAndSendTransaction, } from './_setup'; test('it sets the compute unit limit of a transaction', async () => { - // Given a payer wallet. - const client = createDefaultSolanaClient(); - const payer = await generateKeyPairSignerWithSol(client); + // Given a payer wallet. + const client = createDefaultSolanaClient(); + const payer = await generateKeyPairSignerWithSol(client); - // When we create a transaction with a compute unit limit of 600,000. - const setComputeUnit = getSetComputeUnitLimitInstruction({ - units: 600_000, - }); - const promise = pipe( - await createDefaultTransaction(client, payer), - (tx) => appendTransactionMessageInstruction(setComputeUnit, tx), - (tx) => signAndSendTransaction(client, tx) - ); + // When we create a transaction with a compute unit limit of 600,000. + const setComputeUnit = getSetComputeUnitLimitInstruction({ + units: 600_000, + }); + const promise = pipe( + await createDefaultTransaction(client, payer), + tx => appendTransactionMessageInstruction(setComputeUnit, tx), + tx => signAndSendTransaction(client, tx), + ); - // Then the transaction was successful. - await expect(promise).resolves.toBeTruthy(); + // Then the transaction was successful. + await expect(promise).resolves.toBeTruthy(); }); diff --git a/codama.json b/codama.json new file mode 100644 index 0000000..b8348a0 --- /dev/null +++ b/codama.json @@ -0,0 +1,26 @@ +{ + "idl": "program/idl.json", + "before": [], + "scripts": { + "js": { + "from": "@codama/renderers-js", + "args": [ + "clients/js/src/generated", + { + "packageFolder": "clients/js", + "syncPackageJson": true + } + ] + }, + "rust": { + "from": "@codama/renderers-rust", + "args": [ + "clients/rust/src/generated", + { + "crateFolder": "clients/rust", + "formatCode": true + } + ] + } + } +} diff --git a/package.json b/package.json index 8e682b1..c432edd 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "solana:check": "zx ./scripts/check-solana-version.mjs", "solana:link": "zx ./scripts/link-solana-version.mjs", "generate": "pnpm generate:clients", - "generate:clients": "zx ./scripts/generate-clients.mjs", + "generate:clients": "codama run --all", "validator:start": "zx ./scripts/start-validator.mjs", "validator:restart": "pnpm validator:start --restart", "validator:stop": "zx ./scripts/stop-validator.mjs", @@ -19,15 +19,17 @@ "template:upgrade": "zx ./scripts/upgrade-template.mjs" }, "devDependencies": { - "@codama/renderers-js": "^1.4", + "@codama/renderers-js": "^1.5", "@codama/renderers-rust": "~1.0", "@iarna/toml": "^2.2.5", - "codama": "^1.3", - "typescript": "^5.5.2", + "@solana/prettier-config-solana": "0.0.6", + "codama": "^1.5", + "typescript": "^5.9.3", "zx": "^7.2.3" }, "engines": { "node": ">=v20.0.0" }, - "packageManager": "pnpm@9.1.0" + "packageManager": "pnpm@9.1.0", + "prettier": "@solana/prettier-config-solana" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee13004..f68246e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,87 +9,77 @@ importers: .: devDependencies: '@codama/renderers-js': - specifier: ^1.4 - version: 1.4.2(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.5.3) + specifier: ^1.5 + version: 1.5.5(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.3) '@codama/renderers-rust': specifier: ~1.0 - version: 1.0.16(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.5.3) + version: 1.0.16(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.3) '@iarna/toml': specifier: ^2.2.5 version: 2.2.5 + '@solana/prettier-config-solana': + specifier: 0.0.6 + version: 0.0.6(prettier@3.6.2) codama: - specifier: ^1.3 - version: 1.3.3 + specifier: ^1.5 + version: 1.5.0 typescript: - specifier: ^5.5.2 - version: 5.5.3 + specifier: ^5.9.3 + version: 5.9.3 zx: specifier: ^7.2.3 version: 7.2.3 packages: - '@codama/cli@1.3.1': - resolution: {integrity: sha512-3m84aErp6W0cFIArYh9Ymzp2QFFHL+zFx/QS8R8piBjkA/WbSTdslZnierBBqgXkoSM6uIqvm008DSvo3gj1LA==} + '@codama/cli@1.4.4': + resolution: {integrity: sha512-0uLecW/RZC2c1wx3j/eiRAYvilvNY+2DoyEYu/hV0OfM1/uIgIyuy5U+wolV+LY4wLFYdApjYdy+5D32lngCHg==} hasBin: true '@codama/errors@1.2.8': resolution: {integrity: sha512-TVPf7oJpbHtxdu52ruftJX+DlTNWi7D65tasysqs7mfRKoiZKzmkatr5hqidBz/M9WzCddUeFAHL9ZiW6g9Ccg==} hasBin: true - '@codama/errors@1.3.3': - resolution: {integrity: sha512-iyo5qEW/rgNTTtcZnGqahcnUtMHRRTlTzeTZo6SLpuNistbEn2itOssnklNZVClhXR/4Td0riHwGedP3AjwgJA==} - hasBin: true - - '@codama/errors@1.3.7': - resolution: {integrity: sha512-96BF8agDVc2vAgL4qw1lZZfuJ7XBefdzTBk2VOUnOhdMQiLb0QhJCC4BH88OcL+rZXQdet4pk7Qwarj1I1GFKg==} + '@codama/errors@1.5.0': + resolution: {integrity: sha512-i4cS+S7JaZXhofQHFY3cwzt8rqxUVPNaeJND5VOyKUbtcOi933YXJXk52gDG4mc+CpGqHJijsJjfSpr1lJGxzg==} hasBin: true '@codama/node-types@1.2.8': resolution: {integrity: sha512-PEvPLMN3QGJvkwsQ7R9DmAtdazQXN0RD9WYlmHyeiR4nathV0qy9nZGFDoRh5nbNfPkbeLTgL5o3zAoeeRP6GQ==} - '@codama/node-types@1.3.3': - resolution: {integrity: sha512-41GdFy/OPRemXTAmptDSi/wDXHPimy40mx9v0z2EdIMNYEyKAYZDcvr2jzSei8meeCV9j4PgKF5snwBQK7HaSg==} - - '@codama/node-types@1.3.7': - resolution: {integrity: sha512-L9UTFfoeki5t+BYJAa4OMsqBPpbMbx8YJQar+55mYcjwGlJsKJW7mRfLYvwEFkCUYyLdNva40OVmTf88jccZCA==} + '@codama/node-types@1.5.0': + resolution: {integrity: sha512-Ebz2vOUukmNaFXWdkni1ZihXkAIUnPYtqIMXYxKXOxjMP+TGz2q0lGtRo7sqw1pc2ksFBIkfBp5pZsl5p6gwXA==} '@codama/nodes@1.2.8': resolution: {integrity: sha512-tCi7KErG2ChQr5n3Nj3dwciFmUo3O8RQ+S4Qv23w1zvYLaGwhEvdg3KRtgCGEI0wr9uvm2QtTBM670kdLntZiQ==} - '@codama/nodes@1.3.3': - resolution: {integrity: sha512-CgxGfH6ndcZpvf+RfVwSyIOyq8cNejbqY9TRr4SqVMIEbE1Wpqx+GPrEGRKtwHgB8KqsWCz7Pve8BCGhsPkr2g==} - - '@codama/nodes@1.3.7': - resolution: {integrity: sha512-3OV6SIBcqsIDARyzZVGdfnffNlnKSYcb0aGp/9Liz5/EID0oBTIyuh/Cmj5Ww6RX4WPb+GNAxABAGW94zbcfQg==} + '@codama/nodes@1.5.0': + resolution: {integrity: sha512-yg+xmorWiMNjS3n19CGIt/FZ/ZCuDIu+HEY45bq6gHu1MN3RtJZY+Q3v0ErnBPA60D8mNWkvkKoeSZXfzcAvfw==} '@codama/renderers-core@1.0.10': resolution: {integrity: sha512-7NwoyP2j1cZKgHCrd1RRn891gtxpZeiXNSP3aCFdVsRPW8dDNUL1sJ1SNOF9ILHfNP77clCBtL3eoZIFdeNQAg==} - '@codama/renderers-core@1.2.2': - resolution: {integrity: sha512-dPyHgn5L45G+tWP17ITvOlpX3+s2FcJHMjAhFZlmUHAJpH/wl+UsUwuWg698iSb56Er2jUwqX7srw5iZf7XHjQ==} + '@codama/renderers-core@1.3.5': + resolution: {integrity: sha512-MuZLU+3LZPQb1HuZffwZl+v5JHQDe5LYHGhA1wTMNlwRedYIysSxBjogHNciNIHsKP3JjmqyYmLO5LCEp3hjaQ==} - '@codama/renderers-js@1.4.2': - resolution: {integrity: sha512-emYJEPNDQ/DjHYDBNPt/HEr+97ClpEQT7LPPNZ44DRSEG4Qj9ti/aBvtgOrIyESyyTOaKrUzu7Ew6S+TBB/eFg==} + '@codama/renderers-js@1.5.5': + resolution: {integrity: sha512-zYVw8KGRHFzrpPKAv8PJI1pMy28qc/iEMspMC6Iw915Vsg0od75FUmUhDAvrTwgc28oyCmlrsWv6BNON4AKmqQ==} engines: {node: '>=20.18.0'} '@codama/renderers-rust@1.0.16': resolution: {integrity: sha512-pFHwHN6X4Yuk26Yfh+VT9Ps1i/QEjuK3EoT8BpsCTATOk6ntJNqyD5aQngG2lE4KWx3uQrCYYbQEAN4vG6v+EA==} - '@codama/validators@1.3.3': - resolution: {integrity: sha512-dj3vlwMlxU57l6cRLxb76ZwlrEGv+dq7llDtH0aqc1z3OW5SOryREUuzeqL7T/2hY8FiY+pxjH4CQx+A08hULQ==} + '@codama/validators@1.5.0': + resolution: {integrity: sha512-p3ufDxnCH1jiuHGzcBv4/d+ctzUcKD2K3gX/W8169tC41o9DggjlEpNy1Z6YAAhVb3wHnmXVGA2qmp32rWSfWw==} '@codama/visitors-core@1.2.8': resolution: {integrity: sha512-sYmZT2Z6Goacgr/HrAhjLSGtu2Udcal10tEfYN8ZJBXs34PGPu0oWOC8kFx7CxvmAvt/6mw8NhKIPtg/UaIKHw==} - '@codama/visitors-core@1.3.3': - resolution: {integrity: sha512-Kuz2we5iDhq0Y9bPwEjEGGSueBPJkLxoDkJ+Z3NuHlqo/k2aHvDNl9NaoOOUPwNzPVbntfpJW9Ga3pP9oc/PQQ==} - - '@codama/visitors-core@1.3.7': - resolution: {integrity: sha512-B1JnzhRDJiLxewha/F3YzeEp8Zrtd7eKiGNJFJHSPufAnIVm2lQUDaKS+OrAOHnSRmRKIAVdzfpFpdz6EM0N6Q==} + '@codama/visitors-core@1.5.0': + resolution: {integrity: sha512-3PIAlBX0a06hIxzyPtQMfQcqWGFBgfbwysSwcXBbvHUYbemwhD6xwlBKJuqTwm9DyFj3faStp5fpvcp03Rjxtw==} - '@codama/visitors@1.3.3': - resolution: {integrity: sha512-ReZoo0kItffkhpvl9qRjy3HV1nZXv/k8p4wZ10NveUTDtRghk72YkY0kpK2lt/p+2SlWrhQ9IkO4Q+EQoqABrA==} + '@codama/visitors@1.5.0': + resolution: {integrity: sha512-SwtQaleXxAaFz6uHygxki621q4nPUDQlnwEhsg+QKOjHpKWXjLYdJof+R8gUiTV/n7/IeNnjvxJTTNfUsvETPQ==} '@iarna/toml@2.2.5': resolution: {integrity: sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==} @@ -112,11 +102,14 @@ packages: peerDependencies: typescript: '>=5' - '@solana/codecs-core@3.0.3': - resolution: {integrity: sha512-emKykJ3h1DmnDOY29Uv9eJXP8E/FHzvlUBJ6te+5EbKdFjj7vdlKYPfDxOI6iGdXTY+YC/ELtbNBh6QwF2uEDQ==} + '@solana/codecs-core@5.4.0': + resolution: {integrity: sha512-rQ5jXgiDe2vIU+mYCHDjgwMd9WdzZfh4sc5H6JgYleAUjeTUX6mx8hTV2+pcXvvn27LPrgrt9jfxswbDb8O8ww==} engines: {node: '>=20.18.0'} peerDependencies: - typescript: '>=5.3.3' + typescript: ^5.0.0 + peerDependenciesMeta: + typescript: + optional: true '@solana/codecs-numbers@2.0.0-rc.4': resolution: {integrity: sha512-ZJR7TaUO65+3Hzo3YOOUCS0wlzh17IW+j0MZC2LCk1R0woaypRpHKj4iSMYeQOZkMxsd9QT3WNvjFrPC2qA6Sw==} @@ -124,11 +117,14 @@ packages: peerDependencies: typescript: '>=5' - '@solana/codecs-numbers@3.0.3': - resolution: {integrity: sha512-pfXkH9J0glrM8qj6389GAn30+cJOxzXLR2FsPOHCUMXrqLhGjMMZAWhsQkpOQ37SGc/7EiQsT/gmyGC7gxHqJQ==} + '@solana/codecs-numbers@5.4.0': + resolution: {integrity: sha512-z6LMkY+kXWx1alrvIDSAxexY5QLhsso638CjM7XI1u6dB7drTLWKhifyjnm1vOQc1VPVFmbYxTgKKpds8TY8tg==} engines: {node: '>=20.18.0'} peerDependencies: - typescript: '>=5.3.3' + typescript: ^5.0.0 + peerDependenciesMeta: + typescript: + optional: true '@solana/codecs-strings@2.0.0-rc.4': resolution: {integrity: sha512-LGfK2RL0BKjYYUfzu2FG/gTgCsYOMz9FKVs2ntji6WneZygPxJTV5W98K3J8Rl0JewpCSCFQH3xjLSHBJUS0fA==} @@ -137,12 +133,17 @@ packages: fastestsmallesttextencoderdecoder: ^1.0.22 typescript: '>=5' - '@solana/codecs-strings@3.0.3': - resolution: {integrity: sha512-VHBXnnTVtcQ1j+7Vrz+qSYo38no+jiHRdGnhFspRXEHNJbllzwKqgBE7YN3qoIXH+MKxgJUcwO5KHmdzf8Wn2A==} + '@solana/codecs-strings@5.4.0': + resolution: {integrity: sha512-w0trrjfQDhkCVz7O1GTmHBk9m+MkljKx2uNBbQAD3/yW2Qn9dYiTrZ1/jDVq0/+lPPAUkbT3s3Yo7HUZ2QFmHw==} engines: {node: '>=20.18.0'} peerDependencies: fastestsmallesttextencoderdecoder: ^1.0.22 - typescript: '>=5.3.3' + typescript: ^5.0.0 + peerDependenciesMeta: + fastestsmallesttextencoderdecoder: + optional: true + typescript: + optional: true '@solana/errors@2.0.0-rc.4': resolution: {integrity: sha512-0PPaMyB81keEHG/1pnyEuiBVKctbXO641M2w3CIOrYT/wzjunfF0FTxsqq9wYJeYo0AyiefCKGgSPs6wiY2PpQ==} @@ -151,12 +152,20 @@ packages: peerDependencies: typescript: '>=5' - '@solana/errors@3.0.3': - resolution: {integrity: sha512-1l84xJlHNva6io62PcYfUamwWlc0eM95nHgCrKX0g0cLoC6D6QHYPCEbEVkR+C5UtP9JDgyQM8MFiv+Ei5tO9Q==} + '@solana/errors@5.4.0': + resolution: {integrity: sha512-hNoAOmlZAszaVBrAy1Jf7amHJ8wnUnTU0BqhNQXknbSvirvsYr81yEud2iq18YiCqhyJ9SuQ5kWrSAT0x7S0oA==} engines: {node: '>=20.18.0'} hasBin: true peerDependencies: - typescript: '>=5.3.3' + typescript: ^5.0.0 + peerDependenciesMeta: + typescript: + optional: true + + '@solana/prettier-config-solana@0.0.6': + resolution: {integrity: sha512-/s55hDoAyh5QyltQh/jjNK3AgACEq885+DnC6lYhrmYZiV6I0iHITWYnKd8d23KRKs/RBjlaQH54MiafeoI9hw==} + peerDependencies: + prettier: ^3.7.4 '@types/fs-extra@11.0.4': resolution: {integrity: sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==} @@ -210,16 +219,12 @@ packages: resolution: {integrity: sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} - chalk@5.6.0: - resolution: {integrity: sha512-46QrSQFyVSEyYAgQ22hQ+zDa60YHA4fBstHmtSApj1Y5vKtG27fWowW03jCk5KcbXEWPZUIR894aARCA/G1kfQ==} - engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} - chalk@5.6.2: resolution: {integrity: sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} - codama@1.3.3: - resolution: {integrity: sha512-eCOflah25uWKHGyjvW2FPydRAwhDw4ZAjBuBFF9AVJIE3xknR+pcRMLdlxO5LO3ixlxkHKHdESXJY/aVXmzZtw==} + codama@1.5.0: + resolution: {integrity: sha512-hhfSzrOiDX3bV7QmJneEBsBk3ln4gIcMJs6P8BlEJ3EFI+P0QZaTT5W61o8Tq0/79hTZeyj0gP65HZ/LYJil+w==} hasBin: true commander@12.1.0: @@ -230,12 +235,8 @@ packages: resolution: {integrity: sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==} engines: {node: '>=18'} - commander@14.0.0: - resolution: {integrity: sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA==} - engines: {node: '>=20'} - - commander@14.0.1: - resolution: {integrity: sha512-2JkV3gUZUVrbNA+1sjBOYLsMZ5cEEl8GTFP2a4AVz5hvasAMCQ1D2l2le/cX+pV4N6ZU17zjUahLpIXRrnWL8A==} + commander@14.0.2: + resolution: {integrity: sha512-TywoWNNRbhoD0BXs1P3ZEScW8W5iKrnbithIl0YH+uCmBd0QpPOA8yc82DS3BIE5Ma6FnBVUsJ7wVUDz4dvOWQ==} engines: {node: '>=20'} commander@5.1.0: @@ -464,6 +465,11 @@ packages: run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} + semver@7.7.3: + resolution: {integrity: sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==} + engines: {node: '>=10'} + hasBin: true + set-function-length@1.2.2: resolution: {integrity: sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==} engines: {node: '>= 0.4'} @@ -488,8 +494,8 @@ packages: resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} engines: {node: '>=8.0'} - typescript@5.5.3: - resolution: {integrity: sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==} + typescript@5.9.3: + resolution: {integrity: sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==} engines: {node: '>=14.17'} hasBin: true @@ -525,12 +531,12 @@ packages: snapshots: - '@codama/cli@1.3.1': + '@codama/cli@1.4.4': dependencies: - '@codama/nodes': 1.3.3 - '@codama/visitors': 1.3.3 - '@codama/visitors-core': 1.3.3 - commander: 14.0.0 + '@codama/nodes': 1.5.0 + '@codama/visitors': 1.5.0 + '@codama/visitors-core': 1.5.0 + commander: 14.0.2 picocolors: 1.1.1 prompts: 2.4.2 @@ -540,38 +546,25 @@ snapshots: chalk: 5.4.1 commander: 13.1.0 - '@codama/errors@1.3.3': + '@codama/errors@1.5.0': dependencies: - '@codama/node-types': 1.3.3 - chalk: 5.6.0 - commander: 14.0.0 - - '@codama/errors@1.3.7': - dependencies: - '@codama/node-types': 1.3.7 - commander: 14.0.1 + '@codama/node-types': 1.5.0 + commander: 14.0.2 picocolors: 1.1.1 '@codama/node-types@1.2.8': {} - '@codama/node-types@1.3.3': {} - - '@codama/node-types@1.3.7': {} + '@codama/node-types@1.5.0': {} '@codama/nodes@1.2.8': dependencies: '@codama/errors': 1.2.8 '@codama/node-types': 1.2.8 - '@codama/nodes@1.3.3': + '@codama/nodes@1.5.0': dependencies: - '@codama/errors': 1.3.3 - '@codama/node-types': 1.3.3 - - '@codama/nodes@1.3.7': - dependencies: - '@codama/errors': 1.3.7 - '@codama/node-types': 1.3.7 + '@codama/errors': 1.5.0 + '@codama/node-types': 1.5.0 '@codama/renderers-core@1.0.10': dependencies: @@ -579,42 +572,43 @@ snapshots: '@codama/nodes': 1.2.8 '@codama/visitors-core': 1.2.8 - '@codama/renderers-core@1.2.2': + '@codama/renderers-core@1.3.5': dependencies: - '@codama/errors': 1.3.7 - '@codama/nodes': 1.3.7 - '@codama/visitors-core': 1.3.7 + '@codama/errors': 1.5.0 + '@codama/nodes': 1.5.0 + '@codama/visitors-core': 1.5.0 - '@codama/renderers-js@1.4.2(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.5.3)': + '@codama/renderers-js@1.5.5(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.3)': dependencies: - '@codama/errors': 1.3.7 - '@codama/nodes': 1.3.7 - '@codama/renderers-core': 1.2.2 - '@codama/visitors-core': 1.3.7 - '@solana/codecs-strings': 3.0.3(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.5.3) + '@codama/errors': 1.5.0 + '@codama/nodes': 1.5.0 + '@codama/renderers-core': 1.3.5 + '@codama/visitors-core': 1.5.0 + '@solana/codecs-strings': 5.4.0(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.3) prettier: 3.6.2 + semver: 7.7.3 transitivePeerDependencies: - fastestsmallesttextencoderdecoder - typescript - '@codama/renderers-rust@1.0.16(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.5.3)': + '@codama/renderers-rust@1.0.16(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.3)': dependencies: '@codama/errors': 1.2.8 '@codama/nodes': 1.2.8 '@codama/renderers-core': 1.0.10 '@codama/visitors-core': 1.2.8 - '@solana/codecs-strings': 2.0.0-rc.4(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.5.3) + '@solana/codecs-strings': 2.0.0-rc.4(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.3) nunjucks: 3.2.4 transitivePeerDependencies: - chokidar - fastestsmallesttextencoderdecoder - typescript - '@codama/validators@1.3.3': + '@codama/validators@1.5.0': dependencies: - '@codama/errors': 1.3.3 - '@codama/nodes': 1.3.3 - '@codama/visitors-core': 1.3.3 + '@codama/errors': 1.5.0 + '@codama/nodes': 1.5.0 + '@codama/visitors-core': 1.5.0 '@codama/visitors-core@1.2.8': dependencies: @@ -622,23 +616,17 @@ snapshots: '@codama/nodes': 1.2.8 json-stable-stringify: 1.2.1 - '@codama/visitors-core@1.3.3': - dependencies: - '@codama/errors': 1.3.3 - '@codama/nodes': 1.3.3 - json-stable-stringify: 1.3.0 - - '@codama/visitors-core@1.3.7': + '@codama/visitors-core@1.5.0': dependencies: - '@codama/errors': 1.3.7 - '@codama/nodes': 1.3.7 + '@codama/errors': 1.5.0 + '@codama/nodes': 1.5.0 json-stable-stringify: 1.3.0 - '@codama/visitors@1.3.3': + '@codama/visitors@1.5.0': dependencies: - '@codama/errors': 1.3.3 - '@codama/nodes': 1.3.3 - '@codama/visitors-core': 1.3.3 + '@codama/errors': 1.5.0 + '@codama/nodes': 1.5.0 + '@codama/visitors-core': 1.5.0 '@iarna/toml@2.2.5': {} @@ -654,55 +642,63 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 - '@solana/codecs-core@2.0.0-rc.4(typescript@5.5.3)': + '@solana/codecs-core@2.0.0-rc.4(typescript@5.9.3)': dependencies: - '@solana/errors': 2.0.0-rc.4(typescript@5.5.3) - typescript: 5.5.3 + '@solana/errors': 2.0.0-rc.4(typescript@5.9.3) + typescript: 5.9.3 - '@solana/codecs-core@3.0.3(typescript@5.5.3)': + '@solana/codecs-core@5.4.0(typescript@5.9.3)': dependencies: - '@solana/errors': 3.0.3(typescript@5.5.3) - typescript: 5.5.3 + '@solana/errors': 5.4.0(typescript@5.9.3) + optionalDependencies: + typescript: 5.9.3 - '@solana/codecs-numbers@2.0.0-rc.4(typescript@5.5.3)': + '@solana/codecs-numbers@2.0.0-rc.4(typescript@5.9.3)': dependencies: - '@solana/codecs-core': 2.0.0-rc.4(typescript@5.5.3) - '@solana/errors': 2.0.0-rc.4(typescript@5.5.3) - typescript: 5.5.3 + '@solana/codecs-core': 2.0.0-rc.4(typescript@5.9.3) + '@solana/errors': 2.0.0-rc.4(typescript@5.9.3) + typescript: 5.9.3 - '@solana/codecs-numbers@3.0.3(typescript@5.5.3)': + '@solana/codecs-numbers@5.4.0(typescript@5.9.3)': dependencies: - '@solana/codecs-core': 3.0.3(typescript@5.5.3) - '@solana/errors': 3.0.3(typescript@5.5.3) - typescript: 5.5.3 + '@solana/codecs-core': 5.4.0(typescript@5.9.3) + '@solana/errors': 5.4.0(typescript@5.9.3) + optionalDependencies: + typescript: 5.9.3 - '@solana/codecs-strings@2.0.0-rc.4(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.5.3)': + '@solana/codecs-strings@2.0.0-rc.4(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.3)': dependencies: - '@solana/codecs-core': 2.0.0-rc.4(typescript@5.5.3) - '@solana/codecs-numbers': 2.0.0-rc.4(typescript@5.5.3) - '@solana/errors': 2.0.0-rc.4(typescript@5.5.3) + '@solana/codecs-core': 2.0.0-rc.4(typescript@5.9.3) + '@solana/codecs-numbers': 2.0.0-rc.4(typescript@5.9.3) + '@solana/errors': 2.0.0-rc.4(typescript@5.9.3) fastestsmallesttextencoderdecoder: 1.0.22 - typescript: 5.5.3 + typescript: 5.9.3 - '@solana/codecs-strings@3.0.3(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.5.3)': + '@solana/codecs-strings@5.4.0(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.3)': dependencies: - '@solana/codecs-core': 3.0.3(typescript@5.5.3) - '@solana/codecs-numbers': 3.0.3(typescript@5.5.3) - '@solana/errors': 3.0.3(typescript@5.5.3) + '@solana/codecs-core': 5.4.0(typescript@5.9.3) + '@solana/codecs-numbers': 5.4.0(typescript@5.9.3) + '@solana/errors': 5.4.0(typescript@5.9.3) + optionalDependencies: fastestsmallesttextencoderdecoder: 1.0.22 - typescript: 5.5.3 + typescript: 5.9.3 - '@solana/errors@2.0.0-rc.4(typescript@5.5.3)': + '@solana/errors@2.0.0-rc.4(typescript@5.9.3)': dependencies: - chalk: 5.6.0 + chalk: 5.6.2 commander: 12.1.0 - typescript: 5.5.3 + typescript: 5.9.3 - '@solana/errors@3.0.3(typescript@5.5.3)': + '@solana/errors@5.4.0(typescript@5.9.3)': dependencies: chalk: 5.6.2 - commander: 14.0.0 - typescript: 5.5.3 + commander: 14.0.2 + optionalDependencies: + typescript: 5.9.3 + + '@solana/prettier-config-solana@0.0.6(prettier@3.6.2)': + dependencies: + prettier: 3.6.2 '@types/fs-extra@11.0.4': dependencies: @@ -757,25 +753,21 @@ snapshots: chalk@5.4.1: {} - chalk@5.6.0: {} - chalk@5.6.2: {} - codama@1.3.3: + codama@1.5.0: dependencies: - '@codama/cli': 1.3.1 - '@codama/errors': 1.3.3 - '@codama/nodes': 1.3.3 - '@codama/validators': 1.3.3 - '@codama/visitors': 1.3.3 + '@codama/cli': 1.4.4 + '@codama/errors': 1.5.0 + '@codama/nodes': 1.5.0 + '@codama/validators': 1.5.0 + '@codama/visitors': 1.5.0 commander@12.1.0: {} commander@13.1.0: {} - commander@14.0.0: {} - - commander@14.0.1: {} + commander@14.0.2: {} commander@5.1.0: {} @@ -998,6 +990,8 @@ snapshots: dependencies: queue-microtask: 1.2.3 + semver@7.7.3: {} + set-function-length@1.2.2: dependencies: define-data-property: 1.1.4 @@ -1025,7 +1019,7 @@ snapshots: dependencies: is-number: 7.0.0 - typescript@5.5.3: {} + typescript@5.9.3: {} undici-types@5.26.5: {} diff --git a/scripts/generate-clients.mjs b/scripts/generate-clients.mjs deleted file mode 100644 index 95dac89..0000000 --- a/scripts/generate-clients.mjs +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { createFromRoot } from 'codama'; -import { renderVisitor as renderJavaScriptVisitor } from '@codama/renderers-js'; -import { renderVisitor as renderRustVisitor } from '@codama/renderers-rust'; -import { workingDirectory } from './utils.mjs'; - -// Instanciate Codama. -const codama = createFromRoot( - require(path.join(workingDirectory, 'program', 'idl.json')) -); - -// Render JavaScript. -const jsClient = path.join(__dirname, '..', 'clients', 'js'); -codama.accept( - renderJavaScriptVisitor(path.join(jsClient, 'src', 'generated'), { - prettier: require(path.join(jsClient, '.prettierrc.json')), - }) -); - -// Render Rust. -const rustClient = path.join(__dirname, '..', 'clients', 'rust'); -codama.accept( - renderRustVisitor(path.join(rustClient, 'src', 'generated'), { - formatCode: true, - crateFolder: rustClient, - }) -); diff --git a/scripts/upgrade-template.mjs b/scripts/upgrade-template.mjs index 5222e5d..689ea4c 100644 --- a/scripts/upgrade-template.mjs +++ b/scripts/upgrade-template.mjs @@ -29,7 +29,6 @@ const unchangedGlobs = [ 'clients/rust/tests/*', 'program/**/*', 'program/*', - 'scripts/generate-clients.mjs', 'scripts/generate-idls.mjs', 'scripts/upgrade-template.mjs', 'scripts/program/*',