Skip to content

Commit 561c50e

Browse files
committed
nav fuzz testing
1 parent f9efe92 commit 561c50e

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

test/EulerSwap.t.sol

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,51 @@ contract EulerSwapTest is MaglevTestBase {
6161

6262
t2.transfer(address(maglev), q);
6363
if (dir) maglev.swap(amount - 2, 0, address(this), ""); // - 2 due to rounding
64-
6564
else maglev.swap(0, amount - 2, address(this), "");
6665

6766
uint256 q2 = maglev.quoteExactInput(address(t1), address(t2), amount);
6867
assertApproxEqAbs(q, q2, 0.00000001e18);
6968
}
69+
70+
function test_fuzzParams(uint256 amount, uint256 amount2, uint256 px, uint256 py, uint256 cx, uint256 cy, bool dir) public {
71+
amount = bound(amount, 0.1e18, 25e18);
72+
amount2 = bound(amount2, 0.1e18, 25e18);
73+
px = bound(px, 1e18, 1e18);
74+
py = bound(py, 1e18, 1e18);
75+
cx = bound(cx, 0.01e18, 0.99e18);
76+
cy = bound(cy, 0.01e18, 0.99e18);
77+
78+
int256 origNav = getHolderNAV();
79+
80+
vm.prank(owner);
81+
maglev.setEulerSwapParams(Maglev.EulerSwapParams({
82+
px: px,
83+
py: py,
84+
cx: cx,
85+
cy: cy
86+
}));
87+
88+
TestERC20 t1;
89+
TestERC20 t2;
90+
if (dir) (t1, t2) = (assetTST, assetTST2);
91+
else (t1, t2) = (assetTST2, assetTST);
92+
93+
t1.mint(address(this), amount);
94+
uint256 q = maglev.quoteExactInput(address(t1), address(t2), amount);
95+
96+
t1.transfer(address(maglev), amount);
97+
if (dir) maglev.swap(0, q, address(this), "");
98+
else maglev.swap(q, 0, address(this), "");
99+
assertEq(t2.balanceOf(address(this)), q);
100+
101+
t2.mint(address(this), amount2);
102+
uint256 q2 = maglev.quoteExactInput(address(t2), address(t1), amount2);
103+
104+
t2.transfer(address(maglev), amount2);
105+
if (dir) maglev.swap(q2, 0, address(this), "");
106+
else maglev.swap(0, q2, address(this), "");
107+
assertEq(t1.balanceOf(address(this)), q2);
108+
109+
assertGe(getHolderNAV(), origNav);
110+
}
70111
}

test/MaglevTestBase.t.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ contract MaglevTestBase is EVaultTestBase {
5858
vault.deposit(amount, who);
5959
}
6060

61+
function getHolderNAV() public view returns (int256) {
62+
uint256 balance0 = eTST.convertToAssets(eTST.balanceOf(holder));
63+
uint256 debt0 = eTST.debtOf(holder);
64+
uint256 balance1 = eTST2.convertToAssets(eTST2.balanceOf(holder));
65+
uint256 debt1 = eTST2.debtOf(holder);
66+
67+
uint256 balValue = oracle.getQuote(balance0, address(assetTST), unitOfAccount) + oracle.getQuote(balance1, address(assetTST2), unitOfAccount);
68+
uint256 debtValue = oracle.getQuote(debt0, address(assetTST), unitOfAccount) + oracle.getQuote(debt1, address(assetTST2), unitOfAccount);
69+
70+
return int(balValue) - int(debtValue);
71+
}
72+
6173
function logState(address ml) internal view {
6274
console.log("--------------------");
6375
console.log("Account States:");

0 commit comments

Comments
 (0)