Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
270 changes: 249 additions & 21 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions target_chains/ethereum/sdk/js/README_TRANSACTION_FILLER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Transaction Filler

The Transaction Filler is a utility that automatically detects Pyth price feed usage in Ethereum transactions and bundles them with the necessary price updates.

## Features

- Automatically detects Pyth `getPrice*` method calls using transaction tracing
- Fetches latest price updates from Hermes price service
- Bundles price updates with original transaction using multicall
- Iterative approach to handle nested price feed dependencies
- Supports both `trace_call` and `debug_traceCall` methods

## Usage

```typescript
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
import { fillTransactionWithPythData } from "@pythnetwork/pyth-evm-js";

const client = createPublicClient({
chain: mainnet,
transport: http("https://eth.drpc.org"),
});

const config = {
pythContractAddress: "0x4305FB66699C3B2702D4d05CF36551390A4c69C6",
priceServiceEndpoint: "https://hermes.pyth.network",
viemClient: client,
};

const transaction = {
to: "0xe0a80d35bB6618CBA260120b279d357978c42BCE",
data: "0xa824bf67000000000000000000000000c1d023141ad6935f81e5286e577768b75c9ff8e90000000000000000000000000000000000000000000000000000000000000001",
};

const result = await fillTransactionWithPythData(config, transaction);
console.log("Detected price feeds:", result.detectedPriceFeeds);
console.log("Final transaction:", result.transaction);
```

## Detected Methods

The following Pyth methods are automatically detected:
- `getPrice(bytes32 id)`
- `getPriceUnsafe(bytes32 id)`
- `getPriceNoOlderThan(bytes32 id, uint256 age)`
- `getEmaPrice(bytes32 id)`
- `getEmaPriceUnsafe(bytes32 id)`
- `getEmaPriceNoOlderThan(bytes32 id, uint256 age)`

## Configuration

- `pythContractAddress`: Address of the Pyth contract on the target chain
- `priceServiceEndpoint`: URL of the Hermes price service
- `viemClient`: Viem public client for blockchain interactions
- `maxIterations`: Maximum number of iterations for detecting nested dependencies (default: 5)
6 changes: 4 additions & 2 deletions target_chains/ethereum/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-evm-js",
"version": "1.83.0",
"version": "1.84.0",
"description": "Pyth Network EVM Utils in JS",
"homepage": "https://pyth.network",
"author": {
Expand All @@ -24,6 +24,7 @@
"example-client": "pnpm run build && node lib/examples/EvmPriceServiceClient.js",
"example-relay": "pnpm run build && node lib/examples/EvmRelay.js",
"example-benchmark": "pnpm run build && node lib/examples/EvmBenchmark.js",
"example-transaction-filler": "pnpm run build && node -e \"require('./lib/examples/TransactionFillerExample.js').main()\"",
"test:format": "prettier --check \"src/**/*.ts\"",
"test:lint": "eslint src/ --max-warnings 0",
"fix:format": "prettier --write \"src/**/*.ts\"",
Expand Down Expand Up @@ -57,6 +58,7 @@
},
"dependencies": {
"@pythnetwork/price-service-client": "workspace:*",
"buffer": "^6.0.3"
"buffer": "^6.0.3",
"viem": "^2.21.0"
}
}
Loading
Loading