@@ -225,7 +225,7 @@ fn test_remainder_long_settle_too_large_order_step_size() {
225
225
market. amm . base_asset_amount_per_lp = 10 ;
226
226
market. amm . quote_asset_amount_per_lp = -10 ;
227
227
market. amm . base_asset_amount_with_unsettled_lp = -10 ;
228
- market. amm . base_asset_amount_short = - 10 ;
228
+ market. amm . base_asset_amount_with_amm = 10 ;
229
229
230
230
settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
231
231
@@ -235,11 +235,8 @@ fn test_remainder_long_settle_too_large_order_step_size() {
235
235
assert_eq ! ( position. quote_asset_amount, -10 ) ;
236
236
assert_eq ! ( position. remainder_base_asset_amount, 10 ) ;
237
237
assert_eq ! ( market. amm. base_asset_amount_with_unsettled_lp, -10 ) ;
238
- // net baa doesnt change
239
- assert_eq ! (
240
- og_market. amm. base_asset_amount_with_amm,
241
- market. amm. base_asset_amount_with_amm
242
- ) ;
238
+ // net baa doesnt change after settle_lp_position
239
+ assert_eq ! ( market. amm. base_asset_amount_with_amm, 10 ) ;
243
240
244
241
// burn
245
242
let lp_shares = position. lp_shares ;
@@ -273,7 +270,8 @@ fn test_remainder_overflows_too_large_order_step_size() {
273
270
market. amm . base_asset_amount_per_lp = 10 ;
274
271
market. amm . quote_asset_amount_per_lp = -10 ;
275
272
market. amm . base_asset_amount_with_unsettled_lp = -10 ;
276
- market. amm . base_asset_amount_short = -10 ;
273
+ market. amm . base_asset_amount_with_amm = 10 ;
274
+ market. amm . base_asset_amount_short = 0 ;
277
275
278
276
settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
279
277
@@ -283,24 +281,22 @@ fn test_remainder_overflows_too_large_order_step_size() {
283
281
assert_eq ! ( position. quote_asset_amount, -10 ) ;
284
282
assert_eq ! ( position. remainder_base_asset_amount, 10 ) ;
285
283
assert_eq ! ( market. amm. base_asset_amount_with_unsettled_lp, -10 ) ;
286
- // net baa doesnt change
287
- assert_eq ! (
288
- og_market. amm. base_asset_amount_with_amm,
289
- market. amm. base_asset_amount_with_amm
290
- ) ;
284
+ // net baa doesnt change after settle_lp_position
285
+ assert_eq ! ( market. amm. base_asset_amount_with_amm, 10 ) ;
291
286
292
- market. amm . base_asset_amount_per_lp = BASE_PRECISION_I128 + 1 ;
293
- market. amm . quote_asset_amount_per_lp = -16900000000 ;
294
- market. amm . base_asset_amount_with_unsettled_lp = -( BASE_PRECISION_I128 + 1 ) ;
295
- market. amm . base_asset_amount_short = -( BASE_PRECISION_I128 + 1 ) ;
287
+ market. amm . base_asset_amount_per_lp += BASE_PRECISION_I128 + 1 ;
288
+ market. amm . quote_asset_amount_per_lp += -16900000000 ;
289
+ market. amm . base_asset_amount_with_unsettled_lp += -( BASE_PRECISION_I128 + 1 ) ;
290
+ // market.amm.base_asset_amount_short ;
291
+ market. amm . base_asset_amount_with_amm += BASE_PRECISION_I128 + 1 ;
296
292
297
293
settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
298
294
299
- assert_eq ! ( position. last_base_asset_amount_per_lp, 1000000001 ) ;
300
- assert_eq ! ( position. last_quote_asset_amount_per_lp, -16900000000 ) ;
301
- assert_eq ! ( position. quote_asset_amount, -16900000000 ) ;
295
+ assert_eq ! ( position. last_base_asset_amount_per_lp, 1000000011 ) ;
296
+ assert_eq ! ( position. last_quote_asset_amount_per_lp, -16900000010 ) ;
297
+ assert_eq ! ( position. quote_asset_amount, -16900000010 ) ;
302
298
assert_eq ! ( position. base_asset_amount, 0 ) ;
303
- assert_eq ! ( position. remainder_base_asset_amount, 1000000001 ) ;
299
+ assert_eq ! ( position. remainder_base_asset_amount, 1000000011 ) ;
304
300
assert_eq ! (
305
301
( position. remainder_base_asset_amount as u64 ) < market. amm. order_step_size,
306
302
true
@@ -315,11 +311,11 @@ fn test_remainder_overflows_too_large_order_step_size() {
315
311
// not allowed to settle when remainder is above i32 but below order size
316
312
assert ! ( settle_lp_position( & mut position, & mut market) . is_err( ) ) ;
317
313
318
- assert_eq ! ( position. last_base_asset_amount_per_lp, 1000000001 ) ;
319
- assert_eq ! ( position. last_quote_asset_amount_per_lp, -16900000000 ) ;
320
- assert_eq ! ( position. quote_asset_amount, -16900000000 ) ;
314
+ // assert_eq!(position.last_base_asset_amount_per_lp, 1000000001);
315
+ // assert_eq!(position.last_quote_asset_amount_per_lp, -16900000000);
316
+ assert_eq ! ( position. quote_asset_amount, -16900000010 ) ;
321
317
assert_eq ! ( position. base_asset_amount, 0 ) ;
322
- assert_eq ! ( position. remainder_base_asset_amount, 1000000001 ) ;
318
+ // assert_eq!(position.remainder_base_asset_amount, 1000000001);
323
319
assert_eq ! (
324
320
( position. remainder_base_asset_amount as u64 ) < market. amm. order_step_size,
325
321
true
@@ -329,13 +325,14 @@ fn test_remainder_overflows_too_large_order_step_size() {
329
325
market. amm . base_asset_amount_per_lp = 5 * BASE_PRECISION_I128 + 1 ;
330
326
market. amm . quote_asset_amount_per_lp = -116900000000 ;
331
327
market. amm . base_asset_amount_with_unsettled_lp = -( 5 * BASE_PRECISION_I128 + 1 ) ;
332
- market. amm . base_asset_amount_short = -( 5 * BASE_PRECISION_I128 + 1 ) ;
328
+ market. amm . base_asset_amount_short = -( 5 * BASE_PRECISION_I128 ) ;
329
+ market. amm . base_asset_amount_with_amm = 1 ;
333
330
334
331
settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
335
- assert_eq ! ( market. amm. base_asset_amount_with_amm, 0 ) ;
336
332
assert_eq ! ( market. amm. base_asset_amount_with_unsettled_lp, -1 ) ;
337
- assert_eq ! ( market. amm. base_asset_amount_short, -5000000001 ) ;
333
+ assert_eq ! ( market. amm. base_asset_amount_short, -5000000000 ) ;
338
334
assert_eq ! ( market. amm. base_asset_amount_long, 5000000000 ) ;
335
+ assert_eq ! ( market. amm. base_asset_amount_with_amm, 1 ) ;
339
336
340
337
assert_eq ! ( position. last_base_asset_amount_per_lp, 5000000001 ) ;
341
338
assert_eq ! ( position. last_quote_asset_amount_per_lp, -116900000000 ) ;
@@ -357,9 +354,9 @@ fn test_remainder_overflows_too_large_order_step_size() {
357
354
assert_eq ! ( position. base_asset_amount, 5000000000 ) ;
358
355
assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
359
356
360
- assert_eq ! ( market. amm. base_asset_amount_with_amm, - 1 ) ;
357
+ assert_eq ! ( market. amm. base_asset_amount_with_amm, 0 ) ;
361
358
assert_eq ! ( market. amm. base_asset_amount_with_unsettled_lp, 0 ) ;
362
- assert_eq ! ( market. amm. base_asset_amount_short, -5000000001 ) ;
359
+ assert_eq ! ( market. amm. base_asset_amount_short, -5000000000 ) ;
363
360
assert_eq ! ( market. amm. base_asset_amount_long, 5000000000 ) ;
364
361
}
365
362
@@ -384,7 +381,7 @@ fn test_remainder_burn_large_order_step_size() {
384
381
market. amm . base_asset_amount_per_lp = 10 ;
385
382
market. amm . quote_asset_amount_per_lp = -10 ;
386
383
market. amm . base_asset_amount_with_unsettled_lp = -10 ;
387
- market. amm . base_asset_amount_short = - 10 ;
384
+ market. amm . base_asset_amount_with_amm += 10 ;
388
385
389
386
settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
390
387
@@ -394,16 +391,13 @@ fn test_remainder_burn_large_order_step_size() {
394
391
assert_eq ! ( position. quote_asset_amount, -10 ) ;
395
392
assert_eq ! ( position. remainder_base_asset_amount, 10 ) ;
396
393
assert_eq ! ( market. amm. base_asset_amount_with_unsettled_lp, -10 ) ;
397
- // net baa doesnt change
398
- assert_eq ! (
399
- og_market. amm. base_asset_amount_with_amm,
400
- market. amm. base_asset_amount_with_amm
401
- ) ;
394
+ // net baa doesnt change after settle_lp_position
395
+ assert_eq ! ( market. amm. base_asset_amount_with_amm, 10 ) ;
402
396
403
397
market. amm . base_asset_amount_per_lp = BASE_PRECISION_I128 + 1 ;
404
398
market. amm . quote_asset_amount_per_lp = -16900000000 ;
405
- market. amm . base_asset_amount_with_unsettled_lp = -( BASE_PRECISION_I128 + 1 ) ;
406
- market. amm . base_asset_amount_short = - ( BASE_PRECISION_I128 + 1 ) ;
399
+ market. amm . base_asset_amount_with_unsettled_lp + = -( BASE_PRECISION_I128 + 1 ) ;
400
+ market. amm . base_asset_amount_with_amm += BASE_PRECISION_I128 + 1 ;
407
401
408
402
settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
409
403
@@ -500,7 +494,7 @@ pub fn test_lp_settle_pnl() {
500
494
market. amm . base_asset_amount_per_lp = 10 ;
501
495
market. amm . quote_asset_amount_per_lp = -10 ;
502
496
market. amm . base_asset_amount_with_unsettled_lp = -10 ;
503
- market. amm . base_asset_amount_short = - 10 ;
497
+ market. amm . base_asset_amount_with_amm += 10 ;
504
498
market. amm . cumulative_funding_rate_long = 169 ;
505
499
market. amm . cumulative_funding_rate_short = 169 ;
506
500
@@ -862,7 +856,7 @@ fn test_lp_has_correct_entry_be_price_sim_no_remainders() {
862
856
assert_eq ! ( market. amm. sqrt_k, 2000000000 ) ;
863
857
assert_eq ! ( position. get_entry_price( ) . unwrap( ) , 0 ) ;
864
858
assert_eq ! ( position. get_cost_basis( ) . unwrap( ) , 0 ) ;
865
- assert_eq ! ( position. get_be_price ( ) . unwrap( ) , 0 ) ;
859
+ assert_eq ! ( position. get_breakeven_price ( ) . unwrap( ) , 0 ) ;
866
860
assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
867
861
assert_eq ! ( position. base_asset_amount, 0 ) ;
868
862
let mut num_position_flips = 0 ;
@@ -900,7 +894,7 @@ fn test_lp_has_correct_entry_be_price_sim_no_remainders() {
900
894
}
901
895
902
896
let entry = position. get_entry_price ( ) . unwrap ( ) ;
903
- let be = position. get_be_price ( ) . unwrap ( ) ;
897
+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
904
898
let cb = position. get_cost_basis ( ) . unwrap ( ) ;
905
899
906
900
let iii = position
@@ -918,13 +912,13 @@ fn test_lp_has_correct_entry_be_price_sim_no_remainders() {
918
912
) ;
919
913
assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
920
914
921
- if position. get_current_base_with_remainder_abs ( ) . unwrap ( ) != 0 {
915
+ if position. get_base_asset_amount_with_remainder_abs ( ) . unwrap ( ) != 0 {
922
916
assert ! ( entry <= 100 * PRICE_PRECISION as i128 ) ;
923
917
assert ! ( entry >= 99 * PRICE_PRECISION as i128 ) ;
924
918
}
925
919
}
926
920
let entry = position. get_entry_price ( ) . unwrap ( ) ;
927
- let be = position. get_be_price ( ) . unwrap ( ) ;
921
+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
928
922
let cb = position. get_cost_basis ( ) . unwrap ( ) ;
929
923
930
924
assert_eq ! ( position. base_asset_amount, 200500000000 ) ;
@@ -959,7 +953,7 @@ fn test_lp_has_correct_entry_be_price_sim() {
959
953
assert_eq ! ( market. amm. sqrt_k, 2000000000 ) ;
960
954
assert_eq ! ( position. get_entry_price( ) . unwrap( ) , 0 ) ;
961
955
assert_eq ! ( position. get_cost_basis( ) . unwrap( ) , 0 ) ;
962
- assert_eq ! ( position. get_be_price ( ) . unwrap( ) , 0 ) ;
956
+ assert_eq ! ( position. get_breakeven_price ( ) . unwrap( ) , 0 ) ;
963
957
assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
964
958
assert_eq ! ( position. base_asset_amount, 0 ) ;
965
959
let mut num_position_flips = 0 ;
@@ -1040,7 +1034,7 @@ fn test_lp_has_correct_entry_be_price_sim() {
1040
1034
}
1041
1035
1042
1036
let entry = position. get_entry_price ( ) . unwrap ( ) ;
1043
- let be = position. get_be_price ( ) . unwrap ( ) ;
1037
+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
1044
1038
let cb = position. get_cost_basis ( ) . unwrap ( ) ;
1045
1039
1046
1040
let iii = position
@@ -1058,13 +1052,13 @@ fn test_lp_has_correct_entry_be_price_sim() {
1058
1052
) ;
1059
1053
// assert_ne!(position.remainder_base_asset_amount, 0);
1060
1054
1061
- if position. get_current_base_with_remainder_abs ( ) . unwrap ( ) != 0 {
1055
+ if position. get_base_asset_amount_with_remainder_abs ( ) . unwrap ( ) != 0 {
1062
1056
assert ! ( entry <= 100 * PRICE_PRECISION as i128 ) ;
1063
1057
assert ! ( entry >= 99 * PRICE_PRECISION as i128 ) ;
1064
1058
}
1065
1059
}
1066
1060
let entry = position. get_entry_price ( ) . unwrap ( ) ;
1067
- let be = position. get_be_price ( ) . unwrap ( ) ;
1061
+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
1068
1062
let cb = position. get_cost_basis ( ) . unwrap ( ) ;
1069
1063
1070
1064
assert_eq ! ( entry, 99202570 ) ;
@@ -1099,7 +1093,7 @@ fn test_lp_has_correct_entry_be_price_sim_more_flips() {
1099
1093
assert_eq ! ( market. amm. sqrt_k, 2000000000 ) ;
1100
1094
assert_eq ! ( position. get_entry_price( ) . unwrap( ) , 0 ) ;
1101
1095
assert_eq ! ( position. get_cost_basis( ) . unwrap( ) , 0 ) ;
1102
- assert_eq ! ( position. get_be_price ( ) . unwrap( ) , 0 ) ;
1096
+ assert_eq ! ( position. get_breakeven_price ( ) . unwrap( ) , 0 ) ;
1103
1097
assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
1104
1098
assert_eq ! ( position. base_asset_amount, 0 ) ;
1105
1099
let mut num_position_flips = 0 ;
@@ -1138,7 +1132,7 @@ fn test_lp_has_correct_entry_be_price_sim_more_flips() {
1138
1132
assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
1139
1133
1140
1134
let entry = position. get_entry_price ( ) . unwrap ( ) ;
1141
- let be = position. get_be_price ( ) . unwrap ( ) ;
1135
+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
1142
1136
let cb = position. get_cost_basis ( ) . unwrap ( ) ;
1143
1137
1144
1138
let iii = position
@@ -1155,7 +1149,7 @@ fn test_lp_has_correct_entry_be_price_sim_more_flips() {
1155
1149
position. base_asset_amount,
1156
1150
) ;
1157
1151
1158
- if position. get_current_base_with_remainder_abs ( ) . unwrap ( ) != 0 {
1152
+ if position. get_base_asset_amount_with_remainder_abs ( ) . unwrap ( ) != 0 {
1159
1153
assert ! ( entry <= 99_800_000 as i128 ) ;
1160
1154
assert ! ( entry >= 99_199_820 as i128 ) ;
1161
1155
}
@@ -1165,7 +1159,7 @@ fn test_lp_has_correct_entry_be_price_sim_more_flips() {
1165
1159
// assert_eq!(flip_indexes, [0, 1, 18, 19]);
1166
1160
1167
1161
let entry = position. get_entry_price ( ) . unwrap ( ) ;
1168
- let be = position. get_be_price ( ) . unwrap ( ) ;
1162
+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
1169
1163
let cb = position. get_cost_basis ( ) . unwrap ( ) ;
1170
1164
1171
1165
assert_eq ! ( position. base_asset_amount, 150200000000 ) ;
0 commit comments