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

Rescuable721 #34

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
38 changes: 38 additions & 0 deletions src/contracts/utils/Rescuable721.sol
defijesus marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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;
}

/**
* @title Rescuable721
* @author defijesus.eth
* @notice abstract contract 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();
_;
}

/// @inheritdoc IRescuable721
function emergencyTokenTransfer(
address erc721Token,
address to,
uint256 tokenId
) external virtual onlyRescueGuardian {
IERC721(erc721Token).transferFrom(address(this), to, tokenId);

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

/// @inheritdoc IRescuable721
function whoCanRescue() public view virtual returns (address);
}
37 changes: 37 additions & 0 deletions src/contracts/utils/interfaces/IRescuable721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

/**
* @title IRescuable
* @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
* @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
*/
event ERC721Rescued(
address indexed caller,
address indexed token,
address indexed to,
uint256 tokenId
);

/**
* @notice method called to rescue a ERC721 token sent erroneously to the contract. Only callable by owner
* @param erc721Token address of the token to rescue
* @param to address to send the token
* @param tokenId of token to rescue
*/
function emergencyTokenTransfer(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);
}
Loading
Loading