update lending contract

This commit is contained in:
2025-12-29 15:38:25 +08:00
parent dba8fa1af0
commit 2cd584be76
28 changed files with 50 additions and 88 deletions

View File

@@ -51,7 +51,6 @@ contract Lending is
borrowPerSecondInterestRateBase = uint64(config.borrowPerYearInterestRateBase / SECONDS_PER_YEAR);
storeFrontPriceFactor = config.storeFrontPriceFactor;
trackingIndexScale = config.trackingIndexScale;
baseBorrowMin = config.baseBorrowMin;
targetReserves = config.targetReserves;
@@ -211,36 +210,6 @@ contract Lending is
emit WithdrawCollateral(msg.sender, msg.sender, asset, amount);
}
function borrow(uint256 amount) external override nonReentrant whenNotPaused {
accrueInterest();
UserBasic memory user = userBasic[msg.sender];
int104 oldPrincipal = user.principal;
uint256 index = oldPrincipal >= 0 ? supplyIndex : borrowIndex;
int256 oldBalance = LendingMath.principalToBalance(oldPrincipal, index);
int256 newBalance = oldBalance - int256(amount);
if (newBalance < 0 && uint256(-newBalance) < baseBorrowMin) revert BorrowTooSmall();
uint256 newIndex = newBalance >= 0 ? supplyIndex : borrowIndex;
int104 newPrincipal = LendingMath.balanceToPrincipal(newBalance, newIndex);
(uint104 withdrawAmount, uint104 borrowAmount) = LendingMath.withdrawAndBorrowAmount(oldPrincipal, newPrincipal);
totalSupplyBase -= withdrawAmount;
totalBorrowBase += borrowAmount;
userBasic[msg.sender].principal = newPrincipal;
if (!_isSolvent(msg.sender)) revert InsufficientCollateral();
IERC20(baseToken).safeTransfer(msg.sender, amount);
emit Withdraw(msg.sender, msg.sender, amount);
}
function _absorbInternal(address absorber, address borrower) internal {
if (!isLiquidatable(borrower)) revert NotLiquidatable();