Skip to content

Commit 55b3fa7

Browse files
committed
wip
1 parent 117b76b commit 55b3fa7

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

src/MaglevBase.sol

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.0;
33

4+
import {console} from "forge-std/Test.sol";
45
import {Ownable, Context} from "openzeppelin-contracts/access/Ownable.sol";
56
import {EVCUtil} from "evc/utils/EVCUtil.sol";
67
import {IEVC} from "evc/interfaces/IEthereumVaultConnector.sol";
@@ -18,8 +19,8 @@ abstract contract MaglevBase is EVCUtil, Ownable {
1819
uint112 public reserve1;
1920
uint32 private locked;
2021

21-
uint112 public virtualReserve0;
22-
uint112 public virtualReserve1;
22+
uint112 public initialReserve0;
23+
uint112 public initialReserve1;
2324

2425
error Reentrancy();
2526
error Overflow();
@@ -64,20 +65,9 @@ abstract contract MaglevBase is EVCUtil, Ownable {
6465
IEVC(evc).enableCollateral(myAccount, vault1);
6566
}
6667

67-
function setVirtualReserves(uint112 vr0, uint112 vr1) external onlyOwner {
68-
virtualReserve0 = vr0;
69-
virtualReserve1 = vr1;
70-
71-
syncVirtualReserves();
72-
73-
virtualReserve0 = reserve0;
74-
virtualReserve1 = reserve1;
75-
}
76-
77-
/// @dev Call whenever underlying balances change externally
78-
function syncVirtualReserves() public onlyOwner {
79-
reserve0 = adjustReserve(virtualReserve0, vault0);
80-
reserve1 = adjustReserve(virtualReserve1, vault1);
68+
function setDebtLimit(uint112 debtLimit0, uint112 debtLimit1) external onlyOwner {
69+
reserve0 = initialReserve0 = adjustReserve(debtLimit0, vault0);
70+
reserve1 = initialReserve1 = adjustReserve(debtLimit1, vault1);
8171
}
8272

8373
// Swapper interface

src/MaglevEulerSwap.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ contract MaglevEulerSwap is MaglevBase {
3333
//require(_verify(49e18, 51e18, px, py, 50e18, 50e18, cx, cy), KNotSatisfied());
3434

3535
console.log("QQ", newReserve0, newReserve1);
36-
console.log("ZZ", virtualReserve0, virtualReserve1);
37-
require(_verify(newReserve0, newReserve1, px, py, virtualReserve0, virtualReserve1, cx, cy), KNotSatisfied());
36+
console.log("ZZ", initialReserve0, initialReserve1);
37+
require(_verify(newReserve0, newReserve1, px, py, initialReserve0, initialReserve1, cx, cy), KNotSatisfied());
3838
}
3939

4040
function computeQuote(uint256, bool, bool)

test/ConstantProduct.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contract ConstantProductTest is MaglevTestBase {
2626
maglev.configure();
2727

2828
vm.prank(owner);
29-
maglev.setVirtualReserves(50e18, 50e18);
29+
maglev.setDebtLimit(50e18, 50e18);
3030
}
3131

3232
function test_fee_exactIn(uint256 amount, bool dir) public {

test/ConstantSum.t.sol

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contract ConstantSumTest is MaglevTestBase {
2626
maglev.configure();
2727

2828
vm.prank(owner);
29-
maglev.setVirtualReserves(50e18, 50e18);
29+
maglev.setDebtLimit(50e18, 50e18);
3030
}
3131

3232
function test_basicSwapReport() public {
@@ -53,8 +53,8 @@ contract ConstantSumTest is MaglevTestBase {
5353
}
5454

5555
function test_reserveLimit() public {
56-
assertEq(maglev.virtualReserve0(), 50e18);
57-
assertEq(maglev.virtualReserve1(), 50e18);
56+
assertEq(maglev.initialReserve0(), 60e18);
57+
assertEq(maglev.initialReserve1(), 60e18);
5858
assertEq(maglev.reserve0(), 60e18);
5959
assertEq(maglev.reserve1(), 60e18);
6060

@@ -77,21 +77,39 @@ contract ConstantSumTest is MaglevTestBase {
7777
maglev.swap(0, amount, address(this), "");
7878
}
7979

80+
assertEq(eTST.balanceOf(holder), 70e18);
8081
assertEq(eTST2.debtOf(holder), 50e18);
8182
assertEq(maglev.reserve0(), 120e18);
8283
assertEq(maglev.reserve1(), 0e18);
8384

85+
// Same debt limit means reserves not affected
86+
87+
vm.prank(owner);
88+
maglev.setDebtLimit(50e18, 50e18);
89+
assertEq(maglev.reserve0(), 120e18);
90+
assertEq(maglev.reserve1(), 0e18);
91+
92+
// Increase debt limit on one side
93+
8494
vm.prank(owner);
85-
maglev.setVirtualReserves(60e18, 55e18);
95+
maglev.setDebtLimit(50e18, 55e18);
96+
assertEq(maglev.reserve0(), 120e18);
97+
assertEq(maglev.reserve1(), 5e18);
98+
99+
// And the other
86100

87-
assertEq(maglev.reserve0(), 130e18);
101+
vm.prank(owner);
102+
maglev.setDebtLimit(55e18, 55e18);
103+
assertEq(maglev.reserve0(), 125e18);
88104
assertEq(maglev.reserve1(), 5e18);
89105

106+
// Shrink debt limit
107+
90108
vm.prank(owner);
91-
maglev.setVirtualReserves(40e18, 45e18);
109+
maglev.setDebtLimit(40e18, 45e18);
92110

93111
assertEq(maglev.reserve0(), 110e18);
94-
assertEq(maglev.reserve1(), 0e18);
112+
assertEq(maglev.reserve1(), 0e18); // can't go below 0
95113
}
96114

97115
function test_basicSwapFuzz(uint256 amount1, uint256 amount2) public {

test/EulerSwap.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ contract EulerSwapTest is MaglevTestBase {
2626
maglev.configure();
2727

2828
vm.prank(owner);
29-
maglev.setVirtualReserves(50e18, 50e18);
29+
maglev.setDebtLimit(50e18, 50e18);
3030
}
3131

3232
function test_basicSwap() public {
3333
uint256 amountIn = 1e18;
34-
uint256 amountOut = 0.9999999e18;
34+
uint256 amountOut = 0.99e18;
3535

3636
assetTST.mint(address(this), amountIn);
3737

0 commit comments

Comments
 (0)