@@ -114,22 +114,15 @@ where
114114
115115 EvmSwapT :: NativeToken :: can_deposit ( & to, estimated_swapped_balance, Provenance :: Extant )
116116 . into_result ( )
117- . map_err ( |err| {
118- process_dispatch_error ( err, "unable to deposit into target native account" )
119- } ) ?;
117+ . map_err ( process_dispatch_error) ?;
120118
121119 EvmSwapT :: EvmToken :: transfer (
122120 & from,
123121 & EvmSwapT :: BridgePotEvm :: get ( ) ,
124122 value,
125123 Preservation :: Expendable ,
126124 )
127- . map_err ( |err| {
128- process_dispatch_error (
129- err,
130- "unable to transfer from source evm to bridge pot evm account" ,
131- )
132- } ) ?;
125+ . map_err ( process_dispatch_error) ?;
133126
134127 EvmSwapT :: NativeToken :: transfer (
135128 & EvmSwapT :: BridgePotNative :: get ( ) ,
@@ -138,12 +131,7 @@ where
138131 // Bridge pot native account shouldn't be killed.
139132 Preservation :: Preserve ,
140133 )
141- . map_err ( |err| {
142- process_dispatch_error (
143- err,
144- "unable to transfer from bridge pot native to target native account" ,
145- )
146- } ) ?;
134+ . map_err ( process_dispatch_error) ?;
147135
148136 let logs_builder = LogsBuilder :: new ( handle. context ( ) . address ) ;
149137
@@ -161,20 +149,27 @@ where
161149}
162150
163151/// A helper function to process dispatch related errors.
164- fn process_dispatch_error (
165- error : DispatchError ,
166- other_error_message : & ' static str ,
167- ) -> PrecompileFailure {
152+ fn process_dispatch_error ( error : DispatchError ) -> PrecompileFailure {
168153 match error {
169154 DispatchError :: Token ( frame_support:: sp_runtime:: TokenError :: FundsUnavailable ) => {
170155 PrecompileFailure :: Error {
171156 exit_status : ExitError :: OutOfFund ,
172157 }
173158 }
174- other_error_details => PrecompileFailure :: Error {
175- exit_status : ExitError :: Other (
176- format ! ( "{other_error_message}: {other_error_details:?}" ) . into ( ) ,
177- ) ,
159+ DispatchError :: Token ( frame_support:: sp_runtime:: TokenError :: BelowMinimum ) => {
160+ PrecompileFailure :: Error {
161+ exit_status : ExitError :: Other (
162+ "resulted balance is less than existential deposit" . into ( ) ,
163+ ) ,
164+ }
165+ }
166+ DispatchError :: Token ( frame_support:: sp_runtime:: TokenError :: NotExpendable ) => {
167+ PrecompileFailure :: Error {
168+ exit_status : ExitError :: Other ( "account would be killed" . into ( ) ) ,
169+ }
170+ }
171+ _ => PrecompileFailure :: Error {
172+ exit_status : ExitError :: Other ( "unable to execute swap" . into ( ) ) ,
178173 } ,
179174 }
180175}
0 commit comments