mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
Renewed InstaMaker.
This commit is contained in:
parent
5e92995f13
commit
b4a6113f00
|
@ -141,9 +141,6 @@ contract CDPResolver is Helpers {
|
||||||
TokenInterface weth = tub.gem();
|
TokenInterface weth = tub.gem();
|
||||||
TokenInterface peth = tub.skr();
|
TokenInterface peth = tub.skr();
|
||||||
|
|
||||||
(address lad,,,) = tub.cups(cup);
|
|
||||||
require(lad == address(this), "cup-not-owned");
|
|
||||||
|
|
||||||
weth.deposit.value(msg.value)();
|
weth.deposit.value(msg.value)();
|
||||||
|
|
||||||
uint ink = rdiv(msg.value, tub.per());
|
uint ink = rdiv(msg.value, tub.per());
|
||||||
|
@ -181,28 +178,28 @@ contract CDPResolver is Helpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw(uint cdpNum, uint wad) public {
|
function draw(uint cdpNum, uint _wad) public {
|
||||||
bytes32 cup = bytes32(cdpNum);
|
bytes32 cup = bytes32(cdpNum);
|
||||||
if (wad > 0) {
|
if (_wad > 0) {
|
||||||
TubInterface tub = TubInterface(getSaiTubAddress());
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
|
|
||||||
(address lad,,,) = tub.cups(cup);
|
tub.draw(cup, _wad);
|
||||||
require(lad == address(this), "cup-not-owned");
|
tub.sai().transfer(msg.sender, _wad);
|
||||||
|
|
||||||
tub.draw(cup, wad);
|
|
||||||
tub.sai().transfer(msg.sender, wad);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wipe(uint cdpNum, uint wad) public {
|
function wipe(
|
||||||
require(wad > 0, "no-wipe-no-dai");
|
uint cdpNum,
|
||||||
|
uint _wad
|
||||||
|
) public
|
||||||
|
{
|
||||||
|
require(_wad > 0, "no-wipe-no-dai");
|
||||||
|
|
||||||
TubInterface tub = TubInterface(getSaiTubAddress());
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
UniswapExchange daiEx = UniswapExchange(getUniswapDAIExchange());
|
UniswapExchange daiEx = UniswapExchange(getUniswapDAIExchange());
|
||||||
UniswapExchange mkrEx = UniswapExchange(getUniswapMKRExchange());
|
UniswapExchange mkrEx = UniswapExchange(getUniswapMKRExchange());
|
||||||
TokenInterface dai = tub.sai();
|
TokenInterface dai = tub.sai();
|
||||||
TokenInterface mkr = tub.gov();
|
TokenInterface mkr = tub.gov();
|
||||||
PepInterface pep = tub.pep();
|
|
||||||
|
|
||||||
bytes32 cup = bytes32(cdpNum);
|
bytes32 cup = bytes32(cdpNum);
|
||||||
|
|
||||||
|
@ -210,15 +207,13 @@ contract CDPResolver is Helpers {
|
||||||
setAllowance(mkr, getSaiTubAddress());
|
setAllowance(mkr, getSaiTubAddress());
|
||||||
setAllowance(dai, getUniswapDAIExchange());
|
setAllowance(dai, getUniswapDAIExchange());
|
||||||
|
|
||||||
(bytes32 val, bool ok) = pep.peek();
|
(bytes32 val, bool ok) = tub.pep().peek();
|
||||||
|
|
||||||
// MKR required for wipe = Stability fees accrued in Dai / MKRUSD value
|
// 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 mkrFee = wdiv(rmul(_wad, rdiv(tub.rap(cup), tub.tab(cup))), uint(val));
|
||||||
|
|
||||||
uint ethAmt = mkrEx.getEthToTokenOutputPrice(mkrFee);
|
uint daiAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
|
||||||
uint daiAmt = daiEx.getTokenToEthOutputPrice(ethAmt);
|
daiAmt = add(_wad, daiAmt);
|
||||||
|
|
||||||
daiAmt = add(wad, daiAmt);
|
|
||||||
require(dai.transferFrom(msg.sender, address(this), daiAmt), "not-approved-yet");
|
require(dai.transferFrom(msg.sender, address(this), daiAmt), "not-approved-yet");
|
||||||
|
|
||||||
if (ok && val != 0) {
|
if (ok && val != 0) {
|
||||||
|
@ -231,7 +226,7 @@ contract CDPResolver is Helpers {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
tub.wipe(cup, wad);
|
tub.wipe(cup, _wad);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAllowance(TokenInterface token_, address spender_) private {
|
function setAllowance(TokenInterface token_, address spender_) private {
|
||||||
|
@ -245,8 +240,8 @@ contract CDPResolver is Helpers {
|
||||||
|
|
||||||
contract CDPCluster is CDPResolver {
|
contract CDPCluster is CDPResolver {
|
||||||
|
|
||||||
function wipeAndFree(uint cdpNum, uint jam, uint wad) public payable {
|
function wipeAndFree(uint cdpNum, uint jam, uint _wad) public payable {
|
||||||
wipe(cdpNum, wad);
|
wipe(cdpNum, _wad);
|
||||||
free(cdpNum, jam);
|
free(cdpNum, jam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
interface TubLike {
|
interface TubInterface {
|
||||||
function wipe(bytes32, uint) external;
|
function wipe(bytes32, uint) external;
|
||||||
function gov() external view returns (TokenLike);
|
function gov() external view returns (TokenInterface);
|
||||||
function sai() external view returns (TokenLike);
|
function sai() external view returns (TokenInterface);
|
||||||
function tab(bytes32) external returns (uint);
|
function tab(bytes32) external returns (uint);
|
||||||
function rap(bytes32) external returns (uint);
|
function rap(bytes32) external returns (uint);
|
||||||
function pep() external view returns (PepLike);
|
function pep() external view returns (PepInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TokenLike {
|
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 approve(address, uint) external;
|
function approve(address, uint) external;
|
||||||
|
@ -18,11 +18,11 @@ interface TokenLike {
|
||||||
function transferFrom(address, address, uint) external returns (bool);
|
function transferFrom(address, address, uint) external returns (bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PepLike {
|
interface PepInterface {
|
||||||
function peek() external returns (bytes32, bool);
|
function peek() external returns (bytes32, bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UniswapExchangeLike {
|
interface UniswapExchange {
|
||||||
function getEthToTokenOutputPrice(uint256 tokensBought) external view returns (uint256 ethSold);
|
function getEthToTokenOutputPrice(uint256 tokensBought) external view returns (uint256 ethSold);
|
||||||
function getTokenToEthOutputPrice(uint256 ethBought) external view returns (uint256 tokensSold);
|
function getTokenToEthOutputPrice(uint256 ethBought) external view returns (uint256 tokensSold);
|
||||||
function tokenToTokenSwapOutput(
|
function tokenToTokenSwapOutput(
|
||||||
|
@ -65,38 +65,44 @@ contract DSMath {
|
||||||
|
|
||||||
contract WipeProxy is DSMath {
|
contract WipeProxy is DSMath {
|
||||||
|
|
||||||
function wipeWithDai(
|
function getSaiTubAddress() public pure returns (address sai) {
|
||||||
address _tub,
|
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
||||||
address _daiEx,
|
}
|
||||||
address _mkrEx,
|
|
||||||
uint cupid,
|
function getUniswapMKRExchange() public pure returns (address ume) {
|
||||||
uint wad
|
ume = 0x2C4Bd064b998838076fa341A83d007FC2FA50957;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUniswapDAIExchange() public pure returns (address ude) {
|
||||||
|
ude = 0x09cabEC1eAd1c0Ba254B09efb3EE13841712bE14;
|
||||||
|
}
|
||||||
|
|
||||||
|
function wipe(
|
||||||
|
uint cdpNum,
|
||||||
|
uint _wad
|
||||||
) public
|
) public
|
||||||
{
|
{
|
||||||
require(wad > 0, "no-wipe-no-dai");
|
require(_wad > 0, "no-wipe-no-dai");
|
||||||
|
|
||||||
TubLike tub = TubLike(_tub);
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
UniswapExchangeLike daiEx = UniswapExchangeLike(_daiEx);
|
UniswapExchange daiEx = UniswapExchange(getUniswapDAIExchange());
|
||||||
UniswapExchangeLike mkrEx = UniswapExchangeLike(_mkrEx);
|
UniswapExchange mkrEx = UniswapExchange(getUniswapMKRExchange());
|
||||||
TokenLike dai = tub.sai();
|
TokenInterface dai = tub.sai();
|
||||||
TokenLike mkr = tub.gov();
|
TokenInterface mkr = tub.gov();
|
||||||
PepLike pep = tub.pep();
|
|
||||||
|
|
||||||
bytes32 cup = bytes32(cupid);
|
bytes32 cup = bytes32(cdpNum);
|
||||||
|
|
||||||
setAllowance(dai, _tub);
|
setAllowance(dai, getSaiTubAddress());
|
||||||
setAllowance(mkr, _tub);
|
setAllowance(mkr, getSaiTubAddress());
|
||||||
setAllowance(dai, _daiEx);
|
setAllowance(dai, getUniswapDAIExchange());
|
||||||
|
|
||||||
(bytes32 val, bool ok) = pep.peek();
|
(bytes32 val, bool ok) = tub.pep().peek();
|
||||||
|
|
||||||
// MKR required for wipe = Stability fees accrued in Dai / MKRUSD value
|
// 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 mkrFee = wdiv(rmul(_wad, rdiv(tub.rap(cup), tub.tab(cup))), uint(val));
|
||||||
|
|
||||||
uint ethAmt = mkrEx.getEthToTokenOutputPrice(mkrFee);
|
uint daiAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
|
||||||
uint daiAmt = daiEx.getTokenToEthOutputPrice(ethAmt);
|
daiAmt = add(_wad, daiAmt);
|
||||||
|
|
||||||
daiAmt = add(wad, daiAmt);
|
|
||||||
require(dai.transferFrom(msg.sender, address(this), daiAmt), "not-approved-yet");
|
require(dai.transferFrom(msg.sender, address(this), daiAmt), "not-approved-yet");
|
||||||
|
|
||||||
if (ok && val != 0) {
|
if (ok && val != 0) {
|
||||||
|
@ -109,10 +115,10 @@ contract WipeProxy is DSMath {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
tub.wipe(cup, wad);
|
tub.wipe(cup, _wad);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAllowance(TokenLike token_, address spender_) private {
|
function setAllowance(TokenInterface token_, address spender_) private {
|
||||||
if (token_.allowance(address(this), spender_) != uint(-1)) {
|
if (token_.allowance(address(this), spender_) != uint(-1)) {
|
||||||
token_.approve(spender_, uint(-1));
|
token_.approve(spender_, uint(-1));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user