Let me give an example.
The base and quote decimals are 18, the price is 2e18, and the minimum fill percent is 100%.
The creator sets up an auction with a capacity of 10e18.
Due to the fullFill equaling the excess, the entire bid amount for the second bidder will be refunded, and the auction is marked as concluded.
Therefore, no further bids are allowed.
However, we cannot settle this auction because the total bid amount remains 2e19 - 1 and cannot fill the whole capacity.
However, this auction should be settled successfully.
Please check below comments:
totalBidAmount before ==> 19999999999999999999
conclusion before ==> 1086400
totalBidAmount after ==> 19999999999999999999
conclusion after ==> 1000000
settlementCleared final ==> false
This is a complicated and rare case, but I believe we should avoid it.
Recommended
function _bid(
uint96 lotId_,
address bidder_,
address referrer_,
uint256 amount_,
bytes calldata
) internal override returns (uint64) {
uint256 baseScale = 10 ** lotData[lotId_].baseTokenDecimals;
uint256 newFilledCapacity = Math.fullMulDiv(data.totalBidAmount, baseScale, data.price);
// If the new filled capacity is less than the lot capacity, the auction continues
if (newFilledCapacity < lotCapacity) {
return bidId;
}
// If partial fill, then calculate new payout and refund
if (newFilledCapacity > lotCapacity) {
// Store the partial fill
_lotPartialFill[lotId_] = _calculatePartialFill(
bidId, lotCapacity, newFilledCapacity, amount96, baseScale, data.price
);
// Decrement the total bid amount by the refund
data.totalBidAmount -= _lotPartialFill[lotId_].refund;
+ uint256 updatedFilledCapacity = Math.fullMulDiv(data.totalBidAmount, baseScale, data.price);
+ if (updatedFilledCapacity < data.minFilled) {
+ data.minFilled = updatedFilledCapacity;
+ }
}
}
Let me give an example. The
base
andquote decimals
are18
, theprice
is2e18
, and theminimum fill percent
is100%
. Thecreator
sets up anauction
with acapacity
of10e18
.One
bidder
places abid
with2e19 - 1
.Then the
auction
remainsactive
because thecapacity
is10e18
and thenewFilledCapacity
is10e18 - 1
.Another
bidder
places abid
with1e18 + 1
. Then in the_calculatePartialFill
function, the specific values are as follows:Due to the
fullFill
equaling theexcess
, the entirebid amount
for thesecond bidder
will berefunded
, and theauction
is marked asconcluded
. Therefore, no furtherbids
are allowed. However, we cannotsettle
thisauction
because thetotal bid amount
remains2e19 - 1
and cannot fill thewhole capacity
.However, this
auction
should besettled
successfully.Please check below comments:
Please add below test to the
FPB/auction.t.sol
:This is a complicated and rare case, but I believe we should avoid it.
Recommended
This will prevent
1 wei
precision error
.