Skip to content

Commit

Permalink
(L-1), (L-2) - fix timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 committed Nov 15, 2022
1 parent 2a7f026 commit 9a61ca8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
46 changes: 34 additions & 12 deletions contracts/marketplace/direct-listings/DirectListingsLogic.sol
Expand Up @@ -86,10 +86,17 @@ contract DirectListings is IDirectListings, ReentrancyGuard, ERC2771ContextConsu
address listingCreator = _msgSender();
TokenType tokenType = _getTokenType(_params.assetContract);

require(
_params.startTimestamp + 60 minutes >= block.timestamp && _params.startTimestamp < _params.endTimestamp,
"Marketplace: invalid timestamps."
);
uint128 startTime = _params.startTimestamp;
uint128 endTime = _params.endTimestamp;
require(startTime < endTime, "Marketplace: endTimestamp not greater than startTimestamp.");
if (startTime < block.timestamp) {
require(startTime + 60 minutes >= block.timestamp, "Marketplace: invalid startTimestamp.");

startTime = uint128(block.timestamp);
endTime = endTime == type(uint128).max
? endTime
: startTime + (_params.endTimestamp - _params.startTimestamp);
}

_validateNewListing(_params, tokenType);

Expand All @@ -101,8 +108,8 @@ contract DirectListings is IDirectListings, ReentrancyGuard, ERC2771ContextConsu
quantity: _params.quantity,
currency: _params.currency,
pricePerToken: _params.pricePerToken,
startTimestamp: _params.startTimestamp,
endTimestamp: _params.endTimestamp,
startTimestamp: startTime,
endTimestamp: endTime,
reserved: _params.reserved,
tokenType: tokenType
});
Expand All @@ -126,16 +133,31 @@ contract DirectListings is IDirectListings, ReentrancyGuard, ERC2771ContextConsu
Listing memory listing = data.listings[_listingId];
TokenType tokenType = _getTokenType(_params.assetContract);

require(
_params.startTimestamp >= listing.startTimestamp && _params.startTimestamp < _params.endTimestamp,
"Marketplace: invalid timestamps."
);
require(listing.endTimestamp > block.timestamp, "Marketplace: listing expired.");

require(
listing.assetContract == _params.assetContract && listing.tokenId == _params.tokenId,
"Marketplace: cannot update what token is listed."
);

uint128 startTime = _params.startTimestamp;
uint128 endTime = _params.endTimestamp;
require(startTime < endTime, "Marketplace: endTimestamp not greater than startTimestamp.");
require(
listing.startTimestamp > block.timestamp ||
(startTime == listing.startTimestamp && endTime > block.timestamp),
"Marketplace: listing already active."
);
if (startTime != listing.startTimestamp && startTime < block.timestamp) {
require(startTime + 60 minutes >= block.timestamp, "Marketplace: invalid startTimestamp.");

startTime = uint128(block.timestamp);

endTime = endTime == listing.endTimestamp || endTime == type(uint128).max
? endTime
: startTime + (_params.endTimestamp - _params.startTimestamp);
}

_validateNewListing(_params, tokenType);

listing = Listing({
Expand All @@ -146,8 +168,8 @@ contract DirectListings is IDirectListings, ReentrancyGuard, ERC2771ContextConsu
quantity: _params.quantity,
currency: _params.currency,
pricePerToken: _params.pricePerToken,
startTimestamp: _params.startTimestamp,
endTimestamp: _params.endTimestamp,
startTimestamp: startTime,
endTimestamp: endTime,
reserved: _params.reserved,
tokenType: tokenType
});
Expand Down
9 changes: 5 additions & 4 deletions src/test/marketplace/DirectListings.t.sol
Expand Up @@ -363,7 +363,7 @@ contract MarketplaceDirectListingsTest is BaseTest {
);

vm.prank(seller);
vm.expectRevert("Marketplace: invalid timestamps.");
vm.expectRevert("Marketplace: invalid startTimestamp.");
DirectListings(marketplace).createListing(listingParams);
}

Expand Down Expand Up @@ -402,7 +402,7 @@ contract MarketplaceDirectListingsTest is BaseTest {
);

vm.prank(seller);
vm.expectRevert("Marketplace: invalid timestamps.");
vm.expectRevert("Marketplace: endTimestamp not greater than startTimestamp.");
DirectListings(marketplace).createListing(listingParams);
}

Expand Down Expand Up @@ -746,8 +746,9 @@ contract MarketplaceDirectListingsTest is BaseTest {
uint128 currentStartTimestamp = listingParamsToUpdate.startTimestamp;
listingParamsToUpdate.startTimestamp = currentStartTimestamp - 1; // Retroactively decreasing startTimestamp.

vm.warp(currentStartTimestamp + 50);
vm.prank(seller);
vm.expectRevert("Marketplace: invalid timestamps.");
vm.expectRevert("Marketplace: listing already active.");
DirectListings(marketplace).updateListing(listingId, listingParamsToUpdate);
}

Expand All @@ -766,7 +767,7 @@ contract MarketplaceDirectListingsTest is BaseTest {
listingParamsToUpdate.endTimestamp = currentStartTimestamp - 1; // End timestamp less than startTimestamp

vm.prank(seller);
vm.expectRevert("Marketplace: invalid timestamps.");
vm.expectRevert("Marketplace: endTimestamp not greater than startTimestamp.");
DirectListings(marketplace).updateListing(listingId, listingParamsToUpdate);
}

Expand Down

0 comments on commit 9a61ca8

Please sign in to comment.