fix contract

This commit is contained in:
2026-01-12 14:33:16 +08:00
parent a18b9a42e4
commit d56f83726b
70 changed files with 1988 additions and 142 deletions

View File

@@ -238,6 +238,17 @@ contract YTAssetFactory is Initializable, UUPSUpgradeable, OwnableUpgradeable {
YTAssetVault(_vault).setManager(_manager);
}
/**
* @notice 设置vault的价格过期阈值
* @param _vault vault地址
* @param _threshold 阈值(秒)
*/
function setPriceStalenessThreshold(address _vault, uint256 _threshold) external onlyOwner {
if (!isVault[_vault]) revert VaultNotExists();
YTAssetVault(_vault).setPriceStalenessThreshold(_threshold);
}
/**
* @notice 设置vault的下一个赎回时间
* @param _vault vault地址

View File

@@ -43,6 +43,7 @@ contract YTAssetVault is
error InvalidBatchSize();
error InvalidPriceFeed();
error InvalidChainlinkPrice();
error StalePrice();
/// @notice 工厂合约地址
address public factory;
@@ -71,6 +72,9 @@ contract YTAssetVault is
/// @notice Chainlink价格精度
uint256 public constant CHAINLINK_PRICE_PRECISION = 1e8;
/// @notice 价格过期阈值(秒)
uint256 public priceStalenesThreshold;
/// @notice 下一个赎回开放时间(所有用户统一)
uint256 public nextRedemptionTime;
@@ -165,6 +169,9 @@ contract YTAssetVault is
// 设置赎回时间
nextRedemptionTime = _redemptionTime;
// 设置默认价格过期阈值1小时
priceStalenesThreshold = 3600;
}
/**
@@ -179,15 +186,21 @@ contract YTAssetVault is
*/
function _getUSDCPrice() internal view returns (uint256) {
(
/* uint80 roundId */,
uint80 roundId,
int256 price,
/* uint256 startedAt */,
/* uint256 updatedAt */,
/* uint80 answeredInRound */
uint256 updatedAt,
uint80 answeredInRound
) = usdcPriceFeed.latestRoundData();
// 价格有效性检查
if (price <= 0) revert InvalidChainlinkPrice();
// 新鲜度检查:确保价格数据不过期
if (updatedAt == 0) revert StalePrice();
if (answeredInRound < roundId) revert StalePrice();
if (block.timestamp - updatedAt > priceStalenesThreshold) revert StalePrice();
return uint256(price);
}
@@ -228,6 +241,15 @@ contract YTAssetVault is
emit ManagerSet(_manager);
}
/**
* @notice 设置价格过期阈值
* @param _threshold 阈值例如3600 = 1小时86400 = 24小时
*/
function setPriceStalenessThreshold(uint256 _threshold) external onlyFactory {
require(_threshold > 0 && _threshold <= 7 days, "Invalid threshold");
priceStalenesThreshold = _threshold;
}
/**
* @notice 暂停合约仅factory可调用
* @dev 暂停后,所有资金流动操作将被禁止