From f98b0cf567a0647923f4886f01784ba07b1a813c Mon Sep 17 00:00:00 2001 From: bun919tw Date: Tue, 28 Sep 2021 15:41:30 +0800 Subject: [PATCH] contracts/: refactor code structure --- contracts/Governance/Comp.sol | 1 - contracts/{ => Legacy}/CCTokenDelegate.sol | 2 +- contracts/{ => Legacy}/CCapableErc20.sol | 2 +- .../{ => Legacy}/CCapableErc20Delegate.sol | 0 .../CCollateralCapErc20Delegator.sol | 2 +- contracts/{ => Legacy}/CErc20Immutable.sol | 2 +- contracts/{ => Legacy}/CEther.sol | 0 contracts/{ => Legacy}/CSLPDelegate.sol | 2 +- contracts/{ => Legacy}/CTokenDeprecated.sol | 14 +++---- contracts/{ => Legacy}/ComptrollerG1.sol | 14 +++---- contracts/{ => Legacy}/ComptrollerG2.sol | 14 +++---- contracts/{ => Legacy}/ComptrollerG3.sol | 16 ++++---- contracts/{ => Legacy}/ComptrollerG4.sol | 16 ++++---- contracts/{ => Legacy}/ComptrollerG5.sol | 16 ++++---- contracts/{ => Legacy}/ComptrollerG6.sol | 16 ++++---- contracts/PriceOracle/PriceOracleProxy.sol | 1 - tests/Contracts/CErc20Harness.sol | 8 ++-- tests/Contracts/CEtherHarness.sol | 2 +- tests/Contracts/CompHarness.sol | 1 - tests/Contracts/ComptrollerScenarioG1.sol | 2 +- tests/Contracts/ComptrollerScenarioG2.sol | 2 +- tests/Contracts/ComptrollerScenarioG3.sol | 2 +- tests/Contracts/ComptrollerScenarioG4.sol | 2 +- tests/Contracts/EvilToken.sol | 2 +- tests/Contracts/Fauceteer.sol | 41 ------------------- tests/Contracts/MathHelpers.sol | 10 ----- tests/Contracts/MockMCD.sol | 36 ---------------- tests/Contracts/Structs.sol | 1 - 28 files changed, 68 insertions(+), 159 deletions(-) rename contracts/{ => Legacy}/CCTokenDelegate.sol (99%) rename contracts/{ => Legacy}/CCapableErc20.sol (99%) rename contracts/{ => Legacy}/CCapableErc20Delegate.sol (100%) rename contracts/{ => Legacy}/CCollateralCapErc20Delegator.sol (99%) rename contracts/{ => Legacy}/CErc20Immutable.sol (98%) rename contracts/{ => Legacy}/CEther.sol (100%) rename contracts/{ => Legacy}/CSLPDelegate.sol (99%) rename contracts/{ => Legacy}/CTokenDeprecated.sol (99%) rename contracts/{ => Legacy}/ComptrollerG1.sol (99%) rename contracts/{ => Legacy}/ComptrollerG2.sol (99%) rename contracts/{ => Legacy}/ComptrollerG3.sol (99%) rename contracts/{ => Legacy}/ComptrollerG4.sol (99%) rename contracts/{ => Legacy}/ComptrollerG5.sol (99%) rename contracts/{ => Legacy}/ComptrollerG6.sol (99%) delete mode 100644 tests/Contracts/Fauceteer.sol delete mode 100644 tests/Contracts/MathHelpers.sol delete mode 100644 tests/Contracts/MockMCD.sol diff --git a/contracts/Governance/Comp.sol b/contracts/Governance/Comp.sol index c3428670b..551d3e410 100644 --- a/contracts/Governance/Comp.sol +++ b/contracts/Governance/Comp.sol @@ -1,5 +1,4 @@ pragma solidity ^0.5.16; -pragma experimental ABIEncoderV2; contract Comp { /// @notice EIP-20 token name for this token diff --git a/contracts/CCTokenDelegate.sol b/contracts/Legacy/CCTokenDelegate.sol similarity index 99% rename from contracts/CCTokenDelegate.sol rename to contracts/Legacy/CCTokenDelegate.sol index 033168f00..851c6465e 100644 --- a/contracts/CCTokenDelegate.sol +++ b/contracts/Legacy/CCTokenDelegate.sol @@ -1,7 +1,7 @@ pragma solidity ^0.5.16; import "./CCapableErc20Delegate.sol"; -import "./EIP20Interface.sol"; +import "../EIP20Interface.sol"; /** * @notice Compound's Comptroller interface to get Comp address diff --git a/contracts/CCapableErc20.sol b/contracts/Legacy/CCapableErc20.sol similarity index 99% rename from contracts/CCapableErc20.sol rename to contracts/Legacy/CCapableErc20.sol index 56d9fb66b..bcdb42258 100644 --- a/contracts/CCapableErc20.sol +++ b/contracts/Legacy/CCapableErc20.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.16; -import "./CToken.sol"; +import "../CToken.sol"; /** * @title Deprecated Cream's CCapableErc20 Contract diff --git a/contracts/CCapableErc20Delegate.sol b/contracts/Legacy/CCapableErc20Delegate.sol similarity index 100% rename from contracts/CCapableErc20Delegate.sol rename to contracts/Legacy/CCapableErc20Delegate.sol diff --git a/contracts/CCollateralCapErc20Delegator.sol b/contracts/Legacy/CCollateralCapErc20Delegator.sol similarity index 99% rename from contracts/CCollateralCapErc20Delegator.sol rename to contracts/Legacy/CCollateralCapErc20Delegator.sol index e53fe657b..ec01ec0e0 100644 --- a/contracts/CCollateralCapErc20Delegator.sol +++ b/contracts/Legacy/CCollateralCapErc20Delegator.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.16; -import "./CTokenInterfaces.sol"; +import "../CTokenInterfaces.sol"; /** * @title Cream's CCollateralCapErc20Delegator Contract diff --git a/contracts/CErc20Immutable.sol b/contracts/Legacy/CErc20Immutable.sol similarity index 98% rename from contracts/CErc20Immutable.sol rename to contracts/Legacy/CErc20Immutable.sol index 90eac6ac7..a6ee74396 100644 --- a/contracts/CErc20Immutable.sol +++ b/contracts/Legacy/CErc20Immutable.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.16; -import "./CErc20.sol"; +import "../CErc20.sol"; /** * @title Compound's CErc20Immutable Contract diff --git a/contracts/CEther.sol b/contracts/Legacy/CEther.sol similarity index 100% rename from contracts/CEther.sol rename to contracts/Legacy/CEther.sol diff --git a/contracts/CSLPDelegate.sol b/contracts/Legacy/CSLPDelegate.sol similarity index 99% rename from contracts/CSLPDelegate.sol rename to contracts/Legacy/CSLPDelegate.sol index a6f44779d..f0ee946f4 100644 --- a/contracts/CSLPDelegate.sol +++ b/contracts/Legacy/CSLPDelegate.sol @@ -2,7 +2,7 @@ pragma solidity ^0.5.16; pragma experimental ABIEncoderV2; import "./CCapableErc20Delegate.sol"; -import "./EIP20Interface.sol"; +import "../EIP20Interface.sol"; // Ref: https://etherscan.io/address/0xc2edad668740f1aa35e4d8f227fb8e17dca888cd#code interface IMasterChef { diff --git a/contracts/CTokenDeprecated.sol b/contracts/Legacy/CTokenDeprecated.sol similarity index 99% rename from contracts/CTokenDeprecated.sol rename to contracts/Legacy/CTokenDeprecated.sol index 7ec221a97..caeb848ce 100644 --- a/contracts/CTokenDeprecated.sol +++ b/contracts/Legacy/CTokenDeprecated.sol @@ -1,12 +1,12 @@ pragma solidity ^0.5.16; -import "./ComptrollerInterface.sol"; -import "./CTokenInterfaces.sol"; -import "./ErrorReporter.sol"; -import "./Exponential.sol"; -import "./EIP20Interface.sol"; -import "./EIP20NonStandardInterface.sol"; -import "./InterestRateModel.sol"; +import "../ComptrollerInterface.sol"; +import "../CTokenInterfaces.sol"; +import "../ErrorReporter.sol"; +import "../Exponential.sol"; +import "../EIP20Interface.sol"; +import "../EIP20NonStandardInterface.sol"; +import "../InterestRateModel.sol"; /** * @title Deprecated CToken Contract only for CEther. diff --git a/contracts/ComptrollerG1.sol b/contracts/Legacy/ComptrollerG1.sol similarity index 99% rename from contracts/ComptrollerG1.sol rename to contracts/Legacy/ComptrollerG1.sol index 5a7c8ad0e..eeec2d81c 100644 --- a/contracts/ComptrollerG1.sol +++ b/contracts/Legacy/ComptrollerG1.sol @@ -1,12 +1,12 @@ pragma solidity ^0.5.16; -import "./CToken.sol"; -import "./ErrorReporter.sol"; -import "./Exponential.sol"; -import "./PriceOracle/PriceOracle.sol"; -import "./ComptrollerInterface.sol"; -import "./ComptrollerStorage.sol"; -import "./Unitroller.sol"; +import "../CToken.sol"; +import "../ErrorReporter.sol"; +import "../Exponential.sol"; +import "../PriceOracle/PriceOracle.sol"; +import "../ComptrollerInterface.sol"; +import "../ComptrollerStorage.sol"; +import "../Unitroller.sol"; /** * @title Compound's Comptroller Contract diff --git a/contracts/ComptrollerG2.sol b/contracts/Legacy/ComptrollerG2.sol similarity index 99% rename from contracts/ComptrollerG2.sol rename to contracts/Legacy/ComptrollerG2.sol index 1dff31286..dcebce3e9 100644 --- a/contracts/ComptrollerG2.sol +++ b/contracts/Legacy/ComptrollerG2.sol @@ -1,12 +1,12 @@ pragma solidity ^0.5.16; -import "./CToken.sol"; -import "./ErrorReporter.sol"; -import "./Exponential.sol"; -import "./PriceOracle/PriceOracle.sol"; -import "./ComptrollerInterface.sol"; -import "./ComptrollerStorage.sol"; -import "./Unitroller.sol"; +import "../CToken.sol"; +import "../ErrorReporter.sol"; +import "../Exponential.sol"; +import "../PriceOracle/PriceOracle.sol"; +import "../ComptrollerInterface.sol"; +import "../ComptrollerStorage.sol"; +import "../Unitroller.sol"; /** * @title Compound's Comptroller Contract diff --git a/contracts/ComptrollerG3.sol b/contracts/Legacy/ComptrollerG3.sol similarity index 99% rename from contracts/ComptrollerG3.sol rename to contracts/Legacy/ComptrollerG3.sol index 43ebbcf6e..b5e9a527f 100644 --- a/contracts/ComptrollerG3.sol +++ b/contracts/Legacy/ComptrollerG3.sol @@ -1,13 +1,13 @@ pragma solidity ^0.5.16; -import "./CToken.sol"; -import "./ErrorReporter.sol"; -import "./Exponential.sol"; -import "./PriceOracle/PriceOracle.sol"; -import "./ComptrollerInterface.sol"; -import "./ComptrollerStorage.sol"; -import "./Unitroller.sol"; -import "./Governance/Comp.sol"; +import "../CToken.sol"; +import "../ErrorReporter.sol"; +import "../Exponential.sol"; +import "../PriceOracle/PriceOracle.sol"; +import "../ComptrollerInterface.sol"; +import "../ComptrollerStorage.sol"; +import "../Unitroller.sol"; +import "../Governance/Comp.sol"; /** * @title Compound's Comptroller Contract diff --git a/contracts/ComptrollerG4.sol b/contracts/Legacy/ComptrollerG4.sol similarity index 99% rename from contracts/ComptrollerG4.sol rename to contracts/Legacy/ComptrollerG4.sol index 290c8b6a3..f7553c8f9 100644 --- a/contracts/ComptrollerG4.sol +++ b/contracts/Legacy/ComptrollerG4.sol @@ -1,13 +1,13 @@ pragma solidity ^0.5.16; -import "./CToken.sol"; -import "./ErrorReporter.sol"; -import "./Exponential.sol"; -import "./PriceOracle/PriceOracle.sol"; -import "./ComptrollerInterface.sol"; -import "./ComptrollerStorage.sol"; -import "./Unitroller.sol"; -import "./Governance/Comp.sol"; +import "../CToken.sol"; +import "../ErrorReporter.sol"; +import "../Exponential.sol"; +import "../PriceOracle/PriceOracle.sol"; +import "../ComptrollerInterface.sol"; +import "../ComptrollerStorage.sol"; +import "../Unitroller.sol"; +import "../Governance/Comp.sol"; /** * @title Compound's Comptroller Contract diff --git a/contracts/ComptrollerG5.sol b/contracts/Legacy/ComptrollerG5.sol similarity index 99% rename from contracts/ComptrollerG5.sol rename to contracts/Legacy/ComptrollerG5.sol index c9e56925d..0676ece79 100644 --- a/contracts/ComptrollerG5.sol +++ b/contracts/Legacy/ComptrollerG5.sol @@ -1,13 +1,13 @@ pragma solidity ^0.5.16; -import "./CToken.sol"; -import "./ErrorReporter.sol"; -import "./Exponential.sol"; -import "./PriceOracle/PriceOracle.sol"; -import "./ComptrollerInterface.sol"; -import "./ComptrollerStorage.sol"; -import "./Unitroller.sol"; -import "./Governance/Comp.sol"; +import "../CToken.sol"; +import "../ErrorReporter.sol"; +import "../Exponential.sol"; +import "../PriceOracle/PriceOracle.sol"; +import "../ComptrollerInterface.sol"; +import "../ComptrollerStorage.sol"; +import "../Unitroller.sol"; +import "../Governance/Comp.sol"; /** * @title Compound's Comptroller Contract diff --git a/contracts/ComptrollerG6.sol b/contracts/Legacy/ComptrollerG6.sol similarity index 99% rename from contracts/ComptrollerG6.sol rename to contracts/Legacy/ComptrollerG6.sol index 8295b81d5..1e85897bc 100644 --- a/contracts/ComptrollerG6.sol +++ b/contracts/Legacy/ComptrollerG6.sol @@ -1,13 +1,13 @@ pragma solidity ^0.5.16; -import "./CToken.sol"; -import "./ErrorReporter.sol"; -import "./Exponential.sol"; -import "./PriceOracle/PriceOracle.sol"; -import "./ComptrollerInterface.sol"; -import "./ComptrollerStorage.sol"; -import "./Unitroller.sol"; -import "./Governance/Comp.sol"; +import "../CToken.sol"; +import "../ErrorReporter.sol"; +import "../Exponential.sol"; +import "../PriceOracle/PriceOracle.sol"; +import "../ComptrollerInterface.sol"; +import "../ComptrollerStorage.sol"; +import "../Unitroller.sol"; +import "../Governance/Comp.sol"; /** * @title Compound's Comptroller Contract diff --git a/contracts/PriceOracle/PriceOracleProxy.sol b/contracts/PriceOracle/PriceOracleProxy.sol index aff2af4a5..55fcaca3f 100644 --- a/contracts/PriceOracle/PriceOracleProxy.sol +++ b/contracts/PriceOracle/PriceOracleProxy.sol @@ -1,5 +1,4 @@ pragma solidity ^0.5.16; -pragma experimental ABIEncoderV2; import "./Denominations.sol"; import "./PriceOracle.sol"; diff --git a/tests/Contracts/CErc20Harness.sol b/tests/Contracts/CErc20Harness.sol index b3718c440..85f109513 100644 --- a/tests/Contracts/CErc20Harness.sol +++ b/tests/Contracts/CErc20Harness.sol @@ -1,13 +1,13 @@ pragma solidity ^0.5.16; pragma experimental ABIEncoderV2; -import "../../contracts/CErc20Immutable.sol"; +import "../../contracts/Legacy/CErc20Immutable.sol"; import "../../contracts/CErc20Delegator.sol"; import "../../contracts/CErc20Delegate.sol"; -import "../../contracts/CSLPDelegate.sol"; -import "../../contracts/CCTokenDelegate.sol"; +import "../../contracts/Legacy/CSLPDelegate.sol"; +import "../../contracts/Legacy/CCTokenDelegate.sol"; import "../../contracts/CCollateralCapErc20Delegate.sol"; -import "../../contracts/CCollateralCapErc20Delegator.sol"; +import "../../contracts/Legacy/CCollateralCapErc20Delegator.sol"; import "../../contracts/CWrappedNativeDelegate.sol"; import "../../contracts/CWrappedNativeDelegator.sol"; import "./ComptrollerScenario.sol"; diff --git a/tests/Contracts/CEtherHarness.sol b/tests/Contracts/CEtherHarness.sol index 13d080c33..613fbd471 100644 --- a/tests/Contracts/CEtherHarness.sol +++ b/tests/Contracts/CEtherHarness.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.16; -import "../../contracts/CEther.sol"; +import "../../contracts/Legacy/CEther.sol"; import "./ComptrollerScenario.sol"; contract CEtherHarness is CEther { diff --git a/tests/Contracts/CompHarness.sol b/tests/Contracts/CompHarness.sol index 623a93874..f8c20f648 100644 --- a/tests/Contracts/CompHarness.sol +++ b/tests/Contracts/CompHarness.sol @@ -1,5 +1,4 @@ pragma solidity ^0.5.16; -pragma experimental ABIEncoderV2; import "../../contracts/Governance/Comp.sol"; diff --git a/tests/Contracts/ComptrollerScenarioG1.sol b/tests/Contracts/ComptrollerScenarioG1.sol index 061fb6d08..9c84e1e9d 100644 --- a/tests/Contracts/ComptrollerScenarioG1.sol +++ b/tests/Contracts/ComptrollerScenarioG1.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.16; -import "../../contracts/ComptrollerG1.sol"; +import "../../contracts/Legacy/ComptrollerG1.sol"; import "../../contracts/PriceOracle/PriceOracle.sol"; // XXX we should delete G1 everything... diff --git a/tests/Contracts/ComptrollerScenarioG2.sol b/tests/Contracts/ComptrollerScenarioG2.sol index e9ec8dd6c..e3b868e38 100644 --- a/tests/Contracts/ComptrollerScenarioG2.sol +++ b/tests/Contracts/ComptrollerScenarioG2.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.16; -import "../../contracts/ComptrollerG2.sol"; +import "../../contracts/Legacy/ComptrollerG2.sol"; contract ComptrollerScenarioG2 is ComptrollerG2 { uint256 public blockNumber; diff --git a/tests/Contracts/ComptrollerScenarioG3.sol b/tests/Contracts/ComptrollerScenarioG3.sol index 6f1ca2472..d1f820e7c 100644 --- a/tests/Contracts/ComptrollerScenarioG3.sol +++ b/tests/Contracts/ComptrollerScenarioG3.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.16; -import "../../contracts/ComptrollerG3.sol"; +import "../../contracts/Legacy/ComptrollerG3.sol"; contract ComptrollerScenarioG3 is ComptrollerG3 { uint256 public blockNumber; diff --git a/tests/Contracts/ComptrollerScenarioG4.sol b/tests/Contracts/ComptrollerScenarioG4.sol index 8fae310f4..8ae569157 100644 --- a/tests/Contracts/ComptrollerScenarioG4.sol +++ b/tests/Contracts/ComptrollerScenarioG4.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.16; -import "../../contracts/ComptrollerG4.sol"; +import "../../contracts/Legacy/ComptrollerG4.sol"; contract ComptrollerScenarioG4 is ComptrollerG4 { uint256 public blockNumber; diff --git a/tests/Contracts/EvilToken.sol b/tests/Contracts/EvilToken.sol index bbe2fa779..a48e538da 100644 --- a/tests/Contracts/EvilToken.sol +++ b/tests/Contracts/EvilToken.sol @@ -1,7 +1,7 @@ pragma solidity ^0.5.16; import "./FaucetToken.sol"; -import "../../contracts/CEther.sol"; +import "../../contracts/Legacy/CEther.sol"; import "../../contracts/CCollateralCapErc20.sol"; /** diff --git a/tests/Contracts/Fauceteer.sol b/tests/Contracts/Fauceteer.sol deleted file mode 100644 index b210f4f42..000000000 --- a/tests/Contracts/Fauceteer.sol +++ /dev/null @@ -1,41 +0,0 @@ -pragma solidity ^0.5.16; - -import "../../contracts/EIP20NonStandardInterface.sol"; - -/** - * @title Fauceteer - * @author Compound - * @notice First computer program to be part of The Giving Pledge - */ -contract Fauceteer { - /** - * @notice Drips some tokens to caller - * @dev We send 0.01% of our tokens to the caller. Over time, the amount will tend toward and eventually reach zero. - * @param token The token to drip. Note: if we have no balance in this token, function will revert. - */ - function drip(EIP20NonStandardInterface token) public { - uint256 balance = token.balanceOf(address(this)); - require(balance > 0, "Fauceteer is empty"); - token.transfer(msg.sender, balance / 10000); // 0.01% - - bool success; - assembly { - switch returndatasize() - case 0 { - // This is a non-standard ERC-20 - success := not(0) // set success to true - } - case 32 { - // This is a compliant ERC-20 - returndatacopy(0, 0, 32) - success := mload(0) // Set `success = returndata` of external call - } - default { - // This is an excessively non-compliant ERC-20, revert. - revert(0, 0) - } - } - - require(success, "Transfer returned false."); - } -} diff --git a/tests/Contracts/MathHelpers.sol b/tests/Contracts/MathHelpers.sol deleted file mode 100644 index e246df3fb..000000000 --- a/tests/Contracts/MathHelpers.sol +++ /dev/null @@ -1,10 +0,0 @@ -pragma solidity ^0.5.16; - -contract MathHelpers { - /* - * @dev Creates a number like 15e16 as a uint256 from scientific(15, 16). - */ - function scientific(uint256 val, uint256 expTen) internal pure returns (uint256) { - return val * (10**expTen); - } -} diff --git a/tests/Contracts/MockMCD.sol b/tests/Contracts/MockMCD.sol deleted file mode 100644 index 5c8021196..000000000 --- a/tests/Contracts/MockMCD.sol +++ /dev/null @@ -1,36 +0,0 @@ -pragma solidity ^0.5.16; - -contract MockPot { - uint256 public dsr; // the Dai Savings Rate - - constructor(uint256 dsr_) public { - setDsr(dsr_); - } - - function setDsr(uint256 dsr_) public { - dsr = dsr_; - } -} - -contract MockJug { - struct Ilk { - uint256 duty; - uint256 rho; - } - - mapping(bytes32 => Ilk) public ilks; - uint256 public base; - - constructor(uint256 duty_, uint256 base_) public { - setETHDuty(duty_); - setBase(base_); - } - - function setBase(uint256 base_) public { - base = base_; - } - - function setETHDuty(uint256 duty_) public { - ilks["ETH-A"].duty = duty_; - } -} diff --git a/tests/Contracts/Structs.sol b/tests/Contracts/Structs.sol index f3173fb3d..012aca584 100644 --- a/tests/Contracts/Structs.sol +++ b/tests/Contracts/Structs.sol @@ -1,5 +1,4 @@ pragma solidity ^0.5.16; -pragma experimental ABIEncoderV2; contract Structs { struct Outer {