pedrobergamini / flashloaner-contract

This repo introduces a simple example of how to arbitrage trade on-chain using flash loans.
534 stars 308 forks source link

Unauthorized after deployment #2

Open eth0izzle opened 3 years ago

eth0izzle commented 3 years ago

Hey, I'm pretty new to the smart contract world - a lot of take in for sure. I've deployed your contract to mainnet and I'm trying to execute it but receiving a "execution reverted: Unauthorized" error. It looks like it might be from this line:

  require(msg.sender == UniswapV2Library.pairFor(factory, token0, token1), "Unauthorized"); 

Any ideas what I could be missing? My wallet private key is correct and matches the account that deployed the flash contract.

egoid commented 3 years ago

I'm getting the same error on my end and have validated the same..

Any guidance is appreciated.

eth0izzle commented 3 years ago

I've still not figured it out. Did you deploy the migrations?

cwazy2020 commented 3 years ago

The issue is that the function they included is meant to be called by the pair contract after they transfer tokens to you as part of a swap() call. They did not include the initial call to swap() in this example, so we are left to guess to figure out how to do that on our own.

eth0izzle commented 3 years ago

Were you able to figure it out @cwazy2020 ?

6eer commented 3 years ago

Were you able to figure it out @cwazy2020 ?

the issue is the library UniswapV2Library.sol, the method getPair(...) have hard coded some init code that its developer dependant, so if u are using a sushi pair u might be using sushiswap's version of UniswapV2Library.sol, its available in their repo