Skip to content

Commit 38b4a99

Browse files
feat(pyth-evm-js): add transaction filler for automatic Pyth price data bundling
- Add TransactionFiller class and fillTransactionWithPythData function - Support automatic detection of Pyth getPrice* method calls via transaction tracing - Extract price feed IDs from trace results and fetch updates from Hermes - Bundle price updates with original transaction using multicall - Iterative approach to handle nested price feed dependencies - Include comprehensive example and documentation - Bump package version to 1.84.0 Co-Authored-By: Ali <[email protected]>
1 parent 98180a0 commit 38b4a99

File tree

5 files changed

+545
-2
lines changed

5 files changed

+545
-2
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Transaction Filler
2+
3+
The Transaction Filler is a utility that automatically detects Pyth price feed usage in Ethereum transactions and bundles them with the necessary price updates.
4+
5+
## Features
6+
7+
- Automatically detects Pyth `getPrice*` method calls using transaction tracing
8+
- Fetches latest price updates from Hermes price service
9+
- Bundles price updates with original transaction using multicall
10+
- Iterative approach to handle nested price feed dependencies
11+
- Supports both `trace_call` and `debug_traceCall` methods
12+
13+
## Usage
14+
15+
```typescript
16+
import { createPublicClient, http } from "viem";
17+
import { mainnet } from "viem/chains";
18+
import { fillTransactionWithPythData } from "@pythnetwork/pyth-evm-js";
19+
20+
const client = createPublicClient({
21+
chain: mainnet,
22+
transport: http("https://eth.drpc.org"),
23+
});
24+
25+
const config = {
26+
pythContractAddress: "0x4305FB66699C3B2702D4d05CF36551390A4c69C6",
27+
priceServiceEndpoint: "https://hermes.pyth.network",
28+
viemClient: client,
29+
};
30+
31+
const transaction = {
32+
to: "0xe0a80d35bB6618CBA260120b279d357978c42BCE",
33+
data: "0xa824bf67000000000000000000000000c1d023141ad6935f81e5286e577768b75c9ff8e90000000000000000000000000000000000000000000000000000000000000001",
34+
};
35+
36+
const result = await fillTransactionWithPythData(config, transaction);
37+
console.log("Detected price feeds:", result.detectedPriceFeeds);
38+
console.log("Final transaction:", result.transaction);
39+
```
40+
41+
## Detected Methods
42+
43+
The following Pyth methods are automatically detected:
44+
- `getPrice(bytes32 id)`
45+
- `getPriceUnsafe(bytes32 id)`
46+
- `getPriceNoOlderThan(bytes32 id, uint256 age)`
47+
- `getEmaPrice(bytes32 id)`
48+
- `getEmaPriceUnsafe(bytes32 id)`
49+
- `getEmaPriceNoOlderThan(bytes32 id, uint256 age)`
50+
51+
## Configuration
52+
53+
- `pythContractAddress`: Address of the Pyth contract on the target chain
54+
- `priceServiceEndpoint`: URL of the Hermes price service
55+
- `viemClient`: Viem public client for blockchain interactions
56+
- `maxIterations`: Maximum number of iterations for detecting nested dependencies (default: 5)

target_chains/ethereum/sdk/js/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-evm-js",
3-
"version": "1.83.0",
3+
"version": "1.84.0",
44
"description": "Pyth Network EVM Utils in JS",
55
"homepage": "https://pyth.network",
66
"author": {
@@ -24,6 +24,7 @@
2424
"example-client": "pnpm run build && node lib/examples/EvmPriceServiceClient.js",
2525
"example-relay": "pnpm run build && node lib/examples/EvmRelay.js",
2626
"example-benchmark": "pnpm run build && node lib/examples/EvmBenchmark.js",
27+
"example-transaction-filler": "pnpm run build && node -e \"require('./lib/examples/TransactionFillerExample.js').main()\"",
2728
"test:format": "prettier --check \"src/**/*.ts\"",
2829
"test:lint": "eslint src/ --max-warnings 0",
2930
"fix:format": "prettier --write \"src/**/*.ts\"",
@@ -57,6 +58,7 @@
5758
},
5859
"dependencies": {
5960
"@pythnetwork/price-service-client": "workspace:*",
60-
"buffer": "^6.0.3"
61+
"buffer": "^6.0.3",
62+
"viem": "^2.21.0"
6163
}
6264
}

0 commit comments

Comments
 (0)