-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBaseTOFT.sol
105 lines (91 loc) · 3.9 KB
/
BaseTOFT.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.22;
// External
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
// Tapioca
import {BaseTapiocaOmnichainEngine} from "tapioca-periph/tapiocaOmnichainEngine/BaseTapiocaOmnichainEngine.sol";
import {TOFTInitStruct, IToftVault} from "tapioca-periph/interfaces/oft/ITOFT.sol";
import {PearlmitHandler} from "tapioca-periph/pearlmit/PearlmitHandler.sol";
import {IYieldBox} from "tapioca-periph/interfaces/yieldbox/IYieldBox.sol";
import {ICluster} from "tapioca-periph/interfaces/periph/ICluster.sol";
import {BaseTOFTTokenMsgType} from "./BaseTOFTTokenMsgType.sol";
import {ModuleManager} from "./modules/ModuleManager.sol";
/*
████████╗ █████╗ ██████╗ ██╗ ██████╗ ██████╗ █████╗
╚══██╔══╝██╔══██╗██╔══██╗██║██╔═══██╗██╔════╝██╔══██╗
██║ ███████║██████╔╝██║██║ ██║██║ ███████║
██║ ██╔══██║██╔═══╝ ██║██║ ██║██║ ██╔══██║
██║ ██║ ██║██║ ██║╚██████╔╝╚██████╗██║ ██║
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝
*/
/**
* @title BaseTOFT
* @author TapiocaDAO
* @notice Base TOFT contract for LZ V2
*/
abstract contract BaseTOFT is
ModuleManager,
PearlmitHandler,
BaseTapiocaOmnichainEngine,
BaseTOFTTokenMsgType,
Pausable
{
using SafeERC20 for IERC20;
IYieldBox public immutable yieldBox;
IToftVault public immutable vault;
uint256 public immutable hostEid;
address public immutable erc20;
error TOFT_AllowanceNotValid();
error TOFT_NotValid();
error TOFT_VaultWrongERC20();
error TOFT_VaultWrongOwner();
constructor(TOFTInitStruct memory _data)
BaseTapiocaOmnichainEngine(
_data.name,
_data.symbol,
_data.endpoint,
_data.delegate,
_data.extExec,
_data.pearlmit,
ICluster(_data.cluster)
)
{
yieldBox = IYieldBox(_data.yieldBox);
hostEid = _data.hostEid;
erc20 = _data.erc20;
_transferOwnership(_data.delegate);
}
/**
* @notice Un/Pauses this contract.
*/
function setPause(bool _pauseState) external onlyOwner {
if (_pauseState) {
_pause();
} else {
_unpause();
}
}
function _wrap(address _fromAddress, address _toAddress, uint256 _amount, uint256 _feeAmount) internal virtual {
if (_fromAddress != msg.sender) {
if (allowance(_fromAddress, msg.sender) < _amount) {
revert TOFT_AllowanceNotValid();
}
_spendAllowance(_fromAddress, msg.sender, _amount);
}
if (_amount == 0) revert TOFT_NotValid();
// IERC20(erc20).safeTransferFrom(_fromAddress, address(vault), _amount);
bool isErr = pearlmit.transferFromERC20(_fromAddress, address(vault), erc20, _amount);
if (isErr) revert TOFT_NotValid();
_mint(_toAddress, _amount - _feeAmount);
}
function _wrapNative(address _toAddress, uint256 _amount, uint256 _feeAmount) internal virtual {
vault.depositNative{value: _amount - _feeAmount}();
_mint(_toAddress, _amount - _feeAmount);
}
function _unwrap(address _toAddress, uint256 _amount) internal virtual {
_burn(msg.sender, _amount);
vault.withdraw(_toAddress, _amount);
}
}