Skip to content

Commit

Permalink
fix: clippy + cleanup imports
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli committed Sep 5, 2023
1 parent 0b64fa1 commit c195a78
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 57 deletions.
50 changes: 24 additions & 26 deletions runtime/altair/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,7 @@
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
use cfg_primitives::Balance;
use cfg_types::{
tokens::{CrossChainTransferability, CurrencyId},
xcm::XcmMetadata,
};
use codec::{Decode, Encode};
#[cfg(feature = "try-runtime")]
use frame_support::ensure;
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
use sp_std::{vec, vec::Vec};
use xcm::{v3::prelude::*, VersionedMultiLocation};

use crate::{RocksDbWeight, Runtime};

/// The migration set for Altair 1031 @ Kusama. It includes all the migrations
/// that have to be applied on that chain, which includes migrations that have
Expand All @@ -31,13 +19,13 @@ pub type UpgradeAltair1031 = (
// FIXME: This migration fails to decode 4 entries against Altair
// orml_tokens_migration::CurrencyIdRefactorMigration,
// At minimum, bumps storage version from 1 to 2
runtime_common::migrations::nuke::Migration<crate::Loans, RocksDbWeight, 1>,
runtime_common::migrations::nuke::Migration<crate::Loans, crate::RocksDbWeight, 1>,
// At minimum, bumps storage version from 0 to 3
runtime_common::migrations::nuke::Migration<crate::InterestAccrual, RocksDbWeight, 0>,
runtime_common::migrations::nuke::Migration<crate::InterestAccrual, crate::RocksDbWeight, 0>,
// At minimum, bumps storage version from 0 to 1
runtime_common::migrations::nuke::Migration<crate::PoolSystem, RocksDbWeight, 0>,
runtime_common::migrations::nuke::Migration<crate::PoolSystem, crate::RocksDbWeight, 0>,
// At minimum, bumps storage version from 0 to 1
runtime_common::migrations::nuke::Migration<crate::Investments, RocksDbWeight, 0>,
runtime_common::migrations::nuke::Migration<crate::Investments, crate::RocksDbWeight, 0>,
// Funds pallet_rewards::Instance2 account with existential deposit
pallet_rewards::migrations::new_instance::FundExistentialDeposit<
crate::Runtime,
Expand Down Expand Up @@ -71,9 +59,9 @@ pub type UpgradeAltair1031 = (
#[cfg(feature = "testnet-runtime")]
pub type UpgradeAltair1031 = (
// At minimum, bumps storage version from 0 to 1
runtime_common::migrations::nuke::Migration<crate::PoolSystem, RocksDbWeight, 0>,
runtime_common::migrations::nuke::Migration<crate::PoolSystem, crate::RocksDbWeight, 0>,
// At minimum, bump storage version from 0 to 1
runtime_common::migrations::nuke::Migration<crate::Investments, RocksDbWeight, 0>,
runtime_common::migrations::nuke::Migration<crate::Investments, crate::RocksDbWeight, 0>,
runtime_common::migrations::asset_registry_xcmv3::Migration<
crate::Runtime,
asset_registry::metadata_xcmv3::AltairAssets,
Expand All @@ -88,13 +76,14 @@ pub type UpgradeAltair1031 = (
xcm_v2_to_v3::SetSafeXcmVersion,
);

const DEPRECATED_AUSD_CURRENCY_ID: CurrencyId = CurrencyId::AUSD;
const NEW_AUSD_CURRENCY_ID: CurrencyId = CurrencyId::ForeignAsset(2);

mod asset_registry {
use cfg_types::tokens::CustomMetadata;

use super::*;
use cfg_primitives::Balance;
use cfg_types::{
tokens::{CrossChainTransferability, CurrencyId, CustomMetadata},
xcm::XcmMetadata,
};
use sp_std::{vec, vec::Vec};
use xcm::{v3::prelude::*, VersionedMultiLocation};

pub const ALTAIR_ASSET_LOC_COUNT: u32 = 5;
pub const ALTAIR_ASSET_METADATA_COUNT: u32 = 5;
Expand Down Expand Up @@ -477,10 +466,19 @@ mod asset_registry {
}

mod orml_tokens_migration {
use cfg_primitives::AccountId;
use cfg_primitives::{AccountId, Balance};
use cfg_types::tokens::CurrencyId;
use codec::{Decode, Encode};
#[cfg(feature = "try-runtime")]
use frame_support::ensure;
use orml_tokens::AccountData;
use sp_std::vec::Vec;

use super::*;
use crate::Runtime;

const DEPRECATED_AUSD_CURRENCY_ID: CurrencyId = CurrencyId::AUSD;
const NEW_AUSD_CURRENCY_ID: CurrencyId = CurrencyId::ForeignAsset(2);

/// As we dropped `CurrencyId::KSM` and `CurrencyId::AUSD`, we need to
/// migrate the balances under the dropped variants in favour of the new,
Expand Down Expand Up @@ -609,7 +607,7 @@ mod xcm_v2_to_v3 {
)
.unwrap_or_else(|_| log::error!("Failed to set safe XCM version on runtime upgrade, requires manual call via governance"));

RocksDbWeight::get().writes(1)
crate::RocksDbWeight::get().writes(1)
}
}
}
74 changes: 45 additions & 29 deletions runtime/centrifuge/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,7 @@
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
use cfg_primitives::Balance;
use cfg_types::{
tokens::{
lp_eth_usdc_metadata, CrossChainTransferability, CurrencyId, ETHEREUM_MAINNET_CHAIN_ID,
ETHEREUM_USDC, LP_ETH_USDC_CURRENCY_ID,
},
xcm::XcmMetadata,
};
use frame_support::{
traits::{Len, OnRuntimeUpgrade},
weights::Weight,
};
use sp_std::vec;
use xcm::{v3::prelude::*, VersionedMultiLocation};

use crate::{LiquidityPoolsPalletIndex, RocksDbWeight, Runtime};
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};

pub type UpgradeCentrifuge1020 = (
// Removes metadata containing xcm_v1 locations of registered assets and sets to hardcoded ones
Expand All @@ -38,13 +23,13 @@ pub type UpgradeCentrifuge1020 = (
3,
>,
// At minimum, bumps storage version from 1 to 2
runtime_common::migrations::nuke::Migration<crate::Loans, RocksDbWeight, 1>,
runtime_common::migrations::nuke::Migration<crate::Loans, crate::RocksDbWeight, 1>,
// At minimum, bumps storage version from 0 to 3
runtime_common::migrations::nuke::Migration<crate::InterestAccrual, RocksDbWeight, 0>,
runtime_common::migrations::nuke::Migration<crate::InterestAccrual, crate::RocksDbWeight, 0>,
// At minimum, bumps storage version from 0 to 1
runtime_common::migrations::nuke::Migration<crate::PoolSystem, RocksDbWeight, 0>,
runtime_common::migrations::nuke::Migration<crate::PoolSystem, crate::RocksDbWeight, 0>,
// At minimum, bumps storage version from 0 to 1
runtime_common::migrations::nuke::Migration<crate::Investments, RocksDbWeight, 0>,
runtime_common::migrations::nuke::Migration<crate::Investments, crate::RocksDbWeight, 0>,
// Funds pallet_rewards::Instance2 account with existential deposit
pallet_rewards::migrations::new_instance::FundExistentialDeposit<
crate::Runtime,
Expand All @@ -63,10 +48,17 @@ pub type UpgradeCentrifuge1020 = (
);

mod asset_registry {
use cfg_types::tokens::CustomMetadata;
use frame_support::inherent::Vec;
use cfg_primitives::Balance;
use cfg_types::{
tokens::{
lp_eth_usdc_metadata, CrossChainTransferability, CurrencyId, CustomMetadata,
ETHEREUM_MAINNET_CHAIN_ID, ETHEREUM_USDC, LP_ETH_USDC_CURRENCY_ID,
},
xcm::XcmMetadata,
};
use sp_std::{vec, vec::Vec};
use xcm::{v3::prelude::*, VersionedMultiLocation};

use super::*;
use crate::ParachainInfo;

pub const CENTRIFUGE_ASSET_LOC_COUNT: u32 = 6;
Expand All @@ -93,10 +85,7 @@ mod asset_registry {
(loc, meta)
if (loc, meta) == (CATALYST_ASSET_LOC_COUNT, CATALYST_ASSET_METADATA_COUNT) =>
{
Self::get_centrifuge_assets()
.into_iter()
.chain(Self::get_catalyst_assets().into_iter())
.collect()
Self::get_catalyst_assets()
}
_ => vec![],
}
Expand Down Expand Up @@ -272,7 +261,7 @@ mod asset_registry {
(
LP_ETH_USDC_CURRENCY_ID,
lp_eth_usdc_metadata(
LiquidityPoolsPalletIndex::get(),
crate::LiquidityPoolsPalletIndex::get(),
ETHEREUM_MAINNET_CHAIN_ID,
ETHEREUM_USDC,
),
Expand Down Expand Up @@ -301,6 +290,33 @@ mod asset_registry {
tranche_id[..tranche_id_bytes.len()].copy_from_slice(tranche_id_bytes);

vec![
(
CurrencyId::Native,
orml_asset_registry::AssetMetadata {
decimals: 18,
name: b"Centrifuge".to_vec(),
symbol: b"CFG".to_vec(),
existential_deposit: 1_000_000_000_000u128,
location: Some(VersionedMultiLocation::V3(MultiLocation::new(
1,
Junctions::X2(
Parachain(ParachainInfo::parachain_id().into()),
GeneralKey {
length: 2,
data: gk,
},
),
))),
additional: CustomMetadata {
mintable: false,
permissioned: false,
pool_currency: false,
transferability: CrossChainTransferability::Xcm(XcmMetadata {
fee_per_second: None,
}),
},
},
),
(
CurrencyId::ForeignAsset(41),
orml_asset_registry::AssetMetadata {
Expand Down Expand Up @@ -388,7 +404,7 @@ mod xcm_v2_to_v3 {
)
.unwrap_or_else(|_| log::error!("Failed to set safe XCM version on runtime upgrade, requires manual call via governance"));

RocksDbWeight::get().writes(1)
crate::RocksDbWeight::get().writes(1)
}
}
}
5 changes: 3 additions & 2 deletions runtime/common/src/migrations/asset_registry_xcmv3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use frame_support::{
StoragePrefixedMap,
};
use orml_traits::asset_registry::AssetMetadata;
#[cfg(feature = "try-runtime")]
use sp_arithmetic::traits::Zero;
use sp_std::vec::Vec;

Expand Down Expand Up @@ -188,10 +189,10 @@ impl<
// let meta_count = orml_asset_registry::Metadata::<T>::iter_keys().count() as
// u32;
let loc_count = Self::count_storage_keys(
&orml_asset_registry::LocationToAssetId::<T>::final_prefix().to_vec(),
orml_asset_registry::LocationToAssetId::<T>::final_prefix().as_ref(),
);
let meta_count =
Self::count_storage_keys(&orml_asset_registry::Metadata::<T>::final_prefix().to_vec());
Self::count_storage_keys(orml_asset_registry::Metadata::<T>::final_prefix().as_ref());

log::info!(
"💎 AssetRegistryMultilocationToXCMV3: Found {} LocationToAssetId keys ",
Expand Down

0 comments on commit c195a78

Please sign in to comment.