Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Testing: extra asserts #983

Open
wants to merge 2 commits into
base: fix/internal-audit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/zen-bull-netting/test/ZenBullNettingBaseSetup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down
Empty file.