@etherisc/gif-next 0.0.2-81ba549-396 → 0.0.2-81d7358-706
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -1
- package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +155 -0
- package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
- package/artifacts/contracts/components/Distribution.sol/Distribution.json +143 -86
- package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +117 -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/IPoolComponent.sol/IPoolComponent.json +28 -2
- 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 +175 -115
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +151 -95
- 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/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/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
- 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/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
- package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
- package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
- package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +788 -0
- package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
- package/artifacts/contracts/instance/{AccessManagedSimple.sol/AccessManagedSimple.json → Cloneable.sol/Cloneable.json} +86 -2
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +500 -0
- package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
- package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.json +448 -0
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +104 -14
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +162 -679
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +244 -114
- package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +4 -0
- package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +763 -0
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +74 -40
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +183 -151
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +26 -74
- package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
- package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +285 -0
- package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +24 -32
- 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/Lifecycle.sol/Lifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +59 -16
- 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/BundleService.sol/BundleService.dbg.json +4 -0
- package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +945 -0
- package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
- package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +432 -0
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +39 -52
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +49 -72
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +13 -37
- package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
- package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +669 -0
- package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +13 -13
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +13 -13
- package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
- package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +664 -0
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +15 -77
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +17 -220
- package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
- package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +993 -0
- package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
- package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +464 -0
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +48 -160
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +13 -41
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +50 -359
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +13 -61
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +151 -133
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -65
- 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 +170 -225
- package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +4 -0
- package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +285 -0
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +30 -128
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +38 -100
- package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +4 -0
- package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +546 -0
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +14 -27
- 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/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 +1 -1
- package/artifacts/contracts/shared/IService.sol/IService.json +13 -13
- 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 +2 -2
- package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
- package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
- package/artifacts/contracts/shared/Service.sol/Service.json +13 -13
- 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/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 +2 -2
- 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 +31 -31
- 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/TestVersionable.sol/TestVersionable.dbg.json +1 -1
- 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/NftIdSet.sol/LibNftIdSet.json +26 -3
- 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/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/VersionPartLib.dbg.json +1 -1
- package/contracts/components/BaseComponent.sol +79 -11
- package/contracts/components/Distribution.sol +6 -2
- package/contracts/components/IBaseComponent.sol +9 -0
- package/contracts/components/IPoolComponent.sol +5 -1
- package/contracts/components/Pool.sol +40 -11
- package/contracts/components/Product.sol +16 -8
- package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +23 -0
- package/contracts/instance/BundleManager.sol +129 -0
- package/contracts/instance/Cloneable.sol +46 -0
- package/contracts/instance/IInstance.sol +10 -1
- package/contracts/instance/IInstanceBase.sol +26 -0
- package/contracts/instance/IInstanceService.sol +13 -3
- package/contracts/instance/Instance.sol +47 -214
- package/contracts/instance/InstanceAccessManager.sol +93 -78
- package/contracts/instance/InstanceBase.sol +41 -0
- package/contracts/instance/InstanceReader.sol +9 -0
- package/contracts/instance/InstanceService.sol +246 -93
- package/contracts/instance/InstanceServiceManager.sol +5 -8
- package/contracts/instance/ObjectManager.sol +101 -0
- package/contracts/instance/base/ComponentServiceBase.sol +36 -81
- package/contracts/instance/module/IAccess.sol +27 -17
- package/contracts/instance/module/ISetup.sol +3 -1
- package/contracts/instance/service/BundleService.sol +260 -0
- package/contracts/instance/service/BundleServiceManager.sol +51 -0
- package/contracts/instance/service/ComponentOwnerService.sol +4 -6
- package/contracts/instance/service/DistributionService.sol +45 -20
- package/contracts/instance/service/DistributionServiceManager.sol +6 -9
- package/contracts/instance/service/IBundleService.sol +45 -0
- package/contracts/instance/service/IPolicyService.sol +87 -0
- package/contracts/instance/service/IPoolService.sol +6 -23
- package/contracts/instance/service/IProductService.sol +3 -70
- package/contracts/instance/service/PolicyService.sol +503 -0
- package/contracts/instance/service/PolicyServiceManager.sol +54 -0
- package/contracts/instance/service/PoolService.sol +47 -117
- package/contracts/instance/service/PoolServiceManager.sol +5 -8
- package/contracts/instance/service/ProductService.sol +59 -452
- package/contracts/registry/ChainNft.sol +1 -1
- package/contracts/registry/IRegistry.sol +27 -15
- package/contracts/registry/IRegistryService.sol +13 -5
- package/contracts/registry/Registry.sol +151 -199
- package/contracts/registry/RegistryAccessManager.sol +210 -0
- package/contracts/registry/RegistryService.sol +48 -83
- package/contracts/registry/RegistryServiceManager.sol +18 -36
- package/contracts/registry/ReleaseManager.sol +348 -0
- package/contracts/registry/TokenRegistry.sol +5 -6
- package/contracts/shared/IService.sol +2 -1
- package/contracts/shared/ProxyManager.sol +1 -1
- package/contracts/shared/Service.sol +10 -7
- package/contracts/test/TestService.sol +3 -2
- package/contracts/types/NftIdSet.sol +26 -24
- package/contracts/types/RoleId.sol +10 -10
- package/package.json +1 -1
- package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
- package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
- package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1132
- package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +0 -4
- package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.json +0 -1082
- package/contracts/instance/AccessManagedSimple.sol +0 -115
- package/contracts/instance/AccessManagerSimple.sol +0 -692
- package/contracts/instance/IAccessManagerSimple.sol +0 -391
@@ -1,18 +1,21 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.20;
|
3
3
|
|
4
|
+
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
4
5
|
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
5
6
|
|
6
|
-
import {Registerable} from "../shared/Registerable.sol";
|
7
|
-
|
8
|
-
import {IRegistry} from "../registry/IRegistry.sol";
|
9
|
-
import {IInstance} from "../instance/IInstance.sol";
|
10
|
-
|
11
|
-
import {IInstance} from "../instance/IInstance.sol";
|
12
|
-
import {IComponentOwnerService} from "../instance/service/IComponentOwnerService.sol";
|
13
7
|
import {IBaseComponent} from "./IBaseComponent.sol";
|
8
|
+
import {IComponentOwnerService} from "../instance/service/IComponentOwnerService.sol";
|
9
|
+
import {IInstanceService} from "../instance/IInstanceService.sol";
|
10
|
+
import {IInstance} from "../instance/IInstance.sol";
|
11
|
+
import {InstanceAccessManager} from "../instance/InstanceAccessManager.sol";
|
12
|
+
import {IRegistry} from "../registry/IRegistry.sol";
|
14
13
|
import {NftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
|
15
|
-
import {ObjectType} from "../types/ObjectType.sol";
|
14
|
+
import {ObjectType, INSTANCE} from "../types/ObjectType.sol";
|
15
|
+
import {VersionLib} from "../types/Version.sol";
|
16
|
+
import {Registerable} from "../shared/Registerable.sol";
|
17
|
+
import {RoleId, RoleIdLib} from "../types/RoleId.sol";
|
18
|
+
import {IAccess} from "../instance/module/IAccess.sol";
|
16
19
|
|
17
20
|
abstract contract BaseComponent is
|
18
21
|
Registerable,
|
@@ -21,13 +24,30 @@ abstract contract BaseComponent is
|
|
21
24
|
using NftIdLib for NftId;
|
22
25
|
|
23
26
|
IComponentOwnerService internal _componentOwnerService;
|
27
|
+
IInstanceService internal _instanceService;
|
24
28
|
|
25
29
|
address internal _deployer;
|
26
30
|
address internal _wallet;
|
27
31
|
IERC20Metadata internal _token;
|
28
32
|
IInstance internal _instance;
|
33
|
+
InstanceAccessManager internal _instanceAccessManager;
|
29
34
|
NftId internal _productNftId;
|
30
35
|
|
36
|
+
modifier onlyInstanceRole(uint64 roleIdNum) {
|
37
|
+
RoleId roleId = RoleIdLib.toRoleId(roleIdNum);
|
38
|
+
if( !_instanceAccessManager.hasRole(roleId, msg.sender)) {
|
39
|
+
revert ErrorBaseComponentUnauthorized(msg.sender, roleIdNum);
|
40
|
+
}
|
41
|
+
_;
|
42
|
+
}
|
43
|
+
|
44
|
+
modifier isNotLocked() {
|
45
|
+
if (_instanceAccessManager.isTargetLocked(address(this))) {
|
46
|
+
revert IAccess.ErrorIAccessTargetLocked(address(this));
|
47
|
+
}
|
48
|
+
_;
|
49
|
+
}
|
50
|
+
|
31
51
|
constructor(
|
32
52
|
address registry,
|
33
53
|
NftId instanceNftId,
|
@@ -42,25 +62,31 @@ abstract contract BaseComponent is
|
|
42
62
|
|
43
63
|
IRegistry.ObjectInfo memory instanceInfo = getRegistry().getObjectInfo(instanceNftId);
|
44
64
|
_instance = IInstance(instanceInfo.objectAddress);
|
65
|
+
_instanceAccessManager = _instance.getInstanceAccessManager();
|
45
66
|
require(
|
46
67
|
_instance.supportsInterface(type(IInstance).interfaceId),
|
47
68
|
""
|
48
69
|
);
|
49
70
|
|
50
71
|
_componentOwnerService = _instance.getComponentOwnerService();
|
72
|
+
_instanceService = IInstanceService(getRegistry().getServiceAddress(INSTANCE(), VersionLib.toVersion(3, 0, 0).toMajorPart()));
|
51
73
|
_wallet = address(this);
|
52
74
|
_token = IERC20Metadata(token);
|
53
75
|
|
54
76
|
_registerInterface(type(IBaseComponent).interfaceId);
|
55
77
|
}
|
56
78
|
|
79
|
+
function getName() public pure virtual returns (string memory name);
|
80
|
+
|
57
81
|
// from component contract
|
82
|
+
// TODO only owner and instance owner
|
58
83
|
function lock() external onlyOwner override {
|
59
|
-
|
84
|
+
_instanceService.setTargetLocked(getName(), true);
|
60
85
|
}
|
61
|
-
|
86
|
+
|
87
|
+
// TODO only owner and instance owner
|
62
88
|
function unlock() external onlyOwner override {
|
63
|
-
|
89
|
+
_instanceService.setTargetLocked(getName(), false);
|
64
90
|
}
|
65
91
|
|
66
92
|
function getWallet()
|
@@ -72,6 +98,48 @@ abstract contract BaseComponent is
|
|
72
98
|
return _wallet;
|
73
99
|
}
|
74
100
|
|
101
|
+
/// @dev Sets the wallet address for the component.
|
102
|
+
/// if the current wallet has tokens, these will be transferred.
|
103
|
+
/// if the new wallet address is externally owned, an approval from the
|
104
|
+
/// owner of the external wallet for the component to move all tokens must exist.
|
105
|
+
function setWallet(address newWallet) external override onlyOwner {
|
106
|
+
address currentWallet = _wallet;
|
107
|
+
uint256 currentBalance = _token.balanceOf(currentWallet);
|
108
|
+
|
109
|
+
// checks
|
110
|
+
if (newWallet == currentWallet) {
|
111
|
+
revert ErrorBaseComponentWalletAddressIsSameAsCurrent(newWallet);
|
112
|
+
}
|
113
|
+
|
114
|
+
if (currentBalance > 0) {
|
115
|
+
if (currentWallet == address(this)) {
|
116
|
+
// move tokens from component smart contract to external wallet
|
117
|
+
} else {
|
118
|
+
// move tokens from external wallet to component smart contract or another external wallet
|
119
|
+
uint256 allowance = _token.allowance(currentWallet, address(this));
|
120
|
+
if (allowance < currentBalance) {
|
121
|
+
revert ErrorBaseComponentWalletAllowanceTooSmall(currentWallet, newWallet, allowance, currentBalance);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
// effects
|
127
|
+
_wallet = newWallet;
|
128
|
+
emit LogBaseComponentWalletAddressChanged(newWallet);
|
129
|
+
|
130
|
+
// interactions
|
131
|
+
if (currentBalance > 0) {
|
132
|
+
// transfer tokens from current wallet to new wallet
|
133
|
+
if (currentWallet == address(this)) {
|
134
|
+
// transferFrom requires self allowance too
|
135
|
+
_token.approve(address(this), currentBalance);
|
136
|
+
}
|
137
|
+
|
138
|
+
SafeERC20.safeTransferFrom(_token, currentWallet, newWallet, currentBalance);
|
139
|
+
emit LogBaseComponentWalletTokensTransferred(currentWallet, newWallet, currentBalance);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
75
143
|
function getToken() public view override returns (IERC20Metadata token) {
|
76
144
|
return _token;
|
77
145
|
}
|
@@ -16,7 +16,7 @@ import {Registerable} from "../shared/Registerable.sol";
|
|
16
16
|
import {TokenHandler} from "../shared/TokenHandler.sol";
|
17
17
|
import {InstanceReader} from "../instance/InstanceReader.sol";
|
18
18
|
|
19
|
-
contract Distribution is
|
19
|
+
abstract contract Distribution is
|
20
20
|
BaseComponent,
|
21
21
|
IDistributionComponent
|
22
22
|
{
|
@@ -25,6 +25,8 @@ contract Distribution is
|
|
25
25
|
Fee internal _initialDistributionFee;
|
26
26
|
bool internal _isVerifying;
|
27
27
|
|
28
|
+
TokenHandler internal _tokenHandler;
|
29
|
+
|
28
30
|
IDistributionService private _distributionService;
|
29
31
|
IProductService private _productService;
|
30
32
|
|
@@ -49,6 +51,8 @@ contract Distribution is
|
|
49
51
|
_isVerifying = verifying;
|
50
52
|
_initialDistributionFee = distributionFee;
|
51
53
|
|
54
|
+
_tokenHandler = TokenHandler(token);
|
55
|
+
|
52
56
|
_distributionService = _instance.getDistributionService();
|
53
57
|
_productService = _instance.getProductService();
|
54
58
|
|
@@ -148,7 +152,7 @@ contract Distribution is
|
|
148
152
|
abi.encode(
|
149
153
|
ISetup.DistributionSetupInfo(
|
150
154
|
_productNftId,
|
151
|
-
|
155
|
+
_tokenHandler,
|
152
156
|
_initialDistributionFee,
|
153
157
|
_isVerifying,
|
154
158
|
address(this)
|
@@ -8,6 +8,14 @@ import {IInstance} from "../instance/IInstance.sol";
|
|
8
8
|
import {NftId} from "../types/NftId.sol";
|
9
9
|
|
10
10
|
interface IBaseComponent is IRegisterable {
|
11
|
+
error ErrorBaseComponentWalletAddressIsSameAsCurrent(address newWallet);
|
12
|
+
error ErrorBaseComponentWalletAllowanceTooSmall(address oldWallet, address newWallet, uint256 allowance, uint256 balance);
|
13
|
+
error ErrorBaseComponentUnauthorized(address caller, uint64 requiredRoleIdNum);
|
14
|
+
|
15
|
+
event LogBaseComponentWalletAddressChanged(address newWallet);
|
16
|
+
event LogBaseComponentWalletTokensTransferred(address from, address to, uint256 amount);
|
17
|
+
|
18
|
+
function getName() external pure virtual returns (string memory name);
|
11
19
|
|
12
20
|
function lock() external;
|
13
21
|
|
@@ -15,6 +23,7 @@ interface IBaseComponent is IRegisterable {
|
|
15
23
|
|
16
24
|
function getToken() external view returns (IERC20Metadata token);
|
17
25
|
|
26
|
+
function setWallet(address walletAddress) external;
|
18
27
|
function getWallet() external view returns (address walletAddress);
|
19
28
|
|
20
29
|
function getInstance() external view returns (IInstance instance);
|
@@ -43,6 +43,10 @@ interface IPoolComponent {
|
|
43
43
|
uint256 collateralizationAmount
|
44
44
|
) external;
|
45
45
|
|
46
|
+
function lockBundle(NftId bundleNftId) external;
|
47
|
+
|
48
|
+
function unlockBundle(NftId bundleNftId) external;
|
49
|
+
|
46
50
|
/**
|
47
51
|
* @dev returns true iff the policy application data in policyData matches
|
48
52
|
* with the bundle filter criteria encoded in bundleFilter.
|
@@ -55,7 +59,7 @@ interface IPoolComponent {
|
|
55
59
|
view
|
56
60
|
returns (bool isMatching);
|
57
61
|
|
58
|
-
function
|
62
|
+
function isConfirmingApplication() external view returns (bool isConfirmingApplication);
|
59
63
|
|
60
64
|
function getCollateralizationLevel() external view returns (UFixed collateralizationLevel);
|
61
65
|
|
@@ -4,6 +4,7 @@ pragma solidity ^0.8.20;
|
|
4
4
|
import {ObjectType, POOL} from "../types/ObjectType.sol";
|
5
5
|
import {IProductService} from "../instance/service/IProductService.sol";
|
6
6
|
import {IPoolService} from "../instance/service/IPoolService.sol";
|
7
|
+
import {IBundleService} from "../instance/service/IBundleService.sol";
|
7
8
|
import {NftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
|
8
9
|
import {Fee} from "../types/Fee.sol";
|
9
10
|
import {UFixed} from "../types/UFixed.sol";
|
@@ -22,22 +23,26 @@ import {InstanceReader} from "../instance/InstanceReader.sol";
|
|
22
23
|
import {IRegisterable} from "../shared/IRegisterable.sol";
|
23
24
|
import {Registerable} from "../shared/Registerable.sol";
|
24
25
|
|
25
|
-
contract Pool is BaseComponent, IPoolComponent {
|
26
|
+
abstract contract Pool is BaseComponent, IPoolComponent {
|
26
27
|
using NftIdLib for NftId;
|
27
28
|
|
28
|
-
bool internal
|
29
|
+
bool internal _isConfirmingApplication;
|
29
30
|
UFixed internal _collateralizationLevel;
|
30
31
|
|
31
32
|
Fee internal _initialPoolFee;
|
32
33
|
Fee internal _initialStakingFee;
|
33
34
|
Fee internal _initialPerformanceFee;
|
34
35
|
|
36
|
+
TokenHandler internal _tokenHandler;
|
37
|
+
|
35
38
|
// may be used to interact with instance by derived contracts
|
36
39
|
IPoolService internal _poolService;
|
37
40
|
|
38
41
|
// only relevant to protect callback functions for "active" pools
|
39
42
|
IProductService private _productService;
|
40
43
|
|
44
|
+
IBundleService private _bundleService;
|
45
|
+
|
41
46
|
modifier onlyPoolService() {
|
42
47
|
require(
|
43
48
|
msg.sender == address(_poolService),
|
@@ -58,7 +63,7 @@ contract Pool is BaseComponent, IPoolComponent {
|
|
58
63
|
// TODO refactor into tokenNftId
|
59
64
|
address token,
|
60
65
|
bool isInterceptor,
|
61
|
-
bool
|
66
|
+
bool isConfirmingApplication,
|
62
67
|
UFixed collateralizationLevel,
|
63
68
|
Fee memory poolFee,
|
64
69
|
Fee memory stakingFee,
|
@@ -67,15 +72,18 @@ contract Pool is BaseComponent, IPoolComponent {
|
|
67
72
|
)
|
68
73
|
BaseComponent(registry, instanceNftId, token, POOL(), isInterceptor, initialOwner)
|
69
74
|
{
|
70
|
-
|
75
|
+
_isConfirmingApplication = isConfirmingApplication;
|
71
76
|
// TODO add validation
|
72
77
|
_collateralizationLevel = collateralizationLevel;
|
73
78
|
_initialPoolFee = poolFee;
|
74
79
|
_initialStakingFee = stakingFee;
|
75
80
|
_initialPerformanceFee = performanceFee;
|
76
81
|
|
82
|
+
_tokenHandler = new TokenHandler(token);
|
83
|
+
|
77
84
|
_poolService = _instance.getPoolService();
|
78
85
|
_productService = _instance.getProductService();
|
86
|
+
_bundleService = _instance.getBundleService();
|
79
87
|
|
80
88
|
_registerInterface(type(IPoolComponent).interfaceId);
|
81
89
|
}
|
@@ -91,7 +99,7 @@ contract Pool is BaseComponent, IPoolComponent {
|
|
91
99
|
returns(NftId bundleNftId)
|
92
100
|
{
|
93
101
|
address owner = msg.sender;
|
94
|
-
bundleNftId =
|
102
|
+
bundleNftId = _bundleService.createBundle(
|
95
103
|
owner,
|
96
104
|
fee,
|
97
105
|
initialAmount,
|
@@ -136,8 +144,8 @@ contract Pool is BaseComponent, IPoolComponent {
|
|
136
144
|
}
|
137
145
|
|
138
146
|
|
139
|
-
function
|
140
|
-
return
|
147
|
+
function isConfirmingApplication() external view override returns (bool isConfirmingApplication) {
|
148
|
+
return _isConfirmingApplication;
|
141
149
|
}
|
142
150
|
|
143
151
|
function getCollateralizationLevel() external view override returns (UFixed collateralizationLevel) {
|
@@ -164,7 +172,27 @@ contract Pool is BaseComponent, IPoolComponent {
|
|
164
172
|
override
|
165
173
|
// TODO add onlyBundleOwner
|
166
174
|
{
|
167
|
-
|
175
|
+
_bundleService.setBundleFee(bundleNftId, fee);
|
176
|
+
}
|
177
|
+
|
178
|
+
function lockBundle(
|
179
|
+
NftId bundleNftId
|
180
|
+
)
|
181
|
+
external
|
182
|
+
override
|
183
|
+
// TODO add onlyBundleOwner
|
184
|
+
{
|
185
|
+
_bundleService.lockBundle(bundleNftId);
|
186
|
+
}
|
187
|
+
|
188
|
+
function unlockBundle(
|
189
|
+
NftId bundleNftId
|
190
|
+
)
|
191
|
+
external
|
192
|
+
override
|
193
|
+
// TODO add onlyBundleOwner
|
194
|
+
{
|
195
|
+
_bundleService.unlockBundle(bundleNftId);
|
168
196
|
}
|
169
197
|
|
170
198
|
function getSetupInfo() public view returns (ISetup.PoolSetupInfo memory setupInfo) {
|
@@ -191,12 +219,13 @@ contract Pool is BaseComponent, IPoolComponent {
|
|
191
219
|
abi.encode(
|
192
220
|
ISetup.PoolSetupInfo(
|
193
221
|
_productNftId,
|
194
|
-
|
222
|
+
_tokenHandler,
|
195
223
|
_collateralizationLevel,
|
196
224
|
_initialPoolFee,
|
197
225
|
_initialStakingFee,
|
198
226
|
_initialPerformanceFee,
|
199
|
-
|
227
|
+
false,
|
228
|
+
_isConfirmingApplication,
|
200
229
|
_wallet
|
201
230
|
)
|
202
231
|
)
|
@@ -231,7 +260,7 @@ contract Pool is BaseComponent, IPoolComponent {
|
|
231
260
|
internal
|
232
261
|
returns(NftId bundleNftId)
|
233
262
|
{
|
234
|
-
bundleNftId =
|
263
|
+
bundleNftId = _bundleService.createBundle(
|
235
264
|
bundleOwner,
|
236
265
|
fee,
|
237
266
|
amount,
|
@@ -6,6 +6,7 @@ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IER
|
|
6
6
|
import {IRisk} from "../instance/module/IRisk.sol";
|
7
7
|
import {ITreasury} from "../instance/module/ITreasury.sol";
|
8
8
|
import {IProductService} from "../instance/service/IProductService.sol";
|
9
|
+
import {IPolicyService} from "../instance/service/IPolicyService.sol";
|
9
10
|
import {IProductComponent} from "./IProductComponent.sol";
|
10
11
|
import {NftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
|
11
12
|
import {ObjectType, PRODUCT} from "../types/ObjectType.sol";
|
@@ -28,14 +29,16 @@ import {Distribution} from "../components/Distribution.sol";
|
|
28
29
|
|
29
30
|
import {zeroNftId} from "../types/NftId.sol";
|
30
31
|
|
31
|
-
contract Product is BaseComponent, IProductComponent {
|
32
|
+
abstract contract Product is BaseComponent, IProductComponent {
|
32
33
|
using NftIdLib for NftId;
|
33
34
|
|
34
35
|
IProductService internal _productService;
|
36
|
+
IPolicyService internal _policyService;
|
35
37
|
Pool internal _pool;
|
36
38
|
Distribution internal _distribution;
|
37
39
|
Fee internal _initialProductFee;
|
38
40
|
Fee internal _initialProcessingFee;
|
41
|
+
TokenHandler internal _tokenHandler;
|
39
42
|
|
40
43
|
NftId internal _poolNftId;
|
41
44
|
NftId internal _distributionNftId;
|
@@ -53,11 +56,14 @@ contract Product is BaseComponent, IProductComponent {
|
|
53
56
|
) BaseComponent(registry, instanceNftid, token, PRODUCT(), isInterceptor, initialOwner) {
|
54
57
|
// TODO add validation
|
55
58
|
_productService = _instance.getProductService();
|
59
|
+
_policyService = _instance.getPolicyService();
|
56
60
|
_pool = Pool(pool);
|
57
61
|
_distribution = Distribution(distribution);
|
58
62
|
_initialProductFee = productFee;
|
59
63
|
_initialProcessingFee = processingFee;
|
60
64
|
|
65
|
+
_tokenHandler = new TokenHandler(token);
|
66
|
+
|
61
67
|
_poolNftId = getRegistry().getNftId(address(_pool));
|
62
68
|
_distributionNftId = getRegistry().getNftId(address(_distribution));
|
63
69
|
|
@@ -78,7 +84,7 @@ contract Product is BaseComponent, IProductComponent {
|
|
78
84
|
override
|
79
85
|
returns (uint256 premiumAmount)
|
80
86
|
{
|
81
|
-
(premiumAmount,,,,) =
|
87
|
+
(premiumAmount,,,,) = _policyService.calculatePremium(
|
82
88
|
riskId,
|
83
89
|
sumInsuredAmount,
|
84
90
|
lifetime,
|
@@ -151,7 +157,7 @@ contract Product is BaseComponent, IProductComponent {
|
|
151
157
|
NftId bundleNftId,
|
152
158
|
ReferralId referralId
|
153
159
|
) internal returns (NftId nftId) {
|
154
|
-
nftId =
|
160
|
+
nftId = _policyService.createApplication(
|
155
161
|
applicationOwner,
|
156
162
|
riskId,
|
157
163
|
sumInsuredAmount,
|
@@ -169,7 +175,7 @@ contract Product is BaseComponent, IProductComponent {
|
|
169
175
|
)
|
170
176
|
internal
|
171
177
|
{
|
172
|
-
|
178
|
+
_policyService.underwrite(
|
173
179
|
policyNftId,
|
174
180
|
requirePremiumPayment,
|
175
181
|
activateAt);
|
@@ -181,7 +187,7 @@ contract Product is BaseComponent, IProductComponent {
|
|
181
187
|
)
|
182
188
|
internal
|
183
189
|
{
|
184
|
-
|
190
|
+
_policyService.collectPremium(
|
185
191
|
policyNftId,
|
186
192
|
activateAt);
|
187
193
|
}
|
@@ -192,7 +198,7 @@ contract Product is BaseComponent, IProductComponent {
|
|
192
198
|
)
|
193
199
|
internal
|
194
200
|
{
|
195
|
-
|
201
|
+
_policyService.activate(
|
196
202
|
policyNftId,
|
197
203
|
activateAt);
|
198
204
|
}
|
@@ -268,7 +274,7 @@ contract Product is BaseComponent, IProductComponent {
|
|
268
274
|
abi.encode(
|
269
275
|
ISetup.ProductSetupInfo(
|
270
276
|
_token,
|
271
|
-
|
277
|
+
_tokenHandler,
|
272
278
|
_distributionNftId,
|
273
279
|
_poolNftId,
|
274
280
|
distributionSetupInfo.distributionFee,
|
@@ -276,7 +282,9 @@ contract Product is BaseComponent, IProductComponent {
|
|
276
282
|
_initialProcessingFee,
|
277
283
|
poolSetupInfo.poolFee,
|
278
284
|
poolSetupInfo.stakingFee,
|
279
|
-
poolSetupInfo.performanceFee
|
285
|
+
poolSetupInfo.performanceFee,
|
286
|
+
false,
|
287
|
+
_wallet
|
280
288
|
)
|
281
289
|
)
|
282
290
|
);
|
@@ -0,0 +1,23 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.20;
|
3
|
+
|
4
|
+
import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
|
5
|
+
|
6
|
+
|
7
|
+
contract AccessManagerUpgradeableInitializeable is AccessManagerUpgradeable {
|
8
|
+
|
9
|
+
bool private _initialized;
|
10
|
+
|
11
|
+
function __AccessManagerUpgradeableInitializeable_init(address initialAdmin) public {
|
12
|
+
require(!_initialized, "AccessManager: already initialized");
|
13
|
+
|
14
|
+
if (initialAdmin == address(0)) {
|
15
|
+
revert AccessManagerInvalidInitialAdmin(address(0));
|
16
|
+
}
|
17
|
+
|
18
|
+
// admin is active immediately and without any execution delay.
|
19
|
+
_grantRole(ADMIN_ROLE, initialAdmin, 0, 0);
|
20
|
+
_initialized = true;
|
21
|
+
}
|
22
|
+
|
23
|
+
}
|
@@ -0,0 +1,129 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.20;
|
3
|
+
|
4
|
+
import {IInstance} from "./IInstance.sol";
|
5
|
+
import {INSTANCE} from "../types/ObjectType.sol";
|
6
|
+
import {InstanceReader} from "./InstanceReader.sol";
|
7
|
+
import {IPolicy} from "../instance/module/IPolicy.sol";
|
8
|
+
import {IRegistry} from "../registry/IRegistry.sol";
|
9
|
+
import {LibNftIdSet} from "../types/NftIdSet.sol";
|
10
|
+
import {NftId} from "../types/NftId.sol";
|
11
|
+
import {TimestampLib} from "../types/Timestamp.sol";
|
12
|
+
|
13
|
+
import {ObjectManager} from "./ObjectManager.sol";
|
14
|
+
|
15
|
+
contract BundleManager is
|
16
|
+
ObjectManager
|
17
|
+
{
|
18
|
+
|
19
|
+
event LogBundleManagerPolicyLinked(NftId bundleNftId, NftId policyNftId);
|
20
|
+
event LogBundleManagerPolicyUnlinked(NftId bundleNftId, NftId policyNftId);
|
21
|
+
|
22
|
+
event LogBundleManagerBundleAdded(NftId poolNftId, NftId bundleNftId);
|
23
|
+
event LogBundleManagerBundleUnlocked(NftId poolNftId, NftId bundleNftId);
|
24
|
+
event LogBundleManagerBundleLocked(NftId poolNftId, NftId bundleNftId);
|
25
|
+
|
26
|
+
error ErrorBundleManagerErrorPolicyAlreadyActivated(NftId policyNftId);
|
27
|
+
error ErrorBundleManagerErrorBundleLocked(NftId bundleNftId, NftId policyNftId);
|
28
|
+
error ErrorBundleManagerPolicyWithOpenClaims(NftId policyNftId, uint256 openClaimsCount);
|
29
|
+
error ErrorBundleManagerPolicyNotCloseable(NftId policyNftId);
|
30
|
+
error ErrorBundleManagerBundleUnknown(NftId bundleNftId);
|
31
|
+
error ErrorBundleManagerBundleNotRegistered(NftId bundleNftId);
|
32
|
+
|
33
|
+
mapping(NftId bundleNftId => LibNftIdSet.Set policies) internal _activePolicies;
|
34
|
+
|
35
|
+
constructor() ObjectManager() {
|
36
|
+
}
|
37
|
+
|
38
|
+
|
39
|
+
/// @dev links a policy with its bundle
|
40
|
+
// to link a policy it MUST NOT yet have been activated
|
41
|
+
// the bundle MUST be unlocked (active) for linking (underwriting) and registered with this instance
|
42
|
+
function linkPolicy(NftId policyNftId) external restricted() {
|
43
|
+
NftId bundleNftId = _instanceReader.getPolicyInfo(policyNftId).bundleNftId;
|
44
|
+
// decision will likely depend on the decision what to check here and what in the service
|
45
|
+
NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
|
46
|
+
|
47
|
+
// ensure bundle is unlocked (in active set) and registered with this instance
|
48
|
+
if (!_isActive(poolNftId, bundleNftId)) {
|
49
|
+
revert ErrorBundleManagerErrorBundleLocked(bundleNftId, policyNftId);
|
50
|
+
}
|
51
|
+
|
52
|
+
LibNftIdSet.add(_activePolicies[bundleNftId], policyNftId);
|
53
|
+
emit LogBundleManagerPolicyLinked(bundleNftId, policyNftId);
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
/// @dev unlinks a policy from its bundle
|
58
|
+
// to unlink a policy it must closable, ie. meet one of the following criterias
|
59
|
+
// - the policy MUST be past its expiry period and it MUST NOT have any open claims
|
60
|
+
// - the policy's payoutAmount MUST be equal to its sumInsuredAmount and MUST NOT have any open claims
|
61
|
+
function unlinkPolicy(NftId policyNftId) external restricted() {
|
62
|
+
IPolicy.PolicyInfo memory policyInfo = _instanceReader.getPolicyInfo(policyNftId);
|
63
|
+
|
64
|
+
NftId bundleNftId = policyInfo.bundleNftId;
|
65
|
+
// decision will likely depend on the decision what to check here and what in the service
|
66
|
+
NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
|
67
|
+
|
68
|
+
// ensure bundle is registered with this instance
|
69
|
+
if (!_contains(poolNftId, bundleNftId)) {
|
70
|
+
revert ErrorBundleManagerBundleUnknown(bundleNftId);
|
71
|
+
}
|
72
|
+
|
73
|
+
LibNftIdSet.remove(_activePolicies[bundleNftId], policyNftId);
|
74
|
+
emit LogBundleManagerPolicyUnlinked(policyInfo.bundleNftId, policyNftId);
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
/// @dev add a new bundle to a riskpool registerd with this instance
|
79
|
+
// the corresponding pool is fetched via instance reader
|
80
|
+
function add(NftId bundleNftId) external restricted() {
|
81
|
+
NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
|
82
|
+
|
83
|
+
// ensure pool is registered with instance
|
84
|
+
if(poolNftId.eqz()) {
|
85
|
+
revert ErrorBundleManagerBundleNotRegistered(bundleNftId);
|
86
|
+
}
|
87
|
+
|
88
|
+
_add(poolNftId, bundleNftId);
|
89
|
+
emit LogBundleManagerBundleAdded(poolNftId, bundleNftId);
|
90
|
+
}
|
91
|
+
|
92
|
+
/// @dev unlocked (active) bundles are available to underwrite new policies
|
93
|
+
function unlock(NftId bundleNftId) external restricted() {
|
94
|
+
NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
|
95
|
+
_activate(poolNftId, bundleNftId);
|
96
|
+
emit LogBundleManagerBundleUnlocked(poolNftId, bundleNftId);
|
97
|
+
}
|
98
|
+
|
99
|
+
/// @dev locked (deactivated) bundles may not underwrite any new policies
|
100
|
+
function lock(NftId bundleNftId) external restricted() {
|
101
|
+
NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
|
102
|
+
_deactivate(poolNftId, bundleNftId);
|
103
|
+
emit LogBundleManagerBundleLocked(poolNftId, bundleNftId);
|
104
|
+
}
|
105
|
+
|
106
|
+
function bundles(NftId poolNftId) external view returns(uint256) {
|
107
|
+
return _objects(poolNftId);
|
108
|
+
}
|
109
|
+
|
110
|
+
function getBundleNftId(NftId poolNftId, uint256 idx) external view returns(NftId bundleNftId) {
|
111
|
+
return _getObject(poolNftId, idx);
|
112
|
+
}
|
113
|
+
|
114
|
+
function activeBundles(NftId poolNftId) external view returns(uint256) {
|
115
|
+
return _activeObjs(poolNftId);
|
116
|
+
}
|
117
|
+
|
118
|
+
function getActiveBundleNftId(NftId poolNftId, uint256 idx) external view returns(NftId bundleNftId) {
|
119
|
+
return _getActiveObject(poolNftId, idx);
|
120
|
+
}
|
121
|
+
|
122
|
+
function activePolicies(NftId bundleNftId) external view returns(uint256) {
|
123
|
+
return LibNftIdSet.size(_activePolicies[bundleNftId]);
|
124
|
+
}
|
125
|
+
|
126
|
+
function getActivePolicy(NftId bundleNftId, uint256 idx) external view returns(NftId policyNftId) {
|
127
|
+
return LibNftIdSet.getElementAt(_activePolicies[bundleNftId], idx);
|
128
|
+
}
|
129
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.20;
|
3
|
+
|
4
|
+
import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
|
5
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
6
|
+
|
7
|
+
import {IRegistry} from "../registry/IRegistry.sol";
|
8
|
+
|
9
|
+
abstract contract Cloneable is
|
10
|
+
AccessManagedUpgradeable
|
11
|
+
{
|
12
|
+
event CloneableInitialized(address authority, address registry);
|
13
|
+
|
14
|
+
error CloneableRegistryInvalid(address registry);
|
15
|
+
|
16
|
+
IRegistry internal _registry;
|
17
|
+
|
18
|
+
constructor() {
|
19
|
+
_registry = IRegistry(address(0));
|
20
|
+
}
|
21
|
+
|
22
|
+
/// @dev call to initialize MUST be made in the same transaction as cloning of the contract
|
23
|
+
function initialize(
|
24
|
+
address authority,
|
25
|
+
address registry
|
26
|
+
)
|
27
|
+
public
|
28
|
+
initializer
|
29
|
+
{
|
30
|
+
// check/handle access managed
|
31
|
+
__AccessManaged_init(authority);
|
32
|
+
|
33
|
+
// check/handle registry
|
34
|
+
if (registry.code.length == 0) {
|
35
|
+
revert CloneableRegistryInvalid(registry);
|
36
|
+
}
|
37
|
+
|
38
|
+
_registry = IRegistry(registry);
|
39
|
+
|
40
|
+
emit CloneableInitialized(authority, registry);
|
41
|
+
}
|
42
|
+
|
43
|
+
function getRegistry() external view returns (IRegistry) {
|
44
|
+
return _registry;
|
45
|
+
}
|
46
|
+
}
|