Skip to content

Accumulated subgraph rewards reset to zero on edge case #452

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

Merged
merged 3 commits into from
Apr 27, 2021
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
41 changes: 23 additions & 18 deletions contracts/rewards/RewardsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
uint256 p = graphToken.totalSupply();
uint256 a = p.mul(_pow(r, t, TOKEN_DECIMALS)).div(TOKEN_DECIMALS);

// New issuance per signalled token during time steps
// New issuance of tokens during time steps
uint256 x = a.sub(p);

// Get the new issuance per signalled token
// We multiply the decimals to keep the precision as fixed-point number
return x.mul(TOKEN_DECIMALS).div(signalledTokens);
}
Expand All @@ -214,14 +215,12 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
{
Subgraph storage subgraph = subgraphs[_subgraphDeploymentID];

uint256 newAccrued = getAccRewardsPerSignal().sub(subgraph.accRewardsPerSignalSnapshot);
uint256 newRewardsPerSignal = getAccRewardsPerSignal().sub(
subgraph.accRewardsPerSignalSnapshot
);
uint256 subgraphSignalledTokens = curation().getCurationPoolTokens(_subgraphDeploymentID);
if (subgraphSignalledTokens == 0) {
return 0;
}

uint256 newValue = newAccrued.mul(subgraphSignalledTokens).div(TOKEN_DECIMALS);
return subgraph.accRewardsForSubgraph.add(newValue);
uint256 newRewards = newRewardsPerSignal.mul(subgraphSignalledTokens).div(TOKEN_DECIMALS);
return subgraph.accRewardsForSubgraph.add(newRewards);
}

/**
Expand All @@ -239,7 +238,9 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
Subgraph storage subgraph = subgraphs[_subgraphDeploymentID];

uint256 accRewardsForSubgraph = getAccRewardsForSubgraph(_subgraphDeploymentID);
uint256 newAccrued = accRewardsForSubgraph.sub(subgraph.accRewardsForSubgraphSnapshot);
uint256 newRewardsForSubgraph = accRewardsForSubgraph.sub(
subgraph.accRewardsForSubgraphSnapshot
);

uint256 subgraphAllocatedTokens = staking().getSubgraphAllocatedTokens(
_subgraphDeploymentID
Expand All @@ -248,8 +249,13 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
return (0, accRewardsForSubgraph);
}

uint256 newValue = newAccrued.mul(TOKEN_DECIMALS).div(subgraphAllocatedTokens);
return (subgraph.accRewardsPerAllocatedToken.add(newValue), accRewardsForSubgraph);
uint256 newRewardsPerAllocatedToken = newRewardsForSubgraph.mul(TOKEN_DECIMALS).div(
subgraphAllocatedTokens
);
return (
subgraph.accRewardsPerAllocatedToken.add(newRewardsPerAllocatedToken),
accRewardsForSubgraph
);
}

/**
Expand Down Expand Up @@ -356,9 +362,7 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
IStaking staking = staking();
require(msg.sender == address(staking), "Caller must be the staking contract");

IGraphToken graphToken = graphToken();
IStaking.Allocation memory alloc = staking.getAllocation(_allocationID);

uint256 accRewardsPerAllocatedToken = onSubgraphAllocationUpdate(
alloc.subgraphDeploymentID
);
Expand All @@ -375,11 +379,12 @@ contract RewardsManager is RewardsManagerV1Storage, GraphUpgradeable, IRewardsMa
alloc.accRewardsPerAllocatedToken,
accRewardsPerAllocatedToken
);

// Mint directly to staking contract for the reward amount
// The staking contract will do bookkeeping of the reward and
// assign in proportion to each stakeholder incentive
graphToken.mint(address(staking), rewards);
if (rewards > 0) {
// Mint directly to staking contract for the reward amount
// The staking contract will do bookkeeping of the reward and
// assign in proportion to each stakeholder incentive
graphToken().mint(address(staking), rewards);
}

emit RewardsAssigned(alloc.indexer, _allocationID, alloc.closedAtEpoch, rewards);

Expand Down
Loading