add view function

This commit is contained in:
2026-03-09 10:30:50 +08:00
parent 586b04a371
commit e033cbd1c4
11 changed files with 369 additions and 13 deletions

View File

@@ -286,10 +286,60 @@ contract YTPoolManager is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrade
return aum;
}
/**
* @notice 预估添加流动性能获得的 ytLP 数量
* @param _token 存入的 token 地址
* @param _amount 存入的 token 数量
* @return usdyAmount 扣除手续费后实际得到的 USDY 数量
* @return ytLPMintAmount 预计铸造的 ytLP 数量
*/
function getAddLiquidityOutput(
address _token,
uint256 _amount
) external view returns (uint256 usdyAmount, uint256 ytLPMintAmount) {
// 模拟 buyUSDYtoken → USDY含动态手续费
uint256 price = IYTVault(ytVault).getMinPrice(_token);
uint256 rawUsdyAmount = _amount * price / PRICE_PRECISION;
uint256 feeBasisPoints = IYTVault(ytVault).getSwapFeeBasisPoints(_token, usdy, rawUsdyAmount);
uint256 amountAfterFees = _amount - (_amount * feeBasisPoints / BASIS_POINTS_DIVISOR);
usdyAmount = amountAfterFees * price / PRICE_PRECISION;
// 模拟 _addLiquidityUSDY → ytLP mint 数量
uint256 aumInUsdy = getAumInUsdy(true);
uint256 ytLPSupply = IERC20(ytLP).totalSupply();
if (ytLPSupply == 0) {
ytLPMintAmount = usdyAmount;
} else {
ytLPMintAmount = usdyAmount * ytLPSupply / aumInUsdy;
}
}
/**
* @notice 预估移除流动性能获得的 token 数量
* @param _tokenOut 取出的 token 地址
* @param _ytLPAmount 销毁的 ytLP 数量
* @return usdyAmount ytLP 对应的 USDY 价值
* @return amountOut 扣除手续费后实际获得的 token 数量
*/
function getRemoveLiquidityOutput(
address _tokenOut,
uint256 _ytLPAmount
) external view returns (uint256 usdyAmount, uint256 amountOut) {
// 模拟 _removeLiquidityytLP → USDY
uint256 aumInUsdy = getAumInUsdy(false);
uint256 ytLPSupply = IERC20(ytLP).totalSupply();
usdyAmount = _ytLPAmount * aumInUsdy / ytLPSupply;
// 模拟 sellUSDYUSDY → token含动态手续费
uint256 price = IYTVault(ytVault).getMaxPrice(_tokenOut);
uint256 redemptionAmount = usdyAmount * PRICE_PRECISION / price;
uint256 feeBasisPoints = IYTVault(ytVault).getRedemptionFeeBasisPoints(_tokenOut, redemptionAmount);
amountOut = redemptionAmount * (BASIS_POINTS_DIVISOR - feeBasisPoints) / BASIS_POINTS_DIVISOR;
}
/**
* @dev 预留存储空间,用于未来升级时添加新的状态变量
* 50个slot = 50 * 32 bytes = 1600 bytes
*/
uint256[50] private __gap;
}
}