Skip to content

Commit

Permalink
gave the dao ability to set whitelisting
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaniza committed Sep 17, 2024
1 parent 3dd41ea commit f6a73f3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
23 changes: 12 additions & 11 deletions src/escrow/increasing/Lock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,21 @@ contract Lock is ILock, ERC721Enumerable, UUPSUpgradeable, DaoAuthorizable {
}

/*//////////////////////////////////////////////////////////////
WhiteList
Transfers
//////////////////////////////////////////////////////////////*/

/// @notice Transfers disabled by default, only whitelisted addresses can receive transfers
function setWhitelisted(address _account, bool _isWhitelisted) external onlyEscrow {
function setWhitelisted(address _account, bool _isWhitelisted) external auth(LOCK_ADMIN_ROLE) {
whitelisted[_account] = _isWhitelisted;
emit WhitelistSet(_account, _isWhitelisted);
}

function enableTransfers() external onlyEscrow {
/// @notice Enable transfers to any address without whitelisting
function enableTransfers() external auth(LOCK_ADMIN_ROLE) {
whitelisted[WHITELIST_ANY_ADDRESS] = true;
emit WhitelistSet(WHITELIST_ANY_ADDRESS, true);
}

/*//////////////////////////////////////////////////////////////
NFT Functions
//////////////////////////////////////////////////////////////*/

function isApprovedOrOwner(address _spender, uint256 _tokenId) external view returns (bool) {
return _isApprovedOrOwner(_spender, _tokenId);
}

/// @dev Override the transfer to check if the recipient is whitelisted
/// This avoids needing to check for mint/burn but is less idomatic than beforeTokenTransfer
function _transfer(address _from, address _to, uint256 _tokenId) internal override {
Expand All @@ -95,6 +88,14 @@ contract Lock is ILock, ERC721Enumerable, UUPSUpgradeable, DaoAuthorizable {
} else revert NotWhitelisted();
}

/*//////////////////////////////////////////////////////////////
NFT Functions
//////////////////////////////////////////////////////////////*/

function isApprovedOrOwner(address _spender, uint256 _tokenId) external view returns (bool) {
return _isApprovedOrOwner(_spender, _tokenId);
}

/// @notice Minting and burning functions that can only be called by the escrow contract
function mint(address _to, uint256 _tokenId) external onlyEscrow {
_mint(_to, _tokenId);
Expand Down
26 changes: 12 additions & 14 deletions test/escrow/escrow/EscrowAdmin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,25 @@ contract TestEscrowAdmin is EscrowBase {
vm.expectEmit(true, false, false, true);
emit WhitelistSet(addr, true);

vm.startPrank(address(escrow));
{
nftLock.setWhitelisted(addr, true);
assertTrue(nftLock.whitelisted(addr));
nftLock.setWhitelisted(addr, true);
assertTrue(nftLock.whitelisted(addr));

nftLock.setWhitelisted(addr, false);
assertFalse(nftLock.whitelisted(addr));
nftLock.setWhitelisted(addr, false);
assertFalse(nftLock.whitelisted(addr));

nftLock.enableTransfers();
assertTrue(
nftLock.whitelisted(address(uint160(uint256(keccak256("WHITELIST_ANY_ADDRESS")))))
);
}
vm.stopPrank();
nftLock.enableTransfers();
assertTrue(
nftLock.whitelisted(address(uint160(uint256(keccak256("WHITELIST_ANY_ADDRESS")))))
);

bytes memory err = _authErr(attacker, address(nftLock), nftLock.LOCK_ADMIN_ROLE());

vm.startPrank(attacker);
{
vm.expectRevert(OnlyEscrow.selector);
vm.expectRevert(err);
nftLock.setWhitelisted(addr, true);

vm.expectRevert(OnlyEscrow.selector);
vm.expectRevert(err);
nftLock.enableTransfers();
}
vm.stopPrank();
Expand Down
6 changes: 0 additions & 6 deletions test/escrow/escrow/EscrowCreateLock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,13 @@ contract TestCreateLock is EscrowBase, IEscrowCurveUserStorage {
vm.assume(_value > 0);
vm.warp(1);

vm.prank(address(escrow));
nftLock.setWhitelisted(_who, true);

token.mint(address(this), _value);
token.approve(address(escrow), _value);

vm.expectEmit(true, true, true, true);
emit Deposit(_who, 1, 1 weeks, _value, _value);
escrow.createLockFor(_value, _who);
}
// Creating a lock:
// Creating a lock for someone:
// - Test we can make a lock for someone else
}

contract Mock {}
1 change: 0 additions & 1 deletion test/escrow/escrow/EscrowTransfers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ contract TestEscrowTransfers is EscrowBase, IEscrowCurveUserStorage {
}

function testCanTransferIfWhitelisted() public {
vm.prank(address(escrow));
nftLock.setWhitelisted(address(123), true);

assertEq(nftLock.balanceOf(address(123)), 0);
Expand Down

0 comments on commit f6a73f3

Please sign in to comment.