@etherisc/gif-next 0.0.2-d288ca9-933 → 0.0.2-d3207d2-901
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -0
- package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +13 -0
- package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
- package/artifacts/contracts/components/Distribution.sol/Distribution.json +23 -15
- package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +13 -0
- package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +21 -13
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +39 -18
- package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
- package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
- package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +2 -2
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +2 -2
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
- package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +1 -1
- package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.json +0 -13
- package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +1 -1
- package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +403 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +59 -0
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +129 -101
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +34 -47
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +143 -38
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +200 -33
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +71 -15
- package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +59 -0
- package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +2 -2
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +2 -2
- package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
- package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
- package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +18 -18
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +716 -0
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +4 -0
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +444 -0
- package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +4 -0
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +839 -0
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +448 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +182 -0
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -19
- package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +145 -49
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +61 -29
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +43 -34
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +4 -0
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +410 -0
- package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
- package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/contracts/shared/ERC165.sol/ERC165.json +2 -2
- package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/shared/IService.sol/IService.dbg.json +4 -0
- package/artifacts/contracts/{instance/base → shared}/IService.sol/IService.json +1 -1
- package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
- package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
- package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
- package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
- package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/shared/Registerable.sol/Registerable.json +4 -4
- package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +4 -0
- package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.json +442 -0
- package/artifacts/contracts/shared/Service.sol/Service.dbg.json +4 -0
- package/artifacts/contracts/{instance/base/ServiceBase.sol/ServiceBase.json → shared/Service.sol/Service.json} +2 -2
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
- package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
- package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
- package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
- package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +4 -4
- package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
- package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
- package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.json +11 -11
- package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
- package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
- package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
- package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
- package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
- package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
- package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
- package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionPartLib.json +22 -3
- package/contracts/components/BaseComponent.sol +8 -3
- package/contracts/components/Distribution.sol +10 -16
- package/contracts/components/IBaseComponent.sol +1 -0
- package/contracts/components/IDistributionComponent.sol +1 -0
- package/contracts/components/Pool.sol +4 -20
- package/contracts/components/Product.sol +1 -1
- package/contracts/instance/AccessManagedSimple.sol +1 -8
- package/contracts/instance/IInstance.sol +15 -4
- package/contracts/instance/IInstanceService.sol +21 -8
- package/contracts/instance/Instance.sol +19 -18
- package/contracts/instance/InstanceAccessManager.sol +1 -1
- package/contracts/instance/InstanceReader.sol +17 -1
- package/contracts/instance/InstanceService.sol +61 -14
- package/contracts/instance/InstanceServiceManager.sol +6 -5
- package/contracts/instance/base/ComponentServiceBase.sol +83 -8
- package/contracts/instance/module/IBundle.sol +1 -0
- package/contracts/instance/module/ISetup.sol +1 -0
- package/contracts/instance/service/ComponentOwnerService.sol +5 -5
- package/contracts/instance/service/DistributionService.sol +88 -0
- package/contracts/instance/service/DistributionServiceManager.sol +54 -0
- package/contracts/instance/service/IComponentOwnerService.sol +1 -1
- package/contracts/instance/service/IDistributionService.sol +1 -1
- package/contracts/instance/service/IPoolService.sol +1 -1
- package/contracts/instance/service/IProductService.sol +1 -1
- package/contracts/instance/service/PoolService.sol +194 -0
- package/contracts/instance/service/PoolServiceManager.sol +54 -0
- package/contracts/registry/IRegistry.sol +24 -2
- package/contracts/registry/IRegistryService.sol +34 -19
- package/contracts/registry/Registry.sol +57 -36
- package/contracts/registry/RegistryService.sol +42 -123
- package/contracts/registry/RegistryServiceManager.sol +21 -5
- package/contracts/registry/TokenRegistry.sol +111 -0
- package/contracts/shared/ERC165.sol +6 -2
- package/contracts/{instance/base → shared}/IService.sol +3 -3
- package/contracts/shared/NftOwnable.sol +2 -4
- package/contracts/shared/Registerable.sol +1 -0
- package/contracts/shared/RegisterableUpgradable.sol +16 -0
- package/contracts/shared/Service.sol +55 -0
- package/contracts/test/TestService.sol +3 -5
- package/contracts/types/RoleId.sol +7 -0
- package/contracts/types/StateId.sol +4 -0
- package/contracts/types/Version.sol +4 -1
- package/package.json +1 -1
- package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +0 -4
- package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +0 -4
- package/contracts/instance/base/ServiceBase.sol +0 -44
@@ -8,16 +8,18 @@ import {InstanceAccessManager} from "./InstanceAccessManager.sol";
|
|
8
8
|
import {Instance} from "./Instance.sol";
|
9
9
|
import {IInstanceService} from "./IInstanceService.sol";
|
10
10
|
import {InstanceReader} from "./InstanceReader.sol";
|
11
|
-
import {ServiceBase} from "../../contracts/instance/base/ServiceBase.sol";
|
12
11
|
import {IRegistry} from "../registry/IRegistry.sol";
|
13
12
|
import {Registry} from "../registry/Registry.sol";
|
14
13
|
import {RegistryService} from "../registry/RegistryService.sol";
|
15
|
-
import {
|
14
|
+
import {Service} from "../../contracts/shared/Service.sol";
|
15
|
+
import {IService} from "../shared/IService.sol";
|
16
16
|
import {ContractDeployerLib} from "../shared/ContractDeployerLib.sol";
|
17
17
|
import {NftId, NftIdLib, zeroNftId} from "../../contracts/types/NftId.sol";
|
18
|
+
import {RoleId} from "../types/RoleId.sol";
|
18
19
|
import {VersionLib} from "../types/Version.sol";
|
20
|
+
import {ADMIN_ROLE, INSTANCE_SERVICE_ROLE, DISTRIBUTION_SERVICE_ROLE, POOL_SERVICE_ROLE} from "../types/RoleId.sol";
|
19
21
|
|
20
|
-
contract InstanceService is
|
22
|
+
contract InstanceService is Service, IInstanceService {
|
21
23
|
|
22
24
|
address internal _registryAddress;
|
23
25
|
address internal _accessManagerMaster;
|
@@ -37,21 +39,61 @@ contract InstanceService is ServiceBase, IInstanceService {
|
|
37
39
|
InstanceReader clonedInstanceReader
|
38
40
|
)
|
39
41
|
{
|
42
|
+
address instanceOwner = msg.sender;
|
40
43
|
Registry registry = Registry(_registryAddress);
|
41
44
|
NftId registryNftId = registry.getNftId(_registryAddress);
|
42
45
|
address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
|
43
46
|
RegistryService registryService = RegistryService(registryServiceAddress);
|
44
47
|
|
48
|
+
// initially set the authority of the access managar to this (being the instance service).
|
49
|
+
// This will allow the instance service to bootstrap the authorizations of the instance
|
50
|
+
// and then transfer the ownership of the access manager to the instance owner once everything is setup
|
45
51
|
clonedAccessManager = AccessManagerSimple(Clones.clone(_accessManagerMaster));
|
46
|
-
clonedAccessManager.initialize(
|
52
|
+
clonedAccessManager.initialize(address(this));
|
47
53
|
|
48
54
|
clonedInstance = Instance(Clones.clone(_instanceMaster));
|
49
|
-
clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId);
|
55
|
+
clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId, msg.sender);
|
50
56
|
( IRegistry.ObjectInfo memory info, ) = registryService.registerInstance(clonedInstance);
|
51
57
|
instanceNftId = info.nftId;
|
52
58
|
|
53
59
|
clonedInstanceReader = InstanceReader(Clones.clone(address(_instanceReaderMaster)));
|
54
60
|
clonedInstanceReader.initialize(_registryAddress, instanceNftId);
|
61
|
+
|
62
|
+
_grantInitialAuthorizations(clonedAccessManager, clonedInstance);
|
63
|
+
|
64
|
+
clonedInstance.setInstanceReader(clonedInstanceReader);
|
65
|
+
|
66
|
+
// to complete setup switch instance ownership to the instance owner
|
67
|
+
// TODO: use a role less powerful than admin, maybe INSTANCE_ADMIN (does not exist yet)
|
68
|
+
clonedAccessManager.grantRole(ADMIN_ROLE().toInt(), instanceOwner, 0);
|
69
|
+
clonedAccessManager.revokeRole(ADMIN_ROLE().toInt(), address(this));
|
70
|
+
|
71
|
+
emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), instanceNftId);
|
72
|
+
}
|
73
|
+
|
74
|
+
function _grantInitialAuthorizations(AccessManagerSimple clonedAccessManager, Instance clonedInstance) internal {
|
75
|
+
address distributionServiceAddress = _registry.getServiceAddress("DistributionService", VersionLib.toVersion(3, 0, 0).toMajorPart());
|
76
|
+
clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE().toInt(), distributionServiceAddress, 0);
|
77
|
+
bytes4[] memory instanceDistributionServiceSelectors = new bytes4[](2);
|
78
|
+
instanceDistributionServiceSelectors[0] = clonedInstance.createDistributionSetup.selector;
|
79
|
+
instanceDistributionServiceSelectors[1] = clonedInstance.updateDistributionSetup.selector;
|
80
|
+
clonedAccessManager.setTargetFunctionRole(
|
81
|
+
address(clonedInstance),
|
82
|
+
instanceDistributionServiceSelectors,
|
83
|
+
DISTRIBUTION_SERVICE_ROLE().toInt());
|
84
|
+
|
85
|
+
address poolServiceAddress = _registry.getServiceAddress("PoolService", VersionLib.toVersion(3, 0, 0).toMajorPart());
|
86
|
+
clonedAccessManager.grantRole(POOL_SERVICE_ROLE().toInt(), address(poolServiceAddress), 0);
|
87
|
+
bytes4[] memory instancePoolServiceSelectors = new bytes4[](4);
|
88
|
+
instancePoolServiceSelectors[0] = clonedInstance.createPoolSetup.selector;
|
89
|
+
instancePoolServiceSelectors[1] = clonedInstance.updatePoolSetup.selector;
|
90
|
+
instancePoolServiceSelectors[2] = clonedInstance.createBundle.selector;
|
91
|
+
instancePoolServiceSelectors[3] = clonedInstance.updateBundle.selector;
|
92
|
+
clonedAccessManager.setTargetFunctionRole(
|
93
|
+
address(clonedInstance),
|
94
|
+
instancePoolServiceSelectors,
|
95
|
+
POOL_SERVICE_ROLE().toInt());
|
96
|
+
|
55
97
|
}
|
56
98
|
|
57
99
|
function setAccessManagerMaster(address accessManagerMaster) external {
|
@@ -88,7 +130,7 @@ contract InstanceService is ServiceBase, IInstanceService {
|
|
88
130
|
}
|
89
131
|
|
90
132
|
// From IService
|
91
|
-
function getName() public pure override(IService,
|
133
|
+
function getName() public pure override(IService, Service) returns(string memory) {
|
92
134
|
return NAME;
|
93
135
|
}
|
94
136
|
|
@@ -118,19 +160,24 @@ contract InstanceService is ServiceBase, IInstanceService {
|
|
118
160
|
|
119
161
|
address initialOwner = address(0);
|
120
162
|
(_registryAddress, initialOwner) = abi.decode(data, (address, address));
|
121
|
-
|
122
|
-
//
|
123
|
-
|
124
|
-
NftId registryNftId = registry.getNftId(_registryAddress);
|
125
|
-
|
126
|
-
_initializeServiceBase(_registryAddress, registryNftId, initialOwner);
|
163
|
+
// TODO while InstanceService is not deployed in InstanceServiceManager constructor
|
164
|
+
// owner is InstanceServiceManager deployer
|
165
|
+
_initializeService(_registryAddress, owner);
|
127
166
|
|
128
167
|
_registerInterface(type(IService).interfaceId);
|
129
168
|
_registerInterface(type(IInstanceService).interfaceId);
|
130
169
|
}
|
131
170
|
|
132
|
-
function
|
133
|
-
|
171
|
+
function hasRole(address account, RoleId role, NftId instanceNftId) external view returns (bool) {
|
172
|
+
IRegistry.ObjectInfo memory instanceObjectInfo = getRegistry().getObjectInfo(instanceNftId);
|
173
|
+
address instanceAddress = instanceObjectInfo.objectAddress;
|
174
|
+
Instance instance = Instance(instanceAddress);
|
175
|
+
AccessManagerSimple accessManager = AccessManagerSimple(instance.authority());
|
176
|
+
(bool isMember, uint32 executionDelay) = accessManager.hasRole(role.toInt(), account);
|
177
|
+
if (executionDelay > 0) {
|
178
|
+
return false;
|
179
|
+
}
|
180
|
+
return isMember;
|
134
181
|
}
|
135
182
|
}
|
136
183
|
|
@@ -31,14 +31,15 @@ contract InstanceServiceManager is ProxyManager {
|
|
31
31
|
Registry registry = Registry(registryAddress);
|
32
32
|
address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
|
33
33
|
RegistryService registryService = RegistryService(registryServiceAddress);
|
34
|
-
|
35
|
-
registryService.registerService(_instanceService);
|
34
|
+
// TODO this must have a role or own nft to register service
|
35
|
+
//registryService.registerService(_instanceService);
|
36
36
|
// RegistryService registryService = _instanceService.getRegistryService();
|
37
37
|
|
38
|
+
// TODO no nft to link yet
|
38
39
|
// link ownership of instance service manager ot nft owner of instance service
|
39
|
-
_linkToNftOwnable(
|
40
|
-
|
41
|
-
|
40
|
+
//_linkToNftOwnable(
|
41
|
+
// address(registryAddress),
|
42
|
+
// address(_instanceService));
|
42
43
|
|
43
44
|
// implies that after this constructor call only upgrade functionality is available
|
44
45
|
_isDeployed = true;
|
@@ -4,23 +4,98 @@ pragma solidity ^0.8.19;
|
|
4
4
|
import {IRegistry} from "../../registry/IRegistry.sol";
|
5
5
|
import {IRegistryService} from "../../registry/IRegistryService.sol";
|
6
6
|
import {IInstance} from "../../instance/IInstance.sol";
|
7
|
-
import {ObjectType, INSTANCE, PRODUCT, POOL} from "../../types/ObjectType.sol";
|
7
|
+
import {ObjectType, INSTANCE, PRODUCT, POOL, DISTRIBUTION, ORACLE} from "../../types/ObjectType.sol";
|
8
8
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
9
|
+
import {RoleId, PRODUCT_OWNER_ROLE, POOL_OWNER_ROLE, DISTRIBUTION_OWNER_ROLE, ORACLE_OWNER_ROLE} from "../../types/RoleId.sol";
|
9
10
|
|
10
|
-
import {
|
11
|
+
import {BaseComponent} from "../../components/BaseComponent.sol";
|
12
|
+
import {INftOwnable} from "../../shared/INftOwnable.sol";
|
13
|
+
import {Service} from "../../shared/Service.sol";
|
14
|
+
import {InstanceService} from "../InstanceService.sol";
|
11
15
|
import {Version, VersionPart, VersionLib} from "../../types/Version.sol";
|
12
16
|
|
13
|
-
abstract contract ComponentServiceBase is
|
17
|
+
abstract contract ComponentServiceBase is Service {
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
error ExpectedRoleMissing(RoleId expected, address caller);
|
20
|
+
error ComponentTypeInvalid(ObjectType componentType);
|
21
|
+
|
22
|
+
mapping (ObjectType => RoleId) internal _objectTypeToExpectedRole;
|
23
|
+
|
24
|
+
/// @dev modifier to check if caller has a role on the instance the component is registered in
|
25
|
+
modifier onlyComponentOwnerRole(address componentAddress) {
|
26
|
+
BaseComponent component = BaseComponent(componentAddress);
|
27
|
+
ObjectType objectType = _getObjectType(component);
|
28
|
+
RoleId expectedRole = _objectTypeToExpectedRole[objectType];
|
29
|
+
|
30
|
+
address componentOwner = msg.sender;
|
31
|
+
INftOwnable nftOwnable = INftOwnable(address(component.getInstance()));
|
32
|
+
if(! getInstanceService().hasRole(componentOwner, expectedRole, nftOwnable.getNftId())) {
|
33
|
+
revert ExpectedRoleMissing(expectedRole, componentOwner);
|
34
|
+
}
|
35
|
+
_;
|
36
|
+
}
|
37
|
+
|
38
|
+
function _initializeService(
|
39
|
+
address registry,
|
18
40
|
address initialOwner
|
19
41
|
)
|
42
|
+
internal
|
43
|
+
override
|
20
44
|
{
|
21
|
-
|
45
|
+
super._initializeService(registry, initialOwner);
|
46
|
+
_objectTypeToExpectedRole[PRODUCT()] = PRODUCT_OWNER_ROLE();
|
47
|
+
_objectTypeToExpectedRole[POOL()] = POOL_OWNER_ROLE();
|
48
|
+
_objectTypeToExpectedRole[DISTRIBUTION()] = DISTRIBUTION_OWNER_ROLE();
|
49
|
+
_objectTypeToExpectedRole[ORACLE()] = ORACLE_OWNER_ROLE();
|
50
|
+
}
|
51
|
+
|
52
|
+
function getInstanceService() public view returns (InstanceService) {
|
53
|
+
return InstanceService(getRegistry().getServiceAddress("InstanceService", getMajorVersion()));
|
22
54
|
}
|
23
55
|
|
56
|
+
function register(address componentAddress)
|
57
|
+
external
|
58
|
+
onlyComponentOwnerRole(componentAddress)
|
59
|
+
returns (NftId componentNftId)
|
60
|
+
{
|
61
|
+
address componentOwner = msg.sender;
|
62
|
+
BaseComponent component = BaseComponent(componentAddress);
|
63
|
+
ObjectType objectType = _getObjectType(component);
|
64
|
+
IRegistryService registryService = getRegistryService();
|
65
|
+
|
66
|
+
IRegistry.ObjectInfo memory objInfo;
|
67
|
+
bytes memory initialObjData;
|
68
|
+
|
69
|
+
if (objectType == DISTRIBUTION()) {
|
70
|
+
(objInfo, initialObjData) = registryService.registerDistribution(component, componentOwner);
|
71
|
+
} else if (objectType == PRODUCT()) {
|
72
|
+
(objInfo, initialObjData) = registryService.registerProduct(component, componentOwner);
|
73
|
+
} else if (objectType == POOL()) {
|
74
|
+
(objInfo, initialObjData) = registryService.registerPool(component, componentOwner);
|
75
|
+
// TODO: implement this for oracle - currently missing in registry
|
76
|
+
// } else if (objectType == ORACLE()) {
|
77
|
+
// (objInfo, initialObjData) = registryService.registerOracle(component, componentOwner);
|
78
|
+
} else {
|
79
|
+
revert ComponentTypeInvalid(objectType);
|
80
|
+
}
|
81
|
+
|
82
|
+
componentNftId = objInfo.nftId;
|
83
|
+
IInstance instance = _getInstance(objInfo);
|
84
|
+
_finalizeComponentRegistration(componentNftId, initialObjData, instance);
|
85
|
+
}
|
86
|
+
|
87
|
+
function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal virtual;
|
88
|
+
|
89
|
+
function _getObjectType(BaseComponent component) internal view returns (ObjectType) {
|
90
|
+
(IRegistry.ObjectInfo memory compInitialInfo, ) = component.getInitialInfo();
|
91
|
+
return compInitialInfo.objectType;
|
92
|
+
}
|
93
|
+
|
94
|
+
function _getInstance(IRegistry.ObjectInfo memory compObjInfo) internal view returns (IInstance) {
|
95
|
+
IRegistry registry = getRegistry();
|
96
|
+
IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(compObjInfo.parentNftId);
|
97
|
+
return IInstance(instanceInfo.objectAddress);
|
98
|
+
}
|
24
99
|
|
25
100
|
function _getAndVerifyComponentInfoAndInstance(
|
26
101
|
ObjectType objectType
|
@@ -32,7 +107,7 @@ abstract contract ComponentServiceBase is ServiceBase {
|
|
32
107
|
IInstance instance
|
33
108
|
)
|
34
109
|
{
|
35
|
-
NftId componentNftId =
|
110
|
+
NftId componentNftId = _registry.getNftId(msg.sender);
|
36
111
|
require(componentNftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
37
112
|
|
38
113
|
info = getRegistry().getObjectInfo(componentNftId);
|
@@ -13,6 +13,7 @@ interface IBundle {
|
|
13
13
|
uint256 capitalAmount; // net investment capital + net premiums - payouts
|
14
14
|
uint256 lockedAmount; // capital amount linked to collateralizaion of non-closed policies (<= balance)
|
15
15
|
uint256 balanceAmount; // total amount of funds: capitalAmount + fees (balance >= captial)
|
16
|
+
uint256 lifetime;
|
16
17
|
Timestamp expiredAt; // no new policies
|
17
18
|
Timestamp closedAt; // no open policies, locked amount = 0
|
18
19
|
}
|
@@ -5,6 +5,7 @@ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IER
|
|
5
5
|
|
6
6
|
import {Fee} from "../../types/Fee.sol";
|
7
7
|
import {NftId} from "../../types/NftId.sol";
|
8
|
+
import {LibNftIdSet} from "../../types/NftIdSet.sol";
|
8
9
|
import {UFixed} from "../../types/UFixed.sol";
|
9
10
|
import {TokenHandler} from "../../shared/TokenHandler.sol";
|
10
11
|
|
@@ -27,15 +27,15 @@ import {UFixed, UFixedLib} from "../../types/UFixed.sol";
|
|
27
27
|
import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
|
28
28
|
import {IPoolComponent} from "../../components/IPoolComponent.sol";
|
29
29
|
import {IProductComponent} from "../../components/IProductComponent.sol";
|
30
|
-
import {IService} from "
|
30
|
+
import {IService} from "../../shared/IService.sol";
|
31
31
|
import {IComponentOwnerService} from "./IComponentOwnerService.sol";
|
32
|
-
import {
|
32
|
+
import {Service} from "../../shared/Service.sol";
|
33
33
|
// import {IPool, IPoolModule} from "../module/IPoolModule.sol";
|
34
34
|
|
35
35
|
import {IRegistryService} from "../../registry/IRegistryService.sol";
|
36
36
|
|
37
37
|
contract ComponentOwnerService is
|
38
|
-
|
38
|
+
Service,
|
39
39
|
IComponentOwnerService
|
40
40
|
{
|
41
41
|
using NftIdLib for NftId;
|
@@ -64,11 +64,11 @@ contract ComponentOwnerService is
|
|
64
64
|
address initialOwner
|
65
65
|
)
|
66
66
|
{
|
67
|
-
|
67
|
+
_initializeService(registry, initialOwner);
|
68
68
|
_registerInterface(type(IComponentOwnerService).interfaceId);
|
69
69
|
}
|
70
70
|
|
71
|
-
function getName() public pure override(IService,
|
71
|
+
function getName() public pure override(IService, Service) returns(string memory name) {
|
72
72
|
return NAME;
|
73
73
|
}
|
74
74
|
|
@@ -0,0 +1,88 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {IRegistry} from "../../registry/IRegistry.sol";
|
5
|
+
import {IRegistryService} from "../../registry/IRegistryService.sol";
|
6
|
+
import {IInstance} from "../../instance/IInstance.sol";
|
7
|
+
import {InstanceReader} from "../../instance/InstanceReader.sol";
|
8
|
+
import {ISetup} from "../../instance/module/ISetup.sol";
|
9
|
+
import {ITreasury} from "../../instance/module/ITreasury.sol";
|
10
|
+
|
11
|
+
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
12
|
+
import {Fee} from "../../types/Fee.sol";
|
13
|
+
import {DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.sol";
|
14
|
+
import {KEEP_STATE} from "../../types/StateId.sol";
|
15
|
+
import {DISTRIBUTION} from "../../types/ObjectType.sol";
|
16
|
+
import {Version, VersionLib} from "../../types/Version.sol";
|
17
|
+
|
18
|
+
import {IVersionable} from "../../shared/IVersionable.sol";
|
19
|
+
import {Versionable} from "../../shared/Versionable.sol";
|
20
|
+
|
21
|
+
import {IService} from "../../shared/IService.sol";
|
22
|
+
import {Service} from "../../shared/Service.sol";
|
23
|
+
import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
|
24
|
+
import {IDistributionService} from "./IDistributionService.sol";
|
25
|
+
import {Distribution} from "../../components/Distribution.sol";
|
26
|
+
import {InstanceService} from "../InstanceService.sol";
|
27
|
+
import {Instance} from "../Instance.sol";
|
28
|
+
import {INftOwnable} from "../../shared/INftOwnable.sol";
|
29
|
+
|
30
|
+
string constant DISTRIBUTION_SERVICE_NAME = "DistributionService";
|
31
|
+
|
32
|
+
contract DistributionService is
|
33
|
+
ComponentServiceBase,
|
34
|
+
IDistributionService
|
35
|
+
{
|
36
|
+
using NftIdLib for NftId;
|
37
|
+
|
38
|
+
string public constant NAME = "DistributionService";
|
39
|
+
|
40
|
+
address internal _registryAddress;
|
41
|
+
|
42
|
+
function _initialize(
|
43
|
+
address owner,
|
44
|
+
bytes memory data
|
45
|
+
)
|
46
|
+
internal
|
47
|
+
initializer
|
48
|
+
virtual override
|
49
|
+
{
|
50
|
+
address initialOwner = address(0);
|
51
|
+
(_registryAddress, initialOwner) = abi.decode(data, (address, address));
|
52
|
+
// TODO while DistributionService is not deployed in DistributionServiceManager constructor
|
53
|
+
// owner is DistributionServiceManager deployer
|
54
|
+
_initializeService(_registryAddress, owner);
|
55
|
+
|
56
|
+
_registerInterface(type(IService).interfaceId);
|
57
|
+
_registerInterface(type(IDistributionService).interfaceId);
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
function getName() public pure override(IService, Service) returns(string memory name) {
|
62
|
+
return NAME;
|
63
|
+
}
|
64
|
+
|
65
|
+
function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal override {
|
66
|
+
ISetup.DistributionSetupInfo memory initialSetup = abi.decode(
|
67
|
+
initialObjData,
|
68
|
+
(ISetup.DistributionSetupInfo)
|
69
|
+
);
|
70
|
+
instance.createDistributionSetup(componentNftId, initialSetup);
|
71
|
+
}
|
72
|
+
|
73
|
+
function setFees(
|
74
|
+
Fee memory distributionFee
|
75
|
+
)
|
76
|
+
external
|
77
|
+
override
|
78
|
+
{
|
79
|
+
(IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(DISTRIBUTION());
|
80
|
+
InstanceReader instanceReader = instance.getInstanceReader();
|
81
|
+
NftId distributionNftId = info.nftId;
|
82
|
+
|
83
|
+
ISetup.DistributionSetupInfo memory distSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
|
84
|
+
distSetupInfo.distributionFee = distributionFee;
|
85
|
+
|
86
|
+
instance.updateDistributionSetup(distributionNftId, distSetupInfo, KEEP_STATE());
|
87
|
+
}
|
88
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.20;
|
3
|
+
|
4
|
+
import {IVersionable} from "../../shared/IVersionable.sol";
|
5
|
+
import {ProxyManager} from "../../shared/ProxyManager.sol";
|
6
|
+
import {DistributionService} from "./DistributionService.sol";
|
7
|
+
import {Registry} from "../../registry/Registry.sol";
|
8
|
+
import {RegistryService} from "../../registry/RegistryService.sol";
|
9
|
+
import {VersionLib} from "../../types/Version.sol";
|
10
|
+
|
11
|
+
contract DistributionServiceManager is ProxyManager {
|
12
|
+
|
13
|
+
DistributionService private _distributionService;
|
14
|
+
|
15
|
+
/// @dev initializes proxy manager with distribution service implementation and deploys instance
|
16
|
+
constructor(
|
17
|
+
address registryAddress
|
18
|
+
)
|
19
|
+
ProxyManager()
|
20
|
+
{
|
21
|
+
DistributionService distSrv = new DistributionService();
|
22
|
+
bytes memory data = abi.encode(registryAddress, address(this));
|
23
|
+
IVersionable versionable = deploy(
|
24
|
+
address(distSrv),
|
25
|
+
data);
|
26
|
+
|
27
|
+
_distributionService = DistributionService(address(versionable));
|
28
|
+
|
29
|
+
Registry registry = Registry(registryAddress);
|
30
|
+
address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
|
31
|
+
RegistryService registryService = RegistryService(registryServiceAddress);
|
32
|
+
// TODO this must have a role or own nft to register service
|
33
|
+
//registryService.registerService(_distributionService);
|
34
|
+
|
35
|
+
// TODO no nft to link yet
|
36
|
+
// link ownership of instance service manager ot nft owner of instance service
|
37
|
+
//_linkToNftOwnable(
|
38
|
+
// address(registryAddress),
|
39
|
+
// address(_distributionService));
|
40
|
+
|
41
|
+
// implies that after this constructor call only upgrade functionality is available
|
42
|
+
_isDeployed = true;
|
43
|
+
}
|
44
|
+
|
45
|
+
//--- view functions ----------------------------------------------------//
|
46
|
+
function getDistributionService()
|
47
|
+
external
|
48
|
+
view
|
49
|
+
returns (DistributionService distributionService)
|
50
|
+
{
|
51
|
+
return _distributionService;
|
52
|
+
}
|
53
|
+
|
54
|
+
}
|
@@ -5,7 +5,7 @@ import {NftId} from "../../types/NftId.sol";
|
|
5
5
|
import {ObjectType} from "../../types/ObjectType.sol";
|
6
6
|
import {RoleId} from "../../types/RoleId.sol";
|
7
7
|
import {IBaseComponent} from "../../components/IBaseComponent.sol";
|
8
|
-
import {IService} from "
|
8
|
+
import {IService} from "../../shared/IService.sol";
|
9
9
|
|
10
10
|
// TODO rename to registry service
|
11
11
|
interface IComponentOwnerService is IService {
|
@@ -3,7 +3,7 @@ pragma solidity ^0.8.19;
|
|
3
3
|
|
4
4
|
import {NftId} from "../../types/NftId.sol";
|
5
5
|
import {Fee} from "../../types/Fee.sol";
|
6
|
-
import {IService} from "
|
6
|
+
import {IService} from "../../shared/IService.sol";
|
7
7
|
|
8
8
|
interface IDistributionService is IService {
|
9
9
|
function setFees(
|
@@ -3,7 +3,7 @@ pragma solidity ^0.8.19;
|
|
3
3
|
|
4
4
|
import {NftId} from "../../types/NftId.sol";
|
5
5
|
import {Fee} from "../../types/Fee.sol";
|
6
|
-
import {IService} from "
|
6
|
+
import {IService} from "../../shared/IService.sol";
|
7
7
|
|
8
8
|
interface IPoolService is IService {
|
9
9
|
function setFees(
|
@@ -2,7 +2,7 @@
|
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
4
|
import {IRisk} from "../module/IRisk.sol";
|
5
|
-
import {IService} from "
|
5
|
+
import {IService} from "../../shared/IService.sol";
|
6
6
|
|
7
7
|
import {NftId} from "../../types/NftId.sol";
|
8
8
|
import {ReferralId} from "../../types/Referral.sol";
|