@etherisc/gif-next 0.0.2-e6a90b9 → 0.0.2-e6ad61d-739

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. package/README.md +33 -0
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +35 -9
  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 +84 -8
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +34 -152
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +146 -13
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +148 -15
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +59 -0
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +124 -0
  32. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +74 -0
  34. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +4 -0
  35. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +124 -0
  36. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +4 -0
  37. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +207 -0
  38. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  39. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
  40. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  41. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
  42. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  43. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +714 -127
  44. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/Instance.sol/Instance.json +845 -129
  46. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  47. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  48. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  49. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  50. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  51. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  52. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +31 -59
  53. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  54. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +103 -6
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +34 -8
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +31 -59
  60. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  61. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +50 -3
  62. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  63. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +4 -0
  64. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.json +134 -0
  65. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +4 -0
  66. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.json +182 -0
  67. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +4 -0
  68. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +221 -0
  69. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  70. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  71. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +44 -21
  72. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  73. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +44 -21
  74. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  75. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  76. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +23 -43
  77. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  78. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +28 -35
  79. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  80. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +21 -8
  82. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  83. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +85 -14
  85. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +4 -0
  86. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.json +10 -0
  87. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +4 -0
  88. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +490 -0
  89. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  90. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +45 -0
  91. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +4 -0
  92. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +490 -0
  93. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  94. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  95. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  96. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  97. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  98. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +8 -8
  99. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  100. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +20 -111
  101. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  102. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  103. package/artifacts/contracts/registry/Registry.sol/Registerable.json +9 -9
  104. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  105. package/artifacts/contracts/registry/Registry.sol/Registry.json +66 -115
  106. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  107. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  108. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  109. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  110. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  111. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
  112. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  113. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +85 -3
  114. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
  115. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
  116. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
  117. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
  118. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  119. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  120. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  121. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +479 -0
  122. package/contracts/components/Component.sol +39 -24
  123. package/contracts/components/IPool.sol +9 -3
  124. package/contracts/components/IProduct.sol +11 -6
  125. package/contracts/components/Pool.sol +37 -14
  126. package/contracts/components/Product.sol +48 -24
  127. package/contracts/experiment/errors/Require.sol +10 -5
  128. package/contracts/experiment/errors/Revert.sol +13 -8
  129. package/contracts/experiment/inheritance/A.sol +8 -11
  130. package/contracts/experiment/inheritance/B.sol +10 -5
  131. package/contracts/experiment/inheritance/C.sol +11 -5
  132. package/contracts/experiment/inheritance/IA.sol +2 -7
  133. package/contracts/experiment/inheritance/IB.sol +3 -2
  134. package/contracts/experiment/inheritance/IC.sol +4 -3
  135. package/contracts/experiment/statemachine/Dummy.sol +27 -0
  136. package/contracts/experiment/statemachine/ISM.sol +25 -0
  137. package/contracts/experiment/statemachine/README.md +112 -0
  138. package/contracts/experiment/statemachine/SM.sol +57 -0
  139. package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
  140. package/contracts/experiment/types/TypeA.sol +14 -9
  141. package/contracts/experiment/types/TypeB.sol +14 -9
  142. package/contracts/instance/IInstance.sol +8 -3
  143. package/contracts/instance/Instance.sol +24 -15
  144. package/contracts/instance/access/Access.sol +63 -116
  145. package/contracts/instance/access/IAccess.sol +28 -48
  146. package/contracts/instance/component/ComponentModule.sol +163 -135
  147. package/contracts/instance/component/IComponent.sol +41 -61
  148. package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
  149. package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
  150. package/contracts/instance/policy/IPolicy.sol +19 -35
  151. package/contracts/instance/policy/PolicyModule.sol +52 -44
  152. package/contracts/instance/pool/IPoolModule.sol +9 -26
  153. package/contracts/instance/pool/PoolModule.sol +43 -45
  154. package/contracts/instance/product/IProductService.sol +10 -19
  155. package/contracts/instance/product/ProductService.sol +86 -55
  156. package/contracts/instance/treasury/ITreasury.sol +91 -0
  157. package/contracts/instance/treasury/TokenHandler.sol +24 -0
  158. package/contracts/instance/treasury/TreasuryModule.sol +168 -0
  159. package/contracts/registry/ChainNft.sol +23 -61
  160. package/contracts/registry/IChainNft.sol +10 -7
  161. package/contracts/registry/IRegistry.sol +40 -41
  162. package/contracts/registry/Registry.sol +73 -67
  163. package/contracts/types/Blocknumber.sol +118 -0
  164. package/contracts/types/ChainId.sol +24 -10
  165. package/contracts/types/Fee.sol +32 -0
  166. package/contracts/types/NftId.sol +36 -10
  167. package/contracts/types/ObjectType.sol +107 -0
  168. package/contracts/types/StateId.sol +91 -0
  169. package/contracts/types/Timestamp.sol +102 -0
  170. package/contracts/types/UFixed.sol +210 -0
  171. package/package.json +13 -5
@@ -3,102 +3,105 @@ pragma solidity ^0.8.19;
3
3
 
4
4
  import {IChainNft} from "./IChainNft.sol";
5
5
  import {IRegistry, IRegistryLinked, IRegisterable} from "./IRegistry.sol";
6
+ import {NftId, toNftId, NftIdLib} from "../types/NftId.sol";
7
+ import {ObjectType, INSTANCE, POLICY, BUNDLE} from "../types/ObjectType.sol";
6
8
 
7
9
  contract RegistryLinked is IRegistryLinked {
8
-
9
10
  IRegistry internal _registry;
10
-
11
+
11
12
  constructor(address registry) {
12
13
  _registry = IRegistry(registry);
13
14
  }
14
15
 
15
- function getRegistry() external view override returns(IRegistry registry) {
16
+ function getRegistry() external view override returns (IRegistry registry) {
16
17
  return _registry;
17
18
  }
18
-
19
19
  }
20
20
 
21
-
22
- abstract contract Registerable is
23
- RegistryLinked,
24
- IRegisterable
25
- {
21
+ abstract contract Registerable is RegistryLinked, IRegisterable {
22
+ using NftIdLib for NftId;
26
23
 
27
24
  address private _initialOwner;
28
-
29
- constructor(address registry)
30
- RegistryLinked(registry)
31
- {
25
+
26
+ constructor(address registry) RegistryLinked(registry) {
32
27
  _initialOwner = msg.sender;
33
28
  }
34
29
 
35
30
  // getType, getData and register need to be implemented by concrete contract
36
31
 
37
- function isRegisterable() external pure override returns(bool) {
32
+ function isRegisterable() external pure override returns (bool) {
38
33
  return true;
39
34
  }
40
35
 
41
- function getInitialOwner() public view override returns(address deployer) {
36
+ function getInitialOwner() public view override returns (address deployer) {
42
37
  return _initialOwner;
43
38
  }
44
39
 
45
- function isRegistered() public view override returns(bool) {
46
- return _registry.getNftId(address(this)) > 0;
40
+ function isRegistered() public view override returns (bool) {
41
+ NftId nftId = _registry.getNftId(address(this));
42
+ return nftId.gtz();
47
43
  }
48
44
 
49
- function getNftId() public view override returns(uint256 id) {
45
+ function getNftId() public view override returns (NftId nftId) {
50
46
  return _registry.getNftId(address(this));
51
47
  }
52
48
 
53
- function getOwner() public view override returns(address owner) {
54
- uint256 id = _registry.getNftId(address(this));
49
+ function getOwner() public view override returns (address owner) {
50
+ NftId id = _registry.getNftId(address(this));
55
51
  owner = _registry.getOwner(id);
56
52
  return owner != address(0) ? owner : _initialOwner;
57
53
  }
58
-
59
54
  }
60
55
 
61
56
  contract Registry is IRegistry {
57
+ using NftIdLib for NftId;
62
58
 
63
59
  string public constant EMPTY_URI = "";
64
60
 
65
- mapping(uint256 id => RegistryInfo info) private _info;
66
- mapping(uint256 id => address owner) private _owner;
67
- mapping(address object => uint256 id) private _idByAddress;
61
+ mapping(NftId nftId => RegistryInfo info) private _info;
62
+ mapping(NftId nftId => address owner) private _owner;
63
+ mapping(address object => NftId nftId) private _nftIdByAddress;
68
64
 
69
65
  IChainNft private _chainNft;
70
66
 
71
67
  function initialize(address chainNft) external {
72
- require(address(_chainNft) == address(0), "ERROR:REG-001:ALREADY_INITIALIZED");
68
+ require(
69
+ address(_chainNft) == address(0),
70
+ "ERROR:REG-001:ALREADY_INITIALIZED"
71
+ );
73
72
  _chainNft = IChainNft(chainNft);
74
73
  }
75
74
 
76
- function TOKEN() public pure override returns(uint256) { return 30; }
77
- function INSTANCE() public pure override returns(uint256) { return 40; }
78
- function PRODUCT() public pure override returns(uint256) { return 50; }
79
- function ORACLE() public pure override returns(uint256) { return 60; }
80
- function POOL() public pure override returns(uint256) { return 70; }
81
- function POLICY() public pure override returns(uint256) { return 80; }
82
- function BUNDLE() public pure override returns(uint256) { return 90; }
83
-
84
- function register(address objectAddress) external override returns(uint256 nftId) {
85
- require(_idByAddress[objectAddress] == 0, "ERROR:REG-002:ALREADY_REGISTERED");
75
+ function register(
76
+ address objectAddress
77
+ ) external override returns (NftId nftId) {
78
+ require(
79
+ _nftIdByAddress[objectAddress].eqz(),
80
+ "ERROR:REG-002:ALREADY_REGISTERED"
81
+ );
86
82
 
87
83
  IRegisterable registerable = IRegisterable(objectAddress);
88
- require(registerable.isRegisterable(), "ERROR:REG-003:NOT_REGISTERABLE");
84
+ require(
85
+ registerable.isRegisterable(),
86
+ "ERROR:REG-003:NOT_REGISTERABLE"
87
+ );
89
88
 
90
89
  // check parent exists (for objects not instances)
91
- if(registerable.getType() != INSTANCE()) {
92
- RegistryInfo memory parentInfo = _info[registerable.getParentNftId()];
93
- require(parentInfo.nftId > 0, "ERROR:REG-004:PARENT_NOT_FOUND");
90
+ if (registerable.getType() != INSTANCE()) {
91
+ RegistryInfo memory parentInfo = _info[
92
+ registerable.getParentNftId()
93
+ ];
94
+ require(parentInfo.nftId.gtz(), "ERROR:REG-004:PARENT_NOT_FOUND");
94
95
  // check validity of parent relation, valid relations are
95
96
  // policy -> product, bundle -> pool, product -> instance, pool -> instance
96
97
  }
97
98
 
98
- nftId = _chainNft.mint(
99
- registerable.getInitialOwner(),
100
- EMPTY_URI);
101
-
99
+ uint256 mintedTokenId = _chainNft.mint(
100
+ registerable.getInitialOwner(),
101
+ EMPTY_URI
102
+ );
103
+ nftId = toNftId(mintedTokenId);
104
+
102
105
  RegistryInfo memory info = RegistryInfo(
103
106
  nftId,
104
107
  registerable.getParentNftId(),
@@ -108,30 +111,31 @@ contract Registry is IRegistry {
108
111
  );
109
112
 
110
113
  _info[nftId] = info;
111
- _idByAddress[objectAddress] = nftId;
114
+ _nftIdByAddress[objectAddress] = nftId;
112
115
 
113
116
  // add logging
114
117
  }
115
118
 
116
-
117
119
  function registerObjectForInstance(
118
- uint256 parentNftId,
119
- uint256 objectType,
120
+ NftId parentNftId,
121
+ ObjectType objectType,
120
122
  address initialOwner
121
123
  )
122
- external
124
+ external
123
125
  override
124
- // TODO add onlyRegisteredInstance
125
- returns(uint256 nftId)
126
+ returns (
127
+ // TODO add onlyRegisteredInstance
128
+ NftId nftId
129
+ )
126
130
  {
127
131
  // TODO add more validation
128
132
  require(
129
133
  objectType == POLICY() || objectType == BUNDLE(),
130
- "ERROR:REG-005:TYPE_INVALID");
134
+ "ERROR:REG-005:TYPE_INVALID"
135
+ );
131
136
 
132
- nftId = _chainNft.mint(
133
- initialOwner,
134
- EMPTY_URI);
137
+ uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
138
+ nftId = toNftId(mintedTokenId);
135
139
 
136
140
  RegistryInfo memory info = RegistryInfo(
137
141
  nftId,
@@ -146,31 +150,33 @@ contract Registry is IRegistry {
146
150
  // add logging
147
151
  }
148
152
 
149
-
150
- function getObjectCount() external view override returns(uint256) {
153
+ function getObjectCount() external view override returns (uint256) {
151
154
  return _chainNft.totalSupply();
152
155
  }
153
156
 
154
-
155
- function getNftId(address object) external view override returns(uint256 id) {
156
- return _idByAddress[object];
157
+ function getNftId(
158
+ address object
159
+ ) external view override returns (NftId id) {
160
+ return _nftIdByAddress[object];
157
161
  }
158
162
 
159
-
160
- function isRegistered(address object) external view override returns(bool) {
161
- return _idByAddress[object] > 0;
163
+ function isRegistered(
164
+ address object
165
+ ) external view override returns (bool) {
166
+ return _nftIdByAddress[object].gtz();
162
167
  }
163
168
 
164
-
165
- function getInfo(uint256 nftId) external view override returns(RegistryInfo memory info) {
169
+ function getInfo(
170
+ NftId nftId
171
+ ) external view override returns (RegistryInfo memory info) {
166
172
  return _info[nftId];
167
173
  }
168
174
 
169
- function getOwner(uint256 nftId) external view override returns(address) {
170
- return _chainNft.ownerOf(nftId);
175
+ function getOwner(NftId nftId) external view override returns (address) {
176
+ return _chainNft.ownerOf(nftId.toInt());
171
177
  }
172
178
 
173
- function getNftAddress() external view override returns(address nft) {
179
+ function getNftAddress() external view override returns (address nft) {
174
180
  return address(_chainNft);
175
181
  }
176
182
  }
@@ -0,0 +1,118 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ type Blocknumber is uint32;
5
+
6
+ using {
7
+ gtBlocknumber as >,
8
+ gteBlocknumber as >=,
9
+ ltBlocknumber as <,
10
+ lteBlocknumber as <=,
11
+ eqBlocknumber as ==,
12
+ neBlocknumber as !=,
13
+ BlocknumberLib.toInt
14
+ } for Blocknumber global;
15
+
16
+ /// @dev return true if Blocknumber a is greater than Blocknumber b
17
+ function gtBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
18
+ return Blocknumber.unwrap(a) > Blocknumber.unwrap(b);
19
+ }
20
+
21
+ /// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
22
+ function gteBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
23
+ return Blocknumber.unwrap(a) >= Blocknumber.unwrap(b);
24
+ }
25
+
26
+ /// @dev return true if Blocknumber a is less than Blocknumber b
27
+ function ltBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
28
+ return Blocknumber.unwrap(a) < Blocknumber.unwrap(b);
29
+ }
30
+
31
+ /// @dev return true if Blocknumber a is less than or equal to Blocknumber b
32
+ function lteBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
33
+ return Blocknumber.unwrap(a) <= Blocknumber.unwrap(b);
34
+ }
35
+
36
+ /// @dev return true if Blocknumber a is equal to Blocknumber b
37
+ function eqBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
38
+ return Blocknumber.unwrap(a) == Blocknumber.unwrap(b);
39
+ }
40
+
41
+ /// @dev return true if Blocknumber a is not equal to Blocknumber b
42
+ function neBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
43
+ return Blocknumber.unwrap(a) != Blocknumber.unwrap(b);
44
+ }
45
+
46
+ /// @dev Converts the uint256 to a Blocknumber.
47
+ function toBlocknumber(uint256 blocknum) pure returns (Blocknumber) {
48
+ return Blocknumber.wrap(uint32(blocknum));
49
+ }
50
+
51
+ function blockBlocknumber() view returns (Blocknumber) {
52
+ return toBlocknumber(block.number);
53
+ }
54
+
55
+ /// @dev Return the Blocknumber zero (0)
56
+ function zeroBlocknumber() pure returns (Blocknumber) {
57
+ return toBlocknumber(0);
58
+ }
59
+
60
+ /// @dev Return the current block number
61
+ function blockNumber() view returns (Blocknumber) {
62
+ return toBlocknumber(block.number);
63
+ }
64
+
65
+ library BlocknumberLib {
66
+ /// @dev return true if Blocknumber a is greater than Blocknumber b
67
+ function gt(
68
+ Blocknumber a,
69
+ Blocknumber b
70
+ ) public pure returns (bool isAfter) {
71
+ return gtBlocknumber(a, b);
72
+ }
73
+
74
+ /// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
75
+ function gte(
76
+ Blocknumber a,
77
+ Blocknumber b
78
+ ) public pure returns (bool isAfterOrSame) {
79
+ return gteBlocknumber(a, b);
80
+ }
81
+
82
+ /// @dev return true if Blocknumber a is less than Blocknumber b
83
+ function lt(
84
+ Blocknumber a,
85
+ Blocknumber b
86
+ ) public pure returns (bool isBefore) {
87
+ return ltBlocknumber(a, b);
88
+ }
89
+
90
+ /// @dev return true if Blocknumber a is less than or equal to Blocknumber b
91
+ function lte(
92
+ Blocknumber a,
93
+ Blocknumber b
94
+ ) public pure returns (bool isBeforeOrSame) {
95
+ return lteBlocknumber(a, b);
96
+ }
97
+
98
+ /// @dev return true if Blocknumber a is equal to Blocknumber b
99
+ function eq(
100
+ Blocknumber a,
101
+ Blocknumber b
102
+ ) public pure returns (bool isSame) {
103
+ return eqBlocknumber(a, b);
104
+ }
105
+
106
+ /// @dev return true if Blocknumber a is not equal to Blocknumber b
107
+ function ne(
108
+ Blocknumber a,
109
+ Blocknumber b
110
+ ) public pure returns (bool isDifferent) {
111
+ return neBlocknumber(a, b);
112
+ }
113
+
114
+ /// @dev converts the Blocknumber to a uint256
115
+ function toInt(Blocknumber blocknumber) public pure returns (uint256) {
116
+ return uint256(uint32(Blocknumber.unwrap(blocknumber)));
117
+ }
118
+ }
@@ -1,24 +1,38 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
- // bytes5 (uint40) allows for chain ids up to 13 digits
4
+ /// @dev bytes5 (uint40) allows for chain ids up to 13 digits
5
5
  type ChainId is bytes5;
6
6
 
7
7
  // type bindings
8
- using {
9
- eqChainId as ==,
10
- neChainId as !=,
11
- ChainIdLib.toInt
12
- } for ChainId global;
8
+ using {eqChainId as ==, neChainId as !=, ChainIdLib.toInt} for ChainId global;
13
9
 
14
10
  // general pure free functions
15
- function toChainId(uint256 chainId) pure returns(ChainId) { return ChainId.wrap(bytes5(uint40(chainId))); }
11
+ /// @dev Converts the uint256 to a ChainId.
12
+ function toChainId(uint256 chainId) pure returns (ChainId) {
13
+ return ChainId.wrap(bytes5(uint40(chainId)));
14
+ }
15
+
16
+ /// @dev Return the ChainId for the chain the contract is deployed to
17
+ function thisChainId() view returns (ChainId) {
18
+ return toChainId(block.chainid);
19
+ }
16
20
 
17
21
  // pure free functions for operators
18
- function eqChainId(ChainId a, ChainId b) pure returns(bool isSame) { return ChainId.unwrap(a) == ChainId.unwrap(b); }
19
- function neChainId(ChainId a, ChainId b) pure returns(bool isDifferent) { return ChainId.unwrap(a) != ChainId.unwrap(b); }
22
+ /// @dev Returns true if the values are equal (==).
23
+ function eqChainId(ChainId a, ChainId b) pure returns (bool isSame) {
24
+ return ChainId.unwrap(a) == ChainId.unwrap(b);
25
+ }
26
+
27
+ /// @dev Returns true if the values are not equal (!=).
28
+ function neChainId(ChainId a, ChainId b) pure returns (bool isDifferent) {
29
+ return ChainId.unwrap(a) != ChainId.unwrap(b);
30
+ }
20
31
 
21
32
  // library functions that operate on user defined type
22
33
  library ChainIdLib {
23
- function toInt(ChainId chainId) internal pure returns(uint256) { return uint256(uint40(ChainId.unwrap(chainId))); }
34
+ /// @dev Converts the ChainId to a uint256.
35
+ function toInt(ChainId chainId) internal pure returns (uint256) {
36
+ return uint256(uint40(ChainId.unwrap(chainId)));
37
+ }
24
38
  }
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {UFixed} from "./UFixed.sol";
5
+
6
+ struct Fee {
7
+ UFixed fractionalFee;
8
+ uint256 fixedFee;
9
+ }
10
+
11
+ // general pure free functions
12
+ /// @dev Converts the uint256 to a NftId.
13
+ function toFee(
14
+ UFixed fractionalFee,
15
+ uint256 fixedFee
16
+ ) pure returns (Fee memory fee) {
17
+ return Fee(fractionalFee, fixedFee);
18
+ }
19
+
20
+ /// @dev Return the NftId zero (0)
21
+ function zeroFee() pure returns (Fee memory fee) {
22
+ return Fee(UFixed.wrap(0), 0);
23
+ }
24
+
25
+ // pure free functions for operators
26
+ function feeIsSame(Fee memory a, Fee memory b) pure returns (bool isSame) {
27
+ return a.fixedFee == b.fixedFee && a.fractionalFee == b.fractionalFee;
28
+ }
29
+
30
+ function feeIsZero(Fee memory fee) pure returns (bool) {
31
+ return fee.fixedFee == 0 && UFixed.unwrap(fee.fractionalFee) == 0;
32
+ }
@@ -5,21 +5,47 @@ pragma solidity ^0.8.19;
5
5
  type NftId is uint96;
6
6
 
7
7
  // type bindings
8
- using {
9
- eqNftId as ==,
10
- neNftId as !=,
11
- NftIdLib.toInt
12
- } for NftId global;
8
+ using {eqNftId as ==, neNftId as !=, NftIdLib.toInt} for NftId global;
13
9
 
14
10
  // general pure free functions
15
- function toNftId(uint256 id) pure returns(NftId) { return NftId.wrap(uint96(id)); }
16
- function gtz(NftId a) pure returns(bool) { return NftId.unwrap(a) > 0; }
11
+ /// @dev Converts the uint256 to a NftId.
12
+ function toNftId(uint256 id) pure returns (NftId) {
13
+ return NftId.wrap(uint96(id));
14
+ }
15
+
16
+ /// @dev Return the NftId zero (0)
17
+ function zeroNftId() pure returns (NftId) {
18
+ return NftId.wrap(0);
19
+ }
17
20
 
18
21
  // pure free functions for operators
19
- function eqNftId(NftId a, NftId b) pure returns(bool isSame) { return NftId.unwrap(a) == NftId.unwrap(b); }
20
- function neNftId(NftId a, NftId b) pure returns(bool isDifferent) { return NftId.unwrap(a) != NftId.unwrap(b); }
22
+ function eqNftId(NftId a, NftId b) pure returns (bool isSame) {
23
+ return NftId.unwrap(a) == NftId.unwrap(b);
24
+ }
25
+
26
+ function neNftId(NftId a, NftId b) pure returns (bool isDifferent) {
27
+ return NftId.unwrap(a) != NftId.unwrap(b);
28
+ }
21
29
 
22
30
  // library functions that operate on user defined type
23
31
  library NftIdLib {
24
- function toInt(NftId nftId) internal pure returns(uint256) { return uint256(NftId.unwrap(nftId)); }
32
+ /// @dev Converts the NftId to a uint256.
33
+ function toInt(NftId nftId) public pure returns (uint96) {
34
+ return uint96(NftId.unwrap(nftId));
35
+ }
36
+
37
+ /// @dev Returns true if the value is non-zero (> 0).
38
+ function gtz(NftId a) public pure returns (bool) {
39
+ return NftId.unwrap(a) > 0;
40
+ }
41
+
42
+ /// @dev Returns true if the value is zero (== 0).
43
+ function eqz(NftId a) public pure returns (bool) {
44
+ return NftId.unwrap(a) == 0;
45
+ }
46
+
47
+ /// @dev Returns true if the values are equal (==).
48
+ function eq(NftId a, NftId b) public pure returns (bool isSame) {
49
+ return eqNftId(a, b);
50
+ }
25
51
  }
@@ -0,0 +1,107 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ // uint96 allows for chain ids up to 13 digits
5
+ type ObjectType is uint8;
6
+
7
+ // type bindings
8
+ using {
9
+ eqObjectType as ==,
10
+ neObjectType as !=,
11
+ ObjectTypeLib.toInt
12
+ } for ObjectType global;
13
+
14
+ // general pure free functions
15
+
16
+ function PROTOCOL() pure returns (ObjectType) {
17
+ return toObjectType(10);
18
+ }
19
+
20
+ function CHAIN() pure returns (ObjectType) {
21
+ return toObjectType(20);
22
+ }
23
+
24
+ function REGISTRY() pure returns (ObjectType) {
25
+ return toObjectType(30);
26
+ }
27
+
28
+ function TOKEN() pure returns (ObjectType) {
29
+ return toObjectType(40);
30
+ }
31
+
32
+ function INSTANCE() pure returns (ObjectType) {
33
+ return toObjectType(50);
34
+ }
35
+
36
+ function PRODUCT() pure returns (ObjectType) {
37
+ return toObjectType(60);
38
+ }
39
+
40
+ function ORACLE() pure returns (ObjectType) {
41
+ return toObjectType(70);
42
+ }
43
+
44
+ function POOL() pure returns (ObjectType) {
45
+ return toObjectType(80);
46
+ }
47
+
48
+ function BUNDLE() pure returns (ObjectType) {
49
+ return toObjectType(81);
50
+ }
51
+
52
+ function POLICY() pure returns (ObjectType) {
53
+ return toObjectType(90);
54
+ }
55
+
56
+ function CLAIM() pure returns (ObjectType) {
57
+ return toObjectType(91);
58
+ }
59
+
60
+ function PAYOUT() pure returns (ObjectType) {
61
+ return toObjectType(92);
62
+ }
63
+
64
+ /// @dev Converts the uint8 to a ObjectType.
65
+ function toObjectType(uint256 objectType) pure returns (ObjectType) {
66
+ return ObjectType.wrap(uint8(objectType));
67
+ }
68
+
69
+ /// @dev Return the ObjectType zero (0)
70
+ function zeroObjectType() pure returns (ObjectType) {
71
+ return ObjectType.wrap(0);
72
+ }
73
+
74
+ // pure free functions for operators
75
+ function eqObjectType(ObjectType a, ObjectType b) pure returns (bool isSame) {
76
+ return ObjectType.unwrap(a) == ObjectType.unwrap(b);
77
+ }
78
+
79
+ function neObjectType(
80
+ ObjectType a,
81
+ ObjectType b
82
+ ) pure returns (bool isDifferent) {
83
+ return ObjectType.unwrap(a) != ObjectType.unwrap(b);
84
+ }
85
+
86
+ // library functions that operate on user defined type
87
+ library ObjectTypeLib {
88
+ /// @dev Converts the NftId to a uint256.
89
+ function toInt(ObjectType objectType) public pure returns (uint96) {
90
+ return uint96(ObjectType.unwrap(objectType));
91
+ }
92
+
93
+ /// @dev Returns true if the value is non-zero (> 0).
94
+ function gtz(ObjectType a) public pure returns (bool) {
95
+ return ObjectType.unwrap(a) > 0;
96
+ }
97
+
98
+ /// @dev Returns true if the value is zero (== 0).
99
+ function eqz(ObjectType a) public pure returns (bool) {
100
+ return ObjectType.unwrap(a) == 0;
101
+ }
102
+
103
+ /// @dev Returns true if the values are equal (==).
104
+ function eq(ObjectType a, ObjectType b) public pure returns (bool isSame) {
105
+ return eqObjectType(a, b);
106
+ }
107
+ }