Skip to content

Commit da61528

Browse files
authored
improve some documentation
1 parent 483069c commit da61528

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

pyth-sdk/README.md

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,21 @@ println!("0.1 BTC and 0.05 ETH are worth: ({} +- {}) x 10^{} USD",
8282

8383
This operation can be useful for pricing, e.g., an LP token that is backed by two underlying currencies.
8484

85-
## Liquidity-related Pricing Measures
85+
## Adjust Prices using Liquidity
8686

87-
A variety of measures should be taken for protocols looking to mitigate liquidity-related risks. To limit deposits and borrows, protocols could simply derive their limit from the off-chain liquidity estimates and then store those values in contract state. No explicit interaction with the Pyth SDK would be needed in this simple case.
88-
89-
To adjust the price at which collateral is valued based on the liquidity information, a protocol can combine the current Pyth price and their estimate of liquidity:
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:
9088

9189
```rust
9290
let btc_usd: Price = ...;
93-
let deposits: u64 = ...;
94-
let deposits_endpoint: u64 = ...;
95-
let rate_discount_initial: u64 = ...;
96-
let rate_discount_final: u64 = ...;
97-
let discount_exponent: i32 = ...;
91+
// deposits is the total number of tokens deposited in the protocol
92+
let deposits: u64 = 100;
93+
// deposits_endpoint represents the token deposits at which rate_discount_final kicks in
94+
let deposits_endpoint: u64 = 1000;
95+
// rate_discount_initial and _final are percentages, expressed in fixed point as x * 10^discount_exponent.
96+
// E.g. 50 with discount_exponent = -2 is 50%.
97+
let rate_discount_initial: u64 = 100;
98+
let rate_discount_final: u64 = 90;
99+
let discount_exponent: i32 = 2;
98100

99101
let price_collateral: Price = btc_usd.get_collateral_valuation_price(
100102
deposits,
@@ -106,24 +108,6 @@ println!("The valuation price for the collateral given {} tokens deposited is ({
106108
deposits, price_collateral.price, price_collateral.conf, price_collateral.expo);
107109
```
108110

109-
Here, `deposits` indicates the total amount of collateral deposited. `get_collateral_valuation_price` takes in the total deposits in the protocol and interpolates between (`0`, `rate_discount_inital`) and (`deposits_endpoint`, `rate_discount_final`) to linearly caclulate 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.
110-
111-
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:
111+
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.
112112

113-
```rust
114-
let btc_usd: Price = ...;
115-
let borrows: u64 = ...;
116-
let borrows_endpoint: u64 = ...;
117-
let rate_premium_initial: u64 = ...;
118-
let rate_premium_final: u64 = ...;
119-
let premium_exponent: i32 = ...;
120-
121-
let price_borrow: Price = btc_usd.get_borrow_valuation_price(
122-
borrows,
123-
borrows_endpoint,
124-
rate_premium_initial,
125-
rate_premium_final,
126-
premium_exponent).ok_or(StdError::not_found("Issue with querying borrow price"))?;
127-
println!("The valuation price for the borrow given {} tokens borrowed is ({} +- {}) x 10^{} USD",
128-
borrows, price_borrow.price, price_borrow.conf, price_borrow.expo);
129-
```
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

Comments
 (0)