Skip to content

Commit a08a381

Browse files
committed
Merge branch 'feat/liquidity-mining' into feat/lm-cli-upgrade-all-reserves
2 parents ae60f65 + 4137879 commit a08a381

12 files changed

+102
-17
lines changed

ci/solana-version.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
if [[ -n $SOLANA_VERSION ]]; then
1515
solana_version="$SOLANA_VERSION"
1616
else
17-
solana_version=v1.16.20
17+
# we use 1.16.20 for sdk but this version has been deleted from the solana servers so we use
18+
# this version's CLI instead
19+
solana_version=v1.17.34
1820
fi
1921

2022
export solana_version="$solana_version"
@@ -23,7 +25,7 @@ export PATH="$HOME"/.local/share/solana/install/active_release/bin:"$PATH"
2325
if [[ -n $1 ]]; then
2426
case $1 in
2527
install)
26-
sh -c "$(curl -sSfL https://release.solana.com/$solana_version/install)"
28+
sh -c "$(curl -sSfL https://release.anza.xyz/$solana_version/install)"
2729
solana --version
2830
;;
2931
*)

token-lending/program/src/processor.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,13 +1588,15 @@ fn _withdraw_obligation_collateral<'a>(
15881588
.clone() // remaining_outflow is a mutable call, but we don't have mutable access here
15891589
.remaining_outflow(clock.slot)?;
15901590

1591-
let max_lending_market_outflow_liquidity_amount = withdraw_reserve
1592-
.usd_to_liquidity_amount_lower_bound(min(
1593-
max_outflow_usd,
1594-
// min here bc this function can overflow if max_outflow_usd is u64::MAX
1595-
// the actual value doesn't matter too much as long as its sensible
1596-
obligation.deposited_value.try_mul(2)?,
1597-
))?;
1591+
// min here bc this function can overflow if max_outflow_usd is u64::MAX
1592+
// the actual value doesn't matter too much as long as its sensible
1593+
let max_outflow_usd_capped = min(
1594+
max_outflow_usd,
1595+
Decimal::from(100_000_000_000u64), // enough USD to cover all requests
1596+
);
1597+
1598+
let max_lending_market_outflow_liquidity_amount =
1599+
withdraw_reserve.usd_to_liquidity_amount_lower_bound(max_outflow_usd_capped)?;
15981600

15991601
let max_reserve_outflow_liquidity_amount = withdraw_reserve
16001602
.rate_limiter

token-lending/program/tests/attributed_borrows.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ async fn test_refresh_obligation() {
9494
(usdc_mint::id(), 10 * FRACTIONAL_TO_USDC),
9595
(wsol_mint::id(), LAMPORTS_PER_SOL),
9696
],
97+
..Default::default()
9798
},
9899
ObligationArgs {
99100
deposits: vec![
@@ -104,6 +105,7 @@ async fn test_refresh_obligation() {
104105
(usdc_mint::id(), 100 * FRACTIONAL_TO_USDC),
105106
(wsol_mint::id(), 2 * LAMPORTS_PER_SOL),
106107
],
108+
..Default::default()
107109
},
108110
],
109111
)
@@ -232,6 +234,7 @@ async fn test_calculations() {
232234
(usdc_mint::id(), 10 * FRACTIONAL_TO_USDC),
233235
(wsol_mint::id(), LAMPORTS_PER_SOL),
234236
],
237+
..Default::default()
235238
},
236239
ObligationArgs {
237240
deposits: vec![
@@ -242,6 +245,7 @@ async fn test_calculations() {
242245
(usdc_mint::id(), 100 * FRACTIONAL_TO_USDC),
243246
(wsol_mint::id(), 2 * LAMPORTS_PER_SOL),
244247
],
248+
..Default::default()
245249
},
246250
],
247251
)
@@ -616,6 +620,7 @@ async fn test_withdraw() {
616620
(wsol_mint::id(), 2 * LAMPORTS_PER_SOL),
617621
],
618622
borrows: vec![(usdc_mint::id(), 10 * FRACTIONAL_TO_USDC)],
623+
..Default::default()
619624
}],
620625
)
621626
.await;
@@ -813,6 +818,7 @@ async fn test_liquidate() {
813818
&[ObligationArgs {
814819
deposits: vec![(usdc_mint::id(), FRACTIONAL_TO_USDC / 2)],
815820
borrows: vec![(wsol_mint::id(), LAMPORTS_PER_SOL / 40)],
821+
..Default::default()
816822
}],
817823
)
818824
.await;

token-lending/program/tests/borrow_obligation_liquidity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ async fn test_borrow_max_rate_limiter() {
565565
&[ObligationArgs {
566566
deposits: vec![(usdc_mint::id(), 100 * FRACTIONAL_TO_USDC)],
567567
borrows: vec![],
568+
..Default::default()
568569
}],
569570
)
570571
.await;

token-lending/program/tests/forgive_debt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ async fn test_forgive_debt_success_easy() {
7979
ObligationArgs {
8080
deposits: vec![(usdc_mint::id(), 20 * FRACTIONAL_TO_USDC)],
8181
borrows: vec![(wsol_mint::id(), LAMPORTS_PER_SOL)],
82+
..Default::default()
8283
},
8384
ObligationArgs {
8485
deposits: vec![(wsol_mint::id(), LAMPORTS_PER_SOL)],
8586
borrows: vec![],
87+
..Default::default()
8688
},
8789
],
8890
)
@@ -278,6 +280,7 @@ async fn test_forgive_debt_fail_invalid_signer() {
278280
&[ObligationArgs {
279281
deposits: vec![(usdc_mint::id(), 200 * FRACTIONAL_TO_USDC)],
280282
borrows: vec![(wsol_mint::id(), 10 * LAMPORTS_PER_SOL)],
283+
..Default::default()
281284
}],
282285
)
283286
.await;
@@ -379,6 +382,7 @@ async fn test_forgive_debt_fail_no_signer() {
379382
&[ObligationArgs {
380383
deposits: vec![(usdc_mint::id(), 200 * FRACTIONAL_TO_USDC)],
381384
borrows: vec![(wsol_mint::id(), 10 * LAMPORTS_PER_SOL)],
385+
..Default::default()
382386
}],
383387
)
384388
.await;

token-lending/program/tests/helpers/solend_program_test.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,17 @@ pub struct ReserveArgs {
21522152
pub struct ObligationArgs {
21532153
pub deposits: Vec<(Pubkey, u64)>,
21542154
pub borrows: Vec<(Pubkey, u64)>,
2155+
pub should_refresh: bool,
2156+
}
2157+
2158+
impl Default for ObligationArgs {
2159+
fn default() -> Self {
2160+
ObligationArgs {
2161+
deposits: vec![],
2162+
borrows: vec![],
2163+
should_refresh: true,
2164+
}
2165+
}
21552166
}
21562167

21572168
pub async fn custom_scenario(
@@ -2264,17 +2275,19 @@ pub async fn custom_scenario(
22642275
}
22652276
}
22662277

2267-
for (i, obligation_arg) in obligation_args.iter().enumerate() {
2278+
for ((obligation, obligation_owner), obligation_arg) in obligations
2279+
.iter_mut()
2280+
.zip(obligation_owners.iter_mut())
2281+
.zip(obligation_args.iter())
2282+
{
22682283
for (mint, amount) in obligation_arg.borrows.iter() {
22692284
let reserve = reserves
22702285
.iter()
22712286
.find(|reserve| reserve.account.liquidity.mint_pubkey == *mint)
22722287
.unwrap();
22732288

2274-
obligation_owners[i]
2275-
.create_token_account(mint, &mut test)
2276-
.await;
2277-
obligation_owners[i]
2289+
obligation_owner.create_token_account(mint, &mut test).await;
2290+
obligation_owner
22782291
.create_token_account(&reserve.account.collateral.mint_pubkey, &mut test)
22792292
.await;
22802293

@@ -2284,8 +2297,8 @@ pub async fn custom_scenario(
22842297
.borrow_obligation_liquidity(
22852298
&mut test,
22862299
reserve,
2287-
&obligations[i],
2288-
&obligation_owners[i],
2300+
obligation,
2301+
obligation_owner,
22892302
fee_receiver.get_account(mint),
22902303
*amount,
22912304
)
@@ -2294,7 +2307,11 @@ pub async fn custom_scenario(
22942307
}
22952308
}
22962309

2297-
for obligation in obligations.iter_mut() {
2310+
for obligation in obligations
2311+
.iter_mut()
2312+
.zip(obligation_args.iter())
2313+
.filter_map(|(obligation, arg)| arg.should_refresh.then_some(obligation))
2314+
{
22982315
lending_market
22992316
.refresh_obligation(&mut test, obligation)
23002317
.await

token-lending/program/tests/isolated_tier_assets.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ async fn test_refresh_obligation() {
7171
&[ObligationArgs {
7272
deposits: vec![(usdc_mint::id(), 100 * FRACTIONAL_TO_USDC)],
7373
borrows: vec![],
74+
..Default::default()
7475
}],
7576
)
7677
.await;
@@ -202,6 +203,7 @@ async fn borrow_isolated_asset() {
202203
&[ObligationArgs {
203204
deposits: vec![(usdc_mint::id(), 100 * FRACTIONAL_TO_USDC)],
204205
borrows: vec![],
206+
..Default::default()
205207
}],
206208
)
207209
.await;
@@ -298,6 +300,7 @@ async fn borrow_isolated_asset_invalid() {
298300
&[ObligationArgs {
299301
deposits: vec![(usdc_mint::id(), 100 * FRACTIONAL_TO_USDC)],
300302
borrows: vec![(wsol_mint::id(), 1)],
303+
..Default::default()
301304
}],
302305
)
303306
.await;
@@ -383,6 +386,7 @@ async fn borrow_regular_asset_invalid() {
383386
&[ObligationArgs {
384387
deposits: vec![(usdc_mint::id(), 100 * FRACTIONAL_TO_USDC)],
385388
borrows: vec![(bonk_mint::id(), 1)],
389+
..Default::default()
386390
}],
387391
)
388392
.await;
@@ -478,6 +482,7 @@ async fn invalid_borrow_due_to_reserve_config_change() {
478482
&[ObligationArgs {
479483
deposits: vec![(usdc_mint::id(), 100 * FRACTIONAL_TO_USDC)],
480484
borrows: vec![(bonk_mint::id(), 1), (wsol_mint::id(), LAMPORTS_PER_SOL)],
485+
..Default::default()
481486
}],
482487
)
483488
.await;

token-lending/program/tests/liquidate_obligation_and_redeem_collateral.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ async fn test_liquidity_ordering() {
627627
(wsol_mint::id(), LAMPORTS_PER_SOL),
628628
(usdc_mint::id(), FRACTIONAL_TO_USDC),
629629
],
630+
..Default::default()
630631
}],
631632
)
632633
.await;
@@ -756,6 +757,7 @@ async fn test_liquidate_closeable_obligation() {
756757
&[ObligationArgs {
757758
deposits: vec![(usdc_mint::id(), 20 * FRACTIONAL_TO_USDC)],
758759
borrows: vec![(wsol_mint::id(), LAMPORTS_PER_SOL)],
760+
..Default::default()
759761
}],
760762
)
761763
.await;

token-lending/program/tests/mark_obligation_as_closeable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ async fn test_mark_obligation_as_closeable_success() {
6161
&[ObligationArgs {
6262
deposits: vec![(usdc_mint::id(), 20 * FRACTIONAL_TO_USDC)],
6363
borrows: vec![(wsol_mint::id(), LAMPORTS_PER_SOL)],
64+
..Default::default()
6465
}],
6566
)
6667
.await;
@@ -176,6 +177,7 @@ async fn invalid_signer() {
176177
&[ObligationArgs {
177178
deposits: vec![(usdc_mint::id(), 20 * FRACTIONAL_TO_USDC)],
178179
borrows: vec![(wsol_mint::id(), LAMPORTS_PER_SOL)],
180+
..Default::default()
179181
}],
180182
)
181183
.await;

token-lending/program/tests/refresh_obligation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ async fn test_obligation_liquidity_ordering() {
399399
(usdc_mint::id(), 1),
400400
(bonk_mint::id(), 1),
401401
],
402+
..Default::default()
402403
}],
403404
)
404405
.await;

0 commit comments

Comments
 (0)