mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
InstaMcdMigrate done.
This commit is contained in:
parent
b12feeb9bf
commit
28479c78b6
|
@ -113,16 +113,22 @@ contract DSMath {
|
||||||
contract Helpers is DSMath {
|
contract Helpers is DSMath {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev get MakerDAO CDP engine
|
* @dev get MakerDAO SCD CDP engine
|
||||||
*/
|
*/
|
||||||
function getSaiTubAddress() public pure returns (address sai) {
|
function getSaiTubAddress() public pure returns (address sai) {
|
||||||
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get Sai (Dai v1) address
|
||||||
|
*/
|
||||||
function getSaiAddress() public pure returns (address sai) {
|
function getSaiAddress() public pure returns (address sai) {
|
||||||
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
sai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get Dai (Dai v2) address
|
||||||
|
*/
|
||||||
function getDaiAddress() public pure returns (address dai) {
|
function getDaiAddress() public pure returns (address dai) {
|
||||||
dai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
dai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +141,7 @@ contract Helpers is DSMath {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev get Compound OTC Address
|
* @dev get OTC Address
|
||||||
*/
|
*/
|
||||||
function getOtcAddress() public pure returns (address otcAddr) {
|
function getOtcAddress() public pure returns (address otcAddr) {
|
||||||
otcAddr = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e; // main
|
otcAddr = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e; // main
|
||||||
|
@ -148,13 +154,6 @@ contract Helpers is DSMath {
|
||||||
ume = 0x2C4Bd064b998838076fa341A83d007FC2FA50957;
|
ume = 0x2C4Bd064b998838076fa341A83d007FC2FA50957;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev get uniswap DAI exchange
|
|
||||||
*/
|
|
||||||
function getUniswapDAIExchange() public pure returns (address ude) {
|
|
||||||
ude = 0x09cabEC1eAd1c0Ba254B09efb3EE13841712bE14;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev get uniswap factory
|
* @dev get uniswap factory
|
||||||
*/
|
*/
|
||||||
|
@ -170,13 +169,13 @@ contract Helpers is DSMath {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev setting allowance to compound for the "user proxy" if required
|
* @dev setting allowance if required
|
||||||
*/
|
*/
|
||||||
function setApproval(address erc20, uint srcAmt, address to) internal {
|
function setApproval(address erc20, uint srcAmt, address to) internal {
|
||||||
TokenInterface erc20Contract = TokenInterface(erc20);
|
TokenInterface erc20Contract = TokenInterface(erc20);
|
||||||
uint tokenAllowance = erc20Contract.allowance(address(this), to);
|
uint tokenAllowance = erc20Contract.allowance(address(this), to);
|
||||||
if (srcAmt > tokenAllowance) {
|
if (srcAmt > tokenAllowance) {
|
||||||
erc20Contract.approve(to, 2**255);
|
erc20Contract.approve(to, uint(-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +184,7 @@ contract Helpers is DSMath {
|
||||||
|
|
||||||
contract SCDResolver is Helpers {
|
contract SCDResolver is Helpers {
|
||||||
|
|
||||||
function open() public returns (bytes32 cup) {
|
function open() internal returns (bytes32 cup) {
|
||||||
cup = TubInterface(getSaiTubAddress()).open();
|
cup = TubInterface(getSaiTubAddress()).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,10 +351,33 @@ contract MCDResolver is MkrResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract MigrateResolver is MCDResolver {
|
contract LiquidityResolver is MCDResolver {
|
||||||
|
//Had to write seprate for pool, remix was showing error.
|
||||||
|
function getLiquidity(uint _wad) internal {
|
||||||
|
uint[] memory _wadArr = new uint[](1);
|
||||||
|
_wadArr[0] = _wad;
|
||||||
|
|
||||||
|
address[] memory addrArr = new address[](1);
|
||||||
|
addrArr[0] = address(0);
|
||||||
|
|
||||||
|
// Get liquidity assets to payback user wallet borrowed assets
|
||||||
|
PoolInterface(getPoolAddress()).accessToken(addrArr, _wadArr, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function paybackLiquidity(uint _wad) internal {
|
||||||
|
address[] memory addrArr = new address[](1);
|
||||||
|
addrArr[0] = address(0);
|
||||||
|
|
||||||
|
require(TokenInterface(getSaiAddress()).transfer(getPoolAddress(), _wad), "Not-enough-dai");
|
||||||
|
PoolInterface(getPoolAddress()).paybackToken(addrArr, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
contract MigrateResolver is LiquidityResolver {
|
||||||
event LogMigrate(uint scdCdp, uint toConvert, address payFeeWith, uint mcdCdp);
|
event LogMigrate(uint scdCdp, uint toConvert, address payFeeWith, uint mcdCdp);
|
||||||
function migrate(
|
function migrate(
|
||||||
bytes32 scdCup,
|
uint scdCDP,
|
||||||
// uint mcdCDP, for merge
|
// uint mcdCDP, for merge
|
||||||
uint toConvert,
|
uint toConvert,
|
||||||
address payFeeWith,
|
address payFeeWith,
|
||||||
|
@ -363,8 +385,11 @@ contract MigrateResolver is MCDResolver {
|
||||||
) external payable returns (uint cdp)
|
) external payable returns (uint cdp)
|
||||||
{
|
{
|
||||||
TubInterface tub = TubInterface(getSaiTubAddress());
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
|
bytes32 scdCup = bytes32(scdCDP);
|
||||||
|
|
||||||
uint _jam = rmul(tub.ink(scdCup), tub.per());
|
uint _jam = rmul(tub.ink(scdCup), tub.per());
|
||||||
uint _wad = tub.tab(scdCup);
|
uint _wad = tub.tab(scdCup);
|
||||||
|
|
||||||
if (toConvert < 10**18) {
|
if (toConvert < 10**18) {
|
||||||
uint initialPoolBal = sub(getPoolAddress().balance, 10000000000);
|
uint initialPoolBal = sub(getPoolAddress().balance, 10000000000);
|
||||||
bytes32 splitCup = TubInterface(getSaiTubAddress()).open();
|
bytes32 splitCup = TubInterface(getSaiTubAddress()).open();
|
||||||
|
@ -372,22 +397,19 @@ contract MigrateResolver is MCDResolver {
|
||||||
_jam = wmul(_jam, toConvert);
|
_jam = wmul(_jam, toConvert);
|
||||||
_wad = wmul(_wad, toConvert);
|
_wad = wmul(_wad, toConvert);
|
||||||
|
|
||||||
|
//get liquidity from InstaDApp Pool.
|
||||||
uint[] memory _wadArr = new uint[](1);
|
getLiquidity(_wad);
|
||||||
_wadArr[0] = _wad;
|
|
||||||
|
|
||||||
address[] memory addrArr = new address[](1);
|
|
||||||
addrArr[0] = address(0);
|
|
||||||
|
|
||||||
// Get liquidity assets to payback user wallet borrowed assets
|
|
||||||
PoolInterface(getPoolAddress()).accessToken(addrArr, _wadArr, false);
|
|
||||||
|
|
||||||
(bytes32 val, bool ok) = tub.pep().peek();
|
(bytes32 val, bool ok) = tub.pep().peek();
|
||||||
|
|
||||||
if (ok && val != 0) {
|
if (ok && val != 0) {
|
||||||
// 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(scdCup), tub.tab(scdCup))), uint(val));
|
uint mkrFee = rdiv(tub.rap(scdCup), tub.tab(scdCup)); // I had to split because it was showing error in remix.
|
||||||
swapToMkrUniswap(payFeeWith, mkrFee);
|
mkrFee = rmul(_wad, mkrFee);
|
||||||
|
mkrFee = wdiv(mkrFee, uint(val));
|
||||||
|
|
||||||
|
// swapToMkrUniswap(payFeeWith, mkrFee); //Uniswap
|
||||||
|
swapToMkrOtc(payFeeWith, mkrFee); //otc
|
||||||
}
|
}
|
||||||
|
|
||||||
wipe(scdCup, _wad);
|
wipe(scdCup, _wad);
|
||||||
|
@ -396,8 +418,8 @@ contract MigrateResolver is MCDResolver {
|
||||||
lock(splitCup, _jam);
|
lock(splitCup, _jam);
|
||||||
draw(splitCup, _wad);
|
draw(splitCup, _wad);
|
||||||
|
|
||||||
require(TokenInterface(getSaiAddress()).transfer(getPoolAddress(), _wad), "Not-enough-dai");
|
//transfer and payback liquidity to InstaDApp Pool.
|
||||||
PoolInterface(getPoolAddress()).paybackToken(addrArr, false);
|
paybackLiquidity(_wad);
|
||||||
|
|
||||||
uint finalPoolBal = getPoolAddress().balance;
|
uint finalPoolBal = getPoolAddress().balance;
|
||||||
assert(finalPoolBal >= initialPoolBal);
|
assert(finalPoolBal >= initialPoolBal);
|
||||||
|
@ -406,6 +428,11 @@ contract MigrateResolver is MCDResolver {
|
||||||
} else {
|
} else {
|
||||||
cdp = migrateToMCD(scdMcdMigration, scdCup, payFeeWith);
|
cdp = migrateToMCD(scdMcdMigration, scdCup, payFeeWith);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TokenInterface weth = TokenInterface(getWETHAddress());
|
||||||
|
weth.withdraw(weth.balanceOf(address(this))); //withdraw WETH, if any leftover.
|
||||||
|
msg.sender.transfer(address(this).balance); //transfer leftover ETH.
|
||||||
|
|
||||||
emit LogMigrate(
|
emit LogMigrate(
|
||||||
uint(scdCup),
|
uint(scdCup),
|
||||||
toConvert,
|
toConvert,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user