@debridge-finance/solana-utils 4.4.2 → 4.5.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 { VersionedTransaction, Transaction, Keypair, MessageV0, PublicKey, TransactionInstruction, SystemProgram } from '@solana/web3.js';
1
+ import { MessageV0, VersionedTransaction, Transaction, PublicKey, TransactionInstruction, SystemProgram, Keypair } 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
 
@@ -6544,30 +6544,6 @@ function sleep(milliSeconds) {
6544
6544
  });
6545
6545
  });
6546
6546
  }
6547
- /**
6548
- * Serializes transaction and returns serialized size
6549
- * @param transaction tx to get length
6550
- * @param feePayer optional fee payer
6551
- * @returns transaction size
6552
- */
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
- }
6570
- }
6571
6547
  function isVersionedTx(arg) {
6572
6548
  return "version" in arg;
6573
6549
  }
@@ -6736,7 +6712,6 @@ var helpers = /*#__PURE__*/Object.freeze({
6736
6712
  hexToBuffer: hexToBuffer,
6737
6713
  bufferToHex: bufferToHex,
6738
6714
  sleep: sleep,
6739
- getTransactionSize: getTransactionSize,
6740
6715
  Wallet: Wallet,
6741
6716
  sendAll: sendAll
6742
6717
  });
@@ -6954,6 +6929,15 @@ function hashDebridgeId(nativeChainId, nativeTokenAddress) {
6954
6929
  return bridgeId;
6955
6930
  }
6956
6931
  function hashExternalCallBytes(data) {
6932
+ if (data === undefined || (data === null || data === void 0 ? void 0 : data.length) === 0) {
6933
+ // precomputed "empty" hash
6934
+ return buffer.Buffer.from([
6935
+ 197, 210, 70, 1, 134, 247, 35, 60,
6936
+ 146, 126, 125, 178, 220, 199, 3, 192,
6937
+ 229, 0, 182, 83, 202, 130, 39, 59,
6938
+ 123, 250, 216, 4, 93, 133, 164, 112
6939
+ ]);
6940
+ }
6957
6941
  return hexToBuffer(solidityKeccak256(["bytes"], [data ? data : buffer.Buffer.from([])]), 32);
6958
6942
  }
6959
6943
  /**
@@ -7028,6 +7012,390 @@ var crypto = /*#__PURE__*/Object.freeze({
7028
7012
  hashSubmissionIdRaw: hashSubmissionIdRaw
7029
7013
  });
7030
7014
 
7015
+ var microMemoize = {exports: {}};
7016
+
7017
+ (function (module, exports) {
7018
+ (function (global, factory) {
7019
+ module.exports = factory() ;
7020
+ })(commonjsGlobal, (function () {
7021
+ /**
7022
+ * @constant DEFAULT_OPTIONS_KEYS the default options keys
7023
+ */
7024
+ var DEFAULT_OPTIONS_KEYS = {
7025
+ isEqual: true,
7026
+ isMatchingKey: true,
7027
+ isPromise: true,
7028
+ maxSize: true,
7029
+ onCacheAdd: true,
7030
+ onCacheChange: true,
7031
+ onCacheHit: true,
7032
+ transformKey: true,
7033
+ };
7034
+ /**
7035
+ * @function slice
7036
+ *
7037
+ * @description
7038
+ * slice.call() pre-bound
7039
+ */
7040
+ var slice = Array.prototype.slice;
7041
+ /**
7042
+ * @function cloneArray
7043
+ *
7044
+ * @description
7045
+ * clone the array-like object and return the new array
7046
+ *
7047
+ * @param arrayLike the array-like object to clone
7048
+ * @returns the clone as an array
7049
+ */
7050
+ function cloneArray(arrayLike) {
7051
+ var length = arrayLike.length;
7052
+ if (!length) {
7053
+ return [];
7054
+ }
7055
+ if (length === 1) {
7056
+ return [arrayLike[0]];
7057
+ }
7058
+ if (length === 2) {
7059
+ return [arrayLike[0], arrayLike[1]];
7060
+ }
7061
+ if (length === 3) {
7062
+ return [arrayLike[0], arrayLike[1], arrayLike[2]];
7063
+ }
7064
+ return slice.call(arrayLike, 0);
7065
+ }
7066
+ /**
7067
+ * @function getCustomOptions
7068
+ *
7069
+ * @description
7070
+ * get the custom options on the object passed
7071
+ *
7072
+ * @param options the memoization options passed
7073
+ * @returns the custom options passed
7074
+ */
7075
+ function getCustomOptions(options) {
7076
+ var customOptions = {};
7077
+ /* eslint-disable no-restricted-syntax */
7078
+ for (var key in options) {
7079
+ if (!DEFAULT_OPTIONS_KEYS[key]) {
7080
+ customOptions[key] = options[key];
7081
+ }
7082
+ }
7083
+ /* eslint-enable */
7084
+ return customOptions;
7085
+ }
7086
+ /**
7087
+ * @function isMemoized
7088
+ *
7089
+ * @description
7090
+ * is the function passed already memoized
7091
+ *
7092
+ * @param fn the function to test
7093
+ * @returns is the function already memoized
7094
+ */
7095
+ function isMemoized(fn) {
7096
+ return typeof fn === 'function' && fn.isMemoized;
7097
+ }
7098
+ /**
7099
+ * @function isSameValueZero
7100
+ *
7101
+ * @description
7102
+ * are the objects equal based on SameValueZero equality
7103
+ *
7104
+ * @param object1 the first object to compare
7105
+ * @param object2 the second object to compare
7106
+ * @returns are the two objects equal
7107
+ */
7108
+ function isSameValueZero(object1, object2) {
7109
+ // eslint-disable-next-line no-self-compare
7110
+ return object1 === object2 || (object1 !== object1 && object2 !== object2);
7111
+ }
7112
+ /**
7113
+ * @function mergeOptions
7114
+ *
7115
+ * @description
7116
+ * merge the options into the target
7117
+ *
7118
+ * @param existingOptions the options provided
7119
+ * @param newOptions the options to include
7120
+ * @returns the merged options
7121
+ */
7122
+ function mergeOptions(existingOptions, newOptions) {
7123
+ var target = {};
7124
+ /* eslint-disable no-restricted-syntax */
7125
+ for (var key in existingOptions) {
7126
+ target[key] = existingOptions[key];
7127
+ }
7128
+ for (var key in newOptions) {
7129
+ target[key] = newOptions[key];
7130
+ }
7131
+ /* eslint-enable */
7132
+ return target;
7133
+ }
7134
+
7135
+ // utils
7136
+ var Cache = /** @class */ (function () {
7137
+ function Cache(options) {
7138
+ this.keys = [];
7139
+ this.values = [];
7140
+ this.options = options;
7141
+ var isMatchingKeyFunction = typeof options.isMatchingKey === 'function';
7142
+ if (isMatchingKeyFunction) {
7143
+ this.getKeyIndex = this._getKeyIndexFromMatchingKey;
7144
+ }
7145
+ else if (options.maxSize > 1) {
7146
+ this.getKeyIndex = this._getKeyIndexForMany;
7147
+ }
7148
+ else {
7149
+ this.getKeyIndex = this._getKeyIndexForSingle;
7150
+ }
7151
+ this.canTransformKey = typeof options.transformKey === 'function';
7152
+ this.shouldCloneArguments = this.canTransformKey || isMatchingKeyFunction;
7153
+ this.shouldUpdateOnAdd = typeof options.onCacheAdd === 'function';
7154
+ this.shouldUpdateOnChange = typeof options.onCacheChange === 'function';
7155
+ this.shouldUpdateOnHit = typeof options.onCacheHit === 'function';
7156
+ }
7157
+ Object.defineProperty(Cache.prototype, "size", {
7158
+ /**
7159
+ * The number of cached [key,value] results.
7160
+ */
7161
+ get: function () {
7162
+ return this.keys.length;
7163
+ },
7164
+ enumerable: false,
7165
+ configurable: true
7166
+ });
7167
+ Object.defineProperty(Cache.prototype, "snapshot", {
7168
+ /**
7169
+ * A copy of the cache at a moment in time. This is useful
7170
+ * to compare changes over time, since the cache mutates
7171
+ * internally for performance reasons.
7172
+ */
7173
+ get: function () {
7174
+ return {
7175
+ keys: cloneArray(this.keys),
7176
+ size: this.size,
7177
+ values: cloneArray(this.values),
7178
+ };
7179
+ },
7180
+ enumerable: false,
7181
+ configurable: true
7182
+ });
7183
+ /**
7184
+ * Gets the matching key index when a custom key matcher is used.
7185
+ */
7186
+ Cache.prototype._getKeyIndexFromMatchingKey = function (keyToMatch) {
7187
+ var _a = this.options, isMatchingKey = _a.isMatchingKey, maxSize = _a.maxSize;
7188
+ var keys = this.keys;
7189
+ var keysLength = keys.length;
7190
+ if (!keysLength) {
7191
+ return -1;
7192
+ }
7193
+ if (isMatchingKey(keys[0], keyToMatch)) {
7194
+ return 0;
7195
+ }
7196
+ if (maxSize > 1) {
7197
+ for (var index = 1; index < keysLength; index++) {
7198
+ if (isMatchingKey(keys[index], keyToMatch)) {
7199
+ return index;
7200
+ }
7201
+ }
7202
+ }
7203
+ return -1;
7204
+ };
7205
+ /**
7206
+ * Gets the matching key index when multiple keys are used.
7207
+ */
7208
+ Cache.prototype._getKeyIndexForMany = function (keyToMatch) {
7209
+ var isEqual = this.options.isEqual;
7210
+ var keys = this.keys;
7211
+ var keysLength = keys.length;
7212
+ if (!keysLength) {
7213
+ return -1;
7214
+ }
7215
+ if (keysLength === 1) {
7216
+ return this._getKeyIndexForSingle(keyToMatch);
7217
+ }
7218
+ var keyLength = keyToMatch.length;
7219
+ var existingKey;
7220
+ var argIndex;
7221
+ if (keyLength > 1) {
7222
+ for (var index = 0; index < keysLength; index++) {
7223
+ existingKey = keys[index];
7224
+ if (existingKey.length === keyLength) {
7225
+ argIndex = 0;
7226
+ for (; argIndex < keyLength; argIndex++) {
7227
+ if (!isEqual(existingKey[argIndex], keyToMatch[argIndex])) {
7228
+ break;
7229
+ }
7230
+ }
7231
+ if (argIndex === keyLength) {
7232
+ return index;
7233
+ }
7234
+ }
7235
+ }
7236
+ }
7237
+ else {
7238
+ for (var index = 0; index < keysLength; index++) {
7239
+ existingKey = keys[index];
7240
+ if (existingKey.length === keyLength &&
7241
+ isEqual(existingKey[0], keyToMatch[0])) {
7242
+ return index;
7243
+ }
7244
+ }
7245
+ }
7246
+ return -1;
7247
+ };
7248
+ /**
7249
+ * Gets the matching key index when a single key is used.
7250
+ */
7251
+ Cache.prototype._getKeyIndexForSingle = function (keyToMatch) {
7252
+ var keys = this.keys;
7253
+ if (!keys.length) {
7254
+ return -1;
7255
+ }
7256
+ var existingKey = keys[0];
7257
+ var length = existingKey.length;
7258
+ if (keyToMatch.length !== length) {
7259
+ return -1;
7260
+ }
7261
+ var isEqual = this.options.isEqual;
7262
+ if (length > 1) {
7263
+ for (var index = 0; index < length; index++) {
7264
+ if (!isEqual(existingKey[index], keyToMatch[index])) {
7265
+ return -1;
7266
+ }
7267
+ }
7268
+ return 0;
7269
+ }
7270
+ return isEqual(existingKey[0], keyToMatch[0]) ? 0 : -1;
7271
+ };
7272
+ /**
7273
+ * Order the array based on a Least-Recently-Used basis.
7274
+ */
7275
+ Cache.prototype.orderByLru = function (key, value, startingIndex) {
7276
+ var keys = this.keys;
7277
+ var values = this.values;
7278
+ var currentLength = keys.length;
7279
+ var index = startingIndex;
7280
+ while (index--) {
7281
+ keys[index + 1] = keys[index];
7282
+ values[index + 1] = values[index];
7283
+ }
7284
+ keys[0] = key;
7285
+ values[0] = value;
7286
+ var maxSize = this.options.maxSize;
7287
+ if (currentLength === maxSize && startingIndex === currentLength) {
7288
+ keys.pop();
7289
+ values.pop();
7290
+ }
7291
+ else if (startingIndex >= maxSize) {
7292
+ // eslint-disable-next-line no-multi-assign
7293
+ keys.length = values.length = maxSize;
7294
+ }
7295
+ };
7296
+ /**
7297
+ * Update the promise method to auto-remove from cache if rejected, and
7298
+ * if resolved then fire cache hit / changed.
7299
+ */
7300
+ Cache.prototype.updateAsyncCache = function (memoized) {
7301
+ var _this = this;
7302
+ var _a = this.options, onCacheChange = _a.onCacheChange, onCacheHit = _a.onCacheHit;
7303
+ var firstKey = this.keys[0];
7304
+ var firstValue = this.values[0];
7305
+ this.values[0] = firstValue.then(function (value) {
7306
+ if (_this.shouldUpdateOnHit) {
7307
+ onCacheHit(_this, _this.options, memoized);
7308
+ }
7309
+ if (_this.shouldUpdateOnChange) {
7310
+ onCacheChange(_this, _this.options, memoized);
7311
+ }
7312
+ return value;
7313
+ }, function (error) {
7314
+ var keyIndex = _this.getKeyIndex(firstKey);
7315
+ if (keyIndex !== -1) {
7316
+ _this.keys.splice(keyIndex, 1);
7317
+ _this.values.splice(keyIndex, 1);
7318
+ }
7319
+ throw error;
7320
+ });
7321
+ };
7322
+ return Cache;
7323
+ }());
7324
+
7325
+ function createMemoizedFunction(fn, options) {
7326
+ if (options === void 0) { options = {}; }
7327
+ if (isMemoized(fn)) {
7328
+ return createMemoizedFunction(fn.fn, mergeOptions(fn.options, options));
7329
+ }
7330
+ if (typeof fn !== 'function') {
7331
+ throw new TypeError('You must pass a function to `memoize`.');
7332
+ }
7333
+ var _a = options.isEqual, isEqual = _a === void 0 ? isSameValueZero : _a, isMatchingKey = options.isMatchingKey, _b = options.isPromise, isPromise = _b === void 0 ? false : _b, _c = options.maxSize, maxSize = _c === void 0 ? 1 : _c, onCacheAdd = options.onCacheAdd, onCacheChange = options.onCacheChange, onCacheHit = options.onCacheHit, transformKey = options.transformKey;
7334
+ var normalizedOptions = mergeOptions({
7335
+ isEqual: isEqual,
7336
+ isMatchingKey: isMatchingKey,
7337
+ isPromise: isPromise,
7338
+ maxSize: maxSize,
7339
+ onCacheAdd: onCacheAdd,
7340
+ onCacheChange: onCacheChange,
7341
+ onCacheHit: onCacheHit,
7342
+ transformKey: transformKey,
7343
+ }, getCustomOptions(options));
7344
+ var cache = new Cache(normalizedOptions);
7345
+ var keys = cache.keys, values = cache.values, canTransformKey = cache.canTransformKey, shouldCloneArguments = cache.shouldCloneArguments, shouldUpdateOnAdd = cache.shouldUpdateOnAdd, shouldUpdateOnChange = cache.shouldUpdateOnChange, shouldUpdateOnHit = cache.shouldUpdateOnHit;
7346
+ var memoized = function () {
7347
+ var key = shouldCloneArguments
7348
+ ? cloneArray(arguments)
7349
+ : arguments;
7350
+ if (canTransformKey) {
7351
+ key = transformKey(key);
7352
+ }
7353
+ var keyIndex = keys.length ? cache.getKeyIndex(key) : -1;
7354
+ if (keyIndex !== -1) {
7355
+ if (shouldUpdateOnHit) {
7356
+ onCacheHit(cache, normalizedOptions, memoized);
7357
+ }
7358
+ if (keyIndex) {
7359
+ cache.orderByLru(keys[keyIndex], values[keyIndex], keyIndex);
7360
+ if (shouldUpdateOnChange) {
7361
+ onCacheChange(cache, normalizedOptions, memoized);
7362
+ }
7363
+ }
7364
+ }
7365
+ else {
7366
+ var newValue = fn.apply(this, arguments);
7367
+ var newKey = shouldCloneArguments
7368
+ ? key
7369
+ : cloneArray(arguments);
7370
+ cache.orderByLru(newKey, newValue, keys.length);
7371
+ if (isPromise) {
7372
+ cache.updateAsyncCache(memoized);
7373
+ }
7374
+ if (shouldUpdateOnAdd) {
7375
+ onCacheAdd(cache, normalizedOptions, memoized);
7376
+ }
7377
+ if (shouldUpdateOnChange) {
7378
+ onCacheChange(cache, normalizedOptions, memoized);
7379
+ }
7380
+ }
7381
+ return values[0];
7382
+ };
7383
+ memoized.cache = cache;
7384
+ memoized.fn = fn;
7385
+ memoized.isMemoized = true;
7386
+ memoized.options = normalizedOptions;
7387
+ return memoized;
7388
+ }
7389
+
7390
+ return createMemoizedFunction;
7391
+
7392
+ }));
7393
+
7394
+ } (microMemoize));
7395
+
7396
+ var memoize = microMemoize.exports;
7397
+
7398
+ const TOKEN_2022_PROGRAM_ID = new PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
7031
7399
  const TOKEN_METADATA_PROGRAM_ID = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
7032
7400
  const TOKEN_PROGRAM_ID = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
7033
7401
  const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
@@ -7101,35 +7469,40 @@ const deBridgeSettings = {
7101
7469
  getNoBridgeFeeAddress: (SETTINGS_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(deBridgeSettings$1.Seeds.NO_BRIDGE_FEE_INFO)], SETTINGS_PROGRAM_ID),
7102
7470
  };
7103
7471
  const DlnSrc = {
7104
- getStateAccount: (PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.STATE)], PMM_SRC_PROGRAM_ID),
7105
- getNonceAccount: (maker, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([
7472
+ getStateAccount: (DLN_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.STATE)], DLN_SRC_PROGRAM_ID),
7473
+ getNonceAccount: (maker, DLN_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([
7106
7474
  buffer.Buffer.from(dlnSrc$1.Seeds.NONCE),
7107
7475
  isBuffer(maker) ? maker : maker.toBuffer(),
7108
- ], PMM_SRC_PROGRAM_ID),
7109
- getGiveOrderStateAccount: (orderId, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.ORDER_STATE), orderId], PMM_SRC_PROGRAM_ID),
7110
- getAuthorizedNativeSenderAddress: (chainId, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.AUTHORIZED_NATIVE_SENDER), chainId], PMM_SRC_PROGRAM_ID),
7111
- getGiveOrderWalletAddress: (orderId, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.GIVE_ORDER_WALLET), orderId], PMM_SRC_PROGRAM_ID),
7112
- getFeeLedgerWalletAddress: (tokenMint, PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([
7476
+ ], DLN_SRC_PROGRAM_ID),
7477
+ getGiveOrderStateAccount: (orderId, DLN_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.ORDER_STATE), orderId], DLN_SRC_PROGRAM_ID),
7478
+ getAuthorizedNativeSenderAddress: (chainId, DLN_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.AUTHORIZED_NATIVE_SENDER), chainId], DLN_SRC_PROGRAM_ID),
7479
+ getGiveOrderWalletAddress: (orderId, DLN_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.GIVE_ORDER_WALLET), orderId], DLN_SRC_PROGRAM_ID),
7480
+ getFeeLedgerWalletAddress: (tokenMint, DLN_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([
7113
7481
  buffer.Buffer.from(dlnSrc$1.Seeds.FEE_LEDGER_WALLET),
7114
7482
  tokenMint.toBuffer(),
7115
- ], PMM_SRC_PROGRAM_ID),
7116
- getFeeLedgerAddress: (PMM_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.FEE_LEDGER)], PMM_SRC_PROGRAM_ID),
7483
+ ], DLN_SRC_PROGRAM_ID),
7484
+ getFeeLedgerAddress: (DLN_SRC_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnSrc$1.Seeds.FEE_LEDGER)], DLN_SRC_PROGRAM_ID),
7117
7485
  };
7118
7486
  const DlnDst = {
7119
- getAuthorizedSrcContractAddress: (chainId, PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.AUTHORIZED_SRC_CONTRACT), chainId], PMM_DST_PROGRAM_ID),
7120
- getAuthorizedDstNativeSenderAddress: (PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.AUTHORIZED_DST_NATIVE_SENDER)], PMM_DST_PROGRAM_ID),
7121
- getTakeOrderStateAddress: (orderId, PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.ORDER_STATE), orderId], PMM_DST_PROGRAM_ID),
7122
- getTakePatchAddress: (orderId, PMM_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.TAKE_PATCH), orderId], PMM_DST_PROGRAM_ID),
7487
+ getAuthorizedSrcContractAddress: (chainId, DLN_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.AUTHORIZED_SRC_CONTRACT), chainId], DLN_DST_PROGRAM_ID),
7488
+ getAuthorizedDstNativeSenderAddress: (DLN_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.AUTHORIZED_DST_NATIVE_SENDER)], DLN_DST_PROGRAM_ID),
7489
+ getTakeOrderStateAddress: (orderId, DLN_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.ORDER_STATE), orderId], DLN_DST_PROGRAM_ID),
7490
+ getTakePatchAddress: (orderId, DLN_DST_PROGRAM_ID) => PublicKey.findProgramAddressSync([buffer.Buffer.from(dlnDst$1.Seeds.TAKE_PATCH), orderId], DLN_DST_PROGRAM_ID),
7123
7491
  };
7124
7492
  function wrapFn(fn, arg) {
7125
7493
  return (...args) => fn(...args, arg);
7126
7494
  }
7127
7495
  class Resolver {
7128
- constructor(programId, obj) {
7496
+ constructor(programId, obj, memoizeList) {
7129
7497
  this.programId = new PublicKey(programId);
7130
7498
  let methods = {};
7131
7499
  for (let [fnName, fn] of Object.entries(obj)) {
7132
- methods[fnName] = wrapFn(fn, this.programId);
7500
+ if (fnName in memoizeList) {
7501
+ methods[fnName] = memoize(wrapFn(fn, this.programId), Object.assign({}, memoizeList[fnName]));
7502
+ }
7503
+ else {
7504
+ methods[fnName] = wrapFn(fn, this.programId);
7505
+ }
7133
7506
  }
7134
7507
  this.methods = methods;
7135
7508
  }
@@ -7145,9 +7518,41 @@ class ResolverContainer2 {
7145
7518
  this.methods = methods;
7146
7519
  }
7147
7520
  }
7148
- const DeBridgeResolver = (programId, settingsProgramId) => new ResolverContainer2(new Resolver(programId, deBridge$1), new Resolver(settingsProgramId, deBridgeSettings));
7149
- const dlnSrcResolver = (programId) => new Resolver(programId, DlnSrc);
7150
- const dlnDstResolver = (programId) => new Resolver(programId, DlnDst);
7521
+ const DeBridgeResolver = (programId, settingsProgramId) => {
7522
+ const deBridgeMemoizeList = {
7523
+ "getClaimMarkerAddress": {},
7524
+ "getNonceAddress": {},
7525
+ "getMintAuthorityAddress": { maxSize: 20 }
7526
+ };
7527
+ const settingsMemoizeList = {
7528
+ "getTokenMetadataMasterAddress": {},
7529
+ "getTokenMintAddress": { maxSize: 5 },
7530
+ "getStateAddress": {},
7531
+ "getBridgeFeeAddress": { maxSize: 40 },
7532
+ "getChainSupportInfoAddress": { maxSize: 10 },
7533
+ "getBridgeAddress": { maxSize: 10 },
7534
+ "getBridgeMapAddress": { maxSize: 10 },
7535
+ "getNoBridgeFeeAddress": {},
7536
+ "getNoDiscountAddress": {},
7537
+ };
7538
+ return new ResolverContainer2(new Resolver(programId, deBridge$1, deBridgeMemoizeList), new Resolver(settingsProgramId, deBridgeSettings, settingsMemoizeList));
7539
+ };
7540
+ const dlnSrcResolver = (programId) => {
7541
+ const dlnMemoizeList = {
7542
+ "getStateAccount": {},
7543
+ "getAuthorizedNativeSenderAddress": { maxSize: 10 },
7544
+ "getFeeLedgerAddress": {},
7545
+ "getFeeLedgerWalletAddress": { maxSize: 10 }
7546
+ };
7547
+ return new Resolver(programId, DlnSrc, dlnMemoizeList);
7548
+ };
7549
+ const dlnDstResolver = (programId) => {
7550
+ const dstMemoizeList = {
7551
+ "getAuthorizedSrcContractAddress": { maxSize: 10 },
7552
+ "getAuthorizedDstNativeSenderAddress": {},
7553
+ };
7554
+ return new Resolver(programId, DlnDst, dstMemoizeList);
7555
+ };
7151
7556
 
7152
7557
  var Layout$1 = {};
7153
7558
 
@@ -9660,7 +10065,11 @@ function createAssociatedWalletInstruction(tokenMint, associatedAccount, owner,
9660
10065
  ],
9661
10066
  });
9662
10067
  }
9663
- function parseSplAccount(data) {
10068
+ function parseSplAccount(dataOrInfo) {
10069
+ if (dataOrInfo === null) {
10070
+ return null;
10071
+ }
10072
+ const data = 'executable' in dataOrInfo ? dataOrInfo.data : dataOrInfo;
9664
10073
  try {
9665
10074
  return AccountLayout.decode(data);
9666
10075
  }
@@ -9882,5 +10291,89 @@ var programs = /*#__PURE__*/Object.freeze({
9882
10291
  dlnExecutor: dlnExecutor
9883
10292
  });
9884
10293
 
9885
- export { ASSOCIATED_TOKEN_PROGRAM_ID, DeBridgeResolver, TOKEN_METADATA_PROGRAM_ID, TOKEN_PROGRAM_ID, WRAPPED_SOL_MINT, constants, crypto, dlnDstResolver, dlnSrcResolver, findAssociatedTokenAddress, findAssociatedTokenAddressSync, getTokenMetadataAddress, helpers, interfaces, programs, spl };
10294
+ function simulateTransaction(connection, tx, simulateConfig) {
10295
+ var _a, _b, _c, _d, _e, _f, _g, _h;
10296
+ return __awaiter(this, void 0, void 0, function* () {
10297
+ const addressesToGetDiffFor = ((_b = (_a = simulateConfig.accounts) === null || _a === void 0 ? void 0 : _a.addresses) !== null && _b !== void 0 ? _b : []).map((a) => new PublicKey(a));
10298
+ const accountsToFetch = addressesToGetDiffFor.length > 0 ? yield connection.getMultipleAccountsInfo(addressesToGetDiffFor) : [];
10299
+ const result = yield connection.simulateTransaction(tx, simulateConfig);
10300
+ const diffMap = new Map();
10301
+ for (const [idx, simulatedAccountInfo] of ((_c = result.value.accounts) !== null && _c !== void 0 ? _c : []).entries()) {
10302
+ const accountAddress = addressesToGetDiffFor[idx];
10303
+ const oldAccountData = (_d = accountsToFetch.at(idx)) !== null && _d !== void 0 ? _d : null;
10304
+ const oldParsedMaybeSpl = (oldAccountData === null || oldAccountData === void 0 ? void 0 : oldAccountData.owner.equals(TOKEN_PROGRAM_ID)) ? parseSplAccount(oldAccountData) : null;
10305
+ const oldSolValue = (_e = oldAccountData === null || oldAccountData === void 0 ? void 0 : oldAccountData.lamports) !== null && _e !== void 0 ? _e : 0;
10306
+ const newSolValue = (_f = simulatedAccountInfo === null || simulatedAccountInfo === void 0 ? void 0 : simulatedAccountInfo.lamports) !== null && _f !== void 0 ? _f : 0;
10307
+ const solDiff = oldSolValue === newSolValue ? null : {
10308
+ before: oldSolValue,
10309
+ after: newSolValue,
10310
+ };
10311
+ let newParsedMaybeSpl = null;
10312
+ if (simulatedAccountInfo) {
10313
+ const [rawData, encoding] = simulatedAccountInfo.data;
10314
+ if (encoding !== "base64")
10315
+ throw new Error("Expected bs64 account data");
10316
+ const artificialAccountInfo = Object.assign(Object.assign({}, simulatedAccountInfo), { owner: new PublicKey(simulatedAccountInfo.owner), data: Buffer.from(rawData, "base64") });
10317
+ newParsedMaybeSpl = artificialAccountInfo.owner.equals(TOKEN_PROGRAM_ID) ? parseSplAccount(artificialAccountInfo) : null;
10318
+ }
10319
+ let splDiff = null;
10320
+ // old state is spl token account OR new state is spl token account
10321
+ if (oldParsedMaybeSpl !== null || newParsedMaybeSpl !== null) {
10322
+ if (oldParsedMaybeSpl !== newParsedMaybeSpl) {
10323
+ const token = (newParsedMaybeSpl === null || newParsedMaybeSpl === void 0 ? void 0 : newParsedMaybeSpl.mint) || (oldParsedMaybeSpl === null || oldParsedMaybeSpl === void 0 ? void 0 : oldParsedMaybeSpl.mint);
10324
+ if (token === undefined)
10325
+ throw new Error("Failed to get token from the spl token account");
10326
+ const owner = (newParsedMaybeSpl === null || newParsedMaybeSpl === void 0 ? void 0 : newParsedMaybeSpl.owner) || (oldParsedMaybeSpl === null || oldParsedMaybeSpl === void 0 ? void 0 : oldParsedMaybeSpl.owner);
10327
+ if (owner === undefined)
10328
+ throw new Error("Failed to get owner from the spl token account");
10329
+ splDiff = {
10330
+ before: (_g = oldParsedMaybeSpl === null || oldParsedMaybeSpl === void 0 ? void 0 : oldParsedMaybeSpl.amount) !== null && _g !== void 0 ? _g : BigInt(0),
10331
+ after: (_h = newParsedMaybeSpl === null || newParsedMaybeSpl === void 0 ? void 0 : newParsedMaybeSpl.amount) !== null && _h !== void 0 ? _h : BigInt(0),
10332
+ token,
10333
+ owner,
10334
+ };
10335
+ }
10336
+ }
10337
+ if (splDiff !== null || solDiff !== null) {
10338
+ diffMap.set(accountAddress.toBase58(), {
10339
+ native: solDiff,
10340
+ spl: splDiff,
10341
+ });
10342
+ }
10343
+ }
10344
+ return Object.assign(Object.assign({}, result.value), { diff: diffMap });
10345
+ });
10346
+ }
10347
+ /**
10348
+ * Serializes transaction and returns serialized size
10349
+ * @param transaction tx to get length
10350
+ * @param feePayer optional fee payer
10351
+ * @returns transaction size
10352
+ */
10353
+ function getTransactionSize(tx) {
10354
+ try {
10355
+ if ("version" in tx) {
10356
+ const txCopy = new VersionedTransaction(tx.message);
10357
+ txCopy.message.recentBlockhash = FAKE_BLOCKHASH;
10358
+ return txCopy.serialize().length;
10359
+ }
10360
+ else {
10361
+ const txCopy = new Transaction(tx);
10362
+ txCopy.feePayer = Keypair.generate().publicKey;
10363
+ txCopy.recentBlockhash = FAKE_BLOCKHASH;
10364
+ return tx.serialize({ verifySignatures: false }).length;
10365
+ }
10366
+ }
10367
+ catch (e) {
10368
+ return null;
10369
+ }
10370
+ }
10371
+
10372
+ var transaction = /*#__PURE__*/Object.freeze({
10373
+ __proto__: null,
10374
+ simulateTransaction: simulateTransaction,
10375
+ getTransactionSize: getTransactionSize
10376
+ });
10377
+
10378
+ export { ASSOCIATED_TOKEN_PROGRAM_ID, DeBridgeResolver, TOKEN_2022_PROGRAM_ID, TOKEN_METADATA_PROGRAM_ID, TOKEN_PROGRAM_ID, WRAPPED_SOL_MINT, constants, crypto, dlnDstResolver, dlnSrcResolver, findAssociatedTokenAddress, findAssociatedTokenAddressSync, getTokenMetadataAddress, helpers, interfaces, programs, spl, transaction as txs };
9886
10379
  //# sourceMappingURL=index.js.map