Skip to content

Commit 26778ef

Browse files
authored
Adapt to pyth-sdk-solana interface change (#91)
1 parent c7b802f commit 26778ef

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

examples/sol-anchor-contract/Anchor.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[programs.devnet]
2-
example_sol_anchor_contract = "Fwn1fCmbjd8d95hxY9NUUr5Xa7D13khveMnmCUFdd3ah"
2+
example_sol_anchor_contract = "9azQ2ePzPvMPQgHric53kdSNmwjVM5KijDE4ANFCE9D4"
33

44
[provider]
55
cluster = "devnet"

examples/sol-anchor-contract/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ We assume that you have installed `anchor`, `npm` and `yarn`.
2626

2727
# Install the client dependencies and invoke this program
2828
> anchor run install
29-
> anchor run invoke
29+
> anchor run test
3030
```

examples/sol-anchor-contract/programs/example-sol-anchor-contract/src/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use anchor_lang::prelude::*;
33
use solana_program::account_info::AccountInfo;
44
use pyth_sdk_solana::load_price_feed_from_account_info;
55

6-
declare_id!("Fwn1fCmbjd8d95hxY9NUUr5Xa7D13khveMnmCUFdd3ah");
6+
declare_id!("9azQ2ePzPvMPQgHric53kdSNmwjVM5KijDE4ANFCE9D4");
77

88
#[account]
99
pub struct AdminConfig {
@@ -54,7 +54,9 @@ pub mod example_sol_anchor_contract {
5454
// https://docs.pyth.network/consume-data/best-practices
5555
let feed1 = load_price_feed_from_account_info(pyth_loan_account)
5656
.map_err(|_x| error!(ErrorCode::PythError))?;
57-
let result1 = feed1.get_current_price()
57+
let current_timestamp1 = Clock::get()?.unix_timestamp;
58+
let result1 = feed1
59+
.get_price_no_older_than(current_timestamp1, 60)
5860
.ok_or(ErrorCode::PythOffline)?;
5961
let loan_max_price = result1
6062
.price
@@ -75,7 +77,9 @@ pub mod example_sol_anchor_contract {
7577
// https://docs.pyth.network/consume-data/best-practices
7678
let feed2 = load_price_feed_from_account_info(pyth_collateral_account)
7779
.map_err(|_x| error!(ErrorCode::PythError))?;
78-
let result2 = feed2.get_current_price()
80+
let current_timestamp2 = Clock::get()?.unix_timestamp;
81+
let result2 = feed2
82+
.get_price_no_older_than(current_timestamp2, 60)
7983
.ok_or(ErrorCode::PythOffline)?;
8084
let collateral_min_price = result2
8185
.price

examples/sol-anchor-contract/scripts/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ try {
2626
try {
2727
assert(programId.equals(programKey.publicKey));
2828
} catch (error) {
29-
throw new Error("Please make sure you have the same program address inAnchor.toml and program_address.json");
29+
throw new Error("Please make sure you have the same program address in Anchor.toml and program_address.json");
3030
}
3131

3232
it("Initialize the config.", async () => {

0 commit comments

Comments
 (0)