Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m committed Feb 3, 2024
1 parent 28d0a88 commit 239bc6d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
10 changes: 7 additions & 3 deletions auction-server/src/api/marketplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -69,7 +71,9 @@ pub struct LiquidationOpportunity {
}

/// 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.
/// 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 LiquidationOpportunityWithId {
/// The opportunity unique id
Expand Down Expand Up @@ -277,7 +281,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 => {
Expand Down
27 changes: 10 additions & 17 deletions auction-server/src/api/rest.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use {
crate::{
api::RestError,
auction::{
per::MulticallStatus,
simulate_bids,
},
auction::simulate_bids,
state::{
SimulatedBid,
Store,
Expand Down Expand Up @@ -75,20 +72,16 @@ pub async fn handle_bid(store: Arc<Store>, bid: ParsedBid) -> Result<String, Res
);

match call.await {
Ok(result) => {
let multicall_results: Vec<MulticallStatus> = 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 {
Expand Down
18 changes: 11 additions & 7 deletions auction-server/src/liquidation_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ pub fn verify_signature(params: liquidation_adapter::LiquidationCallParams) -> R
})
}

pub fn parse_revert_error(revert: Bytes) -> Option<String> {
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<String> {
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)
}

Expand Down

0 comments on commit 239bc6d

Please sign in to comment.