diff --git a/README.md b/README.md index 04cbeea..c8d0e3e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Balances.sol b/src/Balances.sol index 26502eb..7ea94f8 100644 --- a/src/Balances.sol +++ b/src/Balances.sol @@ -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); @@ -79,4 +79,8 @@ contract Balances { function _setMaxTransfersPerTx(uint _maxTransfersPerTx) internal { maxTransfersPerTx = _maxTransfersPerTx; } + + function _setMinBalanceForTransfer(uint _minBalanceForTransfer) internal { + minBalanceForTransfer = _minBalanceForTransfer; + } } diff --git a/src/ImpactEvaluator.sol b/src/ImpactEvaluator.sol index 1e82073..f6b4176 100644 --- a/src/ImpactEvaluator.sol +++ b/src/ImpactEvaluator.sol @@ -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]); + } + balanceHeld += totalAmount; + } + function tick() public { if (block.number >= currentRoundEndBlockNumber) { advanceRound(); diff --git a/test/ImpactEvaluator.t.sol b/test/ImpactEvaluator.t.sol index 8328f5f..6d989b3 100644 --- a/test/ImpactEvaluator.t.sol +++ b/test/ImpactEvaluator.t.sol @@ -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); + } }