-
Notifications
You must be signed in to change notification settings - Fork 0
/
NFTXVaultFactoryUpgradeable.sol
83 lines (73 loc) · 3.05 KB
/
NFTXVaultFactoryUpgradeable.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
// SPDX-License-Identifier: MIT
pragma solidity 0.6.8;
import "./interface/INFTXVaultFactory.sol";
import "./interface/INFTXLPStaking.sol";
import "./interface/INFTXFeeDistributor.sol";
import "./proxy/ClonesUpgradeable.sol";
import "./proxy/BeaconProxy.sol";
import "./proxy/UpgradeableBeacon.sol";
import "./util/PausableUpgradeable.sol";
import "./NFTXVaultUpgradeable.sol";
// TODO Look through all dependencies.
contract NFTXVaultFactoryUpgradeable is
PausableUpgradeable,
UpgradeableBeacon,
INFTXVaultFactory
{
uint256 public override numVaults;
address public override prevContract;
address public override feeReceiver;
address public override eligibilityManager;
mapping(uint256 => address) public override vault;
mapping(address => address[]) public vaultsForAsset;
address[] public allVaults;
event NewFeeReceiver(address oldReceiver, address newReceiver);
event NewVault(uint256 indexed vaultId, address vaultAddress, address assetAddress);
function __NFTXVaultFactory_init(address _vaultImpl, address _prevContract, address _feeReceiver) public override initializer {
__Pausable_init();
// We use a beacon proxy so that every contract follows the same implementation code.
__UpgradeableBeacon__init(_vaultImpl);
prevContract = _prevContract;
feeReceiver = _feeReceiver;
}
function createVault(
string memory name,
string memory symbol,
address _assetAddress,
bool is1155,
bool allowAllItems
) public virtual override returns (uint256) {
onlyOwnerIfPaused(0);
require(feeReceiver != address(0), "NFTX: Fee receiver unset");
require(implementation() != address(0), "NFTX: Vault implementation unset");
address vaultAddr = deployVault(name, symbol, _assetAddress, is1155, allowAllItems);
uint256 _vaultId = numVaults;
vault[_vaultId] = vaultAddr;
vaultsForAsset[_assetAddress].push(vaultAddr);
allVaults.push(vaultAddr);
numVaults += 1;
INFTXFeeDistributor(feeReceiver).initializeVaultReceivers(_vaultId);
emit NewVault(_vaultId, vaultAddr, _assetAddress);
return _vaultId;
}
function setFeeReceiver(address _feeReceiver) public onlyOwner virtual override {
require(_feeReceiver != address(0));
emit NewFeeReceiver(feeReceiver, _feeReceiver);
feeReceiver = _feeReceiver;
}
function deployVault(
string memory name,
string memory symbol,
address _assetAddress,
bool is1155,
bool allowAllItems
) internal returns (address) {
address newBeaconProxy = address(new BeaconProxy(address(this), ""));
NFTXVaultUpgradeable(newBeaconProxy).__NFTXVault_init(name, symbol, _assetAddress, is1155, allowAllItems);
// Manager for configuration.
NFTXVaultUpgradeable(newBeaconProxy).setManager(msg.sender);
// Owner for administrative functions.
NFTXVaultUpgradeable(newBeaconProxy).transferOwnership(owner());
return newBeaconProxy;
}
}