ytLending supports USDC as the base token

This commit is contained in:
2025-12-26 13:23:50 +08:00
parent e21ee7a5df
commit 9a92c81aec
37 changed files with 4298 additions and 3064 deletions

View File

@@ -200,5 +200,11 @@ contract Configurator is
function getConfiguration(address lendingProxy) external view returns (Configuration memory) {
return configuratorParams[lendingProxy];
}
/**
* @dev 预留存储空间,用于未来升级时添加新的状态变量
* 50个slot = 50 * 32 bytes = 1600 bytes
*/
uint256[50] private __gap;
}

View File

@@ -156,7 +156,7 @@ contract Lending is
function supply(uint256 amount) external override nonReentrant whenNotPaused {
accrueInterest();
IERC20(baseToken).safeTransferFrom(msg.sender, address(this), amount);
IERC20(baseToken).transferFrom(msg.sender, address(this), amount);
// 获取用户当前本金
UserBasic memory user = userBasic[msg.sender];
@@ -240,7 +240,7 @@ contract Lending is
uint256 newTotal = userCollateral[msg.sender][asset] + amount;
if (newTotal > config.supplyCap) revert SupplyCapExceeded();
IERC20(asset).safeTransferFrom(msg.sender, address(this), amount);
IERC20(asset).transferFrom(msg.sender, address(this), amount);
userCollateral[msg.sender][asset] += amount;
@@ -440,7 +440,7 @@ contract Lending is
if (collateralAmount > collateralReserves[asset]) revert InsufficientBalance();
// 收取清算人支付的资金
IERC20(baseToken).safeTransferFrom(msg.sender, address(this), baseAmount);
IERC20(baseToken).transferFrom(msg.sender, address(this), baseAmount);
// 抵押品出库
collateralReserves[asset] -= collateralAmount;
@@ -673,5 +673,11 @@ contract Lending is
emit WithdrawReserves(to, amount);
}
/**
* @dev 预留存储空间,用于未来升级时添加新的状态变量
* 50个slot = 50 * 32 bytes = 1600 bytes
*/
uint256[50] private __gap;
}

View File

@@ -1,39 +1,59 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../interfaces/IYTVault.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "../interfaces/IYTAssetVault.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
contract LendingPriceFeed is Ownable {
address public ytVault;
address public wusdAddress;
contract LendingPriceFeed is OwnableUpgradeable, UUPSUpgradeable {
address public usdcAddress;
AggregatorV3Interface internal usdcPriceFeed;
error InvalidYTVaultAddress();
error InvalidWUSDAddress();
constructor(address _ytVault, address _wusdAddress) Ownable(msg.sender) {
if (_ytVault == address(0)) revert InvalidYTVaultAddress();
if (_wusdAddress == address(0)) revert InvalidWUSDAddress();
ytVault = _ytVault;
wusdAddress = _wusdAddress;
error InvalidUsdcAddress();
error InvalidUsdcPriceFeedAddress();
error InvalidChainlinkPrice();
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function setYTVault(address _ytVault) external onlyOwner {
if (_ytVault == address(0)) revert InvalidYTVaultAddress();
ytVault = _ytVault;
function initialize(address _usdcAddress, address _usdcPriceFeed) external initializer {
__UUPSUpgradeable_init();
__Ownable_init(msg.sender);
if (_usdcAddress == address(0)) revert InvalidUsdcAddress();
if (_usdcPriceFeed == address(0)) revert InvalidUsdcPriceFeedAddress();
usdcAddress = _usdcAddress;
usdcPriceFeed = AggregatorV3Interface(_usdcPriceFeed);
}
function setWUSDAddress(address _wusdAddress) external onlyOwner {
if (_wusdAddress == address(0)) revert InvalidWUSDAddress();
wusdAddress = _wusdAddress;
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
function setUsdcAddress(address _usdcAddress) external onlyOwner {
if (_usdcAddress == address(0)) revert InvalidUsdcAddress();
usdcAddress = _usdcAddress;
}
function getPrice(address _token) external view returns (uint256) {
if (_token == wusdAddress) {
return IYTVault(ytVault).wusdPrice();
} else {
return IYTVault(_token).ytPrice();
if (_token == usdcAddress) {
return _getUSDCPrice();
}
return IYTAssetVault(_token).ytPrice();
}
function _getUSDCPrice() internal view returns (uint256) {
(
/* uint80 roundId */,
int256 price,
/* uint256 startedAt */,
/* uint256 updatedAt */,
/* uint80 answeredInRound */
) = usdcPriceFeed.latestRoundData();
if (price <= 0) revert InvalidChainlinkPrice();
return uint256(price) * 1e22; // 1e22 = 10^(30-8)
}
}