Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q-AJN-7: zero ERC20 transfer on claim reward #74

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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