Skip to content
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

Collateralization Limits Part 2 #172

Merged
merged 7 commits into from
Dec 16, 2023
Merged

Conversation

0xripleys
Copy link

@0xripleys 0xripleys commented Dec 1, 2023

Summary:

  1. allow lending market owner or risk authority to mark obligations as closeable.
  2. Modify liquidate instruction to handle liquidating "closeable" obligations. These obligations are closed without penalty.

@codecov-commenter
Copy link

codecov-commenter commented Dec 1, 2023

Codecov Report

Attention: 27 lines in your changes are missing coverage. Please review.

Comparison is base (e0807ca) 83.98% compared to head (b5c88a3) 84.42%.

Files Patch % Lines
token-lending/program/src/processor.rs 85.96% 16 Missing ⚠️
token-lending/cli/src/main.rs 0.00% 6 Missing ⚠️
token-lending/sdk/src/state/reserve.rs 97.14% 4 Missing ⚠️
token-lending/sdk/src/instruction.rs 98.27% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@                     Coverage Diff                      @@
##           collateralization_limits     #172      +/-   ##
============================================================
+ Coverage                     83.98%   84.42%   +0.44%     
============================================================
  Files                            51       52       +1     
  Lines                         19826    20524     +698     
============================================================
+ Hits                          16650    17327     +677     
- Misses                         3176     3197      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -3115,6 +3136,84 @@ pub fn process_resize_reserve(_program_id: &Pubkey, accounts: &[AccountInfo]) ->
Ok(())
}

/// process mark obligation as closable
pub fn process_mark_obligation_as_closeable(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ig remove expiry time and change this to "set obligation close ability status"

update_borrow_attribution_values(&mut obligation, &accounts[1..], false)?;

// unmark obligation as closable after it's been liquidated enough times
if obligation.is_closeable(clock.slot) && !any_borrow_attribution_limit_exceeded {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close vs open attribution limits

return Err(LendingError::ObligationStale.into());
}

if &lending_market.risk_authority != risk_authority_info.key {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or owner

if obligation.borrowed_value < obligation.unhealthy_borrow_value {
if obligation.is_closeable(current_slot) {
return Ok(Decimal::zero());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think gotta remove the protocol liquidation fee too

@0xripleys
Copy link
Author

actually i don't think we need the init flag. the obligation collateral's borrow attribution value on upgrade will be zero, so the subtraction is useless anyways.

@@ -3185,13 +3192,14 @@ pub fn process_mark_obligation_as_closeable(
return Err(LendingError::ObligationStale.into());
}

if &lending_market.risk_authority != risk_authority_info.key {
if &lending_market.risk_authority != signer_info.key && &lending_market.owner != signer_info.key
{
msg!("Lending market risk authority does not match the risk authority provided");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update msg

&self,
obligation: &Obligation,
current_slot: Slot,
) -> Result<Decimal, ProgramError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets just return the protocol liquidation fee here and save self from re-serializing later

@0xripleys 0xripleys changed the title (WIP) Collateralization Limits Part 2 Collateralization Limits Part 2 Dec 11, 2023
@0xripleys 0xripleys merged commit 922ee1d into collateralization_limits Dec 16, 2023
6 checks passed
0xripleys added a commit that referenced this pull request Dec 17, 2023
* closable instruction

* add more tests around signer

* liquidate closeable obligations

* test fix

* pr fixes

* adding a close borrow attribution limit

* PR fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants