@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.
- package/dist/src/index.js +271 -53
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +212 -2
- package/dist/src/index.mjs.map +1 -1
- package/dist/types/constants.d.ts +12 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/estimateAndSetComputeLimit.d.ts +24 -0
- package/dist/types/estimateAndSetComputeLimit.d.ts.map +1 -0
- package/dist/types/estimateComputeLimit.d.ts +63 -0
- package/dist/types/estimateComputeLimit.d.ts.map +1 -0
- package/dist/types/estimateComputeLimitInternal.d.ts +87 -0
- package/dist/types/estimateComputeLimitInternal.d.ts.map +1 -0
- package/dist/types/generated/instructions/requestHeapFrame.d.ts +2 -2
- package/dist/types/generated/instructions/requestHeapFrame.d.ts.map +1 -1
- package/dist/types/generated/instructions/requestUnits.d.ts +2 -2
- package/dist/types/generated/instructions/requestUnits.d.ts.map +1 -1
- package/dist/types/generated/instructions/setComputeUnitLimit.d.ts +2 -2
- package/dist/types/generated/instructions/setComputeUnitLimit.d.ts.map +1 -1
- package/dist/types/generated/instructions/setComputeUnitPrice.d.ts +2 -2
- package/dist/types/generated/instructions/setComputeUnitPrice.d.ts.map +1 -1
- package/dist/types/generated/instructions/setLoadedAccountsDataSizeLimit.d.ts +2 -2
- package/dist/types/generated/instructions/setLoadedAccountsDataSizeLimit.d.ts.map +1 -1
- package/dist/types/generated/programs/computeBudget.d.ts +1 -1
- package/dist/types/generated/programs/computeBudget.d.ts.map +1 -1
- package/dist/types/generated/shared/index.d.ts +1 -1
- package/dist/types/generated/shared/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/internal.d.ts +35 -0
- package/dist/types/internal.d.ts.map +1 -0
- package/dist/types/internalMoveToKit.d.ts +20 -0
- package/dist/types/internalMoveToKit.d.ts.map +1 -0
- package/dist/types/setComputeLimit.d.ts +36 -0
- package/dist/types/setComputeLimit.d.ts.map +1 -0
- package/dist/types/setComputePrice.d.ts +34 -0
- package/dist/types/setComputePrice.d.ts.map +1 -0
- package/package.json +7 -18
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var kit = require('@solana/kit');
|
|
4
4
|
|
|
5
5
|
// src/generated/instructions/requestHeapFrame.ts
|
|
6
6
|
var COMPUTE_BUDGET_PROGRAM_ADDRESS = "ComputeBudget111111111111111111111111111111";
|
|
@@ -14,19 +14,19 @@ var ComputeBudgetInstruction = /* @__PURE__ */ ((ComputeBudgetInstruction2) => {
|
|
|
14
14
|
})(ComputeBudgetInstruction || {});
|
|
15
15
|
function identifyComputeBudgetInstruction(instruction) {
|
|
16
16
|
const data = "data" in instruction ? instruction.data : instruction;
|
|
17
|
-
if (
|
|
17
|
+
if (kit.containsBytes(data, kit.getU8Encoder().encode(0), 0)) {
|
|
18
18
|
return 0 /* RequestUnits */;
|
|
19
19
|
}
|
|
20
|
-
if (
|
|
20
|
+
if (kit.containsBytes(data, kit.getU8Encoder().encode(1), 0)) {
|
|
21
21
|
return 1 /* RequestHeapFrame */;
|
|
22
22
|
}
|
|
23
|
-
if (
|
|
23
|
+
if (kit.containsBytes(data, kit.getU8Encoder().encode(2), 0)) {
|
|
24
24
|
return 2 /* SetComputeUnitLimit */;
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
26
|
+
if (kit.containsBytes(data, kit.getU8Encoder().encode(3), 0)) {
|
|
27
27
|
return 3 /* SetComputeUnitPrice */;
|
|
28
28
|
}
|
|
29
|
-
if (
|
|
29
|
+
if (kit.containsBytes(data, kit.getU8Encoder().encode(4), 0)) {
|
|
30
30
|
return 4 /* SetLoadedAccountsDataSizeLimit */;
|
|
31
31
|
}
|
|
32
32
|
throw new Error(
|
|
@@ -37,25 +37,25 @@ function identifyComputeBudgetInstruction(instruction) {
|
|
|
37
37
|
// src/generated/instructions/requestHeapFrame.ts
|
|
38
38
|
var REQUEST_HEAP_FRAME_DISCRIMINATOR = 1;
|
|
39
39
|
function getRequestHeapFrameDiscriminatorBytes() {
|
|
40
|
-
return
|
|
40
|
+
return kit.getU8Encoder().encode(REQUEST_HEAP_FRAME_DISCRIMINATOR);
|
|
41
41
|
}
|
|
42
42
|
function getRequestHeapFrameInstructionDataEncoder() {
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
["discriminator",
|
|
46
|
-
["bytes",
|
|
43
|
+
return kit.transformEncoder(
|
|
44
|
+
kit.getStructEncoder([
|
|
45
|
+
["discriminator", kit.getU8Encoder()],
|
|
46
|
+
["bytes", kit.getU32Encoder()]
|
|
47
47
|
]),
|
|
48
48
|
(value) => ({ ...value, discriminator: REQUEST_HEAP_FRAME_DISCRIMINATOR })
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
function getRequestHeapFrameInstructionDataDecoder() {
|
|
52
|
-
return
|
|
53
|
-
["discriminator",
|
|
54
|
-
["bytes",
|
|
52
|
+
return kit.getStructDecoder([
|
|
53
|
+
["discriminator", kit.getU8Decoder()],
|
|
54
|
+
["bytes", kit.getU32Decoder()]
|
|
55
55
|
]);
|
|
56
56
|
}
|
|
57
57
|
function getRequestHeapFrameInstructionDataCodec() {
|
|
58
|
-
return
|
|
58
|
+
return kit.combineCodec(
|
|
59
59
|
getRequestHeapFrameInstructionDataEncoder(),
|
|
60
60
|
getRequestHeapFrameInstructionDataDecoder()
|
|
61
61
|
);
|
|
@@ -79,27 +79,27 @@ function parseRequestHeapFrameInstruction(instruction) {
|
|
|
79
79
|
}
|
|
80
80
|
var REQUEST_UNITS_DISCRIMINATOR = 0;
|
|
81
81
|
function getRequestUnitsDiscriminatorBytes() {
|
|
82
|
-
return
|
|
82
|
+
return kit.getU8Encoder().encode(REQUEST_UNITS_DISCRIMINATOR);
|
|
83
83
|
}
|
|
84
84
|
function getRequestUnitsInstructionDataEncoder() {
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
["discriminator",
|
|
88
|
-
["units",
|
|
89
|
-
["additionalFee",
|
|
85
|
+
return kit.transformEncoder(
|
|
86
|
+
kit.getStructEncoder([
|
|
87
|
+
["discriminator", kit.getU8Encoder()],
|
|
88
|
+
["units", kit.getU32Encoder()],
|
|
89
|
+
["additionalFee", kit.getU32Encoder()]
|
|
90
90
|
]),
|
|
91
91
|
(value) => ({ ...value, discriminator: REQUEST_UNITS_DISCRIMINATOR })
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
function getRequestUnitsInstructionDataDecoder() {
|
|
95
|
-
return
|
|
96
|
-
["discriminator",
|
|
97
|
-
["units",
|
|
98
|
-
["additionalFee",
|
|
95
|
+
return kit.getStructDecoder([
|
|
96
|
+
["discriminator", kit.getU8Decoder()],
|
|
97
|
+
["units", kit.getU32Decoder()],
|
|
98
|
+
["additionalFee", kit.getU32Decoder()]
|
|
99
99
|
]);
|
|
100
100
|
}
|
|
101
101
|
function getRequestUnitsInstructionDataCodec() {
|
|
102
|
-
return
|
|
102
|
+
return kit.combineCodec(
|
|
103
103
|
getRequestUnitsInstructionDataEncoder(),
|
|
104
104
|
getRequestUnitsInstructionDataDecoder()
|
|
105
105
|
);
|
|
@@ -123,13 +123,13 @@ function parseRequestUnitsInstruction(instruction) {
|
|
|
123
123
|
}
|
|
124
124
|
var SET_COMPUTE_UNIT_LIMIT_DISCRIMINATOR = 2;
|
|
125
125
|
function getSetComputeUnitLimitDiscriminatorBytes() {
|
|
126
|
-
return
|
|
126
|
+
return kit.getU8Encoder().encode(SET_COMPUTE_UNIT_LIMIT_DISCRIMINATOR);
|
|
127
127
|
}
|
|
128
128
|
function getSetComputeUnitLimitInstructionDataEncoder() {
|
|
129
|
-
return
|
|
130
|
-
|
|
131
|
-
["discriminator",
|
|
132
|
-
["units",
|
|
129
|
+
return kit.transformEncoder(
|
|
130
|
+
kit.getStructEncoder([
|
|
131
|
+
["discriminator", kit.getU8Encoder()],
|
|
132
|
+
["units", kit.getU32Encoder()]
|
|
133
133
|
]),
|
|
134
134
|
(value) => ({
|
|
135
135
|
...value,
|
|
@@ -138,13 +138,13 @@ function getSetComputeUnitLimitInstructionDataEncoder() {
|
|
|
138
138
|
);
|
|
139
139
|
}
|
|
140
140
|
function getSetComputeUnitLimitInstructionDataDecoder() {
|
|
141
|
-
return
|
|
142
|
-
["discriminator",
|
|
143
|
-
["units",
|
|
141
|
+
return kit.getStructDecoder([
|
|
142
|
+
["discriminator", kit.getU8Decoder()],
|
|
143
|
+
["units", kit.getU32Decoder()]
|
|
144
144
|
]);
|
|
145
145
|
}
|
|
146
146
|
function getSetComputeUnitLimitInstructionDataCodec() {
|
|
147
|
-
return
|
|
147
|
+
return kit.combineCodec(
|
|
148
148
|
getSetComputeUnitLimitInstructionDataEncoder(),
|
|
149
149
|
getSetComputeUnitLimitInstructionDataDecoder()
|
|
150
150
|
);
|
|
@@ -170,13 +170,13 @@ function parseSetComputeUnitLimitInstruction(instruction) {
|
|
|
170
170
|
}
|
|
171
171
|
var SET_COMPUTE_UNIT_PRICE_DISCRIMINATOR = 3;
|
|
172
172
|
function getSetComputeUnitPriceDiscriminatorBytes() {
|
|
173
|
-
return
|
|
173
|
+
return kit.getU8Encoder().encode(SET_COMPUTE_UNIT_PRICE_DISCRIMINATOR);
|
|
174
174
|
}
|
|
175
175
|
function getSetComputeUnitPriceInstructionDataEncoder() {
|
|
176
|
-
return
|
|
177
|
-
|
|
178
|
-
["discriminator",
|
|
179
|
-
["microLamports",
|
|
176
|
+
return kit.transformEncoder(
|
|
177
|
+
kit.getStructEncoder([
|
|
178
|
+
["discriminator", kit.getU8Encoder()],
|
|
179
|
+
["microLamports", kit.getU64Encoder()]
|
|
180
180
|
]),
|
|
181
181
|
(value) => ({
|
|
182
182
|
...value,
|
|
@@ -185,13 +185,13 @@ function getSetComputeUnitPriceInstructionDataEncoder() {
|
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
187
|
function getSetComputeUnitPriceInstructionDataDecoder() {
|
|
188
|
-
return
|
|
189
|
-
["discriminator",
|
|
190
|
-
["microLamports",
|
|
188
|
+
return kit.getStructDecoder([
|
|
189
|
+
["discriminator", kit.getU8Decoder()],
|
|
190
|
+
["microLamports", kit.getU64Decoder()]
|
|
191
191
|
]);
|
|
192
192
|
}
|
|
193
193
|
function getSetComputeUnitPriceInstructionDataCodec() {
|
|
194
|
-
return
|
|
194
|
+
return kit.combineCodec(
|
|
195
195
|
getSetComputeUnitPriceInstructionDataEncoder(),
|
|
196
196
|
getSetComputeUnitPriceInstructionDataDecoder()
|
|
197
197
|
);
|
|
@@ -217,15 +217,15 @@ function parseSetComputeUnitPriceInstruction(instruction) {
|
|
|
217
217
|
}
|
|
218
218
|
var SET_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_DISCRIMINATOR = 4;
|
|
219
219
|
function getSetLoadedAccountsDataSizeLimitDiscriminatorBytes() {
|
|
220
|
-
return
|
|
220
|
+
return kit.getU8Encoder().encode(
|
|
221
221
|
SET_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_DISCRIMINATOR
|
|
222
222
|
);
|
|
223
223
|
}
|
|
224
224
|
function getSetLoadedAccountsDataSizeLimitInstructionDataEncoder() {
|
|
225
|
-
return
|
|
226
|
-
|
|
227
|
-
["discriminator",
|
|
228
|
-
["accountDataSizeLimit",
|
|
225
|
+
return kit.transformEncoder(
|
|
226
|
+
kit.getStructEncoder([
|
|
227
|
+
["discriminator", kit.getU8Encoder()],
|
|
228
|
+
["accountDataSizeLimit", kit.getU32Encoder()]
|
|
229
229
|
]),
|
|
230
230
|
(value) => ({
|
|
231
231
|
...value,
|
|
@@ -234,13 +234,13 @@ function getSetLoadedAccountsDataSizeLimitInstructionDataEncoder() {
|
|
|
234
234
|
);
|
|
235
235
|
}
|
|
236
236
|
function getSetLoadedAccountsDataSizeLimitInstructionDataDecoder() {
|
|
237
|
-
return
|
|
238
|
-
["discriminator",
|
|
239
|
-
["accountDataSizeLimit",
|
|
237
|
+
return kit.getStructDecoder([
|
|
238
|
+
["discriminator", kit.getU8Decoder()],
|
|
239
|
+
["accountDataSizeLimit", kit.getU32Decoder()]
|
|
240
240
|
]);
|
|
241
241
|
}
|
|
242
242
|
function getSetLoadedAccountsDataSizeLimitInstructionDataCodec() {
|
|
243
|
-
return
|
|
243
|
+
return kit.combineCodec(
|
|
244
244
|
getSetLoadedAccountsDataSizeLimitInstructionDataEncoder(),
|
|
245
245
|
getSetLoadedAccountsDataSizeLimitInstructionDataDecoder()
|
|
246
246
|
);
|
|
@@ -265,13 +265,228 @@ function parseSetLoadedAccountsDataSizeLimitInstruction(instruction) {
|
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
// src/constants.ts
|
|
269
|
+
var PROVISORY_COMPUTE_UNIT_LIMIT = 0;
|
|
270
|
+
var MAX_COMPUTE_UNIT_LIMIT = 14e5;
|
|
271
|
+
function getSetComputeUnitLimitInstructionIndexAndUnits(transactionMessage) {
|
|
272
|
+
const index = getSetComputeUnitLimitInstructionIndex(transactionMessage);
|
|
273
|
+
if (index < 0) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
const units = kit.getU32Decoder().decode(
|
|
277
|
+
transactionMessage.instructions[index].data,
|
|
278
|
+
1
|
|
279
|
+
);
|
|
280
|
+
return { index, units };
|
|
281
|
+
}
|
|
282
|
+
function getSetComputeUnitLimitInstructionIndex(transactionMessage) {
|
|
283
|
+
return transactionMessage.instructions.findIndex(
|
|
284
|
+
isSetComputeUnitLimitInstruction
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
function isSetComputeUnitLimitInstruction(instruction) {
|
|
288
|
+
return instruction.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS && identifyComputeBudgetInstruction(instruction.data) === 2 /* SetComputeUnitLimit */;
|
|
289
|
+
}
|
|
290
|
+
function getSetComputeUnitPriceInstructionIndexAndMicroLamports(transactionMessage) {
|
|
291
|
+
const index = getSetComputeUnitPriceInstructionIndex(transactionMessage);
|
|
292
|
+
if (index < 0) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
const microLamports = kit.getU64Decoder().decode(
|
|
296
|
+
transactionMessage.instructions[index].data,
|
|
297
|
+
1
|
|
298
|
+
);
|
|
299
|
+
return { index, microLamports };
|
|
300
|
+
}
|
|
301
|
+
function getSetComputeUnitPriceInstructionIndex(transactionMessage) {
|
|
302
|
+
return transactionMessage.instructions.findIndex(
|
|
303
|
+
isSetComputeUnitPriceInstruction
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
function isSetComputeUnitPriceInstruction(instruction) {
|
|
307
|
+
return instruction.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS && identifyComputeBudgetInstruction(instruction.data) === 3 /* SetComputeUnitPrice */;
|
|
308
|
+
}
|
|
309
|
+
function fillProvisorySetComputeUnitLimitInstruction(transactionMessage) {
|
|
310
|
+
return updateOrAppendSetComputeUnitLimitInstruction(
|
|
311
|
+
(previousUnits) => previousUnits === null ? PROVISORY_COMPUTE_UNIT_LIMIT : previousUnits,
|
|
312
|
+
transactionMessage
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
function updateOrAppendSetComputeUnitLimitInstruction(units, transactionMessage) {
|
|
316
|
+
const getUnits = (previousUnits2) => typeof units === "function" ? units(previousUnits2) : units;
|
|
317
|
+
const instructionDetails = getSetComputeUnitLimitInstructionIndexAndUnits(transactionMessage);
|
|
318
|
+
if (!instructionDetails) {
|
|
319
|
+
return kit.appendTransactionMessageInstruction(
|
|
320
|
+
getSetComputeUnitLimitInstruction({ units: getUnits(null) }),
|
|
321
|
+
transactionMessage
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
const { index, units: previousUnits } = instructionDetails;
|
|
325
|
+
const newUnits = getUnits(previousUnits);
|
|
326
|
+
if (newUnits === previousUnits) {
|
|
327
|
+
return transactionMessage;
|
|
328
|
+
}
|
|
329
|
+
const newInstruction = getSetComputeUnitLimitInstruction({ units: newUnits });
|
|
330
|
+
const newInstructions = [...transactionMessage.instructions];
|
|
331
|
+
newInstructions.splice(index, 1, newInstruction);
|
|
332
|
+
return Object.freeze({
|
|
333
|
+
...transactionMessage,
|
|
334
|
+
instructions: newInstructions
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/estimateAndSetComputeLimit.ts
|
|
339
|
+
function estimateAndUpdateProvisoryComputeUnitLimitFactory(estimateComputeUnitLimit2) {
|
|
340
|
+
return async function fn(transactionMessage, config) {
|
|
341
|
+
const instructionDetails = getSetComputeUnitLimitInstructionIndexAndUnits(transactionMessage);
|
|
342
|
+
if (instructionDetails && instructionDetails.units !== PROVISORY_COMPUTE_UNIT_LIMIT && instructionDetails.units !== MAX_COMPUTE_UNIT_LIMIT) {
|
|
343
|
+
return transactionMessage;
|
|
344
|
+
}
|
|
345
|
+
return updateOrAppendSetComputeUnitLimitInstruction(
|
|
346
|
+
await estimateComputeUnitLimit2(transactionMessage, config),
|
|
347
|
+
transactionMessage
|
|
348
|
+
);
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
var PROVISORY_BLOCKHASH_LIFETIME_CONSTRAINT = {
|
|
352
|
+
blockhash: "11111111111111111111111111111111",
|
|
353
|
+
lastValidBlockHeight: 0n
|
|
354
|
+
// This is not included in compiled transactions; it can be anything.
|
|
355
|
+
};
|
|
356
|
+
function fillMissingTransactionMessageLifetimeUsingProvisoryBlockhash(transactionMessage) {
|
|
357
|
+
if ("lifetimeConstraint" in transactionMessage) {
|
|
358
|
+
return transactionMessage;
|
|
359
|
+
}
|
|
360
|
+
return setTransactionMessageLifetimeUsingProvisoryBlockhash(
|
|
361
|
+
transactionMessage
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
function setTransactionMessageLifetimeUsingProvisoryBlockhash(transactionMessage) {
|
|
365
|
+
return kit.setTransactionMessageLifetimeUsingBlockhash(
|
|
366
|
+
PROVISORY_BLOCKHASH_LIFETIME_CONSTRAINT,
|
|
367
|
+
transactionMessage
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/estimateComputeLimitInternal.ts
|
|
372
|
+
async function estimateComputeUnitLimit({
|
|
373
|
+
transactionMessage,
|
|
374
|
+
...configs
|
|
375
|
+
}) {
|
|
376
|
+
const replaceRecentBlockhash = !kit.isDurableNonceTransaction(transactionMessage);
|
|
377
|
+
const transaction = kit.pipe(
|
|
378
|
+
transactionMessage,
|
|
379
|
+
fillMissingTransactionMessageLifetimeUsingProvisoryBlockhash,
|
|
380
|
+
(m) => updateOrAppendSetComputeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT, m),
|
|
381
|
+
kit.compileTransaction
|
|
382
|
+
);
|
|
383
|
+
return await simulateTransactionAndGetConsumedUnits({
|
|
384
|
+
transaction,
|
|
385
|
+
replaceRecentBlockhash,
|
|
386
|
+
...configs
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
async function simulateTransactionAndGetConsumedUnits({
|
|
390
|
+
abortSignal,
|
|
391
|
+
rpc,
|
|
392
|
+
transaction,
|
|
393
|
+
...simulateConfig
|
|
394
|
+
}) {
|
|
395
|
+
const wireTransactionBytes = kit.getBase64EncodedWireTransaction(transaction);
|
|
396
|
+
try {
|
|
397
|
+
const {
|
|
398
|
+
value: { err: transactionError, unitsConsumed }
|
|
399
|
+
} = await rpc.simulateTransaction(wireTransactionBytes, {
|
|
400
|
+
...simulateConfig,
|
|
401
|
+
encoding: "base64",
|
|
402
|
+
sigVerify: false
|
|
403
|
+
}).send({ abortSignal });
|
|
404
|
+
if (unitsConsumed == null) {
|
|
405
|
+
throw new kit.SolanaError(
|
|
406
|
+
kit.SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
const downcastUnitsConsumed = unitsConsumed > 4294967295n ? 4294967295 : Number(unitsConsumed);
|
|
410
|
+
if (transactionError) {
|
|
411
|
+
throw new kit.SolanaError(
|
|
412
|
+
kit.SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT,
|
|
413
|
+
{
|
|
414
|
+
cause: transactionError,
|
|
415
|
+
unitsConsumed: downcastUnitsConsumed
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
return downcastUnitsConsumed;
|
|
420
|
+
} catch (e) {
|
|
421
|
+
if (kit.isSolanaError(
|
|
422
|
+
e,
|
|
423
|
+
kit.SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT
|
|
424
|
+
))
|
|
425
|
+
throw e;
|
|
426
|
+
throw new kit.SolanaError(
|
|
427
|
+
kit.SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT,
|
|
428
|
+
{ cause: e }
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/estimateComputeLimit.ts
|
|
434
|
+
function estimateComputeUnitLimitFactory({
|
|
435
|
+
rpc
|
|
436
|
+
}) {
|
|
437
|
+
return async function estimateComputeUnitLimitFactoryFunction(transactionMessage, config) {
|
|
438
|
+
return await estimateComputeUnitLimit({
|
|
439
|
+
...config,
|
|
440
|
+
rpc,
|
|
441
|
+
transactionMessage
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function setTransactionMessageComputeUnitPrice(microLamports, transactionMessage) {
|
|
446
|
+
return kit.appendTransactionMessageInstruction(
|
|
447
|
+
getSetComputeUnitPriceInstruction({ microLamports }),
|
|
448
|
+
transactionMessage
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
function updateOrAppendSetComputeUnitPriceInstruction(microLamports, transactionMessage) {
|
|
452
|
+
const getMicroLamports = (previousMicroLamports2) => typeof microLamports === "function" ? microLamports(previousMicroLamports2) : microLamports;
|
|
453
|
+
const instructionDetails = getSetComputeUnitPriceInstructionIndexAndMicroLamports(transactionMessage);
|
|
454
|
+
if (!instructionDetails) {
|
|
455
|
+
return kit.appendTransactionMessageInstruction(
|
|
456
|
+
getSetComputeUnitPriceInstruction({
|
|
457
|
+
microLamports: getMicroLamports(null)
|
|
458
|
+
}),
|
|
459
|
+
transactionMessage
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
const { index, microLamports: previousMicroLamports } = instructionDetails;
|
|
463
|
+
const newMicroLamports = getMicroLamports(previousMicroLamports);
|
|
464
|
+
if (newMicroLamports === previousMicroLamports) {
|
|
465
|
+
return transactionMessage;
|
|
466
|
+
}
|
|
467
|
+
const newInstruction = getSetComputeUnitPriceInstruction({
|
|
468
|
+
microLamports: newMicroLamports
|
|
469
|
+
});
|
|
470
|
+
const newInstructions = [...transactionMessage.instructions];
|
|
471
|
+
newInstructions.splice(index, 1, newInstruction);
|
|
472
|
+
return Object.freeze({
|
|
473
|
+
...transactionMessage,
|
|
474
|
+
instructions: newInstructions
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
|
|
268
478
|
exports.COMPUTE_BUDGET_PROGRAM_ADDRESS = COMPUTE_BUDGET_PROGRAM_ADDRESS;
|
|
269
479
|
exports.ComputeBudgetInstruction = ComputeBudgetInstruction;
|
|
480
|
+
exports.MAX_COMPUTE_UNIT_LIMIT = MAX_COMPUTE_UNIT_LIMIT;
|
|
481
|
+
exports.PROVISORY_COMPUTE_UNIT_LIMIT = PROVISORY_COMPUTE_UNIT_LIMIT;
|
|
270
482
|
exports.REQUEST_HEAP_FRAME_DISCRIMINATOR = REQUEST_HEAP_FRAME_DISCRIMINATOR;
|
|
271
483
|
exports.REQUEST_UNITS_DISCRIMINATOR = REQUEST_UNITS_DISCRIMINATOR;
|
|
272
484
|
exports.SET_COMPUTE_UNIT_LIMIT_DISCRIMINATOR = SET_COMPUTE_UNIT_LIMIT_DISCRIMINATOR;
|
|
273
485
|
exports.SET_COMPUTE_UNIT_PRICE_DISCRIMINATOR = SET_COMPUTE_UNIT_PRICE_DISCRIMINATOR;
|
|
274
486
|
exports.SET_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_DISCRIMINATOR = SET_LOADED_ACCOUNTS_DATA_SIZE_LIMIT_DISCRIMINATOR;
|
|
487
|
+
exports.estimateAndUpdateProvisoryComputeUnitLimitFactory = estimateAndUpdateProvisoryComputeUnitLimitFactory;
|
|
488
|
+
exports.estimateComputeUnitLimitFactory = estimateComputeUnitLimitFactory;
|
|
489
|
+
exports.fillProvisorySetComputeUnitLimitInstruction = fillProvisorySetComputeUnitLimitInstruction;
|
|
275
490
|
exports.getRequestHeapFrameDiscriminatorBytes = getRequestHeapFrameDiscriminatorBytes;
|
|
276
491
|
exports.getRequestHeapFrameInstruction = getRequestHeapFrameInstruction;
|
|
277
492
|
exports.getRequestHeapFrameInstructionDataCodec = getRequestHeapFrameInstructionDataCodec;
|
|
@@ -303,5 +518,8 @@ exports.parseRequestUnitsInstruction = parseRequestUnitsInstruction;
|
|
|
303
518
|
exports.parseSetComputeUnitLimitInstruction = parseSetComputeUnitLimitInstruction;
|
|
304
519
|
exports.parseSetComputeUnitPriceInstruction = parseSetComputeUnitPriceInstruction;
|
|
305
520
|
exports.parseSetLoadedAccountsDataSizeLimitInstruction = parseSetLoadedAccountsDataSizeLimitInstruction;
|
|
521
|
+
exports.setTransactionMessageComputeUnitPrice = setTransactionMessageComputeUnitPrice;
|
|
522
|
+
exports.updateOrAppendSetComputeUnitLimitInstruction = updateOrAppendSetComputeUnitLimitInstruction;
|
|
523
|
+
exports.updateOrAppendSetComputeUnitPriceInstruction = updateOrAppendSetComputeUnitPriceInstruction;
|
|
306
524
|
//# sourceMappingURL=index.js.map
|
|
307
525
|
//# sourceMappingURL=index.js.map
|