mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
added maxConvert to mcd migrate
This commit is contained in:
parent
36dce595ae
commit
f3d7c03f4c
|
@ -129,9 +129,9 @@ contract Helpers is DSMath {
|
||||||
/**
|
/**
|
||||||
* @dev get Dai (Dai v2) address
|
* @dev get Dai (Dai v2) address
|
||||||
*/
|
*/
|
||||||
function getDaiAddress() public pure returns (address dai) {
|
// function getDaiAddress() public pure returns (address dai) {
|
||||||
dai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
// dai = 0x448a5065aeBB8E423F0896E6c5D525C040f59af3;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev get Compound WETH Address
|
* @dev get Compound WETH Address
|
||||||
|
@ -300,20 +300,6 @@ contract SCDResolver is MKRSwapper {
|
||||||
|
|
||||||
|
|
||||||
contract MCDResolver is SCDResolver {
|
contract MCDResolver is SCDResolver {
|
||||||
function swapDaiToSai( // Check Samyak - It's not needed for this contract
|
|
||||||
address payable scdMcdMigration, // Migration contract address
|
|
||||||
uint wad // Amount to swap
|
|
||||||
) internal
|
|
||||||
{
|
|
||||||
// TokenInterface sai = TokenInterface(getSaiAddress());
|
|
||||||
TokenInterface dai = TokenInterface(getDaiAddress());
|
|
||||||
dai.transferFrom(msg.sender, address(this), wad);
|
|
||||||
if (dai.allowance(address(this), scdMcdMigration) < wad) {
|
|
||||||
dai.approve(scdMcdMigration, wad);
|
|
||||||
}
|
|
||||||
MCDInterface(scdMcdMigration).swapDaiToSai(wad);
|
|
||||||
}
|
|
||||||
|
|
||||||
function migrateToMCD(
|
function migrateToMCD(
|
||||||
address payable scdMcdMigration, // Migration contract address
|
address payable scdMcdMigration, // Migration contract address
|
||||||
bytes32 cup, // SCD CDP Id to migrate
|
bytes32 cup, // SCD CDP Id to migrate
|
||||||
|
@ -372,20 +358,31 @@ contract MigrateResolver is LiquidityResolver {
|
||||||
// uint mcdCDP, for merge
|
// uint mcdCDP, for merge
|
||||||
uint toConvert,
|
uint toConvert,
|
||||||
address payFeeWith,
|
address payFeeWith,
|
||||||
address payable scdMcdMigration
|
address payable scdMcdMigration,
|
||||||
|
address daiJoin // Check Thrilok - will remove in the last, when we get final address
|
||||||
) external payable returns (uint cdp)
|
) external payable returns (uint cdp)
|
||||||
{
|
{
|
||||||
TubInterface tub = TubInterface(getSaiTubAddress());
|
TubInterface tub = TubInterface(getSaiTubAddress());
|
||||||
bytes32 scdCup = bytes32(scdCDP);
|
bytes32 scdCup = bytes32(scdCDP);
|
||||||
|
uint maxConvert = toConvert;
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
// Check Samyak - have to check max limit to convert. Hint: SAI balance in "x" contract. If toConvert > maxConvert then toConvert = maxConvert;
|
// Check Thrilok - check if ratio is good.
|
||||||
|
uint saiBal = tub.sai().balanceOf(daiJoin);
|
||||||
|
uint _wadTotal = tub.tab(scdCup);
|
||||||
|
uint _wad = wmul(_wadTotal, toConvert);
|
||||||
|
|
||||||
uint _ink = wmul(tub.ink(scdCup), toConvert); // Taking collateral in PETH only
|
// Check if sai_join has enough sai to migrate.
|
||||||
uint _wad = wmul(tub.tab(scdCup), toConvert);
|
if (saiBal < _wad) {
|
||||||
|
// Set new convert ratio according to sai_join balance.
|
||||||
|
maxConvert = sub(wdiv(saiBal, _wadTotal), 1000000000000000);
|
||||||
|
_wad = wmul(_wadTotal, maxConvert);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint _ink = wmul(tub.ink(scdCup), maxConvert); // Taking collateral in PETH only
|
||||||
|
|
||||||
// getting liquidity from InstaDApp Pool.
|
// getting liquidity from InstaDApp Pool.
|
||||||
getLiquidity(_wad);
|
getLiquidity(_wad);
|
||||||
|
@ -413,7 +410,7 @@ contract MigrateResolver is LiquidityResolver {
|
||||||
|
|
||||||
emit LogMigrate(
|
emit LogMigrate(
|
||||||
uint(scdCup),
|
uint(scdCup),
|
||||||
toConvert,
|
maxConvert,
|
||||||
payFeeWith,
|
payFeeWith,
|
||||||
cdp
|
cdp
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user