Skip to content

Commit 789b026

Browse files
authored
Update threshold for bid amount based on gas fees (#106)
1 parent cc4b8ec commit 789b026

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

auction-server/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auction-server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "auction-server"
3-
version = "0.9.2"
3+
version = "0.9.3"
44
edition = "2021"
55
license-file = "license.txt"
66

auction-server/src/auction.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ use {
8080
},
8181
sqlx::types::time::OffsetDateTime,
8282
std::{
83-
cmp::max,
8483
result,
8584
sync::{
8685
atomic::Ordering,
@@ -193,7 +192,7 @@ impl From<(SimulatedBid, bool)> for MulticallData {
193192
// 1. There will be more gas required for the transaction, which will result in a higher minimum bid amount.
194193
// 2. The transaction size limit will be reduced for each bid.
195194
// 3. Gas consumption limit will decrease for the bid
196-
const TOTAL_BIDS_PER_AUCTION: usize = 5;
195+
const TOTAL_BIDS_PER_AUCTION: usize = 3;
197196

198197
#[tracing::instrument(skip_all)]
199198
async fn get_winner_bids(
@@ -560,7 +559,7 @@ async fn verify_bid_exceeds_gas_cost<G>(
560559
estimated_gas: U256,
561560
oracle: G,
562561
bid_amount: U256,
563-
threshold: U256,
562+
multiplier: U256,
564563
) -> Result<(), RestError>
565564
where
566565
G: GasOracle,
@@ -570,12 +569,12 @@ where
570569
.await
571570
.map_err(|_| RestError::TemporarilyUnavailable)?;
572571
let gas_price = base_fee_per_gas * estimated_gas;
573-
if bid_amount >= gas_price * threshold {
572+
if bid_amount >= gas_price * multiplier {
574573
Ok(())
575574
} else {
576575
Err(RestError::BadParameters(format!(
577-
"Bid amount is insufficient for gas. gas price: {}, threshold: {}",
578-
gas_price, threshold
576+
"Insufficient bid amount. Based on the current gas fees, your bid should be larger than: {}",
577+
gas_price * multiplier
579578
)))
580579
}
581580
}
@@ -596,8 +595,6 @@ async fn verify_bid_under_gas_limit(
596595
}
597596
}
598597

599-
const MINIMUM_GAS_MULTIPLIER: usize = 5;
600-
601598
// As we submit bids together for an auction, the bid is limited as follows:
602599
// 1. The bid amount should cover gas fees for all bids included in the submission.
603600
// 2. Depending on the maximum number of bids in the auction, the transaction size for the bid is limited.
@@ -644,15 +641,13 @@ pub async fn handle_bid(
644641
Err(e) => {
645642
return match e {
646643
ContractError::Revert(reason) => {
647-
if let Some(decoded_error) = ExpressRelayErrors::decode_with_selector(&reason) {
648-
if let ExpressRelayErrors::ExternalCallFailed(failure_result) =
649-
decoded_error
650-
{
651-
return Err(RestError::SimulationError {
652-
result: failure_result.status.external_result,
653-
reason: failure_result.status.multicall_revert_reason,
654-
});
655-
}
644+
if let Some(ExpressRelayErrors::ExternalCallFailed(failure_result)) =
645+
ExpressRelayErrors::decode_with_selector(&reason)
646+
{
647+
return Err(RestError::SimulationError {
648+
result: failure_result.status.external_result,
649+
reason: failure_result.status.multicall_revert_reason,
650+
});
656651
}
657652
Err(RestError::BadParameters(format!(
658653
"Contract Revert Error: {}",
@@ -677,9 +672,9 @@ pub async fn handle_bid(
677672
bid.amount,
678673
// To submit TOTAL_BIDS_PER_AUCTION together, each bid must cover the gas fee for all of the submitted bids.
679674
// Therefore, the bid amount needs to be TOTAL_BIDS_PER_AUCTION times the gas fee.
680-
// The threshold will be multiplied by two to ensure the bid is beneficial, as well as to allow for estimation errors.
675+
// In order to make sure estimation errors are covered, it is summed up with one.
681676
// For example, if we are unable to submit the bid in the current block.
682-
U256::from(max(TOTAL_BIDS_PER_AUCTION * 2, MINIMUM_GAS_MULTIPLIER)),
677+
U256::from(TOTAL_BIDS_PER_AUCTION + 1),
683678
)
684679
.await?;
685680
// The transaction body size will be automatically limited when the gas is limited.

0 commit comments

Comments
 (0)