diff --git a/contracts/integrations/contracts/test/TestFramework.sol b/contracts/integrations/contracts/test/TestFramework.sol index e8bf6cfdad..6eb019e8fb 100644 --- a/contracts/integrations/contracts/test/TestFramework.sol +++ b/contracts/integrations/contracts/test/TestFramework.sol @@ -20,12 +20,14 @@ contract TestFramework { function emptyRevert() external + pure { revert(); } function stringRevert(string calldata message) external + pure { revert(message); } diff --git a/contracts/integrations/test/internal-integration-tests/fillorder_test.ts b/contracts/integrations/test/internal-integration-tests/fillorder_test.ts index ea8f866753..0405538bcd 100644 --- a/contracts/integrations/test/internal-integration-tests/fillorder_test.ts +++ b/contracts/integrations/test/internal-integration-tests/fillorder_test.ts @@ -327,4 +327,46 @@ blockchainTests.resets('fillOrder integration tests', env => { const poolStats = await deployment.staking.stakingWrapper.getStakingPoolStatsThisEpoch.callAsync(poolId); expect(poolStats.feesCollected).to.bignumber.equal(DeploymentManager.protocolFee); }); + it('should collect WETH fees and pay out rewards', async () => { + // Operator and delegator each stake some ZRX; wait an epoch so that the stake is active. + await operator.stakeAsync(toBaseUnitAmount(100), poolId); + await delegator.stakeAsync(toBaseUnitAmount(50), poolId); + await delegator.endEpochAsync(); + + // Fetch the current balances + await balanceStore.updateBalancesAsync(); + + // Create and fill the order. One order's worth of protocol fees are now available as rewards. + const order = await maker.signOrderAsync(); + const receipt = await taker.fillOrderAsync(order, order.takerAssetAmount, { value: constants.ZERO_AMOUNT }); + const rewardsAvailable = DeploymentManager.protocolFee; + const expectedBalances = simulateFill(order, receipt, constants.ZERO_AMOUNT); + + // End the epoch. This should wrap the staking proxy's ETH balance. + const endEpochReceipt = await delegator.endEpochAsync(); + + // Check balances + expectedBalances.burnGas(delegator.address, DeploymentManager.gasPrice.times(endEpochReceipt.gasUsed)); + await balanceStore.updateBalancesAsync(); + balanceStore.assertEquals(expectedBalances); + + // The rewards are split between the operator and delegator based on the pool's operatorShare + const operatorReward = rewardsAvailable + .times(operator.operatorShares[poolId]) + .dividedToIntegerBy(constants.PPM_DENOMINATOR); + + // Finalize the pool. This should automatically pay the operator in WETH. + const [finalizePoolReceipt] = await delegator.finalizePoolsAsync([poolId]); + + // Check balances + expectedBalances.transferAsset( + deployment.staking.stakingProxy.address, + operator.address, + operatorReward, + assetDataUtils.encodeERC20AssetData(deployment.tokens.weth.address), + ); + expectedBalances.burnGas(delegator.address, DeploymentManager.gasPrice.times(finalizePoolReceipt.gasUsed)); + await balanceStore.updateBalancesAsync(); + balanceStore.assertEquals(expectedBalances); + }); }); diff --git a/contracts/integrations/test/utils/deployment_manager.ts b/contracts/integrations/test/utils/deployment_manager.ts index 049e46efcc..876a574032 100644 --- a/contracts/integrations/test/utils/deployment_manager.ts +++ b/contracts/integrations/test/utils/deployment_manager.ts @@ -362,11 +362,7 @@ export class DeploymentManager { stakingLogic.address, ); - const stakingWrapper = new TestStakingContract( - stakingProxy.address, - environment.provider, - txDefaults, - ); + const stakingWrapper = new TestStakingContract(stakingProxy.address, environment.provider, txDefaults); // Add the zrx vault and the weth contract to the staking proxy. await stakingWrapper.setWethContract.awaitTransactionSuccessAsync(tokens.weth.address, { from: owner });