Skip to content

Commit 791471b

Browse files
committed
chore : cleanup
1 parent db4f0dc commit 791471b

File tree

12 files changed

+306
-288
lines changed

12 files changed

+306
-288
lines changed

precompiles/assets-erc20/src/lib.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ where
120120
Runtime: AddressToAssetId<AssetIdOf<Runtime, Instance>>,
121121
<<Runtime as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin: OriginTrait,
122122
AssetIdOf<Runtime, Instance>: Display,
123+
Runtime::AccountId: From<<<Runtime as pallet_evm::Config>::AccountProvider as fp_evm::AccountProvider>::AccountId>,
123124
{
124125
/// PrecompileSet discriminant. Allows knowing if the address maps to an asset id,
125126
/// and if this is the case which one.
@@ -172,11 +173,11 @@ where
172173

173174
let who: H160 = who.into();
174175

175-
// Fetch info.
176-
let amount: U256 = {
177-
let who: Runtime::AccountId = Runtime::AddressMapping::into_account_id(who);
178-
pallet_assets::Pallet::<Runtime, Instance>::balance(asset_id, &who).into()
179-
};
176+
// Fetch info.
177+
let amount: U256 = {
178+
let who: Runtime::AccountId = Runtime::AddressMapping::into_account_id(who).into();
179+
pallet_assets::Pallet::<Runtime, Instance>::balance(asset_id, &who).into()
180+
};
180181

181182
// Build output.
182183
Ok(amount)
@@ -197,10 +198,10 @@ where
197198
let owner: H160 = owner.into();
198199
let spender: H160 = spender.into();
199200

200-
// Fetch info.
201-
let amount: U256 = {
202-
let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(owner);
203-
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender);
201+
// Fetch info.
202+
let amount: U256 = {
203+
let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(owner).into();
204+
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender).into();
204205

205206
// Fetch info.
206207
pallet_assets::Pallet::<Runtime, Instance>::allowance(asset_id, &owner, &spender).into()
@@ -243,20 +244,20 @@ where
243244
spender: H160,
244245
value: U256,
245246
) -> EvmResult {
246-
let owner = Runtime::AddressMapping::into_account_id(owner);
247-
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender);
248-
// Amount saturate if too high.
249-
let amount: BalanceOf<Runtime, Instance> =
250-
value.try_into().unwrap_or_else(|_| Bounded::max_value());
251-
252-
// Storage item: Approvals:
253-
// Blake2_128(16) + AssetId(16) + (2 * Blake2_128(16) + AccountId(20)) + Approval(32)
254-
handle.record_db_read::<Runtime>(136)?;
255-
256-
// If previous approval exists, we need to clean it
257-
if pallet_assets::Pallet::<Runtime, Instance>::allowance(asset_id.clone(), &owner, &spender) !=
258-
0u32.into()
259-
{
247+
let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(owner).into();
248+
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender).into();
249+
// Amount saturate if too high.
250+
let amount: BalanceOf<Runtime, Instance> =
251+
value.try_into().unwrap_or_else(|_| Bounded::max_value());
252+
253+
// Storage item: Approvals:
254+
// Blake2_128(16) + AssetId(16) + (2 * Blake2_128(16) + AccountId(20)) + Approval(32)
255+
handle.record_db_read::<Runtime>(136)?;
256+
257+
// If previous approval exists, we need to clean it
258+
if pallet_assets::Pallet::<Runtime, Instance>::allowance(asset_id.clone(), &owner, &spender) !=
259+
0u32.into()
260+
{
260261
RuntimeHelper::<Runtime>::try_dispatch(
261262
handle,
262263
<Runtime as frame_system::Config>::RuntimeOrigin::signed(owner.clone()),

precompiles/balances-erc20/src/eip2612.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ where
140140
Erc20BalancesPrecompile::<Runtime, Metadata, Instance>::u256_to_amount(value)
141141
.unwrap_or_else(|_| Bounded::max_value());
142142

143-
let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(owner);
144-
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender);
143+
let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(owner).into();
144+
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender).into();
145145
ApprovesStorage::<Runtime, Instance>::insert(owner, spender, amount);
146146
}
147147

precompiles/balances-erc20/src/lib.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use frame_support::{
2424
dispatch::{GetDispatchInfo, PostDispatchInfo},
2525
sp_runtime::traits::{Bounded, CheckedSub, Dispatchable, StaticLookup},
2626
storage::types::{StorageDoubleMap, StorageMap, ValueQuery},
27-
traits::StorageInstance,
27+
traits::{OriginTrait, StorageInstance},
2828
Blake2_128Concat,
2929
};
3030
use pallet_balances::pallet::{
@@ -194,7 +194,7 @@ where
194194
BalanceOf<Runtime, Instance>: TryFrom<U256> + Into<U256>,
195195
Metadata: Erc20Metadata,
196196
Instance: InstanceToPrefix + 'static,
197-
Runtime::AccountId: From<AccountId32>,
197+
Runtime::AccountId: From<AccountId32> + From<<<Runtime as pallet_evm::Config>::AccountProvider as fp_evm::AccountProvider>::AccountId>,
198198
{
199199
#[precompile::public("totalSupply()")]
200200
#[precompile::view]
@@ -212,8 +212,8 @@ where
212212
// Blake2128(16) + AccountId(20) + AccountInfo ((4 * 4) + AccountData(16 * 4))
213213
handle.record_db_read::<Runtime>(116)?;
214214

215-
let owner: H160 = owner.into();
216-
let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(owner);
215+
let owner: H160 = owner.into();
216+
let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(owner).into();
217217

218218
Ok(pallet_balances::Pallet::<Runtime, Instance>::usable_balance(&owner).into())
219219
}
@@ -232,8 +232,8 @@ where
232232
let owner: H160 = owner.into();
233233
let spender: H160 = spender.into();
234234

235-
let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(owner);
236-
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender);
235+
let owner: Runtime::AccountId = Runtime::AddressMapping::into_account_id(owner).into();
236+
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender).into();
237237

238238
Ok(ApprovesStorage::<Runtime, Instance>::get(owner, spender)
239239
.unwrap_or_default()
@@ -253,9 +253,9 @@ where
253253

254254
// Write into storage.
255255
{
256-
let caller: Runtime::AccountId =
257-
Runtime::AddressMapping::into_account_id(handle.context().caller);
258-
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender);
256+
let caller: Runtime::AccountId =
257+
Runtime::AddressMapping::into_account_id(handle.context().caller).into();
258+
let spender: Runtime::AccountId = Runtime::AddressMapping::into_account_id(spender).into();
259259
// Amount saturate if too high.
260260
let value = Self::u256_to_amount(value).unwrap_or_else(|_| Bounded::max_value());
261261

@@ -283,14 +283,14 @@ where
283283

284284
// Build call with origin.
285285
{
286-
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
287-
let to = Runtime::AddressMapping::into_account_id(to);
286+
let origin: Runtime::AccountId = Runtime::AddressMapping::into_account_id(handle.context().caller).into();
287+
let to: Runtime::AccountId = Runtime::AddressMapping::into_account_id(to).into();
288288
let value = Self::u256_to_amount(value).in_field("value")?;
289289

290290
// Dispatch call (if enough gas).
291291
RuntimeHelper::<Runtime>::try_dispatch(
292292
handle,
293-
RuntimeOrigin::signed(origin),
293+
<Runtime as frame_system::Config>::RuntimeOrigin::signed(origin),
294294
pallet_balances::Call::<Runtime, Instance>::transfer_allow_death {
295295
dest: Runtime::Lookup::unlookup(to),
296296
value,
@@ -324,13 +324,13 @@ where
324324

325325
// Build call with origin.
326326
{
327-
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
328-
let value = Self::u256_to_amount(value).in_field("value")?;
327+
let origin: Runtime::AccountId = Runtime::AddressMapping::into_account_id(handle.context().caller).into();
328+
let value = Self::u256_to_amount(value).in_field("value")?;
329329

330330
// Dispatch call (if enough gas).
331331
RuntimeHelper::<Runtime>::try_dispatch(
332332
handle,
333-
RuntimeOrigin::signed(origin),
333+
<Runtime as frame_system::Config>::RuntimeOrigin::signed(origin),
334334
pallet_balances::Call::<Runtime, Instance>::transfer_allow_death {
335335
dest: Runtime::Lookup::unlookup(to_account_id),
336336
value,
@@ -367,10 +367,10 @@ where
367367
let to: H160 = to.into();
368368

369369
{
370-
let caller: Runtime::AccountId =
371-
Runtime::AddressMapping::into_account_id(handle.context().caller);
372-
let from: Runtime::AccountId = Runtime::AddressMapping::into_account_id(from);
373-
let to: Runtime::AccountId = Runtime::AddressMapping::into_account_id(to);
370+
let caller: Runtime::AccountId =
371+
Runtime::AddressMapping::into_account_id(handle.context().caller).into();
372+
let from: Runtime::AccountId = Runtime::AddressMapping::into_account_id(from).into();
373+
let to: Runtime::AccountId = Runtime::AddressMapping::into_account_id(to).into();
374374
let value = Self::u256_to_amount(value).in_field("value")?;
375375

376376
// If caller is "from", it can spend as much as it wants.
@@ -442,9 +442,9 @@ where
442442
return Err(RevertReason::UnknownSelector.into());
443443
}
444444

445-
let caller: Runtime::AccountId =
446-
Runtime::AddressMapping::into_account_id(handle.context().caller);
447-
let precompile = Runtime::AddressMapping::into_account_id(handle.context().address);
445+
let caller: Runtime::AccountId =
446+
Runtime::AddressMapping::into_account_id(handle.context().caller).into();
447+
let precompile: Runtime::AccountId = Runtime::AddressMapping::into_account_id(handle.context().address).into();
448448
let amount = Self::u256_to_amount(handle.context().apparent_value)?;
449449

450450
if amount.into() == U256::from(0u32) {
@@ -484,9 +484,9 @@ where
484484
handle.record_log_costs_manual(2, 32)?;
485485

486486
let account_amount: U256 = {
487-
let owner: Runtime::AccountId =
488-
Runtime::AddressMapping::into_account_id(handle.context().caller);
489-
pallet_balances::Pallet::<Runtime, Instance>::usable_balance(&owner).into()
487+
let owner: Runtime::AccountId =
488+
Runtime::AddressMapping::into_account_id(handle.context().caller).into();
489+
pallet_balances::Pallet::<Runtime, Instance>::usable_balance(&owner).into()
490490
};
491491

492492
if value > account_amount {

precompiles/credits/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ where
3030
<Runtime::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<Runtime::AccountId>>,
3131
Runtime::RuntimeCall: From<pallet_credits::Call<Runtime>>,
3232
BalanceOf<Runtime>: TryFrom<U256> + Into<U256> + solidity::Codec,
33+
Runtime::AccountId: From<<<Runtime as pallet_evm::Config>::AccountProvider as fp_evm::AccountProvider>::AccountId>,
3334
{
3435
fn default() -> Self {
3536
Self::new()
@@ -43,6 +44,7 @@ where
4344
<Runtime::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<Runtime::AccountId>>,
4445
Runtime::RuntimeCall: From<pallet_credits::Call<Runtime>>,
4546
BalanceOf<Runtime>: TryFrom<U256> + Into<U256> + solidity::Codec,
47+
Runtime::AccountId: From<<<Runtime as pallet_evm::Config>::AccountProvider as fp_evm::AccountProvider>::AccountId>,
4648
{
4749
pub fn new() -> Self {
4850
Self(PhantomData)
@@ -67,12 +69,13 @@ where
6769
<Runtime::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<Runtime::AccountId>>,
6870
Runtime::RuntimeCall: From<pallet_credits::Call<Runtime>>,
6971
BalanceOf<Runtime>: TryFrom<U256> + Into<U256> + solidity::Codec,
72+
Runtime::AccountId: From<<<Runtime as pallet_evm::Config>::AccountProvider as fp_evm::AccountProvider>::AccountId>,
7073
{
7174
#[precompile::public("burn(uint256)")]
7275
fn burn(handle: &mut impl PrecompileHandle, amount: U256) -> EvmResult<bool> {
7376
handle.record_cost(RuntimeHelper::<Runtime>::db_write_gas_cost())?;
7477

75-
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
78+
let origin: Runtime::AccountId = Runtime::AddressMapping::into_account_id(handle.context().caller).into();
7679
let amount = Self::u256_to_balance(amount)?;
7780

7881
let call = pallet_credits::Call::<Runtime>::burn { amount };
@@ -89,7 +92,7 @@ where
8992
) -> EvmResult<bool> {
9093
handle.record_cost(RuntimeHelper::<Runtime>::db_write_gas_cost())?;
9194

92-
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
95+
let origin: Runtime::AccountId = Runtime::AddressMapping::into_account_id(handle.context().caller).into();
9396
let amount_to_claim = Self::u256_to_balance(amount_to_claim)?;
9497

9598
// Convert BoundedBytes to BoundedVec<u8>
@@ -125,10 +128,10 @@ where
125128
handle: &mut impl PrecompileHandle,
126129
account: Address,
127130
) -> EvmResult<U256> {
128-
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
131+
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
129132

130-
let account_id = Runtime::AddressMapping::into_account_id(account.into());
131-
let current_block = frame_system::Pallet::<Runtime>::block_number();
133+
let account_id: Runtime::AccountId = Runtime::AddressMapping::into_account_id(account.into()).into();
134+
let current_block = frame_system::Pallet::<Runtime>::block_number();
132135

133136
// Call the internal pallet function to calculate accrued credits
134137
let accrued_amount =

0 commit comments

Comments
 (0)