You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pyth-sdk/README.md
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -81,3 +81,33 @@ println!("0.1 BTC and 0.05 ETH are worth: ({} +- {}) x 10^{} USD",
81
81
```
82
82
83
83
This operation can be useful for pricing, e.g., an LP token that is backed by two underlying currencies.
84
+
85
+
## Adjust Prices using Liquidity
86
+
87
+
Applications can adjust Pyth prices to incorporate market impact and liquidity for large positions, since the effective transaction price for large positions differs from the midprice and top-of-book price. Suppose the application wants to value the effective execution price on selling 100 BTC, based on the fact that 1000 BTC sell at a 10% discount (90% of the midprice). Based on assuming the market impact is constant with respect to amount sold, the application can combine the current Pyth price and its liquidity views to calculate the adjusted price:
88
+
89
+
```rust
90
+
letbtc_usd:Price=...;
91
+
// deposits is the total number of tokens deposited in the protocol
92
+
letdeposits:u64=100;
93
+
// deposits_endpoint represents the token deposits at which rate_discount_final kicks in
94
+
letdeposits_endpoint:u64=1000;
95
+
// rate_discount_initial and _final are percentages, expressed in fixed point as x * 10^discount_exponent.
Here, `deposits` indicates the total amount of collateral deposited. `get_collateral_valuation_price` takes in the total deposits in the protocol and linearly interpolates between (`0`, `rate_discount_inital`) and (`deposits_endpoint`, `rate_discount_final`) to calculate the discount at `deposits`. As a note, this function scales the price depending on the provided discount and deposit inputs, but it does not alter the confidence.
112
+
113
+
To adjust the price at which a borrow position is valued, a protocol can similarly combine the current Pyth price and their estimate of liquidity, but using the `get_borrow_valuation_price` function now in place of `get_collateral_valuation_price`.
0 commit comments