Skip to content

Commit ba0da9b

Browse files
committed
start of fee support for ES curve
1 parent b75c947 commit ba0da9b

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

TODO

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* events
33
* reserve change on each swap
44
* ConstantSum: incorporate price multipliers in quote methods
5+
* natspec
56
? alternate curves
67
? registry contract
78
? transparent proxy so AMM address can stay constant

src/MaglevEulerSwap.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ contract MaglevEulerSwap is MaglevBase {
1010
uint256 public _py;
1111
uint256 public _cx;
1212
uint256 public _cy;
13+
uint256 public _fee;
1314

1415
error KNotSatisfied();
1516
error ReservesZero();
@@ -20,6 +21,7 @@ contract MaglevEulerSwap is MaglevBase {
2021
uint256 py;
2122
uint256 cx;
2223
uint256 cy;
24+
uint256 fee;
2325
}
2426

2527
constructor(BaseParams memory baseParams, EulerSwapParams memory params) MaglevBase(baseParams) {
@@ -31,8 +33,10 @@ contract MaglevEulerSwap is MaglevBase {
3133
_py = params.py;
3234
_cx = params.cx;
3335
_cy = params.cy;
36+
_fee = Math.max(params.fee, 1.0000000000001e18); // minimum fee required to compensate for rounding
3437
}
3538

39+
// FIXME: how to charge fees?
3640
function verify(uint256, uint256, uint256 newReserve0, uint256 newReserve1) internal view virtual override {
3741
int256 delta = 0;
3842

@@ -42,12 +46,10 @@ contract MaglevEulerSwap is MaglevBase {
4246
delta = int256(newReserve1) - int256(fx(newReserve0, _px, _py, initialReserve0, initialReserve1, _cx, _cy));
4347
}
4448

45-
// if delta is > zero, then point is above the curve
49+
// if delta is >= zero, then point is on or above the curve
4650
require(delta >= 0, KNotSatisfied());
4751
}
4852

49-
uint256 private constant roundingCompensation = 1.0000000000001e18;
50-
5153
function computeQuote(uint256 amount, bool exactIn, bool asset0IsInput)
5254
internal
5355
view
@@ -86,11 +88,11 @@ contract MaglevEulerSwap is MaglevBase {
8688
if (exactIn) {
8789
if (asset0IsInput) output = uint256(-dy);
8890
else output = uint256(-dx);
89-
output = output * 1e18 / roundingCompensation;
91+
output = output * 1e18 / _fee;
9092
} else {
9193
if (asset0IsInput) output = uint256(dx);
9294
else output = uint256(dy);
93-
output = output * roundingCompensation / 1e18;
95+
output = output * _fee / 1e18;
9496
}
9597
}
9698

test/EulerSwap.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ contract EulerSwapTest is MaglevTestBase {
1818

1919
vm.prank(owner);
2020
maglev =
21-
new Maglev(_getMaglevBaseParams(), Maglev.EulerSwapParams({px: 1e18, py: 1e18, cx: 0.4e18, cy: 0.85e18}));
21+
new Maglev(_getMaglevBaseParams(), Maglev.EulerSwapParams({px: 1e18, py: 1e18, cx: 0.4e18, cy: 0.85e18, fee:0}));
2222

2323
vm.prank(holder);
2424
evc.setAccountOperator(holder, address(maglev), true);
@@ -66,7 +66,7 @@ contract EulerSwapTest is MaglevTestBase {
6666
int256 origNAV = getHolderNAV();
6767

6868
vm.prank(owner);
69-
maglev.setEulerSwapParams(Maglev.EulerSwapParams({px: px, py: py, cx: 0.4e18, cy: 0.85e18}));
69+
maglev.setEulerSwapParams(Maglev.EulerSwapParams({px: px, py: py, cx: 0.4e18, cy: 0.85e18, fee:0}));
7070

7171
uint256 amountIn = 1e18;
7272
uint256 amountOut = maglev.quoteExactInput(address(assetTST), address(assetTST2), amountIn);
@@ -119,7 +119,7 @@ contract EulerSwapTest is MaglevTestBase {
119119
oracle.setPrice(address(assetTST), unitOfAccount, price);
120120

121121
vm.prank(owner);
122-
maglev.setEulerSwapParams(Maglev.EulerSwapParams({px: px, py: py, cx: cx, cy: cy}));
122+
maglev.setEulerSwapParams(Maglev.EulerSwapParams({px: px, py: py, cx: cx, cy: cy, fee:0}));
123123

124124
int256 origNAV = getHolderNAV();
125125

0 commit comments

Comments
 (0)