1inchProtocol icon indicating copy to clipboard operation
1inchProtocol copied to clipboard

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

Open golkir opened this issue 5 years ago • 0 comments

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?

golkir avatar Nov 24 '20 12:11 golkir