Skip to content
Lattice

ERC1363Lib

Git Source

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.transferFrom and ERC20Lib.approve, not the diamond's transfer/transferFrom/approve selectors. OpenZeppelin calls the virtual functions, so an override such as ERC20Pausable or ERC20Votes applies to *AndCall too. Here it does not: a facet that Replaces 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 *Failed errors are kept for parity but never fire.
  • The *Failed and Invalid* errors live on IERC1363 instead of the contract and ERC1363Utils.

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

NameTypeDescription
toaddress
valueuint256
databytes

Returns

NameTypeDescription
<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

NameTypeDescription
fromaddress
toaddress
valueuint256
databytes

Returns

NameTypeDescription
<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

NameTypeDescription
spenderaddress
valueuint256
databytes

Returns

NameTypeDescription
<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

NameTypeDescription
operatoraddress
fromaddress
toaddress
valueuint256
databytes

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

NameTypeDescription
operatoraddress
spenderaddress
valueuint256
databytes