Skip to content

Commit

Permalink
Feature/orml currency (paritytech#193)
Browse files Browse the repository at this point in the history
* add multicurrency impl

* fix tests and runtime, add comments

* add orml currencies module

* add test for muticurrency and fix bug in repatriate_reserved
  • Loading branch information
atenjin authored Aug 16, 2020
1 parent 3bbaf22 commit bb841e4
Show file tree
Hide file tree
Showing 21 changed files with 959 additions and 55 deletions.
35 changes: 34 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn pcx() -> (AssetId, AssetInfo, AssetRestrictions) {
AssetRestriction::Deposit
| AssetRestriction::Withdraw
| AssetRestriction::DestroyWithdrawal
| AssetRestriction::DestroyFree,
| AssetRestriction::DestroyUsable,
)
}

Expand All @@ -224,7 +224,7 @@ fn xbtc() -> (AssetId, AssetInfo, AssetRestrictions) {
b"ChainX's Cross-chain Bitcoin".to_vec(),
)
.unwrap(),
AssetRestriction::DestroyFree.into(),
AssetRestriction::DestroyUsable.into(),
)
}

Expand Down
11 changes: 0 additions & 11 deletions primitives/mining/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,3 @@ impl<Balance> AssetMining<Balance> for () {

fn reward(_: AssetId, _: Balance) {}
}

/// This trait provides a simple way to get the treasury account.
pub trait TreasuryAccount<AccountId> {
fn treasury_account() -> AccountId;
}

impl<AccountId: Default> TreasuryAccount<AccountId> for () {
fn treasury_account() -> AccountId {
Default::default()
}
}
2 changes: 2 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub type Block = generic::Block<Header, OpaqueExtrinsic>;
pub type BlockId = generic::BlockId<Block>;

// Runtime type
/// Signed version of Balance
pub type Amount = i128;
/// String for Runtime
pub type Text = Vec<u8>;
pub type Desc = Vec<u8>;
Expand Down
7 changes: 7 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ pallet-balances = { path = "../frame/balances", default-features = false }
pallet-transaction-payment = { path = "../frame/transaction-payment", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { path = "../frame/transaction-payment/rpc/runtime-api", default-features = false }

# orml
orml-traits = { version = "0.1.3-dev", git = "https://github.com/open-web3-stack/open-runtime-module-library.git", rev = "d3630e35ce737aef3f9c7857e9b4bd540f37530c", default-features = false }
orml-currencies = { version = "0.1.3-dev", git = "https://github.com/open-web3-stack/open-runtime-module-library.git", rev = "d3630e35ce737aef3f9c7857e9b4bd540f37530c", default-features = false }

# ChainX primitives
chainx-primitives = { path = "../primitives", default-features = false }
xp-runtime = { path = "../primitives/runtime", default-features = false }
Expand Down Expand Up @@ -138,6 +142,9 @@ std = [
"pallet-transaction-payment/std",
"pallet-transaction-payment-rpc-runtime-api/std",

"orml-traits/std",
"orml-currencies/std",

"chainx-primitives/std",
"xp-runtime/std",
"xp-mining-staking/std",
Expand Down
35 changes: 31 additions & 4 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};

pub use chainx_primitives::{
AccountId, AccountIndex, AddrStr, AssetId, Balance, BlockNumber, ChainAddress, Hash, Index,
Moment, Name, ReferralId, Signature, Token,
AccountId, AccountIndex, AddrStr, Amount, AssetId, Balance, BlockNumber, ChainAddress, Hash,
Index, Moment, Name, ReferralId, Signature, Token,
};
pub use xp_runtime::Memo;

Expand Down Expand Up @@ -143,6 +143,10 @@ pub fn native_version() -> NativeVersion {
pub struct BaseFilter;
impl Filter<Call> for BaseFilter {
fn filter(call: &Call) -> bool {
match call {
Call::Currencies(_) => return false, // forbidden Currencies call now
_ => {}
}
use frame_support::dispatch::GetCallMetadata;
let metadata = call.get_call_metadata();
!XSystem::is_paused(metadata)
Expand Down Expand Up @@ -778,6 +782,22 @@ impl pallet_society::Trait for Runtime {
type ChallengePeriod = ChallengePeriod;
}

///////////////////////////////////////////
// orml
///////////////////////////////////////////
use orml_currencies::BasicCurrencyAdapter;
// parameter_types! {
// pub const GetNativeCurrencyId: CurrencyId = CurrencyId::Native;
// pub const GetStableCurrencyId: CurrencyId = CurrencyId::USDT;
// }

impl orml_currencies::Trait for Runtime {
type Event = Event;
type MultiCurrency = XAssets;
type NativeCurrency = BasicCurrencyAdapter<Balances, Balance, Balance, Amount, BlockNumber>;
type GetNativeCurrencyId = ChainXAssetId;
}

///////////////////////////////////////////
// Chainx pallets
///////////////////////////////////////////
Expand All @@ -796,8 +816,10 @@ impl xpallet_assets_registrar::Trait for Runtime {
}

impl xpallet_assets::Trait for Runtime {
type Currency = Balances;
type Event = Event;
type Currency = Balances;
type Amount = Amount;
type TreasuryAccount = SimpleTreasuryAccount;
type OnCreatedAccount = frame_system::CallOnCreatedAccount<Runtime>;
type OnAssetChanged = XMiningAsset;
}
Expand Down Expand Up @@ -841,7 +863,7 @@ impl xpallet_contracts::Trait for Runtime {
}

pub struct SimpleTreasuryAccount;
impl xp_mining_staking::TreasuryAccount<AccountId> for SimpleTreasuryAccount {
impl xpallet_support::traits::TreasuryAccount<AccountId> for SimpleTreasuryAccount {
fn treasury_account() -> AccountId {
TreasuryModuleId::get().into_account()
}
Expand Down Expand Up @@ -917,6 +939,11 @@ construct_runtime!(
Multisig: pallet_multisig::{Module, Call, Storage, Event<T>},
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},

// orml
// we retain Currencies Call for this call may be used in future, but we do not need this now,
// so that we filter it in BaseFilter.
Currencies: orml_currencies::{Module, Call, Event<T>},

// ChainX basics.
XSystem: xpallet_system::{Module, Call, Storage, Event<T>, Config},
XAssetsRegistrar: xpallet_assets_registrar::{Module, Call, Storage, Event<T>, Config},
Expand Down
3 changes: 3 additions & 0 deletions scripts/chainx-js/chainx_types_manual.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"Amount": "i128",
"CurrencyIdOf": "AssetId",
"CurrencyId": "AssetId",
"AssetInfoForRpc": {
"token": "String",
"token_name": "String",
Expand Down
3 changes: 3 additions & 0 deletions scripts/chainx-js/res/chainx_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@
]
},
"OrderInfo": "Order",
"Amount": "i128",
"CurrencyIdOf": "AssetId",
"CurrencyId": "AssetId",
"AssetInfoForRpc": {
"token": "String",
"tokenName": "String",
Expand Down
5 changes: 5 additions & 0 deletions xpallets/assets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ sp-runtime = { version = "2.0.0-rc5", default-features = false }
frame-support = { version = "2.0.0-rc5", default-features = false }
frame-system = { version = "2.0.0-rc5", default-features = false }

# orml
orml-traits = { version = "0.1.3-dev", git = "https://github.com/open-web3-stack/open-runtime-module-library.git", rev = "d3630e35ce737aef3f9c7857e9b4bd540f37530c", default-features = false }

# ChainX primitives
chainx-primitives = { path = "../../primitives", default-features = false }
xp-runtime = { path = "../../primitives/runtime", default-features = false }
Expand Down Expand Up @@ -53,4 +56,6 @@ std = [
"xpallet-assets-registrar/std",
"xpallet-protocol/std",
"xpallet-support/std",

"orml-traits/std",
]
Loading

0 comments on commit bb841e4

Please sign in to comment.