diff --git a/.github/workflows/pyth-sdk-solana.yml b/.github/workflows/pyth-sdk-solana.yml index 6a891ce..d02aa03 100644 --- a/.github/workflows/pyth-sdk-solana.yml +++ b/.github/workflows/pyth-sdk-solana.yml @@ -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 diff --git a/examples/sol-contract/Cargo.toml b/examples/sol-contract/Cargo.toml index 38e2ba5..647549c 100644 --- a/examples/sol-contract/Cargo.toml +++ b/examples/sol-contract/Cargo.toml @@ -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" diff --git a/examples/sol-contract/README.md b/examples/sol-contract/README.md index 9ff52e6..24b92db 100644 --- a/examples/sol-contract/README.md +++ b/examples/sol-contract/README.md @@ -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. @@ -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 ``` diff --git a/examples/sol-contract/src/processor.rs b/examples/sol-contract/src/processor.rs index cf100d6..ef5a488 100644 --- a/examples/sol-contract/src/processor.rs +++ b/examples/sol-contract/src/processor.rs @@ -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, @@ -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) @@ -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) diff --git a/pyth-sdk-solana/test-contract/Cargo.toml b/pyth-sdk-solana/test-contract/Cargo.toml index 754f44c..b9ef683 100644 --- a/pyth-sdk-solana/test-contract/Cargo.toml +++ b/pyth-sdk-solana/test-contract/Cargo.toml @@ -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"]