Skip to content

Commit

Permalink
ON-533: add deposit func
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Mar 19, 2024
1 parent b645f21 commit 2aa0489
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
26 changes: 15 additions & 11 deletions contracts/RolesRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,11 @@ contract RolesRegistryCustodial is IRolesRegistryCustodial {
// Just an example of transfer logic when granting roles
// that would be a separated helper function
address _tokenOwner = tokenOwners[_roleAssignment.tokenAddress][_roleAssignment.tokenId];
if (_tokenOwner != address(0)) {
require(_tokenOwner == _roleAssignment.grantor, 'RolesRegistry: grantor must be token owner');
} else {
IERC721(_roleAssignment.tokenAddress).transferFrom(
_roleAssignment.grantor,
address(this),
_roleAssignment.tokenId
);
tokenOwners[_roleAssignment.tokenAddress][_roleAssignment.tokenId] = _roleAssignment.grantor;
emit Deposit(_roleAssignment.grantor, _roleAssignment.tokenAddress, _roleAssignment.tokenId);
}
// Not necessary to check, just for verbosity
require(address(0) != _tokenOwner, 'RolesRegistry: token must be deposited');
// An alternative would be depositing the token if it's not deposited while granting the role
// Just left that way for simplicity
require(_tokenOwner == _roleAssignment.grantor, 'RolesRegistry: grantor must be token owner');
}

function revokeRole(
Expand Down Expand Up @@ -151,6 +145,16 @@ contract RolesRegistryCustodial is IRolesRegistryCustodial {
emit RoleRevoked(_role, _tokenAddress, _tokenId, _revoker, _grantee);
}

function deposit(
address _tokenAddress,
uint256 _tokenId
) external onlyOwnerOrApproved(_tokenAddress, _tokenId, msg.sender) {
address _tokenOwner = IERC721(_tokenAddress).ownerOf(_tokenId);
IERC721(_tokenAddress).transferFrom(_tokenOwner, address(this), _tokenId);
tokenOwners[_tokenAddress][_tokenId] = _tokenOwner;
emit Deposit(_tokenOwner, _tokenAddress, _tokenId);
}

function withdraw(
address _tokenAddress,
uint256 _tokenId
Expand Down
4 changes: 4 additions & 0 deletions contracts/interfaces/IRolesRegistryCustodial.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ interface IRolesRegistryCustodial is IERC7432 {
uint256 indexed _tokenId
);

/// @notice Deposits an NFT into the contract.
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
function deposit(address _tokenAddress, uint256 _tokenId) external;

/// @notice Withdraws an NFT from the contract.
/// @param _tokenAddress The token address.
Expand Down

0 comments on commit 2aa0489

Please sign in to comment.