diff --git a/Cargo.lock b/Cargo.lock index 524a66c77..000473d77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2523,7 +2523,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fc-cli" version = "1.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "clap", "ethereum-types", @@ -2541,7 +2541,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "async-trait", "fp-consensus", @@ -2557,7 +2557,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "async-trait", "ethereum", @@ -2587,7 +2587,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "fc-db", "fc-storage", @@ -2610,7 +2610,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "ethereum", "ethereum-types", @@ -2660,7 +2660,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "ethereum", "ethereum-types", @@ -2673,7 +2673,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "ethereum", "ethereum-types", @@ -2851,7 +2851,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "hex", "impl-serde", @@ -2870,7 +2870,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "ethereum", "parity-scale-codec", @@ -2882,7 +2882,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "ethereum", "ethereum-types", @@ -2896,7 +2896,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "evm", "frame-support", @@ -2911,7 +2911,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "ethereum", "ethereum-types", @@ -2928,7 +2928,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "frame-support", "parity-scale-codec", @@ -2940,7 +2940,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "parity-scale-codec", "serde", @@ -6296,7 +6296,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "ethereum", "ethereum-types", @@ -6332,7 +6332,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "environmental", "evm", @@ -6372,7 +6372,7 @@ dependencies = [ [[package]] name = "pallet-evm-balances" version = "1.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "frame-support", "frame-system", @@ -6386,7 +6386,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "fp-evm", "num", @@ -6395,7 +6395,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-sha3fips" version = "2.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "fp-evm", "tiny-keccak", @@ -6404,7 +6404,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "fp-evm", "ripemd", @@ -6414,7 +6414,7 @@ dependencies = [ [[package]] name = "pallet-evm-system" version = "1.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?branch=locked/polkadot-v0.9.42#e557011a443ea526d18fad0b751708f237fdf461" +source = "git+https://github.com/humanode-network/frontier?branch=evm-balances-fungible-polkadot-v0.9.42#bb889629b9686e54f54109f4c3333c66c38d6232" dependencies = [ "fp-evm", "frame-support", diff --git a/Cargo.toml b/Cargo.toml index e2cd8f243..cac0672ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -139,24 +139,24 @@ substrate-wasm-builder = { git = "https://github.com/humanode-network/substrate" try-runtime-cli = { git = "https://github.com/humanode-network/substrate", branch = "locked/polkadot-v0.9.42", default-features = false } # Frontier fork. -fc-cli = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fc-consensus = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fc-db = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fc-mapping-sync = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fc-rpc = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fc-rpc-core = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fc-storage = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fp-evm = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fp-rpc = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fp-self-contained = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -fp-storage = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -pallet-ethereum = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -pallet-evm = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -pallet-evm-balances = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -pallet-evm-precompile-modexp = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -pallet-evm-precompile-sha3fips = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -pallet-evm-precompile-simple = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } -pallet-evm-system = { git = "https://github.com/humanode-network/frontier", branch = "locked/polkadot-v0.9.42", default-features = false } +fc-cli = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fc-consensus = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fc-db = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fc-mapping-sync = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fc-rpc = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fc-rpc-core = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fc-storage = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fp-evm = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fp-rpc = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fp-self-contained = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +fp-storage = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +pallet-ethereum = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +pallet-evm = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +pallet-evm-balances = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +pallet-evm-precompile-modexp = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +pallet-evm-precompile-sha3fips = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +pallet-evm-precompile-simple = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } +pallet-evm-system = { git = "https://github.com/humanode-network/frontier", branch = "evm-balances-fungible-polkadot-v0.9.42", default-features = false } [profile.release-lto] inherits = "release" diff --git a/crates/bridge-pot-currency-swap/src/existence_optional.rs b/crates/bridge-pot-currency-swap/src/existence_optional.rs index 0a7bd3693..ae543701c 100644 --- a/crates/bridge-pot-currency-swap/src/existence_optional.rs +++ b/crates/bridge-pot-currency-swap/src/existence_optional.rs @@ -3,7 +3,11 @@ use frame_support::{ sp_runtime::{traits::Convert, DispatchError}, - traits::{Currency, ExistenceRequirement, Get, Imbalance, WithdrawReasons}, + traits::{ + fungible::{Balanced, Credit, Inspect}, + tokens::{Fortitude, Precision, Preservation}, + Get, Imbalance, + }, }; use super::{Config, CurrencySwap}; @@ -19,9 +23,9 @@ impl primitives_currency_swap::CurrencySwap>::NegativeImbalance, + incoming_imbalance: Credit, ) -> Result< - >::NegativeImbalance, + Credit, primitives_currency_swap::ErrorFor, > { let amount = incoming_imbalance.peek(); @@ -29,8 +33,9 @@ impl primitives_currency_swap::CurrencySwap imbalance, Err(error) => { @@ -47,8 +52,8 @@ impl primitives_currency_swap::CurrencySwap>::Balance, - ) -> >::Balance { + balance: >::Balance, + ) -> >::Balance { T::BalanceConverter::convert(balance) } } diff --git a/crates/bridge-pot-currency-swap/src/lib.rs b/crates/bridge-pot-currency-swap/src/lib.rs index c9da023f2..53075a9f4 100644 --- a/crates/bridge-pot-currency-swap/src/lib.rs +++ b/crates/bridge-pot-currency-swap/src/lib.rs @@ -6,7 +6,10 @@ use frame_support::{ sp_runtime::traits::Convert, sp_std::marker::PhantomData, - traits::{fungible::Inspect, Currency, Get}, + traits::{ + fungible::{Balanced, Inspect}, + Get, + }, }; pub mod existence_optional; @@ -24,24 +27,16 @@ pub trait Config { type AccountIdTo; /// The currency to swap from. - type CurrencyFrom: Currency - + Inspect< - Self::AccountIdFrom, - Balance = >::Balance, - >; + type CurrencyFrom: Inspect + Balanced; /// The currency to swap to. - type CurrencyTo: Currency - + Inspect< - Self::AccountIdTo, - Balance = >::Balance, - >; + type CurrencyTo: Inspect + Balanced; /// The converter to determine how the balance amount should be converted from one currency to /// another. type BalanceConverter: Convert< - >::Balance, - >::Balance, + >::Balance, + >::Balance, >; /// The account to land the balances to when receiving the funds as part of the swap operation. diff --git a/crates/humanode-runtime/src/lib.rs b/crates/humanode-runtime/src/lib.rs index 01deba7cb..eafdb3c78 100644 --- a/crates/humanode-runtime/src/lib.rs +++ b/crates/humanode-runtime/src/lib.rs @@ -404,48 +404,57 @@ impl pallet_pot::Config for Runtime { type RuntimeEvent = RuntimeEvent; type AccountId = AccountId; type PalletId = TreasuryPotPalletId; - type Currency = Balances; + type FungibleAsset = Balances; } impl pallet_pot::Config for Runtime { type RuntimeEvent = RuntimeEvent; type AccountId = AccountId; type PalletId = FeesPotPalletId; - type Currency = Balances; + type FungibleAsset = Balances; } impl pallet_pot::Config for Runtime { type RuntimeEvent = RuntimeEvent; type AccountId = AccountId; type PalletId = TokenClaimsPotPalletId; - type Currency = Balances; + type FungibleAsset = Balances; } impl pallet_pot::Config for Runtime { type RuntimeEvent = RuntimeEvent; type AccountId = AccountId; type PalletId = NativeToEvmSwapBridgePotPalletId; - type Currency = Balances; + type FungibleAsset = Balances; } impl pallet_pot::Config for Runtime { type RuntimeEvent = RuntimeEvent; type AccountId = EvmAccountId; type PalletId = EvmToNativeSwapBridgePotPalletId; - type Currency = EvmBalances; + type FungibleAsset = EvmBalances; } impl pallet_balances::Config for Runtime { - type MaxLocks = ConstU32<50>; - type MaxReserves = (); + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; type ReserveIdentifier = [u8; 8]; /// The type for recording an account's balance. type Balance = Balance; - /// The ubiquitous event type. - type RuntimeEvent = RuntimeEvent; - type DustRemoval = TreasuryPot; + type DustRemoval = pallet_pot::OnUnbalancedOverCredit; type ExistentialDeposit = ConstU128<500>; type AccountStore = System; + type MaxLocks = ConstU32<50>; + // Until you introduce pallets which use holds and freezes, + // then these can safely be set to ConstU32<0> in the case of `MaxHolds`, `MaxFreezes` + // and () in the case of `HoldIdentifier`, `FreezeIdentifier`. + // + // . + type HoldIdentifier = (); + type FreezeIdentifier = (); + type MaxReserves = (); + type MaxHolds = ConstU32<0>; + type MaxFreezes = ConstU32<0>; type WeightInfo = weights::pallet_balances::WeightInfo; } diff --git a/crates/pallet-pot/src/lib.rs b/crates/pallet-pot/src/lib.rs index a822c1fc1..ac09983ba 100644 --- a/crates/pallet-pot/src/lib.rs +++ b/crates/pallet-pot/src/lib.rs @@ -5,7 +5,10 @@ #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::traits::{Imbalance, OnUnbalanced, StorageVersion}; +use frame_support::traits::{ + fungible::{Balanced, Credit, Inspect, Mutate, Unbalanced}, + Imbalance, OnUnbalanced, StorageVersion, +}; use frame_support::{pallet_prelude::*, traits::Currency, PalletId}; use frame_system::pallet_prelude::*; use sp_runtime::traits::{AccountIdConversion, CheckedSub, MaybeDisplay, Saturating}; @@ -17,11 +20,14 @@ const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); /// The balance of accessor for the currency. pub type BalanceOf = - <>::Currency as Currency<>::AccountId>>::Balance; + <>::FungibleAsset as Currency<>::AccountId>>::Balance; /// The negative implanace accessor. pub type NegativeImbalanceOf = - <>::Currency as Currency<>::AccountId>>::NegativeImbalance; + <>::FungibleAsset as Currency<>::AccountId>>::NegativeImbalance; + +/// The credit accessor. +pub type CreditOf = Credit<>::AccountId, >::FungibleAsset>; /// The initial state of the pot, for use in genesis. #[cfg(feature = "std")] @@ -63,8 +69,12 @@ pub mod pallet { + Ord + MaxEncodedLen; - /// The currency to operate with. - type Currency: Currency<>::AccountId>; + /// The fungible asset to operate with. + type FungibleAsset: Currency<>::AccountId> + + Inspect<>::AccountId, Balance = BalanceOf> + + Balanced<>::AccountId, Balance = BalanceOf> + + Unbalanced<>::AccountId, Balance = BalanceOf> + + Mutate<>::AccountId, Balance = BalanceOf>; /// The pot's pallet id, used for deriving its sovereign account ID. #[pallet::constant] @@ -127,20 +137,20 @@ pub mod pallet { // Just pass though. } InitialState::Initialized => { - let current = T::Currency::free_balance(&account_id); - let min = T::Currency::minimum_balance(); + let current = T::FungibleAsset::balance(&account_id); + let min = >::minimum_balance(); assert!( current >= min, "the initial pot balance must be greater or equal than the existential balance" ); } InitialState::Balance { balance } => { - let min = T::Currency::minimum_balance(); + let min = >::minimum_balance(); assert!( balance >= min, "the configured initial pot balance must be greater or equal than the existential balance" ); - let _ = T::Currency::make_free_balance_be(&account_id, balance); + let _ = T::FungibleAsset::set_balance(&account_id, balance); } } } @@ -159,9 +169,9 @@ impl, I: 'static> Pallet { // The existential deposit (`minimum_balance`) is not part of // the pot so the pot account never gets killed. pub fn balance() -> BalanceOf { - T::Currency::free_balance(&Self::account_id()) + T::FungibleAsset::balance(&Self::account_id()) // Must never be less than 0 but better be safe. - .saturating_sub(T::Currency::minimum_balance()) + .saturating_sub(>::minimum_balance()) } /// Update the inactive supply for this pot. @@ -169,17 +179,17 @@ impl, I: 'static> Pallet { /// This function uses the whole balance of the account, unlike [`Self::balance`], /// which subtracts the existential balance. fn update_inactive() -> Weight { - let balance = T::Currency::free_balance(&Self::account_id()); + let balance = T::FungibleAsset::balance(&Self::account_id()); let current = Inactive::::get(); let mut weight = T::DbWeight::get().reads(2); if balance != current { if let Some(delta) = balance.checked_sub(¤t) { - T::Currency::deactivate(delta) + >::deactivate(delta) } if let Some(delta) = current.checked_sub(&balance) { - T::Currency::reactivate(delta) + >::reactivate(delta) } Inactive::::put(balance); @@ -195,10 +205,25 @@ impl, I: 'static> OnUnbalanced> for Palle let numeric_amount = amount.peek(); // Must resolve into existing but better to be safe. - T::Currency::resolve_creating(&Self::account_id(), amount); + T::FungibleAsset::resolve_creating(&Self::account_id(), amount); Self::deposit_event(Event::Deposit { value: numeric_amount, }); } } + +pub struct OnUnbalancedOverCredit(Pallet); + +impl, I: 'static> OnUnbalanced> for OnUnbalancedOverCredit { + fn on_nonzero_unbalanced(amount: CreditOf) { + let numeric_amount = amount.peek(); + + T::FungibleAsset::resolve(&Pallet::::account_id(), amount); + T::FungibleAsset::done_deposit(&Pallet::::account_id(), numeric_amount); + + Pallet::::deposit_event(Event::Deposit { + value: numeric_amount, + }); + } +} diff --git a/crates/primitives-currency-swap-proxy/src/lib.rs b/crates/primitives-currency-swap-proxy/src/lib.rs index 152050ebf..6b630d726 100644 --- a/crates/primitives-currency-swap-proxy/src/lib.rs +++ b/crates/primitives-currency-swap-proxy/src/lib.rs @@ -5,7 +5,7 @@ use frame_support::{ sp_std::marker::PhantomData, - traits::{Currency, OnUnbalanced}, + traits::{fungible::Credit, OnUnbalanced}, }; use primitives_currency_swap::CurrencySwap; @@ -21,15 +21,13 @@ type CurrencyToFor = <::CurrencySwap as CurrencySwap< ::AccountIdTo, >>::To; -/// A utility type alias for easy access to [`Currency::NegativeImbalance`] of +/// A utility type alias for easy access to [`Credit`] of /// [`CurrencySwap::From`] of [`Config::CurrencySwap`]. -type CurrencyFromNegativeImbalanceFor = - as Currency<::AccountIdFrom>>::NegativeImbalance; +type CurrencyFromCreditFor = Credit<::AccountIdFrom, CurrencyFromFor>; -/// A utility type alias for easy access to [`Currency::NegativeImbalance`] of +/// A utility type alias for easy access to [`Credit`] of /// [`CurrencySwap::To`] of [`Config::CurrencySwap`]. -type CurrencyToNegativeImbalanceFor = - as Currency<::AccountIdTo>>::NegativeImbalance; +type CurrencyToCreditFor = Credit<::AccountIdTo, CurrencyToFor>; /// The general config for the currency swap proxy implementations. pub trait Config { @@ -47,14 +45,13 @@ pub trait Config { /// If swap fails, will try to pass the original imbalance to the `Fallback`. pub struct SwapUnbalanced(PhantomData<(T, To, Fallback)>); -impl OnUnbalanced> - for SwapUnbalanced +impl OnUnbalanced> for SwapUnbalanced where T: Config, - To: OnUnbalanced>, - Fallback: OnUnbalanced>, + To: OnUnbalanced>, + Fallback: OnUnbalanced>, { - fn on_nonzero_unbalanced(amount: CurrencyFromNegativeImbalanceFor) { + fn on_nonzero_unbalanced(amount: CurrencyFromCreditFor) { let amount = match T::CurrencySwap::swap(amount) { Ok(amount) => amount, Err(primitives_currency_swap::Error { diff --git a/crates/primitives-currency-swap/src/lib.rs b/crates/primitives-currency-swap/src/lib.rs index 7b8601c9f..60b0b8cb2 100644 --- a/crates/primitives-currency-swap/src/lib.rs +++ b/crates/primitives-currency-swap/src/lib.rs @@ -5,29 +5,24 @@ use frame_support::{ sp_runtime::DispatchError, - traits::{fungible::Inspect, Currency}, + traits::fungible::{Balanced, Credit, Inspect}, }; /// Currency swap interface. pub trait CurrencySwap { /// The currency to convert from. - type From: Currency - + Inspect>::Balance>; + type From: Inspect + Balanced; /// The currency to convert to. - type To: Currency - + Inspect>::Balance>; + type To: Inspect + Balanced; /// A possible error happens during the actual swap logic. type Error: Into; /// The actual swap logic. fn swap( - imbalance: FromNegativeImbalanceFor, - ) -> Result< - ToNegativeImbalanceFor, - ErrorFor, - >; + imbalance: Credit, + ) -> Result, ErrorFor>; /// Obtain the estimated resulted balance value. fn estimate_swapped_balance( @@ -37,27 +32,15 @@ pub trait CurrencySwap { /// An easy way to access the [`Currency::Balance`] of [`CurrencySwap::From`] of `T`. pub type FromBalanceFor = - <>::From as Currency>::Balance; - -/// An easy way to access the [`Currency::NegativeImbalance`] of [`CurrencySwap::From`] of `T`. -pub type FromNegativeImbalanceFor = <>::From as Currency>::NegativeImbalance; + <>::From as Inspect>::Balance; /// An easy way to access the [`Currency::Balance`] of [`CurrencySwap::To`] of `T`. pub type ToBalanceFor = - <>::To as Currency>::Balance; - -/// An easy way to access the [`Currency::NegativeImbalance`] of [`CurrencySwap::To`] of `T`. -pub type ToNegativeImbalanceFor = <>::To as Currency>::NegativeImbalance; + <>::To as Inspect>::Balance; /// A type alias for compact declaration of the error type for the [`CurrencySwap::swap`] call. pub type ErrorFor = Error< - FromNegativeImbalanceFor, + Credit>::From>, >::Error, >; diff --git a/logs.txt b/logs.txt new file mode 100644 index 000000000..a1ebeda77 --- /dev/null +++ b/logs.txt @@ -0,0 +1,145 @@ +warning: /Users/dmitrylavrenov/humanode/humanode/crates/keystore-bioauth-account-id/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-currency-swap/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-dummy-precompiles-code/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/precompile-evm-accounts-mapping/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-bootnodes/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-balanced-currency-swap-bridges-initializer/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/author-ext-api/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-chain-start-moment/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-humanode-session/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-token-claims/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-pot/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/precompile-utils/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/humanode-peer/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/precompile-bioauth/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-vesting/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/robonode-server/Cargo.toml: unused manifest key: dev-dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-evm-accounts-mapping/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/humanode-runtime/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/precompile-native-currency/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/vesting-schedule-linear/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/bioauth-flow-api/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/primitives-auth-ticket/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-chain-properties/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/primitives-ethereum/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-bioauth/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/primitives-liveness-data/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-erc20-support/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/pallet-ethereum-chain-id/Cargo.toml: unused manifest key: dependencies.codec.package +warning: /Users/dmitrylavrenov/humanode/humanode/crates/precompile-currency-swap/Cargo.toml: unused manifest key: dependencies.codec.package + Compiling humanode-runtime v0.1.0 (/Users/dmitrylavrenov/humanode/humanode/crates/humanode-runtime) + Checking pallet-pot v0.1.0 (/Users/dmitrylavrenov/humanode/humanode/crates/pallet-pot) +warning: missing documentation for a struct + --> crates/pallet-pot/src/lib.rs:216:1 + | +216 | pub struct OnUnbalancedOverCredit(Pallet); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: requested on the command line with `-W missing-docs` + +warning: unused `Result` that must be used + --> crates/pallet-pot/src/lib.rs:222:9 + | +222 | T::FungibleAsset::resolve(&Pallet::::account_id(), amount); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this `Result` may be an `Err` variant, which should be handled + = note: `#[warn(unused_must_use)]` on by default +help: use `let _ = ...` to ignore the resulting value + | +222 | let _ = T::FungibleAsset::resolve(&Pallet::::account_id(), amount); + | +++++++ + +warning: `pallet-pot` (lib) generated 2 warnings +error: failed to run custom build command for `humanode-runtime v0.1.0 (/Users/dmitrylavrenov/humanode/humanode/crates/humanode-runtime)` + +Caused by: + process didn't exit successfully: `/Users/dmitrylavrenov/humanode/humanode/target/debug/build/humanode-runtime-05e5ccf412b61116/build-script-build` (exit status: 1) + --- stdout + Information that should be included in a bug report. + Executing build command: env -u CARGO_ENCODED_RUSTFLAGS -u CARGO_TARGET_DIR RUSTFLAGS="-C target-cpu=mvp -C target-feature=-sign-ext -C link-arg=--export-table -C link-arg=--import-memory -Clink-arg=--export=__heap_base -C target-cpu=mvp -C target-feature=-sign-ext " SKIP_WASM_BUILD="" "/Users/dmitrylavrenov/.rustup/toolchains/nightly-2023-10-08-aarch64-apple-darwin/bin/cargo" "rustc" "--target=wasm32-unknown-unknown" "--manifest-path=/Users/dmitrylavrenov/humanode/humanode/target/debug/wbuild/humanode-runtime/Cargo.toml" "--color=always" "--profile" "release" + Using rustc version: rustc 1.75.0-nightly (97c81e1b5 2023-10-07) + + + --- stderr + warning: /Users/dmitrylavrenov/humanode/humanode/crates/humanode-runtime/Cargo.toml: unused manifest key: dependencies.codec.package + warning: associated function `issue_validators_set_init` is never used + --> /Users/dmitrylavrenov/humanode/humanode/crates/pallet-bioauth/src/lib.rs:665:12 + | + 564 | impl Pallet { + | ------------------------- associated function in this implementation + ... + 665 | fn issue_validators_set_init( + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(dead_code)]` on by default + + warning: `pallet-bioauth` (lib) generated 1 warning + warning: unused import: `CheckedAdd` + --> /Users/dmitrylavrenov/humanode/humanode/crates/pallet-token-claims/src/lib.rs:45:45 + | + 45 | use frame_support::sp_runtime::traits::{CheckedAdd, Zero}; + | ^^^^^^^^^^ + | + = note: `#[warn(unused_imports)]` on by default + + warning: unused import: `Zero` + --> /Users/dmitrylavrenov/humanode/humanode/crates/pallet-token-claims/src/lib.rs:45:57 + | + 45 | use frame_support::sp_runtime::traits::{CheckedAdd, Zero}; + | ^^^^ + + warning: `pallet-token-claims` (lib) generated 2 warnings (run `cargo fix --lib -p pallet-token-claims` to apply 1 suggestion) + warning: unused `Result` that must be used + --> /Users/dmitrylavrenov/humanode/humanode/crates/pallet-pot/src/lib.rs:222:9 + | + 222 | T::FungibleAsset::resolve(&Pallet::::account_id(), amount); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this `Result` may be an `Err` variant, which should be handled + = note: `#[warn(unused_must_use)]` on by default + help: use `let _ = ...` to ignore the resulting value + | + 222 | let _ = T::FungibleAsset::resolve(&Pallet::::account_id(), amount); + | +++++++ + + warning: `pallet-pot` (lib) generated 1 warning + Compiling humanode-runtime v0.1.0 (/Users/dmitrylavrenov/humanode/humanode/crates/humanode-runtime) + error[E0277]: the trait bound `pallet_evm_balances::Pallet: hidden_include::traits::fungible::Mutate` is not satisfied + --> /Users/dmitrylavrenov/humanode/humanode/crates/humanode-runtime/src/lib.rs:435:26 + | + 435 | type FungibleAsset = EvmBalances; + | ^^^^^^^^^^^ the trait `hidden_include::traits::fungible::Mutate` is not implemented for `pallet_evm_balances::Pallet` + | + = help: the following other types implement trait `hidden_include::traits::fungible::Mutate`: + as hidden_include::traits::fungible::Mutate<::AccountId>> + as hidden_include::traits::fungible::Mutate> + note: required by a bound in `pallet_pot::Config::FungibleAsset` + --> /Users/dmitrylavrenov/humanode/humanode/crates/pallet-pot/src/lib.rs:77:15 + | + 73 | type FungibleAsset: Currency<>::AccountId> + | ------------- required by a bound in this associated type + ... + 77 | + Mutate<>::AccountId, Balance = BalanceOf>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Config::FungibleAsset` + + error[E0277]: the trait bound `pallet_evm_balances::Pallet: hidden_include::traits::fungible::Balanced` is not satisfied + --> /Users/dmitrylavrenov/humanode/humanode/crates/humanode-runtime/src/lib.rs:435:26 + | + 435 | type FungibleAsset = EvmBalances; + | ^^^^^^^^^^^ the trait `hidden_include::traits::fungible::Balanced` is not implemented for `pallet_evm_balances::Pallet` + | + = help: the following other types implement trait `hidden_include::traits::fungible::Balanced`: + as hidden_include::traits::fungible::Balanced<::AccountId>> + as hidden_include::traits::fungible::Balanced> + note: required by a bound in `pallet_pot::Config::FungibleAsset` + --> /Users/dmitrylavrenov/humanode/humanode/crates/pallet-pot/src/lib.rs:75:15 + | + 73 | type FungibleAsset: Currency<>::AccountId> + | ------------- required by a bound in this associated type + 74 | + Inspect<>::AccountId, Balance = BalanceOf> + 75 | + Balanced<>::AccountId, Balance = BalanceOf> + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Config::FungibleAsset` + + For more information about this error, try `rustc --explain E0277`. + error: could not compile `humanode-runtime` (lib) due to 2 previous errors