From c7966fcbd442cdb1abd51d0f3265f665342bf7b7 Mon Sep 17 00:00:00 2001 From: Ewan Sheldon Date: Mon, 21 Oct 2024 16:25:31 +0200 Subject: [PATCH] correct smart vault withdrawal test to account for protocol + uniswap fees --- test/foundry/SmartVault.t.sol | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/foundry/SmartVault.t.sol b/test/foundry/SmartVault.t.sol index 895f13e..4fa31ac 100644 --- a/test/foundry/SmartVault.t.sol +++ b/test/foundry/SmartVault.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.21; -import {Test, stdError} from "forge-std/Test.sol"; +import {Test, stdError, console} from "forge-std/Test.sol"; import {IHypervisor} from "contracts/interfaces/IHypervisor.sol"; import {ERC20Mock} from "src/test_utils/ERC20Mock.sol"; @@ -454,7 +454,11 @@ contract SmartVaultTest is SmartVaultFixture, Test { emit Withdraw(address(smartVault), address(weth), address(usdsHypervisor), 0); smartVault.withdrawYield(address(usdsHypervisor), NATIVE, 5e4, block.timestamp + 60); vm.stopPrank(); - assertGt(address(smartVault).balance, nativeAmount + wethAmount - nativeBefore); + uint256 fee = (nativeAmount + wethAmount) * PROTOCOL_FEE_RATE / 1e5; + uint256 maxUniswapFee = (nativeAmount + wethAmount) * 3000 / 1e6; + assertGt(address(smartVault).balance, nativeAmount + wethAmount - nativeBefore - fee - maxUniswapFee); + // approx assertion (1%) because there is some loss with uniswap fees + assertApproxEqAbs(weth.balanceOf(PROTOCOL), fee, fee / 100); } function test_yieldCollateralCheck() public {