@@ -117,71 +117,4 @@ impl PriceFeed {
117
117
expo : self . expo ,
118
118
} )
119
119
}
120
-
121
- /// Get the current price of this account in a different quote currency.
122
- ///
123
- /// If this account represents the price of the product X/Z, and `quote` represents the price
124
- /// of the product Y/Z, this method returns the price of X/Y. Use this method to get the
125
- /// price of e.g., mSOL/SOL from the mSOL/USD and SOL/USD accounts.
126
- ///
127
- /// `result_expo` determines the exponent of the result, i.e., the number of digits below the
128
- /// decimal point. This method returns `None` if either the price or confidence are too
129
- /// large to be represented with the requested exponent.
130
- ///
131
- /// Example:
132
- /// ```ignore
133
- /// let btc_usd: PriceFeed = ...;
134
- /// let eth_usd: PriceFeed = ...;
135
- /// // -8 is the desired exponent for the result
136
- /// let btc_eth: Price = btc_usd.get_price_in_quote(ð_usd, -8);
137
- /// println!("BTC/ETH price: ({} +- {}) x 10^{}", price.price, price.conf, price.expo);
138
- /// ```
139
- pub fn get_price_in_quote ( & self , quote : & PriceFeed , result_expo : i32 ) -> Option < Price > {
140
- match ( self . get_current_price ( ) , quote. get_current_price ( ) ) {
141
- ( Some ( base_price_conf) , Some ( quote_price_conf) ) => base_price_conf
142
- . div ( & quote_price_conf) ?
143
- . scale_to_exponent ( result_expo) ,
144
- ( _, _) => None ,
145
- }
146
- }
147
-
148
- /// Get the price of a basket of currencies.
149
- ///
150
- /// Each entry in `amounts` is of the form `(price, qty, qty_expo)`, and the result is the sum
151
- /// of `price * qty * 10^qty_expo`. The result is returned with exponent `result_expo`.
152
- ///
153
- /// An example use case for this function is to get the value of an LP token.
154
- ///
155
- /// Example:
156
- /// ```ignore
157
- /// let btc_usd: PriceFeed = ...;
158
- /// let eth_usd: PriceFeed = ...;
159
- /// // Quantity of each asset in fixed-point a * 10^e.
160
- /// // This represents 0.1 BTC and .05 ETH.
161
- /// // -8 is desired exponent for result
162
- /// let basket_price: Price = Price::price_basket(&[
163
- /// (btc_usd, 10, -2),
164
- /// (eth_usd, 5, -2)
165
- /// ], -8);
166
- /// println!("0.1 BTC and 0.05 ETH are worth: ({} +- {}) x 10^{} USD",
167
- /// basket_price.price, basket_price.conf, basket_price.expo);
168
- /// ```
169
- pub fn price_basket ( amounts : & [ ( PriceFeed , i64 , i32 ) ] , result_expo : i32 ) -> Option < Price > {
170
- assert ! ( amounts. len( ) > 0 ) ;
171
- let mut res = Price {
172
- price : 0 ,
173
- conf : 0 ,
174
- expo : result_expo,
175
- } ;
176
- for i in 0 ..amounts. len ( ) {
177
- res = res. add (
178
- & amounts[ i]
179
- . 0
180
- . get_current_price ( ) ?
181
- . cmul ( amounts[ i] . 1 , amounts[ i] . 2 ) ?
182
- . scale_to_exponent ( result_expo) ?,
183
- ) ?
184
- }
185
- Some ( res)
186
- }
187
120
}
0 commit comments