pallet_evm_precompile_xcm_transactor/v2/
mod.rs1use crate::functions::{CurrencyIdOf, GetDataLimit, TransactorOf, XcmTransactorWrapper};
20use fp_evm::PrecompileHandle;
21use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo};
22use pallet_evm::AddressMapping;
23use precompile_utils::prelude::*;
24use sp_core::{H160, U256};
25use sp_runtime::traits::Dispatchable;
26use sp_std::{convert::TryFrom, marker::PhantomData};
27use xcm::latest::Location;
28use xcm_primitives::AccountIdToCurrencyId;
29
30pub struct XcmTransactorPrecompileV2<Runtime>(PhantomData<Runtime>);
32
33#[precompile_utils::precompile]
34impl<Runtime> XcmTransactorPrecompileV2<Runtime>
35where
36 Runtime: pallet_xcm_transactor::Config + pallet_evm::Config + frame_system::Config,
37 Runtime::RuntimeCall: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
38 Runtime::RuntimeCall: From<pallet_xcm_transactor::Call<Runtime>>,
39 TransactorOf<Runtime>: TryFrom<u8>,
40 Runtime::AccountId: Into<H160>,
41 Runtime: AccountIdToCurrencyId<Runtime::AccountId, CurrencyIdOf<Runtime>>,
42 <Runtime as pallet_evm::Config>::AddressMapping: AddressMapping<Runtime::AccountId>,
43{
44 #[precompile::public("indexToAccount(uint16)")]
45 #[precompile::view]
46 fn index_to_account(handle: &mut impl PrecompileHandle, index: u16) -> EvmResult<Address> {
47 XcmTransactorWrapper::<Runtime>::account_index(handle, index)
48 }
49
50 #[precompile::public("transactInfoWithSigned((uint8,bytes[]))")]
51 #[precompile::view]
52 fn transact_info_with_signed(
53 handle: &mut impl PrecompileHandle,
54 location: Location,
55 ) -> EvmResult<(u64, u64, u64)> {
56 XcmTransactorWrapper::<Runtime>::transact_info_with_signed(handle, location)
57 }
58
59 #[precompile::public("feePerSecond((uint8,bytes[]))")]
60 #[precompile::view]
61 fn fee_per_second(handle: &mut impl PrecompileHandle, location: Location) -> EvmResult<U256> {
62 XcmTransactorWrapper::<Runtime>::fee_per_second(handle, location)
63 }
64
65 #[precompile::public(
66 "transactThroughDerivativeMultilocation(\
67 uint8,\
68 uint16,\
69 (uint8,bytes[]),\
70 uint64,bytes,\
71 uint256,\
72 uint64)"
73 )]
74 fn transact_through_derivative_multilocation(
75 handle: &mut impl PrecompileHandle,
76 transactor: u8,
77 index: u16,
78 fee_asset: Location,
79 weight: u64,
80 inner_call: BoundedBytes<GetDataLimit>,
81 fee_amount: Convert<U256, u128>,
82 overall_weight: u64,
83 ) -> EvmResult {
84 XcmTransactorWrapper::<Runtime>::transact_through_derivative_multilocation_fee_weight(
85 handle,
86 transactor,
87 index,
88 fee_asset,
89 weight,
90 inner_call,
91 fee_amount.converted(),
92 overall_weight,
93 )
94 }
95
96 #[precompile::public(
97 "transactThroughDerivative(\
98 uint8,\
99 uint16,\
100 address,\
101 uint64,\
102 bytes,\
103 uint256,\
104 uint64)"
105 )]
106 fn transact_through_derivative(
107 handle: &mut impl PrecompileHandle,
108 transactor: u8,
109 index: u16,
110 fee_asset: Address,
111 weight: u64,
112 inner_call: BoundedBytes<GetDataLimit>,
113 fee_amount: Convert<U256, u128>,
114 overall_weight: u64,
115 ) -> EvmResult {
116 XcmTransactorWrapper::<Runtime>::transact_through_derivative_fee_weight(
117 handle,
118 transactor,
119 index,
120 fee_asset,
121 weight,
122 inner_call,
123 fee_amount.converted(),
124 overall_weight,
125 )
126 }
127
128 #[precompile::public(
129 "transactThroughSignedMultilocation(\
130 (uint8,bytes[]),\
131 (uint8,bytes[]),\
132 uint64,\
133 bytes,\
134 uint256,\
135 uint64)"
136 )]
137 fn transact_through_signed_multilocation(
138 handle: &mut impl PrecompileHandle,
139 dest: Location,
140 fee_asset: Location,
141 weight: u64,
142 call: BoundedBytes<GetDataLimit>,
143 fee_amount: Convert<U256, u128>,
144 overall_weight: u64,
145 ) -> EvmResult {
146 XcmTransactorWrapper::<Runtime>::transact_through_signed_multilocation_fee_weight(
147 handle,
148 dest,
149 fee_asset,
150 weight,
151 call,
152 fee_amount.converted(),
153 overall_weight,
154 )
155 }
156
157 #[precompile::public(
158 "transactThroughSigned((uint8,bytes[]),address,uint64,bytes,uint256,uint64)"
159 )]
160 fn transact_through_signed(
161 handle: &mut impl PrecompileHandle,
162 dest: Location,
163 fee_asset: Address,
164 weight: u64,
165 call: BoundedBytes<GetDataLimit>,
166 fee_amount: Convert<U256, u128>,
167 overall_weight: u64,
168 ) -> EvmResult {
169 XcmTransactorWrapper::<Runtime>::transact_through_signed_fee_weight(
170 handle,
171 dest,
172 fee_asset,
173 weight,
174 call,
175 fee_amount.converted(),
176 overall_weight,
177 )
178 }
179
180 #[precompile::public("encodeUtilityAsDerivative(uint8,uint16,bytes)")]
181 #[precompile::public("encode_utility_as_derivative(uint8,uint16,bytes)")]
182 #[precompile::view]
183 fn encode_utility_as_derivative(
184 handle: &mut impl PrecompileHandle,
185 transactor: u8,
186 index: u16,
187 inner_call: BoundedBytes<GetDataLimit>,
188 ) -> EvmResult<UnboundedBytes> {
189 XcmTransactorWrapper::<Runtime>::encode_utility_as_derivative(
190 handle, transactor, index, inner_call,
191 )
192 }
193}