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.
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.
From the docs, we are instructed to implement the following function in our contract:
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.