From cc217c5c5d260a753a32ddc69318d42eeff898a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Thu, 28 Sep 2023 13:33:30 -0500 Subject: [PATCH] Handling a community-governed treasury account (#300) * chore(communities:tests): remove qualified references to sp_runtime::DispatchError * refactor(communities:functions): simplify qualified references to types and traits * feat(pallets/communities): implement assets_transfer * feat(pallets/communities): implement balance_transfer * chore(pallets/communities): update docs * fix(communities:functions/tokens): apply fmt * refactor(communities:functions/tokens): rename mod to treasury * refactor(communities:functions): move do_create_community_account to treasury module * chore(communities:functions/registration): rename as registry * m:change(communities:registry): directly override value on do_set_metadata --- pallets/communities/README.md | 7 +- .../communities/src/functions/challenges.rs | 4 +- pallets/communities/src/functions/getters.rs | 4 +- .../communities/src/functions/membership.rs | 14 +- pallets/communities/src/functions/mod.rs | 7 +- .../communities/src/functions/registration.rs | 77 ------- pallets/communities/src/functions/registry.rs | 41 ++++ pallets/communities/src/functions/treasury.rs | 48 +++++ pallets/communities/src/lib.rs | 58 ++++- pallets/communities/src/tests.rs | 199 +++++++++++++++++- pallets/communities/src/types.rs | 6 +- pallets/communities/src/weights.rs | 46 ++++ 12 files changed, 402 insertions(+), 109 deletions(-) delete mode 100644 pallets/communities/src/functions/registration.rs create mode 100644 pallets/communities/src/functions/registry.rs create mode 100644 pallets/communities/src/functions/treasury.rs diff --git a/pallets/communities/README.md b/pallets/communities/README.md index 6ddb9eec..5a45cd42 100644 --- a/pallets/communities/README.md +++ b/pallets/communities/README.md @@ -24,9 +24,8 @@ facilitating its participants to have governance over the community entity - **Community:** An entity comprised of _members_ —each one defined by their [`AccountId`][1]— with a given _description_ who can vote on _proposals_ and actively take decisions on behalf of it. Communities are given a - _treasury account_ and can issue _governance_ and _economic_ tokens. It is - required that a community contributes to the network to be active and - operate within it. + _treasury account_ and can issue tokens. It is required that a community + contributes to the network to be active and operate within it. - **Community Description:** A set of metadata used to identify a community distinctively. Typically, a name, a list of locations (given as a list of one or more [`H3Index`][2]), and a list of URL links. @@ -176,5 +175,5 @@ dispatched through an approved proposal. ! [6]: https://github.com/virto-network/virto-node/pull/282 [7]: https://paritytech.github.io/substrate/master/pallet_assets/index.html#terminology [8]: https://docs.substrate.io/reference/glossary/#existential-deposit -[t00]: src/lib.rs#L233 +[t00]: src/lib.rs#L237 [t01]: src/types.rs#L57 diff --git a/pallets/communities/src/functions/challenges.rs b/pallets/communities/src/functions/challenges.rs index 8c291e74..37ebf3ca 100644 --- a/pallets/communities/src/functions/challenges.rs +++ b/pallets/communities/src/functions/challenges.rs @@ -1,7 +1,7 @@ use super::*; impl Pallet { - pub(crate) fn ensure_active(community_id: &T::CommunityId) -> DispatchResult { + pub(crate) fn ensure_active(community_id: &CommunityIdOf) -> DispatchResult { let community_info = >::try_get(community_id).map_err(|_| Error::::CommunityDoesNotExist)?; @@ -13,7 +13,7 @@ impl Pallet { } #[allow(dead_code)] - pub(crate) fn do_force_complete_challenge(community_id: &T::CommunityId) -> DispatchResult { + pub(crate) fn do_force_complete_challenge(community_id: &CommunityIdOf) -> DispatchResult { >::try_mutate_exists(community_id, |value| { let Some(community_info) = value else { return Err::<(), DispatchError>(Error::::CommunityDoesNotExist.into()); diff --git a/pallets/communities/src/functions/getters.rs b/pallets/communities/src/functions/getters.rs index 9a106b51..e6591ec2 100644 --- a/pallets/communities/src/functions/getters.rs +++ b/pallets/communities/src/functions/getters.rs @@ -2,11 +2,11 @@ use super::*; use frame_support::sp_runtime::traits::AccountIdConversion; impl Pallet { - pub(crate) fn get_community_account_id(community_id: &T::CommunityId) -> T::AccountId { + pub(crate) fn get_community_account_id(community_id: &CommunityIdOf) -> AccountIdOf { T::PalletId::get().into_sub_account_truncating(community_id) } - pub(crate) fn get_community_admin(community_id: &T::CommunityId) -> Result { + pub(crate) fn get_community_admin(community_id: &CommunityIdOf) -> Result, DispatchError> { let Some(community) = >::get(community_id) else { Err(Error::::CommunityDoesNotExist)? }; diff --git a/pallets/communities/src/functions/membership.rs b/pallets/communities/src/functions/membership.rs index 39e73d0f..6cf9fb74 100644 --- a/pallets/communities/src/functions/membership.rs +++ b/pallets/communities/src/functions/membership.rs @@ -3,11 +3,11 @@ use super::*; impl Pallet { pub(crate) fn ensure_origin_member( origin: OriginFor, - community_id: &T::CommunityId, + community_id: &CommunityIdOf, ) -> Result<(), DispatchError> { let caller = ensure_signed(origin)?; - if !>::contains_key(community_id, caller) { + if Self::member_information(community_id, caller).is_none() { return Err(DispatchError::BadOrigin); } @@ -16,7 +16,7 @@ impl Pallet { pub(crate) fn ensure_origin_privileged( origin: OriginFor, - community_id: &T::CommunityId, + community_id: &CommunityIdOf, ) -> Result<(), DispatchError> { if let Some(caller) = ensure_signed_or_root(origin)? { if caller != Self::get_community_admin(community_id)? { @@ -27,7 +27,7 @@ impl Pallet { Ok(()) } - pub(crate) fn do_insert_member(community_id: &T::CommunityId, who: &T::AccountId) -> DispatchResult { + pub(crate) fn do_insert_member(community_id: &CommunityIdOf, who: &AccountIdOf) -> DispatchResult { >::try_mutate_exists(community_id, who, |value| { if value.is_some() { return Err(Error::::AlreadyAMember.into()); @@ -37,7 +37,7 @@ impl Pallet { *value = Some(Default::default()); // Increases member count - let members_count = >::try_get(community_id).unwrap_or_default(); + let members_count = Self::members_count(community_id).unwrap_or_default(); >::set(community_id, members_count.checked_add(1)); Ok(()) @@ -50,7 +50,7 @@ impl Pallet { return Err(Error::::NotAMember.into()); } - let Some(community_info) = >::get(community_id) else { + let Some(community_info) = Self::community(community_id) else { return Err(Error::::CommunityDoesNotExist.into()); }; @@ -62,7 +62,7 @@ impl Pallet { *value = None; // Decreases member count - let members_count = >::try_get(community_id).unwrap_or_default(); + let members_count = Self::members_count(community_id).unwrap_or_default(); >::set(community_id, members_count.checked_sub(1)); Ok(()) diff --git a/pallets/communities/src/functions/mod.rs b/pallets/communities/src/functions/mod.rs index d77a80aa..a75ef9e5 100644 --- a/pallets/communities/src/functions/mod.rs +++ b/pallets/communities/src/functions/mod.rs @@ -1,9 +1,14 @@ pub(self) use crate::*; pub(self) use frame_support::pallet_prelude::*; +pub(self) use frame_support::traits::tokens::{ + fungible::{Inspect, Mutate, MutateFreeze}, + fungibles::Mutate as MutateFuns, +}; pub(self) use frame_system::pallet_prelude::*; pub(self) use types::*; mod challenges; mod getters; mod membership; -mod registration; +mod registry; +mod treasury; diff --git a/pallets/communities/src/functions/registration.rs b/pallets/communities/src/functions/registration.rs deleted file mode 100644 index ba8ad4cb..00000000 --- a/pallets/communities/src/functions/registration.rs +++ /dev/null @@ -1,77 +0,0 @@ -use super::*; - -use frame_support::traits::tokens::fungible; - -impl Pallet { - pub(crate) fn community_exists(community_id: &T::CommunityId) -> bool { - >::contains_key(community_id) - } - - /// Stores an initial info about the community - /// Sets the caller as the community admin, the initial community state - /// to its default value(awaiting) - pub(crate) fn do_register_community(who: &T::AccountId, community_id: &T::CommunityId) -> DispatchResult { - // Check that the community doesn't exist - if Self::community_exists(community_id) { - return Err(Error::::CommunityAlreadyExists.into()); - } - - >::insert( - community_id.clone(), - Community { - admin: who.clone(), - state: Default::default(), - sufficient_asset_id: None, - }, - ); - - Self::do_insert_member(community_id, who)?; - - Ok(()) - } - - /// Takes a deposit from the caller and - pub(crate) fn do_create_community_account( - caller: &AccountIdOf, - community_id: &CommunityIdOf, - ) -> DispatchResult { - let community_account_id = Self::get_community_account_id(community_id); - let minimum_balance = >::minimum_balance(); - - >::transfer( - caller, - &community_account_id, - minimum_balance, - frame_support::traits::tokens::Preservation::Preserve, - )?; - - // Lock funds so the account can exist at all times - >::set_freeze( - &T::FreezeIdentifier::get(), - &community_account_id, - minimum_balance, - )?; - - Ok(()) - } - - pub(crate) fn do_set_metadata( - community_id: &CommunityIdOf, - value: types::CommunityMetadata, - ) -> DispatchResult { - >::try_mutate(community_id, |metadata| { - if let Some(metadata) = metadata { - metadata.name = value.name; - metadata.description = value.description; - metadata.urls = value.urls; - metadata.locations = value.locations; - } else { - *metadata = Some(value); - } - - Ok::<(), DispatchError>(()) - })?; - - Ok(()) - } -} diff --git a/pallets/communities/src/functions/registry.rs b/pallets/communities/src/functions/registry.rs new file mode 100644 index 00000000..c793a82a --- /dev/null +++ b/pallets/communities/src/functions/registry.rs @@ -0,0 +1,41 @@ +use super::*; + +impl Pallet { + pub(crate) fn community_exists(community_id: &CommunityIdOf) -> bool { + Self::community(community_id).is_some() + } + + /// Stores an initial info about the community + /// Sets the caller as the community admin, the initial community state + /// to its default value(awaiting) + pub(crate) fn do_register_community(who: &AccountIdOf, community_id: &CommunityIdOf) -> DispatchResult { + // Check that the community doesn't exist + if Self::community_exists(community_id) { + return Err(Error::::CommunityAlreadyExists.into()); + } + + >::insert( + community_id.clone(), + Community { + admin: who.clone(), + state: Default::default(), + sufficient_asset_id: None, + }, + ); + + Self::do_insert_member(community_id, who)?; + + Ok(()) + } + + pub(crate) fn do_set_metadata( + community_id: &CommunityIdOf, + value: types::CommunityMetadata, + ) -> DispatchResult { + >::try_mutate(community_id, |metadata| { + *metadata = Some(value); + + Ok(()) + }) + } +} diff --git a/pallets/communities/src/functions/treasury.rs b/pallets/communities/src/functions/treasury.rs new file mode 100644 index 00000000..717817de --- /dev/null +++ b/pallets/communities/src/functions/treasury.rs @@ -0,0 +1,48 @@ +use super::*; +use frame_support::traits::tokens::Preservation; + +impl Pallet { + /// Takes a deposit from the caller and + pub(crate) fn do_create_community_account( + caller: &AccountIdOf, + community_id: &CommunityIdOf, + ) -> DispatchResult { + let community_account_id = Self::get_community_account_id(community_id); + let minimum_balance = T::Balances::minimum_balance(); + + T::Balances::transfer( + caller, + &community_account_id, + minimum_balance, + frame_support::traits::tokens::Preservation::Preserve, + )?; + + // Lock funds so the account can exist at all times + T::Balances::set_freeze(&T::FreezeIdentifier::get(), &community_account_id, minimum_balance)?; + + Ok(()) + } + + pub(crate) fn do_assets_transfer( + community_id: &CommunityIdOf, + asset_id: AssetIdOf, + dest: &AccountIdOf, + amount: BalanceOf, + ) -> DispatchResult { + let community_account_id = Self::get_community_account_id(community_id); + T::Assets::transfer(asset_id, &community_account_id, dest, amount, Preservation::Preserve)?; + + Ok(()) + } + + pub(crate) fn do_balance_transfer( + community_id: &CommunityIdOf, + dest: &AccountIdOf, + amount: NativeBalanceOf, + ) -> DispatchResult { + let community_account_id = Self::get_community_account_id(community_id); + T::Balances::transfer(&community_account_id, dest, amount, Preservation::Preserve)?; + + Ok(()) + } +} diff --git a/pallets/communities/src/lib.rs b/pallets/communities/src/lib.rs index e367bb61..5e3f5d0e 100644 --- a/pallets/communities/src/lib.rs +++ b/pallets/communities/src/lib.rs @@ -29,9 +29,8 @@ //! - **Community:** An entity comprised of _members_ —each one defined by their //! [`AccountId`][1]— with a given _description_ who can vote on _proposals_ //! and actively take decisions on behalf of it. Communities are given a -//! _treasury account_ and can issue _governance_ and _economic_ tokens. It is -//! required that a community contributes to the network to be active and -//! operate within it. +//! _treasury account_ and can issue tokens. It is required that a community +//! contributes to the network to be active and operate within it. //! - **Community Description:** A set of metadata used to identify a community //! distinctively. Typically, a name, a list of locations (given as a list of //! one or more [`H3Index`][2]), and a list of URL links. @@ -144,9 +143,9 @@ //! _"free"_," further ones would be subject to network-wide referenda. //! - `close_proposal`: Forcefully closes a proposal, dispatching the call when //! approved. -//! - `assets_transfer`: Transfers an amount of a given asset from the treasury -//! account to a beneficiary. -//! - `balance_transfer`: Transfers funds from the treasury account to a +//! - [`assets_transfer`][c04]: Transfers an amount of a given asset from the +//! treasury account to a beneficiary. +//! - [`balance_transfer`][c05]: Transfers funds from the treasury account to a //! beneficiary. //! - `set_sufficient_asset`: Marks an [asset][7] issued by the community as //! sufficient. Only one asset at a time can be marked as such. @@ -191,6 +190,8 @@ //! [c01]: `crate::Pallet::set_metadata` //! [c02]: `crate::Pallet::add_member` //! [c03]: `crate::Pallet::remove_member` +//! [c04]: `crate::Pallet::assets_transfer` +//! [c05]: `crate::Pallet::balance_transfer` //! //! [g00]: `crate::Pallet::community` //! [g01]: `crate::Pallet::metadata` @@ -462,5 +463,50 @@ pub mod pallet { Ok(()) } + + /// Transfers an amount of a given asset from the treasury account to a + /// beneficiary. + #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::assets_transfer())] + pub fn assets_transfer( + origin: OriginFor, + community_id: T::CommunityId, + asset_id: AssetIdOf, + dest: AccountIdLookupOf, + amount: BalanceOf, + ) -> DispatchResult { + Self::ensure_origin_privileged(origin, &community_id)?; + Self::ensure_active(&community_id)?; + + Self::do_assets_transfer( + &community_id, + asset_id, + &<::Lookup as StaticLookup>::lookup(dest)?, + amount, + )?; + + Ok(()) + } + + /// Transfers funds from the treasury account to a beneficiary + #[pallet::call_index(5)] + #[pallet::weight(T::WeightInfo::balance_transfer())] + pub fn balance_transfer( + origin: OriginFor, + community_id: T::CommunityId, + dest: AccountIdLookupOf, + amount: NativeBalanceOf, + ) -> DispatchResult { + Self::ensure_origin_privileged(origin, &community_id)?; + Self::ensure_active(&community_id)?; + + Self::do_balance_transfer( + &community_id, + &<::Lookup as StaticLookup>::lookup(dest)?, + amount, + )?; + + Ok(()) + } } } diff --git a/pallets/communities/src/tests.rs b/pallets/communities/src/tests.rs index c3076908..be49063d 100644 --- a/pallets/communities/src/tests.rs +++ b/pallets/communities/src/tests.rs @@ -2,6 +2,7 @@ use crate::types::*; use crate::{mock::*, CommunityInfo, Error as PalletError}; use frame_support::traits::fungible; use frame_support::{assert_noop, assert_ok}; +use sp_runtime::{ArithmeticError, DispatchError}; type Error = PalletError; @@ -56,7 +57,7 @@ mod apply { new_test_ext().execute_with(|| { assert_noop!( Communities::do_create_community_account(&COMMUNITY_ADMIN, &COMMUNITY), - sp_runtime::DispatchError::Arithmetic(sp_runtime::ArithmeticError::Underflow) + DispatchError::Arithmetic(ArithmeticError::Underflow) ); }); } @@ -153,7 +154,7 @@ mod set_metadata { // Fail if trying to call from unsigned origin assert_noop!( Communities::set_metadata(RuntimeOrigin::none(), COMMUNITY, None, None, None, None), - sp_runtime::DispatchError::BadOrigin + DispatchError::BadOrigin ); // Fail if trying to call from non-admin assert_noop!( @@ -165,7 +166,7 @@ mod set_metadata { None, None ), - sp_runtime::DispatchError::BadOrigin + DispatchError::BadOrigin ); }); } @@ -254,7 +255,7 @@ mod add_member { assert_noop!( Communities::add_member(RuntimeOrigin::none(), COMMUNITY, COMMUNITY_MEMBER_1), - sp_runtime::DispatchError::BadOrigin + DispatchError::BadOrigin ); assert_noop!( @@ -263,7 +264,7 @@ mod add_member { COMMUNITY, COMMUNITY_MEMBER_1 ), - sp_runtime::DispatchError::BadOrigin + DispatchError::BadOrigin ); }); } @@ -276,7 +277,7 @@ mod add_member { assert_noop!( Communities::add_member(RuntimeOrigin::none(), COMMUNITY, COMMUNITY_MEMBER_1), - sp_runtime::DispatchError::BadOrigin + DispatchError::BadOrigin ); // Successfully adds a member @@ -350,12 +351,12 @@ mod remove_member { assert_noop!( Communities::remove_member(RuntimeOrigin::none(), COMMUNITY, COMMUNITY_MEMBER_1), - sp_runtime::DispatchError::BadOrigin + DispatchError::BadOrigin ); assert_noop!( Communities::remove_member(RuntimeOrigin::signed(COMMUNITY_MEMBER_1), COMMUNITY, COMMUNITY_MEMBER_2), - sp_runtime::DispatchError::BadOrigin + DispatchError::BadOrigin ); }); } @@ -426,3 +427,185 @@ mod remove_member { }); } } + +mod assets_handling { + use super::*; + use frame_support::traits::{ + fungible::{Inspect as FunInspect, Unbalanced}, + fungibles::{Create, Inspect, Mutate}, + tokens::{Fortitude::Polite, Preservation::Preserve}, + }; + use sp_runtime::TokenError; + + const ALICE: u64 = 40; + const BOB: u64 = 41; + const COMMUNITY_MEMBER_1: u64 = 43; + + const ASSET_A: u32 = 100; + + fn setup() { + super::setup(); + + // Let's activate the community + assert_ok!(Communities::do_force_complete_challenge(&COMMUNITY)); + let community_account_id = Communities::get_community_account_id(&COMMUNITY); + + // Let's mint some balance + assert_ok!(Balances::increase_balance( + &ALICE, + 1, + frame_support::traits::tokens::Precision::Exact + )); + + // Let's issue/mint some assets + let minimum_balance = 1; + + assert_ok!(>>::create( + ASSET_A, + community_account_id, + true, + minimum_balance + )); + + assert_ok!(>>::mint_into( + ASSET_A, + &ALICE, + minimum_balance + .checked_add(1) + .expect("This should not overflow as ED is way below U128::MAX; qed") + )); + assert_ok!(>>::mint_into( + ASSET_A, + &community_account_id, + minimum_balance + )); + + // Let's add COMMUNITY_MEMBER_1 to the community + assert_ok!(Communities::do_insert_member(&COMMUNITY, &COMMUNITY_MEMBER_1)); + } + + mod assets_transfer { + use super::*; + + #[test] + fn fails_if_bad_origin() { + new_test_ext().execute_with(|| { + setup(); + + // Fail if trying to call from unsigned origin + assert_noop!( + Communities::assets_transfer(RuntimeOrigin::none(), COMMUNITY, ASSET_A, BOB, 1), + DispatchError::BadOrigin + ); + + // Fail if trying to call from non-admin + assert_noop!( + Communities::assets_transfer(RuntimeOrigin::signed(COMMUNITY_MEMBER_1), COMMUNITY, ASSET_A, BOB, 1), + DispatchError::BadOrigin + ); + }); + } + + #[test] + fn fails_if_not_enough_balance() { + new_test_ext().execute_with(|| { + setup(); + + assert_noop!( + Communities::assets_transfer(RuntimeOrigin::signed(COMMUNITY_ADMIN), COMMUNITY, ASSET_A, BOB, 1), + TokenError::NotExpendable, + ); + }); + } + + #[test] + fn it_works() { + new_test_ext().execute_with(|| { + setup(); + let community_account_id = Communities::get_community_account_id(&COMMUNITY); + + assert_ok!(Assets::transfer( + RuntimeOrigin::signed(ALICE), + codec::Compact(ASSET_A), + community_account_id, + 1 + )); + + assert_ok!(Communities::assets_transfer( + RuntimeOrigin::signed(COMMUNITY_ADMIN), + COMMUNITY, + ASSET_A, + BOB, + 1 + )); + + assert_eq!(Assets::reducible_balance(ASSET_A, &ALICE, Preserve, Polite), 0); + assert_eq!( + Assets::reducible_balance(ASSET_A, &community_account_id, Preserve, Polite), + 0 + ); + assert_eq!(Assets::reducible_balance(ASSET_A, &BOB, Preserve, Polite), 0); + }); + } + } + + mod balances_transfer { + use super::*; + + #[test] + fn fails_if_bad_origin() { + new_test_ext().execute_with(|| { + setup(); + + // Fail if trying to call from unsigned origin + assert_noop!( + Communities::balance_transfer(RuntimeOrigin::none(), COMMUNITY, BOB, 1), + DispatchError::BadOrigin + ); + + // Fail if trying to call from non-admin + assert_noop!( + Communities::balance_transfer(RuntimeOrigin::signed(COMMUNITY_MEMBER_1), COMMUNITY, BOB, 1), + DispatchError::BadOrigin + ); + }); + } + + #[test] + fn fails_if_not_enough_balance() { + new_test_ext().execute_with(|| { + setup(); + + assert_noop!( + Communities::balance_transfer(RuntimeOrigin::signed(COMMUNITY_ADMIN), COMMUNITY, BOB, 1), + TokenError::Frozen, + ); + }); + } + + #[test] + fn it_works() { + new_test_ext().execute_with(|| { + setup(); + let community_account_id = Communities::get_community_account_id(&COMMUNITY); + + assert_ok!(Balances::transfer( + RuntimeOrigin::signed(ALICE), + community_account_id, + 1 + )); + + assert_ok!(Communities::balance_transfer( + RuntimeOrigin::signed(COMMUNITY_ADMIN), + COMMUNITY, + BOB, + 1 + )); + + assert_eq!(Balances::reducible_balance(&ALICE, Preserve, Polite), 0); + assert_eq!(Balances::reducible_balance(&community_account_id, Preserve, Polite), 0); + assert_eq!(Balances::reducible_balance(&BOB, Preserve, Polite), 0); + }); + } + } +} diff --git a/pallets/communities/src/types.rs b/pallets/communities/src/types.rs index 85ab06e2..4c3613d2 100644 --- a/pallets/communities/src/types.rs +++ b/pallets/communities/src/types.rs @@ -1,6 +1,6 @@ use codec::MaxEncodedLen; use frame_support::pallet_prelude::{Decode, Encode}; -use frame_support::traits::fungibles::Inspect; +use frame_support::traits::{fungible::Inspect, fungibles::Inspect as InspectFuns}; use frame_support::{sp_runtime::BoundedVec, traits::ConstU32}; use scale_info::{prelude::vec::Vec, TypeInfo}; use sp_runtime::traits::StaticLookup; @@ -8,11 +8,13 @@ use sp_runtime::traits::StaticLookup; use crate::Config; use frame_system::Config as SystemConfig; +pub type AssetIdOf = <::Assets as InspectFuns>>::AssetId; +pub type BalanceOf = <::Assets as InspectFuns>>::Balance; +pub type NativeBalanceOf = <::Balances as Inspect>>::Balance; pub type AccountIdOf = ::AccountId; pub type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; pub type CommunityIdOf = ::CommunityId; pub type MembershipPassportOf = ::MembershipPassport; -pub type AssetIdOf = <::Assets as Inspect>>::AssetId; pub type MemberListOf = Vec>; pub type Cell = u32; diff --git a/pallets/communities/src/weights.rs b/pallets/communities/src/weights.rs index 0a1d2cca..814881ab 100644 --- a/pallets/communities/src/weights.rs +++ b/pallets/communities/src/weights.rs @@ -38,6 +38,8 @@ pub trait WeightInfo { fn set_metadata() -> Weight; fn add_member() -> Weight; fn remove_member() -> Weight; + fn assets_transfer() -> Weight; + fn balance_transfer() -> Weight; } /// Weights for pallet_communities using the Substrate node and recommended hardware. @@ -86,6 +88,28 @@ impl WeightInfo for SubstrateWeight { Weight::from_parts(9_000_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + + /// Storage: Communities Something (r:0 w:1) + /// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + fn assets_transfer() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 8_000_000 picoseconds. + Weight::from_parts(9_000_000, 0) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + + /// Storage: Communities Something (r:0 w:1) + /// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + fn balance_transfer() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 8_000_000 picoseconds. + Weight::from_parts(9_000_000, 0) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } } // For backwards compatibility and tests @@ -133,4 +157,26 @@ impl WeightInfo for () { Weight::from_parts(9_000_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + + /// Storage: Communities Something (r:0 w:1) + /// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + fn assets_transfer() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 8_000_000 picoseconds. + Weight::from_parts(9_000_000, 0) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + + /// Storage: Communities Something (r:0 w:1) + /// Proof: Communities Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + fn balance_transfer() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 8_000_000 picoseconds. + Weight::from_parts(9_000_000, 0) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } }