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

feature: handle errors #157

Merged
merged 7 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 2 additions & 6 deletions contracts/SwapFactory.sol
luislucena16 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,9 @@ abstract contract SwapFactory is ISwapFactory, ISwap, IErrors {
Asset[] memory biding,
Asset[] memory asking
) public view virtual returns (Swap memory) {
if (expiry < block.timestamp) {
revert InvalidExpiry(expiry);
}
if (expiry < block.timestamp) revert InvalidExpiry(expiry);

if (biding.length == 0 || asking.length == 0) {
revert InvalidAssetsLength();
}
if (biding.length == 0 || asking.length == 0) revert InvalidAssetsLength();

return Swap(owner, allowed, expiry, biding, asking);
}
Expand Down
26 changes: 7 additions & 19 deletions contracts/Swaplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {
* @dev See {ISwaplace-createSwap}.
*/
function createSwap(Swap calldata swap) public returns (uint256) {
if (swap.owner != msg.sender) {
revert InvalidAddress(msg.sender);
}
if (swap.owner != msg.sender) revert InvalidAddress(msg.sender);

if (swap.expiry < block.timestamp) {
revert InvalidExpiry(swap.expiry);
}
if (swap.expiry < block.timestamp) revert InvalidExpiry(swap.expiry);

if (swap.biding.length == 0 || swap.asking.length == 0) {
if (swap.biding.length == 0 || swap.asking.length == 0)
revert InvalidAssetsLength();
}

unchecked {
assembly {
Expand All @@ -57,13 +52,10 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {
function acceptSwap(uint256 id) public returns (bool) {
Swap memory swap = _swaps[id];

if (swap.allowed != address(0) && swap.allowed != msg.sender) {
if (swap.allowed != address(0) && swap.allowed != msg.sender)
revert InvalidAddress(msg.sender);
}

if (swap.expiry < block.timestamp) {
revert InvalidExpiry(swap.expiry);
}
if (swap.expiry < block.timestamp) revert InvalidExpiry(swap.expiry);

_swaps[id].expiry = 0;

Expand Down Expand Up @@ -104,13 +96,9 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {
function cancelSwap(uint256 id) public {
Swap memory swap = _swaps[id];

if (swap.owner != msg.sender) {
revert InvalidAddress(msg.sender);
}
if (swap.owner != msg.sender) revert InvalidAddress(msg.sender);

if (swap.expiry < block.timestamp) {
revert InvalidExpiry(swap.expiry);
}
if (swap.expiry < block.timestamp) revert InvalidExpiry(swap.expiry);

_swaps[id].expiry = 0;

Expand Down
Loading