Skip to content

Commit

Permalink
Merge pull request #113 from OpenQDev/fix-review-token-whitelist
Browse files Browse the repository at this point in the history
Fix review - removes TOKEN_ADDRESS_LIMIT logic in favor of a simple token whitelist
  • Loading branch information
FlacoJones authored Feb 28, 2023
2 parents c14e922 + b32f0b2 commit 26c11e0
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 84 deletions.
22 changes: 1 addition & 21 deletions contracts/DepositManager/Implementations/DepositManagerV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ contract DepositManagerV1 is DepositManagerStorageV1 {
) external payable onlyProxy {
IBounty bounty = IBounty(payable(_bountyAddress));

if (!isWhitelisted(_tokenAddress)) {
require(
!tokenAddressLimitReached(_bountyAddress),
Errors.TOO_MANY_TOKEN_ADDRESSES
);
}
require(isWhitelisted(_tokenAddress), Errors.TOKEN_NOT_ACCEPTED);

require(bountyIsOpen(_bountyAddress), Errors.CONTRACT_ALREADY_CLOSED);

Expand Down Expand Up @@ -202,21 +197,6 @@ contract DepositManagerV1 is DepositManagerStorageV1 {
return openQTokenWhitelist.isWhitelisted(_tokenAddress);
}

/// @notice Returns true if the total number of unique tokens deposited on then bounty is greater than the OpenQWhitelist TOKEN_ADDRESS_LIMIT
/// @param _bountyAddress Address of bounty
/// @return True if the token address limit has been reached
function tokenAddressLimitReached(address _bountyAddress)
public
view
returns (bool)
{
IBounty bounty = IBounty(payable(_bountyAddress));

return
bounty.getTokenAddressesCount() >=
openQTokenWhitelist.TOKEN_ADDRESS_LIMIT();
}

/// @notice Checks if bounty associated with _bountyId is open
/// @param _bountyAddress Address of bounty
/// @return bool True if _bountyId is associated with an open bounty
Expand Down
5 changes: 1 addition & 4 deletions contracts/TokenWhitelist/OpenQTokenWhitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ import './TokenWhitelist.sol';
/// @dev Whitelisting and token address limit is implemented primarily as a means of preventing out-of-gas exceptions when looping over funded addresses for payouts
contract OpenQTokenWhitelist is TokenWhitelist {
/// @notice Initializes OpenQTokenWhitelist with maximum token address limit to prevent out-of-gas errors
/// @param _tokenAddressLimit Maximum number of token addresses allowed
constructor(uint256 _tokenAddressLimit) TokenWhitelist() {
TOKEN_ADDRESS_LIMIT = _tokenAddressLimit;
}
constructor() TokenWhitelist() {}
}
10 changes: 0 additions & 10 deletions contracts/TokenWhitelist/TokenWhitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '../Library/Errors.sol';
/// @notice Base contract for token whitelists
/// @dev Whitelisting and token address limit is implemented primarily as a means of preventing out-of-gas exceptions when looping over funded addresses for payouts
abstract contract TokenWhitelist is Ownable {
uint256 public TOKEN_ADDRESS_LIMIT;
uint256 public tokenCount;
mapping(address => bool) public whitelist;

Expand Down Expand Up @@ -41,13 +40,4 @@ abstract contract TokenWhitelist is Ownable {
whitelist[_tokenAddress] = false;
tokenCount--;
}

/// @notice Updates the tokenAddressLimit
/// @param _newTokenAddressLimit The new value for TOKEN_ADDRESS_LIMIT
function setTokenAddressLimit(uint256 _newTokenAddressLimit)
external
onlyOwner
{
TOKEN_ADDRESS_LIMIT = _newTokenAddressLimit;
}
}
2 changes: 1 addition & 1 deletion deploy/deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function deployContracts() {

console.log('Deploying OpenQTokenWhitelist...');
const OpenQTokenWhitelist = await ethers.getContractFactory('OpenQTokenWhitelist');
const openQTokenWhitelist = await OpenQTokenWhitelist.deploy(5);
const openQTokenWhitelist = await OpenQTokenWhitelist.deploy();
await openQTokenWhitelist.deployed();
await optionalSleep(10000);
console.log(`OpenQTokenWhitelist Deployed to ${openQTokenWhitelist.address}\n`);
Expand Down
2 changes: 1 addition & 1 deletion test/ClaimManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('ClaimManager.sol', () => {
mockNft = await MockNft.deploy();
await mockNft.deployed();

openQTokenWhitelist = await OpenQTokenWhitelist.deploy(5);
openQTokenWhitelist = await OpenQTokenWhitelist.deploy();
await openQTokenWhitelist.deployed();

await openQTokenWhitelist.addToken(mockLink.address);
Expand Down
31 changes: 5 additions & 26 deletions test/DepositManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
tieredFixedBountyInitOperationBuilder_permissionless
} = require('./constants');

describe('DepositManager.sol', () => {
describe.only('DepositManager.sol', () => {
// MOCK ASSETS
let openQProxy;
let openQImplementation;
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('DepositManager.sol', () => {
mockNft = await MockNft.deploy();
await mockNft.deployed();

openQTokenWhitelist = await OpenQTokenWhitelist.deploy(5);
openQTokenWhitelist = await OpenQTokenWhitelist.deploy();
await openQTokenWhitelist.deployed();

await openQTokenWhitelist.addToken(mockLink.address);
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('DepositManager.sol', () => {

// ARRANGE
const OpenQTokenWhitelist = await ethers.getContractFactory('OpenQTokenWhitelist');
const openQTokenWhitelist = await OpenQTokenWhitelist.deploy(20);
const openQTokenWhitelist = await OpenQTokenWhitelist.deploy();
await openQTokenWhitelist.deployed();

// ACT
Expand All @@ -217,7 +217,7 @@ describe('DepositManager.sol', () => {
await expect(depositManager.fundBountyToken(bountyAddress, mockLink.address, 10000000, 1, Constants.funderUuid)).to.be.revertedWith('CONTRACT_ALREADY_CLOSED');
});

it('should revert if funded with a non-whitelisted token and bounty is at funded token address capacity', async () => {
it('should revert if funded with a non-whitelisted token', async () => {
// ARRANGE
await openQProxy.mintBounty(Constants.bountyId, Constants.organization, atomicBountyInitOperation);

Expand All @@ -226,31 +226,10 @@ describe('DepositManager.sol', () => {
await blacklistedMockDai.approve(bountyAddress, 10000000);
await mockLink.approve(bountyAddress, 10000000);

// set lower capacity for token
await openQTokenWhitelist.setTokenAddressLimit(1);

await depositManager.fundBountyToken(bountyAddress, mockLink.address, 10000000, 1, Constants.funderUuid);

// ACT + ASSERT
await expect(depositManager.fundBountyToken(bountyAddress, blacklistedMockDai.address, 10000000, 1, Constants.funderUuid)).to.be.revertedWith('TOO_MANY_TOKEN_ADDRESSES');
});

it('should ALLOW funding with whitelisted token EVEN IF bounty is at funded token address capacity', async () => {
// ARRANGE
await openQProxy.mintBounty(Constants.bountyId, Constants.organization, atomicBountyInitOperation);

const bountyAddress = await openQProxy.bountyIdToAddress(Constants.bountyId);

await mockDai.approve(bountyAddress, 10000000);
await mockLink.approve(bountyAddress, 10000000);

// set lower capacity for token
await openQTokenWhitelist.setTokenAddressLimit(1);

await depositManager.fundBountyToken(bountyAddress, mockLink.address, 10000000, 1, Constants.funderUuid);

// ACT + ASSERT
await expect(depositManager.fundBountyToken(bountyAddress, mockDai.address, 10000000, 1, Constants.funderUuid)).to.not.be.revertedWith('TOO_MANY_TOKEN_ADDRESSES');
await expect(depositManager.fundBountyToken(bountyAddress, blacklistedMockDai.address, 10000000, 1, Constants.funderUuid)).to.be.revertedWith('TOKEN_NOT_ACCEPTED');
});

it('should set funder to msg.sender', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/OpenQ.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('OpenQ.sol', () => {
mockNft = await MockNft.deploy()
await mockNft.deployed()

openQTokenWhitelist = await OpenQTokenWhitelist.deploy(5)
openQTokenWhitelist = await OpenQTokenWhitelist.deploy()
await openQTokenWhitelist.deployed()

await openQTokenWhitelist.addToken(mockLink.address)
Expand Down
21 changes: 1 addition & 20 deletions test/OpenQTokenWhitelist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('OpenQTokenWhitelist.sol', () => {

[owner, notOwner] = await ethers.getSigners();

openQTokenWhitelist = await OpenQTokenWhitelist.deploy(2);
openQTokenWhitelist = await OpenQTokenWhitelist.deploy();
await openQTokenWhitelist.deployed();

mockLink = await MockLink.deploy();
Expand All @@ -31,11 +31,6 @@ describe('OpenQTokenWhitelist.sol', () => {
});

describe('OpenQTokenWhitelist methods', () => {
it('initializes', async () => {
const totalTokenAddresses = await openQTokenWhitelist.TOKEN_ADDRESS_LIMIT();
expect(totalTokenAddresses).to.equal(2);
});

it('can add token', async () => {
// ASSUME
let mockLinkWhitelist = await openQTokenWhitelist.isWhitelisted(mockLink.address);
Expand Down Expand Up @@ -89,19 +84,6 @@ describe('OpenQTokenWhitelist.sol', () => {
expect(tokenCount).to.equal(0);
});

it('increases token address limit', async () => {
// ASSUME
let tokenAddressLimit = await openQTokenWhitelist.TOKEN_ADDRESS_LIMIT();
expect(tokenAddressLimit).to.equal(2);

// ACT
await openQTokenWhitelist.setTokenAddressLimit(5);

// ASSERT
tokenAddressLimit = await openQTokenWhitelist.TOKEN_ADDRESS_LIMIT();
expect(tokenAddressLimit).to.equal(5);
});

it('add and remove token is idempotent', async () => {
// ARRANGE
await openQTokenWhitelist.addToken(mockLink.address);
Expand All @@ -116,7 +98,6 @@ describe('OpenQTokenWhitelist.sol', () => {
// ACT/ASSERT
await expect(openQTokenWhitelist.connect(notOwner).addToken(mockLink.address)).to.revertedWith('Ownable: caller is not the owner');
await expect(openQTokenWhitelist.connect(notOwner).removeToken(mockLink.address)).to.revertedWith('Ownable: caller is not the owner');
await expect(openQTokenWhitelist.connect(notOwner).setTokenAddressLimit(5)).to.revertedWith('Ownable: caller is not the owner');
});
});
});

0 comments on commit 26c11e0

Please sign in to comment.