diff --git a/contracts/PoolUtils.sol b/contracts/PoolUtils.sol index b25c8743..38a928e4 100644 --- a/contracts/PoolUtils.sol +++ b/contracts/PoolUtils.sol @@ -239,17 +239,17 @@ contract PoolUtils is IPoolUtils, AccessControlUpgradeable { uint8 _poolId, uint256 _totalRewards ) external view override returns (uint256 userShare, uint256 operatorShare, uint256 protocolShare) { - uint256 TOTAL_STAKED_ETH = staderConfig.getStakedEthPerNode(); + uint256 totalStakedEth = staderConfig.getStakedEthPerNode(); uint256 collateralETH = getCollateralETH(_poolId); - uint256 usersETH = TOTAL_STAKED_ETH - collateralETH; + uint256 usersETH = totalStakedEth - collateralETH; uint256 protocolFeeBps = getProtocolFee(_poolId); uint256 operatorFeeBps = getOperatorFee(_poolId); - uint256 _userShareBeforeCommission = (_totalRewards * usersETH) / TOTAL_STAKED_ETH; + uint256 _userShareBeforeCommission = (_totalRewards * usersETH) / totalStakedEth; protocolShare = (protocolFeeBps * _userShareBeforeCommission) / staderConfig.getTotalFee(); - operatorShare = (_totalRewards * collateralETH) / TOTAL_STAKED_ETH; + operatorShare = (_totalRewards * collateralETH) / totalStakedEth; operatorShare += (operatorFeeBps * _userShareBeforeCommission) / staderConfig.getTotalFee(); userShare = _totalRewards - protocolShare - operatorShare; diff --git a/test/foundry_tests/PoolUtils.t.sol b/test/foundry_tests/PoolUtils.t.sol index 3c65d300..e7f10ddc 100644 --- a/test/foundry_tests/PoolUtils.t.sol +++ b/test/foundry_tests/PoolUtils.t.sol @@ -407,7 +407,7 @@ contract PoolUtilsTest is Test { poolUtils.onlyValidKeys(pubkey, preDepositSig, depositSig); } - function test_calculateRewardShare() public { + function testCalculateRewardShare() public { address permissionedPool = vm.addr(105); address permissionedNodeRegistry = vm.addr(106); vm.mockCall( @@ -461,4 +461,50 @@ contract PoolUtilsTest is Test { assertEq(operatorShareP2, 0.05 ether); assertEq(protocolShareP2, 0.05 ether); } + + // check commission fee for a 6% protocol and 4% operator fee + function testCalculateRewardShare6_4_90() public { + address permissionedPool = vm.addr(105); + address permissionedNodeRegistry = vm.addr(106); + vm.mockCall( + address(permissionedPool), + abi.encodeWithSelector(IStaderPoolBase.getNodeRegistry.selector), + abi.encode(permissionedNodeRegistry) + ); + vm.mockCall( + address(permissionedPool), + abi.encodeWithSelector(IStaderPoolBase.protocolFee.selector), + abi.encode(600) + ); + + vm.mockCall( + address(permissionedPool), + abi.encodeWithSelector(IStaderPoolBase.operatorFee.selector), + abi.encode(400) + ); + + vm.mockCall( + address(permissionedNodeRegistry), + abi.encodeWithSelector(INodeRegistry.POOL_ID.selector), + abi.encode(2) + ); + + vm.mockCall( + address(permissionedNodeRegistry), + abi.encodeWithSelector(INodeRegistry.getCollateralETH.selector), + abi.encode(0) + ); + + vm.startPrank(staderAdmin); + poolUtils.addNewPool(2, permissionedPool); + + (uint256 userShareP2, uint256 operatorShareP2, uint256 protocolShareP2) = poolUtils.calculateRewardShare( + 2, + 1 ether + ); + + assertEq(userShareP2, 0.9 ether); + assertEq(operatorShareP2, 0.04 ether); + assertEq(protocolShareP2, 0.06 ether); + } }