forked from solana-labs/solana-program-library
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Liquidation protocol fee #71
Closed
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ccd0198
add reserve fields + update pack and unpack
7fed6b3
update cli
d3d9746
comment
cdb807f
add protocol fee to liquidate
592383f
formatting
aa7dc32
update cli
0d962c8
use saturating sub
610cd46
tests
nope-finance da28ec9
add claim protocol fees
d657f7d
account checks
49fe464
ClaimProtocolFees -> ClaimReserveProtocolFees
06c9f8b
debug comments
5ccba68
formatting(again)
cac0a8a
comments
ba6b3c6
validate protocol liquidation fee
706777f
fix oopsie that i did earlier with update reserve config
caf51c0
tests
24b2b1b
formatting
4937344
make sure liquidations accumulate protocol fees
56e61d2
make liquidation protocol fee in terms of base liquidity token
2fd17da
adding claim check at end of liquidation test, cleaning up claim inst…
nope-finance 17ac101
pr comments
nope-finance File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
add reserve fields + update pack and unpack
- Loading branch information
commit ccd0198b2ad68adad5a70107444db13a4207203e
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,6 +290,14 @@ impl Reserve { | |
} | ||
} | ||
|
||
/* | ||
psuedo code for liquidation protocol fee | ||
let mut protocol_fee_amount = withdraw_amount.checked_div(liquidation_pct)?.checked_mul(protocol_fee)?; | ||
if protocol_fee_amount == 0 { | ||
protocol_fee_amount = 1; | ||
} | ||
let withdraw_fee = withdraw_amount.checked_sub(protocol_fee_amount)?;*/ | ||
|
||
Ok(CalculateLiquidationResult { | ||
settle_amount, | ||
repay_amount, | ||
|
@@ -363,6 +371,8 @@ pub struct ReserveLiquidity { | |
pub available_amount: u64, | ||
/// Reserve liquidity borrowed | ||
pub borrowed_amount_wads: Decimal, | ||
/// Reserve accumulated protocol fees to claim | ||
pub accumulated_protocol_fees: Decimal, | ||
/// Reserve liquidity cumulative borrow rate | ||
pub cumulative_borrow_rate_wads: Decimal, | ||
/// Reserve liquidity market price in quote currency | ||
|
@@ -380,6 +390,7 @@ impl ReserveLiquidity { | |
switchboard_oracle_pubkey: params.switchboard_oracle_pubkey, | ||
available_amount: 0, | ||
borrowed_amount_wads: Decimal::zero(), | ||
accumulated_protocol_fees: Decimal::zero(), | ||
cumulative_borrow_rate_wads: Decimal::one(), | ||
market_price: params.market_price, | ||
} | ||
|
@@ -599,6 +610,8 @@ pub struct ReserveConfig { | |
pub loan_to_value_ratio: u8, | ||
/// Bonus a liquidator gets when repaying part of an unhealthy obligation, as a percentage | ||
pub liquidation_bonus: u8, | ||
// Cut of the liquidation bonus that the protocol receives | ||
pub protocol_liquidation_fee: u8, | ||
/// Loan to value ratio at which an obligation can be liquidated, as a percentage | ||
pub liquidation_threshold: u8, | ||
/// Min borrow APY | ||
|
@@ -763,7 +776,9 @@ impl Pack for Reserve { | |
config_deposit_limit, | ||
config_borrow_limit, | ||
config_fee_receiver, | ||
config_protocol_liquidation_fee, | ||
_padding, | ||
liquidity_accumulated_protocol_fees, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we doing it like this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than? |
||
) = mut_array_refs![ | ||
output, | ||
1, | ||
|
@@ -795,7 +810,9 @@ impl Pack for Reserve { | |
8, | ||
8, | ||
PUBKEY_BYTES, | ||
248 | ||
1, | ||
231, | ||
16 | ||
]; | ||
|
||
// reserve | ||
|
@@ -816,6 +833,10 @@ impl Pack for Reserve { | |
self.liquidity.borrowed_amount_wads, | ||
liquidity_borrowed_amount_wads, | ||
); | ||
pack_decimal( | ||
self.liquidity.accumulated_protocol_fees, | ||
liquidity_accumulated_protocol_fees, | ||
); | ||
pack_decimal( | ||
self.liquidity.cumulative_borrow_rate_wads, | ||
liquidity_cumulative_borrow_rate_wads, | ||
|
@@ -831,6 +852,7 @@ impl Pack for Reserve { | |
*config_optimal_utilization_rate = self.config.optimal_utilization_rate.to_le_bytes(); | ||
*config_loan_to_value_ratio = self.config.loan_to_value_ratio.to_le_bytes(); | ||
*config_liquidation_bonus = self.config.liquidation_bonus.to_le_bytes(); | ||
*config_protocol_liquidation_fee = self.config.protocol_liquidation_fee.to_le_bytes(); | ||
*config_liquidation_threshold = self.config.liquidation_threshold.to_le_bytes(); | ||
*config_min_borrow_rate = self.config.min_borrow_rate.to_le_bytes(); | ||
*config_optimal_borrow_rate = self.config.optimal_borrow_rate.to_le_bytes(); | ||
|
@@ -877,7 +899,9 @@ impl Pack for Reserve { | |
config_deposit_limit, | ||
config_borrow_limit, | ||
config_fee_receiver, | ||
config_protocol_liquidation_fee, | ||
_padding, | ||
liquidity_accumulated_protocol_fees, | ||
) = array_refs![ | ||
input, | ||
1, | ||
|
@@ -909,7 +933,9 @@ impl Pack for Reserve { | |
8, | ||
8, | ||
PUBKEY_BYTES, | ||
248 | ||
1, | ||
231, | ||
16 | ||
]; | ||
|
||
let version = u8::from_le_bytes(*version); | ||
|
@@ -935,6 +961,7 @@ impl Pack for Reserve { | |
), | ||
available_amount: u64::from_le_bytes(*liquidity_available_amount), | ||
borrowed_amount_wads: unpack_decimal(liquidity_borrowed_amount_wads), | ||
accumulated_protocol_fees: unpack_decimal(liquidity_accumulated_protocol_fees), | ||
cumulative_borrow_rate_wads: unpack_decimal(liquidity_cumulative_borrow_rate_wads), | ||
market_price: unpack_decimal(liquidity_market_price), | ||
}, | ||
|
@@ -947,6 +974,7 @@ impl Pack for Reserve { | |
optimal_utilization_rate: u8::from_le_bytes(*config_optimal_utilization_rate), | ||
loan_to_value_ratio: u8::from_le_bytes(*config_loan_to_value_ratio), | ||
liquidation_bonus: u8::from_le_bytes(*config_liquidation_bonus), | ||
protocol_liquidation_fee: u8::from_le_bytes(*config_protocol_liquidation_fee), | ||
liquidation_threshold: u8::from_le_bytes(*config_liquidation_threshold), | ||
min_borrow_rate: u8::from_le_bytes(*config_min_borrow_rate), | ||
optimal_borrow_rate: u8::from_le_bytes(*config_optimal_borrow_rate), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't enforcing a minimum protocol fee amount completely disincentive liquidators from liquidating sufficiently small liquidations?
I know they don't really go after the small ones anyway, but it seems like we might not want to have 0 incentivize liquidation opportunities maybe?
idk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the liquidation will fail if withdraw_amount is 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this only affects the smallest of liquidations, which no one is incentivized to do anyway. wont liquidations already fail if withdraw amount is 0? (if you look in processor)