1

I am trying to test 1inch getExpectedReturn function from my Solidity contract. I deploy my contract on the Mainnet forked with Ganache via Remix. The entire contract is pretty simple and looks as follows:

pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;

interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

contract IOneSplit {
    function getExpectedReturn(
        IERC20 fromToken,
        IERC20 toToken,
        uint256 amount,
        uint256 parts,
        uint256 disableFlags
    )
        public
        view
        returns(
            uint256 returnAmount,
            uint256[] memory distribution
        );
}

contract TradingBot  {

    // OneSplit Config
    address ONE_SPLIT_ADDRESS = 0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E;
    uint256 PARTS = 10;
    uint256 FLAGS = 0;

    // Allow the contract to receive Ether
    function () external payable  {}

    function getreturn (address _from, address _to, uint256 _amount) public view returns(uint returnAmount, uint[] memory distribution) {
        IERC20 _fromIERC20 = IERC20(_from);
        IERC20 _toIERC20 = IERC20(_to);
        IOneSplit _oneSplitContract = IOneSplit(ONE_SPLIT_ADDRESS);
        (returnAmount, distribution) = _oneSplitContract.getExpectedReturn(_fromIERC20, _toIERC20, _amount, PARTS, FLAGS);
    } 
}

The contract compiles well but after deployment and running the getreturn function I always get the cryptic "VM Exception while processing transaction: revert" error. I also tried to use the call function:

function getreturn_test () public {
    
    ONE_SPLIT_ADDRESS.call(abi.encodeWithSignature(
                                "getExpectedReturn(address,address,uint256,uint256,uint256)",
                                                    0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,
                                                    0x6B175474E89094C44Da98b954EedeAC495271d0F,
                                                    uint(100), uint(10), uint(0)));
    }

It does not work either. I can't find any explanation why this does not work in my contract. Could anyone see any reasons?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.