@defuse-protocol/intents-sdk 0.43.3 → 0.45.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.
Files changed (94) hide show
  1. package/README.md +143 -21
  2. package/dist/index.cjs +19 -18
  3. package/dist/index.d.cts +5 -3
  4. package/dist/index.d.ts +5 -3
  5. package/dist/index.js +7 -5
  6. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge-utils.cjs +5 -5
  7. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.cjs +24 -12
  8. package/dist/src/bridges/aurora-engine-bridge/aurora-engine-bridge.js +19 -7
  9. package/dist/src/bridges/direct-bridge/direct-bridge-utils.cjs +5 -5
  10. package/dist/src/bridges/direct-bridge/direct-bridge.cjs +22 -10
  11. package/dist/src/bridges/direct-bridge/direct-bridge.js +16 -4
  12. package/dist/src/bridges/direct-bridge/error.cjs +2 -2
  13. package/dist/src/bridges/hot-bridge/error.cjs +4 -26
  14. package/dist/src/bridges/hot-bridge/error.d.cts +1 -17
  15. package/dist/src/bridges/hot-bridge/error.d.ts +1 -17
  16. package/dist/src/bridges/hot-bridge/error.js +1 -21
  17. package/dist/src/bridges/hot-bridge/hot-bridge-chains.cjs +3 -1
  18. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.cts +1 -1
  19. package/dist/src/bridges/hot-bridge/hot-bridge-chains.d.ts +1 -1
  20. package/dist/src/bridges/hot-bridge/hot-bridge-chains.js +3 -1
  21. package/dist/src/bridges/hot-bridge/hot-bridge-utils.cjs +17 -12
  22. package/dist/src/bridges/hot-bridge/hot-bridge-utils.js +7 -2
  23. package/dist/src/bridges/hot-bridge/hot-bridge.cjs +46 -32
  24. package/dist/src/bridges/hot-bridge/hot-bridge.js +38 -24
  25. package/dist/src/bridges/intents-bridge/intents-bridge.cjs +18 -4
  26. package/dist/src/bridges/intents-bridge/intents-bridge.js +18 -4
  27. package/dist/src/bridges/omni-bridge/error.cjs +6 -27
  28. package/dist/src/bridges/omni-bridge/error.d.cts +1 -16
  29. package/dist/src/bridges/omni-bridge/error.d.ts +1 -16
  30. package/dist/src/bridges/omni-bridge/error.js +1 -20
  31. package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +12 -7
  32. package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +5 -1
  33. package/dist/src/bridges/omni-bridge/omni-bridge.cjs +72 -54
  34. package/dist/src/bridges/omni-bridge/omni-bridge.js +47 -29
  35. package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +2 -2
  36. package/dist/src/bridges/poa-bridge/poa-bridge.cjs +79 -26
  37. package/dist/src/bridges/poa-bridge/poa-bridge.js +66 -13
  38. package/dist/src/classes/errors.cjs +7 -7
  39. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
  40. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
  41. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
  42. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
  43. package/dist/src/constants/public-rpc-urls.cjs +3 -1
  44. package/dist/src/constants/public-rpc-urls.js +3 -1
  45. package/dist/src/constants/withdrawal-timing.cjs +57 -0
  46. package/dist/src/constants/withdrawal-timing.js +56 -0
  47. package/dist/src/core/withdrawal-watcher.cjs +83 -0
  48. package/dist/src/core/withdrawal-watcher.d.cts +18 -0
  49. package/dist/src/core/withdrawal-watcher.d.ts +18 -0
  50. package/dist/src/core/withdrawal-watcher.js +79 -0
  51. package/dist/src/intents/expirable-nonce.cjs +3 -3
  52. package/dist/src/intents/intent-executer-impl/intent-executer.cjs +7 -4
  53. package/dist/src/intents/intent-executer-impl/intent-executer.js +5 -2
  54. package/dist/src/intents/intent-hash.cjs +2 -2
  55. package/dist/src/intents/intent-hashes/erc191.cjs +2 -2
  56. package/dist/src/intents/intent-hashes/nep413.cjs +2 -2
  57. package/dist/src/intents/intent-hashes/raw-ed25519.cjs +2 -2
  58. package/dist/src/intents/intent-hashes/sep53.cjs +4 -4
  59. package/dist/src/intents/intent-hashes/tip191.cjs +2 -2
  60. package/dist/src/intents/intent-hashes/ton-connect.cjs +2 -2
  61. package/dist/src/intents/intent-hashes/webauthn.cjs +2 -2
  62. package/dist/src/intents/intent-payload-builder.cjs +4 -4
  63. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +7 -7
  64. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +1 -1
  65. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +2 -2
  66. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +3 -3
  67. package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +3 -3
  68. package/dist/src/intents/interfaces/intent-relayer.d.cts +2 -1
  69. package/dist/src/intents/interfaces/intent-relayer.d.ts +2 -1
  70. package/dist/src/intents/salt-manager.cjs +5 -5
  71. package/dist/src/lib/array.cjs +2 -2
  72. package/dist/src/lib/caip2.cjs +7 -5
  73. package/dist/src/lib/caip2.d.cts +2 -0
  74. package/dist/src/lib/caip2.d.ts +2 -0
  75. package/dist/src/lib/caip2.js +3 -1
  76. package/dist/src/lib/configure-rpc-config.cjs +3 -3
  77. package/dist/src/lib/estimate-fee.cjs +6 -6
  78. package/dist/src/lib/parse-defuse-asset-id.cjs +2 -2
  79. package/dist/src/lib/route-config-factory.cjs +2 -5
  80. package/dist/src/lib/route-config-factory.d.cts +1 -1
  81. package/dist/src/lib/route-config-factory.d.ts +1 -1
  82. package/dist/src/lib/route-config-factory.js +2 -5
  83. package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +3 -3
  84. package/dist/src/lib/validateAddress.cjs +21 -19
  85. package/dist/src/lib/validateAddress.js +3 -1
  86. package/dist/src/sdk.cjs +96 -47
  87. package/dist/src/sdk.d.cts +72 -11
  88. package/dist/src/sdk.d.ts +72 -11
  89. package/dist/src/sdk.js +85 -36
  90. package/dist/src/shared-types.d.cts +49 -15
  91. package/dist/src/shared-types.d.ts +49 -15
  92. package/package.json +3 -5
  93. package/dist/src/lib/route-config.cjs +0 -19
  94. package/dist/src/lib/route-config.js +0 -19
@@ -1,10 +1,10 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const require_caip2 = require('./caip2.cjs');
3
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
3
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
4
4
  let viem = require("viem");
5
- let __noble_hashes_sha2 = require("@noble/hashes/sha2");
6
- let __scure_base = require("@scure/base");
7
- let __solana_web3_js = require("@solana/web3.js");
5
+ let _noble_hashes_sha2 = require("@noble/hashes/sha2");
6
+ let _scure_base = require("@scure/base");
7
+ let _solana_web3_js = require("@solana/web3.js");
8
8
  let ripple_address_codec = require("ripple-address-codec");
9
9
 
10
10
  //#region src/lib/validateAddress.ts
@@ -17,7 +17,7 @@ let ripple_address_codec = require("ripple-address-codec");
17
17
  */
18
18
  function validateAddress(address, blockchain) {
19
19
  switch (blockchain) {
20
- case require_caip2.Chains.Near: return __defuse_protocol_internal_utils.utils.validateNearAddress(address);
20
+ case require_caip2.Chains.Near: return _defuse_protocol_internal_utils.utils.validateNearAddress(address);
21
21
  case require_caip2.Chains.Bitcoin: return validateBtcAddress(address);
22
22
  case require_caip2.Chains.BitcoinCash: return validateBchAddress(address);
23
23
  case require_caip2.Chains.Solana: return validateSolAddress(address);
@@ -43,7 +43,9 @@ function validateAddress(address, blockchain) {
43
43
  case require_caip2.Chains.Base:
44
44
  case require_caip2.Chains.Arbitrum:
45
45
  case require_caip2.Chains.Avalanche:
46
- case require_caip2.Chains.Berachain: return validateEthAddress(address);
46
+ case require_caip2.Chains.Berachain:
47
+ case require_caip2.Chains.Plasma:
48
+ case require_caip2.Chains.Scroll: return validateEthAddress(address);
47
49
  default: return false;
48
50
  }
49
51
  }
@@ -111,7 +113,7 @@ function verifyBchChecksum(address) {
111
113
  }
112
114
  function validateSolAddress(address) {
113
115
  try {
114
- return __solana_web3_js.PublicKey.isOnCurve(address);
116
+ return _solana_web3_js.PublicKey.isOnCurve(address);
115
117
  } catch {
116
118
  return false;
117
119
  }
@@ -132,7 +134,7 @@ function validateZcashAddress(address) {
132
134
  if (address.startsWith("t1") || address.startsWith("t3")) return /^t[13][a-km-zA-HJ-NP-Z1-9]{33}$/.test(address);
133
135
  const expectedHrp = "tex";
134
136
  if (address.startsWith(`${expectedHrp}1`)) try {
135
- const decoded = __scure_base.bech32m.decodeToBytes(address);
137
+ const decoded = _scure_base.bech32m.decodeToBytes(address);
136
138
  if (decoded.prefix !== expectedHrp) return false;
137
139
  return decoded.bytes.length === 20;
138
140
  } catch {
@@ -140,7 +142,7 @@ function validateZcashAddress(address) {
140
142
  }
141
143
  const uaHrp = "u";
142
144
  if (address.startsWith(`${uaHrp}1`)) try {
143
- return __scure_base.bech32m.decodeToBytes(address).prefix === uaHrp;
145
+ return _scure_base.bech32m.decodeToBytes(address).prefix === uaHrp;
144
146
  } catch {
145
147
  return false;
146
148
  }
@@ -158,11 +160,11 @@ function validateTronAddress(address) {
158
160
  }
159
161
  function validateTronBase58Address(address) {
160
162
  try {
161
- const decoded = __scure_base.base58.decode(address);
163
+ const decoded = _scure_base.base58.decode(address);
162
164
  if (decoded.length !== 25) return false;
163
165
  const data = decoded.slice(0, 21);
164
166
  const checksum = decoded.slice(21);
165
- const expectedChecksum = (0, __noble_hashes_sha2.sha256)((0, __noble_hashes_sha2.sha256)(data)).slice(0, 4);
167
+ const expectedChecksum = (0, _noble_hashes_sha2.sha256)((0, _noble_hashes_sha2.sha256)(data)).slice(0, 4);
166
168
  for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return false;
167
169
  return data[0] === 65;
168
170
  } catch {
@@ -171,7 +173,7 @@ function validateTronBase58Address(address) {
171
173
  }
172
174
  function validateTronHexAddress(address) {
173
175
  try {
174
- const decoded = __scure_base.hex.decode(address);
176
+ const decoded = _scure_base.hex.decode(address);
175
177
  return decoded.length === 21 && decoded[0] === 65;
176
178
  } catch {
177
179
  return false;
@@ -195,9 +197,9 @@ function validateAptosAddress(address) {
195
197
  */
196
198
  function validateCardanoAddress(address) {
197
199
  try {
198
- const { prefix, words } = __scure_base.bech32.decode(address, 120);
200
+ const { prefix, words } = _scure_base.bech32.decode(address, 120);
199
201
  if (prefix !== "addr") return false;
200
- const addrType = __scure_base.bech32.fromWords(words)[0] >> 4;
202
+ const addrType = _scure_base.bech32.fromWords(words)[0] >> 4;
201
203
  return addrType >= 0 && addrType <= 7;
202
204
  } catch {
203
205
  return false;
@@ -222,7 +224,7 @@ function validateLitecoinAddress(address) {
222
224
  function validateLitecoinBase58Address(address, expectedVersion) {
223
225
  let decoded;
224
226
  try {
225
- decoded = __scure_base.base58.decode(address);
227
+ decoded = _scure_base.base58.decode(address);
226
228
  } catch {
227
229
  return false;
228
230
  }
@@ -230,7 +232,7 @@ function validateLitecoinBase58Address(address, expectedVersion) {
230
232
  if (decoded[0] !== expectedVersion) return false;
231
233
  const payload = decoded.subarray(0, 21);
232
234
  const checksum = decoded.subarray(21, 25);
233
- const expectedChecksum = (0, __noble_hashes_sha2.sha256)((0, __noble_hashes_sha2.sha256)(payload)).subarray(0, 4);
235
+ const expectedChecksum = (0, _noble_hashes_sha2.sha256)((0, _noble_hashes_sha2.sha256)(payload)).subarray(0, 4);
234
236
  for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return false;
235
237
  return true;
236
238
  }
@@ -238,10 +240,10 @@ function validateLitecoinBech32Address(address) {
238
240
  let decoded;
239
241
  let isBech32m = false;
240
242
  try {
241
- decoded = __scure_base.bech32.decode(address);
243
+ decoded = _scure_base.bech32.decode(address);
242
244
  } catch {
243
245
  try {
244
- decoded = __scure_base.bech32m.decode(address);
246
+ decoded = _scure_base.bech32m.decode(address);
245
247
  isBech32m = true;
246
248
  } catch {
247
249
  return false;
@@ -252,7 +254,7 @@ function validateLitecoinBech32Address(address) {
252
254
  if (!words || words.length < 1) return false;
253
255
  const version = words[0];
254
256
  if (version == null || version < 0 || version > 16) return false;
255
- const progLen = __scure_base.bech32.fromWords(words.slice(1)).length;
257
+ const progLen = _scure_base.bech32.fromWords(words.slice(1)).length;
256
258
  if (progLen < 2 || progLen > 40) return false;
257
259
  if (version === 0) {
258
260
  if (isBech32m) return false;
@@ -42,7 +42,9 @@ function validateAddress(address, blockchain) {
42
42
  case Chains.Base:
43
43
  case Chains.Arbitrum:
44
44
  case Chains.Avalanche:
45
- case Chains.Berachain: return validateEthAddress(address);
45
+ case Chains.Berachain:
46
+ case Chains.Plasma:
47
+ case Chains.Scroll: return validateEthAddress(address);
46
48
  default: return false;
47
49
  }
48
50
  }
package/dist/src/sdk.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  const require_errors = require('./classes/errors.cjs');
3
+ const require_route_enum = require('./constants/route-enum.cjs');
3
4
  const require_caip2 = require('./lib/caip2.cjs');
4
5
  const require_aurora_engine_bridge = require('./bridges/aurora-engine-bridge/aurora-engine-bridge.cjs');
5
6
  const require_direct_bridge = require('./bridges/direct-bridge/direct-bridge.cjs');
@@ -16,11 +17,11 @@ const require_intent_relayer_public = require('./intents/intent-relayer-impl/int
16
17
  const require_intent_signer_noop = require('./intents/intent-signer-impl/intent-signer-noop.cjs');
17
18
  const require_array = require('./lib/array.cjs');
18
19
  const require_configure_rpc_config = require('./lib/configure-rpc-config.cjs');
19
- const require_route_config = require('./lib/route-config.cjs');
20
+ const require_withdrawal_watcher = require('./core/withdrawal-watcher.cjs');
20
21
  const require_salt_manager = require('./intents/salt-manager.cjs');
21
22
  const require_intent_payload_builder = require('./intents/intent-payload-builder.cjs');
22
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
23
- let __hot_labs_omni_sdk = require("@hot-labs/omni-sdk");
23
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
24
+ let _hot_labs_omni_sdk = require("@hot-labs/omni-sdk");
24
25
  let viem = require("viem");
25
26
  let valibot = require("valibot");
26
27
  valibot = require_rolldown_runtime.__toESM(valibot);
@@ -31,9 +32,9 @@ var IntentsSDK = class {
31
32
  this.env = args.env ?? "production";
32
33
  this.referral = args.referral;
33
34
  this.solverRelayApiKey = args.solverRelayApiKey;
34
- const nearRpcUrls = args.rpc?.[require_caip2.Chains.Near] ?? __defuse_protocol_internal_utils.PUBLIC_NEAR_RPC_URLS;
35
- (0, __defuse_protocol_internal_utils.assert)(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
36
- const nearProvider = (0, __defuse_protocol_internal_utils.nearFailoverRpcProvider)({ urls: nearRpcUrls });
35
+ const nearRpcUrls = args.rpc?.[require_caip2.Chains.Near] ?? _defuse_protocol_internal_utils.PUBLIC_NEAR_RPC_URLS;
36
+ (0, _defuse_protocol_internal_utils.assert)(nearRpcUrls.length > 0, "NEAR RPC URLs are not provided");
37
+ const nearProvider = (0, _defuse_protocol_internal_utils.nearFailoverRpcProvider)({ urls: nearRpcUrls });
37
38
  const stellarRpcUrls = require_configure_rpc_config.configureStellarRpcUrls(require_public_rpc_urls.PUBLIC_STELLAR_RPC_URLS, args.rpc);
38
39
  const evmRpcUrls = require_configure_rpc_config.configureEvmRpcUrls(require_public_rpc_urls.PUBLIC_EVM_RPC_URLS, args.rpc, require_hot_bridge_chains.HotBridgeEVMChains);
39
40
  /**
@@ -47,11 +48,14 @@ var IntentsSDK = class {
47
48
  nearProvider,
48
49
  solverRelayApiKey: this.solverRelayApiKey
49
50
  }),
50
- new require_poa_bridge.PoaBridge({ env: this.env }),
51
+ new require_poa_bridge.PoaBridge({
52
+ env: this.env,
53
+ routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
54
+ }),
51
55
  new require_hot_bridge.HotBridge({
52
56
  env: this.env,
53
57
  solverRelayApiKey: this.solverRelayApiKey,
54
- hotSdk: new __hot_labs_omni_sdk.HotBridge({
58
+ hotSdk: new _hot_labs_omni_sdk.HotBridge({
55
59
  logger: console,
56
60
  evmRpc: evmRpcUrls,
57
61
  nearRpc: nearRpcUrls,
@@ -65,7 +69,8 @@ var IntentsSDK = class {
65
69
  new require_omni_bridge.OmniBridge({
66
70
  env: this.env,
67
71
  nearProvider,
68
- solverRelayApiKey: this.solverRelayApiKey
72
+ solverRelayApiKey: this.solverRelayApiKey,
73
+ routeMigratedPoaTokensThroughOmniBridge: args.features?.routeMigratedPoaTokensThroughOmniBridge
69
74
  }),
70
75
  new require_direct_bridge.DirectBridge({
71
76
  env: this.env,
@@ -140,7 +145,7 @@ var IntentsSDK = class {
140
145
  async invalidateNonces(args) {
141
146
  if (args.nonces.length === 0) return;
142
147
  const intentSigner = args.signer ?? this.intentSigner;
143
- (0, __defuse_protocol_internal_utils.assert)(intentSigner != null, "Intent signer is not provided");
148
+ (0, _defuse_protocol_internal_utils.assert)(intentSigner != null, "Intent signer is not provided");
144
149
  const signedIntents = await Promise.all(args.nonces.map(async (nonce) => {
145
150
  const builder = this.intentBuilder().setNonce(nonce);
146
151
  try {
@@ -207,42 +212,87 @@ var IntentsSDK = class {
207
212
  }
208
213
  throw new Error(`Cannot determine bridge for withdrawal = ${(0, viem.stringify)(args.withdrawalParams)}`);
209
214
  }
210
- getWithdrawalsIdentifiers({ withdrawalParams, intentTx }) {
211
- const indexes = /* @__PURE__ */ new Map();
212
- return withdrawalParams.map((w) => {
213
- const routeConfig = require_route_config.determineRouteConfig(this, w);
214
- const route = routeConfig.route;
215
- const currentIndex = indexes.get(route) ?? 0;
216
- indexes.set(route, currentIndex + 1);
217
- return {
218
- routeConfig,
219
- index: currentIndex,
220
- withdrawalParams: w,
221
- tx: intentTx
222
- };
223
- });
224
- }
225
215
  async waitForWithdrawalCompletion(args) {
226
- const wids = this.getWithdrawalsIdentifiers({
227
- withdrawalParams: Array.isArray(args.withdrawalParams) ? args.withdrawalParams : [args.withdrawalParams],
228
- intentTx: args.intentTx
216
+ const withdrawalParamsArray = Array.isArray(args.withdrawalParams) ? args.withdrawalParams : [args.withdrawalParams];
217
+ const promises = this.createWithdrawalCompletionPromises({
218
+ withdrawalParams: withdrawalParamsArray,
219
+ intentTx: args.intentTx,
220
+ signal: args.signal,
221
+ logger: args.logger
229
222
  });
230
- const result = await Promise.all(wids.map((wid) => {
231
- for (const bridge of this.bridges) if (bridge.is(wid.routeConfig)) return bridge.waitForWithdrawalCompletion({
232
- tx: args.intentTx,
233
- index: wid.index,
234
- withdrawalParams: wid.withdrawalParams,
235
- routeConfig: wid.routeConfig,
236
- signal: args.signal,
237
- retryOptions: args.retryOptions,
238
- logger: args.logger
239
- });
240
- throw new Error(`Unsupported route = ${(0, viem.stringify)(wid.routeConfig)}`);
241
- }));
223
+ const result = await Promise.all(promises);
242
224
  if (Array.isArray(args.withdrawalParams)) return result;
243
- (0, __defuse_protocol_internal_utils.assert)(result.length === 1, "Unexpected result length");
225
+ (0, _defuse_protocol_internal_utils.assert)(result.length === 1, "Unexpected result length");
244
226
  return result[0];
245
227
  }
228
+ /**
229
+ * Create promises that resolve when each withdrawal completes on the destination chain.
230
+ * Use this for granular control over handling individual withdrawals as they complete,
231
+ * rather than waiting for all to finish.
232
+ *
233
+ * **Important:** Each promise waits until the withdrawal completes, fails, or the
234
+ * chain-specific p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a
235
+ * shorter timeout budget.
236
+ *
237
+ * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
238
+ * Inspect `error.cause` to determine the reason.
239
+ * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
240
+ * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
241
+ *
242
+ * @param params.withdrawalParams - Array of withdrawal parameters
243
+ * @param params.intentTx - The NEAR transaction info from the published intent
244
+ * @param params.signal - Optional AbortSignal for cancellation/timeout
245
+ * @param params.logger - Optional logger for debugging
246
+ * @returns Array of promises, one per withdrawal, that resolve with transaction info
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * const promises = sdk.createWithdrawalCompletionPromises({
251
+ * withdrawalParams: [withdrawal1, withdrawal2],
252
+ * intentTx,
253
+ * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
254
+ * });
255
+ *
256
+ * // Handle each withdrawal as it completes
257
+ * for (const promise of promises) {
258
+ * promise.then((result) => console.log('Withdrawal completed:', result));
259
+ * }
260
+ * ```
261
+ */
262
+ createWithdrawalCompletionPromises(params) {
263
+ const { withdrawalParams, intentTx, signal, logger } = params;
264
+ const widsPromise = require_withdrawal_watcher.createWithdrawalIdentifiers({
265
+ bridges: this.bridges,
266
+ withdrawalParams,
267
+ intentTx
268
+ });
269
+ const hotChainLastPromise = /* @__PURE__ */ new Map();
270
+ return withdrawalParams.map(async (_, index) => {
271
+ const entry = (await widsPromise)[index];
272
+ (0, _defuse_protocol_internal_utils.assert)(entry != null, `Missing wid for index ${index}`);
273
+ if (entry.bridge.route === require_route_enum.RouteEnum.HotBridge) {
274
+ const landingChain = entry.wid.landingChain;
275
+ const previousPromise = hotChainLastPromise.get(landingChain);
276
+ const sequentialPromise = (async () => {
277
+ if (previousPromise) await Promise.allSettled([previousPromise]);
278
+ return require_withdrawal_watcher.watchWithdrawal({
279
+ bridge: entry.bridge,
280
+ wid: entry.wid,
281
+ signal,
282
+ logger
283
+ });
284
+ })();
285
+ hotChainLastPromise.set(landingChain, sequentialPromise);
286
+ return sequentialPromise;
287
+ }
288
+ return require_withdrawal_watcher.watchWithdrawal({
289
+ bridge: entry.bridge,
290
+ wid: entry.wid,
291
+ signal,
292
+ logger
293
+ });
294
+ });
295
+ }
246
296
  parseAssetId(assetId) {
247
297
  for (const bridge of this.bridges) {
248
298
  const parsed = bridge.parseAssetId(assetId);
@@ -252,7 +302,7 @@ var IntentsSDK = class {
252
302
  }
253
303
  async signAndSendIntent(args) {
254
304
  const intentSigner = args.signer ?? this.intentSigner;
255
- (0, __defuse_protocol_internal_utils.assert)(intentSigner != null, "Intent signer is not provided");
305
+ (0, _defuse_protocol_internal_utils.assert)(intentSigner != null, "Intent signer is not provided");
256
306
  const intentExecuter = new require_intent_executer.IntentExecuter({
257
307
  env: this.env,
258
308
  logger: args.logger,
@@ -273,7 +323,7 @@ var IntentsSDK = class {
273
323
  try {
274
324
  return await fn(await this.saltManager.getCachedSalt());
275
325
  } catch (err) {
276
- if (!(err instanceof __defuse_protocol_internal_utils.RelayPublishError && err.code === "INVALID_SALT")) throw err;
326
+ if (!(err instanceof _defuse_protocol_internal_utils.RelayPublishError && err.code === "INVALID_SALT")) throw err;
277
327
  args.logger?.warn?.("Salt error detected. Refreshing salt and retrying");
278
328
  return fn(await this.saltManager.refresh());
279
329
  }
@@ -322,12 +372,12 @@ var IntentsSDK = class {
322
372
  logger: args.logger,
323
373
  intentSigner: require_intent_signer_noop.noopIntentSigner,
324
374
  intentRelayer: this.intentRelayer
325
- }).waitForSettlement(args.intentHash);
375
+ }).waitForSettlement(args.intentHash, { signal: args.signal });
326
376
  return tx;
327
377
  }
328
378
  async getIntentStatus({ intentHash, logger }) {
329
- return __defuse_protocol_internal_utils.solverRelay.getStatus({ intent_hash: intentHash }, {
330
- baseURL: __defuse_protocol_internal_utils.configsByEnvironment[this.env].solverRelayBaseURL,
379
+ return _defuse_protocol_internal_utils.solverRelay.getStatus({ intent_hash: intentHash }, {
380
+ baseURL: _defuse_protocol_internal_utils.configsByEnvironment[this.env].solverRelayBaseURL,
331
381
  logger,
332
382
  solverRelayApiKey: this.solverRelayApiKey
333
383
  });
@@ -355,7 +405,6 @@ var IntentsSDK = class {
355
405
  const destinationTx = await this.waitForWithdrawalCompletion({
356
406
  withdrawalParams,
357
407
  intentTx,
358
- retryOptions: args.retryOptions ?? __defuse_protocol_internal_utils.RETRY_CONFIGS.FIVE_MINS_STEADY,
359
408
  logger: args.logger
360
409
  });
361
410
  if (!Array.isArray(args.withdrawalParams)) return {
@@ -1,10 +1,10 @@
1
1
  import { IntentHash, IntentPrimitive } from "./intents/shared-types.cjs";
2
2
  import { IIntentSigner } from "./intents/interfaces/intent-signer.cjs";
3
- import { BatchWithdrawalResult, Bridge, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./shared-types.cjs";
3
+ import { BatchWithdrawalResult, Bridge, CreateWithdrawalCompletionPromisesParams, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalParams, WithdrawalResult } from "./shared-types.cjs";
4
4
  import { IIntentRelayer } from "./intents/interfaces/intent-relayer.cjs";
5
5
  import { ISaltManager } from "./intents/interfaces/salt-manager.cjs";
6
6
  import { IntentPayloadBuilder } from "./intents/intent-payload-builder.cjs";
7
- import { ILogger, NearIntentsEnv, RetryOptions } from "@defuse-protocol/internal-utils";
7
+ import { ILogger, NearIntentsEnv } from "@defuse-protocol/internal-utils";
8
8
 
9
9
  //#region src/sdk.d.ts
10
10
  interface IntentsSDKConfig {
@@ -13,6 +13,13 @@ interface IntentsSDKConfig {
13
13
  rpc?: PartialRPCEndpointMap;
14
14
  referral: string;
15
15
  solverRelayApiKey?: string;
16
+ features?: {
17
+ /**
18
+ * Route migrated POA tokens (*.omft.near) through Omni Bridge.
19
+ * Enable this to use Omni Bridge for POA tokens that have been migrated to the Omni infrastructure.
20
+ */
21
+ routeMigratedPoaTokensThroughOmniBridge?: boolean;
22
+ };
16
23
  }
17
24
  declare class IntentsSDK implements IIntentsSDK {
18
25
  protected env: NearIntentsEnv;
@@ -96,33 +103,87 @@ declare class IntentsSDK implements IIntentsSDK {
96
103
  quoteOptions?: QuoteOptions;
97
104
  logger?: ILogger;
98
105
  }): Promise<FeeEstimation>;
99
- protected getWithdrawalsIdentifiers({
100
- withdrawalParams,
101
- intentTx
102
- }: {
103
- withdrawalParams: WithdrawalParams[];
104
- intentTx: NearTxInfo;
105
- }): WithdrawalIdentifier[];
106
+ /**
107
+ * Wait for withdrawal(s) to complete on the destination chain.
108
+ *
109
+ * **Important:** Waits until the withdrawal completes, fails, or the chain-specific
110
+ * p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a shorter timeout budget.
111
+ *
112
+ * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
113
+ * Inspect `error.cause` to determine the reason.
114
+ * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
115
+ * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
116
+ *
117
+ * @param args.withdrawalParams - Single withdrawal or array of withdrawals
118
+ * @param args.intentTx - The NEAR transaction info from the published intent
119
+ * @param args.signal - Optional AbortSignal for cancellation/timeout
120
+ * @param args.logger - Optional logger for debugging
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * // With timeout
125
+ * const result = await sdk.waitForWithdrawalCompletion({
126
+ * withdrawalParams,
127
+ * intentTx,
128
+ * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
129
+ * });
130
+ * ```
131
+ */
106
132
  waitForWithdrawalCompletion(args: {
107
133
  withdrawalParams: WithdrawalParams;
108
134
  intentTx: NearTxInfo;
109
135
  signal?: AbortSignal;
110
- retryOptions?: RetryOptions;
111
136
  logger?: ILogger;
112
137
  }): Promise<TxInfo | TxNoInfo>;
113
138
  waitForWithdrawalCompletion(args: {
114
139
  withdrawalParams: WithdrawalParams[];
115
140
  intentTx: NearTxInfo;
116
141
  signal?: AbortSignal;
117
- retryOptions?: RetryOptions;
118
142
  logger?: ILogger;
119
143
  }): Promise<Array<TxInfo | TxNoInfo>>;
144
+ /**
145
+ * Create promises that resolve when each withdrawal completes on the destination chain.
146
+ * Use this for granular control over handling individual withdrawals as they complete,
147
+ * rather than waiting for all to finish.
148
+ *
149
+ * **Important:** Each promise waits until the withdrawal completes, fails, or the
150
+ * chain-specific p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a
151
+ * shorter timeout budget.
152
+ *
153
+ * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
154
+ * Inspect `error.cause` to determine the reason.
155
+ * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
156
+ * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
157
+ *
158
+ * @param params.withdrawalParams - Array of withdrawal parameters
159
+ * @param params.intentTx - The NEAR transaction info from the published intent
160
+ * @param params.signal - Optional AbortSignal for cancellation/timeout
161
+ * @param params.logger - Optional logger for debugging
162
+ * @returns Array of promises, one per withdrawal, that resolve with transaction info
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const promises = sdk.createWithdrawalCompletionPromises({
167
+ * withdrawalParams: [withdrawal1, withdrawal2],
168
+ * intentTx,
169
+ * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
170
+ * });
171
+ *
172
+ * // Handle each withdrawal as it completes
173
+ * for (const promise of promises) {
174
+ * promise.then((result) => console.log('Withdrawal completed:', result));
175
+ * }
176
+ * ```
177
+ */
178
+ createWithdrawalCompletionPromises(params: CreateWithdrawalCompletionPromisesParams): Array<Promise<TxInfo | TxNoInfo>>;
120
179
  parseAssetId(assetId: string): ParsedAssetInfo;
121
180
  signAndSendIntent(args: SignAndSendArgs): Promise<IntentPublishResult>;
122
181
  private withSaltRetry;
123
182
  signAndSendWithdrawalIntent(args: SignAndSendWithdrawalArgs<WithdrawalParams> | SignAndSendWithdrawalArgs<WithdrawalParams[]>): Promise<IntentPublishResult>;
124
183
  waitForIntentSettlement(args: {
125
184
  intentHash: IntentHash;
185
+ /** AbortSignal for cancellation/timeout. Use AbortSignal.timeout(ms) for timeout. */
186
+ signal?: AbortSignal;
126
187
  logger?: ILogger;
127
188
  }): Promise<NearTxInfo>;
128
189
  getIntentStatus({
package/dist/src/sdk.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { IntentHash, IntentPrimitive } from "./intents/shared-types.js";
2
2
  import { IIntentSigner } from "./intents/interfaces/intent-signer.js";
3
- import { BatchWithdrawalResult, Bridge, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalIdentifier, WithdrawalParams, WithdrawalResult } from "./shared-types.js";
3
+ import { BatchWithdrawalResult, Bridge, CreateWithdrawalCompletionPromisesParams, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalParams, WithdrawalResult } from "./shared-types.js";
4
4
  import { IIntentRelayer } from "./intents/interfaces/intent-relayer.js";
5
5
  import { ISaltManager } from "./intents/interfaces/salt-manager.js";
6
6
  import { IntentPayloadBuilder } from "./intents/intent-payload-builder.js";
7
- import { ILogger, NearIntentsEnv, RetryOptions } from "@defuse-protocol/internal-utils";
7
+ import { ILogger, NearIntentsEnv } from "@defuse-protocol/internal-utils";
8
8
 
9
9
  //#region src/sdk.d.ts
10
10
  interface IntentsSDKConfig {
@@ -13,6 +13,13 @@ interface IntentsSDKConfig {
13
13
  rpc?: PartialRPCEndpointMap;
14
14
  referral: string;
15
15
  solverRelayApiKey?: string;
16
+ features?: {
17
+ /**
18
+ * Route migrated POA tokens (*.omft.near) through Omni Bridge.
19
+ * Enable this to use Omni Bridge for POA tokens that have been migrated to the Omni infrastructure.
20
+ */
21
+ routeMigratedPoaTokensThroughOmniBridge?: boolean;
22
+ };
16
23
  }
17
24
  declare class IntentsSDK implements IIntentsSDK {
18
25
  protected env: NearIntentsEnv;
@@ -96,33 +103,87 @@ declare class IntentsSDK implements IIntentsSDK {
96
103
  quoteOptions?: QuoteOptions;
97
104
  logger?: ILogger;
98
105
  }): Promise<FeeEstimation>;
99
- protected getWithdrawalsIdentifiers({
100
- withdrawalParams,
101
- intentTx
102
- }: {
103
- withdrawalParams: WithdrawalParams[];
104
- intentTx: NearTxInfo;
105
- }): WithdrawalIdentifier[];
106
+ /**
107
+ * Wait for withdrawal(s) to complete on the destination chain.
108
+ *
109
+ * **Important:** Waits until the withdrawal completes, fails, or the chain-specific
110
+ * p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a shorter timeout budget.
111
+ *
112
+ * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
113
+ * Inspect `error.cause` to determine the reason.
114
+ * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
115
+ * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
116
+ *
117
+ * @param args.withdrawalParams - Single withdrawal or array of withdrawals
118
+ * @param args.intentTx - The NEAR transaction info from the published intent
119
+ * @param args.signal - Optional AbortSignal for cancellation/timeout
120
+ * @param args.logger - Optional logger for debugging
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * // With timeout
125
+ * const result = await sdk.waitForWithdrawalCompletion({
126
+ * withdrawalParams,
127
+ * intentTx,
128
+ * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
129
+ * });
130
+ * ```
131
+ */
106
132
  waitForWithdrawalCompletion(args: {
107
133
  withdrawalParams: WithdrawalParams;
108
134
  intentTx: NearTxInfo;
109
135
  signal?: AbortSignal;
110
- retryOptions?: RetryOptions;
111
136
  logger?: ILogger;
112
137
  }): Promise<TxInfo | TxNoInfo>;
113
138
  waitForWithdrawalCompletion(args: {
114
139
  withdrawalParams: WithdrawalParams[];
115
140
  intentTx: NearTxInfo;
116
141
  signal?: AbortSignal;
117
- retryOptions?: RetryOptions;
118
142
  logger?: ILogger;
119
143
  }): Promise<Array<TxInfo | TxNoInfo>>;
144
+ /**
145
+ * Create promises that resolve when each withdrawal completes on the destination chain.
146
+ * Use this for granular control over handling individual withdrawals as they complete,
147
+ * rather than waiting for all to finish.
148
+ *
149
+ * **Important:** Each promise waits until the withdrawal completes, fails, or the
150
+ * chain-specific p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a
151
+ * shorter timeout budget.
152
+ *
153
+ * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors).
154
+ * Inspect `error.cause` to determine the reason.
155
+ * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain.
156
+ * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError").
157
+ *
158
+ * @param params.withdrawalParams - Array of withdrawal parameters
159
+ * @param params.intentTx - The NEAR transaction info from the published intent
160
+ * @param params.signal - Optional AbortSignal for cancellation/timeout
161
+ * @param params.logger - Optional logger for debugging
162
+ * @returns Array of promises, one per withdrawal, that resolve with transaction info
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const promises = sdk.createWithdrawalCompletionPromises({
167
+ * withdrawalParams: [withdrawal1, withdrawal2],
168
+ * intentTx,
169
+ * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout
170
+ * });
171
+ *
172
+ * // Handle each withdrawal as it completes
173
+ * for (const promise of promises) {
174
+ * promise.then((result) => console.log('Withdrawal completed:', result));
175
+ * }
176
+ * ```
177
+ */
178
+ createWithdrawalCompletionPromises(params: CreateWithdrawalCompletionPromisesParams): Array<Promise<TxInfo | TxNoInfo>>;
120
179
  parseAssetId(assetId: string): ParsedAssetInfo;
121
180
  signAndSendIntent(args: SignAndSendArgs): Promise<IntentPublishResult>;
122
181
  private withSaltRetry;
123
182
  signAndSendWithdrawalIntent(args: SignAndSendWithdrawalArgs<WithdrawalParams> | SignAndSendWithdrawalArgs<WithdrawalParams[]>): Promise<IntentPublishResult>;
124
183
  waitForIntentSettlement(args: {
125
184
  intentHash: IntentHash;
185
+ /** AbortSignal for cancellation/timeout. Use AbortSignal.timeout(ms) for timeout. */
186
+ signal?: AbortSignal;
126
187
  logger?: ILogger;
127
188
  }): Promise<NearTxInfo>;
128
189
  getIntentStatus({