Skip to content

Commit

Permalink
Feat(QuestFactory): Remove Token Whitelist (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quazia authored Apr 1, 2024
1 parent ad14258 commit feba1c5
Show file tree
Hide file tree
Showing 26 changed files with 1,671 additions and 295 deletions.
3 changes: 2 additions & 1 deletion QuestFactory.json

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions broadcast/QuestFactory.s.sol/10/run-1711998881.json

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions broadcast/QuestFactory.s.sol/10/run-1711999082.json

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions broadcast/QuestFactory.s.sol/10/run-1711999126.json

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions broadcast/QuestFactory.s.sol/10/run-1711999132.json

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions broadcast/QuestFactory.s.sol/10/run-1711999138.json

Large diffs are not rendered by default.

89 changes: 44 additions & 45 deletions broadcast/QuestFactory.s.sol/10/run-latest.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions broadcast/QuestFactory.s.sol/11155111/run-1711577275.json

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions broadcast/QuestFactory.s.sol/11155111/run-1711577294.json

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions broadcast/QuestFactory.s.sol/11155111/run-1711577300.json

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions broadcast/QuestFactory.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions broadcast/QuestFactory.s.sol/137/run-1711999398.json

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions broadcast/QuestFactory.s.sol/137/run-1711999404.json

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions broadcast/QuestFactory.s.sol/137/run-1711999410.json

Large diffs are not rendered by default.

106 changes: 53 additions & 53 deletions broadcast/QuestFactory.s.sol/137/run-latest.json

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions broadcast/QuestFactory.s.sol/42161/run-1711999315.json

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions broadcast/QuestFactory.s.sol/42161/run-1711999321.json

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions broadcast/QuestFactory.s.sol/42161/run-latest.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions broadcast/QuestFactory.s.sol/8453/run-1711999593.json

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions broadcast/QuestFactory.s.sol/8453/run-1711999599.json

Large diffs are not rendered by default.

76 changes: 39 additions & 37 deletions broadcast/QuestFactory.s.sol/8453/run-latest.json

Large diffs are not rendered by default.

39 changes: 15 additions & 24 deletions contracts/QuestFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
address public erc20QuestAddress;
address public erc1155QuestAddress;
mapping(string => Quest) public quests;
address public rabbitHoleReceiptContract; // not used
address public rabbitHoleTicketsContract; // not used
mapping(address => bool) public rewardAllowlist;
address private __deprecated_rabbitHoleReceiptContract; // not used
address private __deprecated_rabbitHoleTicketsContract; // not used
mapping(address => bool) private __deprecated_rewardAllowlist; // not used
uint16 public questFee;
uint256 public mintFee;
address public defaultMintFeeRecipient;
uint256 private locked;
address public defaultReferralFeeRecipient; // not used
uint256 public nftQuestFee; // not used
address public questNFTAddress; // not used
mapping(address => address[]) public ownerCollections;
mapping(address => NftQuestFees) public nftQuestFeeList; // not used
address private __deprecated_defaultReferralFeeRecipient; // not used
uint256 private __deprecated_nftQuestFee; // not used
address private __deprecated_questNFTAddress; // not used
mapping(address => address[]) private ownerCollections;
mapping(address => NftQuestFees) private __deprecated_nftQuestFeeList; // not used
uint16 public referralFee;
address public sablierV2LockupLinearAddress; // not used
mapping(address => address) public mintFeeRecipientList; // not used
address private __deprecated_sablierV2LockupLinearAddress; // not used
mapping(address => address) private __deprecated_mintFeeRecipientList; // not used
// insert new vars here at the end to keep the storage layout the same

/*//////////////////////////////////////////////////////////////
Expand All @@ -69,7 +69,7 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
address erc20QuestAddress_,
address payable erc1155QuestAddress_,
address ownerAddress_,
uint256 nftQuestFee_,
uint256,
uint16 referralFee_,
uint256 mintFee_
) external initializer {
Expand All @@ -80,7 +80,6 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
protocolFeeRecipient = protocolFeeRecipient_;
erc20QuestAddress = erc20QuestAddress_;
erc1155QuestAddress = erc1155QuestAddress_;
nftQuestFee = nftQuestFee_;
referralFee = referralFee_;
mintFee = mintFee_;
}
Expand All @@ -89,10 +88,9 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
MODIFIERS
//////////////////////////////////////////////////////////////*/

modifier checkQuest(string memory questId_, address rewardTokenAddress_) {
modifier checkQuest(string memory questId_) {
Quest storage currentQuest = quests[questId_];
if (currentQuest.questAddress != address(0)) revert QuestIdUsed();
if (!rewardAllowlist[rewardTokenAddress_]) revert RewardNotAllowed();
if (erc20QuestAddress == address(0)) revert Erc20QuestAddressNotSet();
_;
}
Expand Down Expand Up @@ -155,7 +153,7 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
string memory actionType_,
string memory questName_,
string memory projectName_
) external checkQuest(questId_, rewardTokenAddress_) returns (address) {
) external checkQuest(questId_) returns (address) {
return createERC20QuestInternal(
ERC20QuestData(
txHashChainId_,
Expand Down Expand Up @@ -276,7 +274,7 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
string memory questId_,
string memory actionType_,
string memory questName_
) external checkQuest(questId_, rewardTokenAddress_) returns (address) {
) external checkQuest(questId_) returns (address) {
return createERC20QuestInternal(
ERC20QuestData(
0,
Expand Down Expand Up @@ -304,7 +302,7 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
string memory questId_,
string memory,
uint256
) external checkQuest(questId_, rewardTokenAddress_) returns (address) {
) external checkQuest(questId_) returns (address) {
return createERC20QuestInternal(
ERC20QuestData(
0,
Expand Down Expand Up @@ -479,13 +477,6 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
emit ReferralFeeSet(referralFee_);
}

/// @dev set or remave a contract address to be used as a reward
/// @param rewardAddress_ The contract address to set
/// @param allowed_ Whether the contract address is allowed or not
function setRewardAllowlistAddress(address rewardAddress_, bool allowed_) external onlyOwner {
rewardAllowlist[rewardAddress_] = allowed_;
}

/// @dev set the mintFeeRecipient
/// @param mintFeeRecipient_ The address of the mint fee recipient
function setDefaultMintFeeRecipient(address mintFeeRecipient_) external onlyOwner {
Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/IQuestFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface IQuestFactory {
error QuestTypeNotSupported();
error Reentrancy();
error ReferralFeeTooHigh();
error RewardNotAllowed();
error ZeroAddressNotAllowed();
error QuestAddressMismatch();
error ClaimFailed();
Expand Down Expand Up @@ -202,7 +201,6 @@ interface IQuestFactory {
function setDefaultMintFeeRecipient(address mintFeeRecipient_) external;
function setProtocolFeeRecipient(address protocolFeeRecipient_) external;
function setQuestFee(uint16 questFee_) external;
function setRewardAllowlistAddress(address rewardAddress_, bool allowed_) external;

// Callbacks
function withdrawCallback(string calldata questId_, address protocolFeeRecipient_, uint protocolPayout_, address mintFeeRecipient_, uint mintPayout) external;
Expand Down
18 changes: 4 additions & 14 deletions test/QuestClaimable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
CLAIM ERC20
//////////////////////////////////////////////////////////////*/
function test_claim_with_referrer() public {
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT, QUEST_FEE));
address questAddress = questFactory.createERC20Quest(
Expand Down Expand Up @@ -103,16 +100,12 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
vm.startPrank(participant, participant);
vm.recordLogs();
vm.expectRevert(IQuestFactory.Deprecated.selector);
(bool success, ) = questAddress.call{value: MINT_FEE}(payload);

questAddress.call{value: MINT_FEE}(payload);
vm.stopPrank();
}

function test_claim_without_referrer() public {
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);
referrer = address(0);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT, QUEST_FEE));
address questAddress = questFactory.createERC20Quest(
Expand Down Expand Up @@ -143,8 +136,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
vm.startPrank(participant, participant);
vm.recordLogs();
vm.expectRevert(IQuestFactory.Deprecated.selector);
(bool success, ) = questAddress.call{value: MINT_FEE}(payload);

questAddress.call{value: MINT_FEE}(payload);
vm.stopPrank();
}

Expand Down Expand Up @@ -185,8 +177,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
vm.startPrank(participant, participant);
vm.recordLogs();
vm.expectRevert(IQuestFactory.Deprecated.selector);
(bool success, ) = questAddress.call{value: MINT_FEE}(payload);

questAddress.call{value: MINT_FEE}(payload);
vm.stopPrank();
}

Expand Down Expand Up @@ -225,8 +216,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
vm.startPrank(participant, participant);
vm.recordLogs();
vm.expectRevert(IQuestFactory.Deprecated.selector);
(bool success, ) = questAddress.call{value: MINT_FEE}(payload);

questAddress.call{value: MINT_FEE}(payload);
vm.stopPrank();
}

Expand Down
44 changes: 1 addition & 43 deletions test/QuestFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
}

function test_createERC20Quest() public{
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE));

Expand Down Expand Up @@ -147,31 +144,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
vm.stopPrank();
}

function test_RevertIf_createERC20Quest_RewardNotAllowed() public{
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), false);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE));
vm.expectRevert(abi.encodeWithSelector(RewardNotAllowed.selector));
questFactory.createERC20Quest(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
QUEST.START_TIME,
QUEST.TOTAL_PARTICIPANTS,
QUEST.REWARD_AMOUNT,
QUEST.QUEST_ID_STRING,
QUEST.ACTION_TYPE,
QUEST.QUEST_NAME,
QUEST.PROJECT_NAME
);
}

function test_RevertIf_createERC20Quest_QuestIdUsed() public{
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE));
questFactory.createERC20Quest(
Expand Down Expand Up @@ -204,7 +177,6 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {

function test_RevertIf_createERC20Quest_Erc20QuestAddressNotSet() public{
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);
questFactory.setErc20QuestAddress(address(0));

vm.startPrank(questCreator);
Expand Down Expand Up @@ -274,9 +246,6 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
(, bytes32 r, bytes32 vs) = TestUtils.getSplitSignature(claimSignerPrivateKey, digest);

vm.deal(participant, 1000000);
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE));
questFactory.createERC20Quest(
Expand Down Expand Up @@ -312,8 +281,6 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
(, bytes32 r, bytes32 vs) = TestUtils.getSplitSignature(claimSignerPrivateKey, digest);

vm.deal(participant, 1000000);
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE));
Expand Down Expand Up @@ -344,9 +311,6 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {


function test_claimCompressed_erc20_with_ref() public{
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE));
address questAddress = questFactory.createERC20Quest(
Expand Down Expand Up @@ -410,12 +374,9 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
}

function test_claimOptimized_revert_deprecated() public{
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE));
address questAddress = questFactory.createERC20Quest(
questFactory.createERC20Quest(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand Down Expand Up @@ -443,9 +404,6 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
VIEW
//////////////////////////////////////////////////////////////*/
function test_questData() public {
vm.startPrank(owner);
questFactory.setRewardAllowlistAddress(address(sampleERC20), true);

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE));
address questAddress = questFactory.createERC20Quest(
Expand Down
1 change: 0 additions & 1 deletion test/helpers/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ contract Errors {
error OnlyMinter();

// QuestFactory
error RewardNotAllowed();
error QuestIdUsed();
error Erc20QuestAddressNotSet();
error QuestNotStarted();
Expand Down

0 comments on commit feba1c5

Please sign in to comment.