Skip to content

Commit

Permalink
Merge b2ae936 into 2a64e22
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 authored Nov 21, 2023
2 parents 2a64e22 + b2ae936 commit fea9bac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
12 changes: 6 additions & 6 deletions src/Billboard/Billboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ contract Billboard is IBillboard {
registry.setBidWon(tokenId_, nextAuctionId_, _nextAuction.highestBidder, true);

// set auction lease
uint256 leaseStartAt = block.timestamp;
uint256 leaseEndAt = leaseStartAt + registry.leaseTerm();
uint64 leaseStartAt = uint64(block.timestamp);
uint64 leaseEndAt = uint64(leaseStartAt + registry.leaseTerm());
registry.setAuctionLease(tokenId_, nextAuctionId_, leaseStartAt, leaseEndAt);

// emit AuctionCleared
Expand All @@ -213,7 +213,7 @@ contract Billboard is IBillboard {
// create new auction and new bid first,
// then clear auction and transfer ownership to the bidder immediately.
if (_nextAuction.startAt == 0) {
uint256 _auctionId = _newAuctionAndBid(tokenId_, amount_, block.timestamp);
uint256 _auctionId = _newAuctionAndBid(tokenId_, amount_, uint64(block.timestamp));
_clearAuction(tokenId_, _boardCreator, _auctionId);
return;
}
Expand All @@ -223,7 +223,7 @@ contract Billboard is IBillboard {
// then create new auction and new bid
if (block.timestamp >= _nextAuction.endAt) {
_clearAuction(tokenId_, _boardCreator, _nextAuctionId);
_newAuctionAndBid(tokenId_, amount_, block.timestamp + registry.leaseTerm());
_newAuctionAndBid(tokenId_, amount_, uint64(block.timestamp + registry.leaseTerm()));
return;
}
// if next auction is not ended,
Expand All @@ -240,8 +240,8 @@ contract Billboard is IBillboard {
}
}

function _newAuctionAndBid(uint256 tokenId_, uint256 amount_, uint256 endAt_) private returns (uint256 auctionId) {
uint256 _startAt = block.timestamp;
function _newAuctionAndBid(uint256 tokenId_, uint256 amount_, uint64 endAt_) private returns (uint256 auctionId) {
uint64 _startAt = uint64(block.timestamp);
uint256 _tax = calculateTax(amount_);

auctionId = registry.newAuction(tokenId_, _startAt, endAt_);
Expand Down
14 changes: 7 additions & 7 deletions src/Billboard/BillboardRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
Counters.Counter private _tokenIds;

uint256 public taxRate;
uint256 public leaseTerm = 14 days;
uint64 public leaseTerm = 14 days;

// tokenId => Board
mapping(uint256 => Board) public boards;
Expand Down Expand Up @@ -139,8 +139,8 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
/// @inheritdoc IBillboardRegistry
function newAuction(
uint256 tokenId_,
uint256 startAt_,
uint256 endAt_
uint64 startAt_,
uint64 endAt_
) external isFromOperator returns (uint256 newAuctionId) {
nextBoardAuctionId[tokenId_]++;

Expand All @@ -161,8 +161,8 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
function setAuctionLease(
uint256 tokenId_,
uint256 auctionId_,
uint256 leaseStartAt_,
uint256 leaseEndAt_
uint64 leaseStartAt_,
uint64 leaseEndAt_
) external isFromOperator {
boardAuctions[tokenId_][auctionId_].leaseStartAt = leaseStartAt_;
boardAuctions[tokenId_][auctionId_].leaseEndAt = leaseEndAt_;
Expand Down Expand Up @@ -276,8 +276,8 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
uint256 tokenId_,
uint256 auctionId_,
address highestBidder_,
uint256 leaseStartAt_,
uint256 leaseEndAt_
uint64 leaseStartAt_,
uint64 leaseEndAt_
) external {
emit AuctionCleared(tokenId_, auctionId_, highestBidder_, leaseStartAt_, leaseEndAt_);
}
Expand Down
22 changes: 11 additions & 11 deletions src/Billboard/IBillboardRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ interface IBillboardRegistry is IERC721 {
* @param startAt Start time of the auction.
* @param endAt End time of the auction.
*/
event AuctionCreated(uint256 indexed tokenId, uint256 indexed auctionId, uint256 startAt, uint256 endAt);
event AuctionCreated(uint256 indexed tokenId, uint256 indexed auctionId, uint64 startAt, uint64 endAt);

/**
* @notice Auction is cleared.
Expand All @@ -86,8 +86,8 @@ interface IBillboardRegistry is IERC721 {
uint256 indexed tokenId,
uint256 indexed auctionId,
address indexed highestBidder,
uint256 leaseStartAt,
uint256 leaseEndAt
uint64 leaseStartAt,
uint64 leaseEndAt
);

/**
Expand Down Expand Up @@ -155,10 +155,10 @@ interface IBillboardRegistry is IERC721 {
}

struct Auction {
uint256 startAt; // timestamp
uint256 endAt; // timestamp
uint256 leaseStartAt; // timestamp
uint256 leaseEndAt; // timestamp
uint64 startAt; // timestamp
uint64 endAt; // timestamp
uint64 leaseStartAt; // timestamp
uint64 leaseEndAt; // timestamp
address highestBidder;
}

Expand Down Expand Up @@ -271,7 +271,7 @@ interface IBillboardRegistry is IERC721 {
* @param startAt_ Start time of an auction.
* @param endAt_ End time of an auction.
*/
function newAuction(uint256 tokenId_, uint256 startAt_, uint256 endAt_) external returns (uint256 auctionId);
function newAuction(uint256 tokenId_, uint64 startAt_, uint64 endAt_) external returns (uint256 auctionId);

/**
* @notice Set the data of an auction
Expand All @@ -281,7 +281,7 @@ interface IBillboardRegistry is IERC721 {
* @param leaseStartAt_ Start time of an board lease.
* @param leaseEndAt_ End time of an board lease.
*/
function setAuctionLease(uint256 tokenId_, uint256 auctionId_, uint256 leaseStartAt_, uint256 leaseEndAt_) external;
function setAuctionLease(uint256 tokenId_, uint256 auctionId_, uint64 leaseStartAt_, uint64 leaseEndAt_) external;

/**
* @notice Get bid count of an auction
Expand Down Expand Up @@ -382,8 +382,8 @@ interface IBillboardRegistry is IERC721 {
uint256 tokenId_,
uint256 auctionId_,
address highestBidder_,
uint256 leaseStartAt_,
uint256 leaseEndAt_
uint64 leaseStartAt_,
uint64 leaseEndAt_
) external;

/**
Expand Down
15 changes: 10 additions & 5 deletions src/test/Billboard/BillboardTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,12 @@ contract BillboardTest is BillboardTestBase {
uint256 _prevRegistryBalance = address(registry).balance;

vm.expectEmit(true, true, true, true);
emit IBillboardRegistry.AuctionCreated(_tokenId, _prevNextActionId + 1, block.timestamp, block.timestamp);
emit IBillboardRegistry.AuctionCreated(
_tokenId,
_prevNextActionId + 1,
uint64(block.timestamp),
uint64(block.timestamp)
);
vm.expectEmit(true, true, true, true);
emit IBillboardRegistry.BidCreated(_tokenId, _prevNextActionId + 1, USER_A, _amount, _tax);
vm.expectEmit(true, true, true, true);
Expand All @@ -374,8 +379,8 @@ contract BillboardTest is BillboardTestBase {
_tokenId,
_prevNextActionId + 1,
USER_A,
block.timestamp,
block.timestamp + registry.leaseTerm()
uint64(block.timestamp),
uint64(block.timestamp + registry.leaseTerm())
);

vm.prank(USER_A);
Expand Down Expand Up @@ -579,8 +584,8 @@ contract BillboardTest is BillboardTestBase {

function testClearAuctionIfAuctionEnded() public {
(uint256 _tokenId, uint256 _prevAuctionId) = _mintBoardAndPlaceBid();
uint256 _placedAt = block.timestamp;
uint256 _clearedAt = block.timestamp + registry.leaseTerm() + 1 minutes;
uint64 _placedAt = uint64(block.timestamp);
uint64 _clearedAt = uint64(block.timestamp) + registry.leaseTerm() + 1 minutes;

// place a bid
vm.startPrank(USER_A);
Expand Down

0 comments on commit fea9bac

Please sign in to comment.