Skip to content

Commit

Permalink
only enable liquid crowdloan for acala
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Jul 12, 2023
1 parent 38b0b15 commit 9973dcb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 21 deletions.
8 changes: 6 additions & 2 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use codec::{Decode, DecodeLimit, Encode};
use runtime_common::precompile::AcalaPrecompiles;
use scale_info::TypeInfo;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160};
Expand Down Expand Up @@ -1407,7 +1408,9 @@ parameter_types! {
pub NetworkContractSource: H160 = H160::from_low_u64_be(0);
pub DeveloperDeposit: Balance = 50 * dollar(ACA);
pub PublicationFee: Balance = 10 * dollar(ACA);
pub PrecompilesValue: AllPrecompiles<Runtime, module_transaction_pause::PausedPrecompileFilter<Runtime>> = AllPrecompiles::<_, _>::acala();
pub PrecompilesValue: AllPrecompiles<
Runtime, module_transaction_pause::PausedPrecompileFilter<Runtime>, AcalaPrecompiles<Runtime>
> = AllPrecompiles::<_, _, _>::acala();
}

#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)]
Expand Down Expand Up @@ -1448,7 +1451,8 @@ impl module_evm::Config for Runtime {
type StorageDepositPerByte = StorageDepositPerByte;
type TxFeePerGas = TxFeePerGas;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = AllPrecompiles<Self, module_transaction_pause::PausedPrecompileFilter<Self>>;
type PrecompilesType =
AllPrecompiles<Self, module_transaction_pause::PausedPrecompileFilter<Self>, AcalaPrecompiles<Self>>;
type PrecompilesValue = PrecompilesValue;
type GasToWeight = GasToWeight;
type ChargeTransactionPayment = module_transaction_payment::ChargeTransactionPayment<Runtime>;
Expand Down
4 changes: 2 additions & 2 deletions runtime/common/src/precompile/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ pub type EvmErc20InfoMapping = module_asset_registry::EvmErc20InfoMapping<Test>;

parameter_types! {
pub NetworkContractSource: H160 = alice_evm_addr();
pub PrecompilesValue: AllPrecompiles<Test, module_transaction_pause::PausedPrecompileFilter<Test>> = AllPrecompiles::<_, _>::mandala();
pub PrecompilesValue: AllPrecompiles<Test, module_transaction_pause::PausedPrecompileFilter<Test>, ()> = AllPrecompiles::<_, _, _>::mandala();
}

ord_parameter_types! {
Expand All @@ -587,7 +587,7 @@ impl module_evm::Config for Test {
type StorageDepositPerByte = StorageDepositPerByte;
type TxFeePerGas = ConstU128<10>;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = AllPrecompiles<Self, module_transaction_pause::PausedPrecompileFilter<Self>>;
type PrecompilesType = AllPrecompiles<Self, module_transaction_pause::PausedPrecompileFilter<Self>, ()>;
type PrecompilesValue = PrecompilesValue;
type GasToWeight = GasToWeight;
type ChargeTransactionPayment = module_transaction_payment::ChargeTransactionPayment<Test>;
Expand Down
55 changes: 42 additions & 13 deletions runtime/common/src/precompile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ pub fn target_gas_limit(target_gas: Option<u64>) -> Option<u64> {
target_gas.map(|x| x.saturating_div(10).saturating_mul(9)) // 90%
}

pub struct AllPrecompiles<R, F> {
pub struct AllPrecompiles<R, F, E> {
set: BTreeSet<H160>,
_marker: PhantomData<(R, F)>,
_marker: PhantomData<(R, F, E)>,
}

impl<R, F> AllPrecompiles<R, F>
impl<R, F, E> AllPrecompiles<R, F, E>
where
R: module_evm::Config,
E: PrecompileSet,
{
pub fn acala() -> Self {
Self {
Expand Down Expand Up @@ -176,7 +177,7 @@ where
HONZON,
INCENTIVES,
XTOKENS,
LIQUID_CROWDLOAN,
// LIQUID_CROWDLOAN,
]),
_marker: Default::default(),
}
Expand Down Expand Up @@ -211,16 +212,17 @@ where
HONZON,
INCENTIVES,
XTOKENS,
LIQUID_CROWDLOAN,
// LIQUID_CROWDLOAN,
]),
_marker: Default::default(),
}
}
}

impl<R, PausedPrecompile> PrecompileSet for AllPrecompiles<R, PausedPrecompile>
impl<R, PausedPrecompile, E> PrecompileSet for AllPrecompiles<R, PausedPrecompile, E>
where
R: module_evm::Config,
E: PrecompileSet + Default,
PausedPrecompile: PrecompilePauseFilter,
MultiCurrencyPrecompile<R>: Precompile,
NFTPrecompile<R>: Precompile,
Expand All @@ -234,7 +236,6 @@ where
HonzonPrecompile<R>: Precompile,
IncentivesPrecompile<R>: Precompile,
XtokensPrecompile<R>: Precompile,
LiquidCrowdloanPrecompile<R>: Precompile,
{
fn execute(
&self,
Expand Down Expand Up @@ -353,12 +354,8 @@ where
))
} else if address == XTOKENS {
Some(XtokensPrecompile::<R>::execute(input, target_gas, context, is_static))
} else if address == LIQUID_CROWDLOAN {
Some(LiquidCrowdloanPrecompile::<R>::execute(
input, target_gas, context, is_static,
))
} else {
None
E::execute(&Default::default(), address, input, target_gas, context, is_static)
}
};

Expand All @@ -370,7 +367,39 @@ where
}

fn is_precompile(&self, address: H160) -> bool {
self.set.contains(&address)
self.set.contains(&address) || E::is_precompile(&Default::default(), address)
}
}

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

impl<R> Default for AcalaPrecompiles<R> {
fn default() -> Self {
Self(sp_std::marker::PhantomData)
}
}

impl<R> PrecompileSet for AcalaPrecompiles<R>
where
LiquidCrowdloanPrecompile<R>: Precompile,
{
fn execute(
&self,
address: H160,
input: &[u8],
gas_limit: Option<u64>,
context: &Context,
is_static: bool,
) -> Option<PrecompileResult> {
if address == LIQUID_CROWDLOAN {
Some(LiquidCrowdloanPrecompile::execute(input, gas_limit, context, is_static))
} else {
None
}
}

fn is_precompile(&self, address: H160) -> bool {
address == LIQUID_CROWDLOAN
}
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ parameter_types! {
pub NetworkContractSource: H160 = H160::from_low_u64_be(0);
pub DeveloperDeposit: Balance = 50 * dollar(KAR);
pub PublicationFee: Balance = 10 * dollar(KAR);
pub PrecompilesValue: AllPrecompiles<Runtime, module_transaction_pause::PausedPrecompileFilter<Runtime>> = AllPrecompiles::<_, _>::karura();
pub PrecompilesValue: AllPrecompiles<Runtime, module_transaction_pause::PausedPrecompileFilter<Runtime>, ()> = AllPrecompiles::<_, _, _>::karura();
}

#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)]
Expand Down Expand Up @@ -1466,7 +1466,7 @@ impl module_evm::Config for Runtime {
type StorageDepositPerByte = StorageDepositPerByte;
type TxFeePerGas = TxFeePerGas;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = AllPrecompiles<Self, module_transaction_pause::PausedPrecompileFilter<Self>>;
type PrecompilesType = AllPrecompiles<Self, module_transaction_pause::PausedPrecompileFilter<Self>, ()>;
type PrecompilesValue = PrecompilesValue;
type GasToWeight = GasToWeight;
type ChargeTransactionPayment = module_transaction_payment::ChargeTransactionPayment<Runtime>;
Expand Down
4 changes: 2 additions & 2 deletions runtime/mandala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ impl pallet_proxy::Config for Runtime {

parameter_types! {
pub NetworkContractSource: H160 = H160::from_low_u64_be(0);
pub PrecompilesValue: AllPrecompiles<Runtime, module_transaction_pause::PausedPrecompileFilter<Runtime>> = AllPrecompiles::<_, _>::mandala();
pub PrecompilesValue: AllPrecompiles<Runtime, module_transaction_pause::PausedPrecompileFilter<Runtime>, ()> = AllPrecompiles::<_, _, _>::mandala();
}

#[cfg(feature = "with-ethereum-compatibility")]
Expand Down Expand Up @@ -1639,7 +1639,7 @@ impl module_evm::Config for Runtime {
type StorageDepositPerByte = StorageDepositPerByte;
type TxFeePerGas = TxFeePerGas;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = AllPrecompiles<Self, module_transaction_pause::PausedPrecompileFilter<Self>>;
type PrecompilesType = AllPrecompiles<Self, module_transaction_pause::PausedPrecompileFilter<Self>, ()>;
type PrecompilesValue = PrecompilesValue;
type GasToWeight = GasToWeight;
type ChargeTransactionPayment = module_transaction_payment::ChargeTransactionPayment<Runtime>;
Expand Down

0 comments on commit 9973dcb

Please sign in to comment.