@valve-tech/gas-oracle 0.7.0 → 0.8.0
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/CHANGELOG.md +24 -0
- package/README.md +115 -16
- package/dist/block-position.d.ts +3 -3
- package/dist/block-position.d.ts.map +1 -1
- package/dist/block-position.js +27 -19
- package/dist/block-position.js.map +1 -1
- package/dist/classify-tip.d.ts +33 -0
- package/dist/classify-tip.d.ts.map +1 -0
- package/dist/classify-tip.js +52 -0
- package/dist/classify-tip.js.map +1 -0
- package/dist/inclusion-labels.d.ts +30 -0
- package/dist/inclusion-labels.d.ts.map +1 -0
- package/dist/inclusion-labels.js +35 -0
- package/dist/inclusion-labels.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/math.d.ts +1 -1
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +17 -17
- package/dist/math.js.map +1 -1
- package/dist/oracle.d.ts +2 -2
- package/dist/oracle.d.ts.map +1 -1
- package/dist/oracle.js +7 -6
- package/dist/oracle.js.map +1 -1
- package/dist/presets.d.ts +36 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/presets.js +27 -0
- package/dist/presets.js.map +1 -0
- package/dist/replacement.d.ts +80 -0
- package/dist/replacement.d.ts.map +1 -0
- package/dist/replacement.js +114 -0
- package/dist/replacement.js.map +1 -0
- package/dist/types.d.ts +49 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +57 -1
- package/dist/types.js.map +1 -1
- package/dist/viem-transport.d.ts +1 -1
- package/dist/viem-transport.d.ts.map +1 -1
- package/dist/viem-transport.js +11 -5
- package/dist/viem-transport.js.map +1 -1
- package/package.json +2 -2
- package/skills/gas-oracle-integration/SKILL.md +105 -12
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,KAAK;IACpB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,oBAAoB,EAAE,MAAM,CAAA;IAC5B,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;CAChC;AAED,MAAM,MAAM,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,KAAK;IACpB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cA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C,CAAA;IAC5C,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC"}
|
package/dist/types.js
CHANGED
|
@@ -7,5 +7,61 @@
|
|
|
7
7
|
* bigint values. The caller owns that encoding — this package keeps the
|
|
8
8
|
* canonical numeric form internally.
|
|
9
9
|
*/
|
|
10
|
-
export {
|
|
10
|
+
export const Trend = {
|
|
11
|
+
rising: 'rising',
|
|
12
|
+
falling: 'falling',
|
|
13
|
+
stable: 'stable',
|
|
14
|
+
};
|
|
15
|
+
export const TierName = {
|
|
16
|
+
slow: 'slow',
|
|
17
|
+
standard: 'standard',
|
|
18
|
+
fast: 'fast',
|
|
19
|
+
instant: 'instant',
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Canonical tier ordering, slow → instant. Used by helpers that walk the
|
|
23
|
+
* tier ladder (e.g., `classifyTip` finds the highest tier whose floor a
|
|
24
|
+
* tip clears; `recommendBumpTier` finds the cheapest tier that clears
|
|
25
|
+
* the protocol floor + outpace floor). Ordering is load-bearing.
|
|
26
|
+
*/
|
|
27
|
+
export const TIER_LADDER = [
|
|
28
|
+
TierName.slow,
|
|
29
|
+
TierName.standard,
|
|
30
|
+
TierName.fast,
|
|
31
|
+
TierName.instant,
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Where the chain's inclusion logic draws its priority cutoff in the
|
|
35
|
+
* tx-type space.
|
|
36
|
+
*
|
|
37
|
+
* - `'flat'` — chain ignores the EIP-2718 type byte for ordering.
|
|
38
|
+
* Tiers derive from a single gas-weighted distribution
|
|
39
|
+
* across all txs. Right for extractive validators
|
|
40
|
+
* (PulseChain et al.) where the only signal that matters
|
|
41
|
+
* is fee per gas, regardless of tx envelope.
|
|
42
|
+
* - `'eip1559'` — type 2+ txs get priority. Paying-lane tiers
|
|
43
|
+
* (standard/fast/instant) derive from type-2+ samples
|
|
44
|
+
* only; `slow` still draws from the full distribution
|
|
45
|
+
* so legacy senders find their lane. Right for chains
|
|
46
|
+
* that honor the 1559 fee-market shape.
|
|
47
|
+
*
|
|
48
|
+
* Future cutoffs can be added (e.g. `'eip4844'` for blob-only priority)
|
|
49
|
+
* without re-interpreting existing values.
|
|
50
|
+
*/
|
|
51
|
+
export const PriorityModel = {
|
|
52
|
+
flat: 'flat',
|
|
53
|
+
eip1559: 'eip1559',
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* EIP-2718 transaction type bytes. Identifier values — never participate
|
|
57
|
+
* in arithmetic, so they stay `number` per the package-wide bigint
|
|
58
|
+
* carve-out.
|
|
59
|
+
*/
|
|
60
|
+
export const TxType = {
|
|
61
|
+
legacy: 0,
|
|
62
|
+
eip2930: 1,
|
|
63
|
+
eip1559: 2,
|
|
64
|
+
blob: 3,
|
|
65
|
+
setCodeAuthorization: 4,
|
|
66
|
+
};
|
|
11
67
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA4CH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;CACR,CAAA;AAGV,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;CACV,CAAA;AAGV;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAwB;IAC9C,QAAQ,CAAC,IAAI;IACb,QAAQ,CAAC,QAAQ;IACjB,QAAQ,CAAC,IAAI;IACb,QAAQ,CAAC,OAAO;CACR,CAAA;AA2CV;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;CACV,CAAA;AAGV;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;IACP,oBAAoB,EAAE,CAAC;CACf,CAAA"}
|
package/dist/viem-transport.d.ts
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import { type Transport } from 'viem';
|
|
34
34
|
import { type CreateGasOracleOptions } from './oracle.js';
|
|
35
|
-
import
|
|
35
|
+
import { TierName } from './types.js';
|
|
36
36
|
export interface InterceptOptions {
|
|
37
37
|
/**
|
|
38
38
|
* Additive multi-tier read. Returns `{ baseFee, tiers: { slow, standard,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viem-transport.d.ts","sourceRoot":"","sources":["../src/viem-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,MAAM,CAAA;AAE7C,OAAO,EAAmB,KAAK,sBAAsB,EAAkB,MAAM,aAAa,CAAA;AAC1F,OAAO,
|
|
1
|
+
{"version":3,"file":"viem-transport.d.ts","sourceRoot":"","sources":["../src/viem-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,MAAM,CAAA;AAE7C,OAAO,EAAmB,KAAK,sBAAsB,EAAkB,MAAM,aAAa,CAAA;AAC1F,OAAO,EAAE,QAAQ,EAAwD,MAAM,YAAY,CAAA;AAE3F,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;IAC/B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;CAC5C;AAED,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC;IAClF;;;;OAIG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CAC7B;AAED,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG;IAAE,aAAa,EAAE,MAAM,IAAI,CAAA;CAAE,CAAA;AAmH1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GACxB,gBAAgB,SAAS,EACzB,SAAS,oBAAoB,KAC5B,kBAyCF,CAAA"}
|
package/dist/viem-transport.js
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import { custom } from 'viem';
|
|
34
34
|
import { createGasOracle } from './oracle.js';
|
|
35
|
+
import { TierName, TxType } from './types.js';
|
|
35
36
|
/**
|
|
36
37
|
* Sentinel returned by `dispatchIntercept` when no intercept matched
|
|
37
38
|
* and the request should be passed through to the inner transport.
|
|
@@ -40,23 +41,28 @@ import { createGasOracle } from './oracle.js';
|
|
|
40
41
|
*/
|
|
41
42
|
const PASSTHROUGH = Symbol('gas-oracle:passthrough');
|
|
42
43
|
const toHex = (n) => '0x' + n.toString(16);
|
|
43
|
-
const TIER_NAMES = [
|
|
44
|
+
const TIER_NAMES = [
|
|
45
|
+
TierName.instant,
|
|
46
|
+
TierName.fast,
|
|
47
|
+
TierName.standard,
|
|
48
|
+
TierName.slow,
|
|
49
|
+
];
|
|
44
50
|
/**
|
|
45
51
|
* Format a single tier for the `eth_gasFeeEstimate` response, scoped
|
|
46
52
|
* to the requested tx type. Mirrors the relay's `gas-intercept.ts`
|
|
47
53
|
* formatter so consumers of either surface get identical wire shapes.
|
|
48
54
|
*/
|
|
49
55
|
const formatTier = (tier, txType) => {
|
|
50
|
-
if (txType ===
|
|
56
|
+
if (txType === TxType.legacy || txType === TxType.eip2930) {
|
|
51
57
|
return { gasPrice: toHex(tier.gasPrice) };
|
|
52
58
|
}
|
|
53
|
-
if (txType ===
|
|
59
|
+
if (txType === TxType.eip1559 || txType === TxType.setCodeAuthorization) {
|
|
54
60
|
return {
|
|
55
61
|
maxFeePerGas: toHex(tier.maxFeePerGas),
|
|
56
62
|
maxPriorityFeePerGas: toHex(tier.maxPriorityFeePerGas),
|
|
57
63
|
};
|
|
58
64
|
}
|
|
59
|
-
if (txType ===
|
|
65
|
+
if (txType === TxType.blob) {
|
|
60
66
|
return {
|
|
61
67
|
maxFeePerGas: toHex(tier.maxFeePerGas),
|
|
62
68
|
maxPriorityFeePerGas: toHex(tier.maxPriorityFeePerGas),
|
|
@@ -85,7 +91,7 @@ const buildGasFeeEstimate = (state, params) => {
|
|
|
85
91
|
baseFeeTrend: state.baseFeeTrend,
|
|
86
92
|
blockNumber: toHex(state.blockNumber),
|
|
87
93
|
lastUpdated: toHex(state.timestamp),
|
|
88
|
-
mempoolPendingCount: state.mempool.pendingCount,
|
|
94
|
+
mempoolPendingCount: Number(state.mempool.pendingCount),
|
|
89
95
|
tiers,
|
|
90
96
|
};
|
|
91
97
|
if (state.blob)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viem-transport.js","sourceRoot":"","sources":["../src/viem-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAA;AAE7C,OAAO,EAAE,eAAe,EAA+C,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"viem-transport.js","sourceRoot":"","sources":["../src/viem-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,MAAM,EAAkB,MA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AW,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAW,CAAC,CAAA;QACnF,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AACvE,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valve-tech/gas-oracle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Multi-tier gas-fee oracle for EVM chains. Computes slow/standard/fast/instant tier recommendations from block-included tips, mempool pending tips, and base-fee trend, with a configurable downside-decay cap and a chain-aware EIP-1559 priority cutoff. viem-native — pass it a PublicClient and it does the rest. Ships viem-actions and viem-transport subpaths for drop-in client extension and transport-wrapping.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/valve-tech/evm-toolkit/tree/main/packages/gas-oracle#readme",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"prepare": "yarn build"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@valve-tech/chain-source": "^0.
|
|
62
|
+
"@valve-tech/chain-source": "^0.8.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"viem": "^2.0.0"
|
|
@@ -10,6 +10,8 @@ working in a project that imports the package — it grounds you in the
|
|
|
10
10
|
right configuration choices for the user's chain and the right
|
|
11
11
|
integration shape for their codebase.
|
|
12
12
|
|
|
13
|
+
> **v0.8.0 default change**: `priorityModel` now defaults to `PriorityModel.eip1559` (was `flat`). Examples that previously omitted the field silently get the new default. Set `PriorityModel.flat` explicitly for PulseChain (chain 369) — or use `...chainPresets.pulsechain`.
|
|
14
|
+
|
|
13
15
|
## Decision tree: which integration to use
|
|
14
16
|
|
|
15
17
|
```
|
|
@@ -30,13 +32,13 @@ Is the user already passing a viem PublicClient around?
|
|
|
30
32
|
|
|
31
33
|
| Chain | `chainId` | `priorityModel` | `baseFeeLivenessBlocks` | Notes |
|
|
32
34
|
|---|---|---|---|---|
|
|
33
|
-
| Ethereum mainnet | 1 | `
|
|
34
|
-
| Base | 8453 | `
|
|
35
|
-
| Arbitrum One | 42161 | `
|
|
36
|
-
| Optimism | 10 | `
|
|
37
|
-
| PulseChain mainnet | 369 | `
|
|
38
|
-
| PulseChain testnet v4 | 943 | `
|
|
39
|
-
| Unknown / unsure | — | `
|
|
35
|
+
| Ethereum mainnet | 1 | `PriorityModel.eip1559` (default) | 6 | Validators burn base fee. |
|
|
36
|
+
| Base | 8453 | `PriorityModel.eip1559` (default) | 6 | Same as ETH. |
|
|
37
|
+
| Arbitrum One | 42161 | `PriorityModel.eip1559` (default) | 6 | |
|
|
38
|
+
| Optimism | 10 | `PriorityModel.eip1559` (default) | 6 | |
|
|
39
|
+
| PulseChain mainnet | 369 | `PriorityModel.flat` | 6 | Validators charge tips. Use `...chainPresets.pulsechain`. |
|
|
40
|
+
| PulseChain testnet v4 | 943 | `PriorityModel.flat` | 6 | |
|
|
41
|
+
| Unknown / unsure | — | `PriorityModel.eip1559` (default) | 6 | Default is correct unless you've verified the chain is extractive. |
|
|
40
42
|
|
|
41
43
|
`priorityFeeDecayCap`: leave at default (`WAD/8` = 12.5%/block, EIP-1559
|
|
42
44
|
parity) unless you have a specific reason to tighten/loosen.
|
|
@@ -59,11 +61,12 @@ When reviewing user code, watch for these and suggest fixes:
|
|
|
59
61
|
be missing. Fix: `await oracle.pollOnce()` after `start()` to seed
|
|
60
62
|
state synchronously, then it's safe to call `getState()`.
|
|
61
63
|
|
|
62
|
-
4. **Using `
|
|
63
|
-
chains.**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
4. **Using `PriorityModel.eip1559` on PulseChain or other tip-charging
|
|
65
|
+
chains.** This is now the default — silent footgun on chain 369
|
|
66
|
+
unless you set `PriorityModel.flat` (or use `...chainPresets.pulsechain`).
|
|
67
|
+
It cuts the distribution to type-2+ samples only, but PulseChain
|
|
68
|
+
validators don't honor the type byte — they sort by tip regardless.
|
|
69
|
+
Result: under-published tier values, your tx loses to legacy spam.
|
|
67
70
|
|
|
68
71
|
5. **`keepMempoolSnapshot: true` on a chain whose RPC gates
|
|
69
72
|
`txpool_content`** (most public RPCs). Wastes a poll cycle's RPC
|
|
@@ -89,6 +92,96 @@ import { withGasOracle } from '@valve-tech/gas-oracle/viem-transport'
|
|
|
89
92
|
|
|
90
93
|
`package.json` will show `"@valve-tech/gas-oracle": "^0.2.x"` in dependencies.
|
|
91
94
|
|
|
95
|
+
## Replacement workflow — bumping a stuck tx
|
|
96
|
+
|
|
97
|
+
When the user has a stuck tx and asks how to bump / speed it up,
|
|
98
|
+
recommend the `recommendBumpTier` + `bumpForReplacement` pair. This is
|
|
99
|
+
the canonical caller pattern; don't roll your own +10% math:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import {
|
|
103
|
+
recommendBumpTier,
|
|
104
|
+
bumpForReplacement,
|
|
105
|
+
BumpStrategy,
|
|
106
|
+
} from '@valve-tech/gas-oracle'
|
|
107
|
+
|
|
108
|
+
const tier = recommendBumpTier(
|
|
109
|
+
state,
|
|
110
|
+
{ priorityTip: stuck.maxPriorityFeePerGas, identifier: { hash: stuck.hash } },
|
|
111
|
+
{ strategy: BumpStrategy.cheapestThatLands }, // default
|
|
112
|
+
)
|
|
113
|
+
if (tier === null) return // already paying above top tier — caller's call
|
|
114
|
+
|
|
115
|
+
const target = state.tiers[tier]
|
|
116
|
+
const gas = bumpForReplacement(
|
|
117
|
+
{ maxFeePerGas: stuck.maxFeePerGas, maxPriorityFeePerGas: stuck.maxPriorityFeePerGas },
|
|
118
|
+
{ maxFeePerGas: target.maxFeePerGas, maxPriorityFeePerGas: target.maxPriorityFeePerGas },
|
|
119
|
+
)
|
|
120
|
+
walletClient.sendTransaction({ ...stuck, ...gas })
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`recommendBumpTier` reads `state.mempoolSamples` to compute outpace
|
|
124
|
+
correction (when an `identifier` is supplied) on top of the EIP-1559
|
|
125
|
+
+10% protocol floor. `bumpForReplacement` returns a gas object that
|
|
126
|
+
satisfies BOTH the protocol floor and the target tier — never one or
|
|
127
|
+
the other.
|
|
128
|
+
|
|
129
|
+
## Tip classification
|
|
130
|
+
|
|
131
|
+
Inverse of `tipForBlockPosition`. Given a tip, ask "where would this
|
|
132
|
+
land?" instead of "what tip do I need to land here?":
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { classifyTip } from '@valve-tech/gas-oracle'
|
|
136
|
+
|
|
137
|
+
const result = classifyTip(state, myTip)
|
|
138
|
+
// result.tier — TierName | null (null if below slow)
|
|
139
|
+
// result.requiredForNextTier — bigint floor of next tier above (null at instant)
|
|
140
|
+
// result.percentile — bigint 0-100 (0 = top, 100 = bottom)
|
|
141
|
+
// result.rank — bigint 0-indexed from top
|
|
142
|
+
// result.gasFromTop — bigint accumulated gas above this tip
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Useful for "your fee is low — bump?" UX nudges and for showing a
|
|
146
|
+
user where their existing in-flight tx sits vs. live competition.
|
|
147
|
+
|
|
148
|
+
## UI labels
|
|
149
|
+
|
|
150
|
+
Branded / localized inclusion-time copy without forking the package:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { defaultInclusionLabels, inclusionLabel, TierName } from '@valve-tech/gas-oracle'
|
|
154
|
+
|
|
155
|
+
defaultInclusionLabels[TierName.standard] // 'Next block'
|
|
156
|
+
|
|
157
|
+
const es = { [TierName.standard]: 'Próximo bloque' }
|
|
158
|
+
inclusionLabel(TierName.standard, es) // 'Próximo bloque'
|
|
159
|
+
inclusionLabel(TierName.slow, es) // falls back to default English
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Pass partial overrides — anything not in the override map falls back
|
|
163
|
+
to the package default.
|
|
164
|
+
|
|
165
|
+
## Chain presets
|
|
166
|
+
|
|
167
|
+
For PulseChain (and any future entries we ship), use the preset entry
|
|
168
|
+
points instead of typing `chainId` + `priorityModel` by hand:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import { createGasOracle, chainPresets, presetForChainId } from '@valve-tech/gas-oracle'
|
|
172
|
+
|
|
173
|
+
// Static — caller knows which chain at code-time:
|
|
174
|
+
createGasOracle({ client, ...chainPresets.pulsechain })
|
|
175
|
+
|
|
176
|
+
// Dynamic — caller has chainId at runtime (e.g. from wallet):
|
|
177
|
+
const preset = presetForChainId(chainId)
|
|
178
|
+
createGasOracle({ client, chainId, ...preset })
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`presetForChainId` returns `undefined` for unknown chains; spreading
|
|
182
|
+
`undefined` into the options object is a no-op, so the call still works
|
|
183
|
+
on a chain we haven't preset (it just gets the package defaults).
|
|
184
|
+
|
|
92
185
|
## Where to find more
|
|
93
186
|
|
|
94
187
|
- Full API + types: `node_modules/@valve-tech/gas-oracle/AGENTS.md`
|