Skip to content

Commit 8dad69d

Browse files
committed
Improve f.md docs slightly
1 parent b3dfd85 commit 8dad69d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/f.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
## Implementation of `f`
22

3+
`f` (aka the "EulerSwap Function") is a parameterisable curve that defines the boundary of permissible points for EulerSwap AMMs. Points on the curve or above and to-the right are allowed, others are not.
4+
5+
Only formula 3 from the whitepaper is implemented in the EulerSwap core, since this can be used for both domains of the curve by mirroring the parameters. The more complicated formula 4 is a closed-form method for quoting swaps so it can be implemented in a periphery (if desired).
6+
37
### Derivation
48

5-
Formula 15 from the whitepaper:
9+
Formula 3 from the whitepaper:
610

711
y0 + (px / py) * (x0 - x) * (c + (1 - c) * (x0 / x))
812

@@ -40,3 +44,5 @@ None of the computations for the arguments to `mulDiv` can overflow:
4044
* Upper-bound: `1e18*(2**112 - 1) =~ 172 bits`
4145

4246
If amounts/prices are large, and we travel too far down the curve, then `mulDiv` (or the subsequent `y0` addition) could overflow because its output value cannot be represented as a `uint256`. However, these output values would never be valid anyway, because they exceed `type(uint112).max`.
47+
48+
To see this, consider the case where `mulDiv` fails due to overflow. This means that its result would've been greater than `2**256 - 1`. Dividing this value by the largest allowed value for `py` (`1e36`) gives approximately `2**136`, which is greater than the maximum allowed amount value of `2**112 - 1`. Both the rounding up operation and the final addition of `y0` can only further *increase* this value. This means that all cases where `mulDiv` or the subsequent additions overflow would involve `f()` returning values that are impossible for a swapper to satisfy, so they would revert anyways.

0 commit comments

Comments
 (0)