|
1 |
| -# sol-anchor-contract |
| 1 | +# Pyth SDK Example Program for Solana and the Anchor Library |
2 | 2 |
|
3 |
| -This is a program developed as a Rust Smart Contract(Solana Blockchain). |
4 |
| -It acts as an example for developers who are new to Solana ecosystem to learn on how the program interacts with the Pyth Oracles. |
| 3 | +This example implements the same functionalities as the `sol-contract` example. |
| 4 | +The difference is that this example uses the `anchor` library while the `sol-contract` example uses the lower-level solana interface. |
| 5 | +Please refer to the README of `sol-contract` for a description of the functionalities. |
5 | 6 |
|
6 |
| -Instructions of the program: |
| 7 | +## Run this program |
| 8 | +We assume that you have installed `anchor`, `npm` and `yarn`. |
7 | 9 |
|
8 |
| -1. init |
9 |
| -2. loanToValue |
| 10 | +```shell |
| 11 | +# Generate the program key |
| 12 | +> solana-keygen new -o program_address.json |
10 | 13 |
|
11 |
| -Please find below instructions on running the Smart Contract on local cluster: |
| 14 | +# Use the pubkey generated to replace the following two places |
| 15 | +# "example_sol_anchor_contract" in Anchor.toml |
| 16 | +# "declare_id!()" in programs/example-sol-anchor-contract/src/lib.rs |
12 | 17 |
|
13 |
| -1. |
| 18 | +# Enter the directory and build this example |
| 19 | +> cd examples/sol-contract-anchor |
| 20 | +> anchor build |
14 | 21 |
|
15 |
| -- Open a new terminal |
16 |
| -- Run below command which clones two account addresses and their associated data into local cluster from devnet cluster. |
| 22 | +# Change the `wallet` field in Anchor.toml to your own wallet |
| 23 | +# And then deploy the example contract; An error may occur if |
| 24 | +# your wallet does not have enough funds |
| 25 | +> anchor deploy --program-keypair program_address.json --program-name example-sol-anchor-contract |
17 | 26 |
|
18 |
| -solana-test-validator --reset --clone EdVCmQ9FSPcVe5YySXDPCRmc8aDQLKJ9xvYBMZPie1Vw 38xoQ4oeJCBrcVvca2cGk7iV1dAfrmTR1kmhSCJQ8Jto --url devnet |
19 |
| - |
20 |
| -2. |
21 |
| - |
22 |
| -- Open a new terminal. |
23 |
| -- Run below command which listens to transaction logs. |
24 |
| - |
25 |
| -solana logs |
26 |
| - |
27 |
| -3. |
28 |
| - |
29 |
| -- Open a new terminal. |
30 |
| -- Navigate to the root directory of your application. |
31 |
| -- Build and then deploy. |
32 |
| -- Run below command |
33 |
| - |
34 |
| -anchor test --skip-local-validator |
35 |
| - |
36 |
| -NB |
37 |
| - |
38 |
| -When testing on local cluster you may encounter error "Pyth price oracle is offline.", please find below one of the approaches of addressing it. |
39 |
| -- On file "src\lib.rs", change the value "60" to a higher figure on these lines of code ".get_price_no_older_than(current_timestamp1, 60)" |
40 |
| -and ".get_price_no_older_than(current_timestamp2, 60)". This should just be for testing purposes on local cluster. |
| 27 | +# Install the client dependencies and invoke this program |
| 28 | +> anchor run install |
| 29 | +> anchor run test |
| 30 | +``` |
0 commit comments