mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
fee with MKR new function
This commit is contained in:
parent
2c1b42c6bf
commit
2f440bca2f
|
@ -336,13 +336,7 @@ contract MakerResolver is InstaPoolResolver {
|
||||||
/**
|
/**
|
||||||
* @dev Pay CDP debt
|
* @dev Pay CDP debt
|
||||||
*/
|
*/
|
||||||
function wipe(
|
function wipe(uint cdpNum, uint _wad, bool isCompound) internal returns (uint daiAmt) {
|
||||||
uint cdpNum,
|
|
||||||
uint _wad,
|
|
||||||
bool isCompound,
|
|
||||||
bool feeInMkr
|
|
||||||
) internal returns (uint daiAmt)
|
|
||||||
{
|
|
||||||
if (_wad > 0) {
|
if (_wad > 0) {
|
||||||
TubInterface tub = TubInterface(getSaiTubAddress());
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
UniswapExchange daiEx = UniswapExchange(getUniswapDAIExchange());
|
UniswapExchange daiEx = UniswapExchange(getUniswapDAIExchange());
|
||||||
|
@ -364,27 +358,20 @@ contract MakerResolver is InstaPoolResolver {
|
||||||
// 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 daiFeeAmt = 0;
|
uint daiFeeAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
|
||||||
if (!feeInMkr) {
|
daiAmt = add(_wad, daiFeeAmt);
|
||||||
daiFeeAmt = daiEx.getTokenToEthOutputPrice(mkrEx.getEthToTokenOutputPrice(mkrFee));
|
|
||||||
daiAmt = add(_wad, daiFeeAmt);
|
|
||||||
} else {
|
|
||||||
daiAmt = _wad;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getting Liquidity from Liquidity Contract
|
// Getting Liquidity from Liquidity Contract
|
||||||
accessDai(daiAmt, isCompound);
|
accessDai(daiAmt, isCompound);
|
||||||
|
|
||||||
if (ok && val != 0 && !feeInMkr) {
|
if (ok && val != 0) {
|
||||||
daiEx.tokenToTokenSwapOutput(
|
daiEx.tokenToTokenSwapOutput(
|
||||||
mkrFee,
|
mkrFee,
|
||||||
daiFeeAmt + 1,
|
daiFeeAmt,
|
||||||
uint(999000000000000000000),
|
uint(999000000000000000000),
|
||||||
uint(1899063809), // 6th March 2030 GMT // no logic
|
uint(1899063809), // 6th March 2030 GMT // no logic
|
||||||
address(mkr)
|
address(mkr)
|
||||||
);
|
);
|
||||||
} else if (ok && val != 0) {
|
|
||||||
require(mkr.transferFrom(msg.sender, address(this), mkrFee), "MKR-Allowance?");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tub.wipe(cup, _wad);
|
tub.wipe(cup, _wad);
|
||||||
|
@ -400,6 +387,49 @@ contract MakerResolver is InstaPoolResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Pay CDP debt
|
||||||
|
*/
|
||||||
|
function wipeWithMkr(uint cdpNum, uint _wad, bool isCompound) internal {
|
||||||
|
if (_wad > 0) {
|
||||||
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
|
TokenInterface dai = tub.sai();
|
||||||
|
TokenInterface mkr = tub.gov();
|
||||||
|
|
||||||
|
bytes32 cup = bytes32(cdpNum);
|
||||||
|
|
||||||
|
(address lad,,,) = tub.cups(cup);
|
||||||
|
require(lad == address(this), "cup-not-owned");
|
||||||
|
|
||||||
|
setMakerAllowance(dai, getSaiTubAddress());
|
||||||
|
setMakerAllowance(mkr, getSaiTubAddress());
|
||||||
|
setMakerAllowance(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));
|
||||||
|
|
||||||
|
// Getting Liquidity from Liquidity Contract
|
||||||
|
accessDai(_wad, isCompound);
|
||||||
|
|
||||||
|
if (ok && val != 0) {
|
||||||
|
require(mkr.transferFrom(msg.sender, address(this), mkrFee), "MKR-Allowance?");
|
||||||
|
}
|
||||||
|
|
||||||
|
tub.wipe(cup, _wad);
|
||||||
|
|
||||||
|
emit LogWipe(
|
||||||
|
cdpNum,
|
||||||
|
_wad,
|
||||||
|
mkrFee,
|
||||||
|
0,
|
||||||
|
address(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Withdraw CDP
|
* @dev Withdraw CDP
|
||||||
*/
|
*/
|
||||||
|
@ -489,12 +519,12 @@ contract MakerResolver is InstaPoolResolver {
|
||||||
bool feeInMkr
|
bool feeInMkr
|
||||||
) internal returns (uint daiAmt)
|
) internal returns (uint daiAmt)
|
||||||
{
|
{
|
||||||
daiAmt = wipe(
|
if (feeInMkr) {
|
||||||
cdpNum,
|
wipeWithMkr(cdpNum, _wad, isCompound);
|
||||||
_wad,
|
daiAmt = _wad;
|
||||||
isCompound,
|
} else {
|
||||||
feeInMkr
|
daiAmt = wipe(cdpNum, _wad, isCompound);
|
||||||
);
|
}
|
||||||
free(cdpNum, jam);
|
free(cdpNum, jam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user