Formula

The arbitration logic of NostraSwap is to maximize the product invariant by bringing the market price of the third party DEX as close to our market price as possible, eliminating any potential arbitrage opportunity. 10% of the arbitraging profit goes to the trader, while the rest goes to the liquidity pool.

NostraSwap begins with determining the amount of bonus token the trader should receive by calculating the profit from the arbitrage from the newReserves NostraSwap expects to have if it arbitrages between itself and a third party DEX with the assumption that no bonus token will be returned to the trader.

R0=R0R0+E0R1+E1E0E1E0R_0' = R_0 - \sqrt{\frac{R_0+E_0}{R_1+E_1}E_0E_1} - E_0
R1=R1R1+E1R0+E0E0E1E1R_1' = R_1 - \sqrt{\frac{R_1+E_1}{R_0+E_0}E_0E_1} - E_1

Where

Ri R_i'is the expected new reserve of the ith i^{th}token Ri R_iis the post-swap, pre-arbitrage reserve of the ith i^{th}token Ei E_iis the post-swap, pre-arbitrage reserve of the ith i^{th}token in the third party DEX.

The percent increase of the pool value can be calculated by:

R0R1R0R1\sqrt{\frac{R_0'R_1'}{R_0R_1}}

NostraSwap then uses this ratio to calculate the arbitration profit. 10% of the expected arbitration profit is sent to the trader. This calculation is done on all third-party DEXes to find the one that would yield the best profit.

Then, NostraSwap initiates the actual arbitrage between itself and the third party DEX repeating the calculation of Ri R_i', with its new reserves since the bonus token is already returned to the trader, to find the optimal amount of token to swap with third-party DEX.

Last updated

Was this helpful?