diff --git a/src/ERC721ACH.sol b/src/ERC721ACH.sol index 73edbe8..11fd29c 100644 --- a/src/ERC721ACH.sol +++ b/src/ERC721ACH.sol @@ -86,16 +86,8 @@ contract ERC721ACH is IERC721ACH, ERC721AC { IAfterTokenTransfersHook hook = IAfterTokenTransfersHook( hooks[HookType.AfterTokenTransfers] ); - if ( - address(hook) != address(0) && - hook.useAfterTokenTransfersHook(from, to, startTokenId, quantity) - ) { - hook.afterTokenTransfersOverrideHook( - from, - to, - startTokenId, - quantity - ); + if (address(hook) != address(0)) { + hook.afterTokenTransfersHook(from, to, startTokenId, quantity); } } diff --git a/src/interfaces/IAfterTokenTransfersHook.sol b/src/interfaces/IAfterTokenTransfersHook.sol index 8b7bf0d..ec42590 100644 --- a/src/interfaces/IAfterTokenTransfersHook.sol +++ b/src/interfaces/IAfterTokenTransfersHook.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.15; /// @title IAfterTokenTransfersHook /// @dev Interface that defines hooks to be executed After token transfers. interface IAfterTokenTransfersHook { - /** @notice Emitted when the after token transfers hook is used. @param from Address from which the tokens are being transferred. @@ -20,22 +19,6 @@ interface IAfterTokenTransfersHook { uint256 quantity ); - /** - @notice Checks if the token transfers function should use the custom hook. - @param from Address from which the tokens are being transferred. - @param to Address to which the tokens are being transferred. - @param startTokenId The starting ID of the tokens being transferred. - @param quantity The number of tokens being transferred. - @return A boolean indicating whether or not to use the custom hook for the token transfers function. - - */ - function useAfterTokenTransfersHook( - address from, - address to, - uint256 startTokenId, - uint256 quantity - ) external view returns (bool); - /** @notice Provides a custom implementation for the token transfers process. @param from Address from which the tokens are being transferred. @@ -44,7 +27,7 @@ interface IAfterTokenTransfersHook { @param quantity The number of tokens being transferred. */ - function afterTokenTransfersOverrideHook( + function afterTokenTransfersHook( address from, address to, uint256 startTokenId, diff --git a/test/hooks/AfterTokenTransfers.t.sol b/test/hooks/AfterTokenTransfers.t.sol index c0bbe10..22632ff 100644 --- a/test/hooks/AfterTokenTransfers.t.sol +++ b/test/hooks/AfterTokenTransfers.t.sol @@ -9,7 +9,6 @@ import {AfterTokenTransfersHookMock} from "../utils/hooks/AfterTokenTransfersHoo import {IERC721ACH} from "../../src/interfaces/IERC721ACH.sol"; - contract AfterTokenTransfersHookTest is DSTest { Vm public constant vm = Vm(HEVM_ADDRESS); address public constant DEFAULT_OWNER_ADDRESS = address(0xC0FFEE); @@ -17,8 +16,8 @@ contract AfterTokenTransfersHookTest is DSTest { ERC721ACHMock erc721Mock; AfterTokenTransfersHookMock hookMock; - IERC721ACH.HookType constant AfterTokenTransfers = IERC721ACH.HookType.AfterTokenTransfers; - + IERC721ACH.HookType constant AfterTokenTransfers = + IERC721ACH.HookType.AfterTokenTransfers; function setUp() public { erc721Mock = new ERC721ACHMock(DEFAULT_OWNER_ADDRESS); @@ -32,17 +31,20 @@ contract AfterTokenTransfersHookTest is DSTest { function test_setAfterTokenTransfersHook() public { assertEq(address(0), address(erc721Mock.getHook(AfterTokenTransfers))); - // calling an admin function without being the contract owner should revert + // calling an admin function without being the contract owner should revert vm.expectRevert(); erc721Mock.setHook(AfterTokenTransfers, address(hookMock)); - + vm.prank(DEFAULT_OWNER_ADDRESS); erc721Mock.setHook(AfterTokenTransfers, address(hookMock)); - assertEq(address(hookMock), address(erc721Mock.getHook(AfterTokenTransfers))); + assertEq( + address(hookMock), + address(erc721Mock.getHook(AfterTokenTransfers)) + ); } - function test_afterTokenTransfersHook( + function test_afterTokenTransfersHook( uint256 startTokenId, uint256 quantity ) public { @@ -50,13 +52,10 @@ contract AfterTokenTransfersHookTest is DSTest { vm.assume(startTokenId > 0); vm.assume(quantity < 10_000); vm.assume(quantity >= startTokenId); - // Mint some tokens first - test_setAfterTokenTransfersHook(); erc721Mock.mint(DEFAULT_BUYER_ADDRESS, quantity); - vm.prank(DEFAULT_BUYER_ADDRESS); erc721Mock.transferFrom( DEFAULT_BUYER_ADDRESS, @@ -67,9 +66,13 @@ contract AfterTokenTransfersHookTest is DSTest { assertEq(DEFAULT_OWNER_ADDRESS, erc721Mock.ownerOf(startTokenId)); // Verify hook override + test_setAfterTokenTransfersHook(); + hookMock.setHooksEnabled(true); vm.expectRevert( - AfterTokenTransfersHookMock.AfterTokenTransfersHook_Executed.selector + AfterTokenTransfersHookMock + .AfterTokenTransfersHook_Executed + .selector ); vm.prank(DEFAULT_OWNER_ADDRESS); erc721Mock.transferFrom( @@ -77,11 +80,5 @@ contract AfterTokenTransfersHookTest is DSTest { DEFAULT_BUYER_ADDRESS, startTokenId ); - - } - - - - } diff --git a/test/utils/hooks/AfterTokenTransfersHookMock.sol b/test/utils/hooks/AfterTokenTransfersHookMock.sol index 6f6b66b..993822d 100644 --- a/test/utils/hooks/AfterTokenTransfersHookMock.sol +++ b/test/utils/hooks/AfterTokenTransfersHookMock.sol @@ -13,26 +13,14 @@ contract AfterTokenTransfersHookMock is IAfterTokenTransfersHook { function setHooksEnabled(bool _enabled) public { hooksEnabled = _enabled; } - - /// @notice Check if the AfterTokenTransfers function should use hook. - /// @dev Returns whether or not to use the hook for AfterTokenTransfers function - function useAfterTokenTransfersHook( - address, - address, - uint256, - uint256 - ) external view override returns (bool) { - return hooksEnabled; - } - /// @notice custom implementation for AfterTokenTransfers Hook. - function afterTokenTransfersOverrideHook( + function afterTokenTransfersHook( address, address, uint256, uint256 - ) external pure override { + ) external pure override { revert AfterTokenTransfersHook_Executed(); } }