Skip to content
Merged
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
7 changes: 5 additions & 2 deletions modules/airdrop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use frame_support::{decl_event, decl_module, decl_storage, transactional};
use frame_system::{self as system, ensure_root};
use primitives::{AirDropCurrencyId, Balance};
use sp_runtime::traits::StaticLookup;

mod mock;
mod tests;
Expand Down Expand Up @@ -48,11 +49,12 @@ decl_module! {
#[transactional]
pub fn airdrop(
origin,
to: T::AccountId,
to: <T::Lookup as StaticLookup>::Source,
currency_id: AirDropCurrencyId,
amount: Balance,
) {
ensure_root(origin)?;
let to = T::Lookup::lookup(to)?;
<AirDrops<T>>::mutate(&to, currency_id, |balance| *balance += amount);
Self::deposit_event(RawEvent::Airdrop(to, currency_id, amount));
}
Expand All @@ -61,11 +63,12 @@ decl_module! {
#[transactional]
pub fn update_airdrop(
origin,
to: T::AccountId,
to: <T::Lookup as StaticLookup>::Source,
currency_id: AirDropCurrencyId,
amount: Balance,
) {
ensure_root(origin)?;
let to = T::Lookup::lookup(to)?;
<AirDrops<T>>::insert(&to, currency_id, amount);
Self::deposit_event(RawEvent::UpdateAirdrop(to, currency_id, amount));
}
Expand Down
14 changes: 10 additions & 4 deletions modules/cdp_engine/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use sp_std::vec;
use frame_benchmarking::{account, benchmarks};
use frame_support::traits::Get;
use frame_system::RawOrigin;
use sp_runtime::{traits::UniqueSaturatedInto, DispatchError, FixedPointNumber};
use sp_runtime::{
traits::{StaticLookup, UniqueSaturatedInto},
DispatchError, FixedPointNumber,
};

use cdp_engine::Module as CdpEngine;
use cdp_engine::*;
Expand Down Expand Up @@ -103,6 +106,7 @@ benchmarks! {
let u in 0 .. 1000;

let owner: T::AccountId = account("owner", u, SEED);
let owner_lookup = T::Lookup::unlookup(owner.clone());
let currency_id: CurrencyId = <T as cdp_engine::Config>::CollateralCurrencyIds::get()[0];
let min_debit_value = <T as cdp_engine::Config>::MinimumDebitValue::get();
let debit_exchange_rate = CdpEngine::<T>::get_debit_exchange_rate(currency_id);
Expand Down Expand Up @@ -141,13 +145,14 @@ benchmarks! {
Change::NoChange,
Change::NoChange,
)?;
}: liquidate(RawOrigin::None, currency_id, owner)
}: liquidate(RawOrigin::None, currency_id, owner_lookup)

// `liquidate` by dex
liquidate_by_dex {
let u in 0 .. 1000;

let owner: T::AccountId = account("owner", u, SEED);
let owner_lookup = T::Lookup::unlookup(owner.clone());
let funder: T::AccountId = account("funder", u, SEED);
let currency_id: CurrencyId = <T as cdp_engine::Config>::CollateralCurrencyIds::get()[0];
let base_currency_id: CurrencyId = <T as cdp_engine::Config>::GetStableCurrencyId::get();
Expand Down Expand Up @@ -194,7 +199,7 @@ benchmarks! {
Change::NoChange,
Change::NoChange,
)?;
}: liquidate(RawOrigin::None, currency_id, owner)
}: liquidate(RawOrigin::None, currency_id, owner_lookup)
verify {
let (other_currency_amount, base_currency_amount) = Dex::<T>::get_liquidity_pool(base_currency_id, currency_id);
assert!(other_currency_amount > collateral_amount_in_dex);
Expand All @@ -205,6 +210,7 @@ benchmarks! {
let u in 0 .. 1000;

let owner: T::AccountId = account("owner", u, SEED);
let owner_lookup = T::Lookup::unlookup(owner.clone());
let currency_id: CurrencyId = <T as cdp_engine::Config>::CollateralCurrencyIds::get()[0];
let min_debit_value = <T as cdp_engine::Config>::MinimumDebitValue::get();
let debit_exchange_rate = CdpEngine::<T>::get_debit_exchange_rate(currency_id);
Expand Down Expand Up @@ -235,7 +241,7 @@ benchmarks! {

// shutdown
emergency_shutdown::<T>()?;
}: _(RawOrigin::None, currency_id, owner)
}: _(RawOrigin::None, currency_id, owner_lookup)
}

#[cfg(all(feature = "runtime-benchmarks", test))]
Expand Down
16 changes: 11 additions & 5 deletions modules/cdp_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sp_runtime::{
storage_lock::{StorageLock, Time},
Duration,
},
traits::{BlakeTwo256, Bounded, Convert, Hash, Saturating, Zero},
traits::{BlakeTwo256, Bounded, Convert, Hash, Saturating, StaticLookup, Zero},
transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, ValidTransaction,
},
Expand Down Expand Up @@ -283,9 +283,10 @@ decl_module! {
pub fn liquidate(
origin,
currency_id: CurrencyId,
who: T::AccountId,
who: <T::Lookup as StaticLookup>::Source,
) {
ensure_none(origin)?;
let who = T::Lookup::lookup(who)?;
ensure!(!T::EmergencyShutdown::is_shutdown(), Error::<T>::AlreadyShutdown);
Self::liquidate_unsafe_cdp(who, currency_id)?;
}
Expand All @@ -311,9 +312,10 @@ decl_module! {
pub fn settle(
origin,
currency_id: CurrencyId,
who: T::AccountId,
who: <T::Lookup as StaticLookup>::Source,
) {
ensure_none(origin)?;
let who = T::Lookup::lookup(who)?;
ensure!(T::EmergencyShutdown::is_shutdown(), Error::<T>::MustAfterShutdown);
Self::settle_cdp_has_debit(who, currency_id)?;
}
Expand Down Expand Up @@ -449,6 +451,7 @@ decl_module! {

impl<T: Config> Module<T> {
fn submit_unsigned_liquidation_tx(currency_id: CurrencyId, who: T::AccountId) {
let who = T::Lookup::unlookup(who);
let call = Call::<T>::liquidate(currency_id, who.clone());
if SubmitTransaction::<T, Call<T>>::submit_unsigned_transaction(call.into()).is_err() {
debug::info!(
Expand All @@ -460,6 +463,7 @@ impl<T: Config> Module<T> {
}

fn submit_unsigned_settlement_tx(currency_id: CurrencyId, who: T::AccountId) {
let who = T::Lookup::unlookup(who);
let call = Call::<T>::settle(currency_id, who.clone());
if SubmitTransaction::<T, Call<T>>::submit_unsigned_transaction(call.into()).is_err() {
debug::info!(
Expand Down Expand Up @@ -776,7 +780,8 @@ impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
match call {
Call::liquidate(currency_id, who) => {
let Position { collateral, debit } = <LoansOf<T>>::positions(currency_id, &who);
let account = T::Lookup::lookup(who.clone())?;
let Position { collateral, debit } = <LoansOf<T>>::positions(currency_id, &account);
if !Self::is_cdp_unsafe(*currency_id, collateral, debit) || T::EmergencyShutdown::is_shutdown() {
return InvalidTransaction::Stale.into();
}
Expand All @@ -789,7 +794,8 @@ impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
.build()
}
Call::settle(currency_id, who) => {
let Position { debit, .. } = <LoansOf<T>>::positions(currency_id, who);
let account = T::Lookup::lookup(who.clone())?;
let Position { debit, .. } = <LoansOf<T>>::positions(currency_id, account);
if debit.is_zero() || !T::EmergencyShutdown::is_shutdown() {
return InvalidTransaction::Stale.into();
}
Expand Down
21 changes: 13 additions & 8 deletions modules/honzon/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use frame_benchmarking::{account, benchmarks};
use frame_support::traits::Get;
use frame_system::RawOrigin;
use sp_runtime::{
traits::{Saturating, UniqueSaturatedInto},
traits::{Saturating, StaticLookup, UniqueSaturatedInto},
FixedPointNumber,
};

Expand Down Expand Up @@ -46,19 +46,21 @@ benchmarks! {

let caller: T::AccountId = account("caller", u, SEED);
let to: T::AccountId = account("to", u, SEED);
}: _(RawOrigin::Signed(caller), CurrencyId::Token(TokenSymbol::DOT), to)
let to_lookup = T::Lookup::unlookup(to);
}: _(RawOrigin::Signed(caller), CurrencyId::Token(TokenSymbol::DOT), to_lookup)

unauthorize {
let u in 0 .. 1000;

let caller: T::AccountId = account("caller", u, SEED);
let to: T::AccountId = account("to", u, SEED);
let to_lookup = T::Lookup::unlookup(to);
Honzon::<T>::authorize(
RawOrigin::Signed(caller.clone()).into(),
CurrencyId::Token(TokenSymbol::DOT),
to.clone()
to_lookup.clone()
)?;
}: _(RawOrigin::Signed(caller), CurrencyId::Token(TokenSymbol::DOT), to)
}: _(RawOrigin::Signed(caller), CurrencyId::Token(TokenSymbol::DOT), to_lookup)

unauthorize_all {
let u in 0 .. 1000;
Expand All @@ -70,12 +72,13 @@ benchmarks! {

for i in 0 .. v {
let to: T::AccountId = account("to", i, SEED);
let to_lookup = T::Lookup::unlookup(to);

for j in 0 .. c {
Honzon::<T>::authorize(
RawOrigin::Signed(caller.clone()).into(),
currency_ids[j as usize],
to.clone(),
to_lookup.clone(),
)?;
}
}
Expand Down Expand Up @@ -119,7 +122,9 @@ benchmarks! {

let currency_id: CurrencyId = <T as cdp_engine::Config>::CollateralCurrencyIds::get()[0];
let sender: T::AccountId = account("sender", u, SEED);
let sender_lookup = T::Lookup::unlookup(sender.clone());
let receiver: T::AccountId = account("receiver", u, SEED);
let receiver_lookup = T::Lookup::unlookup(receiver.clone());
let min_debit_value = <T as cdp_engine::Config>::MinimumDebitValue::get();
let debit_exchange_rate = CdpEngine::<T>::get_debit_exchange_rate(currency_id);
let min_debit_amount = debit_exchange_rate.reciprocal().unwrap().saturating_add(ExchangeRate::from_inner(1)).saturating_mul_int(min_debit_value);
Expand Down Expand Up @@ -154,11 +159,11 @@ benchmarks! {

// authorize receiver
Honzon::<T>::authorize(
RawOrigin::Signed(sender.clone()).into(),
RawOrigin::Signed(sender).into(),
currency_id,
receiver.clone()
receiver_lookup
)?;
}: _(RawOrigin::Signed(receiver), currency_id, sender)
}: _(RawOrigin::Signed(receiver), currency_id, sender_lookup)
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
14 changes: 10 additions & 4 deletions modules/honzon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use frame_support::{
};
use frame_system::{self as system, ensure_signed};
use primitives::{Amount, CurrencyId};
use sp_runtime::{traits::Zero, DispatchResult};
use sp_runtime::{
traits::{StaticLookup, Zero},
DispatchResult,
};
use support::EmergencyShutdown;

mod default_weight;
Expand Down Expand Up @@ -124,9 +127,10 @@ decl_module! {
pub fn transfer_loan_from(
origin,
currency_id: CurrencyId,
from: T::AccountId,
from: <T::Lookup as StaticLookup>::Source,
) {
let to = ensure_signed(origin)?;
let from = T::Lookup::lookup(from)?;
ensure!(!T::EmergencyShutdown::is_shutdown(), Error::<T>::AlreadyShutdown);
Self::check_authorization(&from, &to, currency_id)?;
<loans::Module<T>>::transfer_loan(&from, &to, currency_id)?;
Expand All @@ -149,9 +153,10 @@ decl_module! {
pub fn authorize(
origin,
currency_id: CurrencyId,
to: T::AccountId,
to: <T::Lookup as StaticLookup>::Source,
) {
let from = ensure_signed(origin)?;
let to = T::Lookup::lookup(to)?;
<Authorization<T>>::insert(&from, (currency_id, &to), true);
Self::deposit_event(RawEvent::Authorization(from, to, currency_id));
}
Expand All @@ -173,9 +178,10 @@ decl_module! {
pub fn unauthorize(
origin,
currency_id: CurrencyId,
to: T::AccountId,
to: <T::Lookup as StaticLookup>::Source,
) {
let from = ensure_signed(origin)?;
let to = T::Lookup::lookup(to)?;
<Authorization<T>>::remove(&from, (currency_id, &to));
Self::deposit_event(RawEvent::UnAuthorization(from, to, currency_id));
}
Expand Down
19 changes: 12 additions & 7 deletions modules/nft/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sp_std::vec;
use frame_benchmarking::{account, benchmarks};
use frame_support::traits::Get;
use frame_system::RawOrigin;
use sp_runtime::traits::{AccountIdConversion, UniqueSaturatedInto};
use sp_runtime::traits::{AccountIdConversion, StaticLookup, UniqueSaturatedInto};

use module_nft::*;
use orml_traits::BasicCurrencyExtended;
Expand Down Expand Up @@ -44,54 +44,59 @@ benchmarks! {

let caller: T::AccountId = account("caller", 0, SEED);
let to: T::AccountId = account("to", 0, SEED);
let to_lookup = T::Lookup::unlookup(to);

let base_currency_amount = dollar(1000);
<T as orml_currencies::Config>::NativeCurrency::update_balance(&caller, base_currency_amount.unique_saturated_into())?;

let module_account: T::AccountId = T::ModuleId::get().into_sub_account(orml_nft::Module::<T>::next_class_id());
module_nft::Module::<T>::create_class(RawOrigin::Signed(caller).into(), vec![1], Properties(ClassProperty::Transferable | ClassProperty::Burnable))?;
<T as orml_currencies::Config>::NativeCurrency::update_balance(&module_account, base_currency_amount.unique_saturated_into())?;
}: _(RawOrigin::Signed(module_account), to, 0u32.into(), vec![1], i)
}: _(RawOrigin::Signed(module_account), to_lookup, 0u32.into(), vec![1], i)

// transfer NFT token to another account
transfer {
let caller: T::AccountId = account("caller", 0, SEED);
let caller_lookup = T::Lookup::unlookup(caller.clone());
let to: T::AccountId = account("to", 0, SEED);
let to_lookup = T::Lookup::unlookup(to.clone());

let base_currency_amount = dollar(1000);
<T as orml_currencies::Config>::NativeCurrency::update_balance(&caller, base_currency_amount.unique_saturated_into())?;

let module_account: T::AccountId = T::ModuleId::get().into_sub_account(orml_nft::Module::<T>::next_class_id());
module_nft::Module::<T>::create_class(RawOrigin::Signed(caller.clone()).into(), vec![1], Properties(ClassProperty::Transferable | ClassProperty::Burnable))?;
module_nft::Module::<T>::create_class(RawOrigin::Signed(caller).into(), vec![1], Properties(ClassProperty::Transferable | ClassProperty::Burnable))?;
<T as orml_currencies::Config>::NativeCurrency::update_balance(&module_account, base_currency_amount.unique_saturated_into())?;
module_nft::Module::<T>::mint(RawOrigin::Signed(module_account).into(), to.clone(), 0u32.into(), vec![1], 1)?;
}: _(RawOrigin::Signed(to), caller, (0u32.into(), 0u32.into()))
module_nft::Module::<T>::mint(RawOrigin::Signed(module_account).into(), to_lookup, 0u32.into(), vec![1], 1)?;
}: _(RawOrigin::Signed(to), caller_lookup, (0u32.into(), 0u32.into()))

// burn NFT token
burn {
let caller: T::AccountId = account("caller", 0, SEED);
let to: T::AccountId = account("to", 0, SEED);
let to_lookup = T::Lookup::unlookup(to.clone());

let base_currency_amount = dollar(1000);
<T as orml_currencies::Config>::NativeCurrency::update_balance(&caller, base_currency_amount.unique_saturated_into())?;

let module_account: T::AccountId = T::ModuleId::get().into_sub_account(orml_nft::Module::<T>::next_class_id());
module_nft::Module::<T>::create_class(RawOrigin::Signed(caller).into(), vec![1], Properties(ClassProperty::Transferable | ClassProperty::Burnable))?;
<T as orml_currencies::Config>::NativeCurrency::update_balance(&module_account, base_currency_amount.unique_saturated_into())?;
module_nft::Module::<T>::mint(RawOrigin::Signed(module_account).into(), to.clone(), 0u32.into(), vec![1], 1)?;
module_nft::Module::<T>::mint(RawOrigin::Signed(module_account).into(), to_lookup, 0u32.into(), vec![1], 1)?;
}: _(RawOrigin::Signed(to), (0u32.into(), 0u32.into()))

// destroy NFT class
destroy_class {
let caller: T::AccountId = account("caller", 0, SEED);
let to: T::AccountId = account("to", 0, SEED);
let to_lookup = T::Lookup::unlookup(to);

let base_currency_amount = dollar(1000);
<T as orml_currencies::Config>::NativeCurrency::update_balance(&caller, base_currency_amount.unique_saturated_into())?;

let module_account: T::AccountId = T::ModuleId::get().into_sub_account(orml_nft::Module::<T>::next_class_id());
module_nft::Module::<T>::create_class(RawOrigin::Signed(caller).into(), vec![1], Properties(ClassProperty::Transferable | ClassProperty::Burnable))?;
}: _(RawOrigin::Signed(module_account), 0u32.into(), to)
}: _(RawOrigin::Signed(module_account), 0u32.into(), to_lookup)
}

#[cfg(test)]
Expand Down
Loading