---
# System prepended metadata

title: Untitled

---


![](https://i.imgur.com/nnJ8T3x.png)

We first define the amounts as functions of $X$
$$
\begin{align}
DAI_{in}(X) &= E0_{AmountOut}(X_0 * A) + E5_{AmountOut}(X_2*E1_{AmountOut}(((1-X_0) * A)))\\
WETH_{in}(X) &= E1_{AmountOut}((1-X_0) * A) + E4_{AmountOut}((1 - X_1) * E0_{AmountOut}(X_0*A))
\end{align}
$$

Next we define the Prices after swaps as functions of $X$:

$$
\begin{align}
P_a(X) &= E0_{priceAfter}(X_0 * A) * E2_{priceAfter}(DAI_{in}(X))\\
P_b(X) &= E1_{priceAfter}((1-X_0) * A) * E3_{priceAfter}(WETH_{in}(X))\\
P_c(X) &= E0_{priceAfter}(X_0 * A) * E4_{priceAfter}(DAI_{in}(X)) * E3_{priceAfter}(WETH_{in}(X))\\
P_d(X) &= E1_{priceAfter}((1-X_0) * A) * E5_{priceAfter}(WETH_{in}(X)) * E2_{priceAfter}(DAI_{in}(X))\\
\end{align}
$$


For no arbitrage to be possible we must choose X such that:

$$
\begin{align}
P_a(X) &= P_b(X) \\
P_a(X) &= P_c(X) \\
P_a(X) &= P_d(X) \\
P_b(X) &= P_c(X) \\
P_b(X) &= P_d(X) \\
P_c(X) &= P_d(X) \\
\end{align}
$$



From the above we can make some simplifications... It follows that price after swap of $E2$ must equal the price of $E3 * E4$ after swaps:

$$
\begin{align}
P_a(X) &= P_c(X) \\
E0_{priceAfter}(X_0 * A) * E2_{priceAfter}(DAI_{in}(X)) &= E0_{priceAfter}(X_0 * A) * E4_{priceAfter}(DAI_{in}(X)) * E3_{priceAfter}(WETH_{in}(X))\\
E2_{priceAfter}(DAI_{in}(X)) &= E4_{priceAfter}(DAI_{in}(X)) * E3_{priceAfter}(WETH_{in}(X))
\end{align}
$$

And equally so for $E3$ and $E5*E4$:

$$
\begin{align}
P_b(X) &= P_d(X) \\
E1_{priceAfter}((1-X_0) * A) * E3_{priceAfter}(WETH_{in}(X)) &= E1_{priceAfter}((1-X_0) * A) * E5_{priceAfter}(WETH_{in}(X)) * E2_{priceAfter}(DAI_{in}(X)) \\
E3_{priceAfter}(WETH_{in}(X)) &= E5_{priceAfter}(WETH_{in}(X)) * E2_{priceAfter}(DAI_{in}(X))
\end{align}
$$

And so on for all triangles, the single edge must be the same as the other two edges multiplied.


Complete expansion leads to:


$$
\begin{align}
E0_{priceAfter}(X_0 * A) * E2_{priceAfter}(DAI_{in}(X)) &= E1_{priceAfter}((1-X_0) * A) * E3_{priceAfter}(WETH_{in}(X))\\
E2_{priceAfter}(DAI_{in}(X)) &= E4_{priceAfter}(DAI_{in}(X)) * E3_{priceAfter}(WETH_{in}(X))\\
E0_{priceAfter}(X_0 * A) &= E1_{priceAfter}((1-X_0) * A) * E5_{priceAfter}(WETH_{in}(X)) \\
E1_{priceAfter}((1-X_0) * A) &= E0_{priceAfter}(X_0 * A) * E4_{priceAfter}(DAI_{in}(X)) \\
E3_{priceAfter}(WETH_{in}(X)) &= E5_{priceAfter}(WETH_{in}(X)) * E2_{priceAfter}(DAI_{in}(X)) \\
E0_{priceAfter}(X_0 * A) * E4_{priceAfter}(DAI_{in}(X)) * E3_{priceAfter}(WETH_{in}(X))&= E1_{priceAfter}((1-X_0) * A) * E5_{priceAfter}(WETH_{in}(X)) * E2_{priceAfter}(DAI_{in}(X)) \\
\end{align}
$$

This is a system of 6 non linear equations with 3 variables. It should be possible to find a solution e.g. with newtons method.