Skip to content

Commit

Permalink
revert 584fbb0
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjj9219 committed Sep 20, 2022
1 parent b08bdc7 commit 12f5327
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 293 deletions.
2 changes: 1 addition & 1 deletion runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ parameter_type_with_key! {
Self::get(&currency_id_0)
}
},
CurrencyId::Erc20(address) => AssetIdMaps::<Runtime>::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::<Runtime>::get_asset_metadata(AssetIds::StableAssetId(*stable_asset_id)).
map_or(Balance::max_value(), |metatata| metatata.minimal_balance)
Expand Down
272 changes: 1 addition & 271 deletions runtime/integration-tests/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1152,273 +1152,3 @@ fn evm_limits() {
assert_eq!(runtime_common::EvmLimits::<Runtime>::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();

<EVM as EVMTrait<AccountId>>::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
));
});
}
38 changes: 19 additions & 19 deletions runtime/integration-tests/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ parameter_type_with_key! {
Self::get(&currency_id_0)
}
},
CurrencyId::Erc20(address) => AssetIdMaps::<Runtime>::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::<Runtime>::get_asset_metadata(AssetIds::StableAssetId(*stable_asset_id)).
map_or(Balance::max_value(), |metatata| metatata.minimal_balance)
Expand Down
2 changes: 1 addition & 1 deletion runtime/mandala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ parameter_type_with_key! {
Self::get(&currency_id_0)
}
},
CurrencyId::Erc20(address) => AssetIdMaps::<Runtime>::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::<Runtime>::get_asset_metadata(AssetIds::StableAssetId(*stable_asset_id)).
map_or(Balance::max_value(), |metatata| metatata.minimal_balance)
Expand Down

0 comments on commit 12f5327

Please sign in to comment.