@debridge-finance/solana-utils 4.5.3 → 5.0.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.
@@ -6943,16 +6943,42 @@ function hashExternalCallBytes(data) {
6943
6943
  }
6944
6944
  return hexToBuffer(solidityKeccak256(["bytes"], [data ? data : buffer.Buffer.from([])]), 32);
6945
6945
  }
6946
+ function isSendHashedFlagSet(packedFlags) {
6947
+ const SEND_HASHED_DATA_FLAG_BIT_NUMBER = BigInt(3);
6948
+ const result = (packedFlags >> SEND_HASHED_DATA_FLAG_BIT_NUMBER) & BigInt(1);
6949
+ return result === BigInt(1);
6950
+ }
6951
+ function getShortcutFromAutoParams(params) {
6952
+ var _a, _b, _c;
6953
+ const shortcut = (_a = params.autoParams) === null || _a === void 0 ? void 0 : _a.shortcut;
6954
+ if (shortcut) {
6955
+ return isBuffer(shortcut) ? shortcut : hexToBuffer(shortcut);
6956
+ }
6957
+ else {
6958
+ const flags = BigInt(new BN(((_b = params.autoParams) === null || _b === void 0 ? void 0 : _b.flags) || 0).toNumber());
6959
+ const data = (_c = params.autoParams) === null || _c === void 0 ? void 0 : _c.data;
6960
+ if (!data)
6961
+ return hashExternalCallBytes(data);
6962
+ if (isSendHashedFlagSet(flags)) {
6963
+ const result = isBuffer(data) ? data : hexToBuffer(data);
6964
+ if (result.length !== 32) {
6965
+ throw new Error(`Incorrect autoParams.data length for SEND_HASHED_DATA_FLAG`);
6966
+ }
6967
+ return result;
6968
+ }
6969
+ return hashExternalCallBytes(data);
6970
+ }
6971
+ }
6946
6972
  /**
6947
6973
  * Hashes submission for provided data
6948
6974
  * @param params data to hash
6949
6975
  * @returns submissionId from provided params
6950
6976
  */
6951
6977
  function hashSubmissionIdRaw(params) {
6952
- var _a, _b, _c, _d;
6978
+ var _a, _b;
6953
6979
  let packParams = [
6954
6980
  "uint256", // submission prefix
6955
- "uint256", // bridge_id
6981
+ "bytes32", // bridge_id
6956
6982
  "uint256", // source_chain_id
6957
6983
  "uint256", // target_chain_id
6958
6984
  "uint256", // amount
@@ -6964,7 +6990,7 @@ function hashSubmissionIdRaw(params) {
6964
6990
  : typeof params.receiver === "string"
6965
6991
  ? params.receiver.startsWith("0x")
6966
6992
  ? hexToBuffer(params.receiver)
6967
- : new PublicKey(params.receiver)
6993
+ : new PublicKey(params.receiver).toBuffer()
6968
6994
  : new PublicKey(params.receiver).toBuffer();
6969
6995
  let packData = [
6970
6996
  SUBMISSION_PREFIX,
@@ -6979,21 +7005,17 @@ function hashSubmissionIdRaw(params) {
6979
7005
  packParams = packParams.concat([
6980
7006
  "uint256", // execution fee
6981
7007
  "uint256", // flag
6982
- "uint256", // fallback hash
7008
+ "bytes32", // fallback hash
6983
7009
  "uint256", // ext call data hash
6984
7010
  "uint256", // native sender hash
6985
7011
  ]);
6986
- const shortcut = ((_a = params.autoParams) === null || _a === void 0 ? void 0 : _a.shortcut)
6987
- ? isBuffer(params.autoParams.shortcut)
6988
- ? params.autoParams.shortcut
6989
- : hexToBuffer(params.autoParams.shortcut)
6990
- : hashExternalCallBytes((_b = params === null || params === void 0 ? void 0 : params.autoParams) === null || _b === void 0 ? void 0 : _b.data);
7012
+ const shortcut = getShortcutFromAutoParams(params);
6991
7013
  const fallback = params.autoParams.fallbackAddress.startsWith("0x")
6992
7014
  ? hexToBuffer(params.autoParams.fallbackAddress)
6993
7015
  : new PublicKey(params.autoParams.fallbackAddress).toBuffer();
6994
7016
  packData = packData.concat([
6995
- new BN(((_c = params === null || params === void 0 ? void 0 : params.autoParams) === null || _c === void 0 ? void 0 : _c.executionFee) || 0).toArray("be", 32),
6996
- new BN(((_d = params.autoParams) === null || _d === void 0 ? void 0 : _d.flags) || 0).toArray("be", 32),
7017
+ new BN(((_a = params === null || params === void 0 ? void 0 : params.autoParams) === null || _a === void 0 ? void 0 : _a.executionFee) || 0).toArray("be", 32),
7018
+ new BN(((_b = params.autoParams) === null || _b === void 0 ? void 0 : _b.flags) || 0).toArray("be", 32),
6997
7019
  hashExternalCallBytes(fallback),
6998
7020
  shortcut,
6999
7021
  hashExternalCallBytes(params.autoParams.nativeSender),
@@ -10320,7 +10342,7 @@ function parseMultipleAccounts(accounts) {
10320
10342
  parsedAccount.spl = {
10321
10343
  mint: parsedSplAccount.mint,
10322
10344
  owner: parsedSplAccount.owner,
10323
- balance: Number((_b = parsedSplAccount.amount) !== null && _b !== void 0 ? _b : 0),
10345
+ balance: (_b = parsedSplAccount.amount) !== null && _b !== void 0 ? _b : BigInt(0),
10324
10346
  };
10325
10347
  }
10326
10348
  return parsedAccount;
@@ -10328,8 +10350,8 @@ function parseMultipleAccounts(accounts) {
10328
10350
  }
10329
10351
  function getSplDiff(pre, post) {
10330
10352
  var _a, _b, _c, _d, _e, _f;
10331
- const preBalance = (_a = pre === null || pre === void 0 ? void 0 : pre.balance) !== null && _a !== void 0 ? _a : 0;
10332
- const postBalance = (_b = post === null || post === void 0 ? void 0 : post.balance) !== null && _b !== void 0 ? _b : 0;
10353
+ const preBalance = (_a = pre === null || pre === void 0 ? void 0 : pre.balance) !== null && _a !== void 0 ? _a : BigInt(0);
10354
+ const postBalance = (_b = post === null || post === void 0 ? void 0 : post.balance) !== null && _b !== void 0 ? _b : BigInt(0);
10333
10355
  return {
10334
10356
  mint: (_c = pre === null || pre === void 0 ? void 0 : pre.mint) !== null && _c !== void 0 ? _c : post === null || post === void 0 ? void 0 : post.mint,
10335
10357
  owner: (_d = pre === null || pre === void 0 ? void 0 : pre.owner) !== null && _d !== void 0 ? _d : post === null || post === void 0 ? void 0 : post.owner,