Files

114 lines
3.6 KiB
Solidity
Raw Permalink Normal View History

2025-12-18 13:07:35 +08:00
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
/**
* @title YTLPToken
* @notice LP代币
* @dev MinterYTPoolManagerUUPS可升级合约
*/
contract YTLPToken is Initializable, ERC20Upgradeable, OwnableUpgradeable, UUPSUpgradeable {
2025-12-23 14:05:41 +08:00
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
2025-12-18 13:07:35 +08:00
error NotMinter();
error InvalidMinter();
2026-01-12 14:33:16 +08:00
error InvalidPoolManager();
2025-12-18 13:07:35 +08:00
mapping(address => bool) public isMinter;
2026-01-12 14:33:16 +08:00
address public poolManager;
2025-12-18 13:07:35 +08:00
event MinterSet(address indexed minter, bool isActive);
/**
* @notice
*/
function initialize() external initializer {
__ERC20_init("YT Liquidity Provider", "ytLP");
__Ownable_init(msg.sender);
__UUPSUpgradeable_init();
}
/**
* @notice owner可调用
* @param newImplementation
*/
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
modifier onlyMinter() {
if (!isMinter[msg.sender]) revert NotMinter();
_;
}
/**
* @notice
* @param _minter
* @param _isActive
*/
function setMinter(address _minter, bool _isActive) external onlyOwner {
if (_minter == address(0)) revert InvalidMinter();
isMinter[_minter] = _isActive;
emit MinterSet(_minter, _isActive);
}
2026-01-12 14:33:16 +08:00
/**
* @notice PoolManager
* @param _poolManager PoolManager
* @dev PoolManager
*/
function setPoolManager(address _poolManager) external onlyOwner {
if (_poolManager == address(0)) revert InvalidPoolManager();
poolManager = _poolManager;
}
2025-12-18 13:07:35 +08:00
/**
* @notice ytLP代币
* @param _to
* @param _amount
*/
function mint(address _to, uint256 _amount) external onlyMinter {
_mint(_to, _amount);
}
/**
* @notice ytLP代币
* @param _from
* @param _amount
*/
function burn(address _from, uint256 _amount) external onlyMinter {
_burn(_from, _amount);
}
2026-01-12 14:33:16 +08:00
/**
* @notice _update
* @dev LP
*/
function _update(address from, address to, uint256 value) internal override {
super._update(from, to, value);
// 只在实际转账时触发(不包括 mint 和 burn
if (from != address(0) && to != address(0) && poolManager != address(0)) {
// 通知 PoolManager 更新接收方的冷却时间
(bool success, ) = poolManager.call(
abi.encodeWithSignature("onLPTransfer(address,address)", from, to)
);
2026-01-19 11:56:15 +08:00
require(success, "Failed to call onLPTransfer");
2026-01-12 14:33:16 +08:00
}
}
2025-12-18 13:07:35 +08:00
/**
* @dev
* 50slot = 50 * 32 bytes = 1600 bytes
*/
uint256[50] private __gap;
}