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

Always getting “Gas Estimation failed” in Remix when testing 1inch swap function #56

Open
golkir opened this issue Nov 24, 2020 · 0 comments

Comments

@golkir
Copy link

golkir commented Nov 24, 2020

I am trying to test 1inch swap function from the contract deployed via Remix on a Ganache fork of the Ethereum Mainnet. When calling this function I always get the "Gas estimation failed" error and "VM Exception while processing transaction: revert" error in Remix. My contract has enough sold off token (USDC) and Ether.

The contract:

contract TradeBot {
// OneSplit Config
    address ONE_SPLIT_ADDRESS = 0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E;
    uint256 PARTS = uint256(10);
    uint256 FLAGS = uint256(0);

   function oneSplitSwap(address _from, address _to, uint256 _amount, uint256 _minReturn, 
                        uint256[] memory _distribution) public payable {
        _oneSplitSwap(_from, _to, _amount, _minReturn, _distribution);
    }

   function _oneSplitSwap(address _from, address _to, uint256 _amount, uint256 _minReturn, 
                          uint256[] memory _distribution) internal {
        // Setup contracts
        IERC20 _fromIERC20 = IERC20(_from);
        IERC20 _toIERC20 = IERC20(_to);
        IOneSplit _oneSplitContract = IOneSplit(ONE_SPLIT_ADDRESS);
        // Approve tokens
        _fromIERC20.approve(ONE_SPLIT_ADDRESS, _amount);
        // Swap tokens: give _from, get _to
        _oneSplitContract.swap(_fromIERC20, _toIERC20, _amount, _minReturn, _distribution, 
                               FLAGS);
        // Reset approval
        _fromIERC20.approve(ONE_SPLIT_ADDRESS, 0);
}

I test the function with the following parameters:

fromToken: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 // USDC
toToken:   0x6B175474E89094C44Da98b954EedeAC495271d0F // DAI
amount:    100000000
minReturn: 10 
distribution: [0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0]

Can't figure out why this does not work. All parameters seem to be correct and the contract has enough USDC. Am I using the correct 1split contract address or you have a new implementation? Any ideas how to fix this?

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

1 participant