Skip to content

Commit

Permalink
simplify logic, rollback to granular origins per operation
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzamontiel committed Jan 2, 2025
1 parent 0c891f5 commit d3cedc2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 31 deletions.
28 changes: 3 additions & 25 deletions pallets/moonbeam-foreign-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,28 +390,6 @@ pub mod pallet {
AssetsByLocation::<T>::insert(&asset_location, (asset_id, AssetStatus::Active));
AssetsById::<T>::insert(&asset_id, asset_location);
}

/// Ensures that the origin has the required permissions to modifiy an asset
fn ensure_asset_owner(origin: OriginFor<T>, asset_id: AssetId) -> DispatchResult {
let asset_details = AssetsCreationDetails::<T>::get(&asset_id);
let caller = ensure_signed(origin.clone())?;

match asset_details {
Some(data) => match data.owner {
AssetOwner::Account(account) => {
ensure!(account == caller, Error::<T>::OriginIsNotAssetCreator);
}
AssetOwner::Governance | AssetOwner::Root => {
<T as Config>::ForeignAssetFreezerOrigin::ensure_origin(origin)?;
}
},
None => {
<T as Config>::ForeignAssetFreezerOrigin::ensure_origin(origin)?;
}
}

Ok(())
}
}

#[pallet::call]
Expand Down Expand Up @@ -489,7 +467,7 @@ pub mod pallet {
asset_id: AssetId,
new_xcm_location: Location,
) -> DispatchResult {
Self::ensure_asset_owner(origin.clone(), asset_id)?;
T::ForeignAssetModifierOrigin::ensure_origin(origin)?;

let previous_location =
AssetsById::<T>::get(&asset_id).ok_or(Error::<T>::AssetDoesNotExist)?;
Expand Down Expand Up @@ -522,7 +500,7 @@ pub mod pallet {
asset_id: AssetId,
allow_xcm_deposit: bool,
) -> DispatchResult {
Self::ensure_asset_owner(origin.clone(), asset_id)?;
T::ForeignAssetFreezerOrigin::ensure_origin(origin)?;

let xcm_location =
AssetsById::<T>::get(&asset_id).ok_or(Error::<T>::AssetDoesNotExist)?;
Expand Down Expand Up @@ -556,7 +534,7 @@ pub mod pallet {
#[pallet::call_index(3)]
#[pallet::weight(<T as Config>::WeightInfo::unfreeze_foreign_asset())]
pub fn unfreeze_foreign_asset(origin: OriginFor<T>, asset_id: AssetId) -> DispatchResult {
Self::ensure_asset_owner(origin.clone(), asset_id)?;
T::ForeignAssetUnfreezerOrigin::ensure_origin(origin)?;

let xcm_location =
AssetsById::<T>::get(&asset_id).ok_or(Error::<T>::AssetDoesNotExist)?;
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use frame_support::{
traits::{EitherOfDiverse, Everything, Nothing, PalletInfoAccess, TransformOrigin},
};

use frame_system::{EnsureRoot, RawOrigin};
use frame_system::{EnsureRoot, EnsureSigned, RawOrigin};
use sp_core::{ConstU32, H160, H256};
use sp_weights::Weight;
use xcm_builder::{
Expand Down Expand Up @@ -708,7 +708,7 @@ impl pallet_moonbeam_foreign_assets::Config for Runtime {
type AccountIdToH160 = AccountIdToH160;
type AssetIdFilter = EvmForeignAssetIdFilter;
type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin;
type ForeignAssetCreatorOrigin = EnsureSigned<AccountId>;
type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin;
type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin;
type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin;
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbeam/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use sp_runtime::{
};
use sp_weights::Weight;

use frame_system::{EnsureRoot, RawOrigin};
use frame_system::{EnsureRoot, EnsureSigned, RawOrigin};
use sp_core::{ConstU32, H160, H256};

use xcm_builder::{
Expand Down Expand Up @@ -699,7 +699,7 @@ impl pallet_moonbeam_foreign_assets::Config for Runtime {
type AccountIdToH160 = AccountIdToH160;
type AssetIdFilter = EvmForeignAssetIdFilter;
type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin;
type ForeignAssetCreatorOrigin = EnsureSigned<AccountId>;
type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin;
type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin;
type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin;
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonriver/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use sp_runtime::{
};
use sp_weights::Weight;

use frame_system::{EnsureRoot, RawOrigin};
use frame_system::{EnsureRoot, EnsureSigned, RawOrigin};
use sp_core::{ConstU32, H160, H256};

use xcm_builder::{
Expand Down Expand Up @@ -706,7 +706,7 @@ impl pallet_moonbeam_foreign_assets::Config for Runtime {
type AccountIdToH160 = AccountIdToH160;
type AssetIdFilter = EvmForeignAssetIdFilter;
type EvmRunner = EvmRunnerPrecompileOrEthXcm<MoonbeamCall, Self>;
type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin;
type ForeignAssetCreatorOrigin = EnsureSigned<AccountId>;
type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin;
type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin;
type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin;
Expand Down

0 comments on commit d3cedc2

Please sign in to comment.