yuichiroaoki / poly-flashloan-bot

Flashloan Bot on Polygon
https://yuichiroaoki.medium.com/flashloan-bot-on-polygon-part-2-3eae0ac33986?sk=80821da4ca1d0462c7c9ae617df56bdd
MIT License
303 stars 192 forks source link

Fail #10

Open trancee opened 2 years ago

trancee commented 2 years ago

I got quite some transactions that just say Fail without further information. The bot seems to be running successfully, but somehow there is an error inside the smart contract. However, I have no idea how to debug this?

https://polygonscan.com/tx/0x62db419e8b7d43347e0ddb5e438fe8194bac07a3b520d018a7e89c478320d4f6

yuichiroaoki commented 2 years ago

I got this error too and have no idea what's going on there.

Yes, I agree. It's probably because of the contract.

gsngsn123 commented 2 years ago

Fail with error 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT' how can i resolve this error

yuichiroaoki commented 2 years ago

Possible reason

I just happened to know that 1inch api returns the burn address instead of wmatic address.

1inch web UI image

1inch api response image

That's why the bot passes the burn address instead of wmatic address and the transaction ends up failing without any error messages.

bpevreall commented 2 years ago

I noticed the burn address is also on line 1 & 21 of src/constraints, is this of any relevance? looks out of place to me but im by no means experienced

yuichiroaoki commented 2 years ago

True. I didn't write that part.

Replacing the burn address to wmatic one seems to solve the issue.

MetaNynja commented 2 years ago

The burn address also appears in the contract.

Is this the correct address? : 0x0000000000000000000000000000000000001010

And do you mean replacing the burn address with the Matic address? Looks like WMatic is fine.

Great job spotting that btw.

MetaNynja commented 2 years ago

I updated the Matic address from the burn address to 0x0000000000000000000000000000000000001010 on both the contract and the bot but still hasn't been successful :

https://polygonscan.com/address/0x10A1504aE79e7A1f2e80A299f3E94565673A5165

bpevreall commented 2 years ago

If I'm not mistaken you need WMATIC Address rather than MATIC. https://polygonscan.com/token/0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270

im getting INSUFFICIENT_OUTPUT_AMOUNT on every tx after making the amendments, have increased slippage to 5% but still the same after rebuild

MetaNynja commented 2 years ago

I'm confused about it being WMatic still. Where I find the burn address is where Matic is stated.

Line 4: exports.polyMatic = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";

Line 8: MATIC: { Line 12 :address: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",

yuichiroaoki commented 2 years ago

That token info is used only at src/debug.ts to debug transactions, so it doesn't fix the error itself.

MetaNynja commented 2 years ago

No sorry, I just mean that I don’t think you meant to say WMatic above, the burn address is listed beside Matic, not WMatic. Did you mean to say we just need to change the burn address to the Matic address?

MetaNynja commented 2 years ago

Self destruct CHI

Any idea why there is a call to selfdestruct to 1inch Network: CHI Token

I don't see an address for CHI anywhere in the code. Since CHI is a gas token for 1inch, do we need to indicate this anywhere?

yuichiroaoki commented 2 years ago

I have no idea about the selfdestruct to 1inch.

I reproduced the "Fail" error here. https://github.com/yuichiroaoki/poly-flash/pull/16

Does it make sense?

it("should be reverted without any error messages when the path includes the burn address.", async () => {
    await impersonateFundErc20(USDC, DAI_WHALE, Flashloan.address, "100.0", 6);
    await expect(
        Flashloan.dodoFlashLoan({
            flashLoanPool: dodoV2Pool.WETH_USDC,
            loanAmount: getBigNumber(1, 6),
            firstRoutes: [{
                path: [erc20Address.USDC, BurnAddress, erc20Address.WETH],
                router: uniswapRouter.quickswap,
            }],
            secondRoutes: [{
                path: [erc20Address.WETH, erc20Address.USDC],
                router: uniswapRouter.quickswap,
            }]
        }, { gasLimit: 1000000 })
    ).to.be.revertedWith("");
});
MetaNynja commented 2 years ago

In the test error folders there is the following :

            .emit(Flashloan, "SwapFinished")
            .emit(Flashloan, "SentProfit");
        const balance = await USDT.balanceOf(owner.address);
        expect(balance.gt(getBigNumber(0, 6))).to.be.true;
    });

Sent Profit

Do you know why this isn't included in the live script?

yuichiroaoki commented 2 years ago

Good point! That would be awesome. I will do that. Probably that could be done with ethers.js.