update liquidation bot scripts

This commit is contained in:
2026-03-05 10:48:08 +08:00
parent e39529984d
commit e05762aa46
23 changed files with 436 additions and 49 deletions

View File

@@ -11,6 +11,7 @@ interface IYTVault {
function getMinPrice(address _token) external view returns (uint256);
function getSwapFeeBasisPoints(address _tokenIn, address _tokenOut, uint256 _usdyAmount) external view returns (uint256);
function getRedemptionFeeBasisPoints(address _token, uint256 _usdyAmount) external view returns (uint256);
function getSwapAmountOut(address _tokenIn, address _tokenOut, uint256 _amountIn) external view returns (uint256 amountOut, uint256 amountOutAfterFees, uint256 feeBasisPoints);
function ytPrice() external view returns (uint256);
function wusdPrice() external view returns (uint256);
}

View File

@@ -503,6 +503,42 @@ contract YTVault is Initializable, UUPSUpgradeable, ReentrancyGuardUpgradeable {
) public view returns (uint256) {
return _getSwapFeeBasisPoints(usdy, _token, _usdyAmount);
}
/**
* @notice 预估swap输出数量
* @param _tokenIn 输入代币地址
* @param _tokenOut 输出代币地址
* @param _amountIn 输入数量
* @return amountOut 扣费前输出量
* @return amountOutAfterFees 扣费后实际输出量
* @return feeBasisPoints 动态手续费率
*/
function getSwapAmountOut(
address _tokenIn,
address _tokenOut,
uint256 _amountIn
) external view returns (
uint256 amountOut,
uint256 amountOutAfterFees,
uint256 feeBasisPoints
) {
if (_amountIn == 0) revert InvalidAmount();
if (!whitelistedTokens[_tokenIn]) revert TokenNotWhitelisted();
if (!whitelistedTokens[_tokenOut]) revert TokenNotWhitelisted();
if (_tokenIn == _tokenOut) revert SameToken();
uint256 priceIn = _getPrice(_tokenIn, false);
uint256 priceOut = _getPrice(_tokenOut, true);
uint256 usdyAmount = _amountIn * priceIn / PRICE_PRECISION;
usdyAmount = _adjustForDecimals(usdyAmount, _tokenIn, usdy);
amountOut = usdyAmount * PRICE_PRECISION / priceOut;
amountOut = _adjustForDecimals(amountOut, usdy, _tokenOut);
feeBasisPoints = _getSwapFeeBasisPoints(_tokenIn, _tokenOut, usdyAmount);
amountOutAfterFees = amountOut * (BASIS_POINTS_DIVISOR - feeBasisPoints) / BASIS_POINTS_DIVISOR;
}
function _getSwapFeeBasisPoints(
address _tokenIn,