poly-flashloan-bot icon indicating copy to clipboard operation
poly-flashloan-bot copied to clipboard

INSUFFICIENT_OUTPUT_AMOUNT error

Open yuichiroaoki opened this issue 2 years ago • 4 comments

I don't know how this error happened, but some people got this error when they change the config.

yuichiroaoki avatar Dec 17 '21 02:12 yuichiroaoki

Do you know what config was changed? Because I am not sure about that. But what I did is to make sure the arbitrage opportunity is higher before executing the transaction. I guess that the opportunity is changing quite quickly and while the transaction is running, the opportunity was already lost because it was too slow to execute.

trancee avatar Dec 17 '21 07:12 trancee

I thought this error happened when you fail to borrow a loan token from dodo.

it("should be reverted with `INSUFFICIENT_INPUT_AMOUNT` when the bot set a wrong dodo pool and the contract can't borrow tokens.", async () => {
	await expect(
		Flashloan.dodoFlashLoan({
			flashLoanPool: dodoV2Pool.WMATIC_USDT,
			loanAmount: getBigNumber(1, 6),
			firstRoutes: [{
				path: [erc20Address.USDC, erc20Address.DAI],
				router: uniswapRouter.quickswap,
			}],
			secondRoutes: [{
				path: [erc20Address.DAI, erc20Address.USDC],
				router: uniswapRouter.quickswap
			}],
		}, { gasLimit: 1000000 })
	).to.be.revertedWith("UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT");
});

https://github.com/yuichiroaoki/poly-flash/blob/6d29dac77bedf2871eda23ab875b9f4843a993ab/test/errorMsg.test.ts#L37-L53

In this scenario, the contract will try to borrow USDC, but it can't borrow USDC from dodoV2Pool.WMATIC_USDT. The contract checks if the loan token is a base token of the dodo pool, and if not it borrow a quote token of the pool, so the contract would borrow USDT (quote token of dodoV2Pool.WMATIC_USDT).

I should have checked if the quote token is the loan token as well.

https://github.com/yuichiroaoki/poly-flash/blob/6d29dac77bedf2871eda23ab875b9f4843a993ab/contracts/Flashloan.sol#L51-L66

But it could be a different reason, I'm just guessing.

I will update the contract to check the dodo pool before executing flashloan and to make it clear.

ref. https://docs.uniswap.org/protocol/concepts/V3-overview/swaps#safety-checks https://ethereum.stackexchange.com/questions/90241/why-insufficient-output-amount

yuichiroaoki avatar Dec 18 '21 02:12 yuichiroaoki

Thank you for looking into this issue. What you have tested is the INPUT amount, but my issue was about the OUTPUT amount. Can you make sure both are tested?

trancee avatar Dec 18 '21 08:12 trancee

Sure. I opened an issue on that.

https://github.com/yuichiroaoki/poly-flash/issues/4

yuichiroaoki avatar Dec 18 '21 12:12 yuichiroaoki