-
Notifications
You must be signed in to change notification settings - Fork 20
/
Manager.sol
55 lines (45 loc) · 1.77 KB
/
Manager.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {IManager} from "./IManager.sol";
/// @title Correct implementation of `IManager`
contract Manager is IManager {
// Maps a fundId to the fund's data
mapping (uint256 => ManagedFund) public funds;
// A flag indicating if an address is a current manager of some fund
mapping (address => bool) private _isActiveManager;
/// @inheritdoc IManager
function isActiveManager(address manager) public view returns (bool) {
return _isActiveManager[manager];
}
/// @inheritdoc IManager
function createFund(uint256 fundId) public {
require(msg.sender != address(0));
require(funds[fundId].currentManager == address(0));
require(!isActiveManager(msg.sender));
funds[fundId].currentManager = msg.sender;
_isActiveManager[msg.sender] = true;
}
/// @inheritdoc IManager
function setPendingManager(uint256 fundId, address pending) public {
require(funds[fundId].currentManager == msg.sender);
funds[fundId].pendingManager = pending;
}
/// @inheritdoc IManager
function claimManagement(uint256 fundId) public {
require(msg.sender != address(0) && funds[fundId].currentManager != address(0));
require(funds[fundId].pendingManager == msg.sender);
require(!isActiveManager(msg.sender));
_isActiveManager[funds[fundId].currentManager] = false;
funds[fundId].currentManager = msg.sender;
funds[fundId].pendingManager = address(0);
_isActiveManager[msg.sender] = true;
}
/// @inheritdoc IManager
function getCurrentManager(uint256 fundId) public view returns (address) {
return funds[fundId].currentManager;
}
/// @inheritdoc IManager
function getPendingManager(uint256 fundId) public view returns (address) {
return funds[fundId].pendingManager;
}
}