@etherisc/gif-next 0.0.2-d250c72 → 0.0.2-d3543ee-217

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 +28 -2
  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 +78 -2
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +32 -150
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +121 -6
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +121 -6
  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 +686 -99
  44. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/Instance.sol/Instance.json +757 -99
  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 +14 -42
  53. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  54. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +65 -10
  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 +28 -2
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +12 -40
  60. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  61. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +47 -0
  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 +26 -3
  72. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  73. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +26 -3
  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 +15 -35
  77. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  78. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +22 -29
  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 +13 -0
  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 +41 -12
  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 +2 -2
  99. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  100. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +4 -95
  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 +2 -2
  104. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  105. package/artifacts/contracts/registry/Registry.sol/Registry.json +14 -105
  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 +2 -2
  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 +453 -0
  122. package/contracts/components/Component.sol +38 -23
  123. package/contracts/components/IPool.sol +9 -3
  124. package/contracts/components/IProduct.sol +10 -6
  125. package/contracts/components/Pool.sol +37 -14
  126. package/contracts/components/Product.sol +46 -23
  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 +22 -14
  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 +144 -118
  147. package/contracts/instance/component/IComponent.sol +39 -60
  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 +16 -32
  151. package/contracts/instance/policy/PolicyModule.sol +47 -40
  152. package/contracts/instance/pool/IPoolModule.sol +7 -25
  153. package/contracts/instance/pool/PoolModule.sol +40 -45
  154. package/contracts/instance/product/IProductService.sol +6 -16
  155. package/contracts/instance/product/ProductService.sol +76 -48
  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 +35 -38
  162. package/contracts/registry/Registry.sol +57 -57
  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 +29 -13
  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 +206 -0
  171. package/package.json +10 -4
@@ -3,67 +3,59 @@ 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} from "../types/NftId.sol";
7
- import {NftIdLib} from "../types/NftId.sol";
6
+ import {NftId, toNftId, NftIdLib} from "../types/NftId.sol";
7
+ import {ObjectType, INSTANCE, POLICY, BUNDLE} from "../types/ObjectType.sol";
8
8
 
9
9
  contract RegistryLinked is IRegistryLinked {
10
-
11
10
  IRegistry internal _registry;
12
-
11
+
13
12
  constructor(address registry) {
14
13
  _registry = IRegistry(registry);
15
14
  }
16
15
 
17
- function getRegistry() external view override returns(IRegistry registry) {
16
+ function getRegistry() external view override returns (IRegistry registry) {
18
17
  return _registry;
19
18
  }
20
-
21
19
  }
22
20
 
23
-
24
- abstract contract Registerable is
25
- RegistryLinked,
26
- IRegisterable
27
- {
21
+ abstract contract Registerable is RegistryLinked, IRegisterable {
28
22
  using NftIdLib for NftId;
29
23
 
30
24
  address private _initialOwner;
31
-
32
- constructor(address registry)
33
- RegistryLinked(registry)
34
- {
25
+
26
+ constructor(address registry) RegistryLinked(registry) {
35
27
  _initialOwner = msg.sender;
36
28
  }
37
29
 
38
30
  // getType, getData and register need to be implemented by concrete contract
39
31
 
40
- function isRegisterable() external pure override returns(bool) {
32
+ function isRegisterable() external pure override returns (bool) {
41
33
  return true;
42
34
  }
43
35
 
44
- function getInitialOwner() public view override returns(address deployer) {
36
+ function getInitialOwner() public view override returns (address deployer) {
45
37
  return _initialOwner;
46
38
  }
47
39
 
48
- function isRegistered() public view override returns(bool) {
40
+ function isRegistered() public view override returns (bool) {
49
41
  NftId nftId = _registry.getNftId(address(this));
50
42
  return nftId.gtz();
51
43
  }
52
44
 
53
- function getNftId() public view override returns(NftId nftId) {
45
+ function getNftId() public view override returns (NftId nftId) {
54
46
  return _registry.getNftId(address(this));
55
47
  }
56
48
 
57
- function getOwner() public view override returns(address owner) {
49
+ function getOwner() public view override returns (address owner) {
58
50
  NftId id = _registry.getNftId(address(this));
59
51
  owner = _registry.getOwner(id);
60
52
  return owner != address(0) ? owner : _initialOwner;
61
53
  }
62
-
63
54
  }
64
55
 
65
56
  contract Registry is IRegistry {
66
57
  using NftIdLib for NftId;
58
+
67
59
  string public constant EMPTY_URI = "";
68
60
 
69
61
  mapping(NftId nftId => RegistryInfo info) private _info;
@@ -73,37 +65,43 @@ contract Registry is IRegistry {
73
65
  IChainNft private _chainNft;
74
66
 
75
67
  function initialize(address chainNft) external {
76
- require(address(_chainNft) == address(0), "ERROR:REG-001:ALREADY_INITIALIZED");
68
+ require(
69
+ address(_chainNft) == address(0),
70
+ "ERROR:REG-001:ALREADY_INITIALIZED"
71
+ );
77
72
  _chainNft = IChainNft(chainNft);
78
73
  }
79
74
 
80
- function TOKEN() public pure override returns(uint256) { return 30; }
81
- function INSTANCE() public pure override returns(uint256) { return 40; }
82
- function PRODUCT() public pure override returns(uint256) { return 50; }
83
- function ORACLE() public pure override returns(uint256) { return 60; }
84
- function POOL() public pure override returns(uint256) { return 70; }
85
- function POLICY() public pure override returns(uint256) { return 80; }
86
- function BUNDLE() public pure override returns(uint256) { return 90; }
87
-
88
- function register(address objectAddress) external override returns(NftId nftId) {
89
- require(_nftIdByAddress[objectAddress].eqz(), "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
+ );
90
82
 
91
83
  IRegisterable registerable = IRegisterable(objectAddress);
92
- require(registerable.isRegisterable(), "ERROR:REG-003:NOT_REGISTERABLE");
84
+ require(
85
+ registerable.isRegisterable(),
86
+ "ERROR:REG-003:NOT_REGISTERABLE"
87
+ );
93
88
 
94
89
  // check parent exists (for objects not instances)
95
- if(registerable.getType() != INSTANCE()) {
96
- RegistryInfo memory parentInfo = _info[registerable.getParentNftId()];
90
+ if (registerable.getType() != INSTANCE()) {
91
+ RegistryInfo memory parentInfo = _info[
92
+ registerable.getParentNftId()
93
+ ];
97
94
  require(parentInfo.nftId.gtz(), "ERROR:REG-004:PARENT_NOT_FOUND");
98
95
  // check validity of parent relation, valid relations are
99
96
  // policy -> product, bundle -> pool, product -> instance, pool -> instance
100
97
  }
101
98
 
102
99
  uint256 mintedTokenId = _chainNft.mint(
103
- registerable.getInitialOwner(),
104
- EMPTY_URI);
100
+ registerable.getInitialOwner(),
101
+ EMPTY_URI
102
+ );
105
103
  nftId = toNftId(mintedTokenId);
106
-
104
+
107
105
  RegistryInfo memory info = RegistryInfo(
108
106
  nftId,
109
107
  registerable.getParentNftId(),
@@ -118,25 +116,25 @@ contract Registry is IRegistry {
118
116
  // add logging
119
117
  }
120
118
 
121
-
122
119
  function registerObjectForInstance(
123
120
  NftId parentNftId,
124
- uint256 objectType,
121
+ ObjectType objectType,
125
122
  address initialOwner
126
123
  )
127
- external
124
+ external
128
125
  override
129
- // TODO add onlyRegisteredInstance
130
- returns(NftId nftId)
126
+ returns (
127
+ // TODO add onlyRegisteredInstance
128
+ NftId nftId
129
+ )
131
130
  {
132
131
  // TODO add more validation
133
132
  require(
134
133
  objectType == POLICY() || objectType == BUNDLE(),
135
- "ERROR:REG-005:TYPE_INVALID");
134
+ "ERROR:REG-005:TYPE_INVALID"
135
+ );
136
136
 
137
- uint256 mintedTokenId = _chainNft.mint(
138
- initialOwner,
139
- EMPTY_URI);
137
+ uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
140
138
  nftId = toNftId(mintedTokenId);
141
139
 
142
140
  RegistryInfo memory info = RegistryInfo(
@@ -152,31 +150,33 @@ contract Registry is IRegistry {
152
150
  // add logging
153
151
  }
154
152
 
155
-
156
- function getObjectCount() external view override returns(uint256) {
153
+ function getObjectCount() external view override returns (uint256) {
157
154
  return _chainNft.totalSupply();
158
155
  }
159
156
 
160
-
161
- function getNftId(address object) external view override returns(NftId id) {
157
+ function getNftId(
158
+ address object
159
+ ) external view override returns (NftId id) {
162
160
  return _nftIdByAddress[object];
163
161
  }
164
162
 
165
-
166
- function isRegistered(address object) external view override returns(bool) {
163
+ function isRegistered(
164
+ address object
165
+ ) external view override returns (bool) {
167
166
  return _nftIdByAddress[object].gtz();
168
167
  }
169
168
 
170
-
171
- function getInfo(NftId nftId) external view override returns(RegistryInfo memory info) {
169
+ function getInfo(
170
+ NftId nftId
171
+ ) external view override returns (RegistryInfo memory info) {
172
172
  return _info[nftId];
173
173
  }
174
174
 
175
- function getOwner(NftId nftId) external view override returns(address) {
175
+ function getOwner(NftId nftId) external view override returns (address) {
176
176
  return _chainNft.ownerOf(nftId.toInt());
177
177
  }
178
178
 
179
- function getNftAddress() external view override returns(address nft) {
179
+ function getNftAddress() external view override returns (address nft) {
180
180
  return address(_chainNft);
181
181
  }
182
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,31 +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
11
  /// @dev Converts the uint256 to a NftId.
16
- function toNftId(uint256 id) pure returns(NftId) { return NftId.wrap(uint96(id)); }
12
+ function toNftId(uint256 id) pure returns (NftId) {
13
+ return NftId.wrap(uint96(id));
14
+ }
17
15
 
18
16
  /// @dev Return the NftId zero (0)
19
- function zeroNftId() pure returns(NftId) { return NftId.wrap(0); }
17
+ function zeroNftId() pure returns (NftId) {
18
+ return NftId.wrap(0);
19
+ }
20
20
 
21
21
  // pure free functions for operators
22
- function eqNftId(NftId a, NftId b) pure returns(bool isSame) { return NftId.unwrap(a) == NftId.unwrap(b); }
23
- 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
+ }
24
29
 
25
30
  // library functions that operate on user defined type
26
31
  library NftIdLib {
27
32
  /// @dev Converts the NftId to a uint256.
28
- function toInt(NftId nftId) public pure returns(uint96) { return uint96(NftId.unwrap(nftId)); }
33
+ function toInt(NftId nftId) public pure returns (uint96) {
34
+ return uint96(NftId.unwrap(nftId));
35
+ }
36
+
29
37
  /// @dev Returns true if the value is non-zero (> 0).
30
- function gtz(NftId a) public pure returns(bool) { return NftId.unwrap(a) > 0; }
38
+ function gtz(NftId a) public pure returns (bool) {
39
+ return NftId.unwrap(a) > 0;
40
+ }
41
+
31
42
  /// @dev Returns true if the value is zero (== 0).
32
- function eqz(NftId a) public pure returns(bool) { return NftId.unwrap(a) == 0; }
43
+ function eqz(NftId a) public pure returns (bool) {
44
+ return NftId.unwrap(a) == 0;
45
+ }
46
+
33
47
  /// @dev Returns true if the values are equal (==).
34
- function eq(NftId a, NftId b) public pure returns(bool isSame) { return eqNftId(a, b); }
48
+ function eq(NftId a, NftId b) public pure returns (bool isSame) {
49
+ return eqNftId(a, b);
50
+ }
35
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
+ }
@@ -0,0 +1,91 @@
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 StateId is uint8;
6
+
7
+ // type bindings
8
+ using {eqStateId as ==, neStateId as !=, StateIdLib.toInt} for StateId global;
9
+
10
+ // general pure free functions
11
+ function APPLIED() pure returns (StateId) {
12
+ return toStateId(10);
13
+ }
14
+
15
+ function REVOKED() pure returns (StateId) {
16
+ return toStateId(20);
17
+ }
18
+
19
+ function DECLINED() pure returns (StateId) {
20
+ return toStateId(30);
21
+ }
22
+
23
+ function CONFIRMED() pure returns (StateId) {
24
+ return toStateId(40);
25
+ }
26
+
27
+ function EXPECTED() pure returns (StateId) {
28
+ return toStateId(50);
29
+ }
30
+
31
+ function ACTIVE() pure returns (StateId) {
32
+ return toStateId(100);
33
+ }
34
+
35
+ function PAUSED() pure returns (StateId) {
36
+ return toStateId(110);
37
+ }
38
+
39
+ function CLOSED() pure returns (StateId) {
40
+ return toStateId(200);
41
+ }
42
+
43
+ function ARCHIVED() pure returns (StateId) {
44
+ return toStateId(210);
45
+ }
46
+
47
+ function PAID() pure returns (StateId) {
48
+ return toStateId(220);
49
+ }
50
+
51
+ /// @dev Converts the uint8 to a StateId.
52
+ function toStateId(uint256 id) pure returns (StateId) {
53
+ return StateId.wrap(uint8(id));
54
+ }
55
+
56
+ /// @dev Return the StateId zero (0)
57
+ function zeroStateId() pure returns (StateId) {
58
+ return StateId.wrap(0);
59
+ }
60
+
61
+ // pure free functions for operators
62
+ function eqStateId(StateId a, StateId b) pure returns (bool isSame) {
63
+ return StateId.unwrap(a) == StateId.unwrap(b);
64
+ }
65
+
66
+ function neStateId(StateId a, StateId b) pure returns (bool isDifferent) {
67
+ return StateId.unwrap(a) != StateId.unwrap(b);
68
+ }
69
+
70
+ // library functions that operate on user defined type
71
+ library StateIdLib {
72
+ /// @dev Converts the NftId to a uint256.
73
+ function toInt(StateId stateId) public pure returns (uint96) {
74
+ return uint96(StateId.unwrap(stateId));
75
+ }
76
+
77
+ /// @dev Returns true if the value is non-zero (> 0).
78
+ function gtz(StateId a) public pure returns (bool) {
79
+ return StateId.unwrap(a) > 0;
80
+ }
81
+
82
+ /// @dev Returns true if the value is zero (== 0).
83
+ function eqz(StateId a) public pure returns (bool) {
84
+ return StateId.unwrap(a) == 0;
85
+ }
86
+
87
+ /// @dev Returns true if the values are equal (==).
88
+ function eq(StateId a, StateId b) public pure returns (bool isSame) {
89
+ return eqStateId(a, b);
90
+ }
91
+ }