mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
Everything working (except WIPE)
This commit is contained in:
parent
c60688b37d
commit
5e92995f13
|
@ -2,90 +2,58 @@ pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
interface TubInterface {
|
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 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 {
|
interface TokenInterface {
|
||||||
function allowance(address, address) external view returns (uint);
|
function allowance(address, address) external view returns (uint);
|
||||||
function balanceOf(address) external view returns (uint);
|
function balanceOf(address) external view returns (uint);
|
||||||
|
function transfer(address, uint) external returns (bool);
|
||||||
function approve(address, uint) external;
|
function approve(address, uint) external;
|
||||||
function withdraw(uint) external;
|
function withdraw(uint) external;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract DSMath {
|
contract FreeProxy {
|
||||||
|
|
||||||
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) {
|
function getSaiTubAddress() public pure returns (address sai) {
|
||||||
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
function getAddressWETH() public pure returns (address weth) {
|
||||||
|
weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
|
||||||
|
|
||||||
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 {
|
function freeWETH(uint wamt) public {
|
||||||
bytes32 cup = bytes32(cdpNum);
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
address tubAddr = getSaiTubAddress();
|
TokenInterface weth = tub.gem();
|
||||||
|
|
||||||
if (jam > 0) {
|
|
||||||
|
|
||||||
TubInterface tub = TubInterface(tubAddr);
|
|
||||||
TokenInterface peth = tub.skr();
|
|
||||||
|
|
||||||
uint ink = rdiv(jam, tub.per());
|
uint freeJam = wamt;
|
||||||
ink = rmul(ink, tub.per()) <= jam ? ink : ink - 1;
|
if (freeJam == 0) {
|
||||||
tub.free(cup, ink);
|
freeJam = weth.balanceOf(address(this));
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
weth.withdraw(freeJam);
|
||||||
|
msg.sender.transfer(freeJam);
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdrawWETH() public {
|
||||||
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
|
TokenInterface weth = tub.gem();
|
||||||
|
uint freeJam = weth.balanceOf(address(this));
|
||||||
|
weth.transfer(msg.sender, freeJam);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWETHBal() public view returns (uint freeJam) {
|
||||||
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
|
TokenInterface weth = tub.gem();
|
||||||
|
freeJam = weth.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSaiWETH() public view returns (address) {
|
||||||
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
|
return address(tub.gem());
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAllowance(TokenInterface token_, address spender_) private {
|
function setAllowance(TokenInterface token_, address spender_) private {
|
||||||
|
@ -94,19 +62,4 @@ contract CDPResolver is Helpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -165,6 +165,7 @@ contract CDPResolver is Helpers {
|
||||||
|
|
||||||
TubInterface tub = TubInterface(tubAddr);
|
TubInterface tub = TubInterface(tubAddr);
|
||||||
TokenInterface peth = tub.skr();
|
TokenInterface peth = tub.skr();
|
||||||
|
TokenInterface weth = tub.gem();
|
||||||
|
|
||||||
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;
|
||||||
|
@ -173,8 +174,8 @@ contract CDPResolver is Helpers {
|
||||||
setAllowance(peth, tubAddr);
|
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 = weth.balanceOf(address(this)); // withdraw possible previous stuck WETH as well
|
||||||
tub.gem().withdraw(freeJam);
|
weth.withdraw(freeJam);
|
||||||
|
|
||||||
address(msg.sender).transfer(freeJam);
|
address(msg.sender).transfer(freeJam);
|
||||||
}
|
}
|
||||||
|
@ -196,22 +197,18 @@ 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 tubAddr = getSaiTubAddress();
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
address _daiEx = getUniswapDAIExchange();
|
UniswapExchange daiEx = UniswapExchange(getUniswapDAIExchange());
|
||||||
address _mkrEx = getUniswapMKRExchange();
|
UniswapExchange mkrEx = UniswapExchange(getUniswapMKRExchange());
|
||||||
|
|
||||||
TubInterface tub = TubInterface(tubAddr);
|
|
||||||
UniswapExchange daiEx = UniswapExchange(_daiEx);
|
|
||||||
UniswapExchange mkrEx = UniswapExchange(_mkrEx);
|
|
||||||
TokenInterface dai = tub.sai();
|
TokenInterface dai = tub.sai();
|
||||||
TokenInterface mkr = tub.gov();
|
TokenInterface mkr = tub.gov();
|
||||||
PepInterface pep = tub.pep();
|
PepInterface pep = tub.pep();
|
||||||
|
|
||||||
bytes32 cup = bytes32(cdpNum);
|
bytes32 cup = bytes32(cdpNum);
|
||||||
|
|
||||||
setAllowance(dai, tubAddr);
|
setAllowance(dai, getSaiTubAddress());
|
||||||
setAllowance(mkr, tubAddr);
|
setAllowance(mkr, getSaiTubAddress());
|
||||||
setAllowance(dai, _daiEx);
|
setAllowance(dai, getUniswapDAIExchange());
|
||||||
|
|
||||||
(bytes32 val, bool ok) = pep.peek();
|
(bytes32 val, bool ok) = pep.peek();
|
||||||
|
|
||||||
|
@ -286,4 +283,6 @@ contract InstaMaker is CDPCluster {
|
||||||
version = _version;
|
version = _version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function() external payable {}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user