Skip to content

Commit a81004a

Browse files
committed
more fuzz tests
1 parent fc1a7ee commit a81004a

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

src/MaglevEulerSwap.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ contract MaglevEulerSwap is MaglevBase {
3333
_cy = params.cy;
3434
}
3535

36-
// FIXME: how to charge fees?
3736
function verify(uint256, uint256, uint256 newReserve0, uint256 newReserve1) internal view virtual override {
3837
int256 delta = 0;
3938

test/ConstantProduct.t.sol

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,41 @@ contract ConstantProductTest is MaglevTestBase {
100100
uint256 q2 = maglev.quoteExactInput(address(t1), address(t2), amount);
101101
assertApproxEqAbs(q, q2, 2);
102102
}
103+
104+
function test_fuzzAll(uint256 fee, uint256[8] calldata amounts, bool[8] calldata dirs) public {
105+
fee = bound(fee, 0, 0.1e18);
106+
107+
createMaglev(50e18, 50e18, fee);
108+
109+
int256 origNAV = getHolderNAV();
110+
111+
for (uint256 i = 0; i < 8; i++) {
112+
uint256 amount = bound(amounts[i], 0.1e18, 5e18);
113+
bool dir = dirs[i];
114+
115+
TestERC20 t1;
116+
TestERC20 t2;
117+
if (dir) (t1, t2) = (assetTST, assetTST2);
118+
else (t1, t2) = (assetTST2, assetTST);
119+
120+
t1.mint(address(this), amount);
121+
uint256 q = maglev.quoteExactInput(address(t1), address(t2), amount);
122+
123+
t1.transfer(address(maglev), amount);
124+
125+
{
126+
uint256 qPlus = q + 1;
127+
vm.expectRevert();
128+
if (dir) maglev.swap(0, qPlus, address(this), "");
129+
else maglev.swap(qPlus, 0, address(this), "");
130+
}
131+
132+
uint256 prevBal = t2.balanceOf(address(this));
133+
if (dir) maglev.swap(0, q, address(this), "");
134+
else maglev.swap(q, 0, address(this), "");
135+
assertEq(t2.balanceOf(address(this)), q + prevBal);
136+
137+
assertGe(getHolderNAV(), origNAV);
138+
}
139+
}
103140
}

test/ConstantSum.t.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ contract ConstantSumTest is MaglevTestBase {
170170

171171
uint256 feeMultiplier = 1e18 - fee;
172172
uint256 needed = (amount1 * 1e18 + (feeMultiplier - 1)) / feeMultiplier;
173-
console.log(amount1, needed, fee);
174173

175174
TestERC20 tt;
176175
TestERC20 tt2;

test/EulerSwap.t.sol

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,43 @@ contract EulerSwapTest is MaglevTestBase {
166166
maglev.swap(0, amountOut, address(this), "");
167167
assertEq(assetTST2.balanceOf(address(this)), amountOut);
168168
}
169+
170+
function test_fuzzAll(uint256 cx, uint256 cy, uint256 fee, uint256[8] calldata amounts, bool[8] calldata dirs) public {
171+
cx = bound(cx, 0.01e18, 0.99e18);
172+
cy = bound(cy, 0.01e18, 0.99e18);
173+
fee = bound(fee, 0, 0.1e18);
174+
175+
createMaglev(50e18, 50e18, fee, 1e18, 1e18, cx, cy);
176+
177+
int256 origNAV = getHolderNAV();
178+
179+
for (uint256 i = 0; i < 8; i++) {
180+
uint256 amount = bound(amounts[i], 0.1e18, 5e18);
181+
bool dir = dirs[i];
182+
183+
TestERC20 t1;
184+
TestERC20 t2;
185+
if (dir) (t1, t2) = (assetTST, assetTST2);
186+
else (t1, t2) = (assetTST2, assetTST);
187+
188+
t1.mint(address(this), amount);
189+
uint256 q = maglev.quoteExactInput(address(t1), address(t2), amount);
190+
191+
t1.transfer(address(maglev), amount);
192+
193+
{
194+
uint256 qPlus = q * 1.0000000000002e18 / 1e18;
195+
vm.expectRevert();
196+
if (dir) maglev.swap(0, qPlus, address(this), "");
197+
else maglev.swap(qPlus, 0, address(this), "");
198+
}
199+
200+
uint256 prevBal = t2.balanceOf(address(this));
201+
if (dir) maglev.swap(0, q, address(this), "");
202+
else maglev.swap(q, 0, address(this), "");
203+
assertEq(t2.balanceOf(address(this)), q + prevBal);
204+
205+
assertGe(getHolderNAV(), origNAV);
206+
}
207+
}
169208
}

0 commit comments

Comments
 (0)