From 5006f48e50dcc222aca2b11303f30fa827dce973 Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Tue, 12 Sep 2023 17:28:56 +0400 Subject: [PATCH 1/2] Remove `pallet-airdrop` --- Cargo.lock | 32 --- Cargo.toml | 1 - gsdk/src/metadata/errors.rs | 1 - pallets/airdrop/Cargo.toml | 70 ------ pallets/airdrop/README.md | 7 - pallets/airdrop/src/benchmarking.rs | 70 ------ pallets/airdrop/src/lib.rs | 214 ------------------ pallets/airdrop/src/mock.rs | 247 --------------------- pallets/airdrop/src/tests.rs | 173 --------------- pallets/airdrop/src/weights.rs | 95 -------- runtime/vara/Cargo.toml | 4 - runtime/vara/src/lib.rs | 13 +- runtime/vara/src/weights/mod.rs | 1 - runtime/vara/src/weights/pallet_airdrop.rs | 95 -------- 14 files changed, 2 insertions(+), 1021 deletions(-) delete mode 100644 pallets/airdrop/Cargo.toml delete mode 100644 pallets/airdrop/README.md delete mode 100644 pallets/airdrop/src/benchmarking.rs delete mode 100644 pallets/airdrop/src/lib.rs delete mode 100644 pallets/airdrop/src/mock.rs delete mode 100644 pallets/airdrop/src/tests.rs delete mode 100644 pallets/airdrop/src/weights.rs delete mode 100644 runtime/vara/src/weights/pallet_airdrop.rs diff --git a/Cargo.lock b/Cargo.lock index 32ac68ad265..f51d1120230 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7118,37 +7118,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "pallet-airdrop" -version = "1.0.0" -dependencies = [ - "env_logger", - "frame-benchmarking", - "frame-support", - "frame-support-test", - "frame-system", - "gear-common", - "log", - "pallet-authorship", - "pallet-balances", - "pallet-gear", - "pallet-gear-bank", - "pallet-gear-gas", - "pallet-gear-messenger", - "pallet-gear-program", - "pallet-gear-scheduler", - "pallet-sudo", - "pallet-timestamp", - "pallet-vesting", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core 7.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", - "sp-io 7.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", - "sp-runtime 7.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", - "sp-std 5.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v0.9.41-canary-no-sandbox)", -] - [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" @@ -13511,7 +13480,6 @@ dependencies = [ "gear-runtime-primitives", "hex-literal", "log", - "pallet-airdrop", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", diff --git a/Cargo.toml b/Cargo.toml index f3d587003ee..108d5011b92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -221,7 +221,6 @@ gear-wasm-gen = { path = "utils/wasm-gen" } gear-wasm-instrument = { path = "utils/wasm-instrument", default-features = false } junit-common = { path = "utils/junit-common" } actor-system-error = { path = "utils/actor-system-error" } -pallet-airdrop = { path = "pallets/airdrop", default-features = false } pallet-gear = { path = "pallets/gear", default-features = false } pallet-gear-debug = { path = "pallets/gear-debug", default-features = false } pallet-gear-gas = { path = "pallets/gas", default-features = false } diff --git a/gsdk/src/metadata/errors.rs b/gsdk/src/metadata/errors.rs index fef6f00d76e..bfbd006d5a9 100644 --- a/gsdk/src/metadata/errors.rs +++ b/gsdk/src/metadata/errors.rs @@ -94,7 +94,6 @@ macro_rules! export_module_error { // pallets that don't have `Error` type. // // - pallet_transaction_payment -// - pallet_airdrop // // pallets that share the same `errors::RankedCollective` // diff --git a/pallets/airdrop/Cargo.toml b/pallets/airdrop/Cargo.toml deleted file mode 100644 index 35f74034b41..00000000000 --- a/pallets/airdrop/Cargo.toml +++ /dev/null @@ -1,70 +0,0 @@ -[package] -name = "pallet-airdrop" -version = "1.0.0" -authors = ['Gear Technologies'] -edition = '2021' -license.workspace = true -homepage = "https://gear-tech.io" -repository = "https://github.com/gear-tech/gear" -description = "Airdrop pallet" -readme = "README.md" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -parity-scale-codec = { workspace = true, features = ["derive", "max-encoded-len"] } -scale-info = { workspace = true, features = ["derive"] } -log.workspace = true - -# Internal deps -common.workspace = true -pallet-gear.workspace = true -pallet-gear-bank.workspace = true - -# Substrate deps -frame-support.workspace = true -frame-system.workspace = true -frame-benchmarking = { workspace = true, optional = true } -sp-runtime.workspace = true -sp-std.workspace = true -pallet-balances.workspace = true -pallet-vesting.workspace = true - -[dev-dependencies] -serde.workspace = true -env_logger.workspace = true -sp-core = { workspace = true, features = ["std"] } -sp-io = { workspace = true, features = ["std"] } -pallet-authorship = { workspace = true, features = ["std"] } -pallet-sudo = { workspace = true, features = ["std"] } -pallet-timestamp = { workspace = true, features = ["std"] } -pallet-gear-program = { workspace = true, features = ["std"] } -pallet-gear-messenger = { workspace = true, features = ["std"] } -pallet-gear-scheduler = { workspace = true, features = ["std"] } -pallet-gear-gas = { workspace = true, features = ["std"] } -frame-support-test = { workspace = true, features = ["std"] } - -[features] -default = ["std"] -std = [ - "common/std", - "parity-scale-codec/std", - "log/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "scale-info/std", - "sp-std/std", - "pallet-balances/std", - "pallet-vesting/std", - "pallet-gear/std", - "pallet-gear-bank/std", -] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "common/runtime-benchmarks", -] -try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/airdrop/README.md b/pallets/airdrop/README.md deleted file mode 100644 index 3f75afc1b5b..00000000000 --- a/pallets/airdrop/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Airdrop pallet used on testnet to dispense funds to users - -A crate which provides a mechanism to transfer tokens from pre-funded account to users while generic balance transfers are disabled. - -### Dispatchable Functions - -License: Unlicense diff --git a/pallets/airdrop/src/benchmarking.rs b/pallets/airdrop/src/benchmarking.rs deleted file mode 100644 index 68064fca290..00000000000 --- a/pallets/airdrop/src/benchmarking.rs +++ /dev/null @@ -1,70 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2022-2023 Gear Technologies Inc. -// 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 . - -#[allow(unused)] -use crate::Pallet as Airdrop; -use crate::*; -use common::{benchmarking, Origin}; -use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; -use frame_support::traits::Currency; -use frame_system::RawOrigin; -use pallet_vesting::VestingInfo; -use sp_runtime::traits::{StaticLookup, UniqueSaturatedInto}; - -benchmarks! { - where_clause { where - T::AccountId: Origin, - } - - transfer { - let q in 1 .. 256; - - let source: T::AccountId = benchmarking::account("source", 0, 0); - ::Currency::deposit_creating(&source, (1u128 << 60).unique_saturated_into()); - let recipient: T::AccountId = benchmarking::account("recipient", 0, 0); - // Keeping in mind the existential deposit - let amount = 10_000_000_000_000_u128.saturating_add(10_u128.saturating_mul(q.into())); - - }: _(RawOrigin::Root, source, recipient.clone(), amount.unique_saturated_into()) - verify { - assert_eq!(pallet_balances::Pallet::::total_balance(&recipient), amount.unique_saturated_into()); - } - - transfer_vested { - let q in 1 .. 256; - - let source: T::AccountId = benchmarking::account("source", 0, 0); - let source_lookup = T::Lookup::unlookup(source.clone()); - ::Currency::deposit_creating(&source, (1u128 << 60).unique_saturated_into()); - let recipient: T::AccountId = benchmarking::account("recipient", 0, 0); - let amount = ::MinVestedTransfer::get().saturating_mul(q.into()); - - // create vesting schedule amount * 2 - let vested_amount = amount.saturating_mul(2u128.unique_saturated_into()); - let vesting_schedule = VestingInfo::new(vested_amount.unique_saturated_into(), 10u128.unique_saturated_into(), 1000u32.into()); - pallet_vesting::Pallet::::vested_transfer(RawOrigin::Signed(source.clone()).into(), source_lookup, vesting_schedule)?; - - }: _(RawOrigin::Root, source.clone(), recipient.clone(), 0, Some(amount)) - verify { - // check that the total vested amount is halved between the source and the recipient - assert_eq!(pallet_vesting::Pallet::::vesting_balance(&source), Some(amount)); - assert_eq!(::Currency::free_balance(&recipient), amount); - } -} - -impl_benchmark_test_suite!(Airdrop, crate::mock::new_test_ext(), crate::mock::Test,); diff --git a/pallets/airdrop/src/lib.rs b/pallets/airdrop/src/lib.rs deleted file mode 100644 index 7609271c50e..00000000000 --- a/pallets/airdrop/src/lib.rs +++ /dev/null @@ -1,214 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2021-2023 Gear Technologies Inc. -// 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 . - -#![cfg_attr(not(feature = "std"), no_std)] - -use frame_support::{ - pallet_prelude::*, - traits::{Currency, ExistenceRequirement, VestingSchedule}, -}; -pub use pallet::*; -use sp_runtime::traits::{Convert, Saturating}; -pub use weights::WeightInfo; - -pub mod weights; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - -#[cfg(test)] -mod mock; - -#[cfg(test)] -mod tests; - -pub(crate) type BalanceOf = <::Currency as Currency< - ::AccountId, ->>::Balance; - -pub(crate) type VestingBalanceOf = <::Currency as Currency< - ::AccountId, ->>::Balance; - -#[frame_support::pallet] -pub mod pallet { - use super::*; - - use frame_system::pallet_prelude::*; - - #[pallet::config] - pub trait Config: - frame_system::Config - + pallet_gear::Config - + pallet_balances::Config - + pallet_vesting::Config - { - /// Because this pallet emits events, it depends on the runtime's definition of an event. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; - - /// To modify/remove vesting schedule - type VestingSchedule: VestingSchedule< - Self::AccountId, - Currency = ::Currency, - Moment = Self::BlockNumber, - >; - } - - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - TokensDeposited { - account: T::AccountId, - amount: BalanceOf, - }, - VestingScheduleRemoved { - who: T::AccountId, - schedule_index: u32, - }, - } - - /// Error for the airdrop pallet. - #[pallet::error] - pub enum Error { - /// Amount to being transferred is bigger than vested. - AmountBigger, - } - - #[pallet::call] - impl Pallet { - /// Transfer tokens from pre-funded `source` to `dest` account. - /// - /// The origin must be the root. - /// - /// Parameters: - /// - `source`: the pre-funded account (i.e. root), - /// - `dest`: the beneficiary account, - /// - `amount`: the amount of tokens to be minted. - /// - /// Emits the following events: - /// - `TokensDeposited{ dest, amount }` - #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::transfer(1))] - pub fn transfer( - origin: OriginFor, - source: T::AccountId, - dest: T::AccountId, - amount: BalanceOf, - ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - - <::Currency as Currency<_>>::transfer( - &source, - &dest, - amount, - ExistenceRequirement::KeepAlive, - )?; - Self::deposit_event(Event::TokensDeposited { - account: dest, - amount, - }); - - // This extrinsic is not chargeable - Ok(Pays::No.into()) - } - - /// Remove vesting for `source` account and transfer tokens to `dest` account. - /// - /// The origin must be the root. - /// - /// Parameters: - /// - `source`: the account with vesting running, - /// - `dest`: the beneficiary account, - /// - `schedule_index`: the index of `VestingInfo` for source account. - /// - `amount`: the amount to be unlocked and transferred from `VestingInfo`. - /// - /// Emits the following events: - /// - `VestingScheduleRemoved{ who, schedule_index }` - #[pallet::call_index(1)] - #[pallet::weight(::WeightInfo::transfer_vested(1))] - pub fn transfer_vested( - origin: OriginFor, - source: T::AccountId, - dest: T::AccountId, - schedule_index: u32, - amount: Option>, - ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - - let schedules = pallet_vesting::Pallet::::vesting(&source) - .ok_or(pallet_vesting::Error::::NotVesting)?; - - let schedule = schedules - .get(schedule_index as usize) - .ok_or(pallet_vesting::Error::::ScheduleIndexOutOfBounds)?; - - T::VestingSchedule::remove_vesting_schedule(&source, schedule_index)?; - - Self::deposit_event(Event::VestingScheduleRemoved { - who: source.clone(), - schedule_index, - }); - - let amount = if let Some(amount) = amount { - ensure!(amount <= schedule.locked(), Error::::AmountBigger); - let end_amount = schedule.locked().saturating_sub(amount); - let end_block = schedule.ending_block_as_balance::(); - let start_block = T::BlockNumberToBalance::convert(schedule.starting_block()); - let per_block = end_amount / end_block.saturating_sub(start_block); - - T::VestingSchedule::can_add_vesting_schedule( - &source, - end_amount, - per_block, - schedule.starting_block(), - )?; - let res = T::VestingSchedule::add_vesting_schedule( - &source, - end_amount, - per_block, - schedule.starting_block(), - ); - - debug_assert!( - res.is_ok(), - "Failed to add a schedule when we had to succeed." - ); - - amount - } else { - schedule.locked() - }; - - <::Currency as Currency<_>>::transfer( - &source, - &dest, - amount, - ExistenceRequirement::AllowDeath, - )?; - - // This extrinsic is not chargeable - Ok(Pays::No.into()) - } - } -} diff --git a/pallets/airdrop/src/mock.rs b/pallets/airdrop/src/mock.rs deleted file mode 100644 index 6e4f334f9f2..00000000000 --- a/pallets/airdrop/src/mock.rs +++ /dev/null @@ -1,247 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2021-2023 Gear Technologies Inc. -// 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 as pallet_airdrop; -use frame_support::{ - construct_runtime, parameter_types, - traits::{ConstU64, GenesisBuild, WithdrawReasons}, -}; -use frame_support_test::TestRandomness; -use frame_system as system; -use sp_core::ConstBool; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, ConvertInto, IdentityLookup}, -}; -use sp_std::convert::{TryFrom, TryInto}; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; -type AccountId = u64; -type BlockNumber = u64; -type Balance = u128; - -pub const ALICE: AccountId = 1; -pub const BOB: AccountId = 2; -pub const ROOT: AccountId = 255; - -// Configure a mock runtime to test the pallet. -construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: system, - Balances: pallet_balances, - Sudo: pallet_sudo, - Authorship: pallet_authorship, - Timestamp: pallet_timestamp, - GearProgram: pallet_gear_program, - GearMessenger: pallet_gear_messenger, - GearScheduler: pallet_gear_scheduler, - GearGas: pallet_gear_gas, - GearBank: pallet_gear_bank, - Gear: pallet_gear, - Airdrop: pallet_airdrop, - Vesting: pallet_vesting, - } -); - -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; - pub const ExistentialDeposit: Balance = 1; - pub const OutgoingLimit: u32 = 1024; - pub GearSchedule: pallet_gear::Schedule = >::default(); -} - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Index = u64; - type BlockNumber = BlockNumber; - type Hash = sp_core::H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = RuntimeEvent; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} - -impl pallet_sudo::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeCall = RuntimeCall; -} - -impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = ConstU64<500>; - type WeightInfo = (); -} - -impl pallet_authorship::Config for Test { - type FindAuthor = (); - - type EventHandler = (); -} - -impl pallet_gear_gas::Config for Test { - type BlockGasLimit = ConstU64<100_000_000>; -} - -impl pallet_gear_messenger::Config for Test { - type BlockLimiter = GearGas; - type CurrentBlockNumber = Gear; -} - -impl pallet_gear_program::Config for Test { - type Scheduler = GearScheduler; - type CurrentBlockNumber = (); -} - -parameter_types! { - pub RentFreePeriod: BlockNumber = 1_000; - pub RentCostPerBlock: Balance = 11; - pub ResumeMinimalPeriod: BlockNumber = 100; - pub ResumeSessionDuration: BlockNumber = 1_000; - pub const BankAddress: AccountId = 15082001; - pub const GasMultiplier: common::GasMultiplier = common::GasMultiplier::ValuePerGas(25); -} - -impl pallet_gear_bank::Config for Test { - type Currency = Balances; - type BankAddress = BankAddress; - type GasMultiplier = GasMultiplier; -} - -impl pallet_gear::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Randomness = TestRandomness; - type WeightInfo = (); - type Schedule = GearSchedule; - type OutgoingLimit = OutgoingLimit; - type DebugInfo = (); - type ProgramStorage = GearProgram; - type CodeStorage = GearProgram; - type MailboxThreshold = ConstU64<3000>; - type ReservationsLimit = ConstU64<256>; - type Messenger = GearMessenger; - type GasProvider = GearGas; - type BlockLimiter = GearGas; - type Scheduler = GearScheduler; - type QueueRunner = Gear; - type Voucher = (); - type ProgramRentFreePeriod = RentFreePeriod; - type ProgramResumeMinimalRentPeriod = ResumeMinimalPeriod; - type ProgramRentCostPerBlock = RentCostPerBlock; - type ProgramResumeSessionDuration = ResumeSessionDuration; - type ProgramRentEnabled = ConstBool; - type ProgramRentDisabledDelta = RentFreePeriod; -} - -impl pallet_gear_scheduler::Config for Test { - type BlockLimiter = GearGas; - type ReserveThreshold = ConstU64<1>; - type WaitlistCost = ConstU64<100>; - type MailboxCost = ConstU64<100>; - type ReservationCost = ConstU64<100>; - type DispatchHoldCost = ConstU64<100>; -} - -parameter_types! { - pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons = - WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE); -} - -impl pallet_vesting::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Currency = Balances; - type BlockNumberToBalance = ConvertInto; - type MinVestedTransfer = (); - type WeightInfo = (); - type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons; - const MAX_VESTING_SCHEDULES: u32 = 28; -} - -pub type VestingError = pallet_vesting::Error; - -impl pallet_airdrop::Config for Test { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); - type VestingSchedule = Vesting; -} - -pub type AirdropCall = pallet_airdrop::Call; -pub type AirdropError = pallet_airdrop::Error; - -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = system::GenesisConfig::default() - .build_storage::() - .unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![ - (ROOT, 100_000_000_u128), - (BOB, 100_000_000_u128), - (BankAddress::get(), ExistentialDeposit::get()), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - - pallet_sudo::GenesisConfig:: { key: Some(ROOT) } - .assimilate_storage(&mut t) - .unwrap(); - - pallet_vesting::GenesisConfig:: { - vesting: vec![(BOB, 100, 1000, 0)], - } - .assimilate_storage(&mut t) - .unwrap(); - - t.into() -} diff --git a/pallets/airdrop/src/tests.rs b/pallets/airdrop/src/tests.rs deleted file mode 100644 index 420b8c05930..00000000000 --- a/pallets/airdrop/src/tests.rs +++ /dev/null @@ -1,173 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2021-2023 Gear Technologies Inc. -// 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 super::*; -use crate::mock::{ - new_test_ext, Airdrop, AirdropCall, AirdropError, Balances, BankAddress, ExistentialDeposit, - RuntimeCall, RuntimeOrigin, Sudo, Test, Vesting, VestingError, ALICE, BOB, ROOT, -}; -use frame_support::{assert_err, assert_noop, assert_ok}; -use frame_system::Config; -use pallet_vesting::VestingInfo; - -#[test] -fn test_setup_works() { - new_test_ext().execute_with(|| { - assert_eq!(Sudo::key(), Some(ROOT)); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - }); -} - -#[test] -fn sudo_call_works() { - new_test_ext().execute_with(|| { - let call = Box::new(RuntimeCall::Airdrop(AirdropCall::transfer { - source: ROOT, - dest: ALICE, - amount: 10_000_000, - })); - assert_ok!(Sudo::sudo(RuntimeOrigin::signed(ROOT), call)); - assert_eq!(Balances::total_balance(&ALICE), 10_000_000); - assert_eq!(Balances::total_balance(&ROOT), 90_000_000); - assert_eq!( - Balances::total_balance(&BankAddress::get()), - ExistentialDeposit::get() - ); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - - assert_eq!(Balances::locks(BOB).len(), 1); - let call = Box::new(RuntimeCall::Airdrop(AirdropCall::transfer_vested { - source: BOB, - dest: ALICE, - schedule_index: 0, - amount: None, - })); - assert_ok!(Sudo::sudo(RuntimeOrigin::signed(ROOT), call)); - assert_eq!(Balances::total_balance(&BOB), 0); - assert_eq!(Balances::locks(BOB), vec![]); - assert_eq!(Balances::total_balance(&ALICE), 110_000_000); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - }); -} -#[test] -fn vesting_transfer_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::locks(BOB).len(), 1); - assert_eq!( - Vesting::vesting(BOB).unwrap().first().unwrap(), - &VestingInfo::, ::BlockNumber>::new( - 100_000_000, - 100_000, - 100, - ) - ); - assert_eq!(Balances::total_balance(&ALICE), 0); - assert_eq!(Balances::total_balance(&BOB), 100_000_000); - assert_eq!(Balances::total_balance(&ROOT), 100_000_000); - assert_eq!( - Balances::total_balance(&BankAddress::get()), - ExistentialDeposit::get() - ); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - - // Vesting must exist on the source account - assert_err!( - Airdrop::transfer_vested(RuntimeOrigin::root(), ALICE, BOB, 1, Some(200_000_000)), - VestingError::NotVesting - ); - - // Schedule must exist on the source account - assert_err!( - Airdrop::transfer_vested(RuntimeOrigin::root(), BOB, ALICE, 1, Some(200_000_000)), - VestingError::ScheduleIndexOutOfBounds - ); - - // Amount can't be bigger than locked funds - assert_err!( - Airdrop::transfer_vested(RuntimeOrigin::root(), BOB, ALICE, 0, Some(200_000_000)), - AirdropError::AmountBigger - ); - - // Transfer part of vested funds to ALICE - assert_ok!(Airdrop::transfer_vested( - RuntimeOrigin::root(), - BOB, - ALICE, - 0, - Some(10_000_000) - )); - - // Check that BOB have the same vesting schedule reduced by unlocked funds - assert_eq!( - Vesting::vesting(BOB).unwrap().first().unwrap(), - &VestingInfo::, ::BlockNumber>::new( - 90_000_000, 90_000, 100, - ) - ); - assert_eq!(Balances::total_balance(&BOB), 90_000_000); - assert_eq!(Balances::free_balance(ALICE), 10_000_000); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - - // Transfer all of vested funds to ALICE - assert_ok!(Airdrop::transfer_vested( - RuntimeOrigin::root(), - BOB, - ALICE, - 0, - None - )); - - // Check that BOB have no vesting and ALICE have all the unlocked funds. - assert_eq!(Vesting::vesting(BOB), None); - assert_eq!(Balances::total_balance(&BOB), 0); - assert_eq!(Balances::free_balance(ALICE), 100_000_000); - assert_eq!( - Balances::total_issuance(), - 200_000_000 + ExistentialDeposit::get() - ); - }); -} - -#[test] -fn signed_extrinsic_fails() { - new_test_ext().execute_with(|| { - assert_noop!( - Airdrop::transfer(RuntimeOrigin::signed(ROOT), ROOT, ALICE, 10_000_000_u128), - DispatchError::BadOrigin, - ); - assert_noop!( - Airdrop::transfer_vested(RuntimeOrigin::signed(ROOT), BOB, ALICE, 0, None), - DispatchError::BadOrigin, - ); - }); -} diff --git a/pallets/airdrop/src/weights.rs b/pallets/airdrop/src/weights.rs deleted file mode 100644 index ddaa539a3d9..00000000000 --- a/pallets/airdrop/src/weights.rs +++ /dev/null @@ -1,95 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2022-2023 Gear Technologies Inc. -// 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 pallet_airdrop -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("vara-dev"), DB CACHE: 1024 - -// Executed Command: -// ./target/production/gear benchmark pallet --chain=vara-dev --steps=50 --repeat=20 --pallet=pallet_airdrop --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=pallet_airdrop.rs --template=.maintain/frame-weight-template.hbs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; - -/// Weight functions needed for pallet_airdrop. -pub trait WeightInfo { - fn transfer(q: u32, ) -> Weight; - fn transfer_vested(q: u32, ) -> Weight; -} - -/// Weights for pallet_airdrop using the Gear node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// The range of component `q` is `[1, 256]`. - fn transfer(_q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `103` - // Estimated: `6196` - // Minimum execution time: 25_027_000 picoseconds. - Weight::from_parts(25_985_030, 6196) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// The range of component `q` is `[1, 256]`. - fn transfer_vested(q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `550` - // Estimated: `15482` - // Minimum execution time: 65_271_000 picoseconds. - Weight::from_parts(67_109_074, 15482) - // Standard Error: 328 - .saturating_add(Weight::from_parts(336, 0).saturating_mul(q.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) - } -} - -// For backwards compatibility and tests -impl WeightInfo for () { - /// The range of component `q` is `[1, 256]`. - fn transfer(_q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `103` - // Estimated: `6196` - // Minimum execution time: 25_027_000 picoseconds. - Weight::from_parts(25_985_030, 6196) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// The range of component `q` is `[1, 256]`. - fn transfer_vested(q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `550` - // Estimated: `15482` - // Minimum execution time: 65_271_000 picoseconds. - Weight::from_parts(67_109_074, 15482) - // Standard Error: 328 - .saturating_add(Weight::from_parts(336, 0).saturating_mul(q.into())) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) - } -} diff --git a/runtime/vara/Cargo.toml b/runtime/vara/Cargo.toml index fa91b85ef26..dcfed171e56 100644 --- a/runtime/vara/Cargo.toml +++ b/runtime/vara/Cargo.toml @@ -98,7 +98,6 @@ pallet-gear-staking-rewards.workspace = true pallet-gear-voucher.workspace = true pallet-gear-rpc-runtime-api.workspace = true runtime-primitives.workspace = true -pallet-airdrop.workspace = true [dev-dependencies] sp-io.workspace = true @@ -185,7 +184,6 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", - "pallet-airdrop/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -200,7 +198,6 @@ runtime-benchmarks = [ "pallet-gear/runtime-benchmarks", "pallet-gear-voucher/runtime-benchmarks", "sp-runtime/runtime-benchmarks", - "pallet-airdrop/runtime-benchmarks", "pallet-bags-list/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-conviction-voting/runtime-benchmarks", @@ -255,7 +252,6 @@ try-runtime = [ "pallet-utility/try-runtime", "pallet-vesting/try-runtime", "pallet-whitelist/try-runtime", - "pallet-airdrop/try-runtime", "pallet-bags-list/try-runtime", "runtime-common/try-runtime", ] diff --git a/runtime/vara/src/lib.rs b/runtime/vara/src/lib.rs index cf6de126ae5..849129492ba 100644 --- a/runtime/vara/src/lib.rs +++ b/runtime/vara/src/lib.rs @@ -1015,12 +1015,6 @@ impl pallet_gear_messenger::Config for Runtime { type CurrentBlockNumber = Gear; } -impl pallet_airdrop::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::pallet_airdrop::SubstrateWeight; - type VestingSchedule = Vesting; -} - pub struct ExtraFeeFilter; impl Contains for ExtraFeeFilter { fn contains(call: &RuntimeCall) -> bool { @@ -1167,8 +1161,7 @@ construct_runtime!( // TODO: Remove in stage 3 Sudo: pallet_sudo = 99, - // TODO: remove from production version - Airdrop: pallet_airdrop = 198, + // NOTE (!): `pallet_airdrop` used to be idx(198). // Only available with "debug-mode" feature on GearDebug: pallet_gear_debug = 199, @@ -1232,8 +1225,7 @@ construct_runtime!( // TODO: Remove in stage 3 Sudo: pallet_sudo = 99, - // TODO: remove from production version - Airdrop: pallet_airdrop = 198, + // NOTE (!): `pallet_airdrop` used to be idx(198). } ); @@ -1295,7 +1287,6 @@ mod benches { [pallet_timestamp, Timestamp] [pallet_utility, Utility] // Gear pallets - [pallet_airdrop, Airdrop] [pallet_gear, Gear] [pallet_gear_voucher, GearVoucher] ); diff --git a/runtime/vara/src/weights/mod.rs b/runtime/vara/src/weights/mod.rs index 170d6f59e22..b4eebedfe52 100644 --- a/runtime/vara/src/weights/mod.rs +++ b/runtime/vara/src/weights/mod.rs @@ -19,7 +19,6 @@ //! A list of the different weight modules for our runtime. pub mod frame_system; -pub mod pallet_airdrop; pub mod pallet_balances; pub mod pallet_gear; pub mod pallet_gear_voucher; diff --git a/runtime/vara/src/weights/pallet_airdrop.rs b/runtime/vara/src/weights/pallet_airdrop.rs deleted file mode 100644 index ffe616fea00..00000000000 --- a/runtime/vara/src/weights/pallet_airdrop.rs +++ /dev/null @@ -1,95 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2022-2023 Gear Technologies Inc. -// 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 pallet_airdrop -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-11, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("vara-dev"), DB CACHE: 1024 - -// Executed Command: -// ./target/production/gear benchmark pallet --chain=vara-dev --steps=50 --repeat=20 --pallet=pallet_airdrop --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./scripts/benchmarking/weights-output/pallet_airdrop.rs --template=.maintain/frame-weight-template.hbs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; - -/// Weight functions needed for pallet_airdrop. -pub trait WeightInfo { - fn transfer(q: u32, ) -> Weight; - fn transfer_vested(q: u32, ) -> Weight; -} - -/// Weights for pallet_airdrop using the Gear node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl pallet_airdrop::WeightInfo for SubstrateWeight { - /// The range of component `q` is `[1, 256]`. - fn transfer(_q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `103` - // Estimated: `6196` - // Minimum execution time: 25_162_000 picoseconds. - Weight::from_parts(26_300_954, 6196) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// The range of component `q` is `[1, 256]`. - fn transfer_vested(q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `550` - // Estimated: `15482` - // Minimum execution time: 65_671_000 picoseconds. - Weight::from_parts(67_524_170, 15482) - // Standard Error: 398 - .saturating_add(Weight::from_parts(280, 0).saturating_mul(q.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) - } -} - -// For backwards compatibility and tests -impl WeightInfo for () { - /// The range of component `q` is `[1, 256]`. - fn transfer(_q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `103` - // Estimated: `6196` - // Minimum execution time: 25_162_000 picoseconds. - Weight::from_parts(26_300_954, 6196) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// The range of component `q` is `[1, 256]`. - fn transfer_vested(q: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `550` - // Estimated: `15482` - // Minimum execution time: 65_671_000 picoseconds. - Weight::from_parts(67_524_170, 15482) - // Standard Error: 398 - .saturating_add(Weight::from_parts(280, 0).saturating_mul(q.into())) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) - } -} From 9c56aaeff67c87bde26a1e56fd3dbb9a413f4df0 Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Fri, 15 Sep 2023 17:15:46 +0400 Subject: [PATCH 2/2] Update `gsdk` metadata --- gsdk/src/metadata/generated.rs | 97 ---------------------------------- 1 file changed, 97 deletions(-) diff --git a/gsdk/src/metadata/generated.rs b/gsdk/src/metadata/generated.rs index cfc17329d53..77010704434 100644 --- a/gsdk/src/metadata/generated.rs +++ b/gsdk/src/metadata/generated.rs @@ -1000,73 +1000,6 @@ pub mod runtime_types { } } } - pub mod pallet_airdrop { - use super::runtime_types; - pub mod pallet { - use super::runtime_types; - #[derive(Debug, crate::gp::Decode, crate::gp::DecodeAsType, crate::gp::Encode)] - #[doc = "Contains one variant per dispatchable that can be called by an extrinsic."] - pub enum Call { - #[codec(index = 0)] - #[doc = "Transfer tokens from pre-funded `source` to `dest` account."] - #[doc = ""] - #[doc = "The origin must be the root."] - #[doc = ""] - #[doc = "Parameters:"] - #[doc = "- `source`: the pre-funded account (i.e. root),"] - #[doc = "- `dest`: the beneficiary account,"] - #[doc = "- `amount`: the amount of tokens to be minted."] - #[doc = ""] - #[doc = "Emits the following events:"] - #[doc = "- `TokensDeposited{ dest, amount }`"] - transfer { - source: ::subxt::utils::AccountId32, - dest: ::subxt::utils::AccountId32, - amount: ::core::primitive::u128, - }, - #[codec(index = 1)] - #[doc = "Remove vesting for `source` account and transfer tokens to `dest` account."] - #[doc = ""] - #[doc = "The origin must be the root."] - #[doc = ""] - #[doc = "Parameters:"] - #[doc = "- `source`: the account with vesting running,"] - #[doc = "- `dest`: the beneficiary account,"] - #[doc = "- `schedule_index`: the index of `VestingInfo` for source account."] - #[doc = "- `amount`: the amount to be unlocked and transferred from `VestingInfo`."] - #[doc = ""] - #[doc = "Emits the following events:"] - #[doc = "- `VestingScheduleRemoved{ who, schedule_index }`"] - transfer_vested { - source: ::subxt::utils::AccountId32, - dest: ::subxt::utils::AccountId32, - schedule_index: ::core::primitive::u32, - amount: ::core::option::Option<::core::primitive::u128>, - }, - } - #[derive(Debug, crate::gp::Decode, crate::gp::DecodeAsType, crate::gp::Encode)] - #[doc = "Error for the airdrop pallet."] - pub enum Error { - #[codec(index = 0)] - #[doc = "Amount to being transferred is bigger than vested."] - AmountBigger, - } - #[derive(Debug, crate::gp::Decode, crate::gp::DecodeAsType, crate::gp::Encode)] - #[doc = "\n\t\t\tThe [event](https://docs.substrate.io/main-docs/build/events-errors/) emitted\n\t\t\tby this pallet.\n\t\t\t"] - pub enum Event { - #[codec(index = 0)] - TokensDeposited { - account: ::subxt::utils::AccountId32, - amount: ::core::primitive::u128, - }, - #[codec(index = 1)] - VestingScheduleRemoved { - who: ::subxt::utils::AccountId32, - schedule_index: ::core::primitive::u32, - }, - } - } - } pub mod pallet_babe { use super::runtime_types; pub mod pallet { @@ -9113,8 +9046,6 @@ pub mod runtime_types { GearVoucher(runtime_types::pallet_gear_voucher::pallet::Call), #[codec(index = 99)] Sudo(runtime_types::pallet_sudo::pallet::Call), - #[codec(index = 198)] - Airdrop(runtime_types::pallet_airdrop::pallet::Call), #[codec(index = 199)] GearDebug(runtime_types::pallet_gear_debug::pallet::Call), } @@ -9182,8 +9113,6 @@ pub mod runtime_types { GearVoucher(runtime_types::pallet_gear_voucher::pallet::Event), #[codec(index = 99)] Sudo(runtime_types::pallet_sudo::pallet::Event), - #[codec(index = 198)] - Airdrop(runtime_types::pallet_airdrop::pallet::Event), #[codec(index = 199)] GearDebug(runtime_types::pallet_gear_debug::pallet::Event), } @@ -9204,20 +9133,6 @@ pub mod calls { #[doc = r" returns call name."] fn call_name(&self) -> &'static str; } - #[doc = "Calls of pallet `Airdrop`."] - pub enum AirdropCall { - Transfer, - TransferVested, - } - impl CallInfo for AirdropCall { - const PALLET: &'static str = "Airdrop"; - fn call_name(&self) -> &'static str { - match self { - Self::Transfer => "transfer", - Self::TransferVested => "transfer_vested", - } - } - } #[doc = "Calls of pallet `Babe`."] pub enum BabeCall { ReportEquivocation, @@ -11061,15 +10976,6 @@ pub mod impls { )?, )); } - if pallet_name == "Airdrop" { - return Ok(Event::Airdrop( - crate::metadata::airdrop::Event::decode_with_metadata( - &mut &*pallet_bytes, - pallet_ty, - metadata, - )?, - )); - } if pallet_name == "GearDebug" { return Ok(Event::GearDebug( crate::metadata::gear_debug::Event::decode_with_metadata( @@ -11179,9 +11085,6 @@ pub mod exports { pub mod sudo { pub use super::runtime_types::pallet_sudo::pallet::Event; } - pub mod airdrop { - pub use super::runtime_types::pallet_airdrop::pallet::Event; - } pub mod gear_debug { pub use super::runtime_types::pallet_gear_debug::pallet::Event; }