@sodax/sdk 0.0.1-rc.24 → 0.0.1-rc.26

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
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var viem = require('viem');
4
- var invariant10 = require('tiny-invariant');
4
+ var invariant11 = require('tiny-invariant');
5
5
  var bcs = require('@mysten/sui/bcs');
6
6
  var web3_js = require('@solana/web3.js');
7
7
  var stellarSdk = require('@stellar/stellar-sdk');
@@ -39,7 +39,7 @@ function _interopNamespace(e) {
39
39
  return Object.freeze(n);
40
40
  }
41
41
 
42
- var invariant10__default = /*#__PURE__*/_interopDefault(invariant10);
42
+ var invariant11__default = /*#__PURE__*/_interopDefault(invariant11);
43
43
  var IconSdkRaw__namespace = /*#__PURE__*/_interopNamespace(IconSdkRaw);
44
44
  var rlp__namespace = /*#__PURE__*/_interopNamespace(rlp);
45
45
  var anchor__namespace = /*#__PURE__*/_interopNamespace(anchor);
@@ -6169,16 +6169,16 @@ function calculateFeeAmount(inputAmount, fee) {
6169
6169
  if (!fee) {
6170
6170
  return 0n;
6171
6171
  }
6172
- invariant10__default.default(inputAmount > 0n, "Input amount must be greater than 0");
6172
+ invariant11__default.default(inputAmount > 0n, "Input amount must be greater than 0");
6173
6173
  let feeAmount = 0n;
6174
6174
  if (isPartnerFeeAmount(fee)) {
6175
- invariant10__default.default(
6175
+ invariant11__default.default(
6176
6176
  fee.amount >= 0 && fee.amount <= inputAmount,
6177
6177
  `Fee amount must be greater than 0 and less than or equal to the input amount: ${fee.amount}`
6178
6178
  );
6179
6179
  feeAmount = fee.amount;
6180
6180
  } else if (isPartnerFeePercentage(fee)) {
6181
- invariant10__default.default(
6181
+ invariant11__default.default(
6182
6182
  fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
6183
6183
  `Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
6184
6184
  );
@@ -6187,8 +6187,8 @@ function calculateFeeAmount(inputAmount, fee) {
6187
6187
  return feeAmount;
6188
6188
  }
6189
6189
  function adjustAmountByFee(amount, fee, quoteType) {
6190
- invariant10__default.default(amount > 0n, "Amount must be greater than 0");
6191
- invariant10__default.default(quoteType === "exact_input" || quoteType === "exact_output", "Invalid quote type");
6190
+ invariant11__default.default(amount > 0n, "Amount must be greater than 0");
6191
+ invariant11__default.default(quoteType === "exact_input" || quoteType === "exact_output", "Invalid quote type");
6192
6192
  if (quoteType === "exact_input") {
6193
6193
  return amount - calculateFeeAmount(amount, fee);
6194
6194
  }
@@ -6331,6 +6331,7 @@ var hubChainConfig = {
6331
6331
  sodaToken: "0x7c7d53eecda37a87ce0d5bf8e0b24512a48dc963"
6332
6332
  },
6333
6333
  nativeToken: "0x0000000000000000000000000000000000000000",
6334
+ wrappedNativeToken: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38",
6334
6335
  supportedTokens: []
6335
6336
  }
6336
6337
  };
@@ -6827,6 +6828,7 @@ var spokeChainConfig = {
6827
6828
  [types.SUI_MAINNET_CHAIN_ID]: {
6828
6829
  addresses: {
6829
6830
  connection: "0xf3b1e696a66d02cb776dc15aae73c68bc8f03adcb6ba0ec7f6332d9d90a6a3d2::connectionv3::0x3ee76d13909ac58ae13baab4c9be5a5142818d9a387aed641825e5d4356969bf",
6831
+ assetManagerId: "0xa17a409164d1676db71b411ab50813ba2c7dd547d2df538c699049566f1ff922::asset_manager::0xcb7346339340b7f8dea40fcafb70721dc2fcfa7e8626a89fd954d46c1f928b61",
6830
6832
  assetManager: "0x897f911a4b7691870a1a2513af7e85fdee8de275615c77068fd8b90b8e78c678::asset_manager::0xcb7346339340b7f8dea40fcafb70721dc2fcfa7e8626a89fd954d46c1f928b61",
6831
6833
  xTokenManager: "",
6832
6834
  rateLimit: "",
@@ -9250,6 +9252,32 @@ var EvmSpokeService = class _EvmSpokeService {
9250
9252
  args: [token]
9251
9253
  });
9252
9254
  }
9255
+ /**
9256
+ * Generate simulation parameters for deposit from EvmSpokeDepositParams.
9257
+ * @param {EvmSpokeDepositParams} params - The deposit parameters.
9258
+ * @param {EvmSpokeProvider} spokeProvider - The provider for the spoke chain.
9259
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9260
+ * @returns {Promise<DepositSimulationParams>} The simulation parameters.
9261
+ */
9262
+ static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
9263
+ const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9264
+ spokeProvider.chainConfig.chain.id,
9265
+ params.from,
9266
+ hubProvider
9267
+ );
9268
+ return {
9269
+ spokeChainID: spokeProvider.chainConfig.chain.id,
9270
+ token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
9271
+ from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
9272
+ to,
9273
+ amount: params.amount,
9274
+ data: params.data,
9275
+ srcAddress: encodeAddress(
9276
+ spokeProvider.chainConfig.chain.id,
9277
+ spokeProvider.chainConfig.addresses.assetManager
9278
+ )
9279
+ };
9280
+ }
9253
9281
  /**
9254
9282
  * Calls a contract on the spoke chain using the user's wallet.
9255
9283
  * @param {HubAddress} from - The address of the user on the hub chain.
@@ -9372,6 +9400,32 @@ var InjectiveSpokeService = class _InjectiveSpokeService {
9372
9400
  raw
9373
9401
  );
9374
9402
  }
9403
+ /**
9404
+ * Generate simulation parameters for deposit from InjectiveSpokeDepositParams.
9405
+ * @param {InjectiveSpokeDepositParams} params - The deposit parameters.
9406
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9407
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9408
+ * @returns {Promise<DepositSimulationParams>} The simulation parameters.
9409
+ */
9410
+ static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
9411
+ const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9412
+ spokeProvider.chainConfig.chain.id,
9413
+ viem.toHex(Buffer.from(params.from, "utf-8")),
9414
+ hubProvider
9415
+ );
9416
+ return {
9417
+ spokeChainID: spokeProvider.chainConfig.chain.id,
9418
+ token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
9419
+ from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
9420
+ to,
9421
+ amount: params.amount,
9422
+ data: params.data,
9423
+ srcAddress: encodeAddress(
9424
+ spokeProvider.chainConfig.chain.id,
9425
+ spokeProvider.chainConfig.addresses.assetManager
9426
+ )
9427
+ };
9428
+ }
9375
9429
  /**
9376
9430
  * Get the balance of the token that deposited in the spoke chain Asset Manager.
9377
9431
  * @param {Address} token - The address of the token to get the balance of.
@@ -9509,6 +9563,32 @@ var IconSpokeService = class _IconSpokeService {
9509
9563
  const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
9510
9564
  return _IconSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
9511
9565
  }
9566
+ /**
9567
+ * Generate simulation parameters for deposit from IconSpokeDepositParams.
9568
+ * @param {IconSpokeDepositParams} params - The deposit parameters.
9569
+ * @param {IconSpokeProvider} spokeProvider - The provider for the spoke chain.
9570
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9571
+ * @returns {Promise<DepositSimulationParams>} The simulation parameters.
9572
+ */
9573
+ static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
9574
+ const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9575
+ spokeProvider.chainConfig.chain.id,
9576
+ getIconAddressBytes(params.from),
9577
+ hubProvider
9578
+ );
9579
+ return {
9580
+ spokeChainID: spokeProvider.chainConfig.chain.id,
9581
+ token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
9582
+ from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
9583
+ to,
9584
+ amount: params.amount,
9585
+ data: params.data,
9586
+ srcAddress: encodeAddress(
9587
+ spokeProvider.chainConfig.chain.id,
9588
+ spokeProvider.chainConfig.addresses.assetManager
9589
+ )
9590
+ };
9591
+ }
9512
9592
  /**
9513
9593
  * Transfers tokens to the hub chain.
9514
9594
  */
@@ -9709,6 +9789,32 @@ var SolanaSpokeService = class _SolanaSpokeService {
9709
9789
  const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
9710
9790
  return _SolanaSpokeService.call(BigInt(relayId), from, viem.keccak256(payload), spokeProvider, raw);
9711
9791
  }
9792
+ /**
9793
+ * Generate simulation parameters for deposit from SolanaSpokeDepositParams.
9794
+ * @param {SolanaSpokeDepositParams} params - The deposit parameters.
9795
+ * @param {SolanaSpokeProvider} spokeProvider - The provider for the spoke chain.
9796
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9797
+ * @returns {Promise<DepositSimulationParams>} The simulation parameters.
9798
+ */
9799
+ static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
9800
+ const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9801
+ spokeProvider.chainConfig.chain.id,
9802
+ encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
9803
+ hubProvider
9804
+ );
9805
+ return {
9806
+ spokeChainID: spokeProvider.chainConfig.chain.id,
9807
+ token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
9808
+ from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
9809
+ to,
9810
+ amount: params.amount,
9811
+ data: params.data,
9812
+ srcAddress: encodeAddress(
9813
+ spokeProvider.chainConfig.chain.id,
9814
+ spokeProvider.chainConfig.addresses.assetManager
9815
+ )
9816
+ };
9817
+ }
9712
9818
  static async transfer({ token, recipient, amount, data }, spokeProvider, raw) {
9713
9819
  let depositInstruction;
9714
9820
  const amountBN = new BN__default.default(amount);
@@ -9877,6 +9983,32 @@ var StellarSpokeService = class _StellarSpokeService {
9877
9983
  static async getDeposit(token, spokeProvider) {
9878
9984
  return BigInt(await spokeProvider.getBalance(token));
9879
9985
  }
9986
+ /**
9987
+ * Generate simulation parameters for deposit from StellarSpokeDepositParams.
9988
+ * @param {StellarSpokeDepositParams} params - The deposit parameters.
9989
+ * @param {StellarSpokeProvider} spokeProvider - The provider for the spoke chain.
9990
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9991
+ * @returns {Promise<DepositSimulationParams>} The simulation parameters.
9992
+ */
9993
+ static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
9994
+ const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9995
+ spokeProvider.chainConfig.chain.id,
9996
+ params.from,
9997
+ hubProvider
9998
+ );
9999
+ return {
10000
+ spokeChainID: spokeProvider.chainConfig.chain.id,
10001
+ token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
10002
+ from: params.from,
10003
+ to,
10004
+ amount: params.amount,
10005
+ data: params.data,
10006
+ srcAddress: encodeAddress(
10007
+ spokeProvider.chainConfig.chain.id,
10008
+ spokeProvider.chainConfig.addresses.assetManager
10009
+ )
10010
+ };
10011
+ }
9880
10012
  /**
9881
10013
  * Calls a contract on the spoke chain using the user's wallet.
9882
10014
  * @param from - The address of the user on the hub chain.
@@ -9959,6 +10091,30 @@ var SuiSpokeService = class _SuiSpokeService {
9959
10091
  static async getDeposit(token, spokeProvider) {
9960
10092
  return spokeProvider.getBalance(token);
9961
10093
  }
10094
+ /**
10095
+ * Generate simulation parameters for deposit from SuiSpokeDepositParams.
10096
+ * @param {SuiSpokeDepositParams} params - The deposit parameters.
10097
+ * @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
10098
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
10099
+ * @returns {Promise<DepositSimulationParams>} The simulation parameters.
10100
+ */
10101
+ static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
10102
+ const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
10103
+ spokeProvider.chainConfig.chain.id,
10104
+ params.from,
10105
+ hubProvider
10106
+ );
10107
+ const encoder = new TextEncoder();
10108
+ return {
10109
+ spokeChainID: spokeProvider.chainConfig.chain.id,
10110
+ token: viem.toHex(encoder.encode(params.token)),
10111
+ from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
10112
+ to,
10113
+ amount: params.amount,
10114
+ data: params.data,
10115
+ srcAddress: viem.toHex(encoder.encode(spokeProvider.chainConfig.addresses.assetManagerId))
10116
+ };
10117
+ }
9962
10118
  /**
9963
10119
  * Calls a contract on the spoke chain using the user's wallet.
9964
10120
  * @param {HubAddress} from - The address of the user on the spoke chain.
@@ -10113,6 +10269,58 @@ var SonicSpokeService = class _SonicSpokeService {
10113
10269
  }
10114
10270
  return spokeProvider.walletProvider.sendTransaction(rawTx);
10115
10271
  }
10272
+ static async createSwapIntent(createIntentParams, creatorHubWalletAddress, solverConfig2, fee, spokeProvider, hubProvider, raw) {
10273
+ let inputToken = getHubAssetInfo(createIntentParams.srcChain, createIntentParams.inputToken)?.asset;
10274
+ if (createIntentParams.srcChain === hubProvider.chainConfig.chain.id && createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase()) {
10275
+ inputToken = hubProvider.chainConfig.nativeToken;
10276
+ }
10277
+ const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
10278
+ invariant11__default.default(
10279
+ inputToken,
10280
+ `hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
10281
+ );
10282
+ invariant11__default.default(
10283
+ outputToken,
10284
+ `hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
10285
+ );
10286
+ const [feeData, feeAmount] = EvmSolverService.createIntentFeeData(fee, createIntentParams.inputAmount);
10287
+ const intentsContract = solverConfig2.intentsContract;
10288
+ const intent = {
10289
+ ...createIntentParams,
10290
+ inputToken,
10291
+ outputToken,
10292
+ inputAmount: createIntentParams.inputAmount - feeAmount,
10293
+ srcChain: getIntentRelayChainId(createIntentParams.srcChain),
10294
+ dstChain: getIntentRelayChainId(createIntentParams.dstChain),
10295
+ srcAddress: encodeAddress(createIntentParams.srcChain, createIntentParams.srcAddress),
10296
+ dstAddress: encodeAddress(createIntentParams.dstChain, createIntentParams.dstAddress),
10297
+ intentId: randomUint256(),
10298
+ creator: creatorHubWalletAddress,
10299
+ data: feeData
10300
+ // fee amount will be deducted from the input amount
10301
+ };
10302
+ const txData = EvmSolverService.encodeCreateIntent(intent, intentsContract);
10303
+ const rawTx = {
10304
+ from: await spokeProvider.walletProvider.getWalletAddress(),
10305
+ to: txData.address,
10306
+ data: txData.data,
10307
+ value: createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase() ? createIntentParams.inputAmount : 0n
10308
+ };
10309
+ if (raw) {
10310
+ return [
10311
+ rawTx,
10312
+ intent,
10313
+ feeAmount,
10314
+ txData.data
10315
+ ];
10316
+ }
10317
+ return [
10318
+ await spokeProvider.walletProvider.sendTransaction(rawTx),
10319
+ intent,
10320
+ feeAmount,
10321
+ txData.data
10322
+ ];
10323
+ }
10116
10324
  /**
10117
10325
  * Get the balance of the token in the spoke chain.
10118
10326
  * @param {Address} token - The address of the token to get the balance of.
@@ -10474,9 +10682,7 @@ function isBalnMigrateParams(value) {
10474
10682
  function isIcxCreateRevertMigrationParams(value) {
10475
10683
  return typeof value === "object" && value !== null && "amount" in value && "to" in value;
10476
10684
  }
10477
-
10478
- // src/services/spoke/SpokeService.ts
10479
- var SpokeService = class {
10685
+ var SpokeService = class _SpokeService {
10480
10686
  constructor() {
10481
10687
  }
10482
10688
  /**
@@ -10530,14 +10736,99 @@ var SpokeService = class {
10530
10736
  }
10531
10737
  throw new Error("Invalid spoke provider");
10532
10738
  }
10739
+ /**
10740
+
10741
+ * Encodes transfer data using RLP encoding to match Solidity Transfer struct.
10742
+ * @param {Hex} token - The token contract address.
10743
+ * @param {Hex} from - The sender address.
10744
+ * @param {Hex} to - The recipient address.
10745
+ * @param {bigint} amount - The transfer amount.
10746
+ * @param {Hex} data - The encoded data payload.
10747
+ * @returns {Promise<Hex>} A promise that resolves to the RLP encoded transfer data.
10748
+ */
10749
+ static encodeTransfer(token, from, to, amount, data) {
10750
+ const rlpInput = [
10751
+ token,
10752
+ // token (bytes)
10753
+ from,
10754
+ // from (bytes)
10755
+ to,
10756
+ // to (bytes)
10757
+ amount,
10758
+ // amount (uint256)
10759
+ data
10760
+ // data (bytes)
10761
+ ];
10762
+ const rlpEncodedData = rlp__namespace.encode(rlpInput);
10763
+ return `0x${Buffer.from(rlpEncodedData).toString("hex")}`;
10764
+ }
10765
+ static async simulateDeposit(params, hubProvider) {
10766
+ const chainId = getIntentRelayChainId(params.spokeChainID);
10767
+ const hubAssetManager = hubProvider.chainConfig.addresses.assetManager;
10768
+ const payload = _SpokeService.encodeTransfer(params.token, params.from, params.to, params.amount, params.data);
10769
+ return _SpokeService.simulateRecvMessage(
10770
+ { target: hubAssetManager, srcChainId: chainId, srcAddress: params.srcAddress, payload },
10771
+ hubProvider
10772
+ );
10773
+ }
10774
+ /**
10775
+ * Simulates receiving a message without signature verification.
10776
+ * This function calls simulateRecvMessage which always reverts with 'Simulation completed'.
10777
+ * @param {bigint} srcChainId - The chain ID of the originating chain.
10778
+ * @param {Hex} srcAddress - The address of the sender on the originating chain.
10779
+ * @param {Hex} payload - The encoded payload containing call data (from encodeTransfer).
10780
+ * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
10781
+ * @returns {Promise<{ success: boolean; error?: string }>} Result of the simulation.
10782
+ */
10783
+ static async simulateRecvMessage(params, hubProvider) {
10784
+ try {
10785
+ const result = await hubProvider.publicClient.call({
10786
+ to: params.target,
10787
+ data: viem.encodeFunctionData({
10788
+ abi: [
10789
+ {
10790
+ name: "simulateRecvMessage",
10791
+ type: "function",
10792
+ stateMutability: "nonpayable",
10793
+ inputs: [
10794
+ { name: "srcChainId", type: "uint256" },
10795
+ { name: "srcAddress", type: "bytes" },
10796
+ { name: "payload", type: "bytes" }
10797
+ ],
10798
+ outputs: []
10799
+ }
10800
+ ],
10801
+ functionName: "simulateRecvMessage",
10802
+ args: [params.srcChainId, params.srcAddress, params.payload]
10803
+ })
10804
+ });
10805
+ console.warn("simulateRecvMessage did not revert as expected", { result });
10806
+ return {
10807
+ success: false,
10808
+ error: 'Function should have reverted with "Simulation completed"'
10809
+ };
10810
+ } catch (error) {
10811
+ if (error instanceof Error && error.message?.includes("Simulation completed")) {
10812
+ console.warn("simulateRecvMessage completed successfully with expected revert");
10813
+ return { success: true };
10814
+ }
10815
+ console.error("simulateRecvMessage failed with unexpected error:", error);
10816
+ return {
10817
+ success: false,
10818
+ error: error instanceof Error ? error.message || "Unknown simulation error" : "Unknown simulation error"
10819
+ };
10820
+ }
10821
+ }
10533
10822
  /**
10534
10823
  * Deposit tokens to the spoke chain.
10535
10824
  * @param {GetSpokeDepositParamsType<T extends SpokeProvider>} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
10536
10825
  * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
10537
10826
  * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
10827
+ * @param {boolean} raw - Whether to return raw transaction data.
10828
+ * @param {boolean} skipSimulation - Whether to skip deposit simulation (optional, defaults to false).
10538
10829
  * @returns {Promise<Hash>} A promise that resolves to the transaction hash.
10539
10830
  */
10540
- static async deposit(params, spokeProvider, hubProvider, raw) {
10831
+ static async deposit(params, spokeProvider, hubProvider, raw, skipSimulation = false) {
10541
10832
  if (spokeProvider instanceof SonicSpokeProvider) {
10542
10833
  return SonicSpokeService.deposit(
10543
10834
  params,
@@ -10546,6 +10837,7 @@ var SpokeService = class {
10546
10837
  );
10547
10838
  }
10548
10839
  if (spokeProvider instanceof EvmSpokeProvider) {
10840
+ await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
10549
10841
  return EvmSpokeService.deposit(
10550
10842
  params,
10551
10843
  spokeProvider,
@@ -10554,14 +10846,11 @@ var SpokeService = class {
10554
10846
  );
10555
10847
  }
10556
10848
  if (spokeProvider instanceof InjectiveSpokeProvider) {
10557
- return InjectiveSpokeService.deposit(
10558
- params,
10559
- spokeProvider,
10560
- hubProvider,
10561
- raw
10562
- );
10849
+ await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
10850
+ return InjectiveSpokeService.deposit(params, spokeProvider, hubProvider, raw);
10563
10851
  }
10564
10852
  if (spokeProvider instanceof IconSpokeProvider) {
10853
+ await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
10565
10854
  return IconSpokeService.deposit(
10566
10855
  params,
10567
10856
  spokeProvider,
@@ -10570,6 +10859,7 @@ var SpokeService = class {
10570
10859
  );
10571
10860
  }
10572
10861
  if (spokeProvider instanceof SuiSpokeProvider) {
10862
+ await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
10573
10863
  return SuiSpokeService.deposit(
10574
10864
  params,
10575
10865
  spokeProvider,
@@ -10578,6 +10868,7 @@ var SpokeService = class {
10578
10868
  );
10579
10869
  }
10580
10870
  if (spokeProvider instanceof SolanaSpokeProvider) {
10871
+ await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
10581
10872
  return SolanaSpokeService.deposit(
10582
10873
  params,
10583
10874
  spokeProvider,
@@ -10586,6 +10877,7 @@ var SpokeService = class {
10586
10877
  );
10587
10878
  }
10588
10879
  if (spokeProvider instanceof StellarSpokeProvider) {
10880
+ await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
10589
10881
  return StellarSpokeService.deposit(
10590
10882
  params,
10591
10883
  spokeProvider,
@@ -10595,6 +10887,60 @@ var SpokeService = class {
10595
10887
  }
10596
10888
  throw new Error("Invalid spoke provider");
10597
10889
  }
10890
+ static getSimulateDepositParams(params, spokeProvider, hubProvider) {
10891
+ if (spokeProvider instanceof EvmSpokeProvider) {
10892
+ return EvmSpokeService.getSimulateDepositParams(
10893
+ params,
10894
+ spokeProvider,
10895
+ hubProvider
10896
+ );
10897
+ }
10898
+ if (spokeProvider instanceof InjectiveSpokeProvider) {
10899
+ return InjectiveSpokeService.getSimulateDepositParams(
10900
+ params,
10901
+ spokeProvider,
10902
+ hubProvider
10903
+ );
10904
+ }
10905
+ if (spokeProvider instanceof IconSpokeProvider) {
10906
+ return IconSpokeService.getSimulateDepositParams(
10907
+ params,
10908
+ spokeProvider,
10909
+ hubProvider
10910
+ );
10911
+ }
10912
+ if (spokeProvider instanceof SuiSpokeProvider) {
10913
+ return SuiSpokeService.getSimulateDepositParams(
10914
+ params,
10915
+ spokeProvider,
10916
+ hubProvider
10917
+ );
10918
+ }
10919
+ if (spokeProvider instanceof SolanaSpokeProvider) {
10920
+ return SolanaSpokeService.getSimulateDepositParams(
10921
+ params,
10922
+ spokeProvider,
10923
+ hubProvider
10924
+ );
10925
+ }
10926
+ if (spokeProvider instanceof StellarSpokeProvider) {
10927
+ return StellarSpokeService.getSimulateDepositParams(
10928
+ params,
10929
+ spokeProvider,
10930
+ hubProvider
10931
+ );
10932
+ }
10933
+ throw new Error("Invalid spoke provider");
10934
+ }
10935
+ static async verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation) {
10936
+ if (!skipSimulation) {
10937
+ const simulationParams = await _SpokeService.getSimulateDepositParams(params, spokeProvider, hubProvider);
10938
+ const result = await _SpokeService.simulateDeposit(simulationParams, hubProvider);
10939
+ if (!result.success) {
10940
+ throw new Error("Simulation failed", { cause: result });
10941
+ }
10942
+ }
10943
+ }
10598
10944
  /**
10599
10945
  * Get the balance of the token in the spoke chain.
10600
10946
  * @param {Address} token - The address of the token to get the balance of.
@@ -10633,14 +10979,16 @@ var SpokeService = class {
10633
10979
  * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
10634
10980
  * @returns {Promise<Hash>} A promise that resolves to the transaction hash.
10635
10981
  */
10636
- static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
10982
+ static async callWallet(from, payload, spokeProvider, hubProvider, raw, skipSimulation = false) {
10637
10983
  if (isSonicSpokeProvider(spokeProvider)) {
10638
10984
  return await SonicSpokeService.callWallet(payload, spokeProvider, raw);
10639
10985
  }
10640
10986
  if (isEvmSpokeProvider(spokeProvider)) {
10987
+ await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
10641
10988
  return await EvmSpokeService.callWallet(from, payload, spokeProvider, hubProvider);
10642
10989
  }
10643
10990
  if (isInjectiveSpokeProvider(spokeProvider)) {
10991
+ await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
10644
10992
  return await InjectiveSpokeService.callWallet(
10645
10993
  from,
10646
10994
  payload,
@@ -10650,12 +10998,15 @@ var SpokeService = class {
10650
10998
  );
10651
10999
  }
10652
11000
  if (isIconSpokeProvider(spokeProvider)) {
11001
+ await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
10653
11002
  return await IconSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
10654
11003
  }
10655
11004
  if (isSuiSpokeProvider(spokeProvider)) {
11005
+ await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
10656
11006
  return await SuiSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
10657
11007
  }
10658
11008
  if (isSolanaSpokeProvider(spokeProvider)) {
11009
+ await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
10659
11010
  return await SolanaSpokeService.callWallet(
10660
11011
  from,
10661
11012
  payload,
@@ -10665,10 +11016,27 @@ var SpokeService = class {
10665
11016
  );
10666
11017
  }
10667
11018
  if (isStellarSpokeProvider(spokeProvider)) {
11019
+ await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
10668
11020
  return await StellarSpokeService.callWallet(from, payload, spokeProvider, hubProvider);
10669
11021
  }
10670
11022
  throw new Error("Invalid spoke provider");
10671
11023
  }
11024
+ static async verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation) {
11025
+ if (!skipSimulation) {
11026
+ const result = await _SpokeService.simulateRecvMessage(
11027
+ {
11028
+ target: from,
11029
+ srcChainId: getIntentRelayChainId(spokeProvider.chainConfig.chain.id),
11030
+ srcAddress: await spokeProvider.walletProvider.getWalletAddressBytes(),
11031
+ payload
11032
+ },
11033
+ hubProvider
11034
+ );
11035
+ if (!result.success) {
11036
+ throw new Error("Simulation failed", { cause: result });
11037
+ }
11038
+ }
11039
+ }
10672
11040
  };
10673
11041
  async function postRequest(payload, apiUrl) {
10674
11042
  const response = await retry(
@@ -10683,19 +11051,19 @@ async function postRequest(payload, apiUrl) {
10683
11051
  return response.json();
10684
11052
  }
10685
11053
  async function submitTransaction(payload, apiUrl) {
10686
- invariant10__default.default(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
10687
- invariant10__default.default(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
11054
+ invariant11__default.default(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
11055
+ invariant11__default.default(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
10688
11056
  return postRequest(payload, apiUrl);
10689
11057
  }
10690
11058
  async function getTransactionPackets(payload, apiUrl) {
10691
- invariant10__default.default(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
10692
- invariant10__default.default(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
11059
+ invariant11__default.default(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
11060
+ invariant11__default.default(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
10693
11061
  return postRequest(payload, apiUrl);
10694
11062
  }
10695
11063
  async function getPacket(payload, apiUrl) {
10696
- invariant10__default.default(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
10697
- invariant10__default.default(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
10698
- invariant10__default.default(payload.params.conn_sn.length > 0, "Invalid input parameters. conn_sn empty");
11064
+ invariant11__default.default(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
11065
+ invariant11__default.default(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
11066
+ invariant11__default.default(payload.params.conn_sn.length > 0, "Invalid input parameters. conn_sn empty");
10699
11067
  return postRequest(payload, apiUrl);
10700
11068
  }
10701
11069
  async function waitUntilIntentExecuted(payload) {
@@ -10820,14 +11188,17 @@ var EvmSolverService = class _EvmSolverService {
10820
11188
  * @param {PartnerFee} fee - The partner fee configuration
10821
11189
  * @returns {Promise<[Hex, Intent, bigint]>} The encoded contract call, intent and fee amount
10822
11190
  */
10823
- static constructCreateIntentData(createIntentParams, creatorHubWalletAddress, solverConfig2, fee) {
10824
- const inputToken = getHubAssetInfo(createIntentParams.srcChain, createIntentParams.inputToken)?.asset;
11191
+ static constructCreateIntentData(createIntentParams, creatorHubWalletAddress, solverConfig2, fee, hubProvider) {
11192
+ let inputToken = getHubAssetInfo(createIntentParams.srcChain, createIntentParams.inputToken)?.asset;
11193
+ if (createIntentParams.srcChain === hubProvider.chainConfig.chain.id && createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase()) {
11194
+ inputToken = hubProvider.chainConfig.wrappedNativeToken;
11195
+ }
10825
11196
  const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
10826
- invariant10__default.default(
11197
+ invariant11__default.default(
10827
11198
  inputToken,
10828
11199
  `hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
10829
11200
  );
10830
- invariant10__default.default(
11201
+ invariant11__default.default(
10831
11202
  outputToken,
10832
11203
  `hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
10833
11204
  );
@@ -10859,7 +11230,7 @@ var EvmSolverService = class _EvmSolverService {
10859
11230
  * @returns A tuple containing [encoded fee data, fee amount]. Fee amount will be 0n if no fee.
10860
11231
  */
10861
11232
  static createIntentFeeData(fee, inputAmount) {
10862
- invariant10__default.default(inputAmount > 0n, "Input amount must be greater than 0");
11233
+ invariant11__default.default(inputAmount > 0n, "Input amount must be greater than 0");
10863
11234
  if (!fee) {
10864
11235
  return ["0x", 0n];
10865
11236
  }
@@ -10867,7 +11238,7 @@ var EvmSolverService = class _EvmSolverService {
10867
11238
  if (isPartnerFeeAmount(fee)) {
10868
11239
  feeAmount = fee.amount;
10869
11240
  } else if (isPartnerFeePercentage(fee)) {
10870
- invariant10__default.default(
11241
+ invariant11__default.default(
10871
11242
  fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
10872
11243
  `Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
10873
11244
  );
@@ -10994,23 +11365,23 @@ var SolverApiService = class {
10994
11365
  * }
10995
11366
  */
10996
11367
  static async getQuote(payload, config) {
10997
- invariant10__default.default(payload.token_src.length > 0, "Empty token_src");
10998
- invariant10__default.default(payload.token_src_blockchain_id.length > 0, "Empty token_src_blockchain_id");
10999
- invariant10__default.default(payload.token_dst.length > 0, "Empty token_dst");
11000
- invariant10__default.default(payload.token_dst_blockchain_id.length > 0, "Empty token_dst_blockchain_id");
11001
- invariant10__default.default(payload.amount > 0n, "amount must be greater than 0");
11002
- invariant10__default.default(
11368
+ invariant11__default.default(payload.token_src.length > 0, "Empty token_src");
11369
+ invariant11__default.default(payload.token_src_blockchain_id.length > 0, "Empty token_src_blockchain_id");
11370
+ invariant11__default.default(payload.token_dst.length > 0, "Empty token_dst");
11371
+ invariant11__default.default(payload.token_dst_blockchain_id.length > 0, "Empty token_dst_blockchain_id");
11372
+ invariant11__default.default(payload.amount > 0n, "amount must be greater than 0");
11373
+ invariant11__default.default(
11003
11374
  isValidOriginalAssetAddress(payload.token_src_blockchain_id, payload.token_src),
11004
11375
  "unsupported token_src for src chain"
11005
11376
  );
11006
- invariant10__default.default(
11377
+ invariant11__default.default(
11007
11378
  isValidOriginalAssetAddress(payload.token_dst_blockchain_id, payload.token_dst),
11008
11379
  "unsupported token_dst for dst chain"
11009
11380
  );
11010
11381
  const tokenSrc = getHubAssetInfo(payload.token_src_blockchain_id, payload.token_src)?.asset;
11011
11382
  const tokenDst = getHubAssetInfo(payload.token_dst_blockchain_id, payload.token_dst)?.asset;
11012
- invariant10__default.default(tokenSrc, "hub asset not found for token_src");
11013
- invariant10__default.default(tokenDst, "hub asset not found for token_dst");
11383
+ invariant11__default.default(tokenSrc, "hub asset not found for token_src");
11384
+ invariant11__default.default(tokenDst, "hub asset not found for token_dst");
11014
11385
  try {
11015
11386
  const response = await fetch(`${config.solverApiEndpoint}/quote`, {
11016
11387
  method: "POST",
@@ -11105,7 +11476,7 @@ var SolverApiService = class {
11105
11476
  }
11106
11477
  }
11107
11478
  static async getStatus(request, config) {
11108
- invariant10__default.default(request.intent_tx_hash.length > 0, "Empty intent_tx_hash");
11479
+ invariant11__default.default(request.intent_tx_hash.length > 0, "Empty intent_tx_hash");
11109
11480
  try {
11110
11481
  const response = await fetch(`${config.solverApiEndpoint}/status`, {
11111
11482
  method: "POST",
@@ -11373,13 +11744,15 @@ var SolverService = class {
11373
11744
  intentParams: params,
11374
11745
  spokeProvider,
11375
11746
  fee = this.config.partnerFee,
11376
- timeout = DEFAULT_RELAY_TX_TIMEOUT
11747
+ timeout = DEFAULT_RELAY_TX_TIMEOUT,
11748
+ skipSimulation = false
11377
11749
  }) {
11378
11750
  return this.createAndSubmitIntent({
11379
11751
  intentParams: params,
11380
11752
  spokeProvider,
11381
11753
  fee,
11382
- timeout
11754
+ timeout,
11755
+ skipSimulation
11383
11756
  });
11384
11757
  }
11385
11758
  /**
@@ -11428,14 +11801,16 @@ var SolverService = class {
11428
11801
  intentParams: params,
11429
11802
  spokeProvider,
11430
11803
  fee = this.config.partnerFee,
11431
- timeout = DEFAULT_RELAY_TX_TIMEOUT
11804
+ timeout = DEFAULT_RELAY_TX_TIMEOUT,
11805
+ skipSimulation = false
11432
11806
  }) {
11433
11807
  try {
11434
11808
  const createIntentResult = await this.createIntent({
11435
11809
  intentParams: params,
11436
11810
  spokeProvider,
11437
11811
  fee,
11438
- raw: false
11812
+ raw: false,
11813
+ skipSimulation
11439
11814
  });
11440
11815
  if (!createIntentResult.ok) {
11441
11816
  return createIntentResult;
@@ -11562,13 +11937,23 @@ var SolverService = class {
11562
11937
  spokeProvider
11563
11938
  }) {
11564
11939
  try {
11565
- if (spokeProvider instanceof EvmSpokeProvider || spokeProvider instanceof SonicSpokeProvider) {
11940
+ if (spokeProvider instanceof EvmSpokeProvider) {
11941
+ const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
11942
+ return await Erc20Service.isAllowanceValid(
11943
+ params.inputToken,
11944
+ params.inputAmount,
11945
+ walletAddress,
11946
+ spokeProvider.chainConfig.addresses.assetManager,
11947
+ spokeProvider
11948
+ );
11949
+ }
11950
+ if (spokeProvider instanceof SonicSpokeProvider) {
11566
11951
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
11567
11952
  return await Erc20Service.isAllowanceValid(
11568
11953
  params.inputToken,
11569
11954
  params.inputAmount,
11570
11955
  walletAddress,
11571
- spokeProvider instanceof EvmSpokeProvider ? spokeProvider.chainConfig.addresses.assetManager : spokeProvider.chainConfig.addresses.walletRouter,
11956
+ getSolverConfig(types.SONIC_MAINNET_CHAIN_ID).intentsContract,
11572
11957
  spokeProvider
11573
11958
  );
11574
11959
  }
@@ -11627,7 +12012,7 @@ var SolverService = class {
11627
12012
  raw
11628
12013
  }) {
11629
12014
  try {
11630
- if (spokeProvider instanceof EvmSpokeProvider || spokeProvider instanceof SonicSpokeProvider) {
12015
+ if (spokeProvider instanceof EvmSpokeProvider) {
11631
12016
  const result = await Erc20Service.approve(
11632
12017
  params.inputToken,
11633
12018
  params.inputAmount,
@@ -11640,6 +12025,19 @@ var SolverService = class {
11640
12025
  value: result
11641
12026
  };
11642
12027
  }
12028
+ if (spokeProvider instanceof SonicSpokeProvider) {
12029
+ const result = await Erc20Service.approve(
12030
+ params.inputToken,
12031
+ params.inputAmount,
12032
+ getSolverConfig(types.SONIC_MAINNET_CHAIN_ID).intentsContract,
12033
+ spokeProvider,
12034
+ raw
12035
+ );
12036
+ return {
12037
+ ok: true,
12038
+ value: result
12039
+ };
12040
+ }
11643
12041
  return {
11644
12042
  ok: false,
11645
12043
  error: new Error("Approve only supported for EVM spoke chains")
@@ -11699,48 +12097,70 @@ var SolverService = class {
11699
12097
  fee = this.config.partnerFee,
11700
12098
  raw
11701
12099
  }) {
11702
- invariant10__default.default(
12100
+ invariant11__default.default(
11703
12101
  isValidOriginalAssetAddress(params.srcChain, params.inputToken),
11704
12102
  `Unsupported spoke chain token (params.srcChain): ${params.srcChain}, params.inputToken): ${params.inputToken}`
11705
12103
  );
11706
- invariant10__default.default(
12104
+ invariant11__default.default(
11707
12105
  isValidOriginalAssetAddress(params.dstChain, params.outputToken),
11708
12106
  `Unsupported spoke chain token (params.dstChain): ${params.dstChain}, params.outputToken): ${params.outputToken}`
11709
12107
  );
11710
- invariant10__default.default(isValidSpokeChainId(params.srcChain), `Invalid spoke chain (params.srcChain): ${params.srcChain}`);
11711
- invariant10__default.default(isValidSpokeChainId(params.dstChain), `Invalid spoke chain (params.dstChain): ${params.dstChain}`);
12108
+ invariant11__default.default(isValidSpokeChainId(params.srcChain), `Invalid spoke chain (params.srcChain): ${params.srcChain}`);
12109
+ invariant11__default.default(isValidSpokeChainId(params.dstChain), `Invalid spoke chain (params.dstChain): ${params.dstChain}`);
11712
12110
  try {
11713
12111
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
11714
- invariant10__default.default(
12112
+ invariant11__default.default(
11715
12113
  params.srcAddress.toLowerCase() === walletAddress.toLowerCase(),
11716
12114
  "srcAddress must be the same as wallet address"
11717
12115
  );
11718
12116
  const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
11719
- const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
11720
- {
11721
- ...params,
11722
- srcAddress: walletAddress
11723
- },
11724
- creatorHubWalletAddress,
11725
- this.config,
11726
- fee
11727
- );
11728
- const txResult = await SpokeService.deposit(
11729
- {
11730
- from: walletAddress,
11731
- to: creatorHubWalletAddress,
11732
- token: params.inputToken,
11733
- amount: params.inputAmount,
11734
- data
11735
- },
11736
- spokeProvider,
11737
- this.hubProvider,
11738
- raw
11739
- );
11740
- return {
11741
- ok: true,
11742
- value: [txResult, { ...intent, feeAmount }, data]
11743
- };
12117
+ if (spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
12118
+ const [txResult, intent, feeAmount, data] = await SonicSpokeService.createSwapIntent(
12119
+ params,
12120
+ creatorHubWalletAddress,
12121
+ this.config,
12122
+ fee,
12123
+ spokeProvider,
12124
+ this.hubProvider,
12125
+ raw
12126
+ );
12127
+ return {
12128
+ ok: true,
12129
+ value: [
12130
+ txResult,
12131
+ { ...intent, feeAmount },
12132
+ data
12133
+ ]
12134
+ };
12135
+ }
12136
+ {
12137
+ const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
12138
+ {
12139
+ ...params,
12140
+ srcAddress: walletAddress
12141
+ },
12142
+ creatorHubWalletAddress,
12143
+ this.config,
12144
+ fee,
12145
+ this.hubProvider
12146
+ );
12147
+ const txResult = await SpokeService.deposit(
12148
+ {
12149
+ from: walletAddress,
12150
+ to: creatorHubWalletAddress,
12151
+ token: params.inputToken,
12152
+ amount: params.inputAmount,
12153
+ data
12154
+ },
12155
+ spokeProvider,
12156
+ this.hubProvider,
12157
+ raw
12158
+ );
12159
+ return {
12160
+ ok: true,
12161
+ value: [txResult, { ...intent, feeAmount }, data]
12162
+ };
12163
+ }
11744
12164
  } catch (error) {
11745
12165
  return {
11746
12166
  ok: false,
@@ -11763,8 +12183,8 @@ var SolverService = class {
11763
12183
  */
11764
12184
  async cancelIntent(intent, spokeProvider, raw) {
11765
12185
  try {
11766
- invariant10__default.default(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
11767
- invariant10__default.default(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
12186
+ invariant11__default.default(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
12187
+ invariant11__default.default(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
11768
12188
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
11769
12189
  const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
11770
12190
  const calls = [];
@@ -12276,7 +12696,7 @@ var IcxMigrationService = class {
12276
12696
  migrateData(params) {
12277
12697
  const calls = [];
12278
12698
  const assetConfig = getHubAssetInfo(types.ICON_MAINNET_CHAIN_ID, params.address);
12279
- invariant10__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${params.address}`);
12699
+ invariant11__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${params.address}`);
12280
12700
  calls.push(
12281
12701
  Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.icxMigration, params.amount)
12282
12702
  );
@@ -12292,7 +12712,7 @@ var IcxMigrationService = class {
12292
12712
  revertMigration(params) {
12293
12713
  const calls = [];
12294
12714
  const assetConfig = getHubAssetInfo(types.ICON_MAINNET_CHAIN_ID, params.wICX);
12295
- invariant10__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
12715
+ invariant11__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
12296
12716
  calls.push(
12297
12717
  Erc20Service.encodeApprove(
12298
12718
  this.hubProvider.chainConfig.addresses.sodaToken,
@@ -12388,9 +12808,9 @@ var MigrationService = class {
12388
12808
  async isAllowanceValid(params, action, spokeProvider) {
12389
12809
  try {
12390
12810
  if (action === "migrate") {
12391
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
12392
- invariant10__default.default(viem.isAddress(params.to) || isIconAddress(params.to), "To address is required");
12393
- invariant10__default.default(
12811
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
12812
+ invariant11__default.default(viem.isAddress(params.to) || isIconAddress(params.to), "To address is required");
12813
+ invariant11__default.default(
12394
12814
  isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
12395
12815
  "Invalid params"
12396
12816
  );
@@ -12416,9 +12836,9 @@ var MigrationService = class {
12416
12836
  };
12417
12837
  }
12418
12838
  if (action === "revert") {
12419
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
12420
- invariant10__default.default(params.to.length > 0, "To address is required");
12421
- invariant10__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
12839
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
12840
+ invariant11__default.default(params.to.length > 0, "To address is required");
12841
+ invariant11__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
12422
12842
  if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
12423
12843
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
12424
12844
  const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
@@ -12474,9 +12894,9 @@ var MigrationService = class {
12474
12894
  async approve(params, action, spokeProvider, raw) {
12475
12895
  try {
12476
12896
  if (action === "migrate") {
12477
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
12478
- invariant10__default.default(params.to.length > 0, "To address is required");
12479
- invariant10__default.default(isUnifiedBnUSDMigrateParams(params), "Invalid params");
12897
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
12898
+ invariant11__default.default(params.to.length > 0, "To address is required");
12899
+ invariant11__default.default(isUnifiedBnUSDMigrateParams(params), "Invalid params");
12480
12900
  if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
12481
12901
  const evmSpokeProvider = spokeProvider;
12482
12902
  const result = await Erc20Service.approve(
@@ -12497,9 +12917,9 @@ var MigrationService = class {
12497
12917
  };
12498
12918
  }
12499
12919
  if (action === "revert") {
12500
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
12501
- invariant10__default.default(params.to.length > 0, "To address is required");
12502
- invariant10__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
12920
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
12921
+ invariant11__default.default(params.to.length > 0, "To address is required");
12922
+ invariant11__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
12503
12923
  if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
12504
12924
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
12505
12925
  const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
@@ -12911,13 +13331,13 @@ var MigrationService = class {
12911
13331
  async createMigratebnUSDIntent(params, spokeProvider, unchecked = false, raw) {
12912
13332
  try {
12913
13333
  if (!unchecked) {
12914
- invariant10__default.default(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
12915
- invariant10__default.default(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
12916
- invariant10__default.default(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
12917
- invariant10__default.default(params.dstbnUSD.length > 0, "New bnUSD token address is required");
12918
- invariant10__default.default(params.amount > 0, "Amount must be greater than 0");
12919
- invariant10__default.default(params.to.length > 0, "Recipient address is required");
12920
- invariant10__default.default(
13334
+ invariant11__default.default(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
13335
+ invariant11__default.default(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
13336
+ invariant11__default.default(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
13337
+ invariant11__default.default(params.dstbnUSD.length > 0, "New bnUSD token address is required");
13338
+ invariant11__default.default(params.amount > 0, "Amount must be greater than 0");
13339
+ invariant11__default.default(params.to.length > 0, "Recipient address is required");
13340
+ invariant11__default.default(
12921
13341
  !(isLegacybnUSDToken(params.srcbnUSD) && isLegacybnUSDToken(params.dstbnUSD)),
12922
13342
  "srcbnUSD and dstbnUSD cannot both be legacy bnUSD tokens"
12923
13343
  );
@@ -12925,11 +13345,11 @@ var MigrationService = class {
12925
13345
  let migrationData;
12926
13346
  if (isLegacybnUSDToken(params.srcbnUSD)) {
12927
13347
  if (!unchecked) {
12928
- invariant10__default.default(
13348
+ invariant11__default.default(
12929
13349
  isLegacybnUSDChainId(params.srcChainId),
12930
13350
  "srcChainId must be a legacy bnUSD chain (icon, sui, stellar) if srcbnUSD is a legacy bnUSD token"
12931
13351
  );
12932
- invariant10__default.default(
13352
+ invariant11__default.default(
12933
13353
  isNewbnUSDChainId(params.dstChainId),
12934
13354
  "dstChainId must be a new bnUSD chain (all spoke chains besides Icon) if dstbnUSD is a legacy bnUSD token"
12935
13355
  );
@@ -12944,15 +13364,15 @@ var MigrationService = class {
12944
13364
  });
12945
13365
  } else if (isLegacybnUSDToken(params.dstbnUSD)) {
12946
13366
  if (!unchecked) {
12947
- invariant10__default.default(
13367
+ invariant11__default.default(
12948
13368
  isLegacybnUSDChainId(params.dstChainId),
12949
13369
  "dstChainId must be a legacy bnUSD chain (sui, stellar, icon) if dstbnUSD is a legacy bnUSD token"
12950
13370
  );
12951
- invariant10__default.default(
13371
+ invariant11__default.default(
12952
13372
  isNewbnUSDToken(params.srcbnUSD),
12953
13373
  "srcbnUSD must be a new bnUSD token if dstbnUSD is a legacy bnUSD token"
12954
13374
  );
12955
- invariant10__default.default(
13375
+ invariant11__default.default(
12956
13376
  isNewbnUSDChainId(params.srcChainId),
12957
13377
  "srcChainId must be a new bnUSD chain (all spoke chains besides Icon) if srcbnUSD is a new bnUSD token"
12958
13378
  );
@@ -13025,13 +13445,13 @@ var MigrationService = class {
13025
13445
  */
13026
13446
  async createMigrateIcxToSodaIntent(params, spokeProvider, raw) {
13027
13447
  try {
13028
- invariant10__default.default(params.amount > 0, "Amount must be greater than 0");
13029
- invariant10__default.default(viem.isAddress(params.to), "Recipient address is required");
13030
- invariant10__default.default(
13448
+ invariant11__default.default(params.amount > 0, "Amount must be greater than 0");
13449
+ invariant11__default.default(viem.isAddress(params.to), "Recipient address is required");
13450
+ invariant11__default.default(
13031
13451
  params.address.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.address.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
13032
13452
  "Token must be wICX or native ICX token"
13033
13453
  );
13034
- invariant10__default.default(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
13454
+ invariant11__default.default(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
13035
13455
  const availableAmount = await this.icxMigration.getAvailableAmount();
13036
13456
  if (availableAmount < params.amount) {
13037
13457
  throw new Error(
@@ -13143,7 +13563,7 @@ var BnUSDMigrationService = class {
13143
13563
  migrateData(params) {
13144
13564
  const calls = [];
13145
13565
  const assetConfig = getHubAssetInfo(params.srcChainId, params.legacybnUSD);
13146
- invariant10__default.default(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
13566
+ invariant11__default.default(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
13147
13567
  const bnUSDVault = getMoneyMarketConfig(types.SONIC_MAINNET_CHAIN_ID).bnUSDVault;
13148
13568
  calls.push(Erc20Service.encodeApprove(assetConfig.asset, assetConfig.vault, params.amount));
13149
13569
  calls.push(EvmVaultTokenService.encodeDeposit(assetConfig.vault, assetConfig.asset, params.amount));
@@ -13155,7 +13575,7 @@ var BnUSDMigrationService = class {
13155
13575
  return encodeContractCalls(calls);
13156
13576
  }
13157
13577
  const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.newbnUSD);
13158
- invariant10__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
13578
+ invariant11__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
13159
13579
  calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.asset, translatedAmount));
13160
13580
  const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
13161
13581
  dstAssetConfig.decimal,
@@ -13188,14 +13608,14 @@ var BnUSDMigrationService = class {
13188
13608
  let decimals = 18;
13189
13609
  if (params.newbnUSD.toLowerCase() !== bnUSDVault.toLowerCase()) {
13190
13610
  const assetConfig = getHubAssetInfo(params.srcChainId, params.newbnUSD);
13191
- invariant10__default.default(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
13611
+ invariant11__default.default(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
13192
13612
  decimals = assetConfig.decimal;
13193
13613
  calls.push(Erc20Service.encodeApprove(assetConfig.asset, bnUSDVault, params.amount));
13194
13614
  calls.push(EvmVaultTokenService.encodeDeposit(bnUSDVault, assetConfig.asset, params.amount));
13195
13615
  }
13196
13616
  const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(decimals, params.amount);
13197
13617
  const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.legacybnUSD);
13198
- invariant10__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
13618
+ invariant11__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
13199
13619
  calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.vault, translatedAmount));
13200
13620
  calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetConfig.vault, dstAssetConfig.asset, translatedAmount));
13201
13621
  const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
@@ -13278,7 +13698,7 @@ var BalnSwapService = class {
13278
13698
  */
13279
13699
  async swapData(balnToken, params) {
13280
13700
  const assetConfig = getHubAssetInfo(types.ICON_MAINNET_CHAIN_ID, balnToken);
13281
- invariant10__default.default(assetConfig, `hub asset not found for baln token: ${balnToken}`);
13701
+ invariant11__default.default(assetConfig, `hub asset not found for baln token: ${balnToken}`);
13282
13702
  const calls = [];
13283
13703
  calls.push(
13284
13704
  Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.balnSwap, params.amount)
@@ -15042,9 +15462,9 @@ var MoneyMarketService = class _MoneyMarketService {
15042
15462
  */
15043
15463
  async isAllowanceValid(params, spokeProvider) {
15044
15464
  try {
15045
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
15046
- invariant10__default.default(params.token.length > 0, "Token is required");
15047
- invariant10__default.default(
15465
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
15466
+ invariant11__default.default(params.token.length > 0, "Token is required");
15467
+ invariant11__default.default(
15048
15468
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15049
15469
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15050
15470
  );
@@ -15139,19 +15559,19 @@ var MoneyMarketService = class _MoneyMarketService {
15139
15559
  */
15140
15560
  async approve(params, spokeProvider, raw) {
15141
15561
  try {
15142
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
15143
- invariant10__default.default(params.token.length > 0, "Token is required");
15144
- invariant10__default.default(
15562
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
15563
+ invariant11__default.default(params.token.length > 0, "Token is required");
15564
+ invariant11__default.default(
15145
15565
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15146
15566
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15147
15567
  );
15148
15568
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
15149
15569
  if (spokeProvider instanceof EvmSpokeProvider) {
15150
- invariant10__default.default(
15570
+ invariant11__default.default(
15151
15571
  params.action === "supply" || params.action === "repay",
15152
15572
  "Invalid action (only supply and repay are supported on evm)"
15153
15573
  );
15154
- invariant10__default.default(viem.isAddress(params.token), "Invalid token address");
15574
+ invariant11__default.default(viem.isAddress(params.token), "Invalid token address");
15155
15575
  const result = await Erc20Service.approve(
15156
15576
  params.token,
15157
15577
  params.amount,
@@ -15165,11 +15585,11 @@ var MoneyMarketService = class _MoneyMarketService {
15165
15585
  };
15166
15586
  }
15167
15587
  if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
15168
- invariant10__default.default(
15588
+ invariant11__default.default(
15169
15589
  params.action === "withdraw" || params.action === "borrow" || params.action === "supply" || params.action === "repay",
15170
15590
  "Invalid action (only withdraw, borrow, supply and repay are supported on sonic)"
15171
15591
  );
15172
- invariant10__default.default(viem.isAddress(params.token), "Invalid token address");
15592
+ invariant11__default.default(viem.isAddress(params.token), "Invalid token address");
15173
15593
  if (params.action === "withdraw") {
15174
15594
  const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
15175
15595
  params.token,
@@ -15341,10 +15761,10 @@ var MoneyMarketService = class _MoneyMarketService {
15341
15761
  */
15342
15762
  async createSupplyIntent(params, spokeProvider, raw) {
15343
15763
  try {
15344
- invariant10__default.default(params.action === "supply", "Invalid action");
15345
- invariant10__default.default(params.token.length > 0, "Token is required");
15346
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
15347
- invariant10__default.default(
15764
+ invariant11__default.default(params.action === "supply", "Invalid action");
15765
+ invariant11__default.default(params.token.length > 0, "Token is required");
15766
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
15767
+ invariant11__default.default(
15348
15768
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15349
15769
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15350
15770
  );
@@ -15496,10 +15916,10 @@ var MoneyMarketService = class _MoneyMarketService {
15496
15916
  * }
15497
15917
  */
15498
15918
  async createBorrowIntent(params, spokeProvider, raw) {
15499
- invariant10__default.default(params.action === "borrow", "Invalid action");
15500
- invariant10__default.default(params.token.length > 0, "Token is required");
15501
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
15502
- invariant10__default.default(
15919
+ invariant11__default.default(params.action === "borrow", "Invalid action");
15920
+ invariant11__default.default(params.token.length > 0, "Token is required");
15921
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
15922
+ invariant11__default.default(
15503
15923
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15504
15924
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15505
15925
  );
@@ -15631,10 +16051,10 @@ var MoneyMarketService = class _MoneyMarketService {
15631
16051
  * }
15632
16052
  */
15633
16053
  async createWithdrawIntent(params, spokeProvider, raw) {
15634
- invariant10__default.default(params.action === "withdraw", "Invalid action");
15635
- invariant10__default.default(params.token.length > 0, "Token is required");
15636
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
15637
- invariant10__default.default(
16054
+ invariant11__default.default(params.action === "withdraw", "Invalid action");
16055
+ invariant11__default.default(params.token.length > 0, "Token is required");
16056
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
16057
+ invariant11__default.default(
15638
16058
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15639
16059
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15640
16060
  );
@@ -15786,10 +16206,10 @@ var MoneyMarketService = class _MoneyMarketService {
15786
16206
  * }
15787
16207
  */
15788
16208
  async createRepayIntent(params, spokeProvider, raw) {
15789
- invariant10__default.default(params.action === "repay", "Invalid action");
15790
- invariant10__default.default(params.token.length > 0, "Token is required");
15791
- invariant10__default.default(params.amount > 0n, "Amount must be greater than 0");
15792
- invariant10__default.default(
16209
+ invariant11__default.default(params.action === "repay", "Invalid action");
16210
+ invariant11__default.default(params.token.length > 0, "Token is required");
16211
+ invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
16212
+ invariant11__default.default(
15793
16213
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15794
16214
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15795
16215
  );
@@ -15832,7 +16252,7 @@ var MoneyMarketService = class _MoneyMarketService {
15832
16252
  buildSupplyData(token, to, amount, spokeChainId) {
15833
16253
  const calls = [];
15834
16254
  const assetConfig = getHubAssetInfo(spokeChainId, token);
15835
- invariant10__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
16255
+ invariant11__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
15836
16256
  let assetAddress = assetConfig.asset;
15837
16257
  const vaultAddress = assetConfig.vault;
15838
16258
  const lendingPool = this.config.lendingPool;
@@ -15863,13 +16283,13 @@ var MoneyMarketService = class _MoneyMarketService {
15863
16283
  * @returns {Hex} The transaction data.
15864
16284
  */
15865
16285
  buildBorrowData(from, to, token, amount, spokeChainId) {
15866
- invariant10__default.default(isValidSpokeChainId(spokeChainId), `Invalid spokeChainId: ${spokeChainId}`);
15867
- invariant10__default.default(
16286
+ invariant11__default.default(isValidSpokeChainId(spokeChainId), `Invalid spokeChainId: ${spokeChainId}`);
16287
+ invariant11__default.default(
15868
16288
  isValidOriginalAssetAddress(spokeChainId, token),
15869
16289
  `Unsupported spoke chain (${spokeChainId}) token: ${token}`
15870
16290
  );
15871
16291
  const assetConfig = getHubAssetInfo(spokeChainId, token);
15872
- invariant10__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
16292
+ invariant11__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
15873
16293
  let assetAddress = assetConfig.asset;
15874
16294
  const vaultAddress = assetConfig.vault;
15875
16295
  const bnUSDVault = this.config.bnUSDVault;