@sodax/sdk 1.0.2-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
  /**
@@ -13893,65 +13919,25 @@ var MoneyMarketService = class _MoneyMarketService {
13893
13919
  );
13894
13920
  }
13895
13921
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
13896
- if (spokeProvider instanceof StellarSpokeProvider && (params.action === "supply" || params.action === "repay")) {
13922
+ if (isStellarSpokeProviderType(spokeProvider) && (params.action === "supply" || params.action === "repay")) {
13897
13923
  return {
13898
13924
  ok: true,
13899
13925
  value: await StellarSpokeService.hasSufficientTrustline(params.token, params.amount, spokeProvider)
13900
13926
  };
13901
13927
  }
13902
- 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;
13903
13933
  return await Erc20Service.isAllowanceValid(
13904
13934
  params.token,
13905
13935
  params.amount,
13906
13936
  walletAddress,
13907
- spokeProvider.chainConfig.addresses.assetManager,
13937
+ spender,
13908
13938
  spokeProvider
13909
13939
  );
13910
13940
  }
13911
- if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
13912
- if (params.action === "withdraw") {
13913
- const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
13914
- params.token,
13915
- params.amount,
13916
- params.toChainId ?? spokeProvider.chainConfig.chain.id,
13917
- this.data,
13918
- this.configService
13919
- );
13920
- return await SonicSpokeService.isWithdrawApproved(
13921
- walletAddress,
13922
- withdrawInfo,
13923
- spokeProvider
13924
- );
13925
- }
13926
- if (params.action === "borrow") {
13927
- const borrowInfo = await SonicSpokeService.getBorrowInfo(
13928
- params.token,
13929
- params.amount,
13930
- params.toChainId ?? spokeProvider.chainConfig.chain.id,
13931
- this.data,
13932
- this.configService,
13933
- this.config
13934
- );
13935
- return await SonicSpokeService.isBorrowApproved(
13936
- walletAddress,
13937
- borrowInfo,
13938
- spokeProvider
13939
- );
13940
- }
13941
- if (params.action === "supply" || params.action === "repay") {
13942
- const userRouter = await SonicSpokeService.getUserRouter(
13943
- walletAddress,
13944
- spokeProvider
13945
- );
13946
- return await Erc20Service.isAllowanceValid(
13947
- params.token,
13948
- params.amount,
13949
- walletAddress,
13950
- userRouter,
13951
- spokeProvider
13952
- );
13953
- }
13954
- }
13955
13941
  return {
13956
13942
  ok: true,
13957
13943
  value: true
@@ -14007,7 +13993,7 @@ var MoneyMarketService = class _MoneyMarketService {
14007
13993
  );
14008
13994
  }
14009
13995
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
14010
- if (spokeProvider instanceof StellarSpokeProvider) {
13996
+ if (isStellarSpokeProviderType(spokeProvider)) {
14011
13997
  invariant6__default.default(
14012
13998
  params.action === "supply" || params.action === "repay",
14013
13999
  "Invalid action (only supply and repay are supported on stellar)"
@@ -14018,16 +14004,20 @@ var MoneyMarketService = class _MoneyMarketService {
14018
14004
  value: result
14019
14005
  };
14020
14006
  }
14021
- if (spokeProvider instanceof EvmSpokeProvider) {
14007
+ if (isEvmSpokeProviderType(spokeProvider) || isSonicSpokeProviderType(spokeProvider)) {
14022
14008
  invariant6__default.default(
14023
14009
  params.action === "supply" || params.action === "repay",
14024
14010
  "Invalid action (only supply and repay are supported on evm)"
14025
14011
  );
14026
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;
14027
14017
  const result = await Erc20Service.approve(
14028
14018
  params.token,
14029
14019
  params.amount,
14030
- spokeProvider.chainConfig.addresses.assetManager,
14020
+ spender,
14031
14021
  spokeProvider,
14032
14022
  raw
14033
14023
  );
@@ -14036,69 +14026,6 @@ var MoneyMarketService = class _MoneyMarketService {
14036
14026
  value: result
14037
14027
  };
14038
14028
  }
14039
- if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
14040
- invariant6__default.default(
14041
- params.action === "withdraw" || params.action === "borrow" || params.action === "supply" || params.action === "repay",
14042
- "Invalid action (only withdraw, borrow, supply and repay are supported on sonic)"
14043
- );
14044
- invariant6__default.default(viem.isAddress(params.token), "Invalid token address");
14045
- if (params.action === "withdraw") {
14046
- const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
14047
- params.token,
14048
- params.amount,
14049
- params?.toChainId ?? spokeProvider.chainConfig.chain.id,
14050
- this.data,
14051
- this.configService
14052
- );
14053
- const result = await SonicSpokeService.approveWithdraw(
14054
- walletAddress,
14055
- withdrawInfo,
14056
- spokeProvider,
14057
- raw
14058
- );
14059
- return {
14060
- ok: true,
14061
- value: result
14062
- };
14063
- }
14064
- if (params.action === "borrow") {
14065
- const borrowInfo = await SonicSpokeService.getBorrowInfo(
14066
- params.token,
14067
- params.amount,
14068
- params?.toChainId ?? spokeProvider.chainConfig.chain.id,
14069
- this.data,
14070
- this.configService,
14071
- this.config
14072
- );
14073
- const result = await SonicSpokeService.approveBorrow(
14074
- walletAddress,
14075
- borrowInfo,
14076
- spokeProvider,
14077
- raw
14078
- );
14079
- return {
14080
- ok: true,
14081
- value: result
14082
- };
14083
- }
14084
- if (params.action === "supply" || params.action === "repay") {
14085
- const userRouter = await SonicSpokeService.getUserRouter(
14086
- walletAddress,
14087
- spokeProvider
14088
- );
14089
- const result = await Erc20Service.approve(
14090
- params.token,
14091
- params.amount,
14092
- userRouter,
14093
- spokeProvider,
14094
- raw
14095
- );
14096
- return {
14097
- ok: true,
14098
- value: result
14099
- };
14100
- }
14101
- }
14102
14029
  return {
14103
14030
  ok: false,
14104
14031
  error: new Error("Approve only supported for EVM spoke chains")
@@ -14157,7 +14084,9 @@ var MoneyMarketService = class _MoneyMarketService {
14157
14084
  };
14158
14085
  }
14159
14086
  let intentTxHash = null;
14160
- 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 {
14161
14090
  const packetResult = await relayTxAndWaitPacket(
14162
14091
  txResult.value,
14163
14092
  spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
@@ -14178,8 +14107,6 @@ var MoneyMarketService = class _MoneyMarketService {
14178
14107
  };
14179
14108
  }
14180
14109
  intentTxHash = packetResult.value.dst_tx_hash;
14181
- } else {
14182
- intentTxHash = txResult.value;
14183
14110
  }
14184
14111
  return { ok: true, value: [txResult.value, intentTxHash] };
14185
14112
  } catch (error) {
@@ -14240,13 +14167,15 @@ var MoneyMarketService = class _MoneyMarketService {
14240
14167
  this.configService.isMoneyMarketSupportedToken(fromChainId, params.token),
14241
14168
  `Unsupported spoke chain (${fromChainId}) token: ${params.token}`
14242
14169
  );
14243
- const fromHubWallet = await deriveUserWalletAddress(this.hubProvider, fromChainId, fromAddress);
14244
- 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
+ ]);
14245
14174
  const data = this.buildSupplyData(fromChainId, params.token, params.amount, toHubWallet);
14246
14175
  const txResult = await SpokeService.deposit(
14247
14176
  {
14248
14177
  from: fromAddress,
14249
- to: fromChainId === this.hubProvider.chainConfig.chain.id ? void 0 : fromHubWallet,
14178
+ to: fromHubWallet,
14250
14179
  token: params.token,
14251
14180
  amount: params.amount,
14252
14181
  data
@@ -14326,7 +14255,7 @@ var MoneyMarketService = class _MoneyMarketService {
14326
14255
  if (spokeProvider.chainConfig.chain.id !== this.hubProvider.chainConfig.chain.id || params.toChainId && params.toAddress && params.toChainId !== this.hubProvider.chainConfig.chain.id) {
14327
14256
  const packetResult = await relayTxAndWaitPacket(
14328
14257
  txResult.value,
14329
- spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
14258
+ isSolanaSpokeProviderType(spokeProvider) ? txResult.data : void 0,
14330
14259
  spokeProvider,
14331
14260
  this.config.relayerApiEndpoint,
14332
14261
  timeout
@@ -14395,14 +14324,14 @@ var MoneyMarketService = class _MoneyMarketService {
14395
14324
  invariant6__default.default(params.action === "borrow", "Invalid action");
14396
14325
  invariant6__default.default(params.token.length > 0, "Token is required");
14397
14326
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
14398
- const fromChainId = spokeProvider.chainConfig.chain.id;
14399
- const fromAddress = await spokeProvider.walletProvider.getWalletAddress();
14327
+ const fromChainId = params.fromChainId ?? spokeProvider.chainConfig.chain.id;
14328
+ const fromAddress = params.fromAddress ?? await spokeProvider.walletProvider.getWalletAddress();
14400
14329
  const toChainId = params.toChainId ?? fromChainId;
14401
14330
  const toAddress = params.toAddress ?? fromAddress;
14402
14331
  const dstToken = this.configService.getMoneyMarketToken(toChainId, params.token);
14403
14332
  invariant6__default.default(dstToken, `Money market token not found for spoke chain (${toChainId}) token: ${params.token}`);
14404
14333
  const encodedToAddress = encodeAddress(toChainId, toAddress);
14405
- const fromHubWallet = await deriveUserWalletAddress(this.hubProvider, fromChainId, fromAddress);
14334
+ const fromHubWallet = await HubService.getUserHubWalletAddress(fromAddress, fromChainId, this.hubProvider);
14406
14335
  const data = this.buildBorrowData(fromHubWallet, encodedToAddress, dstToken.address, params.amount, toChainId);
14407
14336
  let txResult;
14408
14337
  if (fromChainId === this.hubProvider.chainConfig.chain.id && isSonicSpokeProviderType(spokeProvider)) {
@@ -14548,29 +14477,9 @@ var MoneyMarketService = class _MoneyMarketService {
14548
14477
  `Unsupported spoke chain (${toChainId}) token: ${params.token}`
14549
14478
  );
14550
14479
  const encodedToAddress = encodeAddress(toChainId, toAddress);
14551
- const fromHubWallet = await deriveUserWalletAddress(this.hubProvider, fromChainId, fromAddress);
14552
- let data;
14553
- if (spokeProvider instanceof SonicSpokeProvider) {
14554
- const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
14555
- params.token,
14556
- params.amount,
14557
- toChainId,
14558
- this.data,
14559
- this.configService
14560
- );
14561
- data = await SonicSpokeService.buildWithdrawData(
14562
- fromAddress,
14563
- withdrawInfo,
14564
- params.amount,
14565
- encodedToAddress,
14566
- toChainId,
14567
- spokeProvider,
14568
- this
14569
- );
14570
- } else {
14571
- data = this.buildWithdrawData(fromHubWallet, encodedToAddress, params.token, params.amount, toChainId);
14572
- }
14573
- 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);
14574
14483
  return {
14575
14484
  ok: true,
14576
14485
  value: txResult,
@@ -14710,13 +14619,15 @@ var MoneyMarketService = class _MoneyMarketService {
14710
14619
  this.configService.isMoneyMarketSupportedToken(fromChainId, params.token),
14711
14620
  `Unsupported spoke chain (${fromChainId}) token: ${params.token}`
14712
14621
  );
14713
- const toHubWallet = await deriveUserWalletAddress(this.hubProvider, toChainId, toAddress);
14714
- 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
+ ]);
14715
14626
  const data = this.buildRepayData(fromChainId, params.token, params.amount, toHubWallet);
14716
14627
  const txResult = await SpokeService.deposit(
14717
14628
  {
14718
14629
  from: fromAddress,
14719
- to: fromChainId === this.hubProvider.chainConfig.chain.id ? void 0 : fromHubWallet,
14630
+ to: fromHubWallet,
14720
14631
  token: params.token,
14721
14632
  amount: params.amount,
14722
14633
  data
@@ -15195,6 +15106,8 @@ var Sodax = class {
15195
15106
 
15196
15107
  // src/shared/services/hub/WalletAbstractionService.ts
15197
15108
  var WalletAbstractionService = class {
15109
+ constructor() {
15110
+ }
15198
15111
  /**
15199
15112
  * Gets the hub wallet address for a user based on their spoke chain address.
15200
15113
  * @param address - The user's address on the spoke chain
@@ -15219,6 +15132,40 @@ var WalletAbstractionService = class {
15219
15132
  );
15220
15133
  }
15221
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
+ };
15222
15169
  var SuiSpokeService = class _SuiSpokeService {
15223
15170
  constructor() {
15224
15171
  }
@@ -15859,6 +15806,9 @@ function parseToStroops(amount) {
15859
15806
  function sleep(ms) {
15860
15807
  return new Promise((resolve) => setTimeout(resolve, ms));
15861
15808
  }
15809
+ function isHubSpokeProvider(spokeProvider, hubProvider) {
15810
+ return spokeProvider.chainConfig.chain.id === hubProvider.chainConfig.chain.id;
15811
+ }
15862
15812
 
15863
15813
  // src/shared/types.ts
15864
15814
  var SolverIntentStatusCode = /* @__PURE__ */ ((SolverIntentStatusCode2) => {
@@ -16200,7 +16150,7 @@ var BridgeService = class {
16200
16150
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
16201
16151
  invariant6__default.default(params.srcAsset.length > 0, "Source asset is required");
16202
16152
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
16203
- if (spokeProvider instanceof EvmSpokeProvider) {
16153
+ if (isEvmSpokeProviderType(spokeProvider)) {
16204
16154
  invariant6__default.default(viem.isAddress(params.srcAsset), "Invalid source asset address for EVM chain");
16205
16155
  const allowanceResult = await Erc20Service.isAllowanceValid(
16206
16156
  params.srcAsset,
@@ -16223,7 +16173,7 @@ var BridgeService = class {
16223
16173
  value: allowanceResult.value
16224
16174
  };
16225
16175
  }
16226
- if (spokeProvider instanceof StellarSpokeProvider) {
16176
+ if (isStellarSpokeProviderType(spokeProvider)) {
16227
16177
  const allowanceResult = await StellarSpokeService.hasSufficientTrustline(
16228
16178
  params.srcAsset,
16229
16179
  params.amount,
@@ -16243,9 +16193,12 @@ var BridgeService = class {
16243
16193
  value: allowanceResult
16244
16194
  };
16245
16195
  }
16246
- if (spokeProvider instanceof SonicSpokeProvider) {
16196
+ if (isSonicSpokeProviderType(spokeProvider)) {
16247
16197
  invariant6__default.default(viem.isAddress(params.srcAsset), "Invalid source asset address for Sonic chain");
16248
- const userRouter = await SonicSpokeService.getUserRouter(walletAddress, spokeProvider);
16198
+ const userRouter = await SonicSpokeService.getUserRouter(
16199
+ walletAddress,
16200
+ spokeProvider
16201
+ );
16249
16202
  const allowanceResult = await Erc20Service.isAllowanceValid(
16250
16203
  params.srcAsset,
16251
16204
  params.amount,
@@ -16297,7 +16250,7 @@ var BridgeService = class {
16297
16250
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
16298
16251
  invariant6__default.default(params.srcAsset.length > 0, "Source asset is required");
16299
16252
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
16300
- if (spokeProvider instanceof EvmSpokeProvider) {
16253
+ if (isEvmSpokeProviderType(spokeProvider)) {
16301
16254
  invariant6__default.default(viem.isAddress(params.srcAsset), "Invalid source asset address for EVM chain");
16302
16255
  const result = await Erc20Service.approve(
16303
16256
  params.srcAsset,
@@ -16311,14 +16264,14 @@ var BridgeService = class {
16311
16264
  value: result
16312
16265
  };
16313
16266
  }
16314
- if (spokeProvider instanceof StellarSpokeProvider) {
16267
+ if (isStellarSpokeProviderType(spokeProvider)) {
16315
16268
  const result = await StellarSpokeService.requestTrustline(params.srcAsset, params.amount, spokeProvider, raw);
16316
16269
  return {
16317
16270
  ok: true,
16318
16271
  value: result
16319
16272
  };
16320
16273
  }
16321
- if (spokeProvider instanceof SonicSpokeProvider) {
16274
+ if (isSonicSpokeProviderType(spokeProvider)) {
16322
16275
  invariant6__default.default(viem.isAddress(params.srcAsset), "Invalid source asset address for Sonic chain");
16323
16276
  const userRouter = await SonicSpokeService.getUserRouter(
16324
16277
  walletAddress,
@@ -17100,7 +17053,7 @@ var StakingService = class {
17100
17053
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
17101
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;
17102
17055
  invariant6__default.default(targetToken, "Target token not found");
17103
- if (spokeProvider instanceof EvmSpokeProvider) {
17056
+ if (isEvmSpokeProviderType(spokeProvider)) {
17104
17057
  const allowanceResult = await Erc20Service.isAllowanceValid(
17105
17058
  targetToken,
17106
17059
  params.amount,
@@ -17122,7 +17075,7 @@ var StakingService = class {
17122
17075
  value: allowanceResult.value
17123
17076
  };
17124
17077
  }
17125
- if (spokeProvider instanceof SonicSpokeProvider) {
17078
+ if (isSonicSpokeProviderType(spokeProvider)) {
17126
17079
  const userRouter = await SonicSpokeService.getUserRouter(walletAddress, spokeProvider);
17127
17080
  const allowanceResult = await Erc20Service.isAllowanceValid(
17128
17081
  targetToken,
@@ -17145,7 +17098,7 @@ var StakingService = class {
17145
17098
  value: allowanceResult.value
17146
17099
  };
17147
17100
  }
17148
- if (spokeProvider instanceof StellarSpokeProvider) {
17101
+ if (isStellarSpokeProviderType(spokeProvider)) {
17149
17102
  return {
17150
17103
  ok: true,
17151
17104
  value: await StellarSpokeService.hasSufficientTrustline(targetToken, params.amount, spokeProvider)
@@ -17191,7 +17144,7 @@ var StakingService = class {
17191
17144
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
17192
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;
17193
17146
  invariant6__default.default(targetToken, "Target token not found");
17194
- if (spokeProvider instanceof EvmSpokeProvider) {
17147
+ if (isEvmSpokeProviderType(spokeProvider)) {
17195
17148
  const result = await Erc20Service.approve(
17196
17149
  targetToken,
17197
17150
  params.amount,
@@ -17204,7 +17157,7 @@ var StakingService = class {
17204
17157
  value: result
17205
17158
  };
17206
17159
  }
17207
- if (spokeProvider instanceof SonicSpokeProvider) {
17160
+ if (isSonicSpokeProviderType(spokeProvider)) {
17208
17161
  const userRouter = await SonicSpokeService.getUserRouter(
17209
17162
  walletAddress,
17210
17163
  spokeProvider
@@ -17215,7 +17168,7 @@ var StakingService = class {
17215
17168
  value: result
17216
17169
  };
17217
17170
  }
17218
- if (spokeProvider instanceof StellarSpokeProvider) {
17171
+ if (isStellarSpokeProviderType(spokeProvider)) {
17219
17172
  const result = await StellarSpokeService.requestTrustline(targetToken, params.amount, spokeProvider, raw);
17220
17173
  return {
17221
17174
  ok: true,
@@ -18860,23 +18813,23 @@ var MigrationService = class {
18860
18813
  isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
18861
18814
  "Invalid params"
18862
18815
  );
18863
- if (spokeProvider instanceof IconSpokeProvider && (isIcxMigrateParams(params) || isBalnMigrateParams(params))) {
18816
+ if (isIconSpokeProviderType(spokeProvider) && (isIcxMigrateParams(params) || isBalnMigrateParams(params))) {
18864
18817
  return {
18865
18818
  ok: true,
18866
18819
  value: true
18867
18820
  };
18868
18821
  }
18869
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
18870
- const evmSpokeProvider = spokeProvider;
18822
+ if (isUnifiedBnUSDMigrateParams(params) && isEvmSpokeProviderType(spokeProvider)) {
18823
+ const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
18871
18824
  return await Erc20Service.isAllowanceValid(
18872
18825
  params.srcbnUSD,
18873
18826
  params.amount,
18874
- await evmSpokeProvider.walletProvider.getWalletAddress(),
18875
- evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
18876
- evmSpokeProvider
18827
+ walletAddress,
18828
+ isSonicSpokeProviderType(spokeProvider) ? spokeProvider.chainConfig.bnUSD : spokeProvider.chainConfig.addresses.assetManager,
18829
+ spokeProvider
18877
18830
  );
18878
18831
  }
18879
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider instanceof StellarSpokeProvider) {
18832
+ if (isUnifiedBnUSDMigrateParams(params) && isStellarSpokeProviderType(spokeProvider)) {
18880
18833
  return {
18881
18834
  ok: true,
18882
18835
  value: await StellarSpokeService.hasSufficientTrustline(params.srcbnUSD, params.amount, spokeProvider)
@@ -18891,49 +18844,37 @@ var MigrationService = class {
18891
18844
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
18892
18845
  invariant6__default.default(params.to.length > 0, "To address is required");
18893
18846
  invariant6__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
18894
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
18895
- const evmSpokeProvider = spokeProvider;
18847
+ if (isUnifiedBnUSDMigrateParams(params) && isEvmSpokeProviderType(spokeProvider)) {
18896
18848
  let spender;
18897
18849
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
18898
- if (spokeProvider instanceof SonicSpokeProvider) {
18899
- spender = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18850
+ if (isSonicSpokeProviderType(spokeProvider)) {
18851
+ spender = await SonicSpokeService.getUserRouter(
18852
+ wallet,
18853
+ spokeProvider
18854
+ );
18900
18855
  } else {
18901
- spender = evmSpokeProvider.chainConfig.addresses.assetManager;
18856
+ spender = spokeProvider.chainConfig.addresses.assetManager;
18902
18857
  }
18903
18858
  return await Erc20Service.isAllowanceValid(
18904
18859
  params.srcbnUSD,
18905
18860
  params.amount,
18906
18861
  wallet,
18907
18862
  spender,
18908
- evmSpokeProvider
18909
- );
18910
- }
18911
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
18912
- const evmSpokeProvider = spokeProvider;
18913
- let spender;
18914
- const wallet = await spokeProvider.walletProvider.getWalletAddress();
18915
- if (spokeProvider instanceof SonicSpokeProvider) {
18916
- spender = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18917
- } else {
18918
- spender = evmSpokeProvider.chainConfig.addresses.assetManager;
18919
- }
18920
- return await Erc20Service.isAllowanceValid(
18921
- params.srcbnUSD,
18922
- params.amount,
18923
- wallet,
18924
- spender,
18925
- evmSpokeProvider
18863
+ spokeProvider
18926
18864
  );
18927
18865
  }
18928
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider instanceof StellarSpokeProvider) {
18866
+ if (isUnifiedBnUSDMigrateParams(params) && isStellarSpokeProviderType(spokeProvider)) {
18929
18867
  return {
18930
18868
  ok: true,
18931
18869
  value: await StellarSpokeService.hasSufficientTrustline(params.srcbnUSD, params.amount, spokeProvider)
18932
18870
  };
18933
18871
  }
18934
- if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
18872
+ if (isSonicSpokeProviderType(spokeProvider) && isIcxCreateRevertMigrationParams(params)) {
18935
18873
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
18936
- const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18874
+ const userRouter = await SonicSpokeService.getUserRouter(
18875
+ wallet,
18876
+ spokeProvider
18877
+ );
18937
18878
  return await Erc20Service.isAllowanceValid(
18938
18879
  this.hubProvider.chainConfig.addresses.sodaToken,
18939
18880
  params.amount,
@@ -18979,13 +18920,12 @@ var MigrationService = class {
18979
18920
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
18980
18921
  invariant6__default.default(params.to.length > 0, "To address is required");
18981
18922
  invariant6__default.default(isUnifiedBnUSDMigrateParams(params), "Invalid params");
18982
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
18983
- const evmSpokeProvider = spokeProvider;
18923
+ if (isUnifiedBnUSDMigrateParams(params) && isEvmSpokeProviderType(spokeProvider)) {
18984
18924
  const result = await Erc20Service.approve(
18985
18925
  params.srcbnUSD,
18986
18926
  params.amount,
18987
- evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
18988
- evmSpokeProvider,
18927
+ isSonicSpokeProviderType(spokeProvider) ? spokeProvider.chainConfig.bnUSD : spokeProvider.chainConfig.addresses.assetManager,
18928
+ spokeProvider,
18989
18929
  raw
18990
18930
  );
18991
18931
  return {
@@ -18993,7 +18933,7 @@ var MigrationService = class {
18993
18933
  value: result
18994
18934
  };
18995
18935
  }
18996
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider instanceof StellarSpokeProvider) {
18936
+ if (isUnifiedBnUSDMigrateParams(params) && isStellarSpokeProviderType(spokeProvider)) {
18997
18937
  const result = await StellarSpokeService.requestTrustline(params.srcbnUSD, params.amount, spokeProvider, raw);
18998
18938
  return {
18999
18939
  ok: true,
@@ -19009,20 +18949,22 @@ var MigrationService = class {
19009
18949
  invariant6__default.default(params.amount > 0n, "Amount must be greater than 0");
19010
18950
  invariant6__default.default(params.to.length > 0, "To address is required");
19011
18951
  invariant6__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
19012
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
19013
- const evmSpokeProvider = spokeProvider;
18952
+ if (isUnifiedBnUSDMigrateParams(params) && isEvmSpokeProviderType(spokeProvider)) {
19014
18953
  let spender;
19015
18954
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
19016
- if (spokeProvider instanceof SonicSpokeProvider) {
19017
- spender = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18955
+ if (isSonicSpokeProviderType(spokeProvider)) {
18956
+ spender = await SonicSpokeService.getUserRouter(
18957
+ wallet,
18958
+ spokeProvider
18959
+ );
19018
18960
  } else {
19019
- spender = evmSpokeProvider.chainConfig.addresses.assetManager;
18961
+ spender = spokeProvider.chainConfig.addresses.assetManager;
19020
18962
  }
19021
18963
  const result = await Erc20Service.approve(
19022
18964
  params.srcbnUSD,
19023
18965
  params.amount,
19024
18966
  spender,
19025
- evmSpokeProvider,
18967
+ spokeProvider,
19026
18968
  raw
19027
18969
  );
19028
18970
  return {
@@ -19030,16 +18972,19 @@ var MigrationService = class {
19030
18972
  value: result
19031
18973
  };
19032
18974
  }
19033
- if (isUnifiedBnUSDMigrateParams(params) && spokeProvider instanceof StellarSpokeProvider) {
18975
+ if (isUnifiedBnUSDMigrateParams(params) && isStellarSpokeProviderType(spokeProvider)) {
19034
18976
  const result = await StellarSpokeService.requestTrustline(params.srcbnUSD, params.amount, spokeProvider, raw);
19035
18977
  return {
19036
18978
  ok: true,
19037
18979
  value: result
19038
18980
  };
19039
18981
  }
19040
- if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
18982
+ if (isSonicSpokeProviderType(spokeProvider) && isIcxCreateRevertMigrationParams(params)) {
19041
18983
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
19042
- const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
18984
+ const userRouter = await SonicSpokeService.getUserRouter(
18985
+ wallet,
18986
+ spokeProvider
18987
+ );
19043
18988
  const result = await Erc20Service.approve(
19044
18989
  this.hubProvider.chainConfig.addresses.sodaToken,
19045
18990
  params.amount,
@@ -19112,7 +19057,7 @@ var MigrationService = class {
19112
19057
  */
19113
19058
  async migratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT, unchecked = false) {
19114
19059
  try {
19115
- const intentResult = await this.createMigratebnUSDIntent(params, spokeProvider, unchecked);
19060
+ const intentResult = await this.createMigratebnUSDIntent(params, spokeProvider, unchecked, false);
19116
19061
  if (!intentResult.ok) {
19117
19062
  return {
19118
19063
  ok: false,
@@ -19199,7 +19144,7 @@ var MigrationService = class {
19199
19144
  */
19200
19145
  async migrateIcxToSoda(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
19201
19146
  try {
19202
- const txResult = await this.createMigrateIcxToSodaIntent(params, spokeProvider);
19147
+ const txResult = await this.createMigrateIcxToSodaIntent(params, spokeProvider, false);
19203
19148
  if (!txResult.ok) {
19204
19149
  return {
19205
19150
  ok: false,
@@ -19263,7 +19208,7 @@ var MigrationService = class {
19263
19208
  */
19264
19209
  async revertMigrateSodaToIcx(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
19265
19210
  try {
19266
- const txResult = await this.createRevertSodaToIcxMigrationIntent(params, spokeProvider);
19211
+ const txResult = await this.createRevertSodaToIcxMigrationIntent(params, spokeProvider, false);
19267
19212
  if (!txResult.ok) {
19268
19213
  return txResult;
19269
19214
  }
@@ -19326,7 +19271,7 @@ var MigrationService = class {
19326
19271
  */
19327
19272
  async migrateBaln(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
19328
19273
  try {
19329
- const txResult = await this.createMigrateBalnIntent(params, spokeProvider);
19274
+ const txResult = await this.createMigrateBalnIntent(params, spokeProvider, false);
19330
19275
  if (!txResult.ok) {
19331
19276
  return {
19332
19277
  ok: false,
@@ -19589,7 +19534,7 @@ var MigrationService = class {
19589
19534
  params.address.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.address.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
19590
19535
  "Token must be wICX or native ICX token"
19591
19536
  );
19592
- 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");
19593
19538
  const availableAmount = await this.icxMigration.getAvailableAmount();
19594
19539
  if (availableAmount < params.amount) {
19595
19540
  throw new Error(
@@ -19647,7 +19592,10 @@ var MigrationService = class {
19647
19592
  async createRevertSodaToIcxMigrationIntent(params, spokeProvider, raw) {
19648
19593
  try {
19649
19594
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
19650
- const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
19595
+ const userRouter = await SonicSpokeService.getUserRouter(
19596
+ wallet,
19597
+ spokeProvider
19598
+ );
19651
19599
  const wICX = this.configService.spokeChainConfig[types.ICON_MAINNET_CHAIN_ID]?.addresses.wICX;
19652
19600
  invariant6__default.default(wICX, "wICX token not found");
19653
19601
  const data = this.icxMigration.revertMigration({
@@ -20078,6 +20026,7 @@ exports.EvmWalletAbstraction = EvmWalletAbstraction;
20078
20026
  exports.FEE_PERCENTAGE_SCALE = FEE_PERCENTAGE_SCALE;
20079
20027
  exports.HALF_RAY = HALF_RAY;
20080
20028
  exports.HALF_WAD = HALF_WAD;
20029
+ exports.HubService = HubService;
20081
20030
  exports.ICON_TX_RESULT_WAIT_MAX_RETRY = ICON_TX_RESULT_WAIT_MAX_RETRY;
20082
20031
  exports.IconBaseSpokeProvider = IconBaseSpokeProvider;
20083
20032
  exports.IconRawSpokeProvider = IconRawSpokeProvider;
@@ -20200,6 +20149,7 @@ exports.isEvmSpokeProviderType = isEvmSpokeProviderType;
20200
20149
  exports.isEvmUninitializedBrowserConfig = isEvmUninitializedBrowserConfig;
20201
20150
  exports.isEvmUninitializedConfig = isEvmUninitializedConfig;
20202
20151
  exports.isEvmUninitializedPrivateKeyConfig = isEvmUninitializedPrivateKeyConfig;
20152
+ exports.isHubSpokeProvider = isHubSpokeProvider;
20203
20153
  exports.isIconAddress = isIconAddress;
20204
20154
  exports.isIconRawSpokeProvider = isIconRawSpokeProvider;
20205
20155
  exports.isIconSpokeProvider = isIconSpokeProvider;