|
| 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) |
0 commit comments