Skip to content

Commit

Permalink
fix: re-add createERC20Quest with referral param for backward compa…
Browse files Browse the repository at this point in the history
…tibility
  • Loading branch information
jonathandiep committed Jun 18, 2024
1 parent 15d2227 commit b737354
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 25 deletions.
7 changes: 5 additions & 2 deletions contracts/QuestBudget.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ contract QuestBudget is Budget, IERC1155Receiver, ReentrancyGuard {
/// @param actionType_ The action type for the quest
/// @param questName_ The name of the quest
/// @param projectName_ The name of the project/protocol used for the quest
/// @param referralRewardFee_ The fee amount for referrals. The value is counted against the `rewardAmount`
/// @return address the quest contract address
function createERC20Quest(
uint32 txHashChainId_,
Expand All @@ -156,7 +157,8 @@ contract QuestBudget is Budget, IERC1155Receiver, ReentrancyGuard {
string memory questId_,
string memory actionType_,
string memory questName_,
string memory projectName_
string memory projectName_,
uint256 referralRewardFee_
) public virtual onlyAuthorized returns (address) {
uint256 maxTotalRewards = totalParticipants_ * rewardAmount_;
uint256 questFee = uint256(IQuestFactory(questFactory).questFee());
Expand All @@ -173,7 +175,8 @@ contract QuestBudget is Budget, IERC1155Receiver, ReentrancyGuard {
questId_,
actionType_,
questName_,
projectName_
projectName_,
referralRewardFee_
);
}

Expand Down
45 changes: 44 additions & 1 deletion contracts/QuestFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
/// @param questName_ The name of the quest
/// @param projectName_ The name of the project/protocol used for the quest
/// @return address the quest contract address
function createERC20Quest(
function createERC20Boost(
uint32 txHashChainId_,
address rewardTokenAddress_,
uint256 endTime_,
Expand Down Expand Up @@ -175,6 +175,49 @@ contract QuestFactory is Initializable, LegacyStorage, OwnableRoles, IQuestFacto
);
}

/// @dev Create an erc20 quest and start it at the same time. The function will transfer the reward amount to the quest contract
/// @param txHashChainId_ The chain id of the chain the txHash is on
/// @param rewardTokenAddress_ The contract address of the reward token
/// @param endTime_ The end time of the quest
/// @param startTime_ The start time of the quest
/// @param totalParticipants_ The total amount of participants (accounts) the quest will have
/// @param rewardAmount_ The reward amount for an erc20 quest
/// @param questId_ The id of the quest
/// @param actionType_ The action type for the quest
/// @param questName_ The name of the quest
/// @param projectName_ The name of the project/protocol used for the quest
/// @param referralRewardFee_ The fee amount for referrals -- this is no longer used since we now have a flat 2.5% fee
/// @return address the quest contract address
function createERC20Quest(
uint32 txHashChainId_,
address rewardTokenAddress_,
uint256 endTime_,
uint256 startTime_,
uint256 totalParticipants_,
uint256 rewardAmount_,
string memory questId_,
string memory actionType_,
string memory questName_,
string memory projectName_,
uint256 referralRewardFee_
) external checkQuest(questId_) returns (address) {
return createERC20QuestInternal(
ERC20QuestData(
txHashChainId_,
rewardTokenAddress_,
endTime_,
startTime_,
totalParticipants_,
rewardAmount_,
questId_,
actionType_,
questName_,
"erc20",
projectName_
)
);
}

/// @dev Create an erc1155 quest and start it at the same time. The function will transfer the reward amount to the quest contract
/// @param txHashChainId_ The chain id of the chain the txHash is on
/// @param rewardTokenAddress_ The contract address of the reward token
Expand Down
15 changes: 14 additions & 1 deletion contracts/interfaces/IQuestFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ interface IQuestFactory {
function questFee() external view returns (uint16);

// Create
function createERC20Quest(
function createERC20Boost(
uint32 txHashChainId_,
address rewardTokenAddress_,
uint256 endTime_,
Expand All @@ -208,6 +208,19 @@ interface IQuestFactory {
string memory questName_,
string memory projectName_
) external returns (address);
function createERC20Quest(
uint32 txHashChainId_,
address rewardTokenAddress_,
uint256 endTime_,
uint256 startTime_,
uint256 totalParticipants_,
uint256 rewardAmount_,
string memory questId_,
string memory actionType_,
string memory questName_,
string memory projectName_,
uint256 referralRewardFee_
) external returns (address);

function create1155QuestAndQueue(
address rewardTokenAddress_,
Expand Down
8 changes: 6 additions & 2 deletions test/QuestBudget.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ contract QuestBudgetTest is Test, TestUtils, IERC1155Receiver {
string memory actionType_ = "testAction";
string memory questName_ = "Test Quest";
string memory projectName_ = "Test Project";
uint256 referralRewardFee_ = 10 ether;

uint256 maxTotalRewards = totalParticipants_ * rewardAmount_;
uint256 questFee = uint256(mockQuestFactory.questFee());
Expand All @@ -406,7 +407,8 @@ contract QuestBudgetTest is Test, TestUtils, IERC1155Receiver {
questId_,
actionType_,
questName_,
projectName_
projectName_,
referralRewardFee_
);

// Ensure the returned quest address is not the zero address
Expand All @@ -432,6 +434,7 @@ contract QuestBudgetTest is Test, TestUtils, IERC1155Receiver {
string memory actionType_ = "testAction";
string memory questName_ = "Test Quest";
string memory projectName_ = "Test Project";
uint256 referralRewardFee_ = 10 ether;

uint256 maxTotalRewards = totalParticipants_ * rewardAmount_;
uint256 questFee = uint256(mockQuestFactory.questFee());
Expand All @@ -455,7 +458,8 @@ contract QuestBudgetTest is Test, TestUtils, IERC1155Receiver {
questId_,
actionType_,
questName_,
projectName_
projectName_,
referralRewardFee_
);

// Ensure the returned quest address is not the zero address
Expand Down
4 changes: 2 additions & 2 deletions test/QuestClaimable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
function test_claim_with_referrer() public {
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT, QUEST_FEE, REFERRAL_REWARD_FEE));
address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
101,
address(sampleERC20),
END_TIME,
Expand Down Expand Up @@ -109,7 +109,7 @@ contract TestQuestClaimable is Test, Errors, Events, TestUtils {
referrer = address(0);
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(TOTAL_PARTICIPANTS, REWARD_AMOUNT, QUEST_FEE, REFERRAL_REWARD_FEE));
address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
101,
address(sampleERC20),
END_TIME,
Expand Down
30 changes: 15 additions & 15 deletions test/QuestFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
vm.stopPrank();
}

function test_createERC20Quest() public{
function test_createERC20Boost() public{
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));

vm.expectEmit(true,false,true,true);
emit QuestCreated(questCreator, address(0), QUEST.PROJECT_NAME, QUEST.QUEST_NAME, QUEST.QUEST_ID_STRING, "erc20", QUEST.ACTION_TYPE, QUEST.CHAIN_ID, address(sampleERC20), QUEST.END_TIME, QUEST.START_TIME, QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT);

address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand All @@ -144,10 +144,10 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
vm.stopPrank();
}

function test_RevertIf_createERC20Quest_QuestIdUsed() public{
function test_RevertIf_createERC20Boost_QuestIdUsed() public{
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));
questFactory.createERC20Quest(
questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand All @@ -161,7 +161,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
);

vm.expectRevert(abi.encodeWithSelector(QuestIdUsed.selector));
questFactory.createERC20Quest(
questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand All @@ -175,15 +175,15 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
);
}

function test_RevertIf_createERC20Quest_Erc20QuestAddressNotSet() public{
function test_RevertIf_createERC20Boost_Erc20QuestAddressNotSet() public{
vm.startPrank(owner);
questFactory.setErc20QuestAddress(address(0));

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

vm.expectRevert(abi.encodeWithSelector(Erc20QuestAddressNotSet.selector));
questFactory.createERC20Quest(
questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand Down Expand Up @@ -248,7 +248,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
vm.deal(participant, 1000000);
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));
address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand Down Expand Up @@ -287,7 +287,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {

vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));
address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand Down Expand Up @@ -318,7 +318,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
function test_claimCompressed_erc20_with_ref() public{
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));
address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand Down Expand Up @@ -384,7 +384,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
function test_claimOptimized_revert_deprecated() public{
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));
questFactory.createERC20Quest(
questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand Down Expand Up @@ -415,7 +415,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
function test_cancelQuest() public {
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));
address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand All @@ -439,7 +439,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
function test_cancelQuest_alreadyStarted() public {
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));
address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand All @@ -464,7 +464,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
function test_cancelQuest_unauthorized() public {
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));
address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand All @@ -488,7 +488,7 @@ contract TestQuestFactory is Test, Errors, Events, TestUtils {
function test_questData() public {
vm.startPrank(questCreator);
sampleERC20.approve(address(questFactory), calculateTotalRewardsPlusFee(QUEST.TOTAL_PARTICIPANTS, QUEST.REWARD_AMOUNT, QUEST_FEE, REFERRAL_FEE));
address questAddress = questFactory.createERC20Quest(
address questAddress = questFactory.createERC20Boost(
QUEST.CHAIN_ID,
address(sampleERC20),
QUEST.END_TIME,
Expand Down
7 changes: 5 additions & 2 deletions test/mocks/QuestFactoryMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract QuestFactoryMock {
string questName;
string questType;
string projectName;
uint256 referralRewardFee;
}

QuestData public questData;
Expand Down Expand Up @@ -71,7 +72,8 @@ contract QuestFactoryMock {
string memory questId_,
string memory actionType_,
string memory questName_,
string memory projectName_
string memory projectName_,
uint256 referralRewardFee_
) external returns (address) {
uint256 maxTotalRewards = totalParticipants_ * rewardAmount_;
uint256 maxProtocolReward = (maxTotalRewards * 2000) / 10_000; // Assuming questFee is 2000
Expand All @@ -87,7 +89,8 @@ contract QuestFactoryMock {
actionType: actionType_,
questName: questName_,
questType: "erc20",
projectName: projectName_
projectName: projectName_,
referralRewardFee: referralRewardFee_
});

// Transfer rewardAmount_ tokens from the caller to this contract
Expand Down

0 comments on commit b737354

Please sign in to comment.