From 936f56e2c5a09dfcf4d9dc1577c07b966dbc17ff Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Fri, 24 Mar 2023 16:03:07 +1300 Subject: [PATCH 01/20] liquid-crowdloan --- Cargo.lock | 15 +++++ modules/liquid-crowdloan/Cargo.toml | 36 ++++++++++++ modules/liquid-crowdloan/src/lib.rs | 85 +++++++++++++++++++++++++++ modules/liquid-crowdloan/src/mock.rs | 85 +++++++++++++++++++++++++++ modules/liquid-crowdloan/src/tests.rs | 31 ++++++++++ 5 files changed, 252 insertions(+) create mode 100644 modules/liquid-crowdloan/Cargo.toml create mode 100644 modules/liquid-crowdloan/src/lib.rs create mode 100644 modules/liquid-crowdloan/src/mock.rs create mode 100644 modules/liquid-crowdloan/src/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 40f032f341..239d61bb1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6405,6 +6405,21 @@ dependencies = [ "sp-std", ] +[[package]] +name = "module-liquid-crowdloan" +version = "2.16.0" +dependencies = [ + "acala-primitives", + "frame-support", + "frame-system", + "orml-traits", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", +] + [[package]] name = "module-loans" version = "2.16.0" diff --git a/modules/liquid-crowdloan/Cargo.toml b/modules/liquid-crowdloan/Cargo.toml new file mode 100644 index 0000000000..f48d566871 --- /dev/null +++ b/modules/liquid-crowdloan/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "module-liquid-crowdloan" +version = "2.16.0" +authors = ["Acala Developers"] +edition = "2021" + +[dependencies] +scale-info = { version = "2.2.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } + +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } + +orml-traits = { path = "../../orml/traits", default-features = false } +primitives = { package = "acala-primitives", path = "../../primitives", default-features = false } + +[dev-dependencies] +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } + +[features] +default = ["std"] +std = [ + "codec/std", + "scale-info/std", + "sp-runtime/std", + "frame-support/std", + "frame-system/std", + "orml-traits/std", + "primitives/std", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] diff --git a/modules/liquid-crowdloan/src/lib.rs b/modules/liquid-crowdloan/src/lib.rs new file mode 100644 index 0000000000..3073a18091 --- /dev/null +++ b/modules/liquid-crowdloan/src/lib.rs @@ -0,0 +1,85 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2023 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! # Liquid Crowdloan Module +//! +//! Allow people to redeem lcDOT for DOT. + +#![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::unused_unit)] + +use frame_support::{pallet_prelude::*, PalletId}; +use frame_system::pallet_prelude::*; +use orml_traits::MultiCurrency; +use primitives::{Balance, CurrencyId}; +use sp_runtime::traits::AccountIdConversion; + +mod mock; +mod tests; + +pub use module::*; + +#[frame_support::pallet] +pub mod module { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + type Currency: MultiCurrency; + + #[pallet::constant] + type LiquidCrowdloanCurrencyId: Get; + + #[pallet::constant] + type PalletId: Get; + } + + #[pallet::event] + #[pallet::generate_deposit(fn deposit_event)] + pub enum Event { + /// Liquid Crowdloan asset was redeemed. + Redeemed { amount: Balance }, + } + + #[pallet::pallet] + pub struct Pallet(_); + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(0)] + pub fn redeem(origin: OriginFor, #[pallet::compact] amount: Balance) -> DispatchResult { + let who = ensure_signed(origin)?; + + T::Currency::withdraw(T::LiquidCrowdloanCurrencyId::get(), &who, amount)?; + + T::Currency::transfer(T::LiquidCrowdloanCurrencyId::get(), &Self::account_id(), &who, amount)?; + + Self::deposit_event(Event::Redeemed { amount }); + + Ok(()) + } + } +} + +impl Pallet { + pub fn account_id() -> T::AccountId { + T::PalletId::get().into_account_truncating() + } +} diff --git a/modules/liquid-crowdloan/src/mock.rs b/modules/liquid-crowdloan/src/mock.rs new file mode 100644 index 0000000000..339913b587 --- /dev/null +++ b/modules/liquid-crowdloan/src/mock.rs @@ -0,0 +1,85 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2023 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Mocks for example module. + +#![cfg(test)] + +use crate as liquid_crowdloan; +use frame_support::{ + construct_runtime, + pallet_prelude::GenesisBuild, + traits::{ConstU32, ConstU64, Everything}, +}; + +impl frame_system::Config for Runtime { + type BaseCallFilter = Everything; + type RuntimeOrigin = RuntimeOrigin; + type Index = u64; + type BlockNumber = u64; + type RuntimeCall = RuntimeCall; + type Hash = sp_runtime::testing::H256; + type Hashing = sp_runtime::traits::BlakeTwo256; + type AccountId = u64; + type Lookup = sp_runtime::traits::IdentityLookup; + type Header = sp_runtime::testing::Header; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = ConstU64<250>; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = (); + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +impl liquid_crowdloan::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SomeConst = ConstU64<10>; + type Balance = u64; +} + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + System: frame_system::{Pallet, Call, Event}, + LiquidCrowdloan: liquid_crowdloan::{Pallet, Call, Event, Config, Storage}, + } +); + +pub fn new_test_ext() -> sp_io::TestExternalities { + let t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext +} diff --git a/modules/liquid-crowdloan/src/tests.rs b/modules/liquid-crowdloan/src/tests.rs new file mode 100644 index 0000000000..cb724f4528 --- /dev/null +++ b/modules/liquid-crowdloan/src/tests.rs @@ -0,0 +1,31 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2023 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Unit tests for example module. + +#![cfg(test)] + +use crate::mock::*; +use frame_support::assert_ok; + +#[test] +fn set_dummy_work() { + new_test_ext().execute_with(|| { + assert_ok!(Ok(())); + }); +} From 87a2913a457fee771702eec130056440728b152f Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Thu, 6 Apr 2023 14:39:10 +1200 Subject: [PATCH 02/20] impl liquid crowdloan transfer --- Cargo.lock | 1 + modules/liquid-crowdloan/Cargo.toml | 2 + modules/liquid-crowdloan/src/lib.rs | 45 ++++++++++++++++++++- modules/relaychain/src/lib.rs | 51 +++++++++++++++++++++++- modules/support/src/lib.rs | 21 ++++++++++ modules/support/src/liquid_crowdloan.rs | 29 ++++++++++++++ modules/xcm-interface/src/lib.rs | 52 ++++++++++++++++++++++++- runtime/acala/src/lib.rs | 5 +++ runtime/karura/src/lib.rs | 2 + runtime/mandala/src/lib.rs | 2 + 10 files changed, 204 insertions(+), 6 deletions(-) create mode 100644 modules/support/src/liquid_crowdloan.rs diff --git a/Cargo.lock b/Cargo.lock index 239d61bb1c..961515dc4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6412,6 +6412,7 @@ dependencies = [ "acala-primitives", "frame-support", "frame-system", + "module-support", "orml-traits", "parity-scale-codec", "scale-info", diff --git a/modules/liquid-crowdloan/Cargo.toml b/modules/liquid-crowdloan/Cargo.toml index f48d566871..09ce39dff7 100644 --- a/modules/liquid-crowdloan/Cargo.toml +++ b/modules/liquid-crowdloan/Cargo.toml @@ -14,6 +14,7 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk orml-traits = { path = "../../orml/traits", default-features = false } primitives = { package = "acala-primitives", path = "../../primitives", default-features = false } +support = { package = "module-support", path = "../support", default-features = false } [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } @@ -29,6 +30,7 @@ std = [ "frame-system/std", "orml-traits/std", "primitives/std", + "support/std", ] try-runtime = [ "frame-support/try-runtime", diff --git a/modules/liquid-crowdloan/src/lib.rs b/modules/liquid-crowdloan/src/lib.rs index 3073a18091..44e358c972 100644 --- a/modules/liquid-crowdloan/src/lib.rs +++ b/modules/liquid-crowdloan/src/lib.rs @@ -23,12 +23,14 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::unused_unit)] -use frame_support::{pallet_prelude::*, PalletId}; +use frame_support::{pallet_prelude::*, traits::EnsureOrigin, PalletId}; use frame_system::pallet_prelude::*; use orml_traits::MultiCurrency; use primitives::{Balance, CurrencyId}; use sp_runtime::traits::AccountIdConversion; +use support::CrowdloanVaultXcm; + mod mock; mod tests; @@ -49,13 +51,29 @@ pub mod module { #[pallet::constant] type PalletId: Get; + + /// The governance origin for liquid crowdloan module. For instance for DOT cross-chain + /// transfer DOT from relay chain crowdloan vault to liquid crowdloan module account. + type GovernanceOrigin: EnsureOrigin; + + /// The crowdloan vault account on relay chain. + #[pallet::constant] + type CrowdloanVault: Get; + + /// XCM transfer impl. + type XcmTransfer: CrowdloanVaultXcm; } #[pallet::event] #[pallet::generate_deposit(fn deposit_event)] pub enum Event { /// Liquid Crowdloan asset was redeemed. - Redeemed { amount: Balance }, + Redeemed { + amount: Balance, + }, + TransferFromCrowdloanVaultRequested { + amount: Balance, + }, } #[pallet::pallet] @@ -75,6 +93,29 @@ pub mod module { Ok(()) } + + /// Cross-chain transfer DOT from relay chain crowdloan vault to liquid crowdloan module + /// account. + /// + /// This call requires `GovernanceOrigin`. + #[pallet::call_index(1)] + #[pallet::weight(0)] + pub fn transfer_from_crowdloan_vault( + origin: OriginFor, + #[pallet::compact] amount: Balance, + ) -> DispatchResult { + T::GovernanceOrigin::ensure_origin(origin)?; + + T::XcmTransfer::transfer_to_liquid_crowdloan_module_account( + T::CrowdloanVault::get(), + Self::account_id(), + amount, + )?; + + Self::deposit_event(Event::TransferFromCrowdloanVaultRequested { amount }); + + Ok(()) + } } } diff --git a/modules/relaychain/src/lib.rs b/modules/relaychain/src/lib.rs index 40bbad7cce..c2e53e0bfb 100644 --- a/modules/relaychain/src/lib.rs +++ b/modules/relaychain/src/lib.rs @@ -66,6 +66,27 @@ pub enum StakingCall { WithdrawUnbonded(u32), } +/// `pallet-xcm` calls. +#[derive(Encode, Decode, RuntimeDebug)] +pub enum XcmCall { + /// `reserve_transfer_assets(dest, beneficiary, assets, fee_asset_item)` call. + #[codec(index = 2)] + ReserveTransferAssets( + VersionedMultiLocation, + VersionedMultiLocation, + VersionedMultiAssets, + u32, + ), +} + +/// `pallet-proxy` calls. +#[derive(Encode, Decode, RuntimeDebug)] +pub enum ProxyCall { + /// `proxy(real, force_proxy_type, call)` call. + #[codec(index = 0)] + Proxy(::Source, Option<()>, RelayChainCall), +} + #[cfg(feature = "kusama")] mod kusama { use crate::*; @@ -79,7 +100,11 @@ mod kusama { #[codec(index = 6)] Staking(StakingCall), #[codec(index = 24)] - Utility(Box>), + Utility(Box>>), + #[codec(index = 30)] + Proxy(Box>>), + #[codec(index = 99)] + XcmPallet(XcmCall), } } @@ -96,7 +121,11 @@ mod polkadot { #[codec(index = 7)] Staking(StakingCall), #[codec(index = 26)] - Utility(Box>), + Utility(Box>>), + #[codec(index = 29)] + Proxy(Box>>), + #[codec(index = 99)] + XcmPallet(XcmCall), } } @@ -208,4 +237,22 @@ where ] .concat()) } + + fn xcm_pallet_reserve_transfer_assets( + dest: MultiLocation, + beneficiary: MultiLocation, + assets: MultiAssets, + fee_assets_item: u32, + ) -> Self::RelayChainCall { + RelayChainCall::XcmPallet(XcmCall::ReserveTransferAssets( + VersionedMultiLocation::V3(dest), + VersionedMultiLocation::V3(beneficiary), + VersionedMultiAssets::V3(assets), + fee_assets_item, + )) + } + + fn proxy_call(real: Self::AccountId, call: Self::RelayChainCall) -> Self::RelayChainCall { + RelayChainCall::Proxy(Box::new(ProxyCall::Proxy(T::Lookup::unlookup(real), None, call))) + } } diff --git a/modules/support/src/lib.rs b/modules/support/src/lib.rs index fc393217b0..227e04e80d 100644 --- a/modules/support/src/lib.rs +++ b/modules/support/src/lib.rs @@ -36,6 +36,7 @@ pub mod evm; pub mod homa; pub mod honzon; pub mod incentives; +pub mod liquid_crowdloan; pub mod mocks; pub mod stable_asset; @@ -45,6 +46,7 @@ pub use crate::evm::*; pub use crate::homa::*; pub use crate::honzon::*; pub use crate::incentives::*; +pub use crate::liquid_crowdloan::*; pub use crate::stable_asset::*; pub type Price = FixedU128; @@ -152,6 +154,25 @@ pub trait CallBuilder { calls: Vec<(Self::RelayChainCall, XcmWeight)>, extra_fee: Self::Balance, ) -> Xcm<()>; + + /// Reserve transfer assets. + /// params: + /// - dest: The destination chain. + /// - beneficiary: The beneficiary. + /// - assets: The assets to be transferred. + /// - fee_assets_item: The index of assets for fees. + fn xcm_pallet_reserve_transfer_assets( + dest: MultiLocation, + beneficiary: MultiLocation, + assets: MultiAssets, + fee_assets_item: u32, + ) -> Self::RelayChainCall; + + /// Proxy a call with a `real` account without a forced proxy type. + /// params: + /// - real: The real account. + /// - call: The call to be executed. + fn proxy_call(real: Self::AccountId, call: Self::RelayChainCall) -> Self::RelayChainCall; } /// Dispatchable tasks diff --git a/modules/support/src/liquid_crowdloan.rs b/modules/support/src/liquid_crowdloan.rs new file mode 100644 index 0000000000..79d7b3df46 --- /dev/null +++ b/modules/support/src/liquid_crowdloan.rs @@ -0,0 +1,29 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2023 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use sp_runtime::DispatchResult; + +/// Crowdloan vault XCM operations. +pub trait CrowdloanVaultXcm { + /// Cross-chain transfer DOT from crowdloan vault to liquid crowdloan module account. + fn transfer_to_liquid_crowdloan_module_account( + vault: AccountId, + recipient: AccountId, + amount: Balance, + ) -> DispatchResult; +} diff --git a/modules/xcm-interface/src/lib.rs b/modules/xcm-interface/src/lib.rs index 1f8815fc6e..1d4776c4e8 100644 --- a/modules/xcm-interface/src/lib.rs +++ b/modules/xcm-interface/src/lib.rs @@ -27,9 +27,9 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::unused_unit)] -use frame_support::{log, pallet_prelude::*, transactional}; +use frame_support::{log, pallet_prelude::*, traits::Get, transactional}; use frame_system::pallet_prelude::*; -use module_support::{CallBuilder, HomaSubAccountXcm}; +use module_support::{CallBuilder, CrowdloanVaultXcm, HomaSubAccountXcm}; use orml_traits::XcmTransfer; use primitives::{Balance, CurrencyId, EraIndex}; use scale_info::TypeInfo; @@ -57,6 +57,8 @@ pub mod module { HomaUnbond, // Parachain fee with location info ParachainFee(Box), + // `XcmPallet::reserve_transfer_assets` call via proxy account + ProxyReserveTransferAssets, } #[pallet::config] @@ -87,6 +89,17 @@ pub mod module { /// The interface to Cross-chain transfer. type XcmTransfer: XcmTransfer; + + /// Self parachain location. + #[pallet::constant] + type SelfLocation: Get; + + /// Convert AccountId to MultiLocation to build XCM message. + type AccountIdToMultiLocation: Convert; + + /// Crowdloan vault account. + #[pallet::constant] + type CrowdloanVaultAccount: Get; } #[pallet::error] @@ -277,4 +290,39 @@ pub mod module { Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::ParachainFee(Box::new(location))).1 } } + + impl CrowdloanVaultXcm for Pallet { + fn transfer_to_liquid_crowdloan_module_account( + vault: T::AccountId, + recipient: T::AccountId, + amount: Balance, + ) -> DispatchResult { + let (xcm_dest_weight, xcm_fee) = + Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::ProxyReserveTransferAssets); + + let proxy_call = T::RelayChainCallBuilder::proxy_call( + vault.clone(), + T::RelayChainCallBuilder::xcm_pallet_reserve_transfer_assets( + T::SelfLocation::get(), + T::AccountIdToMultiLocation::convert(recipient.clone()), + // Note this message is executed in the relay chain context. + vec![(Concrete(Here.into()), amount).into()].into(), + 0, + ), + ); + let xcm_message = + T::RelayChainCallBuilder::finalize_call_into_xcm_message(proxy_call, xcm_fee, xcm_dest_weight); + + let result = pallet_xcm::Pallet::::send_xcm(Here, Parent, xcm_message); + log::debug!( + target: "xcm-interface", + "Send {:?} DOT from crowdloan vault {:?} to {:?}, result: {:?}", + amount, vault, recipient, result, + ); + + ensure!(result.is_ok(), Error::::XcmFailed); + + Ok(()) + } + } } diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index dced11c26f..28f9cf9b83 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1525,6 +1525,8 @@ impl Convert for SubAccountIndexMultiLocationConvertor { parameter_types! { pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); + //TODO: update with real crowdloan account + pub CrowdloanVaultAccount: AccountId = AccountId::from([0u8; 32]); } impl module_xcm_interface::Config for Runtime { @@ -1536,6 +1538,9 @@ impl module_xcm_interface::Config for Runtime { type SovereignSubAccountLocationConvert = SubAccountIndexMultiLocationConvertor; type RelayChainCallBuilder = RelayChainCallBuilder; type XcmTransfer = XTokens; + type SelfLocation = xcm_config::SelfLocation; + type AccountIdToMultiLocation = xcm_config::AccountIdToMultiLocation; + type CrowdloanVaultAccount = CrowdloanVaultAccount; } impl orml_unknown_tokens::Config for Runtime { diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 09c73a07a4..86777483ef 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1547,6 +1547,8 @@ impl module_xcm_interface::Config for Runtime { type SovereignSubAccountLocationConvert = SubAccountIndexMultiLocationConvertor; type RelayChainCallBuilder = RelayChainCallBuilder; type XcmTransfer = XTokens; + type SelfLocation = xcm_config::SelfLocation; + type AccountIdToMultiLocation = xcm_config::AccountIdToMultiLocation; } impl orml_unknown_tokens::Config for Runtime { diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 8ea8dd24ff..12c76cc45c 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1400,6 +1400,8 @@ impl module_xcm_interface::Config for Runtime { type SovereignSubAccountLocationConvert = SubAccountIndexMultiLocationConvertor; type RelayChainCallBuilder = RelayChainCallBuilder; type XcmTransfer = XTokens; + type SelfLocation = xcm_config::SelfLocation; + type AccountIdToMultiLocation = xcm_config::AccountIdToMultiLocation; } parameter_types! { From 6284e3879aea8fc10abc286fa363729e911ad004 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Wed, 12 Apr 2023 14:12:59 +1200 Subject: [PATCH 03/20] fix RelayChainCall encode/decode --- modules/relaychain/src/lib.rs | 60 +++++++++---------- modules/xcm-interface/src/mock.rs | 18 +++++- runtime/acala/src/lib.rs | 2 +- .../relaychain/kusama_cross_chain_transfer.rs | 20 +++---- .../src/relaychain/relay_chain.rs | 2 +- runtime/karura/src/lib.rs | 5 +- runtime/mandala/src/lib.rs | 5 +- 7 files changed, 65 insertions(+), 47 deletions(-) diff --git a/modules/relaychain/src/lib.rs b/modules/relaychain/src/lib.rs index c2e53e0bfb..03e6cf9725 100644 --- a/modules/relaychain/src/lib.rs +++ b/modules/relaychain/src/lib.rs @@ -23,29 +23,30 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::unused_unit)] -use codec::{Decode, Encode, FullCodec}; -use sp_runtime::traits::StaticLookup; +use codec::{Decode, Encode}; +use sp_runtime::traits::{AccountIdLookup, StaticLookup}; use frame_support::{traits::Get, RuntimeDebug}; use module_support::CallBuilder; -use primitives::Balance; +use primitives::{AccountId, Balance}; use sp_std::{boxed::Box, marker::PhantomData, prelude::*}; pub use cumulus_primitives_core::ParaId; use xcm::{prelude::*, v3::Weight as XcmWeight}; -use frame_system::Config; - // * Since XCM V3, relaychain configs 'SafeCallFilter' to filter the call in Transact: // * https://github.com/paritytech/polkadot/blob/master/runtime/polkadot/src/xcm_config.rs #[derive(Encode, Decode, RuntimeDebug)] -pub enum BalancesCall { +pub enum BalancesCall { #[codec(index = 3)] - TransferKeepAlive(::Source, #[codec(compact)] Balance), /* TODO: because param type - * in relaychain is u64, - * need to confirm - * Balance(u128) is working. */ + TransferKeepAlive(::Source, #[codec(compact)] Balance), /* TODO: because + * param type + * in relaychain is + * u64, + * need to confirm + * Balance(u128) is + * working. */ } #[derive(Encode, Decode, RuntimeDebug)] @@ -79,12 +80,15 @@ pub enum XcmCall { ), } +// Same to `Polkadot` and `Kusama` runtime `Lookup` config. +pub type RelayChainLookup = AccountIdLookup; + /// `pallet-proxy` calls. #[derive(Encode, Decode, RuntimeDebug)] -pub enum ProxyCall { +pub enum ProxyCall { /// `proxy(real, force_proxy_type, call)` call. #[codec(index = 0)] - Proxy(::Source, Option<()>, RelayChainCall), + Proxy(::Source, Option<()>, RelayChainCall), } #[cfg(feature = "kusama")] @@ -94,15 +98,15 @@ mod kusama { /// The encoded index correspondes to Kusama's Runtime module configuration. /// https://github.com/paritytech/polkadot/blob/444e96ae34bcec8362f0f947a07bd912b32ca48f/runtime/kusama/src/lib.rs#L1379 #[derive(Encode, Decode, RuntimeDebug)] - pub enum RelayChainCall { + pub enum RelayChainCall { #[codec(index = 4)] - Balances(BalancesCall), + Balances(BalancesCall), #[codec(index = 6)] Staking(StakingCall), #[codec(index = 24)] - Utility(Box>>), + Utility(Box>), #[codec(index = 30)] - Proxy(Box>>), + Proxy(Box>), #[codec(index = 99)] XcmPallet(XcmCall), } @@ -115,15 +119,15 @@ mod polkadot { /// The encoded index correspondes to Polkadot's Runtime module configuration. /// https://github.com/paritytech/polkadot/blob/84a3962e76151ac5ed3afa4ef1e0af829531ab42/runtime/polkadot/src/lib.rs#L1040 #[derive(Encode, Decode, RuntimeDebug)] - pub enum RelayChainCall { + pub enum RelayChainCall { #[codec(index = 5)] - Balances(BalancesCall), + Balances(BalancesCall), #[codec(index = 7)] Staking(StakingCall), #[codec(index = 26)] - Utility(Box>>), + Utility(Box>), #[codec(index = 29)] - Proxy(Box>>), + Proxy(Box>), #[codec(index = 99)] XcmPallet(XcmCall), } @@ -135,16 +139,12 @@ pub use kusama::*; #[cfg(feature = "polkadot")] pub use polkadot::*; -pub struct RelayChainCallBuilder>(PhantomData<(T, ParachainId)>); +pub struct RelayChainCallBuilder>(PhantomData); -impl> CallBuilder for RelayChainCallBuilder -where - T::AccountId: FullCodec, - RelayChainCall: FullCodec, -{ - type AccountId = T::AccountId; +impl> CallBuilder for RelayChainCallBuilder { + type AccountId = AccountId; type Balance = Balance; - type RelayChainCall = RelayChainCall; + type RelayChainCall = RelayChainCall; fn utility_as_derivative_call(call: Self::RelayChainCall, index: u16) -> Self::RelayChainCall { RelayChainCall::Utility(Box::new(UtilityCall::AsDerivative(index, call))) @@ -163,7 +163,7 @@ where } fn balances_transfer_keep_alive(to: Self::AccountId, amount: Self::Balance) -> Self::RelayChainCall { - RelayChainCall::Balances(BalancesCall::TransferKeepAlive(T::Lookup::unlookup(to), amount)) + RelayChainCall::Balances(BalancesCall::TransferKeepAlive(RelayChainLookup::unlookup(to), amount)) } fn finalize_call_into_xcm_message( @@ -253,6 +253,6 @@ where } fn proxy_call(real: Self::AccountId, call: Self::RelayChainCall) -> Self::RelayChainCall { - RelayChainCall::Proxy(Box::new(ProxyCall::Proxy(T::Lookup::unlookup(real), None, call))) + RelayChainCall::Proxy(Box::new(ProxyCall::Proxy(RelayChainLookup::unlookup(real), None, call))) } } diff --git a/modules/xcm-interface/src/mock.rs b/modules/xcm-interface/src/mock.rs index f94bd2859a..c0110bfb5d 100644 --- a/modules/xcm-interface/src/mock.rs +++ b/modules/xcm-interface/src/mock.rs @@ -131,6 +131,8 @@ parameter_types! { pub const GetStakingCurrencyId: CurrencyId = DOT; pub const ParachainAccount: AccountId = AccountId32::new([0u8; 32]); pub const ParachainId: module_relaychain::ParaId = module_relaychain::ParaId::new(2000); + pub CrowdloanVaultAccount: AccountId = AccountId::from([0u8; 32]); + pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainId::get().into()))); } pub struct SubAccountIndexMultiLocationConvertor; @@ -205,6 +207,17 @@ impl XcmTransfer for MockXcmTransfer { } } +pub struct AccountIdToMultiLocation; +impl Convert for AccountIdToMultiLocation { + fn convert(account: AccountId) -> MultiLocation { + X1(Junction::AccountId32 { + network: None, + id: account.into(), + }) + .into() + } +} + impl Config for Runtime { type RuntimeEvent = RuntimeEvent; type UpdateOrigin = EnsureSignedBy; @@ -212,8 +225,11 @@ impl Config for Runtime { type ParachainAccount = ParachainAccount; type RelayChainUnbondingSlashingSpans = ConstU32<28>; type SovereignSubAccountLocationConvert = SubAccountIndexMultiLocationConvertor; - type RelayChainCallBuilder = module_relaychain::RelayChainCallBuilder; + type RelayChainCallBuilder = module_relaychain::RelayChainCallBuilder; type XcmTransfer = MockXcmTransfer; + type SelfLocation = SelfLocation; + type AccountIdToMultiLocation = AccountIdToMultiLocation; + type CrowdloanVaultAccount = CrowdloanVaultAccount; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 28f9cf9b83..689da75523 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1536,7 +1536,7 @@ impl module_xcm_interface::Config for Runtime { type ParachainAccount = ParachainAccount; type RelayChainUnbondingSlashingSpans = ConstU32<5>; type SovereignSubAccountLocationConvert = SubAccountIndexMultiLocationConvertor; - type RelayChainCallBuilder = RelayChainCallBuilder; + type RelayChainCallBuilder = RelayChainCallBuilder; type XcmTransfer = XTokens; type SelfLocation = xcm_config::SelfLocation; type AccountIdToMultiLocation = xcm_config::AccountIdToMultiLocation; diff --git a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs index cd0c70b152..766389990b 100644 --- a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs +++ b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs @@ -856,11 +856,9 @@ fn unspent_xcm_fee_is_returned_correctly() { Karura::execute_with(|| { // Construct a transfer XCM call with returning the deposit - let transfer_call = RelayChainCallBuilder::::balances_transfer_keep_alive( - AccountId::from(BOB), - dollar_n, - ); - let batch_call = RelayChainCallBuilder::::utility_as_derivative_call(transfer_call, 0); + let transfer_call = + RelayChainCallBuilder::::balances_transfer_keep_alive(AccountId::from(BOB), dollar_n); + let batch_call = RelayChainCallBuilder::::utility_as_derivative_call(transfer_call, 0); let weight = XcmWeight::from_ref_time(10_000_000_000); // Fee to transfer into the hold register let asset = MultiAsset { @@ -899,12 +897,10 @@ fn unspent_xcm_fee_is_returned_correctly() { Karura::execute_with(|| { // Construct a transfer using the RelaychainCallBuilder - let transfer_call = RelayChainCallBuilder::::balances_transfer_keep_alive( - AccountId::from(BOB), - dollar_n, - ); - let batch_call = RelayChainCallBuilder::::utility_as_derivative_call(transfer_call, 0); - let finalized_call = RelayChainCallBuilder::::finalize_call_into_xcm_message( + let transfer_call = + RelayChainCallBuilder::::balances_transfer_keep_alive(AccountId::from(BOB), dollar_n); + let batch_call = RelayChainCallBuilder::::utility_as_derivative_call(transfer_call, 0); + let finalized_call = RelayChainCallBuilder::::finalize_call_into_xcm_message( batch_call, dollar_n, XcmWeight::from_ref_time(10_000_000_000), @@ -938,7 +934,7 @@ fn trapped_asset() -> MultiAsset { }; Karura::execute_with(|| { - let transfer_call = RelayChainCallBuilder::::balances_transfer_keep_alive( + let transfer_call = RelayChainCallBuilder::::balances_transfer_keep_alive( AccountId::from(BOB), dollar(NATIVE_CURRENCY), ); diff --git a/runtime/integration-tests/src/relaychain/relay_chain.rs b/runtime/integration-tests/src/relaychain/relay_chain.rs index b662aafc85..e5ebb50d56 100644 --- a/runtime/integration-tests/src/relaychain/relay_chain.rs +++ b/runtime/integration-tests/src/relaychain/relay_chain.rs @@ -31,7 +31,7 @@ mod karura_tests { use module_support::CallBuilder; use xcm_emulator::TestExt; - type KusamaCallBuilder = RelayChainCallBuilder; + type KusamaCallBuilder = RelayChainCallBuilder; #[test] /// Tests the staking_withdraw_unbonded call. diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 86777483ef..69015e453e 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1536,6 +1536,8 @@ impl Convert for SubAccountIndexMultiLocationConvertor { parameter_types! { pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); + //TODO: update with real crowdloan account + pub CrowdloanVaultAccount: AccountId = AccountId::from([0u8; 32]); } impl module_xcm_interface::Config for Runtime { @@ -1545,10 +1547,11 @@ impl module_xcm_interface::Config for Runtime { type ParachainAccount = ParachainAccount; type RelayChainUnbondingSlashingSpans = ConstU32<5>; type SovereignSubAccountLocationConvert = SubAccountIndexMultiLocationConvertor; - type RelayChainCallBuilder = RelayChainCallBuilder; + type RelayChainCallBuilder = RelayChainCallBuilder; type XcmTransfer = XTokens; type SelfLocation = xcm_config::SelfLocation; type AccountIdToMultiLocation = xcm_config::AccountIdToMultiLocation; + type CrowdloanVaultAccount = CrowdloanVaultAccount; } impl orml_unknown_tokens::Config for Runtime { diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 12c76cc45c..21a256e8cc 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1382,6 +1382,8 @@ impl module_homa::Config for Runtime { parameter_types! { pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); + //TODO: update with real crowdloan account + pub CrowdloanVaultAccount: AccountId = AccountId::from([0u8; 32]); } pub struct SubAccountIndexMultiLocationConvertor; @@ -1398,10 +1400,11 @@ impl module_xcm_interface::Config for Runtime { type ParachainAccount = ParachainAccount; type RelayChainUnbondingSlashingSpans = ConstU32<5>; type SovereignSubAccountLocationConvert = SubAccountIndexMultiLocationConvertor; - type RelayChainCallBuilder = RelayChainCallBuilder; + type RelayChainCallBuilder = RelayChainCallBuilder; type XcmTransfer = XTokens; type SelfLocation = xcm_config::SelfLocation; type AccountIdToMultiLocation = xcm_config::AccountIdToMultiLocation; + type CrowdloanVaultAccount = CrowdloanVaultAccount; } parameter_types! { From 8b94cad6b6f0a25e245e12d0c01114e25ea1dd86 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Wed, 12 Apr 2023 17:27:11 +1200 Subject: [PATCH 04/20] liquid crowdloan module unit tests --- Cargo.lock | 3 + modules/liquid-crowdloan/Cargo.toml | 3 + modules/liquid-crowdloan/src/lib.rs | 9 +- modules/liquid-crowdloan/src/mock.rs | 204 +++++++++++++++++++++++--- modules/liquid-crowdloan/src/tests.rs | 74 +++++++++- 5 files changed, 264 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 961515dc4e..45bc296401 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6412,8 +6412,11 @@ dependencies = [ "acala-primitives", "frame-support", "frame-system", + "module-currencies", "module-support", + "orml-tokens", "orml-traits", + "pallet-balances", "parity-scale-codec", "scale-info", "sp-core", diff --git a/modules/liquid-crowdloan/Cargo.toml b/modules/liquid-crowdloan/Cargo.toml index 09ce39dff7..14080b28dc 100644 --- a/modules/liquid-crowdloan/Cargo.toml +++ b/modules/liquid-crowdloan/Cargo.toml @@ -19,6 +19,9 @@ support = { package = "module-support", path = "../support", default-features = [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" } +module-currencies = { path = "../currencies" } +orml-tokens = { path = "../../orml/tokens" } [features] default = ["std"] diff --git a/modules/liquid-crowdloan/src/lib.rs b/modules/liquid-crowdloan/src/lib.rs index 44e358c972..87057e7f2b 100644 --- a/modules/liquid-crowdloan/src/lib.rs +++ b/modules/liquid-crowdloan/src/lib.rs @@ -49,6 +49,9 @@ pub mod module { #[pallet::constant] type LiquidCrowdloanCurrencyId: Get; + #[pallet::constant] + type RelayChainCurrencyId: Get; + #[pallet::constant] type PalletId: Get; @@ -87,15 +90,15 @@ pub mod module { T::Currency::withdraw(T::LiquidCrowdloanCurrencyId::get(), &who, amount)?; - T::Currency::transfer(T::LiquidCrowdloanCurrencyId::get(), &Self::account_id(), &who, amount)?; + T::Currency::transfer(T::RelayChainCurrencyId::get(), &Self::account_id(), &who, amount)?; Self::deposit_event(Event::Redeemed { amount }); Ok(()) } - /// Cross-chain transfer DOT from relay chain crowdloan vault to liquid crowdloan module - /// account. + /// Send an XCM message to cross-chain transfer DOT from relay chain crowdloan vault to + /// liquid crowdloan module account. /// /// This call requires `GovernanceOrigin`. #[pallet::call_index(1)] diff --git a/modules/liquid-crowdloan/src/mock.rs b/modules/liquid-crowdloan/src/mock.rs index 339913b587..231597253a 100644 --- a/modules/liquid-crowdloan/src/mock.rs +++ b/modules/liquid-crowdloan/src/mock.rs @@ -20,32 +20,51 @@ #![cfg(test)] +use super::*; use crate as liquid_crowdloan; + use frame_support::{ - construct_runtime, - pallet_prelude::GenesisBuild, - traits::{ConstU32, ConstU64, Everything}, + construct_runtime, ord_parameter_types, parameter_types, + traits::{ConstU128, ConstU32, ConstU64, Everything, Nothing}, }; +use frame_system::{EnsureRoot, EnsureSignedBy}; +use orml_traits::parameter_type_with_key; +use primitives::{Amount, TokenSymbol}; +use sp_core::{H160, H256}; +use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; +use std::cell::RefCell; +use support::mocks::MockAddressMapping; + +pub type AccountId = AccountId32; +pub type BlockNumber = u64; + +pub const ACA: CurrencyId = CurrencyId::Token(TokenSymbol::ACA); +pub const DOT: CurrencyId = CurrencyId::Token(TokenSymbol::DOT); +pub const LDOT: CurrencyId = CurrencyId::Token(TokenSymbol::LDOT); + +pub const ALICE: AccountId = AccountId32::new([1u8; 32]); +pub const BOB: AccountId = AccountId32::new([2u8; 32]); +pub const VAULT: AccountId = AccountId32::new([3u8; 32]); impl frame_system::Config for Runtime { type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; - type Index = u64; - type BlockNumber = u64; type RuntimeCall = RuntimeCall; - type Hash = sp_runtime::testing::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; - type AccountId = u64; - type Lookup = sp_runtime::traits::IdentityLookup; - type Header = sp_runtime::testing::Header; + type Index = u64; + type BlockNumber = BlockNumber; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; type RuntimeEvent = RuntimeEvent; type BlockHashCount = ConstU64<250>; - type BlockWeights = (); - type BlockLength = (); type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = (); + type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); @@ -54,10 +73,97 @@ impl frame_system::Config for Runtime { type MaxConsumers = ConstU32<16>; } +parameter_type_with_key! { + pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance { + Default::default() + }; +} + +impl orml_tokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Amount = Amount; + type CurrencyId = CurrencyId; + type WeightInfo = (); + type ExistentialDeposits = ExistentialDeposits; + type CurrencyHooks = (); + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type DustRemovalWhitelist = Nothing; +} + +impl pallet_balances::Config for Runtime { + type Balance = Balance; + type DustRemoval = (); + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ConstU128<0>; + type AccountStore = frame_system::Pallet; + type MaxLocks = (); + type WeightInfo = (); + type MaxReserves = (); + type ReserveIdentifier = (); +} + +pub type AdaptedBasicCurrency = module_currencies::BasicCurrencyAdapter; + +parameter_types! { + pub const GetNativeCurrencyId: CurrencyId = ACA; + pub Erc20HoldingAccount: H160 = H160::from_low_u64_be(1); + pub CrowdloanVault: AccountId = VAULT; + pub LiquidCrowdloanPalletId: PalletId = PalletId(*b"aca/lqcl"); + pub const Ldot: CurrencyId = LDOT; + pub const Dot: CurrencyId = DOT; +} + +impl module_currencies::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MultiCurrency = Tokens; + type NativeCurrency = AdaptedBasicCurrency; + type GetNativeCurrencyId = GetNativeCurrencyId; + type Erc20HoldingAccount = Erc20HoldingAccount; + type WeightInfo = (); + type AddressMapping = MockAddressMapping; + type EVMBridge = (); + type GasToWeight = (); + type SweepOrigin = EnsureRoot; + type OnDust = (); +} + +thread_local! { + pub static TRANSFER_RECORD: RefCell> = RefCell::new(None); + pub static TRANSFER_OK: RefCell = RefCell::new(true); +} + +pub struct MockXcmTransfer; +impl CrowdloanVaultXcm for MockXcmTransfer { + fn transfer_to_liquid_crowdloan_module_account( + vault: AccountId, + recipient: AccountId, + amount: Balance, + ) -> DispatchResult { + if TRANSFER_OK.with(|v| *v.borrow()) { + TRANSFER_RECORD.with(|v| *v.borrow_mut() = Some((vault, recipient, amount))); + Ok(()) + } else { + Err(DispatchError::Other("transfer failed")) + } + } +} + +ord_parameter_types! { + pub const Alice: AccountId = ALICE; +} + impl liquid_crowdloan::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type SomeConst = ConstU64<10>; - type Balance = u64; + type Currency = Currencies; + type LiquidCrowdloanCurrencyId = Ldot; + type RelayChainCurrencyId = Dot; + type PalletId = LiquidCrowdloanPalletId; + type GovernanceOrigin = EnsureSignedBy; + type CrowdloanVault = CrowdloanVault; + type XcmTransfer = MockXcmTransfer; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; @@ -70,16 +176,70 @@ construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic { System: frame_system::{Pallet, Call, Event}, - LiquidCrowdloan: liquid_crowdloan::{Pallet, Call, Event, Config, Storage}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + Tokens: orml_tokens::{Pallet, Storage, Event, Config}, + Currencies: module_currencies::{Pallet, Call, Event}, + LiquidCrowdloan: liquid_crowdloan::{Pallet, Call, Event, Storage}, } ); -pub fn new_test_ext() -> sp_io::TestExternalities { - let t = frame_system::GenesisConfig::default() - .build_storage::() +pub struct ExtBuilder { + balances: Vec<(AccountId, CurrencyId, Balance)>, + transfer_ok: bool, +} + +impl Default for ExtBuilder { + fn default() -> Self { + Self { + balances: vec![], + transfer_ok: true, + } + } +} + +impl ExtBuilder { + pub fn balances(mut self, balances: Vec<(AccountId, CurrencyId, Balance)>) -> Self { + self.balances = balances; + self + } + + pub fn transfer_ok(mut self, transfer_ok: bool) -> Self { + self.transfer_ok = transfer_ok; + self + } + + pub fn build(self) -> sp_io::TestExternalities { + TRANSFER_RECORD.with(|v| *v.borrow_mut() = None); + TRANSFER_OK.with(|v| *v.borrow_mut() = self.transfer_ok); + + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: self + .balances + .clone() + .into_iter() + .filter(|(_, currency_id, _)| *currency_id == ACA) + .map(|(account_id, _, initial_balance)| (account_id, initial_balance)) + .collect::>(), + } + .assimilate_storage(&mut t) .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext + orml_tokens::GenesisConfig:: { + balances: self + .balances + .into_iter() + .filter(|(_, currency_id, _)| *currency_id != ACA) + .collect::>(), + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } } diff --git a/modules/liquid-crowdloan/src/tests.rs b/modules/liquid-crowdloan/src/tests.rs index cb724f4528..abbd929a84 100644 --- a/modules/liquid-crowdloan/src/tests.rs +++ b/modules/liquid-crowdloan/src/tests.rs @@ -20,12 +20,78 @@ #![cfg(test)] +use super::*; use crate::mock::*; -use frame_support::assert_ok; +use frame_support::{assert_err, assert_ok}; +use orml_traits::MultiCurrency; +use sp_runtime::traits::BadOrigin; #[test] -fn set_dummy_work() { - new_test_ext().execute_with(|| { - assert_ok!(Ok(())); +fn redeem_works() { + ExtBuilder::default() + .balances(vec![(BOB, LDOT, 100), (LiquidCrowdloan::account_id(), DOT, 100)]) + .build() + .execute_with(|| { + assert_ok!(LiquidCrowdloan::redeem(RuntimeOrigin::signed(BOB), 100)); + assert_eq!(Currencies::free_balance(LDOT, &BOB), 0); + assert_eq!(Currencies::free_balance(DOT, &BOB), 100); + assert_eq!(Currencies::free_balance(DOT, &LiquidCrowdloan::account_id()), 0); + System::assert_last_event(RuntimeEvent::LiquidCrowdloan(crate::Event::Redeemed { amount: 100 })); + }); +} + +#[test] +fn redeem_fails_if_not_enough_liquid_crowdloan_token() { + ExtBuilder::default().build().execute_with(|| { + assert_err!( + LiquidCrowdloan::redeem(RuntimeOrigin::signed(BOB), 100), + orml_tokens::Error::::BalanceTooLow + ); }); } + +#[test] +fn redeem_fails_if_not_enough_relay_chain_token() { + ExtBuilder::default() + .balances(vec![(BOB, LDOT, 100)]) + .build() + .execute_with(|| { + assert_err!( + LiquidCrowdloan::redeem(RuntimeOrigin::signed(BOB), 100), + orml_tokens::Error::::BalanceTooLow + ); + }); +} + +#[test] +fn transfer_from_crowdloan_vault_works() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(LiquidCrowdloan::transfer_from_crowdloan_vault( + RuntimeOrigin::signed(ALICE), + 100, + )); + System::assert_last_event(RuntimeEvent::LiquidCrowdloan( + crate::Event::TransferFromCrowdloanVaultRequested { amount: 100 }, + )); + }); +} + +#[test] +fn transfer_from_crowdloan_vault_fails_if_not_gov_origin() { + ExtBuilder::default().build().execute_with(|| { + assert_err!( + LiquidCrowdloan::transfer_from_crowdloan_vault(RuntimeOrigin::signed(BOB), 100,), + BadOrigin + ); + }); +} + +#[test] +fn transfer_from_crowdloan_vault_fails_if_sending_xcm_failed() { + ExtBuilder::default().transfer_ok(false).build().execute_with(|| { + assert_err!( + LiquidCrowdloan::transfer_from_crowdloan_vault(RuntimeOrigin::signed(ALICE), 100,), + DispatchError::Other("transfer failed") + ); + }) +} From 71ae5a2072275395b0cfa282becdf48277e38a96 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Thu, 13 Apr 2023 16:33:58 +1200 Subject: [PATCH 05/20] integration tests --- Cargo.lock | 1 + modules/xcm-interface/src/lib.rs | 4 - modules/xcm-interface/src/mock.rs | 2 - runtime/acala/Cargo.toml | 2 + runtime/acala/src/lib.rs | 18 ++- runtime/integration-tests/Cargo.toml | 3 +- .../src/relaychain/liquid_crowdloan.rs | 113 ++++++++++++++++++ .../integration-tests/src/relaychain/mod.rs | 2 + runtime/karura/src/lib.rs | 3 - runtime/mandala/src/lib.rs | 3 - 10 files changed, 135 insertions(+), 16 deletions(-) create mode 100644 runtime/integration-tests/src/relaychain/liquid_crowdloan.rs diff --git a/Cargo.lock b/Cargo.lock index 45bc296401..0c2aaf4c47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -157,6 +157,7 @@ dependencies = [ "module-honzon", "module-idle-scheduler", "module-incentives", + "module-liquid-crowdloan", "module-loans", "module-nft", "module-prices", diff --git a/modules/xcm-interface/src/lib.rs b/modules/xcm-interface/src/lib.rs index 1d4776c4e8..f1f81f8cda 100644 --- a/modules/xcm-interface/src/lib.rs +++ b/modules/xcm-interface/src/lib.rs @@ -96,10 +96,6 @@ pub mod module { /// Convert AccountId to MultiLocation to build XCM message. type AccountIdToMultiLocation: Convert; - - /// Crowdloan vault account. - #[pallet::constant] - type CrowdloanVaultAccount: Get; } #[pallet::error] diff --git a/modules/xcm-interface/src/mock.rs b/modules/xcm-interface/src/mock.rs index c0110bfb5d..03142a2fd0 100644 --- a/modules/xcm-interface/src/mock.rs +++ b/modules/xcm-interface/src/mock.rs @@ -131,7 +131,6 @@ parameter_types! { pub const GetStakingCurrencyId: CurrencyId = DOT; pub const ParachainAccount: AccountId = AccountId32::new([0u8; 32]); pub const ParachainId: module_relaychain::ParaId = module_relaychain::ParaId::new(2000); - pub CrowdloanVaultAccount: AccountId = AccountId::from([0u8; 32]); pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainId::get().into()))); } @@ -229,7 +228,6 @@ impl Config for Runtime { type XcmTransfer = MockXcmTransfer; type SelfLocation = SelfLocation; type AccountIdToMultiLocation = AccountIdToMultiLocation; - type CrowdloanVaultAccount = CrowdloanVaultAccount; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/runtime/acala/Cargo.toml b/runtime/acala/Cargo.toml index 978a46cda2..e5a0cf7aa1 100644 --- a/runtime/acala/Cargo.toml +++ b/runtime/acala/Cargo.toml @@ -116,6 +116,7 @@ module-session-manager = { path = "../../modules/session-manager", default-featu module-relaychain = { path = "../../modules/relaychain", default-features = false, features = ["polkadot"] } module-idle-scheduler = { path = "../../modules/idle-scheduler", default-features = false } module-aggregated-dex = { path = "../../modules/aggregated-dex", default-features = false } +module-liquid-crowdloan = { path = "../../modules/liquid-crowdloan", default-features = false } primitives = { package = "acala-primitives", path = "../../primitives", default-features = false } runtime-common = { path = "../common", default-features = false } @@ -246,6 +247,7 @@ std = [ "module-transaction-pause/std", "module-transaction-payment/std", "module-xcm-interface/std", + "module-liquid-crowdloan/std", "primitives/std", "runtime-common/std", diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 689da75523..3327431dd9 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -172,6 +172,7 @@ parameter_types! { // This Pallet is only used to payment fee pool, it's not added to whitelist by design. // because transaction payment pallet will ensure the accounts always have enough ED. pub const TransactionPaymentPalletId: PalletId = PalletId(*b"aca/fees"); + pub const LiquidCrowdloanPalletId: PalletId = PalletId(*b"aca/lqcl"); pub const StableAssetPalletId: PalletId = PalletId(*b"nuts/sta"); } @@ -1525,8 +1526,8 @@ impl Convert for SubAccountIndexMultiLocationConvertor { parameter_types! { pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); - //TODO: update with real crowdloan account - pub CrowdloanVaultAccount: AccountId = AccountId::from([0u8; 32]); + // Crowdloan vault address: `132zsjMwGjNaUXF5XjUCDs2cDEq9Qao51TsL9RSUTGZbinVK` + pub CrowdloanVault: AccountId = AccountId::from(hex_literal::hex!("59fe89295c2e57d7b4d4d8be9e00a3802e513703ab4b5b424ed0a646e899d3c9")); } impl module_xcm_interface::Config for Runtime { @@ -1540,7 +1541,6 @@ impl module_xcm_interface::Config for Runtime { type XcmTransfer = XTokens; type SelfLocation = xcm_config::SelfLocation; type AccountIdToMultiLocation = xcm_config::AccountIdToMultiLocation; - type CrowdloanVaultAccount = CrowdloanVaultAccount; } impl orml_unknown_tokens::Config for Runtime { @@ -1655,6 +1655,17 @@ impl nutsfinance_stable_asset::Config for Runtime { type EnsurePoolAssetId = EnsurePoolAssetId; } +impl module_liquid_crowdloan::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Currencies; + type LiquidCrowdloanCurrencyId = GetLiquidCurrencyId; + type RelayChainCurrencyId = GetStakingCurrencyId; + type PalletId = LiquidCrowdloanPalletId; + type GovernanceOrigin = EnsureRoot; + type CrowdloanVault = CrowdloanVault; + type XcmTransfer = XcmInterface; +} + construct_runtime!( pub enum Runtime where Block = Block, @@ -1750,6 +1761,7 @@ construct_runtime!( Incentives: module_incentives = 120, NFT: module_nft = 121, AssetRegistry: module_asset_registry = 122, + LiquidCrowdloan: module_liquid_crowdloan = 123, // Smart contracts EVM: module_evm = 130, diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 65c500c8ff..b62b6e6599 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -139,6 +139,7 @@ kusama-runtime-constants = { git = "https://github.com/paritytech/polkadot", bra polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } polkadot-test-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" } xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "754f3b90ecc65af735a6c9a2e1792c5253926ff6" } @@ -147,7 +148,7 @@ module-aggregated-dex = { path = "../../modules/aggregated-dex" } nutsfinance-stable-asset = { version = "0.1.0", path = "../../ecosystem-modules/stable-asset/lib/stable-asset", package = "nutsfinance-stable-asset" } [features] -default = ["std"] +default = ["std", "with-acala-runtime"] no_std = [] with-mandala-runtime = [ "mandala-runtime", diff --git a/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs b/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs new file mode 100644 index 0000000000..821b938cd4 --- /dev/null +++ b/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs @@ -0,0 +1,113 @@ +// This file is part of Acala. + +// Copyright (C) 2023 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::relaychain::fee_test::*; +use crate::relaychain::polkadot_test_net::*; +use crate::setup::*; + +use frame_support::{assert_noop, assert_ok}; +use module_xcm_interface::XcmInterfaceOperation; +use sp_runtime::traits::StaticLookup; +use xcm_emulator::TestExt; + +const ACALA_PARA_ID: u32 = 2000; + +//TODO: Enable after Polkadot runtime allows XCM proxy calls: +// https://github.com/paritytech/polkadot/blob/5c554b95e223b507a9b7e420e2cdee06e0982ab0/runtime/polkadot/src/xcm_config.rs#L167 +#[ignore = "polkadot runtime does not allow XCM proxy calls"] +#[test] +fn transfer_from_crowdloan_vault_works() { + TestNet::reset(); + + let vault = acala_runtime::CrowdloanVault::get(); + let module_liquid_crowdloan_account = acala_runtime::LiquidCrowdloan::account_id(); + let acala_sovereign_account: AccountId = ParaId::from(ACALA_PARA_ID).into_account_truncating(); + + PolkadotNet::execute_with(|| { + use polkadot_runtime::{Balances, Proxy, ProxyType, Runtime, RuntimeCall, RuntimeOrigin, XcmPallet}; + + Balances::deposit_creating(&vault, dollar(DOT) * 100); + + assert_ok!(Proxy::add_proxy( + RuntimeOrigin::signed(vault.clone()), + ::Lookup::unlookup(acala_sovereign_account.clone()), + ProxyType::Any, + 0 + )); + + // NOTE: the following code is to help debugging via duplicating the XCM transact in + // Polkadot runtime. Feel free to delete it after Polkadot runtime allows XCM proxy calls + // and the test can be enabled. + + // let call = RuntimeCall::XcmPallet(pallet_xcm::Call::reserve_transfer_assets { + // dest: Box::new(Parachain(2000).into_versioned()), + // beneficiary: Box::new( + // Junction::AccountId32 { + // id: module_liquid_crowdloan_account.clone().into(), + // network: None + // } + // .into_versioned() + // ), + // assets: Box::new((Here, dollar(DOT)).into()), + // fee_asset_item: 0, + // }); + // assert_ok!(Proxy::proxy( + // RuntimeOrigin::signed(acala_sovereign_account.clone()), + // ::Lookup::unlookup(vault.clone()), + // None, + // Box::new(call), + // )); + + // assert_ok!(XcmPallet::reserve_transfer_assets( + // RuntimeOrigin::signed(vault), + // Box::new(Parachain(2000).into_versioned()), + // Box::new( + // Junction::AccountId32 { + // id: module_liquid_crowdloan_account.clone().into(), + // network: None + // } + // .into_versioned() + // ), + // Box::new((Here, dollar(DOT)).into()), + // 0 + // )); + }); + + Acala::execute_with(|| { + use acala_runtime::{LiquidCrowdloan, RuntimeOrigin, XcmInterface}; + + assert_ok!(XcmInterface::update_xcm_dest_weight_and_fee( + RuntimeOrigin::root(), + vec![( + XcmInterfaceOperation::ProxyReserveTransferAssets, + Some(XcmWeight::from_ref_time(20_000_000_000)), + Some(100_000_000_000) + )] + )); + + assert_ok!(LiquidCrowdloan::transfer_from_crowdloan_vault( + RuntimeOrigin::root(), + dollar(DOT), + )); + + assert_eq!( + Tokens::free_balance(DOT, &module_liquid_crowdloan_account), + 9_998_397_440, + ); + }); +} diff --git a/runtime/integration-tests/src/relaychain/mod.rs b/runtime/integration-tests/src/relaychain/mod.rs index 973452d7e9..ad0f643157 100644 --- a/runtime/integration-tests/src/relaychain/mod.rs +++ b/runtime/integration-tests/src/relaychain/mod.rs @@ -27,6 +27,8 @@ pub mod kusama_test_net; #[cfg(feature = "with-karura-runtime")] mod statemine; +#[cfg(feature = "with-acala-runtime")] +mod liquid_crowdloan; #[cfg(feature = "with-acala-runtime")] mod polkadot_cross_chain_transfer; #[cfg(feature = "with-acala-runtime")] diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 69015e453e..ee1542b950 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1536,8 +1536,6 @@ impl Convert for SubAccountIndexMultiLocationConvertor { parameter_types! { pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); - //TODO: update with real crowdloan account - pub CrowdloanVaultAccount: AccountId = AccountId::from([0u8; 32]); } impl module_xcm_interface::Config for Runtime { @@ -1551,7 +1549,6 @@ impl module_xcm_interface::Config for Runtime { type XcmTransfer = XTokens; type SelfLocation = xcm_config::SelfLocation; type AccountIdToMultiLocation = xcm_config::AccountIdToMultiLocation; - type CrowdloanVaultAccount = CrowdloanVaultAccount; } impl orml_unknown_tokens::Config for Runtime { diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 21a256e8cc..8c16210ae8 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1382,8 +1382,6 @@ impl module_homa::Config for Runtime { parameter_types! { pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); - //TODO: update with real crowdloan account - pub CrowdloanVaultAccount: AccountId = AccountId::from([0u8; 32]); } pub struct SubAccountIndexMultiLocationConvertor; @@ -1404,7 +1402,6 @@ impl module_xcm_interface::Config for Runtime { type XcmTransfer = XTokens; type SelfLocation = xcm_config::SelfLocation; type AccountIdToMultiLocation = xcm_config::AccountIdToMultiLocation; - type CrowdloanVaultAccount = CrowdloanVaultAccount; } parameter_types! { From d94e1c6f57a6b30cbfe6b756e92bb871742ba171 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Thu, 13 Apr 2023 16:44:54 +1200 Subject: [PATCH 06/20] more docstring --- modules/liquid-crowdloan/src/lib.rs | 13 +++++++------ modules/relaychain/src/lib.rs | 1 + .../src/relaychain/liquid_crowdloan.rs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/liquid-crowdloan/src/lib.rs b/modules/liquid-crowdloan/src/lib.rs index 87057e7f2b..d80a85f56c 100644 --- a/modules/liquid-crowdloan/src/lib.rs +++ b/modules/liquid-crowdloan/src/lib.rs @@ -46,12 +46,15 @@ pub mod module { type Currency: MultiCurrency; + /// Liquid crowdloan currency Id, i.e. LDOT for Polkadot. #[pallet::constant] type LiquidCrowdloanCurrencyId: Get; + /// Relay chain currency Id, i.e. DOT for Polkadot. #[pallet::constant] type RelayChainCurrencyId: Get; + /// Pallet Id for liquid crowdloan module. #[pallet::constant] type PalletId: Get; @@ -71,18 +74,16 @@ pub mod module { #[pallet::generate_deposit(fn deposit_event)] pub enum Event { /// Liquid Crowdloan asset was redeemed. - Redeemed { - amount: Balance, - }, - TransferFromCrowdloanVaultRequested { - amount: Balance, - }, + Redeemed { amount: Balance }, + /// The transfer from relay chain crowdloan vault was requested. + TransferFromCrowdloanVaultRequested { amount: Balance }, } #[pallet::pallet] pub struct Pallet(_); #[pallet::call] impl Pallet { + /// Redeem liquid crowdloan currency for relay chain currency. #[pallet::call_index(0)] #[pallet::weight(0)] pub fn redeem(origin: OriginFor, #[pallet::compact] amount: Balance) -> DispatchResult { diff --git a/modules/relaychain/src/lib.rs b/modules/relaychain/src/lib.rs index 03e6cf9725..ef9487bf8d 100644 --- a/modules/relaychain/src/lib.rs +++ b/modules/relaychain/src/lib.rs @@ -22,6 +22,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::unused_unit)] +#![allow(clippy::large_enum_variant)] use codec::{Decode, Encode}; use sp_runtime::traits::{AccountIdLookup, StaticLookup}; diff --git a/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs b/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs index 821b938cd4..40bd026b0d 100644 --- a/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs +++ b/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs @@ -1,6 +1,6 @@ // This file is part of Acala. -// Copyright (C) 2023 Acala Foundation. +// Copyright (C) 2020-2023 Acala Foundation. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify From a75c27253b39fd1f2603203254dd695e9dd39a56 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Thu, 13 Apr 2023 17:23:01 +1200 Subject: [PATCH 07/20] update gov origin for liquid crowdloan module --- runtime/acala/src/lib.rs | 2 +- runtime/integration-tests/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 3327431dd9..a03b0a168f 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1661,7 +1661,7 @@ impl module_liquid_crowdloan::Config for Runtime { type LiquidCrowdloanCurrencyId = GetLiquidCurrencyId; type RelayChainCurrencyId = GetStakingCurrencyId; type PalletId = LiquidCrowdloanPalletId; - type GovernanceOrigin = EnsureRoot; + type GovernanceOrigin = EnsureRootOrHalfGeneralCouncil; type CrowdloanVault = CrowdloanVault; type XcmTransfer = XcmInterface; } diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index b62b6e6599..2268fc63ee 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -148,7 +148,7 @@ module-aggregated-dex = { path = "../../modules/aggregated-dex" } nutsfinance-stable-asset = { version = "0.1.0", path = "../../ecosystem-modules/stable-asset/lib/stable-asset", package = "nutsfinance-stable-asset" } [features] -default = ["std", "with-acala-runtime"] +default = ["std"] no_std = [] with-mandala-runtime = [ "mandala-runtime", From a998f8d6b3d434aba5cd90268035abcb19616443 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Fri, 14 Apr 2023 10:55:51 +1200 Subject: [PATCH 08/20] benchmarking --- Cargo.lock | 1 + runtime/acala/Cargo.toml | 1 + runtime/acala/src/benchmarking/mod.rs | 3 ++ runtime/acala/src/lib.rs | 8 +++- .../src/relaychain/liquid_crowdloan.rs | 21 ++------ runtime/mandala/Cargo.toml | 3 ++ .../src/benchmarking/liquid_crowdloan.rs | 48 +++++++++++++++++++ runtime/mandala/src/benchmarking/mod.rs | 1 + runtime/mandala/src/lib.rs | 19 ++++++++ 9 files changed, 85 insertions(+), 20 deletions(-) create mode 100644 runtime/mandala/src/benchmarking/liquid_crowdloan.rs diff --git a/Cargo.lock b/Cargo.lock index 0c2aaf4c47..fd6f46858b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5605,6 +5605,7 @@ dependencies = [ "module-honzon", "module-idle-scheduler", "module-incentives", + "module-liquid-crowdloan", "module-loans", "module-nft", "module-nominees-election", diff --git a/runtime/acala/Cargo.toml b/runtime/acala/Cargo.toml index e5a0cf7aa1..f816b105ec 100644 --- a/runtime/acala/Cargo.toml +++ b/runtime/acala/Cargo.toml @@ -382,6 +382,7 @@ try-runtime = [ "module-transaction-pause/try-runtime", "module-transaction-payment/try-runtime", "module-xcm-interface/try-runtime", + "module-liquid-crowdloan/try-runtime", "primitives/try-runtime", diff --git a/runtime/acala/src/benchmarking/mod.rs b/runtime/acala/src/benchmarking/mod.rs index ffe02f5481..fe436e52a8 100644 --- a/runtime/acala/src/benchmarking/mod.rs +++ b/runtime/acala/src/benchmarking/mod.rs @@ -83,6 +83,9 @@ pub mod transaction_payment { pub mod session_manager { include!("../../../mandala/src/benchmarking/session_manager.rs"); } +pub mod liquid_crowdloan { + include!("../../../mandala/src/benchmarking/liquid_crowdloan.rs"); +} pub mod nutsfinance_stable_asset { include!("../../../mandala/src/benchmarking/nutsfinance_stable_asset.rs"); diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index a03b0a168f..37a610b202 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1526,8 +1526,6 @@ impl Convert for SubAccountIndexMultiLocationConvertor { parameter_types! { pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); - // Crowdloan vault address: `132zsjMwGjNaUXF5XjUCDs2cDEq9Qao51TsL9RSUTGZbinVK` - pub CrowdloanVault: AccountId = AccountId::from(hex_literal::hex!("59fe89295c2e57d7b4d4d8be9e00a3802e513703ab4b5b424ed0a646e899d3c9")); } impl module_xcm_interface::Config for Runtime { @@ -1655,6 +1653,11 @@ impl nutsfinance_stable_asset::Config for Runtime { type EnsurePoolAssetId = EnsurePoolAssetId; } +parameter_types!( + // Crowdloan vault address: `132zsjMwGjNaUXF5XjUCDs2cDEq9Qao51TsL9RSUTGZbinVK` + pub CrowdloanVault: AccountId = AccountId::from(hex_literal::hex!("59fe89295c2e57d7b4d4d8be9e00a3802e513703ab4b5b424ed0a646e899d3c9")); +); + impl module_liquid_crowdloan::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Currencies; @@ -1868,6 +1871,7 @@ mod benches { [nutsfinance_stable_asset, benchmarking::nutsfinance_stable_asset] [module_idle_scheduler, benchmarking::idle_scheduler] [module_aggregated_dex, benchmarking::aggregated_dex] + [module_liquid_crowdloan, benchmarking::liquid_crowdloan] ); } diff --git a/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs b/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs index 40bd026b0d..8c61e6bd84 100644 --- a/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs +++ b/runtime/integration-tests/src/relaychain/liquid_crowdloan.rs @@ -16,11 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::relaychain::fee_test::*; use crate::relaychain::polkadot_test_net::*; use crate::setup::*; -use frame_support::{assert_noop, assert_ok}; +use frame_support::assert_ok; use module_xcm_interface::XcmInterfaceOperation; use sp_runtime::traits::StaticLookup; use xcm_emulator::TestExt; @@ -39,9 +38,9 @@ fn transfer_from_crowdloan_vault_works() { let acala_sovereign_account: AccountId = ParaId::from(ACALA_PARA_ID).into_account_truncating(); PolkadotNet::execute_with(|| { - use polkadot_runtime::{Balances, Proxy, ProxyType, Runtime, RuntimeCall, RuntimeOrigin, XcmPallet}; + use polkadot_runtime::{Balances, Proxy, ProxyType, Runtime, RuntimeOrigin}; - Balances::deposit_creating(&vault, dollar(DOT) * 100); + let _ = Balances::deposit_creating(&vault, dollar(DOT) * 100); assert_ok!(Proxy::add_proxy( RuntimeOrigin::signed(vault.clone()), @@ -72,20 +71,6 @@ fn transfer_from_crowdloan_vault_works() { // None, // Box::new(call), // )); - - // assert_ok!(XcmPallet::reserve_transfer_assets( - // RuntimeOrigin::signed(vault), - // Box::new(Parachain(2000).into_versioned()), - // Box::new( - // Junction::AccountId32 { - // id: module_liquid_crowdloan_account.clone().into(), - // network: None - // } - // .into_versioned() - // ), - // Box::new((Here, dollar(DOT)).into()), - // 0 - // )); }); Acala::execute_with(|| { diff --git a/runtime/mandala/Cargo.toml b/runtime/mandala/Cargo.toml index 17ef81e1fe..85a204a3ad 100644 --- a/runtime/mandala/Cargo.toml +++ b/runtime/mandala/Cargo.toml @@ -124,6 +124,7 @@ module-session-manager = { path = "../../modules/session-manager", default-featu module-relaychain = { path = "../../modules/relaychain", default-features = false, features = ["polkadot"]} module-idle-scheduler = { path = "../../modules/idle-scheduler", default-features = false } module-aggregated-dex = { path = "../../modules/aggregated-dex", default-features = false } +module-liquid-crowdloan = { path = "../../modules/liquid-crowdloan", default-features = false } primitives = { package = "acala-primitives", path = "../../primitives", default-features = false } runtime-common = { path = "../common", default-features = false } @@ -269,6 +270,7 @@ std = [ "module-transaction-pause/std", "module-transaction-payment/std", "module-xcm-interface/std", + "module-liquid-crowdloan/std", "primitives/std", "runtime-common/std", @@ -418,6 +420,7 @@ try-runtime = [ "module-transaction-pause/try-runtime", "module-transaction-payment/try-runtime", "module-xcm-interface/try-runtime", + "module-liquid-crowdloan/try-runtime", "primitives/try-runtime", diff --git a/runtime/mandala/src/benchmarking/liquid_crowdloan.rs b/runtime/mandala/src/benchmarking/liquid_crowdloan.rs new file mode 100644 index 0000000000..4568aab771 --- /dev/null +++ b/runtime/mandala/src/benchmarking/liquid_crowdloan.rs @@ -0,0 +1,48 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2023 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::{AccountId, LiquidCrowdloan, Runtime}; + +use super::utils::{set_balance, LIQUID, STAKING}; +use frame_benchmarking::whitelisted_caller; +use frame_system::RawOrigin; +use orml_benchmarking::runtime_benchmarks; +use sp_std::prelude::*; + +runtime_benchmarks! { + { Runtime, module_liquid_crowdloan } + + redeem { + let caller: AccountId = whitelisted_caller(); + let amount = 100_000_000_000_000; + set_balance(LIQUID, &caller, amount); + set_balance(STAKING, &LiquidCrowdloan::account_id(), amount); + }: _(RawOrigin::Signed(caller), amount) + + transfer_from_crowdloan_vault { + }: _(RawOrigin::Root, 1) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::benchmarking::utils::tests::new_test_ext; + use orml_benchmarking::impl_benchmark_test_suite; + + impl_benchmark_test_suite!(new_test_ext(),); +} diff --git a/runtime/mandala/src/benchmarking/mod.rs b/runtime/mandala/src/benchmarking/mod.rs index 3692d9c9c0..ecc0ab1be1 100644 --- a/runtime/mandala/src/benchmarking/mod.rs +++ b/runtime/mandala/src/benchmarking/mod.rs @@ -43,6 +43,7 @@ pub mod homa; pub mod honzon; pub mod idle_scheduler; pub mod incentives; +pub mod liquid_crowdloan; pub mod nominees_election; pub mod nutsfinance_stable_asset; pub mod prices; diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 8c16210ae8..58567258ad 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -180,6 +180,7 @@ parameter_types! { // This Pallet is only used to payment fee pool, it's not added to whitelist by design. // because transaction payment pallet will ensure the accounts always have enough ED. pub const TransactionPaymentPalletId: PalletId = PalletId(*b"aca/fees"); + pub const LiquidCrowdloanPalletId: PalletId = PalletId(*b"aca/lqcl"); // Ecosystem modules pub const StableAssetPalletId: PalletId = PalletId(*b"nuts/sta"); // lock identifier for earning module @@ -1787,6 +1788,22 @@ impl module_idle_scheduler::Config for Runtime { impl cumulus_pallet_aura_ext::Config for Runtime {} +parameter_types!( + // Crowdloan vault address: `132zsjMwGjNaUXF5XjUCDs2cDEq9Qao51TsL9RSUTGZbinVK` + pub CrowdloanVault: AccountId = AccountId::from(hex_literal::hex!("59fe89295c2e57d7b4d4d8be9e00a3802e513703ab4b5b424ed0a646e899d3c9")); +); + +impl module_liquid_crowdloan::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Currencies; + type LiquidCrowdloanCurrencyId = GetLiquidCurrencyId; + type RelayChainCurrencyId = GetStakingCurrencyId; + type PalletId = LiquidCrowdloanPalletId; + type GovernanceOrigin = EnsureRootOrHalfGeneralCouncil; + type CrowdloanVault = CrowdloanVault; + type XcmTransfer = XcmInterface; +} + #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)] pub struct ConvertEthereumTx; @@ -2059,6 +2076,7 @@ construct_runtime!( Incentives: module_incentives = 140, NFT: module_nft = 141, AssetRegistry: module_asset_registry = 142, + LiquidCrowdloan: module_liquid_crowdloan = 143, // Ecosystem modules RenVmBridge: ecosystem_renvm_bridge = 150, @@ -2130,6 +2148,7 @@ mod benches { [module_evm_accounts, benchmarking::evm_accounts] [module_currencies, benchmarking::currencies] [module_session_manager, benchmarking::session_manager] + [module_liquid_crowdloan, benchmarking::liquid_crowdloan] [orml_tokens, benchmarking::tokens] [orml_vesting, benchmarking::vesting] [orml_auction, benchmarking::auction] From 2ae551b1801132e8e9e41f46181b74a8dc9c869a Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Fri, 14 Apr 2023 22:29:28 +1200 Subject: [PATCH 09/20] fix benchmarking tests --- modules/relaychain/src/lib.rs | 6 +++--- modules/xcm-interface/src/lib.rs | 2 +- runtime/mandala/src/benchmarking/liquid_crowdloan.rs | 12 ++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/relaychain/src/lib.rs b/modules/relaychain/src/lib.rs index ef9487bf8d..00818ca69b 100644 --- a/modules/relaychain/src/lib.rs +++ b/modules/relaychain/src/lib.rs @@ -246,9 +246,9 @@ impl> CallBuilder for RelayChainCallBuilder Self::RelayChainCall { RelayChainCall::XcmPallet(XcmCall::ReserveTransferAssets( - VersionedMultiLocation::V3(dest), - VersionedMultiLocation::V3(beneficiary), - VersionedMultiAssets::V3(assets), + dest.into_versioned(), + beneficiary.into_versioned(), + assets.into(), fee_assets_item, )) } diff --git a/modules/xcm-interface/src/lib.rs b/modules/xcm-interface/src/lib.rs index f1f81f8cda..d5322d0a02 100644 --- a/modules/xcm-interface/src/lib.rs +++ b/modules/xcm-interface/src/lib.rs @@ -312,7 +312,7 @@ pub mod module { let result = pallet_xcm::Pallet::::send_xcm(Here, Parent, xcm_message); log::debug!( target: "xcm-interface", - "Send {:?} DOT from crowdloan vault {:?} to {:?}, result: {:?}", + "Send {:?} planck DOT from crowdloan vault {:?} to {:?}, result: {:?}", amount, vault, recipient, result, ); diff --git a/runtime/mandala/src/benchmarking/liquid_crowdloan.rs b/runtime/mandala/src/benchmarking/liquid_crowdloan.rs index 4568aab771..0e26610404 100644 --- a/runtime/mandala/src/benchmarking/liquid_crowdloan.rs +++ b/runtime/mandala/src/benchmarking/liquid_crowdloan.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{AccountId, LiquidCrowdloan, Runtime}; +use crate::{AccountId, LiquidCrowdloan, PolkadotXcm, Runtime, RuntimeOrigin, System}; use super::utils::{set_balance, LIQUID, STAKING}; use frame_benchmarking::whitelisted_caller; @@ -33,9 +33,17 @@ runtime_benchmarks! { set_balance(LIQUID, &caller, amount); set_balance(STAKING, &LiquidCrowdloan::account_id(), amount); }: _(RawOrigin::Signed(caller), amount) + verify { + System::assert_last_event(module_liquid_crowdloan::Event::Redeemed { amount }.into()); + } transfer_from_crowdloan_vault { - }: _(RawOrigin::Root, 1) + PolkadotXcm::force_default_xcm_version(RuntimeOrigin::root(), Some(2)).unwrap(); + let amount = 1_000; + }: _(RawOrigin::Root, amount) + verify { + System::assert_last_event(module_liquid_crowdloan::Event::TransferFromCrowdloanVaultRequested { amount }.into()); + } } #[cfg(test)] From e87d11706d3aa0acbe1aec4bbe3e69b78bd33804 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Fri, 14 Apr 2023 22:32:01 +1200 Subject: [PATCH 10/20] docstring for proxytype --- modules/relaychain/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/relaychain/src/lib.rs b/modules/relaychain/src/lib.rs index 00818ca69b..3a03c251cb 100644 --- a/modules/relaychain/src/lib.rs +++ b/modules/relaychain/src/lib.rs @@ -87,7 +87,8 @@ pub type RelayChainLookup = AccountIdLookup; /// `pallet-proxy` calls. #[derive(Encode, Decode, RuntimeDebug)] pub enum ProxyCall { - /// `proxy(real, force_proxy_type, call)` call. + /// `proxy(real, force_proxy_type, call)` call. Force proxy type is not supported and + /// is always set to `None`. #[codec(index = 0)] Proxy(::Source, Option<()>, RelayChainCall), } From a5d926d10e40fdfaebd02b3a4dc33e964df33ba1 Mon Sep 17 00:00:00 2001 From: Acala Github Action Bot Date: Sat, 15 Apr 2023 01:31:28 +0000 Subject: [PATCH 11/20] /bench module module_liquid_crowdloan --- modules/liquid-crowdloan/src/weights.rs | 117 ++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 modules/liquid-crowdloan/src/weights.rs diff --git a/modules/liquid-crowdloan/src/weights.rs b/modules/liquid-crowdloan/src/weights.rs new file mode 100644 index 0000000000..ba2c1341ae --- /dev/null +++ b/modules/liquid-crowdloan/src/weights.rs @@ -0,0 +1,117 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2023 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for module_liquid_crowdloan +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-04-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `6adfd3d7e92a`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// target/release/acala +// benchmark +// pallet +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=module_liquid_crowdloan +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./modules/liquid-crowdloan/src/weights.rs +// --template=./templates/module-weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for module_liquid_crowdloan. +pub trait WeightInfo { + fn redeem() -> Weight; + fn transfer_from_crowdloan_vault() -> Weight; +} + +/// Weights for module_liquid_crowdloan using the Acala node and recommended hardware. +pub struct AcalaWeight(PhantomData); +impl WeightInfo for AcalaWeight { + // Storage: Tokens Accounts (r:3 w:3) + // Proof: Tokens Accounts (max_values: None, max_size: Some(147), added: 2622, mode: MaxEncodedLen) + // Storage: Tokens TotalIssuance (r:1 w:1) + // Proof: Tokens TotalIssuance (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + // Storage: EvmAccounts EvmAddresses (r:2 w:0) + // Proof: EvmAccounts EvmAddresses (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + // Storage: System Account (r:1 w:1) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn redeem() -> Weight { + // Minimum execution time: 108_353 nanoseconds. + Weight::from_ref_time(110_248_000) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(5)) + } + // Storage: XcmInterface XcmDestWeightAndFee (r:1 w:0) + // Proof Skipped: XcmInterface XcmDestWeightAndFee (max_values: None, max_size: None, mode: Measured) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + // Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + fn transfer_from_crowdloan_vault() -> Weight { + // Minimum execution time: 42_218 nanoseconds. + Weight::from_ref_time(43_024_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: Tokens Accounts (r:3 w:3) + // Proof: Tokens Accounts (max_values: None, max_size: Some(147), added: 2622, mode: MaxEncodedLen) + // Storage: Tokens TotalIssuance (r:1 w:1) + // Proof: Tokens TotalIssuance (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + // Storage: EvmAccounts EvmAddresses (r:2 w:0) + // Proof: EvmAccounts EvmAddresses (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + // Storage: System Account (r:1 w:1) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn redeem() -> Weight { + // Minimum execution time: 108_353 nanoseconds. + Weight::from_ref_time(110_248_000) + .saturating_add(RocksDbWeight::get().reads(7)) + .saturating_add(RocksDbWeight::get().writes(5)) + } + // Storage: XcmInterface XcmDestWeightAndFee (r:1 w:0) + // Proof Skipped: XcmInterface XcmDestWeightAndFee (max_values: None, max_size: None, mode: Measured) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + // Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + fn transfer_from_crowdloan_vault() -> Weight { + // Minimum execution time: 42_218 nanoseconds. + Weight::from_ref_time(43_024_000) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(1)) + } +} From aab01e99dadccf11b93d53e7a65351a6fc581cb2 Mon Sep 17 00:00:00 2001 From: Acala Github Action Bot Date: Sun, 16 Apr 2023 23:14:48 +0000 Subject: [PATCH 12/20] /bench runtime acala module_liquid_crowdloan --- .../src/weights/module_liquid_crowdloan.rs | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 runtime/acala/src/weights/module_liquid_crowdloan.rs diff --git a/runtime/acala/src/weights/module_liquid_crowdloan.rs b/runtime/acala/src/weights/module_liquid_crowdloan.rs new file mode 100644 index 0000000000..9dc3d3f07a --- /dev/null +++ b/runtime/acala/src/weights/module_liquid_crowdloan.rs @@ -0,0 +1,85 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2023 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for module_liquid_crowdloan +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-04-16, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `f742e4764e0a`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("acala-dev"), DB CACHE: 1024 + +// Executed Command: +// target/production/acala +// benchmark +// pallet +// --chain=acala-dev +// --steps=50 +// --repeat=20 +// --pallet=module_liquid_crowdloan +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --template=./templates/runtime-weight-template.hbs +// --output=./runtime/acala/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for module_liquid_crowdloan. +pub struct WeightInfo(PhantomData); +impl module_liquid_crowdloan::WeightInfo for WeightInfo { + // Storage: Tokens Accounts (r:3 w:3) + // Proof: Tokens Accounts (max_values: None, max_size: Some(147), added: 2622, mode: MaxEncodedLen) + // Storage: Tokens TotalIssuance (r:1 w:1) + // Proof: Tokens TotalIssuance (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + // Storage: EvmAccounts EvmAddresses (r:2 w:0) + // Proof: EvmAccounts EvmAddresses (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + // Storage: System Account (r:1 w:1) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn redeem() -> Weight { + // Minimum execution time: 74_075 nanoseconds. + Weight::from_ref_time(75_261_000) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(5)) + } + // Storage: XcmInterface XcmDestWeightAndFee (r:1 w:0) + // Proof Skipped: XcmInterface XcmDestWeightAndFee (max_values: None, max_size: None, mode: Measured) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + // Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + fn transfer_from_crowdloan_vault() -> Weight { + // Minimum execution time: 54_143 nanoseconds. + Weight::from_ref_time(55_589_000) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} From 327037aef4fb32f299e8a676a0cd1840515a73e6 Mon Sep 17 00:00:00 2001 From: Acala Github Action Bot Date: Mon, 17 Apr 2023 00:53:09 +0000 Subject: [PATCH 13/20] /bench runtime mandala module_liquid_crowdloan --- .../src/weights/module_liquid_crowdloan.rs | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 runtime/mandala/src/weights/module_liquid_crowdloan.rs diff --git a/runtime/mandala/src/weights/module_liquid_crowdloan.rs b/runtime/mandala/src/weights/module_liquid_crowdloan.rs new file mode 100644 index 0000000000..2ca7f8a916 --- /dev/null +++ b/runtime/mandala/src/weights/module_liquid_crowdloan.rs @@ -0,0 +1,79 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2023 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for module_liquid_crowdloan +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-04-17, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `a77f8711699c`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// target/production/acala +// benchmark +// pallet +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=module_liquid_crowdloan +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --template=./templates/runtime-weight-template.hbs +// --output=./runtime/mandala/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for module_liquid_crowdloan. +pub struct WeightInfo(PhantomData); +impl module_liquid_crowdloan::WeightInfo for WeightInfo { + // Storage: Tokens Accounts (r:3 w:3) + // Proof: Tokens Accounts (max_values: None, max_size: Some(147), added: 2622, mode: MaxEncodedLen) + // Storage: Tokens TotalIssuance (r:1 w:1) + // Proof: Tokens TotalIssuance (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + // Storage: EvmAccounts EvmAddresses (r:2 w:0) + // Proof: EvmAccounts EvmAddresses (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + // Storage: System Account (r:1 w:1) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn redeem() -> Weight { + // Minimum execution time: 79_203 nanoseconds. + Weight::from_ref_time(81_499_000) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(5)) + } + // Storage: XcmInterface XcmDestWeightAndFee (r:1 w:0) + // Proof Skipped: XcmInterface XcmDestWeightAndFee (max_values: None, max_size: None, mode: Measured) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + // Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + fn transfer_from_crowdloan_vault() -> Weight { + // Minimum execution time: 30_495 nanoseconds. + Weight::from_ref_time(30_989_000) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} From 5b24173cd5365ed3807e51131cb8bcb93f744046 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Mon, 17 Apr 2023 13:57:59 +1200 Subject: [PATCH 14/20] add weight info --- Cargo.lock | 1 + modules/liquid-crowdloan/Cargo.toml | 2 ++ modules/liquid-crowdloan/src/lib.rs | 9 +++++++-- modules/liquid-crowdloan/src/mock.rs | 1 + runtime/acala/src/lib.rs | 1 + runtime/acala/src/weights/mod.rs | 1 + runtime/mandala/src/lib.rs | 1 + runtime/mandala/src/weights/mod.rs | 1 + 8 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd6f46858b..93618c04b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6424,6 +6424,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", + "sp-std", ] [[package]] diff --git a/modules/liquid-crowdloan/Cargo.toml b/modules/liquid-crowdloan/Cargo.toml index 14080b28dc..1737479b09 100644 --- a/modules/liquid-crowdloan/Cargo.toml +++ b/modules/liquid-crowdloan/Cargo.toml @@ -9,6 +9,7 @@ scale-info = { version = "2.2.0", default-features = false, features = ["derive" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false } @@ -29,6 +30,7 @@ std = [ "codec/std", "scale-info/std", "sp-runtime/std", + "sp-std/std", "frame-support/std", "frame-system/std", "orml-traits/std", diff --git a/modules/liquid-crowdloan/src/lib.rs b/modules/liquid-crowdloan/src/lib.rs index d80a85f56c..afff520130 100644 --- a/modules/liquid-crowdloan/src/lib.rs +++ b/modules/liquid-crowdloan/src/lib.rs @@ -33,8 +33,10 @@ use support::CrowdloanVaultXcm; mod mock; mod tests; +pub mod weights; pub use module::*; +pub use weights::WeightInfo; #[frame_support::pallet] pub mod module { @@ -68,6 +70,9 @@ pub mod module { /// XCM transfer impl. type XcmTransfer: CrowdloanVaultXcm; + + /// Weight information for the extrinsics in this module. + type WeightInfo: WeightInfo; } #[pallet::event] @@ -85,7 +90,7 @@ pub mod module { impl Pallet { /// Redeem liquid crowdloan currency for relay chain currency. #[pallet::call_index(0)] - #[pallet::weight(0)] + #[pallet::weight(::WeightInfo::redeem())] pub fn redeem(origin: OriginFor, #[pallet::compact] amount: Balance) -> DispatchResult { let who = ensure_signed(origin)?; @@ -103,7 +108,7 @@ pub mod module { /// /// This call requires `GovernanceOrigin`. #[pallet::call_index(1)] - #[pallet::weight(0)] + #[pallet::weight(::WeightInfo::transfer_from_crowdloan_vault())] pub fn transfer_from_crowdloan_vault( origin: OriginFor, #[pallet::compact] amount: Balance, diff --git a/modules/liquid-crowdloan/src/mock.rs b/modules/liquid-crowdloan/src/mock.rs index 231597253a..0c506eb458 100644 --- a/modules/liquid-crowdloan/src/mock.rs +++ b/modules/liquid-crowdloan/src/mock.rs @@ -164,6 +164,7 @@ impl liquid_crowdloan::Config for Runtime { type GovernanceOrigin = EnsureSignedBy; type CrowdloanVault = CrowdloanVault; type XcmTransfer = MockXcmTransfer; + type WeightInfo = (); } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 37a610b202..fad8ec0ae9 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1667,6 +1667,7 @@ impl module_liquid_crowdloan::Config for Runtime { type GovernanceOrigin = EnsureRootOrHalfGeneralCouncil; type CrowdloanVault = CrowdloanVault; type XcmTransfer = XcmInterface; + type WeightInfo = weights::module_liquid_crowdloan::WeightInfo; } construct_runtime!( diff --git a/runtime/acala/src/weights/mod.rs b/runtime/acala/src/weights/mod.rs index 21e9d526f3..34f40f4322 100644 --- a/runtime/acala/src/weights/mod.rs +++ b/runtime/acala/src/weights/mod.rs @@ -34,6 +34,7 @@ pub mod module_evm_accounts; pub mod module_homa; pub mod module_honzon; pub mod module_incentives; +pub mod module_liquid_crowdloan; pub mod module_nft; pub mod module_prices; pub mod module_session_manager; diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 58567258ad..3aa73d47e9 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1802,6 +1802,7 @@ impl module_liquid_crowdloan::Config for Runtime { type GovernanceOrigin = EnsureRootOrHalfGeneralCouncil; type CrowdloanVault = CrowdloanVault; type XcmTransfer = XcmInterface; + type WeightInfo = weights::module_liquid_crowdloan::WeightInfo; } #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)] diff --git a/runtime/mandala/src/weights/mod.rs b/runtime/mandala/src/weights/mod.rs index ad441a23fe..204071158c 100644 --- a/runtime/mandala/src/weights/mod.rs +++ b/runtime/mandala/src/weights/mod.rs @@ -36,6 +36,7 @@ pub mod module_homa; pub mod module_honzon; pub mod module_idle_scheduler; pub mod module_incentives; +pub mod module_liquid_crowdloan; pub mod module_nft; pub mod module_nominees_election; pub mod module_prices; From 052aa64f75c0b0dfae2f1bdfff8670cbda6bd961 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Mon, 17 Apr 2023 14:35:17 +1200 Subject: [PATCH 15/20] fix --- modules/liquid-crowdloan/src/lib.rs | 2 +- runtime/acala/src/lib.rs | 3 ++- runtime/mandala/src/benchmarking/liquid_crowdloan.rs | 6 +++--- runtime/mandala/src/lib.rs | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/liquid-crowdloan/src/lib.rs b/modules/liquid-crowdloan/src/lib.rs index afff520130..bff0b64fd3 100644 --- a/modules/liquid-crowdloan/src/lib.rs +++ b/modules/liquid-crowdloan/src/lib.rs @@ -104,7 +104,7 @@ pub mod module { } /// Send an XCM message to cross-chain transfer DOT from relay chain crowdloan vault to - /// liquid crowdloan module account. + /// liquid crowdloan module account. /// /// This call requires `GovernanceOrigin`. #[pallet::call_index(1)] diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index fad8ec0ae9..6ca717a8b1 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1656,12 +1656,13 @@ impl nutsfinance_stable_asset::Config for Runtime { parameter_types!( // Crowdloan vault address: `132zsjMwGjNaUXF5XjUCDs2cDEq9Qao51TsL9RSUTGZbinVK` pub CrowdloanVault: AccountId = AccountId::from(hex_literal::hex!("59fe89295c2e57d7b4d4d8be9e00a3802e513703ab4b5b424ed0a646e899d3c9")); + pub const LiquidCrowdloanCurrencyId: CurrencyId = LCDOT; ); impl module_liquid_crowdloan::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Currencies; - type LiquidCrowdloanCurrencyId = GetLiquidCurrencyId; + type LiquidCrowdloanCurrencyId = LiquidCrowdloanCurrencyId; type RelayChainCurrencyId = GetStakingCurrencyId; type PalletId = LiquidCrowdloanPalletId; type GovernanceOrigin = EnsureRootOrHalfGeneralCouncil; diff --git a/runtime/mandala/src/benchmarking/liquid_crowdloan.rs b/runtime/mandala/src/benchmarking/liquid_crowdloan.rs index 0e26610404..7b7017dee3 100644 --- a/runtime/mandala/src/benchmarking/liquid_crowdloan.rs +++ b/runtime/mandala/src/benchmarking/liquid_crowdloan.rs @@ -16,9 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{AccountId, LiquidCrowdloan, PolkadotXcm, Runtime, RuntimeOrigin, System}; +use crate::{AccountId, LiquidCrowdloan, LiquidCrowdloanCurrencyId, PolkadotXcm, Runtime, RuntimeOrigin, System}; -use super::utils::{set_balance, LIQUID, STAKING}; +use super::utils::{set_balance, STAKING}; use frame_benchmarking::whitelisted_caller; use frame_system::RawOrigin; use orml_benchmarking::runtime_benchmarks; @@ -30,7 +30,7 @@ runtime_benchmarks! { redeem { let caller: AccountId = whitelisted_caller(); let amount = 100_000_000_000_000; - set_balance(LIQUID, &caller, amount); + set_balance(LiquidCrowdloanCurrencyId::get(), &caller, amount); set_balance(STAKING, &LiquidCrowdloan::account_id(), amount); }: _(RawOrigin::Signed(caller), amount) verify { diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 3aa73d47e9..063fd7a6e7 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -113,7 +113,7 @@ pub use runtime_common::{ GeneralCouncilInstance, GeneralCouncilMembershipInstance, HomaCouncilInstance, HomaCouncilMembershipInstance, MaxTipsOfPriority, OffchainSolutionWeightLimit, OperationalFeeMultiplier, OperatorMembershipInstanceAcala, Price, ProxyType, Rate, Ratio, RuntimeBlockLength, RuntimeBlockWeights, SystemContractsFilter, TechnicalCommitteeInstance, - TechnicalCommitteeMembershipInstance, TimeStampedPrice, TipPerWeightStep, ACA, AUSD, DOT, KSM, LDOT, RENBTC, + TechnicalCommitteeMembershipInstance, TimeStampedPrice, TipPerWeightStep, ACA, AUSD, DOT, KSM, LCDOT, LDOT, RENBTC, }; pub use xcm::{prelude::*, v3::Weight as XcmWeight}; @@ -1791,12 +1791,13 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} parameter_types!( // Crowdloan vault address: `132zsjMwGjNaUXF5XjUCDs2cDEq9Qao51TsL9RSUTGZbinVK` pub CrowdloanVault: AccountId = AccountId::from(hex_literal::hex!("59fe89295c2e57d7b4d4d8be9e00a3802e513703ab4b5b424ed0a646e899d3c9")); + pub const LiquidCrowdloanCurrencyId: CurrencyId = LCDOT; ); impl module_liquid_crowdloan::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Currencies; - type LiquidCrowdloanCurrencyId = GetLiquidCurrencyId; + type LiquidCrowdloanCurrencyId = LiquidCrowdloanCurrencyId; type RelayChainCurrencyId = GetStakingCurrencyId; type PalletId = LiquidCrowdloanPalletId; type GovernanceOrigin = EnsureRootOrHalfGeneralCouncil; From 590e47fc38395b26e1ac5270966937ca4751de6a Mon Sep 17 00:00:00 2001 From: Acala Github Action Bot Date: Fri, 2 Jun 2023 01:42:14 +0000 Subject: [PATCH 16/20] /bench module module_liquid_crowdloan --- modules/liquid-crowdloan/src/weights.rs | 32 +++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/modules/liquid-crowdloan/src/weights.rs b/modules/liquid-crowdloan/src/weights.rs index 5e8e098794..118e470fff 100644 --- a/modules/liquid-crowdloan/src/weights.rs +++ b/modules/liquid-crowdloan/src/weights.rs @@ -19,8 +19,8 @@ //! Autogenerated weights for module_liquid_crowdloan //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `6adfd3d7e92a`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! DATE: 2023-06-02, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `ip-172-31-40-233`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -63,8 +63,11 @@ impl WeightInfo for AcalaWeight { // Storage: System Account (r:1 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn redeem() -> Weight { - // Minimum execution time: 108_353 nanoseconds. - Weight::from_parts(110_248_000, 0) + // Proof Size summary in bytes: + // Measured: `2927` + // Estimated: `22041` + // Minimum execution time: 125_572 nanoseconds. + Weight::from_parts(128_915_000, 22041) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(5)) } @@ -77,8 +80,11 @@ impl WeightInfo for AcalaWeight { // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) // Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) fn transfer_from_crowdloan_vault() -> Weight { - // Minimum execution time: 42_218 nanoseconds. - Weight::from_parts(43_024_000, 0) + // Proof Size summary in bytes: + // Measured: `1255` + // Estimated: `11689` + // Minimum execution time: 46_004 nanoseconds. + Weight::from_parts(46_711_000, 11689) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -95,8 +101,11 @@ impl WeightInfo for () { // Storage: System Account (r:1 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn redeem() -> Weight { - // Minimum execution time: 108_353 nanoseconds. - Weight::from_parts(110_248_000, 0) + // Proof Size summary in bytes: + // Measured: `2927` + // Estimated: `22041` + // Minimum execution time: 125_572 nanoseconds. + Weight::from_parts(128_915_000, 22041) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(5)) } @@ -109,8 +118,11 @@ impl WeightInfo for () { // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) // Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) fn transfer_from_crowdloan_vault() -> Weight { - // Minimum execution time: 42_218 nanoseconds. - Weight::from_parts(43_024_000, 0) + // Proof Size summary in bytes: + // Measured: `1255` + // Estimated: `11689` + // Minimum execution time: 46_004 nanoseconds. + Weight::from_parts(46_711_000, 11689) .saturating_add(RocksDbWeight::get().reads(4)) .saturating_add(RocksDbWeight::get().writes(1)) } From 02543112c5fd20080d41ebc08c4b782d66ad9529 Mon Sep 17 00:00:00 2001 From: Acala Github Action Bot Date: Fri, 2 Jun 2023 03:04:17 +0000 Subject: [PATCH 17/20] /bench runtime mandala module_liquid_crowdloan --- .../src/weights/module_liquid_crowdloan.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/runtime/mandala/src/weights/module_liquid_crowdloan.rs b/runtime/mandala/src/weights/module_liquid_crowdloan.rs index 6f304faeeb..c5d5cc3491 100644 --- a/runtime/mandala/src/weights/module_liquid_crowdloan.rs +++ b/runtime/mandala/src/weights/module_liquid_crowdloan.rs @@ -19,8 +19,8 @@ //! Autogenerated weights for module_liquid_crowdloan //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-17, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `a77f8711699c`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! DATE: 2023-06-02, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `ip-172-31-35-142`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -57,8 +57,11 @@ impl module_liquid_crowdloan::WeightInfo for WeightInfo // Storage: System Account (r:1 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn redeem() -> Weight { - // Minimum execution time: 79_203 nanoseconds. - Weight::from_parts(81_499_000, 0) + // Proof Size summary in bytes: + // Measured: `2927` + // Estimated: `22041` + // Minimum execution time: 86_706 nanoseconds. + Weight::from_parts(88_388_000, 22041) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(5)) } @@ -71,8 +74,11 @@ impl module_liquid_crowdloan::WeightInfo for WeightInfo // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) // Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) fn transfer_from_crowdloan_vault() -> Weight { - // Minimum execution time: 30_495 nanoseconds. - Weight::from_parts(30_989_000, 0) + // Proof Size summary in bytes: + // Measured: `1255` + // Estimated: `11689` + // Minimum execution time: 32_468 nanoseconds. + Weight::from_parts(33_256_000, 11689) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) } From 6607dd5d76afadd06f710cd4c4cbd0d18ef0b218 Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Fri, 2 Jun 2023 15:49:18 +1200 Subject: [PATCH 18/20] Update modules/liquid-crowdloan/src/lib.rs --- modules/liquid-crowdloan/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/liquid-crowdloan/src/lib.rs b/modules/liquid-crowdloan/src/lib.rs index bff0b64fd3..f4b367ffe7 100644 --- a/modules/liquid-crowdloan/src/lib.rs +++ b/modules/liquid-crowdloan/src/lib.rs @@ -48,7 +48,7 @@ pub mod module { type Currency: MultiCurrency; - /// Liquid crowdloan currency Id, i.e. LDOT for Polkadot. + /// Liquid crowdloan currency Id, i.e. LCDOT for Polkadot. #[pallet::constant] type LiquidCrowdloanCurrencyId: Get; From a12a9e6b5b19353f76ebedbb700838fcf7bb9677 Mon Sep 17 00:00:00 2001 From: Acala Github Action Bot Date: Fri, 2 Jun 2023 23:35:00 +0000 Subject: [PATCH 19/20] /bench runtime acala module_liquid_crowdloan --- .../src/weights/module_liquid_crowdloan.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/runtime/acala/src/weights/module_liquid_crowdloan.rs b/runtime/acala/src/weights/module_liquid_crowdloan.rs index f2bc545af1..6d97f9ea05 100644 --- a/runtime/acala/src/weights/module_liquid_crowdloan.rs +++ b/runtime/acala/src/weights/module_liquid_crowdloan.rs @@ -19,8 +19,8 @@ //! Autogenerated weights for module_liquid_crowdloan //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-04-16, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `f742e4764e0a`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! DATE: 2023-06-02, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `ip-172-31-34-64`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("acala-dev"), DB CACHE: 1024 // Executed Command: @@ -57,8 +57,11 @@ impl module_liquid_crowdloan::WeightInfo for WeightInfo // Storage: System Account (r:1 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn redeem() -> Weight { - // Minimum execution time: 74_075 nanoseconds. - Weight::from_parts(75_261_000, 0) + // Proof Size summary in bytes: + // Measured: `1883` + // Estimated: `22041` + // Minimum execution time: 84_404 nanoseconds. + Weight::from_parts(86_781_000, 22041) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(5)) } @@ -77,8 +80,11 @@ impl module_liquid_crowdloan::WeightInfo for WeightInfo // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) // Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) fn transfer_from_crowdloan_vault() -> Weight { - // Minimum execution time: 54_143 nanoseconds. - Weight::from_parts(55_589_000, 0) + // Proof Size summary in bytes: + // Measured: `1392` + // Estimated: `22711` + // Minimum execution time: 56_316 nanoseconds. + Weight::from_parts(57_458_000, 22711) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(2)) } From b04af37d8a6db6497c4a7d6aaa03f130c296cc33 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Sun, 4 Jun 2023 18:28:29 +1200 Subject: [PATCH 20/20] trigger CI