Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Jul 20, 2024
1 parent a946d99 commit 67f4c6a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions contracts/token/OnTokenTransferAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ pragma solidity ^0.8.20;

import "@openzeppelin/contracts/interfaces/IERC1363Receiver.sol";

/**
* @dev This contract exposes the 667 `onTokenTransfer` hook on top of {ERC-1363-onTransferReceived}.
*
* Inheriting from this adapter makes every `ERC1363Receiver` contract automatically compatible with tokens, such as
* Chainlink's Link, that implement the 667 interface for transferAndCall.
*/
abstract contract OnTokenTransferAdapter is IERC1363Receiver {
function onTokenTransfer(address from, uint256 amount, bytes calldata data) public virtual returns (bool) {
// Rewrite call as IERC1363.onTransferReceived
// This uses delegate call to keep the correct sender (token contracts)
//
// TODO: use operator = 0 or operator = from ?
// Note that since 667 doesn't implement `transferFromAndCall`, this hook was called by a simple
// `transferAndCall` and thus the operator is necessarily the `from` address.
(bool success, bytes memory returndata) = address(this).delegatecall(
abi.encodeCall(IERC1363Receiver.onTransferReceived, (address(0), from, amount, data))
abi.encodeCall(IERC1363Receiver.onTransferReceived, (from, from, amount, data))
);
// check success and return as boolean
return
Expand Down

0 comments on commit 67f4c6a

Please sign in to comment.