Skip to content

Commit fe07d1e

Browse files
authored
program: update-max-borrow-token-amount-deltas (#1801)
* program: update-max-borrow-token-amount-deltas * fix tests * sdk match * update changelog
1 parent 9396e23 commit fe07d1e

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Features
1111

12+
- program: update max borrow delta/utilization thresholds ([#1760](https://github.com/drift-labs/protocol-v2/pull/1801))
13+
1214
### Fixes
1315

1416
### Breaking
@@ -18,13 +20,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1820
### Features
1921

2022
### Fixes
23+
2124
- program: update-fee-tier-validates ([#1798](https://github.com/drift-labs/protocol-v2/pull/1798))
2225

2326
### Breaking
2427

2528
## [2.131.0] - 2025-08-04
2629

2730
### Features
31+
2832
- program: update stake + volume fee tier determination ([#1792](https://github.com/drift-labs/protocol-v2/pull/1792))
2933

3034
### Fixes

programs/drift/src/controller/spot_balance/tests.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ fn test_check_withdraw_limits() {
489489
0,
490490
)
491491
.unwrap();
492-
assert_eq!(mbt, 642857);
492+
assert_eq!(mbt, 700000);
493493

494494
let valid_withdraw = check_withdraw_limits(&spot_market, Some(&user), Some(0)).unwrap();
495495
assert!(valid_withdraw);
@@ -578,7 +578,7 @@ fn test_check_withdraw_limits_below_optimal_utilization() {
578578
assert_eq!(mdt_dep, 153000000000000);
579579

580580
assert_eq!(max_bor, 142800000000000);
581-
assert_eq!(mbt_bor, 151342857142857);
581+
assert_eq!(mbt_bor, 163000000000000);
582582

583583
let valid_withdraw = check_withdraw_limits(&sol_spot_market, None, None).unwrap();
584584
assert_eq!(valid_withdraw, true);
@@ -626,17 +626,17 @@ fn test_check_withdraw_limits_above_optimal_utilization() {
626626
initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10,
627627
maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10,
628628
deposit_balance: 200_000 * SPOT_BALANCE_PRECISION, // 200k sol
629-
borrow_balance: 155_000 * SPOT_BALANCE_PRECISION,
629+
borrow_balance: 160_000 * SPOT_BALANCE_PRECISION,
630630
liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000,
631631
deposit_token_twap: 204000000000000_u64,
632-
borrow_token_twap: 192200000000000_u64,
633-
utilization_twap: 890000, // 89%
632+
borrow_token_twap: 199200000000000_u64,
633+
utilization_twap: 929000, // 92.9%
634634
status: MarketStatus::Active,
635635

636636
..SpotMarket::default()
637637
};
638638

639-
assert_eq!(sol_spot_market.get_utilization().unwrap(), 928480);
639+
assert_eq!(sol_spot_market.get_utilization().unwrap(), 958431);
640640
assert!(
641641
sol_spot_market.get_utilization().unwrap() > sol_spot_market.optimal_utilization as u128
642642
); // below optimal util
@@ -673,14 +673,14 @@ fn test_check_withdraw_limits_above_optimal_utilization() {
673673
.unwrap();
674674

675675
assert_eq!(deposit_tokens_1, 204000000000000);
676-
assert_eq!(borrow_tokens_1, 189410000000000);
676+
assert_eq!(borrow_tokens_1, 195520000000000);
677677

678678
// utilization bands differ from others
679-
assert_eq!(min_dep, 200433862433862);
679+
assert_eq!(min_dep, 202716433385173);
680680
assert_eq!(mdt_dep, 153000000000000);
681681

682-
assert_eq!(max_bor, 192780000000000);
683-
assert_eq!(mbt_bor, 178500000000000);
682+
assert_eq!(max_bor, 196758000000000);
683+
assert_eq!(mbt_bor, 189428571428572);
684684

685685
// without passing a user, since borrows are above the built in limit of 80% will fail
686686
let valid_withdraw = check_withdraw_limits(&sol_spot_market, None, None).unwrap();

programs/drift/src/math/spot_withdraw.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ pub fn calculate_max_borrow_token_amount(
3939
let lesser_deposit_amount = deposit_token_amount.min(deposit_token_twap);
4040

4141
let max_borrow_token = if pool_id == 0 {
42-
// main pool between ~30-87.5% utilization with friction on twap in 14% increments
42+
// main pool between ~30-92.5% utilization with friction on twap in 20% increments
4343

4444
withdraw_guard_threshold
4545
.max(
4646
(lesser_deposit_amount / 3)
47-
.max(borrow_token_twap.safe_add(lesser_deposit_amount / 7)?)
48-
.min(lesser_deposit_amount.safe_sub(lesser_deposit_amount / 8)?),
47+
.max(borrow_token_twap.safe_add(lesser_deposit_amount / 5)?)
48+
.min(lesser_deposit_amount.safe_sub(lesser_deposit_amount / 14)?),
4949
)
5050
.min(max_token_borrows)
5151
} else {
52-
// isolated pools between 50-90% utilization with friction on twap in 33% increments
52+
// isolated pools between 50-95% utilization with friction on twap in 33% increments
5353
withdraw_guard_threshold
5454
.max(
5555
(lesser_deposit_amount / 2)
5656
.max(borrow_token_twap.safe_add(lesser_deposit_amount / 3)?)
57-
.min(lesser_deposit_amount.safe_sub(lesser_deposit_amount / 10)?),
57+
.min(lesser_deposit_amount.safe_sub(lesser_deposit_amount / 20)?),
5858
)
5959
.min(max_token_borrows)
6060
};

sdk/src/math/spotBalance.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ export function calculateWithdrawLimit(
593593
),
594594
lesserDepositAmount.sub(lesserDepositAmount.div(new BN(8)))
595595
)
596-
); // main pool between ~15-80% utilization with 10% friction on twap
596+
); // main pool between ~30-92.5% utilization with friction on twap in 20% increments
597597
} else {
598598
maxBorrowTokensTwap = BN.max(
599599
spotMarket.withdrawGuardThreshold,
@@ -602,9 +602,9 @@ export function calculateWithdrawLimit(
602602
marketDepositTokenAmount.div(new BN(2)),
603603
borrowTokenTwapLive.add(lesserDepositAmount.div(new BN(3)))
604604
),
605-
lesserDepositAmount.sub(lesserDepositAmount.div(new BN(10)))
605+
lesserDepositAmount.sub(lesserDepositAmount.div(new BN(20)))
606606
)
607-
); // isolated pool between ~50-90% utilization with 33% friction on twap
607+
); // isolated pools between 50-95% utilization with friction on twap in 33% increments
608608
}
609609

610610
const minDepositTokensTwap = depositTokenTwapLive.sub(

0 commit comments

Comments
 (0)