@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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSolanaRpc, createSolanaRpcSubscriptions, address, getBase64EncodedWireTransaction, compileTransaction, partiallySignTransactionMessageWithSigners, appendTransactionMessageInstruction, setTransactionMessageLifetimeUsingBlockhash, isTransactionSendingSigner, getMessagePackerInstructionPlanFromInstructions, signature, AccountRole, pipe, createTransactionMessage, setTransactionMessageFeePayer, singleTransactionPlan, signAndSendTransactionMessageWithSigners, createTransactionPlanExecutor, signTransactionMessageWithSigners, isSolanaError, SOLANA_ERROR__TRANSACTION_ERROR__ALREADY_PROCESSED, createTransactionPlanner, setTransactionMessageFeePayerSigner, isTransactionPartialSigner, isInstructionForProgram, isInstructionWithData, SolanaError, SOLANA_ERROR__INSTRUCTION_ERROR__GENERIC_ERROR, airdropFactory, signatureBytes } from '@solana/kit';
|
|
1
|
+
import { createSolanaRpc, createSolanaRpcSubscriptions, address, getBase64EncodedWireTransaction, compileTransaction, partiallySignTransactionMessageWithSigners, appendTransactionMessageInstruction, setTransactionMessageLifetimeUsingBlockhash, isTransactionSendingSigner, getMessagePackerInstructionPlanFromInstructions, signature, AccountRole, pipe, createTransactionMessage, setTransactionMessageFeePayer, singleTransactionPlan, signAndSendTransactionMessageWithSigners, createTransactionPlanExecutor, signTransactionMessageWithSigners, isSolanaError, SOLANA_ERROR__TRANSACTION_ERROR__ALREADY_PROCESSED, createTransactionPlanner, setTransactionMessageFeePayerSigner, isTransactionPartialSigner, SOLANA_ERROR__INSTRUCTION_ERROR__COMPUTATIONAL_BUDGET_EXCEEDED, isInstructionForProgram, isInstructionWithData, SolanaError, SOLANA_ERROR__INSTRUCTION_ERROR__GENERIC_ERROR, airdropFactory, signatureBytes } from '@solana/kit';
|
|
2
2
|
import { createBlockHeightExceedencePromiseFactory, createRecentSignatureConfirmationPromiseFactory, waitForRecentTransactionConfirmation } from '@solana/transaction-confirmation';
|
|
3
3
|
import { getBase58Decoder, getBase58Encoder } from '@solana/codecs-strings';
|
|
4
4
|
import { getTransferSolInstruction } from '@solana-program/system';
|
|
@@ -246,11 +246,6 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
246
246
|
},
|
|
247
247
|
lastUpdatedAt: now()
|
|
248
248
|
}));
|
|
249
|
-
logger({
|
|
250
|
-
data: { endpoint, latencyMs, websocketEndpoint },
|
|
251
|
-
level: "info",
|
|
252
|
-
message: "cluster ready"
|
|
253
|
-
});
|
|
254
249
|
} catch (error) {
|
|
255
250
|
store.setState((state) => ({
|
|
256
251
|
...state,
|
|
@@ -1356,10 +1351,23 @@ __name(transactionToBase64WithSigners, "transactionToBase64WithSigners");
|
|
|
1356
1351
|
|
|
1357
1352
|
// src/transactions/prepareTransaction.ts
|
|
1358
1353
|
var DEFAULT_COMPUTE_UNIT_LIMIT_MULTIPLIER = 1.1;
|
|
1354
|
+
var DEFAULT_COMPUTE_UNIT_LIMIT = 2e5;
|
|
1355
|
+
var MAX_COMPUTE_UNIT_LIMIT = 14e5;
|
|
1359
1356
|
function isComputeUnitLimitInstruction(instruction) {
|
|
1360
1357
|
return instruction.programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS && instruction.data?.[0] === 2;
|
|
1361
1358
|
}
|
|
1362
1359
|
__name(isComputeUnitLimitInstruction, "isComputeUnitLimitInstruction");
|
|
1360
|
+
function didExceedComputeBudget(error) {
|
|
1361
|
+
let current = error;
|
|
1362
|
+
while (isSolanaError(current)) {
|
|
1363
|
+
if (isSolanaError(current, SOLANA_ERROR__INSTRUCTION_ERROR__COMPUTATIONAL_BUDGET_EXCEEDED)) {
|
|
1364
|
+
return true;
|
|
1365
|
+
}
|
|
1366
|
+
current = current.cause;
|
|
1367
|
+
}
|
|
1368
|
+
return false;
|
|
1369
|
+
}
|
|
1370
|
+
__name(didExceedComputeBudget, "didExceedComputeBudget");
|
|
1363
1371
|
async function estimateComputeUnits(rpc, transaction) {
|
|
1364
1372
|
let target = transaction;
|
|
1365
1373
|
const hasLifetime = transaction.lifetimeConstraint !== void 0;
|
|
@@ -1371,12 +1379,19 @@ async function estimateComputeUnits(rpc, transaction) {
|
|
|
1371
1379
|
);
|
|
1372
1380
|
}
|
|
1373
1381
|
const base64Transaction = transactionToBase64(target);
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1382
|
+
try {
|
|
1383
|
+
const { value } = await rpc.simulateTransaction(base64Transaction, {
|
|
1384
|
+
encoding: "base64",
|
|
1385
|
+
replaceRecentBlockhash: false,
|
|
1386
|
+
sigVerify: false
|
|
1387
|
+
}).send();
|
|
1388
|
+
return Number(value.unitsConsumed ?? 0) || 0;
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
if (didExceedComputeBudget(error)) {
|
|
1391
|
+
return MAX_COMPUTE_UNIT_LIMIT;
|
|
1392
|
+
}
|
|
1393
|
+
throw error;
|
|
1394
|
+
}
|
|
1380
1395
|
}
|
|
1381
1396
|
__name(estimateComputeUnits, "estimateComputeUnits");
|
|
1382
1397
|
async function prepareTransaction(config) {
|
|
@@ -1387,7 +1402,11 @@ async function prepareTransaction(config) {
|
|
|
1387
1402
|
const computeLimitIndex = transaction.instructions.findIndex(isComputeUnitLimitInstruction);
|
|
1388
1403
|
if (computeLimitIndex === -1 || shouldResetComputeUnits) {
|
|
1389
1404
|
const unitsFromSimulation = await estimateComputeUnits(config.rpc, transaction);
|
|
1390
|
-
const
|
|
1405
|
+
const estimatedUnits = unitsFromSimulation ? Math.ceil(unitsFromSimulation * multiplier) : DEFAULT_COMPUTE_UNIT_LIMIT;
|
|
1406
|
+
const units = Math.min(
|
|
1407
|
+
MAX_COMPUTE_UNIT_LIMIT,
|
|
1408
|
+
Math.max(DEFAULT_COMPUTE_UNIT_LIMIT, Math.max(1, estimatedUnits))
|
|
1409
|
+
);
|
|
1391
1410
|
const instruction = getSetComputeUnitLimitInstruction({ units });
|
|
1392
1411
|
if (computeLimitIndex === -1) {
|
|
1393
1412
|
transaction = appendTransactionMessageInstruction(instruction, transaction);
|