@etherisc/gif-next 0.0.2-ad36bbd → 0.0.2-cc253b3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  2. package/artifacts/contracts/components/Component.sol/Component.json +7 -7
  3. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
  4. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
  5. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +6 -6
  7. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +8 -8
  9. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  10. package/artifacts/contracts/components/Pool.sol/Pool.json +29 -11
  11. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  12. package/artifacts/contracts/components/Product.sol/Product.json +31 -13
  13. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
  15. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
  17. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
  19. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
  21. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
  29. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
  31. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  32. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +60 -60
  33. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  34. package/artifacts/contracts/instance/Instance.sol/Instance.json +114 -64
  35. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  36. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  37. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  38. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  39. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  40. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  41. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +24 -24
  42. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  43. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +48 -6
  44. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  45. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  46. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +6 -6
  47. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  48. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +26 -26
  49. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  50. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +3 -3
  51. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  52. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  53. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  54. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +18 -18
  55. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  56. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +18 -18
  57. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  58. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  59. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +10 -10
  60. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  61. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +10 -10
  62. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  63. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  64. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +8 -8
  65. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  66. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  67. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +54 -12
  68. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  69. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  70. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  71. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  72. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  73. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +6 -6
  74. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  75. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +16 -16
  76. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  77. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  78. package/artifacts/contracts/registry/Registry.sol/Registerable.json +7 -7
  79. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  80. package/artifacts/contracts/registry/Registry.sol/Registry.json +62 -20
  81. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  82. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  83. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  84. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
  85. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  86. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +61 -3
  87. package/contracts/components/Component.sol +3 -3
  88. package/contracts/components/IProduct.sol +2 -1
  89. package/contracts/components/Product.sol +5 -4
  90. package/contracts/experiment/errors/Require.sol +2 -2
  91. package/contracts/instance/Instance.sol +4 -3
  92. package/contracts/instance/component/ComponentModule.sol +32 -43
  93. package/contracts/instance/component/IComponent.sol +11 -10
  94. package/contracts/instance/policy/IPolicy.sol +8 -8
  95. package/contracts/instance/policy/PolicyModule.sol +12 -11
  96. package/contracts/instance/pool/IPoolModule.sol +6 -5
  97. package/contracts/instance/pool/PoolModule.sol +9 -6
  98. package/contracts/instance/product/IProductService.sol +5 -4
  99. package/contracts/instance/product/ProductService.sol +14 -11
  100. package/contracts/registry/IRegistry.sol +13 -11
  101. package/contracts/registry/Registry.sol +28 -22
  102. package/contracts/types/NftId.sol +3 -2
  103. package/package.json +1 -1
@@ -9,7 +9,7 @@ import {IInstance} from "../IInstance.sol";
9
9
  import {IComponent, IComponentContract, IComponentModule, IComponentOwnerService} from "./IComponent.sol";
10
10
  import {IProductComponent} from "../../components/IProduct.sol";
11
11
  import {IPoolModule} from "../pool/IPoolModule.sol";
12
-
12
+ import {NftId, NftIdLib, eqNftId} from "../../types/NftId.sol";
13
13
 
14
14
  abstract contract ComponentModule is
15
15
  IRegistryLinked,
@@ -17,11 +17,12 @@ abstract contract ComponentModule is
17
17
  IAccessCheckRole,
18
18
  IComponentModule
19
19
  {
20
+ using NftIdLib for NftId;
20
21
 
21
- mapping(uint256 nftId => ComponentInfo info) private _componentInfo;
22
- mapping(uint256 nftId => uint256 poolNftId) private _poolNftIdForProduct;
23
- mapping(address cAddress => uint256 id) private _idByAddress;
24
- uint256 [] private _ids;
22
+ mapping(NftId nftId => ComponentInfo info) private _componentInfo;
23
+ mapping(NftId nftId => NftId poolNftId) private _poolNftIdForProduct;
24
+ mapping(address cAddress => NftId nftId) private _nftIdByAddress;
25
+ NftId[] private _nftIds;
25
26
 
26
27
  mapping(uint256 cType => bytes32 role) private _componentOwnerRole;
27
28
 
@@ -40,7 +41,7 @@ abstract contract ComponentModule is
40
41
  external
41
42
  override
42
43
  onlyComponentOwnerService
43
- returns(uint256 nftId)
44
+ returns(NftId nftId)
44
45
  {
45
46
  bytes32 typeRole = getRoleForType(component.getType());
46
47
  require(
@@ -56,8 +57,8 @@ abstract contract ComponentModule is
56
57
  // special case product -> persist product - pool assignment
57
58
  if(component.getType() == this.getRegistry().PRODUCT()) {
58
59
  IProductComponent product = IProductComponent(address(component));
59
- uint256 poolNftId = product.getPoolNftId();
60
- require(poolNftId > 0, "ERROR:CMP-005:POOL_UNKNOWN");
60
+ NftId poolNftId = product.getPoolNftId();
61
+ require(poolNftId.gtz(), "ERROR:CMP-005:POOL_UNKNOWN");
61
62
  // add more validation (type, token, ...)
62
63
 
63
64
  _poolNftIdForProduct[nftId] = poolNftId;
@@ -73,17 +74,17 @@ abstract contract ComponentModule is
73
74
  );
74
75
  }
75
76
 
76
- _idByAddress[address(component)] = nftId;
77
- _ids.push(nftId);
77
+ _nftIdByAddress[address(component)] = nftId;
78
+ _nftIds.push(nftId);
78
79
 
79
80
  // add logging
80
81
  }
81
82
 
82
- function getPoolNftId(uint256 productNftId)
83
+ function getPoolNftId(NftId productNftId)
83
84
  external
84
85
  view
85
86
  override
86
- returns(uint256 poolNftId)
87
+ returns(NftId poolNftId)
87
88
  {
88
89
  poolNftId = _poolNftIdForProduct[productNftId];
89
90
  }
@@ -101,28 +102,28 @@ abstract contract ComponentModule is
101
102
  function setComponentInfo(ComponentInfo memory info)
102
103
  external
103
104
  onlyComponentOwnerService
104
- returns(uint256 nftId)
105
+ returns(NftId nftId)
105
106
  {
106
- uint256 id = info.nftId;
107
+ nftId = info.nftId;
107
108
  require(
108
- id > 0 && _componentInfo[id].nftId == id,
109
- "ERROR:CMP-005:COMPONENT_UNKNOWN");
109
+ nftId.gtz() && eqNftId(_componentInfo[nftId].nftId, nftId),
110
+ "ERROR:CMP-006:COMPONENT_UNKNOWN");
110
111
 
111
- _componentInfo[id] = info;
112
+ _componentInfo[nftId] = info;
112
113
 
113
114
  // add logging
114
115
  }
115
116
 
116
- function getComponentInfo(uint256 id)
117
+ function getComponentInfo(NftId nftId)
117
118
  external
118
119
  override
119
120
  view
120
121
  returns(ComponentInfo memory)
121
122
  {
122
- return _componentInfo[id];
123
+ return _componentInfo[nftId];
123
124
  }
124
125
 
125
- function getComponentOwner(uint256 id)
126
+ function getComponentOwner(NftId nftId)
126
127
  external
127
128
  view
128
129
  returns(address owner)
@@ -133,9 +134,9 @@ abstract contract ComponentModule is
133
134
  function getComponentId(address componentAddress)
134
135
  external
135
136
  view
136
- returns(uint256 id)
137
+ returns(NftId componentNftId)
137
138
  {
138
- return _idByAddress[componentAddress];
139
+ return _nftIdByAddress[componentAddress];
139
140
  }
140
141
 
141
142
 
@@ -143,9 +144,9 @@ abstract contract ComponentModule is
143
144
  external
144
145
  override
145
146
  view
146
- returns(uint256 id)
147
+ returns(NftId componentNftId)
147
148
  {
148
- return _ids[idx];
149
+ return _nftIds[idx];
149
150
  }
150
151
 
151
152
 
@@ -155,7 +156,7 @@ abstract contract ComponentModule is
155
156
  view
156
157
  returns(uint256 numberOfCompnents)
157
158
  {
158
- return _ids.length;
159
+ return _nftIds.length;
159
160
  }
160
161
 
161
162
  function getRoleForType(uint256 cType)
@@ -183,11 +184,12 @@ contract ComponentOwnerService is
183
184
  IComponent,
184
185
  IComponentOwnerService
185
186
  {
187
+ using NftIdLib for NftId;
186
188
 
187
189
  modifier onlyComponentOwner(IComponentContract component) {
188
- uint256 nftId = _registry.getNftId(address(component));
190
+ NftId nftId = _registry.getNftId(address(component));
189
191
  require(
190
- nftId > 0,
192
+ nftId.gtz(),
191
193
  "ERROR:COS-001:COMPONENT_UNKNOWN");
192
194
  require(
193
195
  msg.sender == _registry.getOwner(nftId),
@@ -200,23 +202,10 @@ contract ComponentOwnerService is
200
202
  RegistryLinked(registry)
201
203
  { }
202
204
 
203
-
204
- // modifier onlyComponentOwnerRole(IComponentContract component) {
205
- // IInstance instance = component.getInstance();
206
- // // TODO add set/getComponentOwnerRole to IComonentModule
207
- // bytes32 typeRole = instance.getComponentTypeRole(component.getType());
208
- // require(
209
- // instance.hasRole(typeRole, msg.sender),
210
- // "ERROR:COS-003:COMPONENT_ROLE_MISSING"
211
- // );
212
- // _;
213
- // }
214
-
215
-
216
205
  function register(IComponentContract component)
217
206
  external
218
207
  override
219
- returns(uint256 nftId)
208
+ returns(NftId nftId)
220
209
  {
221
210
  require(
222
211
  msg.sender == component.getInitialOwner(),
@@ -234,7 +223,7 @@ contract ComponentOwnerService is
234
223
  {
235
224
  IInstance instance = component.getInstance();
236
225
  ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
237
- require(info.nftId > 0, "ERROR_COMPONENT_UNKNOWN");
226
+ require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
238
227
  // TODO add state change validation
239
228
 
240
229
  info.state = CState.Locked;
@@ -249,7 +238,7 @@ contract ComponentOwnerService is
249
238
  {
250
239
  IInstance instance = component.getInstance();
251
240
  ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
252
- require(info.nftId > 0, "ERROR_COMPONENT_UNKNOWN");
241
+ require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
253
242
  // TODO state change validation
254
243
 
255
244
  info.state = CState.Active;
@@ -4,6 +4,7 @@ pragma solidity ^0.8.19;
4
4
 
5
5
  import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
6
6
  import {IInstance} from "../IInstance.sol";
7
+ import {NftId} from "../../types/NftId.sol";
7
8
 
8
9
  interface IComponent {
9
10
 
@@ -16,7 +17,7 @@ interface IComponent {
16
17
 
17
18
  // component dynamic info (static info kept in registry)
18
19
  struct ComponentInfo {
19
- uint256 nftId;
20
+ NftId nftId;
20
21
  CState state;
21
22
  }
22
23
  }
@@ -37,7 +38,7 @@ interface IComponentContract is
37
38
 
38
39
  interface IComponentOwnerService is IRegistryLinked{
39
40
 
40
- function register(IComponentContract component) external returns(uint256 id);
41
+ function register(IComponentContract component) external returns(NftId nftId);
41
42
  function lock(IComponentContract component) external;
42
43
  function unlock(IComponentContract component) external;
43
44
  }
@@ -51,18 +52,18 @@ interface IComponentModule is
51
52
 
52
53
  function registerComponent(IComponentContract component)
53
54
  external
54
- returns(uint256 nftInfo);
55
+ returns(NftId nftId);
55
56
 
56
57
  function setComponentInfo(ComponentInfo memory info)
57
58
  external
58
- returns(uint256 componentId);
59
+ returns(NftId componentNftId);
59
60
 
60
- function getComponentInfo(uint256 id)
61
+ function getComponentInfo(NftId nftId)
61
62
  external
62
63
  view
63
64
  returns(ComponentInfo memory info);
64
65
 
65
- function getComponentOwner(uint256 id)
66
+ function getComponentOwner(NftId nftId)
66
67
  external
67
68
  view
68
69
  returns(address owner);
@@ -70,17 +71,17 @@ interface IComponentModule is
70
71
  function getComponentId(address componentAddress)
71
72
  external
72
73
  view
73
- returns(uint256 id);
74
+ returns(NftId nftId);
74
75
 
75
76
  function getComponentId(uint256 idx)
76
77
  external
77
78
  view
78
- returns(uint256 id);
79
+ returns(NftId nftId);
79
80
 
80
- function getPoolNftId(uint256 productNftId)
81
+ function getPoolNftId(NftId productNftId)
81
82
  external
82
83
  view
83
- returns(uint256 poolNftId);
84
+ returns(NftId poolNftId);
84
85
 
85
86
  function components()
86
87
  external
@@ -4,8 +4,8 @@ pragma solidity ^0.8.19;
4
4
 
5
5
  import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
6
6
  import {IInstance} from "../IInstance.sol";
7
-
8
7
  import {IProductService} from "../product/IProductService.sol";
8
+ import {NftId} from "../../types/NftId.sol";
9
9
 
10
10
  // TODO check if there is value to introuce IContract and let IPolicy derive from IContract
11
11
  interface IPolicy {
@@ -19,7 +19,7 @@ interface IPolicy {
19
19
  }
20
20
 
21
21
  struct PolicyInfo {
22
- uint256 nftId;
22
+ NftId nftId;
23
23
  PolicyState state; // applied, withdrawn, rejected, active, closed
24
24
 
25
25
  uint256 sumInsuredAmount;
@@ -45,20 +45,20 @@ interface IPolicyModule is
45
45
  uint256 sumInsuredAmount,
46
46
  uint256 premiumAmount,
47
47
  uint256 lifetime,
48
- uint256 bundleNftId
48
+ NftId bundleNftId
49
49
  )
50
50
  external
51
- returns(uint256 nftId);
51
+ returns(NftId nftId);
52
52
 
53
- function activate(uint256 nftId)
53
+ function activate(NftId nftId)
54
54
  external;
55
55
 
56
- function getBundleNftForPolicy(uint256 nftId)
56
+ function getBundleNftForPolicy(NftId nftId)
57
57
  external
58
58
  view
59
- returns(uint256 bundleNft);
59
+ returns(NftId bundleNft);
60
60
 
61
- function getPolicyInfo(uint256 nftId)
61
+ function getPolicyInfo(NftId nftId)
62
62
  external
63
63
  view
64
64
  returns(PolicyInfo memory info);
@@ -7,15 +7,16 @@ import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
7
7
 
8
8
  import {IProductService} from "../product/IProductService.sol";
9
9
  import {IPolicy, IPolicyModule} from "./IPolicy.sol";
10
-
10
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
11
11
 
12
12
  abstract contract PolicyModule is
13
13
  IRegistryLinked,
14
14
  IPolicyModule
15
15
  {
16
+ using NftIdLib for NftId;
16
17
 
17
- mapping(uint256 nftId => PolicyInfo info) private _policyInfo;
18
- mapping(uint256 nftId => uint256 bundleNftId) private _bundleForPolicy;
18
+ mapping(NftId nftId => PolicyInfo info) private _policyInfo;
19
+ mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
19
20
 
20
21
  IProductService private _productService;
21
22
 
@@ -36,17 +37,17 @@ abstract contract PolicyModule is
36
37
  uint256 sumInsuredAmount,
37
38
  uint256 premiumAmount,
38
39
  uint256 lifetime,
39
- uint256 bundleNftId
40
+ NftId bundleNftId
40
41
  )
41
42
  external
42
43
  override
43
44
  onlyProductService2
44
- returns(uint256 nftId)
45
+ returns(NftId nftId)
45
46
  {
46
47
  // TODO add parameter validation
47
- if(bundleNftId > 0) {
48
+ if(bundleNftId.gtz()) {
48
49
  IRegistry.RegistryInfo memory bundleInfo = this.getRegistry().getInfo(bundleNftId);
49
- IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
50
+ // IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
50
51
  }
51
52
 
52
53
  nftId = this.getRegistry().registerObjectForInstance(
@@ -72,7 +73,7 @@ abstract contract PolicyModule is
72
73
  }
73
74
 
74
75
 
75
- function activate(uint256 nftId)
76
+ function activate(NftId nftId)
76
77
  external
77
78
  override
78
79
  onlyProductService2
@@ -87,16 +88,16 @@ abstract contract PolicyModule is
87
88
 
88
89
 
89
90
 
90
- function getBundleNftForPolicy(uint256 nftId)
91
+ function getBundleNftForPolicy(NftId nftId)
91
92
  external
92
93
  view
93
- returns(uint256 bundleNft)
94
+ returns(NftId bundleNft)
94
95
  {
95
96
  return _bundleForPolicy[nftId];
96
97
  }
97
98
 
98
99
 
99
- function getPolicyInfo(uint256 nftId)
100
+ function getPolicyInfo(NftId nftId)
100
101
  external
101
102
  view
102
103
  returns(PolicyInfo memory info)
@@ -2,11 +2,12 @@
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
9
  struct PoolInfo {
9
- uint256 nftId;
10
+ NftId nftId;
10
11
  address wallet;
11
12
  address token;
12
13
  uint256 capital;
@@ -21,19 +22,19 @@ interface IPoolModule is
21
22
  {
22
23
 
23
24
  function underwrite(
24
- uint256 poolNftId,
25
- uint256 policyNftId
25
+ NftId poolNftId,
26
+ NftId policyNftId
26
27
  )
27
28
  external;
28
29
 
29
30
  function createPoolInfo(
30
- uint256 nftId,
31
+ NftId nftId,
31
32
  address wallet,
32
33
  address token
33
34
  )
34
35
  external;
35
36
 
36
- function getPoolInfo(uint256 nftId)
37
+ function getPoolInfo(NftId nftId)
37
38
  external
38
39
  view
39
40
  returns(PoolInfo memory info);
@@ -5,13 +5,16 @@ 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
10
  abstract contract PoolModule is
10
11
  IPoolModule
11
12
  {
13
+ using NftIdLib for NftId;
14
+
12
15
  uint256 public constant INITIAL_CAPITAL = 10000*10**6;
13
16
 
14
- mapping(uint256 nftId => PoolInfo info) private _poolInfo;
17
+ mapping(NftId nftId => PoolInfo info) private _poolInfo;
15
18
 
16
19
  IProductService private _productService;
17
20
 
@@ -25,7 +28,7 @@ abstract contract PoolModule is
25
28
  }
26
29
 
27
30
  function createPoolInfo(
28
- uint256 nftId,
31
+ NftId nftId,
29
32
  address wallet,
30
33
  address token
31
34
  )
@@ -33,7 +36,7 @@ abstract contract PoolModule is
33
36
  override
34
37
  {
35
38
  require(
36
- _poolInfo[nftId].nftId == 0,
39
+ _poolInfo[nftId].nftId.eqz(),
37
40
  "ERROR:PL-001:ALREADY_CREATED");
38
41
 
39
42
  _poolInfo[nftId] = PoolInfo(
@@ -48,8 +51,8 @@ abstract contract PoolModule is
48
51
 
49
52
 
50
53
  function underwrite(
51
- uint256 poolNftId,
52
- uint256 policyNftId
54
+ NftId poolNftId,
55
+ NftId policyNftId
53
56
  )
54
57
  external
55
58
  override
@@ -71,7 +74,7 @@ abstract contract PoolModule is
71
74
  }
72
75
 
73
76
 
74
- function getPoolInfo(uint256 nftId)
77
+ function getPoolInfo(NftId nftId)
75
78
  external
76
79
  view
77
80
  override
@@ -4,6 +4,7 @@ pragma solidity ^0.8.19;
4
4
 
5
5
  import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
6
6
  import {IInstance} from "../IInstance.sol";
7
+ import {NftId} from "../../types/NftId.sol";
7
8
 
8
9
 
9
10
  // TODO or name this IProtectionService to have Product be something more generic (loan, savings account, ...)
@@ -16,17 +17,17 @@ interface IProductService is
16
17
  uint256 sumInsuredAmount,
17
18
  uint256 premiumAmount,
18
19
  uint256 lifetime,
19
- uint256 bundleNftId
20
+ NftId bundleNftId
20
21
  )
21
22
  external
22
- returns(uint256 nftId);
23
+ returns(NftId nftId);
23
24
 
24
25
  // function revoke(unit256 nftId) external;
25
26
 
26
- function underwrite(uint256 nftId) external;
27
+ function underwrite(NftId nftId) external;
27
28
  // function decline(uint256 nftId) external;
28
29
  // function expire(uint256 nftId) external;
29
- function close(uint256 nftId) external;
30
+ function close(NftId nftId) external;
30
31
 
31
32
  // function collectPremium(uint256 nftId, uint256 premiumAmount) external;
32
33
 
@@ -11,12 +11,15 @@ import {RegistryLinked} from "../../registry/Registry.sol";
11
11
  import {IProductService, IProductModule} from "./IProductService.sol";
12
12
  import {IComponentModule} from "../../instance/component/IComponent.sol";
13
13
  import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
14
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
14
15
 
15
16
  // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
16
17
  contract ProductService is
17
18
  RegistryLinked,
18
19
  IProductService
19
20
  {
21
+ using NftIdLib for NftId;
22
+
20
23
  constructor(address registry)
21
24
  RegistryLinked(registry)
22
25
  { }
@@ -27,20 +30,20 @@ contract ProductService is
27
30
  uint256 sumInsuredAmount,
28
31
  uint256 premiumAmount,
29
32
  uint256 lifetime,
30
- uint256 bundleNftId
33
+ NftId bundleNftId
31
34
  )
32
35
  external
33
36
  override
34
- returns(uint256 nftId)
37
+ returns(NftId nftId)
35
38
  {
36
39
  // same as only registered product
37
- uint256 productNftId = _registry.getNftId(msg.sender);
38
- require(productNftId > 0, "ERROR_PRODUCT_UNKNOWN");
40
+ NftId productNftId = _registry.getNftId(msg.sender);
41
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
39
42
  IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
40
43
  require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
41
44
 
42
45
  IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
43
- require(instanceInfo.nftId > 0, "ERROR_INSTANCE_UNKNOWN");
46
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
44
47
  require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
45
48
 
46
49
  IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
@@ -55,23 +58,23 @@ contract ProductService is
55
58
  // add logging
56
59
  }
57
60
 
58
- function underwrite(uint256 nftId)
61
+ function underwrite(NftId nftId)
59
62
  external
60
63
  override
61
64
  {
62
65
  // same as only registered product
63
- uint256 productNftId = _registry.getNftId(msg.sender);
64
- require(productNftId > 0, "ERROR_PRODUCT_UNKNOWN");
66
+ NftId productNftId = _registry.getNftId(msg.sender);
67
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
65
68
  IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
66
69
  require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
67
70
 
68
71
  IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
69
- require(instanceInfo.nftId > 0, "ERROR_INSTANCE_UNKNOWN");
72
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
70
73
  require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
71
74
 
72
75
  // get responsible pool
73
76
  IComponentModule componentModule = IComponentModule(instanceInfo.objectAddress);
74
- uint256 poolNftId = componentModule.getPoolNftId(productNftId);
77
+ NftId poolNftId = componentModule.getPoolNftId(productNftId);
75
78
 
76
79
  // lock capital (and update pool accounting)
77
80
  IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
@@ -86,7 +89,7 @@ contract ProductService is
86
89
  // add logging
87
90
  }
88
91
 
89
- function close(uint256 nftId) external override {}
92
+ function close(NftId nftId) external override {}
90
93
  }
91
94
 
92
95
  abstract contract ProductModule is
@@ -1,6 +1,8 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {NftId} from "../types/NftId.sol";
5
+
4
6
  interface IOwnable {
5
7
  function getOwner() external view returns(address owner);
6
8
  }
@@ -17,10 +19,10 @@ interface IRegisterable is
17
19
  IRegistryLinked
18
20
  {
19
21
 
20
- function register() external returns(uint256 nftId);
22
+ function register() external returns(NftId nftId);
21
23
 
22
- function getNftId() external view returns(uint256 nftId);
23
- function getParentNftId() external view returns(uint256 parentNftId);
24
+ function getNftId() external view returns(NftId nftId);
25
+ function getParentNftId() external view returns(NftId parentNftId);
24
26
  function getType() external view returns(uint256 objectType);
25
27
  function getData() external view returns(bytes memory data);
26
28
  function isRegisterable() external pure returns(bool);
@@ -33,8 +35,8 @@ interface IRegisterable is
33
35
  interface IRegistry {
34
36
 
35
37
  struct RegistryInfo {
36
- uint256 nftId;
37
- uint256 parentNftId;
38
+ NftId nftId;
39
+ NftId parentNftId;
38
40
  uint256 objectType;
39
41
  address objectAddress;
40
42
  address initialOwner;
@@ -48,19 +50,19 @@ interface IRegistry {
48
50
  function POLICY() external pure returns(uint256);
49
51
  function BUNDLE() external pure returns(uint256);
50
52
 
51
- function register(address objectAddress) external returns(uint256 nftId);
53
+ function register(address objectAddress) external returns(NftId nftId);
52
54
  function registerObjectForInstance(
53
- uint256 parentNftid,
55
+ NftId parentNftid,
54
56
  uint256 objectType,
55
57
  address initialOwner
56
58
  )
57
- external returns(uint256 nftId);
59
+ external returns(NftId nftId);
58
60
 
59
61
  function getObjectCount() external view returns(uint256);
60
62
 
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);
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);
64
66
 
65
67
  function isRegistered(address objectAddress) external view returns(bool);
66
68