Skip to content

Commit 9f8d68b

Browse files
authored
Merge pull request #67 from euler-xyz/fInverse-bugfix
fInverse bugfix
2 parents ab6f3a7 + c514e81 commit 9f8d68b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/libraries/QuoteLib.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ library QuoteLib {
210210
xNew = reserve0 - amount;
211211
if (xNew < x0) {
212212
// remain on f()
213-
yNew = CurveLib.f(xNew, py, px, y0, x0, cx);
213+
yNew = CurveLib.f(xNew, px, py, x0, y0, cx);
214214
} else {
215215
// move to g()
216216
yNew = CurveLib.fInverse(xNew, py, px, y0, x0, cy);

test/Basic.t.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ contract Basic is EulerSwapTestBase {
114114

115115
t1.mint(address(this), amount);
116116
uint256 q = periphery.quoteExactInput(address(eulerSwap), address(t1), address(t2), amount);
117+
{
118+
uint256 qRev = periphery.quoteExactOutput(address(eulerSwap), address(t1), address(t2), q);
119+
assertApproxEqAbs(amount, qRev, 200 + (MAX_QUOTE_ERROR + 1) * 2); // max 100:1 price differential, 2 swaps
120+
}
117121

118122
t1.transfer(address(eulerSwap), amount);
119123
if (dir) eulerSwap.swap(0, q, address(this), "");
@@ -122,6 +126,10 @@ contract Basic is EulerSwapTestBase {
122126

123127
t2.mint(address(this), amount2);
124128
uint256 q2 = periphery.quoteExactInput(address(eulerSwap), address(t2), address(t1), amount2);
129+
{
130+
uint256 qRev = periphery.quoteExactOutput(address(eulerSwap), address(t2), address(t1), q2);
131+
assertApproxEqAbs(amount2, qRev, 200 + (MAX_QUOTE_ERROR + 1) * 2);
132+
}
125133

126134
t2.transfer(address(eulerSwap), amount2);
127135
if (dir) eulerSwap.swap(q2, 0, address(this), "");

test/PreserveNav.t.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ contract PreserveNav is EulerSwapTestBase {
4242
else (t1, t2) = (assetTST2, assetTST);
4343

4444
uint256 q = periphery.quoteExactInput(address(eulerSwap), address(t1), address(t2), amount1);
45+
{
46+
uint256 qRev = periphery.quoteExactOutput(address(eulerSwap), address(t1), address(t2), q);
47+
assertApproxEqAbs(amount1, qRev, (MAX_QUOTE_ERROR + 1) * 2);
48+
}
4549

4650
t1.mint(address(this), amount1);
4751
t1.transfer(address(eulerSwap), amount1);
@@ -66,6 +70,10 @@ contract PreserveNav is EulerSwapTestBase {
6670
else (t1, t2) = (assetTST2, assetTST);
6771

6872
uint256 q = periphery.quoteExactInput(address(eulerSwap), address(t1), address(t2), amount2);
73+
{
74+
uint256 qRev = periphery.quoteExactOutput(address(eulerSwap), address(t1), address(t2), q);
75+
assertApproxEqAbs(amount2, qRev, (MAX_QUOTE_ERROR + 1) * 2);
76+
}
6977

7078
t1.mint(address(this), amount2);
7179
t1.transfer(address(eulerSwap), amount2);

0 commit comments

Comments
 (0)