Skip to content

Commit a31383c

Browse files
committed
Update documentation
1 parent 126d0d9 commit a31383c

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

clients/js/src/estimateAndSetComputeLimit.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ type EstimateAndUpdateProvisoryComputeUnitLimitFactoryFunction = <
3232
*
3333
* @example
3434
* ```ts
35-
* const estimateComputeUnitLimit = estimateComputeUnitLimitFactory({ rpc });
36-
* const estimateAndUpdateProvisoryComputeUnitLimit =
37-
* estimateAndUpdateProvisoryComputeUnitLimitFactory(estimateComputeUnitLimit);
38-
* const estimatedTransactionMessage =
39-
* await estimateAndUpdateProvisoryComputeUnitLimit(transactionMessage)
35+
* const estimateAndUpdateCUs = estimateAndUpdateProvisoryComputeUnitLimitFactory(
36+
* estimateComputeUnitLimitFactory({ rpc })
37+
* );
38+
*
39+
* const transactionMessageWithCUs = await estimateAndUpdateCUs(transactionMessage);
4040
* ```
41+
*
42+
* @see {@link estimateAndUpdateProvisoryComputeUnitLimitFactory}
4143
*/
4244
export function estimateAndUpdateProvisoryComputeUnitLimitFactory(
4345
estimateComputeUnitLimit: EstimateComputeUnitLimitFactoryFunction

clients/js/src/estimateComputeLimit.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ import {
4141
* @example
4242
* ```ts
4343
* import { getSetComputeUnitLimitInstruction } from '@solana-program/compute-budget';
44-
* import { createSolanaRpc, getComputeUnitEstimateForTransactionMessageFactory, pipe } from '@solana/kit';
44+
* import { createSolanaRpc, estimateComputeUnitLimitFactory, pipe } from '@solana/kit';
4545
*
4646
* // Create an estimator function.
4747
* const rpc = createSolanaRpc('http://127.0.0.1:8899');
48-
* const getComputeUnitEstimateForTransactionMessage = getComputeUnitEstimateForTransactionMessageFactory({
49-
* rpc,
50-
* });
48+
* const estimateComputeUnitLimit = estimateComputeUnitLimitFactory({ rpc });
5149
*
5250
* // Create your transaction message.
5351
* const transactionMessage = pipe(
@@ -57,11 +55,11 @@ import {
5755
*
5856
* // Request an estimate of the actual compute units this message will consume. This is done by
5957
* // simulating the transaction and grabbing the estimated compute units from the result.
60-
* const computeUnitsEstimate = await getComputeUnitEstimateForTransactionMessage(transactionMessage);
58+
* const estimatedUnits = await estimateComputeUnitLimit(transactionMessage);
6159
*
6260
* // Set the transaction message's compute unit budget.
6361
* const transactionMessageWithComputeUnitLimit = prependTransactionMessageInstruction(
64-
* getSetComputeUnitLimitInstruction({ units: computeUnitsEstimate }),
62+
* getSetComputeUnitLimitInstruction({ units: estimatedUnits }),
6563
* transactionMessage,
6664
* );
6765
* ```

clients/js/src/setComputeLimit.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import { getSetComputeUnitLimitInstructionIndexAndUnits } from './internal';
1010
* Appends a `SetComputeUnitLimit` instruction with a provisory
1111
* compute unit limit to a given transaction message
1212
* if and only if it does not already have one.
13+
*
14+
* @example
15+
* ```ts
16+
* const transactionMessage = pipe(
17+
* createTransactionMessage({ version: 0 }),
18+
* fillProvisorySetComputeUnitLimitInstruction,
19+
* // ...
20+
* );
21+
* ```
1322
*/
1423
export function fillProvisorySetComputeUnitLimitInstruction<
1524
TTransactionMessage extends BaseTransactionMessage,
@@ -24,10 +33,20 @@ export function fillProvisorySetComputeUnitLimitInstruction<
2433
/**
2534
* Updates the first `SetComputeUnitLimit` instruction in a transaction message
2635
* with the given units, or appends a new instruction if none exists.
36+
* A function of the current value can be provided instead of a static value.
2737
*
2838
* @param units - The new compute unit limit, or a function that takes the previous
2939
* compute unit limit and returns the new limit.
3040
* @param transactionMessage - The transaction message to update.
41+
*
42+
* @example
43+
* ```ts
44+
* const updatedTransactionMessage = updateOrAppendSetComputeUnitLimitInstruction(
45+
* // E.g. Keep the current limit if it is set, otherwise set it to the maximum.
46+
* (currentUnits) => currentUnits === null ? MAX_COMPUTE_UNIT_LIMIT : currentUnits,
47+
* transactionMessage,
48+
* );
49+
* ```
3150
*/
3251
export function updateOrAppendSetComputeUnitLimitInstruction<
3352
TTransactionMessage extends BaseTransactionMessage,

clients/js/src/setComputePrice.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ import {
66
import { getSetComputeUnitPriceInstruction } from './generated';
77
import { getSetComputeUnitPriceInstructionIndexAndMicroLamports } from './internal';
88

9+
/**
10+
* Sets the compute unit price of a transaction message in micro-Lamports.
11+
*
12+
* @example
13+
* ```ts
14+
* const transactionMessage = pipe(
15+
* createTransactionMessage({ version: 0 }),
16+
* (m) => setTransactionMessageComputeUnitPrice(10_000, m),
17+
* // ...
18+
* );
19+
* ```
20+
*/
921
export function setTransactionMessageComputeUnitPrice<
1022
TTransactionMessage extends BaseTransactionMessage,
1123
>(microLamports: number | bigint, transactionMessage: TTransactionMessage) {
@@ -17,11 +29,21 @@ export function setTransactionMessageComputeUnitPrice<
1729

1830
/**
1931
* Updates the first `SetComputeUnitPrice` instruction in a transaction message
20-
* with the given units, or appends a new instruction if none exists.
32+
* with the given micro-Lamports, or appends a new instruction if none exists.
33+
* A function of the current value can be provided instead of a static value.
2134
*
2235
* @param microLamports - The new compute unit price, or a function that
2336
* takes the previous price and returns the new one.
2437
* @param transactionMessage - The transaction message to update.
38+
*
39+
* @example
40+
* ```ts
41+
* const updatedTransactionMessage = updateOrAppendSetComputeUnitPriceInstruction(
42+
* // E.g. double the current price or set it to 10_000 if it isn't set.
43+
* (currentPrice) => currentPrice === null ? 10_000 : currentPrice * 2,
44+
* transactionMessage,
45+
* );
46+
* ```
2547
*/
2648
export function updateOrAppendSetComputeUnitPriceInstruction<
2749
TTransactionMessage extends BaseTransactionMessage,

0 commit comments

Comments
 (0)