Skip to content
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
65 changes: 65 additions & 0 deletions EIPS/eip-6551.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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,
Expand Down