@etherisc/gif-next 0.0.2-ebbe63d → 0.0.2-f9905e1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. package/README.md +95 -1
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +4 -0
  3. package/artifacts/contracts/components/Component.sol/Component.json +179 -0
  4. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +4 -0
  5. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +35 -0
  6. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +4 -0
  7. package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +179 -0
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +4 -0
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +192 -0
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +4 -0
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +195 -0
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
  13. package/artifacts/contracts/components/Product.sol/Product.json +213 -0
  14. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
  15. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
  16. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
  17. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
  18. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
  19. package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
  20. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
  22. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
  26. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
  27. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
  28. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
  30. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
  32. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
  34. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +4 -0
  35. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +892 -0
  36. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +4 -0
  37. package/artifacts/contracts/instance/Instance.sol/Instance.json +1009 -0
  38. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +4 -0
  39. package/artifacts/contracts/instance/access/Access.sol/AccessModule.json +400 -0
  40. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +4 -0
  41. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.json +10 -0
  42. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +4 -0
  43. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.json +35 -0
  44. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +4 -0
  45. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.json +50 -0
  46. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +4 -0
  47. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.json +336 -0
  48. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +4 -0
  49. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +327 -0
  50. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +4 -0
  51. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +105 -0
  52. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +4 -0
  53. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.json +10 -0
  54. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +4 -0
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +179 -0
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +4 -0
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +245 -0
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +4 -0
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +94 -0
  60. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +4 -0
  61. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.json +24 -0
  62. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +4 -0
  63. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.json +10 -0
  64. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +4 -0
  65. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +231 -0
  66. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +4 -0
  67. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +231 -0
  68. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +4 -0
  69. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.json +10 -0
  70. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +4 -0
  71. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +149 -0
  72. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +4 -0
  73. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +162 -0
  74. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +4 -0
  75. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.json +75 -0
  76. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +4 -0
  77. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +114 -0
  78. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +4 -0
  79. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.json +75 -0
  80. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +4 -0
  81. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +125 -0
  82. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +4 -0
  83. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.json +24 -0
  84. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +4 -0
  85. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +166 -0
  86. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +4 -0
  87. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +271 -0
  88. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +4 -0
  89. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.json +49 -0
  90. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +4 -0
  91. package/artifacts/contracts/registry/Registry.sol/Registerable.json +166 -0
  92. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +4 -0
  93. package/artifacts/contracts/registry/Registry.sol/Registry.json +289 -0
  94. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +4 -0
  95. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +60 -0
  96. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  97. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  98. package/contracts/components/Component.sol +62 -0
  99. package/contracts/components/IPool.sol +9 -0
  100. package/contracts/components/IProduct.sol +11 -0
  101. package/contracts/components/Pool.sol +29 -0
  102. package/contracts/components/Product.sol +65 -0
  103. package/contracts/experiment/inheritance/A.sol +56 -0
  104. package/contracts/experiment/inheritance/B.sol +23 -0
  105. package/contracts/experiment/inheritance/C.sol +28 -0
  106. package/contracts/experiment/inheritance/IA.sol +18 -0
  107. package/contracts/experiment/inheritance/IB.sol +9 -0
  108. package/contracts/experiment/inheritance/IC.sol +11 -0
  109. package/contracts/experiment/types/TypeA.sol +42 -0
  110. package/contracts/experiment/types/TypeB.sol +24 -0
  111. package/contracts/instance/IInstance.sol +20 -0
  112. package/contracts/instance/Instance.sol +63 -0
  113. package/contracts/instance/access/Access.sol +218 -0
  114. package/contracts/instance/access/IAccess.sol +83 -0
  115. package/contracts/instance/component/ComponentModule.sol +259 -0
  116. package/contracts/instance/component/IComponent.sol +94 -0
  117. package/contracts/instance/policy/IPolicy.sol +66 -0
  118. package/contracts/instance/policy/PolicyModule.sol +106 -0
  119. package/contracts/instance/pool/IPoolModule.sol +40 -0
  120. package/contracts/instance/pool/PoolModule.sol +83 -0
  121. package/contracts/instance/product/IProductService.sol +45 -0
  122. package/contracts/instance/product/ProductService.sol +105 -0
  123. package/contracts/registry/IRegistry.sol +66 -0
  124. package/contracts/registry/Registry.sol +197 -0
  125. package/contracts/types/ChainId.sol +24 -0
  126. package/package.json +7 -6
  127. package/artifacts/contracts/Dip.sol/DIP.dbg.json +0 -4
  128. package/artifacts/contracts/Dip.sol/DIP.json +0 -338
  129. package/artifacts/contracts/Lock.sol/Lock.dbg.json +0 -4
  130. package/artifacts/contracts/Lock.sol/Lock.json +0 -74
  131. package/contracts/Dip.sol +0 -26
  132. package/contracts/Lock.sol +0 -34
@@ -0,0 +1,106 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+
5
+ // import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
6
+ import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
7
+
8
+ import {IProductService} from "../product/IProductService.sol";
9
+ import {IPolicy, IPolicyModule} from "./IPolicy.sol";
10
+
11
+
12
+ abstract contract PolicyModule is
13
+ IRegistryLinked,
14
+ IPolicyModule
15
+ {
16
+
17
+ mapping(uint256 nftId => PolicyInfo info) private _policyInfo;
18
+ mapping(uint256 nftId => uint256 bundleNftId) private _bundleForPolicy;
19
+
20
+ IProductService private _productService;
21
+
22
+ // TODO find a better place to avoid dupliation
23
+ modifier onlyProductService2() {
24
+ require(address(_productService) == msg.sender, "ERROR:POL-001:NOT_PRODUCT_SERVICE");
25
+ _;
26
+ }
27
+
28
+ constructor(address productService) {
29
+ _productService = IProductService(productService);
30
+ }
31
+
32
+
33
+ function createApplication(
34
+ IRegistry.RegistryInfo memory productInfo,
35
+ address applicationOwner,
36
+ uint256 sumInsuredAmount,
37
+ uint256 premiumAmount,
38
+ uint256 lifetime,
39
+ uint256 bundleNftId
40
+ )
41
+ external
42
+ override
43
+ onlyProductService2
44
+ returns(uint256 nftId)
45
+ {
46
+ // TODO add parameter validation
47
+ if(bundleNftId > 0) {
48
+ IRegistry.RegistryInfo memory bundleInfo = this.getRegistry().getInfo(bundleNftId);
49
+ IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
50
+ }
51
+
52
+ nftId = this.getRegistry().registerObjectForInstance(
53
+ productInfo.nftId,
54
+ this.getRegistry().POLICY(),
55
+ applicationOwner);
56
+
57
+ _policyInfo[nftId] = PolicyInfo(
58
+ nftId,
59
+ PolicyState.Applied,
60
+ sumInsuredAmount,
61
+ premiumAmount,
62
+ lifetime,
63
+ block.timestamp,
64
+ 0, // activatedAt
65
+ 0, // expiredAt
66
+ 0 // closedAt
67
+ );
68
+
69
+ _bundleForPolicy[nftId] = bundleNftId;
70
+
71
+ // add logging
72
+ }
73
+
74
+
75
+ function activate(uint256 nftId)
76
+ external
77
+ override
78
+ onlyProductService2
79
+ {
80
+ PolicyInfo storage info = _policyInfo[nftId];
81
+ info.activatedAt = block.timestamp;
82
+ info.expiredAt = block.timestamp + info.lifetime;
83
+ info.state = PolicyState.Active;
84
+
85
+ // add logging
86
+ }
87
+
88
+
89
+
90
+ function getBundleNftForPolicy(uint256 nftId)
91
+ external
92
+ view
93
+ returns(uint256 bundleNft)
94
+ {
95
+ return _bundleForPolicy[nftId];
96
+ }
97
+
98
+
99
+ function getPolicyInfo(uint256 nftId)
100
+ external
101
+ view
102
+ returns(PolicyInfo memory info)
103
+ {
104
+ return _policyInfo[nftId];
105
+ }
106
+ }
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
5
+
6
+ interface IPool {
7
+
8
+ struct PoolInfo {
9
+ uint256 nftId;
10
+ address wallet;
11
+ address token;
12
+ uint256 capital;
13
+ uint256 lockedCapital;
14
+ }
15
+ }
16
+
17
+ interface IPoolModule is
18
+ IOwnable,
19
+ IRegistryLinked,
20
+ IPool
21
+ {
22
+
23
+ function underwrite(
24
+ uint256 poolNftId,
25
+ uint256 policyNftId
26
+ )
27
+ external;
28
+
29
+ function createPoolInfo(
30
+ uint256 nftId,
31
+ address wallet,
32
+ address token
33
+ )
34
+ external;
35
+
36
+ function getPoolInfo(uint256 nftId)
37
+ external
38
+ view
39
+ returns(PoolInfo memory info);
40
+ }
@@ -0,0 +1,83 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
5
+ import {IProductService} from "../product/IProductService.sol";
6
+ import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
7
+ import {IPoolModule} from "./IPoolModule.sol";
8
+
9
+ abstract contract PoolModule is
10
+ IPoolModule
11
+ {
12
+ uint256 public constant INITIAL_CAPITAL = 10000*10**6;
13
+
14
+ mapping(uint256 nftId => PoolInfo info) private _poolInfo;
15
+
16
+ IProductService private _productService;
17
+
18
+ modifier onlyProductService() {
19
+ require(address(_productService) == msg.sender, "ERROR:POL-001:NOT_PRODUCT_SERVICE");
20
+ _;
21
+ }
22
+
23
+ constructor(address productService) {
24
+ _productService = IProductService(productService);
25
+ }
26
+
27
+ function createPoolInfo(
28
+ uint256 nftId,
29
+ address wallet,
30
+ address token
31
+ )
32
+ public
33
+ override
34
+ {
35
+ require(
36
+ _poolInfo[nftId].nftId == 0,
37
+ "ERROR:PL-001:ALREADY_CREATED");
38
+
39
+ _poolInfo[nftId] = PoolInfo(
40
+ nftId,
41
+ wallet,
42
+ token,
43
+ INITIAL_CAPITAL,
44
+ 0 // locked capital
45
+ );
46
+
47
+ }
48
+
49
+
50
+ function underwrite(
51
+ uint256 poolNftId,
52
+ uint256 policyNftId
53
+ )
54
+ external
55
+ override
56
+ onlyProductService
57
+ {
58
+ PoolInfo storage poolInfo = _poolInfo[poolNftId];
59
+ require(
60
+ poolInfo.nftId == poolNftId,
61
+ "ERROR:PL-002:POOL_UNKNOWN");
62
+
63
+ IPolicyModule policyModule = IPolicyModule(address(this));
64
+ IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(policyNftId);
65
+
66
+ require(
67
+ poolInfo.capital - poolInfo.lockedCapital >= policyInfo.sumInsuredAmount,
68
+ "ERROR:PL-003:CAPACITY_TOO_LOW");
69
+
70
+ poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
71
+ }
72
+
73
+
74
+ function getPoolInfo(uint256 nftId)
75
+ external
76
+ view
77
+ override
78
+ returns(PoolInfo memory info)
79
+ {
80
+ info = _poolInfo[nftId];
81
+ }
82
+
83
+ }
@@ -0,0 +1,45 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+
5
+ import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
6
+ import {IInstance} from "../IInstance.sol";
7
+
8
+
9
+ // TODO or name this IProtectionService to have Product be something more generic (loan, savings account, ...)
10
+ interface IProductService is
11
+ IRegistryLinked
12
+ {
13
+
14
+ function createApplication(
15
+ address applicationOwner,
16
+ uint256 sumInsuredAmount,
17
+ uint256 premiumAmount,
18
+ uint256 lifetime,
19
+ uint256 bundleNftId
20
+ )
21
+ external
22
+ returns(uint256 nftId);
23
+
24
+ // function revoke(unit256 nftId) external;
25
+
26
+ function underwrite(uint256 nftId) external;
27
+ // function decline(uint256 nftId) external;
28
+ // function expire(uint256 nftId) external;
29
+ function close(uint256 nftId) external;
30
+
31
+ // function collectPremium(uint256 nftId, uint256 premiumAmount) external;
32
+
33
+ // function createClaim(uint256 nftId, uint256 claimAmount) external;
34
+ // function confirmClaim(uint256 nftId, uint256 claimId, uint256 claimAmount) external;
35
+ // function declineClaim(uint256 nftId, uint256 claimId) external;
36
+ // function closeClaim(uint256 nftId, uint256 claimId) external;
37
+ }
38
+
39
+
40
+ interface IProductModule is
41
+ IOwnable,
42
+ IRegistryLinked
43
+ {
44
+ function getProductService() external view returns(IProductService);
45
+ }
@@ -0,0 +1,105 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+
5
+ // import {IProduct} from "../../components/IProduct.sol";
6
+ // import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
7
+ // import {IInstance} from "../IInstance.sol";
8
+ import {IRegistry} from "../../registry/IRegistry.sol";
9
+ import {IPolicyModule} from "../policy/IPolicy.sol";
10
+ import {RegistryLinked} from "../../registry/Registry.sol";
11
+ import {IProductService, IProductModule} from "./IProductService.sol";
12
+ import {IComponentModule} from "../../instance/component/IComponent.sol";
13
+ import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
14
+
15
+ // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
16
+ contract ProductService is
17
+ RegistryLinked,
18
+ IProductService
19
+ {
20
+ constructor(address registry)
21
+ RegistryLinked(registry)
22
+ { }
23
+
24
+
25
+ function createApplication(
26
+ address applicationOwner,
27
+ uint256 sumInsuredAmount,
28
+ uint256 premiumAmount,
29
+ uint256 lifetime,
30
+ uint256 bundleNftId
31
+ )
32
+ external
33
+ override
34
+ returns(uint256 nftId)
35
+ {
36
+ // same as only registered product
37
+ uint256 productNftId = _registry.getNftId(msg.sender);
38
+ require(productNftId > 0, "ERROR_PRODUCT_UNKNOWN");
39
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
40
+ require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
41
+
42
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
43
+ require(instanceInfo.nftId > 0, "ERROR_INSTANCE_UNKNOWN");
44
+ require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
45
+
46
+ IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
47
+ nftId = policyModule.createApplication(
48
+ productInfo,
49
+ applicationOwner,
50
+ sumInsuredAmount,
51
+ premiumAmount,
52
+ lifetime,
53
+ bundleNftId);
54
+
55
+ // add logging
56
+ }
57
+
58
+ function underwrite(uint256 nftId)
59
+ external
60
+ override
61
+ {
62
+ // same as only registered product
63
+ uint256 productNftId = _registry.getNftId(msg.sender);
64
+ require(productNftId > 0, "ERROR_PRODUCT_UNKNOWN");
65
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
66
+ require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
67
+
68
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
69
+ require(instanceInfo.nftId > 0, "ERROR_INSTANCE_UNKNOWN");
70
+ require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
71
+
72
+ // get responsible pool
73
+ IComponentModule componentModule = IComponentModule(instanceInfo.objectAddress);
74
+ uint256 poolNftId = componentModule.getPoolNftId(productNftId);
75
+
76
+ // lock capital (and update pool accounting)
77
+ IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
78
+ poolModule.underwrite(
79
+ poolNftId,
80
+ nftId);
81
+
82
+ // activate policy
83
+ IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
84
+ policyModule.activate(nftId);
85
+
86
+ // add logging
87
+ }
88
+
89
+ function close(uint256 nftId) external override {}
90
+ }
91
+
92
+ abstract contract ProductModule is
93
+ IProductModule
94
+ {
95
+ IProductService private _productService;
96
+
97
+ constructor(address productService) {
98
+ _productService = IProductService(productService);
99
+ }
100
+
101
+ function getProductService() external view returns(IProductService) {
102
+ return _productService;
103
+ }
104
+
105
+ }
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ interface IOwnable {
5
+ function getOwner() external view returns(address owner);
6
+ }
7
+
8
+ interface IRegistryLinked {
9
+
10
+ event LogDebug(uint256 idx, address module, string comment);
11
+
12
+ function getRegistry() external view returns(IRegistry registry);
13
+ }
14
+
15
+ interface IRegisterable is
16
+ IOwnable,
17
+ IRegistryLinked
18
+ {
19
+
20
+ function register() external returns(uint256 nftId);
21
+
22
+ function getNftId() external view returns(uint256 nftId);
23
+ function getParentNftId() external view returns(uint256 parentNftId);
24
+ function getType() external view returns(uint256 objectType);
25
+ function getData() external view returns(bytes memory data);
26
+ function isRegisterable() external pure returns(bool);
27
+ function getInitialOwner() external view returns(address initialOwner);
28
+
29
+ function isRegistered() external view returns(bool);
30
+ }
31
+
32
+
33
+ interface IRegistry {
34
+
35
+ struct RegistryInfo {
36
+ uint256 nftId;
37
+ uint256 parentNftId;
38
+ uint256 objectType;
39
+ address objectAddress;
40
+ address initialOwner;
41
+ }
42
+
43
+ function TOKEN() external pure returns(uint256);
44
+ function INSTANCE() external pure returns(uint256);
45
+ function PRODUCT() external pure returns(uint256);
46
+ function ORACLE() external pure returns(uint256);
47
+ function POOL() external pure returns(uint256);
48
+ function POLICY() external pure returns(uint256);
49
+ function BUNDLE() external pure returns(uint256);
50
+
51
+ function register(address objectAddress) external returns(uint256 nftId);
52
+ function registerObjectForInstance(
53
+ uint256 parentNftid,
54
+ uint256 objectType,
55
+ address initialOwner
56
+ )
57
+ external returns(uint256 nftId);
58
+
59
+ function transfer(uint256 nftId, address newOwner) external;
60
+
61
+ function getNftId(address objectAddress) external view returns(uint256 nftId);
62
+ function getInfo(uint256 nftId) external view returns(RegistryInfo memory info);
63
+ function getOwner(uint256 nftId) external view returns(address ownerAddress);
64
+
65
+ function isRegistered(address objectAddress) external view returns(bool);
66
+ }
@@ -0,0 +1,197 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IRegistry, IRegistryLinked, IRegisterable} from "./IRegistry.sol";
5
+
6
+ contract RegistryLinked is IRegistryLinked {
7
+
8
+ IRegistry internal _registry;
9
+
10
+ constructor(address registry) {
11
+ _registry = IRegistry(registry);
12
+ }
13
+
14
+ // function setRegistry(address registry) public override {
15
+ // require(address(_registry) == address(0), "ERROR:RGL-001:REGISTRY_ALREADY_SET");
16
+ // _registry = IRegistry(registry);
17
+ // }
18
+
19
+ function getRegistry() external view override returns(IRegistry registry) {
20
+ return _registry;
21
+ }
22
+
23
+ }
24
+
25
+
26
+ abstract contract Registerable is
27
+ RegistryLinked,
28
+ IRegisterable
29
+ {
30
+
31
+ address private _initialOwner;
32
+
33
+ constructor(address registry)
34
+ RegistryLinked(registry)
35
+ {
36
+ _initialOwner = msg.sender;
37
+ }
38
+
39
+ // getType, getData and register need to be implemented by concrete contract
40
+
41
+ function isRegisterable() external pure override returns(bool) {
42
+ return true;
43
+ }
44
+
45
+ function getInitialOwner() public view override returns(address deployer) {
46
+ return _initialOwner;
47
+ }
48
+
49
+ function isRegistered() public view override returns(bool) {
50
+ return _registry.getNftId(address(this)) > 0;
51
+ }
52
+
53
+ function getNftId() public view override returns(uint256 id) {
54
+ return _registry.getNftId(address(this));
55
+ }
56
+
57
+ function getOwner() public view override returns(address owner) {
58
+ uint256 id = _registry.getNftId(address(this));
59
+ owner = _registry.getOwner(id);
60
+ return owner != address(0) ? owner : _initialOwner;
61
+ }
62
+
63
+ }
64
+
65
+ // struct RegistryInfo {
66
+ // bytes32 id;
67
+ // uint256 objectType;
68
+ // address objectAddress;
69
+ // address initialOwner;
70
+ // }
71
+
72
+ contract Registry is IRegistry {
73
+
74
+ mapping(uint256 id => RegistryInfo info) private _info;
75
+ mapping(uint256 id => address owner) private _owner;
76
+ mapping(address object => uint256 id) private _idByAddress;
77
+ uint256 [] private _ids;
78
+ uint256 private _idNext;
79
+
80
+
81
+ constructor() {
82
+ _idNext = 0;
83
+ }
84
+
85
+ function TOKEN() public pure override returns(uint256) { return 30; }
86
+ function INSTANCE() public pure override returns(uint256) { return 40; }
87
+ function PRODUCT() public pure override returns(uint256) { return 50; }
88
+ function ORACLE() public pure override returns(uint256) { return 60; }
89
+ function POOL() public pure override returns(uint256) { return 70; }
90
+ function POLICY() public pure override returns(uint256) { return 80; }
91
+ function BUNDLE() public pure override returns(uint256) { return 90; }
92
+
93
+ function register(address objectAddress) external override returns(uint256 nftId) {
94
+ require(_idByAddress[objectAddress] == 0, "ERROR:REG-001:ALREADY_REGISTERED");
95
+
96
+ IRegisterable registerable = IRegisterable(objectAddress);
97
+ require(registerable.isRegisterable(), "ERROR:REG-002:NOT_REGISTERABLE");
98
+
99
+ // check parent exists (for objects not instances)
100
+ if(registerable.getType() != INSTANCE()) {
101
+ RegistryInfo memory parentInfo = _info[registerable.getParentNftId()];
102
+ require(parentInfo.nftId > 0, "ERROR:REG-003:PARENT_NOT_FOUND");
103
+ // check validity of parent relation, valid relations are
104
+ // policy -> product, bundle -> pool, product -> instance, pool -> instance
105
+ }
106
+
107
+ nftId = _mint(registerable.getInitialOwner());
108
+
109
+ RegistryInfo memory info = RegistryInfo(
110
+ nftId,
111
+ registerable.getParentNftId(),
112
+ registerable.getType(),
113
+ objectAddress,
114
+ registerable.getInitialOwner()
115
+ );
116
+
117
+ _info[nftId] = info;
118
+ _idByAddress[objectAddress] = nftId;
119
+
120
+ // add logging
121
+ }
122
+
123
+
124
+ function registerObjectForInstance(
125
+ uint256 parentNftId,
126
+ uint256 objectType,
127
+ address initialOwner
128
+ )
129
+ external
130
+ override
131
+ // TODO add onlyRegisteredInstance
132
+ returns(uint256 nftId)
133
+ {
134
+ // TODO add more validation
135
+ require(
136
+ objectType == POLICY() || objectType == BUNDLE(),
137
+ "ERROR:REG-005:TYPE_INVALID");
138
+
139
+ nftId = _mint(initialOwner);
140
+
141
+ RegistryInfo memory info = RegistryInfo(
142
+ nftId,
143
+ parentNftId,
144
+ objectType,
145
+ address(0),
146
+ initialOwner
147
+ );
148
+
149
+ _info[nftId] = info;
150
+
151
+ // add logging
152
+ }
153
+
154
+
155
+ function transfer(uint256 id, address newOwner) external {
156
+ require(msg.sender == _owner[id], "ERROR:REG-010:NOT_OWNER");
157
+ _owner[id] = newOwner;
158
+
159
+ // TODO logging
160
+ }
161
+
162
+
163
+ function getObjectCount() external view returns(uint256) {
164
+ return _ids.length;
165
+ }
166
+
167
+
168
+ function getNftId(address object) external view override returns(uint256 id) {
169
+ return _idByAddress[object];
170
+ }
171
+
172
+
173
+ function isRegistered(address object) external view override returns(bool) {
174
+ return _idByAddress[object] > 0;
175
+ }
176
+
177
+
178
+ function getInfo(uint256 id) external view override returns(RegistryInfo memory info) {
179
+ return _info[id];
180
+ }
181
+
182
+ function getOwner(uint256 id) external view override returns(address) {
183
+ return _owner[id];
184
+ }
185
+
186
+
187
+ function _mint(address initialOwner)
188
+ internal
189
+ returns(uint256 id)
190
+ {
191
+ _idNext++;
192
+
193
+ id = _idNext;
194
+ _owner[id] = initialOwner;
195
+ _ids.push(id);
196
+ }
197
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ // bytes5 allows for chain ids up to 13 digits
5
+ type ChainId is bytes5;
6
+
7
+ // type bindings
8
+ using {
9
+ eqChainId as ==,
10
+ neChainId as !=,
11
+ ChainIdLib.toInt
12
+ } for ChainId global;
13
+
14
+ // general pure free functions
15
+ function toChainId(uint256 chainId) pure returns(ChainId) { return ChainId.wrap(bytes5(uint40(chainId))); }
16
+
17
+ // pure free functions for operators
18
+ function eqChainId(ChainId a, ChainId b) pure returns(bool isSame) { return ChainId.unwrap(a) == ChainId.unwrap(b); }
19
+ function neChainId(ChainId a, ChainId b) pure returns(bool isDifferent) { return ChainId.unwrap(a) != ChainId.unwrap(b); }
20
+
21
+ // library functions that operate on user defined type
22
+ library ChainIdLib {
23
+ function toInt(ChainId chainId) internal pure returns(uint256) { return uint256(uint40(ChainId.unwrap(chainId))); }
24
+ }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@etherisc/gif-next",
3
- "version": "0.0.2-ebbe63d",
3
+ "version": "0.0.2-f9905e1",
4
4
  "description": "This is the repository for the next version of the Generic Insurance Framework (GIF) smart contracts. ",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "build": "hardhat compile",
8
- "test": "hardhat test",
9
- "ptest": "hardhat test --parallel",
10
- "test-with-gas": "REPORT_GAS=true hardhat test",
11
- "coverage": "hardhat coverage"
7
+ "build": "hh compile",
8
+ "test": "hh test",
9
+ "ptest": "hh test --parallel",
10
+ "test-with-gas": "REPORT_GAS=true hh test",
11
+ "coverage": "hh coverage"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
@@ -27,6 +27,7 @@
27
27
  "devDependencies": {
28
28
  "@nomicfoundation/hardhat-foundry": "^1.0.3",
29
29
  "@nomicfoundation/hardhat-toolbox": "^3.0.0",
30
+ "dotenv": "^16.3.1",
30
31
  "hardhat": "^2.17.1"
31
32
  },
32
33
  "dependencies": {
@@ -1,4 +0,0 @@
1
- {
2
- "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../build-info/d6ddc31c8d0f29d05ebcf7dbd3184aca.json"
4
- }