From 35be4067ad4fd719ccd433dd611bc04f2252f0c3 Mon Sep 17 00:00:00 2001 From: Jonathan Diep Date: Sat, 29 Jun 2024 15:02:37 -0700 Subject: [PATCH] feat: add deployer fee --- contracts/QuestBudget.sol | 5 +++++ test/QuestBudget.t.sol | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/contracts/QuestBudget.sol b/contracts/QuestBudget.sol index 3a6aa150..080eccf3 100644 --- a/contracts/QuestBudget.sol +++ b/contracts/QuestBudget.sol @@ -161,6 +161,11 @@ contract QuestBudget is Budget, IERC1155Receiver, ReentrancyGuard { uint256 referralRewardFee_ ) public virtual onlyAuthorized returns (address) { uint256 maxTotalRewards = totalParticipants_ * rewardAmount_; + + uint256 deployerFee = (maxTotalRewards * 500) / 10_000; // Deployer fee is 500 (5%) + rewardTokenAddress_.safeApprove(address(this), deployerFee); + rewardTokenAddress_.safeTransferFrom(address(this), msg.sender, deployerFee); + uint256 questFee = uint256(IQuestFactory(questFactory).questFee()); uint256 maxProtocolReward = (maxTotalRewards * questFee) / 10_000; // Assuming questFee is 2000 uint256 approvalAmount = maxTotalRewards + maxProtocolReward; diff --git a/test/QuestBudget.t.sol b/test/QuestBudget.t.sol index 7f90f61a..275ff652 100644 --- a/test/QuestBudget.t.sol +++ b/test/QuestBudget.t.sol @@ -388,14 +388,17 @@ contract QuestBudgetTest is Test, TestUtils, IERC1155Receiver { uint256 maxTotalRewards = totalParticipants_ * rewardAmount_; uint256 questFee = uint256(mockQuestFactory.questFee()); uint256 maxProtocolReward = (maxTotalRewards * questFee) / 10_000; // Assuming questFee is 2000 + uint256 deployerFee = (maxTotalRewards * 500) / 10_000; uint256 approvalAmount = maxTotalRewards + maxProtocolReward; - mockERC20.mint(address(this), approvalAmount); - // Ensure the budget has enough tokens for the reward - mockERC20.approve(address(questBudget), approvalAmount); + mockERC20.mint(address(this), approvalAmount + deployerFee); + // Ensure the budget has enough tokens for the reward + deployerFee + mockERC20.approve(address(questBudget), approvalAmount + deployerFee); questBudget.allocate( - _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), approvalAmount) + _makeFungibleTransfer(Budget.AssetType.ERC20, address(mockERC20), address(this), approvalAmount + deployerFee) ); + uint256 deployerBalanceBeforeFee = mockERC20.balanceOf(address(this)); + // Create the new quest address questAddress = questBudget.createERC20Quest( txHashChainId_, @@ -416,6 +419,9 @@ contract QuestBudgetTest is Test, TestUtils, IERC1155Receiver { // Ensure the quest contract has the correct reward amount assertEq(IERC20(rewardTokenAddress_).balanceOf(questAddress), approvalAmount); + + // Ensure the quest deployer gets the deployer fee + assertEq(IERC20(rewardTokenAddress_).balanceOf(address(this)), deployerBalanceBeforeFee + deployerFee); } ///////////////////////////