diff --git a/EIPS/eip-6551.md b/EIPS/eip-6551.md index b2b1bc657ec5c3..71cf4cfaa2e37b 100644 --- a/EIPS/eip-6551.md +++ b/EIPS/eip-6551.md @@ -156,6 +156,34 @@ interface IERC6551Account { */ receive() external payable; + /** + * @dev initialize function is used to initialize the tken bound account + * after any ownership change + * + * The function can only be called by current owner of token + * + * The function is used to tract current and previous owner of the NFT + * which is used during circular locks and to prevent previous owner to call + * the functions of the contract + * + * @return the status of the call in boolean format + */ + function initialize() external returns (bool); + + /** + * @dev the function is used to transfer token during the situations + * of circular lock + * + * The function first checks the circular lock condition i.e. when + * address(this) equals to the address returned by owner() function + * + * The function checks if the call is created by previous owner or not + * and transfer ownership of token to the previous owner + * + * @return the status of the call in boolean format + */ + function unlockCircularLock() external returns (bool); + /** * @dev Returns the identifier of the non-fungible token which owns the account * @@ -324,6 +352,43 @@ contract ExampleERC6551Account is IERC165, IERC1271, IERC6551Account, IERC6551Ex receive() external payable {} + address public _prevOwner; + address public _currOwner; + + function initialize() external returns (bool) { + require( + owner() == msg.sender, + "only new owner could call this function" + ); + if (_prevOwner == address(0)) { + _prevOwner = _currOwner = msg.sender; + } else { + _prevOwner = _currOwner; + _currOwner = msg.sender; + } + + return true; + } + + function unlockCircularLock() external returns (bool) { + require( + owner() == address(this), + "circular lock condition is not present" + ); + require( + msg.sender == _prevOwner, + "could only be called by previous owner" + ); + (, address _tokenAddr, uint256 _tokenId) = token(); + IERC721(_tokenAddr).safeTransferFrom( + address(this), + _prevOwner, + _tokenId + ); + + return true; + } + function execute( address to, uint256 value,