@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/README.md +80 -0
- package/dist/index.cjs +328 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +150 -43
- package/dist/index.d.ts +150 -43
- package/dist/index.mjs +328 -49
- 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:
|