@sodax/sdk 0.0.1-rc.25 → 0.0.1-rc.27

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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getAbiItem, encodeAbiParameters, parseAbiParameters, toHex, erc20Abi as erc20Abi$1, encodeFunctionData, fromHex, createPublicClient, http, decodeAbiParameters, encodePacked, parseEventLogs, keccak256, isAddress } from 'viem';
2
- import invariant10 from 'tiny-invariant';
2
+ import invariant11 from 'tiny-invariant';
3
3
  import { bcs } from '@mysten/sui/bcs';
4
4
  import { PublicKey, Connection, VersionedTransaction, SystemProgram, ComputeBudgetProgram } from '@solana/web3.js';
5
5
  import { SorobanRpc, Address, Horizon, Contract, TransactionBuilder, BASE_FEE, nativeToScVal, TimeoutInfinite, rpc, scValToBigInt, Operation, Account, FeeBumpTransaction } from '@stellar/stellar-sdk';
@@ -6141,16 +6141,16 @@ function calculateFeeAmount(inputAmount, fee) {
6141
6141
  if (!fee) {
6142
6142
  return 0n;
6143
6143
  }
6144
- invariant10(inputAmount > 0n, "Input amount must be greater than 0");
6144
+ invariant11(inputAmount > 0n, "Input amount must be greater than 0");
6145
6145
  let feeAmount = 0n;
6146
6146
  if (isPartnerFeeAmount(fee)) {
6147
- invariant10(
6147
+ invariant11(
6148
6148
  fee.amount >= 0 && fee.amount <= inputAmount,
6149
6149
  `Fee amount must be greater than 0 and less than or equal to the input amount: ${fee.amount}`
6150
6150
  );
6151
6151
  feeAmount = fee.amount;
6152
6152
  } else if (isPartnerFeePercentage(fee)) {
6153
- invariant10(
6153
+ invariant11(
6154
6154
  fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
6155
6155
  `Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
6156
6156
  );
@@ -6159,8 +6159,8 @@ function calculateFeeAmount(inputAmount, fee) {
6159
6159
  return feeAmount;
6160
6160
  }
6161
6161
  function adjustAmountByFee(amount, fee, quoteType) {
6162
- invariant10(amount > 0n, "Amount must be greater than 0");
6163
- invariant10(quoteType === "exact_input" || quoteType === "exact_output", "Invalid quote type");
6162
+ invariant11(amount > 0n, "Amount must be greater than 0");
6163
+ invariant11(quoteType === "exact_input" || quoteType === "exact_output", "Invalid quote type");
6164
6164
  if (quoteType === "exact_input") {
6165
6165
  return amount - calculateFeeAmount(amount, fee);
6166
6166
  }
@@ -10241,6 +10241,58 @@ var SonicSpokeService = class _SonicSpokeService {
10241
10241
  }
10242
10242
  return spokeProvider.walletProvider.sendTransaction(rawTx);
10243
10243
  }
10244
+ static async createSwapIntent(createIntentParams, creatorHubWalletAddress, solverConfig2, fee, spokeProvider, hubProvider, raw) {
10245
+ let inputToken = getHubAssetInfo(createIntentParams.srcChain, createIntentParams.inputToken)?.asset;
10246
+ if (createIntentParams.srcChain === hubProvider.chainConfig.chain.id && createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase()) {
10247
+ inputToken = hubProvider.chainConfig.nativeToken;
10248
+ }
10249
+ const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
10250
+ invariant11(
10251
+ inputToken,
10252
+ `hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
10253
+ );
10254
+ invariant11(
10255
+ outputToken,
10256
+ `hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
10257
+ );
10258
+ const [feeData, feeAmount] = EvmSolverService.createIntentFeeData(fee, createIntentParams.inputAmount);
10259
+ const intentsContract = solverConfig2.intentsContract;
10260
+ const intent = {
10261
+ ...createIntentParams,
10262
+ inputToken,
10263
+ outputToken,
10264
+ inputAmount: createIntentParams.inputAmount - feeAmount,
10265
+ srcChain: getIntentRelayChainId(createIntentParams.srcChain),
10266
+ dstChain: getIntentRelayChainId(createIntentParams.dstChain),
10267
+ srcAddress: encodeAddress(createIntentParams.srcChain, createIntentParams.srcAddress),
10268
+ dstAddress: encodeAddress(createIntentParams.dstChain, createIntentParams.dstAddress),
10269
+ intentId: randomUint256(),
10270
+ creator: creatorHubWalletAddress,
10271
+ data: feeData
10272
+ // fee amount will be deducted from the input amount
10273
+ };
10274
+ const txData = EvmSolverService.encodeCreateIntent(intent, intentsContract);
10275
+ const rawTx = {
10276
+ from: await spokeProvider.walletProvider.getWalletAddress(),
10277
+ to: txData.address,
10278
+ data: txData.data,
10279
+ value: createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase() ? createIntentParams.inputAmount : 0n
10280
+ };
10281
+ if (raw) {
10282
+ return [
10283
+ rawTx,
10284
+ intent,
10285
+ feeAmount,
10286
+ txData.data
10287
+ ];
10288
+ }
10289
+ return [
10290
+ await spokeProvider.walletProvider.sendTransaction(rawTx),
10291
+ intent,
10292
+ feeAmount,
10293
+ txData.data
10294
+ ];
10295
+ }
10244
10296
  /**
10245
10297
  * Get the balance of the token in the spoke chain.
10246
10298
  * @param {Address} token - The address of the token to get the balance of.
@@ -10770,7 +10822,6 @@ var SpokeService = class _SpokeService {
10770
10822
  return InjectiveSpokeService.deposit(params, spokeProvider, hubProvider, raw);
10771
10823
  }
10772
10824
  if (spokeProvider instanceof IconSpokeProvider) {
10773
- await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
10774
10825
  return IconSpokeService.deposit(
10775
10826
  params,
10776
10827
  spokeProvider,
@@ -10797,7 +10848,6 @@ var SpokeService = class _SpokeService {
10797
10848
  );
10798
10849
  }
10799
10850
  if (spokeProvider instanceof StellarSpokeProvider) {
10800
- await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
10801
10851
  return StellarSpokeService.deposit(
10802
10852
  params,
10803
10853
  spokeProvider,
@@ -10971,19 +11021,19 @@ async function postRequest(payload, apiUrl) {
10971
11021
  return response.json();
10972
11022
  }
10973
11023
  async function submitTransaction(payload, apiUrl) {
10974
- invariant10(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
10975
- invariant10(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
11024
+ invariant11(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
11025
+ invariant11(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
10976
11026
  return postRequest(payload, apiUrl);
10977
11027
  }
10978
11028
  async function getTransactionPackets(payload, apiUrl) {
10979
- invariant10(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
10980
- invariant10(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
11029
+ invariant11(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
11030
+ invariant11(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
10981
11031
  return postRequest(payload, apiUrl);
10982
11032
  }
10983
11033
  async function getPacket(payload, apiUrl) {
10984
- invariant10(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
10985
- invariant10(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
10986
- invariant10(payload.params.conn_sn.length > 0, "Invalid input parameters. conn_sn empty");
11034
+ invariant11(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
11035
+ invariant11(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
11036
+ invariant11(payload.params.conn_sn.length > 0, "Invalid input parameters. conn_sn empty");
10987
11037
  return postRequest(payload, apiUrl);
10988
11038
  }
10989
11039
  async function waitUntilIntentExecuted(payload) {
@@ -11114,11 +11164,11 @@ var EvmSolverService = class _EvmSolverService {
11114
11164
  inputToken = hubProvider.chainConfig.wrappedNativeToken;
11115
11165
  }
11116
11166
  const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
11117
- invariant10(
11167
+ invariant11(
11118
11168
  inputToken,
11119
11169
  `hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
11120
11170
  );
11121
- invariant10(
11171
+ invariant11(
11122
11172
  outputToken,
11123
11173
  `hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
11124
11174
  );
@@ -11150,7 +11200,7 @@ var EvmSolverService = class _EvmSolverService {
11150
11200
  * @returns A tuple containing [encoded fee data, fee amount]. Fee amount will be 0n if no fee.
11151
11201
  */
11152
11202
  static createIntentFeeData(fee, inputAmount) {
11153
- invariant10(inputAmount > 0n, "Input amount must be greater than 0");
11203
+ invariant11(inputAmount > 0n, "Input amount must be greater than 0");
11154
11204
  if (!fee) {
11155
11205
  return ["0x", 0n];
11156
11206
  }
@@ -11158,7 +11208,7 @@ var EvmSolverService = class _EvmSolverService {
11158
11208
  if (isPartnerFeeAmount(fee)) {
11159
11209
  feeAmount = fee.amount;
11160
11210
  } else if (isPartnerFeePercentage(fee)) {
11161
- invariant10(
11211
+ invariant11(
11162
11212
  fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
11163
11213
  `Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
11164
11214
  );
@@ -11285,23 +11335,23 @@ var SolverApiService = class {
11285
11335
  * }
11286
11336
  */
11287
11337
  static async getQuote(payload, config) {
11288
- invariant10(payload.token_src.length > 0, "Empty token_src");
11289
- invariant10(payload.token_src_blockchain_id.length > 0, "Empty token_src_blockchain_id");
11290
- invariant10(payload.token_dst.length > 0, "Empty token_dst");
11291
- invariant10(payload.token_dst_blockchain_id.length > 0, "Empty token_dst_blockchain_id");
11292
- invariant10(payload.amount > 0n, "amount must be greater than 0");
11293
- invariant10(
11338
+ invariant11(payload.token_src.length > 0, "Empty token_src");
11339
+ invariant11(payload.token_src_blockchain_id.length > 0, "Empty token_src_blockchain_id");
11340
+ invariant11(payload.token_dst.length > 0, "Empty token_dst");
11341
+ invariant11(payload.token_dst_blockchain_id.length > 0, "Empty token_dst_blockchain_id");
11342
+ invariant11(payload.amount > 0n, "amount must be greater than 0");
11343
+ invariant11(
11294
11344
  isValidOriginalAssetAddress(payload.token_src_blockchain_id, payload.token_src),
11295
11345
  "unsupported token_src for src chain"
11296
11346
  );
11297
- invariant10(
11347
+ invariant11(
11298
11348
  isValidOriginalAssetAddress(payload.token_dst_blockchain_id, payload.token_dst),
11299
11349
  "unsupported token_dst for dst chain"
11300
11350
  );
11301
11351
  const tokenSrc = getHubAssetInfo(payload.token_src_blockchain_id, payload.token_src)?.asset;
11302
11352
  const tokenDst = getHubAssetInfo(payload.token_dst_blockchain_id, payload.token_dst)?.asset;
11303
- invariant10(tokenSrc, "hub asset not found for token_src");
11304
- invariant10(tokenDst, "hub asset not found for token_dst");
11353
+ invariant11(tokenSrc, "hub asset not found for token_src");
11354
+ invariant11(tokenDst, "hub asset not found for token_dst");
11305
11355
  try {
11306
11356
  const response = await fetch(`${config.solverApiEndpoint}/quote`, {
11307
11357
  method: "POST",
@@ -11396,7 +11446,7 @@ var SolverApiService = class {
11396
11446
  }
11397
11447
  }
11398
11448
  static async getStatus(request, config) {
11399
- invariant10(request.intent_tx_hash.length > 0, "Empty intent_tx_hash");
11449
+ invariant11(request.intent_tx_hash.length > 0, "Empty intent_tx_hash");
11400
11450
  try {
11401
11451
  const response = await fetch(`${config.solverApiEndpoint}/status`, {
11402
11452
  method: "POST",
@@ -11857,13 +11907,23 @@ var SolverService = class {
11857
11907
  spokeProvider
11858
11908
  }) {
11859
11909
  try {
11860
- if (spokeProvider instanceof EvmSpokeProvider || spokeProvider instanceof SonicSpokeProvider) {
11910
+ if (spokeProvider instanceof EvmSpokeProvider) {
11911
+ const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
11912
+ return await Erc20Service.isAllowanceValid(
11913
+ params.inputToken,
11914
+ params.inputAmount,
11915
+ walletAddress,
11916
+ spokeProvider.chainConfig.addresses.assetManager,
11917
+ spokeProvider
11918
+ );
11919
+ }
11920
+ if (spokeProvider instanceof SonicSpokeProvider) {
11861
11921
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
11862
11922
  return await Erc20Service.isAllowanceValid(
11863
11923
  params.inputToken,
11864
11924
  params.inputAmount,
11865
11925
  walletAddress,
11866
- spokeProvider instanceof EvmSpokeProvider ? spokeProvider.chainConfig.addresses.assetManager : spokeProvider.chainConfig.addresses.walletRouter,
11926
+ getSolverConfig(SONIC_MAINNET_CHAIN_ID).intentsContract,
11867
11927
  spokeProvider
11868
11928
  );
11869
11929
  }
@@ -11922,7 +11982,7 @@ var SolverService = class {
11922
11982
  raw
11923
11983
  }) {
11924
11984
  try {
11925
- if (spokeProvider instanceof EvmSpokeProvider || spokeProvider instanceof SonicSpokeProvider) {
11985
+ if (spokeProvider instanceof EvmSpokeProvider) {
11926
11986
  const result = await Erc20Service.approve(
11927
11987
  params.inputToken,
11928
11988
  params.inputAmount,
@@ -11935,6 +11995,19 @@ var SolverService = class {
11935
11995
  value: result
11936
11996
  };
11937
11997
  }
11998
+ if (spokeProvider instanceof SonicSpokeProvider) {
11999
+ const result = await Erc20Service.approve(
12000
+ params.inputToken,
12001
+ params.inputAmount,
12002
+ getSolverConfig(SONIC_MAINNET_CHAIN_ID).intentsContract,
12003
+ spokeProvider,
12004
+ raw
12005
+ );
12006
+ return {
12007
+ ok: true,
12008
+ value: result
12009
+ };
12010
+ }
11938
12011
  return {
11939
12012
  ok: false,
11940
12013
  error: new Error("Approve only supported for EVM spoke chains")
@@ -11994,49 +12067,70 @@ var SolverService = class {
11994
12067
  fee = this.config.partnerFee,
11995
12068
  raw
11996
12069
  }) {
11997
- invariant10(
12070
+ invariant11(
11998
12071
  isValidOriginalAssetAddress(params.srcChain, params.inputToken),
11999
12072
  `Unsupported spoke chain token (params.srcChain): ${params.srcChain}, params.inputToken): ${params.inputToken}`
12000
12073
  );
12001
- invariant10(
12074
+ invariant11(
12002
12075
  isValidOriginalAssetAddress(params.dstChain, params.outputToken),
12003
12076
  `Unsupported spoke chain token (params.dstChain): ${params.dstChain}, params.outputToken): ${params.outputToken}`
12004
12077
  );
12005
- invariant10(isValidSpokeChainId(params.srcChain), `Invalid spoke chain (params.srcChain): ${params.srcChain}`);
12006
- invariant10(isValidSpokeChainId(params.dstChain), `Invalid spoke chain (params.dstChain): ${params.dstChain}`);
12078
+ invariant11(isValidSpokeChainId(params.srcChain), `Invalid spoke chain (params.srcChain): ${params.srcChain}`);
12079
+ invariant11(isValidSpokeChainId(params.dstChain), `Invalid spoke chain (params.dstChain): ${params.dstChain}`);
12007
12080
  try {
12008
12081
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
12009
- invariant10(
12082
+ invariant11(
12010
12083
  params.srcAddress.toLowerCase() === walletAddress.toLowerCase(),
12011
12084
  "srcAddress must be the same as wallet address"
12012
12085
  );
12013
12086
  const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
12014
- const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
12015
- {
12016
- ...params,
12017
- srcAddress: walletAddress
12018
- },
12019
- creatorHubWalletAddress,
12020
- this.config,
12021
- fee,
12022
- this.hubProvider
12023
- );
12024
- const txResult = await SpokeService.deposit(
12025
- {
12026
- from: walletAddress,
12027
- to: creatorHubWalletAddress,
12028
- token: params.inputToken,
12029
- amount: params.inputAmount,
12030
- data
12031
- },
12032
- spokeProvider,
12033
- this.hubProvider,
12034
- raw
12035
- );
12036
- return {
12037
- ok: true,
12038
- value: [txResult, { ...intent, feeAmount }, data]
12039
- };
12087
+ if (spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
12088
+ const [txResult, intent, feeAmount, data] = await SonicSpokeService.createSwapIntent(
12089
+ params,
12090
+ creatorHubWalletAddress,
12091
+ this.config,
12092
+ fee,
12093
+ spokeProvider,
12094
+ this.hubProvider,
12095
+ raw
12096
+ );
12097
+ return {
12098
+ ok: true,
12099
+ value: [
12100
+ txResult,
12101
+ { ...intent, feeAmount },
12102
+ data
12103
+ ]
12104
+ };
12105
+ }
12106
+ {
12107
+ const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
12108
+ {
12109
+ ...params,
12110
+ srcAddress: walletAddress
12111
+ },
12112
+ creatorHubWalletAddress,
12113
+ this.config,
12114
+ fee,
12115
+ this.hubProvider
12116
+ );
12117
+ const txResult = await SpokeService.deposit(
12118
+ {
12119
+ from: walletAddress,
12120
+ to: creatorHubWalletAddress,
12121
+ token: params.inputToken,
12122
+ amount: params.inputAmount,
12123
+ data
12124
+ },
12125
+ spokeProvider,
12126
+ this.hubProvider,
12127
+ raw
12128
+ );
12129
+ return {
12130
+ ok: true,
12131
+ value: [txResult, { ...intent, feeAmount }, data]
12132
+ };
12133
+ }
12040
12134
  } catch (error) {
12041
12135
  return {
12042
12136
  ok: false,
@@ -12059,8 +12153,8 @@ var SolverService = class {
12059
12153
  */
12060
12154
  async cancelIntent(intent, spokeProvider, raw) {
12061
12155
  try {
12062
- invariant10(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
12063
- invariant10(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
12156
+ invariant11(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
12157
+ invariant11(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
12064
12158
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
12065
12159
  const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
12066
12160
  const calls = [];
@@ -12572,7 +12666,7 @@ var IcxMigrationService = class {
12572
12666
  migrateData(params) {
12573
12667
  const calls = [];
12574
12668
  const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.address);
12575
- invariant10(assetConfig, `hub asset not found for spoke chain token (token): ${params.address}`);
12669
+ invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${params.address}`);
12576
12670
  calls.push(
12577
12671
  Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.icxMigration, params.amount)
12578
12672
  );
@@ -12588,7 +12682,7 @@ var IcxMigrationService = class {
12588
12682
  revertMigration(params) {
12589
12683
  const calls = [];
12590
12684
  const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.wICX);
12591
- invariant10(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
12685
+ invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
12592
12686
  calls.push(
12593
12687
  Erc20Service.encodeApprove(
12594
12688
  this.hubProvider.chainConfig.addresses.sodaToken,
@@ -12684,9 +12778,9 @@ var MigrationService = class {
12684
12778
  async isAllowanceValid(params, action, spokeProvider) {
12685
12779
  try {
12686
12780
  if (action === "migrate") {
12687
- invariant10(params.amount > 0n, "Amount must be greater than 0");
12688
- invariant10(isAddress(params.to) || isIconAddress(params.to), "To address is required");
12689
- invariant10(
12781
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
12782
+ invariant11(isAddress(params.to) || isIconAddress(params.to), "To address is required");
12783
+ invariant11(
12690
12784
  isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
12691
12785
  "Invalid params"
12692
12786
  );
@@ -12712,9 +12806,9 @@ var MigrationService = class {
12712
12806
  };
12713
12807
  }
12714
12808
  if (action === "revert") {
12715
- invariant10(params.amount > 0n, "Amount must be greater than 0");
12716
- invariant10(params.to.length > 0, "To address is required");
12717
- invariant10(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
12809
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
12810
+ invariant11(params.to.length > 0, "To address is required");
12811
+ invariant11(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
12718
12812
  if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
12719
12813
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
12720
12814
  const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
@@ -12770,9 +12864,9 @@ var MigrationService = class {
12770
12864
  async approve(params, action, spokeProvider, raw) {
12771
12865
  try {
12772
12866
  if (action === "migrate") {
12773
- invariant10(params.amount > 0n, "Amount must be greater than 0");
12774
- invariant10(params.to.length > 0, "To address is required");
12775
- invariant10(isUnifiedBnUSDMigrateParams(params), "Invalid params");
12867
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
12868
+ invariant11(params.to.length > 0, "To address is required");
12869
+ invariant11(isUnifiedBnUSDMigrateParams(params), "Invalid params");
12776
12870
  if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
12777
12871
  const evmSpokeProvider = spokeProvider;
12778
12872
  const result = await Erc20Service.approve(
@@ -12793,9 +12887,9 @@ var MigrationService = class {
12793
12887
  };
12794
12888
  }
12795
12889
  if (action === "revert") {
12796
- invariant10(params.amount > 0n, "Amount must be greater than 0");
12797
- invariant10(params.to.length > 0, "To address is required");
12798
- invariant10(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
12890
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
12891
+ invariant11(params.to.length > 0, "To address is required");
12892
+ invariant11(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
12799
12893
  if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
12800
12894
  const wallet = await spokeProvider.walletProvider.getWalletAddress();
12801
12895
  const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
@@ -13207,13 +13301,13 @@ var MigrationService = class {
13207
13301
  async createMigratebnUSDIntent(params, spokeProvider, unchecked = false, raw) {
13208
13302
  try {
13209
13303
  if (!unchecked) {
13210
- invariant10(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
13211
- invariant10(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
13212
- invariant10(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
13213
- invariant10(params.dstbnUSD.length > 0, "New bnUSD token address is required");
13214
- invariant10(params.amount > 0, "Amount must be greater than 0");
13215
- invariant10(params.to.length > 0, "Recipient address is required");
13216
- invariant10(
13304
+ invariant11(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
13305
+ invariant11(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
13306
+ invariant11(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
13307
+ invariant11(params.dstbnUSD.length > 0, "New bnUSD token address is required");
13308
+ invariant11(params.amount > 0, "Amount must be greater than 0");
13309
+ invariant11(params.to.length > 0, "Recipient address is required");
13310
+ invariant11(
13217
13311
  !(isLegacybnUSDToken(params.srcbnUSD) && isLegacybnUSDToken(params.dstbnUSD)),
13218
13312
  "srcbnUSD and dstbnUSD cannot both be legacy bnUSD tokens"
13219
13313
  );
@@ -13221,11 +13315,11 @@ var MigrationService = class {
13221
13315
  let migrationData;
13222
13316
  if (isLegacybnUSDToken(params.srcbnUSD)) {
13223
13317
  if (!unchecked) {
13224
- invariant10(
13318
+ invariant11(
13225
13319
  isLegacybnUSDChainId(params.srcChainId),
13226
13320
  "srcChainId must be a legacy bnUSD chain (icon, sui, stellar) if srcbnUSD is a legacy bnUSD token"
13227
13321
  );
13228
- invariant10(
13322
+ invariant11(
13229
13323
  isNewbnUSDChainId(params.dstChainId),
13230
13324
  "dstChainId must be a new bnUSD chain (all spoke chains besides Icon) if dstbnUSD is a legacy bnUSD token"
13231
13325
  );
@@ -13240,15 +13334,15 @@ var MigrationService = class {
13240
13334
  });
13241
13335
  } else if (isLegacybnUSDToken(params.dstbnUSD)) {
13242
13336
  if (!unchecked) {
13243
- invariant10(
13337
+ invariant11(
13244
13338
  isLegacybnUSDChainId(params.dstChainId),
13245
13339
  "dstChainId must be a legacy bnUSD chain (sui, stellar, icon) if dstbnUSD is a legacy bnUSD token"
13246
13340
  );
13247
- invariant10(
13341
+ invariant11(
13248
13342
  isNewbnUSDToken(params.srcbnUSD),
13249
13343
  "srcbnUSD must be a new bnUSD token if dstbnUSD is a legacy bnUSD token"
13250
13344
  );
13251
- invariant10(
13345
+ invariant11(
13252
13346
  isNewbnUSDChainId(params.srcChainId),
13253
13347
  "srcChainId must be a new bnUSD chain (all spoke chains besides Icon) if srcbnUSD is a new bnUSD token"
13254
13348
  );
@@ -13321,13 +13415,13 @@ var MigrationService = class {
13321
13415
  */
13322
13416
  async createMigrateIcxToSodaIntent(params, spokeProvider, raw) {
13323
13417
  try {
13324
- invariant10(params.amount > 0, "Amount must be greater than 0");
13325
- invariant10(isAddress(params.to), "Recipient address is required");
13326
- invariant10(
13418
+ invariant11(params.amount > 0, "Amount must be greater than 0");
13419
+ invariant11(isAddress(params.to), "Recipient address is required");
13420
+ invariant11(
13327
13421
  params.address.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.address.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
13328
13422
  "Token must be wICX or native ICX token"
13329
13423
  );
13330
- invariant10(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
13424
+ invariant11(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
13331
13425
  const availableAmount = await this.icxMigration.getAvailableAmount();
13332
13426
  if (availableAmount < params.amount) {
13333
13427
  throw new Error(
@@ -13439,7 +13533,7 @@ var BnUSDMigrationService = class {
13439
13533
  migrateData(params) {
13440
13534
  const calls = [];
13441
13535
  const assetConfig = getHubAssetInfo(params.srcChainId, params.legacybnUSD);
13442
- invariant10(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
13536
+ invariant11(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
13443
13537
  const bnUSDVault = getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID).bnUSDVault;
13444
13538
  calls.push(Erc20Service.encodeApprove(assetConfig.asset, assetConfig.vault, params.amount));
13445
13539
  calls.push(EvmVaultTokenService.encodeDeposit(assetConfig.vault, assetConfig.asset, params.amount));
@@ -13451,7 +13545,7 @@ var BnUSDMigrationService = class {
13451
13545
  return encodeContractCalls(calls);
13452
13546
  }
13453
13547
  const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.newbnUSD);
13454
- invariant10(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
13548
+ invariant11(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
13455
13549
  calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.asset, translatedAmount));
13456
13550
  const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
13457
13551
  dstAssetConfig.decimal,
@@ -13484,14 +13578,14 @@ var BnUSDMigrationService = class {
13484
13578
  let decimals = 18;
13485
13579
  if (params.newbnUSD.toLowerCase() !== bnUSDVault.toLowerCase()) {
13486
13580
  const assetConfig = getHubAssetInfo(params.srcChainId, params.newbnUSD);
13487
- invariant10(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
13581
+ invariant11(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
13488
13582
  decimals = assetConfig.decimal;
13489
13583
  calls.push(Erc20Service.encodeApprove(assetConfig.asset, bnUSDVault, params.amount));
13490
13584
  calls.push(EvmVaultTokenService.encodeDeposit(bnUSDVault, assetConfig.asset, params.amount));
13491
13585
  }
13492
13586
  const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(decimals, params.amount);
13493
13587
  const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.legacybnUSD);
13494
- invariant10(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
13588
+ invariant11(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
13495
13589
  calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.vault, translatedAmount));
13496
13590
  calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetConfig.vault, dstAssetConfig.asset, translatedAmount));
13497
13591
  const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
@@ -13574,7 +13668,7 @@ var BalnSwapService = class {
13574
13668
  */
13575
13669
  async swapData(balnToken, params) {
13576
13670
  const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, balnToken);
13577
- invariant10(assetConfig, `hub asset not found for baln token: ${balnToken}`);
13671
+ invariant11(assetConfig, `hub asset not found for baln token: ${balnToken}`);
13578
13672
  const calls = [];
13579
13673
  calls.push(
13580
13674
  Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.balnSwap, params.amount)
@@ -15338,9 +15432,9 @@ var MoneyMarketService = class _MoneyMarketService {
15338
15432
  */
15339
15433
  async isAllowanceValid(params, spokeProvider) {
15340
15434
  try {
15341
- invariant10(params.amount > 0n, "Amount must be greater than 0");
15342
- invariant10(params.token.length > 0, "Token is required");
15343
- invariant10(
15435
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
15436
+ invariant11(params.token.length > 0, "Token is required");
15437
+ invariant11(
15344
15438
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15345
15439
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15346
15440
  );
@@ -15435,19 +15529,19 @@ var MoneyMarketService = class _MoneyMarketService {
15435
15529
  */
15436
15530
  async approve(params, spokeProvider, raw) {
15437
15531
  try {
15438
- invariant10(params.amount > 0n, "Amount must be greater than 0");
15439
- invariant10(params.token.length > 0, "Token is required");
15440
- invariant10(
15532
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
15533
+ invariant11(params.token.length > 0, "Token is required");
15534
+ invariant11(
15441
15535
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15442
15536
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15443
15537
  );
15444
15538
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
15445
15539
  if (spokeProvider instanceof EvmSpokeProvider) {
15446
- invariant10(
15540
+ invariant11(
15447
15541
  params.action === "supply" || params.action === "repay",
15448
15542
  "Invalid action (only supply and repay are supported on evm)"
15449
15543
  );
15450
- invariant10(isAddress(params.token), "Invalid token address");
15544
+ invariant11(isAddress(params.token), "Invalid token address");
15451
15545
  const result = await Erc20Service.approve(
15452
15546
  params.token,
15453
15547
  params.amount,
@@ -15461,11 +15555,11 @@ var MoneyMarketService = class _MoneyMarketService {
15461
15555
  };
15462
15556
  }
15463
15557
  if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
15464
- invariant10(
15558
+ invariant11(
15465
15559
  params.action === "withdraw" || params.action === "borrow" || params.action === "supply" || params.action === "repay",
15466
15560
  "Invalid action (only withdraw, borrow, supply and repay are supported on sonic)"
15467
15561
  );
15468
- invariant10(isAddress(params.token), "Invalid token address");
15562
+ invariant11(isAddress(params.token), "Invalid token address");
15469
15563
  if (params.action === "withdraw") {
15470
15564
  const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
15471
15565
  params.token,
@@ -15637,10 +15731,10 @@ var MoneyMarketService = class _MoneyMarketService {
15637
15731
  */
15638
15732
  async createSupplyIntent(params, spokeProvider, raw) {
15639
15733
  try {
15640
- invariant10(params.action === "supply", "Invalid action");
15641
- invariant10(params.token.length > 0, "Token is required");
15642
- invariant10(params.amount > 0n, "Amount must be greater than 0");
15643
- invariant10(
15734
+ invariant11(params.action === "supply", "Invalid action");
15735
+ invariant11(params.token.length > 0, "Token is required");
15736
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
15737
+ invariant11(
15644
15738
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15645
15739
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15646
15740
  );
@@ -15792,10 +15886,10 @@ var MoneyMarketService = class _MoneyMarketService {
15792
15886
  * }
15793
15887
  */
15794
15888
  async createBorrowIntent(params, spokeProvider, raw) {
15795
- invariant10(params.action === "borrow", "Invalid action");
15796
- invariant10(params.token.length > 0, "Token is required");
15797
- invariant10(params.amount > 0n, "Amount must be greater than 0");
15798
- invariant10(
15889
+ invariant11(params.action === "borrow", "Invalid action");
15890
+ invariant11(params.token.length > 0, "Token is required");
15891
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
15892
+ invariant11(
15799
15893
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15800
15894
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15801
15895
  );
@@ -15927,10 +16021,10 @@ var MoneyMarketService = class _MoneyMarketService {
15927
16021
  * }
15928
16022
  */
15929
16023
  async createWithdrawIntent(params, spokeProvider, raw) {
15930
- invariant10(params.action === "withdraw", "Invalid action");
15931
- invariant10(params.token.length > 0, "Token is required");
15932
- invariant10(params.amount > 0n, "Amount must be greater than 0");
15933
- invariant10(
16024
+ invariant11(params.action === "withdraw", "Invalid action");
16025
+ invariant11(params.token.length > 0, "Token is required");
16026
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
16027
+ invariant11(
15934
16028
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
15935
16029
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
15936
16030
  );
@@ -16082,10 +16176,10 @@ var MoneyMarketService = class _MoneyMarketService {
16082
16176
  * }
16083
16177
  */
16084
16178
  async createRepayIntent(params, spokeProvider, raw) {
16085
- invariant10(params.action === "repay", "Invalid action");
16086
- invariant10(params.token.length > 0, "Token is required");
16087
- invariant10(params.amount > 0n, "Amount must be greater than 0");
16088
- invariant10(
16179
+ invariant11(params.action === "repay", "Invalid action");
16180
+ invariant11(params.token.length > 0, "Token is required");
16181
+ invariant11(params.amount > 0n, "Amount must be greater than 0");
16182
+ invariant11(
16089
16183
  isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
16090
16184
  `Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
16091
16185
  );
@@ -16128,7 +16222,7 @@ var MoneyMarketService = class _MoneyMarketService {
16128
16222
  buildSupplyData(token, to, amount, spokeChainId) {
16129
16223
  const calls = [];
16130
16224
  const assetConfig = getHubAssetInfo(spokeChainId, token);
16131
- invariant10(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
16225
+ invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
16132
16226
  let assetAddress = assetConfig.asset;
16133
16227
  const vaultAddress = assetConfig.vault;
16134
16228
  const lendingPool = this.config.lendingPool;
@@ -16159,13 +16253,13 @@ var MoneyMarketService = class _MoneyMarketService {
16159
16253
  * @returns {Hex} The transaction data.
16160
16254
  */
16161
16255
  buildBorrowData(from, to, token, amount, spokeChainId) {
16162
- invariant10(isValidSpokeChainId(spokeChainId), `Invalid spokeChainId: ${spokeChainId}`);
16163
- invariant10(
16256
+ invariant11(isValidSpokeChainId(spokeChainId), `Invalid spokeChainId: ${spokeChainId}`);
16257
+ invariant11(
16164
16258
  isValidOriginalAssetAddress(spokeChainId, token),
16165
16259
  `Unsupported spoke chain (${spokeChainId}) token: ${token}`
16166
16260
  );
16167
16261
  const assetConfig = getHubAssetInfo(spokeChainId, token);
16168
- invariant10(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
16262
+ invariant11(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
16169
16263
  let assetAddress = assetConfig.asset;
16170
16264
  const vaultAddress = assetConfig.vault;
16171
16265
  const bnUSDVault = this.config.bnUSDVault;