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
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
"pallets/parachain-staking",
"pallets/vesting-manager",
"pallets/orml-currencies-allowance-extension",
"pallets/orml-tokens-extension",
"pallets/orml-tokens-management-extension",
"runtime/common",
"runtime/amplitude",
"runtime/foucoco",
Expand Down
17 changes: 16 additions & 1 deletion pallets/orml-currencies-allowance-extension/src/mock.rs
gianfra-t marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,27 @@ impl ExtBuilder {
}
}

pub const USER1 = 1;
pub const USER2 = 2;
pub const USER2 = 3;

pub const USER_INITIAL_BALANCE = 100000;

pub fn run_test<T>(test: T)
where
T: FnOnce(),
{
ExtBuilder::build().execute_with(|| {
System::set_block_number(1);
test();

let mut storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();

pallet_balances::GenesisConfig::<Test> {
balances: vec![(USER1,USER_INITIAL_BALANCE),
(USER1,USER_INITIAL_BALANCE),
(USER1,USER_INITIAL_BALANCE)]
}
.assimilate_storage(&mut storage)
.unwrap();
});
}
35 changes: 0 additions & 35 deletions pallets/orml-tokens-extension/src/ext.rs

This file was deleted.

230 changes: 0 additions & 230 deletions pallets/orml-tokens-extension/src/tests.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Pendulum Chain"]
edition = "2021"
name = "orml-tokens-extension"
name = "orml-tokens-management-extension"
version = "1.0.0"

[dependencies]
Expand Down
66 changes: 66 additions & 0 deletions pallets/orml-tokens-management-extension/src/ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#[cfg(test)]
use mocktopus::macros::mockable;

#[cfg_attr(test, mockable)]
pub(crate) mod orml_tokens {
use crate::{AccountIdOf, BalanceOf, CurrencyOf};
use orml_traits::{MultiCurrency, MultiReservableCurrency};
use sp_runtime::DispatchError;
use frame_support::traits::BalanceStatus;

pub fn mint<T: crate::Config>(
currency_id: CurrencyOf<T>,
who: &AccountIdOf<T>,
amount: BalanceOf<T>,
) -> Result<(), DispatchError> {
<orml_currencies::Pallet<T> as MultiCurrency<AccountIdOf<T>>>::deposit(
currency_id,
who,
amount,
)?;
Ok(())
}

pub fn burn<T: crate::Config>(
currency_id: CurrencyOf<T>,
who: &AccountIdOf<T>,
amount: BalanceOf<T>,
) -> Result<(), DispatchError> {
<orml_currencies::Pallet<T> as MultiCurrency<AccountIdOf<T>>>::withdraw(
currency_id,
who,
amount,
)?;
Ok(())
}

pub fn reserve<T: crate::Config>(
currency_id: CurrencyOf<T>,
who: &AccountIdOf<T>,
amount: BalanceOf<T>,
) -> Result<(), DispatchError> {
<orml_currencies::Pallet<T> as MultiReservableCurrency<AccountIdOf<T>>>::reserve(
currency_id,
who,
amount,
)?;
Ok(())
}

// moves the reserved balance from "source" to "destination"
pub fn repatriate_reserve<T: crate::Config>(
currency_id: CurrencyOf<T>,
from: &AccountIdOf<T>,
to: &AccountIdOf<T>,
amount: BalanceOf<T>,
) -> Result<(), DispatchError> {
<orml_currencies::Pallet<T> as MultiReservableCurrency<AccountIdOf<T>>>::repatriate_reserved(
currency_id,
from,
to,
amount,
BalanceStatus::Reserved
)?;
Ok(())
}
}
Loading
Loading