Skip to content

Commit

Permalink
feat: add keepers for newbieVilla
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert committed Oct 11, 2023
1 parent 90ffcd8 commit 7ba12a1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions contracts/misc/NewbieVilla.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ contract NewbieVilla is Initializable, AccessControlEnumerable, IERC721Receiver,
mapping(uint256 => uint256) internal _balances;
address internal _tips; // tips contract

mapping(uint256 characterId => address keeper) private _keepers;

// events
/**
* @dev Emitted when the web3Entry character nft is withdrawn.
Expand Down Expand Up @@ -192,8 +194,11 @@ contract NewbieVilla is Initializable, AccessControlEnumerable, IERC721Receiver,
bytes32 signedData = ECDSA.toEthSignedMessageHash(
keccak256(abi.encodePacked(address(this), characterId, nonce, expires))
);

address signer = ECDSA.recover(signedData, proof);
address keeper = _keepers[characterId];
require(
hasRole(ADMIN_ROLE, ECDSA.recover(signedData, proof)),
(keeper == signer) || (keeper == address(0) && hasRole(ADMIN_ROLE, signer)),
"NewbieVilla: unauthorized withdraw"
);

Expand Down Expand Up @@ -230,9 +235,11 @@ contract NewbieVilla is Initializable, AccessControlEnumerable, IERC721Receiver,
) external override returns (bytes4) {
// Only character nft could be received, other nft, e.g. mint nft would be reverted
require(msg.sender == web3Entry, "NewbieVilla: receive unknown token");
// Only admin role could send character to this contract
require(hasRole(ADMIN_ROLE, operator), "NewbieVilla: receive unknown character");

// set keeper for tokenId
_keepers[tokenId] = operator;

// grant operator permissions
if (data.length == 0) {
IWeb3Entry(web3Entry).grantOperatorPermissions(
tokenId,
Expand Down Expand Up @@ -295,6 +302,15 @@ contract NewbieVilla is Initializable, AccessControlEnumerable, IERC721Receiver,
return _balances[characterId];
}

/**
* @notice Returns the address of keeper by `characterId`.
* @param characterId The character ID to query.
* @return address The address of the keeper.
*/
function getKeeper(uint256 characterId) external view returns (address) {
return _keepers[characterId];
}

/**
* @notice Returns the address of mira token contract.
* @return The address of mira token contract.
Expand Down

0 comments on commit 7ba12a1

Please sign in to comment.