@debridge-finance/solana-utils 4.3.0 → 4.4.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 +49 -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 +35 -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 +36 -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;
|
|
@@ -6669,6 +6650,7 @@ function simulateTx(connection, tx, commitment, feePayer, convertToV0, alreadySi
|
|
|
6669
6650
|
});
|
|
6670
6651
|
}
|
|
6671
6652
|
else {
|
|
6653
|
+
txCopy.recentBlockhash = FAKE_BLOCKHASH;
|
|
6672
6654
|
result = yield connection.simulateTransaction(txCopy.compileMessage());
|
|
6673
6655
|
}
|
|
6674
6656
|
if (result.value.err !== null) {
|
|
@@ -6693,7 +6675,6 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6693
6675
|
: options.blockhashCommitment;
|
|
6694
6676
|
const convertIntoTxV0 = (options === null || options === void 0 ? void 0 : options.convertIntoTxV0) === undefined ? true : options.convertIntoTxV0;
|
|
6695
6677
|
const skipPreflight = (options === null || options === void 0 ? void 0 : options.skipPreflight) === undefined ? false : options.skipPreflight;
|
|
6696
|
-
const rpcCalls = (options === null || options === void 0 ? void 0 : options.rpcCalls) === undefined ? 3 : options.rpcCalls;
|
|
6697
6678
|
if (!Array.isArray(transactions))
|
|
6698
6679
|
transactions = [transactions];
|
|
6699
6680
|
if (convertIntoTxV0) {
|
|
@@ -6705,25 +6686,26 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6705
6686
|
yield Promise.all(transactions.map((tx) => simulateTx(connection, tx, blockhashCommitment, wallet.publicKey, convertIntoTxV0, skipSign)));
|
|
6706
6687
|
}
|
|
6707
6688
|
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash({ commitment: blockhashCommitment });
|
|
6689
|
+
let signed = transactions;
|
|
6708
6690
|
if (!skipSign) {
|
|
6709
6691
|
// set real blockhash
|
|
6710
6692
|
transactions.map((tx) => setBlockhash(tx, blockhash));
|
|
6693
|
+
// sign after setting correct blockhashes
|
|
6694
|
+
signed = yield wallet.signAllTransactions(transactions, options === null || options === void 0 ? void 0 : options.signers);
|
|
6711
6695
|
}
|
|
6712
|
-
// sign after setting correct blockhashes
|
|
6713
|
-
const signed = yield wallet.signAllTransactions(transactions, options === null || options === void 0 ? void 0 : options.signers);
|
|
6714
6696
|
txIds = yield Promise.all(signed.map((signedTx) => {
|
|
6715
6697
|
var _a;
|
|
6716
|
-
const serialized = buffer.Buffer.from(signedTx.serialize());
|
|
6717
|
-
(_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.call(options, `Sending tx: ${serialized
|
|
6718
|
-
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
|
+
});
|
|
6719
6704
|
}));
|
|
6720
6705
|
}
|
|
6721
6706
|
else {
|
|
6722
6707
|
for (let i = 0; i < transactions.length; i++) {
|
|
6723
6708
|
const tx = transactions[i];
|
|
6724
|
-
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash({
|
|
6725
|
-
commitment: blockhashCommitment,
|
|
6726
|
-
});
|
|
6727
6709
|
const signed = skipSign
|
|
6728
6710
|
? tx
|
|
6729
6711
|
: yield wallet.signTransaction(tx, (options === null || options === void 0 ? void 0 : options.signers) && (options === null || options === void 0 ? void 0 : options.signers.length) > i
|
|
@@ -6732,9 +6714,12 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6732
6714
|
if (!skipPreflight) {
|
|
6733
6715
|
yield simulateTx(connection, tx, blockhashCommitment, wallet.publicKey, convertIntoTxV0, skipSign);
|
|
6734
6716
|
}
|
|
6735
|
-
const serialized = buffer.Buffer.from(signed.serialize());
|
|
6736
|
-
(_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.call(options, `Sending tx: ${serialized
|
|
6737
|
-
txIds.push(yield
|
|
6717
|
+
const serialized = buffer.Buffer.from(signed.serialize()).toString("base64");
|
|
6718
|
+
(_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.call(options, `Sending tx: ${serialized}`);
|
|
6719
|
+
txIds.push(yield connection.sendEncodedTransaction(serialized, {
|
|
6720
|
+
preflightCommitment: blockhashCommitment,
|
|
6721
|
+
skipPreflight: false,
|
|
6722
|
+
}));
|
|
6738
6723
|
yield sleep(options.waitBetweenSend);
|
|
6739
6724
|
}
|
|
6740
6725
|
}
|
|
@@ -6976,12 +6961,12 @@ function hashExternalCallBytes(data) {
|
|
|
6976
6961
|
function hashSubmissionIdRaw(params) {
|
|
6977
6962
|
var _a, _b, _c, _d;
|
|
6978
6963
|
let packParams = [
|
|
6979
|
-
"uint256",
|
|
6980
|
-
"uint256",
|
|
6981
|
-
"uint256",
|
|
6982
|
-
"uint256",
|
|
6983
|
-
"uint256",
|
|
6984
|
-
"bytes",
|
|
6964
|
+
"uint256", // submission prefix
|
|
6965
|
+
"uint256", // bridge_id
|
|
6966
|
+
"uint256", // source_chain_id
|
|
6967
|
+
"uint256", // target_chain_id
|
|
6968
|
+
"uint256", // amount
|
|
6969
|
+
"bytes", // receiver
|
|
6985
6970
|
"uint256", // nonce
|
|
6986
6971
|
];
|
|
6987
6972
|
const receiver = isBuffer(params.receiver)
|
|
@@ -6993,19 +6978,19 @@ function hashSubmissionIdRaw(params) {
|
|
|
6993
6978
|
: new PublicKey(params.receiver).toBuffer();
|
|
6994
6979
|
let packData = [
|
|
6995
6980
|
SUBMISSION_PREFIX,
|
|
6996
|
-
params.debridgeId,
|
|
6997
|
-
normalizeChainId(params.sourceChainId),
|
|
6998
|
-
normalizeChainId(params.targetChainId),
|
|
6999
|
-
new BN(params.amount).toArray("be", 32),
|
|
7000
|
-
receiver,
|
|
6981
|
+
params.debridgeId, // bridge_id
|
|
6982
|
+
normalizeChainId(params.sourceChainId), // source_chain_id
|
|
6983
|
+
normalizeChainId(params.targetChainId), // target_chain_id
|
|
6984
|
+
new BN(params.amount).toArray("be", 32), // amount
|
|
6985
|
+
receiver, // receiver
|
|
7001
6986
|
params.nonce, // nonce
|
|
7002
6987
|
];
|
|
7003
6988
|
if (params === null || params === void 0 ? void 0 : params.autoParams) {
|
|
7004
6989
|
packParams = packParams.concat([
|
|
7005
|
-
"uint256",
|
|
7006
|
-
"uint256",
|
|
7007
|
-
"uint256",
|
|
7008
|
-
"uint256",
|
|
6990
|
+
"uint256", // execution fee
|
|
6991
|
+
"uint256", // flag
|
|
6992
|
+
"uint256", // fallback hash
|
|
6993
|
+
"uint256", // ext call data hash
|
|
7009
6994
|
"uint256", // native sender hash
|
|
7010
6995
|
]);
|
|
7011
6996
|
const shortcut = ((_a = params.autoParams) === null || _a === void 0 ? void 0 : _a.shortcut)
|