@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.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';
@@ -6680,8 +6684,8 @@ var isNativeToken = (chainId, token) => {
6680
6684
  return token.address.toLowerCase() === spokeChainConfig[chainId].nativeToken.toLowerCase();
6681
6685
  };
6682
6686
 
6683
- // src/entities/cosmos/CW20Token.ts
6684
- var CW20Token = class {
6687
+ // src/entities/injective/Injective20Token.ts
6688
+ var Injective20Token = class {
6685
6689
  client;
6686
6690
  contractAddress;
6687
6691
  constructor(client, contractAddress) {
@@ -6745,14 +6749,16 @@ var CW20Token = class {
6745
6749
  return await this.client.execute(senderAddress, this.contractAddress, msg, "auto");
6746
6750
  }
6747
6751
  };
6748
-
6749
- // src/entities/cosmos/CWSpokeProvider.ts
6750
- var CWSpokeProvider = class {
6752
+ var InjectiveSpokeProvider = class {
6751
6753
  walletProvider;
6752
6754
  chainConfig;
6755
+ txClient;
6753
6756
  constructor(conf, walletProvider) {
6754
6757
  this.chainConfig = conf;
6755
6758
  this.walletProvider = walletProvider;
6759
+ this.txClient = new TxGrpcClient(
6760
+ getNetworkEndpoints(this.chainConfig.network === "Mainnet" ? Network.Mainnet : Network.Testnet).grpc
6761
+ );
6756
6762
  }
6757
6763
  // Query Methods
6758
6764
  async getState() {
@@ -6795,8 +6801,8 @@ var CWSpokeProvider = class {
6795
6801
  return res.transactionHash;
6796
6802
  }
6797
6803
  async depositToken(sender, tokenAddress, to, amount, data = new Uint8Array(), raw) {
6798
- const cw20Token = new CW20Token(this.walletProvider, tokenAddress);
6799
- await cw20Token.increaseAllowance(sender, this.chainConfig.addresses.assetManager, amount);
6804
+ const injective20Token = new Injective20Token(this.walletProvider, tokenAddress);
6805
+ await injective20Token.increaseAllowance(sender, this.chainConfig.addresses.assetManager, amount);
6800
6806
  return this.transfer(sender, tokenAddress, to, amount, data, [], raw);
6801
6807
  }
6802
6808
  static async deposit(sender, token_address, to, amount, data = "0x", provider, raw) {
@@ -6814,11 +6820,13 @@ var CWSpokeProvider = class {
6814
6820
  }
6815
6821
  async isNative(token) {
6816
6822
  let isNative2 = true;
6817
- const cw20Token = new CW20Token(this.walletProvider, token);
6823
+ const injective20Token = new Injective20Token(this.walletProvider, token);
6818
6824
  try {
6819
- await cw20Token.getTokenInfo();
6825
+ await injective20Token.getTokenInfo();
6820
6826
  isNative2 = false;
6821
6827
  } catch (err) {
6828
+ console.error("[InjectiveSpokeProvider] isNative error", err);
6829
+ throw err;
6822
6830
  }
6823
6831
  return isNative2;
6824
6832
  }
@@ -6889,15 +6897,17 @@ var CWSpokeProvider = class {
6889
6897
  return num.toString();
6890
6898
  }
6891
6899
  };
6892
- var IconSdk = IconSdkRaw.default?.default ? IconSdkRaw.default : IconSdkRaw;
6900
+ var IconSdk = "default" in IconSdkRaw.default ? IconSdkRaw.default : IconSdkRaw;
6893
6901
  var IconSpokeProvider = class {
6894
6902
  walletProvider;
6895
6903
  chainConfig;
6896
6904
  iconService;
6897
- constructor(walletProvider, chainConfig, rpcUrl = "https://ctz.solidwallet.io/api/v3") {
6905
+ debugRpcUrl;
6906
+ constructor(walletProvider, chainConfig, rpcUrl = "https://ctz.solidwallet.io/api/v3", debugRpcUrl = "https://ctz.solidwallet.io/api/v3d") {
6898
6907
  this.walletProvider = walletProvider;
6899
6908
  this.chainConfig = chainConfig;
6900
6909
  this.iconService = new IconSdk.IconService(new IconSdk.IconService.HttpProvider(rpcUrl));
6910
+ this.debugRpcUrl = debugRpcUrl;
6901
6911
  }
6902
6912
  };
6903
6913
 
@@ -7148,7 +7158,7 @@ var StellarSpokeProvider = class {
7148
7158
  networkPassphrase: network.passphrase
7149
7159
  }).addOperation(operation).setTimeout(STELLAR_DEFAULT_TX_TIMEOUT_SECONDS).build();
7150
7160
  const simulation = await this.sorobanServer.simulateTransaction(priorityTransaction);
7151
- return [SorobanRpc.assembleTransaction(priorityTransaction, simulation).build(), simulation];
7161
+ return [priorityTransaction, simulation];
7152
7162
  }
7153
7163
  handleSendTransactionError(response) {
7154
7164
  if (response.status === "ERROR") {
@@ -7236,9 +7246,14 @@ var StellarSpokeProvider = class {
7236
7246
  const accountResponse = await this.server.loadAccount(walletAddress);
7237
7247
  const stellarAccount = new CustomStellarAccount(accountResponse);
7238
7248
  const depositCall = this.buildDepositCall(walletAddress, token, amount, recipient, data);
7239
- const [priorityTx, simulation] = await this.buildPriorityStellarTransaction(stellarAccount, network, depositCall);
7249
+ const [rawPriorityTx, simulation] = await this.buildPriorityStellarTransaction(
7250
+ stellarAccount,
7251
+ network,
7252
+ depositCall
7253
+ );
7254
+ const assembledPriorityTx = SorobanRpc.assembleTransaction(rawPriorityTx, simulation).build();
7240
7255
  if (raw) {
7241
- const transactionXdr = priorityTx.toXDR();
7256
+ const transactionXdr = rawPriorityTx.toXDR();
7242
7257
  return {
7243
7258
  from: walletAddress,
7244
7259
  to: this.chainConfig.addresses.assetManager,
@@ -7246,7 +7261,13 @@ var StellarSpokeProvider = class {
7246
7261
  data: transactionXdr
7247
7262
  };
7248
7263
  }
7249
- const hash = await this.submitOrRestoreAndRetry(stellarAccount, network, priorityTx, depositCall, simulation);
7264
+ const hash = await this.submitOrRestoreAndRetry(
7265
+ stellarAccount,
7266
+ network,
7267
+ assembledPriorityTx,
7268
+ depositCall,
7269
+ simulation
7270
+ );
7250
7271
  return `${hash}`;
7251
7272
  } catch (error) {
7252
7273
  console.error("Error during deposit:", error);
@@ -7315,9 +7336,11 @@ var StellarSpokeProvider = class {
7315
7336
  var SuiSpokeProvider = class _SuiSpokeProvider {
7316
7337
  walletProvider;
7317
7338
  chainConfig;
7339
+ publicClient;
7318
7340
  constructor(config, wallet_provider) {
7319
7341
  this.chainConfig = config;
7320
7342
  this.walletProvider = wallet_provider;
7343
+ this.publicClient = new SuiClient({ url: getFullnodeUrl("mainnet") });
7321
7344
  }
7322
7345
  async getBalance(token) {
7323
7346
  const assetmanager = this.splitAddress(this.chainConfig.addresses.assetManager);
@@ -7357,7 +7380,11 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
7357
7380
  ]
7358
7381
  });
7359
7382
  if (raw) {
7360
- const transactionRaw = await tx.build();
7383
+ tx.setSender(walletAddress);
7384
+ const transactionRaw = await tx.build({
7385
+ client: this.publicClient,
7386
+ onlyTransactionKind: true
7387
+ });
7361
7388
  const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
7362
7389
  return {
7363
7390
  from: walletAddress,
@@ -7420,10 +7447,14 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
7420
7447
  txb.pure(bcs.vector(bcs.u8()).serialize(data))
7421
7448
  ]
7422
7449
  });
7450
+ const walletAddress = await this.walletProvider.getWalletAddress();
7423
7451
  if (raw) {
7424
- const transactionRaw = await txb.build();
7452
+ txb.setSender(walletAddress);
7453
+ const transactionRaw = await txb.build({
7454
+ client: this.publicClient,
7455
+ onlyTransactionKind: true
7456
+ });
7425
7457
  const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
7426
- const walletAddress = await this.walletProvider.getWalletAddressBytes();
7427
7458
  return {
7428
7459
  from: walletAddress,
7429
7460
  to: `${connection.packageId}::${connection.moduleId}::send_message_ua`,
@@ -8086,6 +8117,15 @@ function encodeAddress(spokeChainId, address) {
8086
8117
  return address;
8087
8118
  }
8088
8119
  }
8120
+ function hexToBigInt(hex) {
8121
+ const trimmed = hex.trim().toLowerCase();
8122
+ const isValid = /^(0x)?[0-9a-f]+$/.test(trimmed);
8123
+ if (!isValid) {
8124
+ throw new Error(`Invalid hex string: "${hex}"`);
8125
+ }
8126
+ const normalized = trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`;
8127
+ return BigInt(normalized);
8128
+ }
8089
8129
  var MoneyMarketService = class _MoneyMarketService {
8090
8130
  config;
8091
8131
  hubProvider;
@@ -8113,6 +8153,15 @@ var MoneyMarketService = class _MoneyMarketService {
8113
8153
  }
8114
8154
  this.hubProvider = hubProvider;
8115
8155
  }
8156
+ /**
8157
+ * Estimate the gas for a raw transaction.
8158
+ * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
8159
+ * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
8160
+ * @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
8161
+ */
8162
+ static async estimateGas(params, spokeProvider) {
8163
+ return SpokeService.estimateGas(params, spokeProvider);
8164
+ }
8116
8165
  /**
8117
8166
  * Check if allowance is sufficient for actions on the money market pool
8118
8167
  * @param {MoneyMarketParams} params - Money market params containing token address and amount
@@ -9276,6 +9325,37 @@ var MoneyMarketService = class _MoneyMarketService {
9276
9325
  var EvmSpokeService = class _EvmSpokeService {
9277
9326
  constructor() {
9278
9327
  }
9328
+ /**
9329
+ * Estimates the gas necessary to complete a transaction without submitting it to the network.
9330
+ *
9331
+ * - Docs: https://viem.sh/docs/actions/public/estimateGas
9332
+ * - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
9333
+ *
9334
+ * @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
9335
+ * @param {EvmSpokeProvider} spokeProvider - The EVM spoke provider.
9336
+ * @returns {Promise<bigint>} Estimated gas for the transaction.
9337
+ *
9338
+ * @example
9339
+ *
9340
+ * const rawTx: EvmRawTransaction = {
9341
+ * from: '0x1234...abcd', // sender address
9342
+ * to: '0xabcd...1234', // recipient address
9343
+ * value: 1000000000000000000n, // 1 ETH in wei
9344
+ * data: '0x', // no calldata
9345
+ * };
9346
+ *
9347
+ * // Assume spokeProvider is an initialized EvmSpokeProvider
9348
+ * const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
9349
+ * console.log(`Estimated gas: ${estimatedGas}`);
9350
+ */
9351
+ static async estimateGas(rawTx, spokeProvider) {
9352
+ return spokeProvider.publicClient.estimateGas({
9353
+ account: rawTx.from,
9354
+ to: rawTx.to,
9355
+ value: rawTx.value,
9356
+ data: rawTx.data
9357
+ });
9358
+ }
9279
9359
  /**
9280
9360
  * Deposit tokens to the spoke chain.
9281
9361
  * @param {EvmSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
@@ -9389,16 +9469,35 @@ var EvmSpokeService = class _EvmSpokeService {
9389
9469
  return spokeProvider.walletProvider.sendTransaction(rawTx);
9390
9470
  }
9391
9471
  };
9392
- var CWSpokeService = class _CWSpokeService {
9472
+ var InjectiveSpokeService = class _InjectiveSpokeService {
9393
9473
  constructor() {
9394
9474
  }
9475
+ /**
9476
+ * Estimate the gas for a transaction.
9477
+ * @param {InjectiveRawTransaction} rawTx - The raw transaction to estimate the gas for.
9478
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9479
+ * @returns {Promise<InjectiveGasEstimate>} The estimated gas for the transaction.
9480
+ */
9481
+ static async estimateGas(rawTx, spokeProvider) {
9482
+ const txRaw = TxRaw.fromPartial({
9483
+ bodyBytes: rawTx.signedDoc.bodyBytes,
9484
+ authInfoBytes: rawTx.signedDoc.authInfoBytes,
9485
+ signatures: []
9486
+ // not required for simulation
9487
+ });
9488
+ const { gasInfo } = await spokeProvider.txClient.simulate(txRaw);
9489
+ return {
9490
+ gasWanted: gasInfo.gasWanted,
9491
+ gasUsed: gasInfo.gasUsed
9492
+ };
9493
+ }
9395
9494
  /**
9396
9495
  * Deposit tokens to the spoke chain.
9397
- * @param {CWSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
9398
- * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
9496
+ * @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
9497
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9399
9498
  * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9400
9499
  * @param {boolean} raw - The return type raw or just transaction hash
9401
- * @returns {PromiseCWTxReturnType<R>} A promise that resolves to the transaction hash.
9500
+ * @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
9402
9501
  */
9403
9502
  static async deposit(params, spokeProvider, hubProvider, raw) {
9404
9503
  const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
@@ -9406,7 +9505,7 @@ var CWSpokeService = class _CWSpokeService {
9406
9505
  toHex(Buffer.from(params.from, "utf-8")),
9407
9506
  hubProvider
9408
9507
  );
9409
- return _CWSpokeService.transfer(
9508
+ return _InjectiveSpokeService.transfer(
9410
9509
  {
9411
9510
  token: params.token,
9412
9511
  recipient: userWallet,
@@ -9420,7 +9519,7 @@ var CWSpokeService = class _CWSpokeService {
9420
9519
  /**
9421
9520
  * Get the balance of the token in the spoke chain.
9422
9521
  * @param {Address} token - The address of the token to get the balance of.
9423
- * @param {CWSpokeProvider} spokeProvider - The spoke provider.
9522
+ * @param {InjectiveSpokeProvider} spokeProvider - The spoke provider.
9424
9523
  * @returns {Promise<bigint>} The balance of the token.
9425
9524
  */
9426
9525
  static async getDeposit(token, spokeProvider) {
@@ -9431,47 +9530,80 @@ var CWSpokeService = class _CWSpokeService {
9431
9530
  * Calls a contract on the spoke chain using the user's wallet.
9432
9531
  * @param {HubAddress} from - The address of the user on the hub chain.
9433
9532
  * @param {Hex} payload - The payload to send to the contract.
9434
- * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
9533
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9435
9534
  * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9436
- * @returns {PromiseCWTxReturnType<R>} A promise that resolves to the transaction hash.
9535
+ * @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
9437
9536
  */
9438
9537
  static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
9439
9538
  const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
9440
- return _CWSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
9539
+ return _InjectiveSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
9441
9540
  }
9442
9541
  /**
9443
9542
  * Transfers tokens to the hub chain.
9444
- * @param {TransferToHubParams} params - The parameters for the transfer, including:
9543
+ * @param {InjectiveTransferToHubParams} params - The parameters for the transfer, including:
9445
9544
  * - {string} token: The address of the token to transfer (use address(0) for native token).
9446
9545
  * - {Uint8Array} recipient: The recipient address on the hub chain.
9447
9546
  * - {string} amount: The amount to transfer.
9448
9547
  * - {Uint8Array} [data=new Uint8Array([])]: Additional data for the transfer.
9449
- * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
9548
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9450
9549
  * @param {boolean} raw - The return type raw or just transaction hash
9451
- * @returns {PromiseCWTxReturnType<R>} A promise that resolves to the transaction hash.
9550
+ * @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
9452
9551
  */
9453
9552
  static async transfer({ token, recipient, amount, data = "0x" }, spokeProvider, raw) {
9454
9553
  const sender = await spokeProvider.walletProvider.getWalletAddress();
9455
- return CWSpokeProvider.deposit(sender, token, recipient, amount, data, spokeProvider, raw);
9554
+ return InjectiveSpokeProvider.deposit(sender, token, recipient, amount, data, spokeProvider, raw);
9456
9555
  }
9457
9556
  /**
9458
9557
  * Sends a message to the hub chain.
9459
9558
  * @param {bigint} dstChainId - The chain ID of the hub chain.
9460
9559
  * @param {Address} dstAddress - The address on the hub chain.
9461
9560
  * @param {Hex} payload - The payload to send.
9462
- * @param {CWSpokeProvider} spokeProvider - The provider for the spoke chain.
9463
- * @returns {PromiseCWTxReturnType<R>} A promise that resolves to the transaction hash.
9561
+ * @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
9562
+ * @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
9464
9563
  */
9465
9564
  static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
9466
9565
  const sender = await spokeProvider.walletProvider.getWalletAddress();
9467
9566
  return spokeProvider.send_message(sender, dstChainId.toString(), dstAddress, payload, raw);
9468
9567
  }
9469
9568
  };
9470
- var IconSdk2 = IconSdkRaw.default?.default ? IconSdkRaw.default : IconSdkRaw;
9569
+
9570
+ // src/utils/icon-utils.ts
9571
+ async function estimateStepCost(rawTx, debugRpcUrl) {
9572
+ try {
9573
+ const tmpRawTx = { ...rawTx };
9574
+ delete tmpRawTx["stepLimit"];
9575
+ const response = await fetch(debugRpcUrl, {
9576
+ method: "POST",
9577
+ headers: {
9578
+ "Content-Type": "application/json"
9579
+ },
9580
+ body: JSON.stringify({
9581
+ jsonrpc: "2.0",
9582
+ method: "debug_estimateStep",
9583
+ id: 1234,
9584
+ params: tmpRawTx
9585
+ })
9586
+ });
9587
+ if (!response.ok) {
9588
+ throw new Error(`Failed to fetch step cost: ${response.statusText}`);
9589
+ }
9590
+ const data = await response.json();
9591
+ return hexToBigInt(data.result);
9592
+ } catch (e) {
9593
+ console.error("estimateStepCost error:", e);
9594
+ throw e;
9595
+ }
9596
+ }
9597
+
9598
+ // src/services/spoke/IconSpokeService.ts
9599
+ var IconSdk2 = "default" in IconSdkRaw.default ? IconSdkRaw.default : IconSdkRaw;
9471
9600
  var { Converter, CallTransactionBuilder, CallBuilder } = IconSdk2;
9472
9601
  var IconSpokeService = class _IconSpokeService {
9473
9602
  constructor() {
9474
9603
  }
9604
+ static async estimateGas(rawTx, spokeProvider) {
9605
+ return estimateStepCost(rawTx, spokeProvider.debugRpcUrl);
9606
+ }
9475
9607
  /**
9476
9608
  * Deposit tokens to the spoke chain.
9477
9609
  * @param {IconSpokeDepositParams} params - The parameters for the deposit
@@ -9535,15 +9667,16 @@ var IconSpokeService = class _IconSpokeService {
9535
9667
  };
9536
9668
  const value = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? BigIntToHex(amount) : "0x0";
9537
9669
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
9670
+ const to = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token;
9538
9671
  const rawTransaction = Converter.toRawTransaction(
9539
- 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()
9672
+ 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()
9540
9673
  );
9541
9674
  if (raw) {
9542
9675
  return rawTransaction;
9543
9676
  }
9544
9677
  return spokeProvider.walletProvider.sendTransaction({
9545
9678
  from: walletAddress,
9546
- to: isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token,
9679
+ to,
9547
9680
  value,
9548
9681
  nid: spokeProvider.chainConfig.nid,
9549
9682
  method: "transfer",
@@ -9660,6 +9793,22 @@ var AssetManagerPDA = {
9660
9793
  var SolanaSpokeService = class _SolanaSpokeService {
9661
9794
  constructor() {
9662
9795
  }
9796
+ /**
9797
+ * Estimate the gas for a transaction.
9798
+ * @param {SolanaRawTransaction} rawTx - The raw transaction to estimate the gas for.
9799
+ * @param {SolanaSpokeProvider} spokeProvider - The provider for the spoke chain.
9800
+ * @returns {Promise<number | undefined>} The units consumed for the transaction.
9801
+ */
9802
+ static async estimateGas(rawTx, spokeProvider) {
9803
+ const connection = new Connection(spokeProvider.chainConfig.rpcUrl, "confirmed");
9804
+ const serializedTxBytes = Buffer.from(rawTx.data, "base64");
9805
+ const versionedTx = VersionedTransaction.deserialize(serializedTxBytes);
9806
+ const { value } = await connection.simulateTransaction(versionedTx);
9807
+ if (value.err) {
9808
+ throw new Error(`Failed to simulate transaction: ${JSON.stringify(value.err, null, 2)}`);
9809
+ }
9810
+ return value.unitsConsumed;
9811
+ }
9663
9812
  static async deposit(params, spokeProvider, hubProvider, raw) {
9664
9813
  const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9665
9814
  spokeProvider.chainConfig.chain.id,
@@ -9840,6 +9989,24 @@ var SolanaSpokeService = class _SolanaSpokeService {
9840
9989
  var StellarSpokeService = class _StellarSpokeService {
9841
9990
  constructor() {
9842
9991
  }
9992
+ /**
9993
+ * Estimate the gas for a transaction.
9994
+ * @param rawTx - The raw transaction to estimate the gas for.
9995
+ * @param spokeProvider - The spoke provider.
9996
+ * @returns The estimated gas (minResourceFee) for the transaction.
9997
+ */
9998
+ static async estimateGas(rawTx, spokeProvider) {
9999
+ const network = await spokeProvider.sorobanServer.getNetwork();
10000
+ let tx = TransactionBuilder.fromXDR(rawTx.data, network.passphrase);
10001
+ if (tx instanceof FeeBumpTransaction) {
10002
+ tx = tx.innerTransaction;
10003
+ }
10004
+ const simulationForFee = await spokeProvider.sorobanServer.simulateTransaction(tx);
10005
+ if (!rpc.Api.isSimulationSuccess(simulationForFee)) {
10006
+ throw new Error(`Simulation error: ${JSON.stringify(simulationForFee)}`);
10007
+ }
10008
+ return BigInt(simulationForFee.minResourceFee);
10009
+ }
9843
10010
  static async deposit(params, spokeProvider, hubProvider, raw) {
9844
10011
  const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
9845
10012
  spokeProvider.chainConfig.chain.id,
@@ -9894,9 +10061,23 @@ var StellarSpokeService = class _StellarSpokeService {
9894
10061
  var SuiSpokeService = class _SuiSpokeService {
9895
10062
  constructor() {
9896
10063
  }
10064
+ /**
10065
+ * Estimate the gas for a transaction.
10066
+ * @param {SuiRawTransaction} rawTx - The raw transaction to estimate the gas for.
10067
+ * @param {SuiSpokeProvider} spokeProvider - The spoke provider.
10068
+ * @returns {Promise<bigint>} The estimated computation cost.
10069
+ */
10070
+ static async estimateGas(rawTx, spokeProvider) {
10071
+ const txb = Transaction.fromKind(rawTx.data);
10072
+ const result = await spokeProvider.publicClient.devInspectTransactionBlock({
10073
+ sender: rawTx.from,
10074
+ transactionBlock: txb
10075
+ });
10076
+ return result.effects.gasUsed;
10077
+ }
9897
10078
  /**
9898
10079
  * Deposit tokens to the spoke chain.
9899
- * @param {CWSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
10080
+ * @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
9900
10081
  * @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
9901
10082
  * @param {EvmHubProvider} hubProvider - The provider for the hub chain.
9902
10083
  * @param {boolean} raw - The return type raw or just transaction hash
@@ -9943,7 +10124,7 @@ var SuiSpokeService = class _SuiSpokeService {
9943
10124
  }
9944
10125
  /**
9945
10126
  * Transfers tokens to the hub chain.
9946
- * @param {TransferToHubParams} params - The parameters for the transfer, including:
10127
+ * @param {SuiTransferToHubParams} params - The parameters for the transfer, including:
9947
10128
  * - {string} token: The address of the token to transfer (use address(0) for native token).
9948
10129
  * - {Uint8Array} recipient: The recipient address on the hub chain.
9949
10130
  * - {string} amount: The amount to transfer.
@@ -9971,6 +10152,38 @@ var SuiSpokeService = class _SuiSpokeService {
9971
10152
  var SonicSpokeService = class _SonicSpokeService {
9972
10153
  constructor() {
9973
10154
  }
10155
+ /**
10156
+ /**
10157
+ * Estimates the gas necessary to complete a transaction without submitting it to the network.
10158
+ *
10159
+ * - Docs: https://viem.sh/docs/actions/public/estimateGas
10160
+ * - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
10161
+ *
10162
+ * @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
10163
+ * @param {SonicSpokeProvider} spokeProvider - The EVM spoke provider.
10164
+ * @returns {Promise<bigint>} Estimated gas for the transaction.
10165
+ *
10166
+ * @example
10167
+ *
10168
+ * const rawTx: EvmRawTransaction = {
10169
+ * from: '0x1234...abcd', // sender address
10170
+ * to: '0xabcd...1234', // recipient address
10171
+ * value: 1000000000000000000n, // 1 ETH in wei
10172
+ * data: '0x', // no calldata
10173
+ * };
10174
+ *
10175
+ * // Assume spokeProvider is an initialized EvmSpokeProvider
10176
+ * const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
10177
+ * console.log(`Estimated gas: ${estimatedGas}`);
10178
+ */
10179
+ static async estimateGas(rawTx, spokeProvider) {
10180
+ return spokeProvider.publicClient.estimateGas({
10181
+ account: rawTx.from,
10182
+ to: rawTx.to,
10183
+ value: rawTx.value,
10184
+ data: rawTx.data
10185
+ });
10186
+ }
9974
10187
  /**
9975
10188
  * Get the derived address of a contract deployed with CREATE3.
9976
10189
  * @param address - User's address on the specified chain as hex
@@ -10346,8 +10559,8 @@ function isSolanaSpokeProvider(value) {
10346
10559
  function isStellarSpokeProvider(value) {
10347
10560
  return typeof value === "object" && value !== null && value instanceof StellarSpokeProvider && value.chainConfig.chain.type === "STELLAR";
10348
10561
  }
10349
- function isCWSpokeProvider(value) {
10350
- return typeof value === "object" && value !== null && value instanceof CWSpokeProvider && value.chainConfig.chain.type === "INJECTIVE";
10562
+ function isInjectiveSpokeProvider(value) {
10563
+ return typeof value === "object" && value !== null && value instanceof InjectiveSpokeProvider && value.chainConfig.chain.type === "INJECTIVE";
10351
10564
  }
10352
10565
  function isIconSpokeProvider(value) {
10353
10566
  return typeof value === "object" && value !== null && value instanceof IconSpokeProvider && value.chainConfig.chain.type === "ICON";
@@ -10411,6 +10624,57 @@ function isMoneyMarketRepayUnknownError(error) {
10411
10624
  var SpokeService = class {
10412
10625
  constructor() {
10413
10626
  }
10627
+ /**
10628
+ * Estimate the gas for a raw transaction.
10629
+ * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
10630
+ * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
10631
+ * @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
10632
+ */
10633
+ static async estimateGas(params, spokeProvider) {
10634
+ if (spokeProvider instanceof EvmSpokeProvider) {
10635
+ return EvmSpokeService.estimateGas(
10636
+ params,
10637
+ spokeProvider
10638
+ );
10639
+ }
10640
+ if (spokeProvider instanceof SonicSpokeProvider) {
10641
+ return SonicSpokeService.estimateGas(
10642
+ params,
10643
+ spokeProvider
10644
+ );
10645
+ }
10646
+ if (spokeProvider instanceof InjectiveSpokeProvider) {
10647
+ return InjectiveSpokeService.estimateGas(
10648
+ params,
10649
+ spokeProvider
10650
+ );
10651
+ }
10652
+ if (spokeProvider instanceof IconSpokeProvider) {
10653
+ return IconSpokeService.estimateGas(
10654
+ params,
10655
+ spokeProvider
10656
+ );
10657
+ }
10658
+ if (spokeProvider instanceof SuiSpokeProvider) {
10659
+ return SuiSpokeService.estimateGas(
10660
+ params,
10661
+ spokeProvider
10662
+ );
10663
+ }
10664
+ if (spokeProvider instanceof SolanaSpokeProvider) {
10665
+ return SolanaSpokeService.estimateGas(
10666
+ params,
10667
+ spokeProvider
10668
+ );
10669
+ }
10670
+ if (spokeProvider instanceof StellarSpokeProvider) {
10671
+ return StellarSpokeService.estimateGas(
10672
+ params,
10673
+ spokeProvider
10674
+ );
10675
+ }
10676
+ throw new Error("Invalid spoke provider");
10677
+ }
10414
10678
  /**
10415
10679
  * Deposit tokens to the spoke chain.
10416
10680
  * @param {GetSpokeDepositParamsType<T extends SpokeProvider>} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
@@ -10434,8 +10698,8 @@ var SpokeService = class {
10434
10698
  raw
10435
10699
  );
10436
10700
  }
10437
- if (spokeProvider instanceof CWSpokeProvider) {
10438
- return CWSpokeService.deposit(
10701
+ if (spokeProvider instanceof InjectiveSpokeProvider) {
10702
+ return InjectiveSpokeService.deposit(
10439
10703
  params,
10440
10704
  spokeProvider,
10441
10705
  hubProvider,
@@ -10486,8 +10750,8 @@ var SpokeService = class {
10486
10750
  if (spokeProvider instanceof EvmSpokeProvider) {
10487
10751
  return EvmSpokeService.getDeposit(token, spokeProvider);
10488
10752
  }
10489
- if (spokeProvider instanceof CWSpokeProvider) {
10490
- return CWSpokeService.getDeposit(token, spokeProvider);
10753
+ if (spokeProvider instanceof InjectiveSpokeProvider) {
10754
+ return InjectiveSpokeService.getDeposit(token, spokeProvider);
10491
10755
  }
10492
10756
  if (spokeProvider instanceof StellarSpokeProvider) {
10493
10757
  return StellarSpokeService.getDeposit(token, spokeProvider);
@@ -10521,8 +10785,14 @@ var SpokeService = class {
10521
10785
  if (isEvmSpokeProvider(spokeProvider)) {
10522
10786
  return await EvmSpokeService.callWallet(from, payload, spokeProvider, hubProvider);
10523
10787
  }
10524
- if (isCWSpokeProvider(spokeProvider)) {
10525
- return await CWSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
10788
+ if (isInjectiveSpokeProvider(spokeProvider)) {
10789
+ return await InjectiveSpokeService.callWallet(
10790
+ from,
10791
+ payload,
10792
+ spokeProvider,
10793
+ hubProvider,
10794
+ raw
10795
+ );
10526
10796
  }
10527
10797
  if (isIconSpokeProvider(spokeProvider)) {
10528
10798
  return await IconSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
@@ -11043,6 +11313,15 @@ var SolverService = class {
11043
11313
  }
11044
11314
  this.hubProvider = hubProvider;
11045
11315
  }
11316
+ /**
11317
+ * Estimate the gas for a raw transaction.
11318
+ * @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
11319
+ * @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
11320
+ * @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
11321
+ */
11322
+ static async estimateGas(params, spokeProvider) {
11323
+ return SpokeService.estimateGas(params, spokeProvider);
11324
+ }
11046
11325
  /**
11047
11326
  * Request a quote from the solver API
11048
11327
  * @param {SolverIntentQuoteRequest} payload - The solver intent quote request
@@ -12573,6 +12852,6 @@ var SolverIntentErrorCode = /* @__PURE__ */ ((SolverIntentErrorCode2) => {
12573
12852
  return SolverIntentErrorCode2;
12574
12853
  })(SolverIntentErrorCode || {});
12575
12854
 
12576
- export { BigIntToHex, CWSpokeProvider, 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, 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, isCWSpokeProvider, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, 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 };
12855
+ 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 };
12577
12856
  //# sourceMappingURL=index.mjs.map
12578
12857
  //# sourceMappingURL=index.mjs.map