Skip to content

Commit

Permalink
Added events for the exit fee and credit rate (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Jul 23, 2020
1 parent ebcacd8 commit 41bd925
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
37 changes: 33 additions & 4 deletions contracts/prize-strategy/PrizeStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,32 @@ contract PrizeStrategy is PrizeStrategyStorage,
uint256 constant private MAX_TREE_LEAVES = 5;
uint256 internal constant ETHEREUM_BLOCK_TIME_ESTIMATE_MANTISSA = 13.4 ether;

event PrizePoolOpened(address indexed operator, uint256 indexed prizePeriodStartedAt);
event PrizePoolAwardStarted(address indexed operator, address indexed prizePool, uint32 indexed rngRequestId, uint32 rngLockBlock);
event PrizePoolAwarded(address indexed operator, uint256 prize, uint256 reserveFee);
event PrizePoolOpened(
address indexed operator,
uint256 indexed prizePeriodStartedAt
);

event PrizePoolAwardStarted(
address indexed operator,
address indexed prizePool,
uint32 indexed rngRequestId,
uint32 rngLockBlock
);

event PrizePoolAwarded(
address indexed operator,
uint256 randomNumber,
uint256 prize,
uint256 reserveFee
);

event ExitFeeUpdated(
uint256 exitFeeMantissa
);

event CreditRateUpdated(
uint256 creditRateMantissa
);

function initialize (
address _trustedForwarder,
Expand Down Expand Up @@ -81,6 +104,8 @@ contract PrizeStrategy is PrizeStrategyStorage,
exitFeeMantissa = _exitFeeMantissa;
creditRateMantissa = _creditRateMantissa;

emit ExitFeeUpdated(exitFeeMantissa);
emit CreditRateUpdated(creditRateMantissa);
emit PrizePoolOpened(_msgSender(), prizePeriodStartedAt);
}

Expand Down Expand Up @@ -607,7 +632,7 @@ contract PrizeStrategy is PrizeStrategyStorage,

prizePeriodStartedAt = _currentTime();

emit PrizePoolAwarded(_msgSender(), prize, reserveFee);
emit PrizePoolAwarded(_msgSender(), randomNumber, prize, reserveFee);
emit PrizePoolOpened(_msgSender(), prizePeriodStartedAt);
}

Expand Down Expand Up @@ -638,12 +663,16 @@ contract PrizeStrategy is PrizeStrategyStorage,
/// @param _exitFeeMantissa The exit fee to set
function setExitFeeMantissa(uint256 _exitFeeMantissa) external onlyOwner {
exitFeeMantissa = _exitFeeMantissa;

emit ExitFeeUpdated(exitFeeMantissa);
}

/// @notice Sets the rate at which credit accrues per second. The credit rate is a fixed point 18 number (like Ether).
/// @param _creditRateMantissa The credit rate to set
function setCreditRateMantissa(uint256 _creditRateMantissa) external onlyOwner {
creditRateMantissa = _creditRateMantissa;

emit CreditRateUpdated(creditRateMantissa);
}

function _requireNotLocked() internal view {
Expand Down
26 changes: 26 additions & 0 deletions test/PrizeStrategy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ describe('PrizeStrategy', function() {
})
})

describe('setCreditRateMantissa', () => {
it('should only allow the owner to change it', async () => {
await expect(prizeStrategy.setCreditRateMantissa(toWei('0.1')))
.to.emit(prizeStrategy, 'CreditRateUpdated')
.withArgs(toWei('0.1'))
})

it('should not allow anyone but the owner to change', async () => {
prizeStrategy2 = prizeStrategy.connect(wallet2)
await expect(prizeStrategy2.setCreditRateMantissa(toWei('0.1'))).to.be.revertedWith('Ownable: caller is not the owner')
})
})

describe('setExitFeeMantissa', () => {
it('should only allow the owner to change it', async () => {
await expect(prizeStrategy.setExitFeeMantissa(toWei('0.1')))
.to.emit(prizeStrategy, 'ExitFeeUpdated')
.withArgs(toWei('0.1'))
})

it('should not allow anyone but the owner to change', async () => {
prizeStrategy2 = prizeStrategy.connect(wallet2)
await expect(prizeStrategy2.setExitFeeMantissa(toWei('0.1'))).to.be.revertedWith('Ownable: caller is not the owner')
})
})

describe('estimatePrizeWithBlockTime()', () => {
it('should calculate the estimated prize', async () => {
await prizeStrategy.setCurrentTime(await prizeStrategy.prizePeriodStartedAt())
Expand Down

0 comments on commit 41bd925

Please sign in to comment.