@@ -225,7 +225,7 @@ fn test_remainder_long_settle_too_large_order_step_size() {
225225 market. amm . base_asset_amount_per_lp = 10 ;
226226 market. amm . quote_asset_amount_per_lp = -10 ;
227227 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 ;
229229
230230 settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
231231
@@ -235,11 +235,8 @@ fn test_remainder_long_settle_too_large_order_step_size() {
235235 assert_eq ! ( position. quote_asset_amount, -10 ) ;
236236 assert_eq ! ( position. remainder_base_asset_amount, 10 ) ;
237237 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 ) ;
243240
244241 // burn
245242 let lp_shares = position. lp_shares ;
@@ -273,7 +270,8 @@ fn test_remainder_overflows_too_large_order_step_size() {
273270 market. amm . base_asset_amount_per_lp = 10 ;
274271 market. amm . quote_asset_amount_per_lp = -10 ;
275272 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 ;
277275
278276 settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
279277
@@ -283,24 +281,22 @@ fn test_remainder_overflows_too_large_order_step_size() {
283281 assert_eq ! ( position. quote_asset_amount, -10 ) ;
284282 assert_eq ! ( position. remainder_base_asset_amount, 10 ) ;
285283 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 ) ;
291286
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 ;
296292
297293 settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
298294
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 ) ;
302298 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 ) ;
304300 assert_eq ! (
305301 ( position. remainder_base_asset_amount as u64 ) < market. amm. order_step_size,
306302 true
@@ -315,11 +311,11 @@ fn test_remainder_overflows_too_large_order_step_size() {
315311 // not allowed to settle when remainder is above i32 but below order size
316312 assert ! ( settle_lp_position( & mut position, & mut market) . is_err( ) ) ;
317313
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 ) ;
321317 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);
323319 assert_eq ! (
324320 ( position. remainder_base_asset_amount as u64 ) < market. amm. order_step_size,
325321 true
@@ -329,13 +325,14 @@ fn test_remainder_overflows_too_large_order_step_size() {
329325 market. amm . base_asset_amount_per_lp = 5 * BASE_PRECISION_I128 + 1 ;
330326 market. amm . quote_asset_amount_per_lp = -116900000000 ;
331327 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 ;
333330
334331 settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
335- assert_eq ! ( market. amm. base_asset_amount_with_amm, 0 ) ;
336332 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 ) ;
338334 assert_eq ! ( market. amm. base_asset_amount_long, 5000000000 ) ;
335+ assert_eq ! ( market. amm. base_asset_amount_with_amm, 1 ) ;
339336
340337 assert_eq ! ( position. last_base_asset_amount_per_lp, 5000000001 ) ;
341338 assert_eq ! ( position. last_quote_asset_amount_per_lp, -116900000000 ) ;
@@ -357,9 +354,9 @@ fn test_remainder_overflows_too_large_order_step_size() {
357354 assert_eq ! ( position. base_asset_amount, 5000000000 ) ;
358355 assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
359356
360- assert_eq ! ( market. amm. base_asset_amount_with_amm, - 1 ) ;
357+ assert_eq ! ( market. amm. base_asset_amount_with_amm, 0 ) ;
361358 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 ) ;
363360 assert_eq ! ( market. amm. base_asset_amount_long, 5000000000 ) ;
364361}
365362
@@ -384,7 +381,7 @@ fn test_remainder_burn_large_order_step_size() {
384381 market. amm . base_asset_amount_per_lp = 10 ;
385382 market. amm . quote_asset_amount_per_lp = -10 ;
386383 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 ;
388385
389386 settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
390387
@@ -394,16 +391,13 @@ fn test_remainder_burn_large_order_step_size() {
394391 assert_eq ! ( position. quote_asset_amount, -10 ) ;
395392 assert_eq ! ( position. remainder_base_asset_amount, 10 ) ;
396393 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 ) ;
402396
403397 market. amm . base_asset_amount_per_lp = BASE_PRECISION_I128 + 1 ;
404398 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 ;
407401
408402 settle_lp_position ( & mut position, & mut market) . unwrap ( ) ;
409403
@@ -500,7 +494,7 @@ pub fn test_lp_settle_pnl() {
500494 market. amm . base_asset_amount_per_lp = 10 ;
501495 market. amm . quote_asset_amount_per_lp = -10 ;
502496 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 ;
504498 market. amm . cumulative_funding_rate_long = 169 ;
505499 market. amm . cumulative_funding_rate_short = 169 ;
506500
@@ -862,7 +856,7 @@ fn test_lp_has_correct_entry_be_price_sim_no_remainders() {
862856 assert_eq ! ( market. amm. sqrt_k, 2000000000 ) ;
863857 assert_eq ! ( position. get_entry_price( ) . unwrap( ) , 0 ) ;
864858 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 ) ;
866860 assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
867861 assert_eq ! ( position. base_asset_amount, 0 ) ;
868862 let mut num_position_flips = 0 ;
@@ -900,7 +894,7 @@ fn test_lp_has_correct_entry_be_price_sim_no_remainders() {
900894 }
901895
902896 let entry = position. get_entry_price ( ) . unwrap ( ) ;
903- let be = position. get_be_price ( ) . unwrap ( ) ;
897+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
904898 let cb = position. get_cost_basis ( ) . unwrap ( ) ;
905899
906900 let iii = position
@@ -918,13 +912,13 @@ fn test_lp_has_correct_entry_be_price_sim_no_remainders() {
918912 ) ;
919913 assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
920914
921- if position. get_current_base_with_remainder_abs ( ) . unwrap ( ) != 0 {
915+ if position. get_base_asset_amount_with_remainder_abs ( ) . unwrap ( ) != 0 {
922916 assert ! ( entry <= 100 * PRICE_PRECISION as i128 ) ;
923917 assert ! ( entry >= 99 * PRICE_PRECISION as i128 ) ;
924918 }
925919 }
926920 let entry = position. get_entry_price ( ) . unwrap ( ) ;
927- let be = position. get_be_price ( ) . unwrap ( ) ;
921+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
928922 let cb = position. get_cost_basis ( ) . unwrap ( ) ;
929923
930924 assert_eq ! ( position. base_asset_amount, 200500000000 ) ;
@@ -959,7 +953,7 @@ fn test_lp_has_correct_entry_be_price_sim() {
959953 assert_eq ! ( market. amm. sqrt_k, 2000000000 ) ;
960954 assert_eq ! ( position. get_entry_price( ) . unwrap( ) , 0 ) ;
961955 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 ) ;
963957 assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
964958 assert_eq ! ( position. base_asset_amount, 0 ) ;
965959 let mut num_position_flips = 0 ;
@@ -1040,7 +1034,7 @@ fn test_lp_has_correct_entry_be_price_sim() {
10401034 }
10411035
10421036 let entry = position. get_entry_price ( ) . unwrap ( ) ;
1043- let be = position. get_be_price ( ) . unwrap ( ) ;
1037+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
10441038 let cb = position. get_cost_basis ( ) . unwrap ( ) ;
10451039
10461040 let iii = position
@@ -1058,13 +1052,13 @@ fn test_lp_has_correct_entry_be_price_sim() {
10581052 ) ;
10591053 // assert_ne!(position.remainder_base_asset_amount, 0);
10601054
1061- if position. get_current_base_with_remainder_abs ( ) . unwrap ( ) != 0 {
1055+ if position. get_base_asset_amount_with_remainder_abs ( ) . unwrap ( ) != 0 {
10621056 assert ! ( entry <= 100 * PRICE_PRECISION as i128 ) ;
10631057 assert ! ( entry >= 99 * PRICE_PRECISION as i128 ) ;
10641058 }
10651059 }
10661060 let entry = position. get_entry_price ( ) . unwrap ( ) ;
1067- let be = position. get_be_price ( ) . unwrap ( ) ;
1061+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
10681062 let cb = position. get_cost_basis ( ) . unwrap ( ) ;
10691063
10701064 assert_eq ! ( entry, 99202570 ) ;
@@ -1099,7 +1093,7 @@ fn test_lp_has_correct_entry_be_price_sim_more_flips() {
10991093 assert_eq ! ( market. amm. sqrt_k, 2000000000 ) ;
11001094 assert_eq ! ( position. get_entry_price( ) . unwrap( ) , 0 ) ;
11011095 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 ) ;
11031097 assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
11041098 assert_eq ! ( position. base_asset_amount, 0 ) ;
11051099 let mut num_position_flips = 0 ;
@@ -1138,7 +1132,7 @@ fn test_lp_has_correct_entry_be_price_sim_more_flips() {
11381132 assert_eq ! ( position. remainder_base_asset_amount, 0 ) ;
11391133
11401134 let entry = position. get_entry_price ( ) . unwrap ( ) ;
1141- let be = position. get_be_price ( ) . unwrap ( ) ;
1135+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
11421136 let cb = position. get_cost_basis ( ) . unwrap ( ) ;
11431137
11441138 let iii = position
@@ -1155,7 +1149,7 @@ fn test_lp_has_correct_entry_be_price_sim_more_flips() {
11551149 position. base_asset_amount,
11561150 ) ;
11571151
1158- if position. get_current_base_with_remainder_abs ( ) . unwrap ( ) != 0 {
1152+ if position. get_base_asset_amount_with_remainder_abs ( ) . unwrap ( ) != 0 {
11591153 assert ! ( entry <= 99_800_000 as i128 ) ;
11601154 assert ! ( entry >= 99_199_820 as i128 ) ;
11611155 }
@@ -1165,7 +1159,7 @@ fn test_lp_has_correct_entry_be_price_sim_more_flips() {
11651159 // assert_eq!(flip_indexes, [0, 1, 18, 19]);
11661160
11671161 let entry = position. get_entry_price ( ) . unwrap ( ) ;
1168- let be = position. get_be_price ( ) . unwrap ( ) ;
1162+ let be = position. get_breakeven_price ( ) . unwrap ( ) ;
11691163 let cb = position. get_cost_basis ( ) . unwrap ( ) ;
11701164
11711165 assert_eq ! ( position. base_asset_amount, 150200000000 ) ;
0 commit comments