@etherisc/gif-next 0.0.2-fe77319 → 0.0.2-ffba655

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) 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 +4 -0
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
  15. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
  17. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
  18. package/artifacts/contracts/experiment/{A.sol → inheritance/A.sol}/A.json +5 -5
  19. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
  20. package/artifacts/contracts/experiment/{A.sol → inheritance/A.sol}/AShared.json +3 -3
  21. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
  22. package/artifacts/contracts/experiment/{B.sol → inheritance/B.sol}/B.json +2 -2
  23. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
  24. package/artifacts/contracts/experiment/{C.sol → inheritance/C.sol}/C.json +2 -2
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
  26. package/artifacts/contracts/experiment/{IA.sol → inheritance/IA.sol}/IA.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
  28. package/artifacts/contracts/experiment/{IA.sol → inheritance/IA.sol}/ISharedA.json +1 -1
  29. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
  30. package/artifacts/contracts/experiment/{IB.sol → inheritance/IB.sol}/IB.json +1 -1
  31. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
  32. package/artifacts/contracts/experiment/{IC.sol → inheritance/IC.sol}/IC.json +1 -1
  33. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
  34. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
  35. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
  36. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
  37. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  38. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +60 -60
  39. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  40. package/artifacts/contracts/instance/Instance.sol/Instance.json +122 -64
  41. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  42. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  43. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  44. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  45. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  46. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  47. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +24 -24
  48. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  49. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +48 -6
  50. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  51. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  52. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +6 -6
  53. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  54. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +26 -26
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +3 -3
  57. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  58. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  59. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  60. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +18 -18
  61. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  62. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +18 -18
  63. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  64. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  65. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +10 -10
  66. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  67. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +10 -10
  68. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  69. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  70. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +8 -8
  71. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  72. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  73. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +54 -12
  74. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  75. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
  76. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
  77. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
  78. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  79. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  80. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +6 -6
  81. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  82. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +41 -33
  83. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  84. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  85. package/artifacts/contracts/registry/Registry.sol/Registerable.json +7 -7
  86. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  87. package/artifacts/contracts/registry/Registry.sol/Registry.json +100 -42
  88. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  89. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  90. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  91. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  92. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  93. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  94. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  95. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
  96. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  97. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  98. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  99. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +453 -0
  100. package/contracts/components/Component.sol +3 -3
  101. package/contracts/components/IProduct.sol +2 -1
  102. package/contracts/components/Product.sol +5 -4
  103. package/contracts/experiment/errors/Require.sol +33 -0
  104. package/contracts/experiment/errors/Revert.sol +39 -0
  105. package/contracts/experiment/{B.sol → inheritance/B.sol} +1 -1
  106. package/contracts/experiment/{C.sol → inheritance/C.sol} +1 -1
  107. package/contracts/experiment/types/TypeA.sol +42 -0
  108. package/contracts/experiment/types/TypeB.sol +24 -0
  109. package/contracts/instance/IInstance.sol +3 -3
  110. package/contracts/instance/Instance.sol +4 -3
  111. package/contracts/instance/component/ComponentModule.sol +32 -43
  112. package/contracts/instance/component/IComponent.sol +11 -10
  113. package/contracts/instance/policy/IPolicy.sol +8 -8
  114. package/contracts/instance/policy/PolicyModule.sol +12 -11
  115. package/contracts/instance/pool/IPoolModule.sol +6 -5
  116. package/contracts/instance/pool/PoolModule.sol +9 -6
  117. package/contracts/instance/product/IProductService.sol +5 -4
  118. package/contracts/instance/product/ProductService.sol +14 -11
  119. package/contracts/registry/ChainNft.sol +173 -0
  120. package/contracts/registry/IChainNft.sol +18 -0
  121. package/contracts/registry/IRegistry.sol +16 -12
  122. package/contracts/registry/Registry.sol +43 -58
  123. package/contracts/types/Blocknumber.sol +60 -0
  124. package/contracts/types/ChainId.sol +30 -0
  125. package/contracts/types/NftId.sol +35 -0
  126. package/contracts/types/Timestamp.sol +55 -0
  127. package/contracts/types/UFixed.sol +211 -0
  128. package/package.json +1 -1
  129. package/artifacts/contracts/experiment/A.sol/A.dbg.json +0 -4
  130. package/artifacts/contracts/experiment/A.sol/AShared.dbg.json +0 -4
  131. package/artifacts/contracts/experiment/B.sol/B.dbg.json +0 -4
  132. package/artifacts/contracts/experiment/C.sol/C.dbg.json +0 -4
  133. package/artifacts/contracts/experiment/IA.sol/IA.dbg.json +0 -4
  134. package/artifacts/contracts/experiment/IA.sol/ISharedA.dbg.json +0 -4
  135. package/artifacts/contracts/experiment/IB.sol/IB.dbg.json +0 -4
  136. package/artifacts/contracts/experiment/IC.sol/IC.dbg.json +0 -4
  137. /package/contracts/experiment/{A.sol → inheritance/A.sol} +0 -0
  138. /package/contracts/experiment/{IA.sol → inheritance/IA.sol} +0 -0
  139. /package/contracts/experiment/{IB.sol → inheritance/IB.sol} +0 -0
  140. /package/contracts/experiment/{IC.sol → inheritance/IC.sol} +0 -0
@@ -0,0 +1,42 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ /*
5
+ # chisel session for user defined types
6
+
7
+ import {TypeA, toTypeA} from "./contracts/experiment/types/TypeA.sol";
8
+ TypeA a = toTypeA(1);
9
+ TypeA b = toTypeA(2);
10
+ uint(a.toInt())
11
+ uint(b.toInt())
12
+ a == b
13
+ a != b
14
+
15
+ import {TypeB, toTypeB} from "./contracts/experiment/types/TypeB.sol";
16
+ TypeB x = toTypeB(33);
17
+ uint(x.toInt())
18
+ a == x; // -> error
19
+ a.toInt() == x.toInt() // -> no error
20
+ */
21
+
22
+ // bytes5 allows for chain ids up to 13 digits
23
+ type TypeA is uint248;
24
+
25
+ // type bindings
26
+ using {
27
+ eqTypeA as ==,
28
+ neTypeA as !=,
29
+ TypeALib.toInt
30
+ } for TypeA global;
31
+
32
+ // general pure free functions
33
+ function toTypeA(uint256 typeA) pure returns(TypeA) { return TypeA.wrap(uint248(typeA)); }
34
+
35
+ // pure free functions for operators
36
+ function eqTypeA(TypeA a, TypeA b) pure returns(bool isSame) { return TypeA.unwrap(a) == TypeA.unwrap(b); }
37
+ function neTypeA(TypeA a, TypeA b) pure returns(bool isDifferent) { return TypeA.unwrap(a) != TypeA.unwrap(b); }
38
+
39
+ // library functions that operate on user defined type
40
+ library TypeALib {
41
+ function toInt(TypeA typeA) internal pure returns(uint256) { return uint256(TypeA.unwrap(typeA)); }
42
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ // bytes5 allows for chain ids up to 13 digits
5
+ type TypeB is uint248;
6
+
7
+ // type bindings
8
+ using {
9
+ eqTypeB as ==,
10
+ addTypeB as +,
11
+ TypeBLib.toInt
12
+ } for TypeB global;
13
+
14
+ // general pure free functions
15
+ function toTypeB(uint256 x) pure returns(TypeB) { return TypeB.wrap(uint248(x)); }
16
+
17
+ // pure free functions for operators
18
+ function eqTypeB(TypeB a, TypeB b) pure returns(bool isSame) { return TypeB.unwrap(a) == TypeB.unwrap(b); }
19
+ function addTypeB(TypeB a, TypeB b) pure returns(TypeB sum) { return TypeB.wrap(TypeB.unwrap(a) + TypeB.unwrap(b)); }
20
+
21
+ // library functions that operate on user defined type
22
+ library TypeBLib {
23
+ function toInt(TypeB b) internal pure returns(uint256) { return uint256(TypeB.unwrap(b)); }
24
+ }
@@ -12,9 +12,9 @@ import {IPoolModule} from "./pool/IPoolModule.sol";
12
12
  interface IInstance is
13
13
  IRegisterable,
14
14
  IAccessModule,
15
- IComponentModule,
16
- IProductModule,
17
15
  IPolicyModule,
18
- IPoolModule
16
+ IPoolModule,
17
+ IComponentModule,
18
+ IProductModule
19
19
  { }
20
20
 
@@ -11,6 +11,7 @@ import {PolicyModule} from "./policy/PolicyModule.sol";
11
11
  import {PoolModule} from "./pool/PoolModule.sol";
12
12
 
13
13
  import {IInstance} from "./IInstance.sol";
14
+ import {NftId, toNftId} from "../types/NftId.sol";
14
15
 
15
16
  contract Instance is
16
17
  Registerable,
@@ -36,17 +37,17 @@ contract Instance is
36
37
  { }
37
38
 
38
39
  // from registerable
39
- function register() external override returns(uint256 id) {
40
+ function register() external override returns(NftId nftId) {
40
41
  require(address(_registry) != address(0), "ERROR:PRD-001:REGISTRY_ZERO");
41
42
  return _registry.register(address(this));
42
43
  }
43
44
 
44
45
  // from registerable
45
- function getParentNftId() public view override returns(uint256) {
46
+ function getParentNftId() public view override returns(NftId) {
46
47
  // TODO add self registry and exchange 0 for_registry.getNftId();
47
48
  // define parent tree for all registerables
48
49
  // eg 0 <- chain(mainnet) <- global registry <- chain registry <- instance <- component <- policy/bundle
49
- return 0;
50
+ return toNftId(0);
50
51
  }
51
52
 
52
53
  // from registerable
@@ -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} 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() && _componentInfo[nftId].nftId.eq(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