|
1 |
| -# Solana program for receiving price VAA from Pythnet |
2 |
| - |
3 |
| -The program under `cli` receives a VAA string from the shell, verifies the VAA with wormhole, posts the VAA on solana and then invokes the receiver program under `programs`. |
4 |
| -The receiver program verifies that the VAA comes from wormhole (through the `owner` function in `state.rs`) and deserializes the price information (in `decode_posted_vaa` function of `lib.rs`). |
5 |
| - |
6 |
| -```shell |
7 |
| -# Generate the program key |
8 |
| -# and use the key to replace the following two places |
9 |
| -# "pyth-solana-receiver" in Anchor.toml |
10 |
| -# "declare_id!()" in programs/pyth-solana-receiver/src/lib.rs |
11 |
| -> solana-keygen new -o program_address.json |
12 |
| - |
13 |
| -# Build and deploy the receiver program |
14 |
| - > anchor build -- features devnet # use --features mainnet for mainnet |
15 |
| -> anchor run deploy |
16 |
| - |
17 |
| -# Build and test the cli program |
18 |
| -> anchor run cli_build_devnet |
19 |
| -> anchor run cli_test_devnet |
20 |
| -# Example output |
21 |
| -... |
22 |
| -[1/5] Decode the VAA |
23 |
| -[2/5] Get wormhole guardian set configuration |
24 |
| -[3/5] Invoke wormhole on solana to verify the VAA |
25 |
| -Transaction successful : 3VbrqQBCf1RsNLxrcvxN3aTb5fZRht4n8XDUVPM8NKniRmo84NZQUu5iFw5groAQgQYox3YCqaMjKc2WTpPU1yqV |
26 |
| -[4/5] Post the VAA data onto a solana account |
27 |
| -Transaction successful : 3L1vxzSHQv6B6TwtoMv2Y6m7vFGz3hzqApGHEhHSLA9Jn5dNKeWRWKv29UDPDc3vsgt1mYueamUPPt6bHGGEkbxh |
28 |
| -[5/5] Receive and deserialize the VAA on solana |
29 |
| -Receiver program ID is 5dXnHcDXdXaiEp9QgknCDPsEhJStSqZqJ4ATirWfEqeY |
30 |
| -Transaction successful : u5y9Hqc18so3BnjSUvZkLZR4mvA8zkiBgzGKHSEYyWkHQhH3uQatM7xWf4kdrhjZFVGbfBLdR8RJJUmuf28ePtG |
| 1 | +# Pyth Solana Receiver |
| 2 | + |
| 3 | +This folder contains: |
| 4 | + |
| 5 | +- A Pyth receiver program to receive Pythnet price feeds on Solana in `programs/pyth-solana-receiver` |
| 6 | +- A Cli that acts as a simple client to interact with the Pyth receiver program in `cli/` |
| 7 | + |
| 8 | +# Overview of the design |
| 9 | + |
| 10 | +Receiving a price update from Pythnet involves two steps: |
| 11 | + |
| 12 | +- First, verifying the VAA i.e. verifying the Wormhole guardians' signatures on the accumulator root that contains all the price updates for a given Pythnet slot. This happens in the Wormhole receiver contract (Note: this contract is in the Wormhole monorepo, we're currently using this branch https://github.com/guibescos/wormhole/tree/variable-sigs). |
| 13 | +- Second, verifying the price update by providing an inclusion proof that proves the price update is part of the accumulator root that was verified in the first step. This happens in the Pyth receiver contract. |
| 14 | + |
| 15 | +The Pyth receiver program: |
| 16 | + |
| 17 | +- verifies that the VAA has been verified by the Wormhole program (through the owner of the account that contains the VAA, the anchor discriminator and the field `verified_signatures`). |
| 18 | +- checks that the VAA was emitted by the right data source |
| 19 | +- checks the inclusion proof is valid |
| 20 | +- posts the price update to a `PriceUpdateV1` account |
| 21 | + |
| 22 | +# Devnet deployment |
| 23 | + |
| 24 | +The program is currently deployed on Devnet with addresses: |
| 25 | + |
| 26 | +- `HDwcJBJXjL9FpJ7UBsYBtaDjsBUhuLCUYoz3zr8SWWaQ` for the Wormhole receiver |
| 27 | +- `rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ` for the Pyth receiver |
| 28 | + |
| 29 | +# Example flow |
| 30 | + |
| 31 | +The `cli` folder contains some useful client code to interact with both the Wormhole receiver and the Pyth receiver. |
| 32 | + |
| 33 | +To run the full flow of posting a price update (on devnet) please follow the following steps: |
| 34 | + |
| 35 | +Get a Hermes update from Hermes stable: |
| 36 | + |
31 | 37 | ```
|
| 38 | +curl "https://hermes.pyth.network/api/latest_vaas?ids[]=0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace" |
32 | 39 |
|
33 |
| -## Unit tests |
| 40 | +``` |
| 41 | + |
| 42 | +Post it to devnet: |
34 | 43 |
|
35 |
| -Run `anchor run test` to run the unit tests in the `src/tests/` directory. |
36 |
| -**Warning**: do not confuse this command with `anchor test`, which doesn't do anything useful. |
| 44 | +``` |
| 45 | +cargo run --package pyth-solana-receiver-cli -- --url https://api.devnet.solana.com --keypair ${PATH_TO_KEYPAIR} --wormhole HDwcJBJXjL9FpJ7UBsYBtaDjsBUhuLCUYoz3zr8SWWaQ post-price-update -p ${HERMES_UPDATE_IN_BASE_64} |
| 46 | +``` |
0 commit comments