Skip to content

Commit 635a8df

Browse files
committed
pricing tests
1 parent 561c50e commit 635a8df

File tree

4 files changed

+56
-15
lines changed

4 files changed

+56
-15
lines changed

test/ConstantProduct.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ contract ConstantProductTest is MaglevTestBase {
2929
maglev.setDebtLimit(50e18, 50e18);
3030
}
3131

32-
function test_fee_exactIn(uint256 amount, bool dir) public {
32+
function test_fee_exactIn(uint256 amount, bool dir) public monotonicHolderNAV {
3333
amount = bound(amount, 0.1e18, 25e18);
3434

3535
TestERC20 t1;
@@ -53,7 +53,7 @@ contract ConstantProductTest is MaglevTestBase {
5353
assertEq(t2.balanceOf(address(this)), q);
5454
}
5555

56-
function test_pathIndependent(uint256 amount, bool dir) public {
56+
function test_pathIndependent(uint256 amount, bool dir) public monotonicHolderNAV {
5757
amount = bound(amount, 0.1e18, 25e18);
5858

5959
TestERC20 t1;

test/ConstantSum.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ contract ConstantSumTest is MaglevTestBase {
2929
maglev.setDebtLimit(50e18, 50e18);
3030
}
3131

32-
function test_basicSwapReport() public {
32+
function test_basicSwapReport() public monotonicHolderNAV {
3333
uint256 amount = 25e18;
3434
assetTST.mint(address(this), amount);
3535

@@ -52,7 +52,7 @@ contract ConstantSumTest is MaglevTestBase {
5252
logState(address(maglev));
5353
}
5454

55-
function test_reserveLimit() public {
55+
function test_reserveLimit() public monotonicHolderNAV {
5656
assertEq(maglev.initialReserve0(), 60e18);
5757
assertEq(maglev.initialReserve1(), 60e18);
5858
assertEq(maglev.reserve0(), 60e18);
@@ -112,7 +112,7 @@ contract ConstantSumTest is MaglevTestBase {
112112
assertEq(maglev.reserve1(), 0e18); // can't go below 0
113113
}
114114

115-
function test_basicSwapFuzz(uint256 amount1, uint256 amount2) public {
115+
function test_basicSwapFuzz(uint256 amount1, uint256 amount2) public monotonicHolderNAV {
116116
amount1 = bound(amount1, 1e18, 25e18);
117117
amount2 = bound(amount2, 1e18, 50e18);
118118

@@ -129,7 +129,7 @@ contract ConstantSumTest is MaglevTestBase {
129129
assertEq(assetTST2.balanceOf(address(this)), amount1);
130130
}
131131

132-
function test_quoteExactInput() public {
132+
function test_quoteExactInput() public monotonicHolderNAV {
133133
vm.prank(owner);
134134
maglev.setConstantSumParams(Maglev.ConstantSumParams({fee: 0.003e18, priceA: 1, priceB: 1}));
135135

@@ -142,7 +142,7 @@ contract ConstantSumTest is MaglevTestBase {
142142
assertEq(assetTST2.balanceOf(recipient), q);
143143
}
144144

145-
function test_quoteExactOutput() public {
145+
function test_quoteExactOutput() public monotonicHolderNAV {
146146
vm.prank(owner);
147147
maglev.setConstantSumParams(Maglev.ConstantSumParams({fee: 0.003e18, priceA: 1, priceB: 1}));
148148

@@ -156,7 +156,7 @@ contract ConstantSumTest is MaglevTestBase {
156156
assertEq(assetTST2.balanceOf(recipient), 1e18);
157157
}
158158

159-
function test_fees(uint256 fee, uint256 amount1, bool token0) public {
159+
function test_fees(uint256 fee, uint256 amount1, bool token0) public monotonicHolderNAV {
160160
fee = bound(fee, 0, 0.02e18);
161161
amount1 = bound(amount1, 1e18, 25e18);
162162

test/EulerSwap.t.sol

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ contract EulerSwapTest is MaglevTestBase {
3030
maglev.setDebtLimit(50e18, 50e18);
3131
}
3232

33-
function test_basicSwap() public {
33+
function test_basicSwap() public monotonicHolderNAV {
3434
uint256 amountIn = 1e18;
3535
uint256 amountOut = maglev.quoteExactInput(address(assetTST), address(assetTST2), amountIn);
3636

@@ -42,7 +42,36 @@ contract EulerSwapTest is MaglevTestBase {
4242
assertEq(assetTST2.balanceOf(address(this)), amountOut);
4343
}
4444

45-
function test_pathIndependent(uint256 amount, bool dir) public {
45+
function test_price() public {
46+
uint price = 0.5e18;
47+
uint px = price;
48+
uint py = 1e18;
49+
oracle.setPrice(address(eTST), unitOfAccount, 0.5e18);
50+
oracle.setPrice(address(assetTST), unitOfAccount, 0.5e18);
51+
52+
int256 origNAV = getHolderNAV();
53+
54+
vm.prank(owner);
55+
maglev.setEulerSwapParams(Maglev.EulerSwapParams({
56+
px: px,
57+
py: py,
58+
cx: 0.4e18,
59+
cy: 0.85e18
60+
}));
61+
62+
uint256 amountIn = 1e18;
63+
uint256 amountOut = maglev.quoteExactInput(address(assetTST), address(assetTST2), amountIn);
64+
65+
assetTST.mint(address(this), amountIn);
66+
67+
assetTST.transfer(address(maglev), amountIn);
68+
maglev.swap(0, amountOut, address(this), "");
69+
assertEq(assetTST2.balanceOf(address(this)), amountOut);
70+
71+
assertGe(getHolderNAV(), origNAV);
72+
}
73+
74+
function test_pathIndependent(uint256 amount, bool dir) public monotonicHolderNAV {
4675
amount = bound(amount, 0.1e18, 25e18);
4776

4877
TestERC20 t1;
@@ -67,15 +96,17 @@ contract EulerSwapTest is MaglevTestBase {
6796
assertApproxEqAbs(q, q2, 0.00000001e18);
6897
}
6998

70-
function test_fuzzParams(uint256 amount, uint256 amount2, uint256 px, uint256 py, uint256 cx, uint256 cy, bool dir) public {
99+
function test_fuzzParams(uint256 amount, uint256 amount2, uint256 price, uint256 cx, uint256 cy, bool dir) public {
71100
amount = bound(amount, 0.1e18, 25e18);
72101
amount2 = bound(amount2, 0.1e18, 25e18);
73-
px = bound(px, 1e18, 1e18);
74-
py = bound(py, 1e18, 1e18);
102+
price = bound(price, 0.1e18, 10e18);
75103
cx = bound(cx, 0.01e18, 0.99e18);
76104
cy = bound(cy, 0.01e18, 0.99e18);
77105

78-
int256 origNav = getHolderNAV();
106+
uint px = price;
107+
uint py = 1e18;
108+
oracle.setPrice(address(eTST), unitOfAccount, price);
109+
oracle.setPrice(address(assetTST), unitOfAccount, price);
79110

80111
vm.prank(owner);
81112
maglev.setEulerSwapParams(Maglev.EulerSwapParams({
@@ -85,6 +116,8 @@ contract EulerSwapTest is MaglevTestBase {
85116
cy: cy
86117
}));
87118

119+
int256 origNAV = getHolderNAV();
120+
88121
TestERC20 t1;
89122
TestERC20 t2;
90123
if (dir) (t1, t2) = (assetTST, assetTST2);
@@ -106,6 +139,6 @@ contract EulerSwapTest is MaglevTestBase {
106139
else maglev.swap(0, q2, address(this), "");
107140
assertEq(t1.balanceOf(address(this)), q2);
108141

109-
assertGe(getHolderNAV(), origNav);
142+
assertGe(getHolderNAV(), origNAV);
110143
}
111144
}

test/MaglevTestBase.t.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,21 @@ contract MaglevTestBase is EVaultTestBase {
6363
uint256 debt0 = eTST.debtOf(holder);
6464
uint256 balance1 = eTST2.convertToAssets(eTST2.balanceOf(holder));
6565
uint256 debt1 = eTST2.debtOf(holder);
66+
console.log("V0",balance0,debt0);
67+
console.log("V1",balance1,debt1);
6668

6769
uint256 balValue = oracle.getQuote(balance0, address(assetTST), unitOfAccount) + oracle.getQuote(balance1, address(assetTST2), unitOfAccount);
6870
uint256 debtValue = oracle.getQuote(debt0, address(assetTST), unitOfAccount) + oracle.getQuote(debt1, address(assetTST2), unitOfAccount);
6971

7072
return int(balValue) - int(debtValue);
7173
}
7274

75+
modifier monotonicHolderNAV() {
76+
int256 orig = getHolderNAV();
77+
_;
78+
assertGe(getHolderNAV(), orig);
79+
}
80+
7381
function logState(address ml) internal view {
7482
console.log("--------------------");
7583
console.log("Account States:");

0 commit comments

Comments
 (0)