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

Failure to call 1inch getExpectedReturn function from the Solidity contract #55

Open
golkir opened this issue Nov 20, 2020 · 1 comment

Comments

@golkir
Copy link

golkir commented Nov 20, 2020

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. Are these functions implemented correctly?

@CodeForcer
Copy link

Are you sure this compiled correctly? Looks like a syntax error here:

(returnAmount, distribution) = _oneSplitContract.getExpectedReturn(_fromIERC20, _toIERC20, _amount, PARTS, FLAGS);

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

2 participants