@solana/client 0.0.2 → 0.1.1
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/index.browser.cjs +31 -12
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +32 -13
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +32 -13
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +31 -12
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +32 -13
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/client/actions.d.ts.map +1 -1
- package/dist/types/transactions/prepareTransaction.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.cjs
CHANGED
|
@@ -248,11 +248,6 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
248
248
|
},
|
|
249
249
|
lastUpdatedAt: now()
|
|
250
250
|
}));
|
|
251
|
-
logger({
|
|
252
|
-
data: { endpoint, latencyMs, websocketEndpoint },
|
|
253
|
-
level: "info",
|
|
254
|
-
message: "cluster ready"
|
|
255
|
-
});
|
|
256
251
|
} catch (error) {
|
|
257
252
|
store.setState((state) => ({
|
|
258
253
|
...state,
|
|
@@ -1358,10 +1353,23 @@ __name(transactionToBase64WithSigners, "transactionToBase64WithSigners");
|
|
|
1358
1353
|
|
|
1359
1354
|
// src/transactions/prepareTransaction.ts
|
|
1360
1355
|
var DEFAULT_COMPUTE_UNIT_LIMIT_MULTIPLIER = 1.1;
|
|
1356
|
+
var DEFAULT_COMPUTE_UNIT_LIMIT = 2e5;
|
|
1357
|
+
var MAX_COMPUTE_UNIT_LIMIT = 14e5;
|
|
1361
1358
|
function isComputeUnitLimitInstruction(instruction) {
|
|
1362
1359
|
return instruction.programAddress === computeBudget.COMPUTE_BUDGET_PROGRAM_ADDRESS && instruction.data?.[0] === 2;
|
|
1363
1360
|
}
|
|
1364
1361
|
__name(isComputeUnitLimitInstruction, "isComputeUnitLimitInstruction");
|
|
1362
|
+
function didExceedComputeBudget(error) {
|
|
1363
|
+
let current = error;
|
|
1364
|
+
while (kit.isSolanaError(current)) {
|
|
1365
|
+
if (kit.isSolanaError(current, kit.SOLANA_ERROR__INSTRUCTION_ERROR__COMPUTATIONAL_BUDGET_EXCEEDED)) {
|
|
1366
|
+
return true;
|
|
1367
|
+
}
|
|
1368
|
+
current = current.cause;
|
|
1369
|
+
}
|
|
1370
|
+
return false;
|
|
1371
|
+
}
|
|
1372
|
+
__name(didExceedComputeBudget, "didExceedComputeBudget");
|
|
1365
1373
|
async function estimateComputeUnits(rpc, transaction) {
|
|
1366
1374
|
let target = transaction;
|
|
1367
1375
|
const hasLifetime = transaction.lifetimeConstraint !== void 0;
|
|
@@ -1373,12 +1381,19 @@ async function estimateComputeUnits(rpc, transaction) {
|
|
|
1373
1381
|
);
|
|
1374
1382
|
}
|
|
1375
1383
|
const base64Transaction = transactionToBase64(target);
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1384
|
+
try {
|
|
1385
|
+
const { value } = await rpc.simulateTransaction(base64Transaction, {
|
|
1386
|
+
encoding: "base64",
|
|
1387
|
+
replaceRecentBlockhash: false,
|
|
1388
|
+
sigVerify: false
|
|
1389
|
+
}).send();
|
|
1390
|
+
return Number(value.unitsConsumed ?? 0) || 0;
|
|
1391
|
+
} catch (error) {
|
|
1392
|
+
if (didExceedComputeBudget(error)) {
|
|
1393
|
+
return MAX_COMPUTE_UNIT_LIMIT;
|
|
1394
|
+
}
|
|
1395
|
+
throw error;
|
|
1396
|
+
}
|
|
1382
1397
|
}
|
|
1383
1398
|
__name(estimateComputeUnits, "estimateComputeUnits");
|
|
1384
1399
|
async function prepareTransaction(config) {
|
|
@@ -1389,7 +1404,11 @@ async function prepareTransaction(config) {
|
|
|
1389
1404
|
const computeLimitIndex = transaction.instructions.findIndex(isComputeUnitLimitInstruction);
|
|
1390
1405
|
if (computeLimitIndex === -1 || shouldResetComputeUnits) {
|
|
1391
1406
|
const unitsFromSimulation = await estimateComputeUnits(config.rpc, transaction);
|
|
1392
|
-
const
|
|
1407
|
+
const estimatedUnits = unitsFromSimulation ? Math.ceil(unitsFromSimulation * multiplier) : DEFAULT_COMPUTE_UNIT_LIMIT;
|
|
1408
|
+
const units = Math.min(
|
|
1409
|
+
MAX_COMPUTE_UNIT_LIMIT,
|
|
1410
|
+
Math.max(DEFAULT_COMPUTE_UNIT_LIMIT, Math.max(1, estimatedUnits))
|
|
1411
|
+
);
|
|
1393
1412
|
const instruction = computeBudget.getSetComputeUnitLimitInstruction({ units });
|
|
1394
1413
|
if (computeLimitIndex === -1) {
|
|
1395
1414
|
transaction = kit.appendTransactionMessageInstruction(instruction, transaction);
|