From 4c7c79bb13639ebdbbc71d6174ef543992a4bd0c Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Thu, 25 Oct 2018 12:56:37 +0530 Subject: [PATCH] Integrated Kyber Network Protocol. --- .env.sample | 2 - contracts/MoatResolver.sol | 2 + contracts/protocols/MoatKyber.sol | 99 ++++++++++++++++++++++++++++++- 3 files changed, 99 insertions(+), 4 deletions(-) delete mode 100644 .env.sample diff --git a/.env.sample b/.env.sample deleted file mode 100644 index 98aee42..0000000 --- a/.env.sample +++ /dev/null @@ -1,2 +0,0 @@ -RINKEBY_PRIVATE_KEY="df7ebe6c9601adf4e911faac9da547686e6453a11cf13264d895fc2979a6bec2" -ROPSTEN_PRIVATE_KEY="192f175c2f5e5a9437fdbc12043404763f96ccbcd6fc32b1d61dbb61e14e6f34" \ No newline at end of file diff --git a/contracts/MoatResolver.sol b/contracts/MoatResolver.sol index ef993df..96a266e 100644 --- a/contracts/MoatResolver.sol +++ b/contracts/MoatResolver.sol @@ -1,3 +1,5 @@ +// Global Freeze Varaible + // withdraw store the 0.5% on the contract itself and can be withdrawn by admin addresses // this is the logic contract - stores nothing // https://bitbucket.org/Sowmay/resolver-dex/src/master/contracts/MoatResolver.sol \ No newline at end of file diff --git a/contracts/protocols/MoatKyber.sol b/contracts/protocols/MoatKyber.sol index fe2002c..e1ed964 100644 --- a/contracts/protocols/MoatKyber.sol +++ b/contracts/protocols/MoatKyber.sol @@ -1,2 +1,97 @@ -// Kyber Network Integration -// https://github.com/cryptoPay-ETHSF/SmartContract/blob/master/CryptoPayRopsten.sol \ No newline at end of file +// IMPORTANT CHECK - how decimal works on tokens with less than 18 decimals and accordingly store in our MoatAsset DB + +pragma solidity ^0.4.24; + +interface token { + function approve(address spender, uint256 value) external returns (bool); + function transfer(address receiver, uint amount) external returns (bool); + function balanceOf(address who) external returns(uint256); +} + +interface AddressRegistry { + function getAddr(string name) external returns(address); +} + +interface Kyber { + function trade( + address src, + uint srcAmount, + address dest, + address destAddress, + uint maxDestAmount, + uint minConversionRate, + address walletId + ) external payable returns (uint); +} + + +contract Registry { + + address public registryAddress; + modifier onlyResolver() { + require( + msg.sender == getAddress("resolver"), + "Permission Denied" + ); + _; + } + + function getAddress(string name) internal view returns(address addr) { + AddressRegistry aRegistry = AddressRegistry(registryAddress); + addr = aRegistry.getAddr(name); + require(addr != address(0), "Invalid Address"); + } + +} + + +contract KyberSwap is Registry { + + event Swapped(address src, uint srcAmt, address dest, uint destAmt); + + function executeTrade( + uint weiAmt, + address src, + address dest, + uint srcAmt, + uint slipRate, + address walletId + ) public onlyResolver returns (uint destAmt) + { + Kyber kyberFunctions = Kyber(getAddress("kyber")); + destAmt = kyberFunctions.trade.value(weiAmt)( + src, + srcAmt, + dest, + getAddress("asset"), + 2**256 - 1, + slipRate, + walletId + ); + emit Swapped( + src, + srcAmt, + dest, + destAmt + ); + } + + function allowKyber(address[] tokenArr) public { + for (uint i = 0; i < tokenArr.length; i++) { + token tokenFunctions = token(tokenArr[i]); + tokenFunctions.approve(getAddress("kyber"), 2**256 - 1); + } + } + +} + + +contract KyberInit is KyberSwap { + + constructor(address rAddr) public { + registryAddress = rAddr; + } + + function () public payable {} + +} \ No newline at end of file