From fde1f68dc06d18299118fecfaf156d2ffd760054 Mon Sep 17 00:00:00 2001 From: Uncle Stinky Date: Fri, 18 Sep 2026 15:13:06 +0300 Subject: [PATCH] migrate from legacy Currency trait to fungibles Signed-off-by: Uncle Stinky --- pallets/exodus/Cargo.toml | 2 +- pallets/exodus/src/benchmarking.rs | 13 ++++++++----- pallets/exodus/src/lib.rs | 29 +++++++++++++++++------------ pallets/weaver/Cargo.toml | 2 +- pallets/weaver/src/lib.rs | 16 ++++++++-------- pallets/weaver/src/tests.rs | 6 ++++++ 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/pallets/exodus/Cargo.toml b/pallets/exodus/Cargo.toml index 42463e5..a3fee87 100644 --- a/pallets/exodus/Cargo.toml +++ b/pallets/exodus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-exodus" -version = "0.0.11" +version = "0.0.12" description = "Threshold signature generation with DKG included" license.workspace = true authors.workspace = true diff --git a/pallets/exodus/src/benchmarking.rs b/pallets/exodus/src/benchmarking.rs index 1a07074..e303f97 100644 --- a/pallets/exodus/src/benchmarking.rs +++ b/pallets/exodus/src/benchmarking.rs @@ -808,7 +808,9 @@ mod benchmarks { let (_, network_curve, _, _) = prepare_pallet::(1usize); let network_id = NetworkIdOf::::default(); - let amount: BalanceOf = 10_000u32.into(); + let base_amount: BalanceOf = 10_000u32.into(); + let amount = base_amount.saturating_add(T::Currency::minimum_balance()); + let bounty = Perbill::from_percent(5); let receiver = EvmAddress::from([69u8; 20]); @@ -819,14 +821,14 @@ mod benchmarks { } }); - let total_existential = T::Currency::minimum_balance(); - let initial_balance = total_existential + let initial_balance = T::Currency::minimum_balance() .saturating_mul(5u32.into()) .saturating_add(amount); - let _ = T::Currency::make_free_balance_be(&caller, initial_balance); + T::Currency::mint_into(&caller, initial_balance).unwrap(); let _ = T::NetworkDataHandler::register_incoming(&network_id, amount).unwrap(); + let total_issuance = T::Currency::total_issuance(); let current_exodus_session = CurrentExodus::::get(); #[extrinsic_call] @@ -840,7 +842,8 @@ mod benchmarks { assert!(ExodusRequests::::contains_key(&network_curve, current_exodus_session)); assert_eq!(CurrentExodus::::get(), current_exodus_session + 1); - assert_eq!(T::Currency::free_balance(&caller), initial_balance - amount); + assert_eq!(T::Currency::balance(&caller), initial_balance - amount); + assert_eq!(T::Currency::total_issuance(), total_issuance - amount); Ok(()) } diff --git a/pallets/exodus/src/lib.rs b/pallets/exodus/src/lib.rs index 3c51a05..30ebd52 100644 --- a/pallets/exodus/src/lib.rs +++ b/pallets/exodus/src/lib.rs @@ -4,8 +4,9 @@ use frame_support::{ pallet_prelude::*, traits::{ - Currency, DisabledValidators, ValidatorSet, ValidatorSetWithIdentification, - OneSessionHandler, WithdrawReasons, ExistenceRequirement, + tokens::{Preservation, Precision, Fortitude}, fungible::{Inspect, Mutate}, + DisabledValidators, ValidatorSet, ValidatorSetWithIdentification, + OneSessionHandler, }, }; use frame_system::{ @@ -223,11 +224,8 @@ type BitmapByAuthority = BoundedBTreeMap, = PendingDkgAuthorities, BlockNumberFor>; type ActivatedState = ReadyDkgAuthorities>; -pub type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - -pub type NetworkIdOf = - <::NetworkDataHandler as NetworkDataBasicHandler>::NetworkId; +pub type BalanceOf = <::Currency as Inspect<::AccountId>>::Balance; +pub type NetworkIdOf = <::NetworkDataHandler as NetworkDataBasicHandler>::NetworkId; pub type ValidatorId = <::ValidatorSet as ValidatorSet< ::AccountId, @@ -394,7 +392,7 @@ pub mod pallet { + MaxEncodedLen; type ValidatorSet: ValidatorSetWithIdentification; - type Currency: Currency; + type Currency: Inspect + Mutate; type NetworkDataHandler: NetworkDataInspectHandler + NetworkDataMutateHandler> @@ -504,6 +502,7 @@ pub mod pallet { NoActiveAuthorities, InvalidSignatureShare, VerifyingShareNotFound, + BelowExistentialBalance, DkgAuthoritiesInProgress, PackagesAlreadyRegistered, DkgAuthoritiesNotInitialized, @@ -1839,16 +1838,22 @@ pub mod pallet { ) -> DispatchResult { let who = ensure_signed(origin)?; - let _imbalance = T::Currency::withdraw( + ensure!( + amount > T::Currency::minimum_balance(), + Error::::BelowExistentialBalance + ); + + let actual_amount = T::Currency::burn_from( &who, amount, - WithdrawReasons::TRANSFER, - ExistenceRequirement::AllowDeath, + Preservation::Expendable, + Precision::Exact, + Fortitude::Polite, )?; Self::do_register_evm_bridge_out_exodus( network_id, - amount, + actual_amount, bounty, receiver, )?; diff --git a/pallets/weaver/Cargo.toml b/pallets/weaver/Cargo.toml index 729cc91..66be1b1 100644 --- a/pallets/weaver/Cargo.toml +++ b/pallets/weaver/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-weaver" -version = "0.0.10" +version = "0.0.11" description = "Weaving a secure cryptographic tapestry across different external chains." license.workspace = true authors.workspace = true diff --git a/pallets/weaver/src/lib.rs b/pallets/weaver/src/lib.rs index 62911d6..766ec07 100644 --- a/pallets/weaver/src/lib.rs +++ b/pallets/weaver/src/lib.rs @@ -3,7 +3,10 @@ use frame_support::{ pallet_prelude::*, - traits::{Currency, Get, OneSessionHandler}, + traits::{ + Get, OneSessionHandler, + tokens::fungible::{Inspect, Mutate}, + }, }; use frame_system::{ pallet_prelude::*, @@ -86,13 +89,10 @@ type ThreadId = u64; type WeavingSession = u64; type ExternalBlockNumber = u64; -type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - -pub type NetworkIdOf = <::NetworkDataHandler as NetworkDataBasicHandler>::NetworkId; +type BalanceOf = <::Currency as Inspect<::AccountId>>::Balance; +type NetworkIdOf = <::NetworkDataHandler as NetworkDataBasicHandler>::NetworkId; type WeavingResult = Result>>; - type WeaversBitmap = BoundedBitmap::MaxAuthoritiesChunks>; #[frame_support::pallet] @@ -117,7 +117,7 @@ pub mod pallet { + MaybeSerializeDeserialize + MaxEncodedLen; - type Currency: Currency; + type Currency: Inspect + Mutate; type NetworkDataHandler: NetworkDataBasicHandler + NetworkDataInspectHandler @@ -458,7 +458,7 @@ pub mod pallet { T::NetworkDataHandler::register_incoming(&network_id, amount) .map_err(|_| Error::::CouldNotRegisterIncoming)?; - let _ = T::Currency::deposit_creating(&receiver, pure_amount); + T::Currency::mint_into(&receiver, pure_amount)?; PulledThreads::::insert(pulled_thread_key, ()); Self::deposit_event(Event::::ThreadPulled { diff --git a/pallets/weaver/src/tests.rs b/pallets/weaver/src/tests.rs index cb26757..a6c2623 100644 --- a/pallets/weaver/src/tests.rs +++ b/pallets/weaver/src/tests.rs @@ -644,6 +644,8 @@ fn should_successfully_pull_evm_thread_and_mint_currency() { let expected_root = H256::from_slice(&root_string); LoomStates::::insert(&network_id, &session, expected_root); + let mut total_issuance = 0; + for insert in inserts.into_iter() { let index_usize = insert.0 as crate::ThreadId; let proof_index = index_usize % 256; // tree depth is fixed to 8 @@ -671,6 +673,7 @@ fn should_successfully_pull_evm_thread_and_mint_currency() { let thread_info = ThreadProof::EvmThreadProof(evm_thread_proof); let pulled_thread_key = thread_info.get_unique_key(session, network_id); + assert_eq!(Balances::total_issuance(), total_issuance); assert_eq!(Balances::free_balance(&receiver_account), 0); assert!(!PulledThreads::::contains_key( &pulled_thread_key @@ -688,12 +691,15 @@ fn should_successfully_pull_evm_thread_and_mint_currency() { let expected_commission = 0u64; let expected_pure_amount = transfer_amount - expected_commission; + total_issuance = total_issuance.saturating_add(expected_pure_amount); + assert_eq!(Balances::total_issuance(), total_issuance); assert_eq!( Balances::free_balance(&receiver_account), expected_pure_amount ); + System::assert_last_event(RuntimeEvent::GhostWeaver(Event::ThreadPulled { pulled_thread_key, network_id,