Skip to content

Commit

Permalink
wip: safeguard
Browse files Browse the repository at this point in the history
  • Loading branch information
mustermeiszer committed Nov 8, 2023
1 parent 47ce8d1 commit 2b894fb
Show file tree
Hide file tree
Showing 80 changed files with 8,007 additions and 4,520 deletions.
9,658 changes: 6,468 additions & 3,190 deletions Cargo.lock

Large diffs are not rendered by default.

1,136 changes: 665 additions & 471 deletions Cargo.toml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions libs/mocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", default-features = false, version = "3.0.0", features = ["derive"] }
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" }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.1.0" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

cfg-primitives = { path = "../primitives", default-features = false }
cfg-traits = { path = "../traits", default-features = false }
cfg-types = { path = "../types", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.43" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v1.1.0" }

mock-builder = { workspace = true }

Expand Down
24 changes: 12 additions & 12 deletions libs/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ scale-info = { version = "2.3.0", default-features = false, features = ["derive"
serde = { version = "1.0.119" }

# substrate primitives dependencies
sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-consensus-aura = { 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" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-runtime = { 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" }
sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

# substrate frame dependencies
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" }
pallet-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
pallet-collective = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

# cumulus primitives dependencies
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.43" }
cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

# XCM primitives dependencies
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.43" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.43" }
xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

[features]
default = ["std"]
Expand Down
34 changes: 14 additions & 20 deletions libs/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,8 @@ pub mod liquidity_pools {

impl sp_core::Get<[u8; 12]> for GeneralCurrencyPrefix {
fn get() -> [u8; 12] {
let hash: [u8; 16] = frame_support::sp_io::hashing::blake2_128(
&crate::constants::GENERAL_CURRENCY_INDEX_PREFIX,
);
let hash: [u8; 16] =
sp_io::hashing::blake2_128(&crate::constants::GENERAL_CURRENCY_INDEX_PREFIX);
let (trimmed, _) = hash.split_at(12);

trimmed
Expand All @@ -343,36 +342,35 @@ pub mod liquidity_pools {
pub mod xcm {
use codec::{Compact, Encode};
use sp_io::hashing::blake2_256;
use sp_std::{borrow::Borrow, marker::PhantomData, vec::Vec};
use sp_std::{marker::PhantomData, vec::Vec};
use xcm::prelude::{
AccountId32, AccountKey20, Here, MultiLocation, PalletInstance, Parachain, X1,
};
use xcm_executor::traits::Convert;
use xcm_executor::traits::ConvertLocation;

/// NOTE: Copied from <https://github.com/moonbeam-foundation/polkadot/blob/d83bb6cc7d7c93ead2fd3cafce0e268fd3f6b9bc/xcm/xcm-builder/src/location_conversion.rs#L25C1-L68C2>
///
/// temporary struct that mimics the behavior of the upstream type that we
/// will move to once we update this repository to Polkadot 0.9.43+.
pub struct HashedDescriptionDescribeFamilyAllTerminal<AccountId>(PhantomData<AccountId>);
impl<AccountId: From<[u8; 32]> + Clone> HashedDescriptionDescribeFamilyAllTerminal<AccountId> {
fn describe_location_suffix(l: &MultiLocation) -> Result<Vec<u8>, ()> {
fn describe_location_suffix(l: &MultiLocation) -> Option<Vec<u8>> {
match (l.parents, &l.interior) {
(0, Here) => Ok(Vec::new()),
(0, Here) => Some(Vec::new()),
(0, X1(PalletInstance(i))) => {
Ok((b"Pallet", Compact::<u32>::from(*i as u32)).encode())
Some((b"Pallet", Compact::<u32>::from(*i as u32)).encode())
}
(0, X1(AccountId32 { id, .. })) => Ok((b"AccountId32", id).encode()),
(0, X1(AccountKey20 { key, .. })) => Ok((b"AccountKey20", key).encode()),
_ => Err(()),
(0, X1(AccountId32 { id, .. })) => Some((b"AccountId32", id).encode()),
(0, X1(AccountKey20 { key, .. })) => Some((b"AccountKey20", key).encode()),
_ => None,
}
}
}

impl<AccountId: From<[u8; 32]> + Clone> Convert<MultiLocation, AccountId>
impl<AccountId: From<[u8; 32]> + Clone> ConvertLocation<AccountId>
for HashedDescriptionDescribeFamilyAllTerminal<AccountId>
{
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
let l = location.borrow();
fn convert_location(l: &MultiLocation) -> Option<AccountId> {
let to_hash = match (l.parents, l.interior.first()) {
(0, Some(Parachain(index))) => {
let tail = l.interior.split_first().0;
Expand All @@ -389,13 +387,9 @@ pub mod xcm {
let interior = Self::describe_location_suffix(&tail)?;
(b"ParentChain", interior).encode()
}
_ => return Err(()),
_ => return None,
};
Ok(blake2_256(&to_hash).into())
}

fn reverse_ref(_: impl Borrow<AccountId>) -> Result<MultiLocation, ()> {
Err(())
Some(blake2_256(&to_hash).into())
}
}

Expand Down
4 changes: 2 additions & 2 deletions libs/proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"], default-features = false }
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.43" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = true, tag = "polkadot-v1.1.0" }

[features]
default = ["std"]
Expand Down
10 changes: 5 additions & 5 deletions libs/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.119", default-features = false }

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" }
sp-runtime = { 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/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

# Optional dependencies
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.43" }
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, optional = true, tag = "polkadot-v1.1.0" }

[features]
default = ["std"]
Expand Down
8 changes: 4 additions & 4 deletions libs/traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
cfg-primitives = { path = "../primitives", default-features = false }
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"], default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
impl-trait-for-tuples = "0.2.1"
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-runtime = { 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" }
sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

[dev-dependencies]
cfg-mocks = { path = "../mocks" }
Expand Down
5 changes: 3 additions & 2 deletions libs/traits/src/interest.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use cfg_primitives::SECONDS_PER_YEAR;
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{dispatch::DispatchResult, scale_info::TypeInfo, Parameter, RuntimeDebug};
use frame_support::{dispatch::DispatchResult, Parameter};
use scale_info::TypeInfo;
use sp_arithmetic::{
traits::{EnsureAdd, EnsureDiv, EnsureSub},
ArithmeticError, FixedPointNumber,
};
use sp_runtime::{
traits::{Get, Member, One, Zero},
DispatchError,
DispatchError, RuntimeDebug,
};

use crate::Seconds;
Expand Down
10 changes: 5 additions & 5 deletions libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
// Ensure we're `no_std` when compiling for WebAssembly.
#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Codec, Decode, Encode, MaxEncodedLen};
use frame_support::{
dispatch::{Codec, DispatchResult, DispatchResultWithPostInfo},
scale_info::TypeInfo,
dispatch::{DispatchResult, DispatchResultWithPostInfo},
traits::UnixTime,
Parameter, RuntimeDebug,
Parameter,
};
use impl_trait_for_tuples::impl_for_tuples;
use scale_info::TypeInfo;
use sp_runtime::{
traits::{
AtLeast32BitUnsigned, Bounded, Get, MaybeDisplay, MaybeSerialize,
MaybeSerializeDeserialize, Member, Zero,
},
DispatchError,
DispatchError, RuntimeDebug,
};
use sp_std::{fmt::Debug, hash::Hash, str::FromStr, vec::Vec};

Expand Down
16 changes: 8 additions & 8 deletions libs/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ scale-info = { version = "2.3.0", default-features = false, features = ["derive"
serde = { version = "1.0.119" }

# substrate dependencies
frame-support = { 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-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43" }
sp-runtime = { 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/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.43" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.43" }
orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v1.1.0" }
xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-v1.1.0" }

# local dependencies
cfg-primitives = { path = "../primitives", default-features = false }
cfg-traits = { path = "../traits", default-features = false }
cfg-utils = { path = "../utils", default-features = false }

[dev-dependencies]
frame-support = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.43" }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-features = true, tag = "polkadot-v1.1.0" }
hex = { version = "0.4.3", default_features = false }

[features]
Expand Down
6 changes: 4 additions & 2 deletions libs/types/src/domain_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
use cfg_traits::liquidity_pools::Codec;
use cfg_utils::{decode_be_bytes, vec_to_fixed_array};
use codec::{Decode, Encode, Input, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;
use sp_runtime::traits::{AccountIdConversion, Convert};
use sp_runtime::{
traits::{AccountIdConversion, Convert},
RuntimeDebug,
};
use sp_std::{vec, vec::Vec};

use crate::EVMChainId;
Expand Down
6 changes: 4 additions & 2 deletions libs/types/src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

use cfg_traits::Seconds;
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;
use sp_runtime::traits::{One, Saturating};
use sp_runtime::{
traits::{One, Saturating},
RuntimeDebug,
};

#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct EpochState<EpochId> {
Expand Down
2 changes: 1 addition & 1 deletion libs/types/src/fee_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
// GNU General Public License for more details.

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::RuntimeDebug;
use sp_std::cmp::PartialEq;

/// Different fees keys available.
Expand Down
5 changes: 2 additions & 3 deletions libs/types/src/investments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

use cfg_primitives::OrderId;
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{dispatch::fmt::Debug, RuntimeDebug};
use scale_info::TypeInfo;
use sp_arithmetic::traits::{EnsureAdd, EnsureSub};
use sp_runtime::{traits::Zero, DispatchError, DispatchResult};
use sp_std::cmp::PartialEq;
use sp_runtime::{traits::Zero, DispatchError, DispatchResult, RuntimeDebug};
use sp_std::{cmp::PartialEq, fmt::Debug};

use crate::orders::Order;

Expand Down
14 changes: 13 additions & 1 deletion libs/types/src/oracles.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// Copyright 2021 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.

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::RuntimeDebug;

/// [ISIN](https://en.wikipedia.org/wiki/International_Securities_Identification_Number) format.
pub type Isin = [u8; 12];
Expand Down
3 changes: 1 addition & 2 deletions libs/types/src/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
// GNU General Public License for more details.

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::{traits::Zero, Perquintill};
use sp_runtime::{traits::Zero, Perquintill, RuntimeDebug};
use sp_std::{
cmp::{Ord, PartialEq, PartialOrd},
vec::Vec,
Expand Down
Loading

0 comments on commit 2b894fb

Please sign in to comment.