Skip to content

Commit

Permalink
feat: add deployer fee
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathandiep committed Jun 29, 2024
1 parent d319aa2 commit 35be406
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions contracts/QuestBudget.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions test/QuestBudget.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_,
Expand All @@ -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);
}

///////////////////////////
Expand Down

0 comments on commit 35be406

Please sign in to comment.