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

Remove getters in slpx. #1360

Merged
merged 1 commit into from
Aug 14, 2024
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
17 changes: 6 additions & 11 deletions pallets/slpx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ pub mod pallet {

/// Contract whitelist
#[pallet::storage]
#[pallet::getter(fn whitelist_account_ids)]
pub type WhitelistAccountId<T: Config> = StorageMap<
_,
Blake2_128Concat,
Expand All @@ -278,28 +277,23 @@ pub mod pallet {

/// Charge corresponding fees for different CurrencyId
#[pallet::storage]
#[pallet::getter(fn execution_fee)]
pub type ExecutionFee<T: Config> =
StorageMap<_, Blake2_128Concat, CurrencyId, BalanceOf<T>, OptionQuery>;

/// XCM fee for transferring to Moonbeam(BNC)
#[pallet::storage]
#[pallet::getter(fn transfer_to_fee)]
pub type TransferToFee<T: Config> =
StorageMap<_, Blake2_128Concat, SupportChain, BalanceOf<T>, OptionQuery>;

#[pallet::storage]
#[pallet::getter(fn xcm_ethereum_call_configuration)]
pub type XcmEthereumCallConfiguration<T: Config> =
StorageValue<_, EthereumCallConfiguration<BlockNumberFor<T>>>;

#[pallet::storage]
#[pallet::getter(fn currency_id_list)]
pub type CurrencyIdList<T: Config> =
StorageValue<_, BoundedVec<CurrencyId, ConstU32<10>>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn support_xcm_fee_list)]
pub type SupportXcmFeeList<T: Config> =
StorageValue<_, BoundedVec<CurrencyId, ConstU32<100>>, ValueQuery>;

Expand Down Expand Up @@ -500,7 +494,7 @@ pub mod pallet {
Self::ensure_singer_on_whitelist(origin, evm_caller, &target_chain)?;

if vtoken_id == VFIL {
let fee_amount = Self::transfer_to_fee(SupportChain::Moonbeam)
let fee_amount = TransferToFee::<T>::get(SupportChain::Moonbeam)
.unwrap_or_else(|| Self::get_default_fee(BNC));
T::MultiCurrency::transfer(
BNC,
Expand Down Expand Up @@ -914,8 +908,8 @@ impl<T: Config> Pallet<T> {
evm_caller_account_id: &AccountIdOf<T>,
) -> Result<BalanceOf<T>, DispatchError> {
let free_balance = T::MultiCurrency::free_balance(currency_id, evm_caller_account_id);
let execution_fee =
Self::execution_fee(currency_id).unwrap_or_else(|| Self::get_default_fee(currency_id));
let execution_fee = ExecutionFee::<T>::get(currency_id)
.unwrap_or_else(|| Self::get_default_fee(currency_id));

T::MultiCurrency::transfer(
currency_id,
Expand Down Expand Up @@ -993,7 +987,7 @@ impl<T: Config> Pallet<T> {
if SupportXcmFeeList::<T>::get().contains(&currency_id) {
T::XcmTransfer::transfer(caller, currency_id, amount, dest, Unlimited)?;
} else {
let fee_amount = Self::transfer_to_fee(SupportChain::Moonbeam)
let fee_amount = TransferToFee::<T>::get(SupportChain::Moonbeam)
.unwrap_or_else(|| Self::get_default_fee(BNC));
T::MultiCurrency::transfer(BNC, evm_contract_account_id, &caller, fee_amount)?;
let assets = vec![(currency_id, amount), (BNC, fee_amount)];
Expand Down Expand Up @@ -1084,6 +1078,7 @@ impl<T: Config> Pallet<T> {
// Functions to be called by other pallets.
impl<T: Config> SlpxOperator<BalanceOf<T>> for Pallet<T> {
fn get_moonbeam_transfer_to_fee() -> BalanceOf<T> {
Self::transfer_to_fee(SupportChain::Moonbeam).unwrap_or_else(|| Self::get_default_fee(BNC))
TransferToFee::<T>::get(SupportChain::Moonbeam)
.unwrap_or_else(|| Self::get_default_fee(BNC))
}
}
24 changes: 12 additions & 12 deletions pallets/slpx/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn test_whitelist_work() {
assert_ok!(Slpx::add_whitelist(RuntimeOrigin::root(), SupportChain::Astar, ALICE));
assert_ok!(Slpx::add_whitelist(RuntimeOrigin::root(), SupportChain::Astar, BOB));
assert_eq!(
Slpx::whitelist_account_ids(SupportChain::Astar),
WhitelistAccountId::<Test>::get(SupportChain::Astar),
BoundedVec::<AccountId, ConstU32<10>>::try_from(vec![ALICE, BOB]).unwrap()
);
assert_noop!(
Expand All @@ -67,7 +67,7 @@ fn test_whitelist_work() {
);
assert_ok!(Slpx::remove_whitelist(RuntimeOrigin::root(), SupportChain::Astar, ALICE));
assert_eq!(
Slpx::whitelist_account_ids(SupportChain::Astar),
WhitelistAccountId::<Test>::get(SupportChain::Astar),
BoundedVec::<AccountId, ConstU32<10>>::try_from(vec![BOB]).unwrap()
);

Expand Down Expand Up @@ -111,7 +111,7 @@ fn test_execution_fee_work() {
CurrencyId::Token2(0),
10 * 1_000_000_000
));
assert_eq!(Slpx::execution_fee(CurrencyId::Token2(0)), Some(10 * 1_000_000_000));
assert_eq!(ExecutionFee::<Test>::get(CurrencyId::Token2(0)), Some(10 * 1_000_000_000));

let balance_exclude_fee =
Slpx::charge_execution_fee(CurrencyId::Token2(0), &ALICE).unwrap();
Expand All @@ -122,7 +122,7 @@ fn test_execution_fee_work() {
SupportChain::Moonbeam,
10 * 1_000_000_000
));
assert_eq!(Slpx::transfer_to_fee(SupportChain::Moonbeam), Some(10 * 1_000_000_000));
assert_eq!(TransferToFee::<Test>::get(SupportChain::Moonbeam), Some(10 * 1_000_000_000));
});
}

Expand Down Expand Up @@ -277,13 +277,13 @@ fn test_ethereum_call() {
fn test_set_currency_ethereum_call_switch() {
sp_io::TestExternalities::default().execute_with(|| {
assert_ok!(Slpx::set_currency_ethereum_call_switch(RuntimeOrigin::root(), BNC, true));
assert_eq!(Slpx::currency_id_list().to_vec(), vec![BNC]);
assert_eq!(CurrencyIdList::<Test>::get().to_vec(), vec![BNC]);

assert_ok!(Slpx::set_currency_ethereum_call_switch(RuntimeOrigin::root(), KSM, true));
assert_eq!(Slpx::currency_id_list().to_vec(), vec![BNC, KSM]);
assert_eq!(CurrencyIdList::<Test>::get().to_vec(), vec![BNC, KSM]);

assert_ok!(Slpx::set_currency_ethereum_call_switch(RuntimeOrigin::root(), BNC, false));
assert_eq!(Slpx::currency_id_list().to_vec(), vec![KSM]);
assert_eq!(CurrencyIdList::<Test>::get().to_vec(), vec![KSM]);
})
}

Expand All @@ -299,7 +299,7 @@ fn test_set_ethereum_call_configration() {
));

assert_eq!(
Slpx::xcm_ethereum_call_configuration().unwrap(),
XcmEthereumCallConfiguration::<Test>::get().unwrap(),
EthereumCallConfiguration {
xcm_fee: 1_000_000_000_000_000_000u128,
xcm_weight: Weight::default(),
Expand All @@ -318,7 +318,7 @@ fn test_set_ethereum_call_configration() {
));

assert_eq!(
Slpx::xcm_ethereum_call_configuration().unwrap(),
XcmEthereumCallConfiguration::<Test>::get().unwrap(),
EthereumCallConfiguration {
xcm_fee: 1u128,
xcm_weight: Weight::default(),
Expand All @@ -334,13 +334,13 @@ fn test_set_ethereum_call_configration() {
fn test_set_currency_to_support_xcm_fee() {
sp_io::TestExternalities::default().execute_with(|| {
assert_ok!(Slpx::set_currency_support_xcm_fee(RuntimeOrigin::root(), BNC, true));
assert_eq!(Slpx::support_xcm_fee_list().to_vec(), vec![BNC]);
assert_eq!(SupportXcmFeeList::<Test>::get().to_vec(), vec![BNC]);

assert_ok!(Slpx::set_currency_support_xcm_fee(RuntimeOrigin::root(), KSM, true));
assert_eq!(Slpx::support_xcm_fee_list().to_vec(), vec![BNC, KSM]);
assert_eq!(SupportXcmFeeList::<Test>::get().to_vec(), vec![BNC, KSM]);

assert_ok!(Slpx::set_currency_support_xcm_fee(RuntimeOrigin::root(), BNC, false));
assert_eq!(Slpx::support_xcm_fee_list().to_vec(), vec![KSM]);
assert_eq!(SupportXcmFeeList::<Test>::get().to_vec(), vec![KSM]);
})
}

Expand Down