or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
# 🛠 AlphaX Arbitrageurs Docs 💰
🛠 AlphaX Arbitrageurs Docs 💰
This doc will go into details of how to effectively arbitrage on AlphaX, including some PoCs.
AlphaX Recap
To recap, AlphaX has 2 main types of tokens: Long Strike Tokens & Short Strike Tokens.
Long Strike Tokens come in the form ETH-X, e.g., ETH-3000, ETH-2500.
Short Strike Tokens come in the form of Y-ETH, e.g., 6450-ETH, 7100-ETH.
The price of ETH-X should be pegged to (ETH price - X).
The price of Y-ETH should be pegged to (Y - ETH price).
This is regarded as the Oracle Price \(P_O\).
However, the actual ETH-X & Y-ETH token price might be trading on DEXes at another price. This price is the Market Price \(P_M\).
Two main arbitrage cases:
Case 1. Market Price too low (\(P_M < P_O\))
How much XTokens to buy depends on trading pool reserves, market price, and oracle price.
Here are some calculations:
Let
\(R_b\) = trading pool's base reserve (obtained from
pair.getReserves()
)\(R_q\) = trading pool's quote reserve (obtained from
pair.getReserves()
)\(f\) = trading pool's swap fee (0.3% = 0.003 in this case).
Let \(x\) be the optimal amount of XTokens to buy to bring \(P_M\) up to \(P_O\). We want to solve for \(x\).
After the swap, the new reserves become:
\begin{align*} R'_b &= R_b + x \\ R'_q &= \frac{R_b \cdot R_q}{R_b + (1-f) \cdot x} \end{align*}
The new market price becomes:
\begin{align*} P_O = P'_M = \frac{R'_q}{R'_b} = \frac{R_b \cdot R_q}{(R_b + (1-f) \cdot x)\cdot(R_b+x)} \end{align*}
Rearranging the equation gives a solvable quadratic equation:
\begin{align*} P_O \cdot (1-f) \cdot x^2 + (P_O\cdot(2-f)\cdot R_b)\cdot x + P_O\cdot R_b^2 - R_b \cdot R_q = 0 \end{align*}
Calculation Pseudocode:
Case 2. Market Price too high (\(P_M > P_O\))
How much XTokens to sell depends on trading pool reserves, market price, and oracle price.
Here are some calculations:
Let
\(R_b\) = trading pool's base reserve (obtained from
pair.getReserves()
)\(R_q\) = trading pool's quote reserve (obtained from
pair.getReserves()
)\(f\) = trading pool's swap fee (0.3% = 0.003 in this case).
Let \(x\) be the optimal amount of XTokens to sell to bring \(P_M\) down to \(P_O\). We want to solve for \(x\).
After the swap, the new reserves become:
\begin{align*} R'_b &= R_b - x \\ R'_q &= \frac{(1-f)\cdot R_b \cdot R_q + f\cdot R_q \cdot x}{(1-f)\cdot (R_b - x)} \end{align*}
The new market price becomes:
\begin{align*} P_O = P'_M = \frac{(1-f)\cdot R_b \cdot R_q + f\cdot R_q \cdot x}{(1-f)\cdot (R_b - x) \cdot(R_b -x)} \end{align*}
Rearranging the equation gives a solvable quadratic equation:
\begin{align*} P_O \cdot (1-f) \cdot x^2 - (2\cdot P_O \cdot(1-f)\cdot R_b + f \cdot R_q) \cdot x + (P_O \cdot (1-f)\cdot R_b^2 - (1-f)\cdot R_b \cdot R_q) = 0 \end{align*}
Calculation Pseudocode: