@sodax/sdk 0.0.1-rc.13 → 0.0.1-rc.15

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
@@ -3,12 +3,16 @@ import { nibiru, polygon, bsc, optimism, base, arbitrum, avalanche, sonic } from
3
3
  import { ICON_MAINNET_CHAIN_ID, SUI_MAINNET_CHAIN_ID, STELLAR_MAINNET_CHAIN_ID, INJECTIVE_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, BASE_MAINNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID, NIBIRU_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, SOLANA_MAINNET_CHAIN_ID, SONIC_MAINNET_CHAIN_ID, SPOKE_CHAIN_IDS } from '@sodax/types';
4
4
  export * from '@sodax/types';
5
5
  import { coins } from '@cosmjs/stargate';
6
+ import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
7
+ import { TxGrpcClient } from '@injectivelabs/sdk-ts';
6
8
  import * as IconSdkRaw from 'icon-sdk-js';
7
- import { SorobanRpc, Horizon, Contract, TransactionBuilder, BASE_FEE, nativeToScVal, TimeoutInfinite, rpc, scValToBigInt, Operation, Address, Account } from '@stellar/stellar-sdk';
9
+ import { SorobanRpc, Horizon, Contract, TransactionBuilder, BASE_FEE, nativeToScVal, TimeoutInfinite, rpc, scValToBigInt, Operation, Address, Account, FeeBumpTransaction } from '@stellar/stellar-sdk';
8
10
  import { bcs } from '@mysten/sui/bcs';
11
+ import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
9
12
  import { Transaction } from '@mysten/sui/transactions';
10
- import { PublicKey, SystemProgram, ComputeBudgetProgram, Connection } from '@solana/web3.js';
13
+ import { PublicKey, Connection, VersionedTransaction, SystemProgram, ComputeBudgetProgram } from '@solana/web3.js';
11
14
  import invariant2 from 'tiny-invariant';
15
+ import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
12
16
  import * as rlp from 'rlp';
13
17
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
14
18
  import * as anchor from '@coral-xyz/anchor';
@@ -5255,8 +5259,7 @@ var spokeChainConfig = {
5255
5259
  }
5256
5260
  },
5257
5261
  gasPrice: "500000",
5258
- rpcUrl: "https://solana-mainnet.g.alchemy.com/v2/i3q5fE3cYSFBE4Lcg1kS5",
5259
- wsUrl: "https://solana-mainnet.g.alchemy.com/v2/i3q5fE3cYSFBE4Lcg1kS5",
5262
+ rpcUrl: "https://api.mainnet-beta.solana.com",
5260
5263
  walletAddress: ""
5261
5264
  },
5262
5265
  [AVALANCHE_MAINNET_CHAIN_ID]: {
@@ -6745,14 +6748,16 @@ var Injective20Token = class {
6745
6748
  return await this.client.execute(senderAddress, this.contractAddress, msg, "auto");
6746
6749
  }
6747
6750
  };
6748
-
6749
- // src/entities/injective/InjectiveSpokeProvider.ts
6750
6751
  var InjectiveSpokeProvider = class {
6751
6752
  walletProvider;
6752
6753
  chainConfig;
6754
+ txClient;
6753
6755
  constructor(conf, walletProvider) {
6754
6756
  this.chainConfig = conf;
6755
6757
  this.walletProvider = walletProvider;
6758
+ this.txClient = new TxGrpcClient(
6759
+ getNetworkEndpoints(this.chainConfig.network === "Mainnet" ? Network.Mainnet : Network.Testnet).grpc
6760
+ );
6756
6761
  }
6757
6762
  // Query Methods
6758
6763
  async getState() {
@@ -6813,16 +6818,7 @@ var InjectiveSpokeProvider = class {
6813
6818
  return this.transfer(sender, token, to, amount, data, funds, raw);
6814
6819
  }
6815
6820
  async isNative(token) {
6816
- let isNative2 = true;
6817
- const injective20Token = new Injective20Token(this.walletProvider, token);
6818
- try {
6819
- await injective20Token.getTokenInfo();
6820
- isNative2 = false;
6821
- } catch (err) {
6822
- console.log("[InjectiveSpokeProvider] isNative error", err);
6823
- throw err;
6824
- }
6825
- return isNative2;
6821
+ return token === "inj";
6826
6822
  }
6827
6823
  async receiveMessage(senderAddress, srcChainId, srcAddress, connSn, payload, signatures) {
6828
6824
  const msg = {
@@ -6896,10 +6892,12 @@ var IconSpokeProvider = class {
6896
6892
  walletProvider;
6897
6893
  chainConfig;
6898
6894
  iconService;
6899
- constructor(walletProvider, chainConfig, rpcUrl = "https://ctz.solidwallet.io/api/v3") {
6895
+ debugRpcUrl;
6896
+ constructor(walletProvider, chainConfig, rpcUrl = "https://ctz.solidwallet.io/api/v3", debugRpcUrl = "https://ctz.solidwallet.io/api/v3d") {
6900
6897
  this.walletProvider = walletProvider;
6901
6898
  this.chainConfig = chainConfig;
6902
6899
  this.iconService = new IconSdk.IconService(new IconSdk.IconService.HttpProvider(rpcUrl));
6900
+ this.debugRpcUrl = debugRpcUrl;
6903
6901
  }
6904
6902
  };
6905
6903
 
@@ -7150,7 +7148,7 @@ var StellarSpokeProvider = class {
7150
7148
  networkPassphrase: network.passphrase
7151
7149
  }).addOperation(operation).setTimeout(STELLAR_DEFAULT_TX_TIMEOUT_SECONDS).build();
7152
7150
  const simulation = await this.sorobanServer.simulateTransaction(priorityTransaction);
7153
- return [SorobanRpc.assembleTransaction(priorityTransaction, simulation).build(), simulation];
7151
+ return [priorityTransaction, simulation];
7154
7152
  }
7155
7153
  handleSendTransactionError(response) {
7156
7154
  if (response.status === "ERROR") {
@@ -7238,9 +7236,14 @@ var StellarSpokeProvider = class {
7238
7236
  const accountResponse = await this.server.loadAccount(walletAddress);
7239
7237
  const stellarAccount = new CustomStellarAccount(accountResponse);
7240
7238
  const depositCall = this.buildDepositCall(walletAddress, token, amount, recipient, data);
7241
- const [priorityTx, simulation] = await this.buildPriorityStellarTransaction(stellarAccount, network, depositCall);
7239
+ const [rawPriorityTx, simulation] = await this.buildPriorityStellarTransaction(
7240
+ stellarAccount,
7241
+ network,
7242
+ depositCall
7243
+ );
7244
+ const assembledPriorityTx = SorobanRpc.assembleTransaction(rawPriorityTx, simulation).build();
7242
7245
  if (raw) {
7243
- const transactionXdr = priorityTx.toXDR();
7246
+ const transactionXdr = rawPriorityTx.toXDR();
7244
7247
  return {
7245
7248
  from: walletAddress,
7246
7249
  to: this.chainConfig.addresses.assetManager,
@@ -7248,7 +7251,13 @@ var StellarSpokeProvider = class {
7248
7251
  data: transactionXdr
7249
7252
  };
7250
7253
  }
7251
- const hash = await this.submitOrRestoreAndRetry(stellarAccount, network, priorityTx, depositCall, simulation);
7254
+ const hash = await this.submitOrRestoreAndRetry(
7255
+ stellarAccount,
7256
+ network,
7257
+ assembledPriorityTx,
7258
+ depositCall,
7259
+ simulation
7260
+ );
7252
7261
  return `${hash}`;
7253
7262
  } catch (error) {
7254
7263
  console.error("Error during deposit:", error);
@@ -7317,9 +7326,11 @@ var StellarSpokeProvider = class {
7317
7326
  var SuiSpokeProvider = class _SuiSpokeProvider {
7318
7327
  walletProvider;
7319
7328
  chainConfig;
7329
+ publicClient;
7320
7330
  constructor(config, wallet_provider) {
7321
7331
  this.chainConfig = config;
7322
7332
  this.walletProvider = wallet_provider;
7333
+ this.publicClient = new SuiClient({ url: getFullnodeUrl("mainnet") });
7323
7334
  }
7324
7335
  async getBalance(token) {
7325
7336
  const assetmanager = this.splitAddress(this.chainConfig.addresses.assetManager);
@@ -7359,7 +7370,11 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
7359
7370
  ]
7360
7371
  });
7361
7372
  if (raw) {
7362
- const transactionRaw = await tx.build();
7373
+ tx.setSender(walletAddress);
7374
+ const transactionRaw = await tx.build({
7375
+ client: this.publicClient,
7376
+ onlyTransactionKind: true
7377
+ });
7363
7378
  const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
7364
7379
  return {
7365
7380
  from: walletAddress,
@@ -7422,10 +7437,14 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
7422
7437
  txb.pure(bcs.vector(bcs.u8()).serialize(data))
7423
7438
  ]
7424
7439
  });
7440
+ const walletAddress = await this.walletProvider.getWalletAddress();
7425
7441
  if (raw) {
7426
- const transactionRaw = await txb.build();
7442
+ txb.setSender(walletAddress);
7443
+ const transactionRaw = await txb.build({
7444
+ client: this.publicClient,
7445
+ onlyTransactionKind: true
7446
+ });
7427
7447
  const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
7428
- const walletAddress = await this.walletProvider.getWalletAddressBytes();
7429
7448
  return {
7430
7449
  from: walletAddress,
7431
7450
  to: `${connection.packageId}::${connection.moduleId}::send_message_ua`,
@@ -8088,6 +8107,15 @@ function encodeAddress(spokeChainId, address) {
8088
8107
  return address;
8089
8108
  }
8090
8109
  }
8110
+ function hexToBigInt(hex) {
8111
+ const trimmed = hex.trim().toLowerCase();
8112
+ const isValid = /^(0x)?[0-9a-f]+$/.test(trimmed);
8113
+ if (!isValid) {
8114
+ throw new Error(`Invalid hex string: "${hex}"`);
8115
+ }
8116
+ const normalized = trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`;
8117
+ return BigInt(normalized);
8118
+ }
8091
8119
  var MoneyMarketService = class _MoneyMarketService {
8092
8120
  config;
8093
8121
  hubProvider;
@@ -8115,6 +8143,15 @@ var MoneyMarketService = class _MoneyMarketService {
8115
8143
  }
8116
8144
  this.hubProvider = hubProvider;
8117
8145
  }
8146
+ /**
8147
+ * Estimate the gas for a raw transaction.
8148
+ * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
8149
+ * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
8150
+ * @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
8151
+ */
8152
+ static async estimateGas(params, spokeProvider) {
8153
+ return SpokeService.estimateGas(params, spokeProvider);
8154
+ }
8118
8155
  /**
8119
8156
  * Check if allowance is sufficient for actions on the money market pool
8120
8157
  * @param {MoneyMarketParams} params - Money market params containing token address and amount
@@ -9278,6 +9315,37 @@ var MoneyMarketService = class _MoneyMarketService {
9278
9315
  var EvmSpokeService = class _EvmSpokeService {
9279
9316
  constructor() {
9280
9317
  }
9318
+ /**
9319
+ * Estimates the gas necessary to complete a transaction without submitting it to the network.
9320
+ *
9321
+ * - Docs: https://viem.sh/docs/actions/public/estimateGas
9322
+ * - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
9323
+ *
9324
+ * @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
9325
+ * @param {EvmSpokeProvider} spokeProvider - The EVM spoke provider.
9326
+ * @returns {Promise<bigint>} Estimated gas for the transaction.
9327
+ *
9328
+ * @example
9329
+ *
9330
+ * const rawTx: EvmRawTransaction = {
9331
+ * from: '0x1234...abcd', // sender address
9332
+ * to: '0xabcd...1234', // recipient address
9333
+ * value: 1000000000000000000n, // 1 ETH in wei
9334
+ * data: '0x', // no calldata
9335
+ * };
9336
+ *
9337
+ * // Assume spokeProvider is an initialized EvmSpokeProvider
9338
+ * const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
9339
+ * console.log(`Estimated gas: ${estimatedGas}`);
9340
+ */
9341
+ static async estimateGas(rawTx, spokeProvider) {
9342
+ return spokeProvider.publicClient.estimateGas({
9343
+ account: rawTx.from,
9344
+ to: rawTx.to,
9345
+ value: rawTx.value,
9346
+ data: rawTx.data
9347
+ });
9348
+ }
9281
9349
  /**
9282
9350
  * Deposit tokens to the spoke chain.
9283
9351
  * @param {EvmSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
@@ -9394,6 +9462,25 @@ var EvmSpokeService = class _EvmSpokeService {
9394
9462
  var InjectiveSpokeService = class _InjectiveSpokeService {
9395
9463
  constructor() {
9396
9464
  }
9465
+ /**
9466
+ * Estimate the gas for a transaction.
9467
+ * @param {InjectiveRawTransaction} rawTx - The raw transaction to estimate the gas for.
9468
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9469
+ * @returns {Promise<InjectiveGasEstimate>} The estimated gas for the transaction.
9470
+ */
9471
+ static async estimateGas(rawTx, spokeProvider) {
9472
+ const txRaw = TxRaw.fromPartial({
9473
+ bodyBytes: rawTx.signedDoc.bodyBytes,
9474
+ authInfoBytes: rawTx.signedDoc.authInfoBytes,
9475
+ signatures: []
9476
+ // not required for simulation
9477
+ });
9478
+ const { gasInfo } = await spokeProvider.txClient.simulate(txRaw);
9479
+ return {
9480
+ gasWanted: gasInfo.gasWanted,
9481
+ gasUsed: gasInfo.gasUsed
9482
+ };
9483
+ }
9397
9484
  /**
9398
9485
  * Deposit tokens to the spoke chain.
9399
9486
  * @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
@@ -9469,11 +9556,44 @@ var InjectiveSpokeService = class _InjectiveSpokeService {
9469
9556
  return spokeProvider.send_message(sender, dstChainId.toString(), dstAddress, payload, raw);
9470
9557
  }
9471
9558
  };
9559
+
9560
+ // src/utils/icon-utils.ts
9561
+ async function estimateStepCost(rawTx, debugRpcUrl) {
9562
+ try {
9563
+ const tmpRawTx = { ...rawTx };
9564
+ delete tmpRawTx["stepLimit"];
9565
+ const response = await fetch(debugRpcUrl, {
9566
+ method: "POST",
9567
+ headers: {
9568
+ "Content-Type": "application/json"
9569
+ },
9570
+ body: JSON.stringify({
9571
+ jsonrpc: "2.0",
9572
+ method: "debug_estimateStep",
9573
+ id: 1234,
9574
+ params: tmpRawTx
9575
+ })
9576
+ });
9577
+ if (!response.ok) {
9578
+ throw new Error(`Failed to fetch step cost: ${response.statusText}`);
9579
+ }
9580
+ const data = await response.json();
9581
+ return hexToBigInt(data.result);
9582
+ } catch (e) {
9583
+ console.error("estimateStepCost error:", e);
9584
+ throw e;
9585
+ }
9586
+ }
9587
+
9588
+ // src/services/spoke/IconSpokeService.ts
9472
9589
  var IconSdk2 = "default" in IconSdkRaw.default ? IconSdkRaw.default : IconSdkRaw;
9473
9590
  var { Converter, CallTransactionBuilder, CallBuilder } = IconSdk2;
9474
9591
  var IconSpokeService = class _IconSpokeService {
9475
9592
  constructor() {
9476
9593
  }
9594
+ static async estimateGas(rawTx, spokeProvider) {
9595
+ return estimateStepCost(rawTx, spokeProvider.debugRpcUrl);
9596
+ }
9477
9597
  /**
9478
9598
  * Deposit tokens to the spoke chain.
9479
9599
  * @param {IconSpokeDepositParams} params - The parameters for the deposit
@@ -9537,15 +9657,16 @@ var IconSpokeService = class _IconSpokeService {
9537
9657
  };
9538
9658
  const value = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? BigIntToHex(amount) : "0x0";
9539
9659
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
9660
+ const to = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token;
9540
9661
  const rawTransaction = Converter.toRawTransaction(
9541
- 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()
9662
+ 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()
9542
9663
  );
9543
9664
  if (raw) {
9544
9665
  return rawTransaction;
9545
9666
  }
9546
9667
  return spokeProvider.walletProvider.sendTransaction({
9547
9668
  from: walletAddress,
9548
- to: isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token,
9669
+ to,
9549
9670
  value,
9550
9671
  nid: spokeProvider.chainConfig.nid,
9551
9672
  method: "transfer",
@@ -9576,15 +9697,13 @@ var IconSpokeService = class _IconSpokeService {
9576
9697
  });
9577
9698
  }
9578
9699
  };
9579
- async function getProvider(base58PublicKey, rpcUrl, wsUrl) {
9700
+ async function getProvider(base58PublicKey, rpcUrl) {
9580
9701
  const wallet = {
9581
9702
  publicKey: new PublicKey(base58PublicKey),
9582
9703
  signTransaction: () => Promise.reject(),
9583
9704
  signAllTransactions: () => Promise.reject()
9584
9705
  };
9585
- const connection = new Connection(rpcUrl, {
9586
- wsEndpoint: wsUrl
9587
- });
9706
+ const connection = new Connection(rpcUrl);
9588
9707
  return new anchor.AnchorProvider(connection, wallet, { commitment: "confirmed" });
9589
9708
  }
9590
9709
  async function getAssetManagerIdl(assetManager, provider) {
@@ -9611,13 +9730,13 @@ async function getConnectionIdl(connection, provider) {
9611
9730
  throw err;
9612
9731
  }
9613
9732
  }
9614
- async function getAssetManagerProgram(base58PublicKey, rpcUrl, wsUrl, assetManager) {
9615
- const provider = await getProvider(base58PublicKey, rpcUrl, wsUrl);
9733
+ async function getAssetManagerProgram(base58PublicKey, rpcUrl, assetManager) {
9734
+ const provider = await getProvider(base58PublicKey, rpcUrl);
9616
9735
  const idl = await getAssetManagerIdl(assetManager, provider);
9617
9736
  return new anchor.Program(idl, provider);
9618
9737
  }
9619
- async function getConnectionProgram(base58PublicKey, rpcUrl, wsUrl, connection) {
9620
- const provider = await getProvider(base58PublicKey, rpcUrl, wsUrl);
9738
+ async function getConnectionProgram(base58PublicKey, rpcUrl, connection) {
9739
+ const provider = await getProvider(base58PublicKey, rpcUrl);
9621
9740
  const idl = await getConnectionIdl(connection, provider);
9622
9741
  return new anchor.Program(idl, provider);
9623
9742
  }
@@ -9662,6 +9781,22 @@ var AssetManagerPDA = {
9662
9781
  var SolanaSpokeService = class _SolanaSpokeService {
9663
9782
  constructor() {
9664
9783
  }
9784
+ /**
9785
+ * Estimate the gas for a transaction.
9786
+ * @param {SolanaRawTransaction} rawTx - The raw transaction to estimate the gas for.
9787
+ * @param {SolanaSpokeProvider} spokeProvider - The provider for the spoke chain.
9788
+ * @returns {Promise<number | undefined>} The units consumed for the transaction.
9789
+ */
9790
+ static async estimateGas(rawTx, spokeProvider) {
9791
+ const connection = new Connection(spokeProvider.chainConfig.rpcUrl, "confirmed");
9792
+ const serializedTxBytes = Buffer.from(rawTx.data, "base64");
9793
+ const versionedTx = VersionedTransaction.deserialize(serializedTxBytes);
9794
+ const { value } = await connection.simulateTransaction(versionedTx);
9795
+ if (value.err) {
9796
+ throw new Error(`Failed to simulate transaction: ${JSON.stringify(value.err, null, 2)}`);
9797
+ }
9798
+ return value.unitsConsumed;
9799
+ }
9665
9800
  static async deposit(params, spokeProvider, hubProvider, raw) {
9666
9801
  const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9667
9802
  spokeProvider.chainConfig.chain.id,
@@ -9683,7 +9818,6 @@ var SolanaSpokeService = class _SolanaSpokeService {
9683
9818
  const assetManagerProgram = await getAssetManagerProgram(
9684
9819
  spokeProvider.walletProvider.getWalletBase58PublicKey(),
9685
9820
  spokeProvider.chainConfig.rpcUrl,
9686
- spokeProvider.chainConfig.wsUrl,
9687
9821
  spokeProvider.chainConfig.addresses.assetManager
9688
9822
  );
9689
9823
  const solToken = new PublicKey(Buffer.from(token, "hex"));
@@ -9713,18 +9847,16 @@ var SolanaSpokeService = class _SolanaSpokeService {
9713
9847
  let depositInstruction;
9714
9848
  const amountBN = new BN(amount);
9715
9849
  const { walletProvider, chainConfig } = spokeProvider;
9716
- const { rpcUrl, wsUrl, addresses } = chainConfig;
9850
+ const { rpcUrl, addresses } = chainConfig;
9717
9851
  const walletPublicKey = new PublicKey(walletProvider.getWalletBase58PublicKey());
9718
9852
  const assetManagerProgram = await getAssetManagerProgram(
9719
9853
  walletProvider.getWalletBase58PublicKey(),
9720
9854
  rpcUrl,
9721
- wsUrl,
9722
9855
  addresses.assetManager
9723
9856
  );
9724
9857
  const connectionProgram = await getConnectionProgram(
9725
9858
  walletProvider.getWalletBase58PublicKey(),
9726
9859
  rpcUrl,
9727
- wsUrl,
9728
9860
  addresses.connection
9729
9861
  );
9730
9862
  if (isNative(token)) {
@@ -9799,12 +9931,11 @@ var SolanaSpokeService = class _SolanaSpokeService {
9799
9931
  */
9800
9932
  static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
9801
9933
  const { walletProvider, chainConfig } = spokeProvider;
9802
- const { rpcUrl, wsUrl, addresses } = chainConfig;
9934
+ const { rpcUrl, addresses } = chainConfig;
9803
9935
  const walletPublicKey = new PublicKey(walletProvider.getWalletBase58PublicKey());
9804
9936
  const connectionProgram = await getConnectionProgram(
9805
9937
  walletProvider.getWalletBase58PublicKey(),
9806
9938
  rpcUrl,
9807
- wsUrl,
9808
9939
  addresses.connection
9809
9940
  );
9810
9941
  const sendMessageInstruction = await connectionProgram.methods.sendMessage(
@@ -9842,6 +9973,24 @@ var SolanaSpokeService = class _SolanaSpokeService {
9842
9973
  var StellarSpokeService = class _StellarSpokeService {
9843
9974
  constructor() {
9844
9975
  }
9976
+ /**
9977
+ * Estimate the gas for a transaction.
9978
+ * @param rawTx - The raw transaction to estimate the gas for.
9979
+ * @param spokeProvider - The spoke provider.
9980
+ * @returns The estimated gas (minResourceFee) for the transaction.
9981
+ */
9982
+ static async estimateGas(rawTx, spokeProvider) {
9983
+ const network = await spokeProvider.sorobanServer.getNetwork();
9984
+ let tx = TransactionBuilder.fromXDR(rawTx.data, network.passphrase);
9985
+ if (tx instanceof FeeBumpTransaction) {
9986
+ tx = tx.innerTransaction;
9987
+ }
9988
+ const simulationForFee = await spokeProvider.sorobanServer.simulateTransaction(tx);
9989
+ if (!rpc.Api.isSimulationSuccess(simulationForFee)) {
9990
+ throw new Error(`Simulation error: ${JSON.stringify(simulationForFee)}`);
9991
+ }
9992
+ return BigInt(simulationForFee.minResourceFee);
9993
+ }
9845
9994
  static async deposit(params, spokeProvider, hubProvider, raw) {
9846
9995
  const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9847
9996
  spokeProvider.chainConfig.chain.id,
@@ -9896,6 +10045,20 @@ var StellarSpokeService = class _StellarSpokeService {
9896
10045
  var SuiSpokeService = class _SuiSpokeService {
9897
10046
  constructor() {
9898
10047
  }
10048
+ /**
10049
+ * Estimate the gas for a transaction.
10050
+ * @param {SuiRawTransaction} rawTx - The raw transaction to estimate the gas for.
10051
+ * @param {SuiSpokeProvider} spokeProvider - The spoke provider.
10052
+ * @returns {Promise<bigint>} The estimated computation cost.
10053
+ */
10054
+ static async estimateGas(rawTx, spokeProvider) {
10055
+ const txb = Transaction.fromKind(rawTx.data);
10056
+ const result = await spokeProvider.publicClient.devInspectTransactionBlock({
10057
+ sender: rawTx.from,
10058
+ transactionBlock: txb
10059
+ });
10060
+ return result.effects.gasUsed;
10061
+ }
9899
10062
  /**
9900
10063
  * Deposit tokens to the spoke chain.
9901
10064
  * @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
@@ -9945,7 +10108,7 @@ var SuiSpokeService = class _SuiSpokeService {
9945
10108
  }
9946
10109
  /**
9947
10110
  * Transfers tokens to the hub chain.
9948
- * @param {TransferToHubParams} params - The parameters for the transfer, including:
10111
+ * @param {SuiTransferToHubParams} params - The parameters for the transfer, including:
9949
10112
  * - {string} token: The address of the token to transfer (use address(0) for native token).
9950
10113
  * - {Uint8Array} recipient: The recipient address on the hub chain.
9951
10114
  * - {string} amount: The amount to transfer.
@@ -9973,6 +10136,38 @@ var SuiSpokeService = class _SuiSpokeService {
9973
10136
  var SonicSpokeService = class _SonicSpokeService {
9974
10137
  constructor() {
9975
10138
  }
10139
+ /**
10140
+ /**
10141
+ * Estimates the gas necessary to complete a transaction without submitting it to the network.
10142
+ *
10143
+ * - Docs: https://viem.sh/docs/actions/public/estimateGas
10144
+ * - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
10145
+ *
10146
+ * @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
10147
+ * @param {SonicSpokeProvider} spokeProvider - The EVM spoke provider.
10148
+ * @returns {Promise<bigint>} Estimated gas for the transaction.
10149
+ *
10150
+ * @example
10151
+ *
10152
+ * const rawTx: EvmRawTransaction = {
10153
+ * from: '0x1234...abcd', // sender address
10154
+ * to: '0xabcd...1234', // recipient address
10155
+ * value: 1000000000000000000n, // 1 ETH in wei
10156
+ * data: '0x', // no calldata
10157
+ * };
10158
+ *
10159
+ * // Assume spokeProvider is an initialized EvmSpokeProvider
10160
+ * const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
10161
+ * console.log(`Estimated gas: ${estimatedGas}`);
10162
+ */
10163
+ static async estimateGas(rawTx, spokeProvider) {
10164
+ return spokeProvider.publicClient.estimateGas({
10165
+ account: rawTx.from,
10166
+ to: rawTx.to,
10167
+ value: rawTx.value,
10168
+ data: rawTx.data
10169
+ });
10170
+ }
9976
10171
  /**
9977
10172
  * Get the derived address of a contract deployed with CREATE3.
9978
10173
  * @param address - User's address on the specified chain as hex
@@ -10413,6 +10608,57 @@ function isMoneyMarketRepayUnknownError(error) {
10413
10608
  var SpokeService = class {
10414
10609
  constructor() {
10415
10610
  }
10611
+ /**
10612
+ * Estimate the gas for a raw transaction.
10613
+ * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
10614
+ * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
10615
+ * @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
10616
+ */
10617
+ static async estimateGas(params, spokeProvider) {
10618
+ if (spokeProvider instanceof EvmSpokeProvider) {
10619
+ return EvmSpokeService.estimateGas(
10620
+ params,
10621
+ spokeProvider
10622
+ );
10623
+ }
10624
+ if (spokeProvider instanceof SonicSpokeProvider) {
10625
+ return SonicSpokeService.estimateGas(
10626
+ params,
10627
+ spokeProvider
10628
+ );
10629
+ }
10630
+ if (spokeProvider instanceof InjectiveSpokeProvider) {
10631
+ return InjectiveSpokeService.estimateGas(
10632
+ params,
10633
+ spokeProvider
10634
+ );
10635
+ }
10636
+ if (spokeProvider instanceof IconSpokeProvider) {
10637
+ return IconSpokeService.estimateGas(
10638
+ params,
10639
+ spokeProvider
10640
+ );
10641
+ }
10642
+ if (spokeProvider instanceof SuiSpokeProvider) {
10643
+ return SuiSpokeService.estimateGas(
10644
+ params,
10645
+ spokeProvider
10646
+ );
10647
+ }
10648
+ if (spokeProvider instanceof SolanaSpokeProvider) {
10649
+ return SolanaSpokeService.estimateGas(
10650
+ params,
10651
+ spokeProvider
10652
+ );
10653
+ }
10654
+ if (spokeProvider instanceof StellarSpokeProvider) {
10655
+ return StellarSpokeService.estimateGas(
10656
+ params,
10657
+ spokeProvider
10658
+ );
10659
+ }
10660
+ throw new Error("Invalid spoke provider");
10661
+ }
10416
10662
  /**
10417
10663
  * Deposit tokens to the spoke chain.
10418
10664
  * @param {GetSpokeDepositParamsType<T extends SpokeProvider>} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
@@ -11051,6 +11297,15 @@ var SolverService = class {
11051
11297
  }
11052
11298
  this.hubProvider = hubProvider;
11053
11299
  }
11300
+ /**
11301
+ * Estimate the gas for a raw transaction.
11302
+ * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
11303
+ * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
11304
+ * @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
11305
+ */
11306
+ static async estimateGas(params, spokeProvider) {
11307
+ return SpokeService.estimateGas(params, spokeProvider);
11308
+ }
11054
11309
  /**
11055
11310
  * Request a quote from the solver API
11056
11311
  * @param {SolverIntentQuoteRequest} payload - The solver intent quote request
@@ -12581,6 +12836,6 @@ var SolverIntentErrorCode = /* @__PURE__ */ ((SolverIntentErrorCode2) => {
12581
12836
  return SolverIntentErrorCode2;
12582
12837
  })(SolverIntentErrorCode || {});
12583
12838
 
12584
- export { BigIntToHex, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, EVM_CHAIN_IDS, EVM_SPOKE_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IcxMigrationService, InjectiveSpokeProvider, IntentCreatedEventAbi, IntentDataType, IntentsAbi, MAX_UINT256, MigrationService, MoneyMarketService, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaSpokeProvider, SolverIntentErrorCode, SolverIntentStatusCode, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, VAULT_TOKEN_DECIMALS, WalletAbstractionService, assetManagerAbi, calculateFeeAmount, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, encodeAddress, encodeContractCalls, erc20Abi, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getMoneyMarketConfig, getOriginalAssetAddress, getPacket, getRandomBytes, getSolanaAddressBytes, getSolverConfig, getSpokeChainIdFromIntentRelayChainId, getSupportedMoneyMarketTokens, getSupportedSolverTokens, getTransactionPackets, hubAssetToOriginalAssetMap, hubAssets, hubVaults, hubVaultsAddressSet, intentRelayChainIdToSpokeChainIdMap, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, isInjectiveSpokeProvider, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketReserveAsset, isMoneyMarketReserveHubAsset, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketSupportedToken, isMoneyMarketWithdrawUnknownError, isNativeToken, isPartnerFeeAmount, isPartnerFeePercentage, isResponseAddressType, isResponseSigningType, isSolanaSpokeProvider, isSolverSupportedToken, isSonicSpokeProvider, isStellarSpokeProvider, isSuiSpokeProvider, isValidChainHubAsset, isValidHubAsset, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, isWaitUntilIntentExecutedFailed, moneyMarketReserveAssets, moneyMarketReserveHubAssetsSet, moneyMarketSupportedTokens, originalAssetTohubAssetMap, poolAbi, randomUint256, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainIdsSet, submitTransaction, supportedHubAssets, supportedHubChains, supportedSpokeChains, supportedTokensPerChain, uiPoolDataAbi, variableDebtTokenAbi, vaultTokenAbi, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
12839
+ export { BigIntToHex, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, EVM_CHAIN_IDS, EVM_SPOKE_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IcxMigrationService, InjectiveSpokeProvider, IntentCreatedEventAbi, IntentDataType, IntentsAbi, MAX_UINT256, MigrationService, MoneyMarketService, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaSpokeProvider, SolverIntentErrorCode, SolverIntentStatusCode, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, VAULT_TOKEN_DECIMALS, WalletAbstractionService, assetManagerAbi, calculateFeeAmount, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, encodeAddress, encodeContractCalls, erc20Abi, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getMoneyMarketConfig, getOriginalAssetAddress, getPacket, getRandomBytes, getSolanaAddressBytes, getSolverConfig, getSpokeChainIdFromIntentRelayChainId, getSupportedMoneyMarketTokens, getSupportedSolverTokens, getTransactionPackets, hexToBigInt, hubAssetToOriginalAssetMap, hubAssets, hubVaults, hubVaultsAddressSet, intentRelayChainIdToSpokeChainIdMap, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, isInjectiveSpokeProvider, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketReserveAsset, isMoneyMarketReserveHubAsset, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketSupportedToken, isMoneyMarketWithdrawUnknownError, isNativeToken, isPartnerFeeAmount, isPartnerFeePercentage, isResponseAddressType, isResponseSigningType, isSolanaSpokeProvider, isSolverSupportedToken, isSonicSpokeProvider, isStellarSpokeProvider, isSuiSpokeProvider, isValidChainHubAsset, isValidHubAsset, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, isWaitUntilIntentExecutedFailed, moneyMarketReserveAssets, moneyMarketReserveHubAssetsSet, moneyMarketSupportedTokens, originalAssetTohubAssetMap, poolAbi, randomUint256, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainIdsSet, submitTransaction, supportedHubAssets, supportedHubChains, supportedSpokeChains, supportedTokensPerChain, uiPoolDataAbi, variableDebtTokenAbi, vaultTokenAbi, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
12585
12840
  //# sourceMappingURL=index.mjs.map
12586
12841
  //# sourceMappingURL=index.mjs.map