Skip to content

Commit 8aeb8ca

Browse files
authored
Lazer doc updates (#569)
* lazer doc updates * fix a few more issues
1 parent 6633893 commit 8aeb8ca

File tree

3 files changed

+48
-46
lines changed

3 files changed

+48
-46
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ This guide is intended to serve users who wants to consume prices from the Pyth
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 EVM smart contracts to parse the price updates.
9+
1. **Use** Pyth Lazer SDK in 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

15-
### Use Pyth Lazer SDK into smart contracts
15+
### Use Pyth Lazer SDK in smart contracts
1616

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.
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
20-
forge install pythnet/pyth-crosschain
20+
forge install pyth-network/pyth-crosschain
2121
```
2222

2323
Add the following to `requirements.txt{:js}` file:
2424

2525
```bash copy
26-
pyth-lazer-sdk/=lib/pythnet/pyth-crosschain/lazer/contracts/evm
26+
pyth-lazer-sdk/=lib/pyth-network/pyth-crosschain/lazer/contracts/evm
2727
```
2828

2929
Once the SDK is installed, one can import the sdk into smart contracts:
3030

3131
```solidity copy
32-
import { PythLazer } from "pyth-lazer/PythLazer.sol";
33-
import { PythLazerLib } from "pyth-lazer/PythLazerLib.sol";
32+
import { PythLazer } from "pyth-lazer-sdk/PythLazer.sol";
33+
import { PythLazerLib } from "pyth-lazer-sdk/PythLazerLib.sol";
3434
3535
```
3636

@@ -127,7 +127,7 @@ for (uint8 i = 0; i < feedsLen; i++) {
127127

128128
### Subscribe to Pyth Lazer to receive Price Updates
129129

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.
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.
131131

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Integrating with Pyth Lazer in smart contracts as a consumer is a three-step pro
1212

1313
<Steps>
1414

15-
### Use Pyth Lazer SDK into smart contracts
15+
### Use Pyth Lazer SDK in smart contracts
1616

1717
Pyth Lazer provides a [Solana SDK](https://docs.rs/pyth-lazer-solana-contract/latest/pyth_lazer_solana_contract/), which allows consumers to parse and verify the price updates on Solana-compatible chains.
1818

@@ -174,7 +174,7 @@ if data.feeds.is_empty() || data.feeds[0].properties.is_empty() {
174174
}
175175
```
176176

177-
Now you can update the state accourding to the contract's logic.
177+
Now you can update the state according to the contract's logic:
178178

179179
```rust copy
180180
// Read the data PDA of our example contract.

pages/lazer/subscribe-price-updates.mdx

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

33
# How to Subscribe to Price Updates from Pyth Lazer
44

5-
This guide explains how to subscribe to price updates from Pyth Lazer. This guide will also explain various properties and channels that one can use to customize the price updates.
5+
This guide explains how to subscribe to price updates from Pyth Lazer. This guide will also explain various properties and configuration options to customize the price updates.
66

77
Subscribing to price updates is a three-step process:
88

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

1313
The websocket server is available at `wss://pyth-lazer.dourolabs.app/v1/stream{:bash}`.
@@ -20,11 +20,13 @@ Please fill out [this form](https://tally.so/r/nP2lG5) to contact the Pyth team
2020

2121
Use the access token to authenticate the websocket connection by passing it as an `Authorization{:bash}` header with the value `Bearer {token}{:bash}`.
2222

23-
### 2. Adjust subscription parameters
23+
### 2. Configure subscription parameters
2424

25-
One can configure the request/subscription parameters to customize the received price updates. A sample request is shown below:
25+
Lazer supports several request/subscription parameters to customize the received price updates.
26+
These parameters are configured by sending a subscription message to the webservice.
27+
A sample request (using the Lazer SDK client -- see step 3) is shown below:
2628

27-
```js
29+
```js copy
2830
client.send({
2931
type: "subscribe",
3032
subscriptionId: 1,
@@ -35,64 +37,64 @@ client.send({
3537
});
3638
```
3739

38-
Here:
40+
The most significant parameters are:
3941

40-
- `subscriptionId` is an arbitrary numeric identifier one can choose for a subscription. It will be returned back in response by the server. It doesn not affect the signed payload.
41-
- `priceFeedIds` is the list of price feeds one like to receive. Data for all price feeds will be present in the signed price updates generated. Refer to the [Price Feed IDs list](./price-feed-ids.mdx) for the supported price feeds.
42-
- `properties` is the list of properties one can request, such as **price**, **bestBidPrice**, **bestAskPrice**, etc.
43-
- `chains` is the list of chains for which one need a signed payload, such as **evm**, **solana**, etc.
44-
- `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.
42+
- `subscriptionId` is an arbitrary numeric identifier for a subscription. It will be returned back in response by the server. It does not affect the signed payload.
43+
- `priceFeedIds` is the list of price feeds to receive updates for. Data for all price feeds will be present in the signed price updates generated. Refer to the [Price Feed IDs list](./price-feed-ids.mdx) for the supported price feeds.
44+
- `properties` is the list of properties to retrieve, such as **price**, **bestBidPrice**, **bestAskPrice**, etc.
45+
- `chains` is the list of chains to receive a signed payload for, such as **evm**, **solana**, etc.
46+
- `channel` determines 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.
4547

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.
48+
There are also a few other configuration parameters -- see the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details.
49+
50+
Determine the most suitable values for your application -- they will be used in the next step.
4751

4852
### 3. Subscribe to the price updates
4953

50-
To subscribe to the price updates, one needs to send the request to the websocket server. The server will respond with a signed price update.
54+
To subscribe to the price updates, send a request to the websocket server. The server will respond with a signed price update.
5155

52-
1. Pyth Lazer provides a [SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to seamlessly integrate the websocket API into your application.
53-
It can be installed using the following command:
56+
1. Pyth Lazer provides an [SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to seamlessly integrate the websocket API into your application.
57+
Install it using the following command:
5458

55-
```bash
59+
```bash copy
5660
npm install --save @pythnetwork/pyth-lazer-sdk
5761
```
5862

59-
2. Then create a [`PythLazerClient`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/sdk/js/src/client.ts#L32) object using the URL and the access token requested from the Pyth team in the first step.
63+
2. Then create a [`PythLazerClient`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/sdk/js/src/client.ts#L32) object using the URL and the access token requested from the Pyth team in the first step:
6064

61-
```js
65+
```js copy
6266
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
6367

64-
const client = new PythLazerClient(
65-
"wss://pyth-lazer.dourolabs.app/v1/stream",
66-
"ctoken1"
68+
const client = await PythLazerClient.create(
69+
["wss://pyth-lazer.dourolabs.app/v1/stream"],
70+
"YOUR_ACCESS_TOKEN"
6771
);
6872
```
6973

70-
3. After the client is created, one can adjust the subscription parameters and subscribe to the price updates.
71-
72-
```js
73-
client.ws.addEventListener("open", () => {
74-
client.send({
75-
type: "subscribe",
76-
subscriptionId: 1,
77-
priceFeedIds: [1, 2],
78-
properties: ["price"],
79-
chains: ["solana"],
80-
channel: "fixed_rate@200ms",
81-
});
74+
3. After the client is created, subscribe to updates (using the configuration parameters from step 2):
75+
76+
```js copy
77+
client.subscribe({
78+
type: "subscribe",
79+
subscriptionId: 1,
80+
priceFeedIds: [1, 2],
81+
properties: ["price"],
82+
chains: ["solana"],
83+
channel: "fixed_rate@200ms",
8284
});
8385
```
8486

85-
4. One the connection is established, the server will start sending the price updates to the client.
87+
4. Once the connection is established, the server will start sending the price updates to the client:
8688

87-
```js
89+
```js copy
8890
client.addMessageListener((message) => {
8991
console.log(message);
9092
});
9193
```
9294

9395
By default, price updates contain the `parsed` field that one can use to easily interpret the price update in their backend or frontend, as well as `evm` and/or `solana` fields that contain data that one should include in the on-chain transaction:
9496

95-
```json
97+
```json copy
9698
{
9799
"type": "streamUpdated",
98100
"subscriptionId": 1,

0 commit comments

Comments
 (0)