File tree Expand file tree Collapse file tree 1 file changed +6
-24
lines changed
programs/drift/src/controller Expand file tree Collapse file tree 1 file changed +6
-24
lines changed Original file line number Diff line number Diff line change @@ -237,38 +237,20 @@ pub fn update_spreads(market: &mut PerpMarket, reserve_price: u64) -> DriftResul
237
237
} ;
238
238
239
239
if market. amm . amm_spread_adjustment < 0 {
240
+ let adjustment = market. amm . amm_spread_adjustment . unsigned_abs ( ) . cast ( ) ?;
240
241
long_spread = long_spread
241
- . saturating_sub (
242
- long_spread
243
- . safe_mul ( market. amm . amm_spread_adjustment . unsigned_abs ( ) . cast ( ) ?)
244
- . unwrap_or ( u32:: MAX )
245
- . safe_div ( 100 ) ?,
246
- )
242
+ . saturating_sub ( long_spread. saturating_mul ( adjustment) . safe_div ( 100 ) ?)
247
243
. max ( 1 ) ;
248
244
short_spread = short_spread
249
- . saturating_sub (
250
- short_spread
251
- . safe_mul ( market. amm . amm_spread_adjustment . unsigned_abs ( ) . cast ( ) ?)
252
- . unwrap_or ( u32:: MAX )
253
- . safe_div ( 100 ) ?,
254
- )
245
+ . saturating_sub ( short_spread. saturating_mul ( adjustment) . safe_div ( 100 ) ?)
255
246
. max ( 1 ) ;
256
247
} else if market. amm . amm_spread_adjustment > 0 {
248
+ let adjustment = market. amm . amm_spread_adjustment . cast ( ) ?;
257
249
long_spread = long_spread
258
- . saturating_add (
259
- long_spread
260
- . safe_mul ( market. amm . amm_spread_adjustment . cast ( ) ?)
261
- . unwrap_or ( u32:: MAX )
262
- . safe_div_ceil ( 100 ) ?,
263
- )
250
+ . saturating_add ( long_spread. saturating_mul ( adjustment) . safe_div_ceil ( 100 ) ?)
264
251
. max ( 1 ) ;
265
252
short_spread = short_spread
266
- . saturating_add (
267
- short_spread
268
- . safe_mul ( market. amm . amm_spread_adjustment . cast ( ) ?)
269
- . unwrap_or ( u32:: MAX )
270
- . safe_div_ceil ( 100 ) ?,
271
- )
253
+ . saturating_add ( short_spread. saturating_mul ( adjustment) . safe_div_ceil ( 100 ) ?)
272
254
. max ( 1 ) ;
273
255
}
274
256
You can’t perform that action at this time.
0 commit comments