ERC1363Lib
Title: ERC1363Lib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC1363.sol)
Library implementing ERC-1363 transferAndCall, transferFromAndCall and approveAndCall over the
ERC20Lib balances and allowances. Adds no own storage.
Ports OpenZeppelin v5.6.1 ERC1363 and ERC1363Utils. Differences from OpenZeppelin:
- The movement runs through
ERC20Lib.transfer,ERC20Lib.transferFromandERC20Lib.approve, not the diamond'stransfer/transferFrom/approveselectors. OpenZeppelin calls the virtual functions, so an override such as ERC20Pausable or ERC20Votes applies to*AndCalltoo. Here it does not: a facet thatReplaces the base transfer selectors (ERC20Pausable, ERC20Votes, GovernedVault) never sees these movements. Decision D25 on #234 declares ERC1363 mutually exclusive with them. - The caller is
msg.sender, not_msgSender(); Lattice has no ERC-2771 context. - ERC20Lib returns true or reverts, so the three
*Failederrors are kept for parity but never fire. - The
*FailedandInvalid*errors live on IERC1363 instead of the contract andERC1363Utils.
Functions
__ERC1363_init
Registers the IERC1363 interface for ERC-165 discovery.
Must be called inside a pre/postInitializer block. No own storage to initialize.
function __ERC1363_init() internal;registerInterface
Registers support for the IERC1363 interface via ERC-165.
function registerInterface() internal;transferAndCall
Moves value tokens from the caller to to, then calls IERC1363Receiver.onTransferReceived.
function transferAndCall(address to, uint256 value, bytes memory data) internal returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| to | address | |
| value | uint256 | |
| data | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
transferFromAndCall
Moves value tokens from from to to using the caller's allowance, then calls
IERC1363Receiver.onTransferReceived.
function transferFromAndCall(address from, address to, uint256 value, bytes memory data) internal returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| value | uint256 | |
| data | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
approveAndCall
Sets value as spender's allowance over the caller's tokens, then calls
IERC1363Spender.onApprovalReceived.
function approveAndCall(address spender, uint256 value, bytes memory data) internal returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| spender | address | |
| value | uint256 | |
| data | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
checkOnERC1363TransferReceived
Calls IERC1363Receiver.onTransferReceived on to and requires it to accept.
Reverts IERC1363.ERC1363InvalidReceiver when to has no code, returns another value, or reverts with
no data. A revert with data is bubbled up unchanged.
function checkOnERC1363TransferReceived(
address operator,
address from,
address to,
uint256 value,
bytes memory data
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| operator | address | |
| from | address | |
| to | address | |
| value | uint256 | |
| data | bytes |
checkOnERC1363ApprovalReceived
Calls IERC1363Spender.onApprovalReceived on spender and requires it to accept.
Reverts IERC1363.ERC1363InvalidSpender when spender has no code, returns another value, or reverts
with no data. A revert with data is bubbled up unchanged.
function checkOnERC1363ApprovalReceived(address operator, address spender, uint256 value, bytes memory data)
internal;Parameters
| Name | Type | Description |
|---|---|---|
| operator | address | |
| spender | address | |
| value | uint256 | |
| data | bytes |