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

add setMinBalanceForTransfer, addBalances #73

Merged
merged 4 commits into from
Jan 10, 2024
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ will be called and the round finishes.

### `.setMaxTransfersPerTx(uint max)`

### `setMinBalanceForTransfer(uint min)`

### `addBalances(address[] addresses, uint[] balances)`

### `.releaseRewards()`

## Getters / Views
Expand Down
6 changes: 5 additions & 1 deletion src/Balances.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract Balances {
address payable[] public readyForTransfer;
address payable[] public scheduledForTransfer;
uint public maxTransfersPerTx = 10;
uint public constant minBalanceForTransfer = 0.5 ether;
uint public minBalanceForTransfer = 0.5 ether;

event Transfer(address indexed to, uint256 amount);
event TransferFailed(address indexed to, uint256 amount);
Expand Down Expand Up @@ -79,4 +79,8 @@ contract Balances {
function _setMaxTransfersPerTx(uint _maxTransfersPerTx) internal {
maxTransfersPerTx = _maxTransfersPerTx;
}

function _setMinBalanceForTransfer(uint _minBalanceForTransfer) internal {
minBalanceForTransfer = _minBalanceForTransfer;
}
}
24 changes: 24 additions & 0 deletions src/ImpactEvaluator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ contract ImpactEvaluator is AccessControl, Balances {
_setMaxTransfersPerTx(_maxTransfersPerTx);
}

function setMinBalanceForTransfer(
uint _minBalanceForTransfer
) public onlyAdmin {
_setMinBalanceForTransfer(_minBalanceForTransfer);
}

function addBalances(
address payable[] calldata addresses,
uint[] calldata _balances
) public payable onlyAdmin {
uint totalAmount = 0;
for (uint i = 0; i < _balances.length; i++) {
totalAmount += _balances[i];
}
require(
msg.value == totalAmount,
"Sum of balances must match msg.value"
);
for (uint i = 0; i < addresses.length; i++) {
increaseParticipantBalance(addresses[i], _balances[i]);
}
bajtos marked this conversation as resolved.
Show resolved Hide resolved
balanceHeld += totalAmount;
}

function tick() public {
if (block.number >= currentRoundEndBlockNumber) {
advanceRound();
Expand Down
42 changes: 42 additions & 0 deletions test/ImpactEvaluator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,46 @@ contract ImpactEvaluatorTest is Test {
impactEvaluator.setScores(1, addresses, scores);
}
}

function test_SetMinBalanceForTransfer() public {
ImpactEvaluator impactEvaluator = new ImpactEvaluator(address(this));
assertEq(impactEvaluator.minBalanceForTransfer(), 0.5 ether);
impactEvaluator.setMinBalanceForTransfer(1 ether);
assertEq(impactEvaluator.minBalanceForTransfer(), 1 ether);
impactEvaluator.setMinBalanceForTransfer(0);
assertEq(impactEvaluator.minBalanceForTransfer(), 0);
}

function test_SetMinBalanceForTransferNotAdmin() public {
ImpactEvaluator impactEvaluator = new ImpactEvaluator(address(0x1));
vm.expectRevert("Not an admin");
impactEvaluator.setMinBalanceForTransfer(1 ether);
}

function test_AddBalances() public {
ImpactEvaluator impactEvaluator = new ImpactEvaluator(address(this));

address payable[] memory addresses = new address payable[](2);
addresses[0] = payable(vm.addr(1));
addresses[1] = payable(vm.addr(2));
uint[] memory balances = new uint[](2);
balances[0] = 50 ether;
balances[1] = 50 ether;

vm.expectRevert("Sum of balances must match msg.value");
impactEvaluator.addBalances{ value: 0 }(addresses, balances);

impactEvaluator.addBalances{ value: 100 ether }(addresses, balances);
assertEq(
impactEvaluator.rewardsScheduledFor(addresses[0]),
50 ether,
"addresses[0] balance"
);
assertEq(
impactEvaluator.rewardsScheduledFor(addresses[1]),
50 ether,
"addresses[1] balance"
);
assertEq(impactEvaluator.balanceHeld(), 100 ether);
}
}