From 14ce8c5ada0a89f8f322e58ebe3dac1e85af20fd Mon Sep 17 00:00:00 2001 From: JoscelynFarr Date: Thu, 4 Apr 2024 11:06:18 +0800 Subject: [PATCH] add customMaxLoanPerAccount --- src/JUSDBank.sol | 6 ++++-- src/JUSDBankStorage.sol | 6 ++++-- src/JUSDOperation.sol | 12 ++++++++---- test/impl/DegenDealerFundTest.sol | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/JUSDBank.sol b/src/JUSDBank.sol index 178dc1c..ac1a87d 100644 --- a/src/JUSDBank.sol +++ b/src/JUSDBank.sol @@ -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 @@ -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; @@ -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 diff --git a/src/JUSDBankStorage.sol b/src/JUSDBankStorage.sol index c59bd79..cb7b4bf 100644 --- a/src/JUSDBankStorage.sol +++ b/src/JUSDBankStorage.sol @@ -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 @@ -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; diff --git a/src/JUSDOperation.sol b/src/JUSDOperation.sol index d48a168..c22c475 100644 --- a/src/JUSDOperation.sol +++ b/src/JUSDOperation.sol @@ -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); @@ -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 diff --git a/test/impl/DegenDealerFundTest.sol b/test/impl/DegenDealerFundTest.sol index 577490b..31c7ba6 100644 --- a/test/impl/DegenDealerFundTest.sol +++ b/test/impl/DegenDealerFundTest.sol @@ -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(); }