diff --git a/pages/lazer/integrate-as-consumer/evm.mdx b/pages/lazer/integrate-as-consumer/evm.mdx index d2adcf84..6d3bf233 100644 --- a/pages/lazer/integrate-as-consumer/evm.mdx +++ b/pages/lazer/integrate-as-consumer/evm.mdx @@ -6,31 +6,31 @@ This guide is intended to serve users who wants to consume prices from the Pyth Integrating with Pyth Lazer in smart contracts as a consumer is a three-step process: -1. **Use** Pyth Lazer SDK into EVM smart contracts to parse the price updates. +1. **Use** Pyth Lazer SDK in EVM smart contracts to parse the price updates. 2. **Subscribe** to Pyth Lazer websocket to receive price updates on backend or frontend. 3. **Include** the price updates into the smart contract transactions. -### Use Pyth Lazer SDK into smart contracts +### Use Pyth Lazer SDK in smart contracts -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. +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. ```bash copy -forge install pythnet/pyth-crosschain +forge install pyth-network/pyth-crosschain ``` Add the following to `requirements.txt{:js}` file: ```bash copy -pyth-lazer-sdk/=lib/pythnet/pyth-crosschain/lazer/contracts/evm +pyth-lazer-sdk/=lib/pyth-network/pyth-crosschain/lazer/contracts/evm ``` Once the SDK is installed, one can import the sdk into smart contracts: ```solidity copy -import { PythLazer } from "pyth-lazer/PythLazer.sol"; -import { PythLazerLib } from "pyth-lazer/PythLazerLib.sol"; +import { PythLazer } from "pyth-lazer-sdk/PythLazer.sol"; +import { PythLazerLib } from "pyth-lazer-sdk/PythLazerLib.sol"; ``` @@ -127,7 +127,7 @@ for (uint8 i = 0; i < feedsLen; i++) { ### Subscribe to Pyth Lazer to receive Price Updates -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. +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. Consult [How to fetch price updates from Pyth Lazer](../fetch-price-updates.mdx) for a complete step-by-step guide. diff --git a/pages/lazer/integrate-as-consumer/svm.mdx b/pages/lazer/integrate-as-consumer/svm.mdx index a0658573..8e3d63e8 100644 --- a/pages/lazer/integrate-as-consumer/svm.mdx +++ b/pages/lazer/integrate-as-consumer/svm.mdx @@ -12,7 +12,7 @@ Integrating with Pyth Lazer in smart contracts as a consumer is a three-step pro -### Use Pyth Lazer SDK into smart contracts +### Use Pyth Lazer SDK in smart contracts 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. @@ -174,7 +174,7 @@ if data.feeds.is_empty() || data.feeds[0].properties.is_empty() { } ``` -Now you can update the state accourding to the contract's logic. +Now you can update the state according to the contract's logic: ```rust copy // Read the data PDA of our example contract. diff --git a/pages/lazer/subscribe-price-updates.mdx b/pages/lazer/subscribe-price-updates.mdx index 65632852..ca5fbe77 100644 --- a/pages/lazer/subscribe-price-updates.mdx +++ b/pages/lazer/subscribe-price-updates.mdx @@ -2,12 +2,12 @@ import { Callout, Steps } from "nextra/components"; # How to Subscribe to Price Updates from Pyth Lazer -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. +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. Subscribing to price updates is a three-step process: 1. **Acquire** an access token. -2. **Adjust** subscription parameters. +2. **Configure** subscription parameters. 3. **Subscribe** to the price updates via [websocket API](https://pyth-lazer.dourolabs.app/docs). 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 Use the access token to authenticate the websocket connection by passing it as an `Authorization{:bash}` header with the value `Bearer {token}{:bash}`. -### 2. Adjust subscription parameters +### 2. Configure subscription parameters -One can configure the request/subscription parameters to customize the received price updates. A sample request is shown below: +Lazer supports several request/subscription parameters to customize the received price updates. +These parameters are configured by sending a subscription message to the webservice. +A sample request (using the Lazer SDK client -- see step 3) is shown below: -```js +```js copy client.send({ type: "subscribe", subscriptionId: 1, @@ -35,56 +37,56 @@ client.send({ }); ``` -Here: +The most significant parameters are: -- `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. -- `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. -- `properties` is the list of properties one can request, such as **price**, **bestBidPrice**, **bestAskPrice**, etc. -- `chains` is the list of chains for which one need a signed payload, such as **evm**, **solana**, etc. -- `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. +- `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. +- `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. +- `properties` is the list of properties to retrieve, such as **price**, **bestBidPrice**, **bestAskPrice**, etc. +- `chains` is the list of chains to receive a signed payload for, such as **evm**, **solana**, etc. +- `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. -There are also a few other parameters one may use. Refer to the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details. +There are also a few other configuration parameters -- see the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details. + +Determine the most suitable values for your application -- they will be used in the next step. ### 3. Subscribe to the price updates -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. +To subscribe to the price updates, send a request to the websocket server. The server will respond with a signed price update. -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. - It can be installed using the following command: +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. + Install it using the following command: -```bash +```bash copy npm install --save @pythnetwork/pyth-lazer-sdk ``` -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. +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: -```js +```js copy import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk"; -const client = new PythLazerClient( - "wss://pyth-lazer.dourolabs.app/v1/stream", - "ctoken1" +const client = await PythLazerClient.create( + ["wss://pyth-lazer.dourolabs.app/v1/stream"], + "YOUR_ACCESS_TOKEN" ); ``` -3. After the client is created, one can adjust the subscription parameters and subscribe to the price updates. - -```js -client.ws.addEventListener("open", () => { - client.send({ - type: "subscribe", - subscriptionId: 1, - priceFeedIds: [1, 2], - properties: ["price"], - chains: ["solana"], - channel: "fixed_rate@200ms", - }); +3. After the client is created, subscribe to updates (using the configuration parameters from step 2): + +```js copy +client.subscribe({ + type: "subscribe", + subscriptionId: 1, + priceFeedIds: [1, 2], + properties: ["price"], + chains: ["solana"], + channel: "fixed_rate@200ms", }); ``` -4. One the connection is established, the server will start sending the price updates to the client. +4. Once the connection is established, the server will start sending the price updates to the client: -```js +```js copy client.addMessageListener((message) => { console.log(message); }); @@ -92,7 +94,7 @@ client.addMessageListener((message) => { 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: -```json +```json copy { "type": "streamUpdated", "subscriptionId": 1,