Skip to content

Commit

Permalink
refactor: linting all files and updating solidity-docgen
Browse files Browse the repository at this point in the history
  • Loading branch information
0xneves committed Feb 2, 2024
1 parent 02bb801 commit 441b1b1
Show file tree
Hide file tree
Showing 24 changed files with 714 additions and 119 deletions.
16 changes: 7 additions & 9 deletions contracts/SwapFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ abstract contract SwapFactory is ISwapFactory, ISwap, IErrors {
if (biding.length == 0 || asking.length == 0) revert InvalidAssetsLength();

uint256 config = packData(allowed, expiry);
return Swap(owner,config, biding, asking);

return Swap(owner, config, biding, asking);
}

/**
Expand All @@ -68,16 +68,14 @@ abstract contract SwapFactory is ISwapFactory, ISwap, IErrors {
function packData(
address allowed,
uint256 expiry
) public pure returns(uint256) {
return (uint256(uint160(allowed)) << 96) | uint256(expiry);
) public pure returns (uint256) {
return (uint256(uint160(allowed)) << 96) | uint256(expiry);
}

/**
* @dev See {ISwapFactory-parseData}.
*/
function parseData(
uint256 config
) public pure returns(address,uint256) {
return (address(uint160(config >> 96)),uint256(config & ((1 << 96) - 1)));
}
function parseData(uint256 config) public pure returns (address, uint256) {
return (address(uint160(config >> 96)), uint256(config & ((1 << 96) - 1)));
}
}
2 changes: 1 addition & 1 deletion contracts/echidna/TestSwapFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract TestFactory is SwapFactory {
make_asset_array(addr, amountOrId)
);

( , uint256 expiry) = parseData(swap.config);
(, uint256 expiry) = parseData(swap.config);

assert(expiry > block.timestamp);
assert(swap.biding.length > 0);
Expand Down
62 changes: 31 additions & 31 deletions contracts/interfaces/ISwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ pragma solidity ^0.8.17;
* @dev Interface for the Swap Struct, used in the {Swaplace} implementation.
*/
interface ISwap {
/**
* @dev Assets can be ERC20 or ERC721.
*
* It is composed of:
* - `addr` of the asset.
* - `amountOrId` of the asset based on the standard.
*
* NOTE: `amountOrId` is the `amount` of ERC20 or the `tokenId` of ERC721.
*/
struct Asset {
address addr;
uint256 amountOrId;
}
/**
* @dev Assets can be ERC20 or ERC721.
*
* It is composed of:
* - `addr` of the asset.
* - `amountOrId` of the asset based on the standard.
*
* NOTE: `amountOrId` is the `amount` of ERC20 or the `tokenId` of ERC721.
*/
struct Asset {
address addr;
uint256 amountOrId;
}

/**
* @dev The Swap struct is the heart of Swaplace.
*
* It is composed of:
* - `owner` of the Swap.
* - `config` represents two packed values: 'allowed' for the allowed address
* to accept the swap and 'expiry' for the expiration date of the swap.
* - `biding` assets that are being bided by the owner.
* - `asking` assets that are being asked by the owner.
*
* NOTE: When `allowed` address is the zero address, anyone can accept the Swap.
*/
struct Swap {
address owner;
uint256 config;
Asset[] biding;
Asset[] asking;
}
/**
* @dev The Swap struct is the heart of Swaplace.
*
* It is composed of:
* - `owner` of the Swap.
* - `config` represents two packed values: 'allowed' for the allowed address
* to accept the swap and 'expiry' for the expiration date of the swap.
* - `biding` assets that are being bided by the owner.
* - `asking` assets that are being asked by the owner.
*
* NOTE: When `allowed` address is the zero address, anyone can accept the Swap.
*/
struct Swap {
address owner;
uint256 config;
Asset[] biding;
Asset[] asking;
}
}
6 changes: 2 additions & 4 deletions contracts/interfaces/ISwapFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ interface ISwapFactory {
function packData(
address allowed,
uint256 expiry
) external pure returns(uint256);
) external pure returns (uint256);

/**
* @dev Parsing the `config`.
* This function returns the extracted values of `allowed` and `expiry`.
*/
function parseData(
uint256 config
) external pure returns (address,uint256);
function parseData(uint256 config) external pure returns (address, uint256);
}
5 changes: 3 additions & 2 deletions contracts/interfaces/ISwaplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ interface ISwaplace {
event SwapAccepted(
uint256 indexed swapId,
address indexed owner,
address indexed allowed);
address indexed allowed
);

/**
* @dev Emitted when a Swap is canceled.
Expand Down Expand Up @@ -83,4 +84,4 @@ interface ISwaplace {
* If the `owner` is the zero address, then the Swap doesn't exist.
*/
function getSwap(uint256 swapId) external view returns (ISwap.Swap memory);
}
}
23 changes: 20 additions & 3 deletions docs/solidity-docgen/SwapFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## SwapFactory

SwapFactory is a helper for creating Swaps and making asset structs.
_SwapFactory is a helper for creating Swaps and making asset structs.

This helper can be used on and off-chain to easily create a Swap struct to be
used in the {Swaplace-createSwap} function.
Expand All @@ -22,11 +22,11 @@ composed of:

- The `address` of the asset. This address can be from an ERC20 or ERC721 contract.
- The `amount` or `id` of the asset. This amount can be the amount of ERC20 tokens
or the ID of an ERC721 token.
or the ID of an ERC721 token.

To use other standards, like ERC1155, you can wrap the ownership of the asset
in an a trusted contract and Swap as an ERC721. This way, you can tokenize any
on-chain execution and trade on Swaplace.
on-chain execution and trade on Swaplace._

### makeAsset

Expand All @@ -43,3 +43,20 @@ function makeSwap(address owner, address allowed, uint256 expiry, struct ISwap.A
```

_See {ISwapFactory-makeSwap}._

### packData

```solidity
function packData(address allowed, uint256 expiry) public pure returns (uint256)
```

_See {ISwapFactory-packData}._

### parseData

```solidity
function parseData(uint256 config) public pure returns (address, uint256)
```

_See {ISwapFactory-parseData}._

9 changes: 5 additions & 4 deletions docs/solidity-docgen/Swaplace.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## Swaplace

Swaplace is a Decentralized Feeless DEX. It has no owners, it cannot be stoped.
_Swaplace is a Decentralized Feeless DEX. It has no owners, it cannot be stopped.
Its cern is to facilitate swaps between virtual assets following the ERC standard.
Users can propose or accept swaps by allowing Swaplace to move their assets using the
`approve` function or `permit` if available.
`approve` or `permit` function._

### createSwap

Expand All @@ -18,7 +18,7 @@ _See {ISwaplace-createSwap}._
### acceptSwap

```solidity
function acceptSwap(uint256 swapId) public returns (bool)
function acceptSwap(uint256 swapId, address receiver) public returns (bool)
```

_See {ISwaplace-acceptSwap}._
Expand Down Expand Up @@ -53,4 +53,5 @@ _See {IERC165-supportsInterface}._
function totalSwaps() public view returns (uint256)
```

_Getter function for \_totalSwaps._
_Getter function for _totalSwaps._

9 changes: 5 additions & 4 deletions docs/solidity-docgen/interfaces/IERC165.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

## IERC165

Interface of the ERC165 standard, as defined in the
_Interface of the ERC165 standard, as defined in the
https://eips.ethereum.org/EIPS/eip-165[EIP].

Implementers can declare support of contract interfaces, which can then be
queried by others ({ERC165Checker}).

For an implementation, see {ERC165}.
For an implementation, see {ERC165}._

### supportsInterface

```solidity
function supportsInterface(bytes4 interfaceId) external view returns (bool)
```

Returns true if this contract implements the interface defined by
_Returns true if this contract implements the interface defined by
`interfaceId`. See the corresponding
https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
to learn more about how these ids are created.

This function call must use less than 30 000 gas.
This function call must use less than 30 000 gas._

11 changes: 6 additions & 5 deletions docs/solidity-docgen/interfaces/IErrors.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@

## IErrors

Errors only interface for the {Swaplace} implementations.
_Errors only interface for the {Swaplace} implementations._

### InvalidAddress

```solidity
error InvalidAddress(address caller)
```

Displayed when the caller is not the owner of the swap.
_Displayed when the caller is not the owner of the swap._

### InvalidAssetsLength

```solidity
error InvalidAssetsLength()
```

Displayed when the amount of {ISwap-Asset} has a length of zero.
_Displayed when the amount of {ISwap-Asset} has a length of zero.

NOTE: The `biding` or `asking` array must not be empty to avoid mistakes
when creating a swap. Assuming one side of the swap is empty, the
correct approach should be the usage of {transferFrom} and we reinforce
this behavior by requiring the length of the array to be bigger than zero.
this behavior by requiring the length of the array to be bigger than zero._

### InvalidExpiry

```solidity
error InvalidExpiry(uint256 timestamp)
```

Displayed when the `expiry` date is in the past.
_Displayed when the `expiry` date is in the past._

25 changes: 2 additions & 23 deletions docs/solidity-docgen/interfaces/ISwap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## ISwap

Interface for the Swap Struct, used in the {Swaplace} implementation.
_Interface for the Swap Struct, used in the {Swaplace} implementation._

### Asset

Expand All @@ -13,35 +13,14 @@ struct Asset {
}
```

Assets can be ERC20 or ERC721.

It is composed of:

- `addr` of the asset.
- `amountOrId` of the asset based on the standard.

NOTE: `amountOrId` is the `amount` of ERC20 or the `tokenId` of ERC721.

### Swap

```solidity
struct Swap {
address owner;
address allowed;
uint256 expiry;
uint256 config;
struct ISwap.Asset[] biding;
struct ISwap.Asset[] asking;
}
```

The Swap struct is the heart of Swaplace.

It is composed of:

- `owner` of the Swap.
- `allowed` address to accept the Swap.
- `expiry` date of the Swap.
- `biding` assets that are being bided by the owner.
- `asking` assets that are being asked by the owner.

NOTE: When `allowed` address is the zero address, anyone can accept the Swap.
31 changes: 25 additions & 6 deletions docs/solidity-docgen/interfaces/ISwapFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,45 @@

## ISwapFactory

Interface of the {SwapFactory} implementation.
_Interface of the {SwapFactory} implementation._

### makeAsset

```solidity
function makeAsset(address addr, uint256 amountOrId) external pure returns (struct ISwap.Asset)
```

Constructs an asset struct that works for ERC20 or ERC721.
This function is a utility to easily create an `Asset` struct on-chain or off-chain.
_Constructs an asset struct that works for ERC20 or ERC721.
This function is a utility to easily create an `Asset` struct on-chain or off-chain._

### makeSwap

```solidity
function makeSwap(address owner, address allowed, uint256 expiry, struct ISwap.Asset[] assets, struct ISwap.Asset[] asking) external view returns (struct ISwap.Swap)
```

Build a swap struct to use in the {Swaplace-createSwap} function.
_Build a swap struct to use in the {Swaplace-createSwap} function.

Requirements:

- `expiry` cannot be in the past timestamp.
- `biding` and `asking` cannot be empty.
- `expiry` cannot be in the past timestamp.
- `biding` and `asking` cannot be empty._

### packData

```solidity
function packData(address allowed, uint256 expiry) external pure returns (uint256)
```

_Packs `allowed` and the `expiry`.
This function returns the bitwise packing of `allowed` and `expiry` as a uint256._

### parseData

```solidity
function parseData(uint256 config) external pure returns (address, uint256)
```

_Parsing the `config`.
This function returns the extracted values of `allowed` and `expiry`._

Loading

0 comments on commit 441b1b1

Please sign in to comment.