Skip to content

Commit

Permalink
Resolve merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Dec 5, 2023
1 parent 4cef3cf commit f3b0804
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions pallets/dapp-staking-v3/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ pub type EraRewardSpanFor<T> = EraRewardSpan<<T as Config>::EraRewardSpanLength>
// Convenience type for `DAppInfo` usage.
pub type DAppInfoFor<T> = DAppInfo<<T as frame_system::Config>::AccountId>;

// Convenience type for `ProtocolState` usage.
pub type ProtocolStateFor<T> = ProtocolState<BlockNumberFor<T>>;

/// Era number type
pub type EraNumber = u32;
/// Period number type
Expand Down
2 changes: 2 additions & 0 deletions precompiles/dapps-staking-v3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Astar
astar-primitives = { workspace = true }
pallet-dapp-staking-v3 = { workspace = true }
precompile-utils = { workspace = true, default-features = false }

Expand All @@ -43,6 +44,7 @@ default = ["std"]
std = [
"parity-scale-codec/std",
"scale-info/std",
"astar-primitives/std",
"sp-std/std",
"sp-core/std",
"sp-runtime/std",
Expand Down
38 changes: 14 additions & 24 deletions precompiles/dapps-staking-v3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
use fp_evm::{PrecompileHandle, PrecompileOutput};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};

use frame_support::{
dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo},
traits::Currency,
};
use frame_system::pallet_prelude::BlockNumberFor;
use frame_support::dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo};

use pallet_evm::{AddressMapping, Precompile};
use precompile_utils::{
Expand All @@ -39,16 +35,13 @@ use sp_runtime::traits::Zero;
use sp_std::{marker::PhantomData, prelude::*};
extern crate alloc;

use astar_primitives::Balance;
use pallet_dapp_staking_v3::{
AccountLedgerFor, ActiveProtocolState, ContractStake, ContractStakeAmount, CurrentEraInfo,
DAppInfoFor, EraInfo, EraRewardSpanFor, EraRewards, IntegratedDApps, Ledger,
Pallet as DAppStaking, ProtocolStateFor, SingularStakingInfo, StakerInfo,
Pallet as DAppStaking, ProtocolState, SingularStakingInfo, StakerInfo,
};

type BalanceOf<Runtime> = <<Runtime as pallet_dapp_staking_v3::Config>::Currency as Currency<
<Runtime as frame_system::Config>::AccountId,
>>::Balance;

// #[cfg(test)]
// mod mock;
// #[cfg(test)]
Expand All @@ -68,8 +61,6 @@ pub struct DappStakingV3Precompile<R>(PhantomData<R>);
impl<R> DappStakingV3Precompile<R>
where
R: pallet_evm::Config + pallet_dapp_staking_v3::Config,
BalanceOf<R>: EvmData,
BlockNumberFor<R>: EvmData,
<R::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<R::AccountId>>,
R::RuntimeCall: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
R::RuntimeCall: From<pallet_dapp_staking_v3::Call<R>>,
Expand All @@ -80,7 +71,7 @@ where
// TODO: benchmark this function so we can measure ref time & PoV correctly
// Storage item: ActiveProtocolState:
// Twox64(8) + ProtocolState::max_encoded_len
handle.record_db_read::<R>(4 + ProtocolStateFor::<R>::max_encoded_len())?;
handle.record_db_read::<R>(4 + ProtocolState::max_encoded_len())?;

let current_era = ActiveProtocolState::<R>::get().era;

Expand Down Expand Up @@ -135,7 +126,7 @@ where
// TODO: benchmark this function so we can measure ref time & PoV correctly
// Storage item: ActiveProtocolState:
// Twox64(8) + ProtocolState::max_encoded_len
handle.record_db_read::<R>(4 + ProtocolStateFor::<R>::max_encoded_len())?;
handle.record_db_read::<R>(4 + ProtocolState::max_encoded_len())?;

let current_era = ActiveProtocolState::<R>::get().era;

Expand Down Expand Up @@ -196,7 +187,7 @@ where
// Blake2_128Concat(16 + SmartContract::max_encoded_len) + Ledger::max_encoded_len
handle.record_db_read::<R>(
24 + AccountLedgerFor::<R>::max_encoded_len()
+ ProtocolStateFor::<R>::max_encoded_len()
+ ProtocolState::max_encoded_len()
+ <R as pallet_dapp_staking_v3::Config>::SmartContract::max_encoded_len(),
)?;

Expand Down Expand Up @@ -231,7 +222,7 @@ where
// Storage item: StakerInfo:
// Blake2_128Concat(16 + SmartContract::max_encoded_len) + SingularStakingInfo::max_encoded_len
handle.record_db_read::<R>(
24 + ProtocolStateFor::<R>::max_encoded_len()
24 + ProtocolState::max_encoded_len()
+ <R as pallet_dapp_staking_v3::Config>::SmartContract::max_encoded_len()
+ SingularStakingInfo::max_encoded_len(),
)?;
Expand Down Expand Up @@ -275,7 +266,7 @@ where
// Storage item: ContractStake:
// Twox64Concat(8) + EraIndex(4) + ContractStakeAmount::max_encoded_len
handle.record_db_read::<R>(
36 + ProtocolStateFor::<R>::max_encoded_len()
36 + ProtocolState::max_encoded_len()
+ <R as pallet_dapp_staking_v3::Config>::SmartContract::max_encoded_len()
+ DAppInfoFor::<R>::max_encoded_len()
+ ContractStakeAmount::max_encoded_len(),
Expand Down Expand Up @@ -326,7 +317,7 @@ where
// Blake2_128Concat(16 + SmartContract::max_encoded_len()) + Ledger::max_encoded_len
handle.record_db_read::<R>(
24 + AccountLedgerFor::<R>::max_encoded_len()
+ ProtocolStateFor::<R>::max_encoded_len()
+ ProtocolState::max_encoded_len()
+ <R as pallet_dapp_staking_v3::Config>::SmartContract::max_encoded_len(),
)?;

Expand All @@ -336,7 +327,7 @@ where
// Parse smart contract & amount
let contract_h160 = input.read::<Address>()?.0;
let smart_contract = Self::decode_smart_contract(contract_h160)?;
let amount: BalanceOf<R> = input.read()?;
let amount: Balance = input.read()?;

log::trace!(target: "ds-precompile", "bond_and_stake {:?}, {:?}", smart_contract, amount);

Expand Down Expand Up @@ -374,7 +365,7 @@ where
// Storage item: StakerInfo:
// Blake2_128Concat(16 + SmartContract::max_encoded_len) + SingularStakingInfo::max_encoded_len
handle.record_db_read::<R>(
24 + ProtocolStateFor::<R>::max_encoded_len()
24 + ProtocolState::max_encoded_len()
+ <R as pallet_dapp_staking_v3::Config>::SmartContract::max_encoded_len()
+ SingularStakingInfo::max_encoded_len(),
)?;
Expand All @@ -385,7 +376,7 @@ where
// Parse smart contract & amount
let contract_h160 = input.read::<Address>()?.0;
let smart_contract = Self::decode_smart_contract(contract_h160)?;
let amount: BalanceOf<R> = input.read()?;
let amount: Balance = input.read()?;
let origin = R::AddressMapping::into_account_id(handle.context().caller);
log::trace!(target: "ds-precompile", "unbond_and_unstake {:?}, {:?}", smart_contract, amount);

Expand Down Expand Up @@ -509,7 +500,7 @@ where
let origin_contract_h160 = input.read::<Address>()?.0;
let origin_smart_contract = Self::decode_smart_contract(origin_contract_h160)?;

let amount = input.read::<BalanceOf<R>>()?;
let amount = input.read::<Balance>()?;

let target_contract_h160 = input.read::<Address>()?.0;
let target_smart_contract = Self::decode_smart_contract(target_contract_h160)?;
Expand Down Expand Up @@ -629,8 +620,7 @@ where
+ Dispatchable<PostInfo = PostDispatchInfo>
+ GetDispatchInfo,
<R::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<R::AccountId>>,
BalanceOf<R>: EvmData,
BlockNumberFor<R>: EvmData,
Balance: EvmData,
R::AccountId: From<[u8; 32]>,
{
fn execute(handle: &mut impl PrecompileHandle) -> EvmResult<PrecompileOutput> {
Expand Down

0 comments on commit f3b0804

Please sign in to comment.