@@ -394,12 +394,12 @@ where
394
394
/// * `new_tick_upper`: The new upper tick.
395
395
#[ inline]
396
396
pub fn get_rebalanced_position < TP > (
397
- position : & mut Position < TP > ,
397
+ mut position : Position < TP > ,
398
398
new_tick_lower : TP :: Index ,
399
399
new_tick_upper : TP :: Index ,
400
400
) -> Result < Position < TP > , Error >
401
401
where
402
- TP : Clone + TickDataProvider ,
402
+ TP : TickDataProvider ,
403
403
{
404
404
let price = position. pool . token0_price ( ) ;
405
405
// Calculate the position equity denominated in token1 before rebalance.
@@ -414,7 +414,7 @@ where
414
414
// token0's equity denominated in token1 divided by the price
415
415
let amount0_after = ( equity_before - amount1_after) / price;
416
416
Position :: from_amounts (
417
- position. pool . clone ( ) ,
417
+ position. pool ,
418
418
new_tick_lower,
419
419
new_tick_upper,
420
420
U256 :: from_big_uint ( amount0_after. to_big_uint ( ) ) ,
@@ -470,10 +470,10 @@ pub fn get_rebalanced_position_at_price<TP>(
470
470
new_tick_upper : TP :: Index ,
471
471
) -> Result < Position < TP > , Error >
472
472
where
473
- TP : Clone + TickDataProvider ,
473
+ TP : TickDataProvider ,
474
474
{
475
475
get_rebalanced_position (
476
- & mut get_position_at_price ( position, new_price) ?,
476
+ get_position_at_price ( position, new_price) ?,
477
477
new_tick_lower,
478
478
new_tick_upper,
479
479
)
@@ -571,17 +571,17 @@ mod tests {
571
571
572
572
#[ tokio:: test]
573
573
async fn test_get_rebalanced_position ( ) {
574
- let mut position = get_position ( 1 , NPM , uint ! ( 4_ U256 ) , PROVIDER . clone ( ) , BLOCK_ID )
574
+ let position = get_position ( 1 , NPM , uint ! ( 4_ U256 ) , PROVIDER . clone ( ) , BLOCK_ID )
575
575
. await
576
576
. unwrap ( ) ;
577
577
// rebalance to an out of range position
578
578
let new_tick_lower = position. tick_upper ;
579
579
let new_tick_upper = new_tick_lower + 10 * FeeAmount :: MEDIUM . tick_spacing ( ) . as_i32 ( ) ;
580
- let mut new_position =
581
- get_rebalanced_position ( & mut position, new_tick_lower, new_tick_upper) . unwrap ( ) ;
580
+ let new_position =
581
+ get_rebalanced_position ( position. clone ( ) , new_tick_lower, new_tick_upper) . unwrap ( ) ;
582
582
assert ! ( new_position. amount1( ) . unwrap( ) . quotient( ) . is_zero( ) ) ;
583
583
let reverted_position =
584
- get_rebalanced_position ( & mut new_position, position. tick_lower , position. tick_upper )
584
+ get_rebalanced_position ( new_position, position. tick_lower , position. tick_upper )
585
585
. unwrap ( ) ;
586
586
let amount0 = position. amount0 ( ) . unwrap ( ) . quotient ( ) ;
587
587
assert ! ( amount0 - reverted_position. amount0( ) . unwrap( ) . quotient( ) < BigInt :: from( 10 ) ) ;
@@ -614,7 +614,7 @@ mod tests {
614
614
-887220 ,
615
615
52980 ,
616
616
) ;
617
- let mut position1 = get_position_at_price ( position. clone ( ) , small_price) . unwrap ( ) ;
617
+ let position1 = get_position_at_price ( position. clone ( ) , small_price) . unwrap ( ) ;
618
618
assert ! ( position1. amount0( ) . unwrap( ) . quotient( ) . is_positive( ) ) ;
619
619
assert ! ( position1. amount1( ) . unwrap( ) . quotient( ) . is_zero( ) ) ;
620
620
let position2 = get_position_at_price (
@@ -631,7 +631,7 @@ mod tests {
631
631
. unwrap ( ) ;
632
632
assert ! ( position2. amount0( ) . unwrap( ) . quotient( ) . is_zero( ) ) ;
633
633
assert ! ( position2. amount1( ) . unwrap( ) . quotient( ) . is_positive( ) ) ;
634
- let rebalanced_position = get_rebalanced_position ( & mut position1, 46080 , 62160 ) . unwrap ( ) ;
634
+ let rebalanced_position = get_rebalanced_position ( position1, 46080 , 62160 ) . unwrap ( ) ;
635
635
assert ! ( rebalanced_position
636
636
. amount0( )
637
637
. unwrap( )
@@ -642,22 +642,22 @@ mod tests {
642
642
643
643
#[ tokio:: test]
644
644
async fn test_get_rebalanced_position_at_price ( ) {
645
- let mut position = get_position ( 1 , NPM , uint ! ( 4_ U256 ) , PROVIDER . clone ( ) , BLOCK_ID )
645
+ let position = get_position ( 1 , NPM , uint ! ( 4_ U256 ) , PROVIDER . clone ( ) , BLOCK_ID )
646
646
. await
647
647
. unwrap ( ) ;
648
648
// rebalance to an out of range position
649
649
let new_tick_lower = position. tick_upper ;
650
650
let new_tick_upper = new_tick_lower + 10 * FeeAmount :: MEDIUM . tick_spacing ( ) . as_i32 ( ) ;
651
651
let position_rebalanced_at_current_price =
652
- get_rebalanced_position ( & mut position, new_tick_lower, new_tick_upper) . unwrap ( ) ;
652
+ get_rebalanced_position ( position. clone ( ) , new_tick_lower, new_tick_upper) . unwrap ( ) ;
653
653
let price_upper = tick_to_price (
654
654
position. pool . token0 . clone ( ) ,
655
655
position. pool . token1 . clone ( ) ,
656
656
position. tick_upper . try_into ( ) . unwrap ( ) ,
657
657
)
658
658
. unwrap ( ) ;
659
659
let position_rebalanced_at_tick_upper = get_rebalanced_position_at_price (
660
- position. clone ( ) ,
660
+ position,
661
661
fraction_to_big_decimal ( & price_upper) ,
662
662
new_tick_lower,
663
663
new_tick_upper,
0 commit comments