From e671f4e9a24fd6fa12f7f7bc2fa3a205b185b268 Mon Sep 17 00:00:00 2001 From: 0xneves Date: Tue, 19 Dec 2023 16:02:43 -0300 Subject: [PATCH] refactor: format with prettierrc to all files --- contracts/Swaplace.sol | 210 ++++++++++++++++++++--------------------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/contracts/Swaplace.sol b/contracts/Swaplace.sol index 0ce484c..2234fa4 100644 --- a/contracts/Swaplace.sol +++ b/contracts/Swaplace.sol @@ -14,131 +14,131 @@ import {SwapFactory} from "./SwapFactory.sol"; * `approve` or `permit` function. */ contract Swaplace is SwapFactory, ISwaplace, IERC165 { - /// @dev Swap Identifier counter. - uint256 private _totalSwaps; + /// @dev Swap Identifier counter. + uint256 private _totalSwaps; + + /// @dev Mapping of Swap ID to Swap struct. See {ISwap-Swap}. + mapping(uint256 => Swap) private _swaps; + + /** + * @dev See {ISwaplace-createSwap}. + */ + function createSwap(Swap calldata swap) public returns (uint256) { + if (swap.owner != msg.sender) { + revert InvalidAddress(msg.sender); + } - /// @dev Mapping of Swap ID to Swap struct. See {ISwap-Swap}. - mapping(uint256 => Swap) private _swaps; + if (swap.expiry < block.timestamp) { + revert InvalidExpiry(swap.expiry); + } - /** - * @dev See {ISwaplace-createSwap}. - */ - function createSwap(Swap calldata swap) public returns (uint256) { - if (swap.owner != msg.sender) { - revert InvalidAddress(msg.sender); - } + if (swap.biding.length == 0 || swap.asking.length == 0) { + revert InvalidAssetsLength(); + } - if (swap.expiry < block.timestamp) { - revert InvalidExpiry(swap.expiry); - } + unchecked { + assembly { + sstore(_totalSwaps.slot, add(sload(_totalSwaps.slot), 1)) + } + } - if (swap.biding.length == 0 || swap.asking.length == 0) { - revert InvalidAssetsLength(); - } + uint256 swapId = _totalSwaps; - unchecked { - assembly { - sstore(_totalSwaps.slot, add(sload(_totalSwaps.slot), 1)) - } - } + _swaps[swapId] = swap; - uint256 swapId = _totalSwaps; + emit SwapCreated(swapId, msg.sender, swap.expiry); - _swaps[swapId] = swap; + return swapId; + } - emit SwapCreated(swapId, msg.sender, swap.expiry); + /** + * @dev See {ISwaplace-acceptSwap}. + */ + function acceptSwap(uint256 id) public returns (bool) { + Swap memory swap = _swaps[id]; - return swapId; + if (swap.allowed != address(0) && swap.allowed != msg.sender) { + revert InvalidAddress(msg.sender); } - /** - * @dev See {ISwaplace-acceptSwap}. - */ - function acceptSwap(uint256 id) public returns (bool) { - Swap memory swap = _swaps[id]; - - if (swap.allowed != address(0) && swap.allowed != msg.sender) { - revert InvalidAddress(msg.sender); - } - - if (swap.expiry < block.timestamp) { - revert InvalidExpiry(swap.expiry); - } - - _swaps[id].expiry = 0; - - Asset[] memory assets = swap.asking; - - for (uint256 i = 0; i < assets.length; ) { - ITransfer(assets[i].addr).transferFrom( - msg.sender, - swap.owner, - assets[i].amountOrId - ); - unchecked { - i++; - } - } - - assets = swap.biding; - - for (uint256 i = 0; i < assets.length; ) { - ITransfer(assets[i].addr).transferFrom( - swap.owner, - msg.sender, - assets[i].amountOrId - ); - unchecked { - i++; - } - } - - emit SwapAccepted(id, msg.sender); - - return true; + if (swap.expiry < block.timestamp) { + revert InvalidExpiry(swap.expiry); } - /** - * @dev See {ISwaplace-cancelSwap}. - */ - function cancelSwap(uint256 id) public { - Swap memory swap = _swaps[id]; - - if (swap.owner != msg.sender) { - revert InvalidAddress(msg.sender); - } + _swaps[id].expiry = 0; - if (swap.expiry < block.timestamp) { - revert InvalidExpiry(swap.expiry); - } + Asset[] memory assets = swap.asking; - _swaps[id].expiry = 0; - - emit SwapCanceled(id, msg.sender); + for (uint256 i = 0; i < assets.length; ) { + ITransfer(assets[i].addr).transferFrom( + msg.sender, + swap.owner, + assets[i].amountOrId + ); + unchecked { + i++; + } } - /** - * @dev See {ISwaplace-getSwap}. - */ - function getSwap(uint256 id) public view returns (Swap memory) { - return _swaps[id]; + assets = swap.biding; + + for (uint256 i = 0; i < assets.length; ) { + ITransfer(assets[i].addr).transferFrom( + swap.owner, + msg.sender, + assets[i].amountOrId + ); + unchecked { + i++; + } } - /** - * @dev See {IERC165-supportsInterface}. - */ - function supportsInterface( - bytes4 interfaceID - ) external pure override(IERC165) returns (bool) { - return - interfaceID == type(IERC165).interfaceId || - interfaceID == type(ISwaplace).interfaceId; + emit SwapAccepted(id, msg.sender); + + return true; + } + + /** + * @dev See {ISwaplace-cancelSwap}. + */ + function cancelSwap(uint256 id) public { + Swap memory swap = _swaps[id]; + + if (swap.owner != msg.sender) { + revert InvalidAddress(msg.sender); } - /** - * @dev Getter function for _totalSwaps. - */ - function totalSwaps() public view returns (uint256) { - return _totalSwaps; + if (swap.expiry < block.timestamp) { + revert InvalidExpiry(swap.expiry); } + + _swaps[id].expiry = 0; + + emit SwapCanceled(id, msg.sender); + } + + /** + * @dev See {ISwaplace-getSwap}. + */ + function getSwap(uint256 id) public view returns (Swap memory) { + return _swaps[id]; + } + + /** + * @dev See {IERC165-supportsInterface}. + */ + function supportsInterface( + bytes4 interfaceID + ) external pure override(IERC165) returns (bool) { + return + interfaceID == type(IERC165).interfaceId || + interfaceID == type(ISwaplace).interfaceId; + } + + /** + * @dev Getter function for _totalSwaps. + */ + function totalSwaps() public view returns (uint256) { + return _totalSwaps; + } }