@molteee/arena-tools 0.2.9 → 0.2.10
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/utils/tx.d.ts +2 -2
- package/dist/utils/tx.js +25 -20
- package/dist/utils/tx.js.map +1 -1
- package/package.json +1 -1
package/dist/utils/tx.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Send a write transaction with automatic retry on 429 rate limits.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Always estimates gas to avoid overpaying (Monad charges full gas limit).
|
|
4
|
+
* Falls back to 1M gas limit only if estimation fails or ARENA_SKIP_ESTIMATE=1.
|
|
5
5
|
* Returns the transaction hash, gas used, and receipt logs.
|
|
6
6
|
*/
|
|
7
7
|
export declare function sendTx(params: {
|
package/dist/utils/tx.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { getPublicClient, getWalletClient } from "../client.js";
|
|
2
|
-
//
|
|
3
|
-
// 1M
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const SHOULD_ESTIMATE = !!process.env.ARENA_ESTIMATE_GAS;
|
|
2
|
+
// IMPORTANT: Monad charges for the FULL gas limit, not just gas used.
|
|
3
|
+
// A hardcoded 1M limit costs ~0.102 MON per tx even for simple actions (~170k actual).
|
|
4
|
+
// Always estimate gas to avoid 5-6x overpay. Fallback to 1M only if estimation fails.
|
|
5
|
+
// Set ARENA_SKIP_ESTIMATE=1 to use fixed gas limit (NOT recommended).
|
|
6
|
+
const FALLBACK_GAS = 1000000n;
|
|
7
|
+
const SHOULD_SKIP_ESTIMATE = !!process.env.ARENA_SKIP_ESTIMATE;
|
|
9
8
|
// Max retries for 429 rate limit errors at the sendTx level
|
|
10
9
|
const MAX_RETRIES = 3;
|
|
11
10
|
const BASE_DELAY_MS = 2000;
|
|
@@ -20,8 +19,8 @@ function sleep(ms) {
|
|
|
20
19
|
}
|
|
21
20
|
/**
|
|
22
21
|
* Send a write transaction with automatic retry on 429 rate limits.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Always estimates gas to avoid overpaying (Monad charges full gas limit).
|
|
23
|
+
* Falls back to 1M gas limit only if estimation fails or ARENA_SKIP_ESTIMATE=1.
|
|
25
24
|
* Returns the transaction hash, gas used, and receipt logs.
|
|
26
25
|
*/
|
|
27
26
|
export async function sendTx(params) {
|
|
@@ -31,17 +30,23 @@ export async function sendTx(params) {
|
|
|
31
30
|
let lastError;
|
|
32
31
|
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
33
32
|
try {
|
|
34
|
-
// Gas:
|
|
35
|
-
let gas =
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
// Gas: always estimate to avoid overpay. Fallback to 1M on failure.
|
|
34
|
+
let gas = FALLBACK_GAS;
|
|
35
|
+
if (!SHOULD_SKIP_ESTIMATE) {
|
|
36
|
+
try {
|
|
37
|
+
const gasEstimate = await publicClient.estimateGas({
|
|
38
|
+
account: account.address,
|
|
39
|
+
to: params.to,
|
|
40
|
+
data: params.data,
|
|
41
|
+
value: params.value ?? 0n,
|
|
42
|
+
});
|
|
43
|
+
// 1.5x buffer — Monad needs more headroom than Ethereum
|
|
44
|
+
gas = (gasEstimate * 3n) / 2n;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Estimation failed (e.g. rate limited) — use fallback
|
|
48
|
+
gas = FALLBACK_GAS;
|
|
49
|
+
}
|
|
45
50
|
}
|
|
46
51
|
// Send transaction
|
|
47
52
|
const hash = await walletClient.sendTransaction({
|
package/dist/utils/tx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx.js","sourceRoot":"","sources":["../../src/utils/tx.ts"],"names":[],"m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