1use crate::{Runtime, RuntimeCall, UnifiedAccounts};
22use astar_primitives::precompiles::DispatchFilterValidate;
23use frame_support::traits::ConstU32;
24use frame_support::{parameter_types, traits::Contains};
25use pallet_evm_precompile_assets_erc20::Erc20AssetsPrecompileSet;
26use pallet_evm_precompile_blake2::Blake2F;
27use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing};
28use pallet_evm_precompile_dapp_staking::DappStakingV3Precompile;
29use pallet_evm_precompile_dispatch::Dispatch;
30use pallet_evm_precompile_dispatch_lockdrop::DispatchLockdrop;
31use pallet_evm_precompile_ed25519::Ed25519Verify;
32use pallet_evm_precompile_modexp::Modexp;
33use pallet_evm_precompile_sha3fips::Sha3FIPS256;
34use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256};
35use pallet_evm_precompile_sr25519::Sr25519Precompile;
36use pallet_evm_precompile_substrate_ecdsa::SubstrateEcdsaPrecompile;
37use pallet_evm_precompile_unified_accounts::UnifiedAccountsPrecompile;
38use pallet_evm_precompile_xcm::XcmPrecompile;
39use precompile_utils::precompile_set::*;
40use sp_std::fmt::Debug;
41
42pub const ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4];
45parameter_types! {
46 pub AssetPrefix: &'static [u8] = ASSET_PRECOMPILE_ADDRESS_PREFIX;
47}
48
49type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, CallableByPrecompile);
52
53pub struct WhitelistedCalls;
55
56impl Contains<RuntimeCall> for WhitelistedCalls {
57 fn contains(t: &RuntimeCall) -> bool {
58 match t {
59 RuntimeCall::Utility(pallet_utility::Call::batch { calls })
60 | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => {
61 calls.iter().all(|call| WhitelistedCalls::contains(call))
62 }
63 RuntimeCall::DappStaking(_) => true,
64 RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true,
65 RuntimeCall::XTokens(orml_xtokens::Call::transfer_multiasset_with_fee { .. }) => true,
66 RuntimeCall::XTokens(orml_xtokens::Call::transfer_multiasset { .. }) => true,
67 RuntimeCall::Democracy(_)
69 | RuntimeCall::Treasury(_)
70 | RuntimeCall::CommunityTreasury(_)
71 | RuntimeCall::Preimage(_) => true,
72 _ => false,
73 }
74 }
75}
76
77pub struct WhitelistedLockdropCalls;
79
80impl Contains<RuntimeCall> for WhitelistedLockdropCalls {
81 fn contains(t: &RuntimeCall) -> bool {
82 match t {
83 RuntimeCall::Utility(pallet_utility::Call::batch { calls })
84 | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => calls
85 .iter()
86 .all(|call| WhitelistedLockdropCalls::contains(call)),
87 RuntimeCall::DappStaking(pallet_dapp_staking::Call::unbond_and_unstake { .. }) => true,
88 RuntimeCall::DappStaking(pallet_dapp_staking::Call::withdraw_unbonded { .. }) => true,
89 RuntimeCall::Balances(pallet_balances::Call::transfer_all { .. }) => true,
90 RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { .. }) => true,
91 RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. }) => true,
92 RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true,
93 _ => false,
94 }
95 }
96}
97
98#[precompile_utils::precompile_name_from_address]
100pub type ShibuyaPrecompilesSetAt<R, C> = (
101 PrecompileAt<AddressU64<1>, ECRecover, EthereumPrecompilesChecks>,
104 PrecompileAt<AddressU64<2>, Sha256, EthereumPrecompilesChecks>,
105 PrecompileAt<AddressU64<3>, Ripemd160, EthereumPrecompilesChecks>,
106 PrecompileAt<AddressU64<4>, Identity, EthereumPrecompilesChecks>,
107 PrecompileAt<AddressU64<5>, Modexp, EthereumPrecompilesChecks>,
108 PrecompileAt<AddressU64<6>, Bn128Add, EthereumPrecompilesChecks>,
109 PrecompileAt<AddressU64<7>, Bn128Mul, EthereumPrecompilesChecks>,
110 PrecompileAt<AddressU64<8>, Bn128Pairing, EthereumPrecompilesChecks>,
111 PrecompileAt<AddressU64<9>, Blake2F, EthereumPrecompilesChecks>,
112 PrecompileAt<
114 AddressU64<1024>,
115 Sha3FIPS256<Runtime, ()>,
116 (CallableByContract, CallableByPrecompile),
117 >,
118 PrecompileAt<
119 AddressU64<1025>,
120 Dispatch<R, DispatchFilterValidate<RuntimeCall, WhitelistedCalls>>,
121 (),
123 >,
124 PrecompileAt<AddressU64<1026>, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>,
125 PrecompileAt<AddressU64<1027>, Ed25519Verify, (CallableByContract, CallableByPrecompile)>,
126 PrecompileAt<
128 AddressU64<20481>,
129 DappStakingV3Precompile<R>,
130 (CallableByContract, CallableByPrecompile),
131 >,
132 PrecompileAt<
133 AddressU64<20482>,
134 Sr25519Precompile<R>,
135 (CallableByContract, CallableByPrecompile),
136 >,
137 PrecompileAt<
138 AddressU64<20483>,
139 SubstrateEcdsaPrecompile<R>,
140 (CallableByContract, CallableByPrecompile),
141 >,
142 PrecompileAt<
143 AddressU64<20484>,
144 XcmPrecompile<R, C>,
145 (
146 SubcallWithMaxNesting<1>,
147 CallableByContract,
148 CallableByPrecompile,
149 ),
150 >,
151 PrecompileAt<
153 AddressU64<20486>,
154 UnifiedAccountsPrecompile<R, UnifiedAccounts>,
155 (CallableByContract, CallableByPrecompile),
156 >,
157 PrecompileAt<
158 AddressU64<20487>,
159 DispatchLockdrop<
160 R,
161 DispatchFilterValidate<RuntimeCall, WhitelistedLockdropCalls>,
162 ConstU32<8>,
163 >,
164 (),
166 >,
167);
168
169pub type ShibuyaPrecompiles<R, C> = PrecompileSetBuilder<
170 R,
171 (
172 PrecompilesInRangeInclusive<
174 (AddressU64<1>, AddressU64<40951>),
176 ShibuyaPrecompilesSetAt<R, C>,
177 >,
178 PrecompileSetStartingWith<AssetPrefix, Erc20AssetsPrecompileSet<R>, CallableByContract>,
180 ),
181>;