@etherisc/gif-next 0.0.2-b9b3e89 → 0.0.2-c4efd5e

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. package/README.md +25 -0
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +7 -7
  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 +6 -6
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +8 -8
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +29 -11
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +31 -13
  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 +4 -0
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
  24. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
  25. package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
  27. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
  28. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
  30. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
  32. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
  34. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
  35. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
  36. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
  37. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
  38. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  39. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +60 -60
  40. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  41. package/artifacts/contracts/instance/Instance.sol/Instance.json +122 -64
  42. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  43. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  44. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  45. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  46. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  47. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  48. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +24 -24
  49. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  50. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +48 -6
  51. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  52. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  53. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +6 -6
  54. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +26 -26
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +3 -3
  58. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  59. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  60. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  61. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +18 -18
  62. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  63. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +18 -18
  64. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  65. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  66. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +10 -10
  67. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  68. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +10 -10
  69. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  70. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  71. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +8 -8
  72. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  73. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  74. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +54 -12
  75. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  76. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
  77. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
  78. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
  79. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  80. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  81. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +6 -6
  82. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  83. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +41 -33
  84. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  85. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  86. package/artifacts/contracts/registry/Registry.sol/Registerable.json +7 -7
  87. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  88. package/artifacts/contracts/registry/Registry.sol/Registry.json +100 -42
  89. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  90. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  91. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  92. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  93. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  94. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  95. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  96. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
  97. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  98. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  99. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  100. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +453 -0
  101. package/contracts/components/Component.sol +17 -19
  102. package/contracts/components/IPool.sol +3 -3
  103. package/contracts/components/IProduct.sol +4 -6
  104. package/contracts/components/Pool.sol +6 -13
  105. package/contracts/components/Product.sol +12 -22
  106. package/contracts/experiment/errors/Require.sol +38 -0
  107. package/contracts/experiment/errors/Revert.sol +44 -0
  108. package/contracts/experiment/inheritance/A.sol +53 -0
  109. package/contracts/experiment/inheritance/B.sol +28 -0
  110. package/contracts/experiment/inheritance/C.sol +34 -0
  111. package/contracts/experiment/inheritance/IA.sol +13 -0
  112. package/contracts/experiment/inheritance/IB.sol +10 -0
  113. package/contracts/experiment/inheritance/IC.sol +12 -0
  114. package/contracts/experiment/types/TypeA.sol +47 -0
  115. package/contracts/experiment/types/TypeB.sol +29 -0
  116. package/contracts/instance/IInstance.sol +4 -6
  117. package/contracts/instance/Instance.sol +15 -14
  118. package/contracts/instance/access/Access.sol +63 -116
  119. package/contracts/instance/access/IAccess.sol +28 -48
  120. package/contracts/instance/component/ComponentModule.sol +84 -130
  121. package/contracts/instance/component/IComponent.sol +32 -53
  122. package/contracts/instance/policy/IPolicy.sol +12 -27
  123. package/contracts/instance/policy/PolicyModule.sol +25 -40
  124. package/contracts/instance/pool/IPoolModule.sol +10 -21
  125. package/contracts/instance/pool/PoolModule.sol +28 -38
  126. package/contracts/instance/product/IProductService.sol +9 -18
  127. package/contracts/instance/product/ProductService.sol +54 -47
  128. package/contracts/registry/ChainNft.sol +135 -0
  129. package/contracts/registry/IChainNft.sol +21 -0
  130. package/contracts/registry/IRegistry.sol +52 -38
  131. package/contracts/registry/Registry.sol +107 -95
  132. package/contracts/types/Blocknumber.sol +118 -0
  133. package/contracts/types/ChainId.sol +38 -0
  134. package/contracts/types/NftId.sol +51 -0
  135. package/contracts/types/Timestamp.sol +102 -0
  136. package/contracts/types/UFixed.sol +205 -0
  137. package/package.json +7 -3
@@ -0,0 +1,38 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ contract Require {
5
+ error AsmallerThanB_S();
6
+ error AsmallerThanB_M(uint a);
7
+ error AsmallerThanB_L(uint a, uint b);
8
+
9
+ uint256 private _b;
10
+
11
+ constructor() {
12
+ _b = 42;
13
+ }
14
+
15
+ function isAlargerThanBRequire_S(
16
+ uint a
17
+ ) external view returns (bool isLarger) {
18
+ require(a > _b, "ERROR:ABC-001");
19
+
20
+ return true;
21
+ }
22
+
23
+ function isAlargerThanBRequire_M(
24
+ uint a
25
+ ) external view returns (bool isLarger) {
26
+ require(a > _b, "ERROR:ABC-002:A_IS_SMALLER");
27
+
28
+ return true;
29
+ }
30
+
31
+ function isAlargerThanBRequire_L(
32
+ uint a
33
+ ) external view returns (bool isLarger) {
34
+ require(a > _b, "ERROR:ABC-003:A_IS_SMALLER_THAN_B");
35
+
36
+ return true;
37
+ }
38
+ }
@@ -0,0 +1,44 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ contract Revert {
5
+ error AsmallerThanB_S();
6
+ error AsmallerThanB_M(uint a);
7
+ error AsmallerThanB_L(uint a, uint b);
8
+
9
+ uint256 private _b;
10
+
11
+ constructor() {
12
+ _b = 42;
13
+ }
14
+
15
+ function isAlargerThanBRevert_S(
16
+ uint a
17
+ ) external view returns (bool isLarger) {
18
+ if (a <= _b) {
19
+ revert AsmallerThanB_S();
20
+ }
21
+
22
+ return true;
23
+ }
24
+
25
+ function isAlargerThanBRevert_M(
26
+ uint a
27
+ ) external view returns (bool isLarger) {
28
+ if (a <= _b) {
29
+ revert AsmallerThanB_M(a);
30
+ }
31
+
32
+ return true;
33
+ }
34
+
35
+ function isAlargerThanBRevert_L(
36
+ uint a
37
+ ) external view returns (bool isLarger) {
38
+ if (a <= _b) {
39
+ revert AsmallerThanB_L(a, _b);
40
+ }
41
+
42
+ return true;
43
+ }
44
+ }
@@ -0,0 +1,53 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IA, ISharedA} from "./IA.sol";
5
+ import {B} from "./B.sol";
6
+ import {C} from "./C.sol";
7
+
8
+ /*
9
+
10
+ # dependency graph
11
+
12
+ B <...+
13
+ ^ |
14
+ | |
15
+ A --> C
16
+
17
+ - A is the main contract
18
+ - A provides functionality implemented by modules B and C
19
+ - B and C rely on functionality shared by A
20
+ - C accesses functionality of module B
21
+
22
+ # chisel session
23
+
24
+ import {A} from "./contracts/experiment/A.sol";
25
+ A a = new A();
26
+ uint(a.getA())
27
+ uint(a.getB()))
28
+ uint(a.getC())
29
+ uint(a.getAfromB())
30
+ uint(a.getAfromC())
31
+ uint(a.getBfromC())
32
+ a.setA(100);
33
+ a.setB(10);
34
+ a.setC(20);
35
+ */
36
+
37
+ contract AShared is ISharedA {
38
+ uint256 private _x;
39
+
40
+ constructor() {
41
+ _x = 42;
42
+ }
43
+
44
+ function getA() external view override returns (uint256) {
45
+ return _x;
46
+ }
47
+
48
+ function setA(uint256 newA) external override {
49
+ _x = newA;
50
+ }
51
+ }
52
+
53
+ contract A is AShared, B, C, IA {}
@@ -0,0 +1,28 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {ISharedA} from "./IA.sol";
5
+ import {IB} from "./IB.sol";
6
+
7
+ abstract contract B is ISharedA, IB {
8
+ // names of private variables can be re-used in inheritance
9
+ uint256 private _x;
10
+
11
+ constructor() {
12
+ _x = 1;
13
+ }
14
+
15
+ // access own state
16
+ function getB() external view override returns (uint256) {
17
+ return _x;
18
+ }
19
+
20
+ function setB(uint256 newB) external override {
21
+ _x = newB;
22
+ }
23
+
24
+ // access state from parent contract A
25
+ function getAfromB() external view override returns (uint256) {
26
+ return this.getA();
27
+ }
28
+ }
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {ISharedA} from "./IA.sol";
5
+ import {IB} from "./IB.sol";
6
+ import {IC} from "./IC.sol";
7
+
8
+ abstract contract C is ISharedA, IC {
9
+ uint256 private _x;
10
+
11
+ constructor() {
12
+ _x = 2;
13
+ }
14
+
15
+ // access own state
16
+ function getC() external view override returns (uint256) {
17
+ return _x;
18
+ }
19
+
20
+ function setC(uint256 newC) external override {
21
+ _x = newC;
22
+ }
23
+
24
+ // access state from parent contract A
25
+ function getAfromC() external view override returns (uint256) {
26
+ return this.getA();
27
+ }
28
+
29
+ // access state from other module B
30
+ function getBfromC() external view override returns (uint256) {
31
+ IB b = IB(address(this));
32
+ return b.getB();
33
+ }
34
+ }
@@ -0,0 +1,13 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IB} from "./IB.sol";
5
+ import {IC} from "./IC.sol";
6
+
7
+ interface ISharedA {
8
+ function getA() external view returns (uint256);
9
+
10
+ function setA(uint256 newA) external;
11
+ }
12
+
13
+ interface IA is ISharedA, IB, IC {}
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ interface IB {
5
+ function getAfromB() external view returns (uint256);
6
+
7
+ function getB() external view returns (uint256);
8
+
9
+ function setB(uint256 newA) external;
10
+ }
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ interface IC {
5
+ function getAfromC() external view returns (uint256);
6
+
7
+ function getBfromC() external view returns (uint256);
8
+
9
+ function getC() external view returns (uint256);
10
+
11
+ function setC(uint256 newA) external;
12
+ }
@@ -0,0 +1,47 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ /*
5
+ # chisel session for user defined types
6
+
7
+ import {TypeA, toTypeA} from "./contracts/experiment/types/TypeA.sol";
8
+ TypeA a = toTypeA(1);
9
+ TypeA b = toTypeA(2);
10
+ uint(a.toInt())
11
+ uint(b.toInt())
12
+ a == b
13
+ a != b
14
+
15
+ import {TypeB, toTypeB} from "./contracts/experiment/types/TypeB.sol";
16
+ TypeB x = toTypeB(33);
17
+ uint(x.toInt())
18
+ a == x; // -> error
19
+ a.toInt() == x.toInt() // -> no error
20
+ */
21
+
22
+ // bytes5 allows for chain ids up to 13 digits
23
+ type TypeA is uint248;
24
+
25
+ // type bindings
26
+ using {eqTypeA as ==, neTypeA as !=, TypeALib.toInt} for TypeA global;
27
+
28
+ // general pure free functions
29
+ function toTypeA(uint256 typeA) pure returns (TypeA) {
30
+ return TypeA.wrap(uint248(typeA));
31
+ }
32
+
33
+ // pure free functions for operators
34
+ function eqTypeA(TypeA a, TypeA b) pure returns (bool isSame) {
35
+ return TypeA.unwrap(a) == TypeA.unwrap(b);
36
+ }
37
+
38
+ function neTypeA(TypeA a, TypeA b) pure returns (bool isDifferent) {
39
+ return TypeA.unwrap(a) != TypeA.unwrap(b);
40
+ }
41
+
42
+ // library functions that operate on user defined type
43
+ library TypeALib {
44
+ function toInt(TypeA typeA) internal pure returns (uint256) {
45
+ return uint256(TypeA.unwrap(typeA));
46
+ }
47
+ }
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ // bytes5 allows for chain ids up to 13 digits
5
+ type TypeB is uint248;
6
+
7
+ // type bindings
8
+ using {eqTypeB as ==, addTypeB as +, TypeBLib.toInt} for TypeB global;
9
+
10
+ // general pure free functions
11
+ function toTypeB(uint256 x) pure returns (TypeB) {
12
+ return TypeB.wrap(uint248(x));
13
+ }
14
+
15
+ // pure free functions for operators
16
+ function eqTypeB(TypeB a, TypeB b) pure returns (bool isSame) {
17
+ return TypeB.unwrap(a) == TypeB.unwrap(b);
18
+ }
19
+
20
+ function addTypeB(TypeB a, TypeB b) pure returns (TypeB sum) {
21
+ return TypeB.wrap(TypeB.unwrap(a) + TypeB.unwrap(b));
22
+ }
23
+
24
+ // library functions that operate on user defined type
25
+ library TypeBLib {
26
+ function toInt(TypeB b) internal pure returns (uint256) {
27
+ return uint256(TypeB.unwrap(b));
28
+ }
29
+ }
@@ -8,13 +8,11 @@ import {IProductModule} from "./product/IProductService.sol";
8
8
  import {IPolicyModule} from "./policy/IPolicy.sol";
9
9
  import {IPoolModule} from "./pool/IPoolModule.sol";
10
10
 
11
-
12
11
  interface IInstance is
13
12
  IRegisterable,
14
13
  IAccessModule,
15
- IComponentModule,
16
- IProductModule,
17
14
  IPolicyModule,
18
- IPoolModule
19
- { }
20
-
15
+ IPoolModule,
16
+ IComponentModule,
17
+ IProductModule
18
+ {}
@@ -11,17 +11,17 @@ import {PolicyModule} from "./policy/PolicyModule.sol";
11
11
  import {PoolModule} from "./pool/PoolModule.sol";
12
12
 
13
13
  import {IInstance} from "./IInstance.sol";
14
+ import {NftId, toNftId} from "../types/NftId.sol";
14
15
 
15
16
  contract Instance is
16
17
  Registerable,
17
18
  AccessModule,
18
- ComponentModule,
19
- PolicyModule,
19
+ ComponentModule,
20
+ PolicyModule,
20
21
  PoolModule,
21
- ProductModule,
22
+ ProductModule,
22
23
  IInstance
23
24
  {
24
-
25
25
  constructor(
26
26
  address registry,
27
27
  address componentOwnerService,
@@ -33,31 +33,32 @@ contract Instance is
33
33
  PolicyModule(productService)
34
34
  ProductModule(productService)
35
35
  PoolModule(productService)
36
- { }
36
+ {}
37
37
 
38
38
  // from registerable
39
- function register() external override returns(uint256 id) {
40
- require(address(_registry) != address(0), "ERROR:PRD-001:REGISTRY_ZERO");
39
+ function register() external override returns (NftId nftId) {
40
+ require(
41
+ address(_registry) != address(0),
42
+ "ERROR:PRD-001:REGISTRY_ZERO"
43
+ );
41
44
  return _registry.register(address(this));
42
45
  }
43
46
 
44
47
  // from registerable
45
- function getParentNftId() public view override returns(uint256) {
48
+ function getParentNftId() public view override returns (NftId) {
46
49
  // TODO add self registry and exchange 0 for_registry.getNftId();
47
50
  // define parent tree for all registerables
48
- // eg 0 <- chain(mainnet) <- global registry <- chain registry <- instance <- component <- policy/bundle
49
- return 0;
51
+ // eg 0 <- chain(mainnet) <- global registry <- chain registry <- instance <- component <- policy/bundle
52
+ return toNftId(0);
50
53
  }
51
54
 
52
55
  // from registerable
53
- function getType() external view override returns(uint256 objectType) {
56
+ function getType() external view override returns (uint256 objectType) {
54
57
  return _registry.INSTANCE();
55
58
  }
56
59
 
57
60
  // from registerable
58
- function getData() external view override returns(bytes memory data) {
61
+ function getData() external view override returns (bytes memory data) {
59
62
  return bytes(abi.encode(0));
60
63
  }
61
-
62
-
63
64
  }
@@ -7,26 +7,24 @@ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
7
7
 
8
8
  import {IAccessModule} from "./IAccess.sol";
9
9
 
10
-
11
- abstract contract AccessModule is
12
- IAccessModule
13
- {
14
- string constant public PRODUCT_OWNER = "ProductOwner";
15
- string constant public ORACLE_OWNER = "OracleOwner";
16
- string constant public POOL_OWNER = "PoolOwner";
10
+ abstract contract AccessModule is IAccessModule {
11
+ string public constant PRODUCT_OWNER = "ProductOwner";
12
+ string public constant ORACLE_OWNER = "OracleOwner";
13
+ string public constant POOL_OWNER = "PoolOwner";
17
14
 
18
15
  using EnumerableSet for EnumerableSet.AddressSet;
19
16
 
20
17
  event LogAccessRoleGranted(bytes32 role, address member, bool isMember);
21
18
 
22
19
  mapping(bytes32 role => RoleInfo info) private _info;
23
- bytes32 [] private _roles;
20
+ bytes32[] private _roles;
24
21
 
25
22
  bytes32 private immutable _productOwnerRole;
26
23
  bytes32 private immutable _oracleOwnerRole;
27
24
  bytes32 private immutable _poolOwnerRole;
28
25
 
29
- mapping(bytes32 role => mapping(address member => bool isMember)) private _isRoleMember;
26
+ mapping(bytes32 role => mapping(address member => bool isMember))
27
+ private _isRoleMember;
30
28
  mapping(bytes32 role => EnumerableSet.AddressSet) private _roleMembers;
31
29
 
32
30
  modifier onlyOwner() {
@@ -40,70 +38,54 @@ abstract contract AccessModule is
40
38
  _poolOwnerRole = _createRole(POOL_OWNER);
41
39
  }
42
40
 
43
- function PRODUCT_OWNER_ROLE() public view override returns(bytes32 role) { return _productOwnerRole; }
44
- function ORACLE_OWNER_ROLE() public view override returns(bytes32 role) { return _oracleOwnerRole; }
45
- function POOL_OWNER_ROLE() public view override returns(bytes32 role) { return _poolOwnerRole; }
41
+ function PRODUCT_OWNER_ROLE() public view override returns (bytes32 role) {
42
+ return _productOwnerRole;
43
+ }
44
+
45
+ function ORACLE_OWNER_ROLE() public view override returns (bytes32 role) {
46
+ return _oracleOwnerRole;
47
+ }
46
48
 
49
+ function POOL_OWNER_ROLE() public view override returns (bytes32 role) {
50
+ return _poolOwnerRole;
51
+ }
47
52
 
48
- function createRole(string memory roleName)
49
- external
50
- override
51
- onlyOwner
52
- returns(bytes32 role)
53
- {
53
+ function createRole(
54
+ string memory roleName
55
+ ) external override onlyOwner returns (bytes32 role) {
54
56
  return _createRole(roleName);
55
57
  }
56
58
 
57
- function _createRole(string memory roleName)
58
- internal
59
- returns(bytes32 role)
60
- {
61
- RoleInfo memory info = RoleInfo(
62
- 0,
63
- roleName,
64
- true
65
- );
59
+ function _createRole(
60
+ string memory roleName
61
+ ) internal returns (bytes32 role) {
62
+ RoleInfo memory info = RoleInfo(0, roleName, true);
66
63
 
67
64
  role = _setRoleInfo(info);
68
-
69
-
70
65
  }
71
66
 
72
67
  // TODO move to module
73
- function disableRole(bytes32 role)
74
- external
75
- override
76
- onlyOwner
77
- {
68
+ function disableRole(bytes32 role) external override onlyOwner {
78
69
  RoleInfo memory info = _info[role];
79
70
  require(info.id == role, "ERROR:AOS-001:ROLE_DOES_NOT_EXIST");
80
71
 
81
72
  info.isActive = false;
82
73
  _setRoleInfo(info);
83
-
84
-
85
- }
74
+ }
86
75
 
87
76
  // TODO move to module
88
- function enableRole(bytes32 role)
89
- external
90
- override
91
- onlyOwner
92
- {
77
+ function enableRole(bytes32 role) external override onlyOwner {
93
78
  RoleInfo memory info = _info[role];
94
79
  require(info.id == role, "ERROR:AOS-002:ROLE_DOES_NOT_EXIST");
95
80
 
96
81
  info.isActive = true;
97
82
  _setRoleInfo(info);
83
+ }
98
84
 
99
-
100
- }
101
-
102
- function grantRole(bytes32 role, address member)
103
- external
104
- override
105
- onlyOwner
106
- {
85
+ function grantRole(
86
+ bytes32 role,
87
+ address member
88
+ ) external override onlyOwner {
107
89
  require(_info[role].id == role, "ERROR:ACM-010:ROLE_NOT_EXISTING");
108
90
  require(_info[role].isActive, "ERROR:ACM-011:ROLE_NOT_ACTIVE");
109
91
 
@@ -113,106 +95,71 @@ abstract contract AccessModule is
113
95
  emit LogAccessRoleGranted(role, member, _isRoleMember[role][member]);
114
96
  }
115
97
 
116
-
117
- function revokeRole(bytes32 role, address member)
118
- external
119
- override
120
- onlyOwner
121
- {
98
+ function revokeRole(
99
+ bytes32 role,
100
+ address member
101
+ ) external override onlyOwner {
122
102
  require(_info[role].id == role, "ERROR:ACM-020:ROLE_NOT_EXISTING");
123
103
 
124
104
  _isRoleMember[role][member] = false;
125
105
  _roleMembers[role].remove(member);
126
-
127
-
128
106
  }
129
107
 
130
-
131
- function hasRole(bytes32 role, address member)
132
- external
133
- view
134
- override
135
- returns(bool)
136
- {
108
+ function hasRole(
109
+ bytes32 role,
110
+ address member
111
+ ) external view override returns (bool) {
137
112
  return _isRoleMember[role][member];
138
113
  }
139
114
 
140
-
141
- function getRoleInfo(bytes32 role)
142
- external
143
- override
144
- view
145
- returns(RoleInfo memory info)
146
- {
115
+ function getRoleInfo(
116
+ bytes32 role
117
+ ) external view override returns (RoleInfo memory info) {
147
118
  return _info[role];
148
119
  }
149
120
 
150
-
151
- function getRole(uint256 idx)
152
- external
153
- override
154
- view
155
- returns(bytes32 role)
156
- {
121
+ function getRole(
122
+ uint256 idx
123
+ ) external view override returns (bytes32 role) {
157
124
  return _roles[idx];
158
125
  }
159
126
 
160
-
161
- function getRoleCount()
162
- external
163
- override
164
- view
165
- returns(uint256 roles)
166
- {
127
+ function getRoleCount() external view override returns (uint256 roles) {
167
128
  return _roles.length;
168
- }
169
-
170
- function getRoleMemberCount(bytes32 role)
171
- public
172
- override
173
- view
174
- returns(uint256 roleMembers)
175
- {
129
+ }
130
+
131
+ function getRoleMemberCount(
132
+ bytes32 role
133
+ ) public view override returns (uint256 roleMembers) {
176
134
  return _roleMembers[role].length();
177
135
  }
178
136
 
179
- function getRoleMember(bytes32 role, uint256 idx)
180
- public
181
- override
182
- view
183
- returns(address roleMembers)
184
- {
137
+ function getRoleMember(
138
+ bytes32 role,
139
+ uint256 idx
140
+ ) public view override returns (address roleMembers) {
185
141
  return _roleMembers[role].at(idx);
186
142
  }
187
143
 
188
- function getRoleForName(string memory roleName)
189
- public
190
- override
191
- pure
192
- returns(bytes32 role)
193
- {
144
+ function getRoleForName(
145
+ string memory roleName
146
+ ) public pure override returns (bytes32 role) {
194
147
  return keccak256(abi.encode(roleName));
195
148
  }
196
149
 
197
-
198
- function _setRoleInfo(RoleInfo memory info)
199
- internal
200
- returns(bytes32 role)
201
- {
150
+ function _setRoleInfo(
151
+ RoleInfo memory info
152
+ ) internal returns (bytes32 role) {
202
153
  role = info.id;
203
154
 
204
- if(role == bytes32(0)) {
155
+ if (role == bytes32(0)) {
205
156
  role = getRoleForName(info.name);
206
157
  // TODO check that this is a new role id
207
158
 
208
159
  info.id = role;
209
160
  _roles.push(role);
210
-
211
-
212
161
  }
213
162
 
214
163
  _info[role] = info;
215
-
216
-
217
164
  }
218
165
  }