mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Remove generic asset palet (#7156)
This commit is contained in:
Generated
-14
@@ -4541,20 +4541,6 @@ dependencies = [
|
||||
"sp-std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pallet-generic-asset"
|
||||
version = "2.0.0-rc6"
|
||||
dependencies = [
|
||||
"frame-support",
|
||||
"frame-system",
|
||||
"parity-scale-codec",
|
||||
"serde",
|
||||
"sp-core",
|
||||
"sp-io",
|
||||
"sp-runtime",
|
||||
"sp-std",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pallet-grandpa"
|
||||
version = "2.0.0-rc6"
|
||||
|
||||
@@ -79,7 +79,6 @@ members = [
|
||||
"frame/example-offchain-worker",
|
||||
"frame/executive",
|
||||
"frame/finality-tracker",
|
||||
"frame/generic-asset",
|
||||
"frame/grandpa",
|
||||
"frame/identity",
|
||||
"frame/im-online",
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
[package]
|
||||
name = "pallet-generic-asset"
|
||||
version = "2.0.0-rc6"
|
||||
authors = ["Centrality Developers <support@centrality.ai>"]
|
||||
edition = "2018"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://substrate.dev"
|
||||
repository = "https://github.com/paritytech/substrate/"
|
||||
description = "FRAME pallet for generic asset management"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.101", optional = true }
|
||||
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] }
|
||||
sp-std = { version = "2.0.0-rc6", default-features = false, path = "../../primitives/std" }
|
||||
sp-runtime = { version = "2.0.0-rc6", default-features = false, path = "../../primitives/runtime" }
|
||||
frame-support = { version = "2.0.0-rc6", default-features = false, path = "../support" }
|
||||
frame-system = { version = "2.0.0-rc6", default-features = false, path = "../system" }
|
||||
|
||||
[dev-dependencies]
|
||||
sp-io ={ version = "2.0.0-rc6", path = "../../primitives/io" }
|
||||
sp-core = { version = "2.0.0-rc6", path = "../../primitives/core" }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std =[
|
||||
"serde/std",
|
||||
"codec/std",
|
||||
"sp-std/std",
|
||||
"sp-runtime/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
]
|
||||
@@ -1,131 +0,0 @@
|
||||
# Generic Asset Module
|
||||
|
||||
The Generic Asset module provides functionality for handling accounts and asset balances.
|
||||
|
||||
## Overview
|
||||
|
||||
The Generic Asset module provides functions for:
|
||||
|
||||
- Creating a new kind of asset.
|
||||
- Setting permissions of an asset.
|
||||
- Getting and setting free balances.
|
||||
- Retrieving total, reserved and unreserved balances.
|
||||
- Repatriating a reserved balance to a beneficiary account.
|
||||
- Transferring a balance between accounts (when not reserved).
|
||||
- Slashing an account balance.
|
||||
- Managing total issuance.
|
||||
- Setting and managing locks.
|
||||
|
||||
### Terminology
|
||||
|
||||
- **Staking Asset:** The asset for staking, to participate as Validators in the network.
|
||||
- **Spending Asset:** The asset for payment, such as paying transfer fees, gas fees, etc.
|
||||
- **Permissions:** A set of rules for a kind of asset, defining the allowed operations to the asset, and which
|
||||
accounts are allowed to possess it.
|
||||
- **Total Issuance:** The total number of units in existence in a system.
|
||||
- **Free Balance:** The portion of a balance that is not reserved. The free balance is the only balance that matters
|
||||
for most operations. When this balance falls below the existential deposit, most functionality of the account is
|
||||
removed. When both it and the reserved balance are deleted, then the account is said to be dead.
|
||||
- **Reserved Balance:** Reserved balance still belongs to the account holder, but is suspended. Reserved balance
|
||||
can still be slashed, but only after all the free balance has been slashed. If the reserved balance falls below the
|
||||
existential deposit then it and any related functionality will be deleted. When both it and the free balance are
|
||||
deleted, then the account is said to be dead.
|
||||
- **Imbalance:** A condition when some assets were credited or debited without equal and opposite accounting
|
||||
(i.e. a difference between total issuance and account balances). Functions that result in an imbalance will
|
||||
return an object of the `Imbalance` trait that can be managed within your runtime logic. (If an imbalance is
|
||||
simply dropped, it should automatically maintain any book-keeping such as total issuance.)
|
||||
- **Lock:** A freeze on a specified amount of an account's free balance until a specified block number. Multiple
|
||||
locks always operate over the same funds, so they "overlay" rather than "stack".
|
||||
|
||||
### Implementations
|
||||
|
||||
The Generic Asset module provides `AssetCurrency`, which implements the following traits. If these traits provide
|
||||
the functionality that you need, you can avoid coupling with the Generic Asset module.
|
||||
|
||||
- `Currency`: Functions for dealing with a fungible assets system.
|
||||
- `ReservableCurrency`: Functions for dealing with assets that can be reserved from an account.
|
||||
- `LockableCurrency`: Functions for dealing with accounts that allow liquidity restrictions.
|
||||
- `Imbalance`: Functions for handling imbalances between total issuance in the system and account balances.
|
||||
Must be used when a function creates new assets (e.g. a reward) or destroys some assets (e.g. a system fee).
|
||||
|
||||
The Generic Asset module provides two types of `AssetCurrency` as follows.
|
||||
|
||||
- `StakingAssetCurrency`: Currency for staking.
|
||||
- `SpendingAssetCurrency`: Currency for payments such as transfer fee, gas fee.
|
||||
|
||||
## Interface
|
||||
|
||||
### Dispatchable Functions
|
||||
|
||||
- `create`: Create a new kind of asset.
|
||||
- `transfer`: Transfer some liquid free balance to another account.
|
||||
- `update_permission`: Updates permission for a given `asset_id` and an account. The origin of this call
|
||||
must have update permissions.
|
||||
- `mint`: Mint an asset, increases its total issuance. The origin of this call must have mint permissions.
|
||||
- `burn`: Burn an asset, decreases its total issuance. The origin of this call must have burn permissions.
|
||||
- `create_reserved`: Create a new kind of reserved asset. The origin of this call must be root.
|
||||
|
||||
### Public Functions
|
||||
|
||||
- `total_balance`: Get an account's total balance of an asset kind.
|
||||
- `free_balance`: Get an account's free balance of an asset kind.
|
||||
- `reserved_balance`: Get an account's reserved balance of an asset kind.
|
||||
- `create_asset`: Creates an asset.
|
||||
- `make_transfer`: Transfer some liquid free balance from one account to another.
|
||||
This will not emit the `Transferred` event.
|
||||
- `make_transfer_with_event`: Transfer some liquid free balance from one account to another.
|
||||
This will emit the `Transferred` event.
|
||||
- `reserve`: Moves an amount from free balance to reserved balance.
|
||||
- `unreserve`: Move up to an amount from reserved balance to free balance. This function cannot fail.
|
||||
- `mint_free`: Mint to an account's free balance.
|
||||
- `burn_free`: Burn an account's free balance.
|
||||
- `slash`: Deduct up to an amount from the combined balance of `who`, preferring to deduct from the
|
||||
free balance. This function cannot fail.
|
||||
- `slash_reserved`: Deduct up to an amount from reserved balance of an account. This function cannot fail.
|
||||
- `repatriate_reserved`: Move up to an amount from reserved balance of an account to free balance of another
|
||||
account.
|
||||
- `check_permission`: Check permission to perform burn, mint or update.
|
||||
- `ensure_can_withdraw`: Check if the account is able to make a withdrawal of the given amount
|
||||
for the given reason.
|
||||
|
||||
### Usage
|
||||
|
||||
The following examples show how to use the Generic Asset Pallet in your custom pallet.
|
||||
|
||||
### Examples from the FRAME pallet
|
||||
|
||||
The Fees Pallet uses the `Currency` trait to handle fee charge/refund, and its types inherit from `Currency`:
|
||||
|
||||
```rust
|
||||
use frame_support::{
|
||||
dispatch,
|
||||
traits::{Currency, ExistenceRequirement, WithdrawReason},
|
||||
};
|
||||
type AssetOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
|
||||
|
||||
fn charge_fee<T: Trait>(transactor: &T::AccountId, amount: AssetOf<T>) -> dispatch::DispatchResult {
|
||||
// ...
|
||||
T::Currency::withdraw(
|
||||
transactor,
|
||||
amount,
|
||||
WithdrawReason::TransactionPayment.into(),
|
||||
ExistenceRequirement::KeepAlive,
|
||||
)?;
|
||||
// ...
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn refund_fee<T: Trait>(transactor: &T::AccountId, amount: AssetOf<T>) -> dispatch::DispatchResult {
|
||||
// ...
|
||||
T::Currency::deposit_into_existing(transactor, amount)?;
|
||||
// ...
|
||||
Ok(())
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Genesis config
|
||||
|
||||
The Generic Asset Pallet depends on the [`GenesisConfig`](./struct.GenesisConfig.html).
|
||||
|
||||
License: Apache-2.0
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,152 +0,0 @@
|
||||
// Copyright 2019-2020
|
||||
// by Centrality Investments Ltd.
|
||||
// and Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// 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.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Mocks for the module.
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use sp_runtime::{
|
||||
Perbill,
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
};
|
||||
use sp_core::H256;
|
||||
use frame_support::{parameter_types, impl_outer_event, impl_outer_origin, weights::Weight};
|
||||
|
||||
use super::*;
|
||||
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test where system = frame_system {}
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const MaximumBlockWeight: Weight = 1024;
|
||||
pub const MaximumBlockLength: u32 = 2 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
||||
}
|
||||
impl frame_system::Trait for Test {
|
||||
type BaseCallFilter = ();
|
||||
type Origin = Origin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Call = ();
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<u64>;
|
||||
type Header = Header;
|
||||
type Event = TestEvent;
|
||||
type MaximumBlockWeight = MaximumBlockWeight;
|
||||
type DbWeight = ();
|
||||
type BlockExecutionWeight = ();
|
||||
type ExtrinsicBaseWeight = ();
|
||||
type MaximumExtrinsicWeight = MaximumBlockWeight;
|
||||
type MaximumBlockLength = MaximumBlockLength;
|
||||
type AvailableBlockRatio = AvailableBlockRatio;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
}
|
||||
|
||||
impl Trait for Test {
|
||||
type Balance = u64;
|
||||
type AssetId = u32;
|
||||
type Event = TestEvent;
|
||||
}
|
||||
|
||||
mod generic_asset {
|
||||
pub use crate::Event;
|
||||
}
|
||||
|
||||
use frame_system as system;
|
||||
impl_outer_event! {
|
||||
pub enum TestEvent for Test {
|
||||
system<T>,
|
||||
generic_asset<T>,
|
||||
}
|
||||
}
|
||||
|
||||
pub type GenericAsset = Module<Test>;
|
||||
|
||||
pub type System = frame_system::Module<Test>;
|
||||
|
||||
pub struct ExtBuilder {
|
||||
asset_id: u32,
|
||||
next_asset_id: u32,
|
||||
accounts: Vec<u64>,
|
||||
initial_balance: u64,
|
||||
}
|
||||
|
||||
// Returns default values for genesis config
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
asset_id: 0,
|
||||
next_asset_id: 1000,
|
||||
accounts: vec![0],
|
||||
initial_balance: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExtBuilder {
|
||||
// Sets free balance to genesis config
|
||||
pub fn free_balance(mut self, free_balance: (u32, u64, u64)) -> Self {
|
||||
self.asset_id = free_balance.0;
|
||||
self.accounts = vec![free_balance.1];
|
||||
self.initial_balance = free_balance.2;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn next_asset_id(mut self, asset_id: u32) -> Self {
|
||||
self.next_asset_id = asset_id;
|
||||
self
|
||||
}
|
||||
|
||||
// builds genesis config
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
|
||||
GenesisConfig::<Test> {
|
||||
assets: vec![self.asset_id],
|
||||
endowed_accounts: self.accounts,
|
||||
initial_balance: self.initial_balance,
|
||||
next_asset_id: self.next_asset_id,
|
||||
staking_asset_id: 16000,
|
||||
spending_asset_id: 16001,
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
|
||||
let mut ext = sp_io::TestExternalities::new(t);
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
frame_system::GenesisConfig::default()
|
||||
.build_storage::<Test>()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user