Skip to content

Commit

Permalink
fixing lint issue, add test for 6% protocol fee, 4% operator
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Jun 28, 2024
1 parent 6ad9ef1 commit 315b0d7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
8 changes: 4 additions & 4 deletions contracts/PoolUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 47 additions & 1 deletion test/foundry_tests/PoolUtils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 315b0d7

Please sign in to comment.