Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting UniswapV2: LOCKED exception #44

Closed
alonmuroch opened this issue Aug 13, 2020 · 5 comments
Closed

getting UniswapV2: LOCKED exception #44

alonmuroch opened this issue Aug 13, 2020 · 5 comments

Comments

@alonmuroch
Copy link

Hi Uniswap team,
I've encountered an issue when trying to integrate with Uniswap, didn't find anything on google which is similar.

I'm using Genache (forking mainnet).
IDE Remix
Deployment truffle

I did a simple contract which tries to exchange eth -> CDT (and erc20 token)

    function exchangeCDTUniswap(uint256 eth_amount) internal returns(uint256 cdt_bought) {
        address weth = IUniswapV2Router02(uniswap_router).WETH();

        address[] memory path = new address[](2);
        path[0] = weth;
        path[1] = cdt;

        uint[] memory amounts = IUniswapV2Router02(uniswap_router).swapExactETHForTokens{value:eth_amount}(1, path, address(this), now + 15);
        return amounts[1];
    }

uniswap_router = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
cdt = 0x177d39ac676ed1c67a2b268ad7f1e58826e5b0af

From that call I get UniswapV2: LOCKED which, after looking around, only appears in UniswapV2Pair.sol (here)

What did I do wrong here?

@MicahZoltu
Copy link

That error indicates reentrance. Is the token you are trying to swap calling into Uniswap on its transfer function?

@moodysalem
Copy link
Contributor

This is a common issue with the ganache fork chain, for some reason the locked state is not correct. I would recommend deploying to your own test chain

@alonmuroch
Copy link
Author

@MicahZoltu no, it's a plain old ERC20

@moodysalem have you encountered it before? seems a bit of an overkill deploying the whole uniswap project just for simple tests..

@moodysalem
Copy link
Contributor

moodysalem commented Aug 14, 2020

@alonmuroch only via the discord questions, I haven't encountered it myself, but you only have to deploy the uniswap factory and router. I would recommend a local testnet over a mainnet ganache fork for unit tests anyway.

This is an issue with the ganache fork code, as the pool is always unlocked after a swap. Nothing we can do in the uniswap contracts to fix it.

@Samboy76
Copy link

I´m having the same issue in Hardhat deployment. #159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants