Skip to content

Commit

Permalink
Merge pull request #213 from InvArch/gabriel-v0.9.43
Browse files Browse the repository at this point in the history
Upgrade to v0.9.43
  • Loading branch information
arrudagates authored Aug 17, 2023
2 parents 22682fa + 7153877 commit 82061c3
Show file tree
Hide file tree
Showing 40 changed files with 1,175 additions and 1,797 deletions.
30 changes: 15 additions & 15 deletions INV4/pallet-inv4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ version = '0.1.0-dev'
[dependencies]
serde = { version = "1.0.132", optional = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" }
smallvec = "1.6.1"

scale-info = { version = "2.0.0", features = ["derive"], default-features = false }
Expand All @@ -25,21 +25,21 @@ log = { version = "0.4.14", default-features = false }
# InvArch dependencies
primitives = { package = "invarch-primitives", path = "../../primitives", default-features = false }

sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" }

pallet-balances = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.36", default-features = false }
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', default-features = false , branch = "polkadot-v0.9.43" }

frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.36", default-features = false, optional = true }
frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', default-features = false, optional = true , branch = "polkadot-v0.9.43" }

orml-tokens2 = { package = "orml-tokens", git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, rev = "4f5a3f34d8cbd98b7bc2e295219a3e7b99b9ecaf" }
orml-tokens2 = { package = "orml-tokens", git = "https://github.com/arrudagates/open-runtime-module-library", default-features = false, rev = "7ecebeab7e3dbc2226ed58d32ee159271a8176ae" }

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
orml-traits2 = { package = "orml-traits", git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, rev = "4f5a3f34d8cbd98b7bc2e295219a3e7b99b9ecaf" }
orml-traits = { package = "orml-traits", git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.36" }
orml-tokens = { package = "orml-tokens", git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.36" }
orml-asset-registry = { package = "orml-asset-registry", git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.36" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, rev = "7ecebeab7e3dbc2226ed58d32ee159271a8176ae" }
orml-traits2 = { package = "orml-traits", git = "https://github.com/arrudagates/open-runtime-module-library", default-features = false, rev = "7ecebeab7e3dbc2226ed58d32ee159271a8176ae" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, rev = "7ecebeab7e3dbc2226ed58d32ee159271a8176ae" }
orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, rev = "7ecebeab7e3dbc2226ed58d32ee159271a8176ae" }

[features]
default = ["std"]
Expand Down
24 changes: 12 additions & 12 deletions INV4/pallet-inv4/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ use core::convert::TryFrom;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_support::{
dispatch::PostDispatchInfo,
pallet_prelude::DispatchResultWithPostInfo,
traits::{Currency, Get},
BoundedBTreeMap,
BoundedBTreeMap, BoundedVec,
};
use frame_system::RawOrigin as SystemOrigin;
use sp_runtime::{
traits::{Bounded, Hash, Zero},
DispatchError, DispatchErrorWithPostInfo, Perbill,
};
use sp_std::{collections::btree_map::BTreeMap, iter::Sum, ops::Div, prelude::*, vec};
use sp_std::{
collections::btree_map::BTreeMap, convert::TryInto, iter::Sum, ops::Div, prelude::*, vec,
};

use crate::Pallet as INV4;

Expand All @@ -39,7 +42,7 @@ fn derive_account<T: Config>(core_id: T::CoreId) -> T::AccountId {
derive_core_account::<T, T::CoreId, T::AccountId>(core_id)
}

fn mock_core<T: Config>() -> Result<(), DispatchError>
fn mock_core<T: Config>() -> DispatchResultWithPostInfo
where
Result<
INV4Origin<T, <T as pallet::Config>::CoreId, <T as frame_system::Config>::AccountId>,
Expand All @@ -55,7 +58,7 @@ where

INV4::<T>::create_core(
SystemOrigin::Signed(whitelisted_caller()).into(),
vec![],
vec![].try_into().unwrap(),
perbill_one(),
perbill_one(),
FeeAsset::TNKR,
Expand Down Expand Up @@ -156,7 +159,7 @@ benchmarks! {
create_core {
let m in 0 .. T::MaxMetadata::get();

let metadata = vec![u8::MAX; m as usize];
let metadata: BoundedVec<u8, T::MaxMetadata> = vec![u8::MAX; m as usize].try_into().unwrap();
let caller = whitelisted_caller();
let minimum_support = perbill_one();
let required_approval = perbill_one();
Expand All @@ -168,7 +171,7 @@ benchmarks! {
assert_last_event::<T>(Event::CoreCreated {
core_account: derive_account::<T>(0u32.into()),
core_id: 0u32.into(),
metadata,
metadata: metadata.to_vec(),
minimum_support,
required_approval
}.into());
Expand All @@ -179,7 +182,7 @@ benchmarks! {

mock_core().unwrap();

let metadata = Some(vec![u8::MAX; m as usize]);
let metadata: Option<BoundedVec<u8, T::MaxMetadata>> = Some(vec![u8::MAX; m as usize].try_into().unwrap());
let minimum_support = Some(perbill_one());
let required_approval = Some(perbill_one());
let frozen_tokens = Some(true);
Expand All @@ -188,7 +191,7 @@ benchmarks! {
verify {
assert_last_event::<T>(Event::ParametersSet {
core_id: 0u32.into(),
metadata,
metadata: metadata.map(|m| m.to_vec()),
minimum_support,
required_approval,
frozen_tokens
Expand Down Expand Up @@ -237,7 +240,7 @@ benchmarks! {
remark: vec![0; z as usize]
}.into();

let metadata = vec![u8::MAX; m as usize];
let metadata: BoundedVec<u8, T::MaxMetadata> = vec![u8::MAX; m as usize].try_into().unwrap();
let caller: T::AccountId = whitelisted_caller();
let core_id: T::CoreId = 0u32.into();
let call_hash = <<T as frame_system::Config>::Hashing as Hash>::hash_of(&call.clone());
Expand All @@ -251,7 +254,6 @@ benchmarks! {
voter: caller,
votes_added: Vote::Aye(T::CoreSeedBalance::get()),
call_hash,
call,
}.into());
}

Expand Down Expand Up @@ -286,7 +288,6 @@ benchmarks! {
])).unwrap()
),
call_hash,
call,
}.into());
}

Expand All @@ -312,7 +313,6 @@ benchmarks! {
voter: caller,
votes_removed: Vote::Aye(BalanceOf::<T>::max_value().div(4u32.into())),
call_hash,
call,
}.into());
}

Expand Down
4 changes: 2 additions & 2 deletions INV4/pallet-inv4/src/fee_handling.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Config;
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
traits::{fungibles::CreditOf, Currency},
traits::{fungibles::Credit, Currency},
unsigned::TransactionValidityError,
};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -44,7 +44,7 @@ pub trait MultisigFeeHandler<T: Config> {
fn handle_creation_fee(
imbalance: FeeAssetNegativeImbalance<
<T::Currency as Currency<T::AccountId>>::NegativeImbalance,
CreditOf<T::AccountId, T::Tokens>,
Credit<T::AccountId, T::Tokens>,
>,
);
}
22 changes: 10 additions & 12 deletions INV4/pallet-inv4/src/inv4_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use frame_support::{
pallet_prelude::*,
traits::{
fungibles::{Balanced, Mutate},
tokens::{Fortitude, Precision, Preservation},
Currency, ExistenceRequirement, WithdrawReasons,
},
};
use frame_system::{ensure_signed, pallet_prelude::*};
use primitives::CoreInfo;
use sp_arithmetic::traits::{CheckedAdd, One};
use sp_runtime::Perbill;
use sp_std::{convert::TryInto, vec::Vec};

pub type CoreIndexOf<T> = <T as Config>::CoreId;

Expand All @@ -31,19 +31,14 @@ where
/// Create IP Set
pub(crate) fn inner_create_core(
origin: OriginFor<T>,
metadata: Vec<u8>,
metadata: BoundedVec<u8, T::MaxMetadata>,
minimum_support: Perbill,
required_approval: Perbill,
creation_fee_asset: FeeAsset,
) -> DispatchResult {
NextCoreId::<T>::try_mutate(|next_id| -> DispatchResult {
let creator = ensure_signed(origin)?;

let bounded_metadata: BoundedVec<u8, T::MaxMetadata> = metadata
.clone()
.try_into()
.map_err(|_| Error::<T>::MaxMetadataExceeded)?;

// Increment counter
let current_id = *next_id;
*next_id = next_id
Expand All @@ -63,7 +58,7 @@ where

let info = CoreInfo {
account: core_account.clone(),
metadata: bounded_metadata,
metadata: metadata.clone(),
minimum_support,
required_approval,
frozen_tokens: true,
Expand All @@ -83,6 +78,9 @@ where
T::KSMAssetId::get(),
&creator,
T::KSMCoreCreationFee::get(),
Precision::Exact,
Preservation::Protect,
Fortitude::Force,
)?),
});

Expand All @@ -92,7 +90,7 @@ where

Self::deposit_event(Event::CoreCreated {
core_account,
metadata,
metadata: metadata.to_vec(),
core_id: current_id,
minimum_support,
required_approval,
Expand All @@ -104,7 +102,7 @@ where

pub(crate) fn inner_set_parameters(
origin: OriginFor<T>,
metadata: Option<Vec<u8>>,
metadata: Option<BoundedVec<u8, T::MaxMetadata>>,
minimum_support: Option<Perbill>,
required_approval: Option<Perbill>,
frozen_tokens: Option<bool>,
Expand All @@ -124,7 +122,7 @@ where
}

if let Some(m) = metadata.clone() {
c.metadata = m.try_into().map_err(|_| Error::<T>::MaxMetadataExceeded)?;
c.metadata = m;
}

if let Some(f) = frozen_tokens {
Expand All @@ -135,7 +133,7 @@ where

Self::deposit_event(Event::ParametersSet {
core_id,
metadata,
metadata: metadata.map(|m| m.to_vec()),
minimum_support,
required_approval,
frozen_tokens,
Expand Down
18 changes: 9 additions & 9 deletions INV4/pallet-inv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ mod benchmarking;
#[cfg(test)]
mod tests;

//pub mod migrations;

mod dispatch;
pub mod fee_handling;
pub mod inv4_core;
mod lookup;
pub mod migrations;
pub mod multisig;
pub mod origin;
pub mod util;
Expand Down Expand Up @@ -142,8 +143,7 @@ pub mod pallet {
type KSMAssetId: Get<<<Self as Config>::Tokens as Inspect<<Self as frame_system::Config>::AccountId>>::AssetId>;

type AssetsProvider: fungibles::Inspect<Self::AccountId, Balance = BalanceOf<Self>, AssetId = Self::CoreId>
+ fungibles::Mutate<Self::AccountId, AssetId = Self::CoreId>
+ fungibles::Transfer<Self::AccountId, AssetId = Self::CoreId>;
+ fungibles::Mutate<Self::AccountId, AssetId = Self::CoreId>; // + fungibles::Transfer<Self::AccountId, AssetId = Self::CoreId>;

type Tokens: Balanced<Self::AccountId> + Inspect<Self::AccountId>;

Expand All @@ -152,6 +152,9 @@ pub mod pallet {
#[pallet::constant]
type GenesisHash: Get<<Self as frame_system::Config>::Hash>;

#[pallet::constant]
type MaxCallSize: Get<u32>;

type WeightInfo: WeightInfo;
}

Expand Down Expand Up @@ -241,7 +244,6 @@ pub mod pallet {
voter: T::AccountId,
votes_added: VoteRecord<T>,
call_hash: T::Hash,
call: CallOf<T>,
},
/// Voting weight was added towards the vote threshold, but not enough to execute the `Call`
///
Expand All @@ -253,15 +255,13 @@ pub mod pallet {
votes_added: VoteRecord<T>,
current_votes: Tally<T>,
call_hash: T::Hash,
call: CallOf<T>,
},
MultisigVoteWithdrawn {
core_id: T::CoreId,
executor_account: T::AccountId,
voter: T::AccountId,
votes_removed: VoteRecord<T>,
call_hash: T::Hash,
call: CallOf<T>,
},
/// Multisig call was executed.
///
Expand Down Expand Up @@ -329,7 +329,7 @@ pub mod pallet {
#[pallet::weight(<T as Config>::WeightInfo::create_core(metadata.len() as u32))]
pub fn create_core(
owner: OriginFor<T>,
metadata: Vec<u8>,
metadata: BoundedVec<u8, T::MaxMetadata>,
minimum_support: Perbill,
required_approval: Perbill,
creation_fee_asset: FeeAsset,
Expand Down Expand Up @@ -380,7 +380,7 @@ pub mod pallet {
pub fn operate_multisig(
caller: OriginFor<T>,
core_id: T::CoreId,
metadata: Option<Vec<u8>>,
metadata: Option<BoundedVec<u8, T::MaxMetadata>>,
fee_asset: FeeAsset,
call: Box<<T as pallet::Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
Expand Down Expand Up @@ -423,7 +423,7 @@ pub mod pallet {
))]
pub fn set_parameters(
origin: OriginFor<T>,
metadata: Option<Vec<u8>>,
metadata: Option<BoundedVec<u8, T::MaxMetadata>>,
minimum_support: Option<Perbill>,
required_approval: Option<Perbill>,
frozen_tokens: Option<bool>,
Expand Down
7 changes: 3 additions & 4 deletions INV4/pallet-inv4/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ impl<T: Config> StaticLookup for INV4Lookup<T> {
}

fn unlookup(a: Self::Target) -> Self::Source {
if let Some(core_id) = CoreByAccount::<T>::get(&a) {
MultiAddress::Index(core_id)
} else {
MultiAddress::Id(a)
match CoreByAccount::<T>::get(&a) {
Some(core_id) => MultiAddress::Index(core_id),
None => MultiAddress::Id(a),
}
}
}
Loading

0 comments on commit 82061c3

Please sign in to comment.