Skip to content

Commit 59be1c5

Browse files
authored
program: amm-spread-inventory-spread-adj-base-spread-lb (#1803)
1 parent 3b31084 commit 59be1c5

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

programs/drift/src/controller/position/tests.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -940,10 +940,10 @@ fn amm_ref_price_offset_decay_logic() {
940940
assert_eq!(
941941
sspreads,
942942
[
943-
7147, 6937, 6727, 6517, 6307, 6097, 6077, 6057, 6037, 6017, 5807, 5596, 5386, 5176,
944-
4966, 4756, 4546, 4336, 4126, 3916, 3706, 3496, 3286, 3076, 2866, 2656, 2446, 2236,
945-
2026, 1816, 1626, 1455, 1302, 1164, 1040, 928, 827, 736, 654, 581, 515, 456, 402, 354,
946-
311, 272, 237, 205, 177, 151, 128, 107, 87, 67, 47, 27, 7, 6, 6, 6
943+
7150, 6940, 6730, 6520, 6310, 6100, 6080, 6060, 6040, 6020, 5810, 5600, 5390, 5180,
944+
4970, 4760, 4550, 4340, 4130, 3920, 3710, 3500, 3290, 3080, 2870, 2660, 2450, 2240,
945+
2030, 1820, 1630, 1459, 1306, 1168, 1044, 932, 831, 740, 658, 585, 519, 460, 406, 358,
946+
315, 276, 241, 209, 181, 155, 132, 111, 91, 71, 51, 31, 11, 10, 10, 10
947947
]
948948
);
949949
}
@@ -1108,10 +1108,11 @@ fn amm_negative_ref_price_offset_decay_logic() {
11081108
assert_eq!(
11091109
sspreads,
11101110
[
1111-
207, 207, 207, 207, 207, 207, 17, 17, 17, 17, 207, 206, 206, 206, 206, 206, 206, 206,
1112-
206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206,
1113-
206, 206, 206, 126, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
1114-
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6
1111+
210, 210, 210, 210, 210, 210, 20, 20, 20, 20, 210, 210, 210, 210, 210, 210, 210, 210,
1112+
210, 210, 210, 210, 210, 210, 210, 210, 210, 210, 210, 210, 210, 210, 210, 210, 210,
1113+
210, 210, 210, 130, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1114+
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1115+
10, 10
11151116
]
11161117
);
11171118
assert_eq!(

programs/drift/src/math/amm_spread.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,24 +458,24 @@ pub fn calculate_spread(
458458
let adjustment: u64 = amm_inventory_spread_adjustment
459459
.cast::<i64>()?
460460
.unsigned_abs();
461-
long_spread = long_vol_spread.max(
461+
long_spread = max(half_base_spread_u64, long_vol_spread).max(
462462
long_spread
463463
.saturating_sub(long_spread.saturating_mul(adjustment).safe_div(100)?)
464464
.max(1),
465465
);
466-
short_spread = short_vol_spread.max(
466+
short_spread = max(half_base_spread_u64, short_vol_spread).max(
467467
short_spread
468468
.saturating_sub(short_spread.saturating_mul(adjustment).safe_div(100)?)
469469
.max(1),
470470
);
471471
} else if amm_inventory_spread_adjustment > 0 {
472472
let adjustment = amm_inventory_spread_adjustment.cast()?;
473-
long_spread = long_vol_spread.max(
473+
long_spread = max(half_base_spread_u64, long_vol_spread).max(
474474
long_spread
475475
.saturating_add(long_spread.saturating_mul(adjustment).safe_div_ceil(100)?)
476476
.max(1),
477477
);
478-
short_spread = short_vol_spread.max(
478+
short_spread = max(half_base_spread_u64, short_vol_spread).max(
479479
short_spread
480480
.saturating_add(short_spread.saturating_mul(adjustment).safe_div_ceil(100)?)
481481
.max(1),

0 commit comments

Comments
 (0)