@etherisc/gif-next 0.0.2-f9905e1 → 0.0.2-f99f1d2-109

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) 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 +4 -0
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +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 +4 -0
  94. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
  95. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
  96. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
  97. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  98. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  99. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +8 -8
  100. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  101. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +45 -128
  102. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  103. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  104. package/artifacts/contracts/registry/Registry.sol/Registerable.json +9 -9
  105. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  106. package/artifacts/contracts/registry/Registry.sol/Registry.json +95 -128
  107. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  108. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  109. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  110. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  111. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  112. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
  113. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  114. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
  115. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
  116. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
  117. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
  118. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
  119. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  120. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  121. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  122. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +453 -0
  123. package/contracts/components/Component.sol +39 -24
  124. package/contracts/components/IPool.sol +9 -3
  125. package/contracts/components/IProduct.sol +11 -6
  126. package/contracts/components/Pool.sol +37 -14
  127. package/contracts/components/Product.sol +48 -24
  128. package/contracts/experiment/errors/Require.sol +38 -0
  129. package/contracts/experiment/errors/Revert.sol +44 -0
  130. package/contracts/experiment/inheritance/A.sol +8 -11
  131. package/contracts/experiment/inheritance/B.sol +10 -5
  132. package/contracts/experiment/inheritance/C.sol +11 -5
  133. package/contracts/experiment/inheritance/IA.sol +2 -7
  134. package/contracts/experiment/inheritance/IB.sol +3 -2
  135. package/contracts/experiment/inheritance/IC.sol +4 -3
  136. package/contracts/experiment/statemachine/Dummy.sol +27 -0
  137. package/contracts/experiment/statemachine/ISM.sol +25 -0
  138. package/contracts/experiment/statemachine/README.md +112 -0
  139. package/contracts/experiment/statemachine/SM.sol +57 -0
  140. package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
  141. package/contracts/experiment/types/TypeA.sol +14 -9
  142. package/contracts/experiment/types/TypeB.sol +14 -9
  143. package/contracts/instance/IInstance.sol +9 -4
  144. package/contracts/instance/Instance.sol +24 -15
  145. package/contracts/instance/access/Access.sol +63 -116
  146. package/contracts/instance/access/IAccess.sol +28 -48
  147. package/contracts/instance/component/ComponentModule.sol +162 -147
  148. package/contracts/instance/component/IComponent.sol +41 -61
  149. package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
  150. package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
  151. package/contracts/instance/policy/IPolicy.sol +19 -35
  152. package/contracts/instance/policy/PolicyModule.sol +52 -44
  153. package/contracts/instance/pool/IPoolModule.sol +9 -26
  154. package/contracts/instance/pool/PoolModule.sol +43 -45
  155. package/contracts/instance/product/IProductService.sol +10 -19
  156. package/contracts/instance/product/ProductService.sol +86 -55
  157. package/contracts/instance/treasury/ITreasury.sol +91 -0
  158. package/contracts/instance/treasury/TokenHandler.sol +24 -0
  159. package/contracts/instance/treasury/TreasuryModule.sol +168 -0
  160. package/contracts/registry/ChainNft.sol +135 -0
  161. package/contracts/registry/IChainNft.sol +21 -0
  162. package/contracts/registry/IRegistry.sol +41 -40
  163. package/contracts/registry/Registry.sol +82 -97
  164. package/contracts/types/Blocknumber.sol +118 -0
  165. package/contracts/types/ChainId.sol +24 -10
  166. package/contracts/types/Fee.sol +32 -0
  167. package/contracts/types/NftId.sol +51 -0
  168. package/contracts/types/ObjectType.sol +107 -0
  169. package/contracts/types/StateId.sol +91 -0
  170. package/contracts/types/Timestamp.sol +102 -0
  171. package/contracts/types/UFixed.sol +206 -0
  172. package/package.json +13 -5
@@ -1,66 +1,67 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {NftId} from "../types/NftId.sol";
5
+ import {ObjectType} from "../types/ObjectType.sol";
6
+
4
7
  interface IOwnable {
5
- function getOwner() external view returns(address owner);
8
+ function getOwner() external view returns (address owner);
6
9
  }
7
10
 
8
11
  interface IRegistryLinked {
9
-
10
12
  event LogDebug(uint256 idx, address module, string comment);
11
13
 
12
- function getRegistry() external view returns(IRegistry registry);
14
+ function getRegistry() external view returns (IRegistry registry);
13
15
  }
14
16
 
15
- interface IRegisterable is
16
- IOwnable,
17
- IRegistryLinked
18
- {
19
-
20
- function register() external returns(uint256 nftId);
21
-
22
- function getNftId() external view returns(uint256 nftId);
23
- function getParentNftId() external view returns(uint256 parentNftId);
24
- function getType() external view returns(uint256 objectType);
25
- function getData() external view returns(bytes memory data);
26
- function isRegisterable() external pure returns(bool);
27
- function getInitialOwner() external view returns(address initialOwner);
28
-
29
- function isRegistered() external view returns(bool);
30
- }
17
+ interface IRegisterable is IOwnable, IRegistryLinked {
18
+ function register() external returns (NftId nftId);
31
19
 
20
+ function getNftId() external view returns (NftId nftId);
32
21
 
33
- interface IRegistry {
22
+ function getParentNftId() external view returns (NftId parentNftId);
23
+
24
+ function getType() external view returns (ObjectType objectType);
25
+
26
+ function getData() external view returns (bytes memory data);
27
+
28
+ function isRegisterable() external pure returns (bool);
34
29
 
30
+ function getInitialOwner() external view returns (address initialOwner);
31
+
32
+ function isRegistered() external view returns (bool);
33
+ }
34
+
35
+ interface IRegistry {
35
36
  struct RegistryInfo {
36
- uint256 nftId;
37
- uint256 parentNftId;
38
- uint256 objectType;
37
+ NftId nftId;
38
+ NftId parentNftId;
39
+ ObjectType objectType;
39
40
  address objectAddress;
40
41
  address initialOwner;
41
42
  }
42
43
 
43
- function TOKEN() external pure returns(uint256);
44
- function INSTANCE() external pure returns(uint256);
45
- function PRODUCT() external pure returns(uint256);
46
- function ORACLE() external pure returns(uint256);
47
- function POOL() external pure returns(uint256);
48
- function POLICY() external pure returns(uint256);
49
- function BUNDLE() external pure returns(uint256);
44
+ function register(address objectAddress) external returns (NftId nftId);
50
45
 
51
- function register(address objectAddress) external returns(uint256 nftId);
52
46
  function registerObjectForInstance(
53
- uint256 parentNftid,
54
- uint256 objectType,
47
+ NftId parentNftid,
48
+ ObjectType objectType,
55
49
  address initialOwner
56
- )
57
- external returns(uint256 nftId);
50
+ ) external returns (NftId nftId);
51
+
52
+ function getObjectCount() external view returns (uint256);
53
+
54
+ function getNftId(
55
+ address objectAddress
56
+ ) external view returns (NftId nftId);
57
+
58
+ function getInfo(
59
+ NftId nftId
60
+ ) external view returns (RegistryInfo memory info);
58
61
 
59
- function transfer(uint256 nftId, address newOwner) external;
62
+ function getOwner(NftId nftId) external view returns (address ownerAddress);
60
63
 
61
- function getNftId(address objectAddress) external view returns(uint256 nftId);
62
- function getInfo(uint256 nftId) external view returns(RegistryInfo memory info);
63
- function getOwner(uint256 nftId) external view returns(address ownerAddress);
64
+ function isRegistered(address objectAddress) external view returns (bool);
64
65
 
65
- function isRegistered(address objectAddress) external view returns(bool);
66
+ function getNftAddress() external view returns (address nft);
66
67
  }
@@ -1,111 +1,107 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {IChainNft} from "./IChainNft.sol";
4
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";
5
8
 
6
9
  contract RegistryLinked is IRegistryLinked {
7
-
8
10
  IRegistry internal _registry;
9
-
11
+
10
12
  constructor(address registry) {
11
13
  _registry = IRegistry(registry);
12
14
  }
13
15
 
14
- // function setRegistry(address registry) public override {
15
- // require(address(_registry) == address(0), "ERROR:RGL-001:REGISTRY_ALREADY_SET");
16
- // _registry = IRegistry(registry);
17
- // }
18
-
19
- function getRegistry() external view override returns(IRegistry registry) {
16
+ function getRegistry() external view override returns (IRegistry registry) {
20
17
  return _registry;
21
18
  }
22
-
23
19
  }
24
20
 
25
-
26
- abstract contract Registerable is
27
- RegistryLinked,
28
- IRegisterable
29
- {
21
+ abstract contract Registerable is RegistryLinked, IRegisterable {
22
+ using NftIdLib for NftId;
30
23
 
31
24
  address private _initialOwner;
32
-
33
- constructor(address registry)
34
- RegistryLinked(registry)
35
- {
25
+
26
+ constructor(address registry) RegistryLinked(registry) {
36
27
  _initialOwner = msg.sender;
37
28
  }
38
29
 
39
30
  // getType, getData and register need to be implemented by concrete contract
40
31
 
41
- function isRegisterable() external pure override returns(bool) {
32
+ function isRegisterable() external pure override returns (bool) {
42
33
  return true;
43
34
  }
44
35
 
45
- function getInitialOwner() public view override returns(address deployer) {
36
+ function getInitialOwner() public view override returns (address deployer) {
46
37
  return _initialOwner;
47
38
  }
48
39
 
49
- function isRegistered() public view override returns(bool) {
50
- 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();
51
43
  }
52
44
 
53
- function getNftId() public view override returns(uint256 id) {
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) {
58
- uint256 id = _registry.getNftId(address(this));
49
+ function getOwner() public view override returns (address owner) {
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
- // struct RegistryInfo {
66
- // bytes32 id;
67
- // uint256 objectType;
68
- // address objectAddress;
69
- // address initialOwner;
70
- // }
71
-
72
56
  contract Registry is IRegistry {
57
+ using NftIdLib for NftId;
73
58
 
74
- mapping(uint256 id => RegistryInfo info) private _info;
75
- mapping(uint256 id => address owner) private _owner;
76
- mapping(address object => uint256 id) private _idByAddress;
77
- uint256 [] private _ids;
78
- uint256 private _idNext;
59
+ string public constant EMPTY_URI = "";
79
60
 
61
+ mapping(NftId nftId => RegistryInfo info) private _info;
62
+ mapping(NftId nftId => address owner) private _owner;
63
+ mapping(address object => NftId nftId) private _nftIdByAddress;
80
64
 
81
- constructor() {
82
- _idNext = 0;
83
- }
65
+ IChainNft private _chainNft;
84
66
 
85
- function TOKEN() public pure override returns(uint256) { return 30; }
86
- function INSTANCE() public pure override returns(uint256) { return 40; }
87
- function PRODUCT() public pure override returns(uint256) { return 50; }
88
- function ORACLE() public pure override returns(uint256) { return 60; }
89
- function POOL() public pure override returns(uint256) { return 70; }
90
- function POLICY() public pure override returns(uint256) { return 80; }
91
- function BUNDLE() public pure override returns(uint256) { return 90; }
67
+ function initialize(address chainNft) external {
68
+ require(
69
+ address(_chainNft) == address(0),
70
+ "ERROR:REG-001:ALREADY_INITIALIZED"
71
+ );
72
+ _chainNft = IChainNft(chainNft);
73
+ }
92
74
 
93
- function register(address objectAddress) external override returns(uint256 nftId) {
94
- require(_idByAddress[objectAddress] == 0, "ERROR:REG-001: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
+ );
95
82
 
96
83
  IRegisterable registerable = IRegisterable(objectAddress);
97
- require(registerable.isRegisterable(), "ERROR:REG-002:NOT_REGISTERABLE");
84
+ require(
85
+ registerable.isRegisterable(),
86
+ "ERROR:REG-003:NOT_REGISTERABLE"
87
+ );
98
88
 
99
89
  // check parent exists (for objects not instances)
100
- if(registerable.getType() != INSTANCE()) {
101
- RegistryInfo memory parentInfo = _info[registerable.getParentNftId()];
102
- require(parentInfo.nftId > 0, "ERROR:REG-003: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");
103
95
  // check validity of parent relation, valid relations are
104
96
  // policy -> product, bundle -> pool, product -> instance, pool -> instance
105
97
  }
106
98
 
107
- nftId = _mint(registerable.getInitialOwner());
108
-
99
+ uint256 mintedTokenId = _chainNft.mint(
100
+ registerable.getInitialOwner(),
101
+ EMPTY_URI
102
+ );
103
+ nftId = toNftId(mintedTokenId);
104
+
109
105
  RegistryInfo memory info = RegistryInfo(
110
106
  nftId,
111
107
  registerable.getParentNftId(),
@@ -115,28 +111,31 @@ contract Registry is IRegistry {
115
111
  );
116
112
 
117
113
  _info[nftId] = info;
118
- _idByAddress[objectAddress] = nftId;
114
+ _nftIdByAddress[objectAddress] = nftId;
119
115
 
120
116
  // add logging
121
117
  }
122
118
 
123
-
124
119
  function registerObjectForInstance(
125
- uint256 parentNftId,
126
- uint256 objectType,
120
+ NftId parentNftId,
121
+ ObjectType objectType,
127
122
  address initialOwner
128
123
  )
129
- external
124
+ external
130
125
  override
131
- // TODO add onlyRegisteredInstance
132
- returns(uint256 nftId)
126
+ returns (
127
+ // TODO add onlyRegisteredInstance
128
+ NftId nftId
129
+ )
133
130
  {
134
131
  // TODO add more validation
135
132
  require(
136
133
  objectType == POLICY() || objectType == BUNDLE(),
137
- "ERROR:REG-005:TYPE_INVALID");
134
+ "ERROR:REG-005:TYPE_INVALID"
135
+ );
138
136
 
139
- nftId = _mint(initialOwner);
137
+ uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
138
+ nftId = toNftId(mintedTokenId);
140
139
 
141
140
  RegistryInfo memory info = RegistryInfo(
142
141
  nftId,
@@ -151,47 +150,33 @@ contract Registry is IRegistry {
151
150
  // add logging
152
151
  }
153
152
 
154
-
155
- function transfer(uint256 id, address newOwner) external {
156
- require(msg.sender == _owner[id], "ERROR:REG-010:NOT_OWNER");
157
- _owner[id] = newOwner;
158
-
159
- // TODO logging
160
- }
161
-
162
-
163
- function getObjectCount() external view returns(uint256) {
164
- return _ids.length;
153
+ function getObjectCount() external view override returns (uint256) {
154
+ return _chainNft.totalSupply();
165
155
  }
166
156
 
167
-
168
- function getNftId(address object) external view override returns(uint256 id) {
169
- return _idByAddress[object];
157
+ function getNftId(
158
+ address object
159
+ ) external view override returns (NftId id) {
160
+ return _nftIdByAddress[object];
170
161
  }
171
162
 
172
-
173
- function isRegistered(address object) external view override returns(bool) {
174
- return _idByAddress[object] > 0;
163
+ function isRegistered(
164
+ address object
165
+ ) external view override returns (bool) {
166
+ return _nftIdByAddress[object].gtz();
175
167
  }
176
168
 
177
-
178
- function getInfo(uint256 id) external view override returns(RegistryInfo memory info) {
179
- return _info[id];
169
+ function getInfo(
170
+ NftId nftId
171
+ ) external view override returns (RegistryInfo memory info) {
172
+ return _info[nftId];
180
173
  }
181
174
 
182
- function getOwner(uint256 id) external view override returns(address) {
183
- return _owner[id];
175
+ function getOwner(NftId nftId) external view override returns (address) {
176
+ return _chainNft.ownerOf(nftId.toInt());
184
177
  }
185
178
 
186
-
187
- function _mint(address initialOwner)
188
- internal
189
- returns(uint256 id)
190
- {
191
- _idNext++;
192
-
193
- id = _idNext;
194
- _owner[id] = initialOwner;
195
- _ids.push(id);
179
+ function getNftAddress() external view override returns (address nft) {
180
+ return address(_chainNft);
196
181
  }
197
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 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
+ }
@@ -0,0 +1,51 @@
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 NftId is uint96;
6
+
7
+ // type bindings
8
+ using {eqNftId as ==, neNftId as !=, NftIdLib.toInt} for NftId global;
9
+
10
+ // general pure free functions
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
+ }
20
+
21
+ // pure free functions for operators
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
+ }
29
+
30
+ // library functions that operate on user defined type
31
+ library NftIdLib {
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
+ }
51
+ }