-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasyAuction.sol
748 lines (713 loc) · 26.2 KB
/
EasyAuction.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
pragma solidity >=0.6.8;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "./libraries/IterableOrderedOrderSet.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./libraries/IdToAddressBiMap.sol";
import "./libraries/SafeCast.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/AllowListVerifier.sol";
contract EasyAuction is Ownable {
using SafeERC20 for IERC20;
using SafeMath for uint64;
using SafeMath for uint96;
using SafeMath for uint256;
using SafeCast for uint256;
using IterableOrderedOrderSet for IterableOrderedOrderSet.Data;
using IterableOrderedOrderSet for bytes32;
using IdToAddressBiMap for IdToAddressBiMap.Data;
modifier atStageOrderPlacement(uint256 auctionId) {
require(
block.timestamp < auctionData[auctionId].auctionEndDate,
"no longer in order placement phase"
);
_;
}
modifier atStageOrderPlacementAndCancelation(uint256 auctionId) {
require(
block.timestamp < auctionData[auctionId].orderCancellationEndDate,
"no longer in order placement and cancelation phase"
);
_;
}
modifier atStageSolutionSubmission(uint256 auctionId) {
{
uint256 auctionEndDate = auctionData[auctionId].auctionEndDate;
require(
auctionEndDate != 0 &&
block.timestamp >= auctionEndDate &&
auctionData[auctionId].clearingPriceOrder == bytes32(0),
"Auction not in solution submission phase"
);
}
_;
}
modifier atStageFinished(uint256 auctionId) {
require(
auctionData[auctionId].clearingPriceOrder != bytes32(0),
"Auction not yet finished"
);
_;
}
event NewSellOrder(
uint256 indexed auctionId,
uint64 indexed userId,
uint96 buyAmount,
uint96 sellAmount
);
event CancellationSellOrder(
uint256 indexed auctionId,
uint64 indexed userId,
uint96 buyAmount,
uint96 sellAmount
);
event ClaimedFromOrder(
uint256 indexed auctionId,
uint64 indexed userId,
uint96 buyAmount,
uint96 sellAmount
);
event NewUser(uint64 indexed userId, address indexed userAddress);
event NewAuction(
uint256 indexed auctionId,
IERC20 indexed _auctioningToken,
IERC20 indexed _biddingToken,
uint256 orderCancellationEndDate,
uint256 auctionEndDate,
uint64 userId,
uint96 _auctionedSellAmount,
uint96 _minBuyAmount,
uint256 minimumBiddingAmountPerOrder,
uint256 minFundingThreshold,
address allowListContract,
bytes allowListData
);
event AuctionCleared(
uint256 indexed auctionId,
uint96 soldAuctioningTokens,
uint96 soldBiddingTokens,
bytes32 clearingPriceOrder
);
event UserRegistration(address indexed user, uint64 userId);
struct AuctionData {
IERC20 auctioningToken;
IERC20 biddingToken;
uint256 orderCancellationEndDate;
uint256 auctionEndDate;
bytes32 initialAuctionOrder;
uint256 minimumBiddingAmountPerOrder;
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;
IdToAddressBiMap.Data private registeredUsers;
uint64 public numUsers;
uint256 public auctionCounter;
constructor() public Ownable() {}
uint256 public feeNumerator = 0;
uint256 public constant FEE_DENOMINATOR = 1000;
uint64 public feeReceiverUserId = 1;
function setFeeParameters(
uint256 newFeeNumerator,
address newfeeReceiverAddress
) public onlyOwner() {
require(
newFeeNumerator <= 15,
"Fee is not allowed to be set higher than 1.5%"
);
// caution: for currently running auctions, the feeReceiverUserId is changing as well.
feeReceiverUserId = getUserId(newfeeReceiverAddress);
feeNumerator = newFeeNumerator;
}
// @dev: function to intiate a new auction
// Warning: In case the auction is expected to raise more than
// 2^96 units of the biddingToken, don't start the auction, as
// it will not be settlable. This corresponds to about 79
// billion DAI.
//
// Prices between biddingToken and auctioningToken are expressed by a
// fraction whose components are stored as uint96.
function initiateAuction(
IERC20 _auctioningToken,
IERC20 _biddingToken,
uint256 orderCancellationEndDate,
uint256 auctionEndDate,
uint96 _auctionedSellAmount,
uint96 _minBuyAmount,
uint256 minimumBiddingAmountPerOrder,
uint256 minFundingThreshold,
bool isAtomicClosureAllowed,
address accessManagerContract,
bytes memory accessManagerContractData
) public returns (uint256) {
// withdraws sellAmount + fees
_auctioningToken.safeTransferFrom(
msg.sender,
address(this),
_auctionedSellAmount.mul(FEE_DENOMINATOR.add(feeNumerator)).div(
FEE_DENOMINATOR
) //[0]
);
require(_auctionedSellAmount > 0, "cannot auction zero tokens");
require(_minBuyAmount > 0, "tokens cannot be auctioned for free");
require(
minimumBiddingAmountPerOrder > 0,
"minimumBiddingAmountPerOrder is not allowed to be zero"
);
require(
orderCancellationEndDate <= auctionEndDate,
"time periods are not configured correctly"
);
require(
auctionEndDate > block.timestamp,
"auction end date must be in the future"
);
auctionCounter = auctionCounter.add(1);
sellOrders[auctionCounter].initializeEmptyList();
uint64 userId = getUserId(msg.sender);
auctionData[auctionCounter] = AuctionData(
_auctioningToken,
_biddingToken,
orderCancellationEndDate,
auctionEndDate,
IterableOrderedOrderSet.encodeOrder(
userId,
_minBuyAmount,
_auctionedSellAmount
),
minimumBiddingAmountPerOrder,
0,
IterableOrderedOrderSet.QUEUE_START,
bytes32(0),
0,
false,
isAtomicClosureAllowed,
feeNumerator,
minFundingThreshold
);
auctionAccessManager[auctionCounter] = accessManagerContract;
auctionAccessData[auctionCounter] = accessManagerContractData;
emit NewAuction(
auctionCounter,
_auctioningToken,
_biddingToken,
orderCancellationEndDate,
auctionEndDate,
userId,
_auctionedSellAmount,
_minBuyAmount,
minimumBiddingAmountPerOrder,
minFundingThreshold,
accessManagerContract,
accessManagerContractData
);
return auctionCounter;
}
function placeSellOrders(
uint256 auctionId,
uint96[] memory _minBuyAmounts,
uint96[] memory _sellAmounts,
bytes32[] memory _prevSellOrders,
bytes calldata allowListCallData
) external atStageOrderPlacement(auctionId) returns (uint64 userId) {
return
_placeSellOrders(
auctionId,
_minBuyAmounts,
_sellAmounts,
_prevSellOrders,
allowListCallData,
msg.sender
);
}
function placeSellOrdersOnBehalf(
uint256 auctionId,
uint96[] memory _minBuyAmounts,
uint96[] memory _sellAmounts,
bytes32[] memory _prevSellOrders,
bytes calldata allowListCallData,
address orderSubmitter
) external atStageOrderPlacement(auctionId) returns (uint64 userId) {
return
_placeSellOrders(
auctionId,
_minBuyAmounts,
_sellAmounts,
_prevSellOrders,
allowListCallData,
orderSubmitter
);
}
function _placeSellOrders(
uint256 auctionId,
uint96[] memory _minBuyAmounts,
uint96[] memory _sellAmounts,
bytes32[] memory _prevSellOrders,
bytes calldata allowListCallData,
address orderSubmitter
) internal returns (uint64 userId) {
{
address allowListManger = auctionAccessManager[auctionId];
if (allowListManger != address(0)) {
require(
AllowListVerifier(allowListManger).isAllowed(
orderSubmitter,
auctionId,
allowListCallData
) == AllowListVerifierHelper.MAGICVALUE,
"user not allowed to place order"
);
}
}
{
(
,
uint96 buyAmountOfInitialAuctionOrder,
uint96 sellAmountOfInitialAuctionOrder
) = auctionData[auctionId].initialAuctionOrder.decodeOrder();
for (uint256 i = 0; i < _minBuyAmounts.length; i++) {
require(
_minBuyAmounts[i].mul(buyAmountOfInitialAuctionOrder) <
sellAmountOfInitialAuctionOrder.mul(_sellAmounts[i]),
"limit price not better than mimimal offer"
);
}
}
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(
userId,
_minBuyAmounts[i],
_sellAmounts[i]
),
_prevSellOrders[i]
)
) {
sumOfSellAmounts = sumOfSellAmounts.add(_sellAmounts[i]);
emit NewSellOrder(
auctionId,
userId,
_minBuyAmounts[i],
_sellAmounts[i]
);
}
}
auctionData[auctionId].biddingToken.safeTransferFrom(
msg.sender,
address(this),
sumOfSellAmounts
); //[1]
}
function cancelSellOrders(uint256 auctionId, bytes32[] memory _sellOrders)
public
atStageOrderPlacementAndCancelation(auctionId)
{
uint64 userId = getUserId(msg.sender);
uint256 claimableAmount = 0;
for (uint256 i = 0; i < _sellOrders.length; i++) {
// Note: we keep the back pointer of the deleted element so that
// it can be used as a reference point to insert a new node.
bool success =
sellOrders[auctionId].removeKeepHistory(_sellOrders[i]);
if (success) {
(
uint64 userIdOfIter,
uint96 buyAmountOfIter,
uint96 sellAmountOfIter
) = _sellOrders[i].decodeOrder();
require(
userIdOfIter == userId,
"Only the user can cancel his orders"
);
claimableAmount = claimableAmount.add(sellAmountOfIter);
emit CancellationSellOrder(
auctionId,
userId,
buyAmountOfIter,
sellAmountOfIter
);
}
}
auctionData[auctionId].biddingToken.safeTransfer(
msg.sender,
claimableAmount
); //[2]
}
function precalculateSellAmountSum(
uint256 auctionId,
uint256 iterationSteps
) public atStageSolutionSubmission(auctionId) {
(, , uint96 auctioneerSellAmount) =
auctionData[auctionId].initialAuctionOrder.decodeOrder();
uint256 sumBidAmount = auctionData[auctionId].interimSumBidAmount;
bytes32 iterOrder = auctionData[auctionId].interimOrder;
for (uint256 i = 0; i < iterationSteps; i++) {
iterOrder = sellOrders[auctionId].next(iterOrder);
(, , uint96 sellAmountOfIter) = iterOrder.decodeOrder();
sumBidAmount = sumBidAmount.add(sellAmountOfIter);
}
require(
iterOrder != IterableOrderedOrderSet.QUEUE_END,
"reached end of order list"
);
// it is checked that not too many iteration steps were taken:
// require that the sum of SellAmounts times the price of the last order
// is not more than initially sold amount
(, uint96 buyAmountOfIter, uint96 sellAmountOfIter) =
iterOrder.decodeOrder();
require(
sumBidAmount.mul(buyAmountOfIter) <
auctioneerSellAmount.mul(sellAmountOfIter),
"too many orders summed up"
);
auctionData[auctionId].interimSumBidAmount = sumBidAmount;
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
atStageSolutionSubmission(auctionId)
returns (bytes32 clearingOrder)
{
(
uint64 auctioneerId,
uint96 minAuctionedBuyAmount,
uint96 fullAuctionedAmount
) = auctionData[auctionId].initialAuctionOrder.decodeOrder();
uint256 currentBidSum = auctionData[auctionId].interimSumBidAmount;
bytes32 currentOrder = auctionData[auctionId].interimOrder;
uint256 buyAmountOfIter;
uint256 sellAmountOfIter;
uint96 fillVolumeOfAuctioneerOrder = fullAuctionedAmount;
// Sum order up, until fullAuctionedAmount is fully bought or queue end is reached
do {
bytes32 nextOrder = sellOrders[auctionId].next(currentOrder);
if (nextOrder == IterableOrderedOrderSet.QUEUE_END) {
break;
}
currentOrder = nextOrder;
(, buyAmountOfIter, sellAmountOfIter) = currentOrder.decodeOrder();
currentBidSum = currentBidSum.add(sellAmountOfIter);
} while (
currentBidSum.mul(buyAmountOfIter) <
fullAuctionedAmount.mul(sellAmountOfIter)
);
if (
currentBidSum > 0 &&
currentBidSum.mul(buyAmountOfIter) >=
fullAuctionedAmount.mul(sellAmountOfIter)
) {
// All considered/summed orders are sufficient to close the auction fully
// at price between current and previous orders.
uint256 uncoveredBids =
currentBidSum.sub(
fullAuctionedAmount.mul(sellAmountOfIter).div(
buyAmountOfIter
)
);
if (sellAmountOfIter >= uncoveredBids) {
//[13]
// Auction fully filled via partial match of currentOrder
uint256 sellAmountClearingOrder =
sellAmountOfIter.sub(uncoveredBids);
auctionData[auctionId]
.volumeClearingPriceOrder = sellAmountClearingOrder
.toUint96();
currentBidSum = currentBidSum.sub(uncoveredBids);
clearingOrder = currentOrder;
} else {
//[14]
// Auction fully filled via price strictly between currentOrder and the order
// immediately before. For a proof, see the security-considerations.md
currentBidSum = currentBidSum.sub(sellAmountOfIter);
clearingOrder = IterableOrderedOrderSet.encodeOrder(
0,
fullAuctionedAmount,
currentBidSum.toUint96()
);
}
} else {
// All considered/summed orders are not sufficient to close the auction fully at price of last order //[18]
// Either a higher price must be used or auction is only partially filled
if (currentBidSum > minAuctionedBuyAmount) {
//[15]
// Price higher than last order would fill the auction
clearingOrder = IterableOrderedOrderSet.encodeOrder(
0,
fullAuctionedAmount,
currentBidSum.toUint96()
);
} else {
//[16]
// Even at the initial auction price, the auction is partially filled
clearingOrder = IterableOrderedOrderSet.encodeOrder(
0,
fullAuctionedAmount,
minAuctionedBuyAmount
);
fillVolumeOfAuctioneerOrder = currentBidSum
.mul(fullAuctionedAmount)
.div(minAuctionedBuyAmount)
.toUint96();
}
}
auctionData[auctionId].clearingPriceOrder = clearingOrder;
if (auctionData[auctionId].minFundingThreshold > currentBidSum) {
auctionData[auctionId].minFundingThresholdNotReached = true;
}
processFeesAndAuctioneerFunds(
auctionId,
fillVolumeOfAuctioneerOrder,
auctioneerId,
fullAuctionedAmount
);
emit AuctionCleared(
auctionId,
fillVolumeOfAuctioneerOrder,
uint96(currentBidSum),
clearingOrder
);
// Gas refunds
auctionAccessManager[auctionId] = address(0);
delete auctionAccessData[auctionId];
auctionData[auctionId].initialAuctionOrder = bytes32(0);
auctionData[auctionId].interimOrder = bytes32(0);
auctionData[auctionId].interimSumBidAmount = uint256(0);
auctionData[auctionId].minimumBiddingAmountPerOrder = uint256(0);
}
function claimFromParticipantOrder(
uint256 auctionId,
bytes32[] memory orders
)
public
atStageFinished(auctionId)
returns (
uint256 sumAuctioningTokenAmount,
uint256 sumBiddingTokenAmount
)
{
for (uint256 i = 0; i < orders.length; i++) {
// Note: we don't need to keep any information about the node since
// no new elements need to be inserted.
require(
sellOrders[auctionId].remove(orders[i]),
"order is no longer claimable"
);
}
AuctionData memory auction = auctionData[auctionId];
(, uint96 priceNumerator, uint96 priceDenominator) =
auction.clearingPriceOrder.decodeOrder();
(uint64 userId, , ) = orders[0].decodeOrder();
bool minFundingThresholdNotReached =
auctionData[auctionId].minFundingThresholdNotReached;
for (uint256 i = 0; i < orders.length; i++) {
(uint64 userIdOrder, uint96 buyAmount, uint96 sellAmount) =
orders[i].decodeOrder();
require(
userIdOrder == userId,
"only allowed to claim for same user"
);
if (minFundingThresholdNotReached) {
//[10]
sumBiddingTokenAmount = sumBiddingTokenAmount.add(sellAmount);
} else {
//[23]
if (orders[i] == auction.clearingPriceOrder) {
//[25]
sumAuctioningTokenAmount = sumAuctioningTokenAmount.add(
auction
.volumeClearingPriceOrder
.mul(priceNumerator)
.div(priceDenominator)
);
sumBiddingTokenAmount = sumBiddingTokenAmount.add(
sellAmount.sub(auction.volumeClearingPriceOrder)
);
} else {
if (orders[i].smallerThan(auction.clearingPriceOrder)) {
//[17]
sumAuctioningTokenAmount = sumAuctioningTokenAmount.add(
sellAmount.mul(priceNumerator).div(priceDenominator)
);
} else {
//[24]
sumBiddingTokenAmount = sumBiddingTokenAmount.add(
sellAmount
);
}
}
}
emit ClaimedFromOrder(auctionId, userId, buyAmount, sellAmount);
}
sendOutTokens(
auctionId,
sumAuctioningTokenAmount,
sumBiddingTokenAmount,
userId
); //[3]
}
function processFeesAndAuctioneerFunds(
uint256 auctionId,
uint256 fillVolumeOfAuctioneerOrder,
uint64 auctioneerId,
uint96 fullAuctionedAmount
) internal {
uint256 feeAmount =
fullAuctionedAmount.mul(auctionData[auctionId].feeNumerator).div(
FEE_DENOMINATOR
); //[20]
if (auctionData[auctionId].minFundingThresholdNotReached) {
sendOutTokens(
auctionId,
fullAuctionedAmount.add(feeAmount),
0,
auctioneerId
); //[4]
} else {
//[11]
(, uint96 priceNumerator, uint96 priceDenominator) =
auctionData[auctionId].clearingPriceOrder.decodeOrder();
uint256 unsettledAuctionTokens =
fullAuctionedAmount.sub(fillVolumeOfAuctioneerOrder);
uint256 auctioningTokenAmount =
unsettledAuctionTokens.add(
feeAmount.mul(unsettledAuctionTokens).div(
fullAuctionedAmount
)
);
uint256 biddingTokenAmount =
fillVolumeOfAuctioneerOrder.mul(priceDenominator).div(
priceNumerator
);
sendOutTokens(
auctionId,
auctioningTokenAmount,
biddingTokenAmount,
auctioneerId
); //[5]
sendOutTokens(
auctionId,
feeAmount.mul(fillVolumeOfAuctioneerOrder).div(
fullAuctionedAmount
),
0,
feeReceiverUserId
); //[7]
}
}
function sendOutTokens(
uint256 auctionId,
uint256 auctioningTokenAmount,
uint256 biddingTokenAmount,
uint64 userId
) internal {
address userAddress = registeredUsers.getAddressAt(userId);
if (auctioningTokenAmount > 0) {
auctionData[auctionId].auctioningToken.safeTransfer(
userAddress,
auctioningTokenAmount
);
}
if (biddingTokenAmount > 0) {
auctionData[auctionId].biddingToken.safeTransfer(
userAddress,
biddingTokenAmount
);
}
}
function registerUser(address user) public returns (uint64 userId) {
numUsers = numUsers.add(1).toUint64();
require(
registeredUsers.insert(numUsers, user),
"User already registered"
);
userId = numUsers;
emit UserRegistration(user, userId);
}
function getUserId(address user) public returns (uint64 userId) {
if (registeredUsers.hasAddress(user)) {
userId = registeredUsers.getId(user);
} else {
userId = registerUser(user);
emit NewUser(userId, user);
}
}
function getSecondsRemainingInBatch(uint256 auctionId)
public
view
returns (uint256)
{
if (auctionData[auctionId].auctionEndDate < block.timestamp) {
return 0;
}
return auctionData[auctionId].auctionEndDate.sub(block.timestamp);
}
function containsOrder(uint256 auctionId, bytes32 order)
public
view
returns (bool)
{
return sellOrders[auctionId].contains(order);
}
}