@rhinestone/service-sdk 0.2.10 → 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 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
- type FeeEstimationClient = Pick<PublicClient, 'estimateFeesPerGas' | 'getFeeHistory'>;
3
- export declare function estimateGasFees(client: FeeEstimationClient, chainId: number): Promise<FeeValuesEIP1559>;
4
- export {};
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
@@ -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;AAa1D,KAAK,mBAAmB,GAAG,IAAI,CAC7B,YAAY,EACZ,oBAAoB,GAAG,eAAe,CACvC,CAAA;AA0GD,wBAAsB,eAAe,CACnC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,gBAAgB,CAAC,CAU3B"}
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
@@ -73,7 +73,27 @@ const TIP_FLOOR_WEI = {
73
73
  const WINDOWED_TIP_CHAINS = new Set([chains_1.polygon.id, chains_1.base.id]);
74
74
  const WINDOWED_TIP_HISTORY_BLOCKS = 20;
75
75
  const WINDOWED_TIP_PERCENTILE = 50; // p50 per block, nearest-rank across the window
76
- async function estimateGasFees(client, chainId) {
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
+ }
77
97
  if (HISTORICAL_FEE_CHAINS.has(chainId)) {
78
98
  const config = { ...DEFAULT_FEE_CONFIG, ...FEE_CONFIG_OVERRIDES[chainId] };
79
99
  return estimateFeeHistoryGasFees(client, config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinestone/service-sdk",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "Shared SDK for Rhinestone services",
5
5
  "author": {
6
6
  "name": "Rhinestone",