@sodax/sdk 0.0.1-rc.12 → 0.0.1-rc.14

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
@@ -4,12 +4,16 @@ var viem = require('viem');
4
4
  var chains = require('viem/chains');
5
5
  var types = require('@sodax/types');
6
6
  var stargate = require('@cosmjs/stargate');
7
+ var networks = require('@injectivelabs/networks');
8
+ var sdkTs = require('@injectivelabs/sdk-ts');
7
9
  var IconSdkRaw = require('icon-sdk-js');
8
10
  var stellarSdk = require('@stellar/stellar-sdk');
9
11
  var bcs = require('@mysten/sui/bcs');
12
+ var client = require('@mysten/sui/client');
10
13
  var transactions = require('@mysten/sui/transactions');
11
14
  var web3_js = require('@solana/web3.js');
12
15
  var invariant2 = require('tiny-invariant');
16
+ var tx_js = require('cosmjs-types/cosmos/tx/v1beta1/tx.js');
13
17
  var rlp = require('rlp');
14
18
  var splToken = require('@solana/spl-token');
15
19
  var anchor = require('@coral-xyz/anchor');
@@ -6707,8 +6711,8 @@ var isNativeToken = (chainId, token) => {
6707
6711
  return token.address.toLowerCase() === spokeChainConfig[chainId].nativeToken.toLowerCase();
6708
6712
  };
6709
6713
 
6710
- // src/entities/cosmos/CW20Token.ts
6711
- var CW20Token = class {
6714
+ // src/entities/injective/Injective20Token.ts
6715
+ var Injective20Token = class {
6712
6716
  client;
6713
6717
  contractAddress;
6714
6718
  constructor(client, contractAddress) {
@@ -6772,14 +6776,16 @@ var CW20Token = class {
6772
6776
  return await this.client.execute(senderAddress, this.contractAddress, msg, "auto");
6773
6777
  }
6774
6778
  };
6775
-
6776
- // src/entities/cosmos/CWSpokeProvider.ts
6777
- var CWSpokeProvider = class {
6779
+ var InjectiveSpokeProvider = class {
6778
6780
  walletProvider;
6779
6781
  chainConfig;
6782
+ txClient;
6780
6783
  constructor(conf, walletProvider) {
6781
6784
  this.chainConfig = conf;
6782
6785
  this.walletProvider = walletProvider;
6786
+ this.txClient = new sdkTs.TxGrpcClient(
6787
+ networks.getNetworkEndpoints(this.chainConfig.network === "Mainnet" ? networks.Network.Mainnet : networks.Network.Testnet).grpc
6788
+ );
6783
6789
  }
6784
6790
  // Query Methods
6785
6791
  async getState() {
@@ -6822,8 +6828,8 @@ var CWSpokeProvider = class {
6822
6828
  return res.transactionHash;
6823
6829
  }
6824
6830
  async depositToken(sender, tokenAddress, to, amount, data = new Uint8Array(), raw) {
6825
- const cw20Token = new CW20Token(this.walletProvider, tokenAddress);
6826
- await cw20Token.increaseAllowance(sender, this.chainConfig.addresses.assetManager, amount);
6831
+ const injective20Token = new Injective20Token(this.walletProvider, tokenAddress);
6832
+ await injective20Token.increaseAllowance(sender, this.chainConfig.addresses.assetManager, amount);
6827
6833
  return this.transfer(sender, tokenAddress, to, amount, data, [], raw);
6828
6834
  }
6829
6835
  static async deposit(sender, token_address, to, amount, data = "0x", provider, raw) {
@@ -6841,11 +6847,13 @@ var CWSpokeProvider = class {
6841
6847
  }
6842
6848
  async isNative(token) {
6843
6849
  let isNative2 = true;
6844
- const cw20Token = new CW20Token(this.walletProvider, token);
6850
+ const injective20Token = new Injective20Token(this.walletProvider, token);
6845
6851
  try {
6846
- await cw20Token.getTokenInfo();
6852
+ await injective20Token.getTokenInfo();
6847
6853
  isNative2 = false;
6848
6854
  } catch (err) {
6855
+ console.error("[InjectiveSpokeProvider] isNative error", err);
6856
+ throw err;
6849
6857
  }
6850
6858
  return isNative2;
6851
6859
  }
@@ -6916,15 +6924,17 @@ var CWSpokeProvider = class {
6916
6924
  return num.toString();
6917
6925
  }
6918
6926
  };
6919
- var IconSdk = IconSdkRaw__namespace.default?.default ? IconSdkRaw__namespace.default : IconSdkRaw__namespace;
6927
+ var IconSdk = "default" in IconSdkRaw__namespace.default ? IconSdkRaw__namespace.default : IconSdkRaw__namespace;
6920
6928
  var IconSpokeProvider = class {
6921
6929
  walletProvider;
6922
6930
  chainConfig;
6923
6931
  iconService;
6924
- constructor(walletProvider, chainConfig, rpcUrl = "https://ctz.solidwallet.io/api/v3") {
6932
+ debugRpcUrl;
6933
+ constructor(walletProvider, chainConfig, rpcUrl = "https://ctz.solidwallet.io/api/v3", debugRpcUrl = "https://ctz.solidwallet.io/api/v3d") {
6925
6934
  this.walletProvider = walletProvider;
6926
6935
  this.chainConfig = chainConfig;
6927
6936
  this.iconService = new IconSdk.IconService(new IconSdk.IconService.HttpProvider(rpcUrl));
6937
+ this.debugRpcUrl = debugRpcUrl;
6928
6938
  }
6929
6939
  };
6930
6940
 
@@ -7175,7 +7185,7 @@ var StellarSpokeProvider = class {
7175
7185
  networkPassphrase: network.passphrase
7176
7186
  }).addOperation(operation).setTimeout(STELLAR_DEFAULT_TX_TIMEOUT_SECONDS).build();
7177
7187
  const simulation = await this.sorobanServer.simulateTransaction(priorityTransaction);
7178
- return [stellarSdk.SorobanRpc.assembleTransaction(priorityTransaction, simulation).build(), simulation];
7188
+ return [priorityTransaction, simulation];
7179
7189
  }
7180
7190
  handleSendTransactionError(response) {
7181
7191
  if (response.status === "ERROR") {
@@ -7263,9 +7273,14 @@ var StellarSpokeProvider = class {
7263
7273
  const accountResponse = await this.server.loadAccount(walletAddress);
7264
7274
  const stellarAccount = new CustomStellarAccount(accountResponse);
7265
7275
  const depositCall = this.buildDepositCall(walletAddress, token, amount, recipient, data);
7266
- const [priorityTx, simulation] = await this.buildPriorityStellarTransaction(stellarAccount, network, depositCall);
7276
+ const [rawPriorityTx, simulation] = await this.buildPriorityStellarTransaction(
7277
+ stellarAccount,
7278
+ network,
7279
+ depositCall
7280
+ );
7281
+ const assembledPriorityTx = stellarSdk.SorobanRpc.assembleTransaction(rawPriorityTx, simulation).build();
7267
7282
  if (raw) {
7268
- const transactionXdr = priorityTx.toXDR();
7283
+ const transactionXdr = rawPriorityTx.toXDR();
7269
7284
  return {
7270
7285
  from: walletAddress,
7271
7286
  to: this.chainConfig.addresses.assetManager,
@@ -7273,7 +7288,13 @@ var StellarSpokeProvider = class {
7273
7288
  data: transactionXdr
7274
7289
  };
7275
7290
  }
7276
- const hash = await this.submitOrRestoreAndRetry(stellarAccount, network, priorityTx, depositCall, simulation);
7291
+ const hash = await this.submitOrRestoreAndRetry(
7292
+ stellarAccount,
7293
+ network,
7294
+ assembledPriorityTx,
7295
+ depositCall,
7296
+ simulation
7297
+ );
7277
7298
  return `${hash}`;
7278
7299
  } catch (error) {
7279
7300
  console.error("Error during deposit:", error);
@@ -7342,9 +7363,11 @@ var StellarSpokeProvider = class {
7342
7363
  var SuiSpokeProvider = class _SuiSpokeProvider {
7343
7364
  walletProvider;
7344
7365
  chainConfig;
7366
+ publicClient;
7345
7367
  constructor(config, wallet_provider) {
7346
7368
  this.chainConfig = config;
7347
7369
  this.walletProvider = wallet_provider;
7370
+ this.publicClient = new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
7348
7371
  }
7349
7372
  async getBalance(token) {
7350
7373
  const assetmanager = this.splitAddress(this.chainConfig.addresses.assetManager);
@@ -7384,7 +7407,11 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
7384
7407
  ]
7385
7408
  });
7386
7409
  if (raw) {
7387
- const transactionRaw = await tx.build();
7410
+ tx.setSender(walletAddress);
7411
+ const transactionRaw = await tx.build({
7412
+ client: this.publicClient,
7413
+ onlyTransactionKind: true
7414
+ });
7388
7415
  const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
7389
7416
  return {
7390
7417
  from: walletAddress,
@@ -7447,10 +7474,14 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
7447
7474
  txb.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(data))
7448
7475
  ]
7449
7476
  });
7477
+ const walletAddress = await this.walletProvider.getWalletAddress();
7450
7478
  if (raw) {
7451
- const transactionRaw = await txb.build();
7479
+ txb.setSender(walletAddress);
7480
+ const transactionRaw = await txb.build({
7481
+ client: this.publicClient,
7482
+ onlyTransactionKind: true
7483
+ });
7452
7484
  const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
7453
- const walletAddress = await this.walletProvider.getWalletAddressBytes();
7454
7485
  return {
7455
7486
  from: walletAddress,
7456
7487
  to: `${connection.packageId}::${connection.moduleId}::send_message_ua`,
@@ -8113,6 +8144,15 @@ function encodeAddress(spokeChainId, address) {
8113
8144
  return address;
8114
8145
  }
8115
8146
  }
8147
+ function hexToBigInt(hex) {
8148
+ const trimmed = hex.trim().toLowerCase();
8149
+ const isValid = /^(0x)?[0-9a-f]+$/.test(trimmed);
8150
+ if (!isValid) {
8151
+ throw new Error(`Invalid hex string: "${hex}"`);
8152
+ }
8153
+ const normalized = trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`;
8154
+ return BigInt(normalized);
8155
+ }
8116
8156
  var MoneyMarketService = class _MoneyMarketService {
8117
8157
  config;
8118
8158
  hubProvider;
@@ -8140,6 +8180,15 @@ var MoneyMarketService = class _MoneyMarketService {
8140
8180
  }
8141
8181
  this.hubProvider = hubProvider;
8142
8182
  }
8183
+ /**
8184
+ * Estimate the gas for a raw transaction.
8185
+ * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
8186
+ * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
8187
+ * @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
8188
+ */
8189
+ static async estimateGas(params, spokeProvider) {
8190
+ return SpokeService.estimateGas(params, spokeProvider);
8191
+ }
8143
8192
  /**
8144
8193
  * Check if allowance is sufficient for actions on the money market pool
8145
8194
  * @param {MoneyMarketParams} params - Money market params containing token address and amount
@@ -9303,6 +9352,37 @@ var MoneyMarketService = class _MoneyMarketService {
9303
9352
  var EvmSpokeService = class _EvmSpokeService {
9304
9353
  constructor() {
9305
9354
  }
9355
+ /**
9356
+ * Estimates the gas necessary to complete a transaction without submitting it to the network.
9357
+ *
9358
+ * - Docs: https://viem.sh/docs/actions/public/estimateGas
9359
+ * - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
9360
+ *
9361
+ * @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
9362
+ * @param {EvmSpokeProvider} spokeProvider - The EVM spoke provider.
9363
+ * @returns {Promise<bigint>} Estimated gas for the transaction.
9364
+ *
9365
+ * @example
9366
+ *
9367
+ * const rawTx: EvmRawTransaction = {
9368
+ * from: '0x1234...abcd', // sender address
9369
+ * to: '0xabcd...1234', // recipient address
9370
+ * value: 1000000000000000000n, // 1 ETH in wei
9371
+ * data: '0x', // no calldata
9372
+ * };
9373
+ *
9374
+ * // Assume spokeProvider is an initialized EvmSpokeProvider
9375
+ * const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
9376
+ * console.log(`Estimated gas: ${estimatedGas}`);
9377
+ */
9378
+ static async estimateGas(rawTx, spokeProvider) {
9379
+ return spokeProvider.publicClient.estimateGas({
9380
+ account: rawTx.from,
9381
+ to: rawTx.to,
9382
+ value: rawTx.value,
9383
+ data: rawTx.data
9384
+ });
9385
+ }
9306
9386
  /**
9307
9387
  * Deposit tokens to the spoke chain.
9308
9388
  * @param {EvmSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
@@ -9416,16 +9496,35 @@ var EvmSpokeService = class _EvmSpokeService {
9416
9496
  return spokeProvider.walletProvider.sendTransaction(rawTx);
9417
9497
  }
9418
9498
  };
9419
- var CWSpokeService = class _CWSpokeService {
9499
+ var InjectiveSpokeService = class _InjectiveSpokeService {
9420
9500
  constructor() {
9421
9501
  }
9502
+ /**
9503
+ * Estimate the gas for a transaction.
9504
+ * @param {InjectiveRawTransaction} rawTx - The raw transaction to estimate the gas for.
9505
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9506
+ * @returns {Promise<InjectiveGasEstimate>} The estimated gas for the transaction.
9507
+ */
9508
+ static async estimateGas(rawTx, spokeProvider) {
9509
+ const txRaw = tx_js.TxRaw.fromPartial({
9510
+ bodyBytes: rawTx.signedDoc.bodyBytes,
9511
+ authInfoBytes: rawTx.signedDoc.authInfoBytes,
9512
+ signatures: []
9513
+ // not required for simulation
9514
+ });
9515
+ const { gasInfo } = await spokeProvider.txClient.simulate(txRaw);
9516
+ return {
9517
+ gasWanted: gasInfo.gasWanted,
9518
+ gasUsed: gasInfo.gasUsed
9519
+ };
9520
+ }
9422
9521
  /**
9423
9522
  * Deposit tokens to the spoke chain.
9424
- * @param {CWSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
9425
- * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
9523
+ * @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
9524
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9426
9525
  * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9427
9526
  * @param {boolean} raw - The return type raw or just transaction hash
9428
- * @returns {PromiseCWTxReturnType<R>} A promise that resolves to the transaction hash.
9527
+ * @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
9429
9528
  */
9430
9529
  static async deposit(params, spokeProvider, hubProvider, raw) {
9431
9530
  const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
@@ -9433,7 +9532,7 @@ var CWSpokeService = class _CWSpokeService {
9433
9532
  viem.toHex(Buffer.from(params.from, "utf-8")),
9434
9533
  hubProvider
9435
9534
  );
9436
- return _CWSpokeService.transfer(
9535
+ return _InjectiveSpokeService.transfer(
9437
9536
  {
9438
9537
  token: params.token,
9439
9538
  recipient: userWallet,
@@ -9447,7 +9546,7 @@ var CWSpokeService = class _CWSpokeService {
9447
9546
  /**
9448
9547
  * Get the balance of the token in the spoke chain.
9449
9548
  * @param {Address} token - The address of the token to get the balance of.
9450
- * @param {CWSpokeProvider} spokeProvider - The spoke provider.
9549
+ * @param {InjectiveSpokeProvider} spokeProvider - The spoke provider.
9451
9550
  * @returns {Promise<bigint>} The balance of the token.
9452
9551
  */
9453
9552
  static async getDeposit(token, spokeProvider) {
@@ -9458,47 +9557,80 @@ var CWSpokeService = class _CWSpokeService {
9458
9557
  * Calls a contract on the spoke chain using the user's wallet.
9459
9558
  * @param {HubAddress} from - The address of the user on the hub chain.
9460
9559
  * @param {Hex} payload - The payload to send to the contract.
9461
- * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
9560
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9462
9561
  * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9463
- * @returns {PromiseCWTxReturnType<R>} A promise that resolves to the transaction hash.
9562
+ * @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
9464
9563
  */
9465
9564
  static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
9466
9565
  const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
9467
- return _CWSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
9566
+ return _InjectiveSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
9468
9567
  }
9469
9568
  /**
9470
9569
  * Transfers tokens to the hub chain.
9471
- * @param {TransferToHubParams} params - The parameters for the transfer, including:
9570
+ * @param {InjectiveTransferToHubParams} params - The parameters for the transfer, including:
9472
9571
  * - {string} token: The address of the token to transfer (use address(0) for native token).
9473
9572
  * - {Uint8Array} recipient: The recipient address on the hub chain.
9474
9573
  * - {string} amount: The amount to transfer.
9475
9574
  * - {Uint8Array} [data=new Uint8Array([])]: Additional data for the transfer.
9476
- * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
9575
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9477
9576
  * @param {boolean} raw - The return type raw or just transaction hash
9478
- * @returns {PromiseCWTxReturnType<R>} A promise that resolves to the transaction hash.
9577
+ * @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
9479
9578
  */
9480
9579
  static async transfer({ token, recipient, amount, data = "0x" }, spokeProvider, raw) {
9481
9580
  const sender = await spokeProvider.walletProvider.getWalletAddress();
9482
- return CWSpokeProvider.deposit(sender, token, recipient, amount, data, spokeProvider, raw);
9581
+ return InjectiveSpokeProvider.deposit(sender, token, recipient, amount, data, spokeProvider, raw);
9483
9582
  }
9484
9583
  /**
9485
9584
  * Sends a message to the hub chain.
9486
9585
  * @param {bigint} dstChainId - The chain ID of the hub chain.
9487
9586
  * @param {Address} dstAddress - The address on the hub chain.
9488
9587
  * @param {Hex} payload - The payload to send.
9489
- * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
9490
- * @returns {PromiseCWTxReturnType<R>} A promise that resolves to the transaction hash.
9588
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9589
+ * @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
9491
9590
  */
9492
9591
  static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
9493
9592
  const sender = await spokeProvider.walletProvider.getWalletAddress();
9494
9593
  return spokeProvider.send_message(sender, dstChainId.toString(), dstAddress, payload, raw);
9495
9594
  }
9496
9595
  };
9497
- var IconSdk2 = IconSdkRaw__namespace.default?.default ? IconSdkRaw__namespace.default : IconSdkRaw__namespace;
9596
+
9597
+ // src/utils/icon-utils.ts
9598
+ async function estimateStepCost(rawTx, debugRpcUrl) {
9599
+ try {
9600
+ const tmpRawTx = { ...rawTx };
9601
+ delete tmpRawTx["stepLimit"];
9602
+ const response = await fetch(debugRpcUrl, {
9603
+ method: "POST",
9604
+ headers: {
9605
+ "Content-Type": "application/json"
9606
+ },
9607
+ body: JSON.stringify({
9608
+ jsonrpc: "2.0",
9609
+ method: "debug_estimateStep",
9610
+ id: 1234,
9611
+ params: tmpRawTx
9612
+ })
9613
+ });
9614
+ if (!response.ok) {
9615
+ throw new Error(`Failed to fetch step cost: ${response.statusText}`);
9616
+ }
9617
+ const data = await response.json();
9618
+ return hexToBigInt(data.result);
9619
+ } catch (e) {
9620
+ console.error("estimateStepCost error:", e);
9621
+ throw e;
9622
+ }
9623
+ }
9624
+
9625
+ // src/services/spoke/IconSpokeService.ts
9626
+ var IconSdk2 = "default" in IconSdkRaw__namespace.default ? IconSdkRaw__namespace.default : IconSdkRaw__namespace;
9498
9627
  var { Converter, CallTransactionBuilder, CallBuilder } = IconSdk2;
9499
9628
  var IconSpokeService = class _IconSpokeService {
9500
9629
  constructor() {
9501
9630
  }
9631
+ static async estimateGas(rawTx, spokeProvider) {
9632
+ return estimateStepCost(rawTx, spokeProvider.debugRpcUrl);
9633
+ }
9502
9634
  /**
9503
9635
  * Deposit tokens to the spoke chain.
9504
9636
  * @param {IconSpokeDepositParams} params - The parameters for the deposit
@@ -9562,15 +9694,16 @@ var IconSpokeService = class _IconSpokeService {
9562
9694
  };
9563
9695
  const value = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? BigIntToHex(amount) : "0x0";
9564
9696
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
9697
+ const to = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token;
9565
9698
  const rawTransaction = Converter.toRawTransaction(
9566
- new CallTransactionBuilder().from(walletAddress).to(token).stepLimit(Converter.toBigNumber("2000000")).nid(spokeProvider.chainConfig.nid).version("0x3").timestamp((/* @__PURE__ */ new Date()).getTime() * 1e3).value(value).method("transfer").params(params).build()
9699
+ new CallTransactionBuilder().from(walletAddress).to(to).stepLimit(Converter.toBigNumber("2000000")).nid(spokeProvider.chainConfig.nid).version("0x3").timestamp((/* @__PURE__ */ new Date()).getTime() * 1e3).value(value).method("transfer").params(params).build()
9567
9700
  );
9568
9701
  if (raw) {
9569
9702
  return rawTransaction;
9570
9703
  }
9571
9704
  return spokeProvider.walletProvider.sendTransaction({
9572
9705
  from: walletAddress,
9573
- to: isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token,
9706
+ to,
9574
9707
  value,
9575
9708
  nid: spokeProvider.chainConfig.nid,
9576
9709
  method: "transfer",
@@ -9687,6 +9820,22 @@ var AssetManagerPDA = {
9687
9820
  var SolanaSpokeService = class _SolanaSpokeService {
9688
9821
  constructor() {
9689
9822
  }
9823
+ /**
9824
+ * Estimate the gas for a transaction.
9825
+ * @param {SolanaRawTransaction} rawTx - The raw transaction to estimate the gas for.
9826
+ * @param {SolanaSpokeProvider} spokeProvider - The provider for the spoke chain.
9827
+ * @returns {Promise<number | undefined>} The units consumed for the transaction.
9828
+ */
9829
+ static async estimateGas(rawTx, spokeProvider) {
9830
+ const connection = new web3_js.Connection(spokeProvider.chainConfig.rpcUrl, "confirmed");
9831
+ const serializedTxBytes = Buffer.from(rawTx.data, "base64");
9832
+ const versionedTx = web3_js.VersionedTransaction.deserialize(serializedTxBytes);
9833
+ const { value } = await connection.simulateTransaction(versionedTx);
9834
+ if (value.err) {
9835
+ throw new Error(`Failed to simulate transaction: ${JSON.stringify(value.err, null, 2)}`);
9836
+ }
9837
+ return value.unitsConsumed;
9838
+ }
9690
9839
  static async deposit(params, spokeProvider, hubProvider, raw) {
9691
9840
  const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9692
9841
  spokeProvider.chainConfig.chain.id,
@@ -9867,6 +10016,24 @@ var SolanaSpokeService = class _SolanaSpokeService {
9867
10016
  var StellarSpokeService = class _StellarSpokeService {
9868
10017
  constructor() {
9869
10018
  }
10019
+ /**
10020
+ * Estimate the gas for a transaction.
10021
+ * @param rawTx - The raw transaction to estimate the gas for.
10022
+ * @param spokeProvider - The spoke provider.
10023
+ * @returns The estimated gas (minResourceFee) for the transaction.
10024
+ */
10025
+ static async estimateGas(rawTx, spokeProvider) {
10026
+ const network = await spokeProvider.sorobanServer.getNetwork();
10027
+ let tx = stellarSdk.TransactionBuilder.fromXDR(rawTx.data, network.passphrase);
10028
+ if (tx instanceof stellarSdk.FeeBumpTransaction) {
10029
+ tx = tx.innerTransaction;
10030
+ }
10031
+ const simulationForFee = await spokeProvider.sorobanServer.simulateTransaction(tx);
10032
+ if (!stellarSdk.rpc.Api.isSimulationSuccess(simulationForFee)) {
10033
+ throw new Error(`Simulation error: ${JSON.stringify(simulationForFee)}`);
10034
+ }
10035
+ return BigInt(simulationForFee.minResourceFee);
10036
+ }
9870
10037
  static async deposit(params, spokeProvider, hubProvider, raw) {
9871
10038
  const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9872
10039
  spokeProvider.chainConfig.chain.id,
@@ -9921,9 +10088,23 @@ var StellarSpokeService = class _StellarSpokeService {
9921
10088
  var SuiSpokeService = class _SuiSpokeService {
9922
10089
  constructor() {
9923
10090
  }
10091
+ /**
10092
+ * Estimate the gas for a transaction.
10093
+ * @param {SuiRawTransaction} rawTx - The raw transaction to estimate the gas for.
10094
+ * @param {SuiSpokeProvider} spokeProvider - The spoke provider.
10095
+ * @returns {Promise<bigint>} The estimated computation cost.
10096
+ */
10097
+ static async estimateGas(rawTx, spokeProvider) {
10098
+ const txb = transactions.Transaction.fromKind(rawTx.data);
10099
+ const result = await spokeProvider.publicClient.devInspectTransactionBlock({
10100
+ sender: rawTx.from,
10101
+ transactionBlock: txb
10102
+ });
10103
+ return result.effects.gasUsed;
10104
+ }
9924
10105
  /**
9925
10106
  * Deposit tokens to the spoke chain.
9926
- * @param {CWSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
10107
+ * @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
9927
10108
  * @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
9928
10109
  * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9929
10110
  * @param {boolean} raw - The return type raw or just transaction hash
@@ -9970,7 +10151,7 @@ var SuiSpokeService = class _SuiSpokeService {
9970
10151
  }
9971
10152
  /**
9972
10153
  * Transfers tokens to the hub chain.
9973
- * @param {TransferToHubParams} params - The parameters for the transfer, including:
10154
+ * @param {SuiTransferToHubParams} params - The parameters for the transfer, including:
9974
10155
  * - {string} token: The address of the token to transfer (use address(0) for native token).
9975
10156
  * - {Uint8Array} recipient: The recipient address on the hub chain.
9976
10157
  * - {string} amount: The amount to transfer.
@@ -9998,6 +10179,38 @@ var SuiSpokeService = class _SuiSpokeService {
9998
10179
  var SonicSpokeService = class _SonicSpokeService {
9999
10180
  constructor() {
10000
10181
  }
10182
+ /**
10183
+ /**
10184
+ * Estimates the gas necessary to complete a transaction without submitting it to the network.
10185
+ *
10186
+ * - Docs: https://viem.sh/docs/actions/public/estimateGas
10187
+ * - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
10188
+ *
10189
+ * @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
10190
+ * @param {SonicSpokeProvider} spokeProvider - The EVM spoke provider.
10191
+ * @returns {Promise<bigint>} Estimated gas for the transaction.
10192
+ *
10193
+ * @example
10194
+ *
10195
+ * const rawTx: EvmRawTransaction = {
10196
+ * from: '0x1234...abcd', // sender address
10197
+ * to: '0xabcd...1234', // recipient address
10198
+ * value: 1000000000000000000n, // 1 ETH in wei
10199
+ * data: '0x', // no calldata
10200
+ * };
10201
+ *
10202
+ * // Assume spokeProvider is an initialized EvmSpokeProvider
10203
+ * const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
10204
+ * console.log(`Estimated gas: ${estimatedGas}`);
10205
+ */
10206
+ static async estimateGas(rawTx, spokeProvider) {
10207
+ return spokeProvider.publicClient.estimateGas({
10208
+ account: rawTx.from,
10209
+ to: rawTx.to,
10210
+ value: rawTx.value,
10211
+ data: rawTx.data
10212
+ });
10213
+ }
10001
10214
  /**
10002
10215
  * Get the derived address of a contract deployed with CREATE3.
10003
10216
  * @param address - User's address on the specified chain as hex
@@ -10373,8 +10586,8 @@ function isSolanaSpokeProvider(value) {
10373
10586
  function isStellarSpokeProvider(value) {
10374
10587
  return typeof value === "object" && value !== null && value instanceof StellarSpokeProvider && value.chainConfig.chain.type === "STELLAR";
10375
10588
  }
10376
- function isCWSpokeProvider(value) {
10377
- return typeof value === "object" && value !== null && value instanceof CWSpokeProvider && value.chainConfig.chain.type === "INJECTIVE";
10589
+ function isInjectiveSpokeProvider(value) {
10590
+ return typeof value === "object" && value !== null && value instanceof InjectiveSpokeProvider && value.chainConfig.chain.type === "INJECTIVE";
10378
10591
  }
10379
10592
  function isIconSpokeProvider(value) {
10380
10593
  return typeof value === "object" && value !== null && value instanceof IconSpokeProvider && value.chainConfig.chain.type === "ICON";
@@ -10438,6 +10651,57 @@ function isMoneyMarketRepayUnknownError(error) {
10438
10651
  var SpokeService = class {
10439
10652
  constructor() {
10440
10653
  }
10654
+ /**
10655
+ * Estimate the gas for a raw transaction.
10656
+ * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
10657
+ * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
10658
+ * @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
10659
+ */
10660
+ static async estimateGas(params, spokeProvider) {
10661
+ if (spokeProvider instanceof EvmSpokeProvider) {
10662
+ return EvmSpokeService.estimateGas(
10663
+ params,
10664
+ spokeProvider
10665
+ );
10666
+ }
10667
+ if (spokeProvider instanceof SonicSpokeProvider) {
10668
+ return SonicSpokeService.estimateGas(
10669
+ params,
10670
+ spokeProvider
10671
+ );
10672
+ }
10673
+ if (spokeProvider instanceof InjectiveSpokeProvider) {
10674
+ return InjectiveSpokeService.estimateGas(
10675
+ params,
10676
+ spokeProvider
10677
+ );
10678
+ }
10679
+ if (spokeProvider instanceof IconSpokeProvider) {
10680
+ return IconSpokeService.estimateGas(
10681
+ params,
10682
+ spokeProvider
10683
+ );
10684
+ }
10685
+ if (spokeProvider instanceof SuiSpokeProvider) {
10686
+ return SuiSpokeService.estimateGas(
10687
+ params,
10688
+ spokeProvider
10689
+ );
10690
+ }
10691
+ if (spokeProvider instanceof SolanaSpokeProvider) {
10692
+ return SolanaSpokeService.estimateGas(
10693
+ params,
10694
+ spokeProvider
10695
+ );
10696
+ }
10697
+ if (spokeProvider instanceof StellarSpokeProvider) {
10698
+ return StellarSpokeService.estimateGas(
10699
+ params,
10700
+ spokeProvider
10701
+ );
10702
+ }
10703
+ throw new Error("Invalid spoke provider");
10704
+ }
10441
10705
  /**
10442
10706
  * Deposit tokens to the spoke chain.
10443
10707
  * @param {GetSpokeDepositParamsType<T extends SpokeProvider>} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
@@ -10461,8 +10725,8 @@ var SpokeService = class {
10461
10725
  raw
10462
10726
  );
10463
10727
  }
10464
- if (spokeProvider instanceof CWSpokeProvider) {
10465
- return CWSpokeService.deposit(
10728
+ if (spokeProvider instanceof InjectiveSpokeProvider) {
10729
+ return InjectiveSpokeService.deposit(
10466
10730
  params,
10467
10731
  spokeProvider,
10468
10732
  hubProvider,
@@ -10513,8 +10777,8 @@ var SpokeService = class {
10513
10777
  if (spokeProvider instanceof EvmSpokeProvider) {
10514
10778
  return EvmSpokeService.getDeposit(token, spokeProvider);
10515
10779
  }
10516
- if (spokeProvider instanceof CWSpokeProvider) {
10517
- return CWSpokeService.getDeposit(token, spokeProvider);
10780
+ if (spokeProvider instanceof InjectiveSpokeProvider) {
10781
+ return InjectiveSpokeService.getDeposit(token, spokeProvider);
10518
10782
  }
10519
10783
  if (spokeProvider instanceof StellarSpokeProvider) {
10520
10784
  return StellarSpokeService.getDeposit(token, spokeProvider);
@@ -10548,8 +10812,14 @@ var SpokeService = class {
10548
10812
  if (isEvmSpokeProvider(spokeProvider)) {
10549
10813
  return await EvmSpokeService.callWallet(from, payload, spokeProvider, hubProvider);
10550
10814
  }
10551
- if (isCWSpokeProvider(spokeProvider)) {
10552
- return await CWSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
10815
+ if (isInjectiveSpokeProvider(spokeProvider)) {
10816
+ return await InjectiveSpokeService.callWallet(
10817
+ from,
10818
+ payload,
10819
+ spokeProvider,
10820
+ hubProvider,
10821
+ raw
10822
+ );
10553
10823
  }
10554
10824
  if (isIconSpokeProvider(spokeProvider)) {
10555
10825
  return await IconSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
@@ -11070,6 +11340,15 @@ var SolverService = class {
11070
11340
  }
11071
11341
  this.hubProvider = hubProvider;
11072
11342
  }
11343
+ /**
11344
+ * Estimate the gas for a raw transaction.
11345
+ * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
11346
+ * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
11347
+ * @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
11348
+ */
11349
+ static async estimateGas(params, spokeProvider) {
11350
+ return SpokeService.estimateGas(params, spokeProvider);
11351
+ }
11073
11352
  /**
11074
11353
  * Request a quote from the solver API
11075
11354
  * @param {SolverIntentQuoteRequest} payload - The solver intent quote request
@@ -12601,7 +12880,6 @@ var SolverIntentErrorCode = /* @__PURE__ */ ((SolverIntentErrorCode2) => {
12601
12880
  })(SolverIntentErrorCode || {});
12602
12881
 
12603
12882
  exports.BigIntToHex = BigIntToHex;
12604
- exports.CWSpokeProvider = CWSpokeProvider;
12605
12883
  exports.DEFAULT_MAX_RETRY = DEFAULT_MAX_RETRY;
12606
12884
  exports.DEFAULT_RELAYER_API_ENDPOINT = DEFAULT_RELAYER_API_ENDPOINT;
12607
12885
  exports.DEFAULT_RELAY_TX_TIMEOUT = DEFAULT_RELAY_TX_TIMEOUT;
@@ -12622,6 +12900,7 @@ exports.ICON_TX_RESULT_WAIT_MAX_RETRY = ICON_TX_RESULT_WAIT_MAX_RETRY;
12622
12900
  exports.INTENT_RELAY_CHAIN_IDS = INTENT_RELAY_CHAIN_IDS;
12623
12901
  exports.IconSpokeProvider = IconSpokeProvider;
12624
12902
  exports.IcxMigrationService = IcxMigrationService;
12903
+ exports.InjectiveSpokeProvider = InjectiveSpokeProvider;
12625
12904
  exports.IntentCreatedEventAbi = IntentCreatedEventAbi;
12626
12905
  exports.IntentDataType = IntentDataType;
12627
12906
  exports.IntentsAbi = IntentsAbi;
@@ -12665,12 +12944,12 @@ exports.getSpokeChainIdFromIntentRelayChainId = getSpokeChainIdFromIntentRelayCh
12665
12944
  exports.getSupportedMoneyMarketTokens = getSupportedMoneyMarketTokens;
12666
12945
  exports.getSupportedSolverTokens = getSupportedSolverTokens;
12667
12946
  exports.getTransactionPackets = getTransactionPackets;
12947
+ exports.hexToBigInt = hexToBigInt;
12668
12948
  exports.hubAssetToOriginalAssetMap = hubAssetToOriginalAssetMap;
12669
12949
  exports.hubAssets = hubAssets;
12670
12950
  exports.hubVaults = hubVaults;
12671
12951
  exports.hubVaultsAddressSet = hubVaultsAddressSet;
12672
12952
  exports.intentRelayChainIdToSpokeChainIdMap = intentRelayChainIdToSpokeChainIdMap;
12673
- exports.isCWSpokeProvider = isCWSpokeProvider;
12674
12953
  exports.isConfiguredMoneyMarketConfig = isConfiguredMoneyMarketConfig;
12675
12954
  exports.isConfiguredSolverConfig = isConfiguredSolverConfig;
12676
12955
  exports.isEvmHubChainConfig = isEvmHubChainConfig;
@@ -12682,6 +12961,7 @@ exports.isEvmUninitializedConfig = isEvmUninitializedConfig;
12682
12961
  exports.isEvmUninitializedPrivateKeyConfig = isEvmUninitializedPrivateKeyConfig;
12683
12962
  exports.isIconAddress = isIconAddress;
12684
12963
  exports.isIconSpokeProvider = isIconSpokeProvider;
12964
+ exports.isInjectiveSpokeProvider = isInjectiveSpokeProvider;
12685
12965
  exports.isIntentCreationFailedError = isIntentCreationFailedError;
12686
12966
  exports.isIntentCreationUnknownError = isIntentCreationUnknownError;
12687
12967
  exports.isIntentPostExecutionFailedError = isIntentPostExecutionFailedError;