Skip to content

Commit 4248add

Browse files
committed
chore(dev-hub) Move Pyth lazer pages
1 parent 396393d commit 4248add

File tree

16 files changed

+715
-35
lines changed

16 files changed

+715
-35
lines changed

apps/developer-hub/content/docs/openapi/(generated)/index.mdx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ _openapi:
55
toc:
66
- depth: 2
77
title: Get the list of supported chain ids
8-
url: '#get-the-list-of-supported-chain-ids'
8+
url: "#get-the-list-of-supported-chain-ids"
99
- depth: 2
1010
title: Reveal the random value for a given sequence number and blockchain.
11-
url: '#reveal-the-random-value-for-a-given-sequence-number-and-blockchain'
11+
url: "#reveal-the-random-value-for-a-given-sequence-number-and-blockchain"
1212
- depth: 2
1313
title: Returns the logs of all requests captured by the keeper.
14-
url: '#returns-the-logs-of-all-requests-captured-by-the-keeper'
14+
url: "#returns-the-logs-of-all-requests-captured-by-the-keeper"
1515
structuredData:
1616
headings:
1717
- content: Get the list of supported chain ids
@@ -55,4 +55,13 @@ _openapi:
5555

5656
{/* This file was generated by Fumadocs. Do not edit this file directly. Any changes should be made by running the generation command again. */}
5757

58-
<APIPage document={"https://fortuna.dourolabs.app/docs/openapi.json"} operations={[{"path":"/v1/chains","method":"get"},{"path":"/v1/chains/{chain_id}/revelations/{sequence}","method":"get"},{"path":"/v1/logs","method":"get"}]} webhooks={[]} hasHead={true} />
58+
<APIPage
59+
document={"https://fortuna.dourolabs.app/docs/openapi.json"}
60+
operations={[
61+
{ path: "/v1/chains", method: "get" },
62+
{ path: "/v1/chains/{chain_id}/revelations/{sequence}", method: "get" },
63+
{ path: "/v1/logs", method: "get" },
64+
]}
65+
webhooks={[]}
66+
hasHead={true}
67+
/>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: "Acquire an Access Token"
3+
description: "This guide explains how to acquire an access token for Pyth Lazer, which is required to authenticate websocket connections and subscribe to price updates."
4+
full: false
5+
index: false
6+
---
7+
8+
This guide explains how to acquire an access token for Pyth Lazer, which is required to authenticate websocket connections and subscribe to price updates.
9+
10+
## Request Access Token
11+
12+
Please fill out [this form](https://tally.so/r/nP2lG5) to contact the Pyth team and get the access token.
13+
14+
<InfoBox variant="info">
15+
Access tokens are required for all Pyth Lazer websocket connections. Make sure
16+
to keep your token secure and do not share it publicly.
17+
</InfoBox>
18+
19+
## Using the Access Token
20+
21+
Once you receive your access token, use it to authenticate the websocket connection by passing it as an `Authorization` header with the value `Bearer {token}`.
22+
23+
### Example Usage
24+
25+
```js copy
26+
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
27+
28+
const client = await PythLazerClient.create(
29+
["wss://pyth-lazer.dourolabs.app/v1/stream"],
30+
"YOUR_ACCESS_TOKEN",
31+
);
32+
```
33+
34+
## Next Steps
35+
36+
After acquiring your access token, you can proceed to [subscribe to price updates](./subscribe-price-updates.mdx) using the Pyth Lazer websocket API.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: "Getting Started with Pyth Lazer"
3+
description: "Please refer to the how-to guides to get started."
4+
full: false
5+
index: false
6+
---
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: "Pyth Lazer"
3+
description: >-
4+
Pyth Lazer is a low latency, highly customizable price oracle.
5+
full: false
6+
index: true
7+
---
8+
9+
Pyth Lazer is a low latency, highly customizable price oracle.
10+
It offers a customizable set of price feeds, target chains (EVM or Solana) and channels (real time or fixed rate):
11+
12+
- Real time channels send updates as frequently as they become available;
13+
- Fixed rate channels send updates at fixed time intervals (you can choose between 50 ms or 200 ms).
14+
15+
The table below shows the difference between Pyth Core and Pyth Lazer:
16+
17+
| | **Pyth Core** | **Pyth Lazer** |
18+
| ----------------------- | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
19+
| **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. |
20+
| **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. |
21+
| **Data Types** | Aggregate price and confidence intervals. | Aggregate price, bid/ask price, and **customizable** market data (market depth and more). |
22+
| **Fees** | On-chain fee per signed cross-chain price update. | On-chain fee per signed cross-chain price update. |
23+
| **Update Costs** | >1,000-byte proofs and complex signature verification. | **100-byte proofs** and simple signature verification. |
24+
| **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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"title": "Integrate as a Consumer",
3+
"description": "Real-time data from financial institutions",
4+
"icon": "ChartLine",
5+
"pages": ["on-solana-and-fogo", "on-evm-chains"]
6+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
title: "On EVM chains"
3+
description: "This guide explains how to integrate Pyth Lazer into your EVM smart contracts."
4+
full: false
5+
index: false
6+
---
7+
8+
This guide is intended to serve users who wants to consume prices from the Pyth Lazer on **EVM chains**.
9+
10+
Integrating with Pyth Lazer in smart contracts as a consumer is a three-step process:
11+
12+
1. **Use** Pyth Lazer SDK in EVM smart contracts to parse the price updates.
13+
2. **Subscribe** to Pyth Lazer websocket to receive price updates on backend or frontend.
14+
3. **Include** the price updates into the smart contract transactions.
15+
16+
<Steps>
17+
18+
### Use Pyth Lazer SDK in smart contracts
19+
20+
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.
21+
22+
```bash copy
23+
forge install pyth-network/pyth-crosschain
24+
```
25+
26+
Add the following to `requirements.txt{:js}` file:
27+
28+
```bash copy
29+
pyth-lazer-sdk/=lib/pyth-network/pyth-crosschain/lazer/contracts/evm
30+
```
31+
32+
Once the SDK is installed, one can import the sdk into smart contracts:
33+
34+
```solidity copy
35+
import { PythLazer } from "pyth-lazer-sdk/PythLazer.sol";
36+
import { PythLazerLib } from "pyth-lazer-sdk/PythLazerLib.sol";
37+
38+
```
39+
40+
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:
41+
42+
```solidity copy
43+
contract ExampleConsumer {
44+
// Example state.
45+
PythLazer pythLazer;
46+
uint64 public price;
47+
uint64 public timestamp;
48+
49+
//...
50+
51+
constructor(address pythLazerAddress) {
52+
pythLazer = PythLazer(pythLazerAddress);
53+
}
54+
}
55+
56+
```
57+
58+
Add an argument of type `bytes calldata{:solidity}` to the method which will receive the Pyth Lazer price udpate:
59+
60+
```solidity copy
61+
function updatePrice(bytes calldata priceUpdate) public payable {
62+
uint256 verification_fee = pythLazer.verification_fee();
63+
(bytes calldata payload, ) = verifyUpdate{ value: verification_fee }(update);
64+
//...
65+
}
66+
67+
```
68+
69+
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.
70+
71+
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.
72+
73+
```solidity copy
74+
(uint64 _timestamp, Channel channel, uint8 feedsLen, uint16 pos) = parsePayloadHeader(payload);
75+
```
76+
77+
This method returns:
78+
79+
- `_timestamp`: The timestamp of the price update.
80+
- `channel`: The channel of the price update.
81+
- `feedsLen`: The number of feeds in the price update.
82+
- `pos`: The cursor position of the payload.
83+
84+
One can iterate over all the feeds and properties present within the price update, modifying the state variables as necessary.
85+
86+
Here is an example of how to iterate over the feeds and properties:
87+
88+
```solidity copy
89+
for (uint8 i = 0; i < feedsLen; i++) {
90+
uint32 feedId;
91+
uint8 num_properties;
92+
(feedId, num_properties, pos) = parseFeedHeader(payload, pos);
93+
for (uint8 j = 0; j < num_properties; j++) {
94+
PriceFeedProperty property;
95+
(property, pos) = parseFeedProperty(payload, pos);
96+
if (property == PriceFeedProperty.Price) {
97+
uint64 _price;
98+
(_price, pos) = parseFeedValueUint64(payload, pos);
99+
if (feedId == 2 && _timestamp > timestamp) {
100+
price = _price;
101+
timestamp = _timestamp;
102+
}
103+
} else if (property == PriceFeedProperty.BestBidPrice) {
104+
uint64 _price;
105+
(_price, pos) = parseFeedValueUint64(payload, pos);
106+
} else if (property == PriceFeedProperty.BestAskPrice) {
107+
uint64 _price;
108+
(_price, pos) = parseFeedValueUint64(payload, pos);
109+
} else {
110+
revert("unknown property");
111+
}
112+
}
113+
}
114+
```
115+
116+
<Callout type="warning" emoji="⚠️">
117+
Make sure to pass the `pos` variable to every parsing call and assign the
118+
returned `pos` value to the same variable. Failure to do so will cause
119+
incorrect parsing results.
120+
</Callout>
121+
122+
<Callout type="warning" emoji="⚠️">
123+
When calling these parse functions, you must not skip price feeds or
124+
properties. Every parsing function will modify your `pos` variable, so
125+
skipping a call of `parseFeedHeader`, `parseFeedProperty`, or
126+
`parseFeedValueUint64` will lead to incorrect parsing results. Keep in mind
127+
that you can customize the set of price feeds and properties when requesting
128+
price updates via WebSocket. This will be explained in the next step.
129+
</Callout>
130+
131+
### Subscribe to Pyth Lazer to receive Price Updates
132+
133+
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.
134+
135+
Consult [How to subscribe to price updates from Pyth Lazer](../subscribe-price-updates.mdx) for a complete step-by-step guide.
136+
137+
### Include the price updates into smart contract transactions
138+
139+
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.
140+
141+
</Steps>
142+
143+
## Additional Resources
144+
145+
You may find these additional resources helpful for integrating Pyth Lazer into your EVM smart contracts.
146+
147+
### Price Feed IDs
148+
149+
Pyth Lazer supports a wide range of price feeds. Consult the [Price Feed IDs](../price-feed-ids.mdx) page for a complete list of supported price feeds.
150+
151+
### Examples
152+
153+
[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.
154+
155+
[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.

0 commit comments

Comments
 (0)