Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max bidding amount #85

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 47 additions & 67 deletions contracts/EasyAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,20 @@ contract EasyAuction is Ownable {
uint256 auctionEndDate;
bytes32 initialAuctionOrder;
uint256 minimumBiddingAmountPerOrder;
uint256 maximumBiddingAmountPerAccount;
uint256 interimSumBidAmount;
bytes32 interimOrder;
bytes32 clearingPriceOrder;
uint96 volumeClearingPriceOrder;
bool minFundingThresholdNotReached;
bool isAtomicClosureAllowed;
uint256 feeNumerator;
uint256 minFundingThreshold;
}
mapping(uint256 => IterableOrderedOrderSet.Data) internal sellOrders;
mapping(uint256 => AuctionData) public auctionData;
mapping(uint256 => address) public auctionAccessManager;
mapping(uint256 => bytes) public auctionAccessData;
mapping(uint256 => mapping(address => uint256)) public biddingAmountPerUser;

IdToAddressBiMap.Data private registeredUsers;
uint64 public numUsers;
Expand Down Expand Up @@ -157,8 +158,8 @@ contract EasyAuction is Ownable {
uint96 _auctionedSellAmount,
uint96 _minBuyAmount,
uint256 minimumBiddingAmountPerOrder,
uint256 maximumBiddingAmountPerAccount,
uint256 minFundingThreshold,
bool isAtomicClosureAllowed,
address accessManagerContract,
bytes memory accessManagerContractData
) public returns (uint256) {
Expand Down Expand Up @@ -198,12 +199,12 @@ contract EasyAuction is Ownable {
_auctionedSellAmount
),
minimumBiddingAmountPerOrder,
maximumBiddingAmountPerAccount,
0,
IterableOrderedOrderSet.QUEUE_START,
bytes32(0),
0,
false,
isAtomicClosureAllowed,
feeNumerator,
minFundingThreshold
);
Expand Down Expand Up @@ -300,38 +301,54 @@ contract EasyAuction is Ownable {
}
uint256 sumOfSellAmounts = 0;
userId = getUserId(orderSubmitter);
uint256 minimumBiddingAmountPerOrder =
auctionData[auctionId].minimumBiddingAmountPerOrder;
for (uint256 i = 0; i < _minBuyAmounts.length; i++) {
require(
_minBuyAmounts[i] > 0,
"_minBuyAmounts must be greater than 0"
);
// orders should have a minimum bid size in order to limit the gas
// required to compute the final price of the auction.
require(
_sellAmounts[i] > minimumBiddingAmountPerOrder,
"order too small"
);
if (
sellOrders[auctionId].insert(
IterableOrderedOrderSet.encodeOrder(
{
uint256 minimumBiddingAmountPerOrder =
auctionData[auctionId].minimumBiddingAmountPerOrder;
for (uint256 i = 0; i < _minBuyAmounts.length; i++) {
require(
_minBuyAmounts[i] > 0,
"_minBuyAmounts must be greater than 0"
);
// orders should have a minimum bid size in order to limit the gas
// required to compute the final price of the auction.
require(
_sellAmounts[i] > minimumBiddingAmountPerOrder,
"order too small"
);
if (
sellOrders[auctionId].insert(
IterableOrderedOrderSet.encodeOrder(
userId,
_minBuyAmounts[i],
_sellAmounts[i]
),
_prevSellOrders[i]
)
) {
sumOfSellAmounts = sumOfSellAmounts.add(_sellAmounts[i]);
emit NewSellOrder(
auctionId,
userId,
_minBuyAmounts[i],
_sellAmounts[i]
),
_prevSellOrders[i]
)
) {
sumOfSellAmounts = sumOfSellAmounts.add(_sellAmounts[i]);
emit NewSellOrder(
auctionId,
userId,
_minBuyAmounts[i],
_sellAmounts[i]
);
);
}
}
}
uint256 maxBiddingAmount =
auctionData[auctionId].maximumBiddingAmountPerAccount;
if (maxBiddingAmount > 0) {
biddingAmountPerUser[auctionId][
orderSubmitter
] = biddingAmountPerUser[auctionId][orderSubmitter].add(
sumOfSellAmounts
);
require(
biddingAmountPerUser[auctionId][orderSubmitter] <
maxBiddingAmount,
"Bids exceed max bidding amount"
);
}
auctionData[auctionId].biddingToken.safeTransferFrom(
msg.sender,
address(this),
Expand Down Expand Up @@ -410,43 +427,6 @@ contract EasyAuction is Ownable {
auctionData[auctionId].interimOrder = iterOrder;
}

function settleAuctionAtomically(
uint256 auctionId,
uint96[] memory _minBuyAmount,
uint96[] memory _sellAmount,
bytes32[] memory _prevSellOrder,
bytes calldata allowListCallData
) public atStageSolutionSubmission(auctionId) {
require(
auctionData[auctionId].isAtomicClosureAllowed,
"not allowed to settle auction atomically"
);
require(
_minBuyAmount.length == 1 && _sellAmount.length == 1,
"Only one order can be placed atomically"
);
uint64 userId = getUserId(msg.sender);
require(
auctionData[auctionId].interimOrder.smallerThan(
IterableOrderedOrderSet.encodeOrder(
userId,
_minBuyAmount[0],
_sellAmount[0]
)
),
"precalculateSellAmountSum is already too advanced"
);
_placeSellOrders(
auctionId,
_minBuyAmount,
_sellAmount,
_prevSellOrder,
allowListCallData,
msg.sender
);
settleAuction(auctionId);
}

// @dev function settling the auction and calculating the price
function settleAuction(uint256 auctionId)
public
Expand Down