diff --git a/contracts/mainnet/connectors/makerdao-import/events.sol b/contracts/mainnet/connectors/makerdao-import/events.sol new file mode 100644 index 00000000..6f59d9ab --- /dev/null +++ b/contracts/mainnet/connectors/makerdao-import/events.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogTransferToAvo(uint256 indexed vault, bytes32 indexed ilk, address indexed avoAddress); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/makerdao-import/helpers.sol b/contracts/mainnet/connectors/makerdao-import/helpers.sol new file mode 100644 index 00000000..1c261d28 --- /dev/null +++ b/contracts/mainnet/connectors/makerdao-import/helpers.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +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, VatLike, IAvoFactory, IAvoCreditManagerAddress } from "./interface.sol"; + +abstract contract Helpers is DSMath, Basic { + ManagerLike internal constant managerContract = ManagerLike(0x5ef30b9986345249bc32d8928B7ee64DE9435E39); + IAvoFactory internal constant avoFactory = IAvoFactory(0x3AdAE9699029AB2953F607AE1f62372681D35978); + IAvoCreditManagerAddress internal constant avoCreditManager = IAvoCreditManagerAddress(0xE4C9751D5CBCde942165871Ca2089172307F9971); + + function getVaultData(uint vault) internal view returns (bytes32 ilk, address urn) { + ilk = managerContract.ilks(vault); + urn = managerContract.urns(vault); + } + + function stringToBytes32(string memory str) internal pure returns (bytes32 result) { + require(bytes(str).length != 0, "string-empty"); + assembly { + result := mload(add(str, 32)) + } + } + + 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)); + } else { + _vault = vault; + } + } +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/makerdao-import/interface.sol b/contracts/mainnet/connectors/makerdao-import/interface.sol new file mode 100644 index 00000000..7d2d7534 --- /dev/null +++ b/contracts/mainnet/connectors/makerdao-import/interface.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: MIT +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; +} + +interface VatLike { + 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( + bytes32, + address, + address, + address, + int, + int + ) external; + function hope(address) external; + function move(address, address, uint) external; + function gem(bytes32, address) external view returns (uint); +} + +interface IAvoFactory { + function computeAddress(address owner_) external view returns (address); +} + +interface IAvoCreditManagerAddress { + function dsaMakerImport(uint256 vaultId_, address avoSafe_, address auth_) external; +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/makerdao-import/main.sol b/contracts/mainnet/connectors/makerdao-import/main.sol new file mode 100644 index 00000000..0ca17b80 --- /dev/null +++ b/contracts/mainnet/connectors/makerdao-import/main.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import { TokenInterface, AccountInterface } from "../../common/interfaces.sol"; +import { Helpers } from "./helpers.sol"; +import { Events } from "./events.sol"; + +contract MakerTransferResolver is Helpers, Events { + function transferToAvo(uint256 vaultId) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint256 _vault = getVault(vaultId); + (bytes32 ilk,) = getVaultData(_vault); + + require(managerContract.owns(_vault) == address(this), "not-owner"); + + address avoAddress = avoFactory.computeAddress(msg.sender); + managerContract.give(_vault, avoAddress); + + avoCreditManager.dsaMakerImport(_vault, avoAddress, msg.sender); + + _eventName = "LogTransferToAvo(uint256,bytes32,address)"; + _eventParam = abi.encode(_vault, ilk, avoAddress); + } +} + +contract ConnectV2AvoMakerImport is MakerTransferResolver { + string public constant name = "Avocado-Maker-Import-v1.0"; +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bc7ad39e..66958ac1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24015,6 +24015,20 @@ "node": ">=6" } }, + "node_modules/mocha/node_modules/fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "deprecated": "\"Please update to latest v2.3 or v2.2\"", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/mocha/node_modules/glob": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", @@ -49813,6 +49827,12 @@ "locate-path": "^3.0.0" } }, + "fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "optional": true + }, "glob": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",