diff --git a/Cargo.lock b/Cargo.lock index 0649571452..18559e03f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3129,6 +3129,7 @@ dependencies = [ "orml-xcm-support", "orml-xtokens", "pallet-anchors", + "pallet-anchors-v2", "pallet-aura", "pallet-authorship", "pallet-balances", @@ -7382,6 +7383,22 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2)", ] +[[package]] +name = "pallet-anchors-v2" +version = "1.0.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2)", +] + [[package]] name = "pallet-asset-conversion" version = "10.0.0" diff --git a/Cargo.toml b/Cargo.toml index 72ca487ae2..abc49e02e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "libs/types", "libs/utils", "pallets/anchors", + "pallets/anchors-v2", "pallets/bridge", "pallets/block-rewards", "pallets/collator-allowlist", @@ -219,6 +220,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-s axelar-gateway-precompile = { path = "pallets/liquidity-pools-gateway/axelar-gateway-precompile", default-features = false } liquidity-pools-gateway-routers = { path = "pallets/liquidity-pools-gateway/routers", default-features = false } pallet-anchors = { path = "pallets/anchors", default-features = false } +pallet-anchors-v2 = { path = "pallets/anchors-v2", default-features = false } pallet-block-rewards = { path = "pallets/block-rewards", default-features = false } pallet-bridge = { path = "pallets/bridge", default-features = false } pallet-collator-allowlist = { path = "pallets/collator-allowlist", default-features = false } diff --git a/README.md b/README.md index 66258e0772..93e4959484 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Centrifuge is the infrastructure that facilitates the decentralized financing of On top of the [Substrate FRAME](https://docs.substrate.io/reference/frame-pallets/) framework, Centrifuge Chain is composed of custom pallets which can be found inside the `pallets` folder. The following list gives a brief overview, and links to the corresponding documentation: - [**anchors**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/anchors) ([docs](https://reference.centrifuge.io/pallet_anchors/index.html)): Storing hashes of documents on-chain. The documents are stored in the Private Off-chain Data (POD) node network. +- +- [**anchors-v2**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/anchors-v2) ([docs](https://reference.centrifuge.io/pallet_anchors_v2/index.html)): Second version of the pallet used to store document hashes on-chain. - [**block-rewards**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/block-rewards) ([docs](https://reference.centrifuge.io/pallet_block_rewards/index.html)): Provides means of configuring and distributing block rewards to collators as well as the annual treasury inflation. diff --git a/pallets/anchors-v2/Cargo.toml b/pallets/anchors-v2/Cargo.toml new file mode 100644 index 0000000000..c259105cb3 --- /dev/null +++ b/pallets/anchors-v2/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "pallet-anchors-v2" +description = "Anchors V2 pallet for runtime" +version = "1.0.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true +documentation.workspace = true + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +parity-scale-codec = { workspace = true } +scale-info = { workspace = true } + +frame-benchmarking = { workspace = true, optional = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } + +[dev-dependencies] +pallet-balances = { workspace = true, default-features = true } +sp-core = { workspace = true, default-features = true } +sp-io = { workspace = true, default-features = true } + +[features] +default = ["std"] +std = [ + "parity-scale-codec/std", + "scale-info/std", + "frame-support/std", + "frame-system/std", + "sp-runtime/std", + "sp-std/std", + "frame-benchmarking/std", +] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "sp-runtime/try-runtime", +] diff --git a/pallets/anchors-v2/src/benchmarking.rs b/pallets/anchors-v2/src/benchmarking.rs new file mode 100644 index 0000000000..af9eea12ff --- /dev/null +++ b/pallets/anchors-v2/src/benchmarking.rs @@ -0,0 +1,91 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version (see http://www.gnu.org/licenses). + +// Centrifuge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +use frame_benchmarking::{account, impl_benchmark_test_suite, v2::*}; +use frame_support::traits::Currency; +use frame_system::RawOrigin; +use parity_scale_codec::EncodeLike; +use sp_core::H256; + +use super::*; + +#[benchmarks( + where + T: Config, + T::AccountId: EncodeLike<::AccountId>, +)] +mod benchmarks { + use super::*; + + #[benchmark] + fn set_anchor() -> Result<(), BenchmarkError> { + let caller: T::AccountId = account("acc_0", 0, 0); + + let document_id = 123; + let document_version = 456; + let hash = H256::from_low_u64_be(1); + + let _ = T::Currency::deposit_creating( + &caller.clone().into(), + T::Currency::minimum_balance() + T::DefaultAnchorDeposit::get(), + ); + + #[extrinsic_call] + set_anchor( + RawOrigin::Signed(caller), + document_id, + document_version, + hash, + ); + + Ok(()) + } + + #[benchmark] + fn remove_anchor() -> Result<(), BenchmarkError> { + let caller: T::AccountId = account("acc_0", 0, 0); + + let document_id = 123; + let document_version = 456; + let hash = H256::from_low_u64_be(1); + let deposit = AnchorDeposit::::get(); + + let anchor = Anchor:: { + account_id: caller.clone(), + document_id, + document_version, + hash, + deposit, + }; + + Anchors::::insert((document_id, document_version), anchor); + PersonalAnchors::::insert(caller.clone(), (document_id, document_version), ()); + + #[extrinsic_call] + remove_anchor(RawOrigin::Signed(caller), document_id, document_version); + + Ok(()) + } + + #[benchmark] + fn set_deposit_value() -> Result<(), BenchmarkError> { + let deposit = 2 * T::DefaultAnchorDeposit::get(); + + #[extrinsic_call] + set_deposit_value(RawOrigin::Root, deposit); + + Ok(()) + } + + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime); +} diff --git a/pallets/anchors-v2/src/lib.rs b/pallets/anchors-v2/src/lib.rs new file mode 100644 index 0000000000..d1fe005044 --- /dev/null +++ b/pallets/anchors-v2/src/lib.rs @@ -0,0 +1,232 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version (see http://www.gnu.org/licenses). + +// Centrifuge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +#![cfg_attr(not(feature = "std"), no_std)] + +use frame_support::{pallet_prelude::*, traits::ReservableCurrency}; +use frame_system::pallet_prelude::*; +pub use pallet::*; +use scale_info::TypeInfo; +pub use weights::*; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; +#[cfg(test)] +mod mock; +#[cfg(test)] +mod tests; + +pub mod weights; + +/// Document ID type. +pub type DocumentId = u128; + +/// Document version type. +pub type DocumentVersion = u64; + +#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] +#[scale_info(skip_type_params(T))] +pub struct Anchor { + account_id: T::AccountId, + document_id: DocumentId, + document_version: DocumentVersion, + hash: T::Hash, + deposit: T::Balance, +} + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + type Balance: frame_support::traits::tokens::Balance; + + type Currency: ReservableCurrency; + + /// Default deposit that will be taken when adding an anchor. + type DefaultAnchorDeposit: Get; + + /// Origin used when setting a deposit. + type AdminOrigin: EnsureOrigin; + + /// Weight information. + type WeightInfo: WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(_); + + /// Storage for document anchors. + #[pallet::storage] + #[pallet::getter(fn get_anchor)] + pub type Anchors = + StorageMap<_, Blake2_256, (DocumentId, DocumentVersion), Anchor>; + + /// Storage for document anchors specific to an account. + #[pallet::storage] + #[pallet::getter(fn get_personal_anchor)] + pub type PersonalAnchors = StorageDoubleMap< + _, + Blake2_256, + T::AccountId, + Blake2_256, + (DocumentId, DocumentVersion), + (), + >; + + /// Stores the current deposit that will be taken when storing an anchor. + #[pallet::storage] + #[pallet::getter(fn get_anchor_deposit)] + pub type AnchorDeposit = + StorageValue<_, T::Balance, ValueQuery, T::DefaultAnchorDeposit>; + + #[pallet::event] + #[pallet::generate_deposit(pub (super) fn deposit_event)] + pub enum Event { + /// An anchor was added. + AnchorAdded { + account_id: T::AccountId, + document_id: u128, + document_version: u64, + hash: T::Hash, + deposit: T::Balance, + }, + /// An anchor was removed. + AnchorRemoved { + account_id: T::AccountId, + document_id: u128, + document_version: u64, + hash: T::Hash, + deposit: T::Balance, + }, + /// A deposit was set. + DepositSet { new_deposit: T::Balance }, + } + + #[pallet::error] + pub enum Error { + /// The anchor already exists. + AnchorAlreadyExists, + + /// The personal anchor already exists. + PersonalAnchorAlreadyExists, + + /// The anchor was not found in storage. + AnchorNotFound, + + /// The personal anchor was not found in storage. + PersonalAnchorNotFound, + } + + #[pallet::call] + impl Pallet { + /// Sets an anchor for a document ID and version. + #[pallet::weight(T::WeightInfo::set_anchor())] + #[pallet::call_index(0)] + pub fn set_anchor( + origin: OriginFor, + document_id: u128, + document_version: u64, + hash: T::Hash, + ) -> DispatchResult { + let account_id = ensure_signed(origin)?; + + // Only one anchor should be stored for a particular document ID and version. + ensure!( + Anchors::::get((document_id, document_version)).is_none(), + Error::::AnchorAlreadyExists + ); + ensure!( + PersonalAnchors::::get(account_id.clone(), (document_id, document_version)) + .is_none(), + Error::::PersonalAnchorAlreadyExists + ); + + let deposit = AnchorDeposit::::get(); + + T::Currency::reserve(&account_id, deposit)?; + + let anchor = Anchor:: { + account_id: account_id.clone(), + document_id, + document_version, + hash, + deposit, + }; + + Anchors::::insert((document_id, document_version), anchor); + + PersonalAnchors::::insert(account_id.clone(), (document_id, document_version), ()); + + Self::deposit_event(Event::AnchorAdded { + account_id, + document_id, + document_version, + hash, + deposit, + }); + + Ok(()) + } + + /// Removes an anchor for a document ID and version. + #[pallet::weight(T::WeightInfo::remove_anchor())] + #[pallet::call_index(1)] + pub fn remove_anchor( + origin: OriginFor, + document_id: u128, + document_version: u64, + ) -> DispatchResult { + let account_id = ensure_signed(origin)?; + + ensure!( + PersonalAnchors::::get(account_id.clone(), (document_id, document_version)) + .is_some(), + Error::::PersonalAnchorNotFound + ); + + let anchor = Anchors::::get((document_id, document_version)) + .ok_or(Error::::AnchorNotFound)?; + + T::Currency::unreserve(&account_id, anchor.deposit); + + Anchors::::remove((document_id, document_version)); + PersonalAnchors::::remove(account_id.clone(), (document_id, document_version)); + + Self::deposit_event(Event::AnchorRemoved { + account_id, + document_id, + document_version, + hash: anchor.hash, + deposit: anchor.deposit, + }); + + Ok(()) + } + + /// Set a new anchor deposit. + #[pallet::weight(T::WeightInfo::set_deposit_value())] + #[pallet::call_index(2)] + pub fn set_deposit_value(origin: OriginFor, new_deposit: T::Balance) -> DispatchResult { + T::AdminOrigin::ensure_origin(origin)?; + + >::set(new_deposit); + + Self::deposit_event(Event::DepositSet { new_deposit }); + + Ok(()) + } + } +} diff --git a/pallets/anchors-v2/src/mock.rs b/pallets/anchors-v2/src/mock.rs new file mode 100644 index 0000000000..c23fbc0428 --- /dev/null +++ b/pallets/anchors-v2/src/mock.rs @@ -0,0 +1,62 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version (see http://www.gnu.org/licenses). + +// Centrifuge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +use frame_support::{derive_impl, parameter_types}; +use frame_system::EnsureRoot; +use sp_runtime::traits::ConstU128; + +use crate::{self as pallet_anchors_v2, Config}; + +pub type Balance = u128; + +pub const CURRENCY: Balance = 1_000_000_000_000_000_000; + +frame_support::construct_runtime!( + pub enum Runtime { + System: frame_system, + AnchorsV2: pallet_anchors_v2, + Balances: pallet_balances, + } +); + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] +impl frame_system::Config for Runtime { + type AccountData = pallet_balances::AccountData; + type Block = frame_system::mocking::MockBlock; +} + +#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] +impl pallet_balances::Config for Runtime { + type AccountStore = System; + type Balance = Balance; + type DustRemoval = (); + type ExistentialDeposit = ConstU128<1>; + type RuntimeHoldReason = (); +} + +parameter_types! { + pub const DefaultAnchorDeposit: Balance = 100 * CURRENCY; +} + +impl Config for Runtime { + type AdminOrigin = EnsureRoot; + type Balance = Balance; + type Currency = Balances; + type DefaultAnchorDeposit = DefaultAnchorDeposit; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); +} + +pub fn new_test_ext() -> sp_io::TestExternalities { + System::externalities() +} diff --git a/pallets/anchors-v2/src/tests.rs b/pallets/anchors-v2/src/tests.rs new file mode 100644 index 0000000000..23c03c736a --- /dev/null +++ b/pallets/anchors-v2/src/tests.rs @@ -0,0 +1,312 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version (see http://www.gnu.org/licenses). + +// Centrifuge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +use frame_support::{assert_err, assert_ok, dispatch::RawOrigin}; +use pallet_balances::Error::InsufficientBalance; +use sp_runtime::{testing::H256, DispatchError::BadOrigin}; + +use super::*; +use crate::mock::{RuntimeEvent as MockEvent, *}; + +mod set_anchor { + use super::*; + + #[test] + fn success() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = Anchor:: { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }; + + Balances::force_set_balance(RuntimeOrigin::root(), origin, deposit * 2).unwrap(); + + assert_ok!(AnchorsV2::set_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + hash, + )); + + assert_eq!( + Anchors::::get((document_id, document_version)), + Some(anchor.clone()), + "anchor should be in storage" + ); + assert_eq!( + PersonalAnchors::::get(origin, (document_id, document_version)), + Some(()), + "personal anchor should be in storage" + ); + + event_exists(Event::::AnchorAdded { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }); + + assert_eq!( + Balances::reserved_balance(&origin), + deposit, + "correct amount should be reserved" + ); + }); + } + + #[test] + fn unsigned_origin() { + new_test_ext().execute_with(|| { + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + + assert_err!( + AnchorsV2::set_anchor(RawOrigin::None.into(), document_id, document_version, hash,), + BadOrigin + ); + }); + } + + #[test] + fn anchor_present() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = Anchor:: { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }; + + Anchors::::insert((document_id, document_version), anchor); + + assert_err!( + AnchorsV2::set_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + hash, + ), + Error::::AnchorAlreadyExists + ); + }); + } + + #[test] + fn personal_anchor_present() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + + PersonalAnchors::::insert(origin, (document_id, document_version), ()); + + assert_err!( + AnchorsV2::set_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + hash, + ), + Error::::PersonalAnchorAlreadyExists + ); + }); + } + + #[test] + fn insufficient_balance() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + + assert_err!( + AnchorsV2::set_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + hash, + ), + InsufficientBalance:: + ); + }); + } +} + +mod remove_anchor { + use super::*; + + #[test] + fn success() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + let hash = H256::random(); + let deposit = AnchorDeposit::::get(); + + let anchor = Anchor:: { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }; + + Anchors::::insert((document_id, document_version), anchor); + PersonalAnchors::::insert(origin, (document_id, document_version), ()); + + Balances::force_set_balance(RuntimeOrigin::root(), origin, deposit * 2).unwrap(); + assert_ok!(Balances::reserve(&origin, deposit)); + + assert_ok!(AnchorsV2::remove_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + )); + + assert!(Anchors::::get((document_id, document_version)).is_none()); + assert!( + PersonalAnchors::::get(origin, (document_id, document_version)).is_none() + ); + + event_exists(Event::::AnchorRemoved { + account_id: origin, + document_id, + document_version, + hash, + deposit, + }); + + assert_eq!(Balances::reserved_balance(&origin), 0); + }); + } + + #[test] + fn unsigned_origin() { + new_test_ext().execute_with(|| { + let document_id = 123; + let document_version = 456; + + assert_err!( + AnchorsV2::remove_anchor(RawOrigin::None.into(), document_id, document_version), + BadOrigin + ); + }); + } + + #[test] + fn personal_anchor_not_found() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + + assert_err!( + AnchorsV2::remove_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + ), + Error::::PersonalAnchorNotFound + ); + }); + } + + #[test] + fn anchor_not_found() { + new_test_ext().execute_with(|| { + let origin: u64 = 1; + let document_id = 123; + let document_version = 456; + + PersonalAnchors::::insert(origin, (document_id, document_version), ()); + + assert_err!( + AnchorsV2::remove_anchor( + RuntimeOrigin::signed(origin), + document_id, + document_version, + ), + Error::::AnchorNotFound + ); + }); + } +} + +mod set_deposit { + use super::*; + + #[test] + fn success() { + new_test_ext().execute_with(|| { + let deposit = AnchorDeposit::::get(); + let new_deposit = deposit * 2; + + assert_ok!(AnchorsV2::set_deposit_value( + RuntimeOrigin::root(), + new_deposit + )); + assert_eq!(AnchorDeposit::::get(), new_deposit); + + event_exists(Event::::DepositSet { new_deposit }); + }) + } + + #[test] + fn bad_origin() { + new_test_ext().execute_with(|| { + let new_deposit = 123; + assert_err!( + AnchorsV2::set_deposit_value(RuntimeOrigin::signed(1), new_deposit), + BadOrigin + ); + }) + } +} + +fn event_exists>(e: E) { + let actual: Vec = frame_system::Pallet::::events() + .iter() + .map(|e| e.event.clone()) + .collect(); + + let e: MockEvent = e.into(); + let mut exists = false; + for evt in actual { + if evt == e { + exists = true; + break; + } + } + assert!(exists); +} diff --git a/pallets/anchors-v2/src/weights.rs b/pallets/anchors-v2/src/weights.rs new file mode 100644 index 0000000000..796a57e9fb --- /dev/null +++ b/pallets/anchors-v2/src/weights.rs @@ -0,0 +1,34 @@ +// Copyright 2021 Centrifuge Foundation (centrifuge.io). +// This file is part of Centrifuge chain project. + +// Centrifuge is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version (see http://www.gnu.org/licenses). + +// Centrifuge is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +use frame_support::weights::Weight; + +pub trait WeightInfo { + fn set_anchor() -> Weight; + fn remove_anchor() -> Weight; + fn set_deposit_value() -> Weight; +} + +impl WeightInfo for () { + fn set_anchor() -> Weight { + Weight::zero() + } + + fn remove_anchor() -> Weight { + Weight::zero() + } + + fn set_deposit_value() -> Weight { + Weight::zero() + } +} diff --git a/pallets/pool-system/src/mock.rs b/pallets/pool-system/src/mock.rs index da4ec270df..a385b59856 100644 --- a/pallets/pool-system/src/mock.rs +++ b/pallets/pool-system/src/mock.rs @@ -393,7 +393,6 @@ impl EnsureOriginWithArg for All { #[cfg(feature = "runtime-benchmarks")] fn try_successful_origin(_: &PoolId) -> Result { - use frame_support::dispatch::RawOrigin; Ok(RawOrigin::Root.into()) } } diff --git a/pallets/pool-system/src/pool_types.rs b/pallets/pool-system/src/pool_types.rs index d2a5a4551c..0594d15ab2 100644 --- a/pallets/pool-system/src/pool_types.rs +++ b/pallets/pool-system/src/pool_types.rs @@ -12,6 +12,7 @@ use cfg_traits::Seconds; use cfg_types::{epoch::EpochState, pools::TrancheMetadata}; +pub use changes::PoolChangeProposal; use frame_support::{ dispatch::DispatchResult, pallet_prelude::{DispatchError, RuntimeDebug}, @@ -419,5 +420,3 @@ pub mod changes { pub change: ChangeProposal, } } - -pub use changes::PoolChangeProposal; diff --git a/pallets/pool-system/src/tranches.rs b/pallets/pool-system/src/tranches.rs index afa0a5ebbf..9b7011ca13 100644 --- a/pallets/pool-system/src/tranches.rs +++ b/pallets/pool-system/src/tranches.rs @@ -1724,7 +1724,6 @@ pub mod test { } mod tranche { - use super::*; #[test] diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 56aae05d43..29dd4bd01c 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -15,19 +15,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub mod account_conversion; -pub mod apis; -pub mod changes; -pub mod evm; -pub mod fees; -pub mod gateway; -pub mod migrations; -pub mod oracle; -pub mod pool; -pub mod remarks; -pub mod transfer_filter; -pub mod xcm; - use cfg_primitives::Balance; use cfg_types::{ fee_keys::FeeKey, @@ -44,6 +31,19 @@ use sp_runtime::{ }; use sp_std::marker::PhantomData; +pub mod account_conversion; +pub mod apis; +pub mod changes; +pub mod evm; +pub mod fees; +pub mod gateway; +pub mod migrations; +pub mod oracle; +pub mod pool; +pub mod remarks; +pub mod transfer_filter; +pub mod xcm; + pub mod instances { /// The rewards associated to block rewards pub type BlockRewards = pallet_rewards::Instance1; diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 440ee5309c..e5c4c4989e 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -81,6 +81,7 @@ orml-tokens = { workspace = true } orml-xcm = { workspace = true } orml-xtokens = { workspace = true } pallet-anchors = { workspace = true } +pallet-anchors-v2 = { workspace = true } pallet-aura = { workspace = true } pallet-authorship = { workspace = true } pallet-balances = { workspace = true } @@ -206,6 +207,7 @@ std = [ "orml-xcm/std", "orml-xtokens/std", "pallet-anchors/std", + "pallet-anchors-v2/std", "pallet-aura/std", "pallet-authorship/std", "pallet-balances/std", @@ -294,6 +296,7 @@ runtime-benchmarks = [ "orml-tokens/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", "pallet-anchors/runtime-benchmarks", + "pallet-anchors-v2/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-block-rewards/runtime-benchmarks", "pallet-bridge/runtime-benchmarks", @@ -374,6 +377,7 @@ try-runtime = [ "orml-xcm/try-runtime", "orml-xtokens/try-runtime", "pallet-anchors/try-runtime", + "pallet-anchors-v2/try-runtime", "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index cc8d52cc88..00bddcbde6 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -1643,6 +1643,19 @@ impl pallet_keystore::pallet::Config for Runtime { type WeightInfo = weights::pallet_keystore::WeightInfo; } +parameter_types! { + pub const DefaultAnchorDeposit: Balance = 100 * CFG; +} + +impl pallet_anchors_v2::pallet::Config for Runtime { + type AdminOrigin = EnsureRootOr; + type Balance = Balance; + type Currency = Balances; + type DefaultAnchorDeposit = DefaultAnchorDeposit; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_anchors_v2::WeightInfo; +} + parameter_types! { pub const MaxOutstandingCollects: u32 = 10; } @@ -2128,6 +2141,9 @@ construct_runtime!( OraclePriceFeed: pallet_oracle_feed::{Pallet, Call, Storage, Event} = 118, OraclePriceCollection: pallet_oracle_collection::{Pallet, Call, Storage, Event} = 119, + // our pallets part 2 + AnchorsV2: pallet_anchors_v2::{Pallet, Call, Storage, Event} = 130, + // XCM XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 120, PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Config, Event, Origin} = 121, @@ -2831,6 +2847,7 @@ mod benches { [pallet_preimage, Preimage] [pallet_fees, Fees] [pallet_anchors, Anchor] + [pallet_anchors_v2, AnchorsV2] [pallet_block_rewards, BlockRewards] [pallet_collator_allowlist, CollatorAllowlist] [pallet_collator_selection, CollatorSelection] diff --git a/runtime/development/src/weights/mod.rs b/runtime/development/src/weights/mod.rs index 659c89486d..857944649e 100644 --- a/runtime/development/src/weights/mod.rs +++ b/runtime/development/src/weights/mod.rs @@ -12,6 +12,7 @@ pub mod cumulus_pallet_xcmp_queue; pub mod frame_system; pub mod pallet_anchors; +pub mod pallet_anchors_v2; pub mod pallet_balances; pub mod pallet_block_rewards; pub mod pallet_collator_allowlist; diff --git a/runtime/development/src/weights/pallet_anchors_v2.rs b/runtime/development/src/weights/pallet_anchors_v2.rs new file mode 100644 index 0000000000..78afe2dd5e --- /dev/null +++ b/runtime/development/src/weights/pallet_anchors_v2.rs @@ -0,0 +1,51 @@ + +//! Autogenerated weights for `pallet_anchors_v2` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-06-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("centrifuge-local")`, DB CACHE: 1024 + +// Executed Command: +// target/release/centrifuge-chain +// benchmark +// pallet +// --chain=centrifuge-local +// --steps=50 +// --repeat=20 +// --pallet=pallet_anchors_v2 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=/tmp/runtime/centrifuge/src/weights/pallet_keystore.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_anchors_v2`. +pub struct WeightInfo(PhantomData); +impl pallet_anchors_v2::WeightInfo for WeightInfo { + fn set_anchor() -> Weight { + Weight::from_parts(7_645_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + + fn remove_anchor() -> Weight { + Weight::from_parts(7_645_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + + fn set_deposit_value() -> Weight { + Weight::from_parts(7_645_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } +}