Skip to content

Commit

Permalink
feat: use v5 (#11)
Browse files Browse the repository at this point in the history
* Update OpenZeppelin reference to 5.0.0
* Use custom errors in ERC1363
* Bumb minimum compiler version to 0.8.20
* Add `ERC1363Holder`
* Improve documentation
* Add slither and codespell
  • Loading branch information
vittominacori authored Oct 9, 2023
1 parent e27038f commit cbd7613
Show file tree
Hide file tree
Showing 42 changed files with 3,122 additions and 2,015 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,31 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

slither:
name: Slither
runs-on: ubuntu-latest
env:
FORCE_COLOR: 1
steps:
- name: Setup Code
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup

- name: Run Slither
uses: crytic/[email protected]
with:
node-version: 18

codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run CodeSpell
uses: codespell-project/[email protected]
with:
check_hidden: true
check_filenames: true
skip: package-lock.json
48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

ERC-1363 allows to implement an ERC-20 smart token.

It means that we can add a callback after transferring or approving tokens to be executed.
It means that we can add a callback to be executed after transferring or approving tokens.

This is an implementation of the [EIP-1363](https://eips.ethereum.org/EIPS/eip-1363) that defines a token interface for EIP-20 tokens that supports executing recipient contract code after `transfer` or `transferFrom`, or spender contract code after `approve` in a single transaction.
This is an implementation of the [EIP-1363](https://eips.ethereum.org/EIPS/eip-1363) that defines an 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.

## Abstract
There is no way to execute any code on a receiver or spender contract after an EIP-20 `transfer`, `transferFrom` or `approve` so, to make an action, it is required to send another transaction.
There is no way to execute any code on a receiver or spender contract after an ERC-20 `transfer`, `transferFrom` or `approve` so, to make an action, it is required to send another transaction.

This introduces complexity on UI development and friction on adoption because users must wait for the first transaction to be executed and then send the second one. They must also pay GAS twice.
This introduces complexity on UI development and friction on adoption because users must wait for the first transaction to be executed, and then send the second one. They must also pay GAS twice.

This proposal aims to make tokens capable of performing actions more easily and working without the use of any other listener.
This proposal aims to make tokens capable of performing actions more easily and working with contracts without the use of any other external listener.
It allows to make a callback on a receiver or spender contract, after a transfer or an approval, in a single transaction.

There are many proposed uses of Ethereum smart contracts that can accept EIP-20 callbacks.
Expand All @@ -41,7 +41,7 @@ npm install erc-payable-token
## Usage

```solidity
pragma solidity ^0.8.0;
pragma solidity ^0.8.20;
import {ERC1363} from "erc-payable-token/contracts/token/ERC1363/ERC1363.sol";
Expand All @@ -63,24 +63,30 @@ This repo contains:

[IERC1363.sol](https://github.com/vittominacori/erc1363-payable-token/blob/master/contracts/token/ERC1363/IERC1363.sol)

Interface of an ERC1363 compliant contract, as defined in the [EIP-1363](https://eips.ethereum.org/EIPS/eip-1363).
Interface of the ERC1363 standard as defined in the [EIP-1363](https://eips.ethereum.org/EIPS/eip-1363).

```solidity
interface IERC1363 is IERC20, IERC165 {
function transferAndCall(address to, uint256 amount) external returns (bool);
function transferAndCall(address to, uint256 amount, bytes calldata data) external returns (bool);
function transferFromAndCall(address from, address to, uint256 amount) external returns (bool);
function transferFromAndCall(address from, address to, uint256 amount, bytes calldata data) external returns (bool);
function approveAndCall(address spender, uint256 amount) external returns (bool);
function approveAndCall(address spender, uint256 amount, bytes calldata data) external returns (bool);
function transferAndCall(address to, uint256 value) external returns (bool);
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
function approveAndCall(address spender, uint256 value) external returns (bool);
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
```

### IERC1363Errors

[IERC1363Errors.sol](https://github.com/vittominacori/erc1363-payable-token/blob/master/contracts/token/ERC1363/IERC1363Errors.sol)

Interface of the ERC1363 custom errors following the [ERC-6093](https://eips.ethereum.org/EIPS/eip-6093) rationale.

### ERC1363

[ERC1363.sol](https://github.com/vittominacori/erc1363-payable-token/blob/master/contracts/token/ERC1363/ERC1363.sol)

Implementation of an IERC1363 interface.
Implementation of the ERC1363 interface.

### IERC1363Receiver

Expand All @@ -106,6 +112,14 @@ interface IERC1363Spender {
}
```

### ERC1363Holder

[ERC1363Holder.sol](https://github.com/vittominacori/erc1363-payable-token/blob/master/contracts/token/ERC1363/utils/ERC1363Holder.sol)

Implementation of `IERC1363Receiver` and `IERC1363Spender` that will allow a contract to receive ERC1363 token transfers or approval.

IMPORTANT: When inheriting this contract, you must include a way to use the received tokens or spend the allowance, otherwise they will be stuck.

### ERC1363Payable

[ERC1363Payable.sol](https://github.com/vittominacori/erc1363-payable-token/blob/master/contracts/payment/ERC1363Payable.sol)
Expand All @@ -114,11 +128,11 @@ Implementation proposal of a contract that wants to accept ERC1363 payments. It

It emits a `TokensReceived` event to notify the transfer received by the contract.

It also implements a `transferReceived` function that can be overridden to make your stuffs within your contract after a `onTransferReceived`.
It also implements a `_transferReceived` function that can be overridden to make your stuff within your contract after a `onTransferReceived`.

It emits a `TokensApproved` event to notify the approval received by the contract.

It also implements a `approvalReceived` function that can be overridden to make your stuffs within your contract after a `onApprovalReceived`.
It also implements a `_approvalReceived` function that can be overridden to make your stuff within your contract after a `onApprovalReceived`.

### ERC1363PayableCrowdsale

Expand Down Expand Up @@ -146,7 +160,7 @@ As example: a contract allowing to test passing methods via abi encoded function
npm install
```

### Usage (using Hardhat)
### Usage

Open the console

Expand Down
Binary file modified analysis/control-flow/ERC1363.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 13 additions & 7 deletions analysis/description-table/ERC1363.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

| File Name | SHA-1 Hash |
|-------------|--------------|
| flat/ERC1363.flat.sol | 4001df32418c3f18a82e126acea48c0aa70fe2b6 |
| dist/ERC1363.dist.sol | 8f3b06895133e071cf1dac6aca85e6dc51ae19b8 |


### Contracts Description Table
Expand All @@ -15,6 +15,12 @@
|:----------:|:-------------------:|:----------------:|:----------------:|:---------------:|
|| **Function Name** | **Visibility** | **Mutability** | **Modifiers** |
||||||
| **IERC20Errors** | Interface | |||
||||||
| **IERC721Errors** | Interface | |||
||||||
| **IERC1155Errors** | Interface | |||
||||||
| **IERC20** | Interface | |||
|| totalSupply | External ❗️ | |NO❗️ |
|| balanceOf | External ❗️ | |NO❗️ |
Expand All @@ -32,7 +38,7 @@
|| _msgSender | Internal 🔒 | | |
|| _msgData | Internal 🔒 | | |
||||||
| **ERC20** | Implementation | Context, IERC20, IERC20Metadata |||
| **ERC20** | Implementation | Context, IERC20, IERC20Metadata, IERC20Errors |||
|| <Constructor> | Public ❗️ | 🛑 |NO❗️ |
|| name | Public ❗️ | |NO❗️ |
|| symbol | Public ❗️ | |NO❗️ |
Expand All @@ -43,15 +49,13 @@
|| allowance | Public ❗️ | |NO❗️ |
|| approve | Public ❗️ | 🛑 |NO❗️ |
|| transferFrom | Public ❗️ | 🛑 |NO❗️ |
|| increaseAllowance | Public ❗️ | 🛑 |NO❗️ |
|| decreaseAllowance | Public ❗️ | 🛑 |NO❗️ |
|| _transfer | Internal 🔒 | 🛑 | |
|| _update | Internal 🔒 | 🛑 | |
|| _mint | Internal 🔒 | 🛑 | |
|| _burn | Internal 🔒 | 🛑 | |
|| _approve | Internal 🔒 | 🛑 | |
|| _approve | Internal 🔒 | 🛑 | |
|| _spendAllowance | Internal 🔒 | 🛑 | |
|| _beforeTokenTransfer | Internal 🔒 | 🛑 | |
|| _afterTokenTransfer | Internal 🔒 | 🛑 | |
||||||
| **IERC165** | Interface | |||
|| supportsInterface | External ❗️ | |NO❗️ |
Expand All @@ -67,13 +71,15 @@
|| approveAndCall | External ❗️ | 🛑 |NO❗️ |
|| approveAndCall | External ❗️ | 🛑 |NO❗️ |
||||||
| **IERC1363Errors** | Interface | |||
||||||
| **IERC1363Receiver** | Interface | |||
|| onTransferReceived | External ❗️ | 🛑 |NO❗️ |
||||||
| **IERC1363Spender** | Interface | |||
|| onApprovalReceived | External ❗️ | 🛑 |NO❗️ |
||||||
| **ERC1363** | Implementation | ERC20, IERC1363, ERC165 |||
| **ERC1363** | Implementation | ERC20, ERC165, IERC1363, IERC1363Errors |||
|| supportsInterface | Public ❗️ | |NO❗️ |
|| transferAndCall | Public ❗️ | 🛑 |NO❗️ |
|| transferAndCall | Public ❗️ | 🛑 |NO❗️ |
Expand Down
Binary file modified analysis/inheritance-tree/ERC1363.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit cbd7613

Please sign in to comment.