difftreelog
wip checkpoint. Opal builds.
in: master
8 files changed
Cargo.lockdiffbeforeafterboth5190 "frame-try-runtime",5190 "frame-try-runtime",5191 "hex-literal",5191 "hex-literal",5192 "log",5192 "log",5193 "orml-tokens",5194 "orml-traits",5193 "orml-vesting",5195 "orml-vesting",5196 "orml-xtokens",5194 "pallet-aura",5197 "pallet-aura",5195 "pallet-balances",5198 "pallet-balances",5196 "pallet-base-fee",5199 "pallet-base-fee",5202 "pallet-evm-contract-helpers",5205 "pallet-evm-contract-helpers",5203 "pallet-evm-migration",5206 "pallet-evm-migration",5204 "pallet-evm-transaction-payment",5207 "pallet-evm-transaction-payment",5208 "pallet-foreing-assets",5205 "pallet-fungible",5209 "pallet-fungible",5206 "pallet-inflation",5210 "pallet-inflation",5207 "pallet-nonfungible",5211 "pallet-nonfungible",5306 "num-traits",5310 "num-traits",5307]5311]53125313[[package]]5314name = "orml-tokens"5315version = "0.4.1-dev"5316source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"5317dependencies = [5318 "frame-support",5319 "frame-system",5320 "orml-traits",5321 "parity-scale-codec 3.1.5",5322 "scale-info",5323 "serde",5324 "sp-runtime",5325 "sp-std",5326]53275328[[package]]5329name = "orml-traits"5330version = "0.4.1-dev"5331source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"5332dependencies = [5333 "frame-support",5334 "impl-trait-for-tuples",5335 "num-traits",5336 "orml-utilities",5337 "parity-scale-codec 3.1.5",5338 "scale-info",5339 "serde",5340 "sp-io",5341 "sp-runtime",5342 "sp-std",5343 "xcm",5344]53455346[[package]]5347name = "orml-utilities"5348version = "0.4.1-dev"5349source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"5350dependencies = [5351 "frame-support",5352 "parity-scale-codec 3.1.5",5353 "scale-info",5354 "serde",5355 "sp-io",5356 "sp-runtime",5357 "sp-std",5358]530853595309[[package]]5360[[package]]5310name = "orml-vesting"5361name = "orml-vesting"5321 "sp-std",5372 "sp-std",5322]5373]53745375[[package]]5376name = "orml-xcm-support"5377version = "0.4.1-dev"5378source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"5379dependencies = [5380 "frame-support",5381 "orml-traits",5382 "parity-scale-codec 3.1.5",5383 "sp-runtime",5384 "sp-std",5385 "xcm",5386 "xcm-executor",5387]53885389[[package]]5390name = "orml-xtokens"5391version = "0.4.1-dev"5392source = "git+https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.27#377213f750755cc48e80a3131eaae63b5eda8362"5393dependencies = [5394 "cumulus-primitives-core",5395 "frame-support",5396 "frame-system",5397 "orml-traits",5398 "orml-xcm-support",5399 "pallet-xcm",5400 "parity-scale-codec 3.1.5",5401 "scale-info",5402 "serde",5403 "sp-io",5404 "sp-runtime",5405 "sp-std",5406 "xcm",5407 "xcm-executor",5408]532354095324[[package]]5410[[package]]5325name = "os_str_bytes"5411name = "os_str_bytes"5788 "up-sponsorship",5874 "up-sponsorship",5789]5875]58765877[[package]]5878name = "pallet-foreing-assets"5879version = "0.1.0"5880dependencies = [5881 "frame-support",5882 "frame-system",5883 "hex",5884 "log",5885 "orml-tokens",5886 "pallet-balances",5887 "pallet-common",5888 "pallet-fungible",5889 "pallet-timestamp",5890 "parity-scale-codec 3.1.5",5891 "scale-info",5892 "serde",5893 "serde_json",5894 "sp-core",5895 "sp-io",5896 "sp-runtime",5897 "sp-std",5898 "up-data-structs",5899 "xcm",5900 "xcm-builder",5901 "xcm-executor",5902]579059035791[[package]]5904[[package]]5792name = "pallet-fungible"5905name = "pallet-fungible"12130source = "registry+https://github.com/rust-lang/crates.io-index"12243source = "registry+https://github.com/rust-lang/crates.io-index"12131checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"12244checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"12132dependencies = [12245dependencies = [12133 "cfg-if 1.0.0",12246 "cfg-if 0.1.10",12134 "digest 0.10.3",12247 "digest 0.10.3",12135 "rand 0.8.5",12248 "rand 0.8.5",12136 "static_assertions",12249 "static_assertions",124731258612474[[package]]12587[[package]]12475name = "up-common"12588name = "up-common"12476version = "0.9.25"12589version = "0.9.27"12477dependencies = [12590dependencies = [12478 "fp-rpc",12591 "fp-rpc",12479 "frame-support",12592 "frame-support",pallets/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"]
pallets/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,
runtime/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 = ();
+}
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -40,6 +40,9 @@
#[cfg(feature = "scheduler")]
pub mod scheduler;
+#[cfg(feature = "foreign-asset")]
+pub mod foreign_asset;
+
parameter_types! {
pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account_truncating();
pub const CollectionCreationPrice: Balance = 2 * UNIQUE;
runtime/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,
runtime/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
runtime/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";