I'm a bit confused about the calculation of sAmountIn:
const sAmountIn = await sRouter.methods.getAmountIn(**amountIn**,sReserve1 ,sReserve0).call()
Output log:
Watermelon (WTM) {T0} | Pineapple (PNA) {T1} reserves
On Uniswap
WTM: 1000 | PNA: 500
On Sushiswap
WTM: 10000 | PNA: 100000
Swap's direction
PNA -> WTM
Uniswap's pool state
WTM excess/PNA shortage
On Uniswap
Mid price before swap: 2.00 WTM/PNA
Mid price after swap: 0.10 WTM/PNA
Swap 1738 PNA for 776 WTM
Trade price: 0.45 WTM/PNA (sell price)
Sushiswap price: 0.10 WTM/PNA (buy price)
Difference: 0.34 WTM/PNA
Total difference: 56.49445 ETH or 598.68 WTM
Gas needed: 0.36 M
Gas price: 20 gwei
Gas cost: 0.00720 ETH
Profit: 56.48725 ETH or 113855.24 DAI
My understanding is that the bot discovers and arbitrage opportunity where WTM is underpriced relative to PNA on Uniswap than it is on sushiswap (since on Uniswap, WTM is in excess and PNA is in shortage). So in order to exploit this, we would want to purchase WTM on Uniswap and sell PNA on Uniswap, hence we would be swapping amountIn PNA for amountOut WTM on uniswap.
Now that we have WTM, we would look to sell it on Sushiswap, so we would be sending in WTM and getting back PNA.
If so, why is it that sAmountIn is calculated from amountIn (this PNA amount going into Uniswap), and not amountOut (the WTM amount coming out of uniswap)?
I'm a bit confused about the calculation of sAmountIn:
Output log:
My understanding is that the bot discovers and arbitrage opportunity where WTM is underpriced relative to PNA on Uniswap than it is on sushiswap (since on Uniswap, WTM is in excess and PNA is in shortage). So in order to exploit this, we would want to purchase WTM on Uniswap and sell PNA on Uniswap, hence we would be swapping
amountInPNA foramountOutWTM on uniswap.Now that we have WTM, we would look to sell it on Sushiswap, so we would be sending in WTM and getting back PNA.
If so, why is it that sAmountIn is calculated from amountIn (this PNA amount going into Uniswap), and not amountOut (the WTM amount coming out of uniswap)?