Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Hooks _afterTokenTransfer for ERC1155 #3104

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions contracts/token/ERC1155/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
emit TransferSingle(operator, from, to, id, amount);

_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);

_afterTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
}

/**
Expand Down Expand Up @@ -221,6 +223,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
emit TransferBatch(operator, from, to, ids, amounts);

_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);

_afterTokenTransfer(operator, from, to, ids, amounts, data);
}

/**
Expand Down Expand Up @@ -273,6 +277,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
emit TransferSingle(operator, address(0), to, id, amount);

_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);

_afterTokenTransfer(operator, address(0), to, _asSingletonArray(id), _asSingletonArray(amount), data);
}

/**
Expand Down Expand Up @@ -304,6 +310,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
emit TransferBatch(operator, address(0), to, ids, amounts);

_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);

_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
}

/**
Expand Down Expand Up @@ -332,6 +340,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
}

emit TransferSingle(operator, from, address(0), id, amount);

_afterTokenTransfer(operator, from, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
}

/**
Expand Down Expand Up @@ -365,6 +375,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
}

emit TransferBatch(operator, from, address(0), ids, amounts);

_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}

/**
Expand Down Expand Up @@ -410,6 +422,35 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256[] memory amounts,
bytes memory data
) internal virtual {}

/**
* @dev Hook that is called after any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `id` and `amount` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}

function _doSafeTransferAcceptanceCheck(
address operator,
Expand Down