Skip to content

Commit

Permalink
Added 75% of rewardsdistributor
Browse files Browse the repository at this point in the history
  • Loading branch information
alsco77 committed Jun 18, 2020
1 parent d9029d1 commit da66746
Show file tree
Hide file tree
Showing 7 changed files with 818 additions and 298 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="https://mstable.org/assets/img/email/mstable_logo_horizontal_black.png" width="420" >

[![CircleCI](https://circleci.com/gh/mstable/mStable-contracts.svg?style=svg&circle-token=a8bb29a97a0a0949a15cc28bd9b2245960287bc2)](https://circleci.com/gh/mstable/mStable-contracts)
[![Coverage Status](https://coveralls.io/repos/github/mstable/mStable-contracts/badge.svg?t=7A5XxE)](https://coveralls.io/github/mstable/mStable-contracts)
[![Coverage Status](https://coveralls.io/repos/github/mstable/mStable-contracts/badge.svg?branch=master)](https://coveralls.io/github/mstable/mStable-contracts?branch=master)
[![Discord](https://img.shields.io/discord/525087739801239552?color=7289DA&label=discord%20)](https://discordapp.com/channels/525087739801239552/)


Expand Down
9 changes: 6 additions & 3 deletions contracts/rewards/RewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ contract RewardsDistributor is InitializableGovernableWhitelist {
using SafeERC20 for IERC20;

event RemovedFundManager(address indexed _address);
event DistributedReward(address funder, address recipient, address rewardToken, uint256 amount);

/** @dev Recipient is a module, governed by mStable governance */
constructor(
Expand All @@ -32,7 +33,7 @@ contract RewardsDistributor is InitializableGovernableWhitelist {
* @param _address FundManager to add
*/
function addFundManager(address _address)
internal
external
onlyGovernor
{
_addWhitelist(_address);
Expand All @@ -43,7 +44,7 @@ contract RewardsDistributor is InitializableGovernableWhitelist {
* @param _address FundManager to remove
*/
function removeFundManager(address _address)
internal
external
onlyGovernor
{
require(_address != address(0), "Address is zero");
Expand Down Expand Up @@ -77,8 +78,10 @@ contract RewardsDistributor is InitializableGovernableWhitelist {
// Send the RewardToken to recipient
IERC20 rewardToken = recipient.getRewardToken();
rewardToken.safeTransferFrom(msg.sender, address(recipient), amount);
// Notify the contract of the new funds
// Only after successfull tx - notify the contract of the new funds
recipient.notifyRewardAmount(amount);

emit DistributedReward(msg.sender, address(recipient), address(rewardToken), amount);
}
}
}
23 changes: 23 additions & 0 deletions contracts/z_mocks/rewards/MockRewardsDistributionRecipient.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity 0.5.16;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IRewardsDistributionRecipient } from "../../interfaces/IRewardsDistributionRecipient.sol";

contract MockRewardsDistributionRecipient is IRewardsDistributionRecipient {

IERC20 public rewardToken;

constructor(IERC20 _rewardToken) public {
rewardToken = _rewardToken;
}

function notifyRewardAmount(uint256 reward)
external
{
// do nothing
}

function getRewardToken() external returns (IERC20) {
return rewardToken;
}
}
3 changes: 3 additions & 0 deletions test-utils/machines/standardAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class StandardAccounts {

public fundManager: Address;

public fundManager2: Address;

constructor(accounts: Address[]) {
this.all = accounts;

Expand All @@ -37,6 +39,7 @@ export class StandardAccounts {
this.dummy3,
this.dummy4,
this.fundManager,
this.fundManager2,
] = accounts;
}
}
Expand Down
12 changes: 9 additions & 3 deletions test/meta-token/TestMetaToken.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expectRevert } from "@openzeppelin/test-helpers";
import { expectEvent, expectRevert } from "@openzeppelin/test-helpers";

import { StandardAccounts, SystemMachine } from "@utils/machines";
import { simpleToExactAmount } from "@utils/math";
Expand Down Expand Up @@ -97,7 +97,10 @@ contract("MetaToken", async (accounts) => {
});
it("should allow the governor to add a minter", async () => {
expect(await meta.isMinter(sa.dummy1)).eq(false);
await meta.addMinter(sa.dummy1, { from: sa.governor });
const tx = await meta.addMinter(sa.dummy1, { from: sa.governor });
expectEvent(tx.receipt, "MinterAdded", {
account: sa.dummy1,
});
expect(await meta.isMinter(sa.dummy1)).eq(true);
});
it("should not allow minters to remove minters", async () => {
Expand All @@ -121,7 +124,10 @@ contract("MetaToken", async (accounts) => {
await meta.addMinter(sa.dummy1, { from: sa.governor });
expect(await meta.isMinter(sa.dummy1)).eq(true);
// Minter or other cannot remove role
await meta.removeMinter(sa.dummy1, { from: sa.governor });
const tx = await meta.removeMinter(sa.dummy1, { from: sa.governor });
expectEvent(tx.receipt, "MinterRemoved", {
account: sa.dummy1,
});
expect(await meta.isMinter(sa.dummy1)).eq(false);
});
it("should allow a minter to renounce their minting ability", async () => {
Expand Down

0 comments on commit da66746

Please sign in to comment.