Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reorganize interfaces, introduce contractType getter #284

Merged
merged 3 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions contracts/core/AccountFactoryV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ contract AccountFactoryV3 is IAccountFactoryV3, Ownable {
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "AF";

/// @notice Delay after which returned credit accounts can be reused
uint40 public constant override delay = 3 days;

Expand Down
3 changes: 3 additions & 0 deletions contracts/core/BotListV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ contract BotListV3 is IBotListV3, SanityCheckTrait, Ownable {
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "BL";

/// @notice Credit manager's approved status
mapping(address => bool) public override approvedCreditManager;

Expand Down
3 changes: 3 additions & 0 deletions contracts/core/GearStakingV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ contract GearStakingV3 is IGearStakingV3, Ownable, ReentrancyGuardTrait, SanityC
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "GS";

/// @notice Address of the GEAR token
address public immutable override gear;

Expand Down
3 changes: 3 additions & 0 deletions contracts/core/PriceOracleV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ contract PriceOracleV3 is ControlledTrait, PriceFeedValidationTrait, SanityCheck
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "PO";

/// @dev Mapping from token address to price feed params
mapping(address => PriceFeedParams) internal _priceFeedsParams;

Expand Down
5 changes: 4 additions & 1 deletion contracts/credit/CreditAccountV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ contract CreditAccountV3 is ICreditAccountV3 {
using Address for address;

/// @notice Contract version
uint256 public constant override version = 3_00;
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "CA";

/// @notice Account factory this account was deployed with
address public immutable override factory;
Expand Down
5 changes: 4 additions & 1 deletion contracts/credit/CreditConfiguratorV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ contract CreditConfiguratorV3 is ICreditConfiguratorV3, ControlledTrait, SanityC
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "CC";

/// @notice Credit manager address
address public immutable override creditManager;

Expand Down Expand Up @@ -284,7 +287,7 @@ contract CreditConfiguratorV3 is ICreditConfiguratorV3, ControlledTrait, SanityC
}

address cf = creditFacade();
if (targetContract == creditFacade() || adapter == creditFacade()) {
if (targetContract == cf || adapter == cf) {
revert TargetContractNotAllowedException(); // I:[CC-10C]
}

Expand Down
5 changes: 4 additions & 1 deletion contracts/credit/CreditFacadeV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
ICreditManagerV3,
ManageDebtAction
} from "../interfaces/ICreditManagerV3.sol";
import {IDegenNFT} from "../interfaces/IDegenNFT.sol";
import {IDegenNFT} from "../interfaces/base/IDegenNFT.sol";
import "../interfaces/IExceptions.sol";
import {IPoolV3} from "../interfaces/IPoolV3.sol";
import {IPriceOracleV3, PriceUpdate} from "../interfaces/IPriceOracleV3.sol";
Expand Down Expand Up @@ -74,6 +74,9 @@ contract CreditFacadeV3 is ICreditFacadeV3, Pausable, ACLTrait, ReentrancyGuardT
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "CF";

/// @notice Maximum quota size, as a multiple of `maxDebt`
uint256 public constant override maxQuotaMultiplier = 2;

Expand Down
5 changes: 5 additions & 0 deletions contracts/credit/CreditManagerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuardT
creditConfigurator = msg.sender; // U:[CM-1]
}

/// @notice Contract type
function contractType() external view virtual override returns (bytes32) {
return "CM";
}

// ------------------ //
// ACCOUNT MANAGEMENT //
// ------------------ //
Expand Down
3 changes: 3 additions & 0 deletions contracts/credit/CreditManagerV3_USDT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {IPoolV3} from "../interfaces/IPoolV3.sol";
/// @title Credit manager V3 USDT
/// @notice Credit manager variation for USDT underlying with enabled transfer fees
contract CreditManagerV3_USDT is CreditManagerV3, USDT_Transfer {
/// @notice Contract type
bytes32 public constant override contractType = "CM_USDT";

constructor(
address _pool,
address _accountFactory,
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/ICreditConfiguratorV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pragma solidity ^0.8.17;

import {IVersion} from "./base/IVersion.sol";
import {IControlledTrait} from "./base/IControlledTrait.sol";

enum AllowanceAction {
FORBID,
Expand Down Expand Up @@ -95,7 +96,7 @@ interface ICreditConfiguratorV3Events {
}

/// @title Credit configurator V3 interface
interface ICreditConfiguratorV3 is IVersion, ICreditConfiguratorV3Events {
interface ICreditConfiguratorV3 is IVersion, IControlledTrait, ICreditConfiguratorV3Events {
function creditManager() external view returns (address);

function creditFacade() external view returns (address);
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/ICreditFacadeV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pragma solidity ^0.8.17;
import {AllowanceAction} from "./ICreditConfiguratorV3.sol";
import "./ICreditFacadeV3Multicall.sol";
import {PriceUpdate} from "./IPriceOracleV3.sol";
import {IACLTrait} from "./base/IACLTrait.sol";
import {IVersion} from "./base/IVersion.sol";

/// @notice Multicall element
Expand Down Expand Up @@ -82,7 +83,7 @@ interface ICreditFacadeV3Events {
}

/// @title Credit facade V3 interface
interface ICreditFacadeV3 is IVersion, ICreditFacadeV3Events {
interface ICreditFacadeV3 is IVersion, IACLTrait, ICreditFacadeV3Events {
function creditManager() external view returns (address);

function underlying() external view returns (address);
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/IGaugeV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.17;

import {IControlledTrait} from "./base/IControlledTrait.sol";
import {IRateKeeper} from "./base/IRateKeeper.sol";
import {IVotingContract} from "./base/IVotingContract.sol";

Expand Down Expand Up @@ -39,7 +40,7 @@ interface IGaugeV3Events {
}

/// @title Gauge V3 interface
interface IGaugeV3 is IVotingContract, IRateKeeper, IGaugeV3Events {
interface IGaugeV3 is IVotingContract, IRateKeeper, IControlledTrait, IGaugeV3Events {
function voter() external view returns (address);

function updateEpoch() external;
Expand Down
4 changes: 3 additions & 1 deletion contracts/interfaces/IPoolQuotaKeeperV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.17;

import {IControlledTrait} from "./base/IControlledTrait.sol";
import {IContractsRegisterTrait} from "./base/IContractsRegisterTrait.sol";
import {IVersion} from "./base/IVersion.sol";

struct TokenQuotaParams {
Expand Down Expand Up @@ -42,7 +44,7 @@ interface IPoolQuotaKeeperV3Events {
}

/// @title Pool quota keeper V3 interface
interface IPoolQuotaKeeperV3 is IPoolQuotaKeeperV3Events, IVersion {
interface IPoolQuotaKeeperV3 is IPoolQuotaKeeperV3Events, IVersion, IControlledTrait, IContractsRegisterTrait {
function pool() external view returns (address);

function underlying() external view returns (address);
Expand Down
4 changes: 3 additions & 1 deletion contracts/interfaces/IPoolV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pragma abicoder v1;
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {IVersion} from "./base/IVersion.sol";
import {IControlledTrait} from "./base/IControlledTrait.sol";
import {IContractsRegisterTrait} from "./base/IContractsRegisterTrait.sol";

interface IPoolV3Events {
/// @notice Emitted when depositing liquidity with referral code
Expand Down Expand Up @@ -41,7 +43,7 @@ interface IPoolV3Events {
}

/// @title Pool V3 interface
interface IPoolV3 is IVersion, IPoolV3Events, IERC4626, IERC20Permit {
interface IPoolV3 is IVersion, IControlledTrait, IContractsRegisterTrait, IPoolV3Events, IERC4626, IERC20Permit {
function underlyingToken() external view returns (address);

function treasury() external view returns (address);
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/IPriceOracleV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pragma solidity ^0.8.17;

import {IVersion} from "./base/IVersion.sol";
import {IControlledTrait} from "./base/IControlledTrait.sol";

/// @notice Price feed params
/// @param priceFeed Price feed address
Expand Down Expand Up @@ -37,7 +38,7 @@ interface IPriceOracleV3Events {
}

/// @title Price oracle V3 interface
interface IPriceOracleV3 is IVersion, IPriceOracleV3Events {
interface IPriceOracleV3 is IVersion, IControlledTrait, IPriceOracleV3Events {
function getTokens() external view returns (address[] memory);

function priceFeeds(address token) external view returns (address priceFeed);
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/ITumblerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pragma solidity ^0.8.17;

import {IRateKeeper} from "./base/IRateKeeper.sol";
import {IControlledTrait} from "./base/IControlledTrait.sol";

interface ITumblerV3Events {
/// @notice Emitted when new token is added
Expand All @@ -14,7 +15,7 @@ interface ITumblerV3Events {
}

/// @title Tumbler V3 interface
interface ITumblerV3 is IRateKeeper, ITumblerV3Events {
interface ITumblerV3 is IRateKeeper, IControlledTrait, ITumblerV3Events {
function underlying() external view returns (address);

function poolQuotaKeeper() external view returns (address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
pragma solidity ^0.8.17;

interface IACL {
function owner() external view returns (address);
function isConfigurator(address account) external view returns (bool);
function isPausableAdmin(address addr) external view returns (bool);
function isUnpausableAdmin(address addr) external view returns (bool);
Expand Down
8 changes: 8 additions & 0 deletions contracts/interfaces/base/IACLTrait.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.17;

interface IACLTrait {
function acl() external view returns (address);
}
11 changes: 2 additions & 9 deletions contracts/interfaces/base/IAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.17;

import {AdapterType} from "@gearbox-protocol/sdk-gov/contracts/AdapterType.sol";
import {IVersion} from "./IVersion.sol";

/// @title Adapter interface
/// @notice Generic interface for an adapter that can be used to interact with external protocols.
/// Adapters can be assumed to be non-malicious since they are developed by Gearbox DAO.
interface IAdapter {
/// @notice Adapter type
function _gearboxAdapterType() external view returns (AdapterType);

/// @notice Adapter version
/// @dev Doesn't follow `IVersion` for historic reasons
function _gearboxAdapterVersion() external view returns (uint16);

interface IAdapter is IVersion {
/// @notice Credit manager this adapter is connected to
/// @dev Assumed to be an immutable state variable
function creditManager() external view returns (address);
Expand Down
8 changes: 8 additions & 0 deletions contracts/interfaces/base/IContractsRegisterTrait.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.17;

interface IContractsRegisterTrait {
function contractsRegister() external view returns (address);
}
14 changes: 14 additions & 0 deletions contracts/interfaces/base/IControlledTrait.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.17;

import {IACLTrait} from "./IACLTrait.sol";

interface IControlledTrait is IACLTrait {
/// @notice Emitted when new external controller is set
event NewController(address indexed newController);

function controller() external view returns (address);
function setController(address) external;
}
4 changes: 0 additions & 4 deletions contracts/interfaces/base/IPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
// (c) Gearbox Foundation, 2024.
pragma solidity ^0.8.17;

import {PriceFeedType} from "@gearbox-protocol/sdk-gov/contracts/PriceFeedType.sol";
import {IVersion} from "./IVersion.sol";

/// @title Price feed interface
/// @notice Interface for Chainlink-like price feeds that can be plugged into Gearbox's price oracle
interface IPriceFeed is IVersion {
/// @notice Price feed type
function priceFeedType() external view returns (PriceFeedType);

/// @notice Whether price feed implements its own staleness and sanity checks
function skipPriceCheck() external view returns (bool);

Expand Down
5 changes: 4 additions & 1 deletion contracts/interfaces/base/IVersion.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
pragma solidity ^0.8.17;

/// @title Version interface
/// @notice Defines contract version
/// @notice Defines contract version and type
interface IVersion {
/// @notice Contract version
function version() external view returns (uint256);

/// @notice Contract type
function contractType() external view returns (bytes32);
}
1 change: 1 addition & 0 deletions contracts/interfaces/external/IWETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pragma solidity ^0.8.17;

interface IWETH {
function deposit() external payable;
function withdraw(uint256 amount) external;
}
3 changes: 3 additions & 0 deletions contracts/pool/GaugeV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ contract GaugeV3 is IGaugeV3, ControlledTrait, SanityCheckTrait {
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "RK_GAUGE";

/// @notice Address of the pool this gauge is connected to
address public immutable override pool;

Expand Down
3 changes: 3 additions & 0 deletions contracts/pool/LinearInterestRateModelV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ contract LinearInterestRateModelV3 is ILinearInterestRateModelV3 {
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "IRM_LINEAR";

/// @notice Whether to prevent borrowing over `U_2` utilization
bool public immutable override isBorrowingMoreU2Forbidden;

Expand Down
3 changes: 3 additions & 0 deletions contracts/pool/PoolQuotaKeeperV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ contract PoolQuotaKeeperV3 is IPoolQuotaKeeperV3, ControlledTrait, ContractsRegi
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "QK";

/// @notice Address of the underlying token
address public immutable override underlying;

Expand Down
5 changes: 5 additions & 0 deletions contracts/pool/PoolV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ contract PoolV3 is
_setTotalDebtLimit(totalDebtLimit_); // U:[LP-1B]
}

/// @notice Contract type
function contractType() external view virtual override returns (bytes32) {
return "LP";
}

/// @notice Pool shares decimals, matches underlying token decimals
function decimals() public view override(ERC20, ERC4626, IERC20Metadata) returns (uint8) {
return ERC4626.decimals();
Expand Down
3 changes: 3 additions & 0 deletions contracts/pool/PoolV3_USDT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {USDT_Transfer} from "../traits/USDT_Transfer.sol";
/// @title Pool V3 USDT
/// @notice Pool variation for USDT underlying with enabled transfer fees
contract PoolV3_USDT is PoolV3, USDT_Transfer {
/// @notice Contract type
bytes32 public constant override contractType = "LP_USDT";

constructor(
address acl_,
address contractsRegister_,
Expand Down
3 changes: 3 additions & 0 deletions contracts/pool/TumblerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ contract TumblerV3 is ITumblerV3, ControlledTrait, SanityCheckTrait {
/// @notice Contract version
uint256 public constant override version = 3_10;

/// @notice Contract type
bytes32 public constant override contractType = "RK_TUMBLER";

/// @notice Pool whose quota rates are set by this contract
address public immutable override pool;

Expand Down
Loading
Loading