From 48cd01e5bd1a5a450adba194fc14eac0890dac93 Mon Sep 17 00:00:00 2001 From: 0xripleys <0xripleys@solend.fi> Date: Sat, 17 Feb 2024 00:38:47 -0500 Subject: [PATCH 1/6] make workflow changes --- .github/workflows/pull-request-token-lending.yml | 2 +- .github/workflows/pull-request.yml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull-request-token-lending.yml b/.github/workflows/pull-request-token-lending.yml index 2113caffdc0..61903686d65 100644 --- a/.github/workflows/pull-request-token-lending.yml +++ b/.github/workflows/pull-request-token-lending.yml @@ -13,7 +13,7 @@ on: jobs: cargo-test-bpf: - runs-on: ubuntu-latest-16-cores + runs-on: blacksmith-16vcpu-ubuntu-2204 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2221f07590c..239698625e3 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,7 +11,7 @@ on: jobs: all_github_action_checks: - runs-on: ubuntu-latest + runs-on: blacksmith-16vcpu-ubuntu-2204 needs: - rustfmt - clippy @@ -20,7 +20,7 @@ jobs: - run: echo "Done" rustfmt: - runs-on: ubuntu-latest + runs-on: blacksmith-16vcpu-ubuntu-2204 steps: - uses: actions/checkout@v2 @@ -43,7 +43,7 @@ jobs: args: --all -- --check clippy: - runs-on: ubuntu-latest + runs-on: blacksmith-16vcpu-ubuntu-2204 steps: - uses: actions/checkout@v2 @@ -79,7 +79,7 @@ jobs: args: --workspace --all-targets -- --deny=warnings cargo-build-test: - runs-on: ubuntu-latest + runs-on: blacksmith-16vcpu-ubuntu-2204 steps: - uses: actions/checkout@v2 @@ -126,7 +126,7 @@ jobs: run: ./ci/cargo-build-test.sh cargo-coverage: - runs-on: ubuntu-latest-16-cores + runs-on: blacksmith-16vcpu-ubuntu-2204 steps: - uses: actions/checkout@v2 From e6c4e8897a545632261a86f198d7986363bc4c6a Mon Sep 17 00:00:00 2001 From: 0xripleys <0xripleys@solend.fi> Date: Sat, 17 Feb 2024 00:47:00 -0500 Subject: [PATCH 2/6] bump --- .github/workflows/pull-request-token-lending.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull-request-token-lending.yml b/.github/workflows/pull-request-token-lending.yml index 61903686d65..0d86afe70c6 100644 --- a/.github/workflows/pull-request-token-lending.yml +++ b/.github/workflows/pull-request-token-lending.yml @@ -24,6 +24,7 @@ jobs: source ci/solana-version.sh echo "SOLANA_VERSION=$solana_version" >> $GITHUB_ENV + - uses: actions-rs/toolchain@v1 with: toolchain: ${{ env.RUST_STABLE }} From a055bd19e739b54d4fc79ecc2fb92e57ddfa31f4 Mon Sep 17 00:00:00 2001 From: 0xripleys <0xripleys@solend.fi> Date: Sat, 17 Feb 2024 00:57:18 -0500 Subject: [PATCH 3/6] bump --- token-lending/program/src/processor.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/token-lending/program/src/processor.rs b/token-lending/program/src/processor.rs index 26c05cdd815..03732b25adb 100644 --- a/token-lending/program/src/processor.rs +++ b/token-lending/program/src/processor.rs @@ -2611,6 +2611,7 @@ fn process_redeem_fees(program_id: &Pubkey, accounts: &[AccountInfo]) -> Program return Err(LendingError::InvalidMarketAuthority.into()); } + let withdraw_amount = reserve.calculate_redeem_fees()?; if withdraw_amount == 0 { return Err(LendingError::InsufficientProtocolFeesToRedeem.into()); From 369a48a42cf35d4f02a21158bbe20db899d38ed4 Mon Sep 17 00:00:00 2001 From: 0xripleys <0xripleys@solend.fi> Date: Sat, 17 Feb 2024 00:58:59 -0500 Subject: [PATCH 4/6] use blacksmith cache --- .github/workflows/pull-request-token-lending.yml | 6 +++--- .github/workflows/pull-request.yml | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pull-request-token-lending.yml b/.github/workflows/pull-request-token-lending.yml index 0d86afe70c6..115ada7ea77 100644 --- a/.github/workflows/pull-request-token-lending.yml +++ b/.github/workflows/pull-request-token-lending.yml @@ -31,20 +31,20 @@ jobs: override: true profile: minimal - - uses: actions/cache@v2 + - uses: useblacksmith/cache@v5 with: path: | ~/.cargo/registry ~/.cargo/git key: cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ env.RUST_STABLE}} - - uses: actions/cache@v2 + - uses: useblacksmith/cache@v5 with: path: | ~/.cargo/bin/rustfilt key: cargo-bpf-bins-${{ runner.os }} - - uses: actions/cache@v2 + - uses: useblacksmith/cache@v5 with: path: | ~/.cache diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 239698625e3..d6732f5226e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -59,7 +59,7 @@ jobs: profile: minimal components: clippy - - uses: actions/cache@v2 + - uses: useblacksmith/cache@v5 with: path: | ~/.cargo/registry @@ -96,7 +96,7 @@ jobs: override: true profile: minimal - - uses: actions/cache@v2 + - uses: useblacksmith/cache@v5 with: path: | ~/.cargo/registry @@ -104,13 +104,13 @@ jobs: # target # Removed due to build dependency caching conflicts key: cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ env.RUST_STABLE}} - - uses: actions/cache@v2 + - uses: useblacksmith/cache@v5 with: path: | ~/.cargo/bin/rustfilt key: cargo-bpf-bins-${{ runner.os }} - - uses: actions/cache@v2 + - uses: useblacksmith/cache@v5 with: path: | ~/.cache @@ -143,7 +143,7 @@ jobs: override: true profile: minimal - - uses: actions/cache@v2 + - uses: useblacksmith/cache@v5 with: path: | ~/.cargo/registry From 600871f9a85f00f384b92690bcd2316d5346beb1 Mon Sep 17 00:00:00 2001 From: 0xripleys <0xripleys@solend.fi> Date: Sat, 17 Feb 2024 01:00:17 -0500 Subject: [PATCH 5/6] bump --- token-lending/program/src/processor.rs | 1 - token-lending/program/tests/two_prices.rs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/token-lending/program/src/processor.rs b/token-lending/program/src/processor.rs index 03732b25adb..26c05cdd815 100644 --- a/token-lending/program/src/processor.rs +++ b/token-lending/program/src/processor.rs @@ -2611,7 +2611,6 @@ fn process_redeem_fees(program_id: &Pubkey, accounts: &[AccountInfo]) -> Program return Err(LendingError::InvalidMarketAuthority.into()); } - let withdraw_amount = reserve.calculate_redeem_fees()?; if withdraw_amount == 0 { return Err(LendingError::InsufficientProtocolFeesToRedeem.into()); diff --git a/token-lending/program/tests/two_prices.rs b/token-lending/program/tests/two_prices.rs index 463b562fb06..c2b947dffc7 100644 --- a/token-lending/program/tests/two_prices.rs +++ b/token-lending/program/tests/two_prices.rs @@ -486,6 +486,7 @@ async fn test_liquidation_doesnt_use_smoothed_price() { diff: -((LAMPORTS_PER_SOL / 5) as i128), }, ]); + println!("hi"); assert_eq!(balance_changes, expected_balances_changes); } From 09892e35c6a15c49b862a462bcbcc61028ba42e7 Mon Sep 17 00:00:00 2001 From: 0xripleys <0xripleys@solend.fi> Date: Sat, 17 Feb 2024 01:43:55 -0500 Subject: [PATCH 6/6] bump one last time --- token-lending/program/src/processor.rs | 4 +- .../program/tests/helpers/mock_pyth.rs | 2 +- .../tests/helpers/solend_program_test.rs | 5 +- token-lending/program/tests/two_prices.rs | 2 +- token-lending/sdk/src/state/rate_limiter.rs | 156 +++++++++--------- token-lending/sdk/src/state/reserve.rs | 10 +- 6 files changed, 85 insertions(+), 94 deletions(-) diff --git a/token-lending/program/src/processor.rs b/token-lending/program/src/processor.rs index 26c05cdd815..d570996444c 100644 --- a/token-lending/program/src/processor.rs +++ b/token-lending/program/src/processor.rs @@ -616,9 +616,9 @@ fn _refresh_reserve<'a>( /// Lite version of refresh_reserve that should be used when the oracle price doesn't need to be updated /// BE CAREFUL WHEN USING THIS -fn _refresh_reserve_interest<'a>( +fn _refresh_reserve_interest( program_id: &Pubkey, - reserve_info: &AccountInfo<'a>, + reserve_info: &AccountInfo<'_>, clock: &Clock, ) -> ProgramResult { let mut reserve = Box::new(Reserve::unpack(&reserve_info.data.borrow())?); diff --git a/token-lending/program/tests/helpers/mock_pyth.rs b/token-lending/program/tests/helpers/mock_pyth.rs index 55f177d05d8..72e15f3c990 100644 --- a/token-lending/program/tests/helpers/mock_pyth.rs +++ b/token-lending/program/tests/helpers/mock_pyth.rs @@ -113,7 +113,7 @@ impl Processor { msg!("Mock Pyth: Set price"); let price_account_info = next_account_info(account_info_iter)?; let data = &mut price_account_info.try_borrow_mut_data()?; - let mut price_account: &mut PriceAccount = load_mut(data).unwrap(); + let price_account: &mut PriceAccount = load_mut(data).unwrap(); price_account.agg.price = price; price_account.agg.conf = conf; diff --git a/token-lending/program/tests/helpers/solend_program_test.rs b/token-lending/program/tests/helpers/solend_program_test.rs index ed41e80bdad..90e3f296371 100644 --- a/token-lending/program/tests/helpers/solend_program_test.rs +++ b/token-lending/program/tests/helpers/solend_program_test.rs @@ -1758,10 +1758,7 @@ pub async fn custom_scenario( .or_insert(arg.liquidity_amount); } - let mints_and_liquidity_amounts = mints_and_liquidity_amounts - .into_iter() - .map(|(mint, liquidity_amount)| (mint, liquidity_amount)) - .collect::>(); + let mints_and_liquidity_amounts = mints_and_liquidity_amounts.into_iter().collect::>(); let lending_market_owner = User::new_with_balances(&mut test, &mints_and_liquidity_amounts).await; diff --git a/token-lending/program/tests/two_prices.rs b/token-lending/program/tests/two_prices.rs index c2b947dffc7..8d2d1056ee5 100644 --- a/token-lending/program/tests/two_prices.rs +++ b/token-lending/program/tests/two_prices.rs @@ -486,7 +486,7 @@ async fn test_liquidation_doesnt_use_smoothed_price() { diff: -((LAMPORTS_PER_SOL / 5) as i128), }, ]); - println!("hi"); + println!("hello"); assert_eq!(balance_changes, expected_balances_changes); } diff --git a/token-lending/sdk/src/state/rate_limiter.rs b/token-lending/sdk/src/state/rate_limiter.rs index c83df488f3c..55f86774018 100644 --- a/token-lending/sdk/src/state/rate_limiter.rs +++ b/token-lending/sdk/src/state/rate_limiter.rs @@ -141,84 +141,6 @@ impl RateLimiter { } } -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_rate_limiter() { - let mut rate_limiter = RateLimiter::new( - RateLimiterConfig { - window_duration: 10, - max_outflow: 100, - }, - 10, - ); - - assert_eq!( - rate_limiter.update(9, Decimal::from(1u64)), - Err(LendingError::InvalidAccountInput.into()) - ); - - // case 1: no prev window, all quantity is taken up in first slot - assert_eq!( - rate_limiter.update(10, Decimal::from(101u64)), - Err(LendingError::OutflowRateLimitExceeded.into()) - ); - assert_eq!( - rate_limiter.remaining_outflow(10), - Ok(Decimal::from(100u64)) - ); - - assert_eq!(rate_limiter.update(10, Decimal::from(100u64)), Ok(())); - assert_eq!(rate_limiter.remaining_outflow(10), Ok(Decimal::from(0u64))); - for i in 11..20 { - assert_eq!( - rate_limiter.update(i, Decimal::from(1u64)), - Err(LendingError::OutflowRateLimitExceeded.into()) - ); - assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(0u64))); - } - - // case 2: prev window qty affects cur window's allowed qty. exactly 10 qty frees up every - // slot. - for i in 20..30 { - assert_eq!( - rate_limiter.update(i, Decimal::from(11u64)), - Err(LendingError::OutflowRateLimitExceeded.into()) - ); - - assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(10u64))); - assert_eq!(rate_limiter.update(i, Decimal::from(10u64)), Ok(())); - assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(0u64))); - - assert_eq!( - rate_limiter.update(i, Decimal::from(1u64)), - Err(LendingError::OutflowRateLimitExceeded.into()) - ); - } - - // case 3: new slot is so far ahead, prev window is dropped - assert_eq!( - rate_limiter.remaining_outflow(100), - Ok(Decimal::from(100u64)) - ); - assert_eq!(rate_limiter.update(100, Decimal::from(10u64)), Ok(())); - for i in 101..109 { - assert_eq!( - rate_limiter.remaining_outflow(i), - Ok(Decimal::from(100u64 - 10 * (i - 100))) - ); - assert_eq!(rate_limiter.update(i, Decimal::from(10u64)), Ok(())); - assert_eq!( - rate_limiter.remaining_outflow(i), - Ok(Decimal::from(90u64 - 10 * (i - 100))) - ); - } - println!("{:#?}", rate_limiter); - } -} - impl Default for RateLimiter { fn default() -> Self { Self::new( @@ -301,3 +223,81 @@ pub fn rand_rate_limiter() -> RateLimiter { cur_qty: rand_decimal(), } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_rate_limiter() { + let mut rate_limiter = RateLimiter::new( + RateLimiterConfig { + window_duration: 10, + max_outflow: 100, + }, + 10, + ); + + assert_eq!( + rate_limiter.update(9, Decimal::from(1u64)), + Err(LendingError::InvalidAccountInput.into()) + ); + + // case 1: no prev window, all quantity is taken up in first slot + assert_eq!( + rate_limiter.update(10, Decimal::from(101u64)), + Err(LendingError::OutflowRateLimitExceeded.into()) + ); + assert_eq!( + rate_limiter.remaining_outflow(10), + Ok(Decimal::from(100u64)) + ); + + assert_eq!(rate_limiter.update(10, Decimal::from(100u64)), Ok(())); + assert_eq!(rate_limiter.remaining_outflow(10), Ok(Decimal::from(0u64))); + for i in 11..20 { + assert_eq!( + rate_limiter.update(i, Decimal::from(1u64)), + Err(LendingError::OutflowRateLimitExceeded.into()) + ); + assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(0u64))); + } + + // case 2: prev window qty affects cur window's allowed qty. exactly 10 qty frees up every + // slot. + for i in 20..30 { + assert_eq!( + rate_limiter.update(i, Decimal::from(11u64)), + Err(LendingError::OutflowRateLimitExceeded.into()) + ); + + assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(10u64))); + assert_eq!(rate_limiter.update(i, Decimal::from(10u64)), Ok(())); + assert_eq!(rate_limiter.remaining_outflow(i), Ok(Decimal::from(0u64))); + + assert_eq!( + rate_limiter.update(i, Decimal::from(1u64)), + Err(LendingError::OutflowRateLimitExceeded.into()) + ); + } + + // case 3: new slot is so far ahead, prev window is dropped + assert_eq!( + rate_limiter.remaining_outflow(100), + Ok(Decimal::from(100u64)) + ); + assert_eq!(rate_limiter.update(100, Decimal::from(10u64)), Ok(())); + for i in 101..109 { + assert_eq!( + rate_limiter.remaining_outflow(i), + Ok(Decimal::from(100u64 - 10 * (i - 100))) + ); + assert_eq!(rate_limiter.update(i, Decimal::from(10u64)), Ok(())); + assert_eq!( + rate_limiter.remaining_outflow(i), + Ok(Decimal::from(90u64 - 10 * (i - 100))) + ); + } + println!("{:#?}", rate_limiter); + } +} diff --git a/token-lending/sdk/src/state/reserve.rs b/token-lending/sdk/src/state/reserve.rs index 9ed5e27f938..dcabc0e3400 100644 --- a/token-lending/sdk/src/state/reserve.rs +++ b/token-lending/sdk/src/state/reserve.rs @@ -2605,14 +2605,8 @@ mod test { } fn calculate_liquidation_test_cases() -> impl Strategy { - let close_factor: Decimal = Rate::from_percent(LIQUIDATION_CLOSE_FACTOR) - .try_into() - .unwrap(); - let liquidation_bonus: Decimal = Rate::from_percent(5) - .try_add(Rate::one()) - .unwrap() - .try_into() - .unwrap(); + let close_factor: Decimal = Rate::from_percent(LIQUIDATION_CLOSE_FACTOR).into(); + let liquidation_bonus: Decimal = Rate::from_percent(5).try_add(Rate::one()).unwrap().into(); prop_oneof![ // collateral market value > liquidation value