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