From 0b64fa16193400bd9a441a24137d976b7db76393 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Tue, 5 Sep 2023 12:29:22 +0200 Subject: [PATCH] fix: finalize migrations, add context --- runtime/altair/src/migrations.rs | 734 +++++++++++++-------------- runtime/centrifuge/src/migrations.rs | 158 +----- 2 files changed, 373 insertions(+), 519 deletions(-) diff --git a/runtime/altair/src/migrations.rs b/runtime/altair/src/migrations.rs index 3d158afc7b..be9703e6e3 100644 --- a/runtime/altair/src/migrations.rs +++ b/runtime/altair/src/migrations.rs @@ -36,8 +36,8 @@ pub type UpgradeAltair1031 = ( runtime_common::migrations::nuke::Migration, // At minimum, bumps storage version from 0 to 1 runtime_common::migrations::nuke::Migration, - // FIXME: Pre-upgrade fails as no storage exists, but version bump from 0 to 1 is required - // runtime_common::migrations::nuke::Migration, + // At minimum, bumps storage version from 0 to 1 + runtime_common::migrations::nuke::Migration, // Funds pallet_rewards::Instance2 account with existential deposit pallet_rewards::migrations::new_instance::FundExistentialDeposit< crate::Runtime, @@ -49,7 +49,7 @@ pub type UpgradeAltair1031 = ( // containing xcm_v3 locations runtime_common::migrations::asset_registry_xcmv3::Migration< crate::Runtime, - asset_registry::metadata_xcmv3::AltairAssets, + asset_registry::AltairAssets, 5, 5, 2, @@ -96,394 +96,382 @@ mod asset_registry { use super::*; - pub mod metadata_xcmv3 { - use super::*; - - pub const ALTAIR_ASSET_LOC_COUNT: u32 = 5; - pub const ALTAIR_ASSET_METADATA_COUNT: u32 = 5; - pub const ALGOL_ASSET_LOC_COUNT: u32 = 2; - pub const ALGOL_ASSET_METADATA_COUNT: u32 = 9; - - pub struct AltairAssets; - impl runtime_common::migrations::asset_registry_xcmv3::AssetsToMigrate for AltairAssets { - fn get_assets_to_migrate( - loc_count: u32, - meta_count: u32, - ) -> Vec<( - CurrencyId, - orml_asset_registry::AssetMetadata, - )> { - match (loc_count, meta_count) { - (loc, meta) - if (loc, meta) == (ALTAIR_ASSET_LOC_COUNT, ALTAIR_ASSET_METADATA_COUNT) => - { - Self::get_altair_assets() - } - (loc, meta) - if (loc, meta) == (ALGOL_ASSET_LOC_COUNT, ALGOL_ASSET_METADATA_COUNT) => - { - Self::get_algol_assets() - } - _ => vec![], + pub const ALTAIR_ASSET_LOC_COUNT: u32 = 5; + pub const ALTAIR_ASSET_METADATA_COUNT: u32 = 5; + pub const ALGOL_ASSET_LOC_COUNT: u32 = 2; + pub const ALGOL_ASSET_METADATA_COUNT: u32 = 9; + + pub struct AltairAssets; + impl runtime_common::migrations::asset_registry_xcmv3::AssetsToMigrate for AltairAssets { + fn get_assets_to_migrate( + loc_count: u32, + meta_count: u32, + ) -> Vec<( + CurrencyId, + orml_asset_registry::AssetMetadata, + )> { + match (loc_count, meta_count) { + (loc, meta) + if (loc, meta) == (ALTAIR_ASSET_LOC_COUNT, ALTAIR_ASSET_METADATA_COUNT) => + { + Self::get_altair_assets() } + (loc, meta) + if (loc, meta) == (ALGOL_ASSET_LOC_COUNT, ALGOL_ASSET_METADATA_COUNT) => + { + Self::get_algol_assets() + } + _ => vec![], } } + } - impl AltairAssets { - pub fn get_altair_assets() -> Vec<( - CurrencyId, - orml_asset_registry::AssetMetadata, - )> { - let mut gk = [0u8; 32]; - gk[..2].copy_from_slice(b"01"); - - // 0x0081 - let mut gk_acala = [0u8; 32]; - gk_acala[..2].copy_from_slice(&[0, 129]); - - // Skipping AUSD since it seems that should be registered differently, lets do - // it manually later on - vec![ - ( - CurrencyId::Native, - orml_asset_registry::AssetMetadata { - decimals: 18, - name: b"Altair".to_vec(), - symbol: b"AIR".to_vec(), - existential_deposit: 1_000_000_000_000u128, - location: Some(VersionedMultiLocation::V3(MultiLocation::new( - 0, - Junctions::X1(GeneralKey { - length: 2, - data: gk, - }), - ))), - additional: CustomMetadata { - mintable: false, - permissioned: false, - pool_currency: false, - transferability: CrossChainTransferability::Xcm(XcmMetadata { - fee_per_second: None, - }), - }, + impl AltairAssets { + pub fn get_altair_assets() -> Vec<( + CurrencyId, + orml_asset_registry::AssetMetadata, + )> { + let mut gk = [0u8; 32]; + gk[..2].copy_from_slice(b"01"); + + // 0x0081 + let mut gk_acala = [0u8; 32]; + gk_acala[..2].copy_from_slice(&[0, 129]); + + // Skipping AUSD since it seems that should be registered differently, lets do + // it manually later on + vec![ + ( + CurrencyId::Native, + orml_asset_registry::AssetMetadata { + decimals: 18, + name: b"Altair".to_vec(), + symbol: b"AIR".to_vec(), + existential_deposit: 1_000_000_000_000u128, + location: Some(VersionedMultiLocation::V3(MultiLocation::new( + 0, + Junctions::X1(GeneralKey { + length: 2, + data: gk, + }), + ))), + additional: CustomMetadata { + mintable: false, + permissioned: false, + pool_currency: false, + transferability: CrossChainTransferability::Xcm(XcmMetadata { + fee_per_second: None, + }), }, - ), - ( - CurrencyId::ForeignAsset(1), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"Tether USDT".to_vec(), - symbol: b"USDT".to_vec(), - existential_deposit: 10_000u128, - location: Some(VersionedMultiLocation::V3(MultiLocation::new( - 1, - Junctions::X3( - Parachain(1000), - PalletInstance(50), - GeneralIndex(1984), - ), - ))), - additional: CustomMetadata { - mintable: false, - permissioned: false, - pool_currency: true, - transferability: CrossChainTransferability::Xcm(XcmMetadata { - fee_per_second: None, - }), - }, + }, + ), + ( + CurrencyId::ForeignAsset(1), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"Tether USDT".to_vec(), + symbol: b"USDT".to_vec(), + existential_deposit: 10_000u128, + location: Some(VersionedMultiLocation::V3(MultiLocation::new( + 1, + Junctions::X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984)), + ))), + additional: CustomMetadata { + mintable: false, + permissioned: false, + pool_currency: true, + transferability: CrossChainTransferability::Xcm(XcmMetadata { + fee_per_second: None, + }), }, - ), - ( - CurrencyId::ForeignAsset(2), - orml_asset_registry::AssetMetadata { - decimals: 12, - name: b"Acala Dollar".to_vec(), - symbol: b"aUSD".to_vec(), - existential_deposit: 10_000_000_000u128, - location: Some(VersionedMultiLocation::V3(MultiLocation::new( - 1, - Junctions::X2( - Parachain(2000), - GeneralKey { - length: 2, - data: gk_acala, - }, - ), - ))), - additional: CustomMetadata { - mintable: false, - permissioned: false, - pool_currency: true, - transferability: CrossChainTransferability::Xcm(XcmMetadata { - fee_per_second: None, - }), - }, + }, + ), + ( + CurrencyId::ForeignAsset(2), + orml_asset_registry::AssetMetadata { + decimals: 12, + name: b"Acala Dollar".to_vec(), + symbol: b"aUSD".to_vec(), + existential_deposit: 10_000_000_000u128, + location: Some(VersionedMultiLocation::V3(MultiLocation::new( + 1, + Junctions::X2( + Parachain(2000), + GeneralKey { + length: 2, + data: gk_acala, + }, + ), + ))), + additional: CustomMetadata { + mintable: false, + permissioned: false, + pool_currency: true, + transferability: CrossChainTransferability::Xcm(XcmMetadata { + fee_per_second: None, + }), }, - ), - ( - CurrencyId::ForeignAsset(3), - orml_asset_registry::AssetMetadata { - decimals: 12, - name: b"Kusama".to_vec(), - symbol: b"KSM".to_vec(), - existential_deposit: 10_000_000_000u128, - location: Some(VersionedMultiLocation::V3(MultiLocation::new( - 1, - Junctions::Here, - ))), - additional: CustomMetadata { - mintable: false, - permissioned: false, - pool_currency: false, - transferability: CrossChainTransferability::Xcm(XcmMetadata { - fee_per_second: None, - }), - }, + }, + ), + ( + CurrencyId::ForeignAsset(3), + orml_asset_registry::AssetMetadata { + decimals: 12, + name: b"Kusama".to_vec(), + symbol: b"KSM".to_vec(), + existential_deposit: 10_000_000_000u128, + location: Some(VersionedMultiLocation::V3(MultiLocation::new( + 1, + Junctions::Here, + ))), + additional: CustomMetadata { + mintable: false, + permissioned: false, + pool_currency: false, + transferability: CrossChainTransferability::Xcm(XcmMetadata { + fee_per_second: None, + }), }, - ), - ] - } + }, + ), + ] + } - pub fn get_algol_assets() -> Vec<( - CurrencyId, - orml_asset_registry::AssetMetadata, - )> { - // 02f3a00dd12f644daec907013b16eb6d14bf1c4cb4 - let gk_bytes: &[u8] = &[ - 2u8, 243u8, 160u8, 13u8, 209u8, 47u8, 100u8, 77u8, 174u8, 201u8, 7u8, 1u8, - 59u8, 22u8, 235u8, 109u8, 20u8, 191u8, 28u8, 76u8, 180u8, - ]; - let mut gk = [0u8; 32]; - gk[..gk_bytes.len()].copy_from_slice(gk_bytes); - - // 0x3a39cb9fb7c1b5e5b0071d8a9396fdeb - let polka_jr_bytes = &[ - 58u8, 57u8, 203u8, 159u8, 183u8, 193u8, 181u8, 229u8, 176u8, 7u8, 29u8, 138u8, - 147u8, 150u8, 253u8, 235u8, - ]; - let mut polka_jr = [0u8; 16]; - polka_jr[..polka_jr_bytes.len()].copy_from_slice(polka_jr_bytes); - - // 0xe0af7eeed9aa5e17667d617dbecd5975 - let polka_mezz_1_bytes = &[ - 224u8, 175u8, 126u8, 238u8, 217u8, 170u8, 94u8, 23u8, 102u8, 125u8, 97u8, - 125u8, 190u8, 205u8, 89u8, 117u8, - ]; - let mut polka_mezz_1 = [0u8; 16]; - polka_mezz_1[..polka_mezz_1_bytes.len()].copy_from_slice(polka_mezz_1_bytes); - - // 0xa52f72fd60c3f0a11b8c99fc35f54d9f - let polka_mezz_2_bytes = &[ - 165u8, 47u8, 114u8, 253u8, 96u8, 195u8, 240u8, 161u8, 27u8, 140u8, 153u8, - 252u8, 53u8, 245u8, 77u8, 159u8, - ]; - let mut polka_mezz_2 = [0u8; 16]; - polka_mezz_2[..polka_mezz_2_bytes.len()].copy_from_slice(polka_mezz_2_bytes); - - // 0xa7e7bdcb04b43e1ab323c9690f2bc24e - let polka_mezz_3_bytes = &[ - 167u8, 231u8, 189u8, 203u8, 4u8, 180u8, 62u8, 26u8, 179u8, 35u8, 201u8, 105u8, - 15u8, 43u8, 194u8, 78u8, - ]; - let mut polka_mezz_3 = [0u8; 16]; - polka_mezz_3[..polka_mezz_3_bytes.len()].copy_from_slice(polka_mezz_3_bytes); - - // 0x2793bae22e2db2423b056e8ec7f1cded - let polka_senior_bytes = &[ - 39u8, 147u8, 186u8, 226u8, 46u8, 45u8, 178u8, 66u8, 59u8, 5u8, 110u8, 142u8, - 199u8, 241u8, 205u8, 237u8, - ]; - let mut polka_senior = [0u8; 16]; - polka_senior[..polka_senior_bytes.len()].copy_from_slice(polka_senior_bytes); - - // 0x5b218a7ea17e848b640087adcdd7dfb2 - let just_jr_bytes = &[ - 91u8, 33u8, 138u8, 126u8, 161u8, 126u8, 132u8, 139u8, 100u8, 0u8, 135u8, 173u8, - 205u8, 215u8, 223u8, 178u8, - ]; - let mut just_jr = [0u8; 16]; - just_jr[..just_jr_bytes.len()].copy_from_slice(just_jr_bytes); - - // 0x7acea1c8880afe5e32b41b77747ad8aa - let just_sr_bytes = &[ - 122u8, 206u8, 161u8, 200u8, 136u8, 10u8, 254u8, 94u8, 50u8, 180u8, 27u8, 119u8, - 116u8, 122u8, 216u8, 170u8, - ]; - let mut just_sr = [0u8; 16]; - just_sr[..just_sr_bytes.len()].copy_from_slice(just_sr_bytes); - - // 0x07865c6e87b9f70255377e024ace6630c1eaa37f - let lp_eth_acc: [u8; 20] = [ - 7u8, 134u8, 92u8, 110u8, 135u8, 185u8, 247u8, 2u8, 85u8, 55u8, 126u8, 2u8, - 74u8, 206u8, 102u8, 48u8, 193u8, 234u8, 163u8, 127u8, - ]; - - vec![ - ( - CurrencyId::Tranche(3151673055, polka_jr), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"Polka Pool Junior".to_vec(), - symbol: b"PP1J".to_vec(), - existential_deposit: 0u128, - location: None, - additional: CustomMetadata { - mintable: false, - permissioned: true, - pool_currency: false, - transferability: CrossChainTransferability::LiquidityPools, - }, + pub fn get_algol_assets() -> Vec<( + CurrencyId, + orml_asset_registry::AssetMetadata, + )> { + // 02f3a00dd12f644daec907013b16eb6d14bf1c4cb4 + let gk_bytes: &[u8] = &[ + 2u8, 243u8, 160u8, 13u8, 209u8, 47u8, 100u8, 77u8, 174u8, 201u8, 7u8, 1u8, 59u8, + 22u8, 235u8, 109u8, 20u8, 191u8, 28u8, 76u8, 180u8, + ]; + let mut gk = [0u8; 32]; + gk[..gk_bytes.len()].copy_from_slice(gk_bytes); + + // 0x3a39cb9fb7c1b5e5b0071d8a9396fdeb + let polka_jr_bytes = &[ + 58u8, 57u8, 203u8, 159u8, 183u8, 193u8, 181u8, 229u8, 176u8, 7u8, 29u8, 138u8, + 147u8, 150u8, 253u8, 235u8, + ]; + let mut polka_jr = [0u8; 16]; + polka_jr[..polka_jr_bytes.len()].copy_from_slice(polka_jr_bytes); + + // 0xe0af7eeed9aa5e17667d617dbecd5975 + let polka_mezz_1_bytes = &[ + 224u8, 175u8, 126u8, 238u8, 217u8, 170u8, 94u8, 23u8, 102u8, 125u8, 97u8, 125u8, + 190u8, 205u8, 89u8, 117u8, + ]; + let mut polka_mezz_1 = [0u8; 16]; + polka_mezz_1[..polka_mezz_1_bytes.len()].copy_from_slice(polka_mezz_1_bytes); + + // 0xa52f72fd60c3f0a11b8c99fc35f54d9f + let polka_mezz_2_bytes = &[ + 165u8, 47u8, 114u8, 253u8, 96u8, 195u8, 240u8, 161u8, 27u8, 140u8, 153u8, 252u8, + 53u8, 245u8, 77u8, 159u8, + ]; + let mut polka_mezz_2 = [0u8; 16]; + polka_mezz_2[..polka_mezz_2_bytes.len()].copy_from_slice(polka_mezz_2_bytes); + + // 0xa7e7bdcb04b43e1ab323c9690f2bc24e + let polka_mezz_3_bytes = &[ + 167u8, 231u8, 189u8, 203u8, 4u8, 180u8, 62u8, 26u8, 179u8, 35u8, 201u8, 105u8, + 15u8, 43u8, 194u8, 78u8, + ]; + let mut polka_mezz_3 = [0u8; 16]; + polka_mezz_3[..polka_mezz_3_bytes.len()].copy_from_slice(polka_mezz_3_bytes); + + // 0x2793bae22e2db2423b056e8ec7f1cded + let polka_senior_bytes = &[ + 39u8, 147u8, 186u8, 226u8, 46u8, 45u8, 178u8, 66u8, 59u8, 5u8, 110u8, 142u8, 199u8, + 241u8, 205u8, 237u8, + ]; + let mut polka_senior = [0u8; 16]; + polka_senior[..polka_senior_bytes.len()].copy_from_slice(polka_senior_bytes); + + // 0x5b218a7ea17e848b640087adcdd7dfb2 + let just_jr_bytes = &[ + 91u8, 33u8, 138u8, 126u8, 161u8, 126u8, 132u8, 139u8, 100u8, 0u8, 135u8, 173u8, + 205u8, 215u8, 223u8, 178u8, + ]; + let mut just_jr = [0u8; 16]; + just_jr[..just_jr_bytes.len()].copy_from_slice(just_jr_bytes); + + // 0x7acea1c8880afe5e32b41b77747ad8aa + let just_sr_bytes = &[ + 122u8, 206u8, 161u8, 200u8, 136u8, 10u8, 254u8, 94u8, 50u8, 180u8, 27u8, 119u8, + 116u8, 122u8, 216u8, 170u8, + ]; + let mut just_sr = [0u8; 16]; + just_sr[..just_sr_bytes.len()].copy_from_slice(just_sr_bytes); + + // 0x07865c6e87b9f70255377e024ace6630c1eaa37f + let lp_eth_acc: [u8; 20] = [ + 7u8, 134u8, 92u8, 110u8, 135u8, 185u8, 247u8, 2u8, 85u8, 55u8, 126u8, 2u8, 74u8, + 206u8, 102u8, 48u8, 193u8, 234u8, 163u8, 127u8, + ]; + + vec![ + ( + CurrencyId::Tranche(3151673055, polka_jr), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"Polka Pool Junior".to_vec(), + symbol: b"PP1J".to_vec(), + existential_deposit: 0u128, + location: None, + additional: CustomMetadata { + mintable: false, + permissioned: true, + pool_currency: false, + transferability: CrossChainTransferability::LiquidityPools, }, - ), - ( - CurrencyId::Tranche(3151673055, polka_mezz_1), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"Polka Pool Mezz 1".to_vec(), - symbol: b"PP1M1".to_vec(), - existential_deposit: 0u128, - location: None, - additional: CustomMetadata { - mintable: false, - permissioned: true, - pool_currency: false, - transferability: CrossChainTransferability::LiquidityPools, - }, + }, + ), + ( + CurrencyId::Tranche(3151673055, polka_mezz_1), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"Polka Pool Mezz 1".to_vec(), + symbol: b"PP1M1".to_vec(), + existential_deposit: 0u128, + location: None, + additional: CustomMetadata { + mintable: false, + permissioned: true, + pool_currency: false, + transferability: CrossChainTransferability::LiquidityPools, }, - ), - ( - CurrencyId::Tranche(3151673055, polka_mezz_2), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"Polka Pool Mezz 2".to_vec(), - symbol: b"PP1M2".to_vec(), - existential_deposit: 0u128, - location: None, - additional: CustomMetadata { - mintable: false, - permissioned: true, - pool_currency: false, - transferability: CrossChainTransferability::LiquidityPools, - }, + }, + ), + ( + CurrencyId::Tranche(3151673055, polka_mezz_2), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"Polka Pool Mezz 2".to_vec(), + symbol: b"PP1M2".to_vec(), + existential_deposit: 0u128, + location: None, + additional: CustomMetadata { + mintable: false, + permissioned: true, + pool_currency: false, + transferability: CrossChainTransferability::LiquidityPools, }, - ), - ( - CurrencyId::Tranche(3151673055, polka_mezz_3), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"Polka Pool Mezz 3".to_vec(), - symbol: b"PP1M3".to_vec(), - existential_deposit: 0u128, - location: None, - additional: CustomMetadata { - mintable: false, - permissioned: true, - pool_currency: false, - transferability: CrossChainTransferability::LiquidityPools, - }, + }, + ), + ( + CurrencyId::Tranche(3151673055, polka_mezz_3), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"Polka Pool Mezz 3".to_vec(), + symbol: b"PP1M3".to_vec(), + existential_deposit: 0u128, + location: None, + additional: CustomMetadata { + mintable: false, + permissioned: true, + pool_currency: false, + transferability: CrossChainTransferability::LiquidityPools, }, - ), - ( - CurrencyId::Tranche(3151673055, polka_senior), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"Polka Pool Senior".to_vec(), - symbol: b"PP1S".to_vec(), - existential_deposit: 0u128, - location: None, - additional: CustomMetadata { - mintable: false, - permissioned: true, - pool_currency: false, - transferability: CrossChainTransferability::LiquidityPools, - }, + }, + ), + ( + CurrencyId::Tranche(3151673055, polka_senior), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"Polka Pool Senior".to_vec(), + symbol: b"PP1S".to_vec(), + existential_deposit: 0u128, + location: None, + additional: CustomMetadata { + mintable: false, + permissioned: true, + pool_currency: false, + transferability: CrossChainTransferability::LiquidityPools, }, - ), - ( - CurrencyId::Tranche(3581766799, just_jr), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"Just Logistics Series 3 Junior".to_vec(), - symbol: b"JL3JR".to_vec(), - existential_deposit: 0u128, - location: None, - additional: CustomMetadata { - mintable: false, - permissioned: true, - pool_currency: false, - transferability: CrossChainTransferability::LiquidityPools, - }, + }, + ), + ( + CurrencyId::Tranche(3581766799, just_jr), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"Just Logistics Series 3 Junior".to_vec(), + symbol: b"JL3JR".to_vec(), + existential_deposit: 0u128, + location: None, + additional: CustomMetadata { + mintable: false, + permissioned: true, + pool_currency: false, + transferability: CrossChainTransferability::LiquidityPools, }, - ), - ( - CurrencyId::Tranche(3581766799, just_sr), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"Just Logistics Series 3 Senior".to_vec(), - symbol: b"JL3SR".to_vec(), - existential_deposit: 0u128, - location: None, - additional: CustomMetadata { - mintable: false, - permissioned: true, - pool_currency: false, - transferability: CrossChainTransferability::LiquidityPools, - }, + }, + ), + ( + CurrencyId::Tranche(3581766799, just_sr), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"Just Logistics Series 3 Senior".to_vec(), + symbol: b"JL3SR".to_vec(), + existential_deposit: 0u128, + location: None, + additional: CustomMetadata { + mintable: false, + permissioned: true, + pool_currency: false, + transferability: CrossChainTransferability::LiquidityPools, }, - ), - ( - CurrencyId::ForeignAsset(1), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"Tether USD".to_vec(), - symbol: b"USDT".to_vec(), - existential_deposit: 0u128, - location: Some(VersionedMultiLocation::V3(MultiLocation::new( - 1, - Junctions::X3( - Parachain(1000), - PalletInstance(50), - GeneralIndex(1984), - ), - ))), - additional: CustomMetadata { - mintable: false, - permissioned: false, - pool_currency: true, - transferability: CrossChainTransferability::Xcm(XcmMetadata { - fee_per_second: None, - }), - }, + }, + ), + ( + CurrencyId::ForeignAsset(1), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"Tether USD".to_vec(), + symbol: b"USDT".to_vec(), + existential_deposit: 0u128, + location: Some(VersionedMultiLocation::V3(MultiLocation::new( + 1, + Junctions::X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984)), + ))), + additional: CustomMetadata { + mintable: false, + permissioned: false, + pool_currency: true, + transferability: CrossChainTransferability::Xcm(XcmMetadata { + fee_per_second: None, + }), }, - ), - ( - CurrencyId::ForeignAsset(100001), - orml_asset_registry::AssetMetadata { - decimals: 6, - name: b"LP Ethereum Wrapped USDC".to_vec(), - symbol: b"LpEthUSDC".to_vec(), - existential_deposit: 1_000u128, - location: Some(VersionedMultiLocation::V3(MultiLocation::new( - 0, - Junctions::X3( - PalletInstance(108), - GlobalConsensus(Ethereum { chain_id: 5 }), - AccountKey20 { - network: None, - key: lp_eth_acc, - }, - ), - ))), - additional: CustomMetadata { - mintable: false, - permissioned: false, - pool_currency: true, - transferability: CrossChainTransferability::LiquidityPools, - }, + }, + ), + ( + CurrencyId::ForeignAsset(100001), + orml_asset_registry::AssetMetadata { + decimals: 6, + name: b"LP Ethereum Wrapped USDC".to_vec(), + symbol: b"LpEthUSDC".to_vec(), + existential_deposit: 1_000u128, + location: Some(VersionedMultiLocation::V3(MultiLocation::new( + 0, + Junctions::X3( + PalletInstance(108), + GlobalConsensus(Ethereum { chain_id: 5 }), + AccountKey20 { + network: None, + key: lp_eth_acc, + }, + ), + ))), + additional: CustomMetadata { + mintable: false, + permissioned: false, + pool_currency: true, + transferability: CrossChainTransferability::LiquidityPools, }, - ), - ] - } + }, + ), + ] } } } diff --git a/runtime/centrifuge/src/migrations.rs b/runtime/centrifuge/src/migrations.rs index 4a1f67a072..3147441c61 100644 --- a/runtime/centrifuge/src/migrations.rs +++ b/runtime/centrifuge/src/migrations.rs @@ -27,6 +27,8 @@ use xcm::{v3::prelude::*, VersionedMultiLocation}; use crate::{LiquidityPoolsPalletIndex, RocksDbWeight, Runtime}; pub type UpgradeCentrifuge1020 = ( + // Removes metadata containing xcm_v1 locations of registered assets and sets to hardcoded ones + // containing xcm_v3 locations runtime_common::migrations::asset_registry_xcmv3::Migration< crate::Runtime, asset_registry::CentrifugeAssets, @@ -35,11 +37,15 @@ pub type UpgradeCentrifuge1020 = ( 2, 3, >, - asset_registry::CrossChainTransferabilityMigration, + // At minimum, bumps storage version from 1 to 2 runtime_common::migrations::nuke::Migration, + // At minimum, bumps storage version from 0 to 3 runtime_common::migrations::nuke::Migration, + // At minimum, bumps storage version from 0 to 1 runtime_common::migrations::nuke::Migration, + // At minimum, bumps storage version from 0 to 1 runtime_common::migrations::nuke::Migration, + // Funds pallet_rewards::Instance2 account with existential deposit pallet_rewards::migrations::new_instance::FundExistentialDeposit< crate::Runtime, pallet_rewards::Instance2, @@ -57,157 +63,17 @@ pub type UpgradeCentrifuge1020 = ( ); mod asset_registry { - use cfg_types::{tokens as v1, tokens::CustomMetadata}; - #[cfg(feature = "try-runtime")] - use frame_support::ensure; - use frame_support::{pallet_prelude::OptionQuery, storage_alias, Twox64Concat}; - use orml_traits::asset_registry::AssetMetadata; - #[cfg(feature = "try-runtime")] - use sp_std::vec::Vec; + use cfg_types::tokens::CustomMetadata; + use frame_support::inherent::Vec; use super::*; - use crate::VERSION; + use crate::ParachainInfo; - pub const CENTRIFUGE_ASSET_LOC_COUNT: u32 = 4; + pub const CENTRIFUGE_ASSET_LOC_COUNT: u32 = 6; pub const CENTRIFUGE_ASSET_METADATA_COUNT: u32 = 8; - pub const CATALYST_ASSET_LOC_COUNT: u32 = 1; + pub const CATALYST_ASSET_LOC_COUNT: u32 = 2; pub const CATALYST_ASSET_METADATA_COUNT: u32 = 3; - /// Migrate all the registered asset's metadata to the new version of - /// `CustomMetadata` which contains a `CrossChainTransferability` property. - /// At this point in time, the `transferability` of Tranche tokens should be - /// set to `CrossChainTransferability::Xcm` and for all other tokens to - /// `CrossChainTransferability::Xcm`, with the exception of - /// `Currency::Staking` tokens which are not registered in the first place. - pub struct CrossChainTransferabilityMigration; - - // The old orml_asset_registry Metadata storage using v0::CustomMetadata - #[storage_alias] - type Metadata = StorageMap< - orml_asset_registry::Pallet, - Twox64Concat, - CurrencyId, - AssetMetadata, - OptionQuery, - >; - - impl OnRuntimeUpgrade for CrossChainTransferabilityMigration { - fn on_runtime_upgrade() -> Weight { - if VERSION.spec_version != 1020 { - return Weight::zero(); - } - - orml_asset_registry::Metadata::::translate( - |asset_id: CurrencyId, old_metadata: AssetMetadata| { - match asset_id { - CurrencyId::Staking(_) => None, - CurrencyId::Tranche(_, _) => Some(to_metadata_v1( - old_metadata, - v1::CrossChainTransferability::LiquidityPools, - )), - _ => Some(to_metadata_v1( - old_metadata.clone(), - v1::CrossChainTransferability::Xcm(old_metadata.additional.xcm), - )), - } - }, - ); - - let n = orml_asset_registry::Metadata::::iter().count() as u64; - ::DbWeight::get().reads_writes(n, n) - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - use codec::Encode; - - let old_state: Vec<(CurrencyId, AssetMetadata)> = - Metadata::::iter().collect::>(); - - Ok(old_state.encode()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(old_state_encoded: Vec) -> Result<(), &'static str> { - use codec::Decode; - - let old_state = sp_std::vec::Vec::<( - CurrencyId, - AssetMetadata, - )>::decode(&mut old_state_encoded.as_ref()) - .map_err(|_| "Error decoding pre-upgrade state")?; - - for (asset_id, old_metadata) in old_state { - let new_metadata = crate::OrmlAssetRegistry::metadata(asset_id) - .ok_or_else(|| "New state lost the metadata of an asset")?; - - match asset_id { - CurrencyId::Tranche(_, _) => ensure!(new_metadata == to_metadata_v1( - old_metadata, - v1::CrossChainTransferability::LiquidityPools, - ), "The metadata of a tranche token wasn't just updated by setting `transferability` to `LiquidityPools `"), - _ => ensure!(new_metadata == to_metadata_v1( - old_metadata.clone(), - v1::CrossChainTransferability::Xcm(old_metadata.additional.xcm), - ), "The metadata of a NON tranche token wasn't just updated by setting `transferability` to `Xcm`"), - } - } - - Ok(()) - } - } - - mod v0 { - use cfg_types::xcm::XcmMetadata; - use codec::{Decode, Encode, MaxEncodedLen}; - use scale_info::TypeInfo; - #[cfg(feature = "std")] - use serde::{Deserialize, Serialize}; - - // The `CustomMetadata` type as it was prior to adding the `transferability` - // field and prior to removing the `xcm` field. - #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] - #[derive( - Clone, - Copy, - Default, - PartialOrd, - Ord, - PartialEq, - Eq, - Debug, - Encode, - Decode, - TypeInfo, - MaxEncodedLen, - )] - pub struct CustomMetadata { - pub xcm: XcmMetadata, - pub mintable: bool, - pub permissioned: bool, - pub pool_currency: bool, - } - } - - fn to_metadata_v1( - old: AssetMetadata, - transferability: v1::CrossChainTransferability, - ) -> AssetMetadata { - AssetMetadata { - decimals: old.decimals, - name: old.name, - symbol: old.symbol, - existential_deposit: old.existential_deposit, - location: old.location, - additional: CustomMetadata { - mintable: old.additional.mintable, - permissioned: old.additional.permissioned, - pool_currency: old.additional.pool_currency, - transferability, - }, - } - } - pub struct CentrifugeAssets; impl runtime_common::migrations::asset_registry_xcmv3::AssetsToMigrate for CentrifugeAssets { fn get_assets_to_migrate(