diff --git a/contracts/SwapFactory.sol b/contracts/SwapFactory.sol index ff52c69..5ec37fd 100644 --- a/contracts/SwapFactory.sol +++ b/contracts/SwapFactory.sol @@ -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); } /** @@ -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))); + } } diff --git a/contracts/echidna/TestSwapFactory.sol b/contracts/echidna/TestSwapFactory.sol index 5b6dacc..b8ff11b 100644 --- a/contracts/echidna/TestSwapFactory.sol +++ b/contracts/echidna/TestSwapFactory.sol @@ -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); diff --git a/contracts/interfaces/ISwap.sol b/contracts/interfaces/ISwap.sol index 91f2e11..693f162 100644 --- a/contracts/interfaces/ISwap.sol +++ b/contracts/interfaces/ISwap.sol @@ -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; + } } diff --git a/contracts/interfaces/ISwapFactory.sol b/contracts/interfaces/ISwapFactory.sol index 35e4cb7..70a3d43 100644 --- a/contracts/interfaces/ISwapFactory.sol +++ b/contracts/interfaces/ISwapFactory.sol @@ -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); } diff --git a/contracts/interfaces/ISwaplace.sol b/contracts/interfaces/ISwaplace.sol index c613e69..5dedc9d 100644 --- a/contracts/interfaces/ISwaplace.sol +++ b/contracts/interfaces/ISwaplace.sol @@ -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. @@ -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); -} \ No newline at end of file +} diff --git a/docs/solidity-docgen/SwapFactory.md b/docs/solidity-docgen/SwapFactory.md index 9326a4e..2560a6d 100644 --- a/docs/solidity-docgen/SwapFactory.md +++ b/docs/solidity-docgen/SwapFactory.md @@ -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. @@ -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 @@ -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}._ + diff --git a/docs/solidity-docgen/Swaplace.md b/docs/solidity-docgen/Swaplace.md index 799136d..1a76ad9 100644 --- a/docs/solidity-docgen/Swaplace.md +++ b/docs/solidity-docgen/Swaplace.md @@ -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 @@ -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}._ @@ -53,4 +53,5 @@ _See {IERC165-supportsInterface}._ function totalSwaps() public view returns (uint256) ``` -_Getter function for \_totalSwaps._ +_Getter function for _totalSwaps._ + diff --git a/docs/solidity-docgen/interfaces/IERC165.md b/docs/solidity-docgen/interfaces/IERC165.md index b251fdd..eb67eeb 100644 --- a/docs/solidity-docgen/interfaces/IERC165.md +++ b/docs/solidity-docgen/interfaces/IERC165.md @@ -2,13 +2,13 @@ ## 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 @@ -16,9 +16,10 @@ For an implementation, see {ERC165}. 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._ + diff --git a/docs/solidity-docgen/interfaces/IErrors.md b/docs/solidity-docgen/interfaces/IErrors.md index 23ee2bb..b30555a 100644 --- a/docs/solidity-docgen/interfaces/IErrors.md +++ b/docs/solidity-docgen/interfaces/IErrors.md @@ -2,7 +2,7 @@ ## IErrors -Errors only interface for the {Swaplace} implementations. +_Errors only interface for the {Swaplace} implementations._ ### InvalidAddress @@ -10,7 +10,7 @@ Errors only interface for the {Swaplace} implementations. 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 @@ -18,12 +18,12 @@ Displayed when the caller is not the owner of the swap. 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 @@ -31,4 +31,5 @@ this behavior by requiring the length of the array to be bigger than zero. error InvalidExpiry(uint256 timestamp) ``` -Displayed when the `expiry` date is in the past. +_Displayed when the `expiry` date is in the past._ + diff --git a/docs/solidity-docgen/interfaces/ISwap.md b/docs/solidity-docgen/interfaces/ISwap.md index a3096c0..0209bb6 100644 --- a/docs/solidity-docgen/interfaces/ISwap.md +++ b/docs/solidity-docgen/interfaces/ISwap.md @@ -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 @@ -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. diff --git a/docs/solidity-docgen/interfaces/ISwapFactory.md b/docs/solidity-docgen/interfaces/ISwapFactory.md index fd004ed..e90f35e 100644 --- a/docs/solidity-docgen/interfaces/ISwapFactory.md +++ b/docs/solidity-docgen/interfaces/ISwapFactory.md @@ -2,7 +2,7 @@ ## ISwapFactory -Interface of the {SwapFactory} implementation. +_Interface of the {SwapFactory} implementation._ ### makeAsset @@ -10,8 +10,8 @@ Interface of the {SwapFactory} implementation. 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 @@ -19,9 +19,28 @@ This function is a utility to easily create an `Asset` struct on-chain or off-ch 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`._ + diff --git a/docs/solidity-docgen/interfaces/ISwaplace.md b/docs/solidity-docgen/interfaces/ISwaplace.md index b3e08cc..04846c2 100644 --- a/docs/solidity-docgen/interfaces/ISwaplace.md +++ b/docs/solidity-docgen/interfaces/ISwaplace.md @@ -2,23 +2,23 @@ ## ISwaplace -Interface of the {Swaplace} implementation. +_Interface of the {Swaplace} implementation._ ### SwapCreated ```solidity -event SwapCreated(uint256 swapId, address owner, address allowed, uint256 expiry) +event SwapCreated(uint256 swapId, address owner, address allowed) ``` -Emitted when a new Swap is created. +_Emitted when a new Swap is created._ ### SwapAccepted ```solidity -event SwapAccepted(uint256 swapId, address acceptee) +event SwapAccepted(uint256 swapId, address owner, address allowed) ``` -Emitted when a Swap is accepted. +_Emitted when a Swap is accepted._ ### SwapCanceled @@ -26,7 +26,7 @@ Emitted when a Swap is accepted. event SwapCanceled(uint256 swapId, address owner) ``` -Emitted when a Swap is canceled. +_Emitted when a Swap is canceled._ ### createSwap @@ -34,7 +34,7 @@ Emitted when a Swap is canceled. function createSwap(struct ISwap.Swap Swap) external returns (uint256) ``` -Allow users to create a Swap. Each new Swap self-increments its ID by one. +_Allow users to create a Swap. Each new Swap self-increments its ID by one. Requirements: @@ -42,15 +42,15 @@ Requirements: - `expiry` should be bigger than timestamp. - `biding` and `asking` must not be empty. -Emits a {SwapCreated} event. +Emits a {SwapCreated} event._ ### acceptSwap ```solidity -function acceptSwap(uint256 swapId) external returns (bool) +function acceptSwap(uint256 swapId, address receiver) external returns (bool) ``` -Accepts a Swap. Once the Swap is accepted, the expiry is set +_Accepts a Swap. Once the Swap is accepted, the expiry is set to zero to avoid reutilization. Requirements: @@ -63,7 +63,7 @@ Requirements: Emits a {SwapAccepted} event. NOTE: The expiry is set to 0, because if the Swap is expired it -will revert, preventing reentrancy attacks. +will revert, preventing reentrancy attacks._ ### cancelSwap @@ -71,7 +71,7 @@ will revert, preventing reentrancy attacks. function cancelSwap(uint256 swapId) external ``` -Cancels an active Swap by setting the expiry to zero. +_Cancels an active Swap by setting the expiry to zero. Expiry with 0 seconds means that the Swap doesn't exist or is already canceled. @@ -81,7 +81,7 @@ Requirements: - `owner` must be the caller adress. - `expiry` must be bigger than timestamp. -Emits a {SwapCanceled} event. +Emits a {SwapCanceled} event._ ### getSwap @@ -89,8 +89,9 @@ Emits a {SwapCanceled} event. function getSwap(uint256 swapId) external view returns (struct ISwap.Swap) ``` -Retrieves the details of a Swap based on the `swapId` provided. +_Retrieves the details of a Swap based on the `swapId` provided. NOTE: If the Swaps doesn't exist, the values will be defaulted to 0. You can check if a Swap exists by checking if the `owner` is the zero address. -If the `owner` is the zero address, then the Swap doesn't exist. +If the `owner` is the zero address, then the Swap doesn't exist._ + diff --git a/docs/solidity-docgen/interfaces/ITransfer.md b/docs/solidity-docgen/interfaces/ITransfer.md index f035078..b9e50de 100644 --- a/docs/solidity-docgen/interfaces/ITransfer.md +++ b/docs/solidity-docgen/interfaces/ITransfer.md @@ -2,7 +2,7 @@ ## ITransfer -Generalized Interface for {IERC20} and {IERC721} `transferFrom` functions. +_Generalized Interface for {IERC20} and {IERC721} `transferFrom` functions._ ### transferFrom @@ -10,8 +10,9 @@ Generalized Interface for {IERC20} and {IERC721} `transferFrom` functions. function transferFrom(address from, address to, uint256 amountOrId) external ``` -_See {IERC20-transferFrom} or {IERC721-transferFrom}._ +_See {IERC20-transferFrom} or {IERC721-transferFrom}. Moves an `amount` for ERC20 or `tokenId` for ERC721 from `from` to `to`. -Emits a {Transfer} event. +Emits a {Transfer} event._ + diff --git a/docs/solidity-docgen/mock/ERC20/ERC20.md b/docs/solidity-docgen/mock/ERC20/ERC20.md new file mode 100644 index 0000000..1075c96 --- /dev/null +++ b/docs/solidity-docgen/mock/ERC20/ERC20.md @@ -0,0 +1,205 @@ +# Solidity API + +## ERC20 + +_Lightweight ERC20 with Permit extension._ + +### constructor + +```solidity +constructor(string name_, string symbol_) internal +``` + +_Sets the values for {name} and {symbol}._ + +### name + +```solidity +function name() public view virtual returns (string) +``` + +_Returns the name of the token._ + +### symbol + +```solidity +function symbol() public view virtual returns (string) +``` + +_Returns the symbol of the token, usually a shorter version of the +name._ + +### decimals + +```solidity +function decimals() public view virtual returns (uint8) +``` + +_Returns the number of decimals used to get its user representation. +For example, if `decimals` equals `2`, a balance of `505` tokens should +be displayed to a user as `5.05` (`505 / 10 ** 2`). + +Tokens usually opt for a value of 18, imitating the relationship between +Ether and Wei. This is the default value returned by this function, unless +it's overridden. + +NOTE: This information is only used for _display_ purposes: it in +no way affects any of the arithmetic of the contract, including +{IERC20-balanceOf} and {IERC20-transfer}._ + +### totalSupply + +```solidity +function totalSupply() public view virtual returns (uint256) +``` + +_See {IERC20-totalSupply}._ + +### balanceOf + +```solidity +function balanceOf(address account) public view virtual returns (uint256) +``` + +_See {IERC20-balanceOf}._ + +### allowance + +```solidity +function allowance(address owner, address spender) public view virtual returns (uint256) +``` + +_See {IERC20-allowance}._ + +### nonces + +```solidity +function nonces(address owner) public view virtual returns (uint256) +``` + +_Returns the current nonce of an address._ + +### DOMAIN_SEPARATOR + +```solidity +function DOMAIN_SEPARATOR() public view virtual returns (bytes32) +``` + +_See {IERC20Permit-DOMAIN_SEPARATOR}._ + +### approve + +```solidity +function approve(address spender, uint256 value) public virtual returns (bool) +``` + +_See {IERC20-approve}. + +NOTE: If `value` is the maximum `uint256`, the allowance is not updated on +`transferFrom`. This is semantically equivalent to an infinite approval._ + +### increaseAllowance + +```solidity +function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) +``` + +_See {IERC20-increaseAllowance}._ + +### decreaseAllowance + +```solidity +function decreaseAllowance(address spender, uint256 requestedDecrease) public virtual returns (bool) +``` + +_See {IERC20-decreaseAllowance}. + +Requirements: + +- `spender` must have allowance for the caller of at least +`requestedDecrease`._ + +### permit + +```solidity +function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual returns (bool) +``` + +_See {IERC20Permit-permit}. + +Requirements: + +- `spender` cannot be the zero address. +- `deadline` must be a timestamp in the future. +- `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` +over the EIP712-formatted function arguments. +- the signature must use ``owner``'s current nonce (see {IERC20Permit-nonces})._ + +### _mint + +```solidity +function _mint(address to, uint256 value) internal +``` + +_Creates an `value` of tokens and assigns them to `to` by creating supply. + +Emits a {Transfer} event with `from` set to the zero address._ + +### _burn + +```solidity +function _burn(address from, uint256 value) internal +``` + +_Destroys an `value` of tokens from `from` by lowering the total supply. + +Requirements: + +- `from` must have a balance of at least `value`. + +Emits a {Transfer} event with `to` set to the zero address._ + +### transfer + +```solidity +function transfer(address to, uint256 value) public virtual returns (bool) +``` + +_See {IERC20-transfer}. + +Requirements: + +- the caller must have a balance of at least `value`._ + +### transferFrom + +```solidity +function transferFrom(address from, address to, uint256 value) public virtual returns (bool) +``` + +_See {IERC20-transferFrom}. + +Requirements: + +- `from` must have a balance of at least `value`. +- the caller must have allowance for `from`'s tokens of at least +`value`. + +NOTE: Does not update the allowance if the current allowance +is the maximum `uint256`._ + +### permitTransfer + +```solidity +function permitTransfer(address from, address to, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual returns (bool) +``` + +_See {IERC20Permit-permitTransfer}. + +Requirements: + +- `deadline` must be a timestamp in the future. +- `v`, `r` and `s` must be a valid `secp256k1` signature from `from` +over the EIP712-formatted function arguments. +- the signature must use `from`'s current nonce (see {IERC20Permit-nonces})._ + diff --git a/docs/solidity-docgen/mock/ERC20/interfaces/IERC20.md b/docs/solidity-docgen/mock/ERC20/interfaces/IERC20.md new file mode 100644 index 0000000..d5bf51b --- /dev/null +++ b/docs/solidity-docgen/mock/ERC20/interfaces/IERC20.md @@ -0,0 +1,154 @@ +# Solidity API + +## IERC20 + +_Interface of the ERC20 standard as defined in the EIP._ + +### Approval + +```solidity +event Approval(address owner, address spender, uint256 value) +``` + +_Emitted when the allowance of a `spender` for an `owner` is set by +a call to {approve}. `value` is the new allowance._ + +### Transfer + +```solidity +event Transfer(address from, address to, uint256 value) +``` + +_Emitted when `value` tokens are moved from `from` to `to`. + +NOTE: `value` can be zero._ + +### name + +```solidity +function name() external view returns (string) +``` + +_Returns the name of the token._ + +### symbol + +```solidity +function symbol() external view returns (string) +``` + +_Returns the symbol of the token._ + +### decimals + +```solidity +function decimals() external view returns (uint8) +``` + +_Returns the decimals places of the token._ + +### totalSupply + +```solidity +function totalSupply() external view returns (uint256) +``` + +_Returns the value of tokens in existence._ + +### balanceOf + +```solidity +function balanceOf(address account) external view returns (uint256) +``` + +_Returns the value of tokens owned by `account`._ + +### allowance + +```solidity +function allowance(address owner, address spender) external view returns (uint256) +``` + +_Returns the remaining number of tokens that `spender` will be +allowed to spend on behalf of `owner` through {transferFrom}. This is +zero by default. + +This value changes when {approve} or {transferFrom} are called. + +NOTE: If `value` is the maximum `uint256`, the allowance is not updated on +`transferFrom`. This is semantically equivalent to an infinite approval._ + +### approve + +```solidity +function approve(address spender, uint256 value) external returns (bool) +``` + +_Sets a `value` amount of tokens as the allowance of `spender` over the +caller's tokens. + +Returns a boolean value indicating whether the operation succeeded. + +IMPORTANT: Beware that changing an allowance with this method brings the risk +that someone may use both the old and the new allowance by unfortunate +transaction ordering. One possible solution to mitigate this race +condition is to first reduce the spender's allowance to 0 and set the +desired value afterwards: +https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + +Emits an {Approval} event._ + +### increaseAllowance + +```solidity +function increaseAllowance(address spender, uint256 addedValue) external returns (bool) +``` + +_Atomically increases the allowance granted to `spender` by the caller. + +This is an alternative to {approve} that can be used as a mitigation for +problems described in {IERC20-approve}. + +Emits an {IERC20-Approval} event indicating the updated allowance._ + +### decreaseAllowance + +```solidity +function decreaseAllowance(address spender, uint256 requestedDecrease) external returns (bool) +``` + +_Atomically decreases the allowance granted to `spender` by the caller. + +This is an alternative to {approve} that can be used as a mitigation for +problems described in {IERC20-approve}. + +Emits an {Approval} event indicating the updated allowance. + +NOTE: Although this function is designed to avoid double spending with {approval}, +it can still be frontrunned, preventing any attempt of allowance reduction._ + +### transfer + +```solidity +function transfer(address to, uint256 value) external returns (bool) +``` + +_Moves a `value` amount of tokens from the caller's account to `to`. +Returns a boolean value indicating whether the operation succeeded. + +Emits a {Transfer} event._ + +### transferFrom + +```solidity +function transferFrom(address from, address to, uint256 value) external returns (bool) +``` + +_Moves a `value` amount of tokens from `from` to `to` using the +allowance mechanism. `value` is then deducted from the caller's +allowance. + +Returns a boolean value indicating whether the operation succeeded. + +Emits a {Transfer} event._ + diff --git a/docs/solidity-docgen/mock/ERC20/interfaces/IERC20Errors.md b/docs/solidity-docgen/mock/ERC20/interfaces/IERC20Errors.md new file mode 100644 index 0000000..b0f5ae6 --- /dev/null +++ b/docs/solidity-docgen/mock/ERC20/interfaces/IERC20Errors.md @@ -0,0 +1,98 @@ +# Solidity API + +## IERC20Errors + +_Standard ERC20 Errors_ + +### ERC20InsufficientBalance + +```solidity +error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed) +``` + +_Indicates an error related to the current `balance` of a `sender`. Used in transfers._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| sender | address | Address whose tokens are being transferred. | +| balance | uint256 | Current balance for the interacting account. | +| needed | uint256 | Minimum amount required to perform a transfer. | + +### ERC20InsufficientAllowance + +```solidity +error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed) +``` + +_Indicates a failure with the `spender`’s `allowance`. Used in transfers._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| spender | address | Address that may be allowed to operate on tokens without being their owner. | +| allowance | uint256 | Amount of tokens a `spender` is allowed to operate with. | +| needed | uint256 | Minimum amount required to perform a transfer. | + +### ERC20FailedDecreaseAllowance + +```solidity +error ERC20FailedDecreaseAllowance(address spender, uint256 allowance, uint256 needed) +``` + +_Indicates a failed `decreaseAllowance` request._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| spender | address | Address that may be allowed to operate on tokens without being their owner. | +| allowance | uint256 | Amount of tokens a `spender` want to operate with. | +| needed | uint256 | Amount required to decrease the allowance. | + +### ERC20PermitInvalidNonce + +```solidity +error ERC20PermitInvalidNonce(address account, uint256 nonce) +``` + +_Indicates the nonce used for an `account` is not the expected current nonce._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| account | address | Address whose nonce is being checked. | +| nonce | uint256 | Expected nonce for the given `account`. | + +### ERC2612ExpiredSignature + +```solidity +error ERC2612ExpiredSignature(uint256 deadline) +``` + +_Indicates the expiration of a permit to be used._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| deadline | uint256 | Expiration time limit in seconds. | + +### ERC2612InvalidSigner + +```solidity +error ERC2612InvalidSigner(address signer, address owner) +``` + +_Indicates the mismatched owner when validating the signature._ + +#### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| signer | address | Address of the signer recovered. | +| owner | address | Address of the owner expected to match `signer`. | + diff --git a/docs/solidity-docgen/mock/ERC20/interfaces/IERC20Permit.md b/docs/solidity-docgen/mock/ERC20/interfaces/IERC20Permit.md new file mode 100644 index 0000000..bf13c88 --- /dev/null +++ b/docs/solidity-docgen/mock/ERC20/interfaces/IERC20Permit.md @@ -0,0 +1,69 @@ +# Solidity API + +## IERC20Permit + +_Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in +https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. + +Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by +presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't +need to send a transaction, and thus is not required to hold Ether at all._ + +### nonces + +```solidity +function nonces(address owner) external view returns (uint256) +``` + +_Returns the current nonce for `owner`. This value must be +included whenever a signature is generated for {permit}. + +Every successful call to {permit} increases `owner`'s nonce by one. +This prevents a signature from being used multiple times._ + +### DOMAIN_SEPARATOR + +```solidity +function DOMAIN_SEPARATOR() external view returns (bytes32) +``` + +_Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}._ + +### permit + +```solidity +function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external returns (bool) +``` + +_Sets `value` as the allowance of `spender` over `owner`'s tokens, +given `owner`'s signed approval. + +IMPORTANT: The same issues {IERC20-approve} has related to transaction +ordering also apply here. + +Emits an {IERC20-Approval} event. + +NOTE: `spender` can be the zero address. Checking this on-chain is a bad +usage of gas. For more information on the signature format, see the +https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIPsection]._ + +### permitTransfer + +```solidity +function permitTransfer(address from, address to, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external returns (bool) +``` + +_Allows {IERC20-transferFrom} to be used with the `owner`'s signature. +Similar to permit but changing the scope to handle the balance instead of +allowance. + +Requires less gas than regular {permit} and {IERC20-transferFrom}. + +IMPORTANT: `owner` works as `from` and `spender` as `to` (see {IERC20Permit-permit}). + +Emits an {IERC20-Transfer} event. + +NOTE: Realize that {PERMIT_TYPEHASH} is different from the one in {permit}. +This is because the arguments name differ. But won't result in a different +output as long as it is encoded following the EIP712 and ERC20Permit specs._ + diff --git a/docs/solidity-docgen/mock/MockERC20.md b/docs/solidity-docgen/mock/MockERC20.md new file mode 100644 index 0000000..ee80b9c --- /dev/null +++ b/docs/solidity-docgen/mock/MockERC20.md @@ -0,0 +1,16 @@ +# Solidity API + +## MockERC20 + +### constructor + +```solidity +constructor() public +``` + +### mintTo + +```solidity +function mintTo(address to, uint256 amount) public +``` + diff --git a/docs/solidity-docgen/mock/MockERC721.md b/docs/solidity-docgen/mock/MockERC721.md new file mode 100644 index 0000000..ad0f209 --- /dev/null +++ b/docs/solidity-docgen/mock/MockERC721.md @@ -0,0 +1,22 @@ +# Solidity API + +## MockERC721 + +### totalSupply + +```solidity +uint256 totalSupply +``` + +### constructor + +```solidity +constructor() public +``` + +### mintTo + +```solidity +function mintTo(address to, uint256 id) public +``` + diff --git a/scripts/createSwap.ts b/scripts/createSwap.ts index b7d06ad..c6330b4 100644 --- a/scripts/createSwap.ts +++ b/scripts/createSwap.ts @@ -26,11 +26,13 @@ export async function main() { const askingAddr = ["0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"]; // WBTC const askingAmountOrId = [1]; + // Pack the config together + const config = await Swaplace.packData(allowed, expiry); + // Compose the swap const swap: Swap = await composeSwap( owner, - allowed, - expiry, + config, bidingAddr, bidingAmountOrId, askingAddr, diff --git a/scripts/deployMock.ts b/scripts/deployMock.ts index 52c07bd..2dfdcf3 100644 --- a/scripts/deployMock.ts +++ b/scripts/deployMock.ts @@ -21,7 +21,7 @@ export async function deployMock(signer: any) { MockERC721.address, MockERC721.deployTransaction.hash, ); - + // Return the transaction response return { MockERC20, MockERC721 }; } diff --git a/test/TestSwapFactory.test.ts b/test/TestSwapFactory.test.ts index 2d2e36c..bb1079d 100644 --- a/test/TestSwapFactory.test.ts +++ b/test/TestSwapFactory.test.ts @@ -258,7 +258,7 @@ describe("Swaplace Factory", async function () { } }); - it("Should ensure packData() and parseData() return the right values",async function () { + it("Should ensure packData() and parseData() return the right values", async function () { const currentTimestamp = (await blocktimestamp()) * 2; const config = await Swaplace.packData(acceptee.address, currentTimestamp); diff --git a/test/TestSwaplace.test.ts b/test/TestSwaplace.test.ts index 3aed783..3065cd0 100644 --- a/test/TestSwaplace.test.ts +++ b/test/TestSwaplace.test.ts @@ -326,7 +326,11 @@ describe("Swaplace", async function () { await expect(await Swaplace.connect(owner).createSwap(swap)) .to.emit(Swaplace, "SwapCreated") - .withArgs(await Swaplace.totalSwaps(), owner.address, allowed.address); + .withArgs( + await Swaplace.totalSwaps(), + owner.address, + allowed.address, + ); await expect( await Swaplace.connect(allowed).acceptSwap( @@ -335,7 +339,11 @@ describe("Swaplace", async function () { ), ) .to.emit(Swaplace, "SwapAccepted") - .withArgs(await Swaplace.totalSwaps(), owner.address, allowed.address); + .withArgs( + await Swaplace.totalSwaps(), + owner.address, + allowed.address, + ); }); }); @@ -406,7 +414,11 @@ describe("Swaplace", async function () { await expect(await Swaplace.connect(owner).createSwap(swap)) .to.emit(Swaplace, "SwapCreated") - .withArgs(await Swaplace.totalSwaps(), owner.address, deployer.address); + .withArgs( + await Swaplace.totalSwaps(), + owner.address, + deployer.address, + ); await expect( Swaplace.connect(allowed).acceptSwap( diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 832fe75..679ccf8 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -4,7 +4,7 @@ import { ethers } from "hardhat"; * @dev Get the current `block.timestamp` in seconds from the current * selected network. * - * Use `-- network localhost` to run the tests in a local network. + * Use `--network localhost` to run the tests in a local network. * Networks should be in `hardhat.config.ts` file or via command line. */ export async function blocktimestamp(): Promise { @@ -32,5 +32,5 @@ export async function deploy(contractName: any, signer: any) { module.exports = { blocktimestamp, - deploy + deploy, };