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

333 extend the orml tokens pallet so users are able to mint and burn custom assets #359

Merged
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"pallets/parachain-staking",
"pallets/vesting-manager",
"pallets/orml-currencies-allowance-extension",
"pallets/orml-tokens-management-extension",
"runtime/common",
"runtime/amplitude",
"runtime/foucoco",
Expand Down
61 changes: 61 additions & 0 deletions pallets/orml-tokens-management-extension/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[package]
authors = ["Pendulum Chain"]
edition = "2021"
name = "orml-tokens-management-extension"
version = "1.0.0"

[dependencies]
codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "max-encoded-len"]}
scale-info = {version = "2.2.0", default-features = false, features = ["derive"]}
serde = {version = "1.0.130", default-features = false, features = ["derive"], optional = true}
sha2 = {version = "0.8.2", default-features = false}

# Substrate dependencies
frame-support = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false}
frame-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false}
sp-core = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false}
sp-runtime = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false}
sp-std = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false}

frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false, optional = true }

orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.40", default-features = false }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.40", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.40", default-features = false }



[dev-dependencies]
mocktopus = "0.8.0"
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false}

pallet-balances = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40"}

# Spacewalk libraries
spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "d05b0015d15ca39cc780889bcc095335e9862a36"}


[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sha2/std",
"sp-core/std",
"sp-std/std",
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"orml-currencies/std",
"orml-tokens/std",
"orml-traits/std",
"frame-benchmarking/std",
"spacewalk-primitives/std"
]

runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
100 changes: 100 additions & 0 deletions pallets/orml-tokens-management-extension/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#![allow(warnings)]
use super::{Pallet as TokenExtension, *};

use crate::types::{AccountIdOf, BalanceOf, CurrencyOf};
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_support::assert_ok;
use frame_system::RawOrigin;
use orml_traits::{
arithmetic::{One, Zero},
MultiCurrency,
};
use sp_runtime::traits::Get;
use sp_std::prelude::*;

const AMOUNT_MINTED: u32 = 2000000000;
const AMOUNT_BURNED: u32 = 1000000000;

fn get_test_currency<T: Config>() -> CurrencyOf<T> {
<T as orml_currencies::Config>::GetNativeCurrencyId::get()
}

// mint some tokens to the account
fn set_up_account<T: Config>(account: &AccountIdOf<T>) {
let token_currency_id = get_test_currency::<T>();

assert_ok!(<orml_currencies::Pallet<T> as MultiCurrency<AccountIdOf<T>>>::deposit(
token_currency_id,
&account,
<T as crate::Config>::AssetDeposit::get()
));
}

benchmarks! {
create {
let token_currency_id = get_test_currency::<T>();
let test_account = account("Tester", 0, 0);
set_up_account::<T>(&test_account);
let origin = RawOrigin::Signed(test_account);
}: _(origin,token_currency_id)
verify {
assert!(crate::Pallet::<T>::currency_details(token_currency_id).is_some());
}

mint {
let token_currency_id = get_test_currency::<T>();
let test_account = account("Tester", 0, 0);
set_up_account::<T>(&test_account);
let origin = RawOrigin::Signed(test_account);
let destination = account::<AccountIdOf<T>>("Receiver", 0, 0);
assert_ok!(TokenExtension::<T>::create(origin.clone().into(), token_currency_id));

}: _(origin,token_currency_id, destination.clone(),AMOUNT_MINTED.into())
verify {
assert_eq!(<orml_currencies::Pallet<T> as MultiCurrency<AccountIdOf<T>>>::total_balance(token_currency_id, &destination), AMOUNT_MINTED.into());
}

burn {
let token_currency_id = get_test_currency::<T>();
let test_account = account("Tester", 0, 0);
set_up_account::<T>(&test_account);
let origin = RawOrigin::Signed(test_account);
let destination = account::<AccountIdOf<T>>("Receiver", 0, 0);
assert_ok!(TokenExtension::<T>::create(origin.clone().into(), token_currency_id));
assert_ok!(TokenExtension::<T>::mint(origin.clone().into(), token_currency_id, destination.clone(), AMOUNT_MINTED.into()));

}: _(origin,token_currency_id, destination.clone(),AMOUNT_BURNED.into())
verify {
assert_eq!(<orml_currencies::Pallet<T> as MultiCurrency<AccountIdOf<T>>>::total_balance(token_currency_id, &destination), (AMOUNT_MINTED-AMOUNT_BURNED).into());
}

transfer_ownership {
let token_currency_id = get_test_currency::<T>();
let test_account = account("Tester", 0, 0);
set_up_account::<T>(&test_account);
let origin = RawOrigin::Signed(test_account);
let new_owner = account::<AccountIdOf<T>>("NewOwner", 0, 0);
set_up_account::<T>(&new_owner);
assert_ok!(TokenExtension::<T>::create(origin.clone().into(), token_currency_id));

}: _(origin,token_currency_id, new_owner)
verify {
assert!(crate::Pallet::<T>::currency_details(token_currency_id).is_some());
}

set_managers {
let token_currency_id = get_test_currency::<T>();
let test_account = account("Tester", 0, 0);
set_up_account::<T>(&test_account);
let origin = RawOrigin::Signed(test_account);
let new_issuer = account::<AccountIdOf<T>>("Issuer", 0, 0);
let new_admin = account::<AccountIdOf<T>>("Admin", 0, 0);
assert_ok!(TokenExtension::<T>::create(origin.clone().into(), token_currency_id));

}: _(origin,token_currency_id, new_issuer, new_admin)
verify {
assert!(crate::Pallet::<T>::currency_details(token_currency_id).is_some());
}
}

impl_benchmark_test_suite!(TokenExtension, crate::mock::ExtBuilder::build(), crate::mock::Test);
181 changes: 181 additions & 0 deletions pallets/orml-tokens-management-extension/src/default_weights.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@

//! Autogenerated weights for orml_tokens_management_extension
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-12-08, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `192.168.1.6`, CPU: `<UNKNOWN>`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("foucoco"), DB CACHE: 1024

// Executed Command:
// ./target/production/pendulum-node
// benchmark
// pallet
// --chain
// foucoco
// --execution=wasm
// --wasm-execution=compiled
// --pallet
// orml-tokens-management-extension
// --extrinsic
// *
// --steps
// 50
// --repeat
// 20
// --output
// pallets/orml-tokens-management-extension/src/default_weights.rs
// --template
// .maintain/frame-weight-template.hbs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use core::marker::PhantomData;

/// Weight functions needed for orml_tokens_management_extension.
pub trait WeightInfo {
fn create() -> Weight;
fn mint() -> Weight;
fn burn() -> Weight;
fn transfer_ownership() -> Weight;
fn set_managers() -> Weight;
}

/// Weights for orml_tokens_management_extension using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: OrmlExtension CurrencyData (r:1 w:1)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
fn create() -> Weight {
// Proof Size summary in bytes:
// Measured: `179`
// Estimated: `7232`
// Minimum execution time: 25_000_000 picoseconds.
Weight::from_parts(26_000_000, 7232)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: OrmlExtension CurrencyData (r:1 w:0)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
fn mint() -> Weight {
// Proof Size summary in bytes:
// Measured: `233`
// Estimated: `7232`
// Minimum execution time: 35_000_000 picoseconds.
Weight::from_parts(36_000_000, 7232)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: OrmlExtension CurrencyData (r:1 w:0)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
fn burn() -> Weight {
// Proof Size summary in bytes:
// Measured: `336`
// Estimated: `7232`
// Minimum execution time: 29_000_000 picoseconds.
Weight::from_parts(30_000_000, 7232)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: OrmlExtension CurrencyData (r:1 w:1)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
/// Storage: System Account (r:2 w:2)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
fn transfer_ownership() -> Weight {
// Proof Size summary in bytes:
// Measured: `439`
// Estimated: `9835`
// Minimum execution time: 36_000_000 picoseconds.
Weight::from_parts(37_000_000, 9835)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
/// Storage: OrmlExtension CurrencyData (r:1 w:1)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
fn set_managers() -> Weight {
// Proof Size summary in bytes:
// Measured: `233`
// Estimated: `3639`
// Minimum execution time: 15_000_000 picoseconds.
Weight::from_parts(16_000_000, 3639)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

// For backwards compatibility and tests
impl WeightInfo for () {
/// Storage: OrmlExtension CurrencyData (r:1 w:1)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
fn create() -> Weight {
// Proof Size summary in bytes:
// Measured: `179`
// Estimated: `7232`
// Minimum execution time: 25_000_000 picoseconds.
Weight::from_parts(26_000_000, 7232)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
/// Storage: OrmlExtension CurrencyData (r:1 w:0)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
fn mint() -> Weight {
// Proof Size summary in bytes:
// Measured: `233`
// Estimated: `7232`
// Minimum execution time: 35_000_000 picoseconds.
Weight::from_parts(36_000_000, 7232)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: OrmlExtension CurrencyData (r:1 w:0)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
fn burn() -> Weight {
// Proof Size summary in bytes:
// Measured: `336`
// Estimated: `7232`
// Minimum execution time: 29_000_000 picoseconds.
Weight::from_parts(30_000_000, 7232)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: OrmlExtension CurrencyData (r:1 w:1)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
/// Storage: System Account (r:2 w:2)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
fn transfer_ownership() -> Weight {
// Proof Size summary in bytes:
// Measured: `439`
// Estimated: `9835`
// Minimum execution time: 36_000_000 picoseconds.
Weight::from_parts(37_000_000, 9835)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
/// Storage: OrmlExtension CurrencyData (r:1 w:1)
/// Proof: OrmlExtension CurrencyData (max_values: None, max_size: Some(174), added: 2649, mode: MaxEncodedLen)
fn set_managers() -> Weight {
// Proof Size summary in bytes:
// Measured: `233`
// Estimated: `3639`
// Minimum execution time: 15_000_000 picoseconds.
Weight::from_parts(16_000_000, 3639)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
Loading
Loading