Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: update_asset_metadata updates min_balance and is_sufficient #1059

Draft
wants to merge 1 commit into
base: manta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pallets/asset-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ pub mod pallet {
<T::AssetConfig as AssetConfig<T>>::AssetRegistry::update_asset_metadata(
&asset_id,
metadata.clone().into(),
metadata.min_balance().to_owned(),
metadata.is_sufficient()
)?;
AssetIdMetadata::<T>::insert(asset_id, &metadata);
Self::deposit_event(Event::<T>::AssetMetadataUpdated { asset_id, metadata });
Expand Down
11 changes: 11 additions & 0 deletions primitives/manta/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,20 @@ pub trait AssetRegistry: AssetIdType + BalanceType {
///
/// * `asset_id`: the asset id to be created.
/// * `metadata`: the metadata that the implementation layer stores.
/// * `min_balance`: the minimum balance to hold this asset
/// * `is_sufficient`: whether this asset can be used as reserve asset,
/// to the first approximation. More specifically, Whether a non-zero balance of this asset
/// is deposit of sufficient value to account for the state bloat associated with its
/// balance storage. If set to `true`, then non-zero balances may be stored without a
/// `consumer` reference (and thus an ED in the Balances pallet or whatever else is used to
/// control user-account state growth).
/// WARNING: Exercise extreme caution when changing `min_balance` or `is_sufficient`,
/// ** these can put user's accounts into an invalid existing-but-below-ED state **
fn update_asset_metadata(
asset_id: &Self::AssetId,
metadata: Self::Metadata,
min_balance: Self::Balance,
is_sufficient: bool,
) -> Result<(), Self::Error>;
}

Expand Down
13 changes: 13 additions & 0 deletions runtime/calamari/src/assets_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ impl AssetRegistry for CalamariAssetRegistry {
fn update_asset_metadata(
asset_id: &CalamariAssetId,
metadata: AssetStorageMetadata,
min_balance: Self::Balance,
is_sufficient: bool,
) -> DispatchResult {
Assets::force_set_metadata(
Origin::root(),
Expand All @@ -113,6 +115,17 @@ impl AssetRegistry for CalamariAssetRegistry {
metadata.symbol,
metadata.decimals,
metadata.is_frozen,
)?;
Assets::force_asset_status(
Origin::root(),
*asset_id,
sp_runtime::MultiAddress::Id(AssetManager::account_id()),
sp_runtime::MultiAddress::Id(AssetManager::account_id()),
sp_runtime::MultiAddress::Id(AssetManager::account_id()),
sp_runtime::MultiAddress::Id(AssetManager::account_id()),
min_balance,
is_sufficient,
metadata.is_frozen,
)
}
}
Expand Down
13 changes: 13 additions & 0 deletions runtime/dolphin/src/assets_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ impl AssetRegistry for MantaAssetRegistry {
fn update_asset_metadata(
asset_id: &DolphinAssetId,
metadata: AssetStorageMetadata,
min_balance: Self::Balance,
is_sufficient: bool,
) -> DispatchResult {
Assets::force_set_metadata(
Origin::root(),
Expand All @@ -116,6 +118,17 @@ impl AssetRegistry for MantaAssetRegistry {
metadata.symbol,
metadata.decimals,
metadata.is_frozen,
)?;
Assets::force_asset_status(
Origin::root(),
*asset_id,
sp_runtime::MultiAddress::Id(AssetManager::account_id()),
sp_runtime::MultiAddress::Id(AssetManager::account_id()),
sp_runtime::MultiAddress::Id(AssetManager::account_id()),
sp_runtime::MultiAddress::Id(AssetManager::account_id()),
min_balance,
is_sufficient,
metadata.is_frozen,
)
}
}
Expand Down