Skip to content

Commit 766f2d7

Browse files
committed
from Michael: helper function to compute the post-swap derivative (marginal price)
1 parent 1a7e7e0 commit 766f2d7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libraries/CurveLib.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,15 @@ library CurveLib {
140140
}
141141
return xMin;
142142
}
143+
144+
/// @dev EulerSwap derivative helper function to find the price after a swap
145+
/// Pre-conditions: 0 < x <= x0, 1 <= {px,py} <= 1e36, {x0,y0} <= type(uint112).max, c <= 1e18
146+
function df_dx(uint256 x, uint256 px, uint256 py, uint256 x0, uint256 y0, uint256 c)
147+
internal
148+
pure
149+
returns (int256)
150+
{
151+
uint256 r = Math.mulDiv(x0 * x0 / x, 1e18, x, Math.Rounding.Ceil);
152+
return -int256(px * (c + (1e18 - c) * r / 1e18) / py);
153+
}
143154
}

0 commit comments

Comments
 (0)