Skip to content

Commit 011548e

Browse files
committed
update
1 parent 8b7335a commit 011548e

File tree

8 files changed

+210
-20
lines changed

8 files changed

+210
-20
lines changed

images/lazer/Pyth_Laser_table.png

159 KB
Loading

pages/lazer/fetch-price-updates.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Subscribing to price updates is a three-step process:
88

99
1. **Acquire** an access token.
1010
2. **Adjust** subscription parameters.
11-
3. **Subscribe** to the price updates via [websocket API](https://pyth-lazer-staging.dourolabs.app/docs).
11+
3. **Subscribe** to the price updates via [websocket API](https://pyth-lazer.dourolabs.app/docs).
1212

13-
The websocket server is available at `wss://pyth-lazer-staging.dourolabs.app/v1/stream{:bash}`.
13+
The websocket server is available at `wss://pyth-lazer.dourolabs.app/v1/stream{:bash}`.
1414

1515
<Steps>
1616

@@ -43,7 +43,7 @@ Here:
4343
- `chains` is the list of chains for which one need a signed payload, such as **evm**, **solana**, etc.
4444
- `channel` allows to configure the update rate: updates in the **real_time** channel are sent as frequently as possible, while **fixed_rate@200ms** and **fixed_rate@50ms** channels are updated at fixed rates.
4545

46-
There are also a few other parameters one may use. Refer to the [API documentation](https://pyth-lazer-staging.dourolabs.app/docs) for more details.
46+
There are also a few other parameters one may use. Refer to the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details.
4747

4848
### 3. Subscribe to the price updates
4949

@@ -62,7 +62,7 @@ npm install --save @pythnetwork/pyth-lazer-sdk
6262
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
6363

6464
const client = new PythLazerClient(
65-
"wss://pyth-lazer-staging.dourolabs.app/v1/stream",
65+
"wss://pyth-lazer.dourolabs.app/v1/stream",
6666
"ctoken1"
6767
);
6868
```

pages/lazer/index.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

pages/lazer/index.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Image from "next/image";
2+
3+
# Pyth Lazer
4+
5+
Pyth Lazer is a low latency, highly customizable price oracle.
6+
It offers a customizable set of price feeds, target chains (EVM or Solana) and channels (real time or fixed rate):
7+
8+
- Real time channels send updates as frequently as they become available;
9+
- Fixed rate channels send updates at fixed time intervals (you can choose between 50 ms or 200 ms).
10+
11+
The table below shows the difference between Pyth Core and Pyth Lazer:
12+
13+
| | **Pyth Core** | **Pyth Lazer** |
14+
| ----------------------- | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
15+
| **Solution Type** | Stable, secure, and decentralized price data source for a broad spectrum of DeFi or TradFi applications. | **Permissioned** service focused on **ultra-low-latency** price and market data for highly latency-sensitive users. |
16+
| **Frequency** | 400ms on Pythnet appchain with support for risk mitigation via Benchmarks and confidence intervals. | **1ms** (**real-time**), 50ms, and 200ms channels, **customizable** frequencies, and throttling support to address different needs. |
17+
| **Data Types** | Aggregate price and confidence intervals. | Aggregate price, bid/ask price, and **customizable** market data (market depth and more). |
18+
| **Fees** | On-chain fee per signed cross-chain price update. | On-chain fee per signed cross-chain price update. |
19+
| **Update Costs** | >1,000-byte proofs and complex signature verification. | **100-byte proofs** and simple signature verification. |
20+
| **Integration Process** | Open and permissionless integration for any Web3 or Web2 protocol. | **Specialized** and **permissioned** solution for protocols prioritizing performance over some elements of decentralization. |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"evm": "on EVM chains",
3-
"svm": "on SVM chains"
3+
"svm": "on Solana"
44
}

pages/lazer/integrate-as-consumer/evm.mdx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import { Callout, Tabs, Steps } from "nextra/components";
22

33
# Integrate Pyth Lazer as a Consumer on EVM chains
44

5-
This guide is intended to serve users who wants to consume prices from the Pyth Lazer on EVM chains.
5+
This guide is intended to serve users who wants to consume prices from the Pyth Lazer on **EVM chains**.
66

77
Integrating with Pyth Lazer in smart contracts as a consumer is a three-step process:
88

9-
1. **Use** Pyth Lazer SDK into smart contracts to parse the price updates.
9+
1. **Use** Pyth Lazer SDK into EVM smart contracts to parse the price updates.
1010
2. **Subscribe** to Pyth Lazer websocket to receive price updates on backend or frontend.
1111
3. **Include** the price updates into the smart contract transactions.
1212

1313
<Steps>
1414

1515
### Use Pyth Lazer SDK into smart contracts
1616

17-
Pyth Lazer provides a solidity SDK, which allows consumers to parse the price updates.
17+
Pyth Lazer provides a [solidity SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/contracts/evm), which allows consumers to parse the price updates.
1818

1919
```bash copy
2020
forge install pythnet/pyth-crosschain
@@ -34,7 +34,7 @@ import { PythLazerLib } from "pyth-lazer/PythLazerLib.sol";
3434
3535
```
3636

37-
After importing the SDK, initialize the `PythLazer` contract and set up state varables to store prices and timestamps:
37+
After importing the SDK, initialize the [`PythLazer`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/contracts/evm/src/PythLazer.sol#L7) contract and set up state varables to store prices and timestamps:
3838

3939
```solidity copy
4040
contract ExampleConsumer {
@@ -52,7 +52,7 @@ contract ExampleConsumer {
5252
5353
```
5454

55-
Add an argument of type `bytes calldata` to the method which will receive the Pyth Lazer price udpate:
55+
Add an argument of type `bytes calldata{:solidity}` to the method which will receive the Pyth Lazer price udpate:
5656

5757
```solidity copy
5858
function updatePrice(bytes calldata priceUpdate) public payable {
@@ -63,9 +63,9 @@ function updatePrice(bytes calldata priceUpdate) public payable {
6363
6464
```
6565

66-
The `verifyUpdate` function will verify the price update and return the payload and the verification fee. This call takes a fee which can be queried from `verification_fee()` function and passed to the `verifyUpdate` call. This fee is used to cover the cost of verifying the price update.
66+
The `verifyUpdate` function will verify the price update and return the payload and the verification fee. This call takes a fee which can be queried from [`verification_fee(){:solidity}`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/contracts/evm/src/PythLazer.sol#L9) function and passed to the `verifyUpdate` call. This fee is used to cover the cost of verifying the price update.
6767

68-
This SDK provides `parsePayloadHeader` method to retrieve the values from the payload header.
68+
This SDK provides [`parsePayloadHeader`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/contracts/evm/src/PythLazerLib.sol#L21) method to retrieve the values from the payload header.
6969

7070
```solidity copy
7171
(uint64 _timestamp, Channel channel, uint8 feedsLen, uint16 pos) = parsePayloadHeader(payload);
@@ -110,15 +110,30 @@ for (uint8 i = 0; i < feedsLen; i++) {
110110
}
111111
```
112112

113+
<Callout type="warning" emoji="⚠️">
114+
Make sure to pass the `pos` variable to every parsing call and assign the
115+
returned `pos` value to the same variable. Failure to do so will cause
116+
incorrect parsing results.
117+
</Callout>
118+
119+
<Callout type="warning" emoji="⚠️">
120+
When calling these parse functions, you must not skip price feeds or
121+
properties. Every parsing function will modify your `pos` variable, so
122+
skipping a call of `parseFeedHeader`, `parseFeedProperty`, or
123+
`parseFeedValueUint64` will lead to incorrect parsing results. Keep in mind
124+
that you can customize the set of price feeds and properties when requesting
125+
price updates via WebSocket. This will be explained in the next step.
126+
</Callout>
127+
113128
### Subscribe to Pyth Lazer to receive Price Updates
114129

115-
Pyth Lazer provides a websocket endpoint to receive price updates. Moreover, Pyth Lazer provides a typescript SDK to subscribe to the websocket endpoint.
130+
Pyth Lazer provides a websocket endpoint to receive price updates. Moreover, Pyth Lazer also provides a [typescript SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to subscribe to the websocket endpoint.
116131

117132
Consult [How to fetch price updates from Pyth Lazer](../fetch-price-updates.mdx) for a complete step-by-step guide.
118133

119134
### Include the price updates into smart contract transactions
120135

121-
Now that one have the price updates, and the smart contract is able to parse the price updates, one can include the price updates into the smart contract transactions by passing the price updates received from the websocket to the `updatePrice` method.
136+
Now that you have the price updates, and your smart contract is able to parse the price updates, you can include the price updates into the smart contract transactions by passing the price updates received from the previous step as an argument to the `updatePrice` method of your smart contract.
122137

123138
</Steps>
124139

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import { Callout, Tabs, Steps } from "nextra/components";
2+
3+
# Integrate Pyth Lazer as a Consumer on Solana
4+
5+
This guide is intended to serve users who wants to consume prices from the Pyth Lazer on **Solana**.
6+
7+
Integrating with Pyth Lazer in smart contracts as a consumer is a three-step process:
8+
9+
1. **Use** Pyth Lazer SDK into Solana smart contracts to parse the price updates.
10+
2. **Subscribe** to Pyth Lazer websocket to receive price updates on backend or frontend.
11+
3. **Include** the price updates into the smart contract transactions.
12+
13+
<Steps>
14+
15+
### Use Pyth Lazer SDK into smart contracts
16+
17+
Pyth Lazer provides a [solidity SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/contracts/evm), which allows consumers to parse the price updates.
18+
19+
```bash copy
20+
forge install pythnet/pyth-crosschain
21+
```
22+
23+
Add the following to `requirements.txt{:js}` file:
24+
25+
```bash copy
26+
pyth-lazer-sdk/=lib/pythnet/pyth-crosschain/lazer/contracts/evm
27+
```
28+
29+
Once the SDK is installed, one can import the sdk into smart contracts:
30+
31+
```solidity copy
32+
import { PythLazer } from "pyth-lazer/PythLazer.sol";
33+
import { PythLazerLib } from "pyth-lazer/PythLazerLib.sol";
34+
35+
```
36+
37+
After importing the SDK, initialize the [`PythLazer`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/contracts/evm/src/PythLazer.sol#L7) contract and set up state varables to store prices and timestamps:
38+
39+
```solidity copy
40+
contract ExampleConsumer {
41+
// Example state.
42+
PythLazer pythLazer;
43+
uint64 public price;
44+
uint64 public timestamp;
45+
46+
//...
47+
48+
constructor(address pythLazerAddress) {
49+
pythLazer = PythLazer(pythLazerAddress);
50+
}
51+
}
52+
53+
```
54+
55+
Add an argument of type `bytes calldata{:solidity}` to the method which will receive the Pyth Lazer price udpate:
56+
57+
```solidity copy
58+
function updatePrice(bytes calldata priceUpdate) public payable {
59+
uint256 verification_fee = pythLazer.verification_fee();
60+
(bytes calldata payload, ) = verifyUpdate{ value: verification_fee }(update);
61+
//...
62+
}
63+
64+
```
65+
66+
The `verifyUpdate` function will verify the price update and return the payload and the verification fee. This call takes a fee which can be queried from [`verification_fee(){:solidity}`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/contracts/evm/src/PythLazer.sol#L9) function and passed to the `verifyUpdate` call. This fee is used to cover the cost of verifying the price update.
67+
68+
This SDK provides [`parsePayloadHeader`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/contracts/evm/src/PythLazerLib.sol#L21) method to retrieve the values from the payload header.
69+
70+
```solidity copy
71+
(uint64 _timestamp, Channel channel, uint8 feedsLen, uint16 pos) = parsePayloadHeader(payload);
72+
```
73+
74+
This method returns:
75+
76+
- `_timestamp`: The timestamp of the price update.
77+
- `channel`: The channel of the price update.
78+
- `feedsLen`: The number of feeds in the price update.
79+
- `pos`: The cursor position of the payload.
80+
81+
One can iterate over all the feeds and properties present within the price update, modifying the state variables as necessary.
82+
83+
Here is an example of how to iterate over the feeds and properties:
84+
85+
```solidity copy
86+
for (uint8 i = 0; i < feedsLen; i++) {
87+
uint32 feedId;
88+
uint8 num_properties;
89+
(feedId, num_properties, pos) = parseFeedHeader(payload, pos);
90+
for (uint8 j = 0; j < num_properties; j++) {
91+
PriceFeedProperty property;
92+
(property, pos) = parseFeedProperty(payload, pos);
93+
if (property == PriceFeedProperty.Price) {
94+
uint64 _price;
95+
(_price, pos) = parseFeedValueUint64(payload, pos);
96+
if (feedId == 2 && _timestamp > timestamp) {
97+
price = _price;
98+
timestamp = _timestamp;
99+
}
100+
} else if (property == PriceFeedProperty.BestBidPrice) {
101+
uint64 _price;
102+
(_price, pos) = parseFeedValueUint64(payload, pos);
103+
} else if (property == PriceFeedProperty.BestAskPrice) {
104+
uint64 _price;
105+
(_price, pos) = parseFeedValueUint64(payload, pos);
106+
} else {
107+
revert("unknown property");
108+
}
109+
}
110+
}
111+
```
112+
113+
<Callout type="warning" emoji="⚠️">
114+
Make sure to pass the `pos` variable to every parsing call and assign the
115+
returned `pos` value to the same variable. Failure to do so will cause
116+
incorrect parsing results.
117+
</Callout>
118+
119+
<Callout type="warning" emoji="⚠️">
120+
When calling these parse functions, you must not skip price feeds or
121+
properties. Every parsing function will modify your `pos` variable, so
122+
skipping a call of `parseFeedHeader`, `parseFeedProperty`, or
123+
`parseFeedValueUint64` will lead to incorrect parsing results. Keep in mind
124+
that you can customize the set of price feeds and properties when requesting
125+
price updates via WebSocket. This will be explained in the next step.
126+
</Callout>
127+
128+
### Subscribe to Pyth Lazer to receive Price Updates
129+
130+
Pyth Lazer provides a websocket endpoint to receive price updates. Moreover, Pyth Lazer also provides a [typescript SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to subscribe to the websocket endpoint.
131+
132+
Consult [How to fetch price updates from Pyth Lazer](../fetch-price-updates.mdx) for a complete step-by-step guide.
133+
134+
### Include the price updates into smart contract transactions
135+
136+
Now that you have the price updates, and your smart contract is able to parse the price updates, you can include the price updates into the smart contract transactions by passing the price updates received from the previous step as an argument to the `updatePrice` method of your smart contract.
137+
138+
</Steps>
139+
140+
## Additional Resources
141+
142+
You may find these additional resources helpful for integrating Pyth Lazer into your EVM smart contracts.
143+
144+
### Price Feed IDs
145+
146+
Pyth Lazer supports a wide range of price feeds. Consult the [Price Feed IDs](../price-feeds.mdx) page for a complete list of supported price feeds.
147+
148+
### Examples
149+
150+
[Pyth-lazer-example-evm](https://github.com/pyth-network/pyth-examples/tree/main/lazer/evm) is a simple example contract that parses and consumes price updates from Pyth Lazer.
151+
152+
[pyth-lazer-example-js](https://github.com/pyth-network/pyth-examples/tree/main/lazer/js) is a simple example for subscribing to the Pyth Lazer websocket.
153+
154+
### API Reference
155+
156+
TODO:
157+
158+
### Error Codes
159+
160+
TODO: Add error codes for EVM.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# How to Integrate Pyth Lazer as a Publisher
22

3-
TODO: Fill this up.
3+
We are working on this guide. Please check back later or contact us here if you wish to publish data on Pyth Lazer.

0 commit comments

Comments
 (0)