This commit is contained in:
2025-12-26 13:27:37 +08:00
36 changed files with 4350 additions and 3061 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)
}
}

View File

@@ -146,7 +146,7 @@ contract YTPoolManager is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrade
uint256 aumInUsdy = getAumInUsdy(true);
uint256 ytLPSupply = IERC20(ytLP).totalSupply();
IERC20(_token).safeTransferFrom(_fundingAccount, ytVault, _amount);
IERC20(_token).transferFrom(_fundingAccount, ytVault, _amount);
uint256 usdyAmount = IYTVault(ytVault).buyUSDY(_token, address(this));
if (usdyAmount < _minUsdy) revert InsufficientOutput();

View File

@@ -86,7 +86,7 @@ contract YTRewardRouter is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrad
address account = msg.sender;
IERC20(_token).safeTransferFrom(account, address(this), _amount);
IERC20(_token).transferFrom(account, address(this), _amount);
IERC20(_token).approve(ytPoolManager, _amount);
uint256 ytLPAmount = IYTPoolManager(ytPoolManager).addLiquidityForAccount(
@@ -133,7 +133,7 @@ contract YTRewardRouter is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrad
address account = msg.sender;
IERC20(_tokenIn).safeTransferFrom(account, ytVault, _amountIn);
IERC20(_tokenIn).transferFrom(account, ytVault, _amountIn);
uint256 amountOut = IYTVault(ytVault).swap(_tokenIn, _tokenOut, _receiver);

View File

@@ -201,7 +201,12 @@ contract YTAssetVault is
revert HardCapExceeded();
}
<<<<<<< HEAD
IERC20(usdcAddress).safeTransferFrom(msg.sender, address(this), _usdcAmount);
=======
// 转入USDC
IERC20(usdcAddress).transferFrom(msg.sender, address(this), _usdcAmount);
>>>>>>> usdc
_mint(msg.sender, ytAmount);
@@ -377,7 +382,12 @@ contract YTAssetVault is
managedAssets -= _amount;
}
<<<<<<< HEAD
IERC20(usdcAddress).safeTransferFrom(msg.sender, address(this), _amount);
=======
// 从manager转入USDC到合约
IERC20(usdcAddress).transferFrom(msg.sender, address(this), _amount);
>>>>>>> usdc
emit AssetsDeposited(_amount);
}