@etherisc/gif-next 0.0.2-9141c0d → 0.0.2-a380f15

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.
Files changed (147) 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 +213 -0
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
  13. package/artifacts/contracts/components/Product.sol/Product.json +231 -0
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
  24. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
  25. package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
  27. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
  28. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
  30. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
  32. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
  34. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
  35. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
  36. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
  37. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
  38. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +4 -0
  39. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +892 -0
  40. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +4 -0
  41. package/artifacts/contracts/instance/Instance.sol/Instance.json +1067 -0
  42. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +4 -0
  43. package/artifacts/contracts/instance/access/Access.sol/AccessModule.json +400 -0
  44. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +4 -0
  45. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.json +10 -0
  46. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +4 -0
  47. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.json +35 -0
  48. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +4 -0
  49. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.json +50 -0
  50. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +4 -0
  51. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.json +336 -0
  52. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +4 -0
  53. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +327 -0
  54. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +4 -0
  55. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +147 -0
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +4 -0
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.json +10 -0
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +4 -0
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +179 -0
  60. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +4 -0
  61. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +245 -0
  62. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +4 -0
  63. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +94 -0
  64. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +4 -0
  65. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.json +24 -0
  66. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +4 -0
  67. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.json +10 -0
  68. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +4 -0
  69. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +231 -0
  70. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +4 -0
  71. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +231 -0
  72. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +4 -0
  73. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.json +10 -0
  74. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +4 -0
  75. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +149 -0
  76. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +4 -0
  77. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +162 -0
  78. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +4 -0
  79. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.json +75 -0
  80. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +4 -0
  81. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +114 -0
  82. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +4 -0
  83. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.json +75 -0
  84. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +4 -0
  85. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +167 -0
  86. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  87. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
  88. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
  89. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
  90. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +4 -0
  91. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.json +24 -0
  92. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +4 -0
  93. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +166 -0
  94. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +4 -0
  95. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +279 -0
  96. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +4 -0
  97. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.json +49 -0
  98. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +4 -0
  99. package/artifacts/contracts/registry/Registry.sol/Registerable.json +166 -0
  100. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +4 -0
  101. package/artifacts/contracts/registry/Registry.sol/Registry.json +347 -0
  102. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +4 -0
  103. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +60 -0
  104. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  105. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  106. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  107. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
  108. package/contracts/components/Component.sol +62 -0
  109. package/contracts/components/IPool.sol +9 -0
  110. package/contracts/components/IProduct.sol +12 -0
  111. package/contracts/components/Pool.sol +29 -0
  112. package/contracts/components/Product.sol +66 -0
  113. package/contracts/experiment/errors/Require.sol +33 -0
  114. package/contracts/experiment/errors/Revert.sol +39 -0
  115. package/contracts/experiment/inheritance/A.sol +56 -0
  116. package/contracts/experiment/inheritance/B.sol +23 -0
  117. package/contracts/experiment/inheritance/C.sol +28 -0
  118. package/contracts/experiment/inheritance/IA.sol +18 -0
  119. package/contracts/experiment/inheritance/IB.sol +9 -0
  120. package/contracts/experiment/inheritance/IC.sol +11 -0
  121. package/contracts/experiment/types/TypeA.sol +42 -0
  122. package/contracts/experiment/types/TypeB.sol +24 -0
  123. package/contracts/instance/IInstance.sol +20 -0
  124. package/contracts/instance/Instance.sol +64 -0
  125. package/contracts/instance/access/Access.sol +218 -0
  126. package/contracts/instance/access/IAccess.sol +83 -0
  127. package/contracts/instance/component/ComponentModule.sol +248 -0
  128. package/contracts/instance/component/IComponent.sol +95 -0
  129. package/contracts/instance/policy/IPolicy.sol +66 -0
  130. package/contracts/instance/policy/PolicyModule.sol +107 -0
  131. package/contracts/instance/pool/IPoolModule.sol +41 -0
  132. package/contracts/instance/pool/PoolModule.sol +86 -0
  133. package/contracts/instance/product/IProductService.sol +46 -0
  134. package/contracts/instance/product/ProductService.sol +108 -0
  135. package/contracts/registry/ChainNft.sol +173 -0
  136. package/contracts/registry/IChainNft.sol +18 -0
  137. package/contracts/registry/IRegistry.sol +70 -0
  138. package/contracts/registry/Registry.sol +182 -0
  139. package/contracts/types/ChainId.sol +30 -0
  140. package/contracts/types/NftId.sol +35 -0
  141. package/package.json +7 -6
  142. package/artifacts/contracts/Dip.sol/DIP.dbg.json +0 -4
  143. package/artifacts/contracts/Dip.sol/DIP.json +0 -338
  144. package/artifacts/contracts/Lock.sol/Lock.dbg.json +0 -4
  145. package/artifacts/contracts/Lock.sol/Lock.json +0 -74
  146. package/contracts/Dip.sol +0 -26
  147. package/contracts/Lock.sol +0 -34
@@ -0,0 +1,107 @@
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
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
11
+
12
+ abstract contract PolicyModule is
13
+ IRegistryLinked,
14
+ IPolicyModule
15
+ {
16
+ using NftIdLib for NftId;
17
+
18
+ mapping(NftId nftId => PolicyInfo info) private _policyInfo;
19
+ mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
20
+
21
+ IProductService private _productService;
22
+
23
+ // TODO find a better place to avoid dupliation
24
+ modifier onlyProductService2() {
25
+ require(address(_productService) == msg.sender, "ERROR:POL-001:NOT_PRODUCT_SERVICE");
26
+ _;
27
+ }
28
+
29
+ constructor(address productService) {
30
+ _productService = IProductService(productService);
31
+ }
32
+
33
+
34
+ function createApplication(
35
+ IRegistry.RegistryInfo memory productInfo,
36
+ address applicationOwner,
37
+ uint256 sumInsuredAmount,
38
+ uint256 premiumAmount,
39
+ uint256 lifetime,
40
+ NftId bundleNftId
41
+ )
42
+ external
43
+ override
44
+ onlyProductService2
45
+ returns(NftId nftId)
46
+ {
47
+ // TODO add parameter validation
48
+ if(bundleNftId.gtz()) {
49
+ IRegistry.RegistryInfo memory bundleInfo = this.getRegistry().getInfo(bundleNftId);
50
+ // IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
51
+ }
52
+
53
+ nftId = this.getRegistry().registerObjectForInstance(
54
+ productInfo.nftId,
55
+ this.getRegistry().POLICY(),
56
+ applicationOwner);
57
+
58
+ _policyInfo[nftId] = PolicyInfo(
59
+ nftId,
60
+ PolicyState.Applied,
61
+ sumInsuredAmount,
62
+ premiumAmount,
63
+ lifetime,
64
+ block.timestamp,
65
+ 0, // activatedAt
66
+ 0, // expiredAt
67
+ 0 // closedAt
68
+ );
69
+
70
+ _bundleForPolicy[nftId] = bundleNftId;
71
+
72
+ // add logging
73
+ }
74
+
75
+
76
+ function activate(NftId nftId)
77
+ external
78
+ override
79
+ onlyProductService2
80
+ {
81
+ PolicyInfo storage info = _policyInfo[nftId];
82
+ info.activatedAt = block.timestamp;
83
+ info.expiredAt = block.timestamp + info.lifetime;
84
+ info.state = PolicyState.Active;
85
+
86
+ // add logging
87
+ }
88
+
89
+
90
+
91
+ function getBundleNftForPolicy(NftId nftId)
92
+ external
93
+ view
94
+ returns(NftId bundleNft)
95
+ {
96
+ return _bundleForPolicy[nftId];
97
+ }
98
+
99
+
100
+ function getPolicyInfo(NftId nftId)
101
+ external
102
+ view
103
+ returns(PolicyInfo memory info)
104
+ {
105
+ return _policyInfo[nftId];
106
+ }
107
+ }
@@ -0,0 +1,41 @@
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 {NftId} from "../../types/NftId.sol";
6
+
7
+ interface IPool {
8
+
9
+ struct PoolInfo {
10
+ NftId nftId;
11
+ address wallet;
12
+ address token;
13
+ uint256 capital;
14
+ uint256 lockedCapital;
15
+ }
16
+ }
17
+
18
+ interface IPoolModule is
19
+ IOwnable,
20
+ IRegistryLinked,
21
+ IPool
22
+ {
23
+
24
+ function underwrite(
25
+ NftId poolNftId,
26
+ NftId policyNftId
27
+ )
28
+ external;
29
+
30
+ function createPoolInfo(
31
+ NftId nftId,
32
+ address wallet,
33
+ address token
34
+ )
35
+ external;
36
+
37
+ function getPoolInfo(NftId nftId)
38
+ external
39
+ view
40
+ returns(PoolInfo memory info);
41
+ }
@@ -0,0 +1,86 @@
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
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
9
+
10
+ abstract contract PoolModule is
11
+ IPoolModule
12
+ {
13
+ using NftIdLib for NftId;
14
+
15
+ uint256 public constant INITIAL_CAPITAL = 10000*10**6;
16
+
17
+ mapping(NftId nftId => PoolInfo info) private _poolInfo;
18
+
19
+ IProductService private _productService;
20
+
21
+ modifier onlyProductService() {
22
+ require(address(_productService) == msg.sender, "ERROR:POL-001:NOT_PRODUCT_SERVICE");
23
+ _;
24
+ }
25
+
26
+ constructor(address productService) {
27
+ _productService = IProductService(productService);
28
+ }
29
+
30
+ function createPoolInfo(
31
+ NftId nftId,
32
+ address wallet,
33
+ address token
34
+ )
35
+ public
36
+ override
37
+ {
38
+ require(
39
+ _poolInfo[nftId].nftId.eqz(),
40
+ "ERROR:PL-001:ALREADY_CREATED");
41
+
42
+ _poolInfo[nftId] = PoolInfo(
43
+ nftId,
44
+ wallet,
45
+ token,
46
+ INITIAL_CAPITAL,
47
+ 0 // locked capital
48
+ );
49
+
50
+ }
51
+
52
+
53
+ function underwrite(
54
+ NftId poolNftId,
55
+ NftId policyNftId
56
+ )
57
+ external
58
+ override
59
+ onlyProductService
60
+ {
61
+ PoolInfo storage poolInfo = _poolInfo[poolNftId];
62
+ require(
63
+ poolInfo.nftId == poolNftId,
64
+ "ERROR:PL-002:POOL_UNKNOWN");
65
+
66
+ IPolicyModule policyModule = IPolicyModule(address(this));
67
+ IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(policyNftId);
68
+
69
+ require(
70
+ poolInfo.capital - poolInfo.lockedCapital >= policyInfo.sumInsuredAmount,
71
+ "ERROR:PL-003:CAPACITY_TOO_LOW");
72
+
73
+ poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
74
+ }
75
+
76
+
77
+ function getPoolInfo(NftId nftId)
78
+ external
79
+ view
80
+ override
81
+ returns(PoolInfo memory info)
82
+ {
83
+ info = _poolInfo[nftId];
84
+ }
85
+
86
+ }
@@ -0,0 +1,46 @@
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
+ import {NftId} from "../../types/NftId.sol";
8
+
9
+
10
+ // TODO or name this IProtectionService to have Product be something more generic (loan, savings account, ...)
11
+ interface IProductService is
12
+ IRegistryLinked
13
+ {
14
+
15
+ function createApplication(
16
+ address applicationOwner,
17
+ uint256 sumInsuredAmount,
18
+ uint256 premiumAmount,
19
+ uint256 lifetime,
20
+ NftId bundleNftId
21
+ )
22
+ external
23
+ returns(NftId nftId);
24
+
25
+ // function revoke(unit256 nftId) external;
26
+
27
+ function underwrite(NftId nftId) external;
28
+ // function decline(uint256 nftId) external;
29
+ // function expire(uint256 nftId) external;
30
+ function close(NftId nftId) external;
31
+
32
+ // function collectPremium(uint256 nftId, uint256 premiumAmount) external;
33
+
34
+ // function createClaim(uint256 nftId, uint256 claimAmount) external;
35
+ // function confirmClaim(uint256 nftId, uint256 claimId, uint256 claimAmount) external;
36
+ // function declineClaim(uint256 nftId, uint256 claimId) external;
37
+ // function closeClaim(uint256 nftId, uint256 claimId) external;
38
+ }
39
+
40
+
41
+ interface IProductModule is
42
+ IOwnable,
43
+ IRegistryLinked
44
+ {
45
+ function getProductService() external view returns(IProductService);
46
+ }
@@ -0,0 +1,108 @@
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
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
15
+
16
+ // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
17
+ contract ProductService is
18
+ RegistryLinked,
19
+ IProductService
20
+ {
21
+ using NftIdLib for NftId;
22
+
23
+ constructor(address registry)
24
+ RegistryLinked(registry)
25
+ { }
26
+
27
+
28
+ function createApplication(
29
+ address applicationOwner,
30
+ uint256 sumInsuredAmount,
31
+ uint256 premiumAmount,
32
+ uint256 lifetime,
33
+ NftId bundleNftId
34
+ )
35
+ external
36
+ override
37
+ returns(NftId nftId)
38
+ {
39
+ // same as only registered product
40
+ NftId productNftId = _registry.getNftId(msg.sender);
41
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
42
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
43
+ require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
44
+
45
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
46
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
47
+ require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
48
+
49
+ IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
50
+ nftId = policyModule.createApplication(
51
+ productInfo,
52
+ applicationOwner,
53
+ sumInsuredAmount,
54
+ premiumAmount,
55
+ lifetime,
56
+ bundleNftId);
57
+
58
+ // add logging
59
+ }
60
+
61
+ function underwrite(NftId nftId)
62
+ external
63
+ override
64
+ {
65
+ // same as only registered product
66
+ NftId productNftId = _registry.getNftId(msg.sender);
67
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
68
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
69
+ require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
70
+
71
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
72
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
73
+ require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
74
+
75
+ // get responsible pool
76
+ IComponentModule componentModule = IComponentModule(instanceInfo.objectAddress);
77
+ NftId poolNftId = componentModule.getPoolNftId(productNftId);
78
+
79
+ // lock capital (and update pool accounting)
80
+ IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
81
+ poolModule.underwrite(
82
+ poolNftId,
83
+ nftId);
84
+
85
+ // activate policy
86
+ IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
87
+ policyModule.activate(nftId);
88
+
89
+ // add logging
90
+ }
91
+
92
+ function close(NftId nftId) external override {}
93
+ }
94
+
95
+ abstract contract ProductModule is
96
+ IProductModule
97
+ {
98
+ IProductService private _productService;
99
+
100
+ constructor(address productService) {
101
+ _productService = IProductService(productService);
102
+ }
103
+
104
+ function getProductService() external view returns(IProductService) {
105
+ return _productService;
106
+ }
107
+
108
+ }
@@ -0,0 +1,173 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {ERC721, ERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
5
+ import {IChainNft} from "./IChainNft.sol";
6
+
7
+ contract ChainNft is
8
+ ERC721Enumerable,
9
+ IChainNft
10
+ {
11
+ string public constant NAME = "Dezentralized Insurance Protocol Registry";
12
+ string public constant SYMBOL = "DIPR";
13
+
14
+ // remember token uri
15
+ mapping(uint256 tokenId => string uri) private _uri;
16
+
17
+ // remember registry
18
+ address private _registry;
19
+
20
+ // only used for _getNextTokenId
21
+ uint256 internal _chainIdInt;
22
+ uint256 internal _chainIdDigits;
23
+ uint256 internal _chainIdMultiplier;
24
+ uint256 internal _idNext;
25
+ uint256 internal _totalMinted;
26
+
27
+
28
+ modifier onlyRegistry() {
29
+ require(msg.sender == _registry, "ERROR:NFT-001:CALLER_NOT_REGISTRY");
30
+ _;
31
+ }
32
+
33
+
34
+ constructor(address registry)
35
+ ERC721(NAME, SYMBOL)
36
+ {
37
+ require(registry != address(0), "ERROR:NFT-010:REGISTRY_ZERO");
38
+
39
+ _registry = registry;
40
+
41
+ _chainIdInt = block.chainid;
42
+ _chainIdDigits = _countDigits(_chainIdInt);
43
+ _chainIdMultiplier = 10 ** _chainIdDigits;
44
+
45
+ // on mainnet/goerli start /1 (reserved for protocol nft) on other chains with 2
46
+ if(block.chainid == 1 || block.chainid == 5) {
47
+ _idNext = 1;
48
+ } else {
49
+ _idNext = 2;
50
+ }
51
+ }
52
+
53
+
54
+ function mint(
55
+ address to,
56
+ string memory uri
57
+ )
58
+ external
59
+ override
60
+ onlyRegistry
61
+ returns(uint256 tokenId)
62
+ {
63
+ tokenId = _getNextTokenId();
64
+ _totalMinted++;
65
+
66
+ _safeMint(to, tokenId);
67
+
68
+ if(bytes(uri).length > 0) {
69
+ _uri[tokenId] = uri;
70
+ }
71
+ }
72
+
73
+
74
+ function burn(uint256 tokenId)
75
+ external
76
+ override
77
+ onlyRegistry
78
+ {
79
+ _requireMinted(tokenId);
80
+ _burn(tokenId);
81
+ delete _uri[tokenId];
82
+ }
83
+
84
+
85
+ function setURI(uint256 tokenId, string memory uri)
86
+ external
87
+ override
88
+ onlyRegistry
89
+ {
90
+ require(bytes(uri).length > 0, "ERROR:CRG-011:URI_EMPTY");
91
+
92
+ _requireMinted(tokenId);
93
+ _uri[tokenId] = uri;
94
+ }
95
+
96
+
97
+ function exists(uint256 tokenId)
98
+ external
99
+ view
100
+ override
101
+ returns(bool)
102
+ {
103
+ return _exists(tokenId);
104
+ }
105
+
106
+
107
+ function tokenURI(uint256 tokenId)
108
+ public
109
+ view
110
+ override
111
+ returns(string memory)
112
+ {
113
+ _requireMinted(tokenId);
114
+ return _uri[tokenId];
115
+ }
116
+
117
+
118
+ function getRegistryAddress()
119
+ external
120
+ view
121
+ override
122
+ returns(address)
123
+ {
124
+ return _registry;
125
+ }
126
+
127
+ function totalMinted() external override view returns(uint256) {
128
+ return _totalMinted;
129
+ }
130
+
131
+ // requirement: each chain registry produces token ids that
132
+ // are guaranteed to not collide with any token id genereated
133
+ // on a different chain
134
+ //
135
+ // format concat(counter,chainid,2 digits for len-of-chain-id)
136
+ // restriction chainid up to 99 digits
137
+ // decode: from right to left:
138
+ // - 2 right most digits encode length of chainid
139
+ // - move number of digits to left as determined above (-> chainid)
140
+ // - the reminder to the left is the counter
141
+ // examples
142
+ // 1101
143
+ // ^^ ^
144
+ // || +- 1-digit chain id
145
+ // |+-- chain id = 1 (mainnet)
146
+ // +-- 1st token id on mainnet
147
+ // (1 * 10 ** 1 + 1) * 100 + 1
148
+ // 42987654321010
149
+ // ^ ^ ^
150
+ // | | +- 10-digit chain id
151
+ // | +-- chain id = 9876543210 (hypothetical chainid)
152
+ // +-- 42nd token id on this chain
153
+ // (42 * 10 ** 10 + 9876543210) * 100 + 10
154
+ // (index * 10 ** digits + chainid) * 100 + digits (1 < digits < 100)
155
+
156
+ function _getNextTokenId() private returns(uint256 id) {
157
+ id = (_idNext * _chainIdMultiplier + _chainIdInt) * 100 + _chainIdDigits;
158
+ _idNext++;
159
+ }
160
+
161
+
162
+ function _countDigits(uint256 num)
163
+ private
164
+ pure
165
+ returns (uint256 count)
166
+ {
167
+ count = 0;
168
+ while (num != 0) {
169
+ count++;
170
+ num /= 10;
171
+ }
172
+ }
173
+ }
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
5
+
6
+ interface IChainNft is
7
+ IERC721Enumerable
8
+ {
9
+
10
+ function mint(address to, string memory uri) external returns(uint256 tokenId);
11
+ function burn(uint256 tokenId) external;
12
+ function setURI(uint256 tokenId, string memory uri) external;
13
+
14
+ function exists(uint256 tokenId) external view returns(bool);
15
+ function totalMinted() external view returns(uint256);
16
+
17
+ function getRegistryAddress() external view returns(address registry);
18
+ }
@@ -0,0 +1,70 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {NftId} from "../types/NftId.sol";
5
+
6
+ interface IOwnable {
7
+ function getOwner() external view returns(address owner);
8
+ }
9
+
10
+ interface IRegistryLinked {
11
+
12
+ event LogDebug(uint256 idx, address module, string comment);
13
+
14
+ function getRegistry() external view returns(IRegistry registry);
15
+ }
16
+
17
+ interface IRegisterable is
18
+ IOwnable,
19
+ IRegistryLinked
20
+ {
21
+
22
+ function register() external returns(NftId nftId);
23
+
24
+ function getNftId() external view returns(NftId nftId);
25
+ function getParentNftId() external view returns(NftId parentNftId);
26
+ function getType() external view returns(uint256 objectType);
27
+ function getData() external view returns(bytes memory data);
28
+ function isRegisterable() external pure returns(bool);
29
+ function getInitialOwner() external view returns(address initialOwner);
30
+
31
+ function isRegistered() external view returns(bool);
32
+ }
33
+
34
+
35
+ interface IRegistry {
36
+
37
+ struct RegistryInfo {
38
+ NftId nftId;
39
+ NftId parentNftId;
40
+ uint256 objectType;
41
+ address objectAddress;
42
+ address initialOwner;
43
+ }
44
+
45
+ function TOKEN() external pure returns(uint256);
46
+ function INSTANCE() external pure returns(uint256);
47
+ function PRODUCT() external pure returns(uint256);
48
+ function ORACLE() external pure returns(uint256);
49
+ function POOL() external pure returns(uint256);
50
+ function POLICY() external pure returns(uint256);
51
+ function BUNDLE() external pure returns(uint256);
52
+
53
+ function register(address objectAddress) external returns(NftId nftId);
54
+ function registerObjectForInstance(
55
+ NftId parentNftid,
56
+ uint256 objectType,
57
+ address initialOwner
58
+ )
59
+ external returns(NftId nftId);
60
+
61
+ function getObjectCount() external view returns(uint256);
62
+
63
+ function getNftId(address objectAddress) external view returns(NftId nftId);
64
+ function getInfo(NftId nftId) external view returns(RegistryInfo memory info);
65
+ function getOwner(NftId nftId) external view returns(address ownerAddress);
66
+
67
+ function isRegistered(address objectAddress) external view returns(bool);
68
+
69
+ function getNftAddress() external view returns(address nft);
70
+ }