@valve-tech/gas-oracle 0.2.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/LICENSE +21 -0
- package/README.md +270 -0
- package/dist/block-position.d.ts +97 -0
- package/dist/block-position.d.ts.map +1 -0
- package/dist/block-position.js +131 -0
- package/dist/block-position.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/math.d.ts +148 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +343 -0
- package/dist/math.js.map +1 -0
- package/dist/mempool.d.ts +89 -0
- package/dist/mempool.d.ts.map +1 -0
- package/dist/mempool.js +108 -0
- package/dist/mempool.js.map +1 -0
- package/dist/oracle.d.ts +139 -0
- package/dist/oracle.d.ts.map +1 -0
- package/dist/oracle.js +208 -0
- package/dist/oracle.js.map +1 -0
- package/dist/samples.d.ts +36 -0
- package/dist/samples.d.ts.map +1 -0
- package/dist/samples.js +107 -0
- package/dist/samples.js.map +1 -0
- package/dist/transport.d.ts +75 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +72 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +168 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/dist/viem-actions.d.ts +77 -0
- package/dist/viem-actions.d.ts.map +1 -0
- package/dist/viem-actions.js +118 -0
- package/dist/viem-actions.js.map +1 -0
- package/dist/viem-transport.d.ts +85 -0
- package/dist/viem-transport.d.ts.map +1 -0
- package/dist/viem-transport.js +165 -0
- package/dist/viem-transport.js.map +1 -0
- package/package.json +81 -0
- package/src/index.ts +84 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @valve-tech/gas-oracle/viem-transport — viem Transport wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Use when callers want viem's existing API to *just work better*
|
|
5
|
+
* without changing call-site code:
|
|
6
|
+
*
|
|
7
|
+
* const transport = withGasOracle(http(rpcUrl), {
|
|
8
|
+
* chainId: 1,
|
|
9
|
+
* priorityFeeDecayCap: parseEther('0.125'),
|
|
10
|
+
* priorityModel: 'eip1559',
|
|
11
|
+
* intercept: { eth_maxPriorityFeePerGas: 'fast' },
|
|
12
|
+
* })
|
|
13
|
+
* const client = createPublicClient({ chain: mainnet, transport })
|
|
14
|
+
*
|
|
15
|
+
* // Standard viem APIs now reach the oracle cache instead of upstream:
|
|
16
|
+
* await client.estimateMaxPriorityFeePerGas()
|
|
17
|
+
* await walletClient.sendTransaction({ ... }) // gas auto-fill is corrected
|
|
18
|
+
*
|
|
19
|
+
* Default `intercept` is `{ eth_gasFeeEstimate: true }` only — the
|
|
20
|
+
* additive method that returns the full tier shape. Standard methods
|
|
21
|
+
* (`eth_gasPrice`, `eth_maxPriorityFeePerGas`) pass through to upstream
|
|
22
|
+
* unless the caller opts in AND specifies which tier to map them to.
|
|
23
|
+
* Forcing the tier choice keeps the package out of the silently-pick-a-
|
|
24
|
+
* percentile foot-gun the relay's gas-intercept caught earlier (one
|
|
25
|
+
* customer's eth_gasPrice and another's eth_maxPriorityFeePerGas
|
|
26
|
+
* returning numbers 5x apart because each defaulted to a different
|
|
27
|
+
* percentile).
|
|
28
|
+
*
|
|
29
|
+
* `eth_feeHistory` is intentionally NOT in the intercept options.
|
|
30
|
+
* Synthesizing the historical-percentile array from oracle state is
|
|
31
|
+
* its own design problem; passthrough is the only honest answer in v0.2.
|
|
32
|
+
*/
|
|
33
|
+
import { custom } from 'viem';
|
|
34
|
+
import { createGasOracle } from './oracle.js';
|
|
35
|
+
/**
|
|
36
|
+
* Sentinel returned by `dispatchIntercept` when no intercept matched
|
|
37
|
+
* and the request should be passed through to the inner transport.
|
|
38
|
+
* Using a unique symbol avoids any chance of ambiguity with a real
|
|
39
|
+
* RPC result that happens to be `null` or `undefined`.
|
|
40
|
+
*/
|
|
41
|
+
const PASSTHROUGH = Symbol('gas-oracle:passthrough');
|
|
42
|
+
const toHex = (n) => '0x' + n.toString(16);
|
|
43
|
+
const TIER_NAMES = ['instant', 'fast', 'standard', 'slow'];
|
|
44
|
+
/**
|
|
45
|
+
* Format a single tier for the `eth_gasFeeEstimate` response, scoped
|
|
46
|
+
* to the requested tx type. Mirrors the relay's `gas-intercept.ts`
|
|
47
|
+
* formatter so consumers of either surface get identical wire shapes.
|
|
48
|
+
*/
|
|
49
|
+
const formatTier = (tier, txType) => {
|
|
50
|
+
if (txType === 0 || txType === 1) {
|
|
51
|
+
return { gasPrice: toHex(tier.gasPrice) };
|
|
52
|
+
}
|
|
53
|
+
if (txType === 2 || txType === 4) {
|
|
54
|
+
return {
|
|
55
|
+
maxFeePerGas: toHex(tier.maxFeePerGas),
|
|
56
|
+
maxPriorityFeePerGas: toHex(tier.maxPriorityFeePerGas),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (txType === 3) {
|
|
60
|
+
return {
|
|
61
|
+
maxFeePerGas: toHex(tier.maxFeePerGas),
|
|
62
|
+
maxPriorityFeePerGas: toHex(tier.maxPriorityFeePerGas),
|
|
63
|
+
maxFeePerBlobGas: toHex(tier.maxFeePerBlobGas ?? 0n),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// No type → include everything available
|
|
67
|
+
const out = {
|
|
68
|
+
gasPrice: toHex(tier.gasPrice),
|
|
69
|
+
maxFeePerGas: toHex(tier.maxFeePerGas),
|
|
70
|
+
maxPriorityFeePerGas: toHex(tier.maxPriorityFeePerGas),
|
|
71
|
+
};
|
|
72
|
+
if (tier.maxFeePerBlobGas !== null) {
|
|
73
|
+
out.maxFeePerBlobGas = toHex(tier.maxFeePerBlobGas);
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
};
|
|
77
|
+
const buildGasFeeEstimate = (state, params) => {
|
|
78
|
+
const txType = typeof params[0] === 'number' ? params[0] : undefined;
|
|
79
|
+
const tiers = {};
|
|
80
|
+
for (const name of TIER_NAMES) {
|
|
81
|
+
tiers[name] = formatTier(state.tiers[name], txType);
|
|
82
|
+
}
|
|
83
|
+
const out = {
|
|
84
|
+
baseFee: toHex(state.baseFee),
|
|
85
|
+
baseFeeTrend: state.baseFeeTrend,
|
|
86
|
+
blockNumber: toHex(state.blockNumber),
|
|
87
|
+
lastUpdated: toHex(state.timestamp),
|
|
88
|
+
mempoolPendingCount: state.mempool.pendingCount,
|
|
89
|
+
tiers,
|
|
90
|
+
};
|
|
91
|
+
if (state.blob)
|
|
92
|
+
out.blobBaseFee = toHex(state.blob.blobBaseFee);
|
|
93
|
+
return out;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Decide whether the requested method should be answered from oracle
|
|
97
|
+
* state or passed through. Returns the response value, or PASSTHROUGH
|
|
98
|
+
* when the method either isn't in the intercept config or the oracle
|
|
99
|
+
* has no state yet (cold-start fallback to upstream).
|
|
100
|
+
*/
|
|
101
|
+
const dispatchIntercept = async (args, oracle, intercept) => {
|
|
102
|
+
const params = args.params ?? [];
|
|
103
|
+
if (args.method === 'eth_gasFeeEstimate' && intercept.eth_gasFeeEstimate !== false) {
|
|
104
|
+
const state = oracle.getState() ?? (await oracle.pollOnce());
|
|
105
|
+
if (!state)
|
|
106
|
+
return PASSTHROUGH;
|
|
107
|
+
return buildGasFeeEstimate(state, params);
|
|
108
|
+
}
|
|
109
|
+
if (args.method === 'eth_gasPrice') {
|
|
110
|
+
const tier = intercept.eth_gasPrice;
|
|
111
|
+
if (tier === undefined || tier === false)
|
|
112
|
+
return PASSTHROUGH;
|
|
113
|
+
const state = oracle.getState() ?? (await oracle.pollOnce());
|
|
114
|
+
if (!state)
|
|
115
|
+
return PASSTHROUGH;
|
|
116
|
+
return toHex(state.tiers[tier].gasPrice);
|
|
117
|
+
}
|
|
118
|
+
if (args.method === 'eth_maxPriorityFeePerGas') {
|
|
119
|
+
const tier = intercept.eth_maxPriorityFeePerGas;
|
|
120
|
+
if (tier === undefined || tier === false)
|
|
121
|
+
return PASSTHROUGH;
|
|
122
|
+
const state = oracle.getState() ?? (await oracle.pollOnce());
|
|
123
|
+
if (!state)
|
|
124
|
+
return PASSTHROUGH;
|
|
125
|
+
return toHex(state.tiers[tier].maxPriorityFeePerGas);
|
|
126
|
+
}
|
|
127
|
+
return PASSTHROUGH;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Wrap an existing viem Transport with gas-oracle interception.
|
|
131
|
+
*
|
|
132
|
+
* The returned value is a Transport (drops into `createPublicClient({
|
|
133
|
+
* transport })` directly) plus a `stopGasOracle()` handle for shutdown
|
|
134
|
+
* hooks (HMR, test teardown). The oracle is constructed once per
|
|
135
|
+
* `withGasOracle` call — a single Transport instance is shared with
|
|
136
|
+
* the oracle's poll loop, so wrapping `http(url)` once produces one
|
|
137
|
+
* oracle and one stream of upstream RPC, regardless of how many
|
|
138
|
+
* clients consume the transport downstream.
|
|
139
|
+
*/
|
|
140
|
+
export const withGasOracle = (innerTransport, options) => {
|
|
141
|
+
const intercept = {
|
|
142
|
+
eth_gasFeeEstimate: true,
|
|
143
|
+
...options.intercept,
|
|
144
|
+
};
|
|
145
|
+
// Pull a TransportInstance for the oracle's own RPC fan-out. http() and
|
|
146
|
+
// most built-in transports don't require a chain config for request
|
|
147
|
+
// dispatch — chainId validation happens elsewhere.
|
|
148
|
+
const oracleInner = innerTransport({});
|
|
149
|
+
const oracleClient = { request: oracleInner.request };
|
|
150
|
+
const oracle = createGasOracle({ ...options, client: oracleClient });
|
|
151
|
+
if ((options.lifecycle ?? 'eager') === 'eager')
|
|
152
|
+
oracle.start();
|
|
153
|
+
const wrapped = custom({
|
|
154
|
+
request: async (args) => {
|
|
155
|
+
const result = await dispatchIntercept(args, oracle, intercept);
|
|
156
|
+
if (result !== PASSTHROUGH)
|
|
157
|
+
return result;
|
|
158
|
+
// Reuse the inner transport-instance the oracle already opened
|
|
159
|
+
// so we don't double-instantiate the http transport per client.
|
|
160
|
+
return oracleInner.request({ method: args.method, params: args.params });
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
return Object.assign(wrapped, { stopGasOracle: () => oracle.stop() });
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=viem-transport.js.map
|
|
@@ -0,0 +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;AAyC1F;;;;;GAKG;AACH,MAAM,WAAW,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAA;AAEpD,MAAM,KAAK,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;AAE1D,MAAM,UAAU,GAAe,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;AAEtE;;;;GAIG;AACH,MAAM,UAAU,GAAG,CACjB,IAAwB,EACxB,MAA0B,EACF,EAAE;IAC1B,IAAI,MAAM,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAA;IAC3C,CAAC;IACD,IAAI,MAAM,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;YACL,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC;YACtC,oBAAoB,EAAE,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC;SACvD,CAAA;IACH,CAAC;IACD,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO;YACL,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,C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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
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@valve-tech/gas-oracle",
|
|
3
|
+
"version": "0.2.0",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/valve-tech/gas-oracle#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/valve-tech/gas-oracle.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/valve-tech/gas-oracle/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"ethereum",
|
|
16
|
+
"evm",
|
|
17
|
+
"gas",
|
|
18
|
+
"gas-oracle",
|
|
19
|
+
"gas-price",
|
|
20
|
+
"eip-1559",
|
|
21
|
+
"fee-market",
|
|
22
|
+
"viem",
|
|
23
|
+
"mempool"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"packageManager": "yarn@4.14.1",
|
|
27
|
+
"main": "src/index.ts",
|
|
28
|
+
"types": "src/index.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./src/index.ts",
|
|
32
|
+
"import": "./src/index.ts"
|
|
33
|
+
},
|
|
34
|
+
"./viem-actions": {
|
|
35
|
+
"types": "./src/viem-actions.ts",
|
|
36
|
+
"import": "./src/viem-actions.ts"
|
|
37
|
+
},
|
|
38
|
+
"./viem-transport": {
|
|
39
|
+
"types": "./src/viem-transport.ts",
|
|
40
|
+
"import": "./src/viem-transport.ts"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"main": "dist/index.js",
|
|
45
|
+
"types": "dist/index.d.ts",
|
|
46
|
+
"exports": {
|
|
47
|
+
".": {
|
|
48
|
+
"types": "./dist/index.d.ts",
|
|
49
|
+
"import": "./dist/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./viem-actions": {
|
|
52
|
+
"types": "./dist/viem-actions.d.ts",
|
|
53
|
+
"import": "./dist/viem-actions.js"
|
|
54
|
+
},
|
|
55
|
+
"./viem-transport": {
|
|
56
|
+
"types": "./dist/viem-transport.d.ts",
|
|
57
|
+
"import": "./dist/viem-transport.js"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"files": [
|
|
62
|
+
"dist",
|
|
63
|
+
"README.md",
|
|
64
|
+
"LICENSE"
|
|
65
|
+
],
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsc -p .",
|
|
68
|
+
"typecheck": "tsc -p . --noEmit",
|
|
69
|
+
"test": "vitest run",
|
|
70
|
+
"test:watch": "vitest"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"viem": "^2.0.0"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@types/node": "^22.0.0",
|
|
77
|
+
"typescript": "^6.0.2",
|
|
78
|
+
"viem": "^2.21.0",
|
|
79
|
+
"vitest": "^4.1.4"
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @valve-tech/gas-oracle — public API.
|
|
3
|
+
*
|
|
4
|
+
* Multi-tier gas-fee oracle for EVM chains. Pass it a viem PublicClient
|
|
5
|
+
* and it polls block + mempool data, computes slow/standard/fast/instant
|
|
6
|
+
* tier recommendations, and exposes them via a sub-millisecond in-memory
|
|
7
|
+
* read. Includes EIP-1559-style 12.5%/block downside cap so quiet blocks
|
|
8
|
+
* don't drop the published number off a cliff, and EIP-4844 blob fee
|
|
9
|
+
* for chains that support it.
|
|
10
|
+
*
|
|
11
|
+
* Zero runtime dependencies. viem is the only peer dependency, used to
|
|
12
|
+
* issue the underlying RPC calls (`eth_feeHistory`,
|
|
13
|
+
* `eth_getBlockByNumber`, `txpool_content`).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
createGasOracle,
|
|
18
|
+
reducePollInputs,
|
|
19
|
+
type CreateGasOracleOptions,
|
|
20
|
+
type GasOracle,
|
|
21
|
+
} from './oracle.js'
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
effectiveTip,
|
|
25
|
+
computePercentiles,
|
|
26
|
+
detectTrend,
|
|
27
|
+
cappedTip,
|
|
28
|
+
computeTiers,
|
|
29
|
+
computeBlobBaseFee,
|
|
30
|
+
flattenTxPool,
|
|
31
|
+
gasWeightedPercentiles,
|
|
32
|
+
sortedTips,
|
|
33
|
+
DEFAULT_PRIORITY_FEE_DECAY_CAP,
|
|
34
|
+
DEFAULT_BASE_FEE_LIVENESS_BLOCKS,
|
|
35
|
+
} from './math.js'
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
blockToSample,
|
|
39
|
+
mempoolToSamples,
|
|
40
|
+
} from './samples.js'
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
fetchOracleInputs,
|
|
44
|
+
type FeeHistoryResult,
|
|
45
|
+
type BlockResult,
|
|
46
|
+
type TxPoolContent,
|
|
47
|
+
type OraclePollInputs,
|
|
48
|
+
} from './transport.js'
|
|
49
|
+
|
|
50
|
+
export type {
|
|
51
|
+
RawTx,
|
|
52
|
+
TipPercentiles,
|
|
53
|
+
TierRecommendation,
|
|
54
|
+
TierName,
|
|
55
|
+
Trend,
|
|
56
|
+
MempoolStats,
|
|
57
|
+
BlobStats,
|
|
58
|
+
BlockSample,
|
|
59
|
+
GasOracleState,
|
|
60
|
+
TipSample,
|
|
61
|
+
PriorityModel,
|
|
62
|
+
PollOptions,
|
|
63
|
+
} from './types.js'
|
|
64
|
+
|
|
65
|
+
// Mempool inspection
|
|
66
|
+
export {
|
|
67
|
+
normalizeMempool,
|
|
68
|
+
findByHash,
|
|
69
|
+
findByAddressNonce,
|
|
70
|
+
findInMempool,
|
|
71
|
+
} from './mempool.js'
|
|
72
|
+
export type {
|
|
73
|
+
NormalizedMempool,
|
|
74
|
+
TxIdentifier,
|
|
75
|
+
MempoolBucket,
|
|
76
|
+
MempoolHit,
|
|
77
|
+
} from './mempool.js'
|
|
78
|
+
|
|
79
|
+
// Block-position calculations
|
|
80
|
+
export { tipForBlockPosition } from './block-position.js'
|
|
81
|
+
export type {
|
|
82
|
+
BlockPositionQuery,
|
|
83
|
+
BlockPositionResult,
|
|
84
|
+
} from './block-position.js'
|