@defuse-protocol/intents-sdk 0.16.3 → 0.17.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/index.cjs CHANGED
@@ -30,31 +30,32 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- AssertionError: () => import_internal_utils22.AssertionError,
34
- BaseError: () => import_internal_utils19.BaseError,
33
+ AssertionError: () => import_internal_utils25.AssertionError,
34
+ BaseError: () => import_internal_utils22.BaseError,
35
35
  BridgeNameEnum: () => BridgeNameEnum,
36
36
  Chains: () => Chains,
37
37
  FeeExceedsAmountError: () => FeeExceedsAmountError,
38
38
  HotWithdrawalCancelledError: () => HotWithdrawalCancelledError,
39
39
  HotWithdrawalNotFoundError: () => HotWithdrawalNotFoundError,
40
40
  HotWithdrawalPendingError: () => HotWithdrawalPendingError,
41
- HttpRequestError: () => import_internal_utils21.HttpRequestError,
42
- IntentSettlementError: () => import_internal_utils23.IntentSettlementError,
41
+ HttpRequestError: () => import_internal_utils24.HttpRequestError,
42
+ IntentSettlementError: () => import_internal_utils26.IntentSettlementError,
43
43
  IntentsSDK: () => IntentsSDK,
44
44
  MinWithdrawalAmountError: () => MinWithdrawalAmountError,
45
45
  OmniTransferDestinationChainHashNotFoundError: () => OmniTransferDestinationChainHashNotFoundError,
46
46
  OmniTransferNotFoundError: () => OmniTransferNotFoundError,
47
- PoaWithdrawalInvariantError: () => import_internal_utils20.PoaWithdrawalInvariantError,
48
- PoaWithdrawalNotFoundError: () => import_internal_utils20.PoaWithdrawalNotFoundError,
49
- PoaWithdrawalPendingError: () => import_internal_utils20.PoaWithdrawalPendingError,
50
- QuoteError: () => import_internal_utils23.QuoteError,
51
- RelayPublishError: () => import_internal_utils23.RelayPublishError,
47
+ PoaWithdrawalInvariantError: () => import_internal_utils23.PoaWithdrawalInvariantError,
48
+ PoaWithdrawalNotFoundError: () => import_internal_utils23.PoaWithdrawalNotFoundError,
49
+ PoaWithdrawalPendingError: () => import_internal_utils23.PoaWithdrawalPendingError,
50
+ QuoteError: () => import_internal_utils26.QuoteError,
51
+ RelayPublishError: () => import_internal_utils26.RelayPublishError,
52
52
  RouteEnum: () => RouteEnum,
53
- RpcRequestError: () => import_internal_utils21.RpcRequestError,
54
- TimeoutError: () => import_internal_utils21.TimeoutError,
53
+ RpcRequestError: () => import_internal_utils24.RpcRequestError,
54
+ TimeoutError: () => import_internal_utils24.TimeoutError,
55
55
  TokenNotFoundInDestinationChainError: () => TokenNotFoundInDestinationChainError,
56
56
  TokenNotSupportedByOmniRelayerError: () => TokenNotSupportedByOmniRelayerError,
57
57
  TrustlineNotFoundError: () => TrustlineNotFoundError,
58
+ UnsupportedAssetIdError: () => UnsupportedAssetIdError,
58
59
  UnsupportedDestinationMemoError: () => UnsupportedDestinationMemoError,
59
60
  createDefaultRoute: () => createDefaultRoute,
60
61
  createHotBridgeRoute: () => createHotBridgeRoute,
@@ -63,19 +64,19 @@ __export(index_exports, {
63
64
  createIntentSignerViem: () => createIntentSignerViem,
64
65
  createInternalTransferRoute: () => createInternalTransferRoute,
65
66
  createNearWithdrawalRoute: () => createNearWithdrawalRoute,
66
- createOmniWithdrawalRoute: () => createOmniWithdrawalRoute,
67
+ createOmniBridgeRoute: () => createOmniBridgeRoute,
67
68
  createPoaBridgeRoute: () => createPoaBridgeRoute,
68
69
  createVirtualChainRoute: () => createVirtualChainRoute
69
70
  });
70
71
  module.exports = __toCommonJS(index_exports);
71
72
 
72
73
  // src/sdk.ts
73
- var import_internal_utils16 = require("@defuse-protocol/internal-utils");
74
+ var import_internal_utils19 = require("@defuse-protocol/internal-utils");
74
75
  var import_omni_sdk3 = __toESM(require("@hot-labs/omni-sdk"), 1);
75
76
  var import_viem2 = require("viem");
76
77
 
77
78
  // src/bridges/aurora-engine-bridge/aurora-engine-bridge.ts
78
- var import_internal_utils2 = require("@defuse-protocol/internal-utils");
79
+ var import_internal_utils6 = require("@defuse-protocol/internal-utils");
79
80
 
80
81
  // src/constants/route-enum.ts
81
82
  var RouteEnum = {
@@ -129,6 +130,190 @@ function withdrawalParamsInvariant(params) {
129
130
  );
130
131
  }
131
132
 
133
+ // src/lib/parse-defuse-asset-id.ts
134
+ var import_internal_utils3 = require("@defuse-protocol/internal-utils");
135
+
136
+ // src/classes/errors.ts
137
+ var import_internal_utils2 = require("@defuse-protocol/internal-utils");
138
+ var FeeExceedsAmountError = class extends import_internal_utils2.BaseError {
139
+ constructor(feeEstimation, amount) {
140
+ super("Amount too small to pay fee.", {
141
+ metaMessages: [
142
+ `Required fee: ${feeEstimation.amount}`,
143
+ `Withdrawal amount: ${amount}`
144
+ ],
145
+ name: "FeeExceedsAmountError"
146
+ });
147
+ this.feeEstimation = feeEstimation;
148
+ this.amount = amount;
149
+ }
150
+ };
151
+ var MinWithdrawalAmountError = class extends import_internal_utils2.BaseError {
152
+ constructor(minAmount, requestedAmount, assetId) {
153
+ super("Withdrawal amount is below minimum required by the bridge.", {
154
+ metaMessages: [
155
+ `Asset ID: ${assetId}`,
156
+ `Minimum amount: ${minAmount}`,
157
+ `Requested amount: ${requestedAmount}`
158
+ ],
159
+ name: "MinWithdrawalAmountError"
160
+ });
161
+ this.minAmount = minAmount;
162
+ this.requestedAmount = requestedAmount;
163
+ this.assetId = assetId;
164
+ }
165
+ };
166
+ var UnsupportedDestinationMemoError = class extends import_internal_utils2.BaseError {
167
+ constructor(blockchain, assetId) {
168
+ super("Destination memo is not supported for this blockchain.", {
169
+ details: "Destination memo is only supported for XRP Ledger withdrawals.",
170
+ metaMessages: [`Blockchain: ${blockchain}`, `Asset ID: ${assetId}`],
171
+ name: "UnsupportedDestinationMemoError"
172
+ });
173
+ this.blockchain = blockchain;
174
+ this.assetId = assetId;
175
+ }
176
+ };
177
+ var TrustlineNotFoundError = class extends import_internal_utils2.BaseError {
178
+ constructor(destinationAddress, assetId, blockchain, tokenAddress) {
179
+ super("Destination address does not have a trustline for this asset.", {
180
+ details: "The destination address must establish a trustline before receiving this asset.",
181
+ metaMessages: [
182
+ `Blockchain: ${blockchain}`,
183
+ `Asset ID: ${assetId}`,
184
+ `Destination address: ${destinationAddress}`,
185
+ `Token address: ${tokenAddress}`
186
+ ],
187
+ name: "TrustlineNotFoundError"
188
+ });
189
+ this.destinationAddress = destinationAddress;
190
+ this.assetId = assetId;
191
+ this.blockchain = blockchain;
192
+ this.tokenAddress = tokenAddress;
193
+ }
194
+ };
195
+ var UnsupportedAssetIdError = class extends import_internal_utils2.BaseError {
196
+ constructor(assetId, details) {
197
+ super("Asset ID is not supported.", {
198
+ details,
199
+ metaMessages: [`Asset ID: ${assetId}`],
200
+ name: "UnsupportedAssetIdError"
201
+ });
202
+ this.assetId = assetId;
203
+ }
204
+ };
205
+
206
+ // src/lib/parse-defuse-asset-id.ts
207
+ function parseDefuseAssetId(assetId) {
208
+ try {
209
+ return import_internal_utils3.utils.parseDefuseAssetId(assetId);
210
+ } catch {
211
+ throw new UnsupportedAssetIdError(assetId, "Invalid asset id format.");
212
+ }
213
+ }
214
+
215
+ // src/lib/estimate-fee.ts
216
+ var import_internal_utils5 = require("@defuse-protocol/internal-utils");
217
+
218
+ // src/lib/tokensUsdPricesHttpClient/apis.ts
219
+ var import_internal_utils4 = require("@defuse-protocol/internal-utils");
220
+ async function tokens(config) {
221
+ const response = await (0, import_internal_utils4.request)({
222
+ url: new URL(
223
+ "tokens",
224
+ import_internal_utils4.configsByEnvironment[config.env].managerConsoleBaseURL
225
+ ),
226
+ ...config,
227
+ fetchOptions: {
228
+ ...config.fetchOptions,
229
+ method: "GET"
230
+ }
231
+ });
232
+ return response.json();
233
+ }
234
+
235
+ // src/lib/estimate-fee.ts
236
+ async function getFeeQuote({
237
+ feeAmount,
238
+ feeAssetId,
239
+ tokenAssetId,
240
+ quoteOptions,
241
+ env,
242
+ logger
243
+ }) {
244
+ try {
245
+ return await import_internal_utils5.solverRelay.getQuote({
246
+ quoteParams: {
247
+ defuse_asset_identifier_in: tokenAssetId,
248
+ defuse_asset_identifier_out: feeAssetId,
249
+ exact_amount_out: feeAmount.toString(),
250
+ wait_ms: quoteOptions?.waitMs
251
+ },
252
+ config: {
253
+ baseURL: import_internal_utils5.configsByEnvironment[env].solverRelayBaseURL,
254
+ logBalanceSufficient: false,
255
+ logger
256
+ }
257
+ });
258
+ } catch (err) {
259
+ if (!(err instanceof import_internal_utils5.QuoteError)) {
260
+ throw err;
261
+ }
262
+ logger?.info(
263
+ "Can't get exact out quote, trying to get exact in quote with x1.2"
264
+ );
265
+ const prices = await tokens({ env });
266
+ const feeAssetPrice = prices.items.find(
267
+ (t) => t.defuse_asset_id === feeAssetId
268
+ );
269
+ const tokenAssetPrice = prices.items.find(
270
+ (t) => t.defuse_asset_id === tokenAssetId
271
+ );
272
+ if (feeAssetPrice == null || tokenAssetPrice == null) {
273
+ throw err;
274
+ }
275
+ const USD_SCALE = 1e6;
276
+ const feePriceScaled = BigInt(Math.round(feeAssetPrice.price * USD_SCALE));
277
+ const tokenPriceScaled = BigInt(
278
+ Math.round(tokenAssetPrice.price * USD_SCALE)
279
+ );
280
+ const feeDecimals = BigInt(feeAssetPrice.decimals);
281
+ const tokenDecimals = BigInt(tokenAssetPrice.decimals);
282
+ const num = feeAmount * feePriceScaled * 12n * 10n ** tokenDecimals;
283
+ const den = tokenPriceScaled * 10n ** feeDecimals * 10n;
284
+ let exactAmountIn = num / den;
285
+ if (num % den !== 0n) exactAmountIn += 1n;
286
+ if (exactAmountIn === 0n) exactAmountIn = 1n;
287
+ const quote = await import_internal_utils5.solverRelay.getQuote({
288
+ quoteParams: {
289
+ defuse_asset_identifier_in: tokenAssetId,
290
+ defuse_asset_identifier_out: feeAssetId,
291
+ exact_amount_in: exactAmountIn.toString(),
292
+ wait_ms: quoteOptions?.waitMs
293
+ },
294
+ config: {
295
+ baseURL: import_internal_utils5.configsByEnvironment[env].solverRelayBaseURL,
296
+ logBalanceSufficient: false,
297
+ logger
298
+ }
299
+ });
300
+ const RATIO_SCALE = 1000n;
301
+ const actualRatio = BigInt(quote.amount_out) * RATIO_SCALE / feeAmount;
302
+ const actualRatioNumber = Number(actualRatio) / Number(RATIO_SCALE);
303
+ if (actualRatio > 1500n) {
304
+ logger?.warn(
305
+ `Quote amount_out ratio is too high: ${actualRatioNumber.toFixed(2)}x`
306
+ );
307
+ throw err;
308
+ }
309
+ if (BigInt(quote.amount_out) < feeAmount) {
310
+ logger?.warn("Quote amount_out is less than feeAmount");
311
+ throw err;
312
+ }
313
+ return quote;
314
+ }
315
+ }
316
+
132
317
  // src/bridges/aurora-engine-bridge/aurora-engine-bridge.ts
133
318
  var AuroraEngineBridge = class {
134
319
  constructor({
@@ -141,11 +326,19 @@ var AuroraEngineBridge = class {
141
326
  is(routeConfig) {
142
327
  return routeConfig.route === RouteEnum.VirtualChain;
143
328
  }
144
- supports(params) {
145
- if ("routeConfig" in params && params.routeConfig != null) {
146
- return this.is(params.routeConfig);
329
+ async supports(params) {
330
+ if (params.routeConfig == null || !this.is(params.routeConfig)) {
331
+ return false;
147
332
  }
148
- return false;
333
+ const assetInfo = parseDefuseAssetId(params.assetId);
334
+ const isValid = assetInfo.standard === "nep141";
335
+ if (!isValid) {
336
+ throw new UnsupportedAssetIdError(
337
+ params.assetId,
338
+ "`assetId` does not match `routeConfig`."
339
+ );
340
+ }
341
+ return isValid;
149
342
  }
150
343
  parseAssetId() {
151
344
  return null;
@@ -182,16 +375,16 @@ var AuroraEngineBridge = class {
182
375
  }
183
376
  async estimateWithdrawalFee(args) {
184
377
  withdrawalParamsInvariant(args.withdrawalParams);
185
- const { contractId: tokenAccountId, standard } = import_internal_utils2.utils.parseDefuseAssetId(
378
+ const { contractId: tokenAccountId, standard } = import_internal_utils6.utils.parseDefuseAssetId(
186
379
  args.withdrawalParams.assetId
187
380
  );
188
- (0, import_internal_utils2.assert)(standard === "nep141", "Only NEP-141 is supported");
381
+ (0, import_internal_utils6.assert)(standard === "nep141", "Only NEP-141 is supported");
189
382
  const [minStorageBalance, userStorageBalance] = await Promise.all([
190
- (0, import_internal_utils2.getNearNep141MinStorageBalance)({
383
+ (0, import_internal_utils6.getNearNep141MinStorageBalance)({
191
384
  contractId: tokenAccountId,
192
385
  nearProvider: this.nearProvider
193
386
  }),
194
- (0, import_internal_utils2.getNearNep141StorageBalance)({
387
+ (0, import_internal_utils6.getNearNep141StorageBalance)({
195
388
  contractId: tokenAccountId,
196
389
  accountId: args.withdrawalParams.routeConfig.auroraEngineContractId,
197
390
  nearProvider: this.nearProvider
@@ -205,18 +398,13 @@ var AuroraEngineBridge = class {
205
398
  }
206
399
  const feeAssetId = NEAR_NATIVE_ASSET_ID;
207
400
  const feeAmount = minStorageBalance - userStorageBalance;
208
- const feeQuote = args.withdrawalParams.assetId === feeAssetId ? null : await import_internal_utils2.solverRelay.getQuote({
209
- quoteParams: {
210
- defuse_asset_identifier_in: args.withdrawalParams.assetId,
211
- defuse_asset_identifier_out: feeAssetId,
212
- exact_amount_out: feeAmount.toString(),
213
- wait_ms: args.quoteOptions?.waitMs
214
- },
215
- config: {
216
- baseURL: import_internal_utils2.configsByEnvironment[this.env].solverRelayBaseURL,
217
- logBalanceSufficient: false,
218
- logger: args.logger
219
- }
401
+ const feeQuote = args.withdrawalParams.assetId === feeAssetId ? null : await getFeeQuote({
402
+ feeAmount,
403
+ feeAssetId,
404
+ tokenAssetId: args.withdrawalParams.assetId,
405
+ logger: args.logger,
406
+ env: this.env,
407
+ quoteOptions: args.quoteOptions
220
408
  });
221
409
  return {
222
410
  amount: feeQuote ? BigInt(feeQuote.amount_in) : feeAmount,
@@ -229,7 +417,7 @@ var AuroraEngineBridge = class {
229
417
  };
230
418
 
231
419
  // src/bridges/direct-bridge/direct-bridge.ts
232
- var import_internal_utils5 = require("@defuse-protocol/internal-utils");
420
+ var import_internal_utils9 = require("@defuse-protocol/internal-utils");
233
421
 
234
422
  // src/constants/bridge-name-enum.ts
235
423
  var BridgeNameEnum = {
@@ -240,7 +428,7 @@ var BridgeNameEnum = {
240
428
  };
241
429
 
242
430
  // src/lib/caip2.ts
243
- var import_internal_utils3 = require("@defuse-protocol/internal-utils");
431
+ var import_internal_utils7 = require("@defuse-protocol/internal-utils");
244
432
  var Chains = {
245
433
  Bitcoin: "bip122:000000000019d6689c085ae165831e93",
246
434
  Zcash: "bip122:00040fe8ec8471911baa1db1266ea15d",
@@ -265,11 +453,11 @@ var Chains = {
265
453
  Cardano: "cip34:1-764824073"
266
454
  };
267
455
  function getEIP155ChainId(chain) {
268
- (0, import_internal_utils3.assert)(chain.startsWith("eip155:"), "Chain is not an EIP-155 chain");
456
+ (0, import_internal_utils7.assert)(chain.startsWith("eip155:"), "Chain is not an EIP-155 chain");
269
457
  const chainIdStr = chain.slice(7);
270
- (0, import_internal_utils3.assert)(chainIdStr.length > 0, "Chain is not an EIP-155 chain");
458
+ (0, import_internal_utils7.assert)(chainIdStr.length > 0, "Chain is not an EIP-155 chain");
271
459
  const chainId = Number(chainIdStr);
272
- (0, import_internal_utils3.assert)(!Number.isNaN(chainId), "Chain is not an EIP-155 chain");
460
+ (0, import_internal_utils7.assert)(!Number.isNaN(chainId), "Chain is not an EIP-155 chain");
273
461
  return chainId;
274
462
  }
275
463
 
@@ -277,7 +465,7 @@ function getEIP155ChainId(chain) {
277
465
  var NEAR_NATIVE_ASSET_ID2 = "nep141:wrap.near";
278
466
 
279
467
  // src/bridges/direct-bridge/direct-bridge-utils.ts
280
- var import_internal_utils4 = require("@defuse-protocol/internal-utils");
468
+ var import_internal_utils8 = require("@defuse-protocol/internal-utils");
281
469
  function createWithdrawIntentPrimitive2(params) {
282
470
  if (params.assetId === NEAR_NATIVE_ASSET_ID2 && // Ensure `msg` is not passed, because `native_withdraw` intent doesn't support `msg`
283
471
  params.msg === void 0) {
@@ -287,10 +475,10 @@ function createWithdrawIntentPrimitive2(params) {
287
475
  amount: params.amount.toString()
288
476
  };
289
477
  }
290
- const { contractId: tokenAccountId, standard } = import_internal_utils4.utils.parseDefuseAssetId(
478
+ const { contractId: tokenAccountId, standard } = import_internal_utils8.utils.parseDefuseAssetId(
291
479
  params.assetId
292
480
  );
293
- (0, import_internal_utils4.assert)(standard === "nep141", "Only NEP-141 is supported");
481
+ (0, import_internal_utils8.assert)(standard === "nep141", "Only NEP-141 is supported");
294
482
  return {
295
483
  intent: "ft_withdraw",
296
484
  token: tokenAccountId,
@@ -301,7 +489,7 @@ function createWithdrawIntentPrimitive2(params) {
301
489
  };
302
490
  }
303
491
  function withdrawalParamsInvariant2(params) {
304
- (0, import_internal_utils4.assert)(
492
+ (0, import_internal_utils8.assert)(
305
493
  !params.routeConfig ? true : params.routeConfig.route === RouteEnum.NearWithdrawal,
306
494
  "Bridge is not direct"
307
495
  );
@@ -319,19 +507,22 @@ var DirectBridge = class {
319
507
  is(routeConfig) {
320
508
  return routeConfig.route === RouteEnum.NearWithdrawal;
321
509
  }
322
- supports(params) {
323
- let result = true;
324
- if ("routeConfig" in params && params.routeConfig != null) {
325
- result && (result = this.is(params.routeConfig));
326
- }
327
- try {
328
- return result && this.parseAssetId(params.assetId) != null;
329
- } catch {
510
+ async supports(params) {
511
+ if (params.routeConfig != null && !this.is(params.routeConfig)) {
330
512
  return false;
331
513
  }
514
+ const assetInfo = this.parseAssetId(params.assetId);
515
+ const isValid = assetInfo != null;
516
+ if (!isValid && params.routeConfig != null) {
517
+ throw new UnsupportedAssetIdError(
518
+ params.assetId,
519
+ "`assetId` does not match `routeConfig`."
520
+ );
521
+ }
522
+ return isValid;
332
523
  }
333
524
  parseAssetId(assetId) {
334
- const parsed = import_internal_utils5.utils.parseDefuseAssetId(assetId);
525
+ const parsed = parseDefuseAssetId(assetId);
335
526
  if (parsed.standard === "nep141") {
336
527
  return Object.assign(parsed, {
337
528
  blockchain: Chains.Near,
@@ -372,10 +563,10 @@ var DirectBridge = class {
372
563
  }
373
564
  async estimateWithdrawalFee(args) {
374
565
  withdrawalParamsInvariant2(args.withdrawalParams);
375
- const { contractId: tokenAccountId, standard } = import_internal_utils5.utils.parseDefuseAssetId(
566
+ const { contractId: tokenAccountId, standard } = import_internal_utils9.utils.parseDefuseAssetId(
376
567
  args.withdrawalParams.assetId
377
568
  );
378
- (0, import_internal_utils5.assert)(standard === "nep141", "Only NEP-141 is supported");
569
+ (0, import_internal_utils9.assert)(standard === "nep141", "Only NEP-141 is supported");
379
570
  if (
380
571
  // We don't directly withdraw `wrap.near`, we unwrap it first, so it doesn't require storage
381
572
  args.withdrawalParams.assetId === NEAR_NATIVE_ASSET_ID2 && // Ensure `msg` is not passed, because `native_withdraw` intent doesn't support `msg`
@@ -386,11 +577,11 @@ var DirectBridge = class {
386
577
  quote: null
387
578
  };
388
579
  const [minStorageBalance, userStorageBalance] = await Promise.all([
389
- (0, import_internal_utils5.getNearNep141MinStorageBalance)({
580
+ (0, import_internal_utils9.getNearNep141MinStorageBalance)({
390
581
  contractId: tokenAccountId,
391
582
  nearProvider: this.nearProvider
392
583
  }),
393
- (0, import_internal_utils5.getNearNep141StorageBalance)({
584
+ (0, import_internal_utils9.getNearNep141StorageBalance)({
394
585
  contractId: tokenAccountId,
395
586
  accountId: args.withdrawalParams.destinationAddress,
396
587
  nearProvider: this.nearProvider
@@ -404,18 +595,13 @@ var DirectBridge = class {
404
595
  }
405
596
  const feeAssetId = NEAR_NATIVE_ASSET_ID2;
406
597
  const feeAmount = minStorageBalance - userStorageBalance;
407
- const feeQuote = args.withdrawalParams.assetId === feeAssetId ? null : await import_internal_utils5.solverRelay.getQuote({
408
- quoteParams: {
409
- defuse_asset_identifier_in: args.withdrawalParams.assetId,
410
- defuse_asset_identifier_out: feeAssetId,
411
- exact_amount_out: feeAmount.toString(),
412
- wait_ms: args.quoteOptions?.waitMs
413
- },
414
- config: {
415
- baseURL: import_internal_utils5.configsByEnvironment[this.env].solverRelayBaseURL,
416
- logBalanceSufficient: false,
417
- logger: args.logger
418
- }
598
+ const feeQuote = args.withdrawalParams.assetId === feeAssetId ? null : await getFeeQuote({
599
+ feeAmount,
600
+ feeAssetId,
601
+ tokenAssetId: args.withdrawalParams.assetId,
602
+ logger: args.logger,
603
+ env: this.env,
604
+ quoteOptions: args.quoteOptions
419
605
  });
420
606
  return {
421
607
  amount: feeQuote ? BigInt(feeQuote.amount_in) : feeAmount,
@@ -428,73 +614,13 @@ var DirectBridge = class {
428
614
  };
429
615
 
430
616
  // src/bridges/hot-bridge/hot-bridge.ts
431
- var import_internal_utils9 = require("@defuse-protocol/internal-utils");
617
+ var import_internal_utils12 = require("@defuse-protocol/internal-utils");
432
618
  var import_omni_sdk2 = require("@hot-labs/omni-sdk");
433
619
  var import_attempt = require("@lifeomic/attempt");
434
620
 
435
- // src/classes/errors.ts
436
- var import_internal_utils6 = require("@defuse-protocol/internal-utils");
437
- var FeeExceedsAmountError = class extends import_internal_utils6.BaseError {
438
- constructor(feeEstimation, amount) {
439
- super("Amount too small to pay fee.", {
440
- metaMessages: [
441
- `Required fee: ${feeEstimation.amount}`,
442
- `Withdrawal amount: ${amount}`
443
- ],
444
- name: "FeeExceedsAmountError"
445
- });
446
- this.feeEstimation = feeEstimation;
447
- this.amount = amount;
448
- }
449
- };
450
- var MinWithdrawalAmountError = class extends import_internal_utils6.BaseError {
451
- constructor(minAmount, requestedAmount, assetId) {
452
- super("Withdrawal amount is below minimum required by the bridge.", {
453
- metaMessages: [
454
- `Asset ID: ${assetId}`,
455
- `Minimum amount: ${minAmount}`,
456
- `Requested amount: ${requestedAmount}`
457
- ],
458
- name: "MinWithdrawalAmountError"
459
- });
460
- this.minAmount = minAmount;
461
- this.requestedAmount = requestedAmount;
462
- this.assetId = assetId;
463
- }
464
- };
465
- var UnsupportedDestinationMemoError = class extends import_internal_utils6.BaseError {
466
- constructor(blockchain, assetId) {
467
- super("Destination memo is not supported for this blockchain.", {
468
- details: "Destination memo is only supported for XRP Ledger withdrawals.",
469
- metaMessages: [`Blockchain: ${blockchain}`, `Asset ID: ${assetId}`],
470
- name: "UnsupportedDestinationMemoError"
471
- });
472
- this.blockchain = blockchain;
473
- this.assetId = assetId;
474
- }
475
- };
476
- var TrustlineNotFoundError = class extends import_internal_utils6.BaseError {
477
- constructor(destinationAddress, assetId, blockchain, tokenAddress) {
478
- super("Destination address does not have a trustline for this asset.", {
479
- details: "The destination address must establish a trustline before receiving this asset.",
480
- metaMessages: [
481
- `Blockchain: ${blockchain}`,
482
- `Asset ID: ${assetId}`,
483
- `Destination address: ${destinationAddress}`,
484
- `Token address: ${tokenAddress}`
485
- ],
486
- name: "TrustlineNotFoundError"
487
- });
488
- this.destinationAddress = destinationAddress;
489
- this.assetId = assetId;
490
- this.blockchain = blockchain;
491
- this.tokenAddress = tokenAddress;
492
- }
493
- };
494
-
495
621
  // src/bridges/hot-bridge/error.ts
496
- var import_internal_utils7 = require("@defuse-protocol/internal-utils");
497
- var HotWithdrawalPendingError = class extends import_internal_utils7.BaseError {
622
+ var import_internal_utils10 = require("@defuse-protocol/internal-utils");
623
+ var HotWithdrawalPendingError = class extends import_internal_utils10.BaseError {
498
624
  constructor(txHash, index) {
499
625
  super("Withdrawal is still pending.", {
500
626
  metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
@@ -504,7 +630,7 @@ var HotWithdrawalPendingError = class extends import_internal_utils7.BaseError {
504
630
  this.index = index;
505
631
  }
506
632
  };
507
- var HotWithdrawalNotFoundError = class extends import_internal_utils7.BaseError {
633
+ var HotWithdrawalNotFoundError = class extends import_internal_utils10.BaseError {
508
634
  constructor(txHash, index) {
509
635
  super("Withdrawal with given index is not found.", {
510
636
  metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
@@ -514,7 +640,7 @@ var HotWithdrawalNotFoundError = class extends import_internal_utils7.BaseError
514
640
  this.index = index;
515
641
  }
516
642
  };
517
- var HotWithdrawalCancelledError = class extends import_internal_utils7.BaseError {
643
+ var HotWithdrawalCancelledError = class extends import_internal_utils10.BaseError {
518
644
  constructor(txHash, index) {
519
645
  super("Gasless withdrawal was canceled.", {
520
646
  metaMessages: [`TxHash: ${txHash}`, `Index: ${index}`],
@@ -532,7 +658,7 @@ var HotWithdrawStatus = {
532
658
  };
533
659
 
534
660
  // src/bridges/hot-bridge/hot-bridge-utils.ts
535
- var import_internal_utils8 = require("@defuse-protocol/internal-utils");
661
+ var import_internal_utils11 = require("@defuse-protocol/internal-utils");
536
662
  var import_omni_sdk = require("@hot-labs/omni-sdk");
537
663
 
538
664
  // src/bridges/hot-bridge/hot-bridge-chains.ts
@@ -586,7 +712,7 @@ function formatTxHash(txHash, caip2) {
586
712
  return txHash;
587
713
  }
588
714
  function hotBlockchainInvariant(blockchain) {
589
- (0, import_internal_utils8.assert)(
715
+ (0, import_internal_utils11.assert)(
590
716
  HotBridgeChains.includes(blockchain),
591
717
  `${blockchain} is not a valid HOT Bridge blockchain. Supported values: ${HotBridgeChains.join()}`
592
718
  );
@@ -601,41 +727,60 @@ var HotBridge = class {
601
727
  is(routeConfig) {
602
728
  return routeConfig.route === RouteEnum.HotBridge;
603
729
  }
604
- supports(params) {
605
- let result = true;
606
- if ("routeConfig" in params && params.routeConfig != null) {
607
- result && (result = this.is(params.routeConfig));
608
- }
609
- try {
610
- return result && this.parseAssetId(params.assetId) != null;
611
- } catch {
730
+ async supports(params) {
731
+ if (params.routeConfig != null && !this.is(params.routeConfig)) {
612
732
  return false;
613
733
  }
734
+ const assetInfo = this.parseAssetId(params.assetId);
735
+ const isValid = assetInfo != null;
736
+ if (!isValid && params.routeConfig != null) {
737
+ throw new UnsupportedAssetIdError(
738
+ params.assetId,
739
+ "`assetId` does not match `routeConfig`."
740
+ );
741
+ }
742
+ return isValid;
614
743
  }
615
744
  parseAssetId(assetId) {
616
- const parsed = import_internal_utils9.utils.parseDefuseAssetId(assetId);
617
- if (parsed.contractId === import_omni_sdk2.utils.OMNI_HOT_V2) {
618
- (0, import_internal_utils9.assert)(
619
- parsed.standard === "nep245",
620
- "NEP-245 is supported only for HOT bridge"
745
+ const parsed = parseDefuseAssetId(assetId);
746
+ const contractIdSatisfies = parsed.contractId === import_omni_sdk2.utils.OMNI_HOT_V2;
747
+ if (!contractIdSatisfies) {
748
+ return null;
749
+ }
750
+ if (parsed.standard !== "nep245") {
751
+ throw new UnsupportedAssetIdError(
752
+ assetId,
753
+ 'Should start with "nep245:".'
621
754
  );
622
- const [chainId, address] = import_omni_sdk2.utils.fromOmni(parsed.tokenId).split(":");
623
- (0, import_internal_utils9.assert)(chainId != null, "Chain ID is not found");
624
- (0, import_internal_utils9.assert)(address != null, "Address is not found");
625
- return Object.assign(
626
- parsed,
627
- {
628
- blockchain: hotNetworkIdToCAIP2(chainId),
629
- bridgeName: BridgeNameEnum.Hot
630
- },
631
- address === "native" ? { native: true } : { address }
755
+ }
756
+ const [chainId, address] = import_omni_sdk2.utils.fromOmni(parsed.tokenId).split(":");
757
+ if (chainId == null || address == null) {
758
+ throw new UnsupportedAssetIdError(
759
+ assetId,
760
+ "Asset has invalid token id format."
632
761
  );
633
762
  }
634
- return null;
763
+ let blockchain;
764
+ try {
765
+ blockchain = hotNetworkIdToCAIP2(chainId);
766
+ } catch {
767
+ throw new UnsupportedAssetIdError(
768
+ assetId,
769
+ "Asset belongs to unknown blockchain."
770
+ );
771
+ }
772
+ return Object.assign(
773
+ parsed,
774
+ {
775
+ blockchain,
776
+ bridgeName: BridgeNameEnum.Hot
777
+ },
778
+ address === "native" ? { native: true } : { address }
779
+ );
635
780
  }
636
781
  async createWithdrawalIntents(args) {
637
782
  const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
638
- (0, import_internal_utils9.assert)(assetInfo != null, "Asset is not supported");
783
+ (0, import_internal_utils12.assert)(assetInfo != null, "Asset is not supported");
639
784
  if (args.withdrawalParams.destinationMemo != null && args.withdrawalParams.destinationMemo !== "") {
640
785
  throw new UnsupportedDestinationMemoError(
641
786
  assetInfo.blockchain,
@@ -669,9 +814,9 @@ var HotBridge = class {
669
814
  intentAccount: ""
670
815
  // it is not used inside the function
671
816
  });
672
- (0, import_internal_utils9.assert)(intent.amounts[0] === amount.toString(), "Amount is not correct");
817
+ (0, import_internal_utils12.assert)(intent.amounts[0] === amount.toString(), "Amount is not correct");
673
818
  if (intent.amounts.length === 2) {
674
- (0, import_internal_utils9.assert)(
819
+ (0, import_internal_utils12.assert)(
675
820
  intent.amounts[1] === feeAmount.toString(),
676
821
  "Amount is not correct"
677
822
  );
@@ -686,7 +831,7 @@ var HotBridge = class {
686
831
  */
687
832
  async validateWithdrawal(args) {
688
833
  const assetInfo = this.parseAssetId(args.assetId);
689
- (0, import_internal_utils9.assert)(assetInfo != null, "Asset is not supported");
834
+ (0, import_internal_utils12.assert)(assetInfo != null, "Asset is not supported");
690
835
  hotBlockchainInvariant(assetInfo.blockchain);
691
836
  if (assetInfo.blockchain === Chains.Stellar) {
692
837
  const token = "native" in assetInfo ? "native" : assetInfo.address;
@@ -706,25 +851,20 @@ var HotBridge = class {
706
851
  }
707
852
  async estimateWithdrawalFee(args) {
708
853
  const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
709
- (0, import_internal_utils9.assert)(assetInfo != null, "Asset is not supported");
854
+ (0, import_internal_utils12.assert)(assetInfo != null, "Asset is not supported");
710
855
  hotBlockchainInvariant(assetInfo.blockchain);
711
856
  const { gasPrice: feeAmount } = await this.hotSdk.getGaslessWithdrawFee(
712
857
  toHotNetworkId(assetInfo.blockchain),
713
858
  args.withdrawalParams.destinationAddress
714
859
  );
715
860
  const feeAssetId = getFeeAssetIdForChain(assetInfo.blockchain);
716
- const feeQuote = args.withdrawalParams.assetId === feeAssetId || feeAmount === 0n ? null : await import_internal_utils9.solverRelay.getQuote({
717
- quoteParams: {
718
- defuse_asset_identifier_in: args.withdrawalParams.assetId,
719
- defuse_asset_identifier_out: feeAssetId,
720
- exact_amount_out: feeAmount.toString(),
721
- wait_ms: args.quoteOptions?.waitMs
722
- },
723
- config: {
724
- baseURL: import_internal_utils9.configsByEnvironment[this.env].solverRelayBaseURL,
725
- logBalanceSufficient: false,
726
- logger: args.logger
727
- }
861
+ const feeQuote = args.withdrawalParams.assetId === feeAssetId || feeAmount === 0n ? null : await getFeeQuote({
862
+ feeAmount,
863
+ feeAssetId,
864
+ tokenAssetId: args.withdrawalParams.assetId,
865
+ logger: args.logger,
866
+ env: this.env,
867
+ quoteOptions: args.quoteOptions
728
868
  });
729
869
  return {
730
870
  amount: feeQuote ? BigInt(feeQuote.amount_in) : feeAmount,
@@ -762,7 +902,7 @@ var HotBridge = class {
762
902
  throw new HotWithdrawalPendingError(args.tx.hash, args.index);
763
903
  },
764
904
  {
765
- ...args.retryOptions ?? import_internal_utils9.RETRY_CONFIGS.TWO_MINS_GRADUAL,
905
+ ...args.retryOptions ?? import_internal_utils12.RETRY_CONFIGS.TWO_MINS_GRADUAL,
766
906
  handleError: (err, ctx) => {
767
907
  if (err instanceof HotWithdrawalCancelledError || err === args.signal?.reason) {
768
908
  ctx.abort();
@@ -778,7 +918,7 @@ var IntentsBridge = class {
778
918
  is(routeConfig) {
779
919
  return routeConfig.route === RouteEnum.InternalTransfer;
780
920
  }
781
- supports(params) {
921
+ async supports(params) {
782
922
  if ("routeConfig" in params && params.routeConfig != null) {
783
923
  return this.is(params.routeConfig);
784
924
  }
@@ -817,13 +957,13 @@ var IntentsBridge = class {
817
957
  };
818
958
 
819
959
  // src/bridges/poa-bridge/poa-bridge.ts
820
- var import_internal_utils11 = require("@defuse-protocol/internal-utils");
960
+ var import_internal_utils14 = require("@defuse-protocol/internal-utils");
821
961
  var import_ttlcache = __toESM(require("@isaacs/ttlcache"), 1);
822
962
 
823
963
  // src/bridges/poa-bridge/poa-bridge-utils.ts
824
- var import_internal_utils10 = require("@defuse-protocol/internal-utils");
964
+ var import_internal_utils13 = require("@defuse-protocol/internal-utils");
825
965
  function createWithdrawIntentPrimitive3(params) {
826
- const { contractId: tokenAccountId } = import_internal_utils10.utils.parseDefuseAssetId(
966
+ const { contractId: tokenAccountId } = import_internal_utils13.utils.parseDefuseAssetId(
827
967
  params.assetId
828
968
  );
829
969
  return {
@@ -904,30 +1044,43 @@ var PoaBridge = class {
904
1044
  is(routeConfig) {
905
1045
  return routeConfig.route === RouteEnum.PoaBridge;
906
1046
  }
907
- supports(params) {
908
- let result = true;
909
- if ("routeConfig" in params && params.routeConfig != null) {
910
- result && (result = this.is(params.routeConfig));
911
- }
912
- try {
913
- return result && this.parseAssetId(params.assetId) != null;
914
- } catch {
1047
+ async supports(params) {
1048
+ if (params.routeConfig != null && !this.is(params.routeConfig)) {
915
1049
  return false;
916
1050
  }
1051
+ const assetInfo = this.parseAssetId(params.assetId);
1052
+ const isValid = assetInfo != null;
1053
+ if (!isValid && params.routeConfig != null) {
1054
+ throw new UnsupportedAssetIdError(
1055
+ params.assetId,
1056
+ "`assetId` does not match `routeConfig`."
1057
+ );
1058
+ }
1059
+ return isValid;
917
1060
  }
918
1061
  parseAssetId(assetId) {
919
- const parsed = import_internal_utils11.utils.parseDefuseAssetId(assetId);
920
- if (parsed.contractId.endsWith(
921
- `.${import_internal_utils11.configsByEnvironment[this.env].poaTokenFactoryContractID}`
922
- )) {
923
- return Object.assign(parsed, {
924
- blockchain: contractIdToCaip2(parsed.contractId),
925
- bridgeName: BridgeNameEnum.Poa,
926
- address: ""
927
- // todo: derive address (or native)
928
- });
1062
+ const parsed = parseDefuseAssetId(assetId);
1063
+ const contractIdSatisfies = parsed.contractId.endsWith(
1064
+ `.${import_internal_utils14.configsByEnvironment[this.env].poaTokenFactoryContractID}`
1065
+ );
1066
+ if (!contractIdSatisfies) {
1067
+ return null;
929
1068
  }
930
- return null;
1069
+ let blockchain;
1070
+ try {
1071
+ blockchain = contractIdToCaip2(parsed.contractId);
1072
+ } catch {
1073
+ throw new UnsupportedAssetIdError(
1074
+ assetId,
1075
+ "Asset belongs to unknown blockchain."
1076
+ );
1077
+ }
1078
+ return Object.assign(parsed, {
1079
+ blockchain,
1080
+ bridgeName: BridgeNameEnum.Poa,
1081
+ address: ""
1082
+ // todo: derive address (or native)
1083
+ });
931
1084
  }
932
1085
  createWithdrawalIntents(args) {
933
1086
  const intent = createWithdrawIntentPrimitive3({
@@ -945,12 +1098,12 @@ var PoaBridge = class {
945
1098
  */
946
1099
  async validateWithdrawal(args) {
947
1100
  const assetInfo = this.parseAssetId(args.assetId);
948
- (0, import_internal_utils11.assert)(assetInfo != null, "Asset is not supported");
949
- const { tokens } = await this.getCachedSupportedTokens(
1101
+ (0, import_internal_utils14.assert)(assetInfo != null, "Asset is not supported");
1102
+ const { tokens: tokens2 } = await this.getCachedSupportedTokens(
950
1103
  [toPoaNetwork(assetInfo.blockchain)],
951
1104
  args.logger
952
1105
  );
953
- const tokenInfo = tokens.find(
1106
+ const tokenInfo = tokens2.find(
954
1107
  (token) => token.intents_token_id === args.assetId
955
1108
  );
956
1109
  if (tokenInfo != null) {
@@ -966,16 +1119,16 @@ var PoaBridge = class {
966
1119
  }
967
1120
  async estimateWithdrawalFee(args) {
968
1121
  const assetInfo = this.parseAssetId(args.withdrawalParams.assetId);
969
- (0, import_internal_utils11.assert)(assetInfo != null, "Asset is not supported");
970
- const estimation = await import_internal_utils11.poaBridge.httpClient.getWithdrawalEstimate(
1122
+ (0, import_internal_utils14.assert)(assetInfo != null, "Asset is not supported");
1123
+ const estimation = await import_internal_utils14.poaBridge.httpClient.getWithdrawalEstimate(
971
1124
  {
972
- token: import_internal_utils11.utils.getTokenAccountId(args.withdrawalParams.assetId),
1125
+ token: import_internal_utils14.utils.getTokenAccountId(args.withdrawalParams.assetId),
973
1126
  address: args.withdrawalParams.destinationAddress,
974
1127
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
975
1128
  chain: toPoaNetwork(assetInfo.blockchain)
976
1129
  },
977
1130
  {
978
- baseURL: import_internal_utils11.configsByEnvironment[this.env].poaBridgeBaseURL,
1131
+ baseURL: import_internal_utils14.configsByEnvironment[this.env].poaBridgeBaseURL,
979
1132
  logger: args.logger
980
1133
  }
981
1134
  );
@@ -985,12 +1138,12 @@ var PoaBridge = class {
985
1138
  };
986
1139
  }
987
1140
  async waitForWithdrawalCompletion(args) {
988
- const withdrawalStatus = await import_internal_utils11.poaBridge.waitForWithdrawalCompletion({
1141
+ const withdrawalStatus = await import_internal_utils14.poaBridge.waitForWithdrawalCompletion({
989
1142
  txHash: args.tx.hash,
990
1143
  index: args.index,
991
1144
  signal: args.signal ?? new AbortController().signal,
992
1145
  retryOptions: args.retryOptions,
993
- baseURL: import_internal_utils11.configsByEnvironment[this.env].poaBridgeBaseURL,
1146
+ baseURL: import_internal_utils14.configsByEnvironment[this.env].poaBridgeBaseURL,
994
1147
  logger: args.logger
995
1148
  });
996
1149
  return { hash: withdrawalStatus.destinationTxHash };
@@ -1005,10 +1158,10 @@ var PoaBridge = class {
1005
1158
  if (cached != null) {
1006
1159
  return cached;
1007
1160
  }
1008
- const data = await import_internal_utils11.poaBridge.httpClient.getSupportedTokens(
1161
+ const data = await import_internal_utils14.poaBridge.httpClient.getSupportedTokens(
1009
1162
  { chains },
1010
1163
  {
1011
- baseURL: import_internal_utils11.configsByEnvironment[this.env].poaBridgeBaseURL,
1164
+ baseURL: import_internal_utils14.configsByEnvironment[this.env].poaBridgeBaseURL,
1012
1165
  logger
1013
1166
  }
1014
1167
  );
@@ -1030,7 +1183,7 @@ var PUBLIC_STELLAR_RPC_URLS = {
1030
1183
  };
1031
1184
 
1032
1185
  // src/intents/intent-executer-impl/intent-executer.ts
1033
- var import_internal_utils12 = require("@defuse-protocol/internal-utils");
1186
+ var import_internal_utils15 = require("@defuse-protocol/internal-utils");
1034
1187
 
1035
1188
  // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
1036
1189
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
@@ -1411,7 +1564,7 @@ var IntentExecuter = class {
1411
1564
  relayParams: relayParamsFactory,
1412
1565
  ...intentParams
1413
1566
  }) {
1414
- const verifyingContract = import_internal_utils12.configsByEnvironment[this.env].contractID;
1567
+ const verifyingContract = import_internal_utils15.configsByEnvironment[this.env].contractID;
1415
1568
  let intentPayload = defaultIntentPayloadFactory({
1416
1569
  verifying_contract: verifyingContract,
1417
1570
  ...intentParams
@@ -1461,7 +1614,7 @@ async function mergeIntentPayloads(basePayload, intentPayloadFactory) {
1461
1614
  }
1462
1615
 
1463
1616
  // src/intents/intent-relayer-impl/intent-relayer-public.ts
1464
- var import_internal_utils13 = require("@defuse-protocol/internal-utils");
1617
+ var import_internal_utils16 = require("@defuse-protocol/internal-utils");
1465
1618
  var IntentRelayerPublic = class {
1466
1619
  constructor({ env }) {
1467
1620
  this.env = env;
@@ -1483,13 +1636,13 @@ var IntentRelayerPublic = class {
1483
1636
  multiPayloads,
1484
1637
  quoteHashes
1485
1638
  }, ctx = {}) {
1486
- const a = await import_internal_utils13.solverRelay.publishIntents(
1639
+ const a = await import_internal_utils16.solverRelay.publishIntents(
1487
1640
  {
1488
1641
  quote_hashes: quoteHashes,
1489
1642
  signed_datas: multiPayloads
1490
1643
  },
1491
1644
  {
1492
- baseURL: import_internal_utils13.configsByEnvironment[this.env].solverRelayBaseURL,
1645
+ baseURL: import_internal_utils16.configsByEnvironment[this.env].solverRelayBaseURL,
1493
1646
  logger: ctx.logger
1494
1647
  }
1495
1648
  );
@@ -1499,10 +1652,10 @@ var IntentRelayerPublic = class {
1499
1652
  throw a.unwrapErr();
1500
1653
  }
1501
1654
  async waitForSettlement(ticket, ctx = {}) {
1502
- const result = await import_internal_utils13.solverRelay.waitForIntentSettlement({
1655
+ const result = await import_internal_utils16.solverRelay.waitForIntentSettlement({
1503
1656
  intentHash: ticket,
1504
1657
  signal: new AbortController().signal,
1505
- baseURL: import_internal_utils13.configsByEnvironment[this.env].solverRelayBaseURL,
1658
+ baseURL: import_internal_utils16.configsByEnvironment[this.env].solverRelayBaseURL,
1506
1659
  logger: ctx.logger
1507
1660
  });
1508
1661
  return {
@@ -1510,7 +1663,7 @@ var IntentRelayerPublic = class {
1510
1663
  hash: result.txHash,
1511
1664
  // Usually relayer's account id is the verifying contract (`intents.near`),
1512
1665
  // but it is not set in stone and may change in the future.
1513
- accountId: import_internal_utils13.configsByEnvironment[this.env].contractID
1666
+ accountId: import_internal_utils16.configsByEnvironment[this.env].contractID
1514
1667
  }
1515
1668
  };
1516
1669
  }
@@ -1524,14 +1677,14 @@ var noopIntentSigner = {
1524
1677
  };
1525
1678
 
1526
1679
  // src/lib/array.ts
1527
- var import_internal_utils14 = require("@defuse-protocol/internal-utils");
1680
+ var import_internal_utils17 = require("@defuse-protocol/internal-utils");
1528
1681
  function zip(arr1, arr2) {
1529
- (0, import_internal_utils14.assert)(arr1.length === arr2.length, "Arrays must have the same length");
1682
+ (0, import_internal_utils17.assert)(arr1.length === arr2.length, "Arrays must have the same length");
1530
1683
  return arr1.map((v, i) => [v, arr2[i]]);
1531
1684
  }
1532
1685
 
1533
1686
  // src/lib/configure-rpc-config.ts
1534
- var import_internal_utils15 = require("@defuse-protocol/internal-utils");
1687
+ var import_internal_utils18 = require("@defuse-protocol/internal-utils");
1535
1688
 
1536
1689
  // src/lib/object.ts
1537
1690
  function pick(obj, keys) {
@@ -1555,7 +1708,7 @@ function configureEvmRpcUrls(defaultRpcUrls, userRpcUrls, supportedChains) {
1555
1708
  ).map(([caip2, urls]) => [getEIP155ChainId(caip2), urls])
1556
1709
  );
1557
1710
  for (const [chainId, urls] of Object.entries(evmRpcUrls)) {
1558
- (0, import_internal_utils15.assert)(
1711
+ (0, import_internal_utils18.assert)(
1559
1712
  urls.length > 0,
1560
1713
  `EVM RPC URLs for chain ${chainId} are not provided`
1561
1714
  );
@@ -1569,7 +1722,7 @@ function configureStellarRpcUrls(defaultRpcUrls, userRpcUrls) {
1569
1722
  userRpcUrls?.[Chains.Stellar] ?? {}
1570
1723
  );
1571
1724
  for (const [key, value] of Object.entries(stellarRpcUrls)) {
1572
- (0, import_internal_utils15.assert)(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
1725
+ (0, import_internal_utils18.assert)(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
1573
1726
  }
1574
1727
  return stellarRpcUrls;
1575
1728
  }
@@ -1581,7 +1734,7 @@ function createInternalTransferRoute() {
1581
1734
  function createNearWithdrawalRoute(msg) {
1582
1735
  return { route: RouteEnum.NearWithdrawal, msg };
1583
1736
  }
1584
- function createOmniWithdrawalRoute() {
1737
+ function createOmniBridgeRoute() {
1585
1738
  return { route: RouteEnum.OmniBridge };
1586
1739
  }
1587
1740
  function createVirtualChainRoute(auroraEngineContractId, proxyTokenContractId) {
@@ -1615,17 +1768,11 @@ function determineRouteConfig(sdk, withdrawalParams) {
1615
1768
  const bridgeName = parseAssetId.bridgeName;
1616
1769
  switch (bridgeName) {
1617
1770
  case BridgeNameEnum.Hot:
1618
- return {
1619
- route: RouteEnum.HotBridge,
1620
- chain: parseAssetId.blockchain
1621
- };
1771
+ return createHotBridgeRoute(parseAssetId.blockchain);
1622
1772
  case BridgeNameEnum.Poa:
1623
- return {
1624
- route: RouteEnum.PoaBridge,
1625
- chain: parseAssetId.blockchain
1626
- };
1773
+ return createPoaBridgeRoute(parseAssetId.blockchain);
1627
1774
  case BridgeNameEnum.Omni:
1628
- return createOmniWithdrawalRoute();
1775
+ return createOmniBridgeRoute();
1629
1776
  case BridgeNameEnum.None:
1630
1777
  return createNearWithdrawalRoute();
1631
1778
  default:
@@ -1639,9 +1786,9 @@ var IntentsSDK = class {
1639
1786
  constructor(args) {
1640
1787
  this.env = args.env ?? "production";
1641
1788
  this.referral = args.referral;
1642
- const nearRpcUrls = args.rpc?.[Chains.Near] ?? import_internal_utils16.PUBLIC_NEAR_RPC_URLS;
1643
- (0, import_internal_utils16.assert)(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
1644
- const nearProvider = (0, import_internal_utils16.nearFailoverRpcProvider)({ urls: nearRpcUrls });
1789
+ const nearRpcUrls = args.rpc?.[Chains.Near] ?? import_internal_utils19.PUBLIC_NEAR_RPC_URLS;
1790
+ (0, import_internal_utils19.assert)(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
1791
+ const nearProvider = (0, import_internal_utils19.nearFailoverRpcProvider)({ urls: nearRpcUrls });
1645
1792
  const stellarRpcUrls = configureStellarRpcUrls(
1646
1793
  PUBLIC_STELLAR_RPC_URLS,
1647
1794
  args.rpc
@@ -1690,7 +1837,7 @@ var IntentsSDK = class {
1690
1837
  }
1691
1838
  async createWithdrawalIntents(args) {
1692
1839
  for (const bridge of this.bridges) {
1693
- if (bridge.supports(args.withdrawalParams)) {
1840
+ if (await bridge.supports(args.withdrawalParams)) {
1694
1841
  const actualAmount = args.withdrawalParams.feeInclusive ? args.withdrawalParams.amount - args.feeEstimation.amount : args.withdrawalParams.amount;
1695
1842
  await bridge.validateWithdrawal({
1696
1843
  assetId: args.withdrawalParams.assetId,
@@ -1732,7 +1879,7 @@ var IntentsSDK = class {
1732
1879
  }
1733
1880
  async _estimateWithdrawalFee(args) {
1734
1881
  for (const bridge of this.bridges) {
1735
- if (bridge.supports(args.withdrawalParams)) {
1882
+ if (await bridge.supports(args.withdrawalParams)) {
1736
1883
  const fee = await bridge.estimateWithdrawalFee({
1737
1884
  withdrawalParams: args.withdrawalParams,
1738
1885
  quoteOptions: args.quoteOptions,
@@ -1767,7 +1914,7 @@ var IntentsSDK = class {
1767
1914
  const routeConfig = determineRouteConfig(this, w);
1768
1915
  const route = routeConfig.route;
1769
1916
  const index = indexes.get(route);
1770
- (0, import_internal_utils16.assert)(index != null, "Index is not found for route");
1917
+ (0, import_internal_utils19.assert)(index != null, "Index is not found for route");
1771
1918
  indexes.set(route, index + 1);
1772
1919
  return {
1773
1920
  routeConfig,
@@ -1801,7 +1948,7 @@ var IntentsSDK = class {
1801
1948
  if (Array.isArray(args.withdrawalParams)) {
1802
1949
  return result;
1803
1950
  }
1804
- (0, import_internal_utils16.assert)(result.length === 1, "Unexpected result length");
1951
+ (0, import_internal_utils19.assert)(result.length === 1, "Unexpected result length");
1805
1952
  return result[0];
1806
1953
  }
1807
1954
  parseAssetId(assetId) {
@@ -1815,7 +1962,7 @@ var IntentsSDK = class {
1815
1962
  }
1816
1963
  async signAndSendIntent(args) {
1817
1964
  const intentSigner = args.signer ?? this.intentSigner;
1818
- (0, import_internal_utils16.assert)(intentSigner != null, "Intent signer is not provided");
1965
+ (0, import_internal_utils19.assert)(intentSigner != null, "Intent signer is not provided");
1819
1966
  const intentExecuter = new IntentExecuter({
1820
1967
  env: this.env,
1821
1968
  logger: args.logger,
@@ -1884,12 +2031,12 @@ var IntentsSDK = class {
1884
2031
  intentHash,
1885
2032
  logger
1886
2033
  }) {
1887
- return import_internal_utils16.solverRelay.getStatus(
2034
+ return import_internal_utils19.solverRelay.getStatus(
1888
2035
  {
1889
2036
  intent_hash: intentHash
1890
2037
  },
1891
2038
  {
1892
- baseURL: import_internal_utils16.configsByEnvironment[this.env].solverRelayBaseURL,
2039
+ baseURL: import_internal_utils19.configsByEnvironment[this.env].solverRelayBaseURL,
1893
2040
  logger
1894
2041
  }
1895
2042
  );
@@ -1920,7 +2067,7 @@ var IntentsSDK = class {
1920
2067
  withdrawalParams,
1921
2068
  intentTx,
1922
2069
  logger: args.logger,
1923
- retryOptions: import_internal_utils16.RETRY_CONFIGS.FIVE_MINS_STEADY
2070
+ retryOptions: import_internal_utils19.RETRY_CONFIGS.FIVE_MINS_STEADY
1924
2071
  });
1925
2072
  if (!Array.isArray(args.withdrawalParams)) {
1926
2073
  return {
@@ -1999,14 +2146,14 @@ var IntentSignerNearKeypair = class extends IntentSignerNEP413 {
1999
2146
  };
2000
2147
 
2001
2148
  // src/intents/intent-signer-impl/intent-signer-viem.ts
2002
- var import_internal_utils17 = require("@defuse-protocol/internal-utils");
2149
+ var import_internal_utils20 = require("@defuse-protocol/internal-utils");
2003
2150
  var IntentSignerViem = class {
2004
2151
  constructor(account) {
2005
2152
  this.account = account;
2006
2153
  }
2007
2154
  async signIntent(intent) {
2008
2155
  const payload = JSON.stringify({
2009
- signer_id: intent.signer_id ?? import_internal_utils17.utils.authHandleToIntentsUserId({
2156
+ signer_id: intent.signer_id ?? import_internal_utils20.utils.authHandleToIntentsUserId({
2010
2157
  identifier: this.account.address,
2011
2158
  method: "evm"
2012
2159
  }),
@@ -2024,7 +2171,7 @@ var IntentSignerViem = class {
2024
2171
  return {
2025
2172
  standard: "erc191",
2026
2173
  payload,
2027
- signature: import_internal_utils17.utils.transformERC191Signature(signature)
2174
+ signature: import_internal_utils20.utils.transformERC191Signature(signature)
2028
2175
  };
2029
2176
  }
2030
2177
  };
@@ -2041,11 +2188,11 @@ function createIntentSignerViem(config) {
2041
2188
  }
2042
2189
 
2043
2190
  // index.ts
2044
- var import_internal_utils19 = require("@defuse-protocol/internal-utils");
2191
+ var import_internal_utils22 = require("@defuse-protocol/internal-utils");
2045
2192
 
2046
2193
  // src/bridges/omni-bridge/error.ts
2047
- var import_internal_utils18 = require("@defuse-protocol/internal-utils");
2048
- var OmniTransferNotFoundError = class extends import_internal_utils18.BaseError {
2194
+ var import_internal_utils21 = require("@defuse-protocol/internal-utils");
2195
+ var OmniTransferNotFoundError = class extends import_internal_utils21.BaseError {
2049
2196
  constructor(txHash) {
2050
2197
  super("Omni transfer with given hash is not found in the relayer.", {
2051
2198
  metaMessages: [`OriginTxHash: ${txHash}`],
@@ -2054,7 +2201,7 @@ var OmniTransferNotFoundError = class extends import_internal_utils18.BaseError
2054
2201
  this.txHash = txHash;
2055
2202
  }
2056
2203
  };
2057
- var OmniTransferDestinationChainHashNotFoundError = class extends import_internal_utils18.BaseError {
2204
+ var OmniTransferDestinationChainHashNotFoundError = class extends import_internal_utils21.BaseError {
2058
2205
  constructor(txHash, destinationChain) {
2059
2206
  super("Relayer did not return destination chain hash for a transfer.", {
2060
2207
  metaMessages: [
@@ -2067,7 +2214,7 @@ var OmniTransferDestinationChainHashNotFoundError = class extends import_interna
2067
2214
  this.destinationChain = destinationChain;
2068
2215
  }
2069
2216
  };
2070
- var TokenNotSupportedByOmniRelayerError = class extends import_internal_utils18.BaseError {
2217
+ var TokenNotSupportedByOmniRelayerError = class extends import_internal_utils21.BaseError {
2071
2218
  constructor(token) {
2072
2219
  super(`Omni Relayer doesn't accept fee in the transferred token ${token}`, {
2073
2220
  metaMessages: [`Token: ${token}`],
@@ -2076,7 +2223,7 @@ var TokenNotSupportedByOmniRelayerError = class extends import_internal_utils18.
2076
2223
  this.token = token;
2077
2224
  }
2078
2225
  };
2079
- var TokenNotFoundInDestinationChainError = class extends import_internal_utils18.BaseError {
2226
+ var TokenNotFoundInDestinationChainError = class extends import_internal_utils21.BaseError {
2080
2227
  constructor(token, chainKind) {
2081
2228
  super(
2082
2229
  `The token ${token} doesn't exist in destination network ${chainKind}`,
@@ -2090,10 +2237,10 @@ var TokenNotFoundInDestinationChainError = class extends import_internal_utils18
2090
2237
  };
2091
2238
 
2092
2239
  // index.ts
2093
- var import_internal_utils20 = require("@defuse-protocol/internal-utils");
2094
- var import_internal_utils21 = require("@defuse-protocol/internal-utils");
2095
- var import_internal_utils22 = require("@defuse-protocol/internal-utils");
2096
2240
  var import_internal_utils23 = require("@defuse-protocol/internal-utils");
2241
+ var import_internal_utils24 = require("@defuse-protocol/internal-utils");
2242
+ var import_internal_utils25 = require("@defuse-protocol/internal-utils");
2243
+ var import_internal_utils26 = require("@defuse-protocol/internal-utils");
2097
2244
  // Annotate the CommonJS export names for ESM import in node:
2098
2245
  0 && (module.exports = {
2099
2246
  AssertionError,
@@ -2121,6 +2268,7 @@ var import_internal_utils23 = require("@defuse-protocol/internal-utils");
2121
2268
  TokenNotFoundInDestinationChainError,
2122
2269
  TokenNotSupportedByOmniRelayerError,
2123
2270
  TrustlineNotFoundError,
2271
+ UnsupportedAssetIdError,
2124
2272
  UnsupportedDestinationMemoError,
2125
2273
  createDefaultRoute,
2126
2274
  createHotBridgeRoute,
@@ -2129,7 +2277,7 @@ var import_internal_utils23 = require("@defuse-protocol/internal-utils");
2129
2277
  createIntentSignerViem,
2130
2278
  createInternalTransferRoute,
2131
2279
  createNearWithdrawalRoute,
2132
- createOmniWithdrawalRoute,
2280
+ createOmniBridgeRoute,
2133
2281
  createPoaBridgeRoute,
2134
2282
  createVirtualChainRoute
2135
2283
  });