From 312c4102f838df4ff107568c4882a1012ff27c28 Mon Sep 17 00:00:00 2001 From: Vittorio Minacori Date: Thu, 26 Oct 2023 15:28:06 +0200 Subject: [PATCH] feat: update docs and dependencies --- .github/workflows/ci.yml | 16 ++++---- README.md | 32 +++++++--------- contracts/examples/ERC1363Guardian.sol | 2 +- contracts/token/ERC1363/ERC1363.sol | 6 +-- contracts/token/ERC1363/IERC1363.sol | 2 +- dist/ERC1363.dist.sol | 36 ++++++++---------- hardhat.config.js | 2 +- package-lock.json | 51 +++++++++++++++----------- package.json | 6 +-- truffle-config.js | 2 +- 10 files changed, 76 insertions(+), 79 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03993a4..3b36920 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Setup Code uses: actions/checkout@v4 - + - name: Setup Environment uses: ./.github/actions/setup @@ -33,7 +33,7 @@ jobs: steps: - name: Setup Code uses: actions/checkout@v4 - + - name: Setup Environment uses: ./.github/actions/setup @@ -51,17 +51,15 @@ jobs: steps: - name: Setup Code uses: actions/checkout@v4 - + - name: Setup Environment uses: ./.github/actions/setup - + - name: Run Coverage run: npm run coverage - + - name: Post to Codecov uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} slither: name: Slither @@ -74,7 +72,7 @@ jobs: - name: Setup Environment uses: ./.github/actions/setup - + - name: Run Slither uses: crytic/slither-action@v0.3.0 with: @@ -83,6 +81,8 @@ jobs: codespell: name: Codespell runs-on: ubuntu-latest + env: + FORCE_COLOR: 1 steps: - uses: actions/checkout@v4 - name: Run CodeSpell diff --git a/README.md b/README.md index 166a73a..fef420a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,9 @@ The following are functions and callbacks introduced by ERC-1363: ERC-1363 tokens can be used for specific utilities in all cases that require a callback to be executed after a transfer or an approval received. ERC-1363 is also useful for avoiding token loss or token locking in contracts by verifying the recipient contract's ability to handle tokens. -**NOTE: This repo contains the reference implementation of the official [ERC-1363](https://eips.ethereum.org/EIPS/eip-1363).** +::: tip NOTE +**This repo contains the reference implementation of the official [ERC-1363](https://eips.ethereum.org/EIPS/eip-1363).** +::: ## Install @@ -49,8 +51,6 @@ contract MyToken is ERC1363 { ## Code -This repo contains: - ### IERC1363 [IERC1363.sol](https://github.com/vittominacori/erc1363-payable-token/blob/master/contracts/token/ERC1363/IERC1363.sol) @@ -106,17 +106,21 @@ Implementation of the ERC-1363 interface. The reference implementation of ERC-1363 that extends ERC-20 and adds support for executing code after transfers and approvals on recipient contracts. -> **NOTE**: `transferAndCall`, `transferFromAndCall` and `approveAndCall` revert if the recipient/spender is an EOA address. To transfer tokens to an EOA or approve it to spend tokens, use the ERC-20 `transfer`, `transferFrom` or `approve` methods. +::: tip NOTE +`transferAndCall`, `transferFromAndCall` and `approveAndCall` revert if the recipient/spender is an EOA address. To transfer tokens to an EOA or approve it to spend tokens, use the ERC-20 `transfer`, `transferFrom` or `approve` methods. +::: ## Examples -**IMPORTANT**: the example contracts are for testing purpose only. When inheriting or copying from these contracts, you must include a way to use the received tokens, otherwise they will be stuck into the contract. +::: warning IMPORTANT +The example contracts are for testing purpose only. When inheriting or copying from these contracts, you must include a way to use the received tokens, otherwise they will be stuck into the contract. +::: ### ERC1363Guardian [ERC1363Guardian.sol](https://github.com/vittominacori/erc1363-payable-token/blob/master/contracts/examples/ERC1363Guardian.sol) -As example: a contract that allows to accept ERC-1363 callback after transfers or approvals. +As example: a contract that allows to accept ERC-1363 callbacks after transfers or approvals. It emits a `TokensReceived` event to notify the transfer received by the contract. @@ -132,7 +136,7 @@ It also implements a `_approvalReceived` function that can be overridden to make As example: a contract that allows to test passing methods via abi encoded function call. -It executed the method passed via `data`. Methods emit a `MethodCall` event. +It executes the method passed via `data`. Methods emit a `MethodCall` event. ## Documentation @@ -153,27 +157,19 @@ It executed the method passed via `data`. Methods emit a `MethodCall` event. npm install ``` -### Usage - -Open the console - -```bash -npm run console -``` - -#### Compile +### Compile ```bash npm run compile ``` -#### Test +### Test ```bash npm test ``` -#### Code Coverage +### Code Coverage ```bash npm run coverage diff --git a/contracts/examples/ERC1363Guardian.sol b/contracts/examples/ERC1363Guardian.sol index 571f7ef..1171179 100644 --- a/contracts/examples/ERC1363Guardian.sol +++ b/contracts/examples/ERC1363Guardian.sol @@ -7,7 +7,7 @@ import {IERC1363Spender} from "../token/ERC1363/IERC1363Spender.sol"; /** * @title ERC1363Guardian - * @dev Implementation example of a contract that allows to accept ERC-1363 callback after transfers or approvals. + * @dev Implementation example of a contract that allows to accept ERC-1363 callbacks after transfers or approvals. * * IMPORTANT: This contract is for testing purpose only. When inheriting or copying from this contract, * you must include a way to use the received tokens, otherwise they will be stuck into the contract. diff --git a/contracts/token/ERC1363/ERC1363.sol b/contracts/token/ERC1363/ERC1363.sol index 1ec300f..419197a 100644 --- a/contracts/token/ERC1363/ERC1363.sol +++ b/contracts/token/ERC1363/ERC1363.sol @@ -79,7 +79,7 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { } /** - * @dev Performs a call to `IERC1363Receiver-onTransferReceived` on a target address. + * @dev Performs a call to `IERC1363Receiver::onTransferReceived` on a target address. * This will revert if the target doesn't implement the `IERC1363Receiver` interface or * if the target doesn't accept the token transfer or * if the target address is not a contract. @@ -102,7 +102,6 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { if (reason.length == 0) { revert ERC1363InvalidReceiver(to); } else { - /// @solidity memory-safe-assembly assembly { revert(add(32, reason), mload(reason)) } @@ -111,7 +110,7 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { } /** - * @dev Performs a call to `IERC1363Spender-onApprovalReceived` on a target address. + * @dev Performs a call to `IERC1363Spender::onApprovalReceived` on a target address. * This will revert if the target doesn't implement the `IERC1363Spender` interface or * if the target doesn't accept the token approval or * if the target address is not a contract. @@ -133,7 +132,6 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { if (reason.length == 0) { revert ERC1363InvalidSpender(spender); } else { - /// @solidity memory-safe-assembly assembly { revert(add(32, reason), mload(reason)) } diff --git a/contracts/token/ERC1363/IERC1363.sol b/contracts/token/ERC1363/IERC1363.sol index 7d32661..46e93d2 100644 --- a/contracts/token/ERC1363/IERC1363.sol +++ b/contracts/token/ERC1363/IERC1363.sol @@ -14,7 +14,7 @@ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; */ interface IERC1363 is IERC20, IERC165 { /* - * Note: the ERC-165 identifier for this interface is 0xb0202a11. + * NOTE: the ERC-165 identifier for this interface is 0xb0202a11. * 0xb0202a11 === * bytes4(keccak256('transferAndCall(address,uint256)')) ^ * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^ diff --git a/dist/ERC1363.dist.sol b/dist/ERC1363.dist.sol index f79499c..52f4c45 100644 --- a/dist/ERC1363.dist.sol +++ b/dist/ERC1363.dist.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -// Sources flattened with hardhat v2.18.2 https://hardhat.org +// Sources flattened with hardhat v2.18.3 https://hardhat.org @@ -693,15 +693,14 @@ pragma solidity ^0.8.20; /** * @title IERC1363 - * @dev Interface of the ERC1363 standard as defined in the - * https://eips.ethereum.org/EIPS/eip-1363[EIP-1363]. + * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363]. * - * Defines an extension interface for ERC20 tokens that supports executing code on a recipient contract - * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction. + * An extension interface for ERC-20 tokens that supports executing code on a recipient contract after + * `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction. */ interface IERC1363 is IERC20, IERC165 { /* - * Note: the ERC-165 identifier for this interface is 0xb0202a11. + * NOTE: the ERC-165 identifier for this interface is 0xb0202a11. * 0xb0202a11 === * bytes4(keccak256('transferAndCall(address,uint256)')) ^ * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^ @@ -780,7 +779,7 @@ pragma solidity ^0.8.20; /** * @title IERC1363Errors - * @dev Interface of the ERC1363 custom errors following the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] rationale. + * @dev Interface of the ERC-1363 custom errors following the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] rationale. */ interface IERC1363Errors { /** @@ -818,11 +817,11 @@ pragma solidity ^0.8.20; /** * @title IERC1363Receiver * @dev Interface for any contract that wants to support `transferAndCall` or `transferFromAndCall` - * from ERC1363 token contracts. + * from ERC-1363 token contracts. */ interface IERC1363Receiver { /** - * @dev Whenever ERC1363 tokens are transferred to this contract via `transferAndCall` or `transferFromAndCall` + * @dev Whenever ERC-1363 tokens are transferred to this contract via `transferAndCall` or `transferFromAndCall` * by `operator` from `from`, this function is called. * * NOTE: To accept the transfer, this must return @@ -853,11 +852,11 @@ pragma solidity ^0.8.20; /** * @title ERC1363Spender * @dev Interface for any contract that wants to support `approveAndCall` - * from ERC1363 token contracts. + * from ERC-1363 token contracts. */ interface IERC1363Spender { /** - * @dev Whenever an ERC1363 tokens `owner` approved this contract via `approveAndCall` + * @dev Whenever an ERC-1363 tokens `owner` approved this contract via `approveAndCall` * to spent their tokens, this function is called. * * NOTE: To accept the approval, this must return @@ -885,11 +884,10 @@ pragma solidity ^0.8.20; /** * @title ERC1363 - * @dev Implementation of the ERC1363 interface. - * Extension of ERC20 tokens that adds support for code execution after transfers and approvals - * on recipient contracts in a single transaction. - * Calls after transfers are enabled through the `ERC1363-transferAndCall` and `ERC1363-transferFromAndCall`, - * while calls after approvals can be made with `ERC1363-approveAndCall`. + * @dev Implementation of the ERC-1363 interface. + * + * Extension of ERC-20 tokens that supports executing code on a recipient contract after `transfer` or `transferFrom`, + * or code on a spender contract after `approve`, in a single transaction. */ abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { /** @@ -953,7 +951,7 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { } /** - * @dev Performs a call to `IERC1363Receiver-onTransferReceived` on a target address. + * @dev Performs a call to `IERC1363Receiver::onTransferReceived` on a target address. * This will revert if the target doesn't implement the `IERC1363Receiver` interface or * if the target doesn't accept the token transfer or * if the target address is not a contract. @@ -976,7 +974,6 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { if (reason.length == 0) { revert ERC1363InvalidReceiver(to); } else { - /// @solidity memory-safe-assembly assembly { revert(add(32, reason), mload(reason)) } @@ -985,7 +982,7 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { } /** - * @dev Performs a call to `IERC1363Spender-onApprovalReceived` on a target address. + * @dev Performs a call to `IERC1363Spender::onApprovalReceived` on a target address. * This will revert if the target doesn't implement the `IERC1363Spender` interface or * if the target doesn't accept the token approval or * if the target address is not a contract. @@ -1007,7 +1004,6 @@ abstract contract ERC1363 is ERC20, ERC165, IERC1363, IERC1363Errors { if (reason.length == 0) { revert ERC1363InvalidSpender(spender); } else { - /// @solidity memory-safe-assembly assembly { revert(add(32, reason), mload(reason)) } diff --git a/hardhat.config.js b/hardhat.config.js index f6425ac..7ce7213 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -7,7 +7,7 @@ require('solidity-docgen'); module.exports = { defaultNetwork: 'hardhat', solidity: { - version: '0.8.21', + version: '0.8.22', settings: { evmVersion: 'shanghai', optimizer: { diff --git a/package-lock.json b/package-lock.json index 7c68d3b..ed49e26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "erc-payable-token", - "version": "5.1.0", + "version": "5.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "erc-payable-token", - "version": "5.1.0", + "version": "5.1.1", "license": "MIT", "dependencies": { "@openzeppelin/contracts": "5.0.0" @@ -16,12 +16,12 @@ "@nomiclabs/hardhat-web3": "^2.0.0", "@openzeppelin/test-helpers": "^0.5.16", "chai": "^4.3.10", - "eslint": "^8.51.0", + "eslint": "^8.52.0", "eslint-config-prettier": "^9.0.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-mocha-no-only": "^1.1.1", "graphlib": "^2.1.8", - "hardhat": "^2.18.2", + "hardhat": "^2.18.3", "hardhat-exposed": "^0.3.13", "hardhat-gas-reporter": "^1.0.9", "prettier": "^3.0.3", @@ -2227,9 +2227,9 @@ } }, "node_modules/@eslint/js": { - "version": "8.51.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.51.0.tgz", - "integrity": "sha512-HxjQ8Qn+4SI3/AFv6sOrDB+g6PpUTDwSJiQqOrnneEk8L71161srI9gjzzZvYVbzHiVg/BvcH95+cK/zfIt4pg==", + "version": "8.52.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.52.0.tgz", + "integrity": "sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -3236,12 +3236,12 @@ } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.11", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.11.tgz", - "integrity": "sha512-N2brEuAadi0CcdeMXUkhbZB84eskAc8MEX1By6qEchoVywSgXPIjou4rYsl0V3Hj0ZnuGycGCjdNgockbzeWNA==", + "version": "0.11.13", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz", + "integrity": "sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==", "dev": true, "dependencies": { - "@humanwhocodes/object-schema": "^1.2.1", + "@humanwhocodes/object-schema": "^2.0.1", "debug": "^4.1.1", "minimatch": "^3.0.5" }, @@ -3263,9 +3263,9 @@ } }, "node_modules/@humanwhocodes/object-schema": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", - "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.1.tgz", + "integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==", "dev": true }, "node_modules/@isaacs/cliui": { @@ -7961,6 +7961,12 @@ "@types/node": "*" } }, + "node_modules/@ungap/structured-clone": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", + "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", + "dev": true + }, "node_modules/@vue/babel-helper-vue-jsx-merge-props": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.4.0.tgz", @@ -15630,18 +15636,19 @@ } }, "node_modules/eslint": { - "version": "8.51.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.51.0.tgz", - "integrity": "sha512-2WuxRZBrlwnXi+/vFSJyjMqrNjtJqiasMzehF0shoLaW7DzS3/9Yvrmq5JiT66+pNjiX4UBnLDiKHcWAr/OInA==", + "version": "8.52.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.52.0.tgz", + "integrity": "sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", "@eslint/eslintrc": "^2.1.2", - "@eslint/js": "8.51.0", - "@humanwhocodes/config-array": "^0.11.11", + "@eslint/js": "8.52.0", + "@humanwhocodes/config-array": "^0.11.13", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", + "@ungap/structured-clone": "^1.2.0", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", @@ -22161,9 +22168,9 @@ } }, "node_modules/hardhat": { - "version": "2.18.2", - "resolved": "https://registry.npmjs.org/hardhat/-/hardhat-2.18.2.tgz", - "integrity": "sha512-lUVmJg7DsKcUCDpqv57CJl6vHqo/1PeHSfM3+WIa8UtRKmXyVTj1qQK01TDiuetkZBVg9Dn52qU+ZwaJQynaKA==", + "version": "2.18.3", + "resolved": "https://registry.npmjs.org/hardhat/-/hardhat-2.18.3.tgz", + "integrity": "sha512-JuYaTG+4ZHVjEHCW5Hn6jCHH3LpO75dtgznZpM/dLv12RcSlw/xHbeQh3FAsGahQr1epKryZcZEMHvztVZHe0g==", "dev": true, "dependencies": { "@ethersproject/abi": "^5.1.2", diff --git a/package.json b/package.json index 0b610c7..5260183 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "erc-payable-token", - "version": "5.1.0", + "version": "5.1.1", "description": "ERC-1363 Payable Token Implementation", "files": [ "contracts", @@ -58,12 +58,12 @@ "@nomiclabs/hardhat-web3": "^2.0.0", "@openzeppelin/test-helpers": "^0.5.16", "chai": "^4.3.10", - "eslint": "^8.51.0", + "eslint": "^8.52.0", "eslint-config-prettier": "^9.0.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-mocha-no-only": "^1.1.1", "graphlib": "^2.1.8", - "hardhat": "^2.18.2", + "hardhat": "^2.18.3", "hardhat-exposed": "^0.3.13", "hardhat-gas-reporter": "^1.0.9", "prettier": "^3.0.3", diff --git a/truffle-config.js b/truffle-config.js index 416ecb5..fe8dff7 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -1,7 +1,7 @@ module.exports = { compilers: { solc: { - version: '0.8.21', + version: '0.8.22', settings: { evmVersion: 'shanghai', optimizer: {