@solana-program/compute-budget 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/src/index.js +271 -53
  2. package/dist/src/index.js.map +1 -1
  3. package/dist/src/index.mjs +212 -2
  4. package/dist/src/index.mjs.map +1 -1
  5. package/dist/types/constants.d.ts +12 -0
  6. package/dist/types/constants.d.ts.map +1 -0
  7. package/dist/types/estimateAndSetComputeLimit.d.ts +24 -0
  8. package/dist/types/estimateAndSetComputeLimit.d.ts.map +1 -0
  9. package/dist/types/estimateComputeLimit.d.ts +63 -0
  10. package/dist/types/estimateComputeLimit.d.ts.map +1 -0
  11. package/dist/types/estimateComputeLimitInternal.d.ts +87 -0
  12. package/dist/types/estimateComputeLimitInternal.d.ts.map +1 -0
  13. package/dist/types/generated/instructions/requestHeapFrame.d.ts +2 -2
  14. package/dist/types/generated/instructions/requestHeapFrame.d.ts.map +1 -1
  15. package/dist/types/generated/instructions/requestUnits.d.ts +2 -2
  16. package/dist/types/generated/instructions/requestUnits.d.ts.map +1 -1
  17. package/dist/types/generated/instructions/setComputeUnitLimit.d.ts +2 -2
  18. package/dist/types/generated/instructions/setComputeUnitLimit.d.ts.map +1 -1
  19. package/dist/types/generated/instructions/setComputeUnitPrice.d.ts +2 -2
  20. package/dist/types/generated/instructions/setComputeUnitPrice.d.ts.map +1 -1
  21. package/dist/types/generated/instructions/setLoadedAccountsDataSizeLimit.d.ts +2 -2
  22. package/dist/types/generated/instructions/setLoadedAccountsDataSizeLimit.d.ts.map +1 -1
  23. package/dist/types/generated/programs/computeBudget.d.ts +1 -1
  24. package/dist/types/generated/programs/computeBudget.d.ts.map +1 -1
  25. package/dist/types/generated/shared/index.d.ts +1 -1
  26. package/dist/types/generated/shared/index.d.ts.map +1 -1
  27. package/dist/types/index.d.ts +5 -0
  28. package/dist/types/index.d.ts.map +1 -1
  29. package/dist/types/internal.d.ts +35 -0
  30. package/dist/types/internal.d.ts.map +1 -0
  31. package/dist/types/internalMoveToKit.d.ts +20 -0
  32. package/dist/types/internalMoveToKit.d.ts.map +1 -0
  33. package/dist/types/setComputeLimit.d.ts +36 -0
  34. package/dist/types/setComputeLimit.d.ts.map +1 -0
  35. package/dist/types/setComputePrice.d.ts +34 -0
  36. package/dist/types/setComputePrice.d.ts.map +1 -0
  37. package/package.json +7 -18
@@ -1,2 +1,7 @@
1
1
  export * from './generated';
2
+ export * from './constants';
3
+ export * from './estimateAndSetComputeLimit';
4
+ export * from './estimateComputeLimit';
5
+ export * from './setComputeLimit';
6
+ export * from './setComputePrice';
2
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAE5B,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { BaseTransactionMessage, IInstruction, MicroLamports } from '@solana/kit';
2
+ import { SetComputeUnitLimitInstruction, SetComputeUnitPriceInstruction } from './generated';
3
+ /**
4
+ * Finds the index of the first `SetComputeUnitLimit` instruction in a transaction message
5
+ * and its set limit, if any.
6
+ */
7
+ export declare function getSetComputeUnitLimitInstructionIndexAndUnits(transactionMessage: BaseTransactionMessage): {
8
+ index: number;
9
+ units: number;
10
+ } | null;
11
+ /**
12
+ * Finds the index of the first `SetComputeUnitLimit` instruction in a transaction message, if any.
13
+ */
14
+ export declare function getSetComputeUnitLimitInstructionIndex(transactionMessage: BaseTransactionMessage): number;
15
+ /**
16
+ * Checks if the given instruction is a `SetComputeUnitLimit` instruction.
17
+ */
18
+ export declare function isSetComputeUnitLimitInstruction(instruction: IInstruction): instruction is SetComputeUnitLimitInstruction;
19
+ /**
20
+ * Finds the index of the first `SetComputeUnitPrice` instruction in a transaction message
21
+ * and its set micro-lamports, if any.
22
+ */
23
+ export declare function getSetComputeUnitPriceInstructionIndexAndMicroLamports(transactionMessage: BaseTransactionMessage): {
24
+ index: number;
25
+ microLamports: MicroLamports;
26
+ } | null;
27
+ /**
28
+ * Finds the index of the first `SetComputeUnitPrice` instruction in a transaction message, if any.
29
+ */
30
+ export declare function getSetComputeUnitPriceInstructionIndex(transactionMessage: BaseTransactionMessage): number;
31
+ /**
32
+ * Checks if the given instruction is a `SetComputeUnitPrice` instruction.
33
+ */
34
+ export declare function isSetComputeUnitPriceInstruction(instruction: IInstruction): instruction is SetComputeUnitPriceInstruction;
35
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAGtB,YAAY,EACZ,aAAa,EAEd,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,8BAA8B,EAC9B,8BAA8B,EAC/B,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,wBAAgB,8CAA8C,CAC5D,kBAAkB,EAAE,sBAAsB,GACzC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAYzC;AAED;;GAEG;AACH,wBAAgB,sCAAsC,CACpD,kBAAkB,EAAE,sBAAsB,UAK3C;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,YAAY,GACxB,WAAW,IAAI,8BAA8B,CAM/C;AAED;;;GAGG;AACH,wBAAgB,sDAAsD,CACpE,kBAAkB,EAAE,sBAAsB,GACzC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,aAAa,CAAA;CAAE,GAAG,IAAI,CAYxD;AAED;;GAEG;AACH,wBAAgB,sCAAsC,CACpD,kBAAkB,EAAE,sBAAsB,UAK3C;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,YAAY,GACxB,WAAW,IAAI,8BAA8B,CAM/C"}
@@ -0,0 +1,20 @@
1
+ import { BaseTransactionMessage, TransactionMessageWithBlockhashLifetime, TransactionMessageWithDurableNonceLifetime } from '@solana/kit';
2
+ /**
3
+ * An invalid blockhash lifetime constraint used as a placeholder for
4
+ * transaction messages that are not yet ready to be compiled.
5
+ *
6
+ * This enables various operations on the transaction message, such as
7
+ * simulating it or calculating its transaction size, whilst defering
8
+ * the actual blockhash to a later stage.
9
+ */
10
+ export declare const PROVISORY_BLOCKHASH_LIFETIME_CONSTRAINT: TransactionMessageWithBlockhashLifetime['lifetimeConstraint'];
11
+ /**
12
+ * Sets a provisory blockhash lifetime constraint on the transaction message
13
+ * if and only if it doesn't already have a lifetime constraint.
14
+ */
15
+ export declare function fillMissingTransactionMessageLifetimeUsingProvisoryBlockhash<TTransactionMessage extends BaseTransactionMessage>(transactionMessage: TTransactionMessage): TTransactionMessage & (TransactionMessageWithBlockhashLifetime | TransactionMessageWithDurableNonceLifetime);
16
+ /**
17
+ * Sets a provisory blockhash lifetime constraint on the transaction message.
18
+ */
19
+ export declare function setTransactionMessageLifetimeUsingProvisoryBlockhash<TTransactionMessage extends BaseTransactionMessage>(transactionMessage: TTransactionMessage): TTransactionMessage & TransactionMessageWithBlockhashLifetime;
20
+ //# sourceMappingURL=internalMoveToKit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internalMoveToKit.d.ts","sourceRoot":"","sources":["../../src/internalMoveToKit.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EAGtB,uCAAuC,EACvC,0CAA0C,EAC3C,MAAM,aAAa,CAAC;AAErB;;;;;;;GAOG;AACH,eAAO,MAAM,uCAAuC,EAAE,uCAAuC,CAAC,oBAAoB,CAI/G,CAAC;AAEJ;;;GAGG;AACH,wBAAgB,4DAA4D,CAC1E,mBAAmB,SAAS,sBAAsB,EAElD,kBAAkB,EAAE,mBAAmB,GACtC,mBAAmB,GACpB,CACI,uCAAuC,GACvC,0CAA0C,CAC7C,CAcF;AAED;;GAEG;AACH,wBAAgB,oDAAoD,CAClE,mBAAmB,SAAS,sBAAsB,EAElD,kBAAkB,EAAE,mBAAmB,GACtC,mBAAmB,GAAG,uCAAuC,CAK/D"}
@@ -0,0 +1,36 @@
1
+ import { BaseTransactionMessage } from '@solana/kit';
2
+ /**
3
+ * Appends a `SetComputeUnitLimit` instruction with a provisory
4
+ * compute unit limit to a given transaction message
5
+ * if and only if it does not already have one.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const transactionMessage = pipe(
10
+ * createTransactionMessage({ version: 0 }),
11
+ * fillProvisorySetComputeUnitLimitInstruction,
12
+ * // ...
13
+ * );
14
+ * ```
15
+ */
16
+ export declare function fillProvisorySetComputeUnitLimitInstruction<TTransactionMessage extends BaseTransactionMessage>(transactionMessage: TTransactionMessage): TTransactionMessage;
17
+ /**
18
+ * Updates the first `SetComputeUnitLimit` instruction in a transaction message
19
+ * with the given units, or appends a new instruction if none exists.
20
+ * A function of the current value can be provided instead of a static value.
21
+ *
22
+ * @param units - The new compute unit limit, or a function that takes the previous
23
+ * compute unit limit and returns the new limit.
24
+ * @param transactionMessage - The transaction message to update.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const updatedTransactionMessage = updateOrAppendSetComputeUnitLimitInstruction(
29
+ * // E.g. Keep the current limit if it is set, otherwise set it to the maximum.
30
+ * (currentUnits) => currentUnits === null ? MAX_COMPUTE_UNIT_LIMIT : currentUnits,
31
+ * transactionMessage,
32
+ * );
33
+ * ```
34
+ */
35
+ export declare function updateOrAppendSetComputeUnitLimitInstruction<TTransactionMessage extends BaseTransactionMessage>(units: number | ((previousUnits: number | null) => number), transactionMessage: TTransactionMessage): TTransactionMessage;
36
+ //# sourceMappingURL=setComputeLimit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setComputeLimit.d.ts","sourceRoot":"","sources":["../../src/setComputeLimit.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAKrB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2CAA2C,CACzD,mBAAmB,SAAS,sBAAsB,EAClD,kBAAkB,EAAE,mBAAmB,uBAMxC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4CAA4C,CAC1D,mBAAmB,SAAS,sBAAsB,EAElD,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC,EAC1D,kBAAkB,EAAE,mBAAmB,GACtC,mBAAmB,CA0BrB"}
@@ -0,0 +1,34 @@
1
+ import { BaseTransactionMessage, MicroLamports } from '@solana/kit';
2
+ /**
3
+ * Sets the compute unit price of a transaction message in micro-Lamports.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const transactionMessage = pipe(
8
+ * createTransactionMessage({ version: 0 }),
9
+ * (m) => setTransactionMessageComputeUnitPrice(10_000, m),
10
+ * // ...
11
+ * );
12
+ * ```
13
+ */
14
+ export declare function setTransactionMessageComputeUnitPrice<TTransactionMessage extends BaseTransactionMessage>(microLamports: number | bigint, transactionMessage: TTransactionMessage): TTransactionMessage;
15
+ /**
16
+ * Updates the first `SetComputeUnitPrice` instruction in a transaction message
17
+ * with the given micro-Lamports, or appends a new instruction if none exists.
18
+ * A function of the current value can be provided instead of a static value.
19
+ *
20
+ * @param microLamports - The new compute unit price, or a function that
21
+ * takes the previous price and returns the new one.
22
+ * @param transactionMessage - The transaction message to update.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const updatedTransactionMessage = updateOrAppendSetComputeUnitPriceInstruction(
27
+ * // E.g. double the current price or set it to 10_000 if it isn't set.
28
+ * (currentPrice) => currentPrice === null ? 10_000 : currentPrice * 2,
29
+ * transactionMessage,
30
+ * );
31
+ * ```
32
+ */
33
+ export declare function updateOrAppendSetComputeUnitPriceInstruction<TTransactionMessage extends BaseTransactionMessage>(microLamports: MicroLamports | ((previousMicroLamports: MicroLamports | null) => MicroLamports), transactionMessage: TTransactionMessage): TTransactionMessage;
34
+ //# sourceMappingURL=setComputePrice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setComputePrice.d.ts","sourceRoot":"","sources":["../../src/setComputePrice.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EACtB,aAAa,EACd,MAAM,aAAa,CAAC;AAIrB;;;;;;;;;;;GAWG;AACH,wBAAgB,qCAAqC,CACnD,mBAAmB,SAAS,sBAAsB,EAClD,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,kBAAkB,EAAE,mBAAmB,uBAKxE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4CAA4C,CAC1D,mBAAmB,SAAS,sBAAsB,EAElD,aAAa,EACT,aAAa,GACb,CAAC,CAAC,qBAAqB,EAAE,aAAa,GAAG,IAAI,KAAK,aAAa,CAAC,EACpE,kBAAkB,EAAE,mBAAmB,GACtC,mBAAmB,CAkCrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana-program/compute-budget",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "description": "JavaScript client for the Compute Budget program",
5
5
  "sideEffects": false,
6
6
  "module": "./dist/src/index.mjs",
@@ -32,38 +32,27 @@
32
32
  },
33
33
  "homepage": "https://github.com/solana-program/compute-budget#readme",
34
34
  "peerDependencies": {
35
- "@solana/web3.js": "^2.0.0"
35
+ "@solana/kit": "^2.1.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@ava/typescript": "^4.1.0",
39
38
  "@solana/eslint-config-solana": "^3.0.3",
40
- "@solana/web3.js": "^2.0.0",
39
+ "@solana/kit": "^2.1.0",
41
40
  "@types/node": "^20",
42
41
  "@typescript-eslint/eslint-plugin": "^7.16.1",
43
42
  "@typescript-eslint/parser": "^7.16.1",
44
- "ava": "^6.1.3",
45
43
  "eslint": "^8.57.0",
46
44
  "prettier": "^3.3.3",
47
45
  "rimraf": "^5.0.5",
48
46
  "tsup": "^8.1.2",
49
47
  "typedoc": "^0.25.12",
50
- "typescript": "^5.5.3"
51
- },
52
- "ava": {
53
- "nodeArguments": [
54
- "--no-warnings"
55
- ],
56
- "typescript": {
57
- "compile": false,
58
- "rewritePaths": {
59
- "test/": "dist/test/"
60
- }
61
- }
48
+ "typescript": "^5.5.3",
49
+ "vitest": "^3.1.3"
62
50
  },
63
51
  "scripts": {
64
52
  "build": "rimraf dist && tsup && tsc -p ./tsconfig.declarations.json",
65
53
  "build:docs": "typedoc",
66
- "test": "ava",
54
+ "dev": "vitest",
55
+ "test": "vitest run",
67
56
  "lint": "eslint --ext js,ts,tsx src",
68
57
  "lint:fix": "eslint --fix --ext js,ts,tsx src",
69
58
  "format": "prettier --check src test",