@@ -363,21 +363,21 @@ pub mod pallet {
363
363
Error :: <T >:: UnstakeTooSmall
364
364
) ;
365
365
366
- let asset_amount =
366
+ let staking_amount =
367
367
Self :: liquid_to_staking ( liquid_amount) . ok_or ( Error :: < T > :: InvalidExchangeRate ) ?;
368
368
369
369
let target_blocknumber = T :: RelayChainBlockNumberProvider :: current_block_number ( )
370
370
. checked_add ( & T :: BondingDuration :: get ( ) )
371
371
. ok_or ( ArithmeticError :: Overflow ) ?;
372
- Self :: do_push_back ( & who, asset_amount , target_blocknumber) ?;
372
+ Self :: do_push_back ( & who, staking_amount , target_blocknumber) ?;
373
373
374
374
T :: Assets :: burn_from ( Self :: liquid_currency ( ) ?, & who, liquid_amount) ?;
375
375
376
376
MatchingPool :: < T > :: try_mutate ( |p| -> DispatchResult {
377
- p. update_total_unstake_amount ( liquid_amount , ArithmeticKind :: Addition )
377
+ p. update_total_unstake_amount ( staking_amount , ArithmeticKind :: Addition )
378
378
} ) ?;
379
379
380
- Self :: deposit_event ( Event :: < T > :: Unstaked ( who, liquid_amount, asset_amount ) ) ;
380
+ Self :: deposit_event ( Event :: < T > :: Unstaked ( who, liquid_amount, staking_amount ) ) ;
381
381
Ok ( ( ) . into ( ) )
382
382
}
383
383
@@ -434,7 +434,7 @@ pub mod pallet {
434
434
435
435
let old_matching_ledger = Self :: matching_pool ( ) ;
436
436
let ( bond_amount, rebond_amount, unbond_amount) =
437
- MatchingPool :: < T > :: try_mutate ( |b| b. matching :: < Self > ( unbonding_amount) ) ?;
437
+ MatchingPool :: < T > :: try_mutate ( |b| b. matching ( unbonding_amount) ) ?;
438
438
439
439
if bonding_amount. is_zero ( ) && unbonding_amount. is_zero ( ) {
440
440
Self :: do_bond ( bond_amount, RewardDestination :: Staked ) ?;
@@ -667,10 +667,7 @@ pub mod pallet {
667
667
Self :: notify_placeholder ( ) ,
668
668
) ?;
669
669
670
- let liquid_amount =
671
- Self :: staking_to_liquid ( amount) . ok_or ( Error :: < T > :: InvalidExchangeRate ) ?;
672
-
673
- XcmRequests :: < T > :: insert ( query_id, XcmRequest :: Unbond { liquid_amount } ) ;
670
+ XcmRequests :: < T > :: insert ( query_id, XcmRequest :: Unbond { amount } ) ;
674
671
675
672
Self :: deposit_event ( Event :: < T > :: Unbonding ( amount) ) ;
676
673
@@ -682,14 +679,18 @@ pub mod pallet {
682
679
if amount. is_zero ( ) {
683
680
return Ok ( ( ) ) ;
684
681
}
682
+
685
683
let query_id = T :: XCM :: do_rebond (
686
684
amount,
687
685
Self :: staking_currency ( ) ?,
688
686
T :: DerivativeIndex :: get ( ) ,
689
687
Self :: notify_placeholder ( ) ,
690
688
) ?;
689
+
691
690
XcmRequests :: < T > :: insert ( query_id, XcmRequest :: Rebond { amount } ) ;
691
+
692
692
Self :: deposit_event ( Event :: < T > :: Rebonding ( amount) ) ;
693
+
693
694
Ok ( ( ) )
694
695
}
695
696
@@ -739,25 +740,26 @@ pub mod pallet {
739
740
res : Option < ( u32 , XcmError ) > ,
740
741
) -> DispatchResult {
741
742
let executed = res. is_none ( ) ;
743
+ use XcmRequest :: * ;
742
744
743
745
match request {
744
- XcmRequest :: Bond { amount, .. } | XcmRequest :: BondExtra { amount } if executed => {
746
+ Bond { amount, .. } | BondExtra { amount } if executed => {
745
747
MatchingPool :: < T > :: try_mutate ( |p| -> DispatchResult {
746
748
p. update_total_stake_amount ( amount, ArithmeticKind :: Subtraction )
747
749
} ) ?;
748
750
T :: Assets :: burn_from ( Self :: staking_currency ( ) ?, & Self :: account_id ( ) , amount) ?;
749
751
}
750
- XcmRequest :: Unbond { liquid_amount } if executed => {
752
+ Unbond { amount } if executed => {
751
753
MatchingPool :: < T > :: try_mutate ( |p| -> DispatchResult {
752
- p. update_total_unstake_amount ( liquid_amount , ArithmeticKind :: Subtraction )
754
+ p. update_total_unstake_amount ( amount , ArithmeticKind :: Subtraction )
753
755
} ) ?;
754
756
}
755
- XcmRequest :: Rebond { amount } if executed => {
757
+ Rebond { amount } if executed => {
756
758
MatchingPool :: < T > :: try_mutate ( |p| -> DispatchResult {
757
759
p. update_total_stake_amount ( amount, ArithmeticKind :: Subtraction )
758
760
} ) ?;
759
761
}
760
- XcmRequest :: WithdrawUnbonded {
762
+ WithdrawUnbonded {
761
763
num_slashing_spans : _,
762
764
amount,
763
765
} if executed => {
@@ -769,6 +771,7 @@ pub mod pallet {
769
771
if executed {
770
772
XcmRequests :: < T > :: remove ( & query_id) ;
771
773
}
774
+
772
775
Ok ( ( ) )
773
776
}
774
777
@@ -780,10 +783,9 @@ pub mod pallet {
780
783
match Rate :: checked_from_rational (
781
784
bonding_amount
782
785
. checked_add ( old_matching_ledger. total_stake_amount )
786
+ . and_then ( |r| r. checked_sub ( old_matching_ledger. total_unstake_amount ) )
783
787
. ok_or ( ArithmeticError :: Overflow ) ?,
784
- T :: Assets :: total_issuance ( Self :: liquid_currency ( ) ?)
785
- . checked_add ( old_matching_ledger. total_unstake_amount )
786
- . ok_or ( ArithmeticError :: Overflow ) ?,
788
+ T :: Assets :: total_issuance ( Self :: liquid_currency ( ) ?) ,
787
789
) {
788
790
Some ( exchange_rate) if exchange_rate != Self :: exchange_rate ( ) => {
789
791
ExchangeRate :: < T > :: put ( exchange_rate) ;
0 commit comments