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

Two Prices PR #129

Merged
merged 11 commits into from
Feb 24, 2023
Merged

Two Prices PR #129

merged 11 commits into from
Feb 24, 2023

Conversation

0xripleys
Copy link

@0xripleys 0xripleys commented Feb 22, 2023

Main Changes

  • Add a smoothed_market_price to Reserve that is used to limit borrows and withdraws in cases where smoothed price and spot price diverge.
  • allowed_borrow_value now uses the min(smoothed_market_price, current spot price)
  • new field on obligation called borrowed_value_upper_bound that uses max(smoothed_market_price, current spot price)

Affected instructions

Refresh Reserve

  • special case handilng for switchboard-only reserves
  • for reserves that use pyth, the smoothed price field only gets updated when the pyth key is given
  • for reserves that only use switchboard, the smooth price field gets set to the market price, essentially making this PR useless for switchboard-only reserves

Refresh Obligation

  • modified ways to calculate allowed borrow value
  • add new field to calculate borrowed_value_upper_bound

Withdraw Obligation Collateral + Withdraw Obligation Collateral and Redeem Reserve Liquidity

  • the amount you can withdraw must be inversely related to (allowed borrow value - borrowed value upper bound)

Borrow Obligation Liquidity

  • need to use the max(spot price, ema price) to calculate max borrow amount

Note that liquidations still using current spot prices and have no dependence on the new smoothed_price value or borrowed_value_upper_bound

@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2023

Codecov Report

❗ No coverage uploaded for pull request base (v2_upcoming@debaf17). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 7a0c9c2 differs from pull request most recent head f49ff13. Consider uploading reports for the commit f49ff13 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@              Coverage Diff               @@
##             v2_upcoming     #129   +/-   ##
==============================================
  Coverage               ?   82.88%           
==============================================
  Files                  ?       44           
  Lines                  ?    14809           
  Branches               ?        0           
==============================================
  Hits                   ?    12275           
  Misses                 ?     2534           
  Partials               ?        0           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

/// Risk-adjusted upper bound market value of borrows.
/// ie sum(b.borrowed_amount * max(b.current_spot_price, b.smoothed_price) * b.borrow_weight for b in borrows)
pub borrowed_value_upper_bound: Decimal,
/// The maximum borrow value at the weighted average loan to value ratio using the minimum of
Copy link
Member

Choose a reason for hiding this comment

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

the maximum borrow value using min of spot and smooth price times ltv of each asset

something closer to this?

let remaining_borrow_value = obligation.remaining_borrow_value()?;
let remaining_borrow_value = obligation
.remaining_borrow_value()
.unwrap_or_else(|_| 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.

this wil just error on the next line

@0xripleys 0xripleys marked this pull request as ready for review February 24, 2023 21:01
@0xripleys 0xripleys force-pushed the 0xripleys_two_prices branch from 7a0c9c2 to f49ff13 Compare February 24, 2023 21:24
@0xripleys 0xripleys changed the base branch from 0xripleys_borrow_coefficient to v2_upcoming February 24, 2023 21:24
@0xripleys 0xripleys merged commit 9e4711e into v2_upcoming Feb 24, 2023
0xripleys added a commit to 0xripleys/solana-program-library that referenced this pull request Mar 7, 2023
- Add a smoothed_market_price to Reserve that is used to limit borrows and withdraws in cases where smoothed price and spot price diverge.
- allowed_borrow_value now uses the min(smoothed_market_price, current spot price)
- new field on obligation called borrowed_value_upper_bound that uses max(smoothed_market_price, current spot price)
nope-finance pushed a commit that referenced this pull request Mar 28, 2023
* 0xripleys outflow limits (#125)

Use a sliding window rate limiter to limit borrows and withdraws at the lending pool owner's discretion.

* 0xripleys borrow coefficient (#127)

Add a borrow weight to the Reserve

* Two Prices PR (#129)

- Add a smoothed_market_price to Reserve that is used to limit borrows and withdraws in cases where smoothed price and spot price diverge.
- allowed_borrow_value now uses the min(smoothed_market_price, current spot price)
- new field on obligation called borrowed_value_upper_bound that uses max(smoothed_market_price, current spot price)

* audit nits

* audit fixes pt 2

* disable rate limiter if window duration == 0

* cli changes for v2.0.1 (#133)
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