@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/README.md
CHANGED
|
@@ -251,6 +251,86 @@ const bscSpokeProvider: EvmSpokeProvider = new EvmSpokeProvider(
|
|
|
251
251
|
);
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
+
### Estimate Gas for Raw Transactions
|
|
255
|
+
|
|
256
|
+
The `estimateGas` function allows you to estimate the gas cost for raw transactions before executing them. This is particularly useful for all Sodax operations (swaps, money market operations, approvals) to provide users with accurate gas estimates.
|
|
257
|
+
|
|
258
|
+
The function is available on all service classes:
|
|
259
|
+
- `SolverService.estimateGas()` - for solver/intent operations
|
|
260
|
+
- `MoneyMarketService.estimateGas()` - for money market operations
|
|
261
|
+
- `SpokeService.estimateGas()` - for general spoke chain operations
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import {
|
|
265
|
+
SolverService,
|
|
266
|
+
MoneyMarketService,
|
|
267
|
+
SpokeService,
|
|
268
|
+
MoneyMarketSupplyParams
|
|
269
|
+
} from "@sodax/sdk";
|
|
270
|
+
|
|
271
|
+
// Example: Estimate gas for a solver swap transaction
|
|
272
|
+
const createIntentResult = await sodax.solver.createIntent(
|
|
273
|
+
createIntentParams,
|
|
274
|
+
bscSpokeProvider,
|
|
275
|
+
partnerFeeAmount,
|
|
276
|
+
true, // true = get raw transaction
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
if (createIntentResult.ok) {
|
|
280
|
+
const [rawTx, intent] = createIntentResult.value;
|
|
281
|
+
|
|
282
|
+
// Estimate gas for the raw transaction
|
|
283
|
+
const gasEstimate = await SolverService.estimateGas(rawTx, bscSpokeProvider);
|
|
284
|
+
|
|
285
|
+
if (gasEstimate.ok) {
|
|
286
|
+
console.log('Estimated gas for swap:', gasEstimate.value);
|
|
287
|
+
} else {
|
|
288
|
+
console.error('Failed to estimate gas for swap:', gasEstimate.error);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Example: Estimate gas for a money market supply transaction
|
|
293
|
+
const supplyResult = await sodax.moneyMarket.createSupplyIntent(
|
|
294
|
+
supplyParams,
|
|
295
|
+
bscSpokeProvider,
|
|
296
|
+
true, // true = get raw transaction
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
if (supplyResult.ok) {
|
|
300
|
+
const rawTx = supplyResult.value;
|
|
301
|
+
|
|
302
|
+
// Estimate gas for the raw transaction
|
|
303
|
+
const gasEstimate = await MoneyMarketService.estimateGas(rawTx, bscSpokeProvider);
|
|
304
|
+
|
|
305
|
+
if (gasEstimate.ok) {
|
|
306
|
+
console.log('Estimated gas for supply:', gasEstimate.value);
|
|
307
|
+
} else {
|
|
308
|
+
console.error('Failed to estimate gas for supply:', gasEstimate.error);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Example: Estimate gas for an approval transaction
|
|
313
|
+
const approveResult = await sodax.solver.approve(
|
|
314
|
+
tokenAddress,
|
|
315
|
+
amount,
|
|
316
|
+
bscSpokeProvider,
|
|
317
|
+
true // true = get raw transaction
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
if (approveResult.ok) {
|
|
321
|
+
const rawTx = approveResult.value;
|
|
322
|
+
|
|
323
|
+
// Estimate gas for the approval transaction
|
|
324
|
+
const gasEstimate = await SpokeService.estimateGas(rawTx, bscSpokeProvider);
|
|
325
|
+
|
|
326
|
+
if (gasEstimate.ok) {
|
|
327
|
+
console.log('Estimated gas for approval:', gasEstimate.value);
|
|
328
|
+
} else {
|
|
329
|
+
console.error('Failed to estimate gas for approval:', gasEstimate.error);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
254
334
|
### Accessing Sodax Features
|
|
255
335
|
|
|
256
336
|
Sodax feature set currently contain:
|
package/dist/index.cjs
CHANGED
|
@@ -4,12 +4,16 @@ var viem = require('viem');
|
|
|
4
4
|
var chains = require('viem/chains');
|
|
5
5
|
var types = require('@sodax/types');
|
|
6
6
|
var stargate = require('@cosmjs/stargate');
|
|
7
|
+
var networks = require('@injectivelabs/networks');
|
|
8
|
+
var sdkTs = require('@injectivelabs/sdk-ts');
|
|
7
9
|
var IconSdkRaw = require('icon-sdk-js');
|
|
8
10
|
var stellarSdk = require('@stellar/stellar-sdk');
|
|
9
11
|
var bcs = require('@mysten/sui/bcs');
|
|
12
|
+
var client = require('@mysten/sui/client');
|
|
10
13
|
var transactions = require('@mysten/sui/transactions');
|
|
11
14
|
var web3_js = require('@solana/web3.js');
|
|
12
15
|
var invariant2 = require('tiny-invariant');
|
|
16
|
+
var tx_js = require('cosmjs-types/cosmos/tx/v1beta1/tx.js');
|
|
13
17
|
var rlp = require('rlp');
|
|
14
18
|
var splToken = require('@solana/spl-token');
|
|
15
19
|
var anchor = require('@coral-xyz/anchor');
|
|
@@ -6772,14 +6776,16 @@ var Injective20Token = class {
|
|
|
6772
6776
|
return await this.client.execute(senderAddress, this.contractAddress, msg, "auto");
|
|
6773
6777
|
}
|
|
6774
6778
|
};
|
|
6775
|
-
|
|
6776
|
-
// src/entities/injective/InjectiveSpokeProvider.ts
|
|
6777
6779
|
var InjectiveSpokeProvider = class {
|
|
6778
6780
|
walletProvider;
|
|
6779
6781
|
chainConfig;
|
|
6782
|
+
txClient;
|
|
6780
6783
|
constructor(conf, walletProvider) {
|
|
6781
6784
|
this.chainConfig = conf;
|
|
6782
6785
|
this.walletProvider = walletProvider;
|
|
6786
|
+
this.txClient = new sdkTs.TxGrpcClient(
|
|
6787
|
+
networks.getNetworkEndpoints(this.chainConfig.network === "Mainnet" ? networks.Network.Mainnet : networks.Network.Testnet).grpc
|
|
6788
|
+
);
|
|
6783
6789
|
}
|
|
6784
6790
|
// Query Methods
|
|
6785
6791
|
async getState() {
|
|
@@ -6846,7 +6852,7 @@ var InjectiveSpokeProvider = class {
|
|
|
6846
6852
|
await injective20Token.getTokenInfo();
|
|
6847
6853
|
isNative2 = false;
|
|
6848
6854
|
} catch (err) {
|
|
6849
|
-
console.
|
|
6855
|
+
console.error("[InjectiveSpokeProvider] isNative error", err);
|
|
6850
6856
|
throw err;
|
|
6851
6857
|
}
|
|
6852
6858
|
return isNative2;
|
|
@@ -6923,10 +6929,12 @@ var IconSpokeProvider = class {
|
|
|
6923
6929
|
walletProvider;
|
|
6924
6930
|
chainConfig;
|
|
6925
6931
|
iconService;
|
|
6926
|
-
|
|
6932
|
+
debugRpcUrl;
|
|
6933
|
+
constructor(walletProvider, chainConfig, rpcUrl = "https://ctz.solidwallet.io/api/v3", debugRpcUrl = "https://ctz.solidwallet.io/api/v3d") {
|
|
6927
6934
|
this.walletProvider = walletProvider;
|
|
6928
6935
|
this.chainConfig = chainConfig;
|
|
6929
6936
|
this.iconService = new IconSdk.IconService(new IconSdk.IconService.HttpProvider(rpcUrl));
|
|
6937
|
+
this.debugRpcUrl = debugRpcUrl;
|
|
6930
6938
|
}
|
|
6931
6939
|
};
|
|
6932
6940
|
|
|
@@ -7177,7 +7185,7 @@ var StellarSpokeProvider = class {
|
|
|
7177
7185
|
networkPassphrase: network.passphrase
|
|
7178
7186
|
}).addOperation(operation).setTimeout(STELLAR_DEFAULT_TX_TIMEOUT_SECONDS).build();
|
|
7179
7187
|
const simulation = await this.sorobanServer.simulateTransaction(priorityTransaction);
|
|
7180
|
-
return [
|
|
7188
|
+
return [priorityTransaction, simulation];
|
|
7181
7189
|
}
|
|
7182
7190
|
handleSendTransactionError(response) {
|
|
7183
7191
|
if (response.status === "ERROR") {
|
|
@@ -7265,9 +7273,14 @@ var StellarSpokeProvider = class {
|
|
|
7265
7273
|
const accountResponse = await this.server.loadAccount(walletAddress);
|
|
7266
7274
|
const stellarAccount = new CustomStellarAccount(accountResponse);
|
|
7267
7275
|
const depositCall = this.buildDepositCall(walletAddress, token, amount, recipient, data);
|
|
7268
|
-
const [
|
|
7276
|
+
const [rawPriorityTx, simulation] = await this.buildPriorityStellarTransaction(
|
|
7277
|
+
stellarAccount,
|
|
7278
|
+
network,
|
|
7279
|
+
depositCall
|
|
7280
|
+
);
|
|
7281
|
+
const assembledPriorityTx = stellarSdk.SorobanRpc.assembleTransaction(rawPriorityTx, simulation).build();
|
|
7269
7282
|
if (raw) {
|
|
7270
|
-
const transactionXdr =
|
|
7283
|
+
const transactionXdr = rawPriorityTx.toXDR();
|
|
7271
7284
|
return {
|
|
7272
7285
|
from: walletAddress,
|
|
7273
7286
|
to: this.chainConfig.addresses.assetManager,
|
|
@@ -7275,7 +7288,13 @@ var StellarSpokeProvider = class {
|
|
|
7275
7288
|
data: transactionXdr
|
|
7276
7289
|
};
|
|
7277
7290
|
}
|
|
7278
|
-
const hash = await this.submitOrRestoreAndRetry(
|
|
7291
|
+
const hash = await this.submitOrRestoreAndRetry(
|
|
7292
|
+
stellarAccount,
|
|
7293
|
+
network,
|
|
7294
|
+
assembledPriorityTx,
|
|
7295
|
+
depositCall,
|
|
7296
|
+
simulation
|
|
7297
|
+
);
|
|
7279
7298
|
return `${hash}`;
|
|
7280
7299
|
} catch (error) {
|
|
7281
7300
|
console.error("Error during deposit:", error);
|
|
@@ -7344,9 +7363,11 @@ var StellarSpokeProvider = class {
|
|
|
7344
7363
|
var SuiSpokeProvider = class _SuiSpokeProvider {
|
|
7345
7364
|
walletProvider;
|
|
7346
7365
|
chainConfig;
|
|
7366
|
+
publicClient;
|
|
7347
7367
|
constructor(config, wallet_provider) {
|
|
7348
7368
|
this.chainConfig = config;
|
|
7349
7369
|
this.walletProvider = wallet_provider;
|
|
7370
|
+
this.publicClient = new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
7350
7371
|
}
|
|
7351
7372
|
async getBalance(token) {
|
|
7352
7373
|
const assetmanager = this.splitAddress(this.chainConfig.addresses.assetManager);
|
|
@@ -7386,7 +7407,11 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
|
|
|
7386
7407
|
]
|
|
7387
7408
|
});
|
|
7388
7409
|
if (raw) {
|
|
7389
|
-
|
|
7410
|
+
tx.setSender(walletAddress);
|
|
7411
|
+
const transactionRaw = await tx.build({
|
|
7412
|
+
client: this.publicClient,
|
|
7413
|
+
onlyTransactionKind: true
|
|
7414
|
+
});
|
|
7390
7415
|
const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
|
|
7391
7416
|
return {
|
|
7392
7417
|
from: walletAddress,
|
|
@@ -7449,10 +7474,14 @@ var SuiSpokeProvider = class _SuiSpokeProvider {
|
|
|
7449
7474
|
txb.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(data))
|
|
7450
7475
|
]
|
|
7451
7476
|
});
|
|
7477
|
+
const walletAddress = await this.walletProvider.getWalletAddress();
|
|
7452
7478
|
if (raw) {
|
|
7453
|
-
|
|
7479
|
+
txb.setSender(walletAddress);
|
|
7480
|
+
const transactionRaw = await txb.build({
|
|
7481
|
+
client: this.publicClient,
|
|
7482
|
+
onlyTransactionKind: true
|
|
7483
|
+
});
|
|
7454
7484
|
const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
|
|
7455
|
-
const walletAddress = await this.walletProvider.getWalletAddressBytes();
|
|
7456
7485
|
return {
|
|
7457
7486
|
from: walletAddress,
|
|
7458
7487
|
to: `${connection.packageId}::${connection.moduleId}::send_message_ua`,
|
|
@@ -8115,6 +8144,15 @@ function encodeAddress(spokeChainId, address) {
|
|
|
8115
8144
|
return address;
|
|
8116
8145
|
}
|
|
8117
8146
|
}
|
|
8147
|
+
function hexToBigInt(hex) {
|
|
8148
|
+
const trimmed = hex.trim().toLowerCase();
|
|
8149
|
+
const isValid = /^(0x)?[0-9a-f]+$/.test(trimmed);
|
|
8150
|
+
if (!isValid) {
|
|
8151
|
+
throw new Error(`Invalid hex string: "${hex}"`);
|
|
8152
|
+
}
|
|
8153
|
+
const normalized = trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`;
|
|
8154
|
+
return BigInt(normalized);
|
|
8155
|
+
}
|
|
8118
8156
|
var MoneyMarketService = class _MoneyMarketService {
|
|
8119
8157
|
config;
|
|
8120
8158
|
hubProvider;
|
|
@@ -8142,6 +8180,15 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
8142
8180
|
}
|
|
8143
8181
|
this.hubProvider = hubProvider;
|
|
8144
8182
|
}
|
|
8183
|
+
/**
|
|
8184
|
+
* Estimate the gas for a raw transaction.
|
|
8185
|
+
* @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
|
|
8186
|
+
* @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
8187
|
+
* @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
|
|
8188
|
+
*/
|
|
8189
|
+
static async estimateGas(params, spokeProvider) {
|
|
8190
|
+
return SpokeService.estimateGas(params, spokeProvider);
|
|
8191
|
+
}
|
|
8145
8192
|
/**
|
|
8146
8193
|
* Check if allowance is sufficient for actions on the money market pool
|
|
8147
8194
|
* @param {MoneyMarketParams} params - Money market params containing token address and amount
|
|
@@ -9305,6 +9352,37 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9305
9352
|
var EvmSpokeService = class _EvmSpokeService {
|
|
9306
9353
|
constructor() {
|
|
9307
9354
|
}
|
|
9355
|
+
/**
|
|
9356
|
+
* Estimates the gas necessary to complete a transaction without submitting it to the network.
|
|
9357
|
+
*
|
|
9358
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateGas
|
|
9359
|
+
* - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
|
|
9360
|
+
*
|
|
9361
|
+
* @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
9362
|
+
* @param {EvmSpokeProvider} spokeProvider - The EVM spoke provider.
|
|
9363
|
+
* @returns {Promise<bigint>} Estimated gas for the transaction.
|
|
9364
|
+
*
|
|
9365
|
+
* @example
|
|
9366
|
+
*
|
|
9367
|
+
* const rawTx: EvmRawTransaction = {
|
|
9368
|
+
* from: '0x1234...abcd', // sender address
|
|
9369
|
+
* to: '0xabcd...1234', // recipient address
|
|
9370
|
+
* value: 1000000000000000000n, // 1 ETH in wei
|
|
9371
|
+
* data: '0x', // no calldata
|
|
9372
|
+
* };
|
|
9373
|
+
*
|
|
9374
|
+
* // Assume spokeProvider is an initialized EvmSpokeProvider
|
|
9375
|
+
* const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
|
|
9376
|
+
* console.log(`Estimated gas: ${estimatedGas}`);
|
|
9377
|
+
*/
|
|
9378
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
9379
|
+
return spokeProvider.publicClient.estimateGas({
|
|
9380
|
+
account: rawTx.from,
|
|
9381
|
+
to: rawTx.to,
|
|
9382
|
+
value: rawTx.value,
|
|
9383
|
+
data: rawTx.data
|
|
9384
|
+
});
|
|
9385
|
+
}
|
|
9308
9386
|
/**
|
|
9309
9387
|
* Deposit tokens to the spoke chain.
|
|
9310
9388
|
* @param {EvmSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
@@ -9421,6 +9499,25 @@ var EvmSpokeService = class _EvmSpokeService {
|
|
|
9421
9499
|
var InjectiveSpokeService = class _InjectiveSpokeService {
|
|
9422
9500
|
constructor() {
|
|
9423
9501
|
}
|
|
9502
|
+
/**
|
|
9503
|
+
* Estimate the gas for a transaction.
|
|
9504
|
+
* @param {InjectiveRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
9505
|
+
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9506
|
+
* @returns {Promise<InjectiveGasEstimate>} The estimated gas for the transaction.
|
|
9507
|
+
*/
|
|
9508
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
9509
|
+
const txRaw = tx_js.TxRaw.fromPartial({
|
|
9510
|
+
bodyBytes: rawTx.signedDoc.bodyBytes,
|
|
9511
|
+
authInfoBytes: rawTx.signedDoc.authInfoBytes,
|
|
9512
|
+
signatures: []
|
|
9513
|
+
// not required for simulation
|
|
9514
|
+
});
|
|
9515
|
+
const { gasInfo } = await spokeProvider.txClient.simulate(txRaw);
|
|
9516
|
+
return {
|
|
9517
|
+
gasWanted: gasInfo.gasWanted,
|
|
9518
|
+
gasUsed: gasInfo.gasUsed
|
|
9519
|
+
};
|
|
9520
|
+
}
|
|
9424
9521
|
/**
|
|
9425
9522
|
* Deposit tokens to the spoke chain.
|
|
9426
9523
|
* @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
@@ -9496,11 +9593,44 @@ var InjectiveSpokeService = class _InjectiveSpokeService {
|
|
|
9496
9593
|
return spokeProvider.send_message(sender, dstChainId.toString(), dstAddress, payload, raw);
|
|
9497
9594
|
}
|
|
9498
9595
|
};
|
|
9596
|
+
|
|
9597
|
+
// src/utils/icon-utils.ts
|
|
9598
|
+
async function estimateStepCost(rawTx, debugRpcUrl) {
|
|
9599
|
+
try {
|
|
9600
|
+
const tmpRawTx = { ...rawTx };
|
|
9601
|
+
delete tmpRawTx["stepLimit"];
|
|
9602
|
+
const response = await fetch(debugRpcUrl, {
|
|
9603
|
+
method: "POST",
|
|
9604
|
+
headers: {
|
|
9605
|
+
"Content-Type": "application/json"
|
|
9606
|
+
},
|
|
9607
|
+
body: JSON.stringify({
|
|
9608
|
+
jsonrpc: "2.0",
|
|
9609
|
+
method: "debug_estimateStep",
|
|
9610
|
+
id: 1234,
|
|
9611
|
+
params: tmpRawTx
|
|
9612
|
+
})
|
|
9613
|
+
});
|
|
9614
|
+
if (!response.ok) {
|
|
9615
|
+
throw new Error(`Failed to fetch step cost: ${response.statusText}`);
|
|
9616
|
+
}
|
|
9617
|
+
const data = await response.json();
|
|
9618
|
+
return hexToBigInt(data.result);
|
|
9619
|
+
} catch (e) {
|
|
9620
|
+
console.error("estimateStepCost error:", e);
|
|
9621
|
+
throw e;
|
|
9622
|
+
}
|
|
9623
|
+
}
|
|
9624
|
+
|
|
9625
|
+
// src/services/spoke/IconSpokeService.ts
|
|
9499
9626
|
var IconSdk2 = "default" in IconSdkRaw__namespace.default ? IconSdkRaw__namespace.default : IconSdkRaw__namespace;
|
|
9500
9627
|
var { Converter, CallTransactionBuilder, CallBuilder } = IconSdk2;
|
|
9501
9628
|
var IconSpokeService = class _IconSpokeService {
|
|
9502
9629
|
constructor() {
|
|
9503
9630
|
}
|
|
9631
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
9632
|
+
return estimateStepCost(rawTx, spokeProvider.debugRpcUrl);
|
|
9633
|
+
}
|
|
9504
9634
|
/**
|
|
9505
9635
|
* Deposit tokens to the spoke chain.
|
|
9506
9636
|
* @param {IconSpokeDepositParams} params - The parameters for the deposit
|
|
@@ -9564,15 +9694,16 @@ var IconSpokeService = class _IconSpokeService {
|
|
|
9564
9694
|
};
|
|
9565
9695
|
const value = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? BigIntToHex(amount) : "0x0";
|
|
9566
9696
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9697
|
+
const to = isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token;
|
|
9567
9698
|
const rawTransaction = Converter.toRawTransaction(
|
|
9568
|
-
new CallTransactionBuilder().from(walletAddress).to(
|
|
9699
|
+
new CallTransactionBuilder().from(walletAddress).to(to).stepLimit(Converter.toBigNumber("2000000")).nid(spokeProvider.chainConfig.nid).version("0x3").timestamp((/* @__PURE__ */ new Date()).getTime() * 1e3).value(value).method("transfer").params(params).build()
|
|
9569
9700
|
);
|
|
9570
9701
|
if (raw) {
|
|
9571
9702
|
return rawTransaction;
|
|
9572
9703
|
}
|
|
9573
9704
|
return spokeProvider.walletProvider.sendTransaction({
|
|
9574
9705
|
from: walletAddress,
|
|
9575
|
-
to
|
|
9706
|
+
to,
|
|
9576
9707
|
value,
|
|
9577
9708
|
nid: spokeProvider.chainConfig.nid,
|
|
9578
9709
|
method: "transfer",
|
|
@@ -9689,6 +9820,22 @@ var AssetManagerPDA = {
|
|
|
9689
9820
|
var SolanaSpokeService = class _SolanaSpokeService {
|
|
9690
9821
|
constructor() {
|
|
9691
9822
|
}
|
|
9823
|
+
/**
|
|
9824
|
+
* Estimate the gas for a transaction.
|
|
9825
|
+
* @param {SolanaRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
9826
|
+
* @param {SolanaSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9827
|
+
* @returns {Promise<number | undefined>} The units consumed for the transaction.
|
|
9828
|
+
*/
|
|
9829
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
9830
|
+
const connection = new web3_js.Connection(spokeProvider.chainConfig.rpcUrl, "confirmed");
|
|
9831
|
+
const serializedTxBytes = Buffer.from(rawTx.data, "base64");
|
|
9832
|
+
const versionedTx = web3_js.VersionedTransaction.deserialize(serializedTxBytes);
|
|
9833
|
+
const { value } = await connection.simulateTransaction(versionedTx);
|
|
9834
|
+
if (value.err) {
|
|
9835
|
+
throw new Error(`Failed to simulate transaction: ${JSON.stringify(value.err, null, 2)}`);
|
|
9836
|
+
}
|
|
9837
|
+
return value.unitsConsumed;
|
|
9838
|
+
}
|
|
9692
9839
|
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
9693
9840
|
const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9694
9841
|
spokeProvider.chainConfig.chain.id,
|
|
@@ -9869,6 +10016,24 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
9869
10016
|
var StellarSpokeService = class _StellarSpokeService {
|
|
9870
10017
|
constructor() {
|
|
9871
10018
|
}
|
|
10019
|
+
/**
|
|
10020
|
+
* Estimate the gas for a transaction.
|
|
10021
|
+
* @param rawTx - The raw transaction to estimate the gas for.
|
|
10022
|
+
* @param spokeProvider - The spoke provider.
|
|
10023
|
+
* @returns The estimated gas (minResourceFee) for the transaction.
|
|
10024
|
+
*/
|
|
10025
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
10026
|
+
const network = await spokeProvider.sorobanServer.getNetwork();
|
|
10027
|
+
let tx = stellarSdk.TransactionBuilder.fromXDR(rawTx.data, network.passphrase);
|
|
10028
|
+
if (tx instanceof stellarSdk.FeeBumpTransaction) {
|
|
10029
|
+
tx = tx.innerTransaction;
|
|
10030
|
+
}
|
|
10031
|
+
const simulationForFee = await spokeProvider.sorobanServer.simulateTransaction(tx);
|
|
10032
|
+
if (!stellarSdk.rpc.Api.isSimulationSuccess(simulationForFee)) {
|
|
10033
|
+
throw new Error(`Simulation error: ${JSON.stringify(simulationForFee)}`);
|
|
10034
|
+
}
|
|
10035
|
+
return BigInt(simulationForFee.minResourceFee);
|
|
10036
|
+
}
|
|
9872
10037
|
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
9873
10038
|
const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9874
10039
|
spokeProvider.chainConfig.chain.id,
|
|
@@ -9923,6 +10088,20 @@ var StellarSpokeService = class _StellarSpokeService {
|
|
|
9923
10088
|
var SuiSpokeService = class _SuiSpokeService {
|
|
9924
10089
|
constructor() {
|
|
9925
10090
|
}
|
|
10091
|
+
/**
|
|
10092
|
+
* Estimate the gas for a transaction.
|
|
10093
|
+
* @param {SuiRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
10094
|
+
* @param {SuiSpokeProvider} spokeProvider - The spoke provider.
|
|
10095
|
+
* @returns {Promise<bigint>} The estimated computation cost.
|
|
10096
|
+
*/
|
|
10097
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
10098
|
+
const txb = transactions.Transaction.fromKind(rawTx.data);
|
|
10099
|
+
const result = await spokeProvider.publicClient.devInspectTransactionBlock({
|
|
10100
|
+
sender: rawTx.from,
|
|
10101
|
+
transactionBlock: txb
|
|
10102
|
+
});
|
|
10103
|
+
return result.effects.gasUsed;
|
|
10104
|
+
}
|
|
9926
10105
|
/**
|
|
9927
10106
|
* Deposit tokens to the spoke chain.
|
|
9928
10107
|
* @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
@@ -9972,7 +10151,7 @@ var SuiSpokeService = class _SuiSpokeService {
|
|
|
9972
10151
|
}
|
|
9973
10152
|
/**
|
|
9974
10153
|
* Transfers tokens to the hub chain.
|
|
9975
|
-
* @param {
|
|
10154
|
+
* @param {SuiTransferToHubParams} params - The parameters for the transfer, including:
|
|
9976
10155
|
* - {string} token: The address of the token to transfer (use address(0) for native token).
|
|
9977
10156
|
* - {Uint8Array} recipient: The recipient address on the hub chain.
|
|
9978
10157
|
* - {string} amount: The amount to transfer.
|
|
@@ -10000,6 +10179,38 @@ var SuiSpokeService = class _SuiSpokeService {
|
|
|
10000
10179
|
var SonicSpokeService = class _SonicSpokeService {
|
|
10001
10180
|
constructor() {
|
|
10002
10181
|
}
|
|
10182
|
+
/**
|
|
10183
|
+
/**
|
|
10184
|
+
* Estimates the gas necessary to complete a transaction without submitting it to the network.
|
|
10185
|
+
*
|
|
10186
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateGas
|
|
10187
|
+
* - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
|
|
10188
|
+
*
|
|
10189
|
+
* @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
10190
|
+
* @param {SonicSpokeProvider} spokeProvider - The EVM spoke provider.
|
|
10191
|
+
* @returns {Promise<bigint>} Estimated gas for the transaction.
|
|
10192
|
+
*
|
|
10193
|
+
* @example
|
|
10194
|
+
*
|
|
10195
|
+
* const rawTx: EvmRawTransaction = {
|
|
10196
|
+
* from: '0x1234...abcd', // sender address
|
|
10197
|
+
* to: '0xabcd...1234', // recipient address
|
|
10198
|
+
* value: 1000000000000000000n, // 1 ETH in wei
|
|
10199
|
+
* data: '0x', // no calldata
|
|
10200
|
+
* };
|
|
10201
|
+
*
|
|
10202
|
+
* // Assume spokeProvider is an initialized EvmSpokeProvider
|
|
10203
|
+
* const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
|
|
10204
|
+
* console.log(`Estimated gas: ${estimatedGas}`);
|
|
10205
|
+
*/
|
|
10206
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
10207
|
+
return spokeProvider.publicClient.estimateGas({
|
|
10208
|
+
account: rawTx.from,
|
|
10209
|
+
to: rawTx.to,
|
|
10210
|
+
value: rawTx.value,
|
|
10211
|
+
data: rawTx.data
|
|
10212
|
+
});
|
|
10213
|
+
}
|
|
10003
10214
|
/**
|
|
10004
10215
|
* Get the derived address of a contract deployed with CREATE3.
|
|
10005
10216
|
* @param address - User's address on the specified chain as hex
|
|
@@ -10440,6 +10651,57 @@ function isMoneyMarketRepayUnknownError(error) {
|
|
|
10440
10651
|
var SpokeService = class {
|
|
10441
10652
|
constructor() {
|
|
10442
10653
|
}
|
|
10654
|
+
/**
|
|
10655
|
+
* Estimate the gas for a raw transaction.
|
|
10656
|
+
* @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
|
|
10657
|
+
* @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
10658
|
+
* @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
|
|
10659
|
+
*/
|
|
10660
|
+
static async estimateGas(params, spokeProvider) {
|
|
10661
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
10662
|
+
return EvmSpokeService.estimateGas(
|
|
10663
|
+
params,
|
|
10664
|
+
spokeProvider
|
|
10665
|
+
);
|
|
10666
|
+
}
|
|
10667
|
+
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
10668
|
+
return SonicSpokeService.estimateGas(
|
|
10669
|
+
params,
|
|
10670
|
+
spokeProvider
|
|
10671
|
+
);
|
|
10672
|
+
}
|
|
10673
|
+
if (spokeProvider instanceof InjectiveSpokeProvider) {
|
|
10674
|
+
return InjectiveSpokeService.estimateGas(
|
|
10675
|
+
params,
|
|
10676
|
+
spokeProvider
|
|
10677
|
+
);
|
|
10678
|
+
}
|
|
10679
|
+
if (spokeProvider instanceof IconSpokeProvider) {
|
|
10680
|
+
return IconSpokeService.estimateGas(
|
|
10681
|
+
params,
|
|
10682
|
+
spokeProvider
|
|
10683
|
+
);
|
|
10684
|
+
}
|
|
10685
|
+
if (spokeProvider instanceof SuiSpokeProvider) {
|
|
10686
|
+
return SuiSpokeService.estimateGas(
|
|
10687
|
+
params,
|
|
10688
|
+
spokeProvider
|
|
10689
|
+
);
|
|
10690
|
+
}
|
|
10691
|
+
if (spokeProvider instanceof SolanaSpokeProvider) {
|
|
10692
|
+
return SolanaSpokeService.estimateGas(
|
|
10693
|
+
params,
|
|
10694
|
+
spokeProvider
|
|
10695
|
+
);
|
|
10696
|
+
}
|
|
10697
|
+
if (spokeProvider instanceof StellarSpokeProvider) {
|
|
10698
|
+
return StellarSpokeService.estimateGas(
|
|
10699
|
+
params,
|
|
10700
|
+
spokeProvider
|
|
10701
|
+
);
|
|
10702
|
+
}
|
|
10703
|
+
throw new Error("Invalid spoke provider");
|
|
10704
|
+
}
|
|
10443
10705
|
/**
|
|
10444
10706
|
* Deposit tokens to the spoke chain.
|
|
10445
10707
|
* @param {GetSpokeDepositParamsType<T extends SpokeProvider>} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
@@ -11078,6 +11340,15 @@ var SolverService = class {
|
|
|
11078
11340
|
}
|
|
11079
11341
|
this.hubProvider = hubProvider;
|
|
11080
11342
|
}
|
|
11343
|
+
/**
|
|
11344
|
+
* Estimate the gas for a raw transaction.
|
|
11345
|
+
* @param {TxReturnType<T, true>} params - The parameters for the raw transaction.
|
|
11346
|
+
* @param {SpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
11347
|
+
* @returns {Promise<GetEstimateGasReturnType<T>>} A promise that resolves to the gas.
|
|
11348
|
+
*/
|
|
11349
|
+
static async estimateGas(params, spokeProvider) {
|
|
11350
|
+
return SpokeService.estimateGas(params, spokeProvider);
|
|
11351
|
+
}
|
|
11081
11352
|
/**
|
|
11082
11353
|
* Request a quote from the solver API
|
|
11083
11354
|
* @param {SolverIntentQuoteRequest} payload - The solver intent quote request
|
|
@@ -12673,6 +12944,7 @@ exports.getSpokeChainIdFromIntentRelayChainId = getSpokeChainIdFromIntentRelayCh
|
|
|
12673
12944
|
exports.getSupportedMoneyMarketTokens = getSupportedMoneyMarketTokens;
|
|
12674
12945
|
exports.getSupportedSolverTokens = getSupportedSolverTokens;
|
|
12675
12946
|
exports.getTransactionPackets = getTransactionPackets;
|
|
12947
|
+
exports.hexToBigInt = hexToBigInt;
|
|
12676
12948
|
exports.hubAssetToOriginalAssetMap = hubAssetToOriginalAssetMap;
|
|
12677
12949
|
exports.hubAssets = hubAssets;
|
|
12678
12950
|
exports.hubVaults = hubVaults;
|