The trickiest part of a two-pool arbitrage is determining the optimal borrow amount.

To understand how the problem is solved, consider the the hypothetical equation:

`P(x) = y_b(x) - y_a(x)`

where `y_b(x)`

is the output of token x swapped for token y through Pool B, `y_a(x)`

is the repayment required in token y for a flash borrow of token x through Pool A, and `…`

## Keep reading with a 7-day free trial

Subscribe to Degen Code to keep reading this post and get 7 days of free access to the full post archives.