@debridge-finance/solana-utils 4.3.1 → 4.4.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/browser/index.js +48 -64
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/accounts.js.map +1 -1
- package/dist/cjs/crypto.js +15 -15
- package/dist/cjs/crypto.js.map +1 -1
- package/dist/cjs/helpers.js +34 -42
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/solidityPack.js.map +1 -1
- package/dist/cjs/spl.js.map +1 -1
- package/dist/esm/accounts.js.map +1 -1
- package/dist/esm/crypto.js +15 -15
- package/dist/esm/crypto.js.map +1 -1
- package/dist/esm/helpers.js +35 -43
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/solidityPack.js.map +1 -1
- package/dist/esm/spl.js.map +1 -1
- package/dist/types/accounts.d.ts +1 -0
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/types/helpers.d.ts +3 -2
- 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 { VersionedTransaction, Transaction, Keypair, MessageV0, PublicKey, TransactionInstruction, SystemProgram } 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
|
|
|
@@ -6550,20 +6550,23 @@ function sleep(milliSeconds) {
|
|
|
6550
6550
|
* @param feePayer optional fee payer
|
|
6551
6551
|
* @returns transaction size
|
|
6552
6552
|
*/
|
|
6553
|
-
function getTransactionSize(
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6553
|
+
function getTransactionSize(tx) {
|
|
6554
|
+
try {
|
|
6555
|
+
if (isVersionedTx(tx)) {
|
|
6556
|
+
const txCopy = new VersionedTransaction(tx.message);
|
|
6557
|
+
txCopy.message.recentBlockhash = FAKE_BLOCKHASH;
|
|
6558
|
+
return txCopy.serialize().length;
|
|
6559
|
+
}
|
|
6560
|
+
else {
|
|
6561
|
+
const txCopy = new Transaction(tx);
|
|
6562
|
+
txCopy.feePayer = Keypair.generate().publicKey;
|
|
6563
|
+
txCopy.recentBlockhash = FAKE_BLOCKHASH;
|
|
6564
|
+
return tx.serialize({ verifySignatures: false }).length;
|
|
6565
|
+
}
|
|
6566
|
+
}
|
|
6567
|
+
catch (e) {
|
|
6568
|
+
return null;
|
|
6569
|
+
}
|
|
6567
6570
|
}
|
|
6568
6571
|
function isVersionedTx(arg) {
|
|
6569
6572
|
return "version" in arg;
|
|
@@ -6596,28 +6599,6 @@ class Wallet {
|
|
|
6596
6599
|
});
|
|
6597
6600
|
}
|
|
6598
6601
|
}
|
|
6599
|
-
function sendWithRetries(connection, serialized, lastValidBlockHeight, timesToSend = 5, blockhashCommitment = "finalized") {
|
|
6600
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6601
|
-
const txId = yield connection.sendRawTransaction(serialized, {
|
|
6602
|
-
skipPreflight: false,
|
|
6603
|
-
preflightCommitment: blockhashCommitment,
|
|
6604
|
-
maxRetries: 3,
|
|
6605
|
-
});
|
|
6606
|
-
let blockheight = yield connection.getBlockHeight();
|
|
6607
|
-
let sent = 1;
|
|
6608
|
-
while (blockheight < lastValidBlockHeight && sent < timesToSend) {
|
|
6609
|
-
yield connection.sendRawTransaction(serialized, {
|
|
6610
|
-
skipPreflight: true,
|
|
6611
|
-
preflightCommitment: blockhashCommitment,
|
|
6612
|
-
maxRetries: 5,
|
|
6613
|
-
});
|
|
6614
|
-
yield sleep(300);
|
|
6615
|
-
blockheight = yield connection.getBlockHeight();
|
|
6616
|
-
sent += 1;
|
|
6617
|
-
}
|
|
6618
|
-
return txId;
|
|
6619
|
-
});
|
|
6620
|
-
}
|
|
6621
6602
|
function txToV0(transaction, payer, blockhash) {
|
|
6622
6603
|
if (isVersionedTx(transaction)) {
|
|
6623
6604
|
return transaction;
|
|
@@ -6694,7 +6675,6 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6694
6675
|
: options.blockhashCommitment;
|
|
6695
6676
|
const convertIntoTxV0 = (options === null || options === void 0 ? void 0 : options.convertIntoTxV0) === undefined ? true : options.convertIntoTxV0;
|
|
6696
6677
|
const skipPreflight = (options === null || options === void 0 ? void 0 : options.skipPreflight) === undefined ? false : options.skipPreflight;
|
|
6697
|
-
const rpcCalls = (options === null || options === void 0 ? void 0 : options.rpcCalls) === undefined ? 3 : options.rpcCalls;
|
|
6698
6678
|
if (!Array.isArray(transactions))
|
|
6699
6679
|
transactions = [transactions];
|
|
6700
6680
|
if (convertIntoTxV0) {
|
|
@@ -6705,27 +6685,28 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6705
6685
|
if (!skipPreflight) {
|
|
6706
6686
|
yield Promise.all(transactions.map((tx) => simulateTx(connection, tx, blockhashCommitment, wallet.publicKey, convertIntoTxV0, skipSign)));
|
|
6707
6687
|
}
|
|
6708
|
-
const
|
|
6688
|
+
const blockhashResponse = yield connection.getLatestBlockhashAndContext({ commitment: blockhashCommitment });
|
|
6709
6689
|
let signed = transactions;
|
|
6710
6690
|
if (!skipSign) {
|
|
6711
6691
|
// set real blockhash
|
|
6712
|
-
transactions.map((tx) => setBlockhash(tx, blockhash));
|
|
6692
|
+
transactions.map((tx) => setBlockhash(tx, blockhashResponse.value.blockhash));
|
|
6713
6693
|
// sign after setting correct blockhashes
|
|
6714
6694
|
signed = yield wallet.signAllTransactions(transactions, options === null || options === void 0 ? void 0 : options.signers);
|
|
6715
6695
|
}
|
|
6716
6696
|
txIds = yield Promise.all(signed.map((signedTx) => {
|
|
6717
6697
|
var _a;
|
|
6718
|
-
const serialized = buffer.Buffer.from(signedTx.serialize());
|
|
6719
|
-
(_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.call(options, `Sending tx: ${serialized
|
|
6720
|
-
return
|
|
6698
|
+
const serialized = buffer.Buffer.from(signedTx.serialize()).toString("base64");
|
|
6699
|
+
(_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.call(options, `Sending tx: ${serialized}`);
|
|
6700
|
+
return connection.sendEncodedTransaction(serialized, {
|
|
6701
|
+
preflightCommitment: blockhashCommitment,
|
|
6702
|
+
skipPreflight: false,
|
|
6703
|
+
minContextSlot: blockhashResponse.context.slot + 1
|
|
6704
|
+
});
|
|
6721
6705
|
}));
|
|
6722
6706
|
}
|
|
6723
6707
|
else {
|
|
6724
6708
|
for (let i = 0; i < transactions.length; i++) {
|
|
6725
6709
|
const tx = transactions[i];
|
|
6726
|
-
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash({
|
|
6727
|
-
commitment: blockhashCommitment,
|
|
6728
|
-
});
|
|
6729
6710
|
const signed = skipSign
|
|
6730
6711
|
? tx
|
|
6731
6712
|
: yield wallet.signTransaction(tx, (options === null || options === void 0 ? void 0 : options.signers) && (options === null || options === void 0 ? void 0 : options.signers.length) > i
|
|
@@ -6734,9 +6715,12 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6734
6715
|
if (!skipPreflight) {
|
|
6735
6716
|
yield simulateTx(connection, tx, blockhashCommitment, wallet.publicKey, convertIntoTxV0, skipSign);
|
|
6736
6717
|
}
|
|
6737
|
-
const serialized = buffer.Buffer.from(signed.serialize());
|
|
6738
|
-
(_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.call(options, `Sending tx: ${serialized
|
|
6739
|
-
txIds.push(yield
|
|
6718
|
+
const serialized = buffer.Buffer.from(signed.serialize()).toString("base64");
|
|
6719
|
+
(_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.call(options, `Sending tx: ${serialized}`);
|
|
6720
|
+
txIds.push(yield connection.sendEncodedTransaction(serialized, {
|
|
6721
|
+
preflightCommitment: blockhashCommitment,
|
|
6722
|
+
skipPreflight: false,
|
|
6723
|
+
}));
|
|
6740
6724
|
yield sleep(options.waitBetweenSend);
|
|
6741
6725
|
}
|
|
6742
6726
|
}
|
|
@@ -6978,12 +6962,12 @@ function hashExternalCallBytes(data) {
|
|
|
6978
6962
|
function hashSubmissionIdRaw(params) {
|
|
6979
6963
|
var _a, _b, _c, _d;
|
|
6980
6964
|
let packParams = [
|
|
6981
|
-
"uint256",
|
|
6982
|
-
"uint256",
|
|
6983
|
-
"uint256",
|
|
6984
|
-
"uint256",
|
|
6985
|
-
"uint256",
|
|
6986
|
-
"bytes",
|
|
6965
|
+
"uint256", // submission prefix
|
|
6966
|
+
"uint256", // bridge_id
|
|
6967
|
+
"uint256", // source_chain_id
|
|
6968
|
+
"uint256", // target_chain_id
|
|
6969
|
+
"uint256", // amount
|
|
6970
|
+
"bytes", // receiver
|
|
6987
6971
|
"uint256", // nonce
|
|
6988
6972
|
];
|
|
6989
6973
|
const receiver = isBuffer(params.receiver)
|
|
@@ -6995,19 +6979,19 @@ function hashSubmissionIdRaw(params) {
|
|
|
6995
6979
|
: new PublicKey(params.receiver).toBuffer();
|
|
6996
6980
|
let packData = [
|
|
6997
6981
|
SUBMISSION_PREFIX,
|
|
6998
|
-
params.debridgeId,
|
|
6999
|
-
normalizeChainId(params.sourceChainId),
|
|
7000
|
-
normalizeChainId(params.targetChainId),
|
|
7001
|
-
new BN(params.amount).toArray("be", 32),
|
|
7002
|
-
receiver,
|
|
6982
|
+
params.debridgeId, // bridge_id
|
|
6983
|
+
normalizeChainId(params.sourceChainId), // source_chain_id
|
|
6984
|
+
normalizeChainId(params.targetChainId), // target_chain_id
|
|
6985
|
+
new BN(params.amount).toArray("be", 32), // amount
|
|
6986
|
+
receiver, // receiver
|
|
7003
6987
|
params.nonce, // nonce
|
|
7004
6988
|
];
|
|
7005
6989
|
if (params === null || params === void 0 ? void 0 : params.autoParams) {
|
|
7006
6990
|
packParams = packParams.concat([
|
|
7007
|
-
"uint256",
|
|
7008
|
-
"uint256",
|
|
7009
|
-
"uint256",
|
|
7010
|
-
"uint256",
|
|
6991
|
+
"uint256", // execution fee
|
|
6992
|
+
"uint256", // flag
|
|
6993
|
+
"uint256", // fallback hash
|
|
6994
|
+
"uint256", // ext call data hash
|
|
7011
6995
|
"uint256", // native sender hash
|
|
7012
6996
|
]);
|
|
7013
6997
|
const shortcut = ((_a = params.autoParams) === null || _a === void 0 ? void 0 : _a.shortcut)
|