Proxy Logics => refactoring & removed unused code.

This commit is contained in:
Sowmayjain 2019-04-06 18:53:33 +05:30
parent 992aedcc60
commit 99786654ef
4 changed files with 6 additions and 161 deletions

View File

@ -1,6 +1,5 @@
pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
@ -25,9 +24,6 @@ contract KyberInterface {
contract Helper {
using SafeMath for uint;
using SafeMath for uint256;
/**
* @dev get ethereum address for trade
*/
@ -49,13 +45,6 @@ contract Helper {
admin = 0x7284a8451d9a0e7Dc62B3a71C0593eA2eC5c5638;
}
/**
* @dev get fees to trade // 200 => 0.2%
*/
function getUintFees() public pure returns (uint fees) {
fees = 200;
}
/**
* @dev gets ETH & token balance
* @param src is the token being sold

View File

@ -1,7 +1,5 @@
pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
interface TubInterface {
function open() external returns (bytes32);
function join(uint) external;

View File

@ -1,18 +1,14 @@
pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
contract UniswapFactory {
interface UniswapFactory {
// Get Exchange and Token Info
function getExchange(address token) external view returns (address exchange);
function getToken(address exchange) external view returns (address token);
}
// Solidity Interface
contract UniswapPool {
interface UniswapPool {
// Address of ERC20 token sold on this exchange
function tokenAddress() external view returns (address token);
// Address of Uniswap Factory
@ -37,9 +33,6 @@ contract UniswapPool {
contract Helper {
using SafeMath for uint;
using SafeMath for uint256;
/**
* @dev get Uniswap Proxy address
*/
@ -81,18 +74,10 @@ contract Helper {
* @dev setting allowance to kyber for the "user proxy" if required
* @param token is the token address
*/
function setApproval(address token, address to) internal {
IERC20(token).approve(to, 2**255);
}
/**
* @dev configuring token approval with user proxy
* @param token is the token
*/
function manageApproval(address token, uint srcAmt, address to) internal returns (uint) {
function setApproval(address token, uint srcAmt, address to) internal {
uint tokenAllowance = IERC20(token).allowance(address(this), to);
if (srcAmt > tokenAllowance) {
setApproval(token, to);
IERC20(token).approve(to, 2**255);
}
}
@ -144,7 +129,7 @@ contract InstaUniswapPool is Helper {
uint tokenToDeposit = msg.value * tokenReserve / ethReserve + 1;
require(tokenToDeposit < maxDepositedTokens, "Token to deposit is greater than Max token to Deposit");
IERC20(token).transferFrom(msg.sender, address(this), tokenToDeposit);
manageApproval(token, tokenToDeposit, poolAddr);
setApproval(token, tokenToDeposit, poolAddr);
tokensMinted = UniswapPool(poolAddr).addLiquidity.value(msg.value)(
uint(0),
tokenToDeposit,
@ -168,7 +153,7 @@ contract InstaUniswapPool is Helper {
) public returns (uint ethReturned, uint tokenReturned)
{
address poolAddr = getAddressPool(token);
manageApproval(poolAddr, amount, poolAddr);
setApproval(poolAddr, amount, poolAddr);
(ethReturned, tokenReturned) = UniswapPool(poolAddr).removeLiquidity(
amount,
minEth,

View File

@ -1,127 +0,0 @@
pragma solidity ^0.5.0;
interface TubInterface {
function wipe(bytes32, uint) external;
function gov() external view returns (TokenInterface);
function sai() external view returns (TokenInterface);
function tab(bytes32) external returns (uint);
function rap(bytes32) external returns (uint);
function pep() external view returns (PepInterface);
}
interface TokenInterface {
function allowance(address, address) external view returns (uint);
function balanceOf(address) external view returns (uint);
function approve(address, uint) external;
function transfer(address, uint) external returns (bool);
function transferFrom(address, address, uint) external returns (bool);
}
interface PepInterface {
function peek() external returns (bytes32, bool);
}
interface UniswapExchange {
function getEthToTokenOutputPrice(uint256 tokensBought) external view returns (uint256 ethSold);
function getTokenToEthOutputPrice(uint256 ethBought) external view returns (uint256 tokensSold);
function tokenToTokenSwapOutput(
uint256 tokensBought,
uint256 maxTokensSold,
uint256 maxEthSold,
uint256 deadline,
address tokenAddr
) external returns (uint256 tokensSold);
}
contract DSMath {
function add(uint x, uint y) internal pure returns (uint z) {
require((z = x + y) >= x, "math-not-safe");
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, "math-not-safe");
}
uint constant WAD = 10 ** 18;
uint constant RAY = 10 ** 27;
function rmul(uint x, uint y) internal pure returns (uint z) {
z = add(mul(x, y), RAY / 2) / RAY;
}
function rdiv(uint x, uint y) internal pure returns (uint z) {
z = add(mul(x, RAY), y / 2) / y;
}
function wdiv(uint x, uint y) internal pure returns (uint z) {
z = add(mul(x, WAD), y / 2) / y;
}
}
contract WipeProxy is DSMath {
function getSaiTubAddress() public pure returns (address sai) {
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
}
function getUniswapMKRExchange() public pure returns (address ume) {
ume = 0x2C4Bd064b998838076fa341A83d007FC2FA50957;
}
function getUniswapDAIExchange() public pure returns (address ude) {
ude = 0x09cabEC1eAd1c0Ba254B09efb3EE13841712bE14;
}
function wipe(
uint cdpNum,
uint _wad
) public
{
require(_wad > 0, "no-wipe-no-dai");
TubInterface tub = TubInterface(getSaiTubAddress());
UniswapExchange daiEx = UniswapExchange(getUniswapDAIExchange());
UniswapExchange mkrEx = UniswapExchange(getUniswapMKRExchange());
TokenInterface dai = tub.sai();
TokenInterface mkr = tub.gov();
bytes32 cup = bytes32(cdpNum);
setAllowance(dai, getSaiTubAddress());
setAllowance(mkr, getSaiTubAddress());
setAllowance(dai, getUniswapDAIExchange());
(bytes32 val, bool ok) = tub.pep().peek();
// MKR required for wipe = Stability fees accrued in Dai / MKRUSD value
uint mkrFee = wdiv(rmul(_wad, rdiv(tub.rap(cup), tub.tab(cup))), uint(val));
uint daiAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
daiAmt = add(_wad, daiAmt);
require(dai.transferFrom(msg.sender, address(this), daiAmt), "not-approved-yet");
if (ok && val != 0) {
daiEx.tokenToTokenSwapOutput(
mkrFee,
daiAmt,
uint(999000000000000000000),
uint(1899063809), // 6th March 2030 GMT // no logic
address(mkr)
);
}
tub.wipe(cup, _wad);
}
function setAllowance(TokenInterface token_, address spender_) private {
if (token_.allowance(address(this), spender_) != uint(-1)) {
token_.approve(spender_, uint(-1));
}
}
}