Skip to content

Commit

Permalink
project configs (#233)
Browse files Browse the repository at this point in the history
* add back sudo to rococo

* runtime api

* runtime-api-wiring

* some dummy log statements

* attempt 1 to add try-runtime

* second attempt

* add to the cli

* fix warn issue

* on initialise, remove on runtime upgrade proposasl

* add the new storage version migration

* pick runtime

* new migration for proposals

* fmt

* fix v3-v4 migration test

* fix 2

* fix brief migration test

* clippy

* fmt

* new MilestoneVote implementation

* fix implementation

* get project individual votes

* remove total votes api

* fmt

* ummm

* new format for Individual votes

* boom baby, and a fmt

* clippy

* fix build

* fmt

* bump spec version

* 1

* individual votes impl with storage

* fix buggy impl

* define immutability, update on vote

* use individual votes for oninit and submit and close voting + update migration

* fixing build

* seperated test files, tested ImmutableVotes

* fix runtime api, reorg proposals

* fmt

* fmt

* clippy

* migration, err handling

* fix migration

* fmt

* fix

* clippy

* update executive and spec version

* fmt

* remove todos

* remove wrong comment

* fix failing test

* fmt

* rip the proposals changes

* merge and fix tests

* remove unused config items, reorg them, add test cases

* actually add decent documentation in pallet-proposals

* run on gcp

* bump to rebuild

* use self hosted runner

* already installed on runner

* attempt auto scaling runner

* increase disk size

* bump to build again

* dont delete at the end of the job

* remove unused directories

* bump

* change region

* split the jobs

* add -y flag

* test menually installing rust

* -y flag

* more -y

* remove double install of protobugf

* -y

* trial 1

* fix

* fix2

* fix3

* bump up

* bump

* change zone

* bump

* lol -y

* bump

* bump 2

* set home directory

* try to run as user

* init commit

* commit 2

* test

* test 3

* attempt 4

* bump

* bump

* bump

* bump

* bump

* reduce image size

* bump

* bump

* bump again

* add clippy

* build essentials

* lock

* clang

* refactor

* typo

* typo 2

* make zone configurable

* project voting data api (#224)

* add back sudo to rococo

* runtime api

* runtime-api-wiring

* some dummy log statements

* attempt 1 to add try-runtime

* second attempt

* add to the cli

* fix warn issue

* on initialise, remove on runtime upgrade proposasl

* add the new storage version migration

* pick runtime

* new migration for proposals

* fmt

* fix v3-v4 migration test

* fix 2

* fix brief migration test

* clippy

* fmt

* new MilestoneVote implementation

* fix implementation

* get project individual votes

* remove total votes api

* fmt

* ummm

* new format for Individual votes

* boom baby, and a fmt

* clippy

* fix build

* fmt

* bump spec version

* 1

* individual votes impl with storage

* fix buggy impl

* define immutability, update on vote

* use individual votes for oninit and submit and close voting + update migration

* fixing build

* seperated test files, tested ImmutableVotes

* fix runtime api, reorg proposals

* fmt

* fmt

* clippy

* migration, err handling

* fix migration

* fmt

* fix

* clippy

* update executive and spec version

* fmt

* remove todos

* remove wrong comment

* fix failing test

* fmt

* run on gcp

* bump to rebuild

* use self hosted runner

* already installed on runner

* attempt auto scaling runner

* increase disk size

* bump to build again

* dont delete at the end of the job

* remove unused directories

* bump

* change region

* split the jobs

* add -y flag

* test menually installing rust

* -y flag

* more -y

* remove double install of protobugf

* -y

* trial 1

* fix

* fix2

* fix3

* bump up

* bump

* change zone

* bump

* lol -y

* bump

* bump 2

* set home directory

* try to run as user

* init commit

* commit 2

* test

* test 3

* attempt 4

* bump

* bump

* bump

* bump

* bump

* reduce image size

* bump

* bump

* bump again

* add clippy

* build essentials

* clang

* refactor

* typo

* typo 2

* make zone configurable

---------

Co-authored-by: samelamin <hussam.elamin@gmail.com>

* refactoring

* mark the no_confidence as deprecated with the introduction of pallet-disputes

* migration for new fields

* add to runtime with dummy weights

* add genesis config

* removed everything about no-confidence logic

* fixed the format check as it was failing in the build

* add fellowship migration, add migration to runtime

* move migration to v7 after rococo upgrade

* fix migration

* fix accountid trait bounds

* fix dependancy issue: #252

* add fellowship to runtime benchmarks

* generate fellowship weights

* remove test test

* fmt

* add jury selector trait

* run gcp on all pushes

* restore

* select a random jury given a jury length

* fix randomer

* select jury tests

* refactor minor

* remove genesis, add permissions, FellowshipPermissions trait

* permissions impl, mock impl

* fix tests

* organise tests, add permissions tests

* add new config to runtime

* fmt

* add jury selector into migration

* dispute hooks draft, pallet-dispute in runtime

* raise disputes and hooks skeleton

* forgot

* trait bounds impl, todos

* bugs

* fix

* tests

* track dispute per milestone instead of per project

* minor fixes

* update withdrawn to use is_withdrawn

* fix

* fix

* more todos! Jury selector fix

* tests, refund extrinsic

* mindbending fix

* try_mutate_exists instead

* fixing just keep fixing

* another one

* marching

* my fingers hurt

* green stuff has appeared!

* grants fixes

* fixrs

* fix

* optimise refund extrinsics

* add non zero arith check, deposit event, refund benchmark

* fix

* raise dispute benchmark

* migration madness

* fix migration and tests

* jury selector move around

* fix bloomin proposals

* fix briefs

* fix grants

* fiix runtime

* fix integration test, rewrite get jury

* generate dispute weights

* fix all but deposits

* fix xcm tranfers

* trying

* fix grants benchmark tests

* fix for proposal benchmark tests

* cargo fmt

* fix for failing benchmark tests

* audit warnings

* minor fix

* remove generic param for run to block felloship

* clippy

* weights

* proposal benchmark fixes + weights

* change balance type proposals mock to u128 to prevent overflow

* fmt

---------

Co-authored-by: samelamin <hussam.elamin@gmail.com>
Co-authored-by: Shankar Rao Mata <mshankarrao1970@gmail.com>
  • Loading branch information
3 people authored Nov 24, 2023
1 parent 691fff9 commit a78759c
Show file tree
Hide file tree
Showing 50 changed files with 2,738 additions and 1,291 deletions.
11 changes: 7 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 7 additions & 21 deletions libs/common-types/src/milestone_origin.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{sp_runtime::traits::AccountIdConversion, PalletId};
use scale_info::TypeInfo;
use xcm::latest::{Junction, Junctions::*, MultiLocation};

/// A wrapper around
pub trait TreasuryOriginConverter<AccountId: Into<[u8; 32]>> {
fn get_multi_location(
&self,
recipiant: AccountId,
) -> Result<MultiLocation, TreasuryOriginError>;
pub trait TreasuryOriginConverter {
fn get_multi_location(&self) -> Result<MultiLocation, TreasuryOriginError>;
}

impl<AccountId: Into<[u8; 32]>> TreasuryOriginConverter<AccountId> for TreasuryOrigin {
fn get_multi_location(
&self,
recipiant: AccountId,
) -> Result<MultiLocation, TreasuryOriginError> {
impl TreasuryOriginConverter for TreasuryOrigin {
fn get_multi_location(&self) -> Result<MultiLocation, TreasuryOriginError> {
match &self {
TreasuryOrigin::Kusama => Ok(MultiLocation::new(
1,
X1(Junction::AccountId32 {
id: recipiant.into(),
id: PalletId(*b"py/trsry").into_account_truncating(),
network: None,
}),
)),
TreasuryOrigin::Imbue => Ok(MultiLocation::new(
0,
X1(Junction::AccountId32 {
id: recipiant.into(),
id: PalletId(*b"py/trsry").into_account_truncating(),
network: None,
}),
)),
Expand All @@ -43,15 +38,6 @@ pub enum TreasuryOriginError {
NetworkUnsupported,
}

#[derive(
Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
)]
pub enum FundingType {
Proposal,
Brief,
Grant(TreasuryOrigin),
}

#[derive(
Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
)]
Expand Down
6 changes: 4 additions & 2 deletions pallets/briefs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-li
common-traits = { path = "../../libs/common-traits", default-features = false }
common-types = { path = "../../libs/common-types", default-features = false }
pallet-deposits = {path= "../deposits", default-features = false }
pallet-fellowship = { path = "../fellowship", default-features = false }
pallet-proposals = {path= "../proposals", default-features = false }

[dev-dependencies]
Expand All @@ -54,7 +55,7 @@ common-types = { path = "../../libs/common-types" }
common-runtime = { path = "../../runtime/common"}
pallet-proposals = {path= "../proposals"}
pallet-deposits = {path= "../deposits"}

pallet-disputes = {path= "../disputes"}

[features]
default = [ 'std' ]
Expand All @@ -70,7 +71,7 @@ std = [
"pallet-balances/std",
"pallet-deposits/std",
"pallet-proposals/std",
"pallet-timestamp/std",
"pallet-fellowship/std",
"scale-info/std",
"serde/std",
"sp-api/std",
Expand Down Expand Up @@ -102,6 +103,7 @@ try-runtime = [
"pallet-proposals/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-fellowship/try-runtime",
"pallet-xcm/try-runtime",
"sp-runtime/try-runtime",
]
43 changes: 35 additions & 8 deletions pallets/briefs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ mod benchmarking;
#[cfg(any(feature = "runtime-benchmarks", test))]
mod test_utils;

pub mod migrations;
//pub mod migrations;

#[frame_support::pallet]
pub mod pallet {
use common_types::{milestone_origin::FundingType, CurrencyId};
use common_types::CurrencyId;
use frame_support::{
pallet_prelude::*, sp_runtime::Saturating, traits::Get, weights::Weight, BoundedBTreeMap,
};
use frame_system::pallet_prelude::*;
use orml_traits::{MultiCurrency, MultiReservableCurrency};
use pallet_deposits::traits::DepositHandler;
use pallet_fellowship::traits::SelectJury;
use pallet_proposals::traits::IntoProposal;
use pallet_proposals::{Contribution, ProposedMilestone};
use pallet_proposals::{Contribution, FundingPath, ProposedMilestone};
use sp_arithmetic::per_things::Percent;
use sp_core::H256;
use sp_runtime::traits::Zero;
Expand Down Expand Up @@ -70,8 +71,8 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The currency type.
type RMultiCurrency: MultiReservableCurrency<AccountIdOf<Self>, CurrencyId = CurrencyId>;
type AuthorityOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// The type that allows for evolution from brief to proposal.
type IntoProposal: IntoProposal<AccountIdOf<Self>, BalanceOf<Self>, BlockNumberFor<Self>>;
/// The maximum amount of owners to a brief.
Expand All @@ -82,7 +83,9 @@ pub mod pallet {
/// Storage deposits.
type BriefStorageItem: Get<StorageItemOf<Self>>;
type DepositHandler: DepositHandler<BalanceOf<Self>, AccountIdOf<Self>>;

/// The type that selects a list of jury members.
type JurySelector: SelectJury<AccountIdOf<Self>>;
/// The weight info for the extrinsics.
type WeightInfo: WeightInfoT;
}

Expand Down Expand Up @@ -147,6 +150,8 @@ pub mod pallet {
FreelancerApprovalRequired,
/// Milestones total do not add up to 100%.
MilestonesTotalPercentageMustEqual100,
/// too many milestones here mate fixed with https://github.com/ImbueNetwork/imbue/issues/267
TooManyMilestones,
}

#[pallet::call]
Expand Down Expand Up @@ -291,13 +296,35 @@ pub mod pallet {
let contributions = BriefContributions::<T>::get(brief_id);

<T as Config>::DepositHandler::return_deposit(brief.deposit_id)?;

let refund_locations =
<T as Config>::IntoProposal::convert_contributions_to_refund_locations(
&contributions
.clone()
.into_inner()
.try_into()
.map_err(|_| Error::<T>::TooManyBriefOwners)?,
);

<T as Config>::IntoProposal::convert_to_proposal(
brief.currency_id,
contributions.into_inner(),
contributions
.into_inner()
.try_into()
.map_err(|_| Error::<T>::TooManyBriefOwners)?,
brief_id,
brief.applicant,
brief.milestones.into(),
FundingType::Brief,
brief
.milestones
.to_vec()
.try_into()
.map_err(|_| Error::<T>::TooManyMilestones)?,
refund_locations,
<T::JurySelector as SelectJury<AccountIdOf<T>>>::select_jury()
.to_vec()
.try_into()
.map_err(|_| Error::<T>::TooManyMilestones)?,
FundingPath::TakeFromReserved,
)?;

BriefContributions::<T>::remove(brief_id);
Expand Down
46 changes: 35 additions & 11 deletions pallets/briefs/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,17 @@ parameter_types! {
impl pallet_briefs::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RMultiCurrency = Tokens;
type AuthorityOrigin = EnsureRoot<AccountId>;
type IntoProposal = pallet_proposals::Pallet<Test>;
type MaxBriefOwners = MaxBriefOwners;
type MaxMilestonesPerBrief = MaxMilestonesPerProject;
type BriefStorageItem = BriefStorageItem;
type DepositHandler = MockDepositHandler;
type WeightInfo = pallet_briefs::WeightInfo<Self>;
type JurySelector = MockJurySelector;
}

parameter_types! {
pub const TwoWeekBlockUnit: u32 = 100800u32;
pub const ProposalsPalletId: PalletId = PalletId(*b"imbgrant");
pub NoConfidenceTimeLimit: BlockNumber = 100800u32.into();
pub PercentRequiredForVoteToPass: Percent = Percent::from_percent(75u8);
pub MaximumContributorsPerProject: u32 = 50;
pub RefundsPerBlock: u8 = 2;
Expand All @@ -226,30 +224,31 @@ parameter_types! {
pub ExpiringProjectRoundsPerBlock: u32 = 10;
pub ProjectStorageItem: StorageItem = StorageItem::Project;
pub MaxProjectsPerAccount: u16 = 100;
pub PercentRequiredForVoteNoConfidenceToPass: Percent = Percent::from_percent(75u8);
pub ImbueFeeAccount: AccountId = TREASURY;
pub MaxJuryMembers: u32 = 100;
}

impl pallet_proposals::Config for Test {
type RuntimeEvent = RuntimeEvent;
type PalletId = ProposalsPalletId;
type AuthorityOrigin = EnsureRoot<AccountId>;
type MultiCurrency = Tokens;
type WeightInfo = pallet_proposals::WeightInfo<Self>;
// Adding 2 weeks as th expiration time
type MaxWithdrawalExpiration = TwoWeekBlockUnit;
type NoConfidenceTimeLimit = NoConfidenceTimeLimit;
type PercentRequiredForVoteToPass = PercentRequiredForVoteToPass;
type MaximumContributorsPerProject = MaximumContributorsPerProject;
type MilestoneVotingWindow = MilestoneVotingWindow;
type RefundHandler = pallet_proposals::traits::MockRefundHandler<Test>;
type ExternalRefundHandler = pallet_proposals::traits::MockRefundHandler<Test>;
type MaxMilestonesPerProject = MaxMilestonesPerProject;
type ImbueFee = ImbueFee;
type ImbueFeeAccount = ImbueFeeAccount;
type ExpiringProjectRoundsPerBlock = ExpiringProjectRoundsPerBlock;
type ProjectStorageItem = ProjectStorageItem;
type DepositHandler = MockDepositHandler;
type ProjectStorageItem = ProjectStorageItem;
type MaxProjectsPerAccount = MaxProjectsPerAccount;
type PercentRequiredForVoteNoConfidenceToPass = PercentRequiredForVoteNoConfidenceToPass;
type DisputeRaiser = MockDisputeRaiser;
type JurySelector = MockJurySelector;
type AssetSignerOrigin = EnsureRoot<AccountId>;
}

parameter_types! {
pub const BasicDeposit: u64 = 10;
pub const FieldDeposit: u64 = 10;
Expand Down Expand Up @@ -281,6 +280,7 @@ parameter_types! {
pub static ALICE: AccountId = 125;
pub static BOB: AccountId = 126;
pub static CHARLIE: AccountId = 127;
pub static TREASURY: AccountId = 200;

pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default()
Expand All @@ -307,3 +307,27 @@ pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
});
ext
}

pub struct MockJurySelector;
impl pallet_fellowship::traits::SelectJury<AccountId> for MockJurySelector {
type JurySize = MaxJuryMembers;
fn select_jury() -> BoundedVec<AccountId, Self::JurySize> {
BoundedVec::new()
}
}

pub struct MockDisputeRaiser;
impl pallet_disputes::traits::DisputeRaiser<AccountId> for MockDisputeRaiser {
type DisputeKey = u32;
type SpecificId = u32;
type MaxJurySize = MaxJuryMembers;
type MaxSpecifics = MaxMilestonesPerProject;
fn raise_dispute(
_dispute_key: Self::DisputeKey,
_raised_by: AccountId,
_jury: BoundedVec<AccountId, Self::MaxJurySize>,
_specific_ids: BoundedVec<Self::SpecificId, Self::MaxSpecifics>,
) -> Result<(), DispatchError> {
Ok(())
}
}
Loading

0 comments on commit a78759c

Please sign in to comment.