KyberNetwork / KyberSwap

Codebase for KyberSwap that helps users convert tokens instantly and directly from their own hardware wallets, metamask and so on. No setup, No deposit, no withdrawal needed. Try it out on https://kyberswap.com or join telegram for developers https://t.me/KyberDeveloper.
https://kyberswap.com
MIT License
427 stars 345 forks source link

TypeError: Member "trade" not found #1073

Open nance2uiuc opened 5 years ago

nance2uiuc commented 5 years ago

From the docs, we are instructed to implement the following function in our contract:

function swapEtherToTokenWithChange (KyberNetworkProxyInterface _kyberNetworkProxy, ERC20 token, address destAddress, uint maxDestQty, uint minRate) public payable{
        //note that this.balance has increased by msg.value before the execution of this function
        uint startEthBalance = this.balance;

        //send swapped tokens to dest address. change will be sent to this contract.
        _kyberNetworkProxy.trade.value(msg.value)(ETH_TOKEN_ADDRESS, msg.value, token, destAddress, maxDestQty, minRate, 0);

        //calculate contract starting ETH balance before receiving msg.value (startEthBalance - msg.value)
        //change = current balance after trade - starting ETH contract balance (this.balance - (startEthBalance - msg.value))
        uint change = this.balance - (startEthBalance - msg.value);
        SwapEtherChange(startEthBalance, this.balance, change);

        //return change to get_sender()
        get_sender().transfer(change); //get_sender()
    }

However, this gives a compile error : TypeError: Member "trade" not found or not visible after argument-dependent lookup in contract KyberNetworkProxyInterface

Indeed, when the KyberNetworkProxyInterface.sol contract is inspected, it does not have a trade() method, only a tradeWithHint() method.

Changing KyberNetworkProxyInterface to KyberNetworkProxy in ...swapEtherToTokenWithChange (KyberNetworkProxyInterface _kyberNetworkProxy,... does not result in a type error.

andrewsource147 commented 5 years ago

I doubt about that. You can check kyber smart contract in etherscan, It has trade function: https://etherscan.io/address/0x818e6fecd516ecc3849daf6845e3ec868087b755#writeContract