@debridge-finance/solana-utils 4.3.1 → 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.
@@ -1,4 +1,4 @@
1
- import { Transaction, MessageV0, VersionedTransaction, PublicKey, TransactionInstruction, SystemProgram } from '@solana/web3.js';
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(transaction, feePayer) {
6554
- const clonedTransaction = new Transaction({
6555
- lastValidBlockHeight: 1234,
6556
- feePayer: (transaction === null || transaction === void 0 ? void 0 : transaction.feePayer) ||
6557
- feePayer ||
6558
- transaction.instructions[0].programId,
6559
- blockhash: "CSymwgTNX1j3E4qhKfJAUE41nBWEwXufoYryPbkde5RR", // fake blockhash
6560
- }).add(transaction);
6561
- const serializedMessage = clonedTransaction.serializeMessage();
6562
- const uniqueSigners = new Set(clonedTransaction.instructions.flatMap((ix) => ix.keys
6563
- .filter((meta) => meta.isSigner)
6564
- .map((meta) => meta.pubkey.toBase58())));
6565
- // message length + signatures length (1 byte) + signatures count * signature size (64)
6566
- return serializedMessage.length + uniqueSigners.size * 64 + 1;
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) {
@@ -6715,17 +6695,17 @@ function sendAll(connection, wallet, transactions, options) {
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.toString("base64")}`);
6720
- return sendWithRetries(connection, serialized, lastValidBlockHeight, rpcCalls, blockhashCommitment);
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
+ });
6721
6704
  }));
6722
6705
  }
6723
6706
  else {
6724
6707
  for (let i = 0; i < transactions.length; i++) {
6725
6708
  const tx = transactions[i];
6726
- const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash({
6727
- commitment: blockhashCommitment,
6728
- });
6729
6709
  const signed = skipSign
6730
6710
  ? tx
6731
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
@@ -6734,9 +6714,12 @@ function sendAll(connection, wallet, transactions, options) {
6734
6714
  if (!skipPreflight) {
6735
6715
  yield simulateTx(connection, tx, blockhashCommitment, wallet.publicKey, convertIntoTxV0, skipSign);
6736
6716
  }
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.toString("base64")}`);
6739
- txIds.push(yield sendWithRetries(connection, serialized, lastValidBlockHeight, rpcCalls, blockhashCommitment));
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
+ }));
6740
6723
  yield sleep(options.waitBetweenSend);
6741
6724
  }
6742
6725
  }
@@ -6978,12 +6961,12 @@ function hashExternalCallBytes(data) {
6978
6961
  function hashSubmissionIdRaw(params) {
6979
6962
  var _a, _b, _c, _d;
6980
6963
  let packParams = [
6981
- "uint256",
6982
- "uint256",
6983
- "uint256",
6984
- "uint256",
6985
- "uint256",
6986
- "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
6987
6970
  "uint256", // nonce
6988
6971
  ];
6989
6972
  const receiver = isBuffer(params.receiver)
@@ -6995,19 +6978,19 @@ function hashSubmissionIdRaw(params) {
6995
6978
  : new PublicKey(params.receiver).toBuffer();
6996
6979
  let packData = [
6997
6980
  SUBMISSION_PREFIX,
6998
- params.debridgeId,
6999
- normalizeChainId(params.sourceChainId),
7000
- normalizeChainId(params.targetChainId),
7001
- new BN(params.amount).toArray("be", 32),
7002
- 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
7003
6986
  params.nonce, // nonce
7004
6987
  ];
7005
6988
  if (params === null || params === void 0 ? void 0 : params.autoParams) {
7006
6989
  packParams = packParams.concat([
7007
- "uint256",
7008
- "uint256",
7009
- "uint256",
7010
- "uint256",
6990
+ "uint256", // execution fee
6991
+ "uint256", // flag
6992
+ "uint256", // fallback hash
6993
+ "uint256", // ext call data hash
7011
6994
  "uint256", // native sender hash
7012
6995
  ]);
7013
6996
  const shortcut = ((_a = params.autoParams) === null || _a === void 0 ? void 0 : _a.shortcut)