Skip to content

Commit 60a9231

Browse files
committed
introduce max borrow buffer
1 parent ede599b commit 60a9231

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

programs/drift/src/instructions/lp_pool.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,24 +1588,27 @@ fn transfer_from_program_vault<'info>(
15881588

15891589
let balance_before = constituent.get_full_token_amount(&spot_market)?;
15901590

1591-
// Adding some 1% flexibility to max threshold to prevent race conditions
1591+
// Adding some 5% flexibility to max threshold to prevent race conditions
1592+
let buffer = constituent
1593+
.max_borrow_token_amount
1594+
.safe_mul(5)?
1595+
.safe_div(100)?;
15921596
let max_transfer = constituent
15931597
.max_borrow_token_amount
1598+
.safe_add(buffer)?
15941599
.cast::<i128>()?
15951600
.safe_add(
15961601
constituent
15971602
.spot_balance
15981603
.get_signed_token_amount(spot_market)?,
15991604
)?
16001605
.max(0)
1601-
.safe_mul(101)?
1602-
.safe_div(100)?
16031606
.cast::<u64>()?;
16041607

16051608
validate!(
16061609
max_transfer >= amount,
16071610
ErrorCode::LpInvariantFailed,
1608-
"Max transfer ({} is less than amount ({})",
1611+
"Max transfer ({}) is less than amount ({})",
16091612
max_transfer,
16101613
amount
16111614
)?;

0 commit comments

Comments
 (0)