@etherisc/gif-next 0.0.2-b9b3e89 → 0.0.2-d250c72
Sign up to get free protection for your applications and to get access to all the features.
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/Component.json +7 -7
- package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +6 -6
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +8 -8
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +29 -11
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +31 -13
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
- package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +60 -60
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +122 -64
- package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +24 -24
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +48 -6
- package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +6 -6
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +26 -26
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +3 -3
- package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +18 -18
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +18 -18
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +10 -10
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +10 -10
- package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +8 -8
- package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +54 -12
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
- package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +6 -6
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +41 -33
- package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registerable.json +7 -7
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +100 -42
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
- package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
- package/contracts/components/Component.sol +3 -3
- package/contracts/components/IProduct.sol +2 -1
- package/contracts/components/Product.sol +5 -4
- package/contracts/experiment/errors/Require.sol +33 -0
- package/contracts/experiment/errors/Revert.sol +39 -0
- package/contracts/experiment/inheritance/A.sol +56 -0
- package/contracts/experiment/inheritance/B.sol +23 -0
- package/contracts/experiment/inheritance/C.sol +28 -0
- package/contracts/experiment/inheritance/IA.sol +18 -0
- package/contracts/experiment/inheritance/IB.sol +9 -0
- package/contracts/experiment/inheritance/IC.sol +11 -0
- package/contracts/experiment/types/TypeA.sol +42 -0
- package/contracts/experiment/types/TypeB.sol +24 -0
- package/contracts/instance/IInstance.sol +3 -3
- package/contracts/instance/Instance.sol +4 -3
- package/contracts/instance/component/ComponentModule.sol +32 -43
- package/contracts/instance/component/IComponent.sol +11 -10
- package/contracts/instance/policy/IPolicy.sol +8 -8
- package/contracts/instance/policy/PolicyModule.sol +12 -11
- package/contracts/instance/pool/IPoolModule.sol +6 -5
- package/contracts/instance/pool/PoolModule.sol +9 -6
- package/contracts/instance/product/IProductService.sol +5 -4
- package/contracts/instance/product/ProductService.sol +14 -11
- package/contracts/registry/ChainNft.sol +173 -0
- package/contracts/registry/IChainNft.sol +18 -0
- package/contracts/registry/IRegistry.sol +16 -12
- package/contracts/registry/Registry.sol +43 -58
- package/contracts/types/ChainId.sol +24 -0
- package/contracts/types/NftId.sol +35 -0
- package/package.json +1 -1
@@ -0,0 +1,56 @@
|
|
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
|
+
|
39
|
+
uint256 private _x;
|
40
|
+
|
41
|
+
constructor() {
|
42
|
+
_x = 42;
|
43
|
+
}
|
44
|
+
|
45
|
+
function getA() external view override returns(uint256) { return _x; }
|
46
|
+
function setA(uint256 newA) external override { _x = newA; }
|
47
|
+
}
|
48
|
+
|
49
|
+
contract A is
|
50
|
+
AShared,
|
51
|
+
B,
|
52
|
+
C,
|
53
|
+
IA
|
54
|
+
{
|
55
|
+
|
56
|
+
}
|
@@ -0,0 +1,23 @@
|
|
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
|
+
|
9
|
+
// names of private variables can be re-used in inheritance
|
10
|
+
uint256 private _x;
|
11
|
+
|
12
|
+
constructor() {
|
13
|
+
_x = 1;
|
14
|
+
}
|
15
|
+
|
16
|
+
// access own state
|
17
|
+
function getB() external view override returns(uint256) { return _x; }
|
18
|
+
function setB(uint256 newB) external override { _x = newB; }
|
19
|
+
|
20
|
+
// access state from parent contract A
|
21
|
+
function getAfromB() external view override returns(uint256) { return this.getA(); }
|
22
|
+
|
23
|
+
}
|
@@ -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
|
+
import {IC} from "./IC.sol";
|
7
|
+
|
8
|
+
abstract contract C is ISharedA, IC {
|
9
|
+
|
10
|
+
uint256 private _x;
|
11
|
+
|
12
|
+
constructor() {
|
13
|
+
_x = 2;
|
14
|
+
}
|
15
|
+
|
16
|
+
// access own state
|
17
|
+
function getC() external view override returns(uint256) { return _x; }
|
18
|
+
function setC(uint256 newC) external override { _x = newC; }
|
19
|
+
|
20
|
+
// access state from parent contract A
|
21
|
+
function getAfromC() external view override returns(uint256) { return this.getA(); }
|
22
|
+
|
23
|
+
// access state from other module B
|
24
|
+
function getBfromC() external view override returns(uint256) {
|
25
|
+
IB b = IB(address(this));
|
26
|
+
return b.getB();
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,18 @@
|
|
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
|
+
|
9
|
+
function getA() external view returns(uint256);
|
10
|
+
function setA(uint256 newA) external;
|
11
|
+
}
|
12
|
+
|
13
|
+
interface IA is
|
14
|
+
ISharedA,
|
15
|
+
IB,
|
16
|
+
IC
|
17
|
+
{
|
18
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
interface IC {
|
5
|
+
|
6
|
+
function getAfromC() external view returns(uint256);
|
7
|
+
function getBfromC() external view returns(uint256);
|
8
|
+
|
9
|
+
function getC() external view returns(uint256);
|
10
|
+
function setC(uint256 newA) external;
|
11
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
/*
|
5
|
+
# chisel session for user defined types
|
6
|
+
|
7
|
+
import {TypeA, toTypeA} from "./contracts/experiment/types/TypeA.sol";
|
8
|
+
TypeA a = toTypeA(1);
|
9
|
+
TypeA b = toTypeA(2);
|
10
|
+
uint(a.toInt())
|
11
|
+
uint(b.toInt())
|
12
|
+
a == b
|
13
|
+
a != b
|
14
|
+
|
15
|
+
import {TypeB, toTypeB} from "./contracts/experiment/types/TypeB.sol";
|
16
|
+
TypeB x = toTypeB(33);
|
17
|
+
uint(x.toInt())
|
18
|
+
a == x; // -> error
|
19
|
+
a.toInt() == x.toInt() // -> no error
|
20
|
+
*/
|
21
|
+
|
22
|
+
// bytes5 allows for chain ids up to 13 digits
|
23
|
+
type TypeA is uint248;
|
24
|
+
|
25
|
+
// type bindings
|
26
|
+
using {
|
27
|
+
eqTypeA as ==,
|
28
|
+
neTypeA as !=,
|
29
|
+
TypeALib.toInt
|
30
|
+
} for TypeA global;
|
31
|
+
|
32
|
+
// general pure free functions
|
33
|
+
function toTypeA(uint256 typeA) pure returns(TypeA) { return TypeA.wrap(uint248(typeA)); }
|
34
|
+
|
35
|
+
// pure free functions for operators
|
36
|
+
function eqTypeA(TypeA a, TypeA b) pure returns(bool isSame) { return TypeA.unwrap(a) == TypeA.unwrap(b); }
|
37
|
+
function neTypeA(TypeA a, TypeA b) pure returns(bool isDifferent) { return TypeA.unwrap(a) != TypeA.unwrap(b); }
|
38
|
+
|
39
|
+
// library functions that operate on user defined type
|
40
|
+
library TypeALib {
|
41
|
+
function toInt(TypeA typeA) internal pure returns(uint256) { return uint256(TypeA.unwrap(typeA)); }
|
42
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
// bytes5 allows for chain ids up to 13 digits
|
5
|
+
type TypeB is uint248;
|
6
|
+
|
7
|
+
// type bindings
|
8
|
+
using {
|
9
|
+
eqTypeB as ==,
|
10
|
+
addTypeB as +,
|
11
|
+
TypeBLib.toInt
|
12
|
+
} for TypeB global;
|
13
|
+
|
14
|
+
// general pure free functions
|
15
|
+
function toTypeB(uint256 x) pure returns(TypeB) { return TypeB.wrap(uint248(x)); }
|
16
|
+
|
17
|
+
// pure free functions for operators
|
18
|
+
function eqTypeB(TypeB a, TypeB b) pure returns(bool isSame) { return TypeB.unwrap(a) == TypeB.unwrap(b); }
|
19
|
+
function addTypeB(TypeB a, TypeB b) pure returns(TypeB sum) { return TypeB.wrap(TypeB.unwrap(a) + TypeB.unwrap(b)); }
|
20
|
+
|
21
|
+
// library functions that operate on user defined type
|
22
|
+
library TypeBLib {
|
23
|
+
function toInt(TypeB b) internal pure returns(uint256) { return uint256(TypeB.unwrap(b)); }
|
24
|
+
}
|
@@ -11,6 +11,7 @@ import {PolicyModule} from "./policy/PolicyModule.sol";
|
|
11
11
|
import {PoolModule} from "./pool/PoolModule.sol";
|
12
12
|
|
13
13
|
import {IInstance} from "./IInstance.sol";
|
14
|
+
import {NftId, toNftId} from "../types/NftId.sol";
|
14
15
|
|
15
16
|
contract Instance is
|
16
17
|
Registerable,
|
@@ -36,17 +37,17 @@ contract Instance is
|
|
36
37
|
{ }
|
37
38
|
|
38
39
|
// from registerable
|
39
|
-
function register() external override returns(
|
40
|
+
function register() external override returns(NftId nftId) {
|
40
41
|
require(address(_registry) != address(0), "ERROR:PRD-001:REGISTRY_ZERO");
|
41
42
|
return _registry.register(address(this));
|
42
43
|
}
|
43
44
|
|
44
45
|
// from registerable
|
45
|
-
function getParentNftId() public view override returns(
|
46
|
+
function getParentNftId() public view override returns(NftId) {
|
46
47
|
// TODO add self registry and exchange 0 for_registry.getNftId();
|
47
48
|
// define parent tree for all registerables
|
48
49
|
// eg 0 <- chain(mainnet) <- global registry <- chain registry <- instance <- component <- policy/bundle
|
49
|
-
return 0;
|
50
|
+
return toNftId(0);
|
50
51
|
}
|
51
52
|
|
52
53
|
// from registerable
|
@@ -9,7 +9,7 @@ import {IInstance} from "../IInstance.sol";
|
|
9
9
|
import {IComponent, IComponentContract, IComponentModule, IComponentOwnerService} from "./IComponent.sol";
|
10
10
|
import {IProductComponent} from "../../components/IProduct.sol";
|
11
11
|
import {IPoolModule} from "../pool/IPoolModule.sol";
|
12
|
-
|
12
|
+
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
13
13
|
|
14
14
|
abstract contract ComponentModule is
|
15
15
|
IRegistryLinked,
|
@@ -17,11 +17,12 @@ abstract contract ComponentModule is
|
|
17
17
|
IAccessCheckRole,
|
18
18
|
IComponentModule
|
19
19
|
{
|
20
|
+
using NftIdLib for NftId;
|
20
21
|
|
21
|
-
mapping(
|
22
|
-
mapping(
|
23
|
-
mapping(address cAddress =>
|
24
|
-
|
22
|
+
mapping(NftId nftId => ComponentInfo info) private _componentInfo;
|
23
|
+
mapping(NftId nftId => NftId poolNftId) private _poolNftIdForProduct;
|
24
|
+
mapping(address cAddress => NftId nftId) private _nftIdByAddress;
|
25
|
+
NftId[] private _nftIds;
|
25
26
|
|
26
27
|
mapping(uint256 cType => bytes32 role) private _componentOwnerRole;
|
27
28
|
|
@@ -40,7 +41,7 @@ abstract contract ComponentModule is
|
|
40
41
|
external
|
41
42
|
override
|
42
43
|
onlyComponentOwnerService
|
43
|
-
returns(
|
44
|
+
returns(NftId nftId)
|
44
45
|
{
|
45
46
|
bytes32 typeRole = getRoleForType(component.getType());
|
46
47
|
require(
|
@@ -56,8 +57,8 @@ abstract contract ComponentModule is
|
|
56
57
|
// special case product -> persist product - pool assignment
|
57
58
|
if(component.getType() == this.getRegistry().PRODUCT()) {
|
58
59
|
IProductComponent product = IProductComponent(address(component));
|
59
|
-
|
60
|
-
require(poolNftId
|
60
|
+
NftId poolNftId = product.getPoolNftId();
|
61
|
+
require(poolNftId.gtz(), "ERROR:CMP-005:POOL_UNKNOWN");
|
61
62
|
// add more validation (type, token, ...)
|
62
63
|
|
63
64
|
_poolNftIdForProduct[nftId] = poolNftId;
|
@@ -73,17 +74,17 @@ abstract contract ComponentModule is
|
|
73
74
|
);
|
74
75
|
}
|
75
76
|
|
76
|
-
|
77
|
-
|
77
|
+
_nftIdByAddress[address(component)] = nftId;
|
78
|
+
_nftIds.push(nftId);
|
78
79
|
|
79
80
|
// add logging
|
80
81
|
}
|
81
82
|
|
82
|
-
function getPoolNftId(
|
83
|
+
function getPoolNftId(NftId productNftId)
|
83
84
|
external
|
84
85
|
view
|
85
86
|
override
|
86
|
-
returns(
|
87
|
+
returns(NftId poolNftId)
|
87
88
|
{
|
88
89
|
poolNftId = _poolNftIdForProduct[productNftId];
|
89
90
|
}
|
@@ -101,28 +102,28 @@ abstract contract ComponentModule is
|
|
101
102
|
function setComponentInfo(ComponentInfo memory info)
|
102
103
|
external
|
103
104
|
onlyComponentOwnerService
|
104
|
-
returns(
|
105
|
+
returns(NftId nftId)
|
105
106
|
{
|
106
|
-
|
107
|
+
nftId = info.nftId;
|
107
108
|
require(
|
108
|
-
|
109
|
-
"ERROR:CMP-
|
109
|
+
nftId.gtz() && _componentInfo[nftId].nftId.eq(nftId),
|
110
|
+
"ERROR:CMP-006:COMPONENT_UNKNOWN");
|
110
111
|
|
111
|
-
_componentInfo[
|
112
|
+
_componentInfo[nftId] = info;
|
112
113
|
|
113
114
|
// add logging
|
114
115
|
}
|
115
116
|
|
116
|
-
function getComponentInfo(
|
117
|
+
function getComponentInfo(NftId nftId)
|
117
118
|
external
|
118
119
|
override
|
119
120
|
view
|
120
121
|
returns(ComponentInfo memory)
|
121
122
|
{
|
122
|
-
return _componentInfo[
|
123
|
+
return _componentInfo[nftId];
|
123
124
|
}
|
124
125
|
|
125
|
-
function getComponentOwner(
|
126
|
+
function getComponentOwner(NftId nftId)
|
126
127
|
external
|
127
128
|
view
|
128
129
|
returns(address owner)
|
@@ -133,9 +134,9 @@ abstract contract ComponentModule is
|
|
133
134
|
function getComponentId(address componentAddress)
|
134
135
|
external
|
135
136
|
view
|
136
|
-
returns(
|
137
|
+
returns(NftId componentNftId)
|
137
138
|
{
|
138
|
-
return
|
139
|
+
return _nftIdByAddress[componentAddress];
|
139
140
|
}
|
140
141
|
|
141
142
|
|
@@ -143,9 +144,9 @@ abstract contract ComponentModule is
|
|
143
144
|
external
|
144
145
|
override
|
145
146
|
view
|
146
|
-
returns(
|
147
|
+
returns(NftId componentNftId)
|
147
148
|
{
|
148
|
-
return
|
149
|
+
return _nftIds[idx];
|
149
150
|
}
|
150
151
|
|
151
152
|
|
@@ -155,7 +156,7 @@ abstract contract ComponentModule is
|
|
155
156
|
view
|
156
157
|
returns(uint256 numberOfCompnents)
|
157
158
|
{
|
158
|
-
return
|
159
|
+
return _nftIds.length;
|
159
160
|
}
|
160
161
|
|
161
162
|
function getRoleForType(uint256 cType)
|
@@ -183,11 +184,12 @@ contract ComponentOwnerService is
|
|
183
184
|
IComponent,
|
184
185
|
IComponentOwnerService
|
185
186
|
{
|
187
|
+
using NftIdLib for NftId;
|
186
188
|
|
187
189
|
modifier onlyComponentOwner(IComponentContract component) {
|
188
|
-
|
190
|
+
NftId nftId = _registry.getNftId(address(component));
|
189
191
|
require(
|
190
|
-
nftId
|
192
|
+
nftId.gtz(),
|
191
193
|
"ERROR:COS-001:COMPONENT_UNKNOWN");
|
192
194
|
require(
|
193
195
|
msg.sender == _registry.getOwner(nftId),
|
@@ -200,23 +202,10 @@ contract ComponentOwnerService is
|
|
200
202
|
RegistryLinked(registry)
|
201
203
|
{ }
|
202
204
|
|
203
|
-
|
204
|
-
// modifier onlyComponentOwnerRole(IComponentContract component) {
|
205
|
-
// IInstance instance = component.getInstance();
|
206
|
-
// // TODO add set/getComponentOwnerRole to IComonentModule
|
207
|
-
// bytes32 typeRole = instance.getComponentTypeRole(component.getType());
|
208
|
-
// require(
|
209
|
-
// instance.hasRole(typeRole, msg.sender),
|
210
|
-
// "ERROR:COS-003:COMPONENT_ROLE_MISSING"
|
211
|
-
// );
|
212
|
-
// _;
|
213
|
-
// }
|
214
|
-
|
215
|
-
|
216
205
|
function register(IComponentContract component)
|
217
206
|
external
|
218
207
|
override
|
219
|
-
returns(
|
208
|
+
returns(NftId nftId)
|
220
209
|
{
|
221
210
|
require(
|
222
211
|
msg.sender == component.getInitialOwner(),
|
@@ -234,7 +223,7 @@ contract ComponentOwnerService is
|
|
234
223
|
{
|
235
224
|
IInstance instance = component.getInstance();
|
236
225
|
ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
|
237
|
-
require(info.nftId
|
226
|
+
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
238
227
|
// TODO add state change validation
|
239
228
|
|
240
229
|
info.state = CState.Locked;
|
@@ -249,7 +238,7 @@ contract ComponentOwnerService is
|
|
249
238
|
{
|
250
239
|
IInstance instance = component.getInstance();
|
251
240
|
ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
|
252
|
-
require(info.nftId
|
241
|
+
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
253
242
|
// TODO state change validation
|
254
243
|
|
255
244
|
info.state = CState.Active;
|
@@ -4,6 +4,7 @@ pragma solidity ^0.8.19;
|
|
4
4
|
|
5
5
|
import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
|
6
6
|
import {IInstance} from "../IInstance.sol";
|
7
|
+
import {NftId} from "../../types/NftId.sol";
|
7
8
|
|
8
9
|
interface IComponent {
|
9
10
|
|
@@ -16,7 +17,7 @@ interface IComponent {
|
|
16
17
|
|
17
18
|
// component dynamic info (static info kept in registry)
|
18
19
|
struct ComponentInfo {
|
19
|
-
|
20
|
+
NftId nftId;
|
20
21
|
CState state;
|
21
22
|
}
|
22
23
|
}
|
@@ -37,7 +38,7 @@ interface IComponentContract is
|
|
37
38
|
|
38
39
|
interface IComponentOwnerService is IRegistryLinked{
|
39
40
|
|
40
|
-
function register(IComponentContract component) external returns(
|
41
|
+
function register(IComponentContract component) external returns(NftId nftId);
|
41
42
|
function lock(IComponentContract component) external;
|
42
43
|
function unlock(IComponentContract component) external;
|
43
44
|
}
|
@@ -51,18 +52,18 @@ interface IComponentModule is
|
|
51
52
|
|
52
53
|
function registerComponent(IComponentContract component)
|
53
54
|
external
|
54
|
-
returns(
|
55
|
+
returns(NftId nftId);
|
55
56
|
|
56
57
|
function setComponentInfo(ComponentInfo memory info)
|
57
58
|
external
|
58
|
-
returns(
|
59
|
+
returns(NftId componentNftId);
|
59
60
|
|
60
|
-
function getComponentInfo(
|
61
|
+
function getComponentInfo(NftId nftId)
|
61
62
|
external
|
62
63
|
view
|
63
64
|
returns(ComponentInfo memory info);
|
64
65
|
|
65
|
-
function getComponentOwner(
|
66
|
+
function getComponentOwner(NftId nftId)
|
66
67
|
external
|
67
68
|
view
|
68
69
|
returns(address owner);
|
@@ -70,17 +71,17 @@ interface IComponentModule is
|
|
70
71
|
function getComponentId(address componentAddress)
|
71
72
|
external
|
72
73
|
view
|
73
|
-
returns(
|
74
|
+
returns(NftId nftId);
|
74
75
|
|
75
76
|
function getComponentId(uint256 idx)
|
76
77
|
external
|
77
78
|
view
|
78
|
-
returns(
|
79
|
+
returns(NftId nftId);
|
79
80
|
|
80
|
-
function getPoolNftId(
|
81
|
+
function getPoolNftId(NftId productNftId)
|
81
82
|
external
|
82
83
|
view
|
83
|
-
returns(
|
84
|
+
returns(NftId poolNftId);
|
84
85
|
|
85
86
|
function components()
|
86
87
|
external
|
@@ -4,8 +4,8 @@ pragma solidity ^0.8.19;
|
|
4
4
|
|
5
5
|
import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
|
6
6
|
import {IInstance} from "../IInstance.sol";
|
7
|
-
|
8
7
|
import {IProductService} from "../product/IProductService.sol";
|
8
|
+
import {NftId} from "../../types/NftId.sol";
|
9
9
|
|
10
10
|
// TODO check if there is value to introuce IContract and let IPolicy derive from IContract
|
11
11
|
interface IPolicy {
|
@@ -19,7 +19,7 @@ interface IPolicy {
|
|
19
19
|
}
|
20
20
|
|
21
21
|
struct PolicyInfo {
|
22
|
-
|
22
|
+
NftId nftId;
|
23
23
|
PolicyState state; // applied, withdrawn, rejected, active, closed
|
24
24
|
|
25
25
|
uint256 sumInsuredAmount;
|
@@ -45,20 +45,20 @@ interface IPolicyModule is
|
|
45
45
|
uint256 sumInsuredAmount,
|
46
46
|
uint256 premiumAmount,
|
47
47
|
uint256 lifetime,
|
48
|
-
|
48
|
+
NftId bundleNftId
|
49
49
|
)
|
50
50
|
external
|
51
|
-
returns(
|
51
|
+
returns(NftId nftId);
|
52
52
|
|
53
|
-
function activate(
|
53
|
+
function activate(NftId nftId)
|
54
54
|
external;
|
55
55
|
|
56
|
-
function getBundleNftForPolicy(
|
56
|
+
function getBundleNftForPolicy(NftId nftId)
|
57
57
|
external
|
58
58
|
view
|
59
|
-
returns(
|
59
|
+
returns(NftId bundleNft);
|
60
60
|
|
61
|
-
function getPolicyInfo(
|
61
|
+
function getPolicyInfo(NftId nftId)
|
62
62
|
external
|
63
63
|
view
|
64
64
|
returns(PolicyInfo memory info);
|
@@ -7,15 +7,16 @@ import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
|
|
7
7
|
|
8
8
|
import {IProductService} from "../product/IProductService.sol";
|
9
9
|
import {IPolicy, IPolicyModule} from "./IPolicy.sol";
|
10
|
-
|
10
|
+
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
11
11
|
|
12
12
|
abstract contract PolicyModule is
|
13
13
|
IRegistryLinked,
|
14
14
|
IPolicyModule
|
15
15
|
{
|
16
|
+
using NftIdLib for NftId;
|
16
17
|
|
17
|
-
mapping(
|
18
|
-
mapping(
|
18
|
+
mapping(NftId nftId => PolicyInfo info) private _policyInfo;
|
19
|
+
mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
|
19
20
|
|
20
21
|
IProductService private _productService;
|
21
22
|
|
@@ -36,17 +37,17 @@ abstract contract PolicyModule is
|
|
36
37
|
uint256 sumInsuredAmount,
|
37
38
|
uint256 premiumAmount,
|
38
39
|
uint256 lifetime,
|
39
|
-
|
40
|
+
NftId bundleNftId
|
40
41
|
)
|
41
42
|
external
|
42
43
|
override
|
43
44
|
onlyProductService2
|
44
|
-
returns(
|
45
|
+
returns(NftId nftId)
|
45
46
|
{
|
46
47
|
// TODO add parameter validation
|
47
|
-
if(bundleNftId
|
48
|
+
if(bundleNftId.gtz()) {
|
48
49
|
IRegistry.RegistryInfo memory bundleInfo = this.getRegistry().getInfo(bundleNftId);
|
49
|
-
IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
|
50
|
+
// IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
|
50
51
|
}
|
51
52
|
|
52
53
|
nftId = this.getRegistry().registerObjectForInstance(
|
@@ -72,7 +73,7 @@ abstract contract PolicyModule is
|
|
72
73
|
}
|
73
74
|
|
74
75
|
|
75
|
-
function activate(
|
76
|
+
function activate(NftId nftId)
|
76
77
|
external
|
77
78
|
override
|
78
79
|
onlyProductService2
|
@@ -87,16 +88,16 @@ abstract contract PolicyModule is
|
|
87
88
|
|
88
89
|
|
89
90
|
|
90
|
-
function getBundleNftForPolicy(
|
91
|
+
function getBundleNftForPolicy(NftId nftId)
|
91
92
|
external
|
92
93
|
view
|
93
|
-
returns(
|
94
|
+
returns(NftId bundleNft)
|
94
95
|
{
|
95
96
|
return _bundleForPolicy[nftId];
|
96
97
|
}
|
97
98
|
|
98
99
|
|
99
|
-
function getPolicyInfo(
|
100
|
+
function getPolicyInfo(NftId nftId)
|
100
101
|
external
|
101
102
|
view
|
102
103
|
returns(PolicyInfo memory info)
|
@@ -2,11 +2,12 @@
|
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
4
|
import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
|
5
|
+
import {NftId} from "../../types/NftId.sol";
|
5
6
|
|
6
7
|
interface IPool {
|
7
8
|
|
8
9
|
struct PoolInfo {
|
9
|
-
|
10
|
+
NftId nftId;
|
10
11
|
address wallet;
|
11
12
|
address token;
|
12
13
|
uint256 capital;
|
@@ -21,19 +22,19 @@ interface IPoolModule is
|
|
21
22
|
{
|
22
23
|
|
23
24
|
function underwrite(
|
24
|
-
|
25
|
-
|
25
|
+
NftId poolNftId,
|
26
|
+
NftId policyNftId
|
26
27
|
)
|
27
28
|
external;
|
28
29
|
|
29
30
|
function createPoolInfo(
|
30
|
-
|
31
|
+
NftId nftId,
|
31
32
|
address wallet,
|
32
33
|
address token
|
33
34
|
)
|
34
35
|
external;
|
35
36
|
|
36
|
-
function getPoolInfo(
|
37
|
+
function getPoolInfo(NftId nftId)
|
37
38
|
external
|
38
39
|
view
|
39
40
|
returns(PoolInfo memory info);
|