Fix & Optimize contract
This commit is contained in:
@@ -18,6 +18,11 @@ import "../../interfaces/IUSDY.sol";
|
||||
contract YTPoolManager is Initializable, UUPSUpgradeable, ReentrancyGuardUpgradeable {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor() {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
error Forbidden();
|
||||
error InvalidAddress();
|
||||
error InvalidDuration();
|
||||
@@ -64,6 +69,8 @@ contract YTPoolManager is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrade
|
||||
);
|
||||
event CooldownDurationSet(uint256 duration);
|
||||
event HandlerSet(address indexed handler, bool isActive);
|
||||
event GovChanged(address indexed oldGov, address indexed newGov);
|
||||
event AumAdjustmentChanged(uint256 addition, uint256 deduction);
|
||||
|
||||
modifier onlyGov() {
|
||||
if (msg.sender != gov) revert Forbidden();
|
||||
@@ -109,7 +116,9 @@ contract YTPoolManager is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrade
|
||||
|
||||
function setGov(address _gov) external onlyGov {
|
||||
if (_gov == address(0)) revert InvalidAddress();
|
||||
address oldGov = gov;
|
||||
gov = _gov;
|
||||
emit GovChanged(oldGov, _gov);
|
||||
}
|
||||
|
||||
function setHandler(address _handler, bool _isActive) external onlyGov {
|
||||
@@ -126,6 +135,7 @@ contract YTPoolManager is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrade
|
||||
function setAumAdjustment(uint256 _addition, uint256 _deduction) external onlyGov {
|
||||
aumAddition = _addition;
|
||||
aumDeduction = _deduction;
|
||||
emit AumAdjustmentChanged(_addition, _deduction);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,11 @@ import "../../interfaces/IYTToken.sol";
|
||||
*/
|
||||
contract YTPriceFeed is Initializable, UUPSUpgradeable {
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor() {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
error Forbidden();
|
||||
error MaxChangeTooHigh();
|
||||
error PriceChangeTooLarge();
|
||||
|
||||
@@ -18,6 +18,11 @@ import "../../interfaces/IYTVault.sol";
|
||||
contract YTRewardRouter is Initializable, UUPSUpgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor() {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
error Forbidden();
|
||||
error AlreadyInitialized();
|
||||
error InvalidAddress();
|
||||
|
||||
@@ -17,6 +17,11 @@ import "../../interfaces/IYTPriceFeed.sol";
|
||||
contract YTVault is Initializable, UUPSUpgradeable, ReentrancyGuardUpgradeable {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor() {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
error Forbidden();
|
||||
error OnlyPoolManager();
|
||||
error NotSwapper();
|
||||
@@ -101,6 +106,8 @@ contract YTVault is Initializable, UUPSUpgradeable, ReentrancyGuardUpgradeable {
|
||||
);
|
||||
event EmergencyModeSet(bool enabled);
|
||||
event SwapEnabledSet(bool enabled);
|
||||
event GovChanged(address indexed oldGov, address indexed newGov);
|
||||
event PoolManagerChanged(address indexed oldManager, address indexed newManager);
|
||||
|
||||
modifier onlyGov() {
|
||||
if (msg.sender != gov) revert Forbidden();
|
||||
@@ -159,12 +166,16 @@ contract YTVault is Initializable, UUPSUpgradeable, ReentrancyGuardUpgradeable {
|
||||
|
||||
function setGov(address _gov) external onlyGov {
|
||||
if (_gov == address(0)) revert InvalidAddress();
|
||||
address oldGov = gov;
|
||||
gov = _gov;
|
||||
emit GovChanged(oldGov, _gov);
|
||||
}
|
||||
|
||||
function setPoolManager(address _manager) external onlyGov {
|
||||
if (_manager == address(0)) revert InvalidAddress();
|
||||
address oldManager = ytPoolManager;
|
||||
ytPoolManager = _manager;
|
||||
emit PoolManagerChanged(oldManager, _manager);
|
||||
}
|
||||
|
||||
function setSwapper(address _swapper, bool _isActive) external onlyGov {
|
||||
@@ -545,11 +556,12 @@ contract YTVault is Initializable, UUPSUpgradeable, ReentrancyGuardUpgradeable {
|
||||
}
|
||||
|
||||
// 恶化平衡 → 提高手续费
|
||||
uint256 averageDiff = (initialDiff + nextDiff) / 2;
|
||||
if (averageDiff > targetAmount) {
|
||||
averageDiff = targetAmount;
|
||||
// taxBps = tax * (a + b) / (2 * target)
|
||||
uint256 sumDiff = initialDiff + nextDiff;
|
||||
if (sumDiff / 2 > targetAmount) {
|
||||
sumDiff = targetAmount * 2;
|
||||
}
|
||||
uint256 taxBps = _taxBasisPoints * averageDiff / targetAmount;
|
||||
uint256 taxBps = _taxBasisPoints * sumDiff / (targetAmount * 2);
|
||||
return _feeBasisPoints + taxBps;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
||||
*/
|
||||
contract USDY is Initializable, ERC20Upgradeable, OwnableUpgradeable, UUPSUpgradeable {
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor() {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
error Forbidden();
|
||||
error InvalidVault();
|
||||
|
||||
|
||||
@@ -12,6 +12,11 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||
*/
|
||||
contract WUSD is Initializable, ERC20Upgradeable, UUPSUpgradeable, OwnableUpgradeable {
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor() {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice 初始化合约
|
||||
* @param _name 代币名称
|
||||
|
||||
@@ -13,6 +13,11 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
||||
*/
|
||||
contract YTLPToken is Initializable, ERC20Upgradeable, OwnableUpgradeable, UUPSUpgradeable {
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor() {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
error NotMinter();
|
||||
error InvalidMinter();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user