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

[eth-contracts] Current round logic #477

Merged
merged 5 commits into from
May 20, 2020
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
54 changes: 35 additions & 19 deletions eth-contracts/contracts/ClaimsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,28 @@ contract ClaimsManager is RegistryContract {

// Claim related configurations
uint private fundingRoundBlockDiff;
uint private fundBlock;

// TODO: Make this modifiable based on total staking pool?
uint private fundingAmount;

// Denotes current round
uint private roundNumber;

// Total claimed so far in round
uint private totalClaimedInRound;

// Staking contract ref
ERC20Mintable private audiusToken;

// Struct representing round state
// 1) Block at which round was funded
// 2) Total funded for this round
// 3) Total claimed in round
struct Round {
uint fundBlock;
uint fundingAmount;
uint totalClaimedInRound;
}

// Current round information
Round currentRound;

event RoundInitiated(
uint _blockNumber,
uint _roundNumber,
Expand Down Expand Up @@ -72,10 +80,14 @@ contract ClaimsManager is RegistryContract {
registry = RegistryInterface(_registryAddress);

fundingRoundBlockDiff = 10;
fundBlock = 0;
fundingAmount = 20 * 10**uint256(DECIMALS); // 20 AUDS = 20 * 10**uint256(DECIMALS)
roundNumber = 0;
totalClaimedInRound = 0;

currentRound = Round({
fundBlock: 0,
fundingAmount: 0,
totalClaimedInRound: 0
});

RegistryContract.initialize();
}
Expand All @@ -89,7 +101,7 @@ contract ClaimsManager is RegistryContract {
function getLastFundBlock()
external view returns (uint lastFundBlock)
{
return fundBlock;
return currentRound.fundBlock;
}

function getFundsPerRound()
Expand All @@ -101,7 +113,7 @@ contract ClaimsManager is RegistryContract {
function getTotalClaimedInRound()
external view returns (uint claimedAmount)
{
return totalClaimedInRound;
return currentRound.totalClaimedInRound;
}

/// @dev - Start a new funding round
Expand All @@ -117,18 +129,22 @@ contract ClaimsManager is RegistryContract {
"Round must be initiated from account with staked value or contract deployer"
);
require(
block.number - fundBlock > fundingRoundBlockDiff,
block.number - currentRound.fundBlock > fundingRoundBlockDiff,
"Required block difference not met"
);

fundBlock = block.number;
totalClaimedInRound = 0;
currentRound = Round({
fundBlock: block.number,
fundingAmount: fundingAmount,
totalClaimedInRound: 0
});

roundNumber += 1;

emit RoundInitiated(
fundBlock,
currentRound.fundBlock,
roundNumber,
fundingAmount
currentRound.fundingAmount
);
}

Expand All @@ -149,10 +165,10 @@ contract ClaimsManager is RegistryContract {
Staking stakingContract = Staking(stakingAddress);
// Prevent duplicate claim
uint lastUserClaimBlock = stakingContract.lastClaimedFor(_claimer);
require(lastUserClaimBlock <= fundBlock, "Claim already processed for user");
require(lastUserClaimBlock <= currentRound.fundBlock, "Claim already processed for user");
uint totalStakedAtFundBlockForClaimer = stakingContract.totalStakedForAt(
_claimer,
fundBlock);
currentRound.fundBlock);

( , , , ,uint spMin, uint spMax) = ServiceProviderFactory(
registry.getContract(serviceProviderFactoryKey)
Expand All @@ -166,7 +182,7 @@ contract ClaimsManager is RegistryContract {

// Subtract total locked amount for SP from stake at fund block
uint claimerTotalStake = totalStakedAtFundBlockForClaimer - _totalLockedForSP;
uint totalStakedAtFundBlock = stakingContract.totalStakedAt(fundBlock);
uint totalStakedAtFundBlock = stakingContract.totalStakedAt(currentRound.fundBlock);

// Calculate claimer rewards
uint rewardsForClaimer = (
Expand All @@ -184,7 +200,7 @@ contract ClaimsManager is RegistryContract {
stakingContract.stakeRewards(rewardsForClaimer, _claimer);

// Update round claim value
totalClaimedInRound += rewardsForClaimer;
currentRound.totalClaimedInRound += rewardsForClaimer;

// Update round claim value
uint newTotal = stakingContract.totalStakedFor(_claimer);
Expand Down Expand Up @@ -214,7 +230,7 @@ contract ClaimsManager is RegistryContract {
uint lastClaimedForSP = Staking(
registry.getContract(stakingProxyOwnerKey)
).lastClaimedFor(_sp);
return (lastClaimedForSP < fundBlock);
return (lastClaimedForSP < currentRound.fundBlock);
}

function updateFundingRoundBlockDiff(uint _newFundingRoundBlockDiff) external {
Expand Down
8 changes: 4 additions & 4 deletions eth-contracts/test/claimsManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ contract('ClaimsManager', async (accounts) => {
'Required block difference not met')
})

it('updates funding amount', async () => {
it('Updates funding amount', async () => {
let currentFunding = await claimsManager.getFundsPerRound()
let newAmount = _lib.audToWeiBN(1000)
assert.isTrue(!newAmount.eq(currentFunding), 'Expect change in funding value')
Expand All @@ -263,7 +263,7 @@ contract('ClaimsManager', async (accounts) => {
assert.isTrue(newAmount.eq(updatedFundingAmount), 'Expect updated funding amount')
})

it('updates fundRoundBlockDiff', async () => {
it('Updates fundRoundBlockDiff', async () => {
const curBlockDiff = await claimsManager.getFundingRoundBlockDiff.call()
const proposedBlockDiff = curBlockDiff.mul(_lib.toBN(2))
await _lib.assertRevert(
Expand All @@ -278,7 +278,7 @@ contract('ClaimsManager', async (accounts) => {
)
})

it('minimum bound violation during claim processing,', async () => {
it('Minimum bound violation during claim processing,', async () => {
let invalidAmount = _lib.audToWeiBN(5)
// Stake default amount
await approveTransferAndStake(invalidAmount, staker)
Expand All @@ -288,7 +288,7 @@ contract('ClaimsManager', async (accounts) => {
'Minimum stake bounds violated at fund block')
})

it('maximum bound violation during claim processing,', async () => {
it('Maximum bound violation during claim processing,', async () => {
// Exactly 1 AUD over max bound
let invalidAmount = _lib.audToWeiBN(1000001)
// Stake default amount
Expand Down