@defuse-protocol/intents-sdk 0.43.2 → 0.44.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 (83) 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-utils.cjs +10 -10
  18. package/dist/src/bridges/hot-bridge/hot-bridge.cjs +46 -32
  19. package/dist/src/bridges/hot-bridge/hot-bridge.js +38 -24
  20. package/dist/src/bridges/intents-bridge/intents-bridge.cjs +18 -4
  21. package/dist/src/bridges/intents-bridge/intents-bridge.js +18 -4
  22. package/dist/src/bridges/omni-bridge/error.cjs +6 -27
  23. package/dist/src/bridges/omni-bridge/error.d.cts +1 -16
  24. package/dist/src/bridges/omni-bridge/error.d.ts +1 -16
  25. package/dist/src/bridges/omni-bridge/error.js +1 -20
  26. package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +12 -7
  27. package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +5 -1
  28. package/dist/src/bridges/omni-bridge/omni-bridge.cjs +72 -54
  29. package/dist/src/bridges/omni-bridge/omni-bridge.js +47 -29
  30. package/dist/src/bridges/poa-bridge/poa-bridge-utils.cjs +2 -2
  31. package/dist/src/bridges/poa-bridge/poa-bridge.cjs +79 -26
  32. package/dist/src/bridges/poa-bridge/poa-bridge.js +66 -13
  33. package/dist/src/classes/errors.cjs +7 -7
  34. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.cjs +17 -0
  35. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.cts +12 -0
  36. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.d.ts +12 -0
  37. package/dist/src/constants/poa-tokens-routable-through-omni-bridge.js +16 -0
  38. package/dist/src/constants/withdrawal-timing.cjs +57 -0
  39. package/dist/src/constants/withdrawal-timing.js +56 -0
  40. package/dist/src/core/withdrawal-watcher.cjs +83 -0
  41. package/dist/src/core/withdrawal-watcher.d.cts +18 -0
  42. package/dist/src/core/withdrawal-watcher.d.ts +18 -0
  43. package/dist/src/core/withdrawal-watcher.js +79 -0
  44. package/dist/src/intents/expirable-nonce.cjs +3 -3
  45. package/dist/src/intents/intent-executer-impl/intent-executer.cjs +7 -4
  46. package/dist/src/intents/intent-executer-impl/intent-executer.js +5 -2
  47. package/dist/src/intents/intent-hash.cjs +2 -2
  48. package/dist/src/intents/intent-hashes/erc191.cjs +2 -2
  49. package/dist/src/intents/intent-hashes/nep413.cjs +2 -2
  50. package/dist/src/intents/intent-hashes/raw-ed25519.cjs +2 -2
  51. package/dist/src/intents/intent-hashes/sep53.cjs +4 -4
  52. package/dist/src/intents/intent-hashes/tip191.cjs +2 -2
  53. package/dist/src/intents/intent-hashes/ton-connect.cjs +2 -2
  54. package/dist/src/intents/intent-hashes/webauthn.cjs +2 -2
  55. package/dist/src/intents/intent-payload-builder.cjs +4 -4
  56. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.cjs +7 -7
  57. package/dist/src/intents/intent-relayer-impl/intent-relayer-public.js +1 -1
  58. package/dist/src/intents/intent-signer-impl/intent-signer-near-keypair.cjs +2 -2
  59. package/dist/src/intents/intent-signer-impl/intent-signer-nep413.cjs +3 -3
  60. package/dist/src/intents/intent-signer-impl/intent-signer-viem.cjs +3 -3
  61. package/dist/src/intents/interfaces/intent-relayer.d.cts +2 -1
  62. package/dist/src/intents/interfaces/intent-relayer.d.ts +2 -1
  63. package/dist/src/intents/salt-manager.cjs +5 -5
  64. package/dist/src/lib/array.cjs +2 -2
  65. package/dist/src/lib/caip2.cjs +4 -4
  66. package/dist/src/lib/configure-rpc-config.cjs +3 -3
  67. package/dist/src/lib/estimate-fee.cjs +6 -6
  68. package/dist/src/lib/parse-defuse-asset-id.cjs +2 -2
  69. package/dist/src/lib/route-config-factory.cjs +2 -5
  70. package/dist/src/lib/route-config-factory.d.cts +1 -1
  71. package/dist/src/lib/route-config-factory.d.ts +1 -1
  72. package/dist/src/lib/route-config-factory.js +2 -5
  73. package/dist/src/lib/tokensUsdPricesHttpClient/apis.cjs +3 -3
  74. package/dist/src/lib/validateAddress.cjs +18 -18
  75. package/dist/src/sdk.cjs +96 -47
  76. package/dist/src/sdk.d.cts +72 -11
  77. package/dist/src/sdk.d.ts +72 -11
  78. package/dist/src/sdk.js +85 -36
  79. package/dist/src/shared-types.d.cts +49 -15
  80. package/dist/src/shared-types.d.ts +49 -15
  81. package/package.json +5 -7
  82. package/dist/src/lib/route-config.cjs +0 -19
  83. package/dist/src/lib/route-config.js +0 -19
@@ -1,6 +1,6 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
3
- let __scure_base = require("@scure/base");
2
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
3
+ let _scure_base = require("@scure/base");
4
4
  let valibot = require("valibot");
5
5
  valibot = require_rolldown_runtime.__toESM(valibot);
6
6
 
@@ -11,7 +11,7 @@ var SaltManager = class {
11
11
  this.currentSalt = null;
12
12
  this.fetchPromise = null;
13
13
  this.lastFetchTime = 0;
14
- this.intentsContract = __defuse_protocol_internal_utils.configsByEnvironment[env].contractID;
14
+ this.intentsContract = _defuse_protocol_internal_utils.configsByEnvironment[env].contractID;
15
15
  this.nearProvider = nearProvider;
16
16
  }
17
17
  /**
@@ -59,7 +59,7 @@ var SaltManager = class {
59
59
  * @returns Promise resolving to the salt
60
60
  */
61
61
  async function fetchSalt(nearProvider, contractId) {
62
- const value = await __defuse_protocol_internal_utils.utils.queryContract({
62
+ const value = await _defuse_protocol_internal_utils.utils.queryContract({
63
63
  contractId,
64
64
  methodName: "current_salt",
65
65
  args: {},
@@ -67,7 +67,7 @@ async function fetchSalt(nearProvider, contractId) {
67
67
  nearClient: nearProvider,
68
68
  schema: valibot.string()
69
69
  });
70
- return __scure_base.hex.decode(value);
70
+ return _scure_base.hex.decode(value);
71
71
  }
72
72
 
73
73
  //#endregion
@@ -1,9 +1,9 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
2
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
3
3
 
4
4
  //#region src/lib/array.ts
5
5
  function zip(arr1, arr2) {
6
- (0, __defuse_protocol_internal_utils.assert)(arr1.length === arr2.length, "Arrays must have the same length");
6
+ (0, _defuse_protocol_internal_utils.assert)(arr1.length === arr2.length, "Arrays must have the same length");
7
7
  return arr1.map((v, i) => [v, arr2[i]]);
8
8
  }
9
9
 
@@ -1,5 +1,5 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
2
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
3
3
 
4
4
  //#region src/lib/caip2.ts
5
5
  /**
@@ -35,11 +35,11 @@ const Chains = {
35
35
  Starknet: "starknet:SN_MAIN"
36
36
  };
37
37
  function getEIP155ChainId(chain) {
38
- (0, __defuse_protocol_internal_utils.assert)(chain.startsWith("eip155:"), "Chain is not an EIP-155 chain");
38
+ (0, _defuse_protocol_internal_utils.assert)(chain.startsWith("eip155:"), "Chain is not an EIP-155 chain");
39
39
  const chainIdStr = chain.slice(7);
40
- (0, __defuse_protocol_internal_utils.assert)(chainIdStr.length > 0, "Chain is not an EIP-155 chain");
40
+ (0, _defuse_protocol_internal_utils.assert)(chainIdStr.length > 0, "Chain is not an EIP-155 chain");
41
41
  const chainId = Number(chainIdStr);
42
- (0, __defuse_protocol_internal_utils.assert)(!Number.isNaN(chainId), "Chain is not an EIP-155 chain");
42
+ (0, _defuse_protocol_internal_utils.assert)(!Number.isNaN(chainId), "Chain is not an EIP-155 chain");
43
43
  return chainId;
44
44
  }
45
45
 
@@ -1,17 +1,17 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const require_caip2 = require('./caip2.cjs');
3
3
  const require_object = require('./object.cjs');
4
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
4
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
5
5
 
6
6
  //#region src/lib/configure-rpc-config.ts
7
7
  function configureEvmRpcUrls(defaultRpcUrls, userRpcUrls, supportedChains) {
8
8
  const evmRpcUrls = Object.fromEntries(Object.entries(require_object.pick(Object.assign({}, defaultRpcUrls, userRpcUrls ?? {}), supportedChains)).map(([caip2, urls]) => [require_caip2.getEIP155ChainId(caip2), urls]));
9
- for (const [chainId, urls] of Object.entries(evmRpcUrls)) (0, __defuse_protocol_internal_utils.assert)(urls.length > 0, `EVM RPC URLs for chain ${chainId} are not provided`);
9
+ for (const [chainId, urls] of Object.entries(evmRpcUrls)) (0, _defuse_protocol_internal_utils.assert)(urls.length > 0, `EVM RPC URLs for chain ${chainId} are not provided`);
10
10
  return evmRpcUrls;
11
11
  }
12
12
  function configureStellarRpcUrls(defaultRpcUrls, userRpcUrls) {
13
13
  const stellarRpcUrls = Object.assign({}, defaultRpcUrls, userRpcUrls?.[require_caip2.Chains.Stellar] ?? {});
14
- for (const [key, value] of Object.entries(stellarRpcUrls)) (0, __defuse_protocol_internal_utils.assert)(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
14
+ for (const [key, value] of Object.entries(stellarRpcUrls)) (0, _defuse_protocol_internal_utils.assert)(value.length > 0, `Stellar RPC URL for ${key} is not provided`);
15
15
  return stellarRpcUrls;
16
16
  }
17
17
 
@@ -1,6 +1,6 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const require_apis = require('./tokensUsdPricesHttpClient/apis.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
 
5
5
  //#region src/lib/estimate-fee.ts
6
6
  /**
@@ -25,7 +25,7 @@ function getUnderlyingFee(feeEstimation, route, feeKey) {
25
25
  */
26
26
  async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions, env, logger, solverRelayApiKey }) {
27
27
  try {
28
- return await __defuse_protocol_internal_utils.solverRelay.getQuote({
28
+ return await _defuse_protocol_internal_utils.solverRelay.getQuote({
29
29
  quoteParams: {
30
30
  defuse_asset_identifier_in: tokenAssetId,
31
31
  defuse_asset_identifier_out: feeAssetId,
@@ -36,14 +36,14 @@ async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions,
36
36
  trusted_metadata: quoteOptions?.trustedMetadata
37
37
  },
38
38
  config: {
39
- baseURL: __defuse_protocol_internal_utils.configsByEnvironment[env].solverRelayBaseURL,
39
+ baseURL: _defuse_protocol_internal_utils.configsByEnvironment[env].solverRelayBaseURL,
40
40
  logBalanceSufficient: false,
41
41
  logger,
42
42
  solverRelayApiKey
43
43
  }
44
44
  });
45
45
  } catch (err) {
46
- if (!(err instanceof __defuse_protocol_internal_utils.QuoteError)) throw err;
46
+ if (!(err instanceof _defuse_protocol_internal_utils.QuoteError)) throw err;
47
47
  logger?.info("Can't get exact out quote, trying to get exact in quote with x1.2");
48
48
  const prices = await require_apis.tokens({ env });
49
49
  const feeAssetPrice = prices.items.find((t) => t.defuse_asset_id === feeAssetId);
@@ -59,7 +59,7 @@ async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions,
59
59
  let exactAmountIn = num / den;
60
60
  if (num % den !== 0n) exactAmountIn += 1n;
61
61
  if (exactAmountIn === 0n) exactAmountIn = 1n;
62
- const quote = await __defuse_protocol_internal_utils.solverRelay.getQuote({
62
+ const quote = await _defuse_protocol_internal_utils.solverRelay.getQuote({
63
63
  quoteParams: {
64
64
  defuse_asset_identifier_in: tokenAssetId,
65
65
  defuse_asset_identifier_out: feeAssetId,
@@ -70,7 +70,7 @@ async function getFeeQuote({ feeAmount, feeAssetId, tokenAssetId, quoteOptions,
70
70
  trusted_metadata: quoteOptions?.trustedMetadata
71
71
  },
72
72
  config: {
73
- baseURL: __defuse_protocol_internal_utils.configsByEnvironment[env].solverRelayBaseURL,
73
+ baseURL: _defuse_protocol_internal_utils.configsByEnvironment[env].solverRelayBaseURL,
74
74
  logBalanceSufficient: false,
75
75
  logger,
76
76
  solverRelayApiKey
@@ -1,11 +1,11 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const require_errors = require('../classes/errors.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
 
5
5
  //#region src/lib/parse-defuse-asset-id.ts
6
6
  function parseDefuseAssetId(assetId) {
7
7
  try {
8
- return __defuse_protocol_internal_utils.utils.parseDefuseAssetId(assetId);
8
+ return _defuse_protocol_internal_utils.utils.parseDefuseAssetId(assetId);
9
9
  } catch {
10
10
  throw new require_errors.UnsupportedAssetIdError(assetId, "Invalid asset id format.");
11
11
  }
@@ -22,11 +22,8 @@ function createVirtualChainRoute(auroraEngineContractId, proxyTokenContractId) {
22
22
  proxyTokenContractId
23
23
  };
24
24
  }
25
- function createPoaBridgeRoute(chain) {
26
- return {
27
- route: require_route_enum.RouteEnum.PoaBridge,
28
- chain
29
- };
25
+ function createPoaBridgeRoute() {
26
+ return { route: require_route_enum.RouteEnum.PoaBridge };
30
27
  }
31
28
  function createHotBridgeRoute(chain) {
32
29
  return {
@@ -6,7 +6,7 @@ declare function createInternalTransferRoute(): InternalTransferRouteConfig;
6
6
  declare function createNearWithdrawalRoute(msg?: string): NearWithdrawalRouteConfig;
7
7
  declare function createOmniBridgeRoute(chain?: Chain): OmniBridgeRouteConfig;
8
8
  declare function createVirtualChainRoute(auroraEngineContractId: string, proxyTokenContractId: string | null): VirtualChainRouteConfig;
9
- declare function createPoaBridgeRoute(chain: Chain): PoaBridgeRouteConfig;
9
+ declare function createPoaBridgeRoute(): PoaBridgeRouteConfig;
10
10
  declare function createHotBridgeRoute(chain: Chain): HotBridgeRouteConfig;
11
11
  declare function createDefaultRoute(): undefined;
12
12
  //#endregion
@@ -6,7 +6,7 @@ declare function createInternalTransferRoute(): InternalTransferRouteConfig;
6
6
  declare function createNearWithdrawalRoute(msg?: string): NearWithdrawalRouteConfig;
7
7
  declare function createOmniBridgeRoute(chain?: Chain): OmniBridgeRouteConfig;
8
8
  declare function createVirtualChainRoute(auroraEngineContractId: string, proxyTokenContractId: string | null): VirtualChainRouteConfig;
9
- declare function createPoaBridgeRoute(chain: Chain): PoaBridgeRouteConfig;
9
+ declare function createPoaBridgeRoute(): PoaBridgeRouteConfig;
10
10
  declare function createHotBridgeRoute(chain: Chain): HotBridgeRouteConfig;
11
11
  declare function createDefaultRoute(): undefined;
12
12
  //#endregion
@@ -22,11 +22,8 @@ function createVirtualChainRoute(auroraEngineContractId, proxyTokenContractId) {
22
22
  proxyTokenContractId
23
23
  };
24
24
  }
25
- function createPoaBridgeRoute(chain) {
26
- return {
27
- route: RouteEnum.PoaBridge,
28
- chain
29
- };
25
+ function createPoaBridgeRoute() {
26
+ return { route: RouteEnum.PoaBridge };
30
27
  }
31
28
  function createHotBridgeRoute(chain) {
32
29
  return {
@@ -1,10 +1,10 @@
1
1
  const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
- let __defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
2
+ let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
3
3
 
4
4
  //#region src/lib/tokensUsdPricesHttpClient/apis.ts
5
5
  async function tokens(config) {
6
- return (await (0, __defuse_protocol_internal_utils.request)({
7
- url: new URL("tokens", __defuse_protocol_internal_utils.configsByEnvironment[config.env].managerConsoleBaseURL),
6
+ return (await (0, _defuse_protocol_internal_utils.request)({
7
+ url: new URL("tokens", _defuse_protocol_internal_utils.configsByEnvironment[config.env].managerConsoleBaseURL),
8
8
  ...config,
9
9
  fetchOptions: {
10
10
  ...config.fetchOptions,
@@ -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);
@@ -111,7 +111,7 @@ function verifyBchChecksum(address) {
111
111
  }
112
112
  function validateSolAddress(address) {
113
113
  try {
114
- return __solana_web3_js.PublicKey.isOnCurve(address);
114
+ return _solana_web3_js.PublicKey.isOnCurve(address);
115
115
  } catch {
116
116
  return false;
117
117
  }
@@ -132,7 +132,7 @@ function validateZcashAddress(address) {
132
132
  if (address.startsWith("t1") || address.startsWith("t3")) return /^t[13][a-km-zA-HJ-NP-Z1-9]{33}$/.test(address);
133
133
  const expectedHrp = "tex";
134
134
  if (address.startsWith(`${expectedHrp}1`)) try {
135
- const decoded = __scure_base.bech32m.decodeToBytes(address);
135
+ const decoded = _scure_base.bech32m.decodeToBytes(address);
136
136
  if (decoded.prefix !== expectedHrp) return false;
137
137
  return decoded.bytes.length === 20;
138
138
  } catch {
@@ -140,7 +140,7 @@ function validateZcashAddress(address) {
140
140
  }
141
141
  const uaHrp = "u";
142
142
  if (address.startsWith(`${uaHrp}1`)) try {
143
- return __scure_base.bech32m.decodeToBytes(address).prefix === uaHrp;
143
+ return _scure_base.bech32m.decodeToBytes(address).prefix === uaHrp;
144
144
  } catch {
145
145
  return false;
146
146
  }
@@ -158,11 +158,11 @@ function validateTronAddress(address) {
158
158
  }
159
159
  function validateTronBase58Address(address) {
160
160
  try {
161
- const decoded = __scure_base.base58.decode(address);
161
+ const decoded = _scure_base.base58.decode(address);
162
162
  if (decoded.length !== 25) return false;
163
163
  const data = decoded.slice(0, 21);
164
164
  const checksum = decoded.slice(21);
165
- const expectedChecksum = (0, __noble_hashes_sha2.sha256)((0, __noble_hashes_sha2.sha256)(data)).slice(0, 4);
165
+ const expectedChecksum = (0, _noble_hashes_sha2.sha256)((0, _noble_hashes_sha2.sha256)(data)).slice(0, 4);
166
166
  for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return false;
167
167
  return data[0] === 65;
168
168
  } catch {
@@ -171,7 +171,7 @@ function validateTronBase58Address(address) {
171
171
  }
172
172
  function validateTronHexAddress(address) {
173
173
  try {
174
- const decoded = __scure_base.hex.decode(address);
174
+ const decoded = _scure_base.hex.decode(address);
175
175
  return decoded.length === 21 && decoded[0] === 65;
176
176
  } catch {
177
177
  return false;
@@ -195,9 +195,9 @@ function validateAptosAddress(address) {
195
195
  */
196
196
  function validateCardanoAddress(address) {
197
197
  try {
198
- const { prefix, words } = __scure_base.bech32.decode(address, 120);
198
+ const { prefix, words } = _scure_base.bech32.decode(address, 120);
199
199
  if (prefix !== "addr") return false;
200
- const addrType = __scure_base.bech32.fromWords(words)[0] >> 4;
200
+ const addrType = _scure_base.bech32.fromWords(words)[0] >> 4;
201
201
  return addrType >= 0 && addrType <= 7;
202
202
  } catch {
203
203
  return false;
@@ -222,7 +222,7 @@ function validateLitecoinAddress(address) {
222
222
  function validateLitecoinBase58Address(address, expectedVersion) {
223
223
  let decoded;
224
224
  try {
225
- decoded = __scure_base.base58.decode(address);
225
+ decoded = _scure_base.base58.decode(address);
226
226
  } catch {
227
227
  return false;
228
228
  }
@@ -230,7 +230,7 @@ function validateLitecoinBase58Address(address, expectedVersion) {
230
230
  if (decoded[0] !== expectedVersion) return false;
231
231
  const payload = decoded.subarray(0, 21);
232
232
  const checksum = decoded.subarray(21, 25);
233
- const expectedChecksum = (0, __noble_hashes_sha2.sha256)((0, __noble_hashes_sha2.sha256)(payload)).subarray(0, 4);
233
+ const expectedChecksum = (0, _noble_hashes_sha2.sha256)((0, _noble_hashes_sha2.sha256)(payload)).subarray(0, 4);
234
234
  for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return false;
235
235
  return true;
236
236
  }
@@ -238,10 +238,10 @@ function validateLitecoinBech32Address(address) {
238
238
  let decoded;
239
239
  let isBech32m = false;
240
240
  try {
241
- decoded = __scure_base.bech32.decode(address);
241
+ decoded = _scure_base.bech32.decode(address);
242
242
  } catch {
243
243
  try {
244
- decoded = __scure_base.bech32m.decode(address);
244
+ decoded = _scure_base.bech32m.decode(address);
245
245
  isBech32m = true;
246
246
  } catch {
247
247
  return false;
@@ -252,7 +252,7 @@ function validateLitecoinBech32Address(address) {
252
252
  if (!words || words.length < 1) return false;
253
253
  const version = words[0];
254
254
  if (version == null || version < 0 || version > 16) return false;
255
- const progLen = __scure_base.bech32.fromWords(words.slice(1)).length;
255
+ const progLen = _scure_base.bech32.fromWords(words.slice(1)).length;
256
256
  if (progLen < 2 || progLen > 40) return false;
257
257
  if (version === 0) {
258
258
  if (isBech32m) return false;
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 {