Skip to content

Commit

Permalink
fix: we need to incporporate the swap with fee here
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoka committed Oct 29, 2024
1 parent 470e6ba commit 8a11813
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions integration-tests/src/evm_permit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use hydradx_runtime::AssetRegistry;
use hydradx_runtime::DOT_ASSET_LOCATION;
use hydradx_runtime::XYK;
use hydradx_runtime::{
Balances, Currencies, DotAssetId, MultiTransactionPayment, Omnipool, RuntimeCall, RuntimeOrigin,
Tokens, XykPaymentAssetSupport,
Balances, Currencies, DotAssetId, MultiTransactionPayment, Omnipool, RuntimeCall, RuntimeOrigin, Tokens,
XykPaymentAssetSupport,
};
use hydradx_traits::AssetKind;
use hydradx_traits::Create;
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl pallet_evm::Config for crate::Runtime {
crate::Runtime,
ConvertAmount<ShortOraclePrice, XykPaymentAssetSupport, DotAssetId>,
FeeCurrencyOverrideOrDefault<WethAssetId, EvmAccounts<crate::Runtime>>, // Get account's fee payment asset
FungibleCurrencies<crate::Runtime>, // Account balance inspector
FungibleCurrencies<crate::Runtime>, // Account balance inspector
>,
>;
type RuntimeEvent = crate::RuntimeEvent;
Expand Down
10 changes: 6 additions & 4 deletions runtime/hydradx/src/evm/permit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::evm::precompiles;
use crate::ExtrinsicBaseWeight;
use evm::ExitReason;
use fp_evm::FeeCalculator;
use frame_support::dispatch::{DispatchErrorWithPostInfo, Pays, PostDispatchInfo, RawOrigin};
Expand All @@ -16,7 +17,6 @@ use sp_io::hashing::keccak_256;
use sp_runtime::traits::{One, UniqueSaturatedInto};
use sp_runtime::DispatchResult;
use sp_std::vec::Vec;
use crate::{ExtrinsicBaseWeight};

pub struct EvmPermitHandler<R>(sp_std::marker::PhantomData<R>);

Expand Down Expand Up @@ -165,10 +165,12 @@ where

fn dispatch_weight(gas_limit: u64) -> Weight {
let without_base_extrinsic_weight = true;
let weight = <R as pallet_evm::Config>::GasWeightMapping::gas_to_weight(gas_limit, without_base_extrinsic_weight);
let weight =
<R as pallet_evm::Config>::GasWeightMapping::gas_to_weight(gas_limit, without_base_extrinsic_weight);

// As GasWeightMapping implementation does not exclude the weight-with-swap (only the frame_system::constants::ExtrinsicBaseWeight), therefore we need to substract it manually
weight.saturating_sub(ExtrinsicBaseWeight::get())
// As GasWeightMapping implementation does not include/exclude the weight-with-swap (only the frame_system::constants::ExtrinsicBaseWeight)
// therefore we need to add it manually here
weight.saturating_add(ExtrinsicBaseWeight::get())
}

fn permit_nonce(account: H160) -> U256 {
Expand Down

0 comments on commit 8a11813

Please sign in to comment.