Skip to content

Commit

Permalink
Merge pull request #39 from Gearbox-protocol/unit-tests
Browse files Browse the repository at this point in the history
test: credit facade modifiers and open credit account tests
  • Loading branch information
0xmikko authored May 24, 2023
2 parents 1983c2a + bd94bda commit d7c81be
Show file tree
Hide file tree
Showing 20 changed files with 1,320 additions and 739 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ forge-out/
.mainnet.test.cache
*.log
.eslintcache
.eslint.local.json
.eslint.local.json
.favorites.json
251 changes: 135 additions & 116 deletions contracts/credit/CreditFacadeV3.sol

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contracts/credit/CreditManagerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuardT
function openCreditAccount(uint256 debt, address onBehalfOf)
external
override
nonZeroAddress(onBehalfOf) // todo: add check
nonReentrant // U:[CM-5]
creditFacadeOnly // // U:[CM-2]
returns (address creditAccount)
Expand Down
8 changes: 1 addition & 7 deletions contracts/interfaces/ICreditFacade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,7 @@ interface ICreditFacade is ICreditFacadeEvents, IVersion {
uint256 skipTokenMask,
bool convertToETH,
MultiCall[] calldata calls
) external payable;

// /// @dev Adds collateral to borrower's credit account
// /// @param onBehalfOf Address of the borrower whose account is funded
// /// @param token Address of a collateral token
// /// @param amount Amount to add
// function addCollateral(address onBehalfOf, address token, uint256 amount) external payable;
) external;

/// @dev Executes a batch of transactions within a Multicall, to manage an existing account
/// - Wraps ETH and sends it back to msg.sender, if value > 0
Expand Down
5 changes: 4 additions & 1 deletion contracts/interfaces/ICreditFacadeMulticall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ uint256 constant DISABLE_TOKEN_PERMISSION = 2 ** 4;
uint256 constant WITHDRAW_PERMISSION = 2 ** 5;
uint256 constant UPDATE_QUOTA_PERMISSION = 2 ** 6;
uint256 constant REVOKE_ALLOWANCES_PERMISSION = 2 ** 7;
uint256 constant PAY_BOT_PERMISSION = 2 ** 8;

uint256 constant EXTERNAL_CALLS_PERMISSION = 2 ** 16;

uint256 constant ALL_CREDIT_FACADE_CALLS_PERMISSION = ADD_COLLATERAL_PERMISSION | INCREASE_DEBT_PERMISSION
Expand All @@ -27,6 +27,9 @@ uint256 constant ALL_PERMISSIONS = ALL_CREDIT_FACADE_CALLS_PERMISSION | EXTERNAL
uint256 constant INCREASE_DEBT_WAS_CALLED = 2 ** 193;
uint256 constant EXTERNAL_CONTRACT_WAS_CALLED = 2 ** 194;

// Pay bot permisson is set there because it's used for bots only
uint256 constant PAY_BOT_PERMISSION = 2 ** 195;

interface ICreditFacadeMulticall {
/// @dev Instructs CreditFacadeV3 to check token balances at the end
/// Used to control slippage after the entire sequence of operations, since tracking slippage
Expand Down
6 changes: 4 additions & 2 deletions contracts/interfaces/IExceptions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ error IncorrectPriceFeedException();
/// @dev Thrown on attempting to get a result for a token that does not have a price feed
error PriceFeedNotExistsException();

error ForbiddenInWhitelistedModeException();

///
/// ACCESS
///
Expand Down Expand Up @@ -226,8 +228,6 @@ error NothingToClaimException();

error LiquiditySanityCheckException();

error ZeroCallsException();

/// @dev Thrown when attempting to schedule withdrawal from a credit account that has no free withdrawal slots
error NoFreeWithdrawalSlotsException();

Expand All @@ -243,3 +243,5 @@ error MasterCreditAccountAlreadyDeployedException();

/// @dev Thrown when trying to rescue funds from a credit account that is currently in use
error CreditAccountIsInUseException();

error InsufficientBalanceException();
2 changes: 1 addition & 1 deletion contracts/pool/PoolV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct CreditManagerDebt {

/// @title Core pool contract compatible with ERC4626
/// @notice Implements pool & diesel token business logic
contract PoolV3 is ERC4626, IPoolV3, ACLNonReentrantTrait, ContractsRegisterTrait {
contract PoolV3 is ERC4626, ACLNonReentrantTrait, ContractsRegisterTrait, IPoolV3 {
using Math for uint256;
using EnumerableSet for EnumerableSet.AddressSet;
using SafeERC20 for IERC20;
Expand Down
Loading

0 comments on commit d7c81be

Please sign in to comment.