This repository was archived by the owner on Mar 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
token-lending/program/src Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -1002,7 +1002,9 @@ fn process_withdraw_obligation_collateral(
1002
1002
msg ! ( "Obligation deposited value is zero" ) ;
1003
1003
return Err ( LendingError :: ObligationDepositsZero . into ( ) ) ;
1004
1004
} else {
1005
- let max_withdraw_value = obligation. max_withdraw_value ( ) ?;
1005
+ let max_withdraw_value = obligation. max_withdraw_value ( Rate :: from_percent (
1006
+ withdraw_reserve. config . loan_to_value_ratio ,
1007
+ ) ) ?;
1006
1008
if max_withdraw_value == Decimal :: zero ( ) {
1007
1009
msg ! ( "Maximum withdraw value is zero" ) ;
1008
1010
return Err ( LendingError :: WithdrawTooLarge . into ( ) ) ;
Original file line number Diff line number Diff line change @@ -91,15 +91,19 @@ impl Obligation {
91
91
}
92
92
93
93
/// Calculate the maximum collateral value that can be withdrawn
94
- pub fn max_withdraw_value ( & self ) -> Result < Decimal , ProgramError > {
95
- let required_deposit_value = self
96
- . borrowed_value
97
- . try_mul ( self . deposited_value ) ?
98
- . try_div ( self . allowed_borrow_value ) ?;
99
- if required_deposit_value >= self . deposited_value {
94
+ pub fn max_withdraw_value (
95
+ & self ,
96
+ withdraw_collateral_ltv : Rate ,
97
+ ) -> Result < Decimal , ProgramError > {
98
+ if self . allowed_borrow_value <= self . borrowed_value {
100
99
return Ok ( Decimal :: zero ( ) ) ;
101
100
}
102
- self . deposited_value . try_sub ( required_deposit_value)
101
+ if withdraw_collateral_ltv == Rate :: zero ( ) {
102
+ return Ok ( self . deposited_value ) ;
103
+ }
104
+ self . allowed_borrow_value
105
+ . try_sub ( self . borrowed_value ) ?
106
+ . try_div ( withdraw_collateral_ltv)
103
107
}
104
108
105
109
/// Calculate the maximum liquidity value that can be borrowed
You can’t perform that action at this time.
0 commit comments