Skip to content

Commit

Permalink
Q-AJN-7: zero ERC20 transfer on claim reward (#74)
Browse files Browse the repository at this point in the history
- if claimed rewards are 0 then do not attempt to transfer
- expose unit test
  • Loading branch information
grandizzy authored May 8, 2023
1 parent d10601d commit 86ddbf8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
24 changes: 12 additions & 12 deletions src/grants/base/StandardFunding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ abstract contract StandardFunding is Funding, IStandardFunding {
);

// transfer rewards to delegatee
IERC20(ajnaTokenAddress).safeTransfer(msg.sender, rewardClaimed_);
if (rewardClaimed_ != 0) IERC20(ajnaTokenAddress).safeTransfer(msg.sender, rewardClaimed_);
}

/**
Expand All @@ -279,17 +279,17 @@ abstract contract StandardFunding is Funding, IStandardFunding {
uint256 votingPowerAllocatedByDelegatee = voter_.votingPower - voter_.remainingVotingPower;

// if none of the voter's voting power was allocated, they receive no rewards
if (votingPowerAllocatedByDelegatee == 0) return 0;

// calculate reward
// delegateeReward = 10 % of GBC distributed as per delegatee Voting power allocated
rewards_ = Maths.wdiv(
Maths.wmul(
currentDistribution_.fundsAvailable,
votingPowerAllocatedByDelegatee
),
currentDistribution_.fundingVotePowerCast
) / 10;
if (votingPowerAllocatedByDelegatee != 0) {
// calculate reward
// delegateeReward = 10 % of GBC distributed as per delegatee Voting power allocated
rewards_ = Maths.wdiv(
Maths.wmul(
currentDistribution_.fundsAvailable,
votingPowerAllocatedByDelegatee
),
currentDistribution_.fundingVotePowerCast
) / 10;
}
}

/***********************************/
Expand Down
5 changes: 3 additions & 2 deletions test/unit/StandardFunding.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,9 @@ contract StandardFundingGrantFundTest is GrantFundTestHelper {
vm.expectRevert(IStandardFunding.RewardAlreadyClaimed.selector);
_grantFund.claimDelegateReward(distributionId);

// transfers 0 ajna Token as _tokenHolder6 has not participated in funding stage
_claimDelegateReward(
// no ajna tokens transfered as _tokenHolder6 has not participated in funding stage
// transfer event should not be emitted
_claimZeroDelegateReward(
{
grantFund_: _grantFund,
voter_: _tokenHolder6,
Expand Down
9 changes: 9 additions & 0 deletions test/utils/GrantFundTestHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ abstract contract GrantFundTestHelper is Test {
/************************************/

function _claimDelegateReward(GrantFund grantFund_, address voter_, uint24 distributionId_, uint256 claimedReward_) internal {
changePrank(voter_);
vm.expectEmit(true, true, false, true);
emit DelegateRewardClaimed(voter_, distributionId_, claimedReward_);
vm.expectEmit(true, true, false, true);
emit Transfer(address(grantFund_), voter_, claimedReward_);
grantFund_.claimDelegateReward(distributionId_);
}

function _claimZeroDelegateReward(GrantFund grantFund_, address voter_, uint24 distributionId_, uint256 claimedReward_) internal {
changePrank(voter_);
vm.expectEmit(true, true, false, true);
emit DelegateRewardClaimed(voter_, distributionId_, claimedReward_);
Expand Down

0 comments on commit 86ddbf8

Please sign in to comment.