|
1 | 1 | # pyth-client
|
2 |
| -client API for on-chain pyth programs |
| 2 | + |
| 3 | +Pyth oracle program and off-chain client API. |
| 4 | + |
| 5 | +## Oracle Program |
| 6 | + |
| 7 | +The Pyth oracle program lives in the `program/` directory. |
| 8 | +It consists of both C and Rust code, but everything can be built and tested using `cargo`. |
| 9 | + |
| 10 | +### Build Instructions |
| 11 | + |
| 12 | +First, make sure you have the [solana tool suite](https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-tool) |
| 13 | +installed on your machine. (The build depends on some C makefiles that are in the tool suite.) |
| 14 | + |
| 15 | +Then, simply run `cargo build` to compile the oracle program as a native binary, or `cargo build-bpf` to build a BPF binary |
| 16 | +that can be uploaded to the blockchain. This step will produce a program binary `target/deploy/pyth_oracle.so`. |
| 17 | + |
| 18 | +### Testing |
| 19 | + |
| 20 | +Simply run `cargo test`. This command will run several sets of tests: |
| 21 | + |
| 22 | +- Unit tests of individual functions |
| 23 | +- Simulated transaction tests against the BPF binary running on a solana simulator |
| 24 | +- Exhaustive / randomized test batteries for core oracle functionality |
| 25 | + |
| 26 | +Rust tests live in the `tests/` module of the rust code, and C tests are named something like `test_*.c`. |
| 27 | +The C tests are linked into the rust binary so they run as part of `cargo test` as well (see `tests/test_c_code.rs`). |
| 28 | + |
| 29 | +You can also run `cargo test-bpf`, which runs the same tests as `cargo test`, though it's slightly slower and the UX is worse. |
| 30 | + |
| 31 | +### pre-commit hooks |
| 32 | +pre-commit is a tool that checks and fixes simple issues (formatting, ...) before each commit. You can install it by following [their website](https://pre-commit.com/). In order to enable checks for this repo run `pre-commit install` from command-line in the root of this repo. |
| 33 | + |
| 34 | +The checks are also performed in the CI to ensure the code follows consistent formatting. Formatting is only currently enforced in the `program/` directory. |
| 35 | +You might also need to install the nightly toolchain to run the formatting by running `rustup toolchain install nightly`. |
| 36 | + |
| 37 | +## pythd (off-chain client API) |
| 38 | + |
| 39 | +> :warning: pythd is deprecated and has been replaced by [pyth-agent](https://github.com/pyth-network/pyth-agent). |
| 40 | +> This new client is backward compatible with pythd, but more stable and configurable. |
| 41 | +
|
| 42 | +`pythd` provides exposes a web API for interacting with the on-chain oracle program. |
3 | 43 |
|
4 | 44 | ### Build Instructions
|
5 | 45 |
|
@@ -44,30 +84,6 @@ This command runs a recent pyth-client docker image that already has the necessa
|
44 | 84 | Therefore, once the container is running, all you have to do is run `cd pyth-client && ./scripts/build.sh`.
|
45 | 85 | Note that updates to the `pyth-client` directory made inside the docker container will be persisted to the host filesystem (which is probably desirable).
|
46 | 86 |
|
47 |
| -### Local development |
48 |
| - |
49 |
| -First, make sure you're building on the x86_64 architecture. |
50 |
| -On a mac, this command will switch your shell to x86_64: |
51 |
| - |
52 |
| -`env /usr/bin/arch -x86_64 /bin/bash --login` |
53 |
| - |
54 |
| -then in the `program/c` directory, run: |
55 |
| - |
56 |
| -``` |
57 |
| -make |
58 |
| -make cpyth-bpf |
59 |
| -make cpyth-native |
60 |
| -``` |
61 |
| - |
62 |
| -then in the `program/rust` directory, run: |
63 |
| - |
64 |
| -``` |
65 |
| -cargo build-bpf |
66 |
| -cargo test |
67 |
| -``` |
68 |
| - |
69 |
| -Note that the tests depend on the bpf build! |
70 |
| - |
71 | 87 | ### Fuzzing
|
72 | 88 |
|
73 | 89 | Build a docker image for running fuzz tests:
|
@@ -130,8 +146,3 @@ root@pyth-dev# usermod -u 1002 -g 1004 -s /bin/bash pyth
|
130 | 146 |
|
131 | 147 | Finally, in docker extension inside VS Code click right and choose "Attach VS Code". If you're using a remote host in VS Code make sure to let this connection be open.
|
132 | 148 |
|
133 |
| -### pre-commit hooks |
134 |
| -pre-commit is a tool that checks and fixes simple issues (formatting, ...) before each commit. You can install it by following [their website](https://pre-commit.com/). In order to enable checks for this repo run `pre-commit install` from command-line in the root of this repo. |
135 |
| - |
136 |
| -The checks are also performed in the CI to ensure the code follows consistent formatting. Formatting is only currently enforced in the `program/` directory. |
137 |
| -You might also need to install the nightly toolchain to run the formatting by running `rustup toolchain install nightly`. |
|
0 commit comments