@rhinestone/service-sdk 0.2.9 → 0.2.11
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 +22 -1
- package/dist/chains.d.ts +25 -3
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +22 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
# service-sdk
|
|
1
|
+
# service-sdk
|
|
2
|
+
|
|
3
|
+
## Gas fee estimation
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { estimateGasFees } from '@rhinestone/service-sdk/chains'
|
|
7
|
+
|
|
8
|
+
const fees = await estimateGasFees(client, chainId)
|
|
9
|
+
const legacyFees = await estimateGasFees(client, chainId, { mode: 'legacy' })
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
With no options, `estimateGasFees` retains its chain-aware fee estimation
|
|
13
|
+
behavior. Legacy mode takes precedence over all chain-specific logic and calls
|
|
14
|
+
`client.estimateFeesPerGas({ type: 'legacy' })` without requesting fee history.
|
|
15
|
+
|
|
16
|
+
The return type remains EIP-1559-shaped in both modes. Legacy `gasPrice` is
|
|
17
|
+
normalized to
|
|
18
|
+
`{ maxFeePerGas: gasPrice, maxPriorityFeePerGas: gasPrice }`. Equal caps
|
|
19
|
+
preserve the legacy effective-price ceiling when the result is used as EIP-1559
|
|
20
|
+
fees. On a no-priority local fork where `baseFee == gasPrice`, the max-fee cap
|
|
21
|
+
means the actual paid tip is still zero. The mode selects the estimation source
|
|
22
|
+
only; it does not select or modify a transaction type.
|
package/dist/chains.d.ts
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import type { FeeValuesEIP1559, PublicClient } from 'viem';
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
2
|
+
/** Client methods required to estimate gas fees. */
|
|
3
|
+
export type FeeEstimationClient = Pick<PublicClient, 'estimateFeesPerGas' | 'getFeeHistory'>;
|
|
4
|
+
/** Options for {@link estimateGasFees}. */
|
|
5
|
+
export type EstimateGasFeesOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Uses the RPC's legacy gas-price estimate when set to `legacy`.
|
|
8
|
+
*
|
|
9
|
+
* The legacy price is returned as equal EIP-1559 fee caps, preserving it as
|
|
10
|
+
* the effective-price ceiling for EIP-1559 consumers.
|
|
11
|
+
*
|
|
12
|
+
* Omit this option to retain the chain-aware EIP-1559 estimation strategy.
|
|
13
|
+
*/
|
|
14
|
+
mode?: 'legacy';
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Estimates gas fees for a chain and returns EIP-1559-shaped fee values.
|
|
18
|
+
*
|
|
19
|
+
* Pass `{ mode: 'legacy' }` to source the estimate from the RPC's legacy gas
|
|
20
|
+
* price. The price is used for both EIP-1559 fee caps so it remains the
|
|
21
|
+
* effective-price ceiling. On a no-priority local fork where the base fee
|
|
22
|
+
* equals the gas price, the max-fee cap still limits the actual paid tip to
|
|
23
|
+
* zero. This changes fee estimation only; it does not select a transaction
|
|
24
|
+
* type.
|
|
25
|
+
*/
|
|
26
|
+
export declare function estimateGasFees(client: FeeEstimationClient, chainId: number, options?: EstimateGasFeesOptions): Promise<FeeValuesEIP1559>;
|
|
5
27
|
//# sourceMappingURL=chains.d.ts.map
|
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,
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAmB,YAAY,EAAE,MAAM,MAAM,CAAA;AAa3E,oDAAoD;AACpD,MAAM,MAAM,mBAAmB,GAAG,IAAI,CACpC,YAAY,EACZ,oBAAoB,GAAG,eAAe,CACvC,CAAA;AAED,2CAA2C;AAC3C,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,CAAA;AA8GD;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAsB3B"}
|
package/dist/chains.js
CHANGED
|
@@ -59,6 +59,7 @@ const FEE_CONFIG_OVERRIDES = {
|
|
|
59
59
|
// RHI-4468 audit and subsequent fill-tracker probes; each entry dated).
|
|
60
60
|
const TIP_FLOOR_WEI = {
|
|
61
61
|
[chains_1.base.id]: 3000000n, // 0.003 gwei — oracle ~0.001 (network ~p25); real fills ~0.003-0.0036 (probed 2026-07-08)
|
|
62
|
+
[chains_1.bsc.id]: 50000000n, // 0.05 gwei — post-Maxwell chain-min; oracle intermittently returns 0 through some upstreams, and with BSC's zero base fee that zeroes the ENTIRE bid (probed 2026-07-13)
|
|
62
63
|
[chains_1.polygon.id]: 45000000000n, // 45 gwei — Bor min 30 gwei x1.5; real p50 tip ~200 gwei
|
|
63
64
|
[chains_1.gnosis.id]: 1000000000n, // 1.0 gwei — viem oracle ~21 wei; real p90 inclusion ~1.0 gwei (re-probed 2026-06-25)
|
|
64
65
|
[chains_1.hyperEvm.id]: 150000000n, // 0.15 gwei — oracle returns 0; realized p50 tip ~0.15 gwei
|
|
@@ -72,7 +73,27 @@ const TIP_FLOOR_WEI = {
|
|
|
72
73
|
const WINDOWED_TIP_CHAINS = new Set([chains_1.polygon.id, chains_1.base.id]);
|
|
73
74
|
const WINDOWED_TIP_HISTORY_BLOCKS = 20;
|
|
74
75
|
const WINDOWED_TIP_PERCENTILE = 50; // p50 per block, nearest-rank across the window
|
|
75
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Estimates gas fees for a chain and returns EIP-1559-shaped fee values.
|
|
78
|
+
*
|
|
79
|
+
* Pass `{ mode: 'legacy' }` to source the estimate from the RPC's legacy gas
|
|
80
|
+
* price. The price is used for both EIP-1559 fee caps so it remains the
|
|
81
|
+
* effective-price ceiling. On a no-priority local fork where the base fee
|
|
82
|
+
* equals the gas price, the max-fee cap still limits the actual paid tip to
|
|
83
|
+
* zero. This changes fee estimation only; it does not select a transaction
|
|
84
|
+
* type.
|
|
85
|
+
*/
|
|
86
|
+
async function estimateGasFees(client, chainId, options) {
|
|
87
|
+
if (options?.mode === 'legacy') {
|
|
88
|
+
const legacyClient = client;
|
|
89
|
+
const { gasPrice } = await legacyClient.estimateFeesPerGas({
|
|
90
|
+
type: 'legacy',
|
|
91
|
+
});
|
|
92
|
+
// Equal caps preserve gasPrice as the effective-price ceiling. If a
|
|
93
|
+
// no-priority local fork reports baseFee == gasPrice, the max-fee cap means
|
|
94
|
+
// the actual paid tip remains zero despite this priority-fee allowance.
|
|
95
|
+
return { maxFeePerGas: gasPrice, maxPriorityFeePerGas: gasPrice };
|
|
96
|
+
}
|
|
76
97
|
if (HISTORICAL_FEE_CHAINS.has(chainId)) {
|
|
77
98
|
const config = { ...DEFAULT_FEE_CONFIG, ...FEE_CONFIG_OVERRIDES[chainId] };
|
|
78
99
|
return estimateFeeHistoryGasFees(client, config);
|