Skip to content

Commit 8f6f9bc

Browse files
committed
further restrict constituent max borrow
1 parent 631c962 commit 8f6f9bc

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

programs/drift/src/instructions/lp_pool.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,16 @@ fn transfer_from_program_vault<'info>(
15881588

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

1591-
let max_transfer = constituent.get_max_transfer(&spot_market)?;
1591+
let max_transfer = constituent
1592+
.max_borrow_token_amount
1593+
.cast::<i128>()?
1594+
.safe_add(
1595+
constituent
1596+
.spot_balance
1597+
.get_signed_token_amount(spot_market)?,
1598+
)?
1599+
.max(0)
1600+
.cast::<u64>()?;
15921601

15931602
validate!(
15941603
max_transfer >= amount,

programs/drift/src/state/lp_pool.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -978,19 +978,6 @@ impl Constituent {
978978
bytemuck::bytes_of(bump),
979979
]
980980
}
981-
982-
pub fn get_max_transfer(&self, spot_market: &SpotMarket) -> DriftResult<u64> {
983-
let token_amount = self.get_full_token_amount(spot_market)?;
984-
let max_transfer = if token_amount < 0 {
985-
self.max_borrow_token_amount
986-
.saturating_sub(token_amount.abs().cast::<u64>()?)
987-
} else {
988-
self.max_borrow_token_amount
989-
.saturating_add(token_amount.abs().cast::<u64>()?)
990-
};
991-
992-
Ok(max_transfer)
993-
}
994981
}
995982

996983
#[zero_copy]

tests/lpPool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ describe('LP Pool', () => {
15711571
);
15721572
} catch (e) {
15731573
console.log(e);
1574-
assert(e.toString().includes('0x18b9')); // invariant failed
1574+
assert(e.toString().includes('0x18c1')); // invariant failed
15751575
}
15761576
});
15771577

0 commit comments

Comments
 (0)