@etherisc/gif-next 0.0.2-b9b3e89 → 0.0.2-c4efd5e

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