pallet_evm_precompile_xcm_transactor/v3/
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 sp_weights::Weight;
28use xcm::latest::Location;
29use xcm_primitives::AccountIdToCurrencyId;
30
31pub struct XcmTransactorPrecompileV3<Runtime>(PhantomData<Runtime>);
33
34#[precompile_utils::precompile]
35impl<Runtime> XcmTransactorPrecompileV3<Runtime>
36where
37 Runtime: pallet_xcm_transactor::Config + pallet_evm::Config + frame_system::Config,
38 Runtime::RuntimeCall: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
39 Runtime::RuntimeCall: From<pallet_xcm_transactor::Call<Runtime>>,
40 TransactorOf<Runtime>: TryFrom<u8>,
41 Runtime::AccountId: Into<H160>,
42 Runtime: AccountIdToCurrencyId<Runtime::AccountId, CurrencyIdOf<Runtime>>,
43 <Runtime as pallet_evm::Config>::AddressMapping: AddressMapping<Runtime::AccountId>,
44{
45 #[precompile::public("indexToAccount(uint16)")]
46 #[precompile::view]
47 fn index_to_account(handle: &mut impl PrecompileHandle, index: u16) -> EvmResult<Address> {
48 XcmTransactorWrapper::<Runtime>::account_index(handle, index)
49 }
50
51 #[precompile::public("transactInfoWithSigned((uint8,bytes[]))")]
52 #[precompile::view]
53 fn transact_info_with_signed(
54 handle: &mut impl PrecompileHandle,
55 location: Location,
56 ) -> EvmResult<(Weight, Weight, Weight)> {
57 XcmTransactorWrapper::<Runtime>::transact_info_with_signed_v3(handle, location)
58 }
59
60 #[precompile::public("feePerSecond((uint8,bytes[]))")]
61 #[precompile::view]
62 fn fee_per_second(handle: &mut impl PrecompileHandle, location: Location) -> EvmResult<U256> {
63 XcmTransactorWrapper::<Runtime>::fee_per_second(handle, location)
64 }
65
66 #[precompile::public(
67 "transactThroughDerivativeMultilocation(\
68 uint8,\
69 uint16,\
70 (uint8,bytes[]),\
71 (uint64,uint64),\
72 bytes,\
73 uint256,\
74 (uint64,uint64),\
75 bool)"
76 )]
77 fn transact_through_derivative_multilocation(
78 handle: &mut impl PrecompileHandle,
79 transactor: u8,
80 index: u16,
81 fee_asset: Location,
82 weight: Weight,
83 inner_call: BoundedBytes<GetDataLimit>,
84 fee_amount: Convert<U256, u128>,
85 overall_weight: Weight,
86 refund: bool,
87 ) -> EvmResult {
88 XcmTransactorWrapper::<Runtime>::transact_through_derivative_multilocation_v3(
89 handle,
90 transactor,
91 index,
92 fee_asset,
93 weight,
94 inner_call,
95 fee_amount.converted(),
96 overall_weight,
97 refund,
98 )
99 }
100
101 #[precompile::public(
102 "transactThroughDerivative(\
103 uint8,\
104 uint16,\
105 address,\
106 (uint64,uint64),\
107 bytes,\
108 uint256,\
109 (uint64,uint64),\
110 bool)"
111 )]
112 fn transact_through_derivative(
113 handle: &mut impl PrecompileHandle,
114 transactor: u8,
115 index: u16,
116 fee_asset: Address,
117 weight: Weight,
118 inner_call: BoundedBytes<GetDataLimit>,
119 fee_amount: Convert<U256, u128>,
120 overall_weight: Weight,
121 refund: bool,
122 ) -> EvmResult {
123 XcmTransactorWrapper::<Runtime>::transact_through_derivative_v3(
124 handle,
125 transactor,
126 index,
127 fee_asset,
128 weight,
129 inner_call,
130 fee_amount.converted(),
131 overall_weight,
132 refund,
133 )
134 }
135
136 #[precompile::public(
137 "transactThroughSignedMultilocation(\
138 (uint8,bytes[]),\
139 (uint8,bytes[]),\
140 (uint64,uint64),\
141 bytes,\
142 uint256,\
143 (uint64,uint64),\
144 bool)"
145 )]
146 fn transact_through_signed_multilocation(
147 handle: &mut impl PrecompileHandle,
148 dest: Location,
149 fee_asset: Location,
150 weight: Weight,
151 call: BoundedBytes<GetDataLimit>,
152 fee_amount: Convert<U256, u128>,
153 overall_weight: Weight,
154 refund: bool,
155 ) -> EvmResult {
156 XcmTransactorWrapper::<Runtime>::transact_through_signed_multilocation_v3(
157 handle,
158 dest,
159 fee_asset,
160 weight,
161 call,
162 fee_amount.converted(),
163 overall_weight,
164 refund,
165 )
166 }
167
168 #[precompile::public(
169 "transactThroughSigned(\
170 (uint8,bytes[]),\
171 address,\
172 (uint64,uint64),\
173 bytes,\
174 uint256,\
175 (uint64,uint64),\
176 bool)"
177 )]
178 fn transact_through_signed(
179 handle: &mut impl PrecompileHandle,
180 dest: Location,
181 fee_asset: Address,
182 weight: Weight,
183 call: BoundedBytes<GetDataLimit>,
184 fee_amount: Convert<U256, u128>,
185 overall_weight: Weight,
186 refund: bool,
187 ) -> EvmResult {
188 XcmTransactorWrapper::<Runtime>::transact_through_signed_v3(
189 handle,
190 dest,
191 fee_asset,
192 weight,
193 call,
194 fee_amount.converted(),
195 overall_weight,
196 refund,
197 )
198 }
199
200 #[precompile::public("encodeUtilityAsDerivative(uint8,uint16,bytes)")]
201 #[precompile::public("encode_utility_as_derivative(uint8,uint16,bytes)")]
202 #[precompile::view]
203 fn encode_utility_as_derivative(
204 handle: &mut impl PrecompileHandle,
205 transactor: u8,
206 index: u16,
207 inner_call: BoundedBytes<GetDataLimit>,
208 ) -> EvmResult<UnboundedBytes> {
209 XcmTransactorWrapper::<Runtime>::encode_utility_as_derivative(
210 handle, transactor, index, inner_call,
211 )
212 }
213}