Skip to content

Commit

Permalink
reward: use address#send(), add events
Browse files Browse the repository at this point in the history
Based on #15
  • Loading branch information
juliangruber committed Sep 12, 2023
1 parent 9242c15 commit 6b187da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

### `MeasurementsAdded(string cid, uint roundIndex)`
### `RoundStart(uint roundIndex)`
### `Transfer(address indexed to, uint256 amount)`
### `TransferFailed(address indexed to, uint256 amount)`

## Structs

Expand Down
9 changes: 8 additions & 1 deletion src/ImpactEvaluator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ contract ImpactEvaluator is AccessControl {

event MeasurementsAdded(string cid, uint roundIndex);
event RoundStart(uint roundIndex);
event Transfer(address indexed to, uint256 amount);
event TransferFailed(address indexed to, uint256 amount);

bytes32 public constant EVALUATE_ROLE = keccak256("EVALUATE_ROLE");

Expand Down Expand Up @@ -99,7 +101,12 @@ contract ImpactEvaluator is AccessControl {
for (uint i = 0; i < addresses.length; i++) {
address payable addr = addresses[i];
uint score = scores[i];
addr.transfer((score / 1000000000000000) * roundReward);
uint256 amount = (score / 1000000000000000) * roundReward;
if (addr.send(amount)) {
emit Transfer(addr, amount);
} else {
emit TransferFailed(addr, amount);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions test/ImpactEvaluator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "../src/ImpactEvaluator.sol";
contract ImpactEvaluatorTest is Test {
event RoundStart(uint roundIndex);
event MeasurementsAdded(string cid, uint roundIndex);
event Transfer(address indexed to, uint256 amount);

function test_AdvanceRound() public {
ImpactEvaluator impactEvaluator = new ImpactEvaluator(address(this));
Expand Down Expand Up @@ -93,6 +94,8 @@ contract ImpactEvaluatorTest is Test {
uint[] memory scores = new uint[](1);
scores[0] = 1000000000000000;
vm.deal(payable(address(impactEvaluator)), 100);
vm.expectEmit(false, false, false, true);
emit Transfer(addresses[0], 100);
impactEvaluator.setScores(0, addresses, scores, "1 task performed");
assertEq(addresses[0].balance, 100);

Expand Down

0 comments on commit 6b187da

Please sign in to comment.