You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(lazer/evm): update example to use new PythLazerLib struct-based parsing
- Update ExampleReceiver.sol to use parseUpdateFromPayload() for high-level struct-based parsing
- Add helper function pattern for memory-to-calldata conversion
- Use safe getter functions (hasPrice, getPrice, etc.) for property extraction
- Add utility functions: getCurrentPrice(), getSpread(), isPriceFresh(), setTargetFeedId()
- Update tests to use TransparentUpgradeableProxy for PythLazer initialization
- Add comprehensive test cases for struct-based parsing, fee validation, and helper functions
- Update README with detailed documentation on contract architecture, tri-state property system, and integration guide
- Update pyth-crosschain submodule to include PythLazerStructs.sol
Co-Authored-By: [email protected] <[email protected]>
@@ -4,7 +4,9 @@ This directory contains Solidity smart contract examples demonstrating how to in
4
4
5
5
## What is Pyth Lazer?
6
6
7
-
Pyth Lazer is a high-performance, low-latency price feed service that provides real-time financial market data to blockchain applications. It supports multiple blockchain networks and offers both JSON and binary message formats for optimal performance.
7
+
Pyth Lazer is a high-performance, low-latency price feed protocol that provides real-time financial market data to blockchain applications. Unlike traditional pull-based oracles, Pyth Lazer uses ECDSA signatures for fast verification and delivers sub-second price updates via WebSocket streams.
8
+
9
+
Key features of Pyth Lazer include support for multiple blockchain networks, a tri-state property system that distinguishes between present values, applicable but missing values, and not applicable properties, and support for various price feed properties including price, confidence, bid/ask prices, funding rates, and market session information.
8
10
9
11
## Prerequisites
10
12
@@ -30,131 +32,195 @@ Before running these examples, make sure you have the following installed:
30
32
forge build
31
33
```
32
34
35
+
## Contract Architecture
36
+
37
+
The example uses three main components from the Pyth Lazer SDK:
38
+
39
+
**PythLazer.sol** is the main contract that verifies ECDSA signatures from trusted signers. It manages trusted signer keys with expiration times and collects verification fees for each update.
40
+
41
+
**PythLazerLib.sol** is a library that provides parsing functions for Lazer payloads. It includes both low-level parsing functions like `parsePayloadHeader()` and `parseFeedHeader()`, as well as a high-level `parseUpdateFromPayload()` function that returns a structured `Update` object.
42
+
43
+
**PythLazerStructs.sol** defines the data structures used by the library, including the `Update` struct containing timestamp, channel, and feeds array, the `Feed` struct with all price properties and a tri-state map, and enums for `Channel`, `PriceFeedProperty`, `PropertyState`, and `MarketSession`.
Pyth Lazer prices use a fixed-point representation:
78
-
```
79
-
actual_price = price × 10^exponent
80
-
```
101
+
Pyth Lazer prices use a fixed-point representation where the actual price equals the raw price multiplied by 10 raised to the power of the exponent.
81
102
82
103
**Example from the test:**
83
104
- Raw price: `100000000`
84
105
- Exponent: `-8`
85
106
- Actual price: `100000000 × 10^-8 = $1.00`
86
107
87
-
### Feed Properties
108
+
### Available Feed Properties
109
+
110
+
The `Feed` struct can contain the following properties, each with a tri-state indicating whether it's present, applicable but missing, or not applicable:
88
111
89
-
The contract can extract multiple price feed properties:
112
+
| Property | Type | Description |
113
+
|----------|------|-------------|
114
+
| Price | int64 | Main price value |
115
+
| BestBidPrice | int64 | Highest bid price in the market |
116
+
| BestAskPrice | int64 | Lowest ask price in the market |
2. Obtain feed IDs from the Pyth Lazer documentation or API
198
+
## Deployed Contract Addresses
199
+
200
+
For production deployments, use the official PythLazer contract addresses. You can find the latest addresses in the [Pyth Network documentation](https://docs.pyth.network/price-feeds/contract-addresses).
141
201
142
202
## Troubleshooting
143
203
144
204
### Common Issues
145
205
146
-
1.**Build Errors**: Make sure all dependencies are installed with `forge install`
206
+
**Build Errors**: Make sure all dependencies are installed with `forge install`. If you see missing file errors, try updating the pyth-crosschain submodule:
207
+
```bash
208
+
cd lib/pyth-crosschain && git fetch origin && git checkout origin/main
209
+
```
210
+
211
+
**InvalidInitialization Error in Tests**: The PythLazer contract uses OpenZeppelin's upgradeable pattern. Deploy it via a TransparentUpgradeableProxy as shown in the test file.
147
212
148
-
2.**Test Failures**: Ensure you're using a compatible Foundry version and all submodules are properly initialized
213
+
**Memory to Calldata Conversion**: The `parseUpdateFromPayload()` function expects calldata bytes, but `verifyUpdate()` returns memory bytes. Use the external helper pattern shown in the example to convert between them.
149
214
150
-
3.**Gas Issues**: The contract includes gas optimization for parsing multiple feed properties
215
+
**Gas Optimization**: For gas-sensitive applications, consider using the low-level parsing functions (`parsePayloadHeader`, `parseFeedHeader`, `parseFeedProperty`) to parse only the properties you need.
0 commit comments