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

@@ -27,7 +27,6 @@ interface ILending {
function withdraw(uint256 amount) external;
function supplyCollateral(address asset, uint256 amount) external;
function withdrawCollateral(address asset, uint256 amount) external;
function borrow(uint256 amount) external;
function absorb(address borrower) external;
function absorbMultiple(address absorber, address[] calldata accounts) external;
function buyCollateral(address asset, uint256 minAmount, uint256 baseAmount, address recipient) external;

View File

@@ -50,8 +50,7 @@ contract Configurator is
Configuration memory oldConfiguration = configuratorParams[lendingProxy];
if (oldConfiguration.baseToken != address(0) &&
(oldConfiguration.baseToken != newConfiguration.baseToken ||
oldConfiguration.trackingIndexScale != newConfiguration.trackingIndexScale))
oldConfiguration.baseToken != newConfiguration.baseToken)
revert ConfigurationAlreadyExists();
delete configuratorParams[lendingProxy];
@@ -67,7 +66,6 @@ contract Configurator is
configuratorParams[lendingProxy].borrowPerYearInterestRateSlopeHigh = newConfiguration.borrowPerYearInterestRateSlopeHigh;
configuratorParams[lendingProxy].borrowPerYearInterestRateBase = newConfiguration.borrowPerYearInterestRateBase;
configuratorParams[lendingProxy].storeFrontPriceFactor = newConfiguration.storeFrontPriceFactor;
configuratorParams[lendingProxy].trackingIndexScale = newConfiguration.trackingIndexScale;
configuratorParams[lendingProxy].baseBorrowMin = newConfiguration.baseBorrowMin;
configuratorParams[lendingProxy].targetReserves = newConfiguration.targetReserves;

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();

View File

@@ -26,7 +26,6 @@ contract LendingConfiguration {
uint64 borrowPerYearInterestRateBase; // 借款基础利率
uint64 storeFrontPriceFactor; // 清算价格折扣
uint64 trackingIndexScale; // 追踪索引比例
uint104 baseBorrowMin; // 最小借款额
uint104 targetReserves; // 目标储备金

View File

@@ -19,7 +19,6 @@ abstract contract LendingStorage is LendingConfiguration {
uint64 public borrowPerSecondInterestRateBase;
uint64 public storeFrontPriceFactor;
uint64 public trackingIndexScale;
uint104 public baseBorrowMin;
uint104 public targetReserves;