Skip to content

Commit

Permalink
refactor: format with prettierrc to all files
Browse files Browse the repository at this point in the history
  • Loading branch information
0xneves committed Dec 19, 2023
1 parent 609a09a commit e671f4e
Showing 1 changed file with 105 additions and 105 deletions.
210 changes: 105 additions & 105 deletions contracts/Swaplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit e671f4e

Please sign in to comment.