diff --git a/packages/zen-bull-netting/test/ZenBullNettingBaseSetup.t.sol b/packages/zen-bull-netting/test/ZenBullNettingBaseSetup.t.sol index 03b503a5f..63a32ec34 100644 --- a/packages/zen-bull-netting/test/ZenBullNettingBaseSetup.t.sol +++ b/packages/zen-bull-netting/test/ZenBullNettingBaseSetup.t.sol @@ -7,6 +7,8 @@ import "forge-std/Test.sol"; import { console } from "forge-std/console.sol"; //interface import { IERC20 } from "openzeppelin/token/ERC20/IERC20.sol"; +import { IEulerSimpleLens } from "../src/interface/IEulerSimpleLens.sol"; + // contracts import { SigUtil } from "./util/SigUtil.sol"; import { ZenBullNetting } from "../src/ZenBullNetting.sol"; @@ -39,6 +41,17 @@ contract ZenBullNettingBaseSetup is Test { address public deployer; address public owner; + struct AddressBalances { + uint256 ethBalance; + uint256 usdcBalance; + uint256 wethBalance; + uint256 wPowerPerpBalance; + uint256 crabBalance; + uint256 zenBullBalance; + uint256 eulerUsdcDebtBalance; + uint256 eulerWethBalance; + } + function setUp() public virtual { string memory FORK_URL = vm.envString("FORK_URL"); vm.createSelectFork(FORK_URL, 16419302); @@ -114,6 +127,20 @@ contract ZenBullNettingBaseSetup is Test { ); } + + function _getAddressBalances(address _address) internal returns (AddressBalances memory) { + AddressBalances memory balances; + balances.ethBalance = _address.balance; + balances.usdcBalance = IERC20(USDC).balanceOf(_address); + balances.wethBalance = IERC20(WETH).balanceOf(_address); + balances.wPowerPerpBalance = IERC20(WPOWERPERP).balanceOf(_address); + balances.crabBalance = IERC20(CRAB).balanceOf(_address); + balances.zenBullBalance = IERC20(ZEN_BULL).balanceOf(_address); + balances.eulerUsdcDebtBalance = IEulerSimpleLens(EULER_SIMPLE_LENS).getDTokenBalance(USDC, _address); + balances.eulerWethBalance = IEulerSimpleLens(EULER_SIMPLE_LENS).getETokenBalance(WETH, _address); + return balances; + } + function _calcCrabSharesToMint( uint256 _ethAmount, uint256 _crabCollateral, diff --git a/packages/zen-bull-netting/test/integration-test/ZenBullNetting/DepositAuction.t.sol b/packages/zen-bull-netting/test/integration-test/ZenBullNetting/DepositAuction.t.sol index 35c481ca4..920d0d730 100644 --- a/packages/zen-bull-netting/test/integration-test/ZenBullNetting/DepositAuction.t.sol +++ b/packages/zen-bull-netting/test/integration-test/ZenBullNetting/DepositAuction.t.sol @@ -78,6 +78,11 @@ contract DepositAuction is ZenBullNettingBaseSetup { } function testFullDepositAuction() public { + AddressBalances memory user1BalancesBefore = _getAddressBalances(user1); + AddressBalances memory mm1BalancesBefore = _getAddressBalances(mm1); + AddressBalances memory zenBullBalancesBefore = _getAddressBalances(ZEN_BULL); + + uint256 amount = 10e18; _queueEth(user1, amount); @@ -175,17 +180,60 @@ contract DepositAuction is ZenBullNettingBaseSetup { zenBullNetting.depositAuction(params); vm.stopPrank(); - uint256 wPowerPerpTotalSupplyAfter = IERC20(WPOWERPERP).totalSupply(); + AddressBalances memory user1BalancesAfter = _getAddressBalances(user1); + AddressBalances memory mm1BalancesAfter = _getAddressBalances(mm1); + AddressBalances memory zenBullBalancesAfter = _getAddressBalances(ZEN_BULL); - assertEq( - IERC20(WPOWERPERP).balanceOf(mm1) - mm1WpowerPerpBalanceBefore, - wPowerPerpTotalSupplyAfter - wPowerPerpTotalSupplyBefore + // Depositor gets bull + assertApproxEqAbs( + user1BalancesAfter.zenBullBalance - user1BalancesBefore.zenBullBalance , + bullToMint, 2000 + ); + + // Depositor pays eth + assertApproxEqAbs( + user1BalancesAfter.ethBalance - user1BalancesBefore.ethBalance , + amount, 2000 ); + console.log(user1BalancesAfter.ethBalance - user1BalancesBefore.ethBalance ); + + // MM gets osqth (stack too deep) + assertApproxEqAbs( + mm1BalancesAfter.wPowerPerpBalance - mm1BalancesBefore.wPowerPerpBalance, + oSqthAmount, + 2000 + ); + console.log(mm1BalancesAfter.wPowerPerpBalance - mm1BalancesBefore.wPowerPerpBalance); + console.log(oSqthAmount); + + // mm pays weth (stack too deep) + assertApproxEqAbs( + mm1BalancesAfter.wethBalance - mm1BalancesBefore.wethBalance, + oSqthAmount * params.clearingPrice / 1e18, + 2000 + ); + console.log(mm1BalancesBefore.wethBalance -mm1BalancesAfter.wethBalance); + + assertGt(user1.balance, user1BalancesBefore.ethBalance); + // Euler eth balance changes as expected + assertApproxEqAbs( + zenBullBalancesAfter.eulerWethBalance - zenBullBalancesBefore.eulerWethBalance, + wethToLend, + 2000 + ); + + assertGt(user1.balance, user1EthBalanceBefore); assertEq( IEulerSimpleLens(EULER_SIMPLE_LENS).getETokenBalance(WETH, ZEN_BULL) - wethInEulerBefore, wethToLend ); + // Euler usdc balance changes as expected + assertApproxEqAbs( + zenBullBalancesAfter.eulerUsdcDebtBalance - zenBullBalancesBefore.eulerUsdcDebtBalance, + usdcToBorrow, + 1 + ); } function testPartialDepositAuction() public { diff --git a/packages/zen-bull-netting/test/integration-test/ZenBullNetting/tmp.sol b/packages/zen-bull-netting/test/integration-test/ZenBullNetting/tmp.sol new file mode 100644 index 000000000..e69de29bb