fix contract
This commit is contained in:
@@ -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 暂停后,所有资金流动操作将被禁止
|
||||
|
||||
Reference in New Issue
Block a user