Commented MoatKyber.

This commit is contained in:
Sowmayjain 2018-10-29 04:27:59 +05:30
parent 19c66304a8
commit 20404b567b
2 changed files with 118 additions and 118 deletions

View File

@ -1,142 +1,142 @@
pragma solidity ^0.4.24;
// pragma solidity ^0.4.24;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
// import "openzeppelin-solidity/contracts/math/SafeMath.sol";
// import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
interface AddressRegistry {
function getAddr(string name) external view returns(address);
function isApprovedResolver(address user) external view returns(bool);
}
// interface AddressRegistry {
// function getAddr(string name) external view returns(address);
// function isApprovedResolver(address user) external view returns(bool);
// }
interface Kyber {
function trade(
address src,
uint srcAmount,
address dest,
address destAddress,
uint maxDestAmount,
uint minConversionRate,
address walletId
) external payable returns (uint);
}
// 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 addressRegistry;
modifier onlyAdmin() {
require(
msg.sender == getAddress("admin"),
"Permission Denied"
);
_;
}
function getAddress(string name) internal view returns(address addr) {
AddressRegistry addrReg = AddressRegistry(addressRegistry);
return addrReg.getAddr(name);
}
}
// contract Registry {
// address public addressRegistry;
// modifier onlyAdmin() {
// require(
// msg.sender == getAddress("admin"),
// "Permission Denied"
// );
// _;
// }
// function getAddress(string name) internal view returns(address addr) {
// AddressRegistry addrReg = AddressRegistry(addressRegistry);
// return addrReg.getAddr(name);
// }
// }
contract Trade is Registry {
// contract Trade is Registry {
event KyberTrade(
address src,
uint srcAmt,
address dest,
uint destAmt,
address beneficiary,
uint fees,
uint slipRate,
address affiliate
);
// event KyberTrade(
// address src,
// uint srcAmt,
// address dest,
// uint destAmt,
// address beneficiary,
// uint fees,
// uint slipRate,
// address affiliate
// );
// ropsten network
address public kyberAddr = 0x818E6FECD516Ecc3849DAf6845e3EC868087B755;
address public eth = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee;
// // ropsten network
// address public kyberAddr = 0x818E6FECD516Ecc3849DAf6845e3EC868087B755;
// address public eth = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee;
function executeTrade(
address trader,
address src,
address dest,
uint srcAmt,
uint slipRate
) public payable onlyUserOrResolver(trader) returns (uint destAmt)
{
// function executeTrade(
// address trader,
// address src,
// address dest,
// uint srcAmt,
// uint slipRate
// ) public payable onlyUserOrResolver(trader) returns (uint destAmt)
// {
fetchToken(trader, src, srcAmt);
uint fees = deductFees(src, srcAmt);
// fetchToken(trader, src, srcAmt);
// uint fees = deductFees(src, srcAmt);
Kyber kyberFunctions = Kyber(kyberAddr);
destAmt = kyberFunctions.trade.value(msg.value)(
src,
srcAmt - fees,
dest,
trader,
2**256 - 1,
slipRate,
getAddress("admin")
);
// Kyber kyberFunctions = Kyber(kyberAddr);
// destAmt = kyberFunctions.trade.value(msg.value)(
// src,
// srcAmt - fees,
// dest,
// trader,
// 2**256 - 1,
// slipRate,
// getAddress("admin")
// );
emit KyberTrade(
src,
srcAmt,
dest,
destAmt,
trader,
fees,
slipRate,
getAddress("admin")
);
// emit KyberTrade(
// src,
// srcAmt,
// dest,
// destAmt,
// trader,
// fees,
// slipRate,
// getAddress("admin")
// );
}
// }
function fetchToken(address trader, address src, uint srcAmt) internal {
if (src != eth) {
IERC20 tokenFunctions = IERC20(src);
tokenFunctions.transferFrom(trader, address(this), srcAmt);
}
}
// function fetchToken(address trader, address src, uint srcAmt) internal {
// if (src != eth) {
// IERC20 tokenFunctions = IERC20(src);
// tokenFunctions.transferFrom(trader, address(this), srcAmt);
// }
// }
function deductFees(address src, uint volume) internal returns(uint fees) {
Resolver moatRes = Resolver(getAddress("resolver"));
fees = moatRes.fees();
if (fees > 0) {
fees = volume / fees;
if (src == eth) {
getAddress("admin").transfer(fees);
} else {
IERC20 tokenFunctions = IERC20(src);
tokenFunctions.transfer(getAddress("admin"), fees);
}
}
}
// function deductFees(address src, uint volume) internal returns(uint fees) {
// Resolver moatRes = Resolver(getAddress("resolver"));
// fees = moatRes.fees();
// if (fees > 0) {
// fees = volume / fees;
// if (src == eth) {
// getAddress("admin").transfer(fees);
// } else {
// IERC20 tokenFunctions = IERC20(src);
// tokenFunctions.transfer(getAddress("admin"), fees);
// }
// }
// }
function allowKyber(address[] tokenArr) public {
for (uint i = 0; i < tokenArr.length; i++) {
IERC20 tokenFunctions = IERC20(tokenArr[i]);
tokenFunctions.approve(getAddress("kyber"), 2**256 - 1);
}
}
// function allowKyber(address[] tokenArr) public {
// for (uint i = 0; i < tokenArr.length; i++) {
// IERC20 tokenFunctions = IERC20(tokenArr[i]);
// tokenFunctions.approve(getAddress("kyber"), 2**256 - 1);
// }
// }
}
// }
contract MoatKyber is Trade {
// contract MoatKyber is Trade {
constructor(address rAddr) public {
addressRegistry = rAddr;
}
// constructor(address rAddr) public {
// addressRegistry = rAddr;
// }
function () public payable {}
// function () public payable {}
function collectAsset(address tokenAddress, uint amount) public onlyAdmin {
if (tokenAddress == eth) {
msg.sender.transfer(amount);
} else {
IERC20 tokenFunctions = IERC20(tokenAddress);
tokenFunctions.transfer(msg.sender, amount);
}
}
// function collectAsset(address tokenAddress, uint amount) public onlyAdmin {
// if (tokenAddress == eth) {
// msg.sender.transfer(amount);
// } else {
// IERC20 tokenFunctions = IERC20(tokenAddress);
// tokenFunctions.transfer(msg.sender, amount);
// }
// }
}
// }

View File

@ -69,7 +69,7 @@ contract IssueLoan is GlobalVar {
event LoanedDAI(address borrower, uint loanDAI, uint fees);
event OpenedNewCDP(address borrower, bytes32 cdpBytes);
function pethPEReth(uint eth) public returns (uint rPETH) {
function pethPEReth(uint eth) public view returns (uint rPETH) {
rPETH = eth * (10 ** 27) / loanMaster.per();
}