@rhinestone/service-sdk 0.2.4 → 0.2.5
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/chains.d.ts.map +1 -1
- package/dist/chains.js +40 -10
- package/package.json +1 -1
package/dist/chains.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAG1D,KAAK,mBAAmB,GAAG,IAAI,CAC7B,YAAY,EACZ,oBAAoB,GAAG,eAAe,CACvC,CAAA;
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAG1D,KAAK,mBAAmB,GAAG,IAAI,CAC7B,YAAY,EACZ,oBAAoB,GAAG,eAAe,CACvC,CAAA;AA+CD,wBAAsB,eAAe,CACnC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,gBAAgB,CAAC,CAM3B"}
|
package/dist/chains.js
CHANGED
|
@@ -2,22 +2,52 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.estimateGasFees = estimateGasFees;
|
|
4
4
|
const chains_1 = require("viem/chains");
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// Chains that price fees from eth_feeHistory instead of viem's default
|
|
6
|
+
// estimator (which sources the tip from the unspecified eth_maxPriorityFeePerGas
|
|
7
|
+
// oracle). L2s are intentionally absent — their sequencers include ~zero-tip
|
|
8
|
+
// txs, so the default is fine and a floor would just overpay.
|
|
9
|
+
const HISTORICAL_FEE_CHAINS = new Set([chains_1.sepolia.id, chains_1.mainnet.id]);
|
|
10
|
+
const DEFAULT_FEE_CONFIG = {
|
|
11
|
+
historyBlocks: 1,
|
|
12
|
+
baseFeeMultiplier: 2n,
|
|
13
|
+
// p50, not p75. The mainnet stalls we saw were caused by a *zero* tip, not by
|
|
14
|
+
// tipping below p75 — once the tip is non-zero a fill is reliably included, so
|
|
15
|
+
// a higher percentile buys no extra speed, only cost.
|
|
16
|
+
//
|
|
17
|
+
// Example — bundle 4225…447075 (2026-06-04): the fill broadcast with tip 0 and
|
|
18
|
+
// sat ~3 min. It was mineable (maxFee >= baseFee) for ~12 of its 16 stuck
|
|
19
|
+
// blocks yet still skipped, because a zero-tip tx earns the builder nothing
|
|
20
|
+
// (base fee is burned). The market was tipping p50 ~0.07-0.98 gwei the whole
|
|
21
|
+
// time — any non-zero tip would have gotten it in.
|
|
22
|
+
//
|
|
23
|
+
// At ~$1,800/ETH and ~383k gas/fill the tip runs ~$0.14 at p50 vs ~$0.68 at
|
|
24
|
+
// p75 (~5x), on *every* mainnet fill — not just the rare stuck one.
|
|
25
|
+
rewardPercentile: 50,
|
|
26
|
+
tipFloorWei: 100000000n, // 0.1 gwei (~$0.07/fill); see rewardPercentile
|
|
27
|
+
};
|
|
28
|
+
// Per-chain overrides; any omitted field falls back to DEFAULT_FEE_CONFIG.
|
|
29
|
+
const FEE_CONFIG_OVERRIDES = {
|
|
30
|
+
// Testnet — leave as-is: aggressive percentile, no floor (not real money).
|
|
31
|
+
[chains_1.sepolia.id]: { rewardPercentile: 75, tipFloorWei: 0n },
|
|
32
|
+
};
|
|
7
33
|
async function estimateGasFees(client, chainId) {
|
|
8
|
-
if (chainId
|
|
9
|
-
return
|
|
34
|
+
if (!HISTORICAL_FEE_CHAINS.has(chainId)) {
|
|
35
|
+
return client.estimateFeesPerGas();
|
|
10
36
|
}
|
|
11
|
-
|
|
37
|
+
const config = { ...DEFAULT_FEE_CONFIG, ...FEE_CONFIG_OVERRIDES[chainId] };
|
|
38
|
+
return estimateFeeHistoryGasFees(client, config);
|
|
12
39
|
}
|
|
13
|
-
|
|
40
|
+
// Priority fee = the latest block's reward at `rewardPercentile`, floored at
|
|
41
|
+
// `tipFloorWei`; maxFeePerGas = baseFee * baseFeeMultiplier + priorityFee.
|
|
42
|
+
async function estimateFeeHistoryGasFees(client, config) {
|
|
14
43
|
const feeHistory = await client.getFeeHistory({
|
|
15
|
-
blockCount:
|
|
16
|
-
rewardPercentiles: [
|
|
44
|
+
blockCount: config.historyBlocks,
|
|
45
|
+
rewardPercentiles: [config.rewardPercentile],
|
|
17
46
|
});
|
|
18
|
-
const
|
|
47
|
+
const reward = feeHistory.reward?.at(-1)?.[0] ?? 0n;
|
|
48
|
+
const priorityFee = reward > config.tipFloorWei ? reward : config.tipFloorWei;
|
|
19
49
|
const baseFee = feeHistory.baseFeePerGas.at(-1) ?? 0n;
|
|
20
|
-
const maxFeePerGas = baseFee *
|
|
50
|
+
const maxFeePerGas = baseFee * config.baseFeeMultiplier + priorityFee;
|
|
21
51
|
return {
|
|
22
52
|
maxFeePerGas,
|
|
23
53
|
maxPriorityFeePerGas: priorityFee,
|