@sodax/sdk 1.0.1-beta → 1.0.3-beta

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
@@ -10237,8 +10237,6 @@ var LendingPoolService = class {
10237
10237
  });
10238
10238
  }
10239
10239
  };
10240
-
10241
- // src/moneyMarket/MoneyMarketDataService.ts
10242
10240
  var MoneyMarketDataService = class {
10243
10241
  uiPoolDataProviderService;
10244
10242
  lendingPoolService;
@@ -10251,6 +10249,34 @@ var MoneyMarketDataService = class {
10251
10249
  async getATokenData(aToken) {
10252
10250
  return Erc20Service.getErc20Token(aToken, this.hubProvider.publicClient);
10253
10251
  }
10252
+ /**
10253
+ * Fetches multiple aToken balances in a single multicall for better performance
10254
+ * @param aTokens - Array of aToken addresses
10255
+ * @param userAddress - User's hub wallet address to fetch balances for
10256
+ * @returns Promise<Map<Address, bigint>> - Map of aToken address to balance
10257
+ */
10258
+ async getATokensBalances(aTokens, userAddress) {
10259
+ const contracts = aTokens.map((aToken) => ({
10260
+ address: aToken,
10261
+ abi: viem.erc20Abi,
10262
+ functionName: "balanceOf",
10263
+ args: [userAddress]
10264
+ }));
10265
+ const results = await this.hubProvider.publicClient.multicall({
10266
+ contracts,
10267
+ allowFailure: false
10268
+ });
10269
+ const balanceMap = /* @__PURE__ */ new Map();
10270
+ let resultIndex = 0;
10271
+ for (const aToken of aTokens) {
10272
+ const result = results[resultIndex];
10273
+ if (result !== void 0) {
10274
+ balanceMap.set(aToken, result);
10275
+ }
10276
+ resultIndex++;
10277
+ }
10278
+ return balanceMap;
10279
+ }
10254
10280
  /**
10255
10281
  * LendingPool
10256
10282
  */
@@ -10296,7 +10322,7 @@ var MoneyMarketDataService = class {
10296
10322
  async getUserReservesData(spokeProvider) {
10297
10323
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
10298
10324
  const spokeChainId = spokeProvider.chainConfig.chain.id;
10299
- const hubWalletAddress = await deriveUserWalletAddress(this.hubProvider, spokeChainId, walletAddress);
10325
+ const hubWalletAddress = await HubService.getUserHubWalletAddress(walletAddress, spokeChainId, this.hubProvider);
10300
10326
  return this.uiPoolDataProviderService.getUserReservesData(hubWalletAddress);
10301
10327
  }
10302
10328
  /**
@@ -10328,7 +10354,7 @@ var MoneyMarketDataService = class {
10328
10354
  async getUserReservesHumanized(spokeProvider) {
10329
10355
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
10330
10356
  const spokeChainId = spokeProvider.chainConfig.chain.id;
10331
- const hubWalletAddress = await deriveUserWalletAddress(this.hubProvider, spokeChainId, walletAddress);
10357
+ const hubWalletAddress = await HubService.getUserHubWalletAddress(walletAddress, spokeChainId, this.hubProvider);
10332
10358
  return this.uiPoolDataProviderService.getUserReservesHumanized(hubWalletAddress);
10333
10359
  }
10334
10360
  /**
@@ -12935,7 +12961,8 @@ var SwapService = class {
12935
12961
  intentParams: params,
12936
12962
  spokeProvider,
12937
12963
  fee = this.config.partnerFee,
12938
- raw
12964
+ raw,
12965
+ skipSimulation = false
12939
12966
  }) {
12940
12967
  invariant6__default.default(
12941
12968
  this.configService.isValidOriginalAssetAddress(params.srcChain, params.inputToken),
@@ -13004,7 +13031,8 @@ var SwapService = class {
13004
13031
  },
13005
13032
  spokeProvider,
13006
13033
  this.hubProvider,
13007
- raw
13034
+ raw,
13035
+ skipSimulation
13008
13036
  );
13009
13037
  return {
13010
13038
  ok: true,
@@ -13024,6 +13052,179 @@ var SwapService = class {
13024
13052
  };
13025
13053
  }
13026
13054
  }
13055
+ /**
13056
+ * Creates a limit order intent (no deadline, must be cancelled manually by user).
13057
+ * Similar to swap but enforces deadline=0n (no deadline).
13058
+ * Limit orders remain active until manually cancelled by the user.
13059
+ *
13060
+ * @param {Prettify<LimitOrderParams<S> & OptionalTimeout>} params - Object containing:
13061
+ * - intentParams: The parameters for creating the limit order (deadline is automatically set to 0n, deadline field should be omitted).
13062
+ * - spokeProvider: The spoke provider instance.
13063
+ * - fee: (Optional) Partner fee configuration.
13064
+ * - timeout: (Optional) Timeout in milliseconds for the transaction (default: 60 seconds).
13065
+ * - skipSimulation: (Optional) Whether to skip transaction simulation (default: false).
13066
+ * @returns {Promise<Result<[SolverExecutionResponse, Intent, IntentDeliveryInfo], IntentError<IntentErrorCode>>>} A promise resolving to a Result containing a tuple of SolverExecutionResponse, Intent, and intent delivery info, or an IntentError if the operation fails.
13067
+ *
13068
+ * @example
13069
+ * const payload = {
13070
+ * "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
13071
+ * "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
13072
+ * "inputAmount": 1000000000000000n, // The amount of input tokens
13073
+ * "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
13074
+ * // deadline is omitted - will be automatically set to 0n
13075
+ * "allowPartialFill": false, // Whether the intent can be partially filled
13076
+ * "srcChain": "0x38.bsc", // Chain ID where input tokens originate
13077
+ * "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
13078
+ * "srcAddress": "0x..", // Source address (original address on spoke chain)
13079
+ * "dstAddress": "0x...", // Destination address (original address on spoke chain)
13080
+ * "solver": "0x..", // Optional specific solver address (address(0) = any solver)
13081
+ * "data": "0x..", // Additional arbitrary data
13082
+ * } satisfies CreateLimitOrderParams;
13083
+ *
13084
+ * const createLimitOrderResult = await swapService.createLimitOrder({
13085
+ * intentParams: payload,
13086
+ * spokeProvider,
13087
+ * fee, // optional
13088
+ * timeout, // optional
13089
+ * });
13090
+ *
13091
+ * if (createLimitOrderResult.ok) {
13092
+ * const [solverExecutionResponse, intent, intentDeliveryInfo] = createLimitOrderResult.value;
13093
+ * console.log('Intent execution response:', solverExecutionResponse);
13094
+ * console.log('Intent:', intent);
13095
+ * console.log('Intent delivery info:', intentDeliveryInfo);
13096
+ * // Limit order is now active and will remain until cancelled manually
13097
+ * } else {
13098
+ * // handle error
13099
+ * }
13100
+ */
13101
+ async createLimitOrder({
13102
+ intentParams: params,
13103
+ spokeProvider,
13104
+ fee = this.config.partnerFee,
13105
+ timeout = DEFAULT_RELAY_TX_TIMEOUT,
13106
+ skipSimulation = false
13107
+ }) {
13108
+ const limitOrderParams = {
13109
+ ...params,
13110
+ deadline: 0n
13111
+ };
13112
+ return this.createAndSubmitIntent({
13113
+ intentParams: limitOrderParams,
13114
+ spokeProvider,
13115
+ fee,
13116
+ timeout,
13117
+ skipSimulation
13118
+ });
13119
+ }
13120
+ /**
13121
+ * Creates a limit order intent (no deadline, must be cancelled manually by user).
13122
+ * Similar to createIntent but enforces deadline=0n (no deadline) and uses LimitOrderParams.
13123
+ * Limit orders remain active until manually cancelled by the user.
13124
+ * NOTE: This method does not submit the intent to the Solver API
13125
+ *
13126
+ * @param {Prettify<LimitOrderParams<S> & OptionalRaw<R>>} params - Object containing:
13127
+ * - intentParams: The parameters for creating the limit order (deadline is automatically set to 0n, deadline field should be omitted).
13128
+ * - spokeProvider: The spoke provider instance.
13129
+ * - fee: (Optional) Partner fee configuration.
13130
+ * - raw: (Optional) Whether to return the raw transaction data instead of executing it
13131
+ * - skipSimulation: (Optional) Whether to skip transaction simulation (default: false).
13132
+ * @returns {Promise<Result<[TxReturnType<S, R>, Intent & FeeAmount, Hex], IntentError<'CREATION_FAILED'>>>} The encoded contract call or raw transaction data, Intent and intent data as hex
13133
+ *
13134
+ * @example
13135
+ * const payload = {
13136
+ * "inputToken": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", // BSC ETH token address
13137
+ * "outputToken": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f", // ARB WBTC token address
13138
+ * "inputAmount": 1000000000000000n, // The amount of input tokens
13139
+ * "minOutputAmount": 900000000000000n, // min amount you are expecting to receive
13140
+ * // deadline is omitted - will be automatically set to 0n
13141
+ * "allowPartialFill": false, // Whether the intent can be partially filled
13142
+ * "srcChain": "0x38.bsc", // Chain ID where input tokens originate
13143
+ * "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
13144
+ * "srcAddress": "0x..", // Source address (original address on spoke chain)
13145
+ * "dstAddress": "0x...", // Destination address (original address on spoke chain)
13146
+ * "solver": "0x..", // Optional specific solver address (address(0) = any solver)
13147
+ * "data": "0x..", // Additional arbitrary data
13148
+ * } satisfies CreateLimitOrderParams;
13149
+ *
13150
+ * const createLimitOrderIntentResult = await swapService.createLimitOrderIntent({
13151
+ * intentParams: payload,
13152
+ * spokeProvider,
13153
+ * fee, // optional
13154
+ * raw, // optional
13155
+ * });
13156
+ *
13157
+ * if (createLimitOrderIntentResult.ok) {
13158
+ * const [txResult, intent, intentData] = createLimitOrderIntentResult.value;
13159
+ * console.log('Transaction result:', txResult);
13160
+ * console.log('Intent:', intent);
13161
+ * console.log('Intent data:', intentData);
13162
+ * } else {
13163
+ * // handle error
13164
+ * }
13165
+ */
13166
+ async createLimitOrderIntent({
13167
+ intentParams: params,
13168
+ spokeProvider,
13169
+ fee = this.config.partnerFee,
13170
+ raw,
13171
+ skipSimulation = false
13172
+ }) {
13173
+ const limitOrderParams = {
13174
+ ...params,
13175
+ deadline: 0n
13176
+ };
13177
+ return this.createIntent({
13178
+ intentParams: limitOrderParams,
13179
+ spokeProvider,
13180
+ fee,
13181
+ raw,
13182
+ skipSimulation
13183
+ });
13184
+ }
13185
+ /**
13186
+ * Syntactic sugar for cancelAndSubmitIntent: cancels a limit order intent and submits it to the Relayer API.
13187
+ * Similar to swap function that wraps createAndSubmitIntent.
13188
+ *
13189
+ * @param params - Object containing:
13190
+ * @param params.intent - The limit order intent to cancel.
13191
+ * @param params.spokeProvider - The spoke provider instance.
13192
+ * @param params.timeout - (Optional) Timeout in milliseconds for the transaction (default: 60 seconds).
13193
+ * @returns
13194
+ * A promise resolving to a Result containing a tuple of cancel transaction hash and destination transaction hash,
13195
+ * or an IntentError if the operation fails.
13196
+ *
13197
+ * @example
13198
+ * // Get intent first (or use intent from createLimitOrder response)
13199
+ * const intent: Intent = await swapService.getIntent(txHash);
13200
+ *
13201
+ * // Cancel the limit order
13202
+ * const result = await swapService.cancelLimitOrder({
13203
+ * intent,
13204
+ * spokeProvider,
13205
+ * timeout, // optional
13206
+ * });
13207
+ *
13208
+ * if (result.ok) {
13209
+ * const [cancelTxHash, dstTxHash] = result.value;
13210
+ * console.log('Cancel transaction hash:', cancelTxHash);
13211
+ * console.log('Destination transaction hash:', dstTxHash);
13212
+ * } else {
13213
+ * // handle error
13214
+ * console.error('[cancelLimitOrder] error:', result.error);
13215
+ * }
13216
+ */
13217
+ async cancelLimitOrder({
13218
+ intent,
13219
+ spokeProvider,
13220
+ timeout = DEFAULT_RELAY_TX_TIMEOUT
13221
+ }) {
13222
+ return this.cancelAndSubmitIntent({
13223
+ intent,
13224
+ spokeProvider,
13225
+ timeout
13226
+ });
13227
+ }
13027
13228
  /**
13028
13229
  * Cancels an intent
13029
13230
  * @param {Intent} intent - The intent to cancel
@@ -13065,7 +13266,97 @@ var SwapService = class {
13065
13266
  } catch (error) {
13066
13267
  return {
13067
13268
  ok: false,
13068
- error
13269
+ error: {
13270
+ code: "CANCEL_FAILED",
13271
+ data: {
13272
+ payload: intent,
13273
+ error
13274
+ }
13275
+ }
13276
+ };
13277
+ }
13278
+ }
13279
+ /**
13280
+ * Cancels an intent on the spoke chain, submits the cancel intent to the relayer API,
13281
+ * and waits until the intent cancel is executed (on the destination/hub chain).
13282
+ * Follows a similar workflow to createAndSubmitIntent, but for cancelling.
13283
+ *
13284
+ * @param params - The parameters for canceling and submitting the intent.
13285
+ * @param params.intent - The intent to be canceled.
13286
+ * @param params.spokeProvider - The provider for the spoke chain.
13287
+ * @param params.timeout - Optional timeout in milliseconds (default: 60 seconds).
13288
+ * @returns
13289
+ * A Result containing the SolverExecutionResponse (cancel tx), intent, and relay info,
13290
+ * or an IntentError on failure.
13291
+ */
13292
+ async cancelAndSubmitIntent({
13293
+ intent,
13294
+ spokeProvider,
13295
+ timeout = DEFAULT_RELAY_TX_TIMEOUT
13296
+ }) {
13297
+ try {
13298
+ const cancelResult = await this.cancelIntent(intent, spokeProvider, false);
13299
+ if (!cancelResult.ok) {
13300
+ return cancelResult;
13301
+ }
13302
+ const cancelTxHash = cancelResult.value;
13303
+ const verifyTxHashResult = await SpokeService.verifyTxHash(cancelTxHash, spokeProvider);
13304
+ if (!verifyTxHashResult.ok) {
13305
+ return {
13306
+ ok: false,
13307
+ error: {
13308
+ code: "CANCEL_FAILED",
13309
+ data: {
13310
+ payload: intent,
13311
+ error: verifyTxHashResult.error
13312
+ }
13313
+ }
13314
+ };
13315
+ }
13316
+ let dstIntentTxHash;
13317
+ if (spokeProvider.chainConfig.chain.id !== this.hubProvider.chainConfig.chain.id) {
13318
+ const intentRelayChainId = intent.srcChain.toString();
13319
+ const submitPayload = {
13320
+ action: "submit",
13321
+ params: {
13322
+ chain_id: intentRelayChainId,
13323
+ tx_hash: cancelTxHash
13324
+ }
13325
+ };
13326
+ const submitResult = await this.submitIntent(submitPayload);
13327
+ if (!submitResult.ok) {
13328
+ return submitResult;
13329
+ }
13330
+ const packet = await waitUntilIntentExecuted({
13331
+ intentRelayChainId,
13332
+ spokeTxHash: cancelTxHash,
13333
+ timeout,
13334
+ apiUrl: this.config.relayerApiEndpoint
13335
+ });
13336
+ if (!packet.ok) {
13337
+ return {
13338
+ ok: false,
13339
+ error: packet.error
13340
+ };
13341
+ }
13342
+ dstIntentTxHash = packet.value.dst_tx_hash;
13343
+ } else {
13344
+ dstIntentTxHash = cancelTxHash;
13345
+ }
13346
+ return {
13347
+ ok: true,
13348
+ value: [cancelTxHash, dstIntentTxHash]
13349
+ };
13350
+ } catch (error) {
13351
+ return {
13352
+ ok: false,
13353
+ error: {
13354
+ code: "CANCEL_FAILED",
13355
+ data: {
13356
+ payload: intent,
13357
+ error
13358
+ }
13359
+ }
13069
13360
  };
13070
13361
  }
13071
13362
  }
@@ -13628,65 +13919,25 @@ var MoneyMarketService = class _MoneyMarketService {
13628
13919
  );
13629
13920
  }
13630
13921
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
13631
- if (spokeProvider instanceof StellarSpokeProvider && (params.action === "supply" || params.action === "repay")) {
13922
+ if (isStellarSpokeProviderType(spokeProvider) && (params.action === "supply" || params.action === "repay")) {
13632
13923
  return {
13633
13924
  ok: true,
13634
13925
  value: await StellarSpokeService.hasSufficientTrustline(params.token, params.amount, spokeProvider)
13635
13926
  };
13636
13927
  }
13637
- if (spokeProvider instanceof EvmSpokeProvider && (params.action === "supply" || params.action === "repay")) {
13928
+ if ((isEvmSpokeProviderType(spokeProvider) || isSonicSpokeProviderType(spokeProvider)) && (params.action === "supply" || params.action === "repay")) {
13929
+ const spender = isHubSpokeProvider(spokeProvider, this.hubProvider) ? await HubService.getUserRouter(
13930
+ walletAddress,
13931
+ this.hubProvider
13932
+ ) : spokeProvider.chainConfig.addresses.assetManager;
13638
13933
  return await Erc20Service.isAllowanceValid(
13639
13934
  params.token,
13640
13935
  params.amount,
13641
13936
  walletAddress,
13642
- spokeProvider.chainConfig.addresses.assetManager,
13937
+ spender,
13643
13938
  spokeProvider
13644
13939
  );
13645
13940
  }
13646
- if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
13647
- if (params.action === "withdraw") {
13648
- const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
13649
- params.token,
13650
- params.amount,
13651
- params.toChainId ?? spokeProvider.chainConfig.chain.id,
13652
- this.data,
13653
- this.configService
13654
- );
13655
- return await SonicSpokeService.isWithdrawApproved(
13656
- walletAddress,
13657
- withdrawInfo,
13658
- spokeProvider
13659
- );
13660
- }
13661
- if (params.action === "borrow") {
13662
- const borrowInfo = await SonicSpokeService.getBorrowInfo(
13663
- params.token,
13664
- params.amount,
13665
- params.toChainId ?? spokeProvider.chainConfig.chain.id,
13666
- this.data,
13667
- this.configService,
13668
- this.config
13669
- );
13670
- return await SonicSpokeService.isBorrowApproved(
13671
- walletAddress,
13672
- borrowInfo,
13673
- spokeProvider
13674
- );
13675
- }
13676
- if (params.action === "supply" || params.action === "repay") {
13677
- const userRouter = await SonicSpokeService.getUserRouter(
13678
- walletAddress,
13679
- spokeProvider
13680
- );
13681
- return await Erc20Service.isAllowanceValid(
13682
- params.token,
13683
- params.amount,
13684
- walletAddress,
13685
- userRouter,
13686
- spokeProvider
13687
- );
13688
- }
13689
- }
13690
13941
  return {
13691
13942
  ok: true,
13692
13943
  value: true
@@ -13742,7 +13993,7 @@ var MoneyMarketService = class _MoneyMarketService {
13742
13993
  );
13743
13994
  }
13744
13995
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
13745
- if (spokeProvider instanceof StellarSpokeProvider) {
13996
+ if (isStellarSpokeProviderType(spokeProvider)) {
13746
13997
  invariant6__default.default(
13747
13998
  params.action === "supply" || params.action === "repay",
13748
13999
  "Invalid action (only supply and repay are supported on stellar)"
@@ -13753,16 +14004,20 @@ var MoneyMarketService = class _MoneyMarketService {
13753
14004
  value: result
13754
14005
  };
13755
14006
  }
13756
- if (spokeProvider instanceof EvmSpokeProvider) {
14007
+ if (isEvmSpokeProviderType(spokeProvider) || isSonicSpokeProviderType(spokeProvider)) {
13757
14008
  invariant6__default.default(
13758
14009
  params.action === "supply" || params.action === "repay",
13759
14010
  "Invalid action (only supply and repay are supported on evm)"
13760
14011
  );
13761
14012
  invariant6__default.default(viem.isAddress(params.token), "Invalid token address");
14013
+ const spender = isHubSpokeProvider(spokeProvider, this.hubProvider) ? await HubService.getUserRouter(
14014
+ walletAddress,
14015
+ this.hubProvider
14016
+ ) : spokeProvider.chainConfig.addresses.assetManager;
13762
14017
  const result = await Erc20Service.approve(
13763
14018
  params.token,
13764
14019
  params.amount,
13765
- spokeProvider.chainConfig.addresses.assetManager,
14020
+ spender,
13766
14021
  spokeProvider,
13767
14022
  raw
13768
14023
  );
@@ -13771,69 +14026,6 @@ var MoneyMarketService = class _MoneyMarketService {
13771
14026
  value: result
13772
14027
  };
13773
14028
  }
13774
- if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
13775
- invariant6__default.default(
13776
- params.action === "withdraw" || params.action === "borrow" || params.action === "supply" || params.action === "repay",
13777
- "Invalid action (only withdraw, borrow, supply and repay are supported on sonic)"
13778
- );
13779
- invariant6__default.default(viem.isAddress(params.token), "Invalid token address");
13780
- if (params.action === "withdraw") {
13781
- const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
13782
- params.token,
13783
- params.amount,
13784
- params?.toChainId ?? spokeProvider.chainConfig.chain.id,
13785
- this.data,
13786
- this.configService
13787
- );
13788
- const result = await SonicSpokeService.approveWithdraw(
13789
- walletAddress,
13790
- withdrawInfo,
13791
- spokeProvider,
13792
- raw
13793
- );
13794
- return {
13795
- ok: true,
13796
- value: result
13797
- };
13798
- }
13799
- if (params.action === "borrow") {
13800
- const borrowInfo = await SonicSpokeService.getBorrowInfo(
13801
- params.token,
13802
- params.amount,
13803
- params?.toChainId ?? spokeProvider.chainConfig.chain.id,
13804
- this.data,
13805
- this.configService,
13806
- this.config
13807
- );
13808
- const result = await SonicSpokeService.approveBorrow(
13809
- walletAddress,
13810
- borrowInfo,
13811
- spokeProvider,
13812
- raw
13813
- );
13814
- return {
13815
- ok: true,
13816
- value: result
13817
- };
13818
- }
13819
- if (params.action === "supply" || params.action === "repay") {
13820
- const userRouter = await SonicSpokeService.getUserRouter(
13821
- walletAddress,
13822
- spokeProvider
13823
- );
13824
- const result = await Erc20Service.approve(
13825
- params.token,
13826
- params.amount,
13827
- userRouter,
13828
- spokeProvider,
13829
- raw
13830
- );
13831
- return {
13832
- ok: true,
13833
- value: result
13834
- };
13835
- }
13836
- }
13837
14029
  return {
13838
14030
  ok: false,
13839
14031
  error: new Error("Approve only supported for EVM spoke chains")
@@ -13892,7 +14084,9 @@ var MoneyMarketService = class _MoneyMarketService {
13892
14084
  };
13893
14085
  }
13894
14086
  let intentTxHash = null;
13895
- if (spokeProvider.chainConfig.chain.id !== this.hubProvider.chainConfig.chain.id) {
14087
+ if (spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
14088
+ intentTxHash = txResult.value;
14089
+ } else {
13896
14090
  const packetResult = await relayTxAndWaitPacket(
13897
14091
  txResult.value,
13898
14092
  spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
@@ -13913,8 +14107,6 @@ var MoneyMarketService = class _MoneyMarketService {
13913
14107
  };
13914
14108
  }
13915
14109
  intentTxHash = packetResult.value.dst_tx_hash;
13916
- } else {
13917
- intentTxHash = txResult.value;
13918
14110
  }
13919
14111
  return { ok: true, value: [txResult.value, intentTxHash] };
13920
14112
  } catch (error) {
@@ -13975,13 +14167,15 @@ var MoneyMarketService = class _MoneyMarketService {
13975
14167
  this.configService.isMoneyMarketSupportedToken(fromChainId, params.token),
13976
14168
  `Unsupported spoke chain (${fromChainId}) token: ${params.token}`
13977
14169
  );
13978
- const fromHubWallet = await deriveUserWalletAddress(this.hubProvider, fromChainId, fromAddress);
13979
- const toHubWallet = await deriveUserWalletAddress(this.hubProvider, toChainId, toAddress);
14170
+ const [fromHubWallet, toHubWallet] = await Promise.all([
14171
+ HubService.getUserHubWalletAddress(fromAddress, fromChainId, this.hubProvider),
14172
+ HubService.getUserHubWalletAddress(toAddress, toChainId, this.hubProvider)
14173
+ ]);
13980
14174
  const data = this.buildSupplyData(fromChainId, params.token, params.amount, toHubWallet);
13981
14175
  const txResult = await SpokeService.deposit(
13982
14176
  {
13983
14177
  from: fromAddress,
13984
- to: fromChainId === this.hubProvider.chainConfig.chain.id ? void 0 : fromHubWallet,
14178
+ to: fromHubWallet,
13985
14179
  token: params.token,
13986
14180
  amount: params.amount,
13987
14181
  data
@@ -14061,7 +14255,7 @@ var MoneyMarketService = class _MoneyMarketService {
14061
14255
  if (spokeProvider.chainConfig.chain.id !== this.hubProvider.chainConfig.chain.id || params.toChainId && params.toAddress && params.toChainId !== this.hubProvider.chainConfig.chain.id) {
14062
14256
  const packetResult = await relayTxAndWaitPacket(
14063
14257
  txResult.value,
14064
- spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
14258
+ isSolanaSpokeProviderType(spokeProvider) ? txResult.data : void 0,
14065
14259
  spokeProvider,
14066
14260
  this.config.relayerApiEndpoint,
14067
14261
  timeout
@@ -14130,14 +14324,14 @@ var MoneyMarketService = class _MoneyMarketService {
14130
14324
  invariant6__default.default(params.action === "borrow", "Invalid action");
14131
14325
  invariant6__default.default(params.token.length > 0, "Token is required");
14132
14326
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
14133
- const fromChainId = spokeProvider.chainConfig.chain.id;
14134
- const fromAddress = await spokeProvider.walletProvider.getWalletAddress();
14327
+ const fromChainId = params.fromChainId ?? spokeProvider.chainConfig.chain.id;
14328
+ const fromAddress = params.fromAddress ?? await spokeProvider.walletProvider.getWalletAddress();
14135
14329
  const toChainId = params.toChainId ?? fromChainId;
14136
14330
  const toAddress = params.toAddress ?? fromAddress;
14137
14331
  const dstToken = this.configService.getMoneyMarketToken(toChainId, params.token);
14138
14332
  invariant6__default.default(dstToken, `Money market token not found for spoke chain (${toChainId}) token: ${params.token}`);
14139
14333
  const encodedToAddress = encodeAddress(toChainId, toAddress);
14140
- const fromHubWallet = await deriveUserWalletAddress(this.hubProvider, fromChainId, fromAddress);
14334
+ const fromHubWallet = await HubService.getUserHubWalletAddress(fromAddress, fromChainId, this.hubProvider);
14141
14335
  const data = this.buildBorrowData(fromHubWallet, encodedToAddress, dstToken.address, params.amount, toChainId);
14142
14336
  let txResult;
14143
14337
  if (fromChainId === this.hubProvider.chainConfig.chain.id && isSonicSpokeProviderType(spokeProvider)) {
@@ -14283,29 +14477,9 @@ var MoneyMarketService = class _MoneyMarketService {
14283
14477
  `Unsupported spoke chain (${toChainId}) token: ${params.token}`
14284
14478
  );
14285
14479
  const encodedToAddress = encodeAddress(toChainId, toAddress);
14286
- const fromHubWallet = await deriveUserWalletAddress(this.hubProvider, fromChainId, fromAddress);
14287
- let data;
14288
- if (spokeProvider instanceof SonicSpokeProvider) {
14289
- const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
14290
- params.token,
14291
- params.amount,
14292
- toChainId,
14293
- this.data,
14294
- this.configService
14295
- );
14296
- data = await SonicSpokeService.buildWithdrawData(
14297
- fromAddress,
14298
- withdrawInfo,
14299
- params.amount,
14300
- encodedToAddress,
14301
- toChainId,
14302
- spokeProvider,
14303
- this
14304
- );
14305
- } else {
14306
- data = this.buildWithdrawData(fromHubWallet, encodedToAddress, params.token, params.amount, toChainId);
14307
- }
14308
- const txResult = spokeProvider instanceof SonicSpokeProvider ? await SonicSpokeService.callWallet(data, spokeProvider, raw) : await SpokeService.callWallet(fromHubWallet, data, spokeProvider, this.hubProvider, raw);
14480
+ const fromHubWallet = await HubService.getUserHubWalletAddress(fromAddress, fromChainId, this.hubProvider);
14481
+ const data = this.buildWithdrawData(fromHubWallet, encodedToAddress, params.token, params.amount, toChainId);
14482
+ const txResult = isSonicSpokeProviderType(spokeProvider) ? await SonicSpokeService.callWallet(data, spokeProvider, raw) : await SpokeService.callWallet(fromHubWallet, data, spokeProvider, this.hubProvider, raw);
14309
14483
  return {
14310
14484
  ok: true,
14311
14485
  value: txResult,
@@ -14445,13 +14619,15 @@ var MoneyMarketService = class _MoneyMarketService {
14445
14619
  this.configService.isMoneyMarketSupportedToken(fromChainId, params.token),
14446
14620
  `Unsupported spoke chain (${fromChainId}) token: ${params.token}`
14447
14621
  );
14448
- const toHubWallet = await deriveUserWalletAddress(this.hubProvider, toChainId, toAddress);
14449
- const fromHubWallet = await deriveUserWalletAddress(this.hubProvider, fromChainId, fromAddress);
14622
+ const [fromHubWallet, toHubWallet] = await Promise.all([
14623
+ HubService.getUserHubWalletAddress(fromAddress, fromChainId, this.hubProvider),
14624
+ HubService.getUserHubWalletAddress(toAddress, toChainId, this.hubProvider)
14625
+ ]);
14450
14626
  const data = this.buildRepayData(fromChainId, params.token, params.amount, toHubWallet);
14451
14627
  const txResult = await SpokeService.deposit(
14452
14628
  {
14453
14629
  from: fromAddress,
14454
- to: fromChainId === this.hubProvider.chainConfig.chain.id ? void 0 : fromHubWallet,
14630
+ to: fromHubWallet,
14455
14631
  token: params.token,
14456
14632
  amount: params.amount,
14457
14633
  data
@@ -14930,6 +15106,8 @@ var Sodax = class {
14930
15106
 
14931
15107
  // src/shared/services/hub/WalletAbstractionService.ts
14932
15108
  var WalletAbstractionService = class {
15109
+ constructor() {
15110
+ }
14933
15111
  /**
14934
15112
  * Gets the hub wallet address for a user based on their spoke chain address.
14935
15113
  * @param address - The user's address on the spoke chain
@@ -14954,6 +15132,40 @@ var WalletAbstractionService = class {
14954
15132
  );
14955
15133
  }
14956
15134
  };
15135
+
15136
+ // src/shared/services/hub/HubService.ts
15137
+ var HubService = class _HubService {
15138
+ constructor() {
15139
+ }
15140
+ /**
15141
+ * Get the derived address of a contract deployed with CREATE3.
15142
+ * @param address - User's address on the specified chain as hex
15143
+ * @param hubProvider - Hub provider
15144
+ * @returns {HubAddress} The computed contract address as a EVM address (hex) string
15145
+ */
15146
+ static async getUserRouter(address, hubProvider) {
15147
+ return hubProvider.publicClient.readContract({
15148
+ address: hubProvider.chainConfig.addresses.walletRouter,
15149
+ abi: sonicWalletFactoryAbi,
15150
+ functionName: "getDeployedAddress",
15151
+ args: [address]
15152
+ });
15153
+ }
15154
+ /**
15155
+ * Gets the hub wallet address for a user based on their spoke chain address.
15156
+ * @param address - The user's address on the spoke chain
15157
+ * @param chainId - spoke chain id
15158
+ * @param hubProvider - The provider for interacting with the hub chain
15159
+ * @returns The user's hub wallet address
15160
+ */
15161
+ static async getUserHubWalletAddress(address, chainId, hubProvider) {
15162
+ const encodedAddress = encodeAddress(chainId, address);
15163
+ if (chainId === hubProvider.chainConfig.chain.id) {
15164
+ return _HubService.getUserRouter(encodedAddress, hubProvider);
15165
+ }
15166
+ return EvmWalletAbstraction.getUserHubWalletAddress(chainId, encodedAddress, hubProvider);
15167
+ }
15168
+ };
14957
15169
  var SuiSpokeService = class _SuiSpokeService {
14958
15170
  constructor() {
14959
15171
  }
@@ -15594,6 +15806,9 @@ function parseToStroops(amount) {
15594
15806
  function sleep(ms) {
15595
15807
  return new Promise((resolve) => setTimeout(resolve, ms));
15596
15808
  }
15809
+ function isHubSpokeProvider(spokeProvider, hubProvider) {
15810
+ return spokeProvider.chainConfig.chain.id === hubProvider.chainConfig.chain.id;
15811
+ }
15597
15812
 
15598
15813
  // src/shared/types.ts
15599
15814
  var SolverIntentStatusCode = /* @__PURE__ */ ((SolverIntentStatusCode2) => {
@@ -15706,6 +15921,29 @@ var BackendApiService = class {
15706
15921
  const endpoint = `/solver/orderbook?${queryString}`;
15707
15922
  return this.makeRequest(endpoint, { method: "GET" });
15708
15923
  }
15924
+ /**
15925
+ * Get all intents created by a specific user address with optional filters.
15926
+ *
15927
+ * @param params - Options to filter the user intents.
15928
+ * @param params.userAddress - The user's wallet address on the hub chain (required).
15929
+ * @param params.startDate - Optional. Start timestamp in milliseconds (number, required if filtering by date).
15930
+ * @param params.endDate - Optional. End timestamp in milliseconds (number, required if filtering by date).
15931
+ * @param params.limit - Optional. Max number of results (string).
15932
+ * @param params.offset - Optional. Pagination offset (string).
15933
+ *
15934
+ * @returns {Promise<UserIntentsResponse>} Promise resolving to an array of intent responses for the user.
15935
+ */
15936
+ async getUserIntents(params) {
15937
+ const { userAddress, startDate, endDate, limit, offset } = params;
15938
+ const queryParams = new URLSearchParams();
15939
+ if (startDate) queryParams.append("startDate", new Date(startDate).toISOString());
15940
+ if (endDate) queryParams.append("endDate", new Date(endDate).toISOString());
15941
+ if (limit) queryParams.append("limit", limit);
15942
+ if (offset) queryParams.append("offset", offset);
15943
+ const queryString = queryParams.toString();
15944
+ const endpoint = queryString.length > 0 ? `/intent/user/${userAddress}?${queryString}` : `/intent/user/${userAddress}`;
15945
+ return this.makeRequest(endpoint, { method: "GET" });
15946
+ }
15709
15947
  // Money Market endpoints
15710
15948
  /**
15711
15949
  * Get money market position for a specific user
@@ -15912,7 +16150,7 @@ var BridgeService = class {
15912
16150
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
15913
16151
  invariant6__default.default(params.srcAsset.length > 0, "Source asset is required");
15914
16152
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
15915
- if (spokeProvider instanceof EvmSpokeProvider) {
16153
+ if (isEvmSpokeProviderType(spokeProvider)) {
15916
16154
  invariant6__default.default(viem.isAddress(params.srcAsset), "Invalid source asset address for EVM chain");
15917
16155
  const allowanceResult = await Erc20Service.isAllowanceValid(
15918
16156
  params.srcAsset,
@@ -15935,7 +16173,7 @@ var BridgeService = class {
15935
16173
  value: allowanceResult.value
15936
16174
  };
15937
16175
  }
15938
- if (spokeProvider instanceof StellarSpokeProvider) {
16176
+ if (isStellarSpokeProviderType(spokeProvider)) {
15939
16177
  const allowanceResult = await StellarSpokeService.hasSufficientTrustline(
15940
16178
  params.srcAsset,
15941
16179
  params.amount,
@@ -15955,9 +16193,12 @@ var BridgeService = class {
15955
16193
  value: allowanceResult
15956
16194
  };
15957
16195
  }
15958
- if (spokeProvider instanceof SonicSpokeProvider) {
16196
+ if (isSonicSpokeProviderType(spokeProvider)) {
15959
16197
  invariant6__default.default(viem.isAddress(params.srcAsset), "Invalid source asset address for Sonic chain");
15960
- const userRouter = await SonicSpokeService.getUserRouter(walletAddress, spokeProvider);
16198
+ const userRouter = await SonicSpokeService.getUserRouter(
16199
+ walletAddress,
16200
+ spokeProvider
16201
+ );
15961
16202
  const allowanceResult = await Erc20Service.isAllowanceValid(
15962
16203
  params.srcAsset,
15963
16204
  params.amount,
@@ -16009,7 +16250,7 @@ var BridgeService = class {
16009
16250
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
16010
16251
  invariant6__default.default(params.srcAsset.length > 0, "Source asset is required");
16011
16252
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
16012
- if (spokeProvider instanceof EvmSpokeProvider) {
16253
+ if (isEvmSpokeProviderType(spokeProvider)) {
16013
16254
  invariant6__default.default(viem.isAddress(params.srcAsset), "Invalid source asset address for EVM chain");
16014
16255
  const result = await Erc20Service.approve(
16015
16256
  params.srcAsset,
@@ -16023,14 +16264,14 @@ var BridgeService = class {
16023
16264
  value: result
16024
16265
  };
16025
16266
  }
16026
- if (spokeProvider instanceof StellarSpokeProvider) {
16267
+ if (isStellarSpokeProviderType(spokeProvider)) {
16027
16268
  const result = await StellarSpokeService.requestTrustline(params.srcAsset, params.amount, spokeProvider, raw);
16028
16269
  return {
16029
16270
  ok: true,
16030
16271
  value: result
16031
16272
  };
16032
16273
  }
16033
- if (spokeProvider instanceof SonicSpokeProvider) {
16274
+ if (isSonicSpokeProviderType(spokeProvider)) {
16034
16275
  invariant6__default.default(viem.isAddress(params.srcAsset), "Invalid source asset address for Sonic chain");
16035
16276
  const userRouter = await SonicSpokeService.getUserRouter(
16036
16277
  walletAddress,
@@ -16812,7 +17053,7 @@ var StakingService = class {
16812
17053
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
16813
17054
  const targetToken = params.action === "stake" || spokeProvider.chainConfig.chain.id !== this.hubProvider.chainConfig.chain.id ? spokeProvider.chainConfig.supportedTokens.SODA?.address : this.hubProvider.chainConfig.addresses.xSoda;
16814
17055
  invariant6__default.default(targetToken, "Target token not found");
16815
- if (spokeProvider instanceof EvmSpokeProvider) {
17056
+ if (isEvmSpokeProviderType(spokeProvider)) {
16816
17057
  const allowanceResult = await Erc20Service.isAllowanceValid(
16817
17058
  targetToken,
16818
17059
  params.amount,
@@ -16834,7 +17075,7 @@ var StakingService = class {
16834
17075
  value: allowanceResult.value
16835
17076
  };
16836
17077
  }
16837
- if (spokeProvider instanceof SonicSpokeProvider) {
17078
+ if (isSonicSpokeProviderType(spokeProvider)) {
16838
17079
  const userRouter = await SonicSpokeService.getUserRouter(walletAddress, spokeProvider);
16839
17080
  const allowanceResult = await Erc20Service.isAllowanceValid(
16840
17081
  targetToken,
@@ -16857,7 +17098,7 @@ var StakingService = class {
16857
17098
  value: allowanceResult.value
16858
17099
  };
16859
17100
  }
16860
- if (spokeProvider instanceof StellarSpokeProvider) {
17101
+ if (isStellarSpokeProviderType(spokeProvider)) {
16861
17102
  return {
16862
17103
  ok: true,
16863
17104
  value: await StellarSpokeService.hasSufficientTrustline(targetToken, params.amount, spokeProvider)
@@ -16903,7 +17144,7 @@ var StakingService = class {
16903
17144
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
16904
17145
  const targetToken = params.action === "stake" || spokeProvider.chainConfig.chain.id !== this.hubProvider.chainConfig.chain.id ? spokeProvider.chainConfig.supportedTokens.SODA?.address : this.hubProvider.chainConfig.addresses.xSoda;
16905
17146
  invariant6__default.default(targetToken, "Target token not found");
16906
- if (spokeProvider instanceof EvmSpokeProvider) {
17147
+ if (isEvmSpokeProviderType(spokeProvider)) {
16907
17148
  const result = await Erc20Service.approve(
16908
17149
  targetToken,
16909
17150
  params.amount,
@@ -16916,7 +17157,7 @@ var StakingService = class {
16916
17157
  value: result
16917
17158
  };
16918
17159
  }
16919
- if (spokeProvider instanceof SonicSpokeProvider) {
17160
+ if (isSonicSpokeProviderType(spokeProvider)) {
16920
17161
  const userRouter = await SonicSpokeService.getUserRouter(
16921
17162
  walletAddress,
16922
17163
  spokeProvider
@@ -16927,7 +17168,7 @@ var StakingService = class {
16927
17168
  value: result
16928
17169
  };
16929
17170
  }
16930
- if (spokeProvider instanceof StellarSpokeProvider) {
17171
+ if (isStellarSpokeProviderType(spokeProvider)) {
16931
17172
  const result = await StellarSpokeService.requestTrustline(targetToken, params.amount, spokeProvider, raw);
16932
17173
  return {
16933
17174
  ok: true,
@@ -17182,7 +17423,13 @@ var StakingService = class {
17182
17423
  spokeProvider,
17183
17424
  this.hubProvider
17184
17425
  );
17185
- const data = this.buildUnstakeData(hubWallet, params);
17426
+ const xSoda = this.hubProvider.chainConfig.addresses.xSoda;
17427
+ const underlyingSodaAmount = await StakingLogic.convertXSodaSharesToSoda(
17428
+ xSoda,
17429
+ params.amount,
17430
+ this.hubProvider.publicClient
17431
+ );
17432
+ const data = this.buildUnstakeData(hubWallet, params, xSoda, underlyingSodaAmount);
17186
17433
  let txResult;
17187
17434
  if (isHub) {
17188
17435
  txResult = await SpokeService.deposit(
@@ -17225,13 +17472,12 @@ var StakingService = class {
17225
17472
  * @param params - The unstake parameters
17226
17473
  * @returns The encoded contract call data
17227
17474
  */
17228
- buildUnstakeData(hubWallet, params) {
17475
+ buildUnstakeData(hubWallet, params, xSoda, underlyingSodaAmount) {
17229
17476
  const hubConfig = getHubChainConfig();
17230
17477
  const stakedSoda = hubConfig.addresses.stakedSoda;
17231
- const xSoda = hubConfig.addresses.xSoda;
17232
17478
  const calls = [];
17233
17479
  calls.push(StakingLogic.encodeXSodaRedeem(xSoda, params.amount, hubWallet, hubWallet));
17234
- calls.push(StakingLogic.encodeUnstake(stakedSoda, hubWallet, params.amount));
17480
+ calls.push(StakingLogic.encodeUnstake(stakedSoda, hubWallet, underlyingSodaAmount));
17235
17481
  return encodeContractCalls(calls);
17236
17482
  }
17237
17483
  /**
@@ -18567,23 +18813,23 @@ var MigrationService = class {
18567
18813
  isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
18568
18814
  "Invalid params"
18569
18815
  );
18570
- if (spokeProvider instanceof IconSpokeProvider && (isIcxMigrateParams(params) || isBalnMigrateParams(params))) {
18816
+ if (isIconSpokeProviderType(spokeProvider) && (isIcxMigrateParams(params) || isBalnMigrateParams(params))) {
18571
18817
  return {
18572
18818
  ok: true,
18573
18819
  value: true
18574
18820
  };
18575
18821
  }
18576
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
18577
- const evmSpokeProvider = spokeProvider;
18822
+ if (isUnifiedBnUSDMigrateParams(params) && isEvmSpokeProviderType(spokeProvider)) {
18823
+ const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
18578
18824
  return await Erc20Service.isAllowanceValid(
18579
18825
  params.srcbnUSD,
18580
18826
  params.amount,
18581
- await evmSpokeProvider.walletProvider.getWalletAddress(),
18582
- evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
18583
- evmSpokeProvider
18827
+ walletAddress,
18828
+ isSonicSpokeProviderType(spokeProvider) ? spokeProvider.chainConfig.bnUSD : spokeProvider.chainConfig.addresses.assetManager,
18829
+ spokeProvider
18584
18830
  );
18585
18831
  }
18586
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider instanceof StellarSpokeProvider) {
18832
+ if (isUnifiedBnUSDMigrateParams(params) && isStellarSpokeProviderType(spokeProvider)) {
18587
18833
  return {
18588
18834
  ok: true,
18589
18835
  value: await StellarSpokeService.hasSufficientTrustline(params.srcbnUSD, params.amount, spokeProvider)
@@ -18598,49 +18844,37 @@ var MigrationService = class {
18598
18844
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
18599
18845
  invariant6__default.default(params.to.length > 0, "To address is required");
18600
18846
  invariant6__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
18601
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
18602
- const evmSpokeProvider = spokeProvider;
18847
+ if (isUnifiedBnUSDMigrateParams(params) && isEvmSpokeProviderType(spokeProvider)) {
18603
18848
  let spender;
18604
18849
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
18605
- if (spokeProvider instanceof SonicSpokeProvider) {
18606
- spender = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18850
+ if (isSonicSpokeProviderType(spokeProvider)) {
18851
+ spender = await SonicSpokeService.getUserRouter(
18852
+ wallet,
18853
+ spokeProvider
18854
+ );
18607
18855
  } else {
18608
- spender = evmSpokeProvider.chainConfig.addresses.assetManager;
18856
+ spender = spokeProvider.chainConfig.addresses.assetManager;
18609
18857
  }
18610
18858
  return await Erc20Service.isAllowanceValid(
18611
18859
  params.srcbnUSD,
18612
18860
  params.amount,
18613
18861
  wallet,
18614
18862
  spender,
18615
- evmSpokeProvider
18616
- );
18617
- }
18618
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
18619
- const evmSpokeProvider = spokeProvider;
18620
- let spender;
18621
- const wallet = await spokeProvider.walletProvider.getWalletAddress();
18622
- if (spokeProvider instanceof SonicSpokeProvider) {
18623
- spender = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18624
- } else {
18625
- spender = evmSpokeProvider.chainConfig.addresses.assetManager;
18626
- }
18627
- return await Erc20Service.isAllowanceValid(
18628
- params.srcbnUSD,
18629
- params.amount,
18630
- wallet,
18631
- spender,
18632
- evmSpokeProvider
18863
+ spokeProvider
18633
18864
  );
18634
18865
  }
18635
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider instanceof StellarSpokeProvider) {
18866
+ if (isUnifiedBnUSDMigrateParams(params) && isStellarSpokeProviderType(spokeProvider)) {
18636
18867
  return {
18637
18868
  ok: true,
18638
18869
  value: await StellarSpokeService.hasSufficientTrustline(params.srcbnUSD, params.amount, spokeProvider)
18639
18870
  };
18640
18871
  }
18641
- if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
18872
+ if (isSonicSpokeProviderType(spokeProvider) && isIcxCreateRevertMigrationParams(params)) {
18642
18873
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
18643
- const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18874
+ const userRouter = await SonicSpokeService.getUserRouter(
18875
+ wallet,
18876
+ spokeProvider
18877
+ );
18644
18878
  return await Erc20Service.isAllowanceValid(
18645
18879
  this.hubProvider.chainConfig.addresses.sodaToken,
18646
18880
  params.amount,
@@ -18686,13 +18920,12 @@ var MigrationService = class {
18686
18920
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
18687
18921
  invariant6__default.default(params.to.length > 0, "To address is required");
18688
18922
  invariant6__default.default(isUnifiedBnUSDMigrateParams(params), "Invalid params");
18689
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
18690
- const evmSpokeProvider = spokeProvider;
18923
+ if (isUnifiedBnUSDMigrateParams(params) && isEvmSpokeProviderType(spokeProvider)) {
18691
18924
  const result = await Erc20Service.approve(
18692
18925
  params.srcbnUSD,
18693
18926
  params.amount,
18694
- evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
18695
- evmSpokeProvider,
18927
+ isSonicSpokeProviderType(spokeProvider) ? spokeProvider.chainConfig.bnUSD : spokeProvider.chainConfig.addresses.assetManager,
18928
+ spokeProvider,
18696
18929
  raw
18697
18930
  );
18698
18931
  return {
@@ -18700,7 +18933,7 @@ var MigrationService = class {
18700
18933
  value: result
18701
18934
  };
18702
18935
  }
18703
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider instanceof StellarSpokeProvider) {
18936
+ if (isUnifiedBnUSDMigrateParams(params) && isStellarSpokeProviderType(spokeProvider)) {
18704
18937
  const result = await StellarSpokeService.requestTrustline(params.srcbnUSD, params.amount, spokeProvider, raw);
18705
18938
  return {
18706
18939
  ok: true,
@@ -18716,20 +18949,22 @@ var MigrationService = class {
18716
18949
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
18717
18950
  invariant6__default.default(params.to.length > 0, "To address is required");
18718
18951
  invariant6__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
18719
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
18720
- const evmSpokeProvider = spokeProvider;
18952
+ if (isUnifiedBnUSDMigrateParams(params) && isEvmSpokeProviderType(spokeProvider)) {
18721
18953
  let spender;
18722
18954
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
18723
- if (spokeProvider instanceof SonicSpokeProvider) {
18724
- spender = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18955
+ if (isSonicSpokeProviderType(spokeProvider)) {
18956
+ spender = await SonicSpokeService.getUserRouter(
18957
+ wallet,
18958
+ spokeProvider
18959
+ );
18725
18960
  } else {
18726
- spender = evmSpokeProvider.chainConfig.addresses.assetManager;
18961
+ spender = spokeProvider.chainConfig.addresses.assetManager;
18727
18962
  }
18728
18963
  const result = await Erc20Service.approve(
18729
18964
  params.srcbnUSD,
18730
18965
  params.amount,
18731
18966
  spender,
18732
- evmSpokeProvider,
18967
+ spokeProvider,
18733
18968
  raw
18734
18969
  );
18735
18970
  return {
@@ -18737,16 +18972,19 @@ var MigrationService = class {
18737
18972
  value: result
18738
18973
  };
18739
18974
  }
18740
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider instanceof StellarSpokeProvider) {
18975
+ if (isUnifiedBnUSDMigrateParams(params) && isStellarSpokeProviderType(spokeProvider)) {
18741
18976
  const result = await StellarSpokeService.requestTrustline(params.srcbnUSD, params.amount, spokeProvider, raw);
18742
18977
  return {
18743
18978
  ok: true,
18744
18979
  value: result
18745
18980
  };
18746
18981
  }
18747
- if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
18982
+ if (isSonicSpokeProviderType(spokeProvider) && isIcxCreateRevertMigrationParams(params)) {
18748
18983
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
18749
- const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18984
+ const userRouter = await SonicSpokeService.getUserRouter(
18985
+ wallet,
18986
+ spokeProvider
18987
+ );
18750
18988
  const result = await Erc20Service.approve(
18751
18989
  this.hubProvider.chainConfig.addresses.sodaToken,
18752
18990
  params.amount,
@@ -18819,7 +19057,7 @@ var MigrationService = class {
18819
19057
  */
18820
19058
  async migratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT, unchecked = false) {
18821
19059
  try {
18822
- const intentResult = await this.createMigratebnUSDIntent(params, spokeProvider, unchecked);
19060
+ const intentResult = await this.createMigratebnUSDIntent(params, spokeProvider, unchecked, false);
18823
19061
  if (!intentResult.ok) {
18824
19062
  return {
18825
19063
  ok: false,
@@ -18906,7 +19144,7 @@ var MigrationService = class {
18906
19144
  */
18907
19145
  async migrateIcxToSoda(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
18908
19146
  try {
18909
- const txResult = await this.createMigrateIcxToSodaIntent(params, spokeProvider);
19147
+ const txResult = await this.createMigrateIcxToSodaIntent(params, spokeProvider, false);
18910
19148
  if (!txResult.ok) {
18911
19149
  return {
18912
19150
  ok: false,
@@ -18970,7 +19208,7 @@ var MigrationService = class {
18970
19208
  */
18971
19209
  async revertMigrateSodaToIcx(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
18972
19210
  try {
18973
- const txResult = await this.createRevertSodaToIcxMigrationIntent(params, spokeProvider);
19211
+ const txResult = await this.createRevertSodaToIcxMigrationIntent(params, spokeProvider, false);
18974
19212
  if (!txResult.ok) {
18975
19213
  return txResult;
18976
19214
  }
@@ -19033,7 +19271,7 @@ var MigrationService = class {
19033
19271
  */
19034
19272
  async migrateBaln(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
19035
19273
  try {
19036
- const txResult = await this.createMigrateBalnIntent(params, spokeProvider);
19274
+ const txResult = await this.createMigrateBalnIntent(params, spokeProvider, false);
19037
19275
  if (!txResult.ok) {
19038
19276
  return {
19039
19277
  ok: false,
@@ -19296,7 +19534,7 @@ var MigrationService = class {
19296
19534
  params.address.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.address.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
19297
19535
  "Token must be wICX or native ICX token"
19298
19536
  );
19299
- invariant6__default.default(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
19537
+ invariant6__default.default(isIconSpokeProviderType(spokeProvider), "Spoke provider must be an IconSpokeProviderType");
19300
19538
  const availableAmount = await this.icxMigration.getAvailableAmount();
19301
19539
  if (availableAmount < params.amount) {
19302
19540
  throw new Error(
@@ -19354,7 +19592,10 @@ var MigrationService = class {
19354
19592
  async createRevertSodaToIcxMigrationIntent(params, spokeProvider, raw) {
19355
19593
  try {
19356
19594
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
19357
- const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
19595
+ const userRouter = await SonicSpokeService.getUserRouter(
19596
+ wallet,
19597
+ spokeProvider
19598
+ );
19358
19599
  const wICX = this.configService.spokeChainConfig[types.ICON_MAINNET_CHAIN_ID]?.addresses.wICX;
19359
19600
  invariant6__default.default(wICX, "wICX token not found");
19360
19601
  const data = this.icxMigration.revertMigration({
@@ -19785,6 +20026,7 @@ exports.EvmWalletAbstraction = EvmWalletAbstraction;
19785
20026
  exports.FEE_PERCENTAGE_SCALE = FEE_PERCENTAGE_SCALE;
19786
20027
  exports.HALF_RAY = HALF_RAY;
19787
20028
  exports.HALF_WAD = HALF_WAD;
20029
+ exports.HubService = HubService;
19788
20030
  exports.ICON_TX_RESULT_WAIT_MAX_RETRY = ICON_TX_RESULT_WAIT_MAX_RETRY;
19789
20031
  exports.IconBaseSpokeProvider = IconBaseSpokeProvider;
19790
20032
  exports.IconRawSpokeProvider = IconRawSpokeProvider;
@@ -19907,6 +20149,7 @@ exports.isEvmSpokeProviderType = isEvmSpokeProviderType;
19907
20149
  exports.isEvmUninitializedBrowserConfig = isEvmUninitializedBrowserConfig;
19908
20150
  exports.isEvmUninitializedConfig = isEvmUninitializedConfig;
19909
20151
  exports.isEvmUninitializedPrivateKeyConfig = isEvmUninitializedPrivateKeyConfig;
20152
+ exports.isHubSpokeProvider = isHubSpokeProvider;
19910
20153
  exports.isIconAddress = isIconAddress;
19911
20154
  exports.isIconRawSpokeProvider = isIconRawSpokeProvider;
19912
20155
  exports.isIconSpokeProvider = isIconSpokeProvider;