Skip to content

Commit eb5c48e

Browse files
authored
Merge pull request #143 from 0xneves/review-natspec
docs: review of the entire NatSpec
2 parents 79915b5 + fe5471e commit eb5c48e

16 files changed

+160
-126
lines changed

contracts/SwapFactory.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {ISwap} from "./interfaces/ISwap.sol";
66
import {ISwapFactory} from "./interfaces/ISwapFactory.sol";
77

88
/**
9-
* @dev - SwapFactory is a helper for creating Swaps and making asset structs.
9+
* @dev SwapFactory is a helper for creating Swaps and making asset structs.
1010
*
1111
* This helper can be used on and off-chain to easily create a Swap struct to be
1212
* used in the {Swaplace-createSwap} function.
@@ -44,7 +44,7 @@ abstract contract SwapFactory is ISwapFactory, ISwap, IErrors {
4444
}
4545

4646
/**
47-
* @dev See {ISwapFactory-makeSwap}.
47+
* @dev See {ISwapFactory-makeSwap}.
4848
*/
4949
function makeSwap(
5050
address owner,

contracts/Swaplace.sol

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ import {ISwaplace} from "./interfaces/ISwaplace.sol";
66
import {ITransfer} from "./interfaces/ITransfer.sol";
77
import {SwapFactory} from "./SwapFactory.sol";
88

9-
/** ___ _ ___ ___ _ _____ _ _ _
10-
* | _ ) | / _ \ / __| |/ / __| | | | |
11-
* | _ \ |_| (_) | (__| ' <| _|| |_| | |__
12-
* |___/____\___/ \___|_|\_\_| \___/|____|
9+
/**
1310
* @author @0xneves | @blockful_io
14-
* @dev - Swaplace is a Decentralized Feeless DEX. It has no owners, it cannot be stoped.
15-
* Its core idea is to facilitate swaps between virtual assets following the ERC standard.
11+
* @dev Swaplace is a Decentralized Feeless DEX. It has no owners, it cannot be stoped.
12+
* Its cern is to facilitate swaps between virtual assets following the ERC standard.
1613
* Users can propose or accept swaps by allowing Swaplace to move their assets using the
17-
* `approve` function of the Token standard or `permit` if available.
14+
* `approve` or `permit` function.
1815
*/
1916
contract Swaplace is SwapFactory, ISwaplace, IERC165 {
2017
/// @dev Swap Identifier counter.

contracts/interfaces/ISwapFactory.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface ISwapFactory {
1717
) external pure returns (ISwap.Asset memory);
1818

1919
/**
20-
* @dev Build a swap struct to use in the {Swaplace-createSwap} function.
20+
* @dev Build a swap struct to use in the {Swaplace-createSwap} function.
2121
*
2222
* Requirements:
2323
*

contracts/mock/ERC20/ERC20.sol

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract contract ERC20 is IERC20, IERC20Permit, IERC20Errors {
1919
);
2020

2121
/**
22-
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
22+
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
2323
*/
2424
bytes32 private immutable _domainSeparator;
2525

@@ -41,13 +41,12 @@ abstract contract ERC20 is IERC20, IERC20Permit, IERC20Errors {
4141
/**
4242
* @dev Map accounts to spender to the allowed transfereable value.
4343
*/
44-
mapping(address => mapping(address => uint256))
45-
private _allowance;
44+
mapping(address => mapping(address => uint256)) private _allowance;
4645

4746
/**
4847
* @dev Map accounts to balance of Tokens.
4948
*/
50-
mapping(address => uint256 ) private _balances;
49+
mapping(address => uint256) private _balances;
5150

5251
/**
5352
* @dev Map accounts to its current nonce.

docs/SwapFactory.md

+12-13
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22

33
## SwapFactory
44

5-
_- SwapFactory is a helper for creating Swaps and making asset structs.
5+
SwapFactory is a helper for creating Swaps and making asset structs.
66

77
This helper can be used on and off-chain to easily create a Swap struct to be
88
used in the {Swaplace-createSwap} function.
99

1010
Swaplace uses a {ISwap-Swap} struct to represent a Swap. This struct is
1111
composed of:
1212

13-
- The `owner` of the Swap is the address that created the Swap.
14-
- The `allowed` address is the address that can accept the Swap. If the allowed
15-
address is the zero address, then anyone can accept the Swap.
16-
- The `expiry` date is the timestamp that the Swap will be available to accept.
17-
- The `biding` are the assets that the owner is offering.
18-
- The `asking` are the assets that the owner wants in exchange.
13+
- The `owner` of the Swap is the address that created the Swap.
14+
- The `allowed` address is the address that can accept the Swap. If the allowed
15+
address is the zero address, then anyone can accept the Swap.
16+
- The `expiry` date is the timestamp that the Swap will be available to accept.
17+
- The `biding` are the assets that the owner is offering.
18+
- The `asking` are the assets that the owner wants in exchange.
1919

2020
The Swap struct uses an {Asset} struct to represent the asset. This struct is
2121
composed of:
2222

23-
- The `address` of the asset. This address can be from an ERC20 or ERC721 contract.
24-
- The `amount` or `id` of the asset. This amount can be the amount of ERC20 tokens
25-
or the id of an ERC721 token.
23+
- The `address` of the asset. This address can be from an ERC20 or ERC721 contract.
24+
- The `amount` or `id` of the asset. This amount can be the amount of ERC20 tokens
25+
or the id of an ERC721 token.
2626

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

3131
### makeAsset
3232

@@ -42,5 +42,4 @@ _See {ISwapFactory-makeAsset}._
4242
function makeSwap(address owner, address allowed, uint256 expiry, struct ISwap.Asset[] biding, struct ISwap.Asset[] asking) public view virtual returns (struct ISwap.Swap)
4343
```
4444

45-
@dev See {ISwapFactory-makeSwap}.
46-
45+
_See {ISwapFactory-makeSwap}._

docs/Swaplace.md

+10-16
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,10 @@
22

33
## Swaplace
44

5-
___ _ ___ ___ _ _____ _ _ _
6-
| _ ) | / _ \ / __| |/ / __| | | | |
7-
| _ \ |_| (_) | (__| ' <| _|| |_| | |__
8-
|___/____\___/ \___|_|\_\_| \___/|____|
9-
10-
_- Swaplace is a Decentralized Feeless DEX. It has no owners, it cannot be stoped.
11-
Its core idea is to facilitate swaps between virtual assets following the ERC standard.
5+
Swaplace is a Decentralized Feeless DEX. It has no owners, it cannot be stoped.
6+
Its cern is to facilitate swaps between virtual assets following the ERC standard.
127
Users can propose or accept swaps by allowing Swaplace to move their assets using the
13-
`approve` function of the Token standard or `permit` if available._
14-
15-
### swapId
16-
17-
```solidity
18-
uint256 swapId
19-
```
20-
21-
_Swap Identifier counter._
8+
`approve` function or `permit` if available.
229

2310
### createSwap
2411

@@ -60,3 +47,10 @@ function supportsInterface(bytes4 interfaceID) external pure returns (bool)
6047

6148
_See {IERC165-supportsInterface}._
6249

50+
### totalSwaps
51+
52+
```solidity
53+
function totalSwaps() public view returns (uint256)
54+
```
55+
56+
_Getter function for \_totalSwaps._

docs/echidna/TestSwapFactory.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Solidity API
2+
3+
## TestFactory
4+
5+
### has_values
6+
7+
```solidity
8+
function has_values() public
9+
```
10+
11+
### make_asset_array
12+
13+
```solidity
14+
function make_asset_array(address addr, uint256 amountOrId) public pure returns (struct ISwap.Asset[])
15+
```
16+
17+
### make_valid_swap
18+
19+
```solidity
20+
function make_valid_swap(address owner, address addr, uint256 amountOrId) public view returns (struct ISwap.Swap)
21+
```
22+
23+
### echidna_revert_invalid_expiry
24+
25+
```solidity
26+
function echidna_revert_invalid_expiry() public view
27+
```
28+
29+
### echidna_revert_invalid_length
30+
31+
```solidity
32+
function echidna_revert_invalid_length() public view
33+
```
34+

docs/echidna/TestSwaplace.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Solidity API
2+
3+
## TestSwaplace
4+
5+
### constructor
6+
7+
```solidity
8+
constructor() public
9+
```
10+
11+
### echidna_create_swap
12+
13+
```solidity
14+
function echidna_create_swap() public returns (bool)
15+
```
16+
17+
### echidna_accept_swap
18+
19+
```solidity
20+
function echidna_accept_swap() public returns (bool)
21+
```
22+
23+
### echidna_id_overflow
24+
25+
```solidity
26+
function echidna_id_overflow() public view returns (bool)
27+
```
28+
29+
### echidna_id_never_zero_after_init
30+
31+
```solidity
32+
function echidna_id_never_zero_after_init() public view returns (bool)
33+
```
34+

docs/interfaces/IERC165.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22

33
## IERC165
44

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

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

11-
For an implementation, see {ERC165}._
11+
For an implementation, see {ERC165}.
1212

1313
### supportsInterface
1414

1515
```solidity
1616
function supportsInterface(bytes4 interfaceId) external view returns (bool)
1717
```
1818

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

24-
This function call must use less than 30 000 gas._
25-
24+
This function call must use less than 30 000 gas.

docs/interfaces/IErrors.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,33 @@
22

33
## IErrors
44

5-
_Errors only interface for the {Swaplace} implementations._
5+
Errors only interface for the {Swaplace} implementations.
66

77
### InvalidAddress
88

99
```solidity
1010
error InvalidAddress(address caller)
1111
```
1212

13-
_Displayed when the caller is not the owner of the swap._
13+
Displayed when the caller is not the owner of the swap.
1414

1515
### InvalidAssetsLength
1616

1717
```solidity
1818
error InvalidAssetsLength()
1919
```
2020

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

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

2828
### InvalidExpiry
2929

3030
```solidity
3131
error InvalidExpiry(uint256 timestamp)
3232
```
3333

34-
_Displayed when the `expiry` date is in the past._
35-
34+
Displayed when the `expiry` date is in the past.

docs/interfaces/ISwap.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## ISwap
44

5-
_Interface for the Swap Struct, used in the {Swaplace} implementation._
5+
Interface for the Swap Struct, used in the {Swaplace} implementation.
66

77
### Asset
88

@@ -13,6 +13,15 @@ struct Asset {
1313
}
1414
```
1515

16+
Assets can be ERC20 or ERC721.
17+
18+
It is composed of:
19+
20+
- `addr` of the asset.
21+
- `amountOrId` of the asset based on the standard.
22+
23+
NOTE: `amountOrId` is the `amount` of ERC20 or the `tokenId` of ERC721.
24+
1625
### Swap
1726

1827
```solidity
@@ -25,3 +34,14 @@ struct Swap {
2534
}
2635
```
2736

37+
The Swap struct is the heart of Swaplace.
38+
39+
It is composed of:
40+
41+
- `owner` of the Swap.
42+
- `allowed` address to accept the Swap.
43+
- `expiry` date of the Swap.
44+
- `biding` assets that are being bided by the owner.
45+
- `asking` assets that are being asked by the owner.
46+
47+
NOTE: When `allowed` address is the zero address, anyone can accept the Swap.

docs/interfaces/ISwapFactory.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22

33
## ISwapFactory
44

5-
_Interface of the {SwapFactory} implementation._
5+
Interface of the {SwapFactory} implementation.
66

77
### makeAsset
88

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

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

1616
### makeSwap
1717

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

22-
@dev Build a swap struct to use in the {Swaplace-createSwap} function.
22+
Build a swap struct to use in the {Swaplace-createSwap} function.
2323

2424
Requirements:
2525

26-
- `expiry` cannot be in the past timestamp.
27-
- `biding` and `asking` cannot be empty.
28-
26+
- `expiry` cannot be in the past timestamp.
27+
- `biding` and `asking` cannot be empty.

0 commit comments

Comments
 (0)