diff --git a/.github/actions/sccache-gcloud/action.yml b/.github/actions/sccache-gcloud/action.yml index cd9b0accfb..ee611db560 100644 --- a/.github/actions/sccache-gcloud/action.yml +++ b/.github/actions/sccache-gcloud/action.yml @@ -14,13 +14,13 @@ runs: - name: Auth gcloud id: gauth - uses: google-github-actions/auth@35b0e87d162680511bf346c299f71c9c5c379033 # @v1.1.1 + uses: google-github-actions/auth@55bd3a7c6e2ae7cf1877fd1ccb9d54c0503c457c # @v2.1.2 with: workload_identity_provider: ${{ inputs.GWIP }} service_account: ${{ inputs.GSA }} - name: Run sccache-cache - uses: mozilla-actions/sccache-action@8417cffc2ec64127ad83077aceaa8631f7cdc83e #v0.0.3 + uses: mozilla-actions/sccache-action@2e7f9ec7921547d4b46598398ca573513895d0bd #v0.0.4 - name: set GCS bucket sccache variables shell: bash diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 7b453835ca..f3b624fe8d 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -35,13 +35,13 @@ jobs: uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c #v3.1.0 - name: DockerHub Registry Login - uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 + uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 #v3.1.0 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Github Registry login - uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 + uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 #v3.1.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -77,7 +77,7 @@ jobs: core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); - name: Build and push centrifugeio/centrifuge-chain - uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 #v5.1.0 + uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 #v5.3.0 with: context: . file: ./docker/centrifuge-chain/Dockerfile diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml index e92cfa624f..ee19e6c085 100644 --- a/.github/workflows/build-wasm.yml +++ b/.github/workflows/build-wasm.yml @@ -27,7 +27,7 @@ jobs: steps: # PREP - name: Check out code - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #3.5.2 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4 - name: Prep build on Ubuntu uses: ./.github/actions/prep-ubuntu diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 7d3dad762c..4b572a56c6 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -58,7 +58,7 @@ jobs: done - name: upload Docs files - uses: actions/upload-pages-artifact@0252fc4ba7626f0298f0cf00902a25c6afc77fa8 # v3.0 + uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0 with: path: ./target/doc diff --git a/.github/workflows/sanity-checks.yml b/.github/workflows/sanity-checks.yml index bccfd8ab40..9eea1f6e69 100644 --- a/.github/workflows/sanity-checks.yml +++ b/.github/workflows/sanity-checks.yml @@ -17,7 +17,7 @@ jobs: lint-fmt, lint-clippy, cargo-build, docs-build, lint-taplo] steps: - name: Check out code - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #3.5.2 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4 - name: Prep build uses: ./.github/actions/prep-ubuntu @@ -41,7 +41,7 @@ jobs: runtime: [altair, centrifuge] steps: - name: Check out code - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #3.5.2 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4 - name: Prep build uses: ./.github/actions/prep-ubuntu diff --git a/Cargo.lock b/Cargo.lock index 7a5f1779b3..5174d7d93f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -167,8 +167,6 @@ dependencies = [ "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", - "pallet-crowdloan-claim", - "pallet-crowdloan-reward", "pallet-democracy", "pallet-elections-phragmen", "pallet-ethereum", @@ -1443,8 +1441,6 @@ dependencies = [ "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", - "pallet-crowdloan-claim", - "pallet-crowdloan-reward", "pallet-democracy", "pallet-elections-phragmen", "pallet-ethereum", @@ -3001,8 +2997,6 @@ dependencies = [ "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", - "pallet-crowdloan-claim", - "pallet-crowdloan-reward", "pallet-democracy", "pallet-elections-phragmen", "pallet-ethereum", @@ -7536,49 +7530,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-crowdloan-claim" -version = "0.1.0" -dependencies = [ - "cfg-traits", - "cfg-types", - "frame-benchmarking", - "frame-support", - "frame-system", - "hex", - "pallet-balances", - "pallet-crowdloan-reward", - "pallet-vesting", - "parity-scale-codec 3.6.9", - "proofs", - "scale-info", - "sp-core", - "sp-io", - "sp-keyring", - "sp-runtime", - "sp-std", - "sp-trie", -] - -[[package]] -name = "pallet-crowdloan-reward" -version = "0.1.0" -dependencies = [ - "cfg-traits", - "cfg-types", - "frame-benchmarking", - "frame-support", - "frame-system", - "pallet-balances", - "pallet-vesting", - "parity-scale-codec 3.6.9", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-democracy" version = "4.0.0-dev" @@ -10890,16 +10841,6 @@ dependencies = [ "syn 2.0.57", ] -[[package]] -name = "proofs" -version = "2.0.0" -dependencies = [ - "parity-scale-codec 3.6.9", - "scale-info", - "sp-core", - "sp-std", -] - [[package]] name = "prost" version = "0.11.9" @@ -11564,8 +11505,6 @@ dependencies = [ "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", - "pallet-crowdloan-claim", - "pallet-crowdloan-reward", "pallet-democracy", "pallet-elections-phragmen", "pallet-ethereum", @@ -11684,8 +11623,6 @@ dependencies = [ "pallet-collator-allowlist", "pallet-collator-selection", "pallet-collective", - "pallet-crowdloan-claim", - "pallet-crowdloan-reward", "pallet-democracy", "pallet-elections-phragmen", "pallet-ethereum", diff --git a/Cargo.toml b/Cargo.toml index 1e931f9f96..bd12d51f49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ members = [ "node", "libs/mocks", "libs/primitives", - "libs/proofs", "libs/test-utils", "libs/traits", "libs/types", @@ -13,8 +12,6 @@ members = [ "pallets/bridge", "pallets/block-rewards", "pallets/collator-allowlist", - "pallets/crowdloan-claim", - "pallets/crowdloan-reward", "pallets/ethereum-transaction", "pallets/fees", "pallets/foreign-investments", @@ -236,8 +233,6 @@ pallet-anchors = { path = "pallets/anchors", default-features = false } pallet-block-rewards = { path = "pallets/block-rewards", default-features = false } pallet-bridge = { path = "pallets/bridge", default-features = false } pallet-collator-allowlist = { path = "pallets/collator-allowlist", default-features = false } -pallet-crowdloan-claim = { path = "pallets/crowdloan-claim", default-features = false } -pallet-crowdloan-reward = { path = "pallets/crowdloan-reward", default-features = false } pallet-ethereum-transaction = { path = "pallets/ethereum-transaction", default-features = false } pallet-fees = { path = "pallets/fees", default-features = false } pallet-foreign-investments = { path = "pallets/foreign-investments", default-features = false } @@ -269,7 +264,6 @@ cfg-types = { path = "libs/types", default-features = false } cfg-utils = { path = "libs/utils", default-features = false } cfg-mocks = { path = "libs/mocks", default-features = false } cfg-test-utils = { path = "libs/test-utils", default-features = false } -proofs = { path = "libs/proofs", default-features = false } # Centrifuge runtimes runtime-common = { path = "runtime/common", default-features = false } diff --git a/libs/proofs/Cargo.toml b/libs/proofs/Cargo.toml deleted file mode 100644 index 12e52207b9..0000000000 --- a/libs/proofs/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -name = "proofs" -description = "Proofs" -version = "2.0.0" -authors.workspace = true -edition.workspace = true -license.workspace = true -homepage.workspace = true -repository.workspace = true -documentation.workspace = true - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -parity-scale-codec = { workspace = true } -scale-info = { workspace = true } -sp-std = { workspace = true } - -[dev-dependencies] -sp-core = { workspace = true, default-features = true } - -[features] -default = ["std"] -std = [ - "parity-scale-codec/std", - "sp-std/std", - "scale-info/std", -] diff --git a/libs/proofs/src/lib.rs b/libs/proofs/src/lib.rs deleted file mode 100644 index abd45dec27..0000000000 --- a/libs/proofs/src/lib.rs +++ /dev/null @@ -1,185 +0,0 @@ -//! # Optimized Merkle proof verifier and bundle hasher -//! -//! This pallet provides functionality of verifying optimized merkle proofs and -//! bundle hasher. - -// Ensure we're `no_std` when compiling for WebAssembly. -#![cfg_attr(not(feature = "std"), no_std)] - -use parity_scale_codec::{Decode, Encode}; -use scale_info::TypeInfo; -use sp_std::{fmt::Debug, vec::Vec}; - -#[cfg(test)] -mod tests; - -#[cfg(test)] -mod mock; - -/// Deposit address -pub type DepositAddress = [u8; 20]; - -#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, TypeInfo)] -#[cfg_attr(feature = "std", derive(Debug))] -pub struct Proof { - pub leaf_hash: Hash, - pub sorted_hashes: Vec, -} - -impl Proof { - pub fn new(hash: Hash, sorted_hashes: Vec) -> Self { - Self { - leaf_hash: hash, - sorted_hashes, - } - } - - pub fn len(&self) -> usize { - self.sorted_hashes.len() - } - - pub fn is_empty(&self) -> bool { - self.sorted_hashes.is_empty() - } -} - -pub trait Hasher: Sized { - /// Hash type we deal with - type Hash: Default + AsRef<[u8]> + Copy + PartialEq + PartialOrd + Debug; - - /// Hashes given data to 32 byte u8. Ex: blake256, Keccak - fn hash(data: &[u8]) -> Self::Hash; -} - -pub trait Verifier: Hasher { - /// Computes hash of the a + b using `hash` function - fn hash_of(a: Self::Hash, b: Self::Hash) -> Self::Hash; - - /// Returns the initial set of hashes to verify proofs. - /// `None` implies a failed proof verification - fn initial_matches(&self, doc_root: Self::Hash) -> Option>; - - /// Verifies each proof and return true if all the proofs are valid else - /// returns false - fn verify_proofs(&self, doc_root: Self::Hash, proofs: &[Proof]) -> bool { - if proofs.is_empty() { - return false; - } - - let mut matches = match Self::initial_matches(self, doc_root) { - Some(matches) => matches, - None => return false, - }; - - proofs - .iter() - .map(|proof| inner::verify_proof::(&mut matches, proof)) - .all(|b| b) - } - - /// Verifies the proof and returns true if valid - fn verify_proof(&self, doc_root: Self::Hash, proof: &Proof) -> bool { - let mut matches = match Self::initial_matches(self, doc_root) { - Some(matches) => matches, - None => return false, - }; - - inner::verify_proof::(&mut matches, proof) - } -} -mod inner { - use super::*; - use crate::{Proof, Verifier}; - - /// This is an optimized Merkle proof checker. It caches all valid leaves in - /// an array called matches. If a proof is validated, all the intermediate - /// hashes will be added to the array. When validating a subsequent proof, - /// that proof will stop being validated as soon as a hash has been computed - /// that has been a computed hash in a previously validated proof. - /// - /// When submitting a list of proofs, the client can thus choose to chop of - /// all the already proven nodes when submitting multiple proofs. - /// - /// matches: matches will have a pre computed hashes provided by the client - /// and document root of the reference anchor. static proofs are used to - /// computed the pre computed hashes and the result is checked against - /// document root provided. - pub fn verify_proof(matches: &mut Vec, proof: &Proof) -> bool { - let Proof { - leaf_hash, - sorted_hashes, - } = proof.clone(); - - // if leaf_hash is already cached/computed earlier - if matches.contains(&leaf_hash) { - return true; - } - - let mut hash = leaf_hash; - for proof in sorted_hashes { - matches.push(proof); - hash = V::hash_of(hash, proof); - if matches.contains(&hash) { - return true; - } - matches.push(hash); - } - - false - } -} - -pub mod hashing { - use sp_std::vec::Vec; - - use crate::{DepositAddress, Hasher, Proof}; - - /// computes sorted hash of the a and b - /// if a < b: hash(a+b) - /// else: hash(b+a) - pub fn sort_hash_of(a: H::Hash, b: H::Hash) -> H::Hash { - if a < b { - return hash_of::(a, b); - } - - hash_of::(b, a) - } - - /// computes hash of the a + b - pub fn hash_of(a: H::Hash, b: H::Hash) -> H::Hash { - let data = [a.as_ref(), b.as_ref()].concat(); - H::hash(&data) - } - - /// Return a bundled hash from a list of hashes. - /// - /// This function appends `deposit_address` and all the given `hashes` from - /// the proofs and returns the result hash - pub fn bundled_hash( - hashes: Vec, - deposit_address: DepositAddress, - ) -> H::Hash { - let data = hashes - .into_iter() - .fold(deposit_address.to_vec(), |acc, hash| { - [acc.as_slice(), hash.as_ref()].concat() - }); - H::hash(data.as_slice()) - } - - /// Return a bundled hash from a list of proofs. - /// - /// Same as [`bundled_hash()`] function, but here a list of proofs is given. - /// This function the appends `deposit_address` - /// and all leaf hashes from given `proofs` and returns a bundled hash. - pub fn bundled_hash_from_proofs( - proofs: Vec>, - deposit_address: DepositAddress, - ) -> H::Hash { - // Extract (leaf) hashes from proofs - let hashes = proofs.iter().map(|proof| proof.leaf_hash).collect(); - - // Compute the resulting bundled hash - bundled_hash::(hashes, deposit_address) - } -} diff --git a/libs/proofs/src/mock.rs b/libs/proofs/src/mock.rs deleted file mode 100644 index 397ac1bf64..0000000000 --- a/libs/proofs/src/mock.rs +++ /dev/null @@ -1,104 +0,0 @@ -use sp_core::{blake2_256, keccak_256, H256}; -use sp_std::vec::Vec; - -use crate::{hashing::sort_hash_of, Hasher, Proof}; - -pub struct BundleHasher; - -impl Hasher for BundleHasher { - type Hash = H256; - - fn hash(data: &[u8]) -> Self::Hash { - keccak_256(data).into() - } -} - -pub struct ProofVerifier; - -impl Hasher for ProofVerifier { - type Hash = H256; - - fn hash(data: &[u8]) -> Self::Hash { - blake2_256(data).into() - } -} - -impl crate::Verifier for ProofVerifier { - fn hash_of(a: Self::Hash, b: Self::Hash) -> Self::Hash { - sort_hash_of::(a, b) - } - - fn initial_matches(&self, doc_root: Self::Hash) -> Option> { - Some(vec![doc_root]) - } -} - -pub fn get_valid_proof() -> (Proof, H256) { - let proof = Proof { - leaf_hash: [ - 1, 93, 41, 93, 124, 185, 25, 20, 141, 93, 101, 68, 16, 11, 142, 219, 3, 124, 155, 37, - 85, 23, 189, 209, 48, 97, 34, 3, 169, 157, 88, 159, - ] - .into(), - sorted_hashes: vec![ - [ - 113, 229, 58, 223, 178, 220, 200, 69, 191, 246, 171, 254, 8, 183, 211, 75, 54, 223, - 224, 197, 170, 112, 248, 56, 10, 176, 17, 205, 86, 130, 233, 16, - ] - .into(), - [ - 133, 11, 212, 75, 212, 65, 247, 178, 200, 157, 5, 39, 57, 135, 63, 126, 166, 92, - 232, 170, 46, 155, 223, 237, 50, 237, 43, 101, 180, 104, 126, 84, - ] - .into(), - [ - 197, 248, 165, 165, 247, 119, 114, 231, 95, 114, 94, 16, 66, 142, 230, 184, 78, - 203, 73, 104, 24, 82, 134, 154, 180, 129, 71, 223, 72, 31, 230, 15, - ] - .into(), - [ - 50, 5, 28, 219, 118, 141, 222, 221, 133, 174, 178, 212, 71, 94, 64, 44, 80, 218, - 29, 92, 77, 40, 241, 16, 126, 48, 119, 31, 6, 147, 224, 5, - ] - .into(), - ], - }; - - let doc_root: H256 = [ - 25, 102, 189, 46, 86, 242, 48, 217, 254, 16, 20, 211, 98, 206, 125, 92, 167, 175, 70, 161, - 35, 135, 33, 80, 225, 247, 4, 240, 138, 86, 167, 142, - ] - .into(); - - (proof, doc_root) -} - -pub fn get_invalid_proof() -> (Proof, H256) { - let proof = Proof { - leaf_hash: [ - 1, 93, 41, 93, 124, 185, 25, 20, 141, 93, 101, 68, 16, 11, 142, 219, 3, 124, 155, 37, - 85, 23, 189, 20, 48, 97, 34, 3, 169, 157, 88, 159, - ] - .into(), - sorted_hashes: vec![ - [ - 113, 229, 58, 22, 178, 220, 200, 69, 191, 246, 171, 254, 8, 183, 211, 75, 54, 223, - 224, 197, 170, 112, 248, 56, 10, 176, 17, 205, 86, 130, 233, 16, - ] - .into(), - [ - 133, 11, 212, 75, 212, 65, 247, 178, 200, 157, 5, 39, 57, 135, 63, 126, 166, 92, - 23, 170, 4, 155, 223, 237, 50, 237, 43, 101, 180, 104, 126, 84, - ] - .into(), - ], - }; - - let doc_root: H256 = [ - 25, 102, 189, 46, 86, 242, 48, 217, 254, 16, 20, 211, 98, 206, 125, 92, 167, 175, 70, 161, - 35, 135, 33, 80, 225, 247, 4, 240, 138, 86, 167, 142, - ] - .into(); - - (proof, doc_root) -} diff --git a/libs/proofs/src/tests.rs b/libs/proofs/src/tests.rs deleted file mode 100644 index 37efd1b351..0000000000 --- a/libs/proofs/src/tests.rs +++ /dev/null @@ -1,108 +0,0 @@ -mod tests { - use sp_core::H256; - - use crate::{ - hashing::bundled_hash, - mock::{get_invalid_proof, get_valid_proof, BundleHasher, ProofVerifier}, - Proof, Verifier, - }; - - #[test] - fn bundled_hash_with_leaves() { - let proofs: Vec = vec![ - [ - 103, 46, 60, 60, 148, 2, 8, 108, 29, 15, 111, 98, 88, 90, 56, 3, 57, 124, 5, 25, - 100, 82, 231, 99, 186, 115, 165, 102, 22, 245, 83, 147, - ] - .into(), - [ - 112, 102, 224, 155, 227, 136, 160, 106, 127, 252, 25, 95, 234, 206, 155, 3, 237, - 180, 242, 172, 240, 225, 85, 46, 125, 73, 42, 225, 214, 242, 239, 184, - ] - .into(), - [ - 131, 137, 170, 250, 176, 243, 90, 79, 242, 135, 64, 183, 249, 106, 200, 177, 96, - 105, 70, 38, 50, 221, 139, 175, 247, 161, 201, 31, 71, 169, 101, 114, - ] - .into(), - [ - 181, 110, 49, 204, 113, 201, 241, 253, 213, 177, 124, 217, 157, 68, 43, 8, 157, - 127, 218, 194, 90, 40, 153, 33, 125, 155, 10, 73, 20, 173, 89, 193, - ] - .into(), - ]; - - let deposit_address = [ - 75, 151, 92, 119, 170, 193, 75, 255, 44, 88, 202, 225, 39, 220, 51, 9, 230, 2, 121, 129, - ]; - - let res: H256 = [ - 92, 231, 93, 51, 106, 224, 159, 91, 206, 250, 124, 26, 16, 236, 141, 56, 42, 126, 225, - 64, 28, 191, 37, 51, 131, 63, 224, 233, 24, 207, 211, 182, - ] - .into(); - let got = bundled_hash::(proofs, deposit_address); - assert_eq!(res, got, "must be equal"); - } - - #[test] - fn validate_proof_success() { - let (proof, root) = get_valid_proof(); - let pv = ProofVerifier; - assert!(pv.verify_proof(root, &proof)) - } - - #[test] - fn validate_proof_failed() { - let (proof, root) = get_invalid_proof(); - let pv = ProofVerifier; - assert!(!pv.verify_proof(root, &proof)); - } - - #[test] - fn validate_proof_no_proofs() { - let proof: Proof = Proof { - leaf_hash: [ - 1, 93, 41, 93, 124, 185, 25, 20, 141, 93, 101, 68, 16, 11, 142, 219, 3, 124, 155, - 37, 85, 23, 189, 209, 48, 97, 34, 3, 169, 157, 88, 159, - ] - .into(), - sorted_hashes: vec![], - }; - - let doc_root: H256 = [ - 25, 102, 189, 46, 86, 242, 48, 217, 254, 16, 20, 211, 98, 206, 125, 92, 167, 175, 70, - 161, 35, 135, 33, 80, 225, 247, 4, 240, 138, 86, 167, 142, - ] - .into(); - - let pv = ProofVerifier; - assert!(!pv.verify_proof(doc_root, &proof)); - } - - #[test] - fn validate_proofs_success() { - let (vp1, doc_root) = get_valid_proof(); - let (vp2, _) = get_valid_proof(); - let proofs = vec![vp1, vp2]; - let pv = ProofVerifier; - assert!(pv.verify_proofs(doc_root, &proofs)); - } - - #[test] - fn validate_proofs_failed() { - let (vp, doc_root) = get_valid_proof(); - let (ivp, _) = get_invalid_proof(); - let proofs = vec![vp, ivp]; - let pv = ProofVerifier; - assert!(!pv.verify_proofs(doc_root, &proofs)); - } - - #[test] - fn validate_proofs_no_proofs() { - let (_, doc_root) = get_valid_proof(); - let proofs = vec![]; - let pv = ProofVerifier; - assert!(!pv.verify_proofs(doc_root, &proofs)); - } -} diff --git a/libs/traits/src/lib.rs b/libs/traits/src/lib.rs index be11870b37..ec97102eb5 100644 --- a/libs/traits/src/lib.rs +++ b/libs/traits/src/lib.rs @@ -19,22 +19,16 @@ #![cfg_attr(not(feature = "std"), no_std)] use frame_support::{ - dispatch::{DispatchResult, DispatchResultWithPostInfo}, + dispatch::DispatchResult, pallet_prelude::{RuntimeDebug, TypeInfo}, traits::UnixTime, Parameter, }; use impl_trait_for_tuples::impl_for_tuples; use orml_traits::asset_registry; -use parity_scale_codec::{Codec, Decode, Encode, MaxEncodedLen}; -use sp_runtime::{ - traits::{ - AtLeast32BitUnsigned, Bounded, MaybeDisplay, MaybeSerialize, MaybeSerializeDeserialize, - Member, Zero, - }, - DispatchError, -}; -use sp_std::{fmt::Debug, hash::Hash, marker::PhantomData, vec::Vec}; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use sp_runtime::{traits::Member, DispatchError}; +use sp_std::{fmt::Debug, marker::PhantomData, vec::Vec}; /// Traits related to checked changes. pub mod changes; @@ -61,63 +55,6 @@ pub mod swaps; /// Traits related to benchmarking tooling. pub mod benchmarking; -/// A trait used for loosely coupling the claim pallet with a reward mechanism. -/// -/// ## Overview -/// The crowdloan reward mechanism is separated from the crowdloan claiming -/// process, the latter being generic, acting as a kind of proxy to the -/// rewarding mechanism, that is specific to to each crowdloan campaign. The aim -/// of this pallet is to ensure that a claim for a reward payout is well-formed, -/// checking for replay attacks, spams or invalid claim (e.g. unknown -/// contributor, exceeding reward amount, ...). -/// See the [`crowdloan-reward`] pallet, that implements a reward mechanism with -/// vesting, for instance. -pub trait Reward { - /// The account from the parachain, that the claimer provided in her/his - /// transaction. - type ParachainAccountId: Debug - + MaybeSerialize - + MaybeSerializeDeserialize - + Member - + Ord - + Parameter - + TypeInfo; - - /// The contribution amount in relay chain tokens. - type ContributionAmount: AtLeast32BitUnsigned - + Codec - + Copy - + Debug - + Default - + MaybeSerializeDeserialize - + Member - + Parameter - + Zero - + TypeInfo; - - /// Block number type used by the runtime - type BlockNumber: AtLeast32BitUnsigned - + Bounded - + Copy - + Debug - + Default - + Hash - + MaybeDisplay - + MaybeSerializeDeserialize - + Member - + Parameter - + TypeInfo; - - /// Rewarding function that is invoked from the claim pallet. - /// - /// If this function returns successfully, any subsequent claim of the same - /// claimer will be rejected by the claim module. - fn reward( - who: Self::ParachainAccountId, - contribution: Self::ContributionAmount, - ) -> DispatchResultWithPostInfo; -} - /// A trait that can be used to fetch the nav and update nav for a given pool pub trait PoolNAV { type ClassId; diff --git a/pallets/crowdloan-claim/Cargo.toml b/pallets/crowdloan-claim/Cargo.toml deleted file mode 100644 index 17ef52cdb6..0000000000 --- a/pallets/crowdloan-claim/Cargo.toml +++ /dev/null @@ -1,76 +0,0 @@ -[package] -name = "pallet-crowdloan-claim" -description = "Module for processing crowdloan claim rewards." -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true -homepage.workspace = true -repository.workspace = true -documentation.workspace = true - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -# General dependencies -parity-scale-codec = { workspace = true } -scale-info = { workspace = true } - -# Substrate dependencies -frame-support = { workspace = true } -frame-system = { workspace = true } -pallet-balances = { workspace = true } -sp-core = { workspace = true } -sp-runtime = { workspace = true } -sp-std = { workspace = true } - -# optional dependencies for benchmarking -frame-benchmarking = { workspace = true, optional = true } - -# Local dependencies -cfg-traits = { workspace = true } -cfg-types = { workspace = true } -proofs = { workspace = true } - -[dev-dependencies] -hex = { workspace = true } -pallet-crowdloan-reward = { workspace = true } -pallet-vesting = { workspace = true, default-features = true } -sp-io = { workspace = true, default-features = true } -sp-keyring = { workspace = true, default-features = true } -sp-trie = { workspace = true, default-features = true } - -[features] -default = ["std"] -std = [ - "parity-scale-codec/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "sp-std/std", - "cfg-traits/std", - "proofs/std", - "cfg-types/std", - "frame-benchmarking/std", - "scale-info/std", - "sp-core/std", - "sp-runtime/std", -] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "cfg-traits/runtime-benchmarks", - "cfg-types/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -] -try-runtime = [ - "cfg-traits/try-runtime", - "frame-support/try-runtime", - "cfg-types/try-runtime", - "frame-system/try-runtime", - "pallet-balances/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/pallets/crowdloan-claim/README.md b/pallets/crowdloan-claim/README.md deleted file mode 100644 index 8960a93696..0000000000 --- a/pallets/crowdloan-claim/README.md +++ /dev/null @@ -1,5 +0,0 @@ -Crowdloan claiming functionality pallet. - -Takes care of verifying claims of contributors and calling a rewarding pallet, that provides the actual rewarding strategy. - -License: GPL-v3 diff --git a/pallets/crowdloan-claim/src/benchmarking.rs b/pallets/crowdloan-claim/src/benchmarking.rs deleted file mode 100644 index 7e697e2b3f..0000000000 --- a/pallets/crowdloan-claim/src/benchmarking.rs +++ /dev/null @@ -1,418 +0,0 @@ -#![cfg(feature = "runtime-benchmarks")] -use frame_benchmarking::{account, benchmarks}; -use frame_support::{StorageHasher, Twox128}; -use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; -use sp_runtime::Perbill; - -use super::*; - -const CONTRIBUTION: u128 = 40000000000000000000; - -benchmarks! { - where_clause {where T: pallet_balances::Config} - - claim_reward_ed25519 { - let caller: T::AccountId = account("claimer", 0, 0); - let relay_account: T::RelayChainAccountId = get_account_relay_ed25519::(); - init_pallets::(relay_account.clone()); - let para_account: ParachainAccountIdOf = get_account_para_ed25519::(); - let identity_proof: sp_runtime::MultiSignature = get_signature_ed25519::(); - let contribution: T::Balance = get_contribution::(CONTRIBUTION); - let contribution_proof: proofs::Proof = get_proof::( - relay_account.clone(), - contribution - ); - - }: claim_reward(RawOrigin::Signed(caller), relay_account, para_account, identity_proof, contribution_proof, contribution) - verify { - // TODO: Not sure if it is even possible to use the balances pallet here. But "T" does not implement the pallet_balances::Config - // so currently, I am not able to see a solution to get to the balances. Although, one might use storage directy. But I - // am lazy right now. The tests cover this quite well... - } - - claim_reward_sr25519 { - let caller: T::AccountId = account("claimer", 0, 0); - let relay_account: T::RelayChainAccountId = get_account_relay_sr25519::(); - init_pallets::(relay_account.clone()); - let para_account: ParachainAccountIdOf = get_account_para_sr25519::(); - let identity_proof: sp_runtime::MultiSignature = get_signature_sr25519::(); - let contribution: T::Balance = get_contribution::(CONTRIBUTION); - let contribution_proof: proofs::Proof = get_proof::( - relay_account.clone(), - contribution - ); - }: claim_reward(RawOrigin::Signed(caller), relay_account, para_account, identity_proof, contribution_proof, contribution) - verify{ - // TODO: Not sure if it is even possible to use the balances pallet here. But "T" does not implement the pallet_balances::Config - // so currently, I am not able to see a solution to get to the balances. Although, one might use storage directy. But I - // am lazy right now. The tests cover this quite well.. - } - - claim_reward_ecdsa { - let caller: T::AccountId = account("claimer", 0, 0); - let relay_account: T::RelayChainAccountId = get_account_relay_ecdsa::(); - init_pallets::(relay_account.clone()); - let para_account: ParachainAccountIdOf = get_account_para_ecdsa::(); - let identity_proof: sp_runtime::MultiSignature = get_signature_ecdsa::(); - let contribution: T::Balance = get_contribution::(CONTRIBUTION); - let contribution_proof: proofs::Proof = get_proof::( - relay_account.clone(), - contribution - ); - - }: claim_reward(RawOrigin::Signed(caller), relay_account, para_account, identity_proof, contribution_proof, contribution) - verify { - // TODO: Not sure if it is even possible to use the balances pallet here. But "T" does not implement the pallet_balances::Config - // so currently, I am not able to see a solution to get to the balances. Although, one might use storage directy. But I - // am lazy right now. The tests cover this quite well... - } - - initialize { - let contributions: RootHashOf = get_root::( - get_account_relay_sr25519::(), - get_contribution::(CONTRIBUTION) - ); - let locked_at = 1u32.into(); - let index: TrieIndex = 1u32.into(); - let lease_start = 1u32.into(); - let lease_period = 1u32.into(); - }: _(RawOrigin::Root, contributions, locked_at, index, lease_start, lease_period) - verify { - assert!(Pallet::::contributions().is_some()); - assert!(Pallet::::locked_at().is_some()); - assert!(Pallet::::crowdloan_trie_index().is_some()); - assert_eq!(Pallet::::lease_start(), 1u32.into()); - assert_eq!(Pallet::::lease_period(), 1u32.into()); - } - - set_lease_start{ - let start = 1u32.into(); - }: _(RawOrigin::Root, start) - verify { - assert_eq!(Pallet::::lease_start(), 1u32.into()); - } - - set_lease_period{ - let period = 1u32.into(); - }: _(RawOrigin::Root, period) - verify { - assert_eq!(Pallet::::lease_period(), 1u32.into()); - } - - set_contributions_root { - let root: RootHashOf = get_root::( - get_account_relay_sr25519::(), - get_contribution::(CONTRIBUTION) - ); - }: _(RawOrigin::Root, root) - verify { - assert!(Pallet::::contributions().is_some()); - } - - set_locked_at { - let locked = 1u32.into(); - }: _(RawOrigin::Root, locked) - verify { - assert!(Pallet::::locked_at().is_some()); - } - - set_crowdloan_trie_index { - let index: TrieIndex = 1u32.into(); - }: _(RawOrigin::Root, index) - verify { - assert!(Pallet::::crowdloan_trie_index().is_some()); - } -} - -// Helper functions from here on -// -fn get_contribution(amount: u128) -> T::Balance { - match amount.try_into() { - Ok(contribution) => contribution, - Err(_) => panic!(), - } -} - -#[allow(dead_code)] -fn get_balance(amount: u128) -> T::Balance { - match amount.try_into() { - Ok(contribution) => contribution, - Err(_) => panic!(), - } -} - -// In order to detangle from sp-core/fullCrypto which seems to be missing some -// trait implementations -#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode)] -struct Signature(pub [u8; 64]); - -#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode)] -struct SignatureEcdsa(pub [u8; 65]); - -#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode)] -enum MultiSignature { - /// An Ed25519 signature. - Ed25519(Signature), - /// An Sr25519 signature. - Sr25519(Signature), - /// An ECDSA/SECP256k1 signature. - Ecdsa(SignatureEcdsa), -} - -// All accounts in the following are derived from this Mnemonic -// -// "flight client wild replace umbrella april addict below deer inch mix -// surface" -// - -fn get_account_para_ed25519() -> ParachainAccountIdOf { - let pub_key: [u8; 32] = [ - 130, 168, 6, 216, 161, 211, 10, 240, 194, 245, 185, 187, 131, 189, 246, 132, 115, 145, 87, - 11, 164, 80, 205, 180, 87, 88, 208, 16, 60, 59, 83, 186, - ]; - - parity_scale_codec::Decode::decode(&mut &pub_key[..]).unwrap() -} - -fn get_account_para_ecdsa() -> ParachainAccountIdOf { - let pub_key: [u8; 32] = [ - 89, 211, 18, 12, 18, 109, 171, 175, 21, 236, 203, 33, 33, 168, 153, 55, 198, 227, 184, 139, - 77, 115, 132, 73, 59, 235, 90, 175, 221, 88, 44, 247, - ]; - - parity_scale_codec::Decode::decode(&mut &pub_key[..]).unwrap() -} - -fn get_account_para_sr25519() -> ParachainAccountIdOf { - let pub_key: [u8; 32] = [ - 202, 13, 159, 82, 100, 222, 166, 237, 52, 113, 173, 161, 100, 206, 112, 67, 188, 178, 135, - 53, 61, 178, 143, 121, 157, 182, 189, 207, 59, 166, 7, 92, - ]; - - parity_scale_codec::Decode::decode(&mut &pub_key[..]).unwrap() -} - -fn get_signature_ecdsa() -> sp_runtime::MultiSignature { - let msg: [u8; 65] = [ - 234, 70, 108, 203, 158, 59, 224, 51, 248, 194, 209, 45, 0, 146, 83, 185, 172, 19, 254, 12, - 148, 232, 249, 183, 131, 64, 115, 3, 39, 230, 101, 120, 87, 230, 202, 183, 162, 167, 122, - 95, 186, 231, 179, 183, 119, 241, 166, 55, 10, 21, 243, 228, 147, 73, 2, 84, 34, 211, 51, - 40, 245, 198, 16, 140, 0, - ]; - - let local_sig = SignatureEcdsa(msg); - let local_multisig = MultiSignature::Ecdsa(local_sig); - - parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&local_multisig).as_slice(), - ) - .unwrap() -} - -fn get_signature_sr25519() -> sp_runtime::MultiSignature { - let msg: [u8; 64] = [ - 132, 172, 248, 32, 17, 107, 155, 94, 246, 87, 44, 158, 2, 230, 220, 225, 170, 217, 104, - 189, 211, 57, 98, 161, 179, 160, 79, 23, 185, 165, 250, 1, 160, 253, 160, 116, 27, 168, 19, - 82, 30, 175, 146, 222, 178, 143, 46, 84, 15, 162, 146, 212, 244, 39, 166, 198, 137, 116, - 30, 14, 184, 17, 212, 141, - ]; - - let local_sig = Signature(msg); - let local_multisig = MultiSignature::Sr25519(local_sig); - - parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&local_multisig).as_slice(), - ) - .unwrap() -} - -fn get_signature_ed25519() -> sp_runtime::MultiSignature { - let msg: [u8; 64] = [ - 138, 180, 126, 32, 200, 234, 37, 182, 93, 251, 36, 179, 98, 233, 42, 246, 118, 207, 203, - 108, 89, 229, 1, 218, 194, 32, 206, 88, 199, 27, 224, 54, 90, 214, 233, 122, 229, 50, 175, - 248, 142, 175, 37, 185, 212, 199, 93, 92, 58, 91, 94, 29, 55, 42, 67, 107, 119, 155, 143, - 192, 66, 181, 236, 8, - ]; - let local_sig = Signature(msg); - let local_multisig = MultiSignature::Ed25519(local_sig); - - parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&local_multisig).as_slice(), - ) - .unwrap() -} - -fn get_account_relay_ecdsa() -> T::RelayChainAccountId { - let pub_key: [u8; 32] = [ - 89, 211, 18, 12, 18, 109, 171, 175, 21, 236, 203, 33, 33, 168, 153, 55, 198, 227, 184, 139, - 77, 115, 132, 73, 59, 235, 90, 175, 221, 88, 44, 247, - ]; - - parity_scale_codec::Decode::decode(&mut &pub_key[..]).unwrap() -} - -fn get_account_relay_sr25519() -> T::RelayChainAccountId { - let pub_key: [u8; 32] = [ - 202, 13, 159, 82, 100, 222, 166, 237, 52, 113, 173, 161, 100, 206, 112, 67, 188, 178, 135, - 53, 61, 178, 143, 121, 157, 182, 189, 207, 59, 166, 7, 92, - ]; - - parity_scale_codec::Decode::decode(&mut &pub_key[..]).unwrap() -} - -fn get_account_relay_ed25519() -> T::RelayChainAccountId { - let pub_key: [u8; 32] = [ - 130, 168, 6, 216, 161, 211, 10, 240, 194, 245, 185, 187, 131, 189, 246, 132, 115, 145, 87, - 11, 164, 80, 205, 180, 87, 88, 208, 16, 60, 59, 83, 186, - ]; - - parity_scale_codec::Decode::decode(&mut &pub_key[..]).unwrap() -} - -fn get_proof( - relay: T::RelayChainAccountId, - contribution: T::Balance, -) -> proofs::Proof { - let mut v: Vec = relay.encode(); - v.extend(contribution.encode()); - let leaf_hash: T::Hash = ::Hashing::hash(&v); - - let mut sorted_hashed: Vec = Vec::new(); - - // 10-leaf tree - let leaf_hash_0: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[0u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_1: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[1u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_3: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[2u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_4: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[3u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_5: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[4u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_6: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[5u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_7: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[6u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_8: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[7u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_9: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[8u32; 32]).as_slice(), - ) - .unwrap(); - let node_0 = proofs::hashing::sort_hash_of::>(leaf_hash_0, leaf_hash_1); - let node_2 = proofs::hashing::sort_hash_of::>(leaf_hash_4, leaf_hash_5); - let node_3 = proofs::hashing::sort_hash_of::>(leaf_hash_6, leaf_hash_7); - let node_4 = proofs::hashing::sort_hash_of::>(leaf_hash_8, leaf_hash_9); - let node_01 = proofs::hashing::sort_hash_of::>(node_2, node_3); - - sorted_hashed.push(leaf_hash_3); - sorted_hashed.push(node_0); - sorted_hashed.push(node_01); - sorted_hashed.push(node_4); - - proofs::Proof::new(leaf_hash, sorted_hashed) -} - -fn get_root(relay: T::RelayChainAccountId, contribution: T::Balance) -> RootHashOf { - let mut v: Vec = relay.encode(); - v.extend(contribution.encode()); - let leaf_hash: T::Hash = ::Hashing::hash(&v); - - // 10-leaf tree - let leaf_hash_0: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[0u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_1: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[1u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_2: T::Hash = leaf_hash; - let leaf_hash_3: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[2u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_4: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[3u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_5: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[4u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_6: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[5u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_7: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[6u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_8: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[7u32; 32]).as_slice(), - ) - .unwrap(); - let leaf_hash_9: T::Hash = parity_scale_codec::Decode::decode( - &mut parity_scale_codec::Encode::encode(&[8u32; 32]).as_slice(), - ) - .unwrap(); - let node_0 = proofs::hashing::sort_hash_of::>(leaf_hash_0, leaf_hash_1); - let node_1 = proofs::hashing::sort_hash_of::>(leaf_hash_2, leaf_hash_3); - let node_2 = proofs::hashing::sort_hash_of::>(leaf_hash_4, leaf_hash_5); - let node_3 = proofs::hashing::sort_hash_of::>(leaf_hash_6, leaf_hash_7); - let node_4 = proofs::hashing::sort_hash_of::>(leaf_hash_8, leaf_hash_9); - let node_00 = proofs::hashing::sort_hash_of::>(node_0, node_1); - let node_01 = proofs::hashing::sort_hash_of::>(node_2, node_3); - let node_000 = proofs::hashing::sort_hash_of::>(node_00, node_01); - - proofs::hashing::sort_hash_of::>(node_000, node_4).into() -} - -fn init_pallets(relay_account: T::RelayChainAccountId) { - // Inject storage here. Using the - >::put(get_root::( - relay_account, - get_contribution::(CONTRIBUTION), - )); - >::put(Into::::into(100u32)); - >::put(BlockNumberFor::::from(0u32)); - >::put(BlockNumberFor::::from(0u32)); - >::put(BlockNumberFor::::from(400u32)); - >::put(Into::::into(1u32)); - - let vesting_start_key = create_final_key_crowdloan_reward(b"VestingStart"); - let vesting_start: BlockNumberFor = 100u32.into(); - frame_support::storage::unhashed::put(&vesting_start_key, &vesting_start); - - let vesting_period_key = create_final_key_crowdloan_reward(b"VestingPeriod"); - let vesting_period: BlockNumberFor = 500u32.into(); - frame_support::storage::unhashed::put(&vesting_period_key, &vesting_period); - - let direct_payout_ratio_key = create_final_key_crowdloan_reward(b"DirectPayoutRatio"); - let direct_payout_ratio: Perbill = Perbill::from_percent(20u32); - frame_support::storage::unhashed::put(&direct_payout_ratio_key, &direct_payout_ratio); -} - -fn create_final_key_crowdloan_reward(element: &[u8]) -> [u8; 32] { - let mut final_key = [0u8; 32]; - final_key[0..16].copy_from_slice(&Twox128::hash(b"CrowdloanReward")); - final_key[16..32].copy_from_slice(&Twox128::hash(element)); - final_key -} diff --git a/pallets/crowdloan-claim/src/lib.rs b/pallets/crowdloan-claim/src/lib.rs deleted file mode 100644 index b88cfe9982..0000000000 --- a/pallets/crowdloan-claim/src/lib.rs +++ /dev/null @@ -1,749 +0,0 @@ -// Copyright 2024 Centrifuge Foundation (centrifuge.io). -// -// This file is part of the Centrifuge chain project. -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -//! # Crowdloan Claim Pallet -//! -//! A pallet used for claiming reward payouts for crowdloan campaigns. This -//! does not implement the rewarding strategy, that is the role of the -//! [`pallet-crowdloan-reward`] pallet. -//! -//! ## Overview -//! This pallet is used to proces reward claims from contributors who locked -//! tokens on the Polkadot/Kusama relay chain for participating in a crowdloan -//! campaign for a parachain slot acquisition. -//! -//! This Pallet is intimately bound to the [`pallet-crowdloan-reward`] pallet, -//! where the rewarding strategy is implemented. -//! -//! ## Terminology -//! For information on terms and concepts used in this pallet, -//! please refer to the pallet' specification document. -//! -//! ## Goals -//! The aim of this pallet is to ensure that a contributor who's claiming a -//! reward is eligible for it and avoid potential attacks, such as, for -//! instance, Denial of Service (DoS) or spams by requiring fee payment. -//! -//! ## Dependencies -//! As stated in the overview of this pallet, the latter relies on the -//! [`pallet-crowdloan-reward`] pallet to implement the specific rewarding -//! strategy of a parachain. A rewarding pallet must implement the -//! [`pallet-crowdloan-claim::traits::Reward`] trait that is declared in this -//! pallet. For this pallet to be able to interact with a reward pallet, it must -//! be loosely coupled to the former using an associated type which includes the -//! [`pallet-crowdloan-claim::traits::Reward`] trait. -//! -//! ## References -//! - [Building a Custom Pallet](https://substrate.dev/docs/en/tutorials/build-a-dapp/pallet). -//! Retrieved April 5th, 2021. -//! -//! ## Credits -//! The Centrifugians Tribe - -// Ensure we're `no_std` when compiling for WebAssembly. -#![cfg_attr(not(feature = "std"), no_std)] - -// ---------------------------------------------------------------------------- -// Imports and dependencies -// ---------------------------------------------------------------------------- -use cfg_traits::Reward; -// Runtime, system and frame primitives -use frame_support::{ - ensure, - traits::{EnsureOrigin, Get}, - PalletId, -}; -use frame_system::ensure_root; -// Re-export in crate namespace (for runtime construction) -pub use pallet::*; -use parity_scale_codec::Encode; -use proofs::{Hasher, Proof, Verifier}; -use sp_core::crypto::AccountId32; -use sp_runtime::{ - sp_std::{vec, vec::Vec}, - traits::{AccountIdConversion, Hash, MaybeSerialize, Saturating, Verify, Zero}, - DispatchResult, MultiSignature, -}; -use sp_std::fmt::Debug; - -// Extrinsics weight information -pub use crate::weights::WeightInfo; - -// Mock runtime and unit test cases -#[cfg(test)] -mod mock; -#[cfg(test)] -mod tests; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - -// Extrinsics weight information (computed through runtime benchmarking) -pub mod weights; - -/// Prefix that polkadot-js extension prepends our signed bytes into. -/// See: https://github.com/polkadot-js/common/blob/v7.6.1/packages/util/src/u8a/wrap.ts -const PRE_FIX: &[u8] = b""; - -/// Postfix that polkadot-js extension postpends our signed bytes into. -/// See: https://github.com/polkadot-js/common/blob/v7.6.1/packages/util/src/u8a/wrap.ts -const POST_FIX: &[u8] = b""; - -/// A type alias for crowdloan's child trie root hash, from this claim pallet's -/// point of view. -/// -/// When setting up the pallet via the [`initialize`] transaction, the -/// child trie root hash containing all contributions, is transfered from -/// the [`crowdloan`] pallet' storage to [`Contributions`] storage item -// of this pallet. -/// The [`Contributions`] root hash is used to check if a contributor is -/// eligible for a reward payout and to get the amount of her/his contribution -/// (in relay chain's native token) to a crowdloan campaign. -type RootHashOf = ::Hash; - -/// A type alias for the parachain account identifier from this claim pallet's -/// point of view -type ParachainAccountIdOf = <::RewardMechanism as Reward>::ParachainAccountId; - -/// Index of the crowdloan campaign inside the -/// [crowdloan.rs](https://github.com/paritytech/polkadot/blob/77b3aa5cb3e8fa7ed063d5fbce1ae85f0af55c92/runtime/common/src/crowdloan.rs#L80) -/// on polkadot. -type TrieIndex = u32; - -/// A type that works as an index for which crowdloan the pallet is currently -/// in. Can also be seen as some kind of counter. -type Index = u32; - -/// Verifier struct, that implements our own traits to verify our proofs -struct ProofVerifier(sp_std::marker::PhantomData); - -impl ProofVerifier { - pub fn new() -> Self { - ProofVerifier(sp_std::marker::PhantomData) - } -} - -impl Hasher for ProofVerifier { - type Hash = T::Hash; - - fn hash(data: &[u8]) -> Self::Hash { - ::hash(data) - } -} - -impl Verifier for ProofVerifier { - fn hash_of(a: Self::Hash, b: Self::Hash) -> Self::Hash { - proofs::hashing::sort_hash_of::(a, b) - } - - fn initial_matches(&self, doc_root: Self::Hash) -> Option> { - Some(vec![doc_root]) - } -} - -// ---------------------------------------------------------------------------- -// Pallet module -// ---------------------------------------------------------------------------- - -// Crowdloan claim pallet module -// -// The name of the pallet is provided by `construct_runtime` and is used as -// the unique identifier for the pallet's storage. It is not defined in the -// pallet itself. -#[frame_support::pallet] -pub mod pallet { - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - - use super::*; - - // Crowdloan claim pallet type declaration. - // - // This structure is a placeholder for traits and functions implementation - // for the pallet. - #[pallet::pallet] - pub struct Pallet(_); - - // ------------------------------------------------------------------------ - // Pallet configuration - // ------------------------------------------------------------------------ - - /// Crowdloan claim pallet's configuration trait. - /// - /// Associated types and constants are declared in this trait. If the pallet - /// depends on other super-traits, the latter must be added to this trait, - /// such as, in this case, [`frame_system::Config`] and - /// [`pallet_balances::Config`] super-traits. Note that - /// [`frame_system::Config`] must always be included. - #[pallet::config] - pub trait Config: frame_system::Config + pallet_balances::Config { - /// Associated type for Event enum - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// Constant configuration parameter to store the pallet identifier for - /// the pallet. - /// - /// The pallet identifier may be of the form - /// `PalletId(*b"cc/claim")`. - #[pallet::constant] - type PalletId: Get; - - /// Contributor's account identifier on the relay chain. - type RelayChainAccountId: Debug - + MaybeSerialize - + MaybeSerializeDeserialize - + Member - + Ord - + Parameter - + Into - + MaxEncodedLen; - - /// The maximum length (i.e. depth of the tree) we allow a proof to - /// have. This mitigates DDoS attacks solely. We choose 30, which by a - /// base 2 merkle-tree should be more than enough. - type MaxProofLength: Get; - - /// The reward payout mechanism this claim pallet uses. - /// - /// This associated type allows to implement a loosely-coupled regime - /// between claiming and rewarding pallets. - type RewardMechanism: Reward< - ParachainAccountId = Self::AccountId, - ContributionAmount = Self::Balance, - BlockNumber = BlockNumberFor, - >; - - /// Entity which is allowed to perform administrative transactions - type AdminOrigin: EnsureOrigin; - - /// Weight information for extrinsics in this pallet - type WeightInfo: WeightInfo; - } - - // ------------------------------------------------------------------------ - // Pallet events - // ------------------------------------------------------------------------ - - // The macro generates event metadata and derive Clone, Debug, Eq, PartialEq and - // Codec - #[pallet::event] - // The macro generates a function on Pallet to deposit an event - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// Event emitted when the crowdloan claim pallet is properly - /// configured. - ClaimPalletInitialized, - - /// Event emitted when a reward has been claimed successfully. - RewardClaimed(T::RelayChainAccountId, ParachainAccountIdOf, T::Balance), - - /// The block number, where we lock the contributions has been updated - LockedAtUpdated(BlockNumberFor), - - /// Relay-chain Root hash which allows to verify contributions - ContributionsRootUpdated(RootHashOf), - - /// Trie index of the crowdloan inside the relay-chains crowdloan child - /// storage - CrowdloanTrieIndexUpdated(TrieIndex), - - /// The lease start of the parachain slot. Used to define when we can - /// initialize the next time - LeaseStartUpdated(BlockNumberFor), - - /// The lease period of the parachain slot. Used to define when we can - /// initialize the next time - LeasePeriodUpdated(BlockNumberFor), - } - - // ------------------------------------------------------------------------ - // Pallet storage items - // ------------------------------------------------------------------------ - - /// Root of hash of the relay chain at the time of initialization. - #[pallet::storage] - #[pallet::getter(fn contributions)] - pub(super) type Contributions = StorageValue<_, RootHashOf, OptionQuery>; - - #[pallet::storage] - #[pallet::getter(fn locked_at)] - pub(super) type LockedAt = StorageValue<_, BlockNumberFor, OptionQuery>; - - /// TrieIndex of the crowdloan campaign inside the relay-chain crowdloan - /// pallet. - /// - /// This is needed in order to build the correct keys for proof check. - #[pallet::storage] - #[pallet::getter(fn crowdloan_trie_index)] - pub type CrowdloanTrieIndex = StorageValue<_, TrieIndex>; - - /// A map containing the list of claims for reward payouts that were - /// successfuly processed - #[pallet::storage] - #[pallet::getter(fn processed_claims)] - pub(super) type ProcessedClaims = - StorageMap<_, Blake2_128Concat, (T::RelayChainAccountId, Index), bool>; - - #[pallet::type_value] - pub fn OnIndexEmpty() -> Index { - 0 - } - - #[pallet::storage] - #[pallet::getter(fn curr_index)] - pub type CurrIndex = StorageValue<_, Index, ValueQuery, OnIndexEmpty>; - - #[pallet::storage] - #[pallet::getter(fn prev_index)] - pub type PrevIndex = StorageValue<_, Index, ValueQuery, OnIndexEmpty>; - - #[pallet::type_value] - pub fn OnLeaseEmpty() -> BlockNumberFor { - Zero::zero() - } - - #[pallet::storage] - #[pallet::getter(fn lease_start)] - pub type LeaseStart = - StorageValue<_, BlockNumberFor, ValueQuery, OnLeaseEmpty>; - - #[pallet::storage] - #[pallet::getter(fn lease_period)] - pub type LeasePeriod = - StorageValue<_, BlockNumberFor, ValueQuery, OnLeaseEmpty>; - - // ---------------------------------------------------------------------------- - // Pallet lifecycle hooks - // ---------------------------------------------------------------------------- - - #[pallet::hooks] - impl Hooks> for Pallet { - fn on_finalize(n: BlockNumberFor) { - // On the first block after the lease is over, we allow a new initialization of - // the pallet and forbid further claims for this lease. - if n > Self::lease_start().saturating_add(Self::lease_period()) { - >::put(Self::curr_index()) - } - } - } - - // ------------------------------------------------------------------------ - // Pallet errors - // ------------------------------------------------------------------------ - - #[pallet::error] - pub enum Error { - /// Cannot re-initialize the pallet - PalletAlreadyInitialized, - - /// Cannot call reward before pallet is initialized - PalletNotInitialized, - - /// Claim has already been processed (replay attack, probably) - ClaimAlreadyProcessed, - - /// The proof of a contribution is invalid - InvalidProofOfContribution, - - /// Claimed amount is out of boundaries (too low or too high) - ClaimedAmountIsOutOfBoundaries, - - /// Sensitive transactions can only be performed by administrator entity - /// (e.g. Sudo or Democracy pallet) - MustBeAdministrator, - - /// The reward amount that is claimed does not correspond to the one of - /// the contribution - InvalidClaimAmount, - - /// The signature provided by the contributor when registering is not - /// valid. - /// - /// The consequence is that the relaychain and parachain accounts being - /// not associated, the contributor is not elligible for a reward - /// payout. - InvalidContributorSignature, - - /// A lease is ongoging and the pallet can henced not be initialized - /// again - OngoingLease, - - /// Claiming rewards is only possible during a lease - OutOfLeasePeriod, - } - - // ------------------------------------------------------------------------ - // Pallet dispatchable functions - // ------------------------------------------------------------------------ - - // Declare Call struct and implement dispatchable (or callable) functions. - // - // Dispatchable functions are transactions modifying the state of the chain. - // They are also called extrinsics are constitute the pallet's public interface. - // Note that each parameter used in functions must implement `Clone`, `Debug`, - // `Eq`, `PartialEq` and `Codec` traits. - #[pallet::call] - impl Pallet { - /// Claim for a reward payout - #[pallet::weight(::WeightInfo::claim_reward_sr25519() - .max(::WeightInfo::claim_reward_ed25519()) - .max(::WeightInfo::claim_reward_ecdsa()) - )] - #[pallet::call_index(0)] - pub fn claim_reward( - origin: OriginFor, - relaychain_account_id: T::RelayChainAccountId, - parachain_account_id: ParachainAccountIdOf, - identity_proof: MultiSignature, - contribution_proof: Proof, - contribution: T::Balance, - ) -> DispatchResultWithPostInfo { - ensure_signed(origin)?; - - let curr_index = Self::curr_index(); - - // Ensure that the pallet has been initialized before calling this - // This will only be triggered before the pallet has been initialized once. - // After this, the error will always be `LeaseElapsed` - ensure!(curr_index > 0, Error::::PalletNotInitialized); - - let n = >::block_number(); - let lease_start = Self::lease_start(); - ensure!( - lease_start <= n && n < lease_start.saturating_add(Self::lease_period()), - Error::::OutOfLeasePeriod - ); - - // Be sure user has not already claimed her/his reward payout - ensure!( - !ProcessedClaims::::contains_key((&relaychain_account_id, curr_index)), - Error::::ClaimAlreadyProcessed - ); - - // Check (trustless) contributor identity - Self::verify_contributor_identity_proof( - relaychain_account_id.clone(), - parachain_account_id.clone(), - identity_proof.clone(), - )?; - - let mut leaf_data = relaychain_account_id.encode(); - leaf_data.extend_from_slice(&contribution.encode()); - - // Check the contributor's proof of contribution - Self::verify_contribution_proof(contribution_proof, &leaf_data)?; - - // Claimed amount must be positive value - ensure!( - !contribution.is_zero(), - Error::::ClaimedAmountIsOutOfBoundaries - ); - - // Invoke the reward payout mechanism - T::RewardMechanism::reward(parachain_account_id.clone(), contribution)?; - - // Store this claim in the list of processed claims (so that to process it only - // once) - >::insert((&relaychain_account_id, curr_index), true); - - Self::deposit_event(Event::RewardClaimed( - relaychain_account_id, - parachain_account_id, - contribution, - )); - - let weight = match identity_proof { - MultiSignature::Sr25519(..) => { - Some(::WeightInfo::claim_reward_sr25519()) - } - MultiSignature::Ed25519(..) => { - Some(::WeightInfo::claim_reward_ed25519()) - } - MultiSignature::Ecdsa(..) => Some(::WeightInfo::claim_reward_ecdsa()), - }; - - Ok(weight.into()) - } - - /// Initialize the claim pallet - /// - /// This administrative function is used to transfer the list of - /// contributors and their respective contributions, stored as a child - /// trie root hash in the relay chain's [`crowdloan`](https://github.com/paritytech/polkadot/blob/rococo-v1/runtime/common/src/crowdloan.rs) - /// pallet, to `Contributions` storage item. - /// This transaction can only be called via a signed transactions. - /// The `contributions` parameter contains the hash of the crowdloan - /// pallet's child trie root. It is later used for proving that a - /// contributor effectively contributed to the crowdloan campaign, and - /// that the amount of the contribution is correct as well. - #[pallet::weight(::WeightInfo::initialize())] - #[pallet::call_index(1)] - pub fn initialize( - origin: OriginFor, - contributions: RootHashOf, - locked_at: BlockNumberFor, - index: TrieIndex, - lease_start: BlockNumberFor, - lease_period: BlockNumberFor, - ) -> DispatchResultWithPostInfo { - // Ensure that only administrator entity can perform this administrative - // transaction - let curr_index = Self::curr_index(); - - ensure!( - Self::ensure_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - ensure!( - >::block_number() - > Self::lease_start().saturating_add(Self::lease_period()) - || >::block_number() == Zero::zero(), - Error::::OngoingLease, - ); - - // Ensure that the pallet has not already been initialized. This is more - // a sanity check, as the previous one already ensures this implicitly - ensure!( - Self::prev_index() == curr_index, - Error::::PalletAlreadyInitialized - ); - - // Store relay chain's root hash (containing the list of contributors and their - // contributions) - >::put(contributions); - >::put(index); - >::put(locked_at); - >::put(lease_start); - >::put(lease_period); - - >::put(curr_index.saturating_add(1)); - - // Trigger an event so that to inform that the pallet was successfully - // initialized - Self::deposit_event(Event::ClaimPalletInitialized); - - Ok(().into()) - } - - /// Set the start of the lease period. - #[pallet::weight(< T as pallet::Config >::WeightInfo::set_lease_start())] - #[pallet::call_index(2)] - pub fn set_lease_start( - origin: OriginFor, - start: BlockNumberFor, - ) -> DispatchResultWithPostInfo { - // Ensure that only an administrator or root entity triggered the transaction - ensure!( - Self::ensure_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - >::put(start); - - Self::deposit_event(Event::LeaseStartUpdated(start)); - - Ok(().into()) - } - - /// Set the lease period. - #[pallet::weight(< T as pallet::Config >::WeightInfo::set_lease_period())] - #[pallet::call_index(3)] - pub fn set_lease_period( - origin: OriginFor, - period: BlockNumberFor, - ) -> DispatchResultWithPostInfo { - // Ensure that only an administrator or root entity triggered the transaction - ensure!( - Self::ensure_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - >::put(period); - - Self::deposit_event(Event::LeasePeriodUpdated(period)); - - Ok(().into()) - } - - /// Set the root-hash of the relay-chain, we locked the relay-chain - /// contributions at. - /// - /// This root-hash MUST be the root-hash of the relay-chain at the block - /// we locked at. This root-hash will be used to verify proofs of - /// contribution. - #[pallet::weight(< T as pallet::Config >::WeightInfo::set_contributions_root())] - #[pallet::call_index(4)] - pub fn set_contributions_root( - origin: OriginFor, - root: RootHashOf, - ) -> DispatchResultWithPostInfo { - // Ensure that only an administrator or root entity triggered the transaction - ensure!( - Self::ensure_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - >::put(root); - - Self::deposit_event(Event::ContributionsRootUpdated(root)); - - Ok(().into()) - } - - /// Set the block of the relay at which we lock the contributions. - /// - /// This means, that all generated proofs MUST generate the proof of - /// their contribution at this block, as otherwise the root-hash we - /// store here will not be found in the generated proof of the - /// contributor, which will lead to a rejection of the proof. - #[pallet::weight(< T as pallet::Config >::WeightInfo::set_locked_at())] - #[pallet::call_index(5)] - pub fn set_locked_at( - origin: OriginFor, - locked_at: BlockNumberFor, - ) -> DispatchResultWithPostInfo { - // Ensure that only an administrator or root entity triggered the transaction - ensure!( - Self::ensure_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - >::put(locked_at); - - Self::deposit_event(Event::LockedAtUpdated(locked_at)); - - Ok(().into()) - } - - /// Set the index of the crowdloan. - /// - /// This index comes from the relay-chain crowdloan pallet. More - /// specifically, this index is used to derive the internal patricia key - /// inside the child trie. The index is stored in the `FundInfo` of the - /// relay chain crowdloan pallet. - #[pallet::weight(< T as pallet::Config >::WeightInfo::set_crowdloan_trie_index())] - #[pallet::call_index(6)] - pub fn set_crowdloan_trie_index( - origin: OriginFor, - trie_index: TrieIndex, - ) -> DispatchResultWithPostInfo { - // Ensure that only an administrator or root entity triggered the transaction - ensure!( - Self::ensure_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - >::put(trie_index); - - Self::deposit_event(Event::CrowdloanTrieIndexUpdated(trie_index)); - - Ok(().into()) - } - } -} // end of 'pallet' module - -// ---------------------------------------------------------------------------- -// Pallet implementation block -// ---------------------------------------------------------------------------- - -// Pallet implementation block. -// -// This main implementation block contains two categories of functions, namely: -// - Public functions: These are functions that are `pub` and generally fall -// into inspector functions that do not write to storage and operation -// functions that do. -// - Private functions: These are private helpers or utilities that cannot be -// called from other pallets. -impl Pallet { - /// Return the account identifier of the crowdloan claim pallet. - /// - /// 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_truncating() - } - - // Check if the origin is an administrator or represents the root. - fn ensure_administrator(origin: T::RuntimeOrigin) -> DispatchResult { - T::AdminOrigin::try_origin(origin) - .map(|_| ()) - .or_else(ensure_root)?; - - Ok(()) - } - - // Bind contributor's relaychain account with one on the parachain. - // - // This function aims at proving that the contributor's identity on - // the relay chain is valid, using a signature. She/he also provides - // a parachain account on which the reward payout must be transferred - // and the amount she/he contributed to. - // The [`signature`] is used as the proof. - fn verify_contributor_identity_proof( - relaychain_account_id: T::RelayChainAccountId, - parachain_account_id: ParachainAccountIdOf, - signature: MultiSignature, - ) -> DispatchResult { - // Now check if the contributor's native identity on the relaychain is valid - let payload = parachain_account_id.encode(); - - // Due to how the polkadot-js extension handles signing of raw bytes, we must - // take this into account. - let mut payload_with_pre_post_fix = PRE_FIX.to_vec(); - parachain_account_id.using_encoded(|id| payload_with_pre_post_fix.extend_from_slice(id)); - payload_with_pre_post_fix.extend_from_slice(POST_FIX); - - let signer: AccountId32 = relaychain_account_id.into(); - ensure!( - signature.verify(payload.as_slice(), &signer) - || signature.verify(payload_with_pre_post_fix.as_slice(), &signer), - Error::::InvalidContributorSignature - ); - - Ok(()) - } - - // Verify that the contributor is eligible for a reward payout. - // - // The [`Contributions`] child trie root hash contains all contributions and - // their respective contributors. Given the contributor's relay chain account - // identifier, the claimed amount (in relay chain tokens) and the parachain - // account identifier, this function proves that the contributor's claim is - // valid. - fn verify_contribution_proof(proof: Proof, leaf_data: &[u8]) -> DispatchResult { - // We could unwrap here, as we check in the calling function if pallet is - // initialized (i.e. if contributions is set) but better be safe than sorry... - let root = Self::contributions().ok_or(Error::::PalletNotInitialized)?; - - // Number of proofs should practically never be > 30. Checking this - // blocks abuse. - ensure!( - proof.len() < T::MaxProofLength::get() as usize, - Error::::InvalidProofOfContribution - ); - - ensure!( - T::Hashing::hash(leaf_data) == proof.leaf_hash, - Error::::InvalidProofOfContribution - ); - - let pv = ProofVerifier::::new(); - - ensure!( - pv.verify_proof(root, &proof), - Error::::InvalidProofOfContribution - ); - - Ok(()) - } -} diff --git a/pallets/crowdloan-claim/src/mock.rs b/pallets/crowdloan-claim/src/mock.rs deleted file mode 100644 index 498a9cc79d..0000000000 --- a/pallets/crowdloan-claim/src/mock.rs +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Centrifuge (centrifuge.io) parachain. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -//! Crowdloan claim pallet testing environment and utilities -//! -//! The main components implemented in this mock module is a mock runtime -//! and some helper functions. - -// ---------------------------------------------------------------------------- -// Imports and dependencies -// ---------------------------------------------------------------------------- - -use frame_support::{ - derive_impl, parameter_types, - traits::{SortedMembers, WithdrawReasons}, - PalletId, -}; -use frame_system::EnsureSignedBy; -use sp_io::TestExternalities; -use sp_runtime::{traits::ConstU64, AccountId32, BuildStorage}; - -use crate::{self as pallet_crowdloan_claim, Config}; - -// ---------------------------------------------------------------------------- -// Type alias, constants -// ---------------------------------------------------------------------------- - -type Balance = u64; - -frame_support::construct_runtime!( - pub enum Runtime { - System: frame_system, - Balances: pallet_balances, - Vesting: pallet_vesting, - CrowdloanReward: pallet_crowdloan_reward, - CrowdloanClaim: pallet_crowdloan_claim, - } -); - -#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] -impl frame_system::Config for Runtime { - type AccountData = pallet_balances::AccountData; - type Block = frame_system::mocking::MockBlock; -} - -#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] -impl pallet_balances::Config for Runtime { - type AccountStore = System; - type DustRemoval = (); - type ExistentialDeposit = ConstU64<1>; - type RuntimeHoldReason = (); -} - -parameter_types! { - pub const TestMinVestedTransfer: u64 = 16; - pub const MaxVestingSchedules: u32 = 4; - pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons = - WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE); -} - -// Parameterize vesting pallet configuration -impl pallet_vesting::Config for Runtime { - type BlockNumberToBalance = sp_runtime::traits::Identity; - type Currency = Balances; - type MinVestedTransfer = TestMinVestedTransfer; - type RuntimeEvent = RuntimeEvent; - type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons; - type WeightInfo = (); - - const MAX_VESTING_SCHEDULES: u32 = 1; -} - -// Parameterize crowdloan reward pallet configuration -parameter_types! { - pub const One: u64 = 1; - pub const CrowdloanRewardPalletId: PalletId = cfg_types::ids::CROWDLOAN_REWARD_PALLET_ID; -} - -// Implement crowdloan reward pallet's configuration trait for the runtime -impl pallet_crowdloan_reward::Config for Runtime { - type AdminOrigin = EnsureSignedBy; - type PalletId = CrowdloanRewardPalletId; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); -} - -// Parameterize crowdloan claim pallet -parameter_types! { - pub const CrowdloanClaimPalletId: PalletId = cfg_types::ids::CROWDLOAN_CLAIM_PALLET_ID; - pub const MaxProofLength: u32 = 30; -} - -// Implement crowdloan claim pallet configuration trait for the mock runtime -impl Config for Runtime { - type AdminOrigin = EnsureSignedBy; - type MaxProofLength = MaxProofLength; - type PalletId = CrowdloanClaimPalletId; - type RelayChainAccountId = AccountId32; - type RewardMechanism = CrowdloanReward; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); -} - -impl SortedMembers for One { - fn sorted_members() -> Vec { - vec![1] - } -} - -// ---------------------------------------------------------------------------- -// Runtime externalities -// ---------------------------------------------------------------------------- - -// Runtime externalities builder type declaraction. -// -// This type is mainly used for mocking storage in tests. It is the type alias -// for an in-memory, hashmap-based externalities implementation. -pub struct TestExternalitiesBuilder { - existential_deposit: u64, -} - -// Implement default trait for test externalities builder -impl Default for TestExternalitiesBuilder { - fn default() -> Self { - Self { - existential_deposit: 1, - } - } -} - -impl TestExternalitiesBuilder { - // Build a genesis storage key/value store - pub fn build(self, optional: Option) -> TestExternalities { - let mut storage = frame_system::GenesisConfig::::default() - .build_storage() - .unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![ - (1, 10 * self.existential_deposit), - (2, 20 * self.existential_deposit), - (3, 30 * self.existential_deposit), - (4, 40 * self.existential_deposit), - (12, 100 * self.existential_deposit), - (CrowdloanReward::account_id(), 9999999999999999999), - ], - } - .assimilate_storage(&mut storage) - .unwrap(); - - pallet_vesting::GenesisConfig:: { - vesting: vec![(12, 10, 20, 5)], - } - .assimilate_storage(&mut storage) - .unwrap(); - - let mut ext = TestExternalities::from(storage); - - if let Some(execute) = optional { - ext.execute_with(execute); - } - ext - } -} diff --git a/pallets/crowdloan-claim/src/tests.rs b/pallets/crowdloan-claim/src/tests.rs deleted file mode 100644 index dec4ad6b64..0000000000 --- a/pallets/crowdloan-claim/src/tests.rs +++ /dev/null @@ -1,632 +0,0 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Centrifuge (centrifuge.io) parachain. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -//! Crowdloan claim pallet's unit test cases - -// ---------------------------------------------------------------------------- -// Imports and dependencies -// ---------------------------------------------------------------------------- - -use frame_support::{assert_noop, assert_ok, traits::VestingSchedule}; -use hex; -use sp_core::H256; -use sp_runtime::Perbill; -use sp_std::str::FromStr; - -use crate as pallet_crowdloan_claim; -use crate::{mock::*, Error as CrowdloanClaimError, *}; - -struct Contributor { - proof: proofs::Proof, - signature: MultiSignature, - parachain_account: u64, - relaychain_account: AccountId32, - contribution: u64, -} - -fn get_root() -> H256 { - let amount = 4000000000000000u64; - let contributor = - AccountId32::from_str("0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d") - .unwrap(); - - let mut v: Vec = contributor.encode(); - v.extend(amount.encode()); - let leaf_hash = ::Hashing::hash(&v); - - // 10-leaf tree - let leaf_hash_0: H256 = [0; 32].into(); - let leaf_hash_1: H256 = [1; 32].into(); - let leaf_hash_2: H256 = leaf_hash; - let leaf_hash_3: H256 = [3; 32].into(); - let leaf_hash_4: H256 = [4; 32].into(); - let leaf_hash_5: H256 = [5; 32].into(); - let leaf_hash_6: H256 = [6; 32].into(); - let leaf_hash_7: H256 = [7; 32].into(); - let leaf_hash_8: H256 = [8; 32].into(); - let leaf_hash_9: H256 = [9; 32].into(); - let node_0 = proofs::hashing::sort_hash_of::>( - leaf_hash_0, - leaf_hash_1, - ); - let node_1 = proofs::hashing::sort_hash_of::>( - leaf_hash_2, - leaf_hash_3, - ); - let node_2 = proofs::hashing::sort_hash_of::>( - leaf_hash_4, - leaf_hash_5, - ); - let node_3 = proofs::hashing::sort_hash_of::>( - leaf_hash_6, - leaf_hash_7, - ); - let node_4 = proofs::hashing::sort_hash_of::>( - leaf_hash_8, - leaf_hash_9, - ); - let node_00 = proofs::hashing::sort_hash_of::>( - node_0, node_1, - ); - let node_01 = proofs::hashing::sort_hash_of::>( - node_2, node_3, - ); - let node_000 = proofs::hashing::sort_hash_of::>( - node_00, node_01, - ); - - proofs::hashing::sort_hash_of::>( - node_000, node_4, - ) -} - -fn get_root_for_ext_sig() -> H256 { - let amount = 4000000000000000u64; - let contributor: AccountId32 = AccountId32::from([ - 202, 13, 159, 82, 100, 222, 166, 237, 52, 113, 173, 161, 100, 206, 112, 67, 188, 178, 135, - 53, 61, 178, 143, 121, 157, 182, 189, 207, 59, 166, 7, 92, - ]); - - let mut v: Vec = contributor.encode(); - v.extend(amount.encode()); - let leaf_hash = ::Hashing::hash(&v); - - // 10-leaf tree - let leaf_hash_0: H256 = [0; 32].into(); - let leaf_hash_1: H256 = [1; 32].into(); - let leaf_hash_2: H256 = leaf_hash; - let leaf_hash_3: H256 = [3; 32].into(); - let leaf_hash_4: H256 = [4; 32].into(); - let leaf_hash_5: H256 = [5; 32].into(); - let leaf_hash_6: H256 = [6; 32].into(); - let leaf_hash_7: H256 = [7; 32].into(); - let leaf_hash_8: H256 = [8; 32].into(); - let leaf_hash_9: H256 = [9; 32].into(); - let node_0 = proofs::hashing::sort_hash_of::>( - leaf_hash_0, - leaf_hash_1, - ); - let node_1 = proofs::hashing::sort_hash_of::>( - leaf_hash_2, - leaf_hash_3, - ); - let node_2 = proofs::hashing::sort_hash_of::>( - leaf_hash_4, - leaf_hash_5, - ); - let node_3 = proofs::hashing::sort_hash_of::>( - leaf_hash_6, - leaf_hash_7, - ); - let node_4 = proofs::hashing::sort_hash_of::>( - leaf_hash_8, - leaf_hash_9, - ); - let node_00 = proofs::hashing::sort_hash_of::>( - node_0, node_1, - ); - let node_01 = proofs::hashing::sort_hash_of::>( - node_2, node_3, - ); - let node_000 = proofs::hashing::sort_hash_of::>( - node_00, node_01, - ); - - proofs::hashing::sort_hash_of::>( - node_000, node_4, - ) -} - -fn get_contributor_ext_sig() -> Contributor { - let amount = 4000000000000000u64; - let contributor: AccountId32 = AccountId32::from([ - 202, 13, 159, 82, 100, 222, 166, 237, 52, 113, 173, 161, 100, 206, 112, 67, 188, 178, 135, - 53, 61, 178, 143, 121, 157, 182, 189, 207, 59, 166, 7, 92, - ]); - - let mut v: Vec = contributor.encode(); - v.extend(amount.encode()); - let leaf_hash = ::Hashing::hash(&v); - - // 10-leaf tree - let mut sorted_hashed: Vec = Vec::new(); - - let leaf_hash_0: H256 = [0; 32].into(); - let leaf_hash_1: H256 = [1; 32].into(); - let leaf_hash_3: H256 = [3; 32].into(); - let leaf_hash_4: H256 = [4; 32].into(); - let leaf_hash_5: H256 = [5; 32].into(); - let leaf_hash_6: H256 = [6; 32].into(); - let leaf_hash_7: H256 = [7; 32].into(); - let leaf_hash_8: H256 = [8; 32].into(); - let leaf_hash_9: H256 = [9; 32].into(); - let node_0 = proofs::hashing::sort_hash_of::>( - leaf_hash_0, - leaf_hash_1, - ); - let node_2 = proofs::hashing::sort_hash_of::>( - leaf_hash_4, - leaf_hash_5, - ); - let node_3 = proofs::hashing::sort_hash_of::>( - leaf_hash_6, - leaf_hash_7, - ); - let node_4 = proofs::hashing::sort_hash_of::>( - leaf_hash_8, - leaf_hash_9, - ); - let node_01 = proofs::hashing::sort_hash_of::>( - node_2, node_3, - ); - - sorted_hashed.push(leaf_hash_3); - sorted_hashed.push(node_0); - sorted_hashed.push(node_01); - sorted_hashed.push(node_4); - - // This signature is generate with the logic of: "Bytes" + Data + "Bytes". - // Reason to test this is: - let signature: [u8; 64] = [ - 94, 215, 90, 147, 120, 40, 201, 58, 58, 69, 247, 113, 19, 18, 122, 200, 50, 194, 125, 133, - 72, 241, 154, 88, 122, 223, 138, 245, 237, 158, 72, 76, 144, 61, 44, 104, 25, 209, 72, 79, - 252, 106, 132, 44, 129, 133, 85, 45, 243, 53, 60, 167, 219, 238, 167, 89, 38, 204, 44, 245, - 99, 56, 31, 130, - ]; - - Contributor { - proof: proofs::Proof::new(leaf_hash, sorted_hashed), - signature: MultiSignature::Sr25519(sp_core::sr25519::Signature(signature)), - parachain_account: 1, - relaychain_account: contributor, - contribution: amount, - } -} - -fn get_contributor() -> Contributor { - let amount = 4000000000000000u64; - let contributor = - AccountId32::from_str("0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d") - .unwrap(); - - let mut v: Vec = contributor.encode(); - v.extend(amount.encode()); - let leaf_hash = ::Hashing::hash(&v); - - // 10-leaf tree - let mut sorted_hashed: Vec = Vec::new(); - - let leaf_hash_0: H256 = [0; 32].into(); - let leaf_hash_1: H256 = [1; 32].into(); - let leaf_hash_3: H256 = [3; 32].into(); - let leaf_hash_4: H256 = [4; 32].into(); - let leaf_hash_5: H256 = [5; 32].into(); - let leaf_hash_6: H256 = [6; 32].into(); - let leaf_hash_7: H256 = [7; 32].into(); - let leaf_hash_8: H256 = [8; 32].into(); - let leaf_hash_9: H256 = [9; 32].into(); - let node_0 = proofs::hashing::sort_hash_of::>( - leaf_hash_0, - leaf_hash_1, - ); - let node_2 = proofs::hashing::sort_hash_of::>( - leaf_hash_4, - leaf_hash_5, - ); - let node_3 = proofs::hashing::sort_hash_of::>( - leaf_hash_6, - leaf_hash_7, - ); - let node_4 = proofs::hashing::sort_hash_of::>( - leaf_hash_8, - leaf_hash_9, - ); - let node_01 = proofs::hashing::sort_hash_of::>( - node_2, node_3, - ); - - sorted_hashed.push(leaf_hash_3); - sorted_hashed.push(node_0); - sorted_hashed.push(node_01); - sorted_hashed.push(node_4); - - Contributor { - proof: proofs::Proof::new(leaf_hash, sorted_hashed), - signature: MultiSignature::Sr25519(sp_core::sr25519::Signature( - hex::decode("a0db0cf026ffe5f0bc859681c9a1816e8a15991947753d6d7ecd1ac69c6e204c4ecf8f534d52ec9e76505e770dfa2b5d9614eca5e4d1de556dfa0de40dc7328f").unwrap().try_into().unwrap() - )), - parachain_account: 1, - relaychain_account: contributor, - contribution: amount, - - } -} - -fn get_false_signature() -> MultiSignature { - MultiSignature::Sr25519(sp_core::sr25519::Signature( - hex::decode("111111111111111111111111111111111111111111111111111111111111111111112a8e699c7b6893f649edc630bfe11c7d278fb11b5f1084972669e250cc8c").unwrap().try_into().unwrap() - )) -} - -fn get_false_proof() -> proofs::Proof { - // 10-leaf tree - let mut sorted_hashed: Vec = Vec::new(); - - sorted_hashed.push([0; 32].into()); - sorted_hashed.push([1; 32].into()); - sorted_hashed.push([2; 32].into()); - sorted_hashed.push([3; 32].into()); - sorted_hashed.push([4; 32].into()); - sorted_hashed.push([5; 32].into()); - sorted_hashed.push([6; 32].into()); - sorted_hashed.push([7; 32].into()); - sorted_hashed.push([8; 32].into()); - sorted_hashed.push([9; 32].into()); - - proofs::Proof::new([10; 32].into(), sorted_hashed) -} - -fn init_module() { - CrowdloanClaim::initialize(RuntimeOrigin::signed(1), get_root(), 100, 0, 0, 400).unwrap(); - pallet_crowdloan_reward::Pallet::::initialize( - RuntimeOrigin::signed(1), - Perbill::from_percent(20), - 500, - 100, - ) - .unwrap(); -} - -// ---------------------------------------------------------------------------- -// Test cases -// ---------------------------------------------------------------------------- -#[test] -fn test_valid_initialize_transaction() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - assert!(CrowdloanClaim::contributions().is_some()); - assert!(CrowdloanClaim::crowdloan_trie_index().is_some()); - }) -} - -#[test] -fn test_init_double() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - assert_noop!( - CrowdloanClaim::initialize(RuntimeOrigin::signed(1), get_root(), 100, 0, 200, 400), - CrowdloanClaimError::::PalletAlreadyInitialized - ); - }) -} - -#[test] -fn test_init_non_admin() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - assert_noop!( - CrowdloanClaim::initialize(RuntimeOrigin::signed(2), get_root(), 100, 0, 200, 400), - CrowdloanClaimError::::MustBeAdministrator - ); - }) -} - -#[test] -fn test_set_contribution_root() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - assert_ok!(CrowdloanClaim::set_lease_start( - RuntimeOrigin::signed(1), - 999 - )); - assert_eq!(CrowdloanClaim::lease_start(), 999); - }) -} - -#[test] -fn test_set_locked_at() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - assert_ok!(CrowdloanClaim::set_locked_at(RuntimeOrigin::signed(1), 999)); - assert_eq!(CrowdloanClaim::locked_at(), Some(999)); - }) -} - -#[test] -fn test_set_contributions_trie_index() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - let root = H256::zero(); - assert_ok!(CrowdloanClaim::set_contributions_root( - RuntimeOrigin::signed(1), - root - )); - assert_eq!(CrowdloanClaim::contributions(), Some(root)); - }) -} - -#[test] -fn test_set_lease_start() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - assert_ok!(CrowdloanClaim::set_lease_start( - RuntimeOrigin::signed(1), - 999 - )); - assert_eq!(CrowdloanClaim::lease_start(), 999); - }) -} - -#[test] -fn test_set_lease_period() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - assert_ok!(CrowdloanClaim::set_lease_period( - RuntimeOrigin::signed(1), - 999 - )); - assert_eq!(CrowdloanClaim::lease_period(), 999); - }) -} - -#[test] -fn test_invalid_signed_claim_transaction() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - let alice = get_contributor(); - - assert_noop!( - CrowdloanClaim::claim_reward( - RuntimeOrigin::signed(0), - alice.relaychain_account, - alice.parachain_account, - get_false_signature(), - alice.proof, - alice.contribution - ), - CrowdloanClaimError::::InvalidContributorSignature - ); - }) -} - -#[test] -fn test_valid_claim() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - let bob = get_contributor(); - let bob_balance = Balances::free_balance(&bob.parachain_account); - - assert_ok!(CrowdloanClaim::claim_reward( - RuntimeOrigin::signed(0), - bob.relaychain_account.clone(), - bob.parachain_account, - bob.signature, - bob.proof, - bob.contribution - )); - assert!(ProcessedClaims::::contains_key(( - &bob.relaychain_account, - 1 - ))); - - assert_eq!( - Vesting::vesting_balance(&bob.parachain_account), - Some(3200000000000000) - ); - assert_eq!( - Balances::usable_balance(&bob.parachain_account), - bob_balance + 800000000000000 - ); - }); -} - -#[test] -fn test_valid_claim_ext_signature() { - TestExternalitiesBuilder::default() - .build(Some(|| { - CrowdloanClaim::initialize( - RuntimeOrigin::signed(1), - get_root_for_ext_sig(), - 100, - 0, - 0, - 400, - ) - .unwrap(); - pallet_crowdloan_reward::Pallet::::initialize( - RuntimeOrigin::signed(1), - Perbill::from_percent(20), - 500, - 100, - ) - .unwrap(); - })) - .execute_with(|| { - let bob = get_contributor_ext_sig(); - let bob_balance = Balances::free_balance(&bob.parachain_account); - - assert_ok!(CrowdloanClaim::claim_reward( - RuntimeOrigin::signed(0), - bob.relaychain_account.clone(), - bob.parachain_account, - bob.signature, - bob.proof, - bob.contribution - )); - assert!(ProcessedClaims::::contains_key(( - &bob.relaychain_account, - 1 - ))); - - assert_eq!( - Vesting::vesting_balance(&bob.parachain_account), - Some(3200000000000000) - ); - assert_eq!( - Balances::usable_balance(&bob.parachain_account), - bob_balance + 800000000000000 - ); - }); -} - -#[test] -fn test_valid_claim_but_lease_elapsed() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - System::set_block_number(601); - - let bob = get_contributor(); - assert_noop!( - CrowdloanClaim::claim_reward( - RuntimeOrigin::signed(0), - bob.relaychain_account.clone(), - bob.parachain_account, - bob.signature, - bob.proof, - bob.contribution - ), - Error::::OutOfLeasePeriod - ); - }); -} - -#[test] -fn test_valid_claim_claimed_twice() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - let bob = get_contributor(); - assert_ok!(CrowdloanClaim::claim_reward( - RuntimeOrigin::signed(0), - bob.relaychain_account.clone(), - bob.parachain_account, - bob.signature, - bob.proof, - bob.contribution - )); - assert!(ProcessedClaims::::contains_key(( - &bob.relaychain_account, - 1 - ))); - - let bob = get_contributor(); - assert_noop!( - CrowdloanClaim::claim_reward( - RuntimeOrigin::signed(0), - bob.relaychain_account.clone(), - bob.parachain_account, - bob.signature, - bob.proof, - bob.contribution - ), - CrowdloanClaimError::::ClaimAlreadyProcessed - ); - }) -} - -#[test] -fn test_invalid_claim_invalid_proof() { - TestExternalitiesBuilder::default() - .build(Some(init_module)) - .execute_with(|| { - let alice = get_contributor(); - - assert_noop!( - Pallet::::claim_reward( - RuntimeOrigin::signed(0), - alice.relaychain_account, - alice.parachain_account, - alice.signature, - get_false_proof(), - alice.contribution - ), - CrowdloanClaimError::::InvalidProofOfContribution - ); - }) -} - -#[test] -fn test_invalid_claim_mod_not_initialized() { - TestExternalitiesBuilder::default() - .build(Some(|| {})) - .execute_with(|| { - let alice = get_contributor(); - - assert_noop!( - CrowdloanClaim::claim_reward( - RuntimeOrigin::signed(0), - alice.relaychain_account, - alice.parachain_account, - alice.signature, - alice.proof, - alice.contribution - ), - CrowdloanClaimError::::PalletNotInitialized - ); - }) -} - -#[test] -fn test_claim_reward_requires_origin() { - TestExternalitiesBuilder::default() - .build(Some(|| {})) - .execute_with(|| { - let alice = get_contributor(); - - assert_noop!( - CrowdloanClaim::claim_reward( - RuntimeOrigin::none(), - alice.relaychain_account, - alice.parachain_account, - alice.signature, - alice.proof, - alice.contribution - ), - sp_runtime::DispatchError::BadOrigin - ); - }) -} diff --git a/pallets/crowdloan-claim/src/weights.rs b/pallets/crowdloan-claim/src/weights.rs deleted file mode 100644 index bf9993ac99..0000000000 --- a/pallets/crowdloan-claim/src/weights.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2021 Centrifuge Foundation (centrifuge.io). -// This file is part of Centrifuge chain project. - -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). - -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -use frame_support::weights::Weight; - -pub trait WeightInfo { - fn claim_reward_ed25519() -> Weight; - fn claim_reward_sr25519() -> Weight; - fn claim_reward_ecdsa() -> Weight; - fn initialize() -> Weight; - fn set_lease_start() -> Weight; - fn set_lease_period() -> Weight; - fn set_contributions_root() -> Weight; - fn set_locked_at() -> Weight; - fn set_crowdloan_trie_index() -> Weight; -} - -impl WeightInfo for () { - fn claim_reward_ed25519() -> Weight { - Weight::zero() - } - - fn claim_reward_sr25519() -> Weight { - Weight::zero() - } - - fn claim_reward_ecdsa() -> Weight { - Weight::zero() - } - - fn initialize() -> Weight { - Weight::zero() - } - - fn set_lease_start() -> Weight { - Weight::zero() - } - - fn set_lease_period() -> Weight { - Weight::zero() - } - - fn set_contributions_root() -> Weight { - Weight::zero() - } - - fn set_locked_at() -> Weight { - Weight::zero() - } - - fn set_crowdloan_trie_index() -> Weight { - Weight::zero() - } -} diff --git a/pallets/crowdloan-reward/Cargo.toml b/pallets/crowdloan-reward/Cargo.toml deleted file mode 100644 index bc78eabbc3..0000000000 --- a/pallets/crowdloan-reward/Cargo.toml +++ /dev/null @@ -1,68 +0,0 @@ -[package] -name = "pallet-crowdloan-reward" -description = "Module for processing crowdloan claim rewards." -version = "0.1.0" -authors.workspace = true -edition.workspace = true -license.workspace = true -homepage.workspace = true -repository.workspace = true -documentation.workspace = true - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -# General dependencies -parity-scale-codec = { workspace = true } -scale-info = { workspace = true } - -# Substrae dependencies -frame-benchmarking = { workspace = true, optional = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -pallet-balances = { workspace = true } -pallet-vesting = { workspace = true } -sp-runtime = { workspace = true } -sp-std = { workspace = true } - -# Local dependencies -cfg-traits = { workspace = true } - -[dev-dependencies] -cfg-types = { workspace = true, default_features = true } -pallet-vesting = { workspace = true, default_features = true } -sp-core = { workspace = true, default_features = true } -sp-io = { workspace = true, default_features = true } - -[features] -default = ["std"] -std = [ - "parity-scale-codec/std", - "scale-info/std", - "sp-std/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "pallet-vesting/std", - "cfg-traits/std", - "frame-benchmarking/std", - "sp-runtime/std", -] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "cfg-traits/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "cfg-types/runtime-benchmarks", -] -try-runtime = [ - "cfg-types/try-runtime", - "cfg-traits/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-balances/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/pallets/crowdloan-reward/README.md b/pallets/crowdloan-reward/README.md deleted file mode 100644 index 204edc03cd..0000000000 --- a/pallets/crowdloan-reward/README.md +++ /dev/null @@ -1,8 +0,0 @@ -Crowdloan rewarding functionality pallet. - -Implements the `Reward` trait and provides a rewarding strategy for contributors of a crowdloan. -Can be used with the `Claim` pallet. - -Rewarding Strategy are vested transfers which an adjustable direct payout ratio. - -License: GPL-v3 \ No newline at end of file diff --git a/pallets/crowdloan-reward/src/benchmarking.rs b/pallets/crowdloan-reward/src/benchmarking.rs deleted file mode 100644 index f3321cb978..0000000000 --- a/pallets/crowdloan-reward/src/benchmarking.rs +++ /dev/null @@ -1,66 +0,0 @@ -#![cfg(feature = "runtime-benchmarks")] -use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; -use frame_system::RawOrigin; - -use super::*; - -benchmarks! { - initialize { - let ratio = Perbill::from_percent(2u32); - let vesting_period = 3u32.into(); - let vesting_start = 4u32.into(); - }: _(RawOrigin::Root, ratio, vesting_period, vesting_start ) - verify { - assert_eq!( - Pallet::::direct_payout_ratio(), - Perbill::from_percent(2u32) - ); - assert_eq!(Pallet::::vesting_period().unwrap(), 3u32.into()); - assert_eq!(Pallet::::vesting_start().unwrap(), 4u32.into()); - } - - set_vesting_start { - let start = 1u32.into(); - }: _(RawOrigin::Root, start) - verify { - assert_eq!(Pallet::::vesting_start().unwrap(), 1u32.into()); - } - - set_vesting_period { - let period = 1u32.into(); - }: _(RawOrigin::Root, period) - verify { - assert_eq!(Pallet::::vesting_period().unwrap(), 1u32.into()); - } - - set_direct_payout_ratio { - let ratio: Perbill = Perbill::from_percent(10u32); - }: _(RawOrigin::Root, ratio) - verify { - assert_eq!(Pallet::::direct_payout_ratio(), Perbill::from_percent(10u32)); - } - - /* - TODO: The benchmarking framework does (to the best of my knowledge) not allow to benchmark traits or any other function - that is not part of the Call enum (i.e. extrinsics api of the pallet). So we have one solution here, that I currently - see: Create an intermediate extrinsic that directly goes into the reward trait and bench this. Once the benches are done - we remove it again. - - reward{ - let para_account: T::AccountId = parity_scale_codec::Decode::decode(&mut parity_scale_codec::Encode::encode(&mut 1u64).as_slice()).unwrap(); - let contribution: T::RelayChainBalance = parity_scale_codec::Decode::decode(&mut parity_scale_codec::Encode::encode(&mut 100u64).as_slice()).unwrap(); - - }: reward(RawOrigin::Root, para_account, contribution) - verify { - // TODO: Not sure if it is even possible to use the balances pallet here. But "T" does not implement the pallet_balances::Config - // so currently, I am not able to see a solution to get to the balances. Although, one might use storage directy. But I - // am lazy right now. The tests cover this quite well... - } - */ -} - -impl_benchmark_test_suite!( - Pallet, - crate::mock::TestExternalitiesBuilder::default().build(|| {}), - crate::mock::Runtime, -); diff --git a/pallets/crowdloan-reward/src/lib.rs b/pallets/crowdloan-reward/src/lib.rs deleted file mode 100644 index 1d0f38f6dd..0000000000 --- a/pallets/crowdloan-reward/src/lib.rs +++ /dev/null @@ -1,443 +0,0 @@ -// Copyright 2021 Centrifuge GmbH (centrifuge.io). -// This file is part of Centrifuge chain project. - -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). - -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -//! # Crowdloan Reward Pallet -//! -//! This pallet implements a specific rewarding strategy for crowdloan -//! campaign. It worth pointing out that this pallet works hand in hand -//! with the [`pallet-crowdloan-claim`] pallet, the latter being responsible -//! for managing reward claims (including security aspects, such as malicious -//! Denial of Service or replay attacks). -//! -//! ## Overview -//! The function of this pallet is to provide the Centrifuge-specific reward -//! functionality for contributors of the relay chain crowdloan. In order to -//! provide this functionality the pallet implements the `Reward` Trait from the -//! `Claim` Pallet. Before any rewards can be provided to contributors the -//! pallet MUST be initialized, so that the modules account holds the necessary -//! funds to reward. All rewards are payed in form of a `vested_transfer` with a -//! fixed vesting time. The vesting time is defined via the modules `Config` -//! trait. -//! -//! ## Terminology -//! For information on terms and concepts used in this pallet, -//! please refer to the [pallet' specification document](https://centrifuge.hackmd.io/JIGbo97DSiCPFnBFN62aTQ?both). -//! -//! ## Dependencies -//! This pallet works hand in hand with [`pallet-crowdloan-claim`] pallet. In -//! fact, it must implement this pallet's -//! [`pallet-crowdloan-claim::traits::Reward`] trait so that to interact. -//! -//! ## References -//! -//! ## Credits -//! Frederik Schulz - -// Ensure we're `no_std` when compiling for WebAssembly. -#![cfg_attr(not(feature = "std"), no_std)] - -// ---------------------------------------------------------------------------- -// Imports and dependencies -// ---------------------------------------------------------------------------- - -// Runtime, system and frame primitives -// Claim reward trait to be implemented -use cfg_traits::Reward; -use frame_support::{ - dispatch::DispatchResultWithPostInfo, - ensure, - sp_runtime::traits::{CheckedSub, One}, - traits::{ - Currency, EnsureOrigin, ExistenceRequirement::AllowDeath, Get, VestingSchedule, - WithdrawReasons, - }, - PalletId, -}; -use frame_system::{ensure_root, pallet_prelude::BlockNumberFor}; -// Re-export in crate namespace (for runtime construction) -pub use pallet::*; -use sp_runtime::{ - traits::{AccountIdConversion, CheckedDiv, Convert, Zero}, - Perbill, -}; - -// Extrinsics weight information -pub use crate::weights::WeightInfo; - -// Mock runtime and unit test cases -#[cfg(test)] -mod mock; -#[cfg(test)] -mod tests; - -// Runtime benchmarking features -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - -// Extrinsics weight information (computed through runtime benchmarking) -pub mod weights; - -/// A type alias for the balance type from this pallet's point of view. -type BalanceOf = <::Currency as Currency< - ::AccountId, ->>::Balance; - -// ---------------------------------------------------------------------------- -// Pallet module -// ---------------------------------------------------------------------------- - -// Crowdloan claim pallet module -// -// The name of the pallet is provided by `construct_runtime` macro and is used -// as the unique identifier for the pallet's storage. It is not defined in the -// pallet itself. -#[frame_support::pallet] -pub mod pallet { - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - - use super::*; - - // Declare pallet structure placeholder - #[pallet::pallet] - - pub struct Pallet(_); - - // ---------------------------------------------------------------------------- - // Pallet configuration - // ---------------------------------------------------------------------------- - - #[pallet::config] - pub trait Config: frame_system::Config + pallet_vesting::Config { - /// Constant configuration parameter to store the module identifier for - /// the pallet. - #[pallet::constant] - type PalletId: Get; - - /// Associated type for Event enum - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// Admin or the module. I.e. this is necessary in cases, where the - /// vesting parameters need to be changed without an additional - /// initialization. - type AdminOrigin: EnsureOrigin; - - /// Weight information for extrinsics in this pallet - type WeightInfo: WeightInfo; - } - - // ---------------------------------------------------------------------------- - // Pallet events - // ---------------------------------------------------------------------------- - - // The macro generates event metadata and derive Clone, Debug, Eq, PartialEq and - // Codec - #[pallet::event] - // The macro generates a function on Pallet to deposit an event - #[pallet::generate_deposit(pub (super) fn deposit_event)] - pub enum Event { - /// Event emitted when a reward claim was processed successfully. - /// \[who, direct_reward, vested_reward\] - RewardClaimed(T::AccountId, BalanceOf, BalanceOf), - - /// Event triggered when the reward module is ready to reward - /// contributors \[vesting_start, vesting_period, direct_payout_ratio\] - RewardPalletInitialized(BlockNumberFor, BlockNumberFor, Perbill), - - /// Direct payout ratio for contributors has been updated - /// \[payout_ratio\] - DirectPayoutRatioUpdated(Perbill), - - /// Vesting period has been updated - VestingPeriodUpdated(BlockNumberFor), - - /// Start of vesting has been updated - VestingStartUpdated(BlockNumberFor), - } - - #[pallet::type_value] - pub fn OnRatioEmpty() -> Perbill { - Perbill::from_percent(20) - } - - #[pallet::storage] - #[pallet::getter(fn direct_payout_ratio)] - /// Which ratio of the rewards are payed directly. The rest is transferred - /// via a vesting schedule. - pub(super) type DirectPayoutRatio = - StorageValue<_, Perbill, ValueQuery, OnRatioEmpty>; - - /// Over which period are the contributions vested. - #[pallet::storage] - #[pallet::getter(fn vesting_period)] - pub(super) type VestingPeriod = StorageValue<_, BlockNumberFor>; - - /// At which block number does the vesting start. - #[pallet::storage] - #[pallet::getter(fn vesting_start)] - pub(super) type VestingStart = StorageValue<_, BlockNumberFor>; - - // ---------------------------------------------------------------------------- - // Pallet errors - // ---------------------------------------------------------------------------- - - #[pallet::error] - pub enum Error { - /// Invalid call to an administrative extrinsics - MustBeAdministrator, - - /// The reward is below the existential deposit - RewardInsufficient, - - /// Pallet must be initialized first - PalletNotInitialized, - } - - // ---------------------------------------------------------------------------- - // Pallet dispatchable functions - // ---------------------------------------------------------------------------- - - // Declare Call struct and implement dispatchable (or callable) functions. - // - // Dispatchable functions are transactions modifying the state of the chain. - // They are also called extrinsics are constitute the pallet's public interface. - // Note that each parameter used in functions must implement `Clone`, `Debug`, - // `Eq`, `PartialEq` and `Codec` traits. - #[pallet::call] - impl Pallet { - /// A on call init. Basically a composition of the setters below - #[pallet::weight(< T as pallet::Config >::WeightInfo::initialize())] - #[pallet::call_index(0)] - pub fn initialize( - origin: OriginFor, - direct_payout_ratio: Perbill, - vesting_period: BlockNumberFor, - vesting_start: BlockNumberFor, - ) -> DispatchResultWithPostInfo { - ensure!( - Self::is_origin_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - >::set(Some(vesting_start)); - >::set(Some(vesting_period)); - >::put(direct_payout_ratio); - - Self::deposit_event(Event::RewardPalletInitialized( - vesting_start, - vesting_period, - direct_payout_ratio, - )); - - Ok(().into()) - } - - /// Set the start of the vesting period. - #[pallet::weight(< T as pallet::Config >::WeightInfo::set_vesting_start())] - #[pallet::call_index(1)] - pub fn set_vesting_start( - origin: OriginFor, - start: BlockNumberFor, - ) -> DispatchResultWithPostInfo { - // Ensure that only an administrator or root entity triggered the transaction - ensure!( - Self::is_origin_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - >::put(start); - - Self::deposit_event(Event::VestingStartUpdated(start)); - - Ok(().into()) - } - - /// Set vesting period. - /// - /// This administrative transaction allows to modify the vesting period - /// after a previous [`Pallet::initialize()`] transaction was triggered - /// in order to perform seminal pallet configuration. - /// - /// ## Emits - /// UpdateVestingPeriod - #[pallet::weight(< T as pallet::Config >::WeightInfo::set_vesting_period())] - #[pallet::call_index(2)] - pub fn set_vesting_period( - origin: OriginFor, - period: BlockNumberFor, - ) -> DispatchResultWithPostInfo { - // Ensure that only an administrator or root entity triggered the transaction - ensure!( - Self::is_origin_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - >::put(period); - - Self::deposit_event(Event::VestingPeriodUpdated(period)); - - Ok(().into()) - } - - /// Modify the ratio between vested and direct payout amount. - /// - /// This administrative function allows to modify the ratio - /// between vested and direct payout amount after the pallet - /// was initialized via a call to the [`Pallet::initialize()`] - /// transaction. - #[pallet::weight(< T as pallet::Config >::WeightInfo::set_direct_payout_ratio())] - #[pallet::call_index(3)] - pub fn set_direct_payout_ratio( - origin: OriginFor, - ratio: Perbill, - ) -> DispatchResultWithPostInfo { - // Ensure that only an administrator or root entity triggered the transaction - ensure!( - Self::is_origin_administrator(origin).is_ok(), - Error::::MustBeAdministrator - ); - - >::put(ratio); - - Self::deposit_event(Event::DirectPayoutRatioUpdated(ratio)); - - Ok(().into()) - } - } -} // end of 'pallet' module - -impl Pallet { - /// Return the account identifier of the crowdloan reward pallet. - /// - /// 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_truncating() - } - - // Check if a transaction was called by an administrator or root entity. - fn is_origin_administrator(origin: T::RuntimeOrigin) -> DispatchResultWithPostInfo { - T::AdminOrigin::try_origin(origin) - .map(|_| ()) - .or_else(ensure_root)?; - - Ok(().into()) - } -} - -// ---------------------------------------------------------------------------- -// Reward trait implementation -// ---------------------------------------------------------------------------- - -// Reward trait implementation for the pallet -impl Reward for Pallet -where - BalanceOf: Send + Sync, -{ - type BlockNumber = BlockNumberFor; - type ContributionAmount = BalanceOf; - type ParachainAccountId = T::AccountId; - - // Reward a payout for a claim on a given parachain account - fn reward( - who: Self::ParachainAccountId, - contribution: Self::ContributionAmount, - ) -> DispatchResultWithPostInfo { - ensure!( - Self::vesting_start().is_some() && Self::vesting_period().is_some(), - Error::::PalletNotInitialized - ); - - let direct_reward = Self::direct_payout_ratio() * contribution; - let vested_reward = contribution - .checked_sub(&direct_reward) - .unwrap_or_else(Zero::zero); - - ensure!( - contribution >= T::Currency::minimum_balance(), - Error::::RewardInsufficient - ); - - ensure!( - vested_reward == Zero::zero() || vested_reward >= T::MinVestedTransfer::get(), - pallet_vesting::Error::::AmountLow - ); - - ensure!( - pallet_vesting::Pallet::::vesting(&who) - .unwrap_or_default() - .len() < pallet_vesting::MaxVestingSchedulesGet::::get() - .try_into() - // This is currently a u32, but in case it changes, we will - // fail-safe to zero. - .unwrap_or(0), - pallet_vesting::Error::::AtMaxVestingSchedules, - ); - - // Ensure the division is correct or we give everything on the first block - let per_block = vested_reward - .checked_div(&T::BlockNumberToBalance::convert( - Self::vesting_period().expect("Pallet has been initialized. Qed."), - )) - // In case period is 0 we will give everything on the first block - .unwrap_or(vested_reward) - // Ensure that we are at least giving out 1 per block. Otherwise, vesting will be - // ongoing forever. - .max(One::one()); - - let schedule = pallet_vesting::VestingInfo::new( - vested_reward, - per_block, - Self::vesting_start().expect("Pallet has been initalized. Qed."), - ); - - let from: T::AccountId = Self::account_id(); - - // We MUST NOT fail after this point - - // Mint the new tokens - let positive_imbalance = T::Currency::deposit_creating(&from, contribution); - - // We are transferring everything and add the vesting schedule afterwards. This - // makes it easier. - // - // The reward pallet account only holds enough funds for this reward. So we must - // allow it to die. - T::Currency::transfer(&from, &who, contribution, AllowDeath) - .expect("Move what we created. Qed."); - - as VestingSchedule>::add_vesting_schedule( - &who, - schedule.locked(), - schedule.per_block(), - schedule.starting_block(), - ) - .map_err(|err| { - // Resolve imbalances - T::Currency::settle( - &who, - positive_imbalance, - WithdrawReasons::TRANSFER, - AllowDeath, - ) - .map_err(|_err| panic!("Remove what we created. Qed.")) // I can not use expect here, as PositiveImbalance does not implement fmt::Debug - .unwrap(); - - err - })?; - - Self::deposit_event(Event::RewardClaimed(who, direct_reward, vested_reward)); - - Ok(().into()) - } -} diff --git a/pallets/crowdloan-reward/src/mock.rs b/pallets/crowdloan-reward/src/mock.rs deleted file mode 100644 index b62746efb8..0000000000 --- a/pallets/crowdloan-reward/src/mock.rs +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2021 Centrifuge GmbH (centrifuge.io). -// This file is part of Centrifuge chain project. - -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). - -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -//! Crowdloan reward pallet testing environment and utilities -//! -//! The main components implemented in this module is a mock runtime -//! and some helper functions. - -#![cfg(test)] - -// ---------------------------------------------------------------------------- -// Imports and dependencies -// ---------------------------------------------------------------------------- - -use frame_support::{ - derive_impl, parameter_types, - traits::{SortedMembers, WithdrawReasons}, - PalletId, -}; -use frame_system::EnsureSignedBy; -use sp_runtime::{traits::ConstU64, BuildStorage, Perbill}; - -use crate as pallet_crowdloan_reward; - -type Balance = u64; - -frame_support::construct_runtime!( - pub enum Runtime { - System: frame_system, - Balances: pallet_balances, - Vesting: pallet_vesting, - CrowdloanReward: pallet_crowdloan_reward, - } -); - -#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] -impl frame_system::Config for Runtime { - type AccountData = pallet_balances::AccountData; - type Block = frame_system::mocking::MockBlock; -} - -#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] -impl pallet_balances::Config for Runtime { - type AccountStore = System; - type DustRemoval = (); - type ExistentialDeposit = ConstU64<1>; - type RuntimeHoldReason = (); -} - -// Parameterize vesting pallet -parameter_types! { - pub const MinVestedTransfer: u64 = 16; - pub const MaxVestingSchedules: u32 = 4; - pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons = - WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE); -} - -// Implement vesting pallet configuration for mock runtime -impl pallet_vesting::Config for Runtime { - type BlockNumberToBalance = sp_runtime::traits::Identity; - type Currency = Balances; - type MinVestedTransfer = MinVestedTransfer; - type RuntimeEvent = RuntimeEvent; - type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons; - type WeightInfo = (); - - const MAX_VESTING_SCHEDULES: u32 = 1; -} - -// Parameterize crowdloan reward pallet configuration -parameter_types! { - pub const One: u64 = 1; - pub const CrowdloanRewardPalletId: PalletId = cfg_types::ids::CROWDLOAN_REWARD_PALLET_ID; -} - -// Implement crowdloan reward pallet configuration for mock runtime -impl pallet_crowdloan_reward::Config for Runtime { - type AdminOrigin = EnsureSignedBy; - type PalletId = CrowdloanRewardPalletId; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); -} - -impl SortedMembers for One { - fn sorted_members() -> Vec { - vec![1] - } -} - -// Parameterize frame system pallet -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const MaximumBlockWeight: u64 = 1024; - pub const MaximumBlockLength: u32 = 2 * 1024; - pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); -} - -// ---------------------------------------------------------------------------- -// Runtime externalities -// ---------------------------------------------------------------------------- - -// Runtime externalities builder type declaraction. -// -// This type is mainly used for mocking storage in tests. It is the type alias -// for an in-memory, hashmap-based externalities implementation. -pub struct TestExternalitiesBuilder { - existential_deposit: u64, -} - -// Implement default trait for test externalities builder -impl Default for TestExternalitiesBuilder { - fn default() -> Self { - Self { - existential_deposit: 1, - } - } -} - -// Implement test externalities builder -impl TestExternalitiesBuilder { - pub fn existential_deposit(mut self, existential_deposit: u64) -> Self { - self.existential_deposit = existential_deposit; - self - } - - // Build a genesis storage key/value store - pub fn build(self, execute: impl FnOnce() -> R) -> sp_io::TestExternalities { - let mut storage = frame_system::GenesisConfig::::default() - .build_storage() - .unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![ - (1, 100 * self.existential_deposit), - (2, 200 * self.existential_deposit), - (3, 30 * self.existential_deposit), - (4, 40 * self.existential_deposit), - (12, 100 * self.existential_deposit), - ], - } - .assimilate_storage(&mut storage) - .unwrap(); - - pallet_vesting::GenesisConfig:: { - vesting: vec![(1, 1, 10, 0), (2, 10, 20, 0), (12, 10, 20, 0)], - } - .assimilate_storage(&mut storage) - .unwrap(); - - //pallet_crowdloan_reward::GenesisConfig::default().assimilate_storage(&mut - // storage).unwrap(); - - let mut ext = sp_io::TestExternalities::new(storage); - ext.execute_with(|| { - System::set_block_number(1); - }); - ext.execute_with(execute); - ext - } -} // end of 'TestExternalitiesBuilder' implementation - -pub fn reward_events() -> Vec> { - System::events() - .into_iter() - .map(|r| r.event) - .filter_map(|e| { - if let RuntimeEvent::CrowdloanReward(inner) = e { - Some(inner) - } else { - None - } - }) - .collect() -} diff --git a/pallets/crowdloan-reward/src/tests.rs b/pallets/crowdloan-reward/src/tests.rs deleted file mode 100644 index 9869086a66..0000000000 --- a/pallets/crowdloan-reward/src/tests.rs +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright 2021 Centrifuge GmbH (centrifuge.io). -// This file is part of Centrifuge chain project. - -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). - -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -//! Crowdloan reward pallet's unit test cases - -#![cfg(test)] - -// ---------------------------------------------------------------------------- -// Imports and dependencies -// ---------------------------------------------------------------------------- - -use frame_support::{assert_noop, traits::VestingSchedule}; -use sp_runtime::Perbill; - -use crate::{self as pallet_crowdloan_reward, mock::*, Error as CrowdloanRewardError, *}; - -// ---------------------------------------------------------------------------- -// Test cases -// ---------------------------------------------------------------------------- - -#[test] -fn initalize_module() { - TestExternalitiesBuilder::default() - .existential_deposit(1) - .build(|| System::set_block_number(4)) - .execute_with(|| { - assert!(CrowdloanReward::initialize( - RuntimeOrigin::signed(1), - Perbill::from_percent(12), - 4, - 4, - ) - .is_ok()); - - assert_eq!( - CrowdloanReward::direct_payout_ratio(), - Perbill::from_percent(12) - ); - assert_eq!(CrowdloanReward::vesting_period(), Some(4)); - assert_eq!(CrowdloanReward::vesting_start(), Some(4)); - }); -} - -#[test] -fn not_admin_for_setters() { - TestExternalitiesBuilder::default() - .existential_deposit(1) - .build(|| { - System::set_block_number(1); - CrowdloanReward::initialize(RuntimeOrigin::signed(1), Perbill::from_percent(20), 4, 3) - .unwrap(); - }) - .execute_with(|| { - assert_noop!( - CrowdloanReward::set_vesting_start(RuntimeOrigin::signed(2), 1), - CrowdloanRewardError::::MustBeAdministrator - ); - assert_noop!( - CrowdloanReward::set_vesting_period(RuntimeOrigin::signed(2), 3), - CrowdloanRewardError::::MustBeAdministrator - ); - assert_noop!( - CrowdloanReward::set_direct_payout_ratio( - RuntimeOrigin::signed(2), - Perbill::from_percent(10) - ), - CrowdloanRewardError::::MustBeAdministrator - ); - }); -} - -#[test] -fn setters_ok() { - TestExternalitiesBuilder::default() - .existential_deposit(1) - .build(|| { - System::set_block_number(1); - CrowdloanReward::initialize(RuntimeOrigin::signed(1), Perbill::from_percent(20), 4, 3) - .unwrap(); - }) - .execute_with(|| { - assert!(CrowdloanReward::set_vesting_start(RuntimeOrigin::signed(1), 1).is_ok()); - assert!(CrowdloanReward::set_vesting_period(RuntimeOrigin::signed(1), 55555).is_ok()); - assert!(CrowdloanReward::set_direct_payout_ratio( - RuntimeOrigin::signed(1), - Perbill::from_percent(9) - ) - .is_ok()); - assert!(CrowdloanReward::set_vesting_start(RuntimeOrigin::root(), 1).is_ok()); - assert!(CrowdloanReward::set_vesting_period(RuntimeOrigin::root(), 55555).is_ok()); - assert!(CrowdloanReward::set_direct_payout_ratio( - RuntimeOrigin::root(), - Perbill::from_percent(9) - ) - .is_ok()); - }); -} - -#[test] -fn reward_participant() { - TestExternalitiesBuilder::default() - .existential_deposit(1) - .build(|| { - System::set_block_number(1); - CrowdloanReward::initialize(RuntimeOrigin::signed(1), Perbill::from_percent(20), 4, 3) - .unwrap() - }) - .execute_with(|| { - let mod_account = CrowdloanReward::account_id(); - let total_issuance = Balances::total_issuance(); - let mod_balance = Balances::free_balance(&mod_account); - let rew_balance = Balances::free_balance(&4); - - assert!(CrowdloanReward::reward(4, 100).is_ok()); - assert_eq!(Balances::free_balance(&mod_account), 0); - assert_eq!(mod_balance, 0); - assert_eq!(Balances::total_issuance(), total_issuance + 100); - - assert_eq!(Vesting::vesting_balance(&4), Some(80)); - assert_eq!(Balances::usable_balance(&4), rew_balance + 20); - - System::set_block_number(7); - assert_eq!(System::block_number(), 7); - // Account has fully vested - assert_eq!(Vesting::vesting_balance(&4), Some(0)); - - let events = reward_events(); - assert!(events.iter().any(|event| { - *event == pallet_crowdloan_reward::Event::::RewardClaimed(4, 20, 80) - })); - }); -} - -#[test] -fn zero_direct_payout_reward() { - TestExternalitiesBuilder::default() - .existential_deposit(1) - .build(|| { - System::set_block_number(1); - CrowdloanReward::initialize(RuntimeOrigin::signed(1), Perbill::from_percent(0), 4, 3) - .unwrap() - }) - .execute_with(|| { - let mod_account = CrowdloanReward::account_id(); - let total_issuance = Balances::total_issuance(); - let mod_balance = Balances::free_balance(&mod_account); - let rew_balance = Balances::free_balance(&4); - - assert!(CrowdloanReward::reward(4, 100).is_ok()); - assert_eq!(Balances::free_balance(&mod_account), mod_balance); - assert_eq!(Balances::total_issuance(), total_issuance + 100); - - assert_eq!(Vesting::vesting_balance(&4), Some(100)); - // Ensure that no direct payout happened - assert_eq!(Balances::usable_balance(&4), rew_balance); - - System::set_block_number(7); - assert_eq!(System::block_number(), 7); - // Account has fully vested - assert_eq!(Vesting::vesting_balance(&4), Some(0)); - - let events = reward_events(); - assert!(events.iter().any(|event| { - *event == pallet_crowdloan_reward::Event::::RewardClaimed(4, 0, 100) - })); - }); -} - -#[test] -fn account_already_vesting() { - TestExternalitiesBuilder::default() - .existential_deposit(1) - .build(|| { - System::set_block_number(1); - CrowdloanReward::initialize(RuntimeOrigin::signed(1), Perbill::from_percent(20), 4, 3) - .unwrap() - }) - .execute_with(|| { - assert_noop!( - CrowdloanReward::reward(1, 30), - pallet_vesting::Error::::AtMaxVestingSchedules - ); - }); -} - -#[test] -fn reward_amount_to_low_for_vesting() { - TestExternalitiesBuilder::default() - .existential_deposit(1) - .build(|| { - System::set_block_number(1); - CrowdloanReward::initialize(RuntimeOrigin::signed(1), Perbill::from_percent(20), 4, 3) - .unwrap() - }) - .execute_with(|| { - assert_noop!( - CrowdloanReward::reward(1, 15), - pallet_vesting::Error::::AmountLow - ); - }); -} diff --git a/pallets/crowdloan-reward/src/weights.rs b/pallets/crowdloan-reward/src/weights.rs deleted file mode 100644 index d00758ede3..0000000000 --- a/pallets/crowdloan-reward/src/weights.rs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2021 Centrifuge Foundation (centrifuge.io). -// This file is part of Centrifuge chain project. - -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). - -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -use frame_support::weights::Weight; - -pub trait WeightInfo { - fn initialize() -> Weight; - fn set_vesting_start() -> Weight; - fn set_vesting_period() -> Weight; - fn set_direct_payout_ratio() -> Weight; -} - -impl WeightInfo for () { - fn initialize() -> Weight { - Weight::zero() - } - - fn set_vesting_start() -> Weight { - Weight::zero() - } - - fn set_vesting_period() -> Weight { - Weight::zero() - } - - fn set_direct_payout_ratio() -> Weight { - Weight::zero() - } -} diff --git a/runtime/altair/Cargo.toml b/runtime/altair/Cargo.toml index c721e9cf83..047c0e2bb7 100644 --- a/runtime/altair/Cargo.toml +++ b/runtime/altair/Cargo.toml @@ -90,8 +90,6 @@ pallet-bridge = { workspace = true } pallet-collator-allowlist = { workspace = true } pallet-collator-selection = { workspace = true } pallet-collective = { workspace = true } -pallet-crowdloan-claim = { workspace = true } -pallet-crowdloan-reward = { workspace = true } pallet-democracy = { workspace = true } pallet-elections-phragmen = { workspace = true } pallet-ethereum = { workspace = true } @@ -219,8 +217,6 @@ std = [ "pallet-collator-allowlist/std", "pallet-collator-selection/std", "pallet-collective/std", - "pallet-crowdloan-claim/std", - "pallet-crowdloan-reward/std", "pallet-democracy/std", "pallet-elections-phragmen/std", "pallet-ethereum/std", @@ -309,8 +305,6 @@ runtime-benchmarks = [ "pallet-collator-allowlist/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", - "pallet-crowdloan-claim/runtime-benchmarks", - "pallet-crowdloan-reward/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-elections-phragmen/runtime-benchmarks", "pallet-ethereum/runtime-benchmarks", @@ -396,8 +390,6 @@ try-runtime = [ "pallet-collator-allowlist/try-runtime", "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", - "pallet-crowdloan-claim/try-runtime", - "pallet-crowdloan-reward/try-runtime", "pallet-democracy/try-runtime", "pallet-elections-phragmen/try-runtime", "pallet-ethereum/try-runtime", diff --git a/runtime/altair/src/lib.rs b/runtime/altair/src/lib.rs index 4aa5e3bf40..0a3e278011 100644 --- a/runtime/altair/src/lib.rs +++ b/runtime/altair/src/lib.rs @@ -495,8 +495,6 @@ impl InstanceFilter for ProxyType { RuntimeCall::Preimage(..) | RuntimeCall::Fees(..) | RuntimeCall::Anchor(..) | - RuntimeCall::CrowdloanClaim(..) | - RuntimeCall::CrowdloanReward(..) | RuntimeCall::PoolSystem(..) | // Specifically omitting Loans `repay` & `borrow` for pallet_loans RuntimeCall::Loans(pallet_loans::Call::create{..}) | @@ -980,36 +978,6 @@ impl pallet_collator_allowlist::Config for Runtime { type WeightInfo = weights::pallet_collator_allowlist::WeightInfo; } -// Parameterize crowdloan reward pallet configuration -parameter_types! { - pub const CrowdloanRewardPalletId: PalletId = cfg_types::ids::CROWDLOAN_REWARD_PALLET_ID; -} - -// Implement crowdloan reward pallet's configuration trait for the runtime -impl pallet_crowdloan_reward::Config for Runtime { - type AdminOrigin = EnsureRootOr; - type PalletId = CrowdloanRewardPalletId; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::pallet_crowdloan_reward::WeightInfo; -} - -// Parameterize crowdloan claim pallet -parameter_types! { - pub const CrowdloanClaimPalletId: PalletId = cfg_types::ids::CROWDLOAN_CLAIM_PALLET_ID; - pub const MaxProofLength: u32 = 30; -} - -// Implement crowdloan claim pallet configuration trait for the runtime -impl pallet_crowdloan_claim::Config for Runtime { - type AdminOrigin = EnsureRootOr; - type MaxProofLength = MaxProofLength; - type PalletId = CrowdloanClaimPalletId; - type RelayChainAccountId = AccountId; - type RewardMechanism = CrowdloanReward; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::pallet_crowdloan_claim::WeightInfo; -} - // Parameterize collator selection pallet parameter_types! { pub const PotId: PalletId = cfg_types::ids::STAKE_POT_PALLET_ID; @@ -1979,8 +1947,8 @@ construct_runtime!( Fees: pallet_fees::{Pallet, Call, Storage, Config, Event} = 90, Anchor: pallet_anchors::{Pallet, Call, Storage} = 91, // Removed: Claims = 92 - CrowdloanClaim: pallet_crowdloan_claim::{Pallet, Call, Storage, Event} = 93, - CrowdloanReward: pallet_crowdloan_reward::{Pallet, Call, Storage, Event} = 94, + // Removed: CrowdloanClaim = 93 + // Removed: CrowdloanReward = 94 CollatorAllowlist: pallet_collator_allowlist::{Pallet, Call, Storage, Config, Event} = 95, Permissions: pallet_permissions::{Pallet, Call, Storage, Event} = 96, Tokens: pallet_restricted_tokens::{Pallet, Call, Event} = 97, @@ -2702,8 +2670,6 @@ mod benches { [pallet_fees, Fees] [pallet_anchors, Anchor] [pallet_block_rewards, BlockRewards] - [pallet_crowdloan_claim, CrowdloanClaim] - [pallet_crowdloan_reward, CrowdloanReward] [pallet_collator_allowlist, CollatorAllowlist] [pallet_collator_selection, CollatorSelection] [pallet_permissions, Permissions] diff --git a/runtime/altair/src/weights/mod.rs b/runtime/altair/src/weights/mod.rs index 5f02a62635..3c26b723b1 100644 --- a/runtime/altair/src/weights/mod.rs +++ b/runtime/altair/src/weights/mod.rs @@ -17,8 +17,6 @@ pub mod pallet_block_rewards; pub mod pallet_collator_allowlist; pub mod pallet_collator_selection; pub mod pallet_collective; -pub mod pallet_crowdloan_claim; -pub mod pallet_crowdloan_reward; pub mod pallet_democracy; pub mod pallet_elections_phragmen; pub mod pallet_fees; diff --git a/runtime/altair/src/weights/pallet_crowdloan_claim.rs b/runtime/altair/src/weights/pallet_crowdloan_claim.rs deleted file mode 100644 index d7142acd29..0000000000 --- a/runtime/altair/src/weights/pallet_crowdloan_claim.rs +++ /dev/null @@ -1,216 +0,0 @@ - -//! Autogenerated weights for `pallet_crowdloan_claim` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-03-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("altair-dev"), DB CACHE: 1024 - -// Executed Command: -// target/release/centrifuge-chain -// benchmark -// pallet -// --chain=altair-dev -// --steps=50 -// --repeat=20 -// --pallet=pallet_crowdloan_claim -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=/tmp/runtime/altair/src/weights/pallet_crowdloan_claim.rs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `pallet_crowdloan_claim`. -pub struct WeightInfo(PhantomData); -impl pallet_crowdloan_claim::WeightInfo for WeightInfo { - /// Storage: CrowdloanClaim CurrIndex (r:1 w:0) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:0) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:0) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim ProcessedClaims (r:1 w:1) - /// Proof: CrowdloanClaim ProcessedClaims (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:1 w:0) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingStart (r:1 w:0) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:1 w:0) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:1 w:0) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Vesting Vesting (r:1 w:1) - /// Proof: Vesting Vesting (max_values: None, max_size: Some(1057), added: 3532, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(209), added: 2684, mode: MaxEncodedLen) - fn claim_reward_ed25519() -> Weight { - // Proof Size summary in bytes: - // Measured: `639` - // Estimated: `6196` - // Minimum execution time: 273_536_000 picoseconds. - Weight::from_parts(275_820_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: CrowdloanClaim CurrIndex (r:1 w:0) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:0) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:0) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim ProcessedClaims (r:1 w:1) - /// Proof: CrowdloanClaim ProcessedClaims (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:1 w:0) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingStart (r:1 w:0) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:1 w:0) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:1 w:0) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Vesting Vesting (r:1 w:1) - /// Proof: Vesting Vesting (max_values: None, max_size: Some(1057), added: 3532, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(209), added: 2684, mode: MaxEncodedLen) - fn claim_reward_sr25519() -> Weight { - // Proof Size summary in bytes: - // Measured: `795` - // Estimated: `6196` - // Minimum execution time: 275_250_000 picoseconds. - Weight::from_parts(278_065_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: CrowdloanClaim CurrIndex (r:1 w:0) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:0) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:0) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim ProcessedClaims (r:1 w:1) - /// Proof: CrowdloanClaim ProcessedClaims (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:1 w:0) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingStart (r:1 w:0) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:1 w:0) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:1 w:0) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Vesting Vesting (r:1 w:1) - /// Proof: Vesting Vesting (max_values: None, max_size: Some(1057), added: 3532, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(209), added: 2684, mode: MaxEncodedLen) - fn claim_reward_ecdsa() -> Weight { - // Proof Size summary in bytes: - // Measured: `691` - // Estimated: `6196` - // Minimum execution time: 258_728_000 picoseconds. - Weight::from_parts(261_322_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: CrowdloanClaim CurrIndex (r:1 w:1) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:1) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:1) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim PrevIndex (r:1 w:0) - /// Proof: CrowdloanClaim PrevIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:0 w:1) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim CrowdloanTrieIndex (r:0 w:1) - /// Proof: CrowdloanClaim CrowdloanTrieIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LockedAt (r:0 w:1) - /// Proof: CrowdloanClaim LockedAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn initialize() -> Weight { - // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `1489` - // Minimum execution time: 27_041_000 picoseconds. - Weight::from_parts(27_552_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(6)) - } - /// Storage: CrowdloanClaim LeaseStart (r:0 w:1) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_lease_start() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 12_343_000 picoseconds. - Weight::from_parts(12_764_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim LeasePeriod (r:0 w:1) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_lease_period() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 12_353_000 picoseconds. - Weight::from_parts(12_764_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim Contributions (r:0 w:1) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - fn set_contributions_root() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 13_345_000 picoseconds. - Weight::from_parts(13_676_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim LockedAt (r:0 w:1) - /// Proof: CrowdloanClaim LockedAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_locked_at() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 12_153_000 picoseconds. - Weight::from_parts(12_654_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim CrowdloanTrieIndex (r:0 w:1) - /// Proof: CrowdloanClaim CrowdloanTrieIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_crowdloan_trie_index() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 12_304_000 picoseconds. - Weight::from_parts(12_804_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} diff --git a/runtime/altair/src/weights/pallet_crowdloan_reward.rs b/runtime/altair/src/weights/pallet_crowdloan_reward.rs deleted file mode 100644 index cbc5190064..0000000000 --- a/runtime/altair/src/weights/pallet_crowdloan_reward.rs +++ /dev/null @@ -1,83 +0,0 @@ - -//! Autogenerated weights for `pallet_crowdloan_reward` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-03-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("altair-dev"), DB CACHE: 1024 - -// Executed Command: -// target/release/centrifuge-chain -// benchmark -// pallet -// --chain=altair-dev -// --steps=50 -// --repeat=20 -// --pallet=pallet_crowdloan_reward -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=/tmp/runtime/altair/src/weights/pallet_crowdloan_reward.rs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `pallet_crowdloan_reward`. -pub struct WeightInfo(PhantomData); -impl pallet_crowdloan_reward::WeightInfo for WeightInfo { - /// Storage: CrowdloanReward VestingStart (r:0 w:1) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:0 w:1) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:0 w:1) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn initialize() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 14_026_000 picoseconds. - Weight::from_parts(14_337_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(3)) - } - /// Storage: CrowdloanReward VestingStart (r:0 w:1) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_vesting_start() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_952_000 picoseconds. - Weight::from_parts(12_314_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanReward VestingPeriod (r:0 w:1) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_vesting_period() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 12_003_000 picoseconds. - Weight::from_parts(12_254_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanReward DirectPayoutRatio (r:0 w:1) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_direct_payout_ratio() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 12_082_000 picoseconds. - Weight::from_parts(12_323_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} diff --git a/runtime/centrifuge/Cargo.toml b/runtime/centrifuge/Cargo.toml index 19a8a275c4..bc5bceac63 100644 --- a/runtime/centrifuge/Cargo.toml +++ b/runtime/centrifuge/Cargo.toml @@ -90,8 +90,6 @@ pallet-bridge = { workspace = true } pallet-collator-allowlist = { workspace = true } pallet-collator-selection = { workspace = true } pallet-collective = { workspace = true } -pallet-crowdloan-claim = { workspace = true } -pallet-crowdloan-reward = { workspace = true } pallet-democracy = { workspace = true } pallet-elections-phragmen = { workspace = true } pallet-ethereum = { workspace = true } @@ -219,8 +217,6 @@ std = [ "pallet-collator-allowlist/std", "pallet-collator-selection/std", "pallet-collective/std", - "pallet-crowdloan-claim/std", - "pallet-crowdloan-reward/std", "pallet-democracy/std", "pallet-elections-phragmen/std", "pallet-ethereum/std", @@ -308,8 +304,6 @@ runtime-benchmarks = [ "pallet-collator-allowlist/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", - "pallet-crowdloan-claim/runtime-benchmarks", - "pallet-crowdloan-reward/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-elections-phragmen/runtime-benchmarks", "pallet-ethereum/runtime-benchmarks", @@ -395,8 +389,6 @@ try-runtime = [ "pallet-collator-allowlist/try-runtime", "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", - "pallet-crowdloan-claim/try-runtime", - "pallet-crowdloan-reward/try-runtime", "pallet-democracy/try-runtime", "pallet-elections-phragmen/try-runtime", "pallet-ethereum/try-runtime", diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index f31ab882d1..5b81a46983 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -628,8 +628,6 @@ impl InstanceFilter for ProxyType { RuntimeCall::Preimage(..) | RuntimeCall::Fees(..) | RuntimeCall::Anchor(..) | - RuntimeCall::CrowdloanClaim(..) | - RuntimeCall::CrowdloanReward(..) | RuntimeCall::PoolSystem(..) | // Specifically omitting Loans `repay` & `borrow` for pallet_loans RuntimeCall::Loans(pallet_loans::Call::create{..}) | @@ -1126,36 +1124,6 @@ impl chainbridge::Config for Runtime { type WeightInfo = (); } -// Parameterize crowdloan reward pallet configuration -parameter_types! { - pub const CrowdloanRewardPalletId: PalletId = cfg_types::ids::CROWDLOAN_REWARD_PALLET_ID; -} - -// Implement crowdloan reward pallet's configuration trait for the runtime -impl pallet_crowdloan_reward::Config for Runtime { - type AdminOrigin = EnsureRootOr; - type PalletId = CrowdloanRewardPalletId; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::pallet_crowdloan_reward::WeightInfo; -} - -// Parameterize crowdloan claim pallet -parameter_types! { - pub const CrowdloanClaimPalletId: PalletId = cfg_types::ids::CROWDLOAN_CLAIM_PALLET_ID; - pub const MaxProofLength: u32 = 30; -} - -// Implement crowdloan claim pallet configuration trait for the runtime -impl pallet_crowdloan_claim::Config for Runtime { - type AdminOrigin = EnsureRootOr; - type MaxProofLength = MaxProofLength; - type PalletId = CrowdloanClaimPalletId; - type RelayChainAccountId = AccountId; - type RewardMechanism = CrowdloanReward; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::pallet_crowdloan_claim::WeightInfo; -} - // Parameterize collator selection pallet parameter_types! { pub const PotId: PalletId = cfg_types::ids::STAKE_POT_PALLET_ID; @@ -2094,8 +2062,8 @@ construct_runtime!( // Removed: Nfts = 93 Bridge: pallet_bridge::{Pallet, Call, Storage, Config, Event} = 94, // Removed: Migration = 95 - CrowdloanClaim: pallet_crowdloan_claim::{Pallet, Call, Storage, Event} = 96, - CrowdloanReward: pallet_crowdloan_reward::{Pallet, Call, Storage, Event} = 97, + // Removed: CrowdloanClaim = 96 + // Removed: CrowdloanReward = 97 Tokens: pallet_restricted_tokens::{Pallet, Call, Event} = 98, CollatorAllowlist: pallet_collator_allowlist::{Pallet, Call, Storage, Config, Event} = 99, BlockRewardsBase: pallet_rewards::::{Pallet, Storage, Event, Config} = 100, @@ -2751,8 +2719,6 @@ mod benches { [pallet_fees, Fees] [pallet_anchors, Anchor] [pallet_block_rewards, BlockRewards] - [pallet_crowdloan_claim, CrowdloanClaim] - [pallet_crowdloan_reward, CrowdloanReward] [pallet_collator_allowlist, CollatorAllowlist] [pallet_collator_selection, CollatorSelection] [pallet_pool_registry, PoolRegistry] diff --git a/runtime/centrifuge/src/weights/mod.rs b/runtime/centrifuge/src/weights/mod.rs index 5f02a62635..3c26b723b1 100644 --- a/runtime/centrifuge/src/weights/mod.rs +++ b/runtime/centrifuge/src/weights/mod.rs @@ -17,8 +17,6 @@ pub mod pallet_block_rewards; pub mod pallet_collator_allowlist; pub mod pallet_collator_selection; pub mod pallet_collective; -pub mod pallet_crowdloan_claim; -pub mod pallet_crowdloan_reward; pub mod pallet_democracy; pub mod pallet_elections_phragmen; pub mod pallet_fees; diff --git a/runtime/centrifuge/src/weights/pallet_crowdloan_claim.rs b/runtime/centrifuge/src/weights/pallet_crowdloan_claim.rs deleted file mode 100644 index 8179f299fc..0000000000 --- a/runtime/centrifuge/src/weights/pallet_crowdloan_claim.rs +++ /dev/null @@ -1,216 +0,0 @@ - -//! Autogenerated weights for `pallet_crowdloan_claim` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-03-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("centrifuge-dev"), DB CACHE: 1024 - -// Executed Command: -// target/release/centrifuge-chain -// benchmark -// pallet -// --chain=centrifuge-dev -// --steps=50 -// --repeat=20 -// --pallet=pallet_crowdloan_claim -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=/tmp/runtime/centrifuge/src/weights/pallet_crowdloan_claim.rs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `pallet_crowdloan_claim`. -pub struct WeightInfo(PhantomData); -impl pallet_crowdloan_claim::WeightInfo for WeightInfo { - /// Storage: CrowdloanClaim CurrIndex (r:1 w:0) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:0) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:0) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim ProcessedClaims (r:1 w:1) - /// Proof: CrowdloanClaim ProcessedClaims (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:1 w:0) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingStart (r:1 w:0) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:1 w:0) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:1 w:0) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Vesting Vesting (r:1 w:1) - /// Proof: Vesting Vesting (max_values: None, max_size: Some(157), added: 2632, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(209), added: 2684, mode: MaxEncodedLen) - fn claim_reward_ed25519() -> Weight { - // Proof Size summary in bytes: - // Measured: `639` - // Estimated: `6196` - // Minimum execution time: 266_777_000 picoseconds. - Weight::from_parts(269_562_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: CrowdloanClaim CurrIndex (r:1 w:0) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:0) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:0) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim ProcessedClaims (r:1 w:1) - /// Proof: CrowdloanClaim ProcessedClaims (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:1 w:0) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingStart (r:1 w:0) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:1 w:0) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:1 w:0) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Vesting Vesting (r:1 w:1) - /// Proof: Vesting Vesting (max_values: None, max_size: Some(157), added: 2632, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(209), added: 2684, mode: MaxEncodedLen) - fn claim_reward_sr25519() -> Weight { - // Proof Size summary in bytes: - // Measured: `795` - // Estimated: `6196` - // Minimum execution time: 268_971_000 picoseconds. - Weight::from_parts(271_906_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: CrowdloanClaim CurrIndex (r:1 w:0) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:0) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:0) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim ProcessedClaims (r:1 w:1) - /// Proof: CrowdloanClaim ProcessedClaims (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:1 w:0) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingStart (r:1 w:0) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:1 w:0) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:1 w:0) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Vesting Vesting (r:1 w:1) - /// Proof: Vesting Vesting (max_values: None, max_size: Some(157), added: 2632, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(209), added: 2684, mode: MaxEncodedLen) - fn claim_reward_ecdsa() -> Weight { - // Proof Size summary in bytes: - // Measured: `691` - // Estimated: `6196` - // Minimum execution time: 251_618_000 picoseconds. - Weight::from_parts(255_836_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: CrowdloanClaim CurrIndex (r:1 w:1) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:1) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:1) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim PrevIndex (r:1 w:0) - /// Proof: CrowdloanClaim PrevIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:0 w:1) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim CrowdloanTrieIndex (r:0 w:1) - /// Proof: CrowdloanClaim CrowdloanTrieIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LockedAt (r:0 w:1) - /// Proof: CrowdloanClaim LockedAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn initialize() -> Weight { - // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `1489` - // Minimum execution time: 25_788_000 picoseconds. - Weight::from_parts(26_950_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(6)) - } - /// Storage: CrowdloanClaim LeaseStart (r:0 w:1) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_lease_start() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_722_000 picoseconds. - Weight::from_parts(11_993_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim LeasePeriod (r:0 w:1) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_lease_period() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_691_000 picoseconds. - Weight::from_parts(12_142_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim Contributions (r:0 w:1) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - fn set_contributions_root() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 12_784_000 picoseconds. - Weight::from_parts(13_245_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim LockedAt (r:0 w:1) - /// Proof: CrowdloanClaim LockedAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_locked_at() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_771_000 picoseconds. - Weight::from_parts(12_964_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim CrowdloanTrieIndex (r:0 w:1) - /// Proof: CrowdloanClaim CrowdloanTrieIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_crowdloan_trie_index() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_611_000 picoseconds. - Weight::from_parts(12_173_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} diff --git a/runtime/centrifuge/src/weights/pallet_crowdloan_reward.rs b/runtime/centrifuge/src/weights/pallet_crowdloan_reward.rs deleted file mode 100644 index a56ee127ca..0000000000 --- a/runtime/centrifuge/src/weights/pallet_crowdloan_reward.rs +++ /dev/null @@ -1,83 +0,0 @@ - -//! Autogenerated weights for `pallet_crowdloan_reward` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-03-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("centrifuge-dev"), DB CACHE: 1024 - -// Executed Command: -// target/release/centrifuge-chain -// benchmark -// pallet -// --chain=centrifuge-dev -// --steps=50 -// --repeat=20 -// --pallet=pallet_crowdloan_reward -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=/tmp/runtime/centrifuge/src/weights/pallet_crowdloan_reward.rs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `pallet_crowdloan_reward`. -pub struct WeightInfo(PhantomData); -impl pallet_crowdloan_reward::WeightInfo for WeightInfo { - /// Storage: CrowdloanReward VestingStart (r:0 w:1) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:0 w:1) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:0 w:1) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn initialize() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 13_626_000 picoseconds. - Weight::from_parts(14_047_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(3)) - } - /// Storage: CrowdloanReward VestingStart (r:0 w:1) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_vesting_start() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_381_000 picoseconds. - Weight::from_parts(11_842_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanReward VestingPeriod (r:0 w:1) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_vesting_period() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_421_000 picoseconds. - Weight::from_parts(11_882_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanReward DirectPayoutRatio (r:0 w:1) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_direct_payout_ratio() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_511_000 picoseconds. - Weight::from_parts(11_942_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 471c799026..88050be173 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -73,8 +73,6 @@ pallet-bridge = { workspace = true } pallet-collator-allowlist = { workspace = true } pallet-collator-selection = { workspace = true } pallet-collective = { workspace = true } -pallet-crowdloan-claim = { workspace = true } -pallet-crowdloan-reward = { workspace = true } pallet-democracy = { workspace = true } pallet-elections-phragmen = { workspace = true } pallet-ethereum = { workspace = true } @@ -205,8 +203,6 @@ std = [ "pallet-collator-allowlist/std", "pallet-collator-selection/std", "pallet-collective/std", - "pallet-crowdloan-claim/std", - "pallet-crowdloan-reward/std", "pallet-democracy/std", "pallet-elections-phragmen/std", "pallet-ethereum/std", @@ -285,8 +281,6 @@ runtime-benchmarks = [ "pallet-collator-allowlist/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", - "pallet-crowdloan-claim/runtime-benchmarks", - "pallet-crowdloan-reward/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-elections-phragmen/runtime-benchmarks", "pallet-ethereum/runtime-benchmarks", @@ -360,8 +354,6 @@ try-runtime = [ "pallet-collator-allowlist/try-runtime", "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", - "pallet-crowdloan-claim/try-runtime", - "pallet-crowdloan-reward/try-runtime", "pallet-democracy/try-runtime", "pallet-elections-phragmen/try-runtime", "pallet-ethereum/try-runtime", diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 86dd0cecfd..17cc6bd48d 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -90,8 +90,6 @@ pallet-bridge = { workspace = true } pallet-collator-allowlist = { workspace = true } pallet-collator-selection = { workspace = true } pallet-collective = { workspace = true } -pallet-crowdloan-claim = { workspace = true } -pallet-crowdloan-reward = { workspace = true } pallet-democracy = { workspace = true } pallet-elections-phragmen = { workspace = true } pallet-ethereum = { workspace = true } @@ -216,8 +214,6 @@ std = [ "pallet-collator-allowlist/std", "pallet-collator-selection/std", "pallet-collective/std", - "pallet-crowdloan-claim/std", - "pallet-crowdloan-reward/std", "pallet-democracy/std", "pallet-elections-phragmen/std", "pallet-ethereum/std", @@ -303,8 +299,6 @@ runtime-benchmarks = [ "pallet-collator-allowlist/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", - "pallet-crowdloan-claim/runtime-benchmarks", - "pallet-crowdloan-reward/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-elections-phragmen/runtime-benchmarks", "pallet-ethereum/runtime-benchmarks", @@ -387,8 +381,6 @@ try-runtime = [ "pallet-collator-allowlist/try-runtime", "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", - "pallet-crowdloan-claim/try-runtime", - "pallet-crowdloan-reward/try-runtime", "pallet-democracy/try-runtime", "pallet-elections-phragmen/try-runtime", "pallet-ethereum/try-runtime", diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 3f85a22f85..72d939c146 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -500,8 +500,6 @@ impl InstanceFilter for ProxyType { RuntimeCall::Preimage(..) | RuntimeCall::Fees(..) | RuntimeCall::Anchor(..) | - RuntimeCall::CrowdloanClaim(..) | - RuntimeCall::CrowdloanReward(..) | RuntimeCall::PoolSystem(..) | // Specifically omitting Loans `repay` & `borrow` for pallet_loans RuntimeCall::Loans(pallet_loans::Call::create{..}) | @@ -1195,36 +1193,6 @@ impl PoolUpdateGuard for UpdateGuard { } } -// Parameterize crowdloan reward pallet configuration -parameter_types! { - pub const CrowdloanRewardPalletId: PalletId = PalletId(*b"cc/rewrd"); -} - -// Implement crowdloan reward pallet's configuration trait for the runtime -impl pallet_crowdloan_reward::Config for Runtime { - type AdminOrigin = EnsureRootOr; - type PalletId = CrowdloanRewardPalletId; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::pallet_crowdloan_reward::WeightInfo; -} - -// Parameterize crowdloan claim pallet -parameter_types! { - pub const CrowdloanClaimPalletId: PalletId = PalletId(*b"cc/claim"); - pub const MaxProofLength: u32 = 30; -} - -// Implement crowdloan claim pallet configuration trait for the runtime -impl pallet_crowdloan_claim::Config for Runtime { - type AdminOrigin = EnsureRootOr; - type MaxProofLength = MaxProofLength; - type PalletId = CrowdloanClaimPalletId; - type RelayChainAccountId = AccountId; - type RewardMechanism = CrowdloanReward; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::pallet_crowdloan_claim::WeightInfo; -} - // Parameterize collator selection pallet parameter_types! { pub const PotId: PalletId = cfg_types::ids::STAKE_POT_PALLET_ID; @@ -2070,8 +2038,8 @@ construct_runtime!( Fees: pallet_fees::{Pallet, Call, Storage, Config, Event} = 90, Anchor: pallet_anchors::{Pallet, Call, Storage} = 91, // Removed: Claims = 92 - CrowdloanClaim: pallet_crowdloan_claim::{Pallet, Call, Storage, Event} = 93, - CrowdloanReward: pallet_crowdloan_reward::{Pallet, Call, Storage, Event} = 94, + // Removed: CrowdloanClaim = 93 + // Removed: CrowdloanReward = 94 PoolSystem: pallet_pool_system::{Pallet, Call, Storage, Event} = 95, Loans: pallet_loans::{Pallet, Call, Storage, Event} = 96, Permissions: pallet_permissions::{Pallet, Call, Storage, Event} = 97, @@ -2790,8 +2758,6 @@ mod benches { [pallet_fees, Fees] [pallet_anchors, Anchor] [pallet_block_rewards, BlockRewards] - [pallet_crowdloan_claim, CrowdloanClaim] - [pallet_crowdloan_reward, CrowdloanReward] [pallet_collator_allowlist, CollatorAllowlist] [pallet_collator_selection, CollatorSelection] [pallet_pool_registry, PoolRegistry] diff --git a/runtime/development/src/weights/mod.rs b/runtime/development/src/weights/mod.rs index d2e6fc44bb..a9c0e46ff8 100644 --- a/runtime/development/src/weights/mod.rs +++ b/runtime/development/src/weights/mod.rs @@ -17,8 +17,6 @@ pub mod pallet_block_rewards; pub mod pallet_collator_allowlist; pub mod pallet_collator_selection; pub mod pallet_collective; -pub mod pallet_crowdloan_claim; -pub mod pallet_crowdloan_reward; pub mod pallet_democracy; pub mod pallet_elections_phragmen; pub mod pallet_fees; diff --git a/runtime/development/src/weights/pallet_crowdloan_claim.rs b/runtime/development/src/weights/pallet_crowdloan_claim.rs deleted file mode 100644 index c31d337dae..0000000000 --- a/runtime/development/src/weights/pallet_crowdloan_claim.rs +++ /dev/null @@ -1,216 +0,0 @@ - -//! Autogenerated weights for `pallet_crowdloan_claim` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-03-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("development-local"), DB CACHE: 1024 - -// Executed Command: -// target/release/centrifuge-chain -// benchmark -// pallet -// --chain=development-local -// --steps=50 -// --repeat=20 -// --pallet=pallet_crowdloan_claim -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=/tmp/runtime/development/src/weights/pallet_crowdloan_claim.rs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `pallet_crowdloan_claim`. -pub struct WeightInfo(PhantomData); -impl pallet_crowdloan_claim::WeightInfo for WeightInfo { - /// Storage: CrowdloanClaim CurrIndex (r:1 w:0) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:0) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:0) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim ProcessedClaims (r:1 w:1) - /// Proof: CrowdloanClaim ProcessedClaims (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:1 w:0) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingStart (r:1 w:0) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:1 w:0) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:1 w:0) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Vesting Vesting (r:1 w:1) - /// Proof: Vesting Vesting (max_values: None, max_size: Some(1057), added: 3532, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(209), added: 2684, mode: MaxEncodedLen) - fn claim_reward_ed25519() -> Weight { - // Proof Size summary in bytes: - // Measured: `672` - // Estimated: `6196` - // Minimum execution time: 258_876_000 picoseconds. - Weight::from_parts(261_782_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: CrowdloanClaim CurrIndex (r:1 w:0) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:0) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:0) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim ProcessedClaims (r:1 w:1) - /// Proof: CrowdloanClaim ProcessedClaims (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:1 w:0) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingStart (r:1 w:0) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:1 w:0) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:1 w:0) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Vesting Vesting (r:1 w:1) - /// Proof: Vesting Vesting (max_values: None, max_size: Some(1057), added: 3532, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(209), added: 2684, mode: MaxEncodedLen) - fn claim_reward_sr25519() -> Weight { - // Proof Size summary in bytes: - // Measured: `828` - // Estimated: `6196` - // Minimum execution time: 262_984_000 picoseconds. - Weight::from_parts(265_229_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: CrowdloanClaim CurrIndex (r:1 w:0) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:0) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:0) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim ProcessedClaims (r:1 w:1) - /// Proof: CrowdloanClaim ProcessedClaims (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:1 w:0) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingStart (r:1 w:0) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:1 w:0) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:1 w:0) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: Vesting Vesting (r:1 w:1) - /// Proof: Vesting Vesting (max_values: None, max_size: Some(1057), added: 3532, mode: MaxEncodedLen) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(209), added: 2684, mode: MaxEncodedLen) - fn claim_reward_ecdsa() -> Weight { - // Proof Size summary in bytes: - // Measured: `724` - // Estimated: `6196` - // Minimum execution time: 245_751_000 picoseconds. - Weight::from_parts(248_788_000, 0) - .saturating_add(Weight::from_parts(0, 6196)) - .saturating_add(T::DbWeight::get().reads(13)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: CrowdloanClaim CurrIndex (r:1 w:1) - /// Proof: CrowdloanClaim CurrIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeaseStart (r:1 w:1) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LeasePeriod (r:1 w:1) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim PrevIndex (r:1 w:0) - /// Proof: CrowdloanClaim PrevIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim Contributions (r:0 w:1) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim CrowdloanTrieIndex (r:0 w:1) - /// Proof: CrowdloanClaim CrowdloanTrieIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanClaim LockedAt (r:0 w:1) - /// Proof: CrowdloanClaim LockedAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn initialize() -> Weight { - // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `1489` - // Minimum execution time: 23_744_000 picoseconds. - Weight::from_parts(24_155_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(6)) - } - /// Storage: CrowdloanClaim LeaseStart (r:0 w:1) - /// Proof: CrowdloanClaim LeaseStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_lease_start() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_462_000 picoseconds. - Weight::from_parts(11_933_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim LeasePeriod (r:0 w:1) - /// Proof: CrowdloanClaim LeasePeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_lease_period() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_362_000 picoseconds. - Weight::from_parts(11_762_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim Contributions (r:0 w:1) - /// Proof: CrowdloanClaim Contributions (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - fn set_contributions_root() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 12_563_000 picoseconds. - Weight::from_parts(12_994_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim LockedAt (r:0 w:1) - /// Proof: CrowdloanClaim LockedAt (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_locked_at() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_662_000 picoseconds. - Weight::from_parts(11_983_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanClaim CrowdloanTrieIndex (r:0 w:1) - /// Proof: CrowdloanClaim CrowdloanTrieIndex (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_crowdloan_trie_index() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_501_000 picoseconds. - Weight::from_parts(11_942_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} diff --git a/runtime/development/src/weights/pallet_crowdloan_reward.rs b/runtime/development/src/weights/pallet_crowdloan_reward.rs deleted file mode 100644 index 3f8bea438a..0000000000 --- a/runtime/development/src/weights/pallet_crowdloan_reward.rs +++ /dev/null @@ -1,83 +0,0 @@ - -//! Autogenerated weights for `pallet_crowdloan_reward` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-03-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner`, CPU: `AMD EPYC 7763 64-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("development-local"), DB CACHE: 1024 - -// Executed Command: -// target/release/centrifuge-chain -// benchmark -// pallet -// --chain=development-local -// --steps=50 -// --repeat=20 -// --pallet=pallet_crowdloan_reward -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=/tmp/runtime/development/src/weights/pallet_crowdloan_reward.rs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `pallet_crowdloan_reward`. -pub struct WeightInfo(PhantomData); -impl pallet_crowdloan_reward::WeightInfo for WeightInfo { - /// Storage: CrowdloanReward VestingStart (r:0 w:1) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward VestingPeriod (r:0 w:1) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: CrowdloanReward DirectPayoutRatio (r:0 w:1) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn initialize() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 12_824_000 picoseconds. - Weight::from_parts(13_345_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(3)) - } - /// Storage: CrowdloanReward VestingStart (r:0 w:1) - /// Proof: CrowdloanReward VestingStart (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_vesting_start() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 10_971_000 picoseconds. - Weight::from_parts(11_451_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanReward VestingPeriod (r:0 w:1) - /// Proof: CrowdloanReward VestingPeriod (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_vesting_period() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_061_000 picoseconds. - Weight::from_parts(11_421_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: CrowdloanReward DirectPayoutRatio (r:0 w:1) - /// Proof: CrowdloanReward DirectPayoutRatio (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn set_direct_payout_ratio() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_091_000 picoseconds. - Weight::from_parts(11_411_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 75e436d9f6..7fdcb77e38 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -105,8 +105,6 @@ pallet-bridge = { workspace = true, features = ["std"] } pallet-collator-allowlist = { workspace = true, features = ["std"] } pallet-collator-selection = { workspace = true, features = ["std"] } pallet-collective = { workspace = true, features = ["std"] } -pallet-crowdloan-claim = { workspace = true, features = ["std"] } -pallet-crowdloan-reward = { workspace = true, features = ["std"] } pallet-democracy = { workspace = true, features = ["std"] } pallet-elections-phragmen = { workspace = true, features = ["std"] } pallet-ethereum = { workspace = true, features = ["std"] } diff --git a/scripts/cargo_split.sh b/scripts/cargo_split.sh index 7aae7887ef..be1117c512 100755 --- a/scripts/cargo_split.sh +++ b/scripts/cargo_split.sh @@ -33,11 +33,6 @@ fi for crate in $all_crates do if [[ $2 == *"runtime-benchmarks"* || $2 == *"try-runtime"* ]]; then - if [[ "$crate" == "proofs" ]]; then - echo "Skipping!" - continue - fi - if [[ "$crate" == "runtime-integration-tests" ]]; then echo "Skipping!" continue