@sodax/sdk 0.0.1-rc.13 → 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/README.md +80 -0
- package/dist/index.cjs +286 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +119 -12
- package/dist/index.d.ts +119 -12
- package/dist/index.mjs +288 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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
|
|
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';
|
|
@@ -6745,14 +6749,16 @@ var Injective20Token = class {
|
|
|
6745
6749
|
return await this.client.execute(senderAddress, this.contractAddress, msg, "auto");
|
|
6746
6750
|
}
|
|
6747
6751
|
};
|
|
6748
|
-
|
|
6749
|
-
// src/entities/injective/InjectiveSpokeProvider.ts
|
|
6750
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() {
|
|
@@ -6819,7 +6825,7 @@ var InjectiveSpokeProvider = class {
|
|
|
6819
6825
|
await injective20Token.getTokenInfo();
|
|
6820
6826
|
isNative2 = false;
|
|
6821
6827
|
} catch (err) {
|
|
6822
|
-
console.
|
|
6828
|
+
console.error("[InjectiveSpokeProvider] isNative error", err);
|
|
6823
6829
|
throw err;
|
|
6824
6830
|
}
|
|
6825
6831
|
return isNative2;
|
|
@@ -6896,10 +6902,12 @@ var IconSpokeProvider = class {
|
|
|
6896
6902
|
walletProvider;
|
|
6897
6903
|
chainConfig;
|
|
6898
6904
|
iconService;
|
|
6899
|
-
|
|
6905
|
+
debugRpcUrl;
|
|
6906
|
+
constructor(walletProvider, chainConfig, rpcUrl = "https://ctz.solidwallet.io/api/v3", debugRpcUrl = "https://ctz.solidwallet.io/api/v3d") {
|
|
6900
6907
|
this.walletProvider = walletProvider;
|
|
6901
6908
|
this.chainConfig = chainConfig;
|
|
6902
6909
|
this.iconService = new IconSdk.IconService(new IconSdk.IconService.HttpProvider(rpcUrl));
|
|
6910
|
+
this.debugRpcUrl = debugRpcUrl;
|
|
6903
6911
|
}
|
|
6904
6912
|
};
|
|
6905
6913
|
|
|
@@ -7150,7 +7158,7 @@ var StellarSpokeProvider = class {
|
|
|
7150
7158
|
networkPassphrase: network.passphrase
|
|
7151
7159
|
}).addOperation(operation).setTimeout(STELLAR_DEFAULT_TX_TIMEOUT_SECONDS).build();
|
|
7152
7160
|
const simulation = await this.sorobanServer.simulateTransaction(priorityTransaction);
|
|
7153
|
-
return [
|
|
7161
|
+
return [priorityTransaction, simulation];
|
|
7154
7162
|
}
|
|
7155
7163
|
handleSendTransactionError(response) {
|
|
7156
7164
|
if (response.status === "ERROR") {
|
|
@@ -7238,9 +7246,14 @@ var StellarSpokeProvider = class {
|
|
|
7238
7246
|
const accountResponse = await this.server.loadAccount(walletAddress);
|
|
7239
7247
|
const stellarAccount = new CustomStellarAccount(accountResponse);
|
|
7240
7248
|
const depositCall = this.buildDepositCall(walletAddress, token, amount, recipient, data);
|
|
7241
|
-
const [
|
|
7249
|
+
const [rawPriorityTx, simulation] = await this.buildPriorityStellarTransaction(
|
|
7250
|
+
stellarAccount,
|
|
7251
|
+
network,
|
|
7252
|
+
depositCall
|
|
7253
|
+
);
|
|
7254
|
+
const assembledPriorityTx = SorobanRpc.assembleTransaction(rawPriorityTx, simulation).build();
|
|
7242
7255
|
if (raw) {
|
|
7243
|
-
const transactionXdr =
|
|
7256
|
+
const transactionXdr = rawPriorityTx.toXDR();
|
|
7244
7257
|
return {
|
|
7245
7258
|
from: walletAddress,
|
|
7246
7259
|
to: this.chainConfig.addresses.assetManager,
|
|
@@ -7248,7 +7261,13 @@ var StellarSpokeProvider = class {
|
|
|
7248
7261
|
data: transactionXdr
|
|
7249
7262
|
};
|
|
7250
7263
|
}
|
|
7251
|
-
const hash = await this.submitOrRestoreAndRetry(
|
|
7264
|
+
const hash = await this.submitOrRestoreAndRetry(
|
|
7265
|
+
stellarAccount,
|
|
7266
|
+
network,
|
|
7267
|
+
assembledPriorityTx,
|
|
7268
|
+
depositCall,
|
|
7269
|
+
simulation
|
|
7270
|
+
);
|
|
7252
7271
|
return `${hash}`;
|
|
7253
7272
|
} catch (error) {
|
|
7254
7273
|
console.error("Error during deposit:", error);
|
|
@@ -7317,9 +7336,11 @@ var StellarSpokeProvider = class {
|
|
|
7317
7336
|
var SuiSpokeProvider = class _SuiSpokeProvider {
|
|
7318
7337
|
walletProvider;
|
|
7319
7338
|
chainConfig;
|
|
7339
|
+
publicClient;
|
|
7320
7340
|
constructor(config, wallet_provider) {
|
|
7321
7341
|
this.chainConfig = config;
|
|
7322
7342
|
this.walletProvider = wallet_provider;
|
|
7343
|
+
this.publicClient = new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
7323
7344
|
}
|
|
7324
7345
|
async getBalance(token) {
|
|
7325
7346
|
const assetmanager = this.splitAddress(this.chainConfig.addresses.assetManager);
|
|
@@ -7359,7 +7380,11 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
|
|
|
7359
7380
|
]
|
|
7360
7381
|
});
|
|
7361
7382
|
if (raw) {
|
|
7362
|
-
|
|
7383
|
+
tx.setSender(walletAddress);
|
|
7384
|
+
const transactionRaw = await tx.build({
|
|
7385
|
+
client: this.publicClient,
|
|
7386
|
+
onlyTransactionKind: true
|
|
7387
|
+
});
|
|
7363
7388
|
const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
|
|
7364
7389
|
return {
|
|
7365
7390
|
from: walletAddress,
|
|
@@ -7422,10 +7447,14 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
|
|
|
7422
7447
|
txb.pure(bcs.vector(bcs.u8()).serialize(data))
|
|
7423
7448
|
]
|
|
7424
7449
|
});
|
|
7450
|
+
const walletAddress = await this.walletProvider.getWalletAddress();
|
|
7425
7451
|
if (raw) {
|
|
7426
|
-
|
|
7452
|
+
txb.setSender(walletAddress);
|
|
7453
|
+
const transactionRaw = await txb.build({
|
|
7454
|
+
client: this.publicClient,
|
|
7455
|
+
onlyTransactionKind: true
|
|
7456
|
+
});
|
|
7427
7457
|
const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
|
|
7428
|
-
const walletAddress = await this.walletProvider.getWalletAddressBytes();
|
|
7429
7458
|
return {
|
|
7430
7459
|
from: walletAddress,
|
|
7431
7460
|
to: `${connection.packageId}::${connection.moduleId}::send_message_ua`,
|
|
@@ -8088,6 +8117,15 @@ function encodeAddress(spokeChainId, address) {
|
|
|
8088
8117
|
return address;
|
|
8089
8118
|
}
|
|
8090
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
|
+
}
|
|
8091
8129
|
var MoneyMarketService = class _MoneyMarketService {
|
|
8092
8130
|
config;
|
|
8093
8131
|
hubProvider;
|
|
@@ -8115,6 +8153,15 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
8115
8153
|
}
|
|
8116
8154
|
this.hubProvider = hubProvider;
|
|
8117
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
|
+
}
|
|
8118
8165
|
/**
|
|
8119
8166
|
* Check if allowance is sufficient for actions on the money market pool
|
|
8120
8167
|
* @param {MoneyMarketParams} params - Money market params containing token address and amount
|
|
@@ -9278,6 +9325,37 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9278
9325
|
var EvmSpokeService = class _EvmSpokeService {
|
|
9279
9326
|
constructor() {
|
|
9280
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
|
+
}
|
|
9281
9359
|
/**
|
|
9282
9360
|
* Deposit tokens to the spoke chain.
|
|
9283
9361
|
* @param {EvmSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
@@ -9394,6 +9472,25 @@ var EvmSpokeService = class _EvmSpokeService {
|
|
|
9394
9472
|
var InjectiveSpokeService = class _InjectiveSpokeService {
|
|
9395
9473
|
constructor() {
|
|
9396
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
|
+
}
|
|
9397
9494
|
/**
|
|
9398
9495
|
* Deposit tokens to the spoke chain.
|
|
9399
9496
|
* @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
@@ -9469,11 +9566,44 @@ var InjectiveSpokeService = class _InjectiveSpokeService {
|
|
|
9469
9566
|
return spokeProvider.send_message(sender, dstChainId.toString(), dstAddress, payload, raw);
|
|
9470
9567
|
}
|
|
9471
9568
|
};
|
|
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
|
|
9472
9599
|
var IconSdk2 = "default" in IconSdkRaw.default ? IconSdkRaw.default : IconSdkRaw;
|
|
9473
9600
|
var { Converter, CallTransactionBuilder, CallBuilder } = IconSdk2;
|
|
9474
9601
|
var IconSpokeService = class _IconSpokeService {
|
|
9475
9602
|
constructor() {
|
|
9476
9603
|
}
|
|
9604
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
9605
|
+
return estimateStepCost(rawTx, spokeProvider.debugRpcUrl);
|
|
9606
|
+
}
|
|
9477
9607
|
/**
|
|
9478
9608
|
* Deposit tokens to the spoke chain.
|
|
9479
9609
|
* @param {IconSpokeDepositParams} params - The parameters for the deposit
|
|
@@ -9537,15 +9667,16 @@ var IconSpokeService = class _IconSpokeService {
|
|
|
9537
9667
|
};
|
|
9538
9668
|
const value = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? BigIntToHex(amount) : "0x0";
|
|
9539
9669
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9670
|
+
const to = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token;
|
|
9540
9671
|
const rawTransaction = Converter.toRawTransaction(
|
|
9541
|
-
new CallTransactionBuilder().from(walletAddress).to(
|
|
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()
|
|
9542
9673
|
);
|
|
9543
9674
|
if (raw) {
|
|
9544
9675
|
return rawTransaction;
|
|
9545
9676
|
}
|
|
9546
9677
|
return spokeProvider.walletProvider.sendTransaction({
|
|
9547
9678
|
from: walletAddress,
|
|
9548
|
-
to
|
|
9679
|
+
to,
|
|
9549
9680
|
value,
|
|
9550
9681
|
nid: spokeProvider.chainConfig.nid,
|
|
9551
9682
|
method: "transfer",
|
|
@@ -9662,6 +9793,22 @@ var AssetManagerPDA = {
|
|
|
9662
9793
|
var SolanaSpokeService = class _SolanaSpokeService {
|
|
9663
9794
|
constructor() {
|
|
9664
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
|
+
}
|
|
9665
9812
|
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
9666
9813
|
const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9667
9814
|
spokeProvider.chainConfig.chain.id,
|
|
@@ -9842,6 +9989,24 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
9842
9989
|
var StellarSpokeService = class _StellarSpokeService {
|
|
9843
9990
|
constructor() {
|
|
9844
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
|
+
}
|
|
9845
10010
|
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
9846
10011
|
const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9847
10012
|
spokeProvider.chainConfig.chain.id,
|
|
@@ -9896,6 +10061,20 @@ var StellarSpokeService = class _StellarSpokeService {
|
|
|
9896
10061
|
var SuiSpokeService = class _SuiSpokeService {
|
|
9897
10062
|
constructor() {
|
|
9898
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
|
+
}
|
|
9899
10078
|
/**
|
|
9900
10079
|
* Deposit tokens to the spoke chain.
|
|
9901
10080
|
* @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
@@ -9945,7 +10124,7 @@ var SuiSpokeService = class _SuiSpokeService {
|
|
|
9945
10124
|
}
|
|
9946
10125
|
/**
|
|
9947
10126
|
* Transfers tokens to the hub chain.
|
|
9948
|
-
* @param {
|
|
10127
|
+
* @param {SuiTransferToHubParams} params - The parameters for the transfer, including:
|
|
9949
10128
|
* - {string} token: The address of the token to transfer (use address(0) for native token).
|
|
9950
10129
|
* - {Uint8Array} recipient: The recipient address on the hub chain.
|
|
9951
10130
|
* - {string} amount: The amount to transfer.
|
|
@@ -9973,6 +10152,38 @@ var SuiSpokeService = class _SuiSpokeService {
|
|
|
9973
10152
|
var SonicSpokeService = class _SonicSpokeService {
|
|
9974
10153
|
constructor() {
|
|
9975
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
|
+
}
|
|
9976
10187
|
/**
|
|
9977
10188
|
* Get the derived address of a contract deployed with CREATE3.
|
|
9978
10189
|
* @param address - User's address on the specified chain as hex
|
|
@@ -10413,6 +10624,57 @@ function isMoneyMarketRepayUnknownError(error) {
|
|
|
10413
10624
|
var SpokeService = class {
|
|
10414
10625
|
constructor() {
|
|
10415
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
|
+
}
|
|
10416
10678
|
/**
|
|
10417
10679
|
* Deposit tokens to the spoke chain.
|
|
10418
10680
|
* @param {GetSpokeDepositParamsType<T extends SpokeProvider>} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
@@ -11051,6 +11313,15 @@ var SolverService = class {
|
|
|
11051
11313
|
}
|
|
11052
11314
|
this.hubProvider = hubProvider;
|
|
11053
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
|
+
}
|
|
11054
11325
|
/**
|
|
11055
11326
|
* Request a quote from the solver API
|
|
11056
11327
|
* @param {SolverIntentQuoteRequest} payload - The solver intent quote request
|
|
@@ -12581,6 +12852,6 @@ var SolverIntentErrorCode = /* @__PURE__ */ ((SolverIntentErrorCode2) => {
|
|
|
12581
12852
|
return SolverIntentErrorCode2;
|
|
12582
12853
|
})(SolverIntentErrorCode || {});
|
|
12583
12854
|
|
|
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 };
|
|
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 };
|
|
12585
12856
|
//# sourceMappingURL=index.mjs.map
|
|
12586
12857
|
//# sourceMappingURL=index.mjs.map
|