git.delta.rocks / unique-network / refs/commits / 538e9236a6e0

difftreelog

wip checkpoint. Opal builds.

Ilja Khabarov2022-08-19parent: #83658e7.patch.diff
in: master

8 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5190,7 +5190,10 @@
  "frame-try-runtime",
  "hex-literal",
  "log",
+ "orml-tokens",
+ "orml-traits",
  "orml-vesting",
+ "orml-xtokens",
  "pallet-aura",
  "pallet-balances",
  "pallet-base-fee",
@@ -5202,6 +5205,7 @@
  "pallet-evm-contract-helpers",
  "pallet-evm-migration",
  "pallet-evm-transaction-payment",
+ "pallet-foreing-assets",
  "pallet-fungible",
  "pallet-inflation",
  "pallet-nonfungible",
@@ -5307,6 +5311,53 @@
 ]
 
 [[package]]
+name = "orml-tokens"
+version = "0.4.1-dev"
+source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "orml-traits",
+ "parity-scale-codec 3.1.5",
+ "scale-info",
+ "serde",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
+name = "orml-traits"
+version = "0.4.1-dev"
+source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"
+dependencies = [
+ "frame-support",
+ "impl-trait-for-tuples",
+ "num-traits",
+ "orml-utilities",
+ "parity-scale-codec 3.1.5",
+ "scale-info",
+ "serde",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+ "xcm",
+]
+
+[[package]]
+name = "orml-utilities"
+version = "0.4.1-dev"
+source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"
+dependencies = [
+ "frame-support",
+ "parity-scale-codec 3.1.5",
+ "scale-info",
+ "serde",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
 name = "orml-vesting"
 version = "0.4.1-dev"
 source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"
@@ -5322,6 +5373,41 @@
 ]
 
 [[package]]
+name = "orml-xcm-support"
+version = "0.4.1-dev"
+source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"
+dependencies = [
+ "frame-support",
+ "orml-traits",
+ "parity-scale-codec 3.1.5",
+ "sp-runtime",
+ "sp-std",
+ "xcm",
+ "xcm-executor",
+]
+
+[[package]]
+name = "orml-xtokens"
+version = "0.4.1-dev"
+source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"
+dependencies = [
+ "cumulus-primitives-core",
+ "frame-support",
+ "frame-system",
+ "orml-traits",
+ "orml-xcm-support",
+ "pallet-xcm",
+ "parity-scale-codec 3.1.5",
+ "scale-info",
+ "serde",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+ "xcm",
+ "xcm-executor",
+]
+
+[[package]]
 name = "os_str_bytes"
 version = "6.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -5789,6 +5875,33 @@
 ]
 
 [[package]]
+name = "pallet-foreing-assets"
+version = "0.1.0"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "hex",
+ "log",
+ "orml-tokens",
+ "pallet-balances",
+ "pallet-common",
+ "pallet-fungible",
+ "pallet-timestamp",
+ "parity-scale-codec 3.1.5",
+ "scale-info",
+ "serde",
+ "serde_json",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+ "up-data-structs",
+ "xcm",
+ "xcm-builder",
+ "xcm-executor",
+]
+
+[[package]]
 name = "pallet-fungible"
 version = "0.1.3"
 dependencies = [
@@ -12130,7 +12243,7 @@
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
 dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if 0.1.10",
  "digest 0.10.3",
  "rand 0.8.5",
  "static_assertions",
@@ -12473,7 +12586,7 @@
 
 [[package]]
 name = "up-common"
-version = "0.9.25"
+version = "0.9.27"
 dependencies = [
  "fp-rpc",
  "frame-support",
modifiedpallets/foreing-assets/Cargo.tomldiffbeforeafterboth
--- a/pallets/foreing-assets/Cargo.toml
+++ b/pallets/foreing-assets/Cargo.toml
@@ -9,26 +9,29 @@
 serde = { version = "1.0.136", optional = true }
 scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
 codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
-sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
-sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false  }
-frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
-frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
+sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false }
+sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false  }
+frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false }
+frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false }
 up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
-pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
+pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false }
 pallet-common = { default-features = false, path = '../common' }
 pallet-fungible = { default-features = false, path = '../fungible' }
-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
-xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
-xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
-orml-tokens = { git = 'https://github.com/UniqueNetwork/open-runtime-module-library', branch = 'unique-polkadot-v0.9.24', version = "0.4.1-dev", default-features = false }
+xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27", default-features = false }
+xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27", default-features = false }
+xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27", default-features = false }
+#orml-tokens = { git = 'https://github.com/UniqueNetwork/open-runtime-module-library', branch = 'unique-polkadot-v0.9.24', version = "0.4.1-dev", default-features = false }
+orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.27", version = "0.4.1-dev", default-features = false }
+#git = "https://github.com/open-web3-stack/open-runtime-module-library"
+#branch = "polkadot-v0.9.27"
 
 [dev-dependencies]
 serde_json = "1.0.68"
 hex = { version = "0.4" }
-sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
-sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
-pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
-pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
+sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
 
 [features]
 default = ["std"]
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -167,8 +167,14 @@
 		Value = u128,
 		QueryKind = ValueQuery,
 	>;
+
+	/// Foreign collection flag
+	#[pallet::storage]
+	pub type ForeignCollection<T: Config> =
+	StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = bool, QueryKind = ValueQuery>;
 }
 
+
 /// Wrapper around untyped collection handle, asserting inner collection is of fungible type.
 /// Required for interaction with Fungible collections, type safety and implementation [`solidity_interface`][`evm_coder::solidity_interface`].
 pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);
@@ -215,6 +221,16 @@
 		<PalletCommon<T>>::init_collection(owner, data, false)
 	}
 
+	/// Initializes the collection with ForeignCollection flag. Returns [CollectionId] on success, [DispatchError] otherwise.
+	pub fn init_foreign_collection(
+		owner: T::CrossAccountId,
+		data: CreateCollectionData<T::AccountId>,
+	) -> Result<CollectionId, DispatchError> {
+		let id = <PalletCommon<T>>::init_collection(owner, data, false)?;
+		<ForeignCollection<T>>::insert(id, true);
+		Ok(id)
+	}
+
 	/// Destroys a collection.
 	pub fn destroy_collection(
 		collection: FungibleHandle<T>,
@@ -230,6 +246,7 @@
 
 		PalletCommon::destroy_collection(collection.0, sender)?;
 
+		<ForeignCollection<T>>::remove(id);
 		<TotalSupply<T>>::remove(id);
 		let _ = <Balance<T>>::clear_prefix((id,), u32::MAX, None);
 		let _ = <Allowance<T>>::clear_prefix((id,), u32::MAX, None);
@@ -257,6 +274,12 @@
 			.checked_sub(amount)
 			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
 
+		// Foreign collection check
+		ensure!(
+			!<ForeignCollection<T>>::get(collection.id),
+			<CommonError<T>>::NoPermission
+		);
+
 		if collection.permissions.access() == AccessMode::AllowList {
 			collection.check_allowlist(owner)?;
 		}
@@ -288,6 +311,46 @@
 		Ok(())
 	}
 
+	/// Burns the specified amount of the token.
+	pub fn burn_foreign(
+		collection: &FungibleHandle<T>,
+		owner: &T::CrossAccountId,
+		amount: u128,
+	) -> DispatchResult {
+		let total_supply = <TotalSupply<T>>::get(collection.id)
+			.checked_sub(amount)
+			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
+
+		let balance = <Balance<T>>::get((collection.id, owner))
+			.checked_sub(amount)
+			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
+		// =========
+
+		if balance == 0 {
+			<Balance<T>>::remove((collection.id, owner));
+			<PalletStructure<T>>::unnest_if_nested(owner, collection.id, TokenId::default());
+		} else {
+			<Balance<T>>::insert((collection.id, owner), balance);
+		}
+		<TotalSupply<T>>::insert(collection.id, total_supply);
+
+		<PalletEvm<T>>::deposit_log(
+			ERC20Events::Transfer {
+				from: *owner.as_eth(),
+				to: H160::default(),
+				value: amount.into(),
+			}
+				.to_log(collection_id_to_address(collection.id)),
+		);
+		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
+			collection.id,
+			TokenId::default(),
+			owner.clone(),
+			amount,
+		));
+		Ok(())
+	}
+
 	/// Transfers the specified amount of tokens. Will check that
 	/// the transfer is allowed for the token.
 	///
@@ -373,6 +436,12 @@
 		data: BTreeMap<T::CrossAccountId, u128>,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
+		// Foreign collection check
+		ensure!(
+			!<ForeignCollection<T>>::get(collection.id),
+			<CommonError<T>>::NoPermission
+		);
+
 		if !collection.is_owner_or_admin(sender) {
 			ensure!(
 				collection.permissions.mint_mode(),
@@ -442,6 +511,68 @@
 		Ok(())
 	}
 
+	/// Minting tokens for multiple IDs.
+	/// See [`create_item_foreign`][`Pallet::create_item_foreign`] for more details.
+	pub fn create_multiple_items_foreign(
+		collection: &FungibleHandle<T>,
+		sender: &T::CrossAccountId,
+		data: BTreeMap<T::CrossAccountId, u128>,
+		nesting_budget: &dyn Budget,
+	) -> DispatchResult {
+		let total_supply = data
+			.iter()
+			.map(|(_, v)| *v)
+			.try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {
+				acc.checked_add(v)
+			})
+			.ok_or(ArithmeticError::Overflow)?;
+
+		let mut balances = data;
+		for (k, v) in balances.iter_mut() {
+			*v = <Balance<T>>::get((collection.id, &k))
+				.checked_add(*v)
+				.ok_or(ArithmeticError::Overflow)?;
+		}
+
+		for (to, _) in balances.iter() {
+			<PalletStructure<T>>::check_nesting(
+				sender.clone(),
+				to,
+				collection.id,
+				TokenId::default(),
+				nesting_budget,
+			)?;
+		}
+
+		// =========
+
+		<TotalSupply<T>>::insert(collection.id, total_supply);
+		for (user, amount) in balances {
+			<Balance<T>>::insert((collection.id, &user), amount);
+			<PalletStructure<T>>::nest_if_sent_to_token_unchecked(
+				&user,
+				collection.id,
+				TokenId::default(),
+			);
+			<PalletEvm<T>>::deposit_log(
+				ERC20Events::Transfer {
+					from: H160::default(),
+					to: *user.as_eth(),
+					value: amount.into(),
+				}
+					.to_log(collection_id_to_address(collection.id)),
+			);
+			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(
+				collection.id,
+				TokenId::default(),
+				user.clone(),
+				amount,
+			));
+		}
+
+		Ok(())
+	}
+
 	fn set_allowance_unchecked(
 		collection: &FungibleHandle<T>,
 		owner: &T::CrossAccountId,
@@ -615,6 +746,24 @@
 		)
 	}
 
+	///	Creates fungible token.
+	///
+	/// - `data`: Contains user who will become the owners of the tokens and amount
+	///   of tokens he will receive.
+	pub fn create_item_foreign(
+		collection: &FungibleHandle<T>,
+		sender: &T::CrossAccountId,
+		data: CreateItemData<T>,
+		nesting_budget: &dyn Budget,
+	) -> DispatchResult {
+		Self::create_multiple_items_foreign(
+			collection,
+			sender,
+			[(data.0, data.1)].into_iter().collect(),
+			nesting_budget,
+		)
+	}
+
 	/// Returns 10 tokens owners in no particular order
 	///
 	/// There is no direct way to get token holders in ascending order,
addedruntime/common/config/pallets/foreign_asset.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/config/pallets/foreign_asset.rs
@@ -0,0 +1,9 @@
+use crate::{Runtime, Event, Balances};
+use up_common::types::AccountId;
+
+impl pallet_foreing_assets::Config for Runtime {
+    type Event = Event;
+    type Currency = Balances;
+    type RegisterOrigin = frame_system::EnsureRoot<AccountId>;
+    type WeightInfo = ();
+}
modifiedruntime/common/config/pallets/mod.rsdiffbeforeafterboth
before · runtime/common/config/pallets/mod.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::parameter_types;18use sp_runtime::traits::AccountIdConversion;19use crate::{20	runtime_common::{21		dispatch::CollectionDispatchT,22		config::{substrate::TreasuryModuleId, ethereum::EvmCollectionHelpersAddress},23		weights::CommonWeights,24		RelayChainBlockNumberProvider,25	},26	Runtime, Event, Call, Balances,27};28use frame_support::traits::{ConstU32, ConstU64};29use up_common::{30	types::{AccountId, Balance, BlockNumber},31	constants::*,32};33use up_data_structs::{34	mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},35};3637#[cfg(feature = "rmrk")]38pub mod rmrk;3940#[cfg(feature = "scheduler")]41pub mod scheduler;4243parameter_types! {44	pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account_truncating();45	pub const CollectionCreationPrice: Balance = 2 * UNIQUE;46}4748impl pallet_common::Config for Runtime {49	type WeightInfo = pallet_common::weights::SubstrateWeight<Self>;50	type Event = Event;51	type Currency = Balances;52	type CollectionCreationPrice = CollectionCreationPrice;53	type TreasuryAccountId = TreasuryAccountId;54	type CollectionDispatch = CollectionDispatchT<Self>;5556	type EvmTokenAddressMapping = EvmTokenAddressMapping;57	type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;58	type ContractAddress = EvmCollectionHelpersAddress;59}6061impl pallet_structure::Config for Runtime {62	type Event = Event;63	type Call = Call;64	type WeightInfo = pallet_structure::weights::SubstrateWeight<Self>;65}6667impl pallet_fungible::Config for Runtime {68	type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;69}70impl pallet_refungible::Config for Runtime {71	type WeightInfo = pallet_refungible::weights::SubstrateWeight<Self>;72}73impl pallet_nonfungible::Config for Runtime {74	type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;75}7677parameter_types! {78	pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied79}8081/// Used for the pallet inflation82impl pallet_inflation::Config for Runtime {83	type Currency = Balances;84	type TreasuryAccountId = TreasuryAccountId;85	type InflationBlockInterval = InflationBlockInterval;86	type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;87}8889impl pallet_unique::Config for Runtime {90	type Event = Event;91	type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;92	type CommonWeightInfo = CommonWeights<Self>;93	type RefungibleExtensionsWeightInfo = CommonWeights<Self>;94}9596impl pallet_configuration::Config for Runtime {97	type DefaultWeightToFeeCoefficient = ConstU32<{ up_common::constants::WEIGHT_TO_FEE_COEFF }>;98	type DefaultMinGasPrice = ConstU64<{ up_common::constants::MIN_GAS_PRICE }>;99}
modifiedruntime/common/construct_runtime/mod.rsdiffbeforeafterboth
--- a/runtime/common/construct_runtime/mod.rs
+++ b/runtime/common/construct_runtime/mod.rs
@@ -42,6 +42,8 @@
                 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,
                 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,
                 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,
+                XTokens: orml_xtokens = 38,
+                Tokens: orml_tokens = 39,
                 // Vesting: pallet_vesting::{Pallet, Call, Config<T>, Storage, Event<T>} = 37,
                 // Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>} = 38,
 
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -120,13 +120,18 @@
     'up-sponsorship/std',
 
     "orml-vesting/std",
+    "orml-tokens/std",
+    "orml-xtokens/std",
+    "orml-traits/std",
+    "pallet-foreing-assets/std"
 ]
 limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing']
-opal-runtime = ['refungible', 'scheduler', 'rmrk']
+opal-runtime = ['refungible', 'scheduler', 'rmrk', 'foreign-asset']
 
 refungible = []
 scheduler = []
 rmrk = []
+foreign-asset = []
 
 ################################################################################
 # Substrate Dependencies
@@ -399,6 +404,24 @@
 version = "0.4.1-dev"
 default-features = false
 
+[dependencies.orml-xtokens]
+git = "https://github.com/open-web3-stack/open-runtime-module-library"
+branch = "polkadot-v0.9.27"
+version = "0.4.1-dev"
+default-features = false
+
+[dependencies.orml-tokens]
+git = "https://github.com/open-web3-stack/open-runtime-module-library"
+branch = "polkadot-v0.9.27"
+version = "0.4.1-dev"
+default-features = false
+
+[dependencies.orml-traits]
+git = "https://github.com/open-web3-stack/open-runtime-module-library"
+branch = "polkadot-v0.9.27"
+version = "0.4.1-dev"
+default-features = false
+
 ################################################################################
 # local dependencies
 
@@ -437,6 +460,7 @@
 fp-self-contained = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.27" }
 evm-coder = { default-features = false, path = '../../crates/evm-coder' }
 up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = 'polkadot-v0.9.27' }
+pallet-foreing-assets = { default-features = false, path = "../../pallets/foreing-assets" }
 
 ################################################################################
 # Build Dependencies
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -35,6 +35,8 @@
 #[path = "../../common/mod.rs"]
 mod runtime_common;
 
+pub mod xcm_config;
+
 pub use runtime_common::*;
 
 pub const RUNTIME_NAME: &str = "opal";