Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/pyth-sdk-solana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jobs:
run: sudo apt-get update && sudo apt-get install libudev-dev
- name: Install Solana Binaries
run: |
sh -c "$(curl -sSfL https://release.solana.com/v1.10.40/install)"
# Installing 1.14.x cli tools to have sbf instead of bpf. bpf does not work anymore.
sh -c "$(curl -sSfL https://release.solana.com/v1.14.7/install)"
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
- name: Build
run: cargo build --verbose
Expand Down
6 changes: 1 addition & 5 deletions examples/sol-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ crate-type = ["cdylib", "lib"]
[dependencies]
borsh = "0.9"
arrayref = "0.3.6"
solana-program = "1.10.40"
solana-program = "=1.13.3"
pyth-sdk-solana = { path = "../../pyth-sdk-solana", version = "0.6.1" }

[dev-dependencies]
solana-sdk = "1.10.40"
solana-client = "1.10.40"
5 changes: 3 additions & 2 deletions examples/sol-contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Pyth SDK is used in the `Loan2Value` instruction in `src/processor.rs`.
For the loan, the code first reads the unit price from the Pyth oracle.
```rust
let feed1 = load_price_feed_from_account_info(pyth_loan_account)?;
let result1 = feed1.get_current_price().ok_or(ProgramError::Custom(3))?;
let current_timestamp1 = Clock::get()?.unix_timestamp;
let result1 = feed1.get_price_no_older_than(current_timestamp1, 60).ok_or(ProgramError::Custom(3))?;
```

And then calculate the loan value given the quantity of the loan.
Expand Down Expand Up @@ -49,5 +50,5 @@ We assume that you have installed `cargo`, `solana`, `npm` and `node`.
# Deploy the example contract
> scripts/deploy.sh
# Invoke the example contract
> scripts/invoke.ts
> scripts/invoke.sh
```
12 changes: 10 additions & 2 deletions examples/sol-contract/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use solana_program::msg;
use solana_program::program_error::ProgramError;
use solana_program::program_memory::sol_memcpy;
use solana_program::pubkey::Pubkey;
use solana_program::sysvar::clock::Clock;
use solana_program::sysvar::Sysvar;

use borsh::{
BorshDeserialize,
Expand Down Expand Up @@ -84,7 +86,10 @@ pub fn process_instruction(
// Here is more explanation on confidence interval in Pyth:
// https://docs.pyth.network/consume-data/best-practices
let feed1 = load_price_feed_from_account_info(pyth_loan_account)?;
let result1 = feed1.get_current_price().ok_or(ProgramError::Custom(3))?;
let current_timestamp1 = Clock::get()?.unix_timestamp;
let result1 = feed1
.get_price_no_older_than(current_timestamp1, 60)
.ok_or(ProgramError::Custom(3))?;
let loan_max_price = result1
.price
.checked_add(result1.conf as i64)
Expand All @@ -103,7 +108,10 @@ pub fn process_instruction(
// Here is more explanation on confidence interval in Pyth:
// https://docs.pyth.network/consume-data/best-practices
let feed2 = load_price_feed_from_account_info(pyth_collateral_account)?;
let result2 = feed2.get_current_price().ok_or(ProgramError::Custom(3))?;
let current_timestamp2 = Clock::get()?.unix_timestamp;
let result2 = feed2
.get_price_no_older_than(current_timestamp2, 60)
.ok_or(ProgramError::Custom(3))?;
let collateral_min_price = result2
.price
.checked_sub(result2.conf as i64)
Expand Down
8 changes: 4 additions & 4 deletions pyth-sdk-solana/test-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ no-entrypoint = []

[dependencies]
pyth-sdk-solana = { path = "../", version = "0.6.1" }
solana-program = "1.10.40"
solana-program = "=1.13.3"
bytemuck = "1.7.2"
borsh = "0.9"
borsh-derive = "0.9.0"

[dev-dependencies]
solana-program-test = "1.10.40"
solana-client = "1.10.40"
solana-sdk = "1.10.40"
solana-program-test = "=1.13.3"
solana-client = "=1.13.3"
solana-sdk = "=1.13.3"

[lib]
crate-type = ["cdylib", "lib"]
Expand Down