Skip to content

Commit

Permalink
fix: limit -> quoted
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmikko committed Apr 28, 2023
1 parent 4a93d3a commit 3043320
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
8 changes: 4 additions & 4 deletions contracts/credit/CreditConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ contract CreditConfigurator is ICreditConfigurator, ACLNonReentrantTrait {
uint256 tokenMask = _getAndCheckTokenMaskForSettingLT(token);

// Gets current limited mask
uint256 limitedTokenMask = creditManager.limitedTokenMask();
uint256 quotedTokenMask = creditManager.quotedTokenMask();

// If the token was not limited before, flips the corresponding bit in the mask,
// otherwise no actions done.
if (limitedTokenMask & tokenMask == 0) {
limitedTokenMask |= tokenMask;
creditManager.setLimitedMask(limitedTokenMask);
if (quotedTokenMask & tokenMask == 0) {
quotedTokenMask |= tokenMask;
creditManager.setQuotedMask(quotedTokenMask);
emit LimitToken(token);
}
}
Expand Down
15 changes: 7 additions & 8 deletions contracts/credit/CreditFacadeV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ contract CreditFacadeV3 is ICreditFacade, ACLNonReentrantTrait, BalanceHelperTra
uint256 enabledTokensMask,
uint256 flags
) internal returns (FullCheckParams memory fullCheckParams) {
uint256 limitedTokenMaskInverted = ~creditManager.limitedTokenMask();
uint256 quotedTokenMaskInverted = ~creditManager.quotedTokenMask();
// Emits event for multicall start - used in analytics to track actions within multicalls
emit StartMultiCall(borrower); // F:[FA-26]

Expand Down Expand Up @@ -527,8 +527,7 @@ contract CreditFacadeV3 is ICreditFacade, ACLNonReentrantTrait, BalanceHelperTra
//
else if (method == ICreditFacadeMulticall.addCollateral.selector) {
_revertIfNoPermission(flags, ADD_COLLATERAL_PERMISSION);
enabledTokensMask |=
_addCollateral(creditAccount, callData, borrower) & limitedTokenMaskInverted; // F:[FA-26, 27]
enabledTokensMask |= _addCollateral(creditAccount, callData, borrower) & quotedTokenMaskInverted; // F:[FA-26, 27]
}
//
// INCREASE DEBT
Expand Down Expand Up @@ -563,7 +562,7 @@ contract CreditFacadeV3 is ICreditFacade, ACLNonReentrantTrait, BalanceHelperTra
_revertIfNoPermission(flags, ENABLE_TOKEN_PERMISSION);
// Parses token
address token = abi.decode(callData, (address)); // F: [FA-53]
enabledTokensMask |= _getTokenMaskOrRevert(token) & limitedTokenMaskInverted;
enabledTokensMask |= _getTokenMaskOrRevert(token) & quotedTokenMaskInverted;
}
//
// DISABLE TOKEN
Expand All @@ -573,7 +572,7 @@ contract CreditFacadeV3 is ICreditFacade, ACLNonReentrantTrait, BalanceHelperTra
// Parses token
address token = abi.decode(callData, (address)); // F: [FA-53]
/// IGNORE QUOTED TOKEN MASK
enabledTokensMask &= ~(_getTokenMaskOrRevert(token) & limitedTokenMaskInverted);
enabledTokensMask &= ~(_getTokenMaskOrRevert(token) & quotedTokenMaskInverted);
}
//
// UPDATE QUOTAS
Expand All @@ -592,7 +591,7 @@ contract CreditFacadeV3 is ICreditFacade, ACLNonReentrantTrait, BalanceHelperTra
_revertIfNoPermission(flags, WITHDRAW_PERMISSION);
uint256 tokensToDisable = _withdraw(callData, creditAccount);
/// IGNORE QUOTED TOKEN MASK
enabledTokensMask = enabledTokensMask & (~(tokensToDisable & limitedTokenMaskInverted));
enabledTokensMask = enabledTokensMask & (~(tokensToDisable & quotedTokenMaskInverted));
}
//
// RevokeAdapterAllowances
Expand Down Expand Up @@ -632,8 +631,8 @@ contract CreditFacadeV3 is ICreditFacade, ACLNonReentrantTrait, BalanceHelperTra
bytes memory result = mcall.target.functionCall(mcall.callData); // F:[FA-29]
(uint256 tokensToEnable, uint256 tokensToDisable) = abi.decode(result, (uint256, uint256));
/// IGNORE QUOTED TOKEN MASK
enabledTokensMask = (enabledTokensMask & limitedTokenMaskInverted | tokensToEnable)
& (~(tokensToDisable & limitedTokenMaskInverted));
enabledTokensMask = (enabledTokensMask & quotedTokenMaskInverted | tokensToEnable)
& (~(tokensToDisable & quotedTokenMaskInverted));
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/credit/CreditManagerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuard,
bool public immutable override supportsQuotas;

/// @dev Mask of tokens to apply quotas for
uint256 public override limitedTokenMask;
uint256 public override quotedTokenMask;

IWithdrawManager public withdrawManager;

Expand Down Expand Up @@ -842,7 +842,7 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuard,
bool nonZeroBalance;

enabledTokensMask = _enabledTokensMask;
uint256 checkedTokenMask = supportsQuotas ? enabledTokensMask & (~limitedTokenMask) : enabledTokensMask;
uint256 checkedTokenMask = supportsQuotas ? enabledTokensMask & (~quotedTokenMask) : enabledTokensMask;

if (borrowAmountPlusInterestRateAndFeesUSD != type(uint256).max) {
borrowAmountPlusInterestRateAndFeesUSD *= PERCENTAGE_FACTOR;
Expand Down Expand Up @@ -939,7 +939,7 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuard,
}

function _getQuotedTokens(uint256 enabledTokensMask) internal view returns (TokenLT[] memory tokens) {
uint256 quotedMask = enabledTokensMask & limitedTokenMask;
uint256 quotedMask = enabledTokensMask & quotedTokenMask;

if (quotedMask > 0) {
tokens = new TokenLT[](maxAllowedEnabledTokenLength + 1);
Expand Down Expand Up @@ -1511,15 +1511,15 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuard,
}

/// @dev Sets the limited token mask
/// @param _limitedTokenMask The new mask
/// @param _quotedTokenMask The new mask
/// @notice Limited tokens are counted as collateral not based on their balances,
/// but instead based on their quotas set in the poolQuotaKeeper contract
/// Tokens in the mask also incur additional interest based on their quotas
function setLimitedMask(uint256 _limitedTokenMask)
function setQuotedMask(uint256 _quotedTokenMask)
external
creditConfiguratorOnly // F: [CMQ-2]
{
limitedTokenMask = _limitedTokenMask; // F: [CMQ-2]
quotedTokenMask = _quotedTokenMask; // F: [CMQ-2]
}

/// @dev Sets the maximal number of enabled tokens on a single Credit Account.
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ICreditManagerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ interface ICreditManagerV3 is ICreditManagerV3Events, IVersion {
function getTokenMaskOrRevert(address token) external view returns (uint256);

/// @dev Mask of tokens to apply quotas for
function limitedTokenMask() external view returns (uint256);
function quotedTokenMask() external view returns (uint256);

/// @dev Maps allowed adapters to their respective target contracts.
function adapterToContract(address adapter) external view returns (address);
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/suites/CreditManagerTestSuite.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ contract CreditManagerTestSuite is PoolDeployer {
gaugeMock.updateEpoch();

uint256 tokenMask = creditManager.getTokenMaskOrRevert(token);
uint256 limitedMask = creditManager.limitedTokenMask();
uint256 limitedMask = creditManager.quotedTokenMask();

creditManager.setLimitedMask(limitedMask | tokenMask);
creditManager.setQuotedMask(limitedMask | tokenMask);

evm.stopPrank();
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/test/unit/credit/CreditManager_Quotas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,22 @@ contract CreditManagerQuotasTest is DSTest, ICreditManagerV3Events, BalanceHelpe
assertTrue(creditManager.supportsQuotas(), "Credit Manager does not support quotas");
}

/// @dev [CMQ-2]: setLimitedMask works correctly
function test_CMQ_02_setLimitedMask_works_correctly() public {
/// @dev [CMQ-2]: setQuotedMask works correctly
function test_CMQ_02_setQuotedMask_works_correctly() public {
_addQuotedToken(tokenTestSuite.addressOf(Tokens.LINK), 10_00, uint96(1_000_000 * WAD));

uint256 usdcMask = creditManager.getTokenMaskOrRevert(tokenTestSuite.addressOf(Tokens.USDC));
uint256 linkMask = creditManager.getTokenMaskOrRevert(tokenTestSuite.addressOf(Tokens.LINK));

uint256 limitedTokenMask = creditManager.limitedTokenMask();
uint256 quotedTokenMask = creditManager.quotedTokenMask();

evm.expectRevert(CallerNotConfiguratorException.selector);
creditManager.setLimitedMask(limitedTokenMask | usdcMask);
creditManager.setQuotedMask(quotedTokenMask | usdcMask);

evm.prank(CONFIGURATOR);
creditManager.setLimitedMask(limitedTokenMask | usdcMask);
creditManager.setQuotedMask(quotedTokenMask | usdcMask);

assertEq(creditManager.limitedTokenMask(), usdcMask | linkMask, "New limited mask is incorrect");
assertEq(creditManager.quotedTokenMask(), usdcMask | linkMask, "New limited mask is incorrect");
}

/// @dev [CMQ-3]: updateQuotas works correctly
Expand Down

0 comments on commit 3043320

Please sign in to comment.