Skip to content

Commit

Permalink
ready for review
Browse files Browse the repository at this point in the history
  • Loading branch information
defijesus.eth committed Jul 5, 2024
1 parent d2f0827 commit 300fe01
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
24 changes: 5 additions & 19 deletions src/contracts/utils/Rescuable721.sol
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

import {IRescuable721} from './interfaces/IRescuable721.sol';

interface IERC721 {
function transferFrom(address from, address to, uint256 tokenId) external;
}
import {IRescuable721, IERC721} from './interfaces/IRescuable721.sol';
import {Rescuable} from './Rescuable.sol';

/**
* @title Rescuable721
* @author defijesus.eth
* @notice abstract contract with the methods to rescue ERC721 tokens from a contract
* @notice abstract contract that extend Rescuable with the methods to rescue ERC721 tokens from a contract
*/
abstract contract Rescuable721 is IRescuable721 {

error ONLY_RESCUE_GUARDIAN();

/// @notice modifier that checks that caller is allowed address
modifier onlyRescueGuardian() {
if(msg.sender != whoCanRescue()) revert ONLY_RESCUE_GUARDIAN();
_;
}
abstract contract Rescuable721 is Rescuable, IRescuable721 {

/// @inheritdoc IRescuable721
function emergencyTokenTransfer(
function rescue721(
address erc721Token,
address to,
uint256 tokenId
Expand All @@ -32,7 +21,4 @@ abstract contract Rescuable721 is IRescuable721 {

emit ERC721Rescued(msg.sender, erc721Token, to, tokenId);
}

/// @inheritdoc IRescuable721
function whoCanRescue() public view virtual returns (address);
}
16 changes: 7 additions & 9 deletions src/contracts/utils/interfaces/IRescuable721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
pragma solidity ^0.8.8;

/**
* @title IRescuable
* @title IRescuable721
* @author defijesus.eth
* @notice interface containing the objects, events and methods definitions of the Rescuable721 contract
*/
interface IRescuable721 {
/**
* @notice emitted when erc20 tokens get rescued
* @notice emitted when erc721 tokens get rescued
* @param caller address that triggers the rescue
* @param token address of the rescued token
* @param to address that will receive the rescued tokens
* @param tokenId quantity of tokens rescued
* @param tokenId the id of the token rescued
*/
event ERC721Rescued(
address indexed caller,
Expand All @@ -27,11 +27,9 @@ interface IRescuable721 {
* @param to address to send the token
* @param tokenId of token to rescue
*/
function emergencyTokenTransfer(address erc721Token, address to, uint256 tokenId) external;
function rescue721(address erc721Token, address to, uint256 tokenId) external;
}

/**
* @notice method that defines the address that is allowed to rescue tokens
* @return the allowed address
*/
function whoCanRescue() external view returns (address);
interface IERC721 {
function transferFrom(address from, address to, uint256 tokenId) external;
}
4 changes: 2 additions & 2 deletions test/Rescuable721.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract Rescue721Test is Test {
hoax(ALLOWED);
vm.expectEmit(true, true, false, true);
emit ERC721Rescued(ALLOWED, address(testToken), recipient, 1);
tokensReceiver.emergencyTokenTransfer(address(testToken), recipient, 1);
tokensReceiver.rescue721(address(testToken), recipient, 1);

assertEq(testToken.balanceOf(address(tokensReceiver)), 0);
assertEq(testToken.balanceOf(address(recipient)), 1);
Expand All @@ -65,6 +65,6 @@ contract Rescue721Test is Test {
address recipient = address(1230123519);

vm.expectRevert();
tokensReceiver.emergencyTokenTransfer(address(testToken), recipient, 1);
tokensReceiver.rescue721(address(testToken), recipient, 1);
}
}

0 comments on commit 300fe01

Please sign in to comment.