-
Notifications
You must be signed in to change notification settings - Fork 2
/
ServiceManager.sol
111 lines (100 loc) · 4.61 KB
/
ServiceManager.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
106
107
108
109
110
111
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "./GenericManager.sol";
import "./interfaces/IService.sol";
/// @title Service Manager - Periphery smart contract for managing services
/// @author Aleksandr Kuperman - <[email protected]>
contract ServiceManager is GenericManager {
event CreateMultisig(address indexed multisig);
// Service registry address
address public immutable serviceRegistry;
constructor(address _serviceRegistry) {
serviceRegistry = _serviceRegistry;
owner = msg.sender;
}
/// @dev Creates a new service.
/// @param serviceOwner Individual that creates and controls a service.
/// @param configHash IPFS hash pointing to the config metadata.
/// @param agentIds Canonical agent Ids.
/// @param agentParams Number of agent instances and required bond to register an instance in the service.
/// @param threshold Threshold for a multisig composed by agents.
function create(
address serviceOwner,
bytes32 configHash,
uint32[] memory agentIds,
IService.AgentParams[] memory agentParams,
uint32 threshold
) external returns (uint256)
{
// Check if the minting is paused
if (paused) {
revert Paused();
}
return IService(serviceRegistry).create(serviceOwner, configHash, agentIds, agentParams,
threshold);
}
/// @dev Updates a service in a CRUD way.
/// @param configHash IPFS hash pointing to the config metadata.
/// @param agentIds Canonical agent Ids.
/// @param agentParams Number of agent instances and required bond to register an instance in the service.
/// @param threshold Threshold for a multisig composed by agents.
/// @param serviceId Service Id to be updated.
/// @return success True, if function executed successfully.
function update(
bytes32 configHash,
uint32[] memory agentIds,
IService.AgentParams[] memory agentParams,
uint32 threshold,
uint256 serviceId
) external returns (bool)
{
return IService(serviceRegistry).update(msg.sender, configHash, agentIds, agentParams,
threshold, serviceId);
}
/// @dev Activates the service and its sensitive components.
/// @param serviceId Correspondent service Id.
/// @return success True, if function executed successfully.
function activateRegistration(uint256 serviceId) external payable returns (bool success) {
success = IService(serviceRegistry).activateRegistration{value: msg.value}(msg.sender, serviceId);
}
/// @dev Registers agent instances.
/// @param serviceId Service Id to be updated.
/// @param agentInstances Agent instance addresses.
/// @param agentIds Canonical Ids of the agent correspondent to the agent instance.
/// @return success True, if function executed successfully.
function registerAgents(
uint256 serviceId,
address[] memory agentInstances,
uint32[] memory agentIds
) external payable returns (bool success) {
success = IService(serviceRegistry).registerAgents{value: msg.value}(msg.sender, serviceId, agentInstances, agentIds);
}
/// @dev Creates multisig instance controlled by the set of service agent instances and deploys the service.
/// @param serviceId Correspondent service Id.
/// @param multisigImplementation Multisig implementation address.
/// @param data Data payload for the multisig creation.
/// @return multisig Address of the created multisig.
function deploy(
uint256 serviceId,
address multisigImplementation,
bytes memory data
) external returns (address multisig)
{
multisig = IService(serviceRegistry).deploy(msg.sender, serviceId, multisigImplementation, data);
emit CreateMultisig(multisig);
}
/// @dev Terminates the service.
/// @param serviceId Service Id.
/// @return success True, if function executed successfully.
/// @return refund Refund for the service owner.
function terminate(uint256 serviceId) external returns (bool success, uint256 refund) {
(success, refund) = IService(serviceRegistry).terminate(msg.sender, serviceId);
}
/// @dev Unbonds agent instances of the operator from the service.
/// @param serviceId Service Id.
/// @return success True, if function executed successfully.
/// @return refund The amount of refund returned to the operator.
function unbond(uint256 serviceId) external returns (bool success, uint256 refund) {
(success, refund) = IService(serviceRegistry).unbond(msg.sender, serviceId);
}
}