From 58652214ac04fe5e019f2aa67550df1848237d68 Mon Sep 17 00:00:00 2001 From: devwckd Date: Sat, 7 Dec 2024 18:49:08 -0300 Subject: [PATCH 1/5] feat: add emission pallet skeleton --- Cargo.lock | 9 +++++ pallets/emission0/Cargo.toml | 16 +++++++++ pallets/emission0/src/lib.rs | 60 ++++++++++++++++++++++++++++++++ pallets/emission0/src/weights.rs | 22 ++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 pallets/emission0/Cargo.toml create mode 100644 pallets/emission0/src/lib.rs create mode 100644 pallets/emission0/src/weights.rs diff --git a/Cargo.lock b/Cargo.lock index bbc8437..a0402f9 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -6859,6 +6859,15 @@ dependencies = [ "sp-staking", ] +[[package]] +name = "pallet-emission0" +version = "0.1.0" +dependencies = [ + "parity-scale-codec", + "polkadot-sdk", + "scale-info", +] + [[package]] name = "pallet-fast-unstake" version = "37.0.0" diff --git a/pallets/emission0/Cargo.toml b/pallets/emission0/Cargo.toml new file mode 100644 index 0000000..67a42fd --- /dev/null +++ b/pallets/emission0/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "pallet-emission0" +description = "The chain's emission pallet." +version = "0.1.0" +license = "MIT-0" +authors.workspace = true +edition.workspace = true + +[features] +default = ["std"] +std = ["codec/std", "polkadot-sdk/std", "scale-info/std"] + +[dependencies] +codec = { workspace = true, features = ["derive"] } +scale-info = { workspace = true, features = ["derive"] } +polkadot-sdk = { workspace = true, features = ["experimental", "runtime"] } diff --git a/pallets/emission0/src/lib.rs b/pallets/emission0/src/lib.rs new file mode 100644 index 0000000..a5a3361 --- /dev/null +++ b/pallets/emission0/src/lib.rs @@ -0,0 +1,60 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +mod weights; + +use crate::frame::testing_prelude::DispatchResult; +use crate::frame::testing_prelude::OriginFor; +pub use pallet::*; +use polkadot_sdk::frame_support::pallet_prelude::{ValueQuery, *}; +use polkadot_sdk::polkadot_sdk_frame as frame; + +#[frame::pallet] +pub mod pallet { + use frame::traits::ConstU64; + + use super::*; + + #[pallet::storage] + pub type Weights = + StorageMap<_, Identity, u16, BoundedVec<(u16, u16), ConstU32<{ u32::MAX }>>>; + + #[pallet::storage] + pub type PendingEmission = StorageMap<_, Identity, u16, u64, ValueQuery>; + + #[pallet::storage] + pub type UnitEmission = StorageValue<_, u64, ValueQuery, ConstU64<23148148148>>; + + #[pallet::config] + pub trait Config: polkadot_sdk::frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(0)] + pub fn set_weights_extrinsic( + origin: OriginFor, + uids: Vec, + weights: Vec, + ) -> DispatchResult { + weights::set_weights::(origin, uids, weights) + } + + #[pallet::call_index(2)] + #[pallet::weight(0)] + pub fn delegate_weight_control_extrinsic( + origin: OriginFor, + target: T::AccountId, + ) -> DispatchResult { + weights::delegate_weight_control::(origin, target) + } + + #[pallet::call_index(3)] + #[pallet::weight(0)] + pub fn regain_weight_control_extrinsic(origin: OriginFor) -> DispatchResult { + weights::regain_weight_control::(origin) + } + } +} diff --git a/pallets/emission0/src/weights.rs b/pallets/emission0/src/weights.rs new file mode 100644 index 0000000..bbc193a --- /dev/null +++ b/pallets/emission0/src/weights.rs @@ -0,0 +1,22 @@ +use polkadot_sdk::{ + frame_support::dispatch::DispatchResult, polkadot_sdk_frame::prelude::OriginFor, +}; + +pub fn set_weights( + _origin: OriginFor, + _uids: Vec, + _weights: Vec, +) -> DispatchResult { + todo!() +} + +pub fn delegate_weight_control( + _origin: OriginFor, + _target: T::AccountId, +) -> DispatchResult { + todo!() +} + +pub fn regain_weight_control(_origin: OriginFor) -> DispatchResult { + todo!() +} From ce0b1d55d1992ebc87f3574d545e2ddd0f3b6069 Mon Sep 17 00:00:00 2001 From: devwckd Date: Sun, 8 Dec 2024 23:25:47 -0300 Subject: [PATCH 2/5] feat: add emission pallet skeleton --- pallets/emission0/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/emission0/src/lib.rs b/pallets/emission0/src/lib.rs index a5a3361..7dde22b 100644 --- a/pallets/emission0/src/lib.rs +++ b/pallets/emission0/src/lib.rs @@ -19,7 +19,7 @@ pub mod pallet { StorageMap<_, Identity, u16, BoundedVec<(u16, u16), ConstU32<{ u32::MAX }>>>; #[pallet::storage] - pub type PendingEmission = StorageMap<_, Identity, u16, u64, ValueQuery>; + pub type PendingEmission = StorageMap<_, Identity, u16, u64>; #[pallet::storage] pub type UnitEmission = StorageValue<_, u64, ValueQuery, ConstU64<23148148148>>; From d4551101ec709eb4ae971197aa1e4bd9c5f931fe Mon Sep 17 00:00:00 2001 From: devwckd Date: Mon, 9 Dec 2024 15:13:38 -0300 Subject: [PATCH 3/5] feat: enable dev mode --- pallets/emission0/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/emission0/src/lib.rs b/pallets/emission0/src/lib.rs index 7dde22b..6353180 100644 --- a/pallets/emission0/src/lib.rs +++ b/pallets/emission0/src/lib.rs @@ -8,7 +8,7 @@ pub use pallet::*; use polkadot_sdk::frame_support::pallet_prelude::{ValueQuery, *}; use polkadot_sdk::polkadot_sdk_frame as frame; -#[frame::pallet] +#[frame::pallet(dev_mode)] pub mod pallet { use frame::traits::ConstU64; From 96649fcbaff64b8ca69bc380d74ba9e6a164cc26 Mon Sep 17 00:00:00 2001 From: devwckd Date: Tue, 10 Dec 2024 14:16:34 -0300 Subject: [PATCH 4/5] feat: add type aliases --- pallets/emission0/src/ext.rs | 11 +++++++++++ pallets/emission0/src/lib.rs | 15 ++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 pallets/emission0/src/ext.rs diff --git a/pallets/emission0/src/ext.rs b/pallets/emission0/src/ext.rs new file mode 100644 index 0000000..539a4dd --- /dev/null +++ b/pallets/emission0/src/ext.rs @@ -0,0 +1,11 @@ +use polkadot_sdk::frame_support::traits::Currency; + +pub(super) type BalanceOf = <::Currency as Currency< + ::AccountId, +>>::Balance; + +pub(super) type AccountIdOf = ::AccountId; + +pub(super) type Block = u64; + +pub(super) type BlockAmount = u64; diff --git a/pallets/emission0/src/lib.rs b/pallets/emission0/src/lib.rs index 6353180..f87899d 100644 --- a/pallets/emission0/src/lib.rs +++ b/pallets/emission0/src/lib.rs @@ -1,16 +1,18 @@ #![cfg_attr(not(feature = "std"), no_std)] +mod ext; mod weights; use crate::frame::testing_prelude::DispatchResult; use crate::frame::testing_prelude::OriginFor; +pub(crate) use ext::*; pub use pallet::*; use polkadot_sdk::frame_support::pallet_prelude::{ValueQuery, *}; use polkadot_sdk::polkadot_sdk_frame as frame; #[frame::pallet(dev_mode)] pub mod pallet { - use frame::traits::ConstU64; + use frame::traits::{ConstU128, Currency}; use super::*; @@ -19,13 +21,16 @@ pub mod pallet { StorageMap<_, Identity, u16, BoundedVec<(u16, u16), ConstU32<{ u32::MAX }>>>; #[pallet::storage] - pub type PendingEmission = StorageMap<_, Identity, u16, u64>; + pub type PendingEmission = StorageMap<_, Identity, u16, BalanceOf>; #[pallet::storage] - pub type UnitEmission = StorageValue<_, u64, ValueQuery, ConstU64<23148148148>>; + pub type UnitEmission = + StorageValue<_, BalanceOf, ValueQuery, ConstU128<23148148148>>; #[pallet::config] - pub trait Config: polkadot_sdk::frame_system::Config {} + pub trait Config: polkadot_sdk::frame_system::Config { + type Currency: Currency + Send + Sync; + } #[pallet::pallet] pub struct Pallet(_); @@ -46,7 +51,7 @@ pub mod pallet { #[pallet::weight(0)] pub fn delegate_weight_control_extrinsic( origin: OriginFor, - target: T::AccountId, + target: AccountOf, ) -> DispatchResult { weights::delegate_weight_control::(origin, target) } From 945ac305bdb49b154f495d52cff5a4d7162c223a Mon Sep 17 00:00:00 2001 From: devwckd Date: Tue, 10 Dec 2024 14:18:08 -0300 Subject: [PATCH 5/5] feat: exchange uid usages for account ids --- pallets/emission0/src/ext.rs | 4 ---- pallets/emission0/src/lib.rs | 12 ++++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pallets/emission0/src/ext.rs b/pallets/emission0/src/ext.rs index 539a4dd..5c072c1 100644 --- a/pallets/emission0/src/ext.rs +++ b/pallets/emission0/src/ext.rs @@ -5,7 +5,3 @@ pub(super) type BalanceOf = <::Currency as Currency< >>::Balance; pub(super) type AccountIdOf = ::AccountId; - -pub(super) type Block = u64; - -pub(super) type BlockAmount = u64; diff --git a/pallets/emission0/src/lib.rs b/pallets/emission0/src/lib.rs index f87899d..9e30598 100644 --- a/pallets/emission0/src/lib.rs +++ b/pallets/emission0/src/lib.rs @@ -17,11 +17,15 @@ pub mod pallet { use super::*; #[pallet::storage] - pub type Weights = - StorageMap<_, Identity, u16, BoundedVec<(u16, u16), ConstU32<{ u32::MAX }>>>; + pub type Weights = StorageMap< + _, + Identity, + AccountIdOf, + BoundedVec<(AccountIdOf, u16), ConstU32<{ u32::MAX }>>, + >; #[pallet::storage] - pub type PendingEmission = StorageMap<_, Identity, u16, BalanceOf>; + pub type PendingEmission = StorageMap<_, Identity, AccountIdOf, BalanceOf>; #[pallet::storage] pub type UnitEmission = @@ -51,7 +55,7 @@ pub mod pallet { #[pallet::weight(0)] pub fn delegate_weight_control_extrinsic( origin: OriginFor, - target: AccountOf, + target: AccountIdOf, ) -> DispatchResult { weights::delegate_weight_control::(origin, target) }