diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 1292e87227..ac799ba572 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -758,7 +758,7 @@ parameter_type_with_key! { Self::get(¤cy_id_0) } }, - CurrencyId::Erc20(address) => AssetIdMaps::::get_asset_metadata(AssetIds::Erc20(*address)).map_or(Balance::max_value(), |metatata| metatata.minimal_balance), + CurrencyId::Erc20(_) => Balance::max_value(), // not handled by orml-tokens CurrencyId::StableAssetPoolToken(stable_asset_id) => { AssetIdMaps::::get_asset_metadata(AssetIds::StableAssetId(*stable_asset_id)). map_or(Balance::max_value(), |metatata| metatata.minimal_balance) diff --git a/runtime/integration-tests/src/evm.rs b/runtime/integration-tests/src/evm.rs index 01ab174037..e0ee0fa197 100644 --- a/runtime/integration-tests/src/evm.rs +++ b/runtime/integration-tests/src/evm.rs @@ -28,7 +28,7 @@ use module_evm_bridge::EVMBridge; use module_support::{EVMBridge as EVMBridgeT, Erc20InfoMapping, EVM as EVMTrait}; use primitives::{ evm::{convert_decimals_to_evm, EvmAddress}, - Position, TradingPair, + TradingPair, }; use sp_core::{H256, U256}; use sp_runtime::{traits::SignedExtension, Percent}; @@ -1152,273 +1152,3 @@ fn evm_limits() { assert_eq!(runtime_common::EvmLimits::::max_storage_limit(), 3_670_016); }); } - -#[test] -fn honzon_works_with_evm_contract() { - let erc20_token = CurrencyId::Erc20(erc20_address_0()); - let alice_evm_account = MockAddressMapping::get_account_id(&alice_evm_addr()); - - ExtBuilder::default() - .balances(vec![ - (alice(), NATIVE_CURRENCY, 1_000_000_000 * dollar(NATIVE_CURRENCY)), - ( - // evm alice - alice_evm_account.clone(), - NATIVE_CURRENCY, - 1_000_000_000 * dollar(NATIVE_CURRENCY), - ), - ( - // evm alice - alice_evm_account.clone(), - USD_CURRENCY, - 1_000_000_000 * dollar(USD_CURRENCY), - ), - ( - alice_evm_account.clone(), - RELAY_CHAIN_CURRENCY, - 1_000_000_000 * dollar(RELAY_CHAIN_CURRENCY), - ), - ]) - .build() - .execute_with(|| { - deploy_erc20_contracts(); - - assert_ok!(CdpEngine::set_collateral_params( - Origin::root(), - erc20_token, - Change::NewValue(Some(Rate::saturating_from_rational(1, 100000))), - Change::NewValue(Some(Ratio::saturating_from_rational(3, 2))), - Change::NewValue(Some(Rate::saturating_from_rational(2, 10))), - Change::NewValue(Some(Ratio::saturating_from_rational(9, 5))), - Change::NewValue(10000 * dollar(NATIVE_CURRENCY)), - )); - - assert_ok!(CdpEngine::set_collateral_params( - Origin::root(), - RELAY_CHAIN_CURRENCY, - Change::NewValue(Some(Rate::saturating_from_rational(1, 100000))), - Change::NewValue(Some(Ratio::saturating_from_rational(3, 2))), - Change::NewValue(Some(Rate::saturating_from_rational(2, 10))), - Change::NewValue(Some(Ratio::saturating_from_rational(9, 5))), - Change::NewValue(10000 * dollar(NATIVE_CURRENCY)), - )); - - assert_eq!( - Loans::positions(USD_CURRENCY, alice_evm_account.clone()), - Position { - collateral: 0, - debit: 0 - } - ); - assert_eq!( - Loans::positions(erc20_token, alice_evm_account.clone()), - Position { - collateral: 0, - debit: 0 - } - ); - - assert_eq!( - Loans::total_positions(erc20_token), - Position { - collateral: 0, - debit: 0 - } - ); - - set_oracle_price(vec![ - (erc20_token, Price::saturating_from_rational(2, 1)), // 2 usd - (RELAY_CHAIN_CURRENCY, Price::saturating_from_rational(10, 1)), // 10 usd - ]); - - // erc20 decimals is 17 - let collateral_value = MinimumDebitValue::get() * 1_000_000; // 10 token, 10^18 - let min_debit_value = DefaultDebitExchangeRate::get() - .reciprocal() - .map(|n| n.saturating_mul_int(MinimumDebitValue::get())) - .unwrap(); - - >::set_origin(alice_evm_account.clone()); - // 1.Honzon::adjust_loan - assert_ok!(Honzon::adjust_loan( - Origin::signed(alice_evm_account.clone()), - erc20_token, - collateral_value as i128, - min_debit_value as i128 - )); - - assert_eq!( - Loans::positions(erc20_token, alice_evm_account.clone()), - Position { - collateral: collateral_value, - debit: min_debit_value - } - ); - - // collateral = 0 - assert_ok!(Honzon::adjust_loan( - Origin::signed(alice_evm_account.clone()), - erc20_token, - 0, - min_debit_value as i128 - )); - - assert_eq!( - Loans::positions(erc20_token, alice_evm_account.clone()), - Position { - collateral: collateral_value, - debit: 2 * min_debit_value - } - ); - - // debit = 0 - assert_ok!(Honzon::adjust_loan( - Origin::signed(alice_evm_account.clone()), - erc20_token, - 2 * collateral_value as i128, - 0, - )); - - assert_eq!( - Loans::positions(erc20_token, alice_evm_account.clone()), - Position { - collateral: 3 * collateral_value, - debit: 2 * min_debit_value - } - ); - - // 2.Honzon::adjust_loan_by_debit_value - // withdraws debit - assert_ok!(Honzon::adjust_loan_by_debit_value( - Origin::signed(alice_evm_account.clone()), - erc20_token, - 0, - -3 * min_debit_value as i128 - )); - assert_eq!( - Loans::positions(erc20_token, alice_evm_account.clone()), - Position { - collateral: 3 * collateral_value, - debit: 0 - } - ); - - // Honzon::adjust_loan_by_debit_value - // withdraws collateral - assert_ok!(Honzon::adjust_loan_by_debit_value( - Origin::signed(alice_evm_account.clone()), - erc20_token, - -3 * collateral_value as i128, - 0, - )); - assert_eq!( - Loans::positions(erc20_token, alice_evm_account.clone()), - Position { - collateral: 0, - debit: 0 - } - ); - - // 3.Honzon::transfer_debit - assert_ok!(Honzon::adjust_loan( - Origin::signed(alice_evm_account.clone()), - erc20_token, - collateral_value as i128, - min_debit_value as i128 - )); - assert_ok!(Honzon::adjust_loan( - Origin::signed(alice_evm_account.clone()), - RELAY_CHAIN_CURRENCY, - 100 * dollar(RELAY_CHAIN_CURRENCY) as i128, - min_debit_value as i128 - )); - assert_eq!( - Loans::positions(erc20_token, alice_evm_account.clone()), - Position { - collateral: collateral_value, - debit: min_debit_value - } - ); - assert_eq!( - Loans::positions(RELAY_CHAIN_CURRENCY, alice_evm_account.clone()), - Position { - collateral: 100 * dollar(RELAY_CHAIN_CURRENCY), - debit: min_debit_value - } - ); - - // Honzon::transfer_debit - assert_ok!(Honzon::transfer_debit( - Origin::signed(alice_evm_account.clone()), - erc20_token, - RELAY_CHAIN_CURRENCY, - min_debit_value - )); - assert_eq!( - Loans::positions(erc20_token, alice_evm_account.clone()), - Position { - collateral: collateral_value, - debit: 0 - } - ); - assert_eq!( - Loans::positions(RELAY_CHAIN_CURRENCY, alice_evm_account.clone()), - Position { - collateral: 100 * dollar(RELAY_CHAIN_CURRENCY), - debit: 2 * min_debit_value - } - ); - assert_ok!(Honzon::transfer_debit( - Origin::signed(alice_evm_account.clone()), - RELAY_CHAIN_CURRENCY, - erc20_token, - 2 * min_debit_value - )); - assert_eq!( - Loans::positions(erc20_token, alice_evm_account.clone()), - Position { - collateral: collateral_value, - debit: 2 * min_debit_value - } - ); - - // 4.Honzon::expand_position_collateral - assert_ok!(Dex::list_provisioning( - Origin::root(), - erc20_token, - USD_CURRENCY, - 10, - 100, - 100, - 1000, - 0, - )); - - assert_ok!(Dex::add_provision( - Origin::signed(alice_evm_account.clone()), - erc20_token, - USD_CURRENCY, - 1000 * collateral_value, - 100 * min_debit_value - )); - assert_ok!(Dex::end_provisioning( - Origin::signed(AccountId::from(BOB)), - erc20_token, - USD_CURRENCY, - )); - assert_ok!(Honzon::expand_position_collateral( - Origin::signed(alice_evm_account.clone()), - erc20_token, - min_debit_value, - collateral_value - )); - - // 5.Honzon::shrink_position_debit - assert_ok!(Honzon::shrink_position_debit( - Origin::signed(alice_evm_account.clone()), - erc20_token, - collateral_value, - min_debit_value / 10 - )); - }); -} diff --git a/runtime/integration-tests/src/setup.rs b/runtime/integration-tests/src/setup.rs index febcf123b4..092f21aa48 100644 --- a/runtime/integration-tests/src/setup.rs +++ b/runtime/integration-tests/src/setup.rs @@ -50,14 +50,14 @@ mod mandala_imports { create_x2_parachain_multilocation, get_all_module_accounts, AcalaOracle, AcalaSwap, AccountId, AggregatedDex, AssetRegistry, AuctionManager, Authority, AuthoritysOriginId, Authorship, Balance, Balances, BlockNumber, CDPEnginePalletId, CDPTreasuryPalletId, Call, CdpEngine, CdpTreasury, CollatorSelection, CreateClassDeposit, - CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, DealWithFees, DefaultDebitExchangeRate, - DefaultExchangeRate, Dex, EmergencyShutdown, Event, EvmAccounts, ExistentialDeposits, FinancialCouncil, Get, - GetNativeCurrencyId, Homa, Honzon, IdleScheduler, Loans, MaxTipsOfPriority, MinRewardDistributeAmount, - MinimumDebitValue, MultiLocation, NativeTokenExistentialDeposit, NetworkId, NftPalletId, OneDay, Origin, - OriginCaller, PalletCurrency, ParachainInfo, ParachainSystem, Proxy, ProxyType, Ratio, Runtime, Scheduler, - Session, SessionKeys, SessionManager, SevenDays, StableAsset, StableAssetPalletId, System, Timestamp, - TipPerWeightStep, TokenSymbol, Tokens, TransactionPayment, TransactionPaymentPalletId, TreasuryAccount, - TreasuryPalletId, UncheckedExtrinsic, Utility, Vesting, XcmInterface, EVM, NFT, + CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, DealWithFees, DefaultExchangeRate, Dex, + EmergencyShutdown, Event, EvmAccounts, ExistentialDeposits, FinancialCouncil, Get, GetNativeCurrencyId, Homa, + Honzon, IdleScheduler, Loans, MaxTipsOfPriority, MinRewardDistributeAmount, MinimumDebitValue, MultiLocation, + NativeTokenExistentialDeposit, NetworkId, NftPalletId, OneDay, Origin, OriginCaller, PalletCurrency, + ParachainInfo, ParachainSystem, Proxy, ProxyType, Ratio, Runtime, Scheduler, Session, SessionKeys, + SessionManager, SevenDays, StableAsset, StableAssetPalletId, System, Timestamp, TipPerWeightStep, TokenSymbol, + Tokens, TransactionPayment, TransactionPaymentPalletId, TreasuryAccount, TreasuryPalletId, UncheckedExtrinsic, + Utility, Vesting, XcmInterface, EVM, NFT, }; use module_transaction_payment::BuyWeightRateOfTransactionFeePool; pub use primitives::TradingPair; @@ -102,14 +102,14 @@ mod karura_imports { constants::parachains, create_x2_parachain_multilocation, get_all_module_accounts, AcalaOracle, AcalaSwap, AccountId, AggregatedDex, AssetRegistry, AuctionManager, Authority, AuthoritysOriginId, Balance, Balances, BlockNumber, CDPEnginePalletId, CDPTreasuryPalletId, Call, CdpEngine, CdpTreasury, CreateClassDeposit, - CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, DefaultDebitExchangeRate, DefaultExchangeRate, - Dex, EmergencyShutdown, Event, EvmAccounts, ExistentialDeposits, FinancialCouncil, Get, GetNativeCurrencyId, - Homa, Honzon, IdleScheduler, KaruraFoundationAccounts, Loans, MaxTipsOfPriority, MinimumDebitValue, - MultiLocation, NativeTokenExistentialDeposit, NetworkId, NftPalletId, OneDay, Origin, OriginCaller, - ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, ProxyType, Ratio, Runtime, Scheduler, - Session, SessionManager, SevenDays, StableAsset, StableAssetPalletId, System, Timestamp, TipPerWeightStep, - TokenSymbol, Tokens, TransactionPayment, TransactionPaymentPalletId, TreasuryPalletId, Utility, Vesting, - XTokens, XcmInterface, EVM, NFT, + CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, DefaultExchangeRate, Dex, EmergencyShutdown, + Event, EvmAccounts, ExistentialDeposits, FinancialCouncil, Get, GetNativeCurrencyId, Homa, Honzon, + IdleScheduler, KaruraFoundationAccounts, Loans, MaxTipsOfPriority, MinimumDebitValue, MultiLocation, + NativeTokenExistentialDeposit, NetworkId, NftPalletId, OneDay, Origin, OriginCaller, ParachainAccount, + ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, ProxyType, Ratio, Runtime, Scheduler, Session, + SessionManager, SevenDays, StableAsset, StableAssetPalletId, System, Timestamp, TipPerWeightStep, TokenSymbol, + Tokens, TransactionPayment, TransactionPaymentPalletId, TreasuryPalletId, Utility, Vesting, XTokens, + XcmInterface, EVM, NFT, }; use module_transaction_payment::BuyWeightRateOfTransactionFeePool; pub use primitives::TradingPair; @@ -153,9 +153,9 @@ mod acala_imports { constants::parachains, create_x2_parachain_multilocation, get_all_module_accounts, AcalaFoundationAccounts, AcalaOracle, AcalaSwap, AccountId, AggregatedDex, AssetRegistry, AuctionManager, Authority, AuthoritysOriginId, Balance, Balances, BlockNumber, CDPEnginePalletId, CDPTreasuryPalletId, Call, CdpEngine, CdpTreasury, - CreateClassDeposit, CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, DefaultDebitExchangeRate, - DefaultExchangeRate, Dex, EmergencyShutdown, Event, EvmAccounts, ExistentialDeposits, FinancialCouncil, Get, - GetNativeCurrencyId, Homa, Honzon, IdleScheduler, Loans, MaxTipsOfPriority, MinimumDebitValue, MultiLocation, + CreateClassDeposit, CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, DefaultExchangeRate, Dex, + EmergencyShutdown, Event, EvmAccounts, ExistentialDeposits, FinancialCouncil, Get, GetNativeCurrencyId, Homa, + Honzon, IdleScheduler, Loans, MaxTipsOfPriority, MinimumDebitValue, MultiLocation, NativeTokenExistentialDeposit, NetworkId, NftPalletId, OneDay, Origin, OriginCaller, ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, ProxyType, Ratio, Runtime, Scheduler, Session, SessionManager, SevenDays, StableAsset, StableAssetPalletId, System, Timestamp, TipPerWeightStep, TokenSymbol, diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 5a901c0ac2..e2ad4c3ffa 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -766,7 +766,7 @@ parameter_type_with_key! { Self::get(¤cy_id_0) } }, - CurrencyId::Erc20(address) => AssetIdMaps::::get_asset_metadata(AssetIds::Erc20(*address)).map_or(Balance::max_value(), |metatata| metatata.minimal_balance), + CurrencyId::Erc20(_) => Balance::max_value(), // not handled by orml-tokens CurrencyId::StableAssetPoolToken(stable_asset_id) => { AssetIdMaps::::get_asset_metadata(AssetIds::StableAssetId(*stable_asset_id)). map_or(Balance::max_value(), |metatata| metatata.minimal_balance) diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 279c77cfb6..f5248b95eb 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -830,7 +830,7 @@ parameter_type_with_key! { Self::get(¤cy_id_0) } }, - CurrencyId::Erc20(address) => AssetIdMaps::::get_asset_metadata(AssetIds::Erc20(*address)).map_or(Balance::max_value(), |metatata| metatata.minimal_balance), + CurrencyId::Erc20(_) => Balance::max_value(), // not handled by orml-tokens CurrencyId::StableAssetPoolToken(stable_asset_id) => { AssetIdMaps::::get_asset_metadata(AssetIds::StableAssetId(*stable_asset_id)). map_or(Balance::max_value(), |metatata| metatata.minimal_balance)