diff --git a/contracts/connectors/reflexer/helpers.sol b/contracts/connectors/reflexer/helpers.sol index a6c2b506..2cb478e2 100644 --- a/contracts/connectors/reflexer/helpers.sol +++ b/contracts/connectors/reflexer/helpers.sol @@ -3,7 +3,7 @@ pragma solidity ^0.7.0; import { DSMath } from "../../common/math.sol"; import { Basic } from "../../common/basic.sol"; import { TokenInterface } from "../../common/interfaces.sol"; -import { ManagerLike, DaiJoinInterface, PotLike, VatLike, JugLike } from "./interface.sol"; +import { ManagerLike, CoinJoinInterface, SafeEngineLike, TaxCollectorLike } from "./interface.sol"; abstract contract Helpers is DSMath, Basic { /** @@ -14,17 +14,12 @@ abstract contract Helpers is DSMath, Basic { /** * @dev DAI Join */ - DaiJoinInterface internal constant daiJoinContract = DaiJoinInterface(0x9759A6Ac90977b93B58547b4A71c78317f391A28); - - /** - * @dev Pot - */ - PotLike internal constant potContract = PotLike(0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7); + CoinJoinInterface internal constant daiJoinContract = CoinJoinInterface(0x9759A6Ac90977b93B58547b4A71c78317f391A28); /** * @dev Maker MCD Jug Address. */ - JugLike internal constant mcdJug = JugLike(0x19c0976f590D67707E62397C87829d896Dc0f1F1); + TaxCollectorLike internal constant mcdJug = TaxCollectorLike(0x19c0976f590D67707E62397C87829d896Dc0f1F1); /** * @dev Return Close Vault Address. @@ -35,8 +30,8 @@ abstract contract Helpers is DSMath, Basic { * @dev Get Vault's ilk. */ function getVaultData(uint vault) internal view returns (bytes32 ilk, address urn) { - ilk = managerContract.ilks(vault); - urn = managerContract.urns(vault); + ilk = managerContract.collateralTypes(vault); + urn = managerContract.safes(vault); } /** @@ -54,11 +49,11 @@ abstract contract Helpers is DSMath, Basic { bytes32 ilk, address urn ) internal view returns (uint wad) { - (, uint rate,,,) = VatLike(vat).ilks(ilk); - (, uint art) = VatLike(vat).urns(ilk, urn); - uint dai = VatLike(vat).dai(urn); + (, uint rate,,,) = SafeEngineLike(vat).collateralTypes(ilk); + (, uint art) = SafeEngineLike(vat).safes(ilk, urn); + uint coin = SafeEngineLike(vat).coin(urn); - uint rad = sub(mul(art, rate), dai); + uint rad = sub(mul(art, rate), coin); wad = rad / RAY; wad = mul(wad, RAY) < rad ? wad + 1 : wad; @@ -74,10 +69,10 @@ abstract contract Helpers is DSMath, Basic { uint amt ) internal returns (int dart) { - uint rate = mcdJug.drip(ilk); - uint dai = VatLike(vat).dai(urn); - if (dai < mul(amt, RAY)) { - dart = toInt(sub(mul(amt, RAY), dai) / rate); + uint rate = mcdJug.taxSingle(ilk); + uint coin = SafeEngineLike(vat).coin(urn); + if (coin < mul(amt, RAY)) { + dart = toInt(sub(mul(amt, RAY), coin) / rate); dart = mul(uint(dart), rate) < mul(amt, RAY) ? dart + 1 : dart; } } @@ -92,8 +87,8 @@ abstract contract Helpers is DSMath, Basic { bytes32 ilk ) internal view returns (int dart) { - (, uint rate,,,) = VatLike(vat).ilks(ilk); - (, uint art) = VatLike(vat).urns(ilk, urn); + (, uint rate,,,) = SafeEngineLike(vat).collateralTypes(ilk); + (, uint art) = SafeEngineLike(vat).safes(ilk, urn); dart = toInt(amt / rate); dart = uint(dart) <= art ? - dart : - toInt(art); } @@ -110,12 +105,12 @@ abstract contract Helpers is DSMath, Basic { } /** - * @dev Get vault ID. If `vault` is 0, get last opened vault. + * @dev Get vault ID. If `vault` is 0, get lastSAFEID opened vault. */ function getVault(uint vault) internal view returns (uint _vault) { if (vault == 0) { - require(managerContract.count(address(this)) > 0, "no-vault-opened"); - _vault = managerContract.last(address(this)); + require(managerContract.safeCount(address(this)) > 0, "no-vault-opened"); + _vault = managerContract.lastSAFEID(address(this)); } else { _vault = vault; } diff --git a/contracts/connectors/reflexer/interface.sol b/contracts/connectors/reflexer/interface.sol index 50aa6cd1..983734d7 100644 --- a/contracts/connectors/reflexer/interface.sol +++ b/contracts/connectors/reflexer/interface.sol @@ -3,26 +3,26 @@ pragma solidity ^0.7.0; import { TokenInterface } from "../../common/interfaces.sol"; interface ManagerLike { - function cdpCan(address, uint, address) external view returns (uint); - function ilks(uint) external view returns (bytes32); - function last(address) external view returns (uint); - function count(address) external view returns (uint); - function owns(uint) external view returns (address); - function urns(uint) external view returns (address); - function vat() external view returns (address); - function open(bytes32, address) external returns (uint); - function give(uint, address) external; - function frob(uint, int, int) external; - function flux(uint, address, uint) external; - function move(uint, address, uint) external; + function safeCan(address, uint, address) external view returns (uint); + function collateralTypes(uint) external view returns (bytes32); + function lastSAFEID(address) external view returns (uint); + function safeCount(address) external view returns (uint); + function ownsSAFE(uint) external view returns (address); + function safes(uint) external view returns (address); + function safeEngine() external view returns (address); + function openSAFE(bytes32, address) external returns (uint); + function transferSAFEOwnership(uint, address) external; + function modifySAFECollateralization(uint, int, int) external; + function transferCollateral(uint, address, uint) external; + function transferInternalCoins(uint, address, uint) external; } -interface VatLike { +interface SafeEngineLike { function can(address, address) external view returns (uint); - function ilks(bytes32) external view returns (uint, uint, uint, uint, uint); - function dai(address) external view returns (uint); - function urns(bytes32, address) external view returns (uint, uint); - function frob( + function collateralTypes(bytes32) external view returns (uint, uint, uint, uint, uint); + function coin(address) external view returns (uint); + function safes(bytes32, address) external view returns (uint, uint); + function modifySAFECollateralization( bytes32, address, address, @@ -30,32 +30,25 @@ interface VatLike { int, int ) external; - function hope(address) external; - function move(address, address, uint) external; - function gem(bytes32, address) external view returns (uint); + function approveSAFEModification(address) external; + function transferInternalCoins(address, address, uint) external; + function tokenCollateral(bytes32, address) external view returns (uint); } interface TokenJoinInterface { - function dec() external returns (uint); - function gem() external returns (TokenInterface); + function decimals() external returns (uint); + function collateral() external returns (TokenInterface); function join(address, uint) external payable; function exit(address, uint) external; } -interface DaiJoinInterface { - function vat() external returns (VatLike); - function dai() external returns (TokenInterface); +interface CoinJoinInterface { + function safeEngine() external returns (SafeEngineLike); + function coin() external returns (TokenInterface); function join(address, uint) external payable; function exit(address, uint) external; } -interface JugLike { - function drip(bytes32) external returns (uint); -} - -interface PotLike { - function pie(address) external view returns (uint); - function drip() external returns (uint); - function join(uint) external; - function exit(uint) external; +interface TaxCollectorLike { + function taxSingle(bytes32) external returns (uint); } diff --git a/contracts/connectors/reflexer/main.sol b/contracts/connectors/reflexer/main.sol index 139438d3..c28fba79 100644 --- a/contracts/connectors/reflexer/main.sol +++ b/contracts/connectors/reflexer/main.sol @@ -3,7 +3,7 @@ pragma solidity ^0.7.0; import { TokenInterface } from "../../common/interfaces.sol"; import { Helpers } from "./helpers.sol"; import { Events } from "./events.sol"; -import { VatLike, TokenJoinInterface } from "./interface.sol"; +import { SafeEngineLike, TokenJoinInterface } from "./interface.sol"; abstract contract MakerResolver is Helpers, Events { /** @@ -13,7 +13,7 @@ abstract contract MakerResolver is Helpers, Events { function open(string calldata colType) external payable returns (string memory _eventName, bytes memory _eventParam) { bytes32 ilk = stringToBytes32(colType); require(instaMapping.gemJoinMapping(ilk) != address(0), "wrong-col-type"); - uint256 vault = managerContract.open(ilk, address(this)); + uint256 vault = managerContract.openSAFE(ilk, address(this)); _eventName = "LogOpen(uint256,bytes32)"; _eventParam = abi.encode(vault, ilk); @@ -26,12 +26,12 @@ abstract contract MakerResolver is Helpers, Events { function close(uint256 vault) external payable returns (string memory _eventName, bytes memory _eventParam) { uint _vault = getVault(vault); (bytes32 ilk, address urn) = getVaultData(_vault); - (uint ink, uint art) = VatLike(managerContract.vat()).urns(ilk, urn); + (uint ink, uint art) = SafeEngineLike(managerContract.safeEngine()).safes(ilk, urn); require(ink == 0 && art == 0, "vault-has-assets"); - require(managerContract.owns(_vault) == address(this), "not-owner"); + require(managerContract.ownsSAFE(_vault) == address(this), "not-owner"); - managerContract.give(_vault, giveAddr); + managerContract.transferSAFEOwnership(_vault, giveAddr); _eventName = "LogClose(uint256,bytes32)"; _eventParam = abi.encode(_vault, ilk); @@ -56,7 +56,7 @@ abstract contract MakerResolver is Helpers, Events { address colAddr = instaMapping.gemJoinMapping(ilk); TokenJoinInterface tokenJoinContract = TokenJoinInterface(colAddr); - TokenInterface tokenContract = tokenJoinContract.gem(); + TokenInterface tokenContract = tokenJoinContract.collateral(); if (isEth(address(tokenContract))) { _amt = _amt == uint(-1) ? address(this).balance : _amt; @@ -68,12 +68,12 @@ abstract contract MakerResolver is Helpers, Events { tokenContract.approve(address(colAddr), _amt); tokenJoinContract.join(address(this), _amt); - VatLike(managerContract.vat()).frob( + SafeEngineLike(managerContract.safeEngine()).modifySAFECollateralization( ilk, urn, address(this), address(this), - toInt(convertTo18(tokenJoinContract.dec(), _amt)), + toInt(convertTo18(tokenJoinContract.decimals(), _amt)), 0 ); @@ -105,25 +105,25 @@ abstract contract MakerResolver is Helpers, Events { uint _amt18; if (_amt == uint(-1)) { - (_amt18,) = VatLike(managerContract.vat()).urns(ilk, urn); - _amt = convert18ToDec(tokenJoinContract.dec(), _amt18); + (_amt18,) = SafeEngineLike(managerContract.safeEngine()).safes(ilk, urn); + _amt = convert18ToDec(tokenJoinContract.decimals(), _amt18); } else { - _amt18 = convertTo18(tokenJoinContract.dec(), _amt); + _amt18 = convertTo18(tokenJoinContract.decimals(), _amt); } - managerContract.frob( + managerContract.modifySAFECollateralization( _vault, -toInt(_amt18), 0 ); - managerContract.flux( + managerContract.transferCollateral( _vault, address(this), _amt18 ); - TokenInterface tokenContract = tokenJoinContract.gem(); + TokenInterface tokenContract = tokenJoinContract.collateral(); if (isEth(address(tokenContract))) { tokenJoinContract.exit(address(this), _amt); @@ -155,9 +155,9 @@ abstract contract MakerResolver is Helpers, Events { uint _vault = getVault(vault); (bytes32 ilk, address urn) = getVaultData(_vault); - VatLike vatContract = VatLike(managerContract.vat()); + SafeEngineLike vatContract = SafeEngineLike(managerContract.safeEngine()); - managerContract.frob( + managerContract.modifySAFECollateralization( _vault, 0, _getBorrowAmt( @@ -168,14 +168,14 @@ abstract contract MakerResolver is Helpers, Events { ) ); - managerContract.move( + managerContract.transferInternalCoins( _vault, address(this), toRad(_amt) ); if (vatContract.can(address(this), address(daiJoinContract)) == 0) { - vatContract.hope(address(daiJoinContract)); + vatContract.approveSAFEModification(address(daiJoinContract)); } daiJoinContract.exit(address(this), _amt); @@ -203,7 +203,7 @@ abstract contract MakerResolver is Helpers, Events { uint _vault = getVault(vault); (bytes32 ilk, address urn) = getVaultData(_vault); - address vat = managerContract.vat(); + address vat = managerContract.safeEngine(); uint _maxDebt = _getVaultDebt(vat, ilk, urn); @@ -211,15 +211,15 @@ abstract contract MakerResolver is Helpers, Events { require(_maxDebt >= _amt, "paying-excess-debt"); - daiJoinContract.dai().approve(address(daiJoinContract), _amt); + daiJoinContract.coin().approve(address(daiJoinContract), _amt); daiJoinContract.join(urn, _amt); - managerContract.frob( + managerContract.modifySAFECollateralization( _vault, 0, _getWipeAmt( vat, - VatLike(vat).dai(urn), + SafeEngineLike(vat).coin(urn), urn, ilk ) @@ -252,19 +252,19 @@ abstract contract MakerResolver is Helpers, Events { uint _amt18; if (_amt == uint(-1)) { - _amt18 = VatLike(managerContract.vat()).gem(ilk, urn); - _amt = convert18ToDec(tokenJoinContract.dec(), _amt18); + _amt18 = SafeEngineLike(managerContract.safeEngine()).tokenCollateral(ilk, urn); + _amt = convert18ToDec(tokenJoinContract.decimals(), _amt18); } else { - _amt18 = convertTo18(tokenJoinContract.dec(), _amt); + _amt18 = convertTo18(tokenJoinContract.decimals(), _amt); } - managerContract.flux( + managerContract.transferCollateral( vault, address(this), _amt18 ); - TokenInterface tokenContract = tokenJoinContract.gem(); + TokenInterface tokenContract = tokenJoinContract.collateral(); tokenJoinContract.exit(address(this), _amt); if (isEth(address(tokenContract))) { tokenContract.withdraw(_amt); @@ -280,7 +280,7 @@ abstract contract MakerResolver is Helpers, Events { uint _vault; address colAddr; TokenJoinInterface tokenJoinContract; - VatLike vatContract; + SafeEngineLike vatContract; TokenInterface tokenContract; } /** @@ -311,8 +311,8 @@ abstract contract MakerResolver is Helpers, Events { makerData.colAddr = instaMapping.gemJoinMapping(ilk); makerData.tokenJoinContract = TokenJoinInterface(makerData.colAddr); - makerData.vatContract = VatLike(managerContract.vat()); - makerData.tokenContract = makerData.tokenJoinContract.gem(); + makerData.vatContract = SafeEngineLike(managerContract.safeEngine()); + makerData.tokenContract = makerData.tokenJoinContract.collateral(); if (isEth(address(makerData.tokenContract))) { _amtDeposit = _amtDeposit == uint(-1) ? address(this).balance : _amtDeposit; @@ -324,9 +324,9 @@ abstract contract MakerResolver is Helpers, Events { makerData.tokenContract.approve(address(makerData.colAddr), _amtDeposit); makerData.tokenJoinContract.join(urn, _amtDeposit); - managerContract.frob( + managerContract.modifySAFECollateralization( makerData._vault, - toInt(convertTo18(makerData.tokenJoinContract.dec(), _amtDeposit)), + toInt(convertTo18(makerData.tokenJoinContract.decimals(), _amtDeposit)), _getBorrowAmt( address(makerData.vatContract), urn, @@ -335,14 +335,14 @@ abstract contract MakerResolver is Helpers, Events { ) ); - managerContract.move( + managerContract.transferInternalCoins( makerData._vault, address(this), toRad(_amtBorrow) ); if (makerData.vatContract.can(address(this), address(daiJoinContract)) == 0) { - makerData.vatContract.hope(address(daiJoinContract)); + makerData.vatContract.approveSAFEModification(address(daiJoinContract)); } daiJoinContract.exit(address(this), _amtBorrow); @@ -380,20 +380,20 @@ abstract contract MakerResolver is Helpers, Events { uint _vault = getVault(vault); (bytes32 ilk, address urn) = getVaultData(_vault); - VatLike vatContract = VatLike(managerContract.vat()); + SafeEngineLike vatContract = SafeEngineLike(managerContract.safeEngine()); if(_amt == uint(-1)) { - _amt = vatContract.dai(urn); + _amt = vatContract.coin(urn); _amt = _amt / 10 ** 27; } - managerContract.move( + managerContract.transferInternalCoins( _vault, address(this), toRad(_amt) ); if (vatContract.can(address(this), address(daiJoinContract)) == 0) { - vatContract.hope(address(daiJoinContract)); + vatContract.approveSAFEModification(address(daiJoinContract)); } daiJoinContract.exit(address(this), _amt); @@ -404,79 +404,6 @@ abstract contract MakerResolver is Helpers, Events { _eventParam = abi.encode(_vault, ilk, _amt, getId, setId); } - /** - * @dev Deposit DAI in DSR. - * @param amt DAI amount to deposit. - * @param getId Get token amount at this ID from `InstaMemory` Contract. - * @param setId Set token amount at this ID in `InstaMemory` Contract. - */ - function depositDai( - uint256 amt, - uint256 getId, - uint256 setId - ) external payable returns (string memory _eventName, bytes memory _eventParam) { - uint _amt = getUint(getId, amt); - - _amt = _amt == uint(-1) ? - daiJoinContract.dai().balanceOf(address(this)) : - _amt; - - VatLike vat = daiJoinContract.vat(); - uint chi = potContract.drip(); - - daiJoinContract.dai().approve(address(daiJoinContract), _amt); - daiJoinContract.join(address(this), _amt); - if (vat.can(address(this), address(potContract)) == 0) { - vat.hope(address(potContract)); - } - - potContract.join(mul(_amt, RAY) / chi); - setUint(setId, _amt); - - _eventName = "LogDepositDai(uint256,uint256,uint256)"; - _eventParam = abi.encode(_amt, getId, setId); - } - - /** - * @dev Withdraw DAI from DSR. - * @param amt DAI amount to withdraw. - * @param getId Get token amount at this ID from `InstaMemory` Contract. - * @param setId Set token amount at this ID in `InstaMemory` Contract. - */ - function withdrawDai( - uint256 amt, - uint256 getId, - uint256 setId - ) external payable returns (string memory _eventName, bytes memory _eventParam) { - uint _amt = getUint(getId, amt); - - VatLike vat = daiJoinContract.vat(); - - uint chi = potContract.drip(); - uint pie; - if (_amt == uint(-1)) { - pie = potContract.pie(address(this)); - _amt = mul(chi, pie) / RAY; - } else { - pie = mul(_amt, RAY) / chi; - } - - potContract.exit(pie); - - uint bal = vat.dai(address(this)); - if (vat.can(address(this), address(daiJoinContract)) == 0) { - vat.hope(address(daiJoinContract)); - } - daiJoinContract.exit( - address(this), - bal >= mul(_amt, RAY) ? _amt : bal / RAY - ); - - setUint(setId, _amt); - - _eventName = "LogWithdrawDai(uint256,uint256,uint256)"; - _eventParam = abi.encode(_amt, getId, setId); - } } contract ConnectV2Maker is MakerResolver {