Open rkedia145 opened 3 years ago
hey rob,
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.
It's all right.
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)?
Its because you wanna know how much WTM u will need to payback on sushiswap given u borrow (amountIn) PNA on sushi, so once u know how much u need to repay to sushi, your profit will be the (amountOut) WTMs that u got from uniswap less the sAmountIn of WTM u need to payback the flashloan on sushi (payback for the PNA u borrowed)
I hope have been clear! (otherwise, let me know but i think u got it, after all u understand all the shitty computations i made haha, cheers!)
Hi @6eer ,
Thanks for your comment. I am still a bit confused though. Let me try to break this down into steps and maybe you can identify where exactly I am misunderstanding?
Steps:
This is where i am getting confused, because we dont currently own any WTM, so how can we send in 'sAmountIn' WTM into Sushiswap? Shouldn't there be a step somewhere to borrow WTM on Sushiswap for the ETH that we currently do own? (note that here i am referring to the normal bot, so there should not be any flash loans involved).
Ah, ok! (I saw the edit). Yeah u are right with the normal bot u need to be holding the WTM, u only use sushiswap as oracle, as if the sushiprice was the market price (a VERY BAD assumption, here i suppose using a binance API to get the price reference would be a much better idea). So instead of
4) Since we don't own any PNA, we must first borrow 'amountIn' PNA on Sushiswap, meaning we are taking PNA out of Sushiswap, so we must be sending 'sAmountIn' WTM on Sushiswap.
U use the PNA tokens that u owns (the account u use to send & sign the transaction must have enough PNA). I wrote it in the first paragraph of the What its included in this repo? section
[...]The other uses normal swaps, this bot require you to be holding the tokens needed to do the trade but it contrast it cost less gas to execute.[...]
U dont borrow nothing!! u just make the arbitrage with your funds
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
amountIn
PNA foramountOut
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)?