From 9e951120e8910260f8fd6c250bd1120633c71f68 Mon Sep 17 00:00:00 2001 From: gitpusha Date: Mon, 2 Nov 2020 15:52:03 +0100 Subject: [PATCH] chore: hardhat optimizer settings --- .circleci/config.yml | 9 ++++++ .solhintignore | 1 + README.md | 2 +- contracts/constants/CMaker.sol | 4 +++ .../DebtBridgeFromMakerForFullRefinance.sol | 6 +++- ...DebtBridgeFromMakerForPartialRefinance.sol | 8 +++-- .../ProviderModuleDSAFromMakerToCompound.sol | 12 +++++-- ... => ProviderModuleDsaFromMakerToMaker.sol} | 12 +++++-- contracts/functions/dapps/FMaker.sol | 31 +++++++------------ .../Maker/IMcdManager.sol} | 2 +- .../interfaces/{ => dapps}/Maker/IVat.sol | 0 hardhat.config.js | 6 ++-- package.json | 6 ++-- ...SA_ABI.json => ProviderModuleDsa_ABI.json} | 0 test/0_setup-DSA-Gelato.test.js | 8 ++--- test/1_mv-DAI-DSR-Compound.test.js | 8 ++--- ...ll-Refinancing-Maker-To-Compound.helper.js | 4 +-- ...-Full-Refinancing-Maker-To-Maker.helper.js | 4 +-- ...artial-Refinance-External-Provider.test.js | 6 ++-- 19 files changed, 79 insertions(+), 50 deletions(-) create mode 100644 contracts/constants/CMaker.sol rename contracts/contracts/gelato/provider_modules/{ProviderModuleDSAFromMakerToMaker.sol => ProviderModuleDsaFromMakerToMaker.sol} (92%) rename contracts/interfaces/{Maker/IManager.sol => dapps/Maker/IMcdManager.sol} (90%) rename contracts/interfaces/{ => dapps}/Maker/IVat.sol (100%) rename pre-compiles/{ProviderModuleDSA_ABI.json => ProviderModuleDsa_ABI.json} (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index f2a24b6..2224882 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,9 +27,18 @@ jobs: # a collection of steps - run: # Linting name: ESLint command: yarn eslint . && yarn lint:sol + - restore_cache: # special step to restore the Hardhat Network Fork Cache + # Read about caching dependencies: https://circleci.com/docs/2.0/caching/ + name: Restore Hardhat Network Fork Cache + key: hardhat-network-fork - run: # Tests name: Tests using hardhat mainnet fork command: npx hardhat test + - save_cache: # special step to save the Hardhat Network Fork cache + name: Save Hardhat Network Fork Cache + key: hardhat-network-fork + paths: + - ./cache/hardhat-network-fork # - store_artifacts: # for display in Artifacts: https://circleci.com/docs/2.0/artifacts/ # path: coverage # prefix: coverage diff --git a/.solhintignore b/.solhintignore index 11d5330..fa6f76e 100644 --- a/.solhintignore +++ b/.solhintignore @@ -1,3 +1,4 @@ node_modules/ contracts/constants +contracts/functions contracts/vendor \ No newline at end of file diff --git a/README.md b/README.md index 49f4cff..420a5ef 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Furtheremore the following contracts were added to showcase the automation of th - `ConditionCompareUintsFromTwoSource`: a generic Gelato Condition that allows you to read and compare data from 2 arbitrary on-chain sources (returndata expected to be uint256 and normalized => hence MockDSR and MockCDAI). This Condition was used to compare DSR to CDAI rates and in the test suite we showcase how a change in the CDAI rate (it going above the DSR) can trigger an automatic rebalancing from DSR to CDAI via DSA Connectors. -- `ProviderModuleDSA`: this is needed for any Gelato integration. It tells Gelato how the execution payload should be formatted. In this prototype, it formats the payload for the `DSA.cast` function. +- `ProviderModuleDsa`: this is needed for any Gelato integration. It tells Gelato how the execution payload should be formatted. In this prototype, it formats the payload for the `DSA.cast` function. - `ConnectGelato`: this is a Connector needed for the DSA to be able to submit Tasks to Gelato. In the test suite we unlock the DSA MultiSig Master account at 0xfCD22438AD6eD564a1C26151Df73F6B33B817B56, in order to be able to enable this Connector in our mainnet fork running on the local hardhat network instance. diff --git a/contracts/constants/CMaker.sol b/contracts/constants/CMaker.sol new file mode 100644 index 0000000..8ebef7b --- /dev/null +++ b/contracts/constants/CMaker.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.7.4; + +address constant MCD_MANAGER = 0x5ef30b9986345249bc32d8928B7ee64DE9435E39; \ No newline at end of file diff --git a/contracts/contracts/gelato/data_generators/DebtBridgeFromMakerForFullRefinance.sol b/contracts/contracts/gelato/data_generators/DebtBridgeFromMakerForFullRefinance.sol index 6b33de5..d6ed06e 100644 --- a/contracts/contracts/gelato/data_generators/DebtBridgeFromMakerForFullRefinance.sol +++ b/contracts/contracts/gelato/data_generators/DebtBridgeFromMakerForFullRefinance.sol @@ -42,12 +42,14 @@ contract DebtBridgeFromMakerForFullRefinance { uint256 public constant GAS_COST = 1490779 + (14908 * 2); // 1933080 + ~2% (Estimated Value) // To retrieve when the connector is deployed and replace with the address of the deployed instance - address public connectGelatoProviderPayment; + address public immutable connectGelatoProviderPayment; constructor(address _connectGelatoProviderPayment) { connectGelatoProviderPayment = _connectGelatoProviderPayment; } + /* solhint-disable function-max-lines */ + /// @notice Generate Task for a full refinancing between Maker to Compound. /// @param _vaultId Id of the unsafe vault of the client. /// @param _token vault's col token address . @@ -166,6 +168,8 @@ contract DebtBridgeFromMakerForFullRefinance { ); } + /* solhint-enable function-max-lines */ + /// @notice Generate Data for calling execPayloadForFullRefinanceFromMakerToMaker via a static call. /// @param _vaultId Id of the unsafe vault of the client. /// @param _token vault's col token address . diff --git a/contracts/contracts/gelato/data_generators/DebtBridgeFromMakerForPartialRefinance.sol b/contracts/contracts/gelato/data_generators/DebtBridgeFromMakerForPartialRefinance.sol index ac317b5..fb4805a 100644 --- a/contracts/contracts/gelato/data_generators/DebtBridgeFromMakerForPartialRefinance.sol +++ b/contracts/contracts/gelato/data_generators/DebtBridgeFromMakerForPartialRefinance.sol @@ -59,12 +59,14 @@ contract DebtBridgeFromMakerForPartialRefinance { uint256 public constant GAS_COST = 1490779 + (14908 * 2); // 1933080 + ~2% (Estimated Value) // To retrieve when the connector is deployed and replace with the address of the deployed instance - address public connectGelatoProviderPayment; + address public immutable connectGelatoProviderPayment; constructor(address _connectGelatoProviderPayment) { connectGelatoProviderPayment = _connectGelatoProviderPayment; } + /* solhint-disable function-max-lines */ + /// @notice Generate Task for a full refinancing between Maker to Compound. /// @param _payload contain : // @param _vaultId Id of the unsafe vault of the client. @@ -225,6 +227,8 @@ contract DebtBridgeFromMakerForPartialRefinance { ); } + /* solhint-enable function-max-lines */ + /// @notice Computes values needed for DebtBridge Maker->ProtocolB /// @dev Use wad for colRatios. /// @param _vaultId The id of the makerDAO vault. @@ -356,7 +360,7 @@ contract DebtBridgeFromMakerForPartialRefinance { /// method e.g. the function selector of MakerOracle's read function. /// @param _colType colType of the new vault, exemple : ETH-B, ETH-A. /// @param _provider address of the paying provider. - /// @return a call data for a static call of execPayloadForPartialRefinanceFromMakerToMaker. + /// @return payload for execPayloadForPartialRefinanceFromMakerToMaker. function getDebtBridgePartialRefinanceMakerToMakerData( uint256 _vaultId, address _token, diff --git a/contracts/contracts/gelato/provider_modules/ProviderModuleDSAFromMakerToCompound.sol b/contracts/contracts/gelato/provider_modules/ProviderModuleDSAFromMakerToCompound.sol index 34c033e..d9fa0da 100644 --- a/contracts/contracts/gelato/provider_modules/ProviderModuleDSAFromMakerToCompound.sol +++ b/contracts/contracts/gelato/provider_modules/ProviderModuleDSAFromMakerToCompound.sol @@ -51,12 +51,18 @@ contract ProviderModuleDsaFromMakerToCompound is GelatoProviderModuleStandard { bool gelatoCoreIsAuth ) { if (!gelatoCoreIsAuth) - return "ProviderModuleDSA.isProvided:GelatoCoreNotAuth"; + return + "ProviderModuleDsaFromMakerToCompound.isProvided:GelatoCoreNotAuth"; } catch Error(string memory err) { return - string(abi.encodePacked("ProviderModuleDSA.isProvided:", err)); + string( + abi.encodePacked( + "ProviderModuleDsaFromMakerToCompound.isProvided:", + err + ) + ); } catch { - return "ProviderModuleDSA.isProvided:undefined"; + return "ProviderModuleDsaFromMakerToCompound.isProvided:undefined"; } return OK; diff --git a/contracts/contracts/gelato/provider_modules/ProviderModuleDSAFromMakerToMaker.sol b/contracts/contracts/gelato/provider_modules/ProviderModuleDsaFromMakerToMaker.sol similarity index 92% rename from contracts/contracts/gelato/provider_modules/ProviderModuleDSAFromMakerToMaker.sol rename to contracts/contracts/gelato/provider_modules/ProviderModuleDsaFromMakerToMaker.sol index 082e141..83bc409 100644 --- a/contracts/contracts/gelato/provider_modules/ProviderModuleDSAFromMakerToMaker.sol +++ b/contracts/contracts/gelato/provider_modules/ProviderModuleDsaFromMakerToMaker.sol @@ -51,12 +51,18 @@ contract ProviderModuleDsaFromMakerToMaker is GelatoProviderModuleStandard { bool gelatoCoreIsAuth ) { if (!gelatoCoreIsAuth) - return "ProviderModuleDSA.isProvided:GelatoCoreNotAuth"; + return + "ProviderModuleDsaFromMakerToMaker.isProvided:GelatoCoreNotAuth"; } catch Error(string memory err) { return - string(abi.encodePacked("ProviderModuleDSA.isProvided:", err)); + string( + abi.encodePacked( + "ProviderModuleDsaFromMakerToMaker.isProvided:", + err + ) + ); } catch { - return "ProviderModuleDSA.isProvided:undefined"; + return "ProviderModuleDsaFromMakerToMaker.isProvided:undefined"; } return OK; diff --git a/contracts/functions/dapps/FMaker.sol b/contracts/functions/dapps/FMaker.sol index c17e85b..c27cb2d 100644 --- a/contracts/functions/dapps/FMaker.sol +++ b/contracts/functions/dapps/FMaker.sol @@ -1,23 +1,16 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.7.4; -import {IManager} from "../../interfaces/Maker/IManager.sol"; -import {IVat} from "../../interfaces/Maker/IVat.sol"; +import {MCD_MANAGER} from "../../constants/CMaker.sol"; +import {IMcdManager} from "../../interfaces/dapps/Maker/IMcdManager.sol"; +import {IVat} from "../../interfaces/dapps/Maker/IVat.sol"; import {RAY, sub, mul} from "../../vendor/DSMath.sol"; -function _getMcdManager() pure returns (address) { - return 0x5ef30b9986345249bc32d8928B7ee64DE9435E39; -} - -function _getManager() pure returns (IManager) { - return IManager(_getMcdManager()); -} - function _getMakerVaultDebt(uint256 _vaultId) view returns (uint256 wad) { - IManager cdpManager = _getManager(); + IMcdManager manager = IMcdManager(MCD_MANAGER); - (bytes32 ilk, address urn) = _getVaultData(cdpManager, _vaultId); - IVat vat = IVat(cdpManager.vat()); + (bytes32 ilk, address urn) = _getVaultData(manager, _vaultId); + IVat vat = IVat(manager.vat()); (, uint256 rate, , , ) = vat.ilks(ilk); (, uint256 art) = vat.urns(ilk, urn); uint256 dai = vat.dai(urn); @@ -32,19 +25,19 @@ function _getMakerVaultCollateralBalance(uint256 _vaultId) view returns (uint256) { - IManager cdpManager = _getManager(); + IMcdManager manager = IMcdManager(MCD_MANAGER); - IVat vat = IVat(cdpManager.vat()); - (bytes32 ilk, address urn) = _getVaultData(cdpManager, _vaultId); + IVat vat = IVat(manager.vat()); + (bytes32 ilk, address urn) = _getVaultData(manager, _vaultId); (uint256 ink, ) = vat.urns(ilk, urn); return ink; } -function _getVaultData(IManager cdpManager, uint256 vault) +function _getVaultData(IMcdManager manager, uint256 vault) view returns (bytes32 ilk, address urn) { - ilk = cdpManager.ilks(vault); - urn = cdpManager.urns(vault); + ilk = manager.ilks(vault); + urn = manager.urns(vault); } diff --git a/contracts/interfaces/Maker/IManager.sol b/contracts/interfaces/dapps/Maker/IMcdManager.sol similarity index 90% rename from contracts/interfaces/Maker/IManager.sol rename to contracts/interfaces/dapps/Maker/IMcdManager.sol index f0fa83a..6245755 100644 --- a/contracts/interfaces/Maker/IManager.sol +++ b/contracts/interfaces/dapps/Maker/IMcdManager.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.7.4; -interface IManager { +interface IMcdManager { function ilks(uint256) external view returns (bytes32); function urns(uint256) external view returns (address); diff --git a/contracts/interfaces/Maker/IVat.sol b/contracts/interfaces/dapps/Maker/IVat.sol similarity index 100% rename from contracts/interfaces/Maker/IVat.sol rename to contracts/interfaces/dapps/Maker/IVat.sol diff --git a/hardhat.config.js b/hardhat.config.js index e4c657c..93dea4f 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -51,12 +51,14 @@ module.exports = { CETH: "0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5", DssCdpManager: "0x5ef30b9986345249bc32d8928B7ee64DE9435E39", GetCdps: "0x36a724Bd100c39f0Ea4D3A20F7097eE01A8Ff573", - ProviderModuleDSA: "0x0C25452d20cdFeEd2983fa9b9b9Cf4E81D6f2fE2", + ProviderModuleDsa: "0x0C25452d20cdFeEd2983fa9b9b9Cf4E81D6f2fE2", }, }, solidity: { version: "0.7.4", - optimizer: {enabled: process.env.DEBUG ? false : true}, + settings: { + optimizer: {enabled: process.env.DEBUG ? false : true}, + }, }, }; diff --git a/package.json b/package.json index d280e5f..3f82f6f 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,10 @@ "compile": "npx hardhat compile", "format": "prettier --write .", "lint": "eslint --cache . && yarn lint:sol", - "lint:sol": "solhint contracts/**/*.sol", + "lint:sol": "solhint contracts/**/**/**/**/**/**/**/*.sol", "lint:fix": "eslint --cache --fix . && solhint --fix contracts/**/*.sol", - "test": "yarn compile --force && npx hardhat test", - "debug": "DEBUG=true yarn compile --force && npx hardhat test" + "test": "yarn compile && npx hardhat test", + "debug": "DEBUG=true yarn compile && npx hardhat test" }, "devDependencies": { "@gelatonetwork/core": "1.0.0", diff --git a/pre-compiles/ProviderModuleDSA_ABI.json b/pre-compiles/ProviderModuleDsa_ABI.json similarity index 100% rename from pre-compiles/ProviderModuleDSA_ABI.json rename to pre-compiles/ProviderModuleDsa_ABI.json diff --git a/test/0_setup-DSA-Gelato.test.js b/test/0_setup-DSA-Gelato.test.js index 25ffdc7..69cba7e 100644 --- a/test/0_setup-DSA-Gelato.test.js +++ b/test/0_setup-DSA-Gelato.test.js @@ -16,7 +16,7 @@ const InstaConnectors = require("../pre-compiles/InstaConnectors.json"); const InstaAccount = require("../pre-compiles/InstaAccount.json"); const ConnectAuth = require("../pre-compiles/ConnectAuth.json"); const ConnectBasic = require("../pre-compiles/ConnectBasic.json"); -const ProviderModuleDSA_ABI = require("../pre-compiles/ProviderModuleDSA_ABI.json"); +const ProviderModuleDsa_ABI = require("../pre-compiles/ProviderModuleDsa_ABI.json"); describe("DSA setup with Gelato Tests", function () { this.timeout(50000); @@ -89,8 +89,8 @@ describe("DSA setup with Gelato Tests", function () { hre.network.config.GelatoCore ); providerModuleDSA = await ethers.getContractAt( - ProviderModuleDSA_ABI, - hre.network.config.ProviderModuleDSA + ProviderModuleDsa_ABI, + hre.network.config.ProviderModuleDsa ); }); @@ -183,7 +183,7 @@ describe("DSA setup with Gelato Tests", function () { ).to.be.true; }); - it("#6: Gelato ProviderModuleDSA returns correct execPayload", async function () { + it("#6: Gelato ProviderModuleDsa returns correct execPayload", async function () { // Deposit 1 ETH into DSA await userWallet.sendTransaction({ to: dsaAddress, diff --git a/test/1_mv-DAI-DSR-Compound.test.js b/test/1_mv-DAI-DSR-Compound.test.js index 8aa617f..cb9dfda 100644 --- a/test/1_mv-DAI-DSR-Compound.test.js +++ b/test/1_mv-DAI-DSR-Compound.test.js @@ -237,10 +237,10 @@ describe("Move DAI lending from DSR to Compound", function () { // A GelatoProvider is an object with the address of the provider - in our case // the DSA address - and the address of the "ProviderModule". This module // fulfills certain functions like encoding the execution payload for the Gelato - // protocol. Check out ./contracts/ProviderModuleDSA.sol to see what it does. + // protocol. Check out ./contracts/ProviderModuleDsa.sol to see what it does. const gelatoSelfProvider = new GelatoCoreLib.GelatoProvider({ addr: dsa.address, - module: hre.network.config.ProviderModuleDSA, + module: hre.network.config.ProviderModuleDsa, }); // ======= Executor Setup ========= @@ -271,7 +271,7 @@ describe("Move DAI lending from DSR to Compound", function () { inputs: [ userAddress, [], - [hre.network.config.ProviderModuleDSA], + [hre.network.config.ProviderModuleDsa], TASK_AUTOMATION_FUNDS, 0, // _getId 0, // _setId @@ -296,7 +296,7 @@ describe("Move DAI lending from DSR to Compound", function () { expect( await gelatoCore.isModuleProvided( dsa.address, - hre.network.config.ProviderModuleDSA + hre.network.config.ProviderModuleDsa ) ).to.be.true; diff --git a/test/helpers/setups/Contracts-For-Full-Refinancing-Maker-To-Compound.helper.js b/test/helpers/setups/Contracts-For-Full-Refinancing-Maker-To-Compound.helper.js index 81d0ce7..145d077 100644 --- a/test/helpers/setups/Contracts-For-Full-Refinancing-Maker-To-Compound.helper.js +++ b/test/helpers/setups/Contracts-For-Full-Refinancing-Maker-To-Compound.helper.js @@ -25,10 +25,10 @@ async function getAllContracts() { ); await debtBridgeFromMakerForFullRefinance.deployed(); - const ProviderModuleDSA = await ethers.getContractFactory( + const ProviderModuleDsa = await ethers.getContractFactory( "ProviderModuleDsaFromMakerToCompound" ); - dsaProviderModule = await ProviderModuleDSA.deploy( + dsaProviderModule = await ProviderModuleDsa.deploy( hre.network.config.GelatoCore, contracts.connectGelatoProviderPayment.address ); diff --git a/test/helpers/setups/Contracts-For-Full-Refinancing-Maker-To-Maker.helper.js b/test/helpers/setups/Contracts-For-Full-Refinancing-Maker-To-Maker.helper.js index 2f6c1e5..a383ffc 100644 --- a/test/helpers/setups/Contracts-For-Full-Refinancing-Maker-To-Maker.helper.js +++ b/test/helpers/setups/Contracts-For-Full-Refinancing-Maker-To-Maker.helper.js @@ -25,10 +25,10 @@ async function getAllContracts() { ); await debtBridgeFromMakerForFullRefinance.deployed(); - const ProviderModuleDSA = await ethers.getContractFactory( + const ProviderModuleDsa = await ethers.getContractFactory( "ProviderModuleDsaFromMakerToMaker" ); - dsaProviderModule = await ProviderModuleDSA.deploy( + dsaProviderModule = await ProviderModuleDsa.deploy( hre.network.config.GelatoCore, contracts.connectGelatoProviderPayment.address ); diff --git a/test_temp/3_Partial-Refinance-External-Provider.test.js b/test_temp/3_Partial-Refinance-External-Provider.test.js index 354b3e8..c758ec6 100644 --- a/test_temp/3_Partial-Refinance-External-Provider.test.js +++ b/test_temp/3_Partial-Refinance-External-Provider.test.js @@ -267,10 +267,10 @@ describe("Debt Bridge with External Provider", function () { ); await connectGelatoProviderPayment.deployed(); - const ProviderModuleDSA = await ethers.getContractFactory( - "ProviderModuleDSA" + const ProviderModuleDsa = await ethers.getContractFactory( + "ProviderModuleDsa" ); - dsaProviderModule = await ProviderModuleDSA.deploy( + dsaProviderModule = await ProviderModuleDsa.deploy( hre.network.config.GelatoCore, connectGelatoProviderPayment.address );