@@ -90,7 +90,9 @@ pub mod weights;
90
90
use sp_std:: prelude:: * ;
91
91
92
92
use frame_support:: traits:: {
93
- Currency , ExistenceRequirement :: AllowDeath , Get , Imbalance , OnUnbalanced , ReservableCurrency ,
93
+ fungible:: * ,
94
+ tokens:: { Precision , Preservation } ,
95
+ Get , Imbalance ,
94
96
} ;
95
97
96
98
use sp_runtime:: {
@@ -108,8 +110,7 @@ pub use weights::WeightInfo;
108
110
pub use pallet:: * ;
109
111
110
112
type BalanceOf < T , I = ( ) > = pallet_treasury:: BalanceOf < T , I > ;
111
-
112
- type PositiveImbalanceOf < T , I = ( ) > = pallet_treasury:: PositiveImbalanceOf < T , I > ;
113
+ type DebtOf < T , I = ( ) > = pallet_treasury:: DebtOf < T , I > ;
113
114
114
115
/// An index of a bounty. Just a `u32`.
115
116
pub type BountyIndex = u32 ;
@@ -446,8 +447,9 @@ pub mod pallet {
446
447
447
448
let slash_curator = |curator : & T :: AccountId ,
448
449
curator_deposit : & mut BalanceOf < T , I > | {
449
- let imbalance = T :: Currency :: slash_reserved ( curator, * curator_deposit) . 0 ;
450
- T :: OnSlash :: on_unbalanced ( imbalance) ;
450
+ let imbalance =
451
+ T :: Currency :: slash ( & T :: HoldReason :: get ( ) , curator, * curator_deposit) . 0 ;
452
+ T :: OnSlash :: handle ( imbalance) ;
451
453
* curator_deposit = Zero :: zero ( ) ;
452
454
} ;
453
455
@@ -484,9 +486,13 @@ pub mod pallet {
484
486
} else {
485
487
// Else this is the curator, willingly giving up their role.
486
488
// Give back their deposit.
487
- let err_amount =
488
- T :: Currency :: unreserve ( curator, bounty. curator_deposit ) ;
489
- debug_assert ! ( err_amount. is_zero( ) ) ;
489
+ let err_amount = T :: Currency :: release (
490
+ & T :: HoldReason :: get ( ) ,
491
+ curator,
492
+ bounty. curator_deposit ,
493
+ Precision :: Exact ,
494
+ ) ;
495
+ debug_assert ! ( err_amount. is_ok( ) ) ;
490
496
bounty. curator_deposit = Zero :: zero ( ) ;
491
497
// Continue to change bounty status below...
492
498
}
@@ -532,7 +538,7 @@ pub mod pallet {
532
538
ensure ! ( signer == * curator, Error :: <T , I >:: RequireCurator ) ;
533
539
534
540
let deposit = Self :: calculate_curator_deposit ( & bounty. fee ) ;
535
- T :: Currency :: reserve ( curator, deposit) ?;
541
+ T :: Currency :: hold ( & T :: HoldReason :: get ( ) , curator, deposit) ?;
536
542
bounty. curator_deposit = deposit;
537
543
538
544
let update_due = frame_system:: Pallet :: < T > :: block_number ( ) +
@@ -623,23 +629,36 @@ pub mod pallet {
623
629
Error :: <T , I >:: Premature
624
630
) ;
625
631
let bounty_account = Self :: bounty_account_id ( bounty_id) ;
626
- let balance = T :: Currency :: free_balance ( & bounty_account) ;
632
+ let balance = T :: Currency :: balance ( & bounty_account) ;
627
633
let fee = bounty. fee . min ( balance) ; // just to be safe
628
634
let payout = balance. saturating_sub ( fee) ;
629
- let err_amount = T :: Currency :: unreserve ( & curator, bounty. curator_deposit ) ;
630
- debug_assert ! ( err_amount. is_zero( ) ) ;
635
+ let err_amount = T :: Currency :: release (
636
+ & T :: HoldReason :: get ( ) ,
637
+ & curator,
638
+ bounty. curator_deposit ,
639
+ Precision :: Exact ,
640
+ ) ;
641
+ debug_assert ! ( err_amount. is_ok( ) ) ;
631
642
632
643
// Get total child bounties curator fees, and subtract it from the parent
633
644
// curator fee (the fee in present referenced bounty, `self`).
634
645
let children_fee = T :: ChildBountyManager :: children_curator_fees ( bounty_id) ;
635
646
debug_assert ! ( children_fee <= fee) ;
636
647
637
648
let final_fee = fee. saturating_sub ( children_fee) ;
638
- let res =
639
- T :: Currency :: transfer ( & bounty_account, & curator, final_fee, AllowDeath ) ; // should not fail
649
+ let res = T :: Currency :: transfer (
650
+ & bounty_account,
651
+ & curator,
652
+ final_fee,
653
+ Preservation :: Expendable ,
654
+ ) ; // should not fail
640
655
debug_assert ! ( res. is_ok( ) ) ;
641
- let res =
642
- T :: Currency :: transfer ( & bounty_account, & beneficiary, payout, AllowDeath ) ; // should not fail
656
+ let res = T :: Currency :: transfer (
657
+ & bounty_account,
658
+ & beneficiary,
659
+ payout,
660
+ Preservation :: Expendable ,
661
+ ) ; // should not fail
643
662
debug_assert ! ( res. is_ok( ) ) ;
644
663
645
664
* maybe_bounty = None ;
@@ -693,8 +712,10 @@ pub mod pallet {
693
712
// The reject origin would like to cancel a proposed bounty.
694
713
BountyDescriptions :: < T , I > :: remove ( bounty_id) ;
695
714
let value = bounty. bond ;
696
- let imbalance = T :: Currency :: slash_reserved ( & bounty. proposer , value) . 0 ;
697
- T :: OnSlash :: on_unbalanced ( imbalance) ;
715
+ let credit =
716
+ T :: Currency :: slash ( & T :: HoldReason :: get ( ) , & bounty. proposer , value)
717
+ . 0 ;
718
+ T :: OnSlash :: handle ( credit) ;
698
719
* maybe_bounty = None ;
699
720
700
721
Self :: deposit_event ( Event :: < T , I > :: BountyRejected {
@@ -716,9 +737,13 @@ pub mod pallet {
716
737
} ,
717
738
BountyStatus :: Active { curator, .. } => {
718
739
// Cancelled by council, refund deposit of the working curator.
719
- let err_amount =
720
- T :: Currency :: unreserve ( curator, bounty. curator_deposit ) ;
721
- debug_assert ! ( err_amount. is_zero( ) ) ;
740
+ let err_amount = T :: Currency :: release (
741
+ & T :: HoldReason :: get ( ) ,
742
+ curator,
743
+ bounty. curator_deposit ,
744
+ Precision :: Exact ,
745
+ ) ;
746
+ debug_assert ! ( err_amount. is_ok( ) ) ;
722
747
// Then execute removal of the bounty below.
723
748
} ,
724
749
BountyStatus :: PendingPayout { .. } => {
@@ -734,12 +759,12 @@ pub mod pallet {
734
759
735
760
BountyDescriptions :: < T , I > :: remove ( bounty_id) ;
736
761
737
- let balance = T :: Currency :: free_balance ( & bounty_account) ;
762
+ let balance = T :: Currency :: balance ( & bounty_account) ;
738
763
let res = T :: Currency :: transfer (
739
764
& bounty_account,
740
765
& Self :: account_id ( ) ,
741
766
balance,
742
- AllowDeath ,
767
+ Preservation :: Expendable ,
743
768
) ; // should not fail
744
769
debug_assert ! ( res. is_ok( ) ) ;
745
770
* maybe_bounty = None ;
@@ -834,7 +859,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
834
859
// reserve deposit for new bounty
835
860
let bond = T :: BountyDepositBase :: get ( ) +
836
861
T :: DataDepositPerByte :: get ( ) * ( bounded_description. len ( ) as u32 ) . into ( ) ;
837
- T :: Currency :: reserve ( & proposer, bond)
862
+ T :: Currency :: hold ( & T :: HoldReason :: get ( ) , & proposer, bond)
838
863
. map_err ( |_| Error :: < T , I > :: InsufficientProposersBalance ) ?;
839
864
840
865
BountyCount :: < T , I > :: put ( index + 1 ) ;
@@ -860,7 +885,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
860
885
impl < T : Config < I > , I : ' static > pallet_treasury:: SpendFunds < T , I > for Pallet < T , I > {
861
886
fn spend_funds (
862
887
budget_remaining : & mut BalanceOf < T , I > ,
863
- imbalance : & mut PositiveImbalanceOf < T , I > ,
888
+ imbalance : & mut DebtOf < T , I > ,
864
889
total_weight : & mut Weight ,
865
890
missed_any : & mut bool ,
866
891
) {
@@ -876,14 +901,24 @@ impl<T: Config<I>, I: 'static> pallet_treasury::SpendFunds<T, I> for Pallet<T, I
876
901
bounty. status = BountyStatus :: Funded ;
877
902
878
903
// return their deposit.
879
- let err_amount = T :: Currency :: unreserve ( & bounty. proposer , bounty. bond ) ;
880
- debug_assert ! ( err_amount. is_zero( ) ) ;
904
+ let released_amount = T :: Currency :: release (
905
+ & T :: HoldReason :: get ( ) ,
906
+ & bounty. proposer ,
907
+ bounty. bond ,
908
+ Precision :: Exact ,
909
+ ) ;
910
+ debug_assert ! ( released_amount. is_ok( ) ) ;
881
911
882
912
// fund the bounty account
883
- imbalance . subsume ( T :: Currency :: deposit_creating (
913
+ let _ = T :: Currency :: deposit (
884
914
& Self :: bounty_account_id ( index) ,
885
915
bounty. value ,
886
- ) ) ;
916
+ Precision :: Exact ,
917
+ )
918
+ . and_then ( |debt| {
919
+ imbalance. subsume ( debt) ;
920
+ Ok ( ( ) )
921
+ } ) ;
887
922
888
923
Self :: deposit_event ( Event :: < T , I > :: BountyBecameActive { index } ) ;
889
924
false
0 commit comments