diff --git a/.maintain/reset-spec/peregrine_dev_kilt.py b/.maintain/reset-spec/peregrine_dev_kilt.py index 3170f35c58..34b4f3ac74 100644 --- a/.maintain/reset-spec/peregrine_dev_kilt.py +++ b/.maintain/reset-spec/peregrine_dev_kilt.py @@ -14,7 +14,6 @@ def update_spec(input: typing.Dict): input["properties"]["tokenSymbol"] = "PILT" input["genesis"]["runtime"]["parachainInfo"]["parachainId"] = para_id input["genesis"]["runtime"]["sudo"]["key"] = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" - input["genesis"]["runtime"]["kiltLaunch"]["transferAccount"] = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" input["genesis"]["runtime"]["parachainStaking"]["stakers"] = [ [ "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", diff --git a/.maintain/reset-spec/peregrine_kilt.py b/.maintain/reset-spec/peregrine_kilt.py index 61386035cb..2f3d5cbf11 100644 --- a/.maintain/reset-spec/peregrine_kilt.py +++ b/.maintain/reset-spec/peregrine_kilt.py @@ -26,7 +26,6 @@ def update_spec(input: typing.Dict): input["properties"]["tokenSymbol"] = "PILT" input["genesis"]["runtime"]["parachainInfo"]["parachainId"] = para_id input["genesis"]["runtime"]["sudo"]["key"] = acc_col_1 - input["genesis"]["runtime"]["kiltLaunch"]["transferAccount"] = acc_col_2 input["genesis"]["runtime"]["parachainStaking"]["stakers"] = [ [ acc_col_1, diff --git a/.maintain/reset-spec/peregrine_stg_kilt.py b/.maintain/reset-spec/peregrine_stg_kilt.py index ad87e232bb..9320aa2b33 100644 --- a/.maintain/reset-spec/peregrine_stg_kilt.py +++ b/.maintain/reset-spec/peregrine_stg_kilt.py @@ -28,7 +28,6 @@ def update_spec(input: typing.Dict): input["properties"]["tokenSymbol"] = "PILT" input["genesis"]["runtime"]["parachainInfo"]["parachainId"] = para_id input["genesis"]["runtime"]["sudo"]["key"] = acc_col_1 - input["genesis"]["runtime"]["kiltLaunch"]["transferAccount"] = acc_col_2 input["genesis"]["runtime"]["parachainStaking"]["stakers"] = [ [ acc_col_1, diff --git a/Cargo.lock b/Cargo.lock index ae4b7e2be0..5520368c84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1122,9 +1122,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.1.12" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c167e37342afc5f33fd87bbc870cedd020d2a6dffa05d45ccd9241fbdd146db" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" dependencies = [ "atty", "bitflags", @@ -1139,9 +1139,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.1.7" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1" +checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" dependencies = [ "heck 0.4.0", "proc-macro-error", @@ -1152,9 +1152,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "189ddd3b5d32a70b35e7686054371742a937b0d99128e76dde6340210e966669" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" dependencies = [ "os_str_bytes", ] @@ -1505,7 +1505,7 @@ dependencies = [ [[package]] name = "cumulus-client-cli" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "clap", "sc-cli", @@ -1516,7 +1516,7 @@ dependencies = [ [[package]] name = "cumulus-client-collator" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "cumulus-client-consensus-common", "cumulus-client-network", @@ -1540,7 +1540,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-aura" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "async-trait", "cumulus-client-consensus-common", @@ -1569,7 +1569,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-common" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "async-trait", "cumulus-relay-chain-interface", @@ -1590,7 +1590,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-relay-chain" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "async-trait", "cumulus-client-consensus-common", @@ -1614,7 +1614,7 @@ dependencies = [ [[package]] name = "cumulus-client-network" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "async-trait", "cumulus-relay-chain-interface", @@ -1639,7 +1639,7 @@ dependencies = [ [[package]] name = "cumulus-client-pov-recovery" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "cumulus-primitives-core", "cumulus-relay-chain-interface", @@ -1663,7 +1663,7 @@ dependencies = [ [[package]] name = "cumulus-client-service" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "cumulus-client-cli", "cumulus-client-collator", @@ -1693,7 +1693,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-aura-ext" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "frame-executive", "frame-support", @@ -1711,7 +1711,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "cumulus-pallet-parachain-system-proc-macro", "cumulus-primitives-core", @@ -1741,7 +1741,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system-proc-macro" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "proc-macro-crate 1.1.3", "proc-macro2", @@ -1752,7 +1752,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-session-benchmarking" version = "3.0.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "frame-benchmarking", "frame-support", @@ -1766,7 +1766,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-xcmp-queue" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -1784,7 +1784,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-core" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "frame-support", "parity-scale-codec", @@ -1800,7 +1800,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-parachain-inherent" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -1823,7 +1823,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-timestamp" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "cumulus-primitives-core", "futures 0.3.21", @@ -1836,7 +1836,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-inprocess-interface" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -1864,7 +1864,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-interface" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -1888,7 +1888,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-rpc-interface" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "async-trait", "backoff", @@ -1914,7 +1914,7 @@ dependencies = [ [[package]] name = "cumulus-test-relay-sproof-builder" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "cumulus-primitives-core", "parity-scale-codec", @@ -3756,25 +3756,6 @@ dependencies = [ "winapi-build", ] -[[package]] -name = "kilt-launch" -version = "1.6.2" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "log", - "pallet-balances", - "pallet-vesting", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", -] - [[package]] name = "kilt-parachain" version = "1.6.2" @@ -4783,7 +4764,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", - "kilt-launch", "kilt-support", "log", "pallet-aura", @@ -6660,7 +6640,7 @@ dependencies = [ [[package]] name = "parachain-info" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#0c779d926beeb6e1f3f2aa777d9bcec792c0bdac" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.19#2317ef00dfa29a4d23fd6aa808d791a5dab82a02" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -6939,7 +6919,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", - "kilt-launch", "kilt-support", "log", "pallet-aura", @@ -8871,6 +8850,8 @@ dependencies = [ "attestation", "frame-support", "frame-system", + "frame-try-runtime", + "log", "pallet-authorship", "pallet-balances", "pallet-membership", @@ -11194,7 +11175,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", - "kilt-launch", "kilt-support", "log", "pallet-aura", diff --git a/nodes/parachain/src/chain_spec/peregrine.rs b/nodes/parachain/src/chain_spec/peregrine.rs index 0c0485ac31..c20ad1c529 100644 --- a/nodes/parachain/src/chain_spec/peregrine.rs +++ b/nodes/parachain/src/chain_spec/peregrine.rs @@ -21,9 +21,8 @@ use cumulus_primitives_core::ParaId; use hex_literal::hex; use peregrine_runtime::{ - BalancesConfig, CouncilConfig, GenesisConfig, InflationInfo, KiltLaunchConfig, ParachainInfoConfig, - ParachainStakingConfig, SessionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, VestingConfig, - WASM_BINARY, + BalancesConfig, CouncilConfig, GenesisConfig, InflationInfo, ParachainInfoConfig, ParachainStakingConfig, + SessionConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, VestingConfig, WASM_BINARY, }; use runtime_common::{ constants::{kilt_inflation_config, staking::MinCollatorStake, MAX_COLLATOR_STAKE}, @@ -38,8 +37,6 @@ use crate::chain_spec::{get_account_id_from_seed, get_from_seed, get_properties, /// Specialized `ChainSpec` for the normal parachain runtime. pub type ChainSpec = sc_service::GenericChainSpec; -const TRANSFER_ACCOUNT: [u8; 32] = hex!["6a3c793cec9dbe330b349dc4eea6801090f5e71f53b1b41ad11afb4a313a282c"]; - pub fn make_dev_spec() -> Result { let properties = get_properties("PILT", 15, 38); let wasm = WASM_BINARY.ok_or("No WASM")?; @@ -177,19 +174,6 @@ fn testnet_genesis( }, sudo: SudoConfig { key: Some(root_key) }, parachain_info: ParachainInfoConfig { parachain_id: id }, - kilt_launch: KiltLaunchConfig { - vesting: airdrop_accounts - .iter() - .cloned() - .map(|(who, amount, vesting_length, _)| (who, vesting_length, amount)) - .collect(), - balance_locks: airdrop_accounts - .iter() - .cloned() - .map(|(who, amount, _, locking_length)| (who, locking_length, amount)) - .collect(), - transfer_account: TRANSFER_ACCOUNT.into(), - }, vesting: VestingConfig { vesting: botlabs_accounts .iter() diff --git a/nodes/parachain/src/chain_spec/spiritnet.rs b/nodes/parachain/src/chain_spec/spiritnet.rs index eb07c4ad06..845695ac07 100644 --- a/nodes/parachain/src/chain_spec/spiritnet.rs +++ b/nodes/parachain/src/chain_spec/spiritnet.rs @@ -29,8 +29,8 @@ use sc_telemetry::TelemetryEndpoints; use sp_core::{crypto::UncheckedInto, sr25519}; use sp_runtime::traits::Zero; use spiritnet_runtime::{ - BalancesConfig, CouncilConfig, GenesisConfig, InflationInfo, KiltLaunchConfig, ParachainInfoConfig, - ParachainStakingConfig, SessionConfig, SystemConfig, TechnicalCommitteeConfig, VestingConfig, WASM_BINARY, + BalancesConfig, CouncilConfig, GenesisConfig, InflationInfo, ParachainInfoConfig, ParachainStakingConfig, + SessionConfig, SystemConfig, TechnicalCommitteeConfig, VestingConfig, WASM_BINARY, }; use crate::chain_spec::{get_account_id_from_seed, get_from_seed, DEFAULT_PARA_ID, TELEMETRY_URL}; @@ -107,7 +107,6 @@ pub fn get_chain_spec_dev() -> Result { 10000000 * KILT, ), ], - hex!["6a3c793cec9dbe330b349dc4eea6801090f5e71f53b1b41ad11afb4a313a282c"].into(), DEFAULT_PARA_ID, ) }, @@ -127,7 +126,6 @@ const WILT_COL_ACC_1: [u8; 32] = hex!["e6cf13c86a5f174acba79ca361dc429d89eb704c6 const WILT_COL_SESSION_1: [u8; 32] = hex!["e29df39b74777495ca00cd7a316ce98c5225d7088ae924b122fe0e2e6a4b5569"]; const WILT_COL_ACC_2: [u8; 32] = hex!["e8ed0c2a40fb5a0bbb24c38f5c8cd83d79498ac029ac9f87497677f5701e3d2c"]; const WILT_COL_SESSION_2: [u8; 32] = hex!["7cacfbce640321ba84a85f41dfb43c2a2ea14ed789c096ad62ee0491599b0f44"]; -const WILT_TRANS_ACC: [u8; 32] = hex!["aaf5308b81f962ffdaccaa22352cc95b7bef70033d9d0d5a7023ec5681f05954"]; pub fn get_chain_spec_wilt() -> Result { let properties = get_properties("WILT", 15, 38); @@ -154,9 +152,7 @@ pub fn get_chain_spec_wilt() -> Result { vec![ (WILT_COL_ACC_1.into(), 40000 * KILT), (WILT_COL_ACC_2.into(), 40000 * KILT), - (WILT_TRANS_ACC.into(), 10000 * KILT), ], - WILT_TRANS_ACC.into(), id, ) }, @@ -183,7 +179,6 @@ const RILT_COL_ACC_1: [u8; 32] = hex!["6a5c355bca369a54c334542fd91cf70822be92f21 const RILT_COL_SESSION_1: [u8; 32] = hex!["66c4ca0710c2c8a92504f281d992000508ce255543016545014cf0bfbbe71429"]; const RILT_COL_ACC_2: [u8; 32] = hex!["768538a941d1e4730c31830ab85a54ff34aaaad1f81bdd246db11802a57a5412"]; const RILT_COL_SESSION_2: [u8; 32] = hex!["7cff6c7a53c4630a0a35f8793a04b663681575bbfa43dbe5848b220bc4bd1963"]; -const RILT_TRANS_ACC: [u8; 32] = hex!["6e016ca65cd213156c075da95c132bd1917762de0026ee539c720999aded3216"]; pub fn get_chain_spec_rilt() -> Result { let properties = get_properties("RILT", 15, 38); @@ -210,9 +205,7 @@ pub fn get_chain_spec_rilt() -> Result { vec![ (RILT_COL_ACC_1.into(), 1_000_000 * KILT), (RILT_COL_ACC_2.into(), 1_000_000 * KILT), - (RILT_TRANS_ACC.into(), 10_000 * KILT), ], - RILT_TRANS_ACC.into(), id, ) }, @@ -251,7 +244,6 @@ fn testnet_genesis( max_candidate_stake: Balance, initial_authorities: Vec<(AccountId, AuthorityId)>, endowed_accounts: Vec<(AccountId, Balance)>, - transfer_account: AccountId, id: ParaId, ) -> GenesisConfig { type VestingPeriod = BlockNumber; @@ -286,19 +278,6 @@ fn testnet_genesis( .collect(), }, parachain_info: ParachainInfoConfig { parachain_id: id }, - kilt_launch: KiltLaunchConfig { - vesting: claimable_accounts - .iter() - .cloned() - .map(|(who, amount, vesting_length, _)| (who, vesting_length, amount)) - .collect(), - balance_locks: claimable_accounts - .iter() - .cloned() - .map(|(who, amount, _, locking_length)| (who, locking_length, amount)) - .collect(), - transfer_account, - }, vesting: VestingConfig { vesting: owned_accounts .iter() diff --git a/nodes/standalone/src/chain_spec.rs b/nodes/standalone/src/chain_spec.rs index 091e1a1850..1be68d492b 100644 --- a/nodes/standalone/src/chain_spec.rs +++ b/nodes/standalone/src/chain_spec.rs @@ -19,10 +19,9 @@ //! KILT chain specification use mashnet_node_runtime::{ - BalancesConfig, GenesisConfig, IndicesConfig, KiltLaunchConfig, SessionConfig, SudoConfig, SystemConfig, - VestingConfig, WASM_BINARY, + BalancesConfig, GenesisConfig, IndicesConfig, SessionConfig, SudoConfig, SystemConfig, VestingConfig, WASM_BINARY, }; -use runtime_common::{constants::BLOCKS_PER_YEAR, AccountId, AccountPublic, Balance, BlockNumber}; +use runtime_common::{AccountId, AccountPublic, Balance, BlockNumber}; use hex_literal::hex; @@ -81,8 +80,7 @@ const TELEMETRY_URL: &str = "wss://telemetry-backend.kilt.io:8080/submit"; const SPORRAN_AUTHORITY_ACC: [u8; 32] = hex!("2c94fbcfe0a7db40579e12bc74d0f7215fe91ba51b3eade92799788ca549f373"); const SPORRAN_AUTHORITY_SESSION: [u8; 32] = hex!("3bbaa842650064362767a1d9dd8899f531c80dc42eafb9599f4df0965e4a5299"); -const SPORRAN_FAUCET: [u8; 32] = hex!("780d87860ac7a02ebffa10e41a5a486efdebf63d595a44907ec0ced1d8626c4a"); -const TRANSFER_ACCOUNT: [u8; 32] = hex!("6a3c793cec9dbe330b349dc4eea6801090f5e71f53b1b41ad11afb4a313a282c"); +const SPORRAN_FAUCET: [u8; 32] = hex!("2c9e9c40e15a2767e2d04dc1f05d824dd76d1d37bada3d7bb1d40eca29f3a4ff"); impl Alternative { /// Get an actual chain config from one of the alternatives. @@ -215,19 +213,6 @@ fn testnet_genesis( aura: Default::default(), grandpa: Default::default(), sudo: SudoConfig { key: Some(root_key) }, - kilt_launch: KiltLaunchConfig { - balance_locks: airdrop_accounts - .iter() - .cloned() - .map(|(who, amount, _, locking_length)| (who, locking_length * BLOCKS_PER_YEAR / 12, amount)) - .collect(), - vesting: airdrop_accounts - .iter() - .cloned() - .map(|(who, amount, vesting_length, _)| (who, vesting_length * BLOCKS_PER_YEAR / 12, amount)) - .collect(), - transfer_account: TRANSFER_ACCOUNT.into(), - }, vesting: VestingConfig { vesting: vec![] }, } } diff --git a/pallets/kilt-launch/Cargo.toml b/pallets/kilt-launch/Cargo.toml deleted file mode 100644 index 8c976008a5..0000000000 --- a/pallets/kilt-launch/Cargo.toml +++ /dev/null @@ -1,53 +0,0 @@ -[package] -authors = ["KILT "] -description = "Enables automatic unlocking of balance from genesis block" -edition = "2021" -name = "kilt-launch" -repository = "https://github.com/KILTprotocol/mashnet-node" -version = "1.6.2" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dev-dependencies] -sp-core = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19"} -sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19"} - -[dependencies] -codec = {package = "parity-scale-codec", version = "3.1.2", default-features = false, features = ["derive"]} -log = "0.4.16" -scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} -serde = {version = "1.0.136", optional = true} - -frame-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19", optional = true} -frame-support = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} -frame-system = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} -pallet-balances = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} -pallet-vesting = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} -sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} -sp-std = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} - -[features] -default = ["std"] - -runtime-benchmarks = [ - "frame-benchmarking", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", -] -std = [ - "codec/std", - "frame-benchmarking/std", - "frame-support/std", - "frame-system/std", - "log/std", - "pallet-balances/std", - "pallet-vesting/std", - "scale-info/std", - "serde", - "sp-runtime/std", - "sp-std/std", -] -try-runtime = [ - "frame-support/try-runtime", -] diff --git a/pallets/kilt-launch/src/benchmarking.rs b/pallets/kilt-launch/src/benchmarking.rs deleted file mode 100644 index 8c81f61706..0000000000 --- a/pallets/kilt-launch/src/benchmarking.rs +++ /dev/null @@ -1,287 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain 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. - -// The KILT Blockchain 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 . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -use super::*; - -use crate::{BalanceLocks, BalanceOf, LockedBalance, Pallet as KiltLaunch, UnownedAccount}; -use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, vec, whitelist_account, Zero}; -use frame_support::{ - assert_ok, - inherent::Vec, - traits::{Currency, Get, Hooks}, -}; -use frame_system::{Pallet as System, RawOrigin}; -use pallet_balances::Locks; -use pallet_vesting::{Vesting, VestingInfo}; -use sp_runtime::traits::StaticLookup; -use sp_std::convert::TryFrom; - -const SEED: u32 = 0; -const AMOUNT: u128 = 1000; -const PER_BLOCK: u32 = 100; -const UNLOCK_BLOCK: u32 = 1337; - -type Lookup = <::Lookup as StaticLookup>::Source; - -/// Account to lookup type of system trait. -fn as_lookup(account: T::AccountId) -> Lookup { - T::Lookup::unlookup(account) -} - -type GenesisSetup = ( - ( - ::AccountId, - <::Lookup as StaticLookup>::Source, - ), - Vec<( - ::AccountId, - <::Lookup as StaticLookup>::Source, - )>, - Vec<( - ::AccountId, - <::Lookup as StaticLookup>::Source, - )>, -); - -/// Mock the Pallet's GenesisBuild and return pairs consisting of AccountId and -/// LookupSource for the transfer account, `n` vesting addresses and `n` locking -/// addresses. -fn genesis_setup(n: u32) -> Result, &'static str> -where - ::Balance: From, - <::Currency as Currency<::AccountId>>::Balance: From, -{ - System::::set_block_number(0u32.into()); - - // Setup transfer account - let transfer: T::AccountId = account("transfer", 0, SEED); - let transfer_lookup: ::Source = as_lookup::(transfer.clone()); - KiltLaunch::::change_transfer_account(RawOrigin::Root.into(), transfer_lookup.clone())?; - - // Create `n` genesis accounts each for vesting and locking - let (v_accs, l_accs) = (1..=n).into_iter().fold((vec![], vec![]), |mut acc, i| { - let vest_acc: T::AccountId = account("vesting_{:?}", i, SEED); - let lock_acc: T::AccountId = account("locking", i, SEED); - let vest_lookup: ::Source = as_lookup::(vest_acc.clone()); - let lock_lookup: ::Source = as_lookup::(lock_acc.clone()); - - // Set balance - as Currency>::make_free_balance_be(&vest_acc, AMOUNT.into()); - as Currency>::make_free_balance_be(&lock_acc, AMOUNT.into()); - UnownedAccount::::insert(&vest_acc, ()); - UnownedAccount::::insert(&lock_acc, ()); - - // Set vesting info by mocking the Pallet's GenesisBuild - assert_ok!(Vesting::::try_append( - &vest_acc, - VestingInfo::, T::BlockNumber>::new(AMOUNT.into(), PER_BLOCK.into(), T::BlockNumber::zero()), - )); - // Set locking info by mocking the Pallet's GenesisBuild - BalanceLocks::::insert( - &lock_acc, - LockedBalance:: { - block: UNLOCK_BLOCK.into(), - amount: AMOUNT.into(), - }, - ); - - assert_eq!(>::total_balance(&vest_acc), AMOUNT.into()); - assert_eq!(>::total_balance(&lock_acc), AMOUNT.into()); - acc.0.push((vest_acc, vest_lookup)); - acc.1.push((lock_acc, lock_lookup)); - acc - }); - - Ok(((transfer, transfer_lookup), v_accs, l_accs)) -} - -benchmarks! { - where_clause { - where - T: core::fmt::Debug, - ::Balance: From, - <::Currency as Currency<::AccountId>>::Balance: From, - } - - change_transfer_account { - let transfer_account: T::AccountId = account("transfer_new", 0, SEED); - let transfer_account_lookup: ::Source = as_lookup::(transfer_account.clone()); - }: _(RawOrigin::Root, transfer_account_lookup) - verify { - assert_eq!(TransferAccount::::get(), Some(transfer_account)); - } - - // Worst case: UnlockingAt has MaxClaims entries - force_unlock { - let n in 1 .. T::MaxClaims::get() - 1; - - let ((transfer, _), _, s) = genesis_setup::(n).expect("Genesis setup failure"); - whitelist_account!(transfer); - - // Migrate balance locks 1 by 1 to fill UnlockingAt - for (c, (_, source_lookup)) in s.into_iter().enumerate() { - let target: T::AccountId = account("target", u32::try_from(c).unwrap(), SEED); - let target_lookup: ::Source = as_lookup::(target); - KiltLaunch::::migrate_genesis_account(RawOrigin::Signed(transfer.clone()).into(), source_lookup, target_lookup)?; - } - assert_eq!(UnlockingAt::::get::(UNLOCK_BLOCK.into()).expect("UnlockingAt should not be empty").len(), n as usize); - }: _(RawOrigin::Root, UNLOCK_BLOCK.into()) - verify { - assert!(!UnlockingAt::::contains_key::(UNLOCK_BLOCK.into())); - } - - // Worst case: target already has locked balance pre-transfer, source still has locked balance left post-transfer - locked_transfer { - let ((transfer, _), _, s) = genesis_setup::(3).expect("Genesis setup failure"); - whitelist_account!(transfer); - let mut locked_lookups: Vec<::Source> = s.into_iter().map(|(_, lookup)| lookup).collect(); - let locked_lookup = locked_lookups.split_off(2); - - // Set custom lock with amount `2 * AMOUNT` for source - let source: T::AccountId = account("source", 0, SEED); - let source_lookup: ::Source = as_lookup::(source.clone()); - KiltLaunch::::migrate_multiple_genesis_accounts(RawOrigin::Signed(transfer.clone()).into(), locked_lookups, source_lookup)?; - assert_eq!(BalanceLocks::::get(&source), Some(LockedBalance:: { - block: UNLOCK_BLOCK.into(), - amount: (2 * AMOUNT).into(), - }), "Source BalanceLock not set"); - assert_eq!(UnlockingAt::::get::(UNLOCK_BLOCK.into()).expect("UnlockingAt should not be empty").into_inner(), vec![source.clone()]); - - // Set custom lock with amount `AMOUNT` for target - let target: T::AccountId = account("target", 0, SEED); - let target_lookup: ::Source = as_lookup::(target.clone()); - KiltLaunch::::migrate_multiple_genesis_accounts(RawOrigin::Signed(transfer).into(), locked_lookup, target_lookup.clone())?; - assert_eq!(BalanceLocks::::get(&target), Some(LockedBalance:: { - block: UNLOCK_BLOCK.into(), - amount: AMOUNT.into(), - }), "Target BalanceLock not set"); - assert_eq!(UnlockingAt::::get::(UNLOCK_BLOCK.into()).expect("UnlockingAt should not be empty").into_inner(), vec![source.clone(), target.clone()]); - - // Transfer AMOUNT from source to target - }: _(RawOrigin::Signed(source.clone()), target_lookup, AMOUNT.into()) - verify { - assert_eq!(UnlockingAt::::get::(UNLOCK_BLOCK.into()).expect("UnlockingAt should not be empty").into_inner(), vec![source.clone(), target.clone()]); - assert_eq!(BalanceLocks::::get(&source), Some(LockedBalance:: { - block: UNLOCK_BLOCK.into(), - amount: AMOUNT.into(), - }), "Source BalanceLock not updated"); - assert_eq!(BalanceLocks::::get(&target), Some(LockedBalance:: { - block: UNLOCK_BLOCK.into(), - amount: (2 * AMOUNT).into(), - }), "Target BalanceLock not updated"); - } - - migrate_genesis_account_vesting { - let target: T::AccountId = account("target", 0, SEED); - let target_lookup: ::Source = as_lookup::(target.clone()); - - let ((transfer, transfer_lookup), s, _) = genesis_setup::(1).expect("Genesis setup failure"); - whitelist_account!(transfer); - let (source, source_lookup) = s.get(0).expect("Locking source should not be empty").clone(); - }: migrate_genesis_account(RawOrigin::Signed(transfer), source_lookup, target_lookup) - verify { - assert!(UnownedAccount::::get(&source).is_none()); - assert!(!Vesting::::contains_key(source), "Vesting schedule not removed"); - let expected_vesting = VestingInfo::, T::BlockNumber>::new(AMOUNT.into(), PER_BLOCK.into(), T::BlockNumber::zero()); - assert_eq!(Vesting::::get(&target).expect("Missing vesting info").into_inner().get(0), Some(&expected_vesting), "Vesting schedule not migrated"); - assert_eq!(Locks::::get(&target).len(), 1, "Lock not set"); - } - - migrate_genesis_account_locking { - let target: T::AccountId = account("target", 0, SEED); - let target_lookup: ::Source = as_lookup::(target.clone()); - - let ((transfer, transfer_lookup), _, s) = genesis_setup::(1).expect("Genesis setup failure"); - whitelist_account!(transfer); - let (source, source_lookup) = s.get(0).expect("Locking source should not be empty").clone(); - }: migrate_genesis_account(RawOrigin::Signed(transfer), source_lookup, target_lookup) - verify { - assert!(UnownedAccount::::get(&source).is_none()); - assert!(!BalanceLocks::::contains_key(source), "BalanceLock not removed"); - assert_eq!(BalanceLocks::::get(&target), Some(LockedBalance:: { - block: UNLOCK_BLOCK.into(), - amount: AMOUNT.into(), - }), "BalanceLock not migrated"); - assert_eq!(Locks::::get(&target).len(), 1, "Lock not set"); - } - - migrate_multiple_genesis_accounts_vesting { - let n in 1 .. T::MaxClaims::get() - 1; - - let target: T::AccountId = account("target", 0, SEED); - let target_lookup: ::Source = as_lookup::(target.clone()); - - let ((transfer, transfer_lookup), s, _) = genesis_setup::(n).expect("Genesis setup failure"); - let source_lookups: Vec<::Source> = s.into_iter().map(|(_, lookup)| lookup).collect(); - }: migrate_multiple_genesis_accounts(RawOrigin::Signed(transfer), source_lookups, target_lookup) - verify { - assert_eq!(Vesting::::get(&target).expect("Missing vesting info").into_inner().get(0), Some(&VestingInfo::, T::BlockNumber>::new( - (n as u128 * AMOUNT).into(), - (n * PER_BLOCK).into(), - T::BlockNumber::zero(), - )), "Vesting schedule not migrated"); - assert_eq!(Locks::::get(&target).len(), 1, "Lock not set"); - } - - migrate_multiple_genesis_accounts_locking { - let n in 1 .. T::MaxClaims::get() - 1; - - let target: T::AccountId = account("target", 0, SEED); - let target_lookup: ::Source = as_lookup::(target.clone()); - - let ((transfer, transfer_lookup), _, s) = genesis_setup::(n).expect("Genesis setup failure"); - whitelist_account!(transfer); - let source_lookups: Vec<::Source> = s.into_iter().map(|(_, lookup)| lookup).collect(); - }: migrate_multiple_genesis_accounts(RawOrigin::Signed(transfer), source_lookups, target_lookup) - verify { - assert_eq!(BalanceLocks::::get(&target), Some(LockedBalance:: { - block: UNLOCK_BLOCK.into(), - amount: (n as u128 * AMOUNT).into(), - }), "BalanceLock not migrated"); - assert_eq!(Locks::::get(&target).len(), 1, "Lock not set"); - } - - on_initialize_unlock { - let n in 1 .. T::AutoUnlockBound::get(); - - let ((transfer, _), _, s) = genesis_setup::(n).expect("Genesis setup failure"); - - // Migrate balance locks 1 by 1 to fill UnlockingAt - for (c, (_, source_lookup)) in s.into_iter().enumerate() { - let target: T::AccountId = account("target", u32::try_from(c).unwrap(), SEED); - let target_lookup: ::Source = as_lookup::(target); - KiltLaunch::::migrate_genesis_account(RawOrigin::Signed(transfer.clone()).into(), source_lookup, target_lookup)?; - } - let block: T::BlockNumber = UNLOCK_BLOCK.into(); - assert_eq!(UnlockingAt::::get(&block).expect("UnlockingAt should not be empty").len(), n as usize); - }: { KiltLaunch::::on_initialize(block) } - verify { - assert!(UnlockingAt::::get(&block).is_none()); - } - - on_initialize_no_action { - }: { KiltLaunch::::on_initialize(0_u32.into()) } - verify { - } -} - -impl_benchmark_test_suite!( - KiltLaunch, - crate::mock::ExtBuilder::default().build(), - crate::mock::Test, -); diff --git a/pallets/kilt-launch/src/default_weights.rs b/pallets/kilt-launch/src/default_weights.rs deleted file mode 100644 index 381040323d..0000000000 --- a/pallets/kilt-launch/src/default_weights.rs +++ /dev/null @@ -1,225 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain 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. - -// The KILT Blockchain 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 . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -//! Autogenerated weights for kilt_launch -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-10-29, STEPS: {{cmd.steps}}\, REPEAT: {{cmd.repeat}}\, LOW RANGE: {{cmd.lowest_range_values}}\, HIGH RANGE: {{cmd.highest_range_values}}\ -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 - -// Executed Command: -// target/release/kilt-parachain -// benchmark -// --chain=dev -// --steps=50 -// --repeat=20 -// --pallet=kilt-launch -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=pallets/kilt-launch/src/default_weights.rs -// --template=.maintain/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 kilt_launch. -pub trait WeightInfo { - fn change_transfer_account() -> Weight; - fn force_unlock(n: u32, ) -> Weight; - fn locked_transfer() -> Weight; - fn migrate_genesis_account_vesting() -> Weight; - fn migrate_genesis_account_locking() -> Weight; - fn migrate_multiple_genesis_accounts_vesting(n: u32, ) -> Weight; - fn migrate_multiple_genesis_accounts_locking(n: u32, ) -> Weight; - fn on_initialize_unlock(n: u32, ) -> Weight; - fn on_initialize_no_action() -> Weight; -} - -/// Weights for kilt_launch using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - // Storage: KiltLaunch TransferAccount (r:0 w:1) - fn change_transfer_account() -> Weight { - (2_981_000_u64) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - // Storage: Balances Locks (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: KiltLaunch BalanceLocks (r:0 w:1) - fn force_unlock(n: u32, ) -> Weight { - (26_446_000_u64) - // Standard Error: 17_000 - .saturating_add((27_230_000_u64).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(1_u64)) - .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(n as Weight))) - } - // Storage: System Account (r:2 w:2) - // Storage: KiltLaunch BalanceLocks (r:2 w:2) - // Storage: Balances Locks (r:2 w:2) - fn locked_transfer() -> Weight { - (132_907_000_u64) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:2 w:2) - // Storage: KiltLaunch BalanceLocks (r:1 w:0) - fn migrate_genesis_account_vesting() -> Weight { - (147_997_000_u64) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:1 w:0) - // Storage: KiltLaunch BalanceLocks (r:2 w:2) - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - fn migrate_genesis_account_locking() -> Weight { - (151_816_000_u64) - .saturating_add(T::DbWeight::get().reads(10_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:2 w:2) - // Storage: KiltLaunch BalanceLocks (r:1 w:0) - fn migrate_multiple_genesis_accounts_vesting(n: u32, ) -> Weight { - (48_179_000_u64) - // Standard Error: 47_000 - .saturating_add((96_707_000_u64).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().reads((5_u64).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(3_u64)) - .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(n as Weight))) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:1 w:0) - // Storage: KiltLaunch BalanceLocks (r:2 w:2) - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - fn migrate_multiple_genesis_accounts_locking(n: u32, ) -> Weight { - (57_434_000_u64) - // Standard Error: 95_000 - .saturating_add((94_182_000_u64).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().reads((5_u64).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(4_u64)) - .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(n as Weight))) - } - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - // Storage: Balances Locks (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: KiltLaunch BalanceLocks (r:0 w:1) - fn on_initialize_unlock(n: u32, ) -> Weight { - (26_036_000_u64) - // Standard Error: 10_000 - .saturating_add((27_339_000_u64).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(1_u64)) - .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(n as Weight))) - } - // Storage: KiltLaunch UnlockingAt (r:1 w:0) - fn on_initialize_no_action() -> Weight { - (4_341_000_u64) - .saturating_add(T::DbWeight::get().reads(1_u64)) - } -} - -// For backwards compatibility and tests -impl WeightInfo for () { - fn change_transfer_account() -> Weight { - (2_981_000_u64) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - fn force_unlock(n: u32, ) -> Weight { - (26_446_000_u64) - // Standard Error: 17_000 - .saturating_add((27_230_000_u64).saturating_mul(n as Weight)) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(n as Weight))) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - .saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(n as Weight))) - } - fn locked_transfer() -> Weight { - (132_907_000_u64) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(6_u64)) - } - fn migrate_genesis_account_vesting() -> Weight { - (147_997_000_u64) - .saturating_add(RocksDbWeight::get().reads(9_u64)) - .saturating_add(RocksDbWeight::get().writes(6_u64)) - } - fn migrate_genesis_account_locking() -> Weight { - (151_816_000_u64) - .saturating_add(RocksDbWeight::get().reads(10_u64)) - .saturating_add(RocksDbWeight::get().writes(7_u64)) - } - fn migrate_multiple_genesis_accounts_vesting(n: u32, ) -> Weight { - (48_179_000_u64) - // Standard Error: 47_000 - .saturating_add((96_707_000_u64).saturating_mul(n as Weight)) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().reads((5_u64).saturating_mul(n as Weight))) - .saturating_add(RocksDbWeight::get().writes(3_u64)) - .saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(n as Weight))) - } - fn migrate_multiple_genesis_accounts_locking(n: u32, ) -> Weight { - (57_434_000_u64) - // Standard Error: 95_000 - .saturating_add((94_182_000_u64).saturating_mul(n as Weight)) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().reads((5_u64).saturating_mul(n as Weight))) - .saturating_add(RocksDbWeight::get().writes(4_u64)) - .saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(n as Weight))) - } - fn on_initialize_unlock(n: u32, ) -> Weight { - (26_036_000_u64) - // Standard Error: 10_000 - .saturating_add((27_339_000_u64).saturating_mul(n as Weight)) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(n as Weight))) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - .saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(n as Weight))) - } - fn on_initialize_no_action() -> Weight { - (4_341_000_u64) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - } -} diff --git a/pallets/kilt-launch/src/lib.rs b/pallets/kilt-launch/src/lib.rs deleted file mode 100644 index a510d3a520..0000000000 --- a/pallets/kilt-launch/src/lib.rs +++ /dev/null @@ -1,889 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain 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. - -// The KILT Blockchain 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 . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -//! # KILT Launch Pallet -//! -//! A simple pallet providing means of setting up KILT balance locks and -//! vesting schedules for unowned accounts in the genesis block. These should -//! later be migrated to user-owned accounts via the extrinsic -//! `migrate_genesis_account` which has to be signed by a specific account -//! called `TransferAccount`. The latter is also set in the genesis block -//! and can be changed by calling the sudo extrinsic `change_transfer_account`. -//! -//! - [`Config`] -//! - [`Call`] -//! - [`Pallet`] -//! -//! ## Overview -//! -//! The KILT Launch pallet provides functions for: -//! -//! - Setting vesting information and KILT balance lock for unowned accounts in -//! genesis block. -//! - Migrating vesting/KILT balance lock from unowned accounts to user-owned -//! accounts. -//! - Transfer locked tokens from user-owned account to another. NOTE: This will -//! be made available shortly before we remove the sudo key. -//! - Forcedly (requires sudo) changing the `TransferAccount`. -//! - Forcedly (requires sudo) removing the KILT balance lock. -//! -//! ### Terminology -//! -//! - **Lock:** A freeze on a specified amount of an account's free balance -//! until a specified block number. Multiple locks always operate over the -//! same funds, so they "overlay" rather than "stack". -//! -//! - **KILT balance lock:** A Lock with a KILT specific identifier which is -//! automatically removed when reaching the specified block number. -//! -//! - **Unowned account:** An endowed account for which potentially vesting or -//! the KILT balance lock is set up in the genesis block. -//! -//! - **User-owned account:** A regular account which was created by an entity -//! which wants to claim their tokens (potentially with vesting/KILT balance -//! lock) from an unowned account. -//! -//! ## Interface -//! -//! ### Dispatchable Functions -//! -//! - `migrate_genesis_account` - Migrate vesting or the KILT balance lock from -//! an unowned account to a user-owned account. Requires signature of a -//! special account `TransferAccount` which does not have any other super -//! powers. -//! - `migrate_multiple_genesis_accounts` - Migrate vesting or the KILT balance -//! lock from a list of unowned accounts to the same target user-owned -//! account. Requires signature of a special account `TransferAccount` which -//! does not have any other super powers. -//! - `locked_transfer` - Transfer locked tokens from one user-owned account to -//! another user-owned account. This will be made available shortly before -//! removing the sudo key because the purpose of the lock to disable -//! transferability of the amount. -//! - `change_transfer_account` - Change the transfer account. Can only be -//! called by sudo. -//! - `force_unlock` - Remove all locks for a given block. Can only be called by -//! sudo. -//! -//! ## Genesis config -//! -//! The KiltLaunch pallet depends on the [`GenesisConfig`]. -//! -//! ## Assumptions -//! -//! * All accounts provided with balance and potentially vesting or a KILT -//! balance lock in the genesis block are not owned by anyone and have to be -//! migrated to accounts which are owned by users. -//! * All unowned accounts have either vesting, the KILT balance lock or neither -//! of both. This assumption is neither checked, nor forced, nor does any code -//! break if it does not hold true. -//! * Vesting starts at genesis block for all unowned addresses which should be -//! migrated to user-owned accounts. This assumption is checked during -//! migration. -//! * All KILT balance locks end at the same block for all unowned addresses -//! which should be migrated to user-owned accounts. This assumption is -//! checked during migration and locked transfer. -//! * The total number of accounts for which a KILT balance lock is set up is at -//! most `MaxClaims`, for us it will be ~6. This assumption is not checked -//! when appending to `UnlockedAt`. - -#![cfg_attr(not(feature = "std"), no_std)] -#![allow(clippy::unused_unit)] - -pub use pallet::*; -#[cfg(test)] -mod mock; - -#[cfg(test)] -mod tests; - -#[cfg(feature = "runtime-benchmarks")] -pub mod benchmarking; -pub mod default_weights; - -#[frame_support::pallet] -pub mod pallet { - use super::*; - pub use crate::default_weights::WeightInfo; - #[cfg(feature = "std")] - use frame_support::traits::GenesisBuild; - use frame_support::{ - dispatch::DispatchResultWithPostInfo, - inherent::Vec, - pallet_prelude::*, - sp_runtime::traits::{StaticLookup, Zero}, - storage::types::StorageMap, - traits::{ - Currency, ExistenceRequirement::AllowDeath, Get, LockIdentifier, LockableCurrency, StorageVersion, - WithdrawReasons, - }, - transactional, BoundedVec, PalletId, - }; - use frame_system::pallet_prelude::*; - use pallet_balances::{BalanceLock, Locks}; - use pallet_vesting::{MaxVestingSchedulesGet, Vesting, VestingInfo}; - use scale_info::TypeInfo; - use sp_runtime::traits::{AccountIdConversion, CheckedDiv, Convert, SaturatedConversion, Saturating}; - use sp_std::{ - convert::{TryFrom, TryInto}, - vec, - }; - - /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); - - pub const KILT_LAUNCH_ID: LockIdentifier = *b"kiltlnch"; - pub const VESTING_ID: LockIdentifier = *b"vesting "; - - #[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo, MaxEncodedLen)] - #[scale_info(skip_type_params(T))] - #[codec(mel_bound())] - pub struct LockedBalance { - pub block: ::BlockNumber, - pub amount: ::Balance, - } - - #[pallet::config] - pub trait Config: frame_system::Config + pallet_balances::Config + pallet_vesting::Config { - /// Because this pallet emits events, it depends on the runtime's - /// definition of an event. - type Event: From> + IsType<::Event>; - - /// Maximum number of claims which can be migrated in a single call. - /// Used for weight estimation. - /// - /// Note: Benchmarks will need to be re-run and weights adjusted if this - /// changes. - #[pallet::constant] - type MaxClaims: Get; - - /// Maximum number of accounts that get unlocked in a single block. - #[pallet::constant] - type AutoUnlockBound: Get; - - /// Amount of Balance which will be made available for each account - /// which has either vesting or locking such that transaction fees can - /// be paid from this. - #[pallet::constant] - type UsableBalance: Get<::Balance>; - - /// The kilt launch's pallet id, used for deriving its sovereign account - /// ID. - #[pallet::constant] - type PalletId: Get; - - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; - } - - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - #[pallet::storage_version(STORAGE_VERSION)] - pub struct Pallet(_); - - #[pallet::genesis_config] - pub struct GenesisConfig { - pub balance_locks: Vec<(T::AccountId, T::BlockNumber, ::Balance)>, - pub transfer_account: T::AccountId, - pub vesting: Vec<(T::AccountId, T::BlockNumber, BalanceOf)>, - } - - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - Self { - balance_locks: Default::default(), - transfer_account: Pallet::::account_id(), - vesting: Default::default(), - } - } - } - - // Balance type based on pallet_vesting - pub type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { - fn build(&self) { - // Generate initial custom locking configuration - // * who - Account which we are setting the custom lock for - // * length - Number of blocks from until removal of the lock - // * locked - Number of tokens which are locked - for (ref who, length, locked) in self.balance_locks.iter() { - if !length.is_zero() { - let balance = >::free_balance(who); - assert!(!balance.is_zero(), "Currencies must be init'd before locking"); - assert!( - balance >= *locked, - "Locked balance must not exceed total balance for address {:?}", - who.to_string() - ); - assert!( - !>::contains_key(who), - "Account with address {:?} must not occur twice in locking", - who.to_string() - ); - - // Add unlock block to storage - >::insert( - who, - LockedBalance:: { - block: *length, - amount: (*locked).saturating_sub(T::UsableBalance::get()), - }, - ); - // Instead of setting the lock now, we do so in - // `migrate_genesis_account`, see there for explanation - } - // Add all accounts to UnownedAccount storage - >::insert(&who, ()); - } - - // Generate initial vesting configuration, taken from pallet_vesting - // * who - Account which we are generating vesting configuration for - // * begin - Block when the account will start to vest - // * length - Number of blocks from `begin` until fully vested - for &(ref who, length, locked) in self.vesting.iter() { - if !length.is_zero() { - let balance = <::Currency as Currency< - ::AccountId, - >>::free_balance(who); - assert!(!balance.is_zero(), "Currencies must be init'd before vesting"); - assert!( - balance >= locked, - "Vested balance must not exceed total balance for address {:?}", - who.to_string() - ); - assert!( - !>::contains_key(who), - "Account with address {:?} must not occur twice in vesting", - who.to_string() - ); - - let length_as_balance = T::BlockNumberToBalance::convert(length); - let per_block = locked.checked_div(&length_as_balance).unwrap_or(locked); - - let vesting_info = VestingInfo::new(locked, per_block, T::BlockNumber::zero()); - Vesting::::try_append(who, vesting_info).expect("Too many vesting schedules at genesis"); - // Instead of setting the lock now, we do so in - // `migrate_genesis_account`, see there for explanation - } - // Add all accounts to UnownedAccount storage - >::insert(&who, ()); - } - - // Set the transfer account which has a subset of the powers of root - >::put(self.transfer_account.clone()); - } - } - - /// Account which is permitted to do token transfers in PoA phase. - /// - /// Required for the claiming process. - #[pallet::storage] - #[pallet::getter(fn get_transfer_account)] - pub type TransferAccount = StorageValue<_, ::AccountId>; - - /// Maps a block to account ids which have their balance locked. - /// - /// Required for automatic unlocking once the block number is reached in - /// `on_initialize`. - #[pallet::storage] - #[pallet::getter(fn get_unlocking_at)] - pub type UnlockingAt = StorageMap< - _, - Blake2_128Concat, - ::BlockNumber, - BoundedVec<::AccountId, ::AutoUnlockBound>, - >; - - /// Maps an account id to the (block, balance) pair in which the latter can - /// be unlocked. - /// - /// Required for the claiming process. - #[pallet::storage] - #[pallet::getter(fn get_unlocking_block)] - pub type BalanceLocks = - StorageMap<_, Blake2_128Concat, ::AccountId, LockedBalance>; - - /// Maps an unowned account id to an empty value which reflects whether it - /// is a genesis account which should be migrated, if it exists. - /// - /// Required for the claiming process. - #[pallet::storage] - #[pallet::getter(fn unowned_account)] - pub type UnownedAccount = - StorageMap<_, Blake2_128Concat, ::AccountId, (), OptionQuery>; - - #[pallet::event] - #[pallet::generate_deposit(pub fn deposit_event)] - pub enum Event { - /// A KILT balance lock has been removed in the corresponding block. - /// \[block, len\] - Unlocked(T::BlockNumber, u32), - /// An account transferred their locked balance to another account. - /// \[from, value, target\] - LockedTransfer(T::AccountId, T::Balance, T::AccountId), - /// A KILT balance lock has been set. \[who, value, until\] - AddedKiltLock(T::AccountId, T::Balance, T::BlockNumber), - /// Vesting has been added to an account. \[who, per_block, total\] - AddedVesting(T::AccountId, BalanceOf, BalanceOf), - } - - #[pallet::error] - pub enum Error { - /// The source address does not have KILT balance lock which is - /// required for `locked_transfer`. - BalanceLockNotFound, - /// The source and destination address have limits for their custom KILT - /// balance lock and thus cannot be merged. Should never be thrown. - ConflictingLockingBlocks, - /// The source and destination address differ in their vesting starting - /// blocks and thus cannot be merged. Should never be thrown. - ConflictingVestingStarts, - /// When migrating multiple accounts to the same target, the size of the - /// list of source addresses should never exceed `MaxClaims`. - MaxClaimsExceeded, - /// The source address does not have any balance lock at all which is - /// required for `locked_transfer`. - ExpectedLocks, - /// The source address has less balance available than the locked amount - /// which should be transferred in `locked_transfer`. - InsufficientBalance, - /// The source address has less locked balance than the amount which - /// should be transferred in `locked_transfer`. - InsufficientLockedBalance, - /// The source address is not a valid address which was set up as an - /// unowned account in the genesis build. - NotUnownedAccount, - /// The source address has more than one vesting scheme which should - /// only be a theoretical issue. - MultipleVestingSchemes, - /// The target address should not be the source address. - SameDestination, - /// The signing account is not the transfer account. - Unauthorized, - /// The source address has a balance lock and thus cannot be migrated. - UnexpectedLocks, - } - - #[pallet::hooks] - impl Hooks> for Pallet { - fn on_initialize(now: T::BlockNumber) -> Weight { - let locks = Self::unlock_balance(now); - if locks > 0 { - ::WeightInfo::on_initialize_unlock(locks) - } else { - ::WeightInfo::on_initialize_no_action() - } - } - } - - #[pallet::call] - impl Pallet { - /// Forcedly remove KILT balance locks via sudo for the specified block - /// number. - /// - /// The dispatch origin must be Root. - /// - /// Emits `Unlocked`. - /// - /// # - /// - The transaction's complexity is proportional to the size of - /// storage entries in `UnlockingAt` (N) which is practically uncapped - /// but in theory it should be `MaxClaims` at most. - /// --------- - /// Weight: O(N) where N is the number of accounts for which the lock - /// will be removed for the given block. - /// - Reads: UnlockingAt, [Origin Account] - /// - Kills: UnlockingAt (if N > 0), Locks (if N > 0), BalanceLocks (if - /// N > 0) - /// # - #[pallet::weight(::WeightInfo::force_unlock(T::MaxClaims::get()))] - pub fn force_unlock(origin: OriginFor, block: T::BlockNumber) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - - let weight = ::WeightInfo::force_unlock(Self::unlock_balance(block)); - - Ok(Some(weight).into()) - } - - /// Forcedly change the transfer account to the specified account. - /// - /// The dispatch origin must be Root. - /// - /// # - /// Weight: O(1) - /// - Reads: [Origin Account] - /// - Writes: TransferAccount - /// # - #[pallet::weight(::WeightInfo::change_transfer_account())] - pub fn change_transfer_account( - origin: OriginFor, - transfer_account: ::Source, - ) -> DispatchResult { - ensure_root(origin)?; - let transfer_account = T::Lookup::lookup(transfer_account)?; - - >::put(transfer_account); - - Ok(()) - } - - /// Transfer tokens and vesting information or the KILT balance lock - /// from an unowned source address to an account owned by the target. - /// - /// If vesting info or a KILT balance lock has been set up for the - /// source account in the genesis block via `GenesisBuild`, then - /// the corresponding locked/vested information and balance is migrated - /// automatically. Please note that even though this extrinsic supports - /// migrating both the KILT balance lock as well as vesting in one call, - /// all source accounts should only contain either a KILT balance lock - /// or vesting. - /// - /// Additionally, for vesting we already unlock the - /// usable balance until the current block. This should enable the user - /// to pay the transaction fees for the next call of `vest` which is - /// always required to be explicitly called in order to unlock (more) - /// balance from vesting. - /// - /// NOTE: Setting the KILT balance lock actually only occurs in this - /// call (and not when building the genesis block in `GenesisBuild`) to - /// avoid overhead from handling locks when migrating. We can do so - /// because all target accounts are not owned by anyone and thus these - /// cannot sign and/or call any extrinsics. - /// - /// The dispatch origin must be TransferAccount. - /// - /// Emits either `AddedVesting` or `AddedKiltLock`. - /// - /// # - /// Weight: O(1) - /// - Reads: [Origin Account], TransferAccount, Locks, Balance, Vesting, - /// BalanceLocks - /// - Writes: Locks, Balance, UnownedAccount, Vesting (if source is - /// vesting), BalanceLocks (if source is locking), UnlockingAt (if - /// source is locking) - /// - Kills (for source): Locks, Balance, UnownedAccount, Vesting (if - /// source is vesting), BalanceLocks (if source is locking) - /// # - #[pallet::weight(::WeightInfo::migrate_genesis_account_vesting().max(::WeightInfo::migrate_genesis_account_locking()))] - #[transactional] - pub fn migrate_genesis_account( - origin: OriginFor, - source: ::Source, - target: ::Source, - ) -> DispatchResultWithPostInfo { - let who = ensure_signed(origin)?; - - // The extrinsic has to be called by the TransferAccount - ensure!(Some(who) == >::get(), Error::::Unauthorized); - - let source = T::Lookup::lookup(source)?; - let target = T::Lookup::lookup(target)?; - - ensure!(source != target, Error::::SameDestination); - ensure!( - >::contains_key(&source), - Error::::NotUnownedAccount - ); - - Ok(Some(Self::migrate_user(&source, &target)?).into()) - } - - /// Transfer all balances, vesting information and KILT balance locks - /// from multiple source addresses to the same target address. - /// - /// See `migrate_genesis_account` for details as we run the same logic - /// for each source address. - /// - /// The dispatch origin must be TransferAccount. - /// - /// Emits N events which are either `AddedVesting` or `AddedKiltLock`. - /// - /// # - /// - The transaction's complexity is proportional to the size of - /// `sources` (N) which is capped at CompactAssignments::LIMIT - /// (MaxClaims) - /// --------- - /// Weight: O(N) where N is the number of source addresses. - /// - Reads: [Origin Account], TransferAccount, UnownedAccount, Locks, - /// Balance, Vesting, BalanceLocks - /// - Writes: Locks, Balance, Vesting (if any source is vesting), - /// BalanceLocks (if aby source is locking), UnlockingAt (if any - /// source is locking) - /// - Kills (for sources): Locks, Balance, UnownedAccount, Vesting (if - /// any source is vesting), BalanceLocks (if any source is locking) - /// # - #[pallet::weight(::WeightInfo::migrate_multiple_genesis_accounts_vesting(T::MaxClaims::get()).max(::WeightInfo::migrate_multiple_genesis_accounts_locking(T::MaxClaims::get())))] - #[transactional] - pub fn migrate_multiple_genesis_accounts( - origin: OriginFor, - sources: Vec<::Source>, - target: ::Source, - ) -> DispatchResultWithPostInfo { - let who = ensure_signed(origin)?; - let target = T::Lookup::lookup(target)?; - - // The extrinsic has to be called by the TransferAccount - ensure!(Some(who) == >::get(), Error::::Unauthorized); - - ensure!( - sources.len() < T::MaxClaims::get().saturated_into::(), - Error::::MaxClaimsExceeded - ); - - let mut post_weight: Weight = 0; - for s in sources.clone().into_iter() { - let source = T::Lookup::lookup(s)?; - ensure!(source != target, Error::::SameDestination); - ensure!( - >::contains_key(&source), - Error::::NotUnownedAccount - ); - post_weight += Self::migrate_user(&source, &target)?; - } - - Ok(Some(post_weight).into()) - } - - /// Transfer KILT locked tokens to another account similar to - /// `pallet_vesting::vested_transfer`. - /// - /// Expects the source to have a KILT balance lock and at least the - /// specified amount available as balance locked with LockId - /// `KILT_LAUNCH_ID`. - /// - /// Calls `migrate_kilt_balance_lock` internally. - /// - /// Emits `LockedTransfer` and if target does not have KILT balance - /// lockup prior to transfer `AddedKiltLock`. - /// - /// # - /// Weight: O(1) - /// - Reads: [Origin Account], Locks, Balance, BalanceLocks, UnlockingAt - /// - Writes: Locks, Balance, BalanceLocks, UnlockingAt - /// - Kills (if source transfers all locked balance): Locks, - /// BalanceLocks, UnlockingAt - /// # - #[pallet::weight(::WeightInfo::locked_transfer())] - #[transactional] - pub fn locked_transfer( - origin: OriginFor, - target: ::Source, - amount: ::Balance, - ) -> DispatchResultWithPostInfo { - let source = ensure_signed(origin)?; - let target = T::Lookup::lookup(target)?; - - ensure!(target != source, Error::::SameDestination); - - // The correct check would be `ensure_can_withdraw` but since we expect `amount` - // to be locked, we just check the total balance until we remove the lock below - ensure!( - >::total_balance(&source) >= amount, - Error::::InsufficientBalance - ); - ensure!( - >::get(&source).is_some(), - Error::::BalanceLockNotFound - ); - - let locks = Locks::::get(&source); - ensure!(!locks.is_empty(), Error::::ExpectedLocks); - - if let Some(lock) = locks - .iter() - .find(|BalanceLock::<::Balance> { id, .. }| id == &KILT_LAUNCH_ID) - { - ensure!(lock.amount >= amount, Error::::InsufficientLockedBalance); - - // We can subtract because of the above check, but let's be safe - let amount_new = lock.amount.saturating_sub(amount); - - if amount_new <= T::ExistentialDeposit::get() { - // If the lock equals the ExistentialDeposit, we want to remove the lock because - // if amount_new == 0, `set_lock` would be no-op - >::remove_lock(KILT_LAUNCH_ID, &source); - - // Transfer amount + dust to target - as Currency>::transfer( - &source, - &target, - lock.amount, - AllowDeath, - )?; - } else { - // Reduce source's lock amount to enable token transfer - >::set_lock(KILT_LAUNCH_ID, &source, amount_new, WithdrawReasons::all()); - - // Transfer amount to target - as Currency>::transfer( - &source, &target, amount, AllowDeath, - )?; - } - - Self::deposit_event(Event::LockedTransfer(source.clone(), amount, target.clone())); - - // Set locks in target and remove/update storage entries for source - Ok(Some(Self::migrate_kilt_balance_lock(&source, &target, Some(amount))?).into()) - } else { - Err(Error::::BalanceLockNotFound.into()) - } - } - } - - impl Pallet { - /// The account ID of the initial accounts. - /// - /// This actually does computation. If you need to keep using it, then - /// make sure you cache the value and only call this once. - pub fn account_id() -> T::AccountId { - T::PalletId::get().into_account() - } - - /// Remove KILT balance locks for the specified block - fn unlock_balance(block: T::BlockNumber) -> u32 { - if let Some(unlocking_balance) = >::take(block) { - // Remove locks for all accounts - for account in unlocking_balance.iter() { - >::remove_lock(KILT_LAUNCH_ID, account); - >::remove(account); - } - - Self::deposit_event(Event::Unlocked(block, unlocking_balance.len().saturated_into::())); - // Safe because the vec is bound by an u32 - unlocking_balance.len().saturated_into::() - } else { - 0 - } - } - - /// Transfers all balance of the source to the target address and sets - /// up vesting or the KILT balance lock if any of the two were set up - /// for the source address. - /// - /// Note: Expects the source address to be an unowned address which was - /// set up in the genesis block via `GenesisBuild` and should be claimed - /// by a user to migrate to their account. - fn migrate_user(source: &T::AccountId, target: &T::AccountId) -> Result { - // There should be no locks for the source address - ensure!(Locks::::get(source).len().is_zero(), Error::::UnexpectedLocks); - - // Transfer to target address - let amount = >::total_balance(source); - as Currency>::transfer(source, target, amount, AllowDeath)?; - - // Migrate vesting info and set the corresponding vesting lock if necessary - let mut post_weight: Weight = Self::migrate_vesting(source, target)?; - - // Set the KILT custom lock if necessary - post_weight += Self::migrate_kilt_balance_lock(source, target, None)?; - - >::remove(&source); - post_weight += T::DbWeight::get().writes(1); - - Ok(post_weight) - } - - /// Migrate the vesting schedule from one account to another, if it was - /// set in the genesis block via `GenesisBuild`, and set the - /// corresponding vesting lock. - /// - /// We already unlock all available funds between the starting and the - /// current block. This enables the user to be able to pay for - /// transactions. One of these would be `pallet_vesting::vest()` which - /// has to be called actively to unlock more of the vested funds. - fn migrate_vesting(source: &T::AccountId, target: &T::AccountId) -> Result { - let source_vesting = if let Some(source_vesting) = Vesting::::take(source).unwrap_or_default().get(0) { - *source_vesting - } else { - return Ok(T::DbWeight::get().reads(1)); - }; - - // Check for an already existing vesting schedule for the target account - // which would be the case if the claimer requests migration from multiple - // source accounts to the same target - ensure!( - Vesting::::decode_len(&target).unwrap_or_default() <= 1, - Error::::MultipleVestingSchemes - ); - - let vesting = - if let Some(target_vesting) = Vesting::::take(&target).unwrap_or_default().into_inner().first() { - // Should never return an error all source accounts start vesting in genesis - // block - ensure!( - target_vesting.starting_block() == source_vesting.starting_block(), - Error::::ConflictingVestingStarts - ); - // We can simply sum `locked` and `per_block` because of the above requirement - VestingInfo::, T::BlockNumber>::new( - target_vesting.locked().saturating_add(source_vesting.locked()), - target_vesting.per_block().saturating_add(source_vesting.per_block()), - target_vesting.starting_block(), - ) - } else { - // If vesting hasn't been set up for target account, we can default to the one - // of the source account - source_vesting - }; - let bv = - BoundedVec::, T::BlockNumber>, MaxVestingSchedulesGet>::try_from(vec![ - vesting, - ]) - .map_err(|_| pallet_vesting::Error::::AtMaxVestingSchedules)?; - Vesting::::insert(target, bv); - // Only lock funds from now until vesting expires. - // Enables the user to have funds before actively calling `vest` if claimed - // after the genesis block. - // - // Logic was taken from pallet_vesting. - - // Disallow transfers and reserves from vested tokens which are still locked - let reasons = WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE; - let now = >::block_number(); - let locked_now = vesting.locked_at::<::BlockNumberToBalance>(now); - <::Currency as LockableCurrency>::set_lock( - VESTING_ID, target, locked_now, reasons, - ); - Self::deposit_event(Event::AddedVesting( - target.clone(), - vesting.per_block(), - vesting.locked(), - )); - Ok(::WeightInfo::migrate_genesis_account_vesting()) - } - - /// Set the KILT balance lock for the target address which should - /// always be a user-owned account address. - /// - /// Can be called during the migration of unowned "genesis" addresses to - /// user-owned account addresses in `migrate_user` as well when an - /// account wants to transfer their locked tokens to another account in - /// `locked_transfer`. - fn migrate_kilt_balance_lock( - source: &T::AccountId, - target: &T::AccountId, - // Only used for `locked_transfer`, e.g., it is `None` for migration - max_amount: Option<::Balance>, - ) -> Result { - let LockedBalance:: { - block: unlock_block, - amount: source_amount, - } = if let Some(lock) = >::get(&source) { - lock - } else { - return Ok(T::DbWeight::get().reads(1)); - }; - - // In case of a `locked_transfer`, we might only want to unlock a certain amount - // Otherwise, this will always be the source's locked amount - let max_add_amount = source_amount.min(max_amount.unwrap_or(source_amount)); - - // We don't need to transfer any locks if the lock already expired. So we bail - // early - if unlock_block <= frame_system::Pallet::::block_number() { - // But we still need to reduce the old lock or remove it, if it's consumed - // completely. - if max_add_amount == source_amount { - >::remove(&source); - } else { - >::insert( - &source, - LockedBalance:: { - block: unlock_block, - amount: source_amount.saturating_sub(max_add_amount), - }, - ) - } - return Ok(T::DbWeight::get().reads(1)); - } - - // Check for an already existing KILT balance lock on the target - // account which would be the case if the claimer requests migration from - // multiple source accounts to the same target - let target_amount = if let Some(target_lock) = >::take(&target) { - // Should never throw because there is a single locking period (6 months) - ensure!(target_lock.block == unlock_block, Error::::ConflictingLockingBlocks); - - // We don't need to append `UnlockingAt` because we require both locks to end at - // the same block - // We can simply sum `amount` because of the above requirement and the check - // that source != target in the corresponding extrinsics - target_lock.amount.saturating_add(max_add_amount) - } else { - // If no custom lock has been set up for target account, we can default to the - // one of the source account and append it to `UnlockingAt` - >::try_append(unlock_block, &target).map_err(|_| Error::::MaxClaimsExceeded)?; - max_add_amount - }; - - // Set target lock in case another account should be migrated to this target - // address at a later stage - >::insert( - target, - LockedBalance:: { - amount: target_amount, - block: unlock_block, - }, - ); - // Disallow anything from being paid by custom lock - >::set_lock(KILT_LAUNCH_ID, target, target_amount, WithdrawReasons::all()); - - // Update or remove lock storage items corresponding to the source address - if max_add_amount == source_amount { - >::remove(&source); - - // Only needs to be handled in the case of a `locked_transfer`, e.g., when - // `max_amount` is set because else the source address is never added to - // `UnlockingAt` - if max_amount.is_some() { - >::try_mutate(unlock_block, |maybe_bv| -> DispatchResult { - if let Some(bv) = maybe_bv { - *bv = bv - .clone() - .into_inner() - .into_iter() - .filter(|acc_id| acc_id != source) - .collect::>() - .try_into() - .map_err(|_| Error::::MaxClaimsExceeded)? - } - Ok(()) - })?; - } - } else { - // Reduce the locked amount - // - // Note: The update of the real balance lock with id `KILT_LAUNCH_ID` already - // happens in `locked_transfer` because it is required for the token transfer - >::insert( - &source, - LockedBalance:: { - block: unlock_block, - amount: source_amount.saturating_sub(max_add_amount), - }, - ) - } - - Self::deposit_event(Event::AddedKiltLock(target.clone(), target_amount, unlock_block)); - Ok(::WeightInfo::migrate_genesis_account_locking()) - } - } -} diff --git a/pallets/kilt-launch/src/mock.rs b/pallets/kilt-launch/src/mock.rs deleted file mode 100644 index 74f7050860..0000000000 --- a/pallets/kilt-launch/src/mock.rs +++ /dev/null @@ -1,380 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain 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. - -// The KILT Blockchain 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 . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -#![allow(clippy::from_over_into)] - -use crate as kilt_launch; -use frame_support::{assert_noop, assert_ok, parameter_types, traits::GenesisBuild, PalletId}; -use frame_system as system; -use pallet_balances::{BalanceLock, Locks, Reasons}; -use pallet_vesting::VestingInfo; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, ConvertInto, IdentifyAccount, IdentityLookup, Verify, Zero}, - AccountId32, MultiSignature, -}; - -pub(crate) type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -pub(crate) type Block = frame_system::mocking::MockBlock; -pub(crate) type Hash = sp_core::H256; -pub(crate) type Balance = u128; -pub(crate) type Signature = MultiSignature; -pub(crate) type AccountPublic = ::Signer; -pub(crate) type AccountId = ::AccountId; -pub(crate) type Index = u64; -pub(crate) type BlockNumber = u64; - -pub const MILLI_KILT: Balance = 10u128.pow(12); - -pub const PSEUDO_1: AccountId = AccountId32::new([1u8; 32]); -pub const PSEUDO_2: AccountId = AccountId32::new([2u8; 32]); -pub const PSEUDO_3: AccountId = AccountId32::new([3u8; 32]); -pub const PSEUDO_4: AccountId = AccountId32::new([4u8; 32]); -pub const USER: AccountId = AccountId32::new([10u8; 32]); -pub const TRANSFER_ACCOUNT: AccountId = AccountId32::new([100u8; 32]); - -// Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - Balances: pallet_balances::{Pallet, Call, Config, Storage, Event}, - KiltLaunch: kilt_launch::{Pallet, Call, Config, Storage, Event}, - Vesting: pallet_vesting::{Pallet, Call, Config, Storage, Event}, - } -); - -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 38; -} - -impl system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Origin = Origin; - type Call = Call; - type Index = Index; - type BlockNumber = BlockNumber; - type Hash = Hash; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - 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>; -} - -parameter_types! { - pub const ExistentialDeposit: Balance = 500; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - -impl pallet_balances::Config for Test { - type MaxLocks = MaxLocks; - type MaxReserves = MaxReserves; - type ReserveIdentifier = [u8; 8]; - /// The type for recording an account's balance. - type Balance = Balance; - /// The ubiquitous event type. - type Event = Event; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} - -parameter_types! { - pub const MaxClaims: u32 = 4; - pub const UsableBalance: Balance = 1; - pub const AutoUnlockBound: u32 = 70; -} - -parameter_types! { - pub const LaunchPalletId: PalletId = PalletId(*b"kilt/lch"); -} - -impl kilt_launch::Config for Test { - type Event = Event; - type MaxClaims = MaxClaims; - type UsableBalance = UsableBalance; - type AutoUnlockBound = AutoUnlockBound; - type WeightInfo = (); - type PalletId = LaunchPalletId; -} - -parameter_types! { - pub const MinVestedTransfer: Balance = 100 * MILLI_KILT; -} - -impl pallet_vesting::Config for Test { - type Event = Event; - type Currency = Balances; - type BlockNumberToBalance = ConvertInto; - // disable vested transfers by setting min amount to max balance - type MinVestedTransfer = MinVestedTransfer; - type WeightInfo = (); - const MAX_VESTING_SCHEDULES: u32 = 28; -} - -#[derive(Default)] -pub struct ExtBuilder { - balance_locks: Vec<(AccountId, BlockNumber, Balance)>, - vesting: Vec<(AccountId, BlockNumber, Balance)>, -} - -/// Calls `migrate_genesis_account` and checks whether balance, vesting and -/// balance locks have been migrated properly to the destination address. -pub fn ensure_single_migration_works( - source: &AccountId, - dest: &AccountId, - vesting_info: Option>, - locked_info: Option<(kilt_launch::LockedBalance, Balance)>, -) { - assert_noop!( - KiltLaunch::migrate_genesis_account(Origin::signed(PSEUDO_1), source.to_owned(), dest.to_owned()), - kilt_launch::Error::::Unauthorized - ); - assert_ok!(KiltLaunch::migrate_genesis_account( - Origin::signed(TRANSFER_ACCOUNT), - source.to_owned(), - dest.to_owned() - )); - let now: BlockNumber = System::block_number(); - - // Check for desired death of allocation account - assert!(Balances::free_balance(source).is_zero()); - assert!(Vesting::vesting(source).is_none()); - assert!(kilt_launch::BalanceLocks::::get(source).is_none()); - assert!(!frame_system::Account::::contains_key(source)); - - // Check storage migration to dest - let mut locked_balance: Balance = Balance::zero(); - let mut num_of_locks = 0; - if let Some(vesting) = vesting_info { - assert_eq!( - Vesting::vesting(dest) - .expect("missing vesting info") - .into_inner() - .get(0), - Some(&vesting) - ); - locked_balance = vesting.locked(); - num_of_locks += 1; - } - if let Some((lock, _)) = locked_info.clone() { - // only if the lock is not expired, it should show up here - if lock.block > now { - assert_eq!(kilt_launch::BalanceLocks::::get(dest), Some(lock.clone())); - assert_eq!( - kilt_launch::UnlockingAt::::get(lock.block) - .unwrap_or_default() - .into_inner(), - vec![dest.to_owned()] - ); - locked_balance = locked_balance.max(lock.amount); - num_of_locks += 1; - } - } - - // Check correct setting of locks for dest - let balance_locks = Locks::::get(dest); - let mut fee_balance: Balance = Balance::zero(); - let mut maybe_balance: Balance = Balance::zero(); - let mut usable_balance: Balance = Balance::zero(); - assert_eq!(balance_locks.len(), num_of_locks); - for BalanceLock { id, amount, reasons } in balance_locks { - match id { - crate::VESTING_ID => { - let vesting = vesting_info.expect("No vesting schedule found"); - fee_balance = vesting.locked(); - usable_balance = vesting.per_block(); - assert_eq!(reasons, Reasons::Misc); - } - crate::KILT_LAUNCH_ID => { - let (lock, add) = locked_info.clone().expect("No vesting schedule found"); - assert_eq!(amount, lock.amount); - assert_eq!(reasons, Reasons::All); - maybe_balance = add + ::UsableBalance::get(); - } - _ => panic!("Unexpected balance lock id {:?}", id), - }; - } - - if num_of_locks > 0 { - assert_noop!( - KiltLaunch::migrate_genesis_account(Origin::signed(TRANSFER_ACCOUNT), dest.to_owned(), TRANSFER_ACCOUNT), - kilt_launch::Error::::NotUnownedAccount - ); - } - - // TODO: Add positive check for staking once it has been added - - // Check correct migration of balance - // In our tests, vesting and locking is not resolved before the 10th block. At - // most times, now should be the first block. - if now < 10 { - // locked balance should be free - // custom locks: + UsableBalance - assert_eq!(Balances::free_balance(dest), locked_balance + maybe_balance); - // balance which is usable for fees - // vesting: locked_balance - // custom lock: UsableBalance - assert_eq!(Balances::usable_balance_for_fees(dest), fee_balance + maybe_balance); - // balance which is usable for anything but fees and other - // vesting: per_block * now - // locks custom locked: UsableBalance - assert_eq!(Balances::usable_balance(dest), usable_balance + maybe_balance); - // there should be nothing reserved - assert!(Balances::reserved_balance(dest).is_zero()); - - // Should not be able to transfer more than which is unlocked in first block - assert_noop!( - Balances::transfer( - Origin::signed(dest.to_owned()), - TRANSFER_ACCOUNT, - usable_balance + maybe_balance + 1 - ), - pallet_balances::Error::::LiquidityRestrictions - ); - } - - assert!(kilt_launch::UnownedAccount::::get(source).is_none()); -} - -// Checks whether the usable balance meets the expectations and if exists, if it -// can be transferred which we expect once locks are removed -pub fn assert_balance(who: AccountId, free: Balance, usable_for_fees: Balance, usable: Balance, do_transfer: bool) { - // Check balance after unlocking - assert_eq!(Balances::free_balance(&who), free); - // locked balance should be usable for fees - assert_eq!(Balances::usable_balance_for_fees(&who), usable_for_fees); - // locked balance should not be usable for anything but fees and other locks - assert_eq!(Balances::usable_balance(&who), usable); - // there should be nothing reserved - assert!(Balances::reserved_balance(&who).is_zero()); - - if do_transfer && usable > ExistentialDeposit::get() { - // Should be able to transfer all tokens but ExistentialDeposit - assert_ok!(Balances::transfer( - Origin::signed(who), - TRANSFER_ACCOUNT, - usable - ExistentialDeposit::get() - )); - } -} - -impl ExtBuilder { - #[must_use] - pub fn vest(mut self, vesting: Vec<(AccountId, BlockNumber, Balance)>) -> Self { - self.vesting = vesting; - self - } - - #[must_use] - pub fn pseudos_vest_all(self) -> Self { - self.vest(vec![ - (PSEUDO_1, 10, 10_000), - (PSEUDO_2, 20, 10_000), - (PSEUDO_3, 30, 300_000), - ]) - } - - #[must_use] - pub fn lock_balance(mut self, balance_locks: Vec<(AccountId, BlockNumber, Balance)>) -> Self { - self.balance_locks = balance_locks; - self - } - - pub fn pseudos_lock_something(self) -> Self { - self.lock_balance(vec![(PSEUDO_1, 100, 1111), (PSEUDO_2, 1337, 2222)]) - } - - #[must_use] - pub fn pseudos_lock_all(self) -> Self { - self.lock_balance(vec![ - (PSEUDO_1, 100, 10_000), - (PSEUDO_2, 1337, 10_000), - (PSEUDO_3, 100, 300_000), - ]) - } - - pub fn build(self) -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![ - (PSEUDO_1, 10_000), - (PSEUDO_2, 10_000), - (PSEUDO_3, 300_000), - (PSEUDO_4, 10_000), - (TRANSFER_ACCOUNT, 10_000), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - - kilt_launch::GenesisConfig:: { - balance_locks: self.balance_locks, - vesting: self.vesting, - transfer_account: TRANSFER_ACCOUNT, - } - .assimilate_storage(&mut t) - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext - } - - pub fn build_panic( - self, - balances: Vec<(AccountId, Balance)>, - balance_locks: Vec<(AccountId, BlockNumber, Balance)>, - vesting: Vec<(AccountId, BlockNumber, Balance)>, - ) { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - - pallet_balances::GenesisConfig:: { balances } - .assimilate_storage(&mut t) - .unwrap(); - - kilt_launch::GenesisConfig:: { - balance_locks, - vesting, - transfer_account: TRANSFER_ACCOUNT, - } - .assimilate_storage(&mut t) - .unwrap() - } -} diff --git a/pallets/kilt-launch/src/tests.rs b/pallets/kilt-launch/src/tests.rs deleted file mode 100644 index 204673b5bd..0000000000 --- a/pallets/kilt-launch/src/tests.rs +++ /dev/null @@ -1,720 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain 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. - -// The KILT Blockchain 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 . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -use crate::{ - mock::*, BalanceLocks, Error, LockedBalance, TransferAccount, UnlockingAt, UnownedAccount, KILT_LAUNCH_ID, - VESTING_ID, -}; - -use frame_support::{ - assert_noop, assert_ok, - traits::{Currency, LockableCurrency, OnInitialize, WithdrawReasons}, -}; -use pallet_balances::{BalanceLock, Locks, Reasons}; -use pallet_vesting::{Vesting as VestingStorage, VestingInfo}; -use sp_runtime::traits::Zero; - -#[test] -fn check_build_genesis_config() { - ExtBuilder::default() - .pseudos_vest_all() - .pseudos_lock_something() - .build() - .execute_with(|| { - // Check balances - assert_eq!(Balances::free_balance(&PSEUDO_1), 10_000); - assert_eq!(Balances::free_balance(&PSEUDO_2), 10_000); - assert_eq!(Balances::free_balance(&PSEUDO_3), 300_000); - // Locked balance should be usable for fees - assert_eq!(Balances::usable_balance_for_fees(&PSEUDO_1), 10_000); - assert_eq!(Balances::usable_balance_for_fees(&PSEUDO_2), 10_000); - assert_eq!(Balances::usable_balance_for_fees(&PSEUDO_3), 300_000); - // There should be nothing reserved - assert_eq!(Balances::reserved_balance(&PSEUDO_1), 0); - assert_eq!(Balances::reserved_balance(&PSEUDO_2), 0); - assert_eq!(Balances::reserved_balance(&PSEUDO_3), 0); - - // Check vesting - - // Vesting over 10 blocks - let pseudo_1_vesting = VestingInfo::new(10_000, 1000, 0); - // Vesting over 20 blocks - let pseudo_2_vesting = VestingInfo::new(10_000, 500, 0); - // Vesting over 20 blocks - let pseudo_3_vesting = VestingInfo::new(300_000, 10_000, 0); - assert_eq!( - Vesting::vesting(&PSEUDO_1) - .expect("Missing vesting info") - .into_inner() - .get(0), - Some(&pseudo_1_vesting) - ); - assert_eq!( - Vesting::vesting(&PSEUDO_2) - .expect("Missing vesting info") - .into_inner() - .get(0), - Some(&pseudo_2_vesting) - ); - assert_eq!( - Vesting::vesting(&PSEUDO_3) - .expect("Missing vesting info") - .into_inner() - .get(0), - Some(&pseudo_3_vesting) - ); - - // Check balance locks - let pseudo_1_lock = LockedBalance:: { - block: 100, - amount: 1111 - ::UsableBalance::get(), - }; - let pseudo_2_lock = LockedBalance:: { - block: 1337, - amount: 2222 - ::UsableBalance::get(), - }; - assert_eq!(BalanceLocks::::get(&PSEUDO_1), Some(pseudo_1_lock)); - assert_eq!(BalanceLocks::::get(&PSEUDO_2), Some(pseudo_2_lock)); - assert!(BalanceLocks::::get(&PSEUDO_3).is_none()); - assert!(UnlockingAt::::get(100).is_none()); - assert!(UnlockingAt::::get(1337).is_none()); - - // Ensure there are no locks on pseudo accounts - assert!(Locks::::get(&PSEUDO_1).len().is_zero()); - assert!(Locks::::get(&PSEUDO_2).len().is_zero()); - assert!(Locks::::get(&PSEUDO_3).len().is_zero()); - - // Ensure all pseudo accounts are unowned accounts - assert!(UnownedAccount::::get(&PSEUDO_1).is_some()); - assert!(UnownedAccount::::get(&PSEUDO_2).is_some()); - assert!(UnownedAccount::::get(&PSEUDO_3).is_some()); - }); - - // check only vesting - ExtBuilder::default().pseudos_vest_all().build().execute_with(|| { - assert!(UnownedAccount::::get(&PSEUDO_1).is_some()); - assert!(UnownedAccount::::get(&PSEUDO_2).is_some()); - assert!(UnownedAccount::::get(&PSEUDO_3).is_some()); - }); - - // check only locks - ExtBuilder::default().pseudos_lock_all().build().execute_with(|| { - assert!(UnownedAccount::::get(&PSEUDO_1).is_some()); - assert!(UnownedAccount::::get(&PSEUDO_2).is_some()); - assert!(UnownedAccount::::get(&PSEUDO_3).is_some()); - }); - - // check lengths of 0 - ExtBuilder::default() - .vest(vec![(PSEUDO_1, 0, 100)]) - .lock_balance(vec![(PSEUDO_2, 0, 100)]) - .build() - .execute_with(|| { - assert!(UnownedAccount::::get(&PSEUDO_1).is_some()); - assert!(UnownedAccount::::get(&PSEUDO_2).is_some()); - }); -} - -#[test] -fn check_migrate_single_account_locked() { - ExtBuilder::default().pseudos_lock_all().build().execute_with(|| { - assert_noop!( - KiltLaunch::migrate_genesis_account(Origin::signed(TRANSFER_ACCOUNT), PSEUDO_1, PSEUDO_1), - Error::::SameDestination - ); - assert_noop!( - KiltLaunch::migrate_genesis_account(Origin::signed(TRANSFER_ACCOUNT), USER, PSEUDO_1), - Error::::NotUnownedAccount - ); - - let user_locked_info = LockedBalance { - block: 100, - amount: 10_000 - ::UsableBalance::get(), - }; - // Migration of balance locks - ensure_single_migration_works(&PSEUDO_1, &USER, None, Some((user_locked_info, 0))); - - // Reach balance lock limit - System::set_block_number(100); - >::on_initialize(System::block_number()); - assert!(UnlockingAt::::get(100).is_none()); - assert!(Locks::::get(&USER).len().is_zero()); - - // Should be able to transfer all tokens but ExistentialDeposit - assert_ok!(Balances::transfer( - Origin::signed(USER), - PSEUDO_2, - 10_000 - ExistentialDeposit::get() - )); - }); -} - -#[test] -fn check_migrate_single_locked_account_after_unlock_block() { - ExtBuilder::default().pseudos_lock_all().build().execute_with(|| { - // Reach balance lock limit - System::set_block_number(101); - - let user_locked_info = LockedBalance { - block: 100, - amount: 10_000 - ::UsableBalance::get(), - }; - // Migration of balance locks - ensure_single_migration_works(&PSEUDO_1, &USER, None, Some((user_locked_info, 0))); - - assert!(UnlockingAt::::get(100).is_none()); - assert!(Locks::::get(&USER).len().is_zero()); - - // Should be able to transfer all tokens but ExistentialDeposit - assert_ok!(Balances::transfer( - Origin::signed(USER), - PSEUDO_2, - 10_000 - ExistentialDeposit::get() - )); - }); -} - -#[test] -fn check_migrate_single_account_locked_twice() { - ExtBuilder::default().pseudos_lock_all().build().execute_with(|| { - let mut user_locked_info = LockedBalance { - block: 100, - amount: 10_000 - ::UsableBalance::get(), - }; - // Migrate pseudo1 lock - ensure_single_migration_works(&PSEUDO_1, &USER, None, Some((user_locked_info, 0))); - - user_locked_info = LockedBalance { - block: 100, - amount: 10_000 + 300_000 - 2 * ::UsableBalance::get(), - }; - // Migrate pseudo2 lock - ensure_single_migration_works( - &PSEUDO_3, - &USER, - None, - Some(( - user_locked_info, - // Since we migrated twice, we need to account for the extra UsableBalance when asserting - ::UsableBalance::get(), - )), - ); - - // Reach balance lock limit - System::set_block_number(100); - >::on_initialize(System::block_number()); - assert!(UnlockingAt::::get(100).is_none()); - assert!(Locks::::get(&USER).len().is_zero()); - - // Should be able to transfer all tokens but ExistentialDeposit - assert_ok!(Balances::transfer( - Origin::signed(USER), - PSEUDO_2, - 310_000 - ExistentialDeposit::get() - )); - }); -} - -#[test] -fn check_migrate_accounts_locked() { - ExtBuilder::default().pseudos_lock_all().build().execute_with(|| { - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts( - Origin::signed(USER), - vec![PSEUDO_1, PSEUDO_2, PSEUDO_3], - USER - ), - Error::::Unauthorized - ); - - // Migrate two accounts with same end block - let locked_info = LockedBalance { - block: 100, - amount: 10_000 + 300_000 - 2 * ::UsableBalance::get(), - }; - assert_ok!(KiltLaunch::migrate_multiple_genesis_accounts( - Origin::signed(TRANSFER_ACCOUNT), - vec![PSEUDO_1, PSEUDO_3], - USER - )); - - // Check unlocking info migration - assert_eq!( - UnlockingAt::::get(100).unwrap_or_default().into_inner(), - vec![USER] - ); - assert_eq!(BalanceLocks::::get(&USER), Some(locked_info.clone())); - - // Check correct setting of lock - let balance_locks = Locks::::get(&USER); - assert_eq!(balance_locks.len(), 1); - for BalanceLock { id, amount, reasons } in balance_locks { - match id { - crate::KILT_LAUNCH_ID => { - assert_eq!(amount, locked_info.amount); - assert_eq!(reasons, Reasons::All); - } - _ => panic!("Unexpected balance lock id {:?}", id), - }; - } - - // Check balance migration - assert_balance( - USER, - locked_info.amount + 2 * ::UsableBalance::get(), - 2 * ::UsableBalance::get(), - 2 * ::UsableBalance::get(), - false, - ); - - // TODO: Add positive check for staking once it has been added - - // Reach balance lock limit - System::set_block_number(100); - >::on_initialize(System::block_number()); - assert!(UnlockingAt::::get(100).is_none()); - assert!(Locks::::get(&USER).len().is_zero()); - assert_balance( - USER, - locked_info.amount + 2 * ::UsableBalance::get(), - locked_info.amount + 2 * ::UsableBalance::get(), - locked_info.amount + 2 * ::UsableBalance::get(), - true, - ); - }); -} - -#[test] -fn check_locked_transfer() { - ExtBuilder::default() - .pseudos_lock_all() - .build() - .execute_with(|| { - let locked_info = LockedBalance { - block: 100, - amount: 10_000 - ::UsableBalance::get(), - }; - // Migration of balance locks - ensure_single_migration_works(&PSEUDO_1, &USER, None, Some((locked_info.clone(), 0))); - assert_eq!( - Locks::::get(&USER), - vec![BalanceLock { - id: KILT_LAUNCH_ID, - amount: locked_info.amount, - reasons: Reasons::All, - }] - ); - - // Cannot transfer from source to source - assert_noop!( - KiltLaunch::locked_transfer(Origin::signed(USER), USER, 1), - Error::::SameDestination - ); - - // Cannot transfer without a KILT balance lock - assert_noop!( - KiltLaunch::locked_transfer(Origin::signed(PSEUDO_4), USER, 1), - Error::::BalanceLockNotFound - ); - - // Add 1 free balance to enable to pay for tx fees - <::Currency as Currency<::AccountId>>::make_free_balance_be(&USER, locked_info.amount + 1 + ::UsableBalance::get()); - // Cannot transfer more locked than which is locked - assert_noop!( - KiltLaunch::locked_transfer(Origin::signed(USER), PSEUDO_1, locked_info.amount + 1 + ::UsableBalance::get()), - Error::::InsufficientLockedBalance - ); - - // Locked_Transfer everything but 3000 - assert_ok!(KiltLaunch::locked_transfer( - Origin::signed(USER), - PSEUDO_1, - locked_info.amount - 3000 - )); - assert_eq!( - Locks::::get(&USER), - vec![BalanceLock { - id: KILT_LAUNCH_ID, - amount: 3000, - reasons: Reasons::All, - }] - ); - assert_eq!( - Locks::::get(&PSEUDO_1), - vec![BalanceLock { - id: KILT_LAUNCH_ID, - amount: locked_info.amount - 3000, - reasons: Reasons::All, - }] - ); - assert_eq!(UnlockingAt::::get(100).unwrap_or_default().into_inner(), vec![USER, PSEUDO_1]); - assert_balance(PSEUDO_1, locked_info.amount - 3000, 0, 0, false); - - // Locked_Transfer rest - assert_ok!(KiltLaunch::locked_transfer(Origin::signed(USER), PSEUDO_1, 3000)); - assert_eq!(Locks::::get(&USER), vec![]); - assert_eq!( - Locks::::get(&PSEUDO_1), - vec![BalanceLock { - id: KILT_LAUNCH_ID, - amount: locked_info.amount, - reasons: Reasons::All, - }] - ); - assert!(BalanceLocks::::get(&USER).is_none()); - assert_eq!(BalanceLocks::::get(&PSEUDO_1), Some(locked_info.clone())); - assert_eq!(UnlockingAt::::get(100).unwrap_or_default().into_inner(), vec![PSEUDO_1]); - assert_balance(PSEUDO_1, locked_info.amount, 0, 0, false); - - // Reach balance lock limit - System::set_block_number(100); - >::on_initialize(System::block_number()); - assert!(UnlockingAt::::get(100).is_none()); - assert!(Locks::::get(&PSEUDO_1).len().is_zero()); - assert_balance(PSEUDO_1, locked_info.amount, locked_info.amount, locked_info.amount, true); - }); -} - -#[test] -fn check_migrate_single_account_vested() { - ExtBuilder::default().pseudos_vest_all().build().execute_with(|| { - assert_noop!( - KiltLaunch::migrate_genesis_account(Origin::signed(TRANSFER_ACCOUNT), PSEUDO_1, PSEUDO_1), - Error::::SameDestination - ); - assert_noop!( - KiltLaunch::migrate_genesis_account(Origin::signed(TRANSFER_ACCOUNT), USER, PSEUDO_1), - Error::::NotUnownedAccount - ); - - // Vesting over 10 blocks - let user_vesting_schedule = VestingInfo::new(10_000, 1000, 0); - - // Migration of vesting info and balance locks - ensure_single_migration_works(&PSEUDO_1, &USER, Some(user_vesting_schedule), None); - - // Reach vesting limit - System::set_block_number(10); - - assert_ok!(Vesting::vest(Origin::signed(USER))); - assert!(Vesting::vesting(&USER).is_none()); - assert!(Locks::::get(&USER).len().is_zero()); - // Should be able to transfer the remaining tokens - assert_ok!(Balances::transfer( - Origin::signed(USER), - PSEUDO_1, - user_vesting_schedule.locked() - user_vesting_schedule.per_block() - )); - }); -} - -#[test] -fn check_migrate_single_account_twice_vested() { - ExtBuilder::default().pseudos_vest_all().build().execute_with(|| { - // Migration of vesting info from pseudo_1 to user_1 - // Vesting over 10 blocks - let mut user_vesting_schedule = VestingInfo::new(10_000, 1000, 0); - ensure_single_migration_works(&PSEUDO_1, &USER, Some(user_vesting_schedule), None); - - // Migration of vesting info from pseudo_2 with different vesting period to - // user_1 - // Vesting over 10 blocks - user_vesting_schedule = VestingInfo::new( - user_vesting_schedule.locked() + 10_000, - user_vesting_schedule.per_block() + 500, - 0, - ); - ensure_single_migration_works(&PSEUDO_2, &USER, Some(user_vesting_schedule), None); - - // Reach first vesting limit - System::set_block_number(10); - assert_ok!(Vesting::vest(Origin::signed(USER))); - assert_eq!( - Vesting::vesting(&USER) - .expect("Missing vesting info") - .into_inner() - .get(0), - Some(&user_vesting_schedule) - ); - assert_eq!(Locks::::get(&USER).len(), 1); - assert_balance( - USER, - user_vesting_schedule.locked(), - user_vesting_schedule.locked(), - user_vesting_schedule.locked() - 500 * 10, - false, - ); - - // Reach second vesting limit - System::set_block_number(20); - assert_ok!(Vesting::vest(Origin::signed(USER))); - assert!(Vesting::vesting(&USER).is_none()); - assert!(Locks::::get(&USER).len().is_zero()); - // Should be able to transfer the remaining tokens - assert_balance( - USER, - user_vesting_schedule.locked(), - user_vesting_schedule.locked(), - user_vesting_schedule.locked(), - true, - ); - }); -} - -#[test] -fn check_migrate_accounts_vested() { - ExtBuilder::default().pseudos_vest_all().build().execute_with(|| { - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts( - Origin::signed(USER), - vec![PSEUDO_1, PSEUDO_2, PSEUDO_3], - USER - ), - Error::::Unauthorized - ); - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts( - Origin::signed(TRANSFER_ACCOUNT), - vec![PSEUDO_1, USER], - PSEUDO_2 - ), - Error::::NotUnownedAccount - ); - - assert_ok!(KiltLaunch::migrate_multiple_genesis_accounts( - Origin::signed(TRANSFER_ACCOUNT), - vec![PSEUDO_1, PSEUDO_2, PSEUDO_3], - USER - )); - - let vesting_info = VestingInfo::new(10_000 + 10_000 + 300_000, 10_000 / 10 + 10_000 / 20 + 300_000 / 30, 0); - - // Check vesting info migration - assert_eq!( - Vesting::vesting(&USER) - .expect("Missing vesting info") - .into_inner() - .get(0), - Some(&vesting_info) - ); - - // Check correct setting of lock - let balance_locks = Locks::::get(&USER); - assert_eq!(balance_locks.len(), 1); - for BalanceLock { id, amount, reasons } in balance_locks { - match id { - crate::VESTING_ID => { - assert_eq!(amount, vesting_info.locked() - vesting_info.per_block()); - assert_eq!(reasons, Reasons::Misc); - } - _ => panic!("Unexpected balance lock id {:?}", id), - }; - } - - // Check balance migration - assert_balance( - USER, - vesting_info.locked(), - vesting_info.locked(), - vesting_info.per_block(), - false, - ); - - // TODO: Add positive check for staking once it has been added - - // Reach vesting limits - for block in &[9, 10, 15, 20, 27] { - System::set_block_number(*block); - assert_ok!(Vesting::vest(Origin::signed(USER))); - assert_eq!( - Locks::::get(USER), - vec![BalanceLock { - id: VESTING_ID, - amount: vesting_info.locked() - vesting_info.per_block() * (*block as u128), - reasons: Reasons::Misc - }] - ); - assert_eq!( - Vesting::vesting(&USER) - .expect("Missing vesting info") - .into_inner() - .get(0), - Some(&vesting_info) - ); - assert_balance( - USER, - vesting_info.locked(), - vesting_info.locked(), - vesting_info.per_block() * (*block as u128), - false, - ); - } - System::set_block_number(30); - assert_ok!(Vesting::vest(Origin::signed(USER))); - assert!(Vesting::vesting(&USER).is_none()); - assert!(Locks::::get(&USER).len().is_zero()); - }); -} - -#[test] -fn check_negative_migrate_accounts_vested() { - ExtBuilder::default().pseudos_vest_all().build().execute_with(|| { - // Migrate from source to source - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts(Origin::signed(TRANSFER_ACCOUNT), vec![PSEUDO_1, USER], USER), - Error::::SameDestination - ); - - // Migrate too many accounts - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts( - Origin::signed(TRANSFER_ACCOUNT), - vec![PSEUDO_1, PSEUDO_2, PSEUDO_3, PSEUDO_4], - USER - ), - Error::::MaxClaimsExceeded - ); - - // Set up vesting with conflicting start block - let pseudo_4_vesting = VestingInfo::new(10_000, 1, 1); - assert_ok!(VestingStorage::::try_append(PSEUDO_4, pseudo_4_vesting)); - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts( - Origin::signed(TRANSFER_ACCOUNT), - vec![PSEUDO_1, PSEUDO_4], - USER - ), - Error::::NotUnownedAccount - ); - UnownedAccount::::insert(PSEUDO_4, ()); - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts( - Origin::signed(TRANSFER_ACCOUNT), - vec![PSEUDO_1, PSEUDO_4], - USER - ), - Error::::ConflictingVestingStarts - ); - - // Set a vesting lock which should not be there from the Genesis builder - <::Currency as LockableCurrency>::set_lock( - VESTING_ID, - &PSEUDO_4, - 1, - WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE, - ); - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts(Origin::signed(TRANSFER_ACCOUNT), vec![PSEUDO_4], USER), - Error::::UnexpectedLocks - ); - }); -} - -#[test] -fn check_negative_migrate_accounts_locked() { - ExtBuilder::default().pseudos_lock_all().build().execute_with(|| { - // Migrate from source to source - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts(Origin::signed(TRANSFER_ACCOUNT), vec![PSEUDO_1, USER], USER), - Error::::SameDestination - ); - - // Migrate two accounts with different ending blocks - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts( - Origin::signed(TRANSFER_ACCOUNT), - vec![PSEUDO_1, PSEUDO_2], - USER - ), - Error::::ConflictingLockingBlocks - ); - - // Add a lock to pseudo2 which should not be there - Balances::set_lock(KILT_LAUNCH_ID, &PSEUDO_2, 1, WithdrawReasons::all()); - assert_noop!( - KiltLaunch::migrate_multiple_genesis_accounts(Origin::signed(TRANSFER_ACCOUNT), vec![PSEUDO_2], USER), - Error::::UnexpectedLocks - ); - }); -} - -#[test] -fn check_force_unlock() { - ExtBuilder::default().pseudos_lock_all().build().execute_with(|| { - let user_locked_info = LockedBalance { - block: 100, - amount: 10_000 - ::UsableBalance::get(), - }; - ensure_single_migration_works(&PSEUDO_1, &USER, None, Some((user_locked_info, 0))); - - assert_ok!(KiltLaunch::force_unlock(Origin::root(), 100)); - assert!(BalanceLocks::::get(&USER).is_none()); - assert!(Locks::::get(&USER).len().is_zero()); - assert_eq!(Balances::usable_balance(&USER), 10_000); - }); -} - -#[test] -fn check_change_transfer_account() { - ExtBuilder::default().build().execute_with(|| { - assert_eq!(TransferAccount::::get(), Some(TRANSFER_ACCOUNT)); - assert_ok!(KiltLaunch::change_transfer_account(Origin::root(), PSEUDO_1)); - assert_eq!(TransferAccount::::get(), Some(PSEUDO_1)); - }); -} - -#[test] -#[should_panic = "Currencies must be init'd before locking"] -fn check_genesis_panic_locking_balance() { - ExtBuilder::default().build_panic(vec![], vec![(PSEUDO_1, 100, 10_000)], vec![]); -} -#[test] -#[should_panic = "Currencies must be init'd before vesting"] -fn check_genesis_panic_vesting_balance() { - ExtBuilder::default().build_panic(vec![], vec![], vec![(PSEUDO_1, 100, 10_000)]); -} - -#[test] -#[should_panic = r#"Locked balance must not exceed total balance for address "5C62Ck4UrFPiBtoCmeSrgF7x9yv9mn38446dhCpsi2mLHiFT""#] -fn check_genesis_panic_locking_amount() { - ExtBuilder::default().build_panic(vec![(PSEUDO_1, 10_000)], vec![(PSEUDO_1, 100, 10_001)], vec![]); -} -#[test] -#[should_panic = r#"Vested balance must not exceed total balance for address "5C62Ck4UrFPiBtoCmeSrgF7x9yv9mn38446dhCpsi2mLHiFT""#] -fn check_genesis_panic_vesting_amount() { - ExtBuilder::default().build_panic(vec![(PSEUDO_1, 10_000)], vec![], vec![(PSEUDO_1, 100, 10_001)]); -} - -#[test] -#[should_panic = r#"Account with address "5C62Ck4UrFPiBtoCmeSrgF7x9yv9mn38446dhCpsi2mLHiFT" must not occur twice in locking"#] -fn check_genesis_panic_locking_same_acc() { - ExtBuilder::default().build_panic( - vec![(PSEUDO_1, 10_000)], - vec![(PSEUDO_1, 100, 10_000), (PSEUDO_1, 1337, 10_000)], - vec![], - ); -} -#[test] -#[should_panic = r#"Account with address "5C62Ck4UrFPiBtoCmeSrgF7x9yv9mn38446dhCpsi2mLHiFT" must not occur twice in vesting"#] -fn check_genesis_vesting_locking_same_acc() { - ExtBuilder::default().build_panic( - vec![(PSEUDO_1, 10_000)], - vec![], - vec![(PSEUDO_1, 100, 10_000), (PSEUDO_1, 1337, 10_000)], - ); -} diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index 8e331b80b1..a11f49aa05 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -144,7 +144,7 @@ //! //! ## Genesis config //! -//! The KiltLaunch pallet depends on the [`GenesisConfig`]. +//! The ParachainStaking pallet depends on the [`GenesisConfig`]. //! //! ## Assumptions+ //! diff --git a/runtimes/common/Cargo.toml b/runtimes/common/Cargo.toml index 8bed6f103d..b29886ff74 100644 --- a/runtimes/common/Cargo.toml +++ b/runtimes/common/Cargo.toml @@ -9,6 +9,7 @@ sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0. [dependencies] codec = {package = "parity-scale-codec", version = "3.1.2", default-features = false, features = ["derive"]} +log = "0.4.16" scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} serde = {version = "1.0.136", optional = true, features = ["derive"]} smallvec = "1.8.0" @@ -24,9 +25,13 @@ pallet-membership = {git = "https://github.com/paritytech/substrate", default-fe pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} sp-consensus-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} +sp-io = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} sp-std = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19"} +# Runtime tests +frame-try-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.19", optional = true} + [features] default = ["std"] fast-gov = [] @@ -50,6 +55,11 @@ std = [ "serde", "sp-consensus-aura/std", "sp-core/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", ] +try-runtime = [ + "frame-support/try-runtime", + "frame-try-runtime", +] diff --git a/runtimes/common/src/lib.rs b/runtimes/common/src/lib.rs index c05f191df8..70f5cb27e8 100644 --- a/runtimes/common/src/lib.rs +++ b/runtimes/common/src/lib.rs @@ -45,6 +45,7 @@ use sp_std::marker::PhantomData; pub mod authorization; pub mod constants; pub mod fees; +pub mod migrations; pub mod pallet_id; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtimes/common/src/migrations.rs b/runtimes/common/src/migrations.rs new file mode 100644 index 0000000000..8a444f04f7 --- /dev/null +++ b/runtimes/common/src/migrations.rs @@ -0,0 +1,63 @@ +// KILT Blockchain – https://botlabs.org +// Copyright (C) 2019-2022 BOTLabs GmbH + +// The KILT Blockchain 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. + +// The KILT Blockchain 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 . + +// If you feel like getting in touch with us, you can do so at info@botlabs.org + +use core::marker::PhantomData; +use frame_support::traits::Get; + +pub struct RemoveKiltLaunch(PhantomData); +impl frame_support::traits::OnRuntimeUpgrade for RemoveKiltLaunch { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let prefix: [u8; 16] = sp_io::hashing::twox_128(b"KiltLaunch"); + + let items = match frame_support::storage::unhashed::kill_prefix(&prefix, Some(6)) { + sp_io::KillStorageResult::AllRemoved(n) => { + log::info!("🚀 Successfully removed all {:?} storage items of the launch pallet", n); + n + } + sp_io::KillStorageResult::SomeRemaining(n) => { + log::warn!( + "🚀 Failed to remove all storage items of the launch pallet, {:?} are remaining", + n + ); + n + } + }; + ::DbWeight::get().writes(items.into()) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + let prefix: [u8; 16] = sp_io::hashing::twox_128(b"KiltLaunch"); + + assert!( + sp_io::storage::next_key(&prefix).map_or(false, |next_key| next_key.starts_with(&prefix)), + "🚀 Pre check: Launch pallet storage does not exist!" + ); + Ok(()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + let prefix: [u8; 16] = sp_io::hashing::twox_128(b"KiltLaunch"); + assert!( + sp_io::storage::next_key(&prefix,).map_or(true, |next_key| !next_key.starts_with(&prefix)), + "🚀 Post check: Launch pallet storage still exists!" + ); + Ok(()) + } +} diff --git a/runtimes/peregrine/Cargo.toml b/runtimes/peregrine/Cargo.toml index 2bd5c785a8..8ef40f7c55 100644 --- a/runtimes/peregrine/Cargo.toml +++ b/runtimes/peregrine/Cargo.toml @@ -26,7 +26,6 @@ attestation = {default-features = false, path = "../../pallets/attestation"} ctype = {default-features = false, path = "../../pallets/ctype"} delegation = {default-features = false, path = "../../pallets/delegation"} did = {default-features = false, path = "../../pallets/did"} -kilt-launch = {path = "../../pallets/kilt-launch", default-features = false} kilt-support = {path = "../../support", default-features = false, optional = true} pallet-did-lookup = {default-features = false, path = "../../pallets/pallet-did-lookup"} pallet-inflation = {path = "../../pallets/pallet-inflation", default-features = false} @@ -110,7 +109,6 @@ runtime-benchmarks = [ "frame-system-benchmarking", "frame-system/runtime-benchmarks", "hex-literal", - "kilt-launch/runtime-benchmarks", "kilt-support", "kilt-support/runtime-benchmarks", "pallet-balances/runtime-benchmarks", @@ -151,7 +149,6 @@ std = [ "frame-system-rpc-runtime-api/std", "frame-system/std", "frame-try-runtime/std", - "kilt-launch/std", "log/std", "pallet-aura/std", "pallet-authorship/std", @@ -208,7 +205,6 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "frame-try-runtime", - "kilt-launch/try-runtime", "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", diff --git a/runtimes/peregrine/src/lib.rs b/runtimes/peregrine/src/lib.rs index 92d18d136d..52cb988117 100644 --- a/runtimes/peregrine/src/lib.rs +++ b/runtimes/peregrine/src/lib.rs @@ -267,15 +267,6 @@ parameter_types! { pub const AutoUnlockBound: u32 = 100; } -impl kilt_launch::Config for Runtime { - type Event = Event; - type MaxClaims = MaxClaims; - type UsableBalance = UsableBalance; - type AutoUnlockBound = AutoUnlockBound; - type WeightInfo = weights::kilt_launch::WeightInfo; - type PalletId = pallet_id::Launch; -} - impl pallet_preimage::Config for Runtime { type WeightInfo = weights::pallet_preimage::WeightInfo; type Event = Event; @@ -695,7 +686,6 @@ impl InstanceFilter for ProxyType { | pallet_indices::Call::free { .. } | pallet_indices::Call::freeze { .. } ) - // Excludes `KiltLaunch` | Call::ParachainStaking(..) // Excludes `ParachainSystem` | Call::Preimage(..) @@ -759,7 +749,6 @@ impl InstanceFilter for ProxyType { | pallet_did_lookup::Call::remove_sender_association { .. } ) | Call::Indices(..) - // Excludes `KiltLaunch` | Call::ParachainStaking(..) // Excludes `ParachainSystem` | Call::Preimage(..) @@ -881,7 +870,7 @@ construct_runtime! { Tips: pallet_tips::{Pallet, Call, Storage, Event} = 46, // KILT Pallets. Start indices 60 to leave room - KiltLaunch: kilt_launch = 60, + // DELETED: KiltLaunch: kilt_launch = 60, Ctype: ctype = 61, Attestation: attestation = 62, Delegation: delegation = 63, @@ -977,7 +966,7 @@ pub type Executive = frame_executive::Executive< // Executes pallet hooks in reverse order of definition in construct_runtime // If we want to switch to AllPalletsWithSystem, we need to reorder the staking pallets AllPalletsReversedWithSystemFirst, - pallet_did_lookup::migrations::LookupReverseIndexMigration, + runtime_common::migrations::RemoveKiltLaunch, >; impl_runtime_apis! { @@ -1122,7 +1111,6 @@ impl_runtime_apis! { list_benchmark!(list, extra, delegation, Delegation); list_benchmark!(list, extra, did, Did); list_benchmark!(list, extra, pallet_did_lookup, DidLookup); - list_benchmark!(list, extra, kilt_launch, KiltLaunch); list_benchmark!(list, extra, pallet_inflation, Inflation); list_benchmark!(list, extra, parachain_staking, ParachainStaking); list_benchmark!(list, extra, pallet_web3_names, Web3Names); @@ -1160,8 +1148,6 @@ impl_runtime_apis! { // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7") .to_vec().into(), - // KiltLaunch transfer account - hex_literal::hex!("6a3c793cec9dbe330b349dc4eea6801090f5e71f53b1b41ad11afb4a313a282c").to_vec().into(), ]; let mut batches = Vec::::new(); @@ -1191,7 +1177,6 @@ impl_runtime_apis! { add_benchmark!(params, batches, delegation, Delegation); add_benchmark!(params, batches, did, Did); add_benchmark!(params, batches, pallet_did_lookup, DidLookup); - add_benchmark!(params, batches, kilt_launch, KiltLaunch); add_benchmark!(params, batches, pallet_inflation, Inflation); add_benchmark!(params, batches, parachain_staking, ParachainStaking); add_benchmark!(params, batches, pallet_web3_names, Web3Names); diff --git a/runtimes/peregrine/src/weights/kilt_launch.rs b/runtimes/peregrine/src/weights/kilt_launch.rs deleted file mode 100644 index 65de27fad9..0000000000 --- a/runtimes/peregrine/src/weights/kilt_launch.rs +++ /dev/null @@ -1,149 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain 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. - -// The KILT Blockchain 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 . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -//! Autogenerated weights for kilt_launch -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-10-29, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 - -// Executed Command: -// target/release/kilt-parachain -// benchmark -// --chain=dev -// --steps=50 -// --repeat=20 -// --pallet=kilt-launch -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=./runtimes/peregrine/src/weights/kilt_launch.rs -// --template=.maintain/runtime-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}; -use sp_std::marker::PhantomData; - -/// Weight functions for `kilt_launch`. -pub struct WeightInfo(PhantomData); -impl kilt_launch::WeightInfo for WeightInfo { - // Storage: KiltLaunch TransferAccount (r:0 w:1) - fn change_transfer_account() -> Weight { - (3_005_000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - // Storage: Balances Locks (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: KiltLaunch BalanceLocks (r:0 w:1) - fn force_unlock(n: u32, ) -> Weight { - (29_019_000 as Weight) - // Standard Error: 23_000 - .saturating_add((27_620_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) - } - // Storage: System Account (r:2 w:2) - // Storage: KiltLaunch BalanceLocks (r:2 w:2) - // Storage: Balances Locks (r:2 w:2) - fn locked_transfer() -> Weight { - (134_504_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:2 w:2) - // Storage: KiltLaunch BalanceLocks (r:1 w:0) - fn migrate_genesis_account_vesting() -> Weight { - (151_286_000 as Weight) - .saturating_add(T::DbWeight::get().reads(9 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:1 w:0) - // Storage: KiltLaunch BalanceLocks (r:2 w:2) - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - fn migrate_genesis_account_locking() -> Weight { - (154_814_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:2 w:2) - // Storage: KiltLaunch BalanceLocks (r:1 w:0) - fn migrate_multiple_genesis_accounts_vesting(n: u32, ) -> Weight { - (53_435_000 as Weight) - // Standard Error: 50_000 - .saturating_add((97_798_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().reads((5 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:1 w:0) - // Storage: KiltLaunch BalanceLocks (r:2 w:2) - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - fn migrate_multiple_genesis_accounts_locking(n: u32, ) -> Weight { - (60_289_000 as Weight) - // Standard Error: 51_000 - .saturating_add((95_743_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().reads((5 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) - } - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - // Storage: Balances Locks (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: KiltLaunch BalanceLocks (r:0 w:1) - fn on_initialize_unlock(n: u32, ) -> Weight { - (22_733_000 as Weight) - // Standard Error: 10_000 - .saturating_add((27_719_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) - } - // Storage: KiltLaunch UnlockingAt (r:1 w:0) - fn on_initialize_no_action() -> Weight { - (4_445_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - } -} diff --git a/runtimes/peregrine/src/weights/mod.rs b/runtimes/peregrine/src/weights/mod.rs index a135ba0de6..29b65e432d 100644 --- a/runtimes/peregrine/src/weights/mod.rs +++ b/runtimes/peregrine/src/weights/mod.rs @@ -21,7 +21,6 @@ pub mod ctype; pub mod delegation; pub mod did; pub mod frame_system; -pub mod kilt_launch; pub mod pallet_balances; pub mod pallet_collective; pub mod pallet_democracy; diff --git a/runtimes/spiritnet/Cargo.toml b/runtimes/spiritnet/Cargo.toml index 54c44b161a..0747de359f 100644 --- a/runtimes/spiritnet/Cargo.toml +++ b/runtimes/spiritnet/Cargo.toml @@ -26,7 +26,6 @@ attestation = {default-features = false, path = "../../pallets/attestation"} ctype = {default-features = false, path = "../../pallets/ctype"} delegation = {default-features = false, path = "../../pallets/delegation"} did = {default-features = false, path = "../../pallets/did"} -kilt-launch = {path = "../../pallets/kilt-launch", default-features = false} kilt-support = {path = "../../support", default-features = false, optional = true} pallet-did-lookup = {default-features = false, path = "../../pallets/pallet-did-lookup"} pallet-inflation = {path = "../../pallets/pallet-inflation", default-features = false} @@ -109,7 +108,6 @@ runtime-benchmarks = [ "frame-system-benchmarking", "frame-system/runtime-benchmarks", "hex-literal", - "kilt-launch/runtime-benchmarks", "runtime-common/runtime-benchmarks", "kilt-support", "kilt-support/runtime-benchmarks", @@ -151,7 +149,6 @@ std = [ "frame-system-rpc-runtime-api/std", "frame-system/std", "frame-try-runtime/std", - "kilt-launch/std", "log/std", "pallet-aura/std", "pallet-authorship/std", @@ -208,7 +205,6 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "frame-try-runtime", - "kilt-launch/try-runtime", "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", @@ -230,4 +226,5 @@ try-runtime = [ "pallet-utility/try-runtime", "pallet-vesting/try-runtime", "parachain-staking/try-runtime", + "runtime-common/try-runtime", ] diff --git a/runtimes/spiritnet/src/lib.rs b/runtimes/spiritnet/src/lib.rs index 10e4dbbbc6..d7ee11547c 100644 --- a/runtimes/spiritnet/src/lib.rs +++ b/runtimes/spiritnet/src/lib.rs @@ -28,7 +28,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{ construct_runtime, parameter_types, - traits::{Contains, EnsureOneOf, InstanceFilter, PrivilegeCmp}, + traits::{EnsureOneOf, InstanceFilter, PrivilegeCmp}, weights::{constants::RocksDbWeight, ConstantMultiplier, Weight}, }; use frame_system::EnsureRoot; @@ -100,16 +100,6 @@ parameter_types! { pub const SS58Prefix: u8 = 38; } -pub struct BaseFilter; -impl Contains for BaseFilter { - fn contains(c: &Call) -> bool { - !matches!( - c, - Call::KiltLaunch(kilt_launch::Call::locked_transfer { .. }) | Call::Delegation { .. } - ) - } -} - impl frame_system::Config for Runtime { /// The identifier used to distinguish between accounts. type AccountId = AccountId; @@ -143,7 +133,7 @@ impl frame_system::Config for Runtime { type OnNewAccount = (); type OnKilledAccount = (); type DbWeight = RocksDbWeight; - type BaseCallFilter = BaseFilter; + type BaseCallFilter = frame_support::traits::Everything; type SystemWeightInfo = weights::frame_system::WeightInfo; type BlockWeights = BlockWeights; type BlockLength = BlockLength; @@ -272,15 +262,6 @@ parameter_types! { pub const AutoUnlockBound: u32 = 100; } -impl kilt_launch::Config for Runtime { - type Event = Event; - type MaxClaims = MaxClaims; - type UsableBalance = UsableBalance; - type AutoUnlockBound = AutoUnlockBound; - type WeightInfo = weights::kilt_launch::WeightInfo; - type PalletId = pallet_id::Launch; -} - impl pallet_preimage::Config for Runtime { type WeightInfo = weights::pallet_preimage::WeightInfo; type Event = Event; @@ -700,7 +681,6 @@ impl InstanceFilter for ProxyType { | pallet_indices::Call::free { .. } | pallet_indices::Call::freeze { .. } ) - // Excludes `KiltLaunch` | Call::ParachainStaking(..) // Excludes `ParachainSystem` | Call::Preimage(..) @@ -763,7 +743,6 @@ impl InstanceFilter for ProxyType { | pallet_did_lookup::Call::remove_sender_association { .. } ) | Call::Indices(..) - // Excludes `KiltLaunch` | Call::ParachainStaking(..) // Excludes `ParachainSystem` | Call::Preimage(..) @@ -884,7 +863,7 @@ construct_runtime! { Tips: pallet_tips::{Pallet, Call, Storage, Event} = 46, // KILT Pallets. Start indices 60 to leave room - KiltLaunch: kilt_launch = 60, + // DELETED: KiltLaunch: kilt_launch = 60, Ctype: ctype = 61, Attestation: attestation = 62, Delegation: delegation = 63, @@ -980,7 +959,7 @@ pub type Executive = frame_executive::Executive< // Executes pallet hooks in reverse order of definition in construct_runtime // If we want to switch to AllPalletsWithSystem, we need to reorder the staking pallets AllPalletsReversedWithSystemFirst, - pallet_did_lookup::migrations::LookupReverseIndexMigration, + runtime_common::migrations::RemoveKiltLaunch, >; impl_runtime_apis! { @@ -1125,7 +1104,6 @@ impl_runtime_apis! { list_benchmark!(list, extra, delegation, Delegation); list_benchmark!(list, extra, did, Did); list_benchmark!(list, extra, pallet_did_lookup, DidLookup); - list_benchmark!(list, extra, kilt_launch, KiltLaunch); list_benchmark!(list, extra, pallet_inflation, Inflation); list_benchmark!(list, extra, parachain_staking, ParachainStaking); list_benchmark!(list, extra, pallet_web3_names, Web3Names); @@ -1163,8 +1141,6 @@ impl_runtime_apis! { // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7") .to_vec().into(), - // KiltLaunch transfer account - hex_literal::hex!("6a3c793cec9dbe330b349dc4eea6801090f5e71f53b1b41ad11afb4a313a282c").to_vec().into(), ]; let mut batches = Vec::::new(); @@ -1194,7 +1170,6 @@ impl_runtime_apis! { add_benchmark!(params, batches, delegation, Delegation); add_benchmark!(params, batches, did, Did); add_benchmark!(params, batches, pallet_did_lookup, DidLookup); - add_benchmark!(params, batches, kilt_launch, KiltLaunch); add_benchmark!(params, batches, pallet_inflation, Inflation); add_benchmark!(params, batches, parachain_staking, ParachainStaking); add_benchmark!(params, batches, pallet_web3_names, Web3Names); diff --git a/runtimes/spiritnet/src/weights/kilt_launch.rs b/runtimes/spiritnet/src/weights/kilt_launch.rs deleted file mode 100644 index 4d3bbe14de..0000000000 --- a/runtimes/spiritnet/src/weights/kilt_launch.rs +++ /dev/null @@ -1,149 +0,0 @@ -// KILT Blockchain – https://botlabs.org -// Copyright (C) 2019-2022 BOTLabs GmbH - -// The KILT Blockchain 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. - -// The KILT Blockchain 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 . - -// If you feel like getting in touch with us, you can do so at info@botlabs.org - -//! Autogenerated weights for kilt_launch -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-10-29, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("spiritnet-dev"), DB CACHE: 128 - -// Executed Command: -// target/release/kilt-parachain -// benchmark -// --chain=spiritnet-dev -// --steps=50 -// --repeat=20 -// --pallet=kilt-launch -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=./runtimes/spiritnet/src/weights/kilt_launch.rs -// --template=.maintain/runtime-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}; -use sp_std::marker::PhantomData; - -/// Weight functions for `kilt_launch`. -pub struct WeightInfo(PhantomData); -impl kilt_launch::WeightInfo for WeightInfo { - // Storage: KiltLaunch TransferAccount (r:0 w:1) - fn change_transfer_account() -> Weight { - (3_081_000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - // Storage: Balances Locks (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: KiltLaunch BalanceLocks (r:0 w:1) - fn force_unlock(n: u32, ) -> Weight { - (23_367_000 as Weight) - // Standard Error: 23_000 - .saturating_add((28_602_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) - } - // Storage: System Account (r:2 w:2) - // Storage: KiltLaunch BalanceLocks (r:2 w:2) - // Storage: Balances Locks (r:2 w:2) - fn locked_transfer() -> Weight { - (138_045_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:2 w:2) - // Storage: KiltLaunch BalanceLocks (r:1 w:0) - fn migrate_genesis_account_vesting() -> Weight { - (151_792_000 as Weight) - .saturating_add(T::DbWeight::get().reads(9 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:1 w:0) - // Storage: KiltLaunch BalanceLocks (r:2 w:2) - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - fn migrate_genesis_account_locking() -> Weight { - (155_177_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:2 w:2) - // Storage: KiltLaunch BalanceLocks (r:1 w:0) - fn migrate_multiple_genesis_accounts_vesting(n: u32, ) -> Weight { - (46_828_000 as Weight) - // Standard Error: 51_000 - .saturating_add((100_849_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().reads((5 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) - } - // Storage: KiltLaunch TransferAccount (r:1 w:0) - // Storage: KiltLaunch UnownedAccount (r:1 w:1) - // Storage: Balances Locks (r:2 w:1) - // Storage: System Account (r:2 w:2) - // Storage: Vesting Vesting (r:1 w:0) - // Storage: KiltLaunch BalanceLocks (r:2 w:2) - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - fn migrate_multiple_genesis_accounts_locking(n: u32, ) -> Weight { - (52_280_000 as Weight) - // Standard Error: 47_000 - .saturating_add((98_937_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().reads((5 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) - } - // Storage: KiltLaunch UnlockingAt (r:1 w:1) - // Storage: Balances Locks (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: KiltLaunch BalanceLocks (r:0 w:1) - fn on_initialize_unlock(n: u32, ) -> Weight { - (26_534_000 as Weight) - // Standard Error: 11_000 - .saturating_add((28_512_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(n as Weight))) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) - } - // Storage: KiltLaunch UnlockingAt (r:1 w:0) - fn on_initialize_no_action() -> Weight { - (4_524_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - } -} diff --git a/runtimes/spiritnet/src/weights/mod.rs b/runtimes/spiritnet/src/weights/mod.rs index a135ba0de6..29b65e432d 100644 --- a/runtimes/spiritnet/src/weights/mod.rs +++ b/runtimes/spiritnet/src/weights/mod.rs @@ -21,7 +21,6 @@ pub mod ctype; pub mod delegation; pub mod did; pub mod frame_system; -pub mod kilt_launch; pub mod pallet_balances; pub mod pallet_collective; pub mod pallet_democracy; diff --git a/runtimes/standalone/Cargo.toml b/runtimes/standalone/Cargo.toml index 7eef43c179..38336d6707 100644 --- a/runtimes/standalone/Cargo.toml +++ b/runtimes/standalone/Cargo.toml @@ -21,7 +21,6 @@ attestation = {default-features = false, path = "../../pallets/attestation"} ctype = {default-features = false, path = "../../pallets/ctype"} delegation = {default-features = false, path = "../../pallets/delegation"} did = {default-features = false, path = "../../pallets/did"} -kilt-launch = {default-features = false, path = "../../pallets/kilt-launch"} kilt-support = {path = "../../support", default-features = false, optional = true} pallet-did-lookup = {default-features = false, path = "../../pallets/pallet-did-lookup"} pallet-web3-names = {default-features = false, path = "../../pallets/pallet-web3-names"} @@ -81,7 +80,6 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "frame-system-benchmarking", "hex-literal", - "kilt-launch/runtime-benchmarks", "runtime-common/runtime-benchmarks", "kilt-support", "kilt-support/runtime-benchmarks", @@ -106,7 +104,6 @@ std = [ "frame-system/std", "frame-system-rpc-runtime-api/std", "frame-try-runtime/std", - "kilt-launch/std", "log/std", "pallet-aura/std", "pallet-authorship/std", @@ -149,7 +146,6 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "frame-try-runtime", - "kilt-launch/try-runtime", "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", diff --git a/runtimes/standalone/src/lib.rs b/runtimes/standalone/src/lib.rs index 0f95bf5a42..cf9efc8f05 100644 --- a/runtimes/standalone/src/lib.rs +++ b/runtimes/standalone/src/lib.rs @@ -67,7 +67,7 @@ use runtime_common::{ authorization::{AuthorizationId, PalletAuthorize}, constants::{self, KILT, MILLI_KILT}, fees::ToAuthor, - pallet_id, AccountId, Balance, BlockNumber, DidIdentifier, Hash, Index, Signature, SlowAdjustingFeeUpdate, + AccountId, Balance, BlockNumber, DidIdentifier, Hash, Index, Signature, SlowAdjustingFeeUpdate, }; #[cfg(feature = "std")] @@ -276,15 +276,6 @@ parameter_types! { pub const UsableBalance: Balance = KILT; } -impl kilt_launch::Config for Runtime { - type Event = Event; - type MaxClaims = MaxClaims; - type UsableBalance = UsableBalance; - type WeightInfo = (); - type AutoUnlockBound = AutoUnlockBound; - type PalletId = pallet_id::Launch; -} - impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = CurrencyAdapter>; type OperationalFeeMultiplier = constants::fee::OperationalFeeMultiplier; @@ -687,7 +678,7 @@ construct_runtime!( // Vesting. Usable initially, but removed once all vesting is finished. Vesting: pallet_vesting = 33, - KiltLaunch: kilt_launch = 34, + // DELETED: KiltLaunch: kilt_launch = 34, Utility: pallet_utility = 35, // DELETED CrowdloanContributors: 36, @@ -927,7 +918,6 @@ impl_runtime_apis! { list_benchmark!(list, extra, frame_system, SystemBench::); list_benchmark!(list, extra, pallet_balances, Balances); list_benchmark!(list, extra, pallet_timestamp, Timestamp); - list_benchmark!(list, extra, kilt_launch, KiltLaunch); list_benchmark!(list, extra, pallet_vesting, Vesting); list_benchmark!(list, extra, did, Did); @@ -967,8 +957,6 @@ impl_runtime_apis! { // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7") .to_vec().into(), - // KiltLaunch transfer account - hex_literal::hex!("6a3c793cec9dbe330b349dc4eea6801090f5e71f53b1b41ad11afb4a313a282c").to_vec().into(), ]; let mut batches = Vec::::new(); @@ -978,7 +966,6 @@ impl_runtime_apis! { add_benchmark!(params, batches, frame_system, SystemBench::); add_benchmark!(params, batches, pallet_balances, Balances); add_benchmark!(params, batches, pallet_timestamp, Timestamp); - add_benchmark!(params, batches, kilt_launch, KiltLaunch); add_benchmark!(params, batches, pallet_vesting, Vesting); add_benchmark!(params, batches, did, Did); diff --git a/scripts/run_benches_for_pallets.sh b/scripts/run_benches_for_pallets.sh index 8cf60be4ce..a36f9279eb 100755 --- a/scripts/run_benches_for_pallets.sh +++ b/scripts/run_benches_for_pallets.sh @@ -13,7 +13,6 @@ pallets=( ctype delegation did - kilt-launch parachain-staking ) diff --git a/scripts/run_benches_for_runtime.sh b/scripts/run_benches_for_runtime.sh index 25b641b77b..ad7df3d144 100755 --- a/scripts/run_benches_for_runtime.sh +++ b/scripts/run_benches_for_runtime.sh @@ -13,7 +13,6 @@ pallets=( ctype delegation did - kilt_launch parachain_staking frame_system pallet_balances