Skip to content

Commit b678762

Browse files
committed
update
1 parent d8d597e commit b678762

File tree

2 files changed

+53
-19
lines changed

2 files changed

+53
-19
lines changed

pages/lazer/fetch-price-updates.mdx

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

33
# How to Fetch Price Updates from Pyth Lazer
44

5-
Pyth Lazer provides a [websocket API (TODO: Prod)](https://pyth-lazer-staging.dourolabs.app/docs) to fetch price updates.
6-
5+
Pyth Lazer provides a [websocket API (TODO: Prod)](https://pyth-lazer-staging.dourolabs.app/docs) to fetch price updates.
76

87
This guide explains how to **fetch** price updates, explore various **properties** of these updates, and configure the channel for **update frequency**. (TODO: Rewrite maybe)
98

@@ -24,7 +23,6 @@ Please fill out [this form](https://tally.so/r/nP2lG5) to contact the Pyth team
2423

2524
Use the access token to authenticate the websocket connection as a `Bearer {token}{:bash}`.
2625

27-
2826
### 2. Adjust subscription parameters
2927

3028
One can configure the request/subscription parameters to customize the received price updates. A sample request is shown below:
@@ -39,6 +37,7 @@ One can configure the request/subscription parameters to customize the received
3937
channel: "fixed_rate@200ms",
4038
});
4139
```
40+
4241
Here:
4342

4443
- `subscriptionId` is an arbitrary numeric identifier one can choose for a subscription. It will eb returned back in response by the server. It doesn not affect the signed payload.
@@ -53,8 +52,8 @@ There are also a few other parameters one may use. Refer to the [API documentati
5352

5453
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.
5554

56-
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.
57-
It can be installed using the following command:
55+
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.
56+
It can be installed using the following command:
5857

5958
```bash
6059
npm install --save @pythnetwork/pyth-lazer-sdk
@@ -65,7 +64,10 @@ npm install --save @pythnetwork/pyth-lazer-sdk
6564
```js
6665
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
6766

68-
const client = new PythLazerClient("wss://pyth-lazer-staging.dourolabs.app/v1/stream", "ctoken1");
67+
const client = new PythLazerClient(
68+
"wss://pyth-lazer-staging.dourolabs.app/v1/stream",
69+
"ctoken1"
70+
);
6971
```
7072

7173
3. After the client is created, one can adjust the subscription parameters and subscribe to the price updates.
@@ -117,6 +119,4 @@ By default, price updates contain the `parsed` field that one can use to easily
117119
}
118120
```
119121

120-
121-
122-
</Steps>
122+
</Steps>

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

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,63 @@ This guide is intended to serve for users who wants to consume prices from the P
66

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

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

1313
<Steps>
1414

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

17-
Pyth Lazer provides a solidity SDK, which allows consumers to TODO:
17+
Pyth Lazer provides a solidity SDK, which allows consumers to parse the price updates.
1818

19-
```bash
19+
```bash copy
2020
forge install pythnet/pyth-crosschain
2121
```
2222

23-
TODO: requiremnts.txt
23+
Add the following to your `requirements.txt` file:
2424

25-
```bash
25+
```bash copy
2626
pyth-lazer-sdk/=lib/pythnet/pyth-crosschain/lazer/contracts/evm
2727
```
2828

29-
</Steps>
29+
Once the SDK is installed, one can import the sdk into your smart contracts:
30+
31+
```solidity copy
32+
import { PythLazer } from "pyth-lazer/PythLazer.sol";
33+
import { PythLazerLib } from "pyth-lazer/PythLazerLib.sol";
34+
35+
```
3036

31-
### Modify the smart contract to TODO:
37+
After importing the SDK, initialize the `PythLazer` contract and set up state varables to store prices and timestamps:
3238

33-
1. Import
34-
2. State Variables.
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` 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()` function and passed to the `verifyUpdate` call. This fee is used to cover the cost of verifying the price update.
67+
68+
</Steps>

0 commit comments

Comments
 (0)