Skip to content

Commit

Permalink
add customMaxLoanPerAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
JoscelynFarr committed Apr 4, 2024
1 parent 4b8e22d commit 14ce8c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/JUSDBank.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract JUSDBank is IJUSDBank, JUSDOperation, JUSDView, JUSDMulticall {
address _insurance,
address _JUSD,
address _JOJODealer,
uint256 _maxPerAccountBorrowAmount,
uint256 _defualtAccountMaxBorrowAmount,
uint256 _maxTotalBorrowAmount,
uint256 _borrowFeeRate,
address _primaryAsset
Expand All @@ -33,7 +33,7 @@ contract JUSDBank is IJUSDBank, JUSDOperation, JUSDView, JUSDMulticall {
JUSD = _JUSD;
JOJODealer = _JOJODealer;
insurance = _insurance;
maxPerAccountBorrowAmount = _maxPerAccountBorrowAmount;
defualtAccountMaxBorrowAmount = _defualtAccountMaxBorrowAmount;
maxTotalBorrowAmount = _maxTotalBorrowAmount;
borrowFeeRate = _borrowFeeRate;
tRate = Types.ONE;
Expand Down Expand Up @@ -281,6 +281,8 @@ contract JUSDBank is IJUSDBank, JUSDOperation, JUSDView, JUSDMulticall {
} else {
IERC20(JUSD).safeTransfer(to, tAmount);
}
uint256 maxPerAccountBorrowAmount =
customMaxLoanPerAccount[from] > 0 ? customMaxLoanPerAccount[from] : defualtAccountMaxBorrowAmount;
require(
user.t0BorrowBalance.decimalMul(tRate) <= maxPerAccountBorrowAmount,
Errors.EXCEED_THE_MAX_BORROW_AMOUNT_PER_ACCOUNT
Expand Down
6 changes: 4 additions & 2 deletions src/JUSDBankStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ abstract contract JUSDBankStorage is Ownable, ReentrancyGuard, FlashLoanReentran
uint256 public reservesNum;
// max reserves amount
uint256 public maxReservesNum;
// max borrow JUSD amount per account
uint256 public maxPerAccountBorrowAmount;
// max total borrow JUSD amount
uint256 public defualtAccountMaxBorrowAmount;
// max total borrow JUSD amount
uint256 public maxTotalBorrowAmount;
// t0 total borrow JUSD amount
Expand Down Expand Up @@ -49,6 +49,8 @@ abstract contract JUSDBankStorage is Ownable, ReentrancyGuard, FlashLoanReentran
mapping(address => Types.UserInfo) public userInfo;
// client -> operator -> bool
mapping(address => mapping(address => bool)) public operatorRegistry;
// max borrow JUSD amount
mapping(address => uint256) public customMaxLoanPerAccount;

function accrueRate() public {
uint256 currentTimestamp = block.timestamp;
Expand Down
12 changes: 8 additions & 4 deletions src/JUSDOperation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract contract JUSDOperation is JUSDBankStorage {

event UpdateMaxReservesAmount(uint256 maxReservesAmount, uint256 newMaxReservesAmount);

event UpdateMaxBorrowAmount(uint256 maxPerAccountBorrowAmount, uint256 maxTotalBorrowAmount);
event UpdateMaxBorrowAmount(uint256 defualtAccountMaxBorrowAmount, uint256 maxTotalBorrowAmount);

event SetOperator(address indexed client, address indexed operator, bool isOperator);

Expand Down Expand Up @@ -83,15 +83,19 @@ abstract contract JUSDOperation is JUSDBankStorage {

/// @notice update the max borrow amount of total and per account
function updateMaxBorrowAmount(
uint256 _maxBorrowAmountPerAccount,
uint256 _defualtAccountMaxBorrowAmount,
uint256 _maxTotalBorrowAmount
)
external
onlyOwner
{
maxTotalBorrowAmount = _maxTotalBorrowAmount;
maxPerAccountBorrowAmount = _maxBorrowAmountPerAccount;
emit UpdateMaxBorrowAmount(maxPerAccountBorrowAmount, maxTotalBorrowAmount);
defualtAccountMaxBorrowAmount = _defualtAccountMaxBorrowAmount;
emit UpdateMaxBorrowAmount(defualtAccountMaxBorrowAmount, maxTotalBorrowAmount);
}

function updateCustomMaxLoanPerAccount(address user, uint256 amount) external onlyOwner {
customMaxLoanPerAccount[user] = amount;
}

/// @notice update the insurance account
Expand Down
2 changes: 1 addition & 1 deletion test/impl/DegenDealerFundTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract DegenFundTest is Checkers {
1000e6,
0,
false,
abi.encodeWithSignature("depositToDegenDealer(address,address)", traders[0])
abi.encodeWithSignature("depositToDegenDealer(address)", traders[0])
);
vm.stopPrank();
}
Expand Down

0 comments on commit 14ce8c5

Please sign in to comment.