-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLPToken.sol
71 lines (57 loc) · 3.13 KB
/
LPToken.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
pragma solidity ^0.8.13;
// SPDX-License-Identifier: MIT
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { ERC20PermitUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol";
import { ILPTokenInit } from "../interfaces/ILPTokenInit.sol";
import { ILiquidStakingManagerChildContract } from "../interfaces/ILiquidStakingManagerChildContract.sol";
import { ITransferHookProcessor } from "../interfaces/ITransferHookProcessor.sol";
contract LPToken is ILPTokenInit, ILiquidStakingManagerChildContract, Initializable, ERC20PermitUpgradeable {
/// @notice Contract deployer that can control minting and burning but is associated with a liquid staking manager
address public deployer;
/// @notice Optional hook for processing transfers
ITransferHookProcessor transferHookProcessor;
/// @notice Whenever the address last interacted with a token
mapping(address => uint256) public lastInteractedTimestamp;
modifier onlyDeployer {
require(msg.sender == deployer, "Only savETH vault");
_;
}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() initializer {}
/// @param _deployer Address of the account deploying the LP token
/// @param _transferHookProcessor Optional contract account that can be notified about transfer hooks
function init(
address _deployer,
address _transferHookProcessor,
string calldata _tokenSymbol,
string calldata _tokenName
) external override initializer {
deployer = _deployer;
transferHookProcessor = ITransferHookProcessor(_transferHookProcessor);
__ERC20_init(_tokenName, _tokenSymbol);
__ERC20Permit_init(_tokenName);
}
/// @notice Mints a given amount of LP tokens
/// @dev Only savETH vault can mint
function mint(address _recipient, uint256 _amount) external onlyDeployer {
_mint(_recipient, _amount);
}
/// @notice Allows a LP token owner to burn their tokens
function burn(address _recipient, uint256 _amount) external onlyDeployer {
_burn(_recipient, _amount);
}
/// @notice In order to know the liquid staking network and manager associated with the LP token, call this
function liquidStakingManager() external view returns (address) {
return ILiquidStakingManagerChildContract(deployer).liquidStakingManager();
}
/// @dev If set, notify the transfer hook processor before token transfer
function _beforeTokenTransfer(address _from, address _to, uint256 _amount) internal override {
if (address(transferHookProcessor) != address(0)) transferHookProcessor.beforeTokenTransfer(_from, _to, _amount);
}
/// @dev If set, notify the transfer hook processor after token transfer
function _afterTokenTransfer(address _from, address _to, uint256 _amount) internal override {
lastInteractedTimestamp[_from] = block.timestamp;
lastInteractedTimestamp[_to] = block.timestamp;
if (address(transferHookProcessor) != address(0)) transferHookProcessor.afterTokenTransfer(_from, _to, _amount);
}
}