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

add ACA to CollateralCurrencyIds #1918

Merged
merged 4 commits into from
Feb 23, 2022
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
9 changes: 9 additions & 0 deletions runtime/acala/src/benchmarking/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
use frame_benchmarking::account;
use frame_support::{assert_ok, traits::Contains};
use frame_system::RawOrigin;
use module_support::Erc20InfoMapping;
use orml_traits::MultiCurrencyExtended;
use sp_runtime::{
traits::{SaturatedConversion, StaticLookup},
Expand Down Expand Up @@ -55,6 +56,14 @@ pub fn feed_price(prices: Vec<(CurrencyId, Price)>) -> DispatchResult {
Ok(())
}

pub fn dollar(currency_id: CurrencyId) -> Balance {
if let Some(decimals) = module_asset_registry::EvmErc20InfoMapping::<Runtime>::decimals(currency_id) {
10u128.saturating_pow(decimals.into())
} else {
panic!("{:?} not support decimals", currency_id);
}
}

#[cfg(test)]
pub mod tests {
pub fn new_test_ext() -> sp_io::TestExternalities {
Expand Down
2 changes: 1 addition & 1 deletion runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ where
}

parameter_types! {
pub CollateralCurrencyIds: Vec<CurrencyId> = vec![DOT, LDOT, LCDOT];
pub CollateralCurrencyIds: Vec<CurrencyId> = vec![ACA, DOT, LCDOT, LDOT];
pub DefaultLiquidationRatio: Ratio = Ratio::saturating_from_rational(150, 100);
pub DefaultDebitExchangeRate: ExchangeRate = ExchangeRate::saturating_from_rational(1, 10);
pub DefaultLiquidationPenalty: Rate = Rate::saturating_from_rational(8, 100);
Expand Down
9 changes: 9 additions & 0 deletions runtime/karura/src/benchmarking/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use frame_benchmarking::account;
use frame_support::traits::tokens::fungibles;
use frame_support::{assert_ok, traits::Contains};
use frame_system::RawOrigin;
use module_support::Erc20InfoMapping;
use orml_traits::MultiCurrencyExtended;
use sp_runtime::{
traits::{SaturatedConversion, StaticLookup},
Expand Down Expand Up @@ -60,6 +61,14 @@ pub fn set_balance_fungibles(currency_id: CurrencyId, who: &AccountId, balance:
assert_ok!(<orml_tokens::Pallet<Runtime> as fungibles::Mutate<AccountId>>::mint_into(currency_id, who, balance));
}

pub fn dollar(currency_id: CurrencyId) -> Balance {
if let Some(decimals) = module_asset_registry::EvmErc20InfoMapping::<Runtime>::decimals(currency_id) {
10u128.saturating_pow(decimals.into())
} else {
panic!("{:?} not support decimals", currency_id);
}
}

#[cfg(test)]
pub mod tests {
pub fn new_test_ext() -> sp_io::TestExternalities {
Expand Down
4 changes: 2 additions & 2 deletions runtime/mandala/src/benchmarking/asset_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{dollar, AccountId, AssetRegistry, CurrencyId, GetNativeCurrencyId, Origin, Runtime, EVM};
use crate::{AccountId, AssetRegistry, CurrencyId, GetNativeCurrencyId, Origin, Runtime, EVM};

use super::utils::set_balance;
use super::utils::{dollar, set_balance};
use frame_support::assert_ok;
use frame_system::RawOrigin;
use module_asset_registry::AssetMetadata;
Expand Down
6 changes: 3 additions & 3 deletions runtime/mandala/src/benchmarking/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
dollar, AccountId, Auction, AuctionId, AuctionManager, AuctionTimeToClose, CdpTreasury, CurrencyId,
GetStableCurrencyId, GetStakingCurrencyId, Runtime, System,
AccountId, Auction, AuctionId, AuctionManager, AuctionTimeToClose, CdpTreasury, CurrencyId, GetStableCurrencyId,
GetStakingCurrencyId, Runtime, System,
};

use super::utils::set_balance;
use super::utils::{dollar, set_balance};
use frame_benchmarking::{account, whitelisted_caller};
use frame_support::traits::OnFinalize;
use frame_system::RawOrigin;
Expand Down
6 changes: 3 additions & 3 deletions runtime/mandala/src/benchmarking/auction_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
dollar, AccountId, AuctionId, AuctionManager, CdpTreasury, Currencies, CurrencyId, EmergencyShutdown,
GetStableCurrencyId, GetStakingCurrencyId, Price, Runtime,
AccountId, AuctionId, AuctionManager, CdpTreasury, Currencies, CurrencyId, EmergencyShutdown, GetStableCurrencyId,
GetStakingCurrencyId, Price, Runtime,
};

use super::utils::feed_price;
use super::utils::{dollar, feed_price};
use frame_benchmarking::account;
use frame_system::RawOrigin;
use module_support::{AuctionManager as AuctionManagerTrait, CDPTreasury};
Expand Down
9 changes: 6 additions & 3 deletions runtime/mandala/src/benchmarking/cdp_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
dollar, AccountId, Address, Amount, Balance, CdpEngine, CdpTreasury, CollateralCurrencyIds, CurrencyId,
AccountId, Address, Amount, Balance, CdpEngine, CdpTreasury, CollateralCurrencyIds, CurrencyId,
DefaultDebitExchangeRate, Dex, EmergencyShutdown, ExistentialDeposits, GetLiquidCurrencyId, GetNativeCurrencyId,
GetStableCurrencyId, GetStakingCurrencyId, MaxAuctionsCount, MinimumDebitValue, NativeTokenExistentialDeposit,
Price, Rate, Ratio, Runtime, Timestamp, MILLISECS_PER_BLOCK,
};

use super::utils::{feed_price, set_balance};
use super::utils::{dollar, feed_price, set_balance};
use frame_benchmarking::account;
use frame_support::traits::OnInitialize;
use frame_system::RawOrigin;
Expand Down Expand Up @@ -72,7 +72,7 @@ runtime_benchmarks! {
{ Runtime, module_cdp_engine }

on_initialize {
let c in 0 .. CollateralCurrencyIds::get().len().saturating_sub(1) as u32;
let c in 0 .. CollateralCurrencyIds::get().len() as u32;
let owner: AccountId = account("owner", 0, SEED);
let owner_lookup: Address = AccountIdLookup::unlookup(owner.clone());
let currency_ids = CollateralCurrencyIds::get();
Expand All @@ -93,6 +93,9 @@ runtime_benchmarks! {

for i in 0 .. c {
let currency_id = currency_ids[i as usize];
if matches!(currency_id, CurrencyId::StableAssetPoolToken(_)) {
continue;
}
let collateral_amount = Price::saturating_from_rational(dollar(currency_id), dollar(STABLECOIN)).saturating_mul_int(collateral_value);

let ed = if currency_id == GetNativeCurrencyId::get() {
Expand Down
6 changes: 3 additions & 3 deletions runtime/mandala/src/benchmarking/cdp_treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
dollar, AccountId, CdpTreasury, Currencies, CurrencyId, Dex, GetStableCurrencyId, GetStakingCurrencyId,
MaxAuctionsCount, Runtime,
AccountId, CdpTreasury, Currencies, CurrencyId, Dex, GetStableCurrencyId, GetStakingCurrencyId, MaxAuctionsCount,
Runtime,
};

use super::utils::set_balance;
use super::utils::{dollar, set_balance};
use frame_benchmarking::whitelisted_caller;
use frame_system::RawOrigin;
use module_support::{CDPTreasury, SwapLimit};
Expand Down
4 changes: 2 additions & 2 deletions runtime/mandala/src/benchmarking/currencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use super::utils::{lookup_of_account, set_balance};
use super::utils::{dollar, lookup_of_account, set_balance};
use crate::{
dollar, AccountId, Amount, Balance, Currencies, CurrencyId, GetNativeCurrencyId, GetStakingCurrencyId,
AccountId, Amount, Balance, Currencies, CurrencyId, GetNativeCurrencyId, GetStakingCurrencyId,
NativeTokenExistentialDeposit, Runtime, Tokens, TreasuryPalletId,
};

Expand Down
4 changes: 2 additions & 2 deletions runtime/mandala/src/benchmarking/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use super::utils::dollar;
use crate::{
dollar, AccountId, Balance, Currencies, CurrencyId, Dex, Event, GetLiquidCurrencyId, GetNativeCurrencyId,
AccountId, Balance, Currencies, CurrencyId, Dex, Event, GetLiquidCurrencyId, GetNativeCurrencyId,
GetStableCurrencyId, GetStakingCurrencyId, Runtime, System, TradingPathLimit,
};

use frame_benchmarking::{account, whitelisted_caller};
use frame_system::RawOrigin;
use module_dex::TradingPairStatus;
Expand Down
4 changes: 2 additions & 2 deletions runtime/mandala/src/benchmarking/dex_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use super::utils::dollar;
use crate::{
dollar, AccountId, Balance, Currencies, CurrencyId, Dex, DexOracle, GetNativeCurrencyId, GetStableCurrencyId,
AccountId, Balance, Currencies, CurrencyId, Dex, DexOracle, GetNativeCurrencyId, GetStableCurrencyId,
GetStakingCurrencyId, Runtime, Timestamp,
};

use frame_benchmarking::whitelisted_caller;
use frame_support::traits::OnInitialize;
use frame_system::RawOrigin;
Expand Down
12 changes: 7 additions & 5 deletions runtime/mandala/src/benchmarking/emergency_shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
dollar, AccountId, CdpTreasury, CollateralCurrencyIds, CurrencyId, EmergencyShutdown, GetStableCurrencyId, Price,
Runtime,
AccountId, CdpTreasury, CollateralCurrencyIds, CurrencyId, EmergencyShutdown, GetStableCurrencyId, Price, Runtime,
};

use super::utils::{feed_price, set_balance};
use super::utils::{dollar, feed_price, set_balance};
use frame_benchmarking::{account, whitelisted_caller};
use frame_system::RawOrigin;
use module_support::CDPTreasury;
Expand All @@ -37,7 +36,7 @@ runtime_benchmarks! {
{ Runtime, module_emergency_shutdown }

emergency_shutdown {
let c in 0 .. CollateralCurrencyIds::get().len().saturating_sub(1) as u32;
let c in 0 .. CollateralCurrencyIds::get().len() as u32;
let currency_ids = CollateralCurrencyIds::get();
let mut values = vec![];

Expand All @@ -52,14 +51,17 @@ runtime_benchmarks! {
}: _(RawOrigin::Root)

refund_collaterals {
let c in 0 .. CollateralCurrencyIds::get().len().saturating_sub(1) as u32;
let c in 0 .. CollateralCurrencyIds::get().len() as u32;
let currency_ids = CollateralCurrencyIds::get();
let funder: AccountId = account("funder", 0, SEED);
let caller: AccountId = whitelisted_caller();
let mut values = vec![];

for i in 0 .. c {
let currency_id = currency_ids[i as usize];
if matches!(currency_id, CurrencyId::StableAssetPoolToken(_)) {
continue;
}
values.push((currency_id, Price::one()));
set_balance(currency_id, &funder, 100 * dollar(currency_id));
CdpTreasury::deposit_collateral(&funder, currency_id, 100 * dollar(currency_id))?;
Expand Down
6 changes: 3 additions & 3 deletions runtime/mandala/src/benchmarking/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
dollar, AccountId, Currencies, CurrencyId, Event, EvmAccounts, GetNativeCurrencyId, NetworkContractSource, Origin,
Runtime, System, EVM,
AccountId, Currencies, CurrencyId, Event, EvmAccounts, GetNativeCurrencyId, NetworkContractSource, Origin, Runtime,
System, EVM,
};

use super::utils::set_balance;
use super::utils::{dollar, set_balance};
use frame_support::dispatch::{DispatchError, DispatchResult};
use frame_system::RawOrigin;
use module_evm::MaxCodeSize;
Expand Down
4 changes: 2 additions & 2 deletions runtime/mandala/src/benchmarking/evm_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{dollar, AccountId, CurrencyId, EvmAccounts, GetNativeCurrencyId, Runtime};
use crate::{AccountId, CurrencyId, EvmAccounts, GetNativeCurrencyId, Runtime};

use super::utils::set_balance;
use super::utils::{dollar, set_balance};
use frame_benchmarking::{account, whitelisted_caller};
use frame_system::RawOrigin;
use orml_benchmarking::runtime_benchmarks;
Expand Down
14 changes: 7 additions & 7 deletions runtime/mandala/src/benchmarking/honzon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
dollar, AccountId, Amount, Balance, CdpEngine, CollateralCurrencyIds, Currencies, CurrencyId,
DepositPerAuthorization, Dex, ExistentialDeposits, GetLiquidCurrencyId, GetNativeCurrencyId, GetStableCurrencyId,
GetStakingCurrencyId, Honzon, Price, Rate, Ratio, Runtime,
AccountId, Amount, Balance, CdpEngine, CollateralCurrencyIds, Currencies, CurrencyId, DepositPerAuthorization, Dex,
ExistentialDeposits, GetLiquidCurrencyId, GetNativeCurrencyId, GetStableCurrencyId, GetStakingCurrencyId, Honzon,
Price, Rate, Ratio, Runtime,
};

use super::utils::{feed_price, set_balance};
use super::utils::{dollar, feed_price, set_balance};
use frame_benchmarking::{account, whitelisted_caller};
use frame_system::RawOrigin;
use orml_benchmarking::runtime_benchmarks;
Expand Down Expand Up @@ -102,7 +102,7 @@ runtime_benchmarks! {
}: _(RawOrigin::Signed(caller), STAKING, to_lookup)

unauthorize_all {
let c in 0 .. CollateralCurrencyIds::get().len().saturating_sub(1) as u32;
let c in 0 .. CollateralCurrencyIds::get().len() as u32;

let caller: AccountId = whitelisted_caller();
let currency_ids = CollateralCurrencyIds::get();
Expand Down Expand Up @@ -134,7 +134,7 @@ runtime_benchmarks! {
let collateral_amount = Price::saturating_from_rational(dollar(currency_id), dollar(STABLECOIN)).saturating_mul_int(collateral_value);

// set balance
set_balance(currency_id, &caller, collateral_amount + ExistentialDeposits::get(&currency_id));
set_balance(currency_id, &caller, collateral_amount * 2);

// feed price
feed_price(vec![(currency_id, collateral_price)])?;
Expand Down Expand Up @@ -166,7 +166,7 @@ runtime_benchmarks! {
let collateral_amount = Price::saturating_from_rational(dollar(currency_id), dollar(STABLECOIN)).saturating_mul_int(collateral_value);

// set balance
set_balance(currency_id, &sender, collateral_amount + ExistentialDeposits::get(&currency_id));
set_balance(currency_id, &sender, collateral_amount * 2);
set_balance(NATIVE, &sender, DepositPerAuthorization::get());

// feed price
Expand Down
28 changes: 14 additions & 14 deletions runtime/mandala/src/benchmarking/incentives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
dollar, AccountId, AccumulatePeriod, CollateralCurrencyIds, Currencies, CurrencyId, GetNativeCurrencyId,
AccountId, AccumulatePeriod, CollateralCurrencyIds, Currencies, CurrencyId, GetNativeCurrencyId,
GetStableCurrencyId, GetStakingCurrencyId, Incentives, Rate, Rewards, Runtime, System,
};

use super::utils::set_balance;
use super::utils::{dollar, set_balance};
use frame_benchmarking::{account, whitelisted_caller, BenchmarkError};
use frame_support::traits::OnInitialize;
use frame_system::RawOrigin;
use module_incentives::PoolId;
use orml_benchmarking::runtime_benchmarks;
use orml_traits::MultiCurrency;
use primitives::DexShare;
use sp_std::prelude::*;

const SEED: u32 = 0;
Expand All @@ -41,7 +40,7 @@ runtime_benchmarks! {
{ Runtime, module_incentives }

on_initialize {
let c in 0 .. CollateralCurrencyIds::get().len().saturating_sub(1) as u32;
let c in 0 .. CollateralCurrencyIds::get().len() as u32;
let currency_ids = CollateralCurrencyIds::get();
let block_number = AccumulatePeriod::get();

Expand Down Expand Up @@ -89,7 +88,7 @@ runtime_benchmarks! {
}: _(RawOrigin::Signed(caller), pool_id)

update_incentive_rewards {
let c in 0 .. CollateralCurrencyIds::get().len().saturating_sub(1) as u32;
let c in 0 .. CollateralCurrencyIds::get().len() as u32;
let currency_ids = CollateralCurrencyIds::get();
let mut updates = vec![];

Expand All @@ -100,26 +99,27 @@ runtime_benchmarks! {
}: _(RawOrigin::Root, updates)

update_dex_saving_rewards {
let c in 0 .. CollateralCurrencyIds::get().len().saturating_sub(1) as u32;
let c in 0 .. CollateralCurrencyIds::get().len() as u32;
let currency_ids = CollateralCurrencyIds::get();
let caller: AccountId = account("caller", 0, SEED);
let mut updates = vec![];
let base_currency_id = GetStableCurrencyId::get();

for i in 0 .. c {
let currency_id = currency_ids[i as usize];
let lp_share_currency_id = match (currency_id, base_currency_id) {
(CurrencyId::Token(other_currency_symbol), CurrencyId::Token(base_currency_symbol)) => {
CurrencyId::DexShare(DexShare::Token(other_currency_symbol), DexShare::Token(base_currency_symbol))
}
_ => return Err(BenchmarkError::Stop("invalid currency id")),
};
updates.push((PoolId::Dex(lp_share_currency_id), Rate::default()));
if matches!(currency_id, CurrencyId::StableAssetPoolToken(_)) {
continue;
}
if let Some(lp_share_currency_id) = CurrencyId::join_dex_share_currency_id(currency_id, base_currency_id) {
updates.push((PoolId::Dex(lp_share_currency_id), Rate::default()));
} else {
return Err(BenchmarkError::Stop("invalid currency id"));
}
}
}: _(RawOrigin::Root, updates)

update_claim_reward_deduction_rates {
let c in 0 .. CollateralCurrencyIds::get().len().saturating_sub(1) as u32;
let c in 0 .. CollateralCurrencyIds::get().len() as u32;
let currency_ids = CollateralCurrencyIds::get();
let mut updates = vec![];

Expand Down
2 changes: 1 addition & 1 deletion runtime/mandala/src/benchmarking/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ runtime_benchmarks_instance! {

// feed values
feed_values {
let c in 0 .. CollateralCurrencyIds::get().len().saturating_sub(1) as u32;
let c in 0 .. CollateralCurrencyIds::get().len() as u32;
let currency_ids = CollateralCurrencyIds::get();
let mut values = vec![];

Expand Down
4 changes: 2 additions & 2 deletions runtime/mandala/src/benchmarking/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use super::utils::{lookup_of_account, set_balance as update_balance};
use crate::{dollar, AccountId, Balance, CurrencyId, GetStableCurrencyId, Runtime, Tokens};
use super::utils::{dollar, lookup_of_account, set_balance as update_balance};
use crate::{AccountId, Balance, CurrencyId, GetStableCurrencyId, Runtime, Tokens};

use sp_std::prelude::*;

Expand Down
Loading