-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Scaffold futarchy pallet * Scaffold test suite * . * .
- Loading branch information
1 parent
e586f66
commit 27b3db0
Showing
14 changed files
with
476 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
[dependencies] | ||
frame-benchmarking = { workspace = true, optional = true } | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
orml-traits = { workspace = true } | ||
pallet-preimage = { workspace = true } | ||
parity-scale-codec = { workspace = true, features = ["derive", "max-encoded-len"] } | ||
scale-info = { workspace = true, features = ["derive"] } | ||
sp-runtime = { workspace = true } | ||
zeitgeist-primitives = { workspace = true } | ||
|
||
# mock | ||
|
||
env_logger = { workspace = true, optional = true } | ||
orml-currencies = { workspace = true, optional = true } | ||
orml-tokens = { workspace = true, optional = true } | ||
pallet-balances = { workspace = true, optional = true } | ||
pallet-timestamp = { workspace = true, optional = true } | ||
sp-io = { workspace = true, optional = true } | ||
|
||
[dev-dependencies] | ||
test-case = { workspace = true } | ||
zrml-futarchy = { workspace = true, features = ["default", "mock"] } | ||
|
||
[features] | ||
default = ["std"] | ||
mock = [ | ||
"env_logger/default", | ||
"orml-currencies/default", | ||
"orml-tokens/default", | ||
"sp-io/default", | ||
"pallet-balances/default", | ||
"pallet-timestamp/default", | ||
"zeitgeist-primitives/mock", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
] | ||
std = [ | ||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"orml-traits/std", | ||
"parity-scale-codec/std", | ||
"sp-runtime/std", | ||
"zeitgeist-primitives/std", | ||
] | ||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
] | ||
|
||
[package] | ||
authors = ["Zeitgeist PM <[email protected]>"] | ||
edition.workspace = true | ||
name = "zrml-futarchy" | ||
version = "0.5.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Futarchy Module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2024 Forecasting Technologies LTD. | ||
// | ||
// This file is part of Zeitgeist. | ||
// | ||
// Zeitgeist 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. | ||
// | ||
// Zeitgeist 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 Zeitgeist. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#![doc = include_str!("../README.md")] | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
extern crate alloc; | ||
|
||
pub mod mock; | ||
mod tests; | ||
mod traits; | ||
pub mod types; | ||
|
||
pub use pallet::*; | ||
|
||
#[frame_support::pallet] | ||
mod pallet { | ||
use core::marker::PhantomData; | ||
use frame_support::{ | ||
pallet_prelude::{EnsureOrigin, IsType, StorageVersion}, | ||
require_transactional, | ||
traits::{QueryPreimage, StorePreimage}, | ||
transactional, | ||
}; | ||
use frame_system::pallet_prelude::OriginFor; | ||
use orml_traits::MultiCurrency; | ||
use sp_runtime::DispatchResult; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
type MultiCurrency: MultiCurrency<Self::AccountId>; | ||
|
||
// Preimage interface for acquiring call data. | ||
type Preimages: QueryPreimage + StorePreimage; | ||
|
||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
|
||
type SubmitOrigin: EnsureOrigin<Self::RuntimeOrigin>; | ||
|
||
// // TODO | ||
// // The origin from which proposals may be whitelisted. | ||
// type WhitelistOrigin: EnsureOrigin<Self::RuntimeOrigin>; | ||
|
||
// TODO Scheduler, EnactmentPeriod | ||
} | ||
|
||
#[pallet::pallet] | ||
#[pallet::storage_version(STORAGE_VERSION)] | ||
pub struct Pallet<T>(PhantomData<T>); | ||
|
||
pub(crate) type AccountIdOf<T> = <T as frame_system::Config>::AccountId; | ||
pub(crate) type BalanceOf<T> = | ||
<<T as Config>::MultiCurrency as MultiCurrency<AccountIdOf<T>>>::Balance; | ||
|
||
pub(crate) const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); | ||
|
||
// TODO Storage Items | ||
|
||
#[pallet::event] | ||
#[pallet::generate_deposit(fn deposit_event)] | ||
pub enum Event<T> | ||
where | ||
T: Config, {} | ||
|
||
#[pallet::error] | ||
pub enum Error<T> {} | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::call_index(0)] | ||
#[transactional] | ||
#[pallet::weight({0})] | ||
pub fn submit(origin: OriginFor<T>) -> DispatchResult { | ||
T::SubmitOrigin::ensure_origin(origin)?; | ||
Self::do_submit() | ||
} | ||
} | ||
|
||
impl<T: Config> Pallet<T> { | ||
#[require_transactional] | ||
fn do_submit() -> DispatchResult { | ||
Ok(()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2024 Forecasting Technologies LTD. | ||
// | ||
// This file is part of Zeitgeist. | ||
// | ||
// Zeitgeist 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. | ||
// | ||
// Zeitgeist 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 Zeitgeist. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use crate::mock::runtime::{Runtime, System}; | ||
use sp_io::TestExternalities; | ||
use sp_runtime::BuildStorage; | ||
|
||
#[cfg(feature = "parachain")] | ||
use {crate::mock::consts::FOREIGN_ASSET, zeitgeist_primitives::types::CustomMetadata}; | ||
|
||
pub struct ExtBuilder; | ||
|
||
impl ExtBuilder { | ||
pub fn build() -> TestExternalities { | ||
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap(); | ||
|
||
// See the logs in tests when using `RUST_LOG=debug cargo test -- --nocapture` | ||
let _ = env_logger::builder().is_test(true).try_init(); | ||
|
||
pallet_balances::GenesisConfig::<Runtime> { balances: vec![] } | ||
.assimilate_storage(&mut t) | ||
.unwrap(); | ||
|
||
#[cfg(feature = "parachain")] | ||
{ | ||
orml_tokens::GenesisConfig::<Runtime> { balances: vec![] } | ||
.assimilate_storage(&mut t) | ||
.unwrap(); | ||
|
||
let custom_metadata = | ||
CustomMetadata { allow_as_base_asset: true, ..Default::default() }; | ||
|
||
orml_asset_registry::GenesisConfig::<Runtime> { | ||
assets: vec![( | ||
FOREIGN_ASSET, | ||
AssetMetadata { | ||
decimals: 18, | ||
name: "MKL".as_bytes().to_vec().try_into().unwrap(), | ||
symbol: "MKL".as_bytes().to_vec().try_into().unwrap(), | ||
existential_deposit: 0, | ||
location: None, | ||
additional: custom_metadata, | ||
} | ||
.encode(), | ||
)], | ||
last_asset_id: FOREIGN_ASSET, | ||
} | ||
.assimilate_storage(&mut t) | ||
.unwrap(); | ||
} | ||
|
||
let mut test_ext: sp_io::TestExternalities = t.into(); | ||
|
||
test_ext.execute_with(|| System::set_block_number(1)); | ||
|
||
test_ext | ||
} | ||
} |
Oops, something went wrong.