Asset Conversion: Pool Account ID derivation with additional Pallet ID seed (#3250)

Introduce `PalletId` as an additional seed parameter for pool's account
id derivation.

The PR also introduces the `pallet_asset_conversion_ops` pallet with a
call to migrate a given pool to thew new account. Additionally
`fungibles::lifetime::ResetTeam` and `fungible::lifetime::Refund`
traits, to facilitate the migration of pools.

---------

Co-authored-by: command-bot <>
This commit is contained in:
Muharem
2024-04-17 12:39:23 +02:00
committed by GitHub
parent e6f3106d89
commit 4e10d3b0a6
31 changed files with 1647 additions and 39 deletions
@@ -925,3 +925,28 @@ impl<
}
}
}
impl<
Left: fungible::Inspect<AccountId>,
Right: fungibles::Inspect<AccountId> + fungibles::Refund<AccountId>,
Criterion: Convert<AssetKind, Either<(), <Right as fungibles::Refund<AccountId>>::AssetId>>,
AssetKind: AssetId,
AccountId,
> fungibles::Refund<AccountId> for UnionOf<Left, Right, Criterion, AssetKind, AccountId>
{
type AssetId = AssetKind;
type Balance = <Right as fungibles::Refund<AccountId>>::Balance;
fn deposit_held(asset: AssetKind, who: AccountId) -> Option<(AccountId, Self::Balance)> {
match Criterion::convert(asset) {
Left(()) => None,
Right(a) => <Right as fungibles::Refund<AccountId>>::deposit_held(a, who),
}
}
fn refund(asset: AssetKind, who: AccountId) -> DispatchResult {
match Criterion::convert(asset) {
Left(()) => Err(DispatchError::Unavailable),
Right(a) => <Right as fungibles::Refund<AccountId>>::refund(a, who),
}
}
}
@@ -15,13 +15,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Traits for creating and destroying assets.
//! Traits for creating, editing and destroying assets.
//!
//! See the [`crate::traits::fungibles`] doc for more information about fungibles traits.
use sp_runtime::{DispatchError, DispatchResult};
use super::Inspect;
use crate::traits::tokens::{AssetId, Balance};
use sp_runtime::{DispatchError, DispatchResult};
/// Trait for providing the ability to create new fungible assets.
pub trait Create<AccountId>: Inspect<AccountId> {
@@ -34,6 +34,22 @@ pub trait Create<AccountId>: Inspect<AccountId> {
) -> DispatchResult;
}
/// Trait for refunding the existence deposit of a target asset account.
///
/// The existence deposit might by necessary and present in cases where the asset held by the
/// account is insufficient for the required storage, or when the system cannot provide a consumer
/// reference for any reason.
pub trait Refund<AccountId> {
/// Means of identifying one asset class from another.
type AssetId: AssetId;
/// Scalar type for representing deposit balance of an account.
type Balance: Balance;
/// Returns the amount of account deposit and depositor address, if any.
fn deposit_held(id: Self::AssetId, who: AccountId) -> Option<(AccountId, Self::Balance)>;
/// Return the deposit (if any) of a target asset account.
fn refund(id: Self::AssetId, who: AccountId) -> DispatchResult;
}
/// Trait for providing the ability to destroy existing fungible assets.
pub trait Destroy<AccountId>: Inspect<AccountId> {
/// Start the destruction an existing fungible asset.
@@ -44,7 +44,7 @@ pub use hold::{
Unbalanced as UnbalancedHold,
};
pub use imbalance::{Credit, Debt, HandleImbalanceDrop, Imbalance};
pub use lifetime::{Create, Destroy};
pub use lifetime::{Create, Destroy, Refund};
pub use regular::{
Balanced, DecreaseIssuance, Dust, IncreaseIssuance, Inspect, Mutate, Unbalanced,
};
@@ -19,6 +19,8 @@
//!
//! See the [`crate::traits::fungibles`] doc for more information about fungibles traits.
use sp_runtime::DispatchResult;
pub trait Inspect<AccountId>: super::Inspect<AccountId> {
// Get owner for an AssetId.
fn owner(asset: Self::AssetId) -> Option<AccountId>;
@@ -29,3 +31,22 @@ pub trait Inspect<AccountId>: super::Inspect<AccountId> {
// Get freezer for an AssetId.
fn freezer(asset: Self::AssetId) -> Option<AccountId>;
}
/// Trait for resetting the team configuration of an existing fungible asset.
pub trait ResetTeam<AccountId>: super::Inspect<AccountId> {
/// Reset the team for the asset with the given `id`.
///
/// ### Parameters
/// - `id`: The identifier of the asset for which the team is being reset.
/// - `owner`: The new `owner` account for the asset.
/// - `admin`: The new `admin` account for the asset.
/// - `issuer`: The new `issuer` account for the asset.
/// - `freezer`: The new `freezer` account for the asset.
fn reset_team(
id: Self::AssetId,
owner: AccountId,
admin: AccountId,
issuer: AccountId,
freezer: AccountId,
) -> DispatchResult;
}
@@ -904,3 +904,35 @@ impl<
}
}
}
impl<
Left: fungibles::Inspect<AccountId> + fungibles::Refund<AccountId>,
Right: fungibles::Inspect<AccountId>
+ fungibles::Refund<AccountId, Balance = <Left as fungibles::Refund<AccountId>>::Balance>,
Criterion: Convert<
AssetKind,
Either<
<Left as fungibles::Refund<AccountId>>::AssetId,
<Right as fungibles::Refund<AccountId>>::AssetId,
>,
>,
AssetKind: AssetId,
AccountId,
> fungibles::Refund<AccountId> for UnionOf<Left, Right, Criterion, AssetKind, AccountId>
{
type AssetId = AssetKind;
type Balance = <Left as fungibles::Refund<AccountId>>::Balance;
fn deposit_held(asset: AssetKind, who: AccountId) -> Option<(AccountId, Self::Balance)> {
match Criterion::convert(asset) {
Left(a) => <Left as fungibles::Refund<AccountId>>::deposit_held(a, who),
Right(a) => <Right as fungibles::Refund<AccountId>>::deposit_held(a, who),
}
}
fn refund(asset: AssetKind, who: AccountId) -> DispatchResult {
match Criterion::convert(asset) {
Left(a) => <Left as fungibles::Refund<AccountId>>::refund(a, who),
Right(a) => <Right as fungibles::Refund<AccountId>>::refund(a, who),
}
}
}