diff --git a/auction-server/src/api/marketplace.rs b/auction-server/src/api/marketplace.rs index d4075961..c8066805 100644 --- a/auction-server/src/api/marketplace.rs +++ b/auction-server/src/api/marketplace.rs @@ -45,7 +45,9 @@ pub struct TokenQty { } /// A liquidation opportunity ready to be executed. -/// If a searcher signs the opportunity and have approved enough tokens to liquidation adapter, by calling this contract with the given calldata and structures, they will receive the tokens specified in the receipt_tokens field, and will send the tokens specified in the repay_tokens field. +/// If a searcher signs the opportunity and have approved enough tokens to liquidation adapter, +/// by calling this contract with the given calldata and structures, they will receive the tokens specified +/// in the receipt_tokens field, and will send the tokens specified in the repay_tokens field. #[derive(Serialize, Deserialize, ToSchema, Clone)] pub struct LiquidationOpportunity { /// The permission key required for succesful execution of the liquidation. @@ -68,8 +70,7 @@ pub struct LiquidationOpportunity { receipt_tokens: Vec, } -/// A submitted liquidation opportunity ready to be executed. -/// If a searcher signs the opportunity and have approved enough tokens to liquidation adapter, by calling this contract with the given calldata and structures, they will receive the tokens specified in the receipt_tokens field, and will send the tokens specified in the repay_tokens field. +/// Similar to LiquidationOpportunity, but with the opportunity id included. #[derive(Serialize, Deserialize, ToSchema, Clone)] pub struct LiquidationOpportunityWithId { /// The opportunity unique id @@ -104,7 +105,8 @@ fn parse_tokens(tokens: Vec) -> Result, RestError /// Submit a liquidation opportunity ready to be executed. /// -/// The opportunity will be verified by the server. If the opportunity is valid, it will be stored in the database and will be available for bidding. +/// The opportunity will be verified by the server. If the opportunity is valid, it will be stored in the database +/// and will be available for bidding. #[utoipa::path(post, path = "/liquidation/submit_opportunity", request_body = LiquidationOpportunity, responses( (status = 200, description = "Opportunity was stored succesfuly with the returned uuid", body = String), (status = 400, response=RestError) @@ -277,7 +279,7 @@ pub async fn bid_opportunity( Ok(_) => Ok("OK".to_string()), Err(e) => match e { RestError::SimulationError { result, reason } => { - let parsed = parse_revert_error(result.clone()); + let parsed = parse_revert_error(&result); match parsed { Some(decoded) => Err(RestError::BadParameters(decoded)), None => { diff --git a/auction-server/src/api/rest.rs b/auction-server/src/api/rest.rs index f093418e..d288c82d 100644 --- a/auction-server/src/api/rest.rs +++ b/auction-server/src/api/rest.rs @@ -1,10 +1,7 @@ use { crate::{ api::RestError, - auction::{ - per::MulticallStatus, - simulate_bids, - }, + auction::simulate_bids, state::{ SimulatedBid, Store, @@ -75,20 +72,16 @@ pub async fn handle_bid(store: Arc, bid: ParsedBid) -> Result { - let multicall_results: Vec = result; - if !multicall_results.iter().all(|x| x.external_success) { - let first_reason = multicall_results - .first() - .cloned() - .unwrap() - .multicall_revert_reason; - let first_result = multicall_results.first().cloned().unwrap().external_result; - return Err(RestError::SimulationError { - result: first_result, - reason: first_reason, + Ok(results) => { + results + .iter() + .find(|x| !x.external_success) + .map(|call_status| { + return Err(RestError::SimulationError { + result: call_status.external_result, + reason: call_status.multicall_revert_reason.clone(), + }); }); - } } Err(e) => { return match e { diff --git a/auction-server/src/liquidation_adapter.rs b/auction-server/src/liquidation_adapter.rs index b142ee3a..aae0bce1 100644 --- a/auction-server/src/liquidation_adapter.rs +++ b/auction-server/src/liquidation_adapter.rs @@ -79,14 +79,18 @@ pub fn verify_signature(params: liquidation_adapter::LiquidationCallParams) -> R }) } -pub fn parse_revert_error(revert: Bytes) -> Option { - let apdapter_decoded = - liquidation_adapter::LiquidationAdapterErrors::decode_with_selector(&revert) - .map(|err| format!("Liquidation Adapter Contract Revert Error: {:#?}", err)); - let erc20_decoded = erc20::ERC20Errors::decode_with_selector(&revert).map(|err| { - tracing::info!("ERC20 Contract Revert Error: {:#?}", err); - format!("ERC20 Contract Revert Error: {:#?}", err) +pub fn parse_revert_error(revert: &Bytes) -> Option { + let apdapter_decoded = liquidation_adapter::LiquidationAdapterErrors::decode_with_selector( + revert, + ) + .map(|decoded_error| { + format!( + "Liquidation Adapter Contract Revert Error: {:#?}", + decoded_error + ) }); + let erc20_decoded = erc20::ERC20Errors::decode_with_selector(revert) + .map(|decoded_error| format!("ERC20 Contract Revert Error: {:#?}", decoded_error)); apdapter_decoded.or(erc20_decoded) }