Skip to content

Commit

Permalink
clean last refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Feb 21, 2024
1 parent c351366 commit fa66bdc
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 54 deletions.
11 changes: 7 additions & 4 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,9 @@ fn centrifuge_genesis(
endowed_accounts.extend(endowed_evm_accounts.into_iter().map(|(addr, id)| {
let chain_id = id.unwrap_or_else(|| chain_id.into());
AccountConverter::<
centrifuge_runtime::Runtime,
centrifuge_runtime::xcm::LocationToAccountId,
>::convert_evm_address(chain_id, addr)
centrifuge_runtime::Runtime,
centrifuge_runtime::xcm::LocationToAccountId,
>::convert_evm_address(chain_id, addr)
}));

let num_endowed_accounts = endowed_accounts.len();
Expand Down Expand Up @@ -691,7 +691,10 @@ fn altair_genesis(

endowed_accounts.extend(endowed_evm_accounts.into_iter().map(|(addr, id)| {
let chain_id = id.unwrap_or_else(|| chain_id.into());
AccountConverter::<altair_runtime::Runtime, altair_runtime::xcm::LocationToAccountId>::convert_evm_address(chain_id, addr)
AccountConverter::<
altair_runtime::Runtime,
altair_runtime::xcm::LocationToAccountId,
>::convert_evm_address(chain_id, addr)
}));

let num_endowed_accounts = endowed_accounts.len();
Expand Down
14 changes: 7 additions & 7 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ use runtime_common::{
permissions::PoolAdminCheck,
remarks::Remark,
transfer_filter::PreLpTransfer,
xcm::{AccountIdToMultiLocation, CurrencyIdConvert, LocationToAccountId},
xcm::AccountIdToMultiLocation,
xcm_transactor, AllowanceDeposit, CurrencyED, HoldId,
};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -1381,7 +1381,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type Balance = Balance;
type BaseXcmWeight = BaseXcmWeight;
type CurrencyId = CurrencyId;
type CurrencyIdToMultiLocation = CurrencyIdConvert<Self>;
type CurrencyIdToMultiLocation = CurrencyIdConvert;
type DerivativeAddressRegistrationOrigin = EnsureRoot<AccountId>;
type HrmpEncoder = moonbeam_relay_encoder::westend::WestendEncoder;
type HrmpManipulatorOrigin = EnsureRootOr<HalfOfCouncil>;
Expand Down Expand Up @@ -1753,8 +1753,8 @@ impl pallet_liquidity_pools::Config for Runtime {
type Balance = Balance;
type BalanceRatio = Ratio;
type CurrencyId = CurrencyId;
type DomainAccountToAccountId = AccountConverter<Runtime, LocationToAccountId<RelayNetwork>>;
type DomainAddressToAccountId = AccountConverter<Runtime, LocationToAccountId<RelayNetwork>>;
type DomainAccountToAccountId = AccountConverter<Runtime, LocationToAccountId>;
type DomainAddressToAccountId = AccountConverter<Runtime, LocationToAccountId>;
type ForeignInvestment = ForeignInvestments;
type GeneralCurrencyPrefix = GeneralCurrencyPrefix;
type OutboundQueue = LiquidityPoolsGateway;
Expand All @@ -1774,7 +1774,7 @@ impl pallet_liquidity_pools::Config for Runtime {

parameter_types! {
pub const MaxIncomingMessageSize: u32 = 1024;
pub Sender: AccountId = GatewayAccountProvider::<Runtime, LocationToAccountId<RelayNetwork>>::get_gateway_account();
pub Sender: AccountId = GatewayAccountProvider::<Runtime, LocationToAccountId>::get_gateway_account();
}

impl pallet_liquidity_pools_gateway::Config for Runtime {
Expand Down Expand Up @@ -1845,7 +1845,7 @@ parameter_types! {
}

impl pallet_evm::Config for Runtime {
type AddressMapping = AccountConverter<Runtime, LocationToAccountId<RelayNetwork>>;
type AddressMapping = AccountConverter<Runtime, LocationToAccountId>;
type BlockGasLimit = BlockGasLimit;
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;
type CallOrigin = EnsureAddressRoot<AccountId>;
Expand Down Expand Up @@ -2373,7 +2373,7 @@ impl_runtime_apis! {

impl runtime_common::apis::AccountConversionApi<Block, AccountId> for Runtime {
fn conversion_of(location: MultiLocation) -> Option<AccountId> {
AccountConverter::<Runtime, LocationToAccountId<RelayNetwork>>::try_convert(location).ok()
AccountConverter::<Runtime, LocationToAccountId>::try_convert(location).ok()
}
}

Expand Down
20 changes: 11 additions & 9 deletions runtime/altair/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use pallet_xcm::XcmPassthrough;
use runtime_common::{
transfer_filter::PreXcmTransfer,
xcm::{
general_key, AccountIdToMultiLocation, Barrier, CurrencyIdConvert,
FixedConversionRateProvider, LocationToAccountId, ToTreasury,
general_key, AccountIdToMultiLocation, Barrier, FixedConversionRateProvider, ToTreasury,
},
xcm_fees::native_per_second,
};
Expand Down Expand Up @@ -75,7 +74,7 @@ impl frame_support::traits::Contains<RuntimeCall> for SafeCallFilter {
| RuntimeCall::Proxy(..)
| RuntimeCall::LiquidityPoolsGateway(
pallet_liquidity_pools_gateway::Call::process_msg { .. }
) // TODO: Enable later: | RuntimeCall::OrderBook(..)
) | RuntimeCall::OrderBook(..)
)
}
}
Expand Down Expand Up @@ -142,9 +141,9 @@ pub type FungiblesTransactor = FungiblesAdapter<
Tokens,
// This means that this adapter should handle any token that `CurrencyIdConvert` can convert
// to `CurrencyId`, the `CurrencyId` type of `Tokens`, the fungibles implementation it uses.
ConvertedConcreteId<CurrencyId, Balance, CurrencyIdConvert<Runtime>, JustTry>,
ConvertedConcreteId<CurrencyId, Balance, CurrencyIdConvert, JustTry>,
// Convert an XCM MultiLocation into a local account id
LocationToAccountId<RelayNetwork>,
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly)
AccountId,
// We dont want to allow teleporting assets
Expand Down Expand Up @@ -181,7 +180,7 @@ impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type SovereignAccountOf = LocationToAccountId<RelayNetwork>;
type SovereignAccountOf = LocationToAccountId;
type TrustedLockers = ();
type UniversalLocation = UniversalLocation;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
Expand All @@ -202,6 +201,9 @@ parameter_types! {
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}

pub type CurrencyIdConvert = runtime_common::xcm::CurrencyIdConvert<Runtime>;
pub type LocationToAccountId = runtime_common::xcm::LocationToAccountId<RelayNetwork>;

/// No local origins on this chain are allowed to dispatch XCM sends/executions.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

Expand All @@ -222,7 +224,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
// foreign chains who want to have a local sovereign account on this chain which they control.
SovereignSignedViaLocation<LocationToAccountId<RelayNetwork>, RuntimeOrigin>,
SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when
// recognized.
RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
Expand Down Expand Up @@ -261,7 +263,7 @@ impl orml_xtokens::Config for Runtime {
type Balance = Balance;
type BaseXcmWeight = BaseXcmWeight;
type CurrencyId = CurrencyId;
type CurrencyIdConvert = CurrencyIdConvert<Self>;
type CurrencyIdConvert = CurrencyIdConvert;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type MinXcmFee = ParachainMinFee;
type MultiLocationsFilter = Everything;
Expand All @@ -274,7 +276,7 @@ impl orml_xtokens::Config for Runtime {
}

impl pallet_restricted_xtokens::Config for Runtime {
type PreTransfer = PreXcmTransfer<super::TransferAllowList, CurrencyIdConvert<Self>>;
type PreTransfer = PreXcmTransfer<super::TransferAllowList, CurrencyIdConvert>;
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand Down
14 changes: 7 additions & 7 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use runtime_common::{
origin::EnsureAccountOrRootOr,
permissions::PoolAdminCheck,
transfer_filter::PreLpTransfer,
xcm::{AccountIdToMultiLocation, CurrencyIdConvert, LocationToAccountId},
xcm::AccountIdToMultiLocation,
xcm_transactor, AllowanceDeposit, CurrencyED, HoldId,
};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -1187,7 +1187,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type Balance = Balance;
type BaseXcmWeight = BaseXcmWeight;
type CurrencyId = CurrencyId;
type CurrencyIdToMultiLocation = CurrencyIdConvert<Self>;
type CurrencyIdToMultiLocation = CurrencyIdConvert;
type DerivativeAddressRegistrationOrigin = EnsureRootOr<HalfOfCouncil>;
type HrmpEncoder = moonbeam_relay_encoder::polkadot::PolkadotEncoder;
type HrmpManipulatorOrigin = EnsureRootOr<HalfOfCouncil>;
Expand Down Expand Up @@ -1850,8 +1850,8 @@ impl pallet_liquidity_pools::Config for Runtime {
type Balance = Balance;
type BalanceRatio = Ratio;
type CurrencyId = CurrencyId;
type DomainAccountToAccountId = AccountConverter<Runtime, LocationToAccountId<RelayNetwork>>;
type DomainAddressToAccountId = AccountConverter<Runtime, LocationToAccountId<RelayNetwork>>;
type DomainAccountToAccountId = AccountConverter<Runtime, LocationToAccountId>;
type DomainAddressToAccountId = AccountConverter<Runtime, LocationToAccountId>;
type ForeignInvestment = ForeignInvestments;
type GeneralCurrencyPrefix = GeneralCurrencyPrefix;
type OutboundQueue = LiquidityPoolsGateway;
Expand All @@ -1871,7 +1871,7 @@ impl pallet_liquidity_pools::Config for Runtime {

parameter_types! {
pub const MaxIncomingMessageSize: u32 = 1024;
pub Sender: AccountId = GatewayAccountProvider::<Runtime, LocationToAccountId<RelayNetwork>>::get_gateway_account();
pub Sender: AccountId = GatewayAccountProvider::<Runtime, LocationToAccountId>::get_gateway_account();
}

parameter_types! {
Expand Down Expand Up @@ -1958,7 +1958,7 @@ parameter_types! {
}

impl pallet_evm::Config for Runtime {
type AddressMapping = AccountConverter<Runtime, LocationToAccountId<RelayNetwork>>;
type AddressMapping = AccountConverter<Runtime, LocationToAccountId>;
type BlockGasLimit = BlockGasLimit;
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;
type CallOrigin = EnsureAddressRoot<AccountId>;
Expand Down Expand Up @@ -2421,7 +2421,7 @@ impl_runtime_apis! {
// AccountConversionApi
impl runtime_common::apis::AccountConversionApi<Block, AccountId> for Runtime {
fn conversion_of(location: ::xcm::v3::MultiLocation) -> Option<AccountId> {
AccountConverter::<Runtime, LocationToAccountId<RelayNetwork>>::try_convert(location).ok()
AccountConverter::<Runtime, LocationToAccountId>::try_convert(location).ok()
}
}

Expand Down
25 changes: 13 additions & 12 deletions runtime/centrifuge/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use cfg_traits::TryConvert;
use cfg_types::{tokens::CurrencyId, EVMChainId};
use frame_support::{
parameter_types,
sp_std::marker::PhantomData,
traits::{fungibles, Contains, Everything, Get, Nothing},
traits::{Everything, Get, Nothing},
};
use frame_system::EnsureRoot;
use orml_asset_registry::{AssetRegistryTrader, FixedRateAssetRegistryTrader};
Expand All @@ -29,13 +28,12 @@ use pallet_xcm::XcmPassthrough;
use runtime_common::{
transfer_filter::PreXcmTransfer,
xcm::{
general_key, AccountIdToMultiLocation, Barrier, CurrencyIdConvert,
FixedConversionRateProvider, LocationToAccountId, LpInstanceRelayer, ToTreasury,
general_key, AccountIdToMultiLocation, Barrier, FixedConversionRateProvider,
LpInstanceRelayer, ToTreasury,
},
xcm_fees::native_per_second,
};
use sp_core::ConstU32;
use sp_runtime::traits::Zero;
use xcm::{
prelude::*,
v3::{MultiLocation, Weight as XcmWeight},
Expand Down Expand Up @@ -78,7 +76,7 @@ impl frame_support::traits::Contains<RuntimeCall> for SafeCallFilter {
| RuntimeCall::Proxy(..)
| RuntimeCall::LiquidityPoolsGateway(
pallet_liquidity_pools_gateway::Call::process_msg { .. }
) // TODO: Enable later: | RuntimeCall::OrderBook(..)
) | RuntimeCall::OrderBook(..)
)
}
}
Expand Down Expand Up @@ -145,9 +143,9 @@ pub type FungiblesTransactor = FungiblesAdapter<
Tokens,
// This means that this adapter should handle any token that `CurrencyIdConvert` can convert
// to `CurrencyId`, the `CurrencyId` type of `Tokens`, the fungibles implementation it uses.
ConvertedConcreteId<CurrencyId, Balance, CurrencyIdConvert<Runtime>, JustTry>,
ConvertedConcreteId<CurrencyId, Balance, CurrencyIdConvert, JustTry>,
// Convert an XCM MultiLocation into a local account id
LocationToAccountId<RelayNetwork>,
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly)
AccountId,
// We dont want to allow teleporting assets
Expand Down Expand Up @@ -184,7 +182,7 @@ impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type SovereignAccountOf = LocationToAccountId<RelayNetwork>;
type SovereignAccountOf = LocationToAccountId;
type TrustedLockers = ();
type UniversalLocation = UniversalLocation;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
Expand All @@ -205,6 +203,9 @@ parameter_types! {
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}

pub type CurrencyIdConvert = runtime_common::xcm::CurrencyIdConvert<Runtime>;
pub type LocationToAccountId = runtime_common::xcm::LocationToAccountId<RelayNetwork>;

/// No local origins on this chain are allowed to dispatch XCM sends/executions.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

Expand Down Expand Up @@ -245,7 +246,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
// foreign chains who want to have a local sovereign account on this chain which they control.
SovereignSignedViaLocation<LocationToAccountId<RelayNetwork>, RuntimeOrigin>,
SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when
// recognized.
RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
Expand Down Expand Up @@ -284,7 +285,7 @@ impl orml_xtokens::Config for Runtime {
type Balance = Balance;
type BaseXcmWeight = BaseXcmWeight;
type CurrencyId = CurrencyId;
type CurrencyIdConvert = CurrencyIdConvert<Self>;
type CurrencyIdConvert = CurrencyIdConvert;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type MinXcmFee = ParachainMinFee;
type MultiLocationsFilter = Everything;
Expand All @@ -297,7 +298,7 @@ impl orml_xtokens::Config for Runtime {
}

impl pallet_restricted_xtokens::Config for Runtime {
type PreTransfer = PreXcmTransfer<super::TransferAllowList, CurrencyIdConvert<Self>>;
type PreTransfer = PreXcmTransfer<super::TransferAllowList, CurrencyIdConvert>;
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand Down
14 changes: 7 additions & 7 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ use runtime_common::{
},
permissions::PoolAdminCheck,
transfer_filter::PreLpTransfer,
xcm::{AccountIdToMultiLocation, CurrencyIdConvert, LocationToAccountId},
xcm::AccountIdToMultiLocation,
xcm_transactor, AllowanceDeposit, CurrencyED, HoldId,
};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -1271,7 +1271,7 @@ impl pallet_xcm_transactor::Config for Runtime {
type Balance = Balance;
type BaseXcmWeight = BaseXcmWeight;
type CurrencyId = CurrencyId;
type CurrencyIdToMultiLocation = CurrencyIdConvert<Self>;
type CurrencyIdToMultiLocation = CurrencyIdConvert;
type DerivativeAddressRegistrationOrigin = EnsureRoot<AccountId>;
type HrmpEncoder = moonbeam_relay_encoder::westend::WestendEncoder;
type HrmpManipulatorOrigin = EnsureRootOr<HalfOfCouncil>;
Expand Down Expand Up @@ -1829,8 +1829,8 @@ impl pallet_liquidity_pools::Config for Runtime {
type Balance = Balance;
type BalanceRatio = Ratio;
type CurrencyId = CurrencyId;
type DomainAccountToAccountId = AccountConverter<Runtime, LocationToAccountId<RelayNetwork>>;
type DomainAddressToAccountId = AccountConverter<Runtime, LocationToAccountId<RelayNetwork>>;
type DomainAccountToAccountId = AccountConverter<Runtime, LocationToAccountId>;
type DomainAddressToAccountId = AccountConverter<Runtime, LocationToAccountId>;
type ForeignInvestment = ForeignInvestments;
type GeneralCurrencyPrefix = GeneralCurrencyPrefix;
type OutboundQueue = LiquidityPoolsGateway;
Expand All @@ -1850,7 +1850,7 @@ impl pallet_liquidity_pools::Config for Runtime {

parameter_types! {
pub const MaxIncomingMessageSize: u32 = 1024;
pub Sender: AccountId = GatewayAccountProvider::<Runtime, LocationToAccountId<RelayNetwork>>::get_gateway_account();
pub Sender: AccountId = GatewayAccountProvider::<Runtime, LocationToAccountId>::get_gateway_account();
}

impl pallet_liquidity_pools_gateway::Config for Runtime {
Expand Down Expand Up @@ -1943,7 +1943,7 @@ parameter_types! {
}

impl pallet_evm::Config for Runtime {
type AddressMapping = AccountConverter<Runtime, LocationToAccountId<RelayNetwork>>;
type AddressMapping = AccountConverter<Runtime, LocationToAccountId>;
type BlockGasLimit = BlockGasLimit;
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;
type CallOrigin = EnsureAddressTruncated;
Expand Down Expand Up @@ -2467,7 +2467,7 @@ impl_runtime_apis! {
// AccountConversionApi
impl runtime_common::apis::AccountConversionApi<Block, AccountId> for Runtime {
fn conversion_of(location: MultiLocation) -> Option<AccountId> {
AccountConverter::<Runtime, LocationToAccountId<RelayNetwork>>::try_convert(location).ok()
AccountConverter::<Runtime, LocationToAccountId>::try_convert(location).ok()
}
}

Expand Down
Loading

0 comments on commit fa66bdc

Please sign in to comment.