Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
775 changes: 424 additions & 351 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,10 @@ purge:
.PHONY: restart
restart: purge run

.PHONY: resources
resources:
target/release/parallel export-genesis-state --parachain-id 200 > ./resources/para-200-genesis
target/release/parallel export-genesis-wasm > ./resources/para-200.wasm

help:
@grep -E '^[a-zA-Z_-]+:.*?' Makefile | cut -d: -f1 | sort
25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
![image](https://user-images.githubusercontent.com/40745291/116624086-ea44a100-a90c-11eb-9393-3036a39321da.png)


[![GitHub last commit](https://img.shields.io/github/last-commit/parallel-finance/parallel)](https://github.com/parallel-finance/parallel/commits/master)
[![CI](https://github.com/parallel-finance/parallel/workflows/CI/badge.svg)](https://github.com/parallel-finance/parallel/actions)
[![Discord chat][discord-badge]][discord-url]
Expand Down Expand Up @@ -37,44 +36,36 @@ Once the development environment is set up, build the node template. This comman
cargo build --release
```

### Others available commands
### Available commands

```
build
check
purge
restart
run
test
bench
lint
fmt
help
make help
```

## Run

### Local Testnet

Polkadot (rococo-v1 branch, better use commit hash: `f3e2cbf49f179104d20b9f1b54830710ddac8be3`):
Polkadot (rococo-v1 branch)

```
cargo build --release --features real-overseer
cargo build --release

./target/release/polkadot build-spec --chain rococo-local --raw --disable-default-bootnode > rococo_local.json

./target/release/polkadot --chain ./rococo_local.json -d cumulus_relay0 --validator --alice --port 50555
./target/release/polkadot --chain ./rococo_local.json -d cumulus_relay0 --validator --alice --port 50555 --node-key 0000000000000000000000000000000000000000000000000000000000000001


./target/release/polkadot --chain ./rococo_local.json -d cumulus_relay1 --validator --bob --port 50556 \
--bootnodes /ip4/127.0.0.1/tcp/50555/p2p/<ALICE's peer id>
--bootnodes /ip4/127.0.0.1/tcp/50555/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
```

Substrate Parachain Template:

```
# this command assumes the chain spec is in a directory named polkadot that is a sibling of the working directory
./target/release/parallel -d local-test --collator --alice --ws-port 9915 --parachain-id 200 -- --chain ../polkadot/rococo_local.json \
--bootnodes /ip4/127.0.0.1/tcp/50555/p2p/<ALICE's peer id>
--bootnodes /ip4/127.0.0.1/tcp/50555/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
```

### Registering on Local Relay Chain
Expand Down
8 changes: 4 additions & 4 deletions pallets/loans/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ codec = { package = 'parity-scale-codec', version = '2.0.0', defaul
frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = 'rococo-v1', default-features = false, version = '3.0.0', optional = true }
frame-support = { git = 'https://github.com/paritytech/substrate.git', branch = 'rococo-v1', default-features = false, version = '3.0.0' }
frame-system = { git = 'https://github.com/paritytech/substrate.git', branch = 'rococo-v1', default-features = false, version = '3.0.0' }
orml-currencies = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-tokens = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-utilities = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-currencies = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-tokens = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-traits = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-utilities = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', branch = 'rococo-v1', version = '3.0.0', default-features = false }
primitives = { package = 'parallel-primitives', path = '../../primitives', default-features = false }
serde = { version = '1', features = ['derive'] }
Expand Down
4 changes: 2 additions & 2 deletions pallets/prices/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "roc
frame-support = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-oracle = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-traits = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-oracle = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
primitives = { package = "parallel-primitives", path = "../../primitives", default-features = false }

[dev-dependencies]
Expand Down
8 changes: 4 additions & 4 deletions pallets/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ targets = ['x86_64-unknown-linux-gnu']
codec = { package = 'parity-scale-codec', version = '2.0.0', default-features = false }
frame-support = { git = 'https://github.com/paritytech/substrate.git', branch = 'rococo-v1', default-features = false, version = '3.0.0' }
frame-system = { git = 'https://github.com/paritytech/substrate.git', branch = 'rococo-v1', default-features = false, version = '3.0.0' }
orml-currencies = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-tokens = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-utilities = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-currencies = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-tokens = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-traits = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-utilities = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = 'rococo-v1', default-features = false, version = '3.0.0' }
primitives = { package = 'parallel-primitives', path = '../../primitives', default-features = false }
serde = { version = '1', features = ['derive'] }
Expand Down
14 changes: 9 additions & 5 deletions runtime/parallel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ frame-system = { git = 'https://github.com/parityt
frame-system-benchmarking = { git = 'https://github.com/paritytech/substrate.git', version = '3.0.0', branch = 'rococo-v1', default-features = false, optional = true }
frame-system-rpc-runtime-api = { git = 'https://github.com/paritytech/substrate.git', version = '3.0.0', branch = 'rococo-v1', default-features = false }
hex-literal = { version = '0.3.1', optional = true }
orml-currencies = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-oracle = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-tokens = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-utilities = { git = 'https://github.com/open-web3-stack/open-runtime-module-library.git', default-features = false }
orml-currencies = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-oracle = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-tokens = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-traits = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-unknown-tokens = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-utilities = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-xcm-support = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
orml-xtokens = { git = 'https://github.com/GopherJ/open-runtime-module-library.git', default-features = false }
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', version = '3.0.0', branch = 'rococo-v1', default-features = false }
pallet-collective = { git = 'https://github.com/paritytech/substrate.git', version = '3.0.0', branch = "rococo-v1", default-features = false }
pallet-liquidate = { path = '../../pallets/liquidate', default-features = false }
Expand Down Expand Up @@ -129,4 +132,5 @@ std = [
'orml-tokens/std',
'orml-traits/std',
'orml-utilities/std',
'orml-xtokens/std',
]
142 changes: 116 additions & 26 deletions runtime/parallel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,39 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::traits::{AccountIdLookup, BlakeTwo256, Block as BlockT};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, traits,
traits::Convert,
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, SaturatedConversion,
ApplyExtrinsicResult, DispatchResult, SaturatedConversion,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

// XCM imports
use cumulus_primitives_core::ParaId;
use frame_support::log;
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot,
};
use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset, XcmHandler};
use polkadot_parachain::primitives::Sibling;
use primitives::*;
use xcm::v0::{Junction, MultiLocation, NetworkId};
use xcm::v0::{
Error as XcmError, ExecuteXcm,
Junction::{self, GeneralKey, Parachain, Parent},
MultiAsset,
MultiLocation::{self, X1, X2, X3},
NetworkId, Xcm,
};
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
EnsureXcmOrigin, FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, LocationInverter,
NativeAsset, ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SovereignSignedViaLocation,
TakeWeightCredit,
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, EnsureXcmOrigin,
FixedRateOfConcreteFungible, FixedWeightBounds, LocationInverter, ParentAsSuperuser,
ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SovereignSignedViaLocation, TakeWeightCredit,
};
use xcm_executor::{Config, XcmExecutor};
use xcm_executor::{traits::Convert as XcmConvert, Config, XcmExecutor};

// re-exports
pub use pallet_liquidate;
Expand Down Expand Up @@ -246,6 +254,84 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
}

pub struct CurrencyIdConvert;
impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
fn convert(id: CurrencyId) -> Option<MultiLocation> {
match id {
CurrencyId::KSM => Some(X1(Parent)),
CurrencyId::xKSM => Some(X3(
Parent,
Parachain {
id: ParachainInfo::parachain_id().into(),
},
GeneralKey(b"xKSM".to_vec()),
)),
// TODO: statemine
_ => None,
}
}
}

impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
fn convert(location: MultiLocation) -> Option<CurrencyId> {
match location {
X1(Parent) => Some(CurrencyId::KSM),
X3(Parent, Parachain { id }, GeneralKey(key))
if ParaId::from(id) == ParachainInfo::parachain_id() && key == b"xKSM".to_vec() =>
{
Some(CurrencyId::xKSM)
}
_ => None,
}
}
}
impl Convert<MultiAsset, Option<CurrencyId>> for CurrencyIdConvert {
fn convert(a: MultiAsset) -> Option<CurrencyId> {
if let MultiAsset::ConcreteFungible { id, amount: _ } = a {
Self::convert(id)
} else {
None
}
}
}

pub struct AccountId32Convert;
impl Convert<AccountId, [u8; 32]> for AccountId32Convert {
fn convert(account_id: AccountId) -> [u8; 32] {
account_id.into()
}
}

parameter_types! {
pub SelfLocation: MultiLocation = X2(Parent, Parachain { id: ParachainInfo::parachain_id().into() });
}

pub struct HandleXcm;
impl XcmHandler<AccountId, Call> for HandleXcm {
fn execute_xcm(origin: AccountId, xcm: Xcm<Call>) -> DispatchResult {
let xcm_origin =
ParentIsDefault::<AccountId>::reverse_ref(origin).map_err(|_| XcmError::BadOrigin);

// TODO: remove unwrap
XcmExecutor::<XcmConfig>::execute_xcm(xcm_origin.unwrap(), xcm, 1000);
Ok(())
}
}

impl orml_xtokens::Config for Runtime {
type Event = Event;
type Balance = Balance;
type CurrencyId = CurrencyId;
type CurrencyIdConvert = CurrencyIdConvert;
type AccountId32Convert = AccountId32Convert;
type SelfLocation = SelfLocation;
type XcmHandler = HandleXcm;
}

impl orml_unknown_tokens::Config for Runtime {
type Event = Event;
}

parameter_types! {
pub const GetNativeCurrencyId: CurrencyId = CurrencyId::Native;

Expand Down Expand Up @@ -435,46 +521,48 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
impl parachain_info::Config for Runtime {}

parameter_types! {
pub const RococoLocation: MultiLocation = MultiLocation::X1(Junction::Parent);
pub const RococoNetwork: NetworkId = NetworkId::Polkadot;
pub const KusamaLocation: MultiLocation = MultiLocation::X1(Junction::Parent);
pub HeikoNetwork: NetworkId = NetworkId::Named("heiko".into());
pub const KusamaNetwork: NetworkId = NetworkId::Kusama;
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Junction::Parachain {
id: ParachainInfo::parachain_id().into()
}.into();
pub const RelayChainCurrencyId: CurrencyId = CurrencyId::KSM;
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
/// when determining ownership of accounts for asset transacting and when attempting to use XCM
/// `Transact` in order to determine the dispatch Origin.
pub type LocationToAccountId = (
pub type LocationConverter = (
// The parent (Relay-chain) origin converts to the default `AccountId`.
ParentIsDefault<AccountId>,
// Sibling parachain origins convert to AccountId via the `ParaId::into`.
SiblingParachainConvertsVia<Sibling, AccountId>,
// Straight up local `AccountId32` origins just alias directly to `AccountId`.
AccountId32Aliases<RococoNetwork, AccountId>,
AccountId32Aliases<HeikoNetwork, AccountId>,
);

/// Means for transacting assets on this chain.
pub type LocalAssetTransactor = CurrencyAdapter<
pub type LocalAssetTransactor = MultiCurrencyAdapter<
// Use this currency:
Balances,
// Use this currency when it is a fungible asset matching the given location or name:
IsConcrete<RococoLocation>,
// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
Currencies,
UnknownTokens,
IsNativeConcrete<CurrencyId, CurrencyIdConvert>,
AccountId,
LocationConverter,
CurrencyId,
CurrencyIdConvert,
>;

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
/// biases the kind of local `Origin` it will become.
pub type XcmOriginToTransactDispatchOrigin = (
pub type LocalOriginConverter = (
// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
// foreign chains who want to have a local sovereign account on this chain which they control.
SovereignSignedViaLocation<LocationToAccountId, Origin>,
SovereignSignedViaLocation<LocationConverter, Origin>,
// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when
// recognised.
RelayChainAsNative<RelayChainOrigin, Origin>,
Expand All @@ -486,7 +574,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
ParentAsSuperuser<Origin>,
// Native signed account converter; this just converts an `AccountId32` origin into a normal
// `Origin::Signed` origin of the same 32-byte value.
SignedAccountId32AsNative<RococoNetwork, Origin>,
SignedAccountId32AsNative<HeikoNetwork, Origin>,
);

parameter_types! {
Expand All @@ -495,7 +583,7 @@ parameter_types! {

parameter_types! {
// 1_000_000_000_000 => 1 unit of asset for 1 unit of Weight.
// TODO: Should take the actual weight price. This is just 1_000 ROC per second of weight.
// TODO: Should take the actual weight price. This is just 1_000 KSM per second of weight.
pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::X1(Junction::Parent), 1_000);
pub AllowUnpaidFrom: Vec<MultiLocation> = vec![ MultiLocation::X1(Junction::Parent) ];
}
Expand All @@ -512,9 +600,9 @@ impl Config for XcmConfig {
type XcmSender = XcmRouter;
// How to withdraw and deposit an asset.
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = NativeAsset;
type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of ROC
type OriginConverter = LocalOriginConverter;
type IsReserve = MultiNativeAsset;
type IsTeleporter = ();
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
Expand Down Expand Up @@ -580,6 +668,8 @@ construct_runtime!(
Staking: pallet_staking::{Pallet, Call, Storage, Event<T>, Config},
Liquidate: pallet_liquidate::{Pallet, Call, Event<T>},
Prices: pallet_prices::{Pallet, Storage, Call, Event<T>},
XTokens: orml_xtokens::{Pallet, Storage, Call, Event<T>},
UnknownTokens: orml_unknown_tokens::{Pallet, Storage, Event},
}
);

Expand Down
Loading