@debridge-finance/solana-utils 2.0.0 → 2.3.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/browser/index.js +27 -13
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/helpers.js +25 -13
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/esm/helpers.js +26 -13
- package/dist/esm/helpers.js.map +1 -1
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/helpers.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transaction,
|
|
1
|
+
import { Transaction, VersionedTransaction, MessageV0, PublicKey } from '@solana/web3.js';
|
|
2
2
|
|
|
3
3
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4
4
|
|
|
@@ -7501,6 +7501,20 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
7501
7501
|
});
|
|
7502
7502
|
}
|
|
7503
7503
|
|
|
7504
|
+
function getAccountInfo(connection, account) {
|
|
7505
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7506
|
+
const info = yield connection.getAccountInfo(account);
|
|
7507
|
+
if (info) {
|
|
7508
|
+
// alchemy bug fix
|
|
7509
|
+
if (info.lamports === 0 && info.rentEpoch === 0)
|
|
7510
|
+
return null;
|
|
7511
|
+
return info;
|
|
7512
|
+
}
|
|
7513
|
+
else {
|
|
7514
|
+
return null;
|
|
7515
|
+
}
|
|
7516
|
+
});
|
|
7517
|
+
}
|
|
7504
7518
|
function hexToBuffer(data, align) {
|
|
7505
7519
|
if (!data.startsWith("0x"))
|
|
7506
7520
|
throw new Error("[hexToBuffer]: string must start with 0x");
|
|
@@ -7571,17 +7585,18 @@ class Wallet {
|
|
|
7571
7585
|
});
|
|
7572
7586
|
}
|
|
7573
7587
|
}
|
|
7574
|
-
function sendWithRetries(connection, serialized, lastValidBlockHeight) {
|
|
7588
|
+
function sendWithRetries(connection, serialized, lastValidBlockHeight, timesToSend = 5) {
|
|
7575
7589
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7576
7590
|
const txId = yield connection.sendRawTransaction(serialized, {
|
|
7577
7591
|
skipPreflight: true,
|
|
7592
|
+
maxRetries: 1000,
|
|
7578
7593
|
});
|
|
7579
7594
|
let blockheight = yield connection.getBlockHeight();
|
|
7580
|
-
const timesToSend = 5;
|
|
7581
7595
|
let sent = 0;
|
|
7582
7596
|
while (blockheight < lastValidBlockHeight && sent < timesToSend) {
|
|
7583
7597
|
yield connection.sendRawTransaction(serialized, {
|
|
7584
7598
|
skipPreflight: true,
|
|
7599
|
+
maxRetries: 1000,
|
|
7585
7600
|
});
|
|
7586
7601
|
yield sleep(300);
|
|
7587
7602
|
blockheight = yield connection.getBlockHeight();
|
|
@@ -7603,11 +7618,11 @@ function txToV0(transaction, payer, blockhash) {
|
|
|
7603
7618
|
return new VersionedTransaction(v0Message);
|
|
7604
7619
|
}
|
|
7605
7620
|
}
|
|
7606
|
-
function sendAll(connection, wallet, transactions, signers, waitBetweenSend, skipPreflight = false, debug = false, convertIntoTxV0 = true) {
|
|
7621
|
+
function sendAll(connection, wallet, transactions, signers, waitBetweenSend, skipPreflight = false, debug = false, convertIntoTxV0 = true, rpcCalls = 5) {
|
|
7607
7622
|
var _a;
|
|
7608
7623
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7609
7624
|
if (convertIntoTxV0) {
|
|
7610
|
-
const fakeBlockHash = "
|
|
7625
|
+
const fakeBlockHash = "1".repeat(32);
|
|
7611
7626
|
transactions = transactions.map((tx) => txToV0(tx, wallet.publicKey, fakeBlockHash));
|
|
7612
7627
|
}
|
|
7613
7628
|
let txIds = [];
|
|
@@ -7623,13 +7638,12 @@ function sendAll(connection, wallet, transactions, signers, waitBetweenSend, ski
|
|
|
7623
7638
|
else {
|
|
7624
7639
|
tx.recentBlockhash = blockhash;
|
|
7625
7640
|
tx.feePayer = wallet.publicKey;
|
|
7626
|
-
|
|
7627
|
-
txV0 = new VersionedTransaction(new MessageV0({ addressTableLookups: [], compiledInstructions: [], header: message.header, recentBlockhash: blockhash, staticAccountKeys: message.accountKeys }));
|
|
7641
|
+
txV0 = new VersionedTransaction(MessageV0.compile({ addressLookupTableAccounts: [], instructions: tx.instructions, recentBlockhash: blockhash, payerKey: tx.feePayer }));
|
|
7628
7642
|
}
|
|
7629
7643
|
if (!skipPreflight) {
|
|
7630
7644
|
const simulationResult = yield connection.simulateTransaction(txV0, { sigVerify: false, replaceRecentBlockhash: true, commitment: "confirmed" });
|
|
7631
7645
|
if (simulationResult.value.err !== null) {
|
|
7632
|
-
throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(
|
|
7646
|
+
throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(_b = simulationResult.value.logs) === null || _b === void 0 ? void 0 : _b.join("\n")}`);
|
|
7633
7647
|
}
|
|
7634
7648
|
}
|
|
7635
7649
|
})));
|
|
@@ -7639,7 +7653,7 @@ function sendAll(connection, wallet, transactions, signers, waitBetweenSend, ski
|
|
|
7639
7653
|
const serialized = buffer.Buffer.from(signedTx.serialize());
|
|
7640
7654
|
if (debug)
|
|
7641
7655
|
console.debug(serialized.toString("base64"));
|
|
7642
|
-
return sendWithRetries(connection, serialized, lastValidBlockHeight);
|
|
7656
|
+
return sendWithRetries(connection, serialized, lastValidBlockHeight, rpcCalls);
|
|
7643
7657
|
}));
|
|
7644
7658
|
}
|
|
7645
7659
|
else {
|
|
@@ -7654,20 +7668,19 @@ function sendAll(connection, wallet, transactions, signers, waitBetweenSend, ski
|
|
|
7654
7668
|
else {
|
|
7655
7669
|
tx.recentBlockhash = blockhash;
|
|
7656
7670
|
tx.feePayer = wallet.publicKey;
|
|
7657
|
-
|
|
7658
|
-
txV0 = new VersionedTransaction(new MessageV0({ addressTableLookups: [], compiledInstructions: [], header: message.header, recentBlockhash: blockhash, staticAccountKeys: message.accountKeys }));
|
|
7671
|
+
txV0 = new VersionedTransaction(MessageV0.compile({ addressLookupTableAccounts: [], instructions: tx.instructions, recentBlockhash: blockhash, payerKey: tx.feePayer }));
|
|
7659
7672
|
}
|
|
7660
7673
|
const signed = yield wallet.signTransaction(tx, signers && signers.length > i ? signers[i] : undefined);
|
|
7661
7674
|
if (!skipPreflight) {
|
|
7662
7675
|
const simulationResult = yield connection.simulateTransaction(txV0, { sigVerify: false, replaceRecentBlockhash: true, commitment: "confirmed" });
|
|
7663
7676
|
if (simulationResult.value.err !== null) {
|
|
7664
|
-
throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(
|
|
7677
|
+
throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(_a = simulationResult.value.logs) === null || _a === void 0 ? void 0 : _a.join("\n")}`);
|
|
7665
7678
|
}
|
|
7666
7679
|
}
|
|
7667
7680
|
const serialized = buffer.Buffer.from(signed.serialize());
|
|
7668
7681
|
if (debug)
|
|
7669
7682
|
console.debug(serialized.toString("base64"));
|
|
7670
|
-
txIds.push(yield sendWithRetries(connection, serialized, lastValidBlockHeight));
|
|
7683
|
+
txIds.push(yield sendWithRetries(connection, serialized, lastValidBlockHeight, rpcCalls));
|
|
7671
7684
|
yield sleep(waitBetweenSend);
|
|
7672
7685
|
}
|
|
7673
7686
|
}
|
|
@@ -7677,6 +7690,7 @@ function sendAll(connection, wallet, transactions, signers, waitBetweenSend, ski
|
|
|
7677
7690
|
|
|
7678
7691
|
var helpers = /*#__PURE__*/Object.freeze({
|
|
7679
7692
|
__proto__: null,
|
|
7693
|
+
getAccountInfo: getAccountInfo,
|
|
7680
7694
|
hexToBuffer: hexToBuffer,
|
|
7681
7695
|
bufferToHex: bufferToHex,
|
|
7682
7696
|
sleep: sleep,
|