diff --git a/Cargo.lock b/Cargo.lock index 377bd0b7fb..666d4cd0df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -200,6 +200,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal 0.3.4", + "log", "orml-asset-registry", "orml-tokens", "orml-traits", @@ -1080,6 +1081,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal 0.3.4", + "log", "orml-asset-registry", "orml-tokens", "orml-traits", @@ -7676,7 +7678,6 @@ dependencies = [ "pallet-timestamp", "parachain-info", "parity-scale-codec 3.4.0", - "polkadot-parachain", "rand 0.8.5", "rev_slice", "scale-info", diff --git a/pallets/pool-registry/src/mock.rs b/pallets/pool-registry/src/mock.rs index a6397e61cf..72cad17dd0 100644 --- a/pallets/pool-registry/src/mock.rs +++ b/pallets/pool-registry/src/mock.rs @@ -152,7 +152,6 @@ impl pallet_pool_system::Config for Test { type NAV = FakeNav; type PalletId = PoolPalletId; type PalletIndex = PoolPalletIndex; - type ParachainId = ParachainInfo; type Permission = PermissionsMock; type PoolCreateOrigin = EnsureSigned; type PoolCurrency = PoolCurrency; diff --git a/pallets/pool-system/Cargo.toml b/pallets/pool-system/Cargo.toml index 4f7c9a8771..b85418e45a 100644 --- a/pallets/pool-system/Cargo.toml +++ b/pallets/pool-system/Cargo.toml @@ -29,17 +29,16 @@ sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-featu sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" } sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" } -orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.37" } pallet-permissions = { path = "../../pallets/permissions", default-features = false } -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.37" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.37" } # Benchmarking dependencies - optional frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.37" } +orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, optional = true, branch = "polkadot-v0.9.37" } pallet-investments = { path = "../../pallets/investments", default-features = false, optional = true } [dev-dependencies] cfg-test-utils = { path = "../../libs/test-utils", default-features = true } +orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.37" } orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = true, branch = "polkadot-v0.9.37" } pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.37" } pallet-investments = { path = "../../pallets/investments", default-features = true } @@ -48,6 +47,7 @@ parachain-info = { git = "https://github.com/paritytech/cumulus", default-featur rand = "0.8.5" sp-core = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.37" } sp-io = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.37" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.37" } [features] default = ["std"] @@ -63,7 +63,6 @@ runtime-benchmarks = [ "pallet-investments/runtime-benchmarks", "pallet-permissions/runtime-benchmarks", "xcm/runtime-benchmarks", - "polkadot-parachain/runtime-benchmarks", "orml-asset-registry/runtime-benchmarks", ] std = [ @@ -81,9 +80,6 @@ std = [ "cfg-types/std", "cfg-primitives/std", "pallet-permissions/std", - "polkadot-parachain/std", - "orml-asset-registry/std", - "xcm/std", "frame-benchmarking/std", "serde/std", ] @@ -94,7 +90,6 @@ try-runtime = [ "lazy_static/spin_no_std", "cfg-types/try-runtime", "frame-system/try-runtime", - "orml-asset-registry/try-runtime", "pallet-permissions/try-runtime", "pallet-timestamp/try-runtime", ] diff --git a/pallets/pool-system/src/impls.rs b/pallets/pool-system/src/impls.rs index 91d8bc1cee..c6cace8363 100644 --- a/pallets/pool-system/src/impls.rs +++ b/pallets/pool-system/src/impls.rs @@ -149,15 +149,8 @@ impl PoolMutate for Pallet { None => return Err(Error::::MetadataForCurrencyNotFound.into()), }; - let parachain_id = T::ParachainId::get(); - - let metadata = tranche.create_asset_metadata( - decimals, - parachain_id, - T::PalletIndex::get(), - token_name.to_vec(), - token_symbol.to_vec(), - ); + let metadata = + tranche.create_asset_metadata(decimals, token_name.to_vec(), token_symbol.to_vec()); T::AssetRegistry::register_asset(Some(tranche.currency.into()), metadata) .map_err(|_| Error::::FailedToRegisterTrancheMetadata)?; diff --git a/pallets/pool-system/src/lib.rs b/pallets/pool-system/src/lib.rs index 198db72c59..acd3729cb2 100644 --- a/pallets/pool-system/src/lib.rs +++ b/pallets/pool-system/src/lib.rs @@ -40,7 +40,6 @@ use orml_traits::{ Change, }; pub use pallet::*; -use polkadot_parachain::primitives::Id as ParachainId; use pool_types::{ PoolChanges, PoolDepositInfo, PoolDetails, PoolEssence, PoolLocator, ScheduledUpdateDetails, }; @@ -275,9 +274,6 @@ pub mod pallet { CustomMetadata = CustomMetadata, >; - #[pallet::constant] - type ParachainId: Get; - type Currency: ReservableCurrency; type Tokens: Mutate diff --git a/pallets/pool-system/src/mock.rs b/pallets/pool-system/src/mock.rs index cc22570a71..347946216d 100644 --- a/pallets/pool-system/src/mock.rs +++ b/pallets/pool-system/src/mock.rs @@ -322,7 +322,6 @@ impl Config for Runtime { type NAV = FakeNav; type PalletId = PoolPalletId; type PalletIndex = PoolPalletIndex; - type ParachainId = ParachainInfo; type Permission = Permissions; type PoolCreateOrigin = EnsureSigned; type PoolCurrency = PoolCurrency; diff --git a/pallets/pool-system/src/tests/mod.rs b/pallets/pool-system/src/tests/mod.rs index 9d4b15e9ef..cdc705e875 100644 --- a/pallets/pool-system/src/tests/mod.rs +++ b/pallets/pool-system/src/tests/mod.rs @@ -20,15 +20,10 @@ use cfg_types::{ use frame_support::{assert_err, assert_noop, assert_ok}; use orml_traits::asset_registry::{AssetMetadata, Inspect}; use rand::Rng; -use sp_core::{storage::StateVersion, Encode}; +use sp_core::storage::StateVersion; use sp_runtime::{ - traits::{ConstU32, One, Zero}, - FixedPointNumber, Perquintill, TokenError, WeakBoundedVec, -}; -use xcm::{ - latest::MultiLocation, - prelude::{GeneralKey, PalletInstance, Parachain, X3}, - VersionedMultiLocation, + traits::{One, Zero}, + FixedPointNumber, Perquintill, TokenError, }; use crate::{ @@ -2311,8 +2306,6 @@ fn create_tranche_token_metadata() { let pool = Pool::::get(3).unwrap(); let tranche_currency = pool.tranches.tranches[0].currency; - let tranche_id = - WeakBoundedVec::>::force_from(tranche_currency.encode(), None); assert_eq!( ::AssetRegistry::metadata(&tranche_currency.into()).unwrap(), @@ -2321,14 +2314,7 @@ fn create_tranche_token_metadata() { name: "SuperToken".into(), symbol: "ST".into(), existential_deposit: 0, - location: Some(VersionedMultiLocation::V1(MultiLocation { - parents: 1, - interior: X3( - Parachain(MockParachainId::get()), - PalletInstance(PoolPalletIndex::get()), - GeneralKey(tranche_id) - ), - })), + location: None, additional: CustomMetadata { mintable: false, permissioned: true, diff --git a/pallets/pool-system/src/tranches.rs b/pallets/pool-system/src/tranches.rs index 5b8742bbbd..f25a1db197 100644 --- a/pallets/pool-system/src/tranches.rs +++ b/pallets/pool-system/src/tranches.rs @@ -25,26 +25,20 @@ use frame_support::{ dispatch::DispatchResult, ensure, sp_runtime::ArithmeticError, - traits::{fungibles::Inspect, Get}, + traits::{fungibles::Inspect, Get, Len}, Blake2_128, BoundedVec, Parameter, RuntimeDebug, StorageHasher, }; use orml_traits::asset_registry::AssetMetadata; -use polkadot_parachain::primitives::Id as ParachainId; use rev_slice::{RevSlice, SliceExt}; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; use sp_arithmetic::traits::{checked_pow, BaseArithmetic, Unsigned}; use sp_runtime::{ - traits::{ConstU32, Member, One, Zero}, - DispatchError, FixedPointNumber, FixedPointOperand, Perquintill, WeakBoundedVec, + traits::{Member, One, Zero}, + DispatchError, FixedPointNumber, FixedPointOperand, Perquintill, }; use sp_std::{marker::PhantomData, ops::Deref, vec::Vec}; -use xcm::{ - latest::MultiLocation, - prelude::{GeneralKey, PalletInstance, Parachain, X3}, - VersionedMultiLocation, -}; /// Type that indicates the seniority of a tranche pub type Seniority = u32; @@ -236,8 +230,6 @@ where pub fn create_asset_metadata( &self, decimals: u32, - parachain_id: ParachainId, - pallet_index: u8, token_name: Vec, token_symbol: Vec, ) -> AssetMetadata @@ -246,22 +238,12 @@ where Currency: Encode, CustomMetadata: Parameter + Member + TypeInfo, { - let tranche_id = - WeakBoundedVec::>::force_from(self.currency.encode(), None); - AssetMetadata { decimals, name: token_name, symbol: token_symbol, existential_deposit: Zero::zero(), - location: Some(VersionedMultiLocation::V1(MultiLocation { - parents: 1, - interior: X3( - Parachain(parachain_id.into()), - PalletInstance(pallet_index), - GeneralKey(tranche_id), - ), - })), + location: None, additional: CustomMetadata { mintable: false, permissioned: true, @@ -1854,27 +1836,13 @@ pub mod test { let decimals: u32 = 10; let name: Vec = "Glimmer".into(); let symbol: Vec = "GLMR".into(); - let asset_metadata = tranche.create_asset_metadata( - decimals, - // fake parachain id - ParachainId::from(42), - // fake pallet index - 42u8, - name, - symbol, - ); + let asset_metadata = tranche.create_asset_metadata(decimals, name, symbol); assert_eq!(asset_metadata.existential_deposit, 0); assert_eq!(asset_metadata.name[..], [71, 108, 105, 109, 109, 101, 114]); assert_eq!(asset_metadata.symbol[..], [71, 76, 77, 82]); assert_eq!(asset_metadata.decimals, decimals); - assert!(match asset_metadata.location { - Some(VersionedMultiLocation::V1(xcm::v1::MultiLocation { - parents: 1, - interior: X3(Parachain(42), PalletInstance(42), GeneralKey(_)), - })) => true, - _ => false, - }) + assert_eq!(asset_metadata.location, None); } } diff --git a/runtime/altair/Cargo.toml b/runtime/altair/Cargo.toml index 771d98406b..a45959762c 100644 --- a/runtime/altair/Cargo.toml +++ b/runtime/altair/Cargo.toml @@ -12,6 +12,7 @@ repository = "https://github.com/centrifuge/centrifuge-chain" # third-party dependencies codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] } hex-literal = { version = "0.3.4", optional = true } +log = { version = "0.4.17", default-features = false } scale-info = { version = "2.3.0", default-features = false, features = ["derive"] } serde = { version = "1.0.119", optional = true } static_assertions = "1.1.0" diff --git a/runtime/altair/src/lib.rs b/runtime/altair/src/lib.rs index 271be9ba7c..9899535b55 100644 --- a/runtime/altair/src/lib.rs +++ b/runtime/altair/src/lib.rs @@ -1260,7 +1260,6 @@ impl pallet_pool_system::Config for Runtime { type NAV = Loans; type PalletId = PoolPalletId; type PalletIndex = PoolPalletIndex; - type ParachainId = ParachainInfo; type Permission = Permissions; type PoolCreateOrigin = EnsureRoot; type PoolCurrency = PoolCurrency; @@ -1560,7 +1559,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - crate::migrations::UpgradeAltair1027, + migrations::UpgradeAltair1027, >; #[cfg(not(feature = "disable-runtime-api"))] diff --git a/runtime/altair/src/migrations.rs b/runtime/altair/src/migrations.rs index 4110b4eb25..0ac2da10e6 100644 --- a/runtime/altair/src/migrations.rs +++ b/runtime/altair/src/migrations.rs @@ -10,7 +10,10 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -use crate::{AccountId, BlockRewards, ExistentialDeposit, NativeToken, Runtime}; +use cfg_types::tokens::CurrencyId; +use frame_support::{traits::OnRuntimeUpgrade, weights::Weight}; + +use crate::{AccountId, BlockRewards, ExistentialDeposit, NativeToken, OrmlAssetRegistry, Runtime}; pub type UpgradeAltair1027 = ( pallet_loans_ref::migrations::v1::Migration, @@ -26,6 +29,7 @@ pub type UpgradeAltair1027 = ( NativeToken, ExistentialDeposit, >, + asset_registry::TrancheLocationMigration, ); mod init_block_rewards { @@ -145,3 +149,61 @@ mod session_key_migration { } } } + +mod asset_registry { + use super::*; + + /// This migration sets the AssetMetadata.location of all the Tranche tokens + /// registered in the AssetRegistry to `None`. + pub struct TrancheLocationMigration; + + impl OnRuntimeUpgrade for TrancheLocationMigration { + fn on_runtime_upgrade() -> Weight { + for (asset_id, metadata) in orml_asset_registry::Metadata::::iter() { + if matches!(asset_id, CurrencyId::Tranche(_, _)) && metadata.location.is_some() { + match OrmlAssetRegistry::do_update_asset( + asset_id, + // decimals + None, + // name + None, + // symbol + None, + // existential_deposit + None, + // location: we do set it to `None` + Some(None), + // additional + None, + ) { + Err(e) => log::error!("TrancheLocationMigration: Failed to update asset with underlying error: {:?}", e), + _ => continue, + } + } + } + + // todo(nuno): not sure how to build this properly, + // setting it to a conservative value for now. + Weight::from_ref_time(200_000_000) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + Ok(Default::default()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: sp_std::vec::Vec) -> Result<(), &'static str> { + for (asset_id, metadata) in orml_asset_registry::Metadata::::iter() { + if matches!(asset_id, CurrencyId::Tranche(_, _)) { + frame_support::ensure!( + metadata.location.is_none(), + "A tranche token's location is not None" + ) + } + } + + Ok(()) + } + } +} diff --git a/runtime/centrifuge/Cargo.toml b/runtime/centrifuge/Cargo.toml index 4ecaac9b63..7f3965a7ba 100644 --- a/runtime/centrifuge/Cargo.toml +++ b/runtime/centrifuge/Cargo.toml @@ -12,6 +12,7 @@ repository = "https://github.com/centrifuge/centrifuge-chain" # third-party dependencies codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] } hex-literal = { version = "0.3.4", optional = true } +log = { version = "0.4.17", default-features = false } scale-info = { version = "2.3.0", default-features = false, features = ["derive"] } serde = { version = "1.0.119", optional = true } static_assertions = "1.1.0" diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index fba90c7990..ef19d4e7a0 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -1379,7 +1379,6 @@ impl pallet_pool_system::Config for Runtime { type NAV = Loans; type PalletId = PoolPalletId; type PalletIndex = PoolPalletIndex; - type ParachainId = ParachainInfo; type Permission = Permissions; type PoolCreateOrigin = EnsureRoot; type PoolCurrency = PoolCurrency; @@ -1734,7 +1733,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - crate::migrations::UpgradeCentrifuge1019, + migrations::UpgradeCentrifuge1019, >; #[cfg(not(feature = "disable-runtime-api"))] diff --git a/runtime/centrifuge/src/migrations.rs b/runtime/centrifuge/src/migrations.rs index 1052d4f33e..c73be82e81 100644 --- a/runtime/centrifuge/src/migrations.rs +++ b/runtime/centrifuge/src/migrations.rs @@ -10,7 +10,10 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -use crate::{AccountId, BlockRewards, ExistentialDeposit, NativeToken, Runtime}; +use cfg_types::tokens::CurrencyId; +use frame_support::{traits::OnRuntimeUpgrade, weights::Weight}; + +use crate::{AccountId, BlockRewards, ExistentialDeposit, NativeToken, OrmlAssetRegistry, Runtime}; pub type UpgradeCentrifuge1019 = ( pallet_loans_ref::migrations::v1::Migration, @@ -26,6 +29,7 @@ pub type UpgradeCentrifuge1019 = ( NativeToken, ExistentialDeposit, >, + asset_registry::TrancheLocationMigration, ); mod init_block_rewards { @@ -71,7 +75,7 @@ mod session_key_migration { type QueuedKeys = StorageValue, Vec<(AccountId, OldSessionKeys)>, ValueQuery>; - impl frame_support::traits::OnRuntimeUpgrade for ExtendSessionKeys { + impl OnRuntimeUpgrade for ExtendSessionKeys { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { let queued: Vec<(AccountId, OldSessionKeys)> = QueuedKeys::::get(); @@ -142,3 +146,61 @@ mod session_key_migration { } } } + +mod asset_registry { + use super::*; + + /// This migration sets the AssetMetadata.location of all the Tranche tokens + /// registered in the AssetRegistry to `None`. + pub struct TrancheLocationMigration; + + impl OnRuntimeUpgrade for TrancheLocationMigration { + fn on_runtime_upgrade() -> Weight { + for (asset_id, metadata) in orml_asset_registry::Metadata::::iter() { + if matches!(asset_id, CurrencyId::Tranche(_, _)) && metadata.location.is_some() { + match OrmlAssetRegistry::do_update_asset( + asset_id, + // decimals + None, + // name + None, + // symbol + None, + // existential_deposit + None, + // location: we do set it to `None` + Some(None), + // additional + None, + ) { + Err(e) => log::error!("TrancheLocationMigration: Failed to update asset with underlying error: {:?}", e), + _ => continue, + } + } + } + + // todo(nuno): not sure how to build this properly, + // setting it to a conservative value for now. + Weight::from_ref_time(200_000_000) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { + Ok(Default::default()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: sp_std::vec::Vec) -> Result<(), &'static str> { + for (asset_id, metadata) in orml_asset_registry::Metadata::::iter() { + if matches!(asset_id, CurrencyId::Tranche(_, _)) { + frame_support::ensure!( + metadata.location.is_none(), + "A tranche token's location is not None" + ); + } + } + + Ok(()) + } + } +} diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 24fca41a31..f13648f0a6 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -1026,7 +1026,6 @@ impl pallet_pool_system::Config for Runtime { type NAV = Loans; type PalletId = PoolPalletId; type PalletIndex = PoolPalletIndex; - type ParachainId = ParachainInfo; type Permission = Permissions; type PoolCreateOrigin = EnsureSigned; type PoolCurrency = PoolCurrency; @@ -1915,11 +1914,10 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - UpgradeDev1020, + // We don't run migrations on the development runtime + (), >; -type UpgradeDev1020 = (); - impl fp_self_contained::SelfContainedCall for RuntimeCall { type SignedInfo = H160;