mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
Renewed InstaMaker & Cleaned FreeProxy.
This commit is contained in:
parent
cd9849ade6
commit
c60688b37d
112
contracts/ProxyLogics/FreeProxy.sol
Normal file
112
contracts/ProxyLogics/FreeProxy.sol
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
|
interface TubInterface {
|
||||||
|
function join(uint) external;
|
||||||
|
function exit(uint) external;
|
||||||
|
function free(bytes32, uint) external;
|
||||||
|
function give(bytes32, address) external;
|
||||||
|
function gem() external view returns (TokenInterface);
|
||||||
|
function skr() external view returns (TokenInterface);
|
||||||
|
function ink(bytes32) external view returns (uint);
|
||||||
|
function per() external view returns (uint);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface TokenInterface {
|
||||||
|
function allowance(address, address) external view returns (uint);
|
||||||
|
function balanceOf(address) external view returns (uint);
|
||||||
|
function approve(address, uint) external;
|
||||||
|
function withdraw(uint) external;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
contract Helpers is DSMath {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get MakerDAO CDP engine
|
||||||
|
*/
|
||||||
|
function getSaiTubAddress() public pure returns (address sai) {
|
||||||
|
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
contract CDPResolver is Helpers {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev transfer CDP ownership
|
||||||
|
*/
|
||||||
|
function give(uint cdpNum, address nextOwner) public {
|
||||||
|
TubInterface(getSaiTubAddress()).give(bytes32(cdpNum), nextOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
function free(uint cdpNum, uint jam) public {
|
||||||
|
bytes32 cup = bytes32(cdpNum);
|
||||||
|
address tubAddr = getSaiTubAddress();
|
||||||
|
|
||||||
|
if (jam > 0) {
|
||||||
|
|
||||||
|
TubInterface tub = TubInterface(tubAddr);
|
||||||
|
TokenInterface peth = tub.skr();
|
||||||
|
|
||||||
|
uint ink = rdiv(jam, tub.per());
|
||||||
|
ink = rmul(ink, tub.per()) <= jam ? ink : ink - 1;
|
||||||
|
tub.free(cup, ink);
|
||||||
|
|
||||||
|
setAllowance(peth, tubAddr);
|
||||||
|
|
||||||
|
tub.exit(ink);
|
||||||
|
uint freeJam = tub.gem().balanceOf(address(this)); // withdraw possible previous stuck WETH as well
|
||||||
|
tub.gem().withdraw(freeJam);
|
||||||
|
|
||||||
|
address(msg.sender).transfer(freeJam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setAllowance(TokenInterface token_, address spender_) private {
|
||||||
|
if (token_.allowance(address(this), spender_) != uint(-1)) {
|
||||||
|
token_.approve(spender_, uint(-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
contract InstaMaker is CDPResolver {
|
||||||
|
|
||||||
|
uint public version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev setting up variables on deployment
|
||||||
|
* 1...2...3 versioning in each subsequent deployments
|
||||||
|
*/
|
||||||
|
constructor(uint _version) public {
|
||||||
|
version = _version;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -138,23 +138,21 @@ contract CDPResolver is Helpers {
|
||||||
address tubAddr = getSaiTubAddress();
|
address tubAddr = getSaiTubAddress();
|
||||||
if (msg.value > 0) {
|
if (msg.value > 0) {
|
||||||
TubInterface tub = TubInterface(tubAddr);
|
TubInterface tub = TubInterface(tubAddr);
|
||||||
|
TokenInterface weth = tub.gem();
|
||||||
|
TokenInterface peth = tub.skr();
|
||||||
|
|
||||||
(address lad,,,) = tub.cups(cup);
|
(address lad,,,) = tub.cups(cup);
|
||||||
require(lad == address(this), "cup-not-owned");
|
require(lad == address(this), "cup-not-owned");
|
||||||
|
|
||||||
tub.gem().deposit.value(msg.value)();
|
weth.deposit.value(msg.value)();
|
||||||
|
|
||||||
uint ink = rdiv(msg.value, tub.per());
|
uint ink = rdiv(msg.value, tub.per());
|
||||||
ink = rmul(ink, tub.per()) <= msg.value ? ink : ink - 1;
|
ink = rmul(ink, tub.per()) <= msg.value ? ink : ink - 1;
|
||||||
|
|
||||||
if (tub.gem().allowance(address(this), tubAddr) != uint(-1)) {
|
setAllowance(weth, tubAddr);
|
||||||
tub.gem().approve(tubAddr, uint(-1));
|
|
||||||
}
|
|
||||||
tub.join(ink);
|
tub.join(ink);
|
||||||
|
|
||||||
if (tub.skr().allowance(address(this), tubAddr) != uint(-1)) {
|
setAllowance(peth, tubAddr);
|
||||||
tub.skr().approve(tubAddr, uint(-1));
|
|
||||||
}
|
|
||||||
tub.lock(cup, ink);
|
tub.lock(cup, ink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,17 +160,22 @@ contract CDPResolver is Helpers {
|
||||||
function free(uint cdpNum, uint jam) public {
|
function free(uint cdpNum, uint jam) public {
|
||||||
bytes32 cup = bytes32(cdpNum);
|
bytes32 cup = bytes32(cdpNum);
|
||||||
address tubAddr = getSaiTubAddress();
|
address tubAddr = getSaiTubAddress();
|
||||||
|
|
||||||
if (jam > 0) {
|
if (jam > 0) {
|
||||||
|
|
||||||
TubInterface tub = TubInterface(tubAddr);
|
TubInterface tub = TubInterface(tubAddr);
|
||||||
|
TokenInterface peth = tub.skr();
|
||||||
|
|
||||||
uint ink = rdiv(jam, tub.per());
|
uint ink = rdiv(jam, tub.per());
|
||||||
ink = rmul(ink, tub.per()) <= jam ? ink : ink - 1;
|
ink = rmul(ink, tub.per()) <= jam ? ink : ink - 1;
|
||||||
tub.free(cup, ink);
|
tub.free(cup, ink);
|
||||||
if (tub.skr().allowance(address(this), tubAddr) != uint(-1)) {
|
|
||||||
tub.skr().approve(tubAddr, uint(-1));
|
setAllowance(peth, tubAddr);
|
||||||
}
|
|
||||||
tub.exit(ink);
|
tub.exit(ink);
|
||||||
uint freeJam = tub.gem().balanceOf(address(this)); // Withdraw possible previous stuck WETH as well
|
uint freeJam = tub.gem().balanceOf(address(this)); // withdraw possible previous stuck WETH as well
|
||||||
tub.gem().withdraw(freeJam);
|
tub.gem().withdraw(freeJam);
|
||||||
|
|
||||||
address(msg.sender).transfer(freeJam);
|
address(msg.sender).transfer(freeJam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,11 +196,11 @@ contract CDPResolver is Helpers {
|
||||||
function wipe(uint cdpNum, uint wad) public {
|
function wipe(uint cdpNum, uint wad) public {
|
||||||
require(wad > 0, "no-wipe-no-dai");
|
require(wad > 0, "no-wipe-no-dai");
|
||||||
|
|
||||||
address _tub = getSaiTubAddress();
|
address tubAddr = getSaiTubAddress();
|
||||||
address _daiEx = getUniswapDAIExchange();
|
address _daiEx = getUniswapDAIExchange();
|
||||||
address _mkrEx = getUniswapMKRExchange();
|
address _mkrEx = getUniswapMKRExchange();
|
||||||
|
|
||||||
TubInterface tub = TubInterface(_tub);
|
TubInterface tub = TubInterface(tubAddr);
|
||||||
UniswapExchange daiEx = UniswapExchange(_daiEx);
|
UniswapExchange daiEx = UniswapExchange(_daiEx);
|
||||||
UniswapExchange mkrEx = UniswapExchange(_mkrEx);
|
UniswapExchange mkrEx = UniswapExchange(_mkrEx);
|
||||||
TokenInterface dai = tub.sai();
|
TokenInterface dai = tub.sai();
|
||||||
|
@ -206,8 +209,8 @@ contract CDPResolver is Helpers {
|
||||||
|
|
||||||
bytes32 cup = bytes32(cdpNum);
|
bytes32 cup = bytes32(cdpNum);
|
||||||
|
|
||||||
setAllowance(dai, _tub);
|
setAllowance(dai, tubAddr);
|
||||||
setAllowance(mkr, _tub);
|
setAllowance(mkr, tubAddr);
|
||||||
setAllowance(dai, _daiEx);
|
setAllowance(dai, _daiEx);
|
||||||
|
|
||||||
(bytes32 val, bool ok) = pep.peek();
|
(bytes32 val, bool ok) = pep.peek();
|
||||||
|
@ -271,7 +274,7 @@ contract CDPCluster is CDPResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract InstaMaker is CDPResolver {
|
contract InstaMaker is CDPCluster {
|
||||||
|
|
||||||
uint public version;
|
uint public version;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user