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

4626 #23

Closed
wants to merge 34 commits into from
Closed

4626 #23

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
60bea04
feat: credit configurator updates creditFacade in adapters
Van0k Nov 19, 2022
9f24d7d
feat: blacklist helper
Van0k Nov 19, 2022
a65eb3e
feat: abstractAdapter retrieves CreditFacade dynamically
Van0k Nov 21, 2022
c3b7e39
feat: borrowers can appoint account maintainers
Van0k Nov 22, 2022
3bf31ea
feat: setIncreaseDebtForbidden controlled by pausable admin
Van0k Nov 22, 2022
452b892
fix: bot improvements
Van0k Nov 25, 2022
5a91c23
feat: controller role
Nov 25, 2022
a79ee11
build: publish npm prereleases from v2.1. branch (#17)
doomsower Dec 8, 2022
4363009
build: stop releases from v2.1 branch
Jan 4, 2023
a433294
fix: releases from next branch
Jan 4, 2023
f70225c
feat: credit configurator improvements
Van0k Jan 6, 2023
c6837e5
Merge branch 'next' into adapter-change-fix
Van0k Jan 6, 2023
4aade93
fix: merge fix
Van0k Jan 6, 2023
98ccf23
Merge pull request #19 from Gearbox-protocol/adapter-change-fix
Van0k Jan 24, 2023
52849ba
fix: add blacklisted logic to expired liquidations
Van0k Jan 24, 2023
00f008b
fix: allow lt = 0 in credit configurator
Van0k Jan 24, 2023
dc9e2cb
feat: new pool udpate
0xmikko Jan 31, 2023
83b0afc
fix: style update
0xmikko Feb 1, 2023
800fe57
Merge branch '4626' of github.com:Gearbox-protocol/core-v2 into 4626
0xmikko Feb 1, 2023
356b547
fix: 4626 github update
0xmikko Feb 1, 2023
f40b13e
Merge branch '4626' of github.com:Gearbox-protocol/core-v2 into 4626
0xmikko Feb 1, 2023
8f38fb9
feat: gauge + tokenomics draft
0xmikko Feb 13, 2023
66e2def
fix: typos fixed
0xmikko Feb 13, 2023
0d8d97d
fix: linter
0xmikko Feb 13, 2023
407a2f7
Merge branch 'next' into 4626
Van0k Feb 13, 2023
4443f3d
Merge branch 'main' into 4626
Van0k Feb 13, 2023
54e4512
Merge branch '4626' of https://github.com/Gearbox-protocol/core-v2 in…
Van0k Feb 13, 2023
18d2906
feat: credit manager with quotas draft
Van0k Feb 14, 2023
f6c3d54
fix: gaugfe draft updated
0xmikko Feb 14, 2023
f8c4edf
Merge branch '4626' of github.com:Gearbox-protocol/core-v2 into 4626
0xmikko Feb 14, 2023
64bf20b
fix: adding PoolQuotaKeeper
0xmikko Feb 16, 2023
4286d45
fix: quotas moved to IQoutaKeeper
0xmikko Feb 16, 2023
85c4484
fix: creditAccount filed added to quotas
0xmikko Feb 16, 2023
fae9910
fix: next iteration
0xmikko Feb 16, 2023
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
7 changes: 7 additions & 0 deletions .env.fork
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

REACT_APP_BACKEND_ADDR=http://localhost:8000
REACT_APP_ADDRESS_PROVIDER=0xcF64698AFF7E5f27A11dff868AF228653ba53be0
REACT_APP_CHAIN_ID=1337
REACT_APP_PATHFINDER=0x67C9a1B633e47172Fa609DCAebafec3C72d09f7E
REACT_APP_TOKEN_DISTRIBUTOR=0xBF57539473913685688d224ad4E262684B23dD4c
REACT_APP_ACCOUNT_MINER=0x7B1AAF21AC0D420666B5966338FF9aEe763C29DF
4 changes: 4 additions & 0 deletions .env.goerli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REACT_APP_ADDRESS_PROVIDER=0x95f4cea53121b8A2Cb783C6BFB0915cEc44827D3
REACT_APP_CHAIN_ID=5
REACT_APP_DEGEN_NFT=0xc4cA5B61e58cDAa3cc283906b65aeFc8A80EA04A
REACT_APP_DEGEN_DISTRIBUTOR=0x75f74B4A665BFcc78df0Ff82c2eB677E610B7313
7 changes: 7 additions & 0 deletions .env.mainnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

REACT_APP_BACKEND_ADDR=http://localhost:8000
REACT_APP_ADDRESS_PROVIDER=0xcF64698AFF7E5f27A11dff868AF228653ba53be0
REACT_APP_CHAIN_ID=1
REACT_APP_PATHFINDER=0xBC0DE81339Da70e41897FB377b4D5C33A304f44f
REACT_APP_TOKEN_DISTRIBUTOR=0xBF57539473913685688d224ad4E262684B23dD4c
REACT_APP_ACCOUNT_MINER=0x7B1AAF21AC0D420666B5966338FF9aEe763C29DF
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- "main"
- "next"

env:
HUSKY: 0
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
branch = v1.3.0
11 changes: 10 additions & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"branches": ["main"],
"branches": [
{
"name": "main"
},
{
"name": "next",
"channel": "next",
"prerelease": "next"
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[solidity]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
},

"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.tabSize": 2,
"eslint.validate": ["javascript", "typescript"],
"files.eol": "\n",
"solidity.formatter": "prettier",
"solidity.formatter": "forge",
"solidity.packageDefaultDependenciesContractsDirectory": "contracts",
"solidity.packageDefaultDependenciesDirectory": "node_modules",
"solidity.remappings": [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ This directory contains code used for third-party integration. Since this reposi
This directory contains protocol contracts related to access, contract discovery, data reporting, etc.

1. `AccountFactory.sol` is used to deploy Credit Accounts and managed the existing Credit Account queue. Credit Managers take accounts from the factory when a new account in Gearbox is opened and return them after the account is closed.
2. `ACL.sol` is the main access control contract in the system. Contracts that inherit `ACLTrait.sol` use `ACL.sol` to determine access to configurator-only functions.
2. `ACL.sol` is the main access control contract in the system. Contracts that inherit `ACLNonReentrantTrait.sol` use `ACL.sol` to determine access to configurator-only functions.
3. `AddressProvider.sol` is used by other contracts in the system to determine the up-to-date addresses of core contracts, such as `ACL`, `PriceOracle`, `GearToken`, etc.
4. `ContractsRegister.sol` contains a list of legitimate Gearbox Credit Managers and pools connected to the system.
5. `DataCompressor.sol` is used to retrieve detailed data on particular Credit Managers and Credit Accounts.
Expand Down
9 changes: 6 additions & 3 deletions contracts/adapters/AbstractAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ICreditManagerV2 } from "../interfaces/ICreditManagerV2.sol";
Expand All @@ -15,8 +16,9 @@ abstract contract AbstractAdapter is IAdapter {
address public immutable override targetContract;

constructor(address _creditManager, address _targetContract) {
if (_creditManager == address(0) || _targetContract == address(0))
revert ZeroAddressException(); // F:[AA-2]
if (_creditManager == address(0) || _targetContract == address(0)) {
revert ZeroAddressException();
} // F:[AA-2]

creditManager = ICreditManagerV2(_creditManager); // F:[AA-1]
targetContract = _targetContract; // F:[AA-1]
Expand Down Expand Up @@ -225,8 +227,9 @@ abstract contract AbstractAdapter is IAdapter {
balanceOutBefore
);
} else {
if (disableTokenIn)
if (disableTokenIn) {
creditManager.disableToken(creditAccount, tokenIn);
}
creditManager.checkAndEnableToken(creditAccount, tokenOut);
}
}
Expand Down
119 changes: 119 additions & 0 deletions contracts/core/ACLNonReentrantTrait.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// SPDX-License-Identifier: BUSL-1.1
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
import {AddressProvider} from "./AddressProvider.sol";
import {IACL} from "../interfaces/IACL.sol";
import {
ZeroAddressException,
CallerNotConfiguratorException,
CallerNotPausableAdminException,
CallerNotUnPausableAdminException,
CallerNotControllerException
} from "../interfaces/IErrors.sol";

/// @title ACL Trait
/// @notice Utility class for ACL consumers
abstract contract ACLNonReentrantTrait is Pausable {
uint8 private constant _NOT_ENTERED = 1;
uint8 private constant _ENTERED = 2;

// ACL contract to check rights
IACL public immutable _acl;

address public controller;
bool public externalController;

uint8 private _status = _NOT_ENTERED;

/// @dev Modifier that allow pausable admin to call the function if pause is needed
/// and for unpausable admins if unpause is needed
/// @param callToPause True if pause action is needed
modifier pausableUnpausableAdminsOnly(bool callToPause) {
if (callToPause && !_acl.isPausableAdmin(msg.sender)) {
revert CallerNotPausableAdminException();
} else if (!callToPause && !_acl.isUnpausableAdmin(msg.sender)) {
revert CallerNotUnPausableAdminException();
}

_;
}

/// @dev Prevents a contract from calling itself, directly or indirectly.
/// Calling a `nonReentrant` function from another `nonReentrant`
/// function is not supported. It is possible to prevent this from happening
/// by making the `nonReentrant` function external, and making it call a
/// `private` function that does the actual work.
///
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

// Any calls to nonReentrant after this point will fail
_status = _ENTERED;

_;

// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}

event NewController(address indexed newController);

/// @dev constructor
/// @param addressProvider Address of address repository
constructor(address addressProvider) {
if (addressProvider == address(0)) revert ZeroAddressException(); // F:[AA-2]

_acl = IACL(AddressProvider(addressProvider).getACL());
controller = IACL(AddressProvider(addressProvider).getACL()).owner();
}

/// @dev Reverts if msg.sender is not configurator
modifier configuratorOnly() {
if (!_acl.isConfigurator(msg.sender)) {
revert CallerNotConfiguratorException();
}
_;
}

/// @dev Reverts if msg.sender is not configurator
modifier controllerOnly() {
if (externalController) {
if (msg.sender != controller) {
revert CallerNotControllerException();
}
} else {
if (!_acl.isConfigurator(msg.sender)) {
revert CallerNotControllerException();
}
}
_;
}

///@dev Pause contract
function pause() external {
if (!_acl.isPausableAdmin(msg.sender)) {
revert CallerNotPausableAdminException();
}
_pause();
}

/// @dev Unpause contract
function unpause() external {
if (!_acl.isUnpausableAdmin(msg.sender)) {
revert CallerNotUnPausableAdminException();
}

_unpause();
}

function setController(address newController) external configuratorOnly {
externalController = !_acl.isConfigurator(newController);
controller = newController;
emit NewController(newController);
}
}
46 changes: 0 additions & 46 deletions contracts/core/ACLTrait.sol

This file was deleted.

7 changes: 4 additions & 3 deletions contracts/core/AccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

pragma abicoder v2;

import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
Expand All @@ -12,14 +13,14 @@ import { ICreditAccount } from "../interfaces/ICreditAccount.sol";
import { AddressProvider } from "./AddressProvider.sol";
import { ContractsRegister } from "./ContractsRegister.sol";
import { CreditAccount } from "../credit/CreditAccount.sol";
import { ACLTrait } from "./ACLTrait.sol";
import { ACLNonReentrantTrait } from "./ACLNonReentrantTrait.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";

import { Errors } from "../libraries/Errors.sol";

/// @title Abstract reusable credit accounts factory
/// @notice Creates, holds & lends credit accounts to Credit Managers
contract AccountFactory is IAccountFactory, ACLTrait, ReentrancyGuard {
contract AccountFactory is IAccountFactory, ACLNonReentrantTrait {
using EnumerableSet for EnumerableSet.AddressSet;

//
Expand Down Expand Up @@ -76,7 +77,7 @@ contract AccountFactory is IAccountFactory, ACLTrait, ReentrancyGuard {
*
* @param addressProvider Address of address repository
*/
constructor(address addressProvider) ACLTrait(addressProvider) {
constructor(address addressProvider) ACLNonReentrantTrait(addressProvider) {
require(
addressProvider != address(0),
Errors.ZERO_ADDRESS_IS_NOT_ALLOWED
Expand Down
8 changes: 5 additions & 3 deletions contracts/core/ContractsRegister.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ pragma solidity ^0.8.10;

import { IContractsRegister } from "../interfaces/IContractsRegister.sol";
import { Errors } from "../libraries/Errors.sol";
import { ACLTrait } from "./ACLTrait.sol";
import { ACLNonReentrantTrait } from "./ACLNonReentrantTrait.sol";

/// @title Pool & Credit Manager registry
/// @notice Stores addresses of Pools and Credit Managers
contract ContractsRegister is IContractsRegister, ACLTrait {
contract ContractsRegister is IContractsRegister, ACLNonReentrantTrait {
/// @dev List of all registered pools
address[] public override pools;

Expand All @@ -25,7 +25,9 @@ contract ContractsRegister is IContractsRegister, ACLTrait {
/// @dev Contract version
uint256 public constant version = 1;

constructor(address addressProvider) ACLTrait(addressProvider) {}
constructor(address addressProvider)
ACLNonReentrantTrait(addressProvider)
{}

/// @dev Adds a pool to the list
/// @param newPoolAddress Address of the new pool
Expand Down
Loading