@etherisc/gif-next 0.0.2-f9905e1 → 0.0.2-ffba655
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 +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
- 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 +1 -1
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
- 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 +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/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/Blocknumber.sol +60 -0
- package/contracts/types/ChainId.sol +7 -1
- package/contracts/types/NftId.sol +35 -0
- package/contracts/types/Timestamp.sol +55 -0
- package/contracts/types/UFixed.sol +211 -0
- package/package.json +1 -1
@@ -0,0 +1,173 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {ERC721, ERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
|
5
|
+
import {IChainNft} from "./IChainNft.sol";
|
6
|
+
|
7
|
+
contract ChainNft is
|
8
|
+
ERC721Enumerable,
|
9
|
+
IChainNft
|
10
|
+
{
|
11
|
+
string public constant NAME = "Dezentralized Insurance Protocol Registry";
|
12
|
+
string public constant SYMBOL = "DIPR";
|
13
|
+
|
14
|
+
// remember token uri
|
15
|
+
mapping(uint256 tokenId => string uri) private _uri;
|
16
|
+
|
17
|
+
// remember registry
|
18
|
+
address private _registry;
|
19
|
+
|
20
|
+
// only used for _getNextTokenId
|
21
|
+
uint256 internal _chainIdInt;
|
22
|
+
uint256 internal _chainIdDigits;
|
23
|
+
uint256 internal _chainIdMultiplier;
|
24
|
+
uint256 internal _idNext;
|
25
|
+
uint256 internal _totalMinted;
|
26
|
+
|
27
|
+
|
28
|
+
modifier onlyRegistry() {
|
29
|
+
require(msg.sender == _registry, "ERROR:NFT-001:CALLER_NOT_REGISTRY");
|
30
|
+
_;
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
constructor(address registry)
|
35
|
+
ERC721(NAME, SYMBOL)
|
36
|
+
{
|
37
|
+
require(registry != address(0), "ERROR:NFT-010:REGISTRY_ZERO");
|
38
|
+
|
39
|
+
_registry = registry;
|
40
|
+
|
41
|
+
_chainIdInt = block.chainid;
|
42
|
+
_chainIdDigits = _countDigits(_chainIdInt);
|
43
|
+
_chainIdMultiplier = 10 ** _chainIdDigits;
|
44
|
+
|
45
|
+
// on mainnet/goerli start /1 (reserved for protocol nft) on other chains with 2
|
46
|
+
if(block.chainid == 1 || block.chainid == 5) {
|
47
|
+
_idNext = 1;
|
48
|
+
} else {
|
49
|
+
_idNext = 2;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
function mint(
|
55
|
+
address to,
|
56
|
+
string memory uri
|
57
|
+
)
|
58
|
+
external
|
59
|
+
override
|
60
|
+
onlyRegistry
|
61
|
+
returns(uint256 tokenId)
|
62
|
+
{
|
63
|
+
tokenId = _getNextTokenId();
|
64
|
+
_totalMinted++;
|
65
|
+
|
66
|
+
_safeMint(to, tokenId);
|
67
|
+
|
68
|
+
if(bytes(uri).length > 0) {
|
69
|
+
_uri[tokenId] = uri;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
function burn(uint256 tokenId)
|
75
|
+
external
|
76
|
+
override
|
77
|
+
onlyRegistry
|
78
|
+
{
|
79
|
+
_requireMinted(tokenId);
|
80
|
+
_burn(tokenId);
|
81
|
+
delete _uri[tokenId];
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
function setURI(uint256 tokenId, string memory uri)
|
86
|
+
external
|
87
|
+
override
|
88
|
+
onlyRegistry
|
89
|
+
{
|
90
|
+
require(bytes(uri).length > 0, "ERROR:CRG-011:URI_EMPTY");
|
91
|
+
|
92
|
+
_requireMinted(tokenId);
|
93
|
+
_uri[tokenId] = uri;
|
94
|
+
}
|
95
|
+
|
96
|
+
|
97
|
+
function exists(uint256 tokenId)
|
98
|
+
external
|
99
|
+
view
|
100
|
+
override
|
101
|
+
returns(bool)
|
102
|
+
{
|
103
|
+
return _exists(tokenId);
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
function tokenURI(uint256 tokenId)
|
108
|
+
public
|
109
|
+
view
|
110
|
+
override
|
111
|
+
returns(string memory)
|
112
|
+
{
|
113
|
+
_requireMinted(tokenId);
|
114
|
+
return _uri[tokenId];
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
function getRegistryAddress()
|
119
|
+
external
|
120
|
+
view
|
121
|
+
override
|
122
|
+
returns(address)
|
123
|
+
{
|
124
|
+
return _registry;
|
125
|
+
}
|
126
|
+
|
127
|
+
function totalMinted() external override view returns(uint256) {
|
128
|
+
return _totalMinted;
|
129
|
+
}
|
130
|
+
|
131
|
+
// requirement: each chain registry produces token ids that
|
132
|
+
// are guaranteed to not collide with any token id genereated
|
133
|
+
// on a different chain
|
134
|
+
//
|
135
|
+
// format concat(counter,chainid,2 digits for len-of-chain-id)
|
136
|
+
// restriction chainid up to 99 digits
|
137
|
+
// decode: from right to left:
|
138
|
+
// - 2 right most digits encode length of chainid
|
139
|
+
// - move number of digits to left as determined above (-> chainid)
|
140
|
+
// - the reminder to the left is the counter
|
141
|
+
// examples
|
142
|
+
// 1101
|
143
|
+
// ^^ ^
|
144
|
+
// || +- 1-digit chain id
|
145
|
+
// |+-- chain id = 1 (mainnet)
|
146
|
+
// +-- 1st token id on mainnet
|
147
|
+
// (1 * 10 ** 1 + 1) * 100 + 1
|
148
|
+
// 42987654321010
|
149
|
+
// ^ ^ ^
|
150
|
+
// | | +- 10-digit chain id
|
151
|
+
// | +-- chain id = 9876543210 (hypothetical chainid)
|
152
|
+
// +-- 42nd token id on this chain
|
153
|
+
// (42 * 10 ** 10 + 9876543210) * 100 + 10
|
154
|
+
// (index * 10 ** digits + chainid) * 100 + digits (1 < digits < 100)
|
155
|
+
|
156
|
+
function _getNextTokenId() private returns(uint256 id) {
|
157
|
+
id = (_idNext * _chainIdMultiplier + _chainIdInt) * 100 + _chainIdDigits;
|
158
|
+
_idNext++;
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
function _countDigits(uint256 num)
|
163
|
+
private
|
164
|
+
pure
|
165
|
+
returns (uint256 count)
|
166
|
+
{
|
167
|
+
count = 0;
|
168
|
+
while (num != 0) {
|
169
|
+
count++;
|
170
|
+
num /= 10;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
|
5
|
+
|
6
|
+
interface IChainNft is
|
7
|
+
IERC721Enumerable
|
8
|
+
{
|
9
|
+
|
10
|
+
function mint(address to, string memory uri) external returns(uint256 tokenId);
|
11
|
+
function burn(uint256 tokenId) external;
|
12
|
+
function setURI(uint256 tokenId, string memory uri) external;
|
13
|
+
|
14
|
+
function exists(uint256 tokenId) external view returns(bool);
|
15
|
+
function totalMinted() external view returns(uint256);
|
16
|
+
|
17
|
+
function getRegistryAddress() external view returns(address registry);
|
18
|
+
}
|
@@ -1,6 +1,8 @@
|
|
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
7
|
function getOwner() external view returns(address owner);
|
6
8
|
}
|
@@ -17,10 +19,10 @@ interface IRegisterable is
|
|
17
19
|
IRegistryLinked
|
18
20
|
{
|
19
21
|
|
20
|
-
function register() external returns(
|
22
|
+
function register() external returns(NftId nftId);
|
21
23
|
|
22
|
-
function getNftId() external view returns(
|
23
|
-
function getParentNftId() external view returns(
|
24
|
+
function getNftId() external view returns(NftId nftId);
|
25
|
+
function getParentNftId() external view returns(NftId parentNftId);
|
24
26
|
function getType() external view returns(uint256 objectType);
|
25
27
|
function getData() external view returns(bytes memory data);
|
26
28
|
function isRegisterable() external pure returns(bool);
|
@@ -33,8 +35,8 @@ interface IRegisterable is
|
|
33
35
|
interface IRegistry {
|
34
36
|
|
35
37
|
struct RegistryInfo {
|
36
|
-
|
37
|
-
|
38
|
+
NftId nftId;
|
39
|
+
NftId parentNftId;
|
38
40
|
uint256 objectType;
|
39
41
|
address objectAddress;
|
40
42
|
address initialOwner;
|
@@ -48,19 +50,21 @@ interface IRegistry {
|
|
48
50
|
function POLICY() external pure returns(uint256);
|
49
51
|
function BUNDLE() external pure returns(uint256);
|
50
52
|
|
51
|
-
function register(address objectAddress) external returns(
|
53
|
+
function register(address objectAddress) external returns(NftId nftId);
|
52
54
|
function registerObjectForInstance(
|
53
|
-
|
55
|
+
NftId parentNftid,
|
54
56
|
uint256 objectType,
|
55
57
|
address initialOwner
|
56
58
|
)
|
57
|
-
external returns(
|
59
|
+
external returns(NftId nftId);
|
58
60
|
|
59
|
-
function
|
61
|
+
function getObjectCount() external view returns(uint256);
|
60
62
|
|
61
|
-
function getNftId(address objectAddress) external view returns(
|
62
|
-
function getInfo(
|
63
|
-
function getOwner(
|
63
|
+
function getNftId(address objectAddress) external view returns(NftId nftId);
|
64
|
+
function getInfo(NftId nftId) external view returns(RegistryInfo memory info);
|
65
|
+
function getOwner(NftId nftId) external view returns(address ownerAddress);
|
64
66
|
|
65
67
|
function isRegistered(address objectAddress) external view returns(bool);
|
68
|
+
|
69
|
+
function getNftAddress() external view returns(address nft);
|
66
70
|
}
|
@@ -1,7 +1,10 @@
|
|
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
10
|
|
@@ -11,11 +14,6 @@ contract RegistryLinked is IRegistryLinked {
|
|
11
14
|
_registry = IRegistry(registry);
|
12
15
|
}
|
13
16
|
|
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
17
|
function getRegistry() external view override returns(IRegistry registry) {
|
20
18
|
return _registry;
|
21
19
|
}
|
@@ -27,6 +25,7 @@ abstract contract Registerable is
|
|
27
25
|
RegistryLinked,
|
28
26
|
IRegisterable
|
29
27
|
{
|
28
|
+
using NftIdLib for NftId;
|
30
29
|
|
31
30
|
address private _initialOwner;
|
32
31
|
|
@@ -47,39 +46,35 @@ abstract contract Registerable is
|
|
47
46
|
}
|
48
47
|
|
49
48
|
function isRegistered() public view override returns(bool) {
|
50
|
-
|
49
|
+
NftId nftId = _registry.getNftId(address(this));
|
50
|
+
return nftId.gtz();
|
51
51
|
}
|
52
52
|
|
53
|
-
function getNftId() public view override returns(
|
53
|
+
function getNftId() public view override returns(NftId nftId) {
|
54
54
|
return _registry.getNftId(address(this));
|
55
55
|
}
|
56
56
|
|
57
57
|
function getOwner() public view override returns(address owner) {
|
58
|
-
|
58
|
+
NftId id = _registry.getNftId(address(this));
|
59
59
|
owner = _registry.getOwner(id);
|
60
60
|
return owner != address(0) ? owner : _initialOwner;
|
61
61
|
}
|
62
62
|
|
63
63
|
}
|
64
64
|
|
65
|
-
// struct RegistryInfo {
|
66
|
-
// bytes32 id;
|
67
|
-
// uint256 objectType;
|
68
|
-
// address objectAddress;
|
69
|
-
// address initialOwner;
|
70
|
-
// }
|
71
|
-
|
72
65
|
contract Registry is IRegistry {
|
66
|
+
using NftIdLib for NftId;
|
67
|
+
string public constant EMPTY_URI = "";
|
73
68
|
|
74
|
-
mapping(
|
75
|
-
mapping(
|
76
|
-
mapping(address object =>
|
77
|
-
uint256 [] private _ids;
|
78
|
-
uint256 private _idNext;
|
69
|
+
mapping(NftId nftId => RegistryInfo info) private _info;
|
70
|
+
mapping(NftId nftId => address owner) private _owner;
|
71
|
+
mapping(address object => NftId nftId) private _nftIdByAddress;
|
79
72
|
|
73
|
+
IChainNft private _chainNft;
|
80
74
|
|
81
|
-
|
82
|
-
|
75
|
+
function initialize(address chainNft) external {
|
76
|
+
require(address(_chainNft) == address(0), "ERROR:REG-001:ALREADY_INITIALIZED");
|
77
|
+
_chainNft = IChainNft(chainNft);
|
83
78
|
}
|
84
79
|
|
85
80
|
function TOKEN() public pure override returns(uint256) { return 30; }
|
@@ -90,21 +85,24 @@ contract Registry is IRegistry {
|
|
90
85
|
function POLICY() public pure override returns(uint256) { return 80; }
|
91
86
|
function BUNDLE() public pure override returns(uint256) { return 90; }
|
92
87
|
|
93
|
-
function register(address objectAddress) external override returns(
|
94
|
-
require(
|
88
|
+
function register(address objectAddress) external override returns(NftId nftId) {
|
89
|
+
require(_nftIdByAddress[objectAddress].eqz(), "ERROR:REG-002:ALREADY_REGISTERED");
|
95
90
|
|
96
91
|
IRegisterable registerable = IRegisterable(objectAddress);
|
97
|
-
require(registerable.isRegisterable(), "ERROR:REG-
|
92
|
+
require(registerable.isRegisterable(), "ERROR:REG-003:NOT_REGISTERABLE");
|
98
93
|
|
99
94
|
// check parent exists (for objects not instances)
|
100
95
|
if(registerable.getType() != INSTANCE()) {
|
101
96
|
RegistryInfo memory parentInfo = _info[registerable.getParentNftId()];
|
102
|
-
require(parentInfo.nftId
|
97
|
+
require(parentInfo.nftId.gtz(), "ERROR:REG-004:PARENT_NOT_FOUND");
|
103
98
|
// check validity of parent relation, valid relations are
|
104
99
|
// policy -> product, bundle -> pool, product -> instance, pool -> instance
|
105
100
|
}
|
106
101
|
|
107
|
-
|
102
|
+
uint256 mintedTokenId = _chainNft.mint(
|
103
|
+
registerable.getInitialOwner(),
|
104
|
+
EMPTY_URI);
|
105
|
+
nftId = toNftId(mintedTokenId);
|
108
106
|
|
109
107
|
RegistryInfo memory info = RegistryInfo(
|
110
108
|
nftId,
|
@@ -115,28 +113,31 @@ contract Registry is IRegistry {
|
|
115
113
|
);
|
116
114
|
|
117
115
|
_info[nftId] = info;
|
118
|
-
|
116
|
+
_nftIdByAddress[objectAddress] = nftId;
|
119
117
|
|
120
118
|
// add logging
|
121
119
|
}
|
122
120
|
|
123
121
|
|
124
122
|
function registerObjectForInstance(
|
125
|
-
|
123
|
+
NftId parentNftId,
|
126
124
|
uint256 objectType,
|
127
125
|
address initialOwner
|
128
126
|
)
|
129
127
|
external
|
130
128
|
override
|
131
129
|
// TODO add onlyRegisteredInstance
|
132
|
-
returns(
|
130
|
+
returns(NftId nftId)
|
133
131
|
{
|
134
132
|
// TODO add more validation
|
135
133
|
require(
|
136
134
|
objectType == POLICY() || objectType == BUNDLE(),
|
137
135
|
"ERROR:REG-005:TYPE_INVALID");
|
138
136
|
|
139
|
-
|
137
|
+
uint256 mintedTokenId = _chainNft.mint(
|
138
|
+
initialOwner,
|
139
|
+
EMPTY_URI);
|
140
|
+
nftId = toNftId(mintedTokenId);
|
140
141
|
|
141
142
|
RegistryInfo memory info = RegistryInfo(
|
142
143
|
nftId,
|
@@ -152,46 +153,30 @@ contract Registry is IRegistry {
|
|
152
153
|
}
|
153
154
|
|
154
155
|
|
155
|
-
function
|
156
|
-
|
157
|
-
_owner[id] = newOwner;
|
158
|
-
|
159
|
-
// TODO logging
|
156
|
+
function getObjectCount() external view override returns(uint256) {
|
157
|
+
return _chainNft.totalSupply();
|
160
158
|
}
|
161
159
|
|
162
160
|
|
163
|
-
function
|
164
|
-
return
|
165
|
-
}
|
166
|
-
|
167
|
-
|
168
|
-
function getNftId(address object) external view override returns(uint256 id) {
|
169
|
-
return _idByAddress[object];
|
161
|
+
function getNftId(address object) external view override returns(NftId id) {
|
162
|
+
return _nftIdByAddress[object];
|
170
163
|
}
|
171
164
|
|
172
165
|
|
173
166
|
function isRegistered(address object) external view override returns(bool) {
|
174
|
-
return
|
167
|
+
return _nftIdByAddress[object].gtz();
|
175
168
|
}
|
176
169
|
|
177
170
|
|
178
|
-
function getInfo(
|
179
|
-
return _info[
|
171
|
+
function getInfo(NftId nftId) external view override returns(RegistryInfo memory info) {
|
172
|
+
return _info[nftId];
|
180
173
|
}
|
181
174
|
|
182
|
-
function getOwner(
|
183
|
-
return
|
175
|
+
function getOwner(NftId nftId) external view override returns(address) {
|
176
|
+
return _chainNft.ownerOf(nftId.toInt());
|
184
177
|
}
|
185
178
|
|
186
|
-
|
187
|
-
|
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,60 @@
|
|
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) { return Blocknumber.unwrap(a) > Blocknumber.unwrap(b); }
|
18
|
+
/// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
|
19
|
+
function gteBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) >= Blocknumber.unwrap(b); }
|
20
|
+
|
21
|
+
/// @dev return true if Blocknumber a is less than Blocknumber b
|
22
|
+
function ltBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) < Blocknumber.unwrap(b); }
|
23
|
+
/// @dev return true if Blocknumber a is less than or equal to Blocknumber b
|
24
|
+
function lteBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) <= Blocknumber.unwrap(b); }
|
25
|
+
|
26
|
+
/// @dev return true if Blocknumber a is equal to Blocknumber b
|
27
|
+
function eqBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) == Blocknumber.unwrap(b); }
|
28
|
+
/// @dev return true if Blocknumber a is not equal to Blocknumber b
|
29
|
+
function neBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) != Blocknumber.unwrap(b); }
|
30
|
+
|
31
|
+
/// @dev Converts the uint256 to a Blocknumber.
|
32
|
+
function toBlocknumber(uint256 blocknum) pure returns(Blocknumber) { return Blocknumber.wrap(uint32(blocknum)); }
|
33
|
+
|
34
|
+
function blockBlocknumber() view returns(Blocknumber) { return toBlocknumber(block.number); }
|
35
|
+
|
36
|
+
/// @dev Return the Blocknumber zero (0)
|
37
|
+
function zeroBlocknumber() pure returns(Blocknumber) { return toBlocknumber(0); }
|
38
|
+
|
39
|
+
/// @dev Return the current block number
|
40
|
+
function blockNumber() view returns(Blocknumber) { return toBlocknumber(block.number); }
|
41
|
+
|
42
|
+
library BlocknumberLib {
|
43
|
+
/// @dev return true if Blocknumber a is greater than Blocknumber b
|
44
|
+
function gt(Blocknumber a, Blocknumber b) public pure returns(bool isAfter) { return gtBlocknumber(a, b); }
|
45
|
+
/// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
|
46
|
+
function gte(Blocknumber a, Blocknumber b) public pure returns(bool isAfterOrSame) { return gteBlocknumber(a, b); }
|
47
|
+
|
48
|
+
/// @dev return true if Blocknumber a is less than Blocknumber b
|
49
|
+
function lt(Blocknumber a, Blocknumber b) public pure returns(bool isBefore) { return ltBlocknumber(a, b); }
|
50
|
+
/// @dev return true if Blocknumber a is less than or equal to Blocknumber b
|
51
|
+
function lte(Blocknumber a, Blocknumber b) public pure returns(bool isBeforeOrSame) { return lteBlocknumber(a, b); }
|
52
|
+
|
53
|
+
/// @dev return true if Blocknumber a is equal to Blocknumber b
|
54
|
+
function eq(Blocknumber a, Blocknumber b) public pure returns(bool isSame) { return eqBlocknumber(a, b); }
|
55
|
+
/// @dev return true if Blocknumber a is not equal to Blocknumber b
|
56
|
+
function ne(Blocknumber a, Blocknumber b) public pure returns(bool isDifferent) { return neBlocknumber(a, b); }
|
57
|
+
|
58
|
+
/// @dev converts the Blocknumber to a uint256
|
59
|
+
function toInt(Blocknumber blocknumber) public pure returns(uint256) { return uint256(uint32(Blocknumber.unwrap(blocknumber))); }
|
60
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
|
4
|
+
/// @dev bytes5 (uint40) allows for chain ids up to 13 digits
|
5
5
|
type ChainId is bytes5;
|
6
6
|
|
7
7
|
// type bindings
|
@@ -12,13 +12,19 @@ using {
|
|
12
12
|
} for ChainId global;
|
13
13
|
|
14
14
|
// general pure free functions
|
15
|
+
/// @dev Converts the uint256 to a ChainId.
|
15
16
|
function toChainId(uint256 chainId) pure returns(ChainId) { return ChainId.wrap(bytes5(uint40(chainId))); }
|
17
|
+
/// @dev Return the ChainId for the chain the contract is deployed to
|
18
|
+
function thisChainId() view returns(ChainId) { return toChainId(block.chainid); }
|
16
19
|
|
17
20
|
// pure free functions for operators
|
21
|
+
/// @dev Returns true if the values are equal (==).
|
18
22
|
function eqChainId(ChainId a, ChainId b) pure returns(bool isSame) { return ChainId.unwrap(a) == ChainId.unwrap(b); }
|
23
|
+
/// @dev Returns true if the values are not equal (!=).
|
19
24
|
function neChainId(ChainId a, ChainId b) pure returns(bool isDifferent) { return ChainId.unwrap(a) != ChainId.unwrap(b); }
|
20
25
|
|
21
26
|
// library functions that operate on user defined type
|
22
27
|
library ChainIdLib {
|
28
|
+
/// @dev Converts the ChainId to a uint256.
|
23
29
|
function toInt(ChainId chainId) internal pure returns(uint256) { return uint256(uint40(ChainId.unwrap(chainId))); }
|
24
30
|
}
|
@@ -0,0 +1,35 @@
|
|
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 {
|
9
|
+
eqNftId as ==,
|
10
|
+
neNftId as !=,
|
11
|
+
NftIdLib.toInt
|
12
|
+
} for NftId global;
|
13
|
+
|
14
|
+
// general pure free functions
|
15
|
+
/// @dev Converts the uint256 to a NftId.
|
16
|
+
function toNftId(uint256 id) pure returns(NftId) { return NftId.wrap(uint96(id)); }
|
17
|
+
|
18
|
+
/// @dev Return the NftId zero (0)
|
19
|
+
function zeroNftId() pure returns(NftId) { return NftId.wrap(0); }
|
20
|
+
|
21
|
+
// pure free functions for operators
|
22
|
+
function eqNftId(NftId a, NftId b) pure returns(bool isSame) { return NftId.unwrap(a) == NftId.unwrap(b); }
|
23
|
+
function neNftId(NftId a, NftId b) pure returns(bool isDifferent) { return NftId.unwrap(a) != NftId.unwrap(b); }
|
24
|
+
|
25
|
+
// library functions that operate on user defined type
|
26
|
+
library NftIdLib {
|
27
|
+
/// @dev Converts the NftId to a uint256.
|
28
|
+
function toInt(NftId nftId) public pure returns(uint96) { return uint96(NftId.unwrap(nftId)); }
|
29
|
+
/// @dev Returns true if the value is non-zero (> 0).
|
30
|
+
function gtz(NftId a) public pure returns(bool) { return NftId.unwrap(a) > 0; }
|
31
|
+
/// @dev Returns true if the value is zero (== 0).
|
32
|
+
function eqz(NftId a) public pure returns(bool) { return NftId.unwrap(a) == 0; }
|
33
|
+
/// @dev Returns true if the values are equal (==).
|
34
|
+
function eq(NftId a, NftId b) public pure returns(bool isSame) { return eqNftId(a, b); }
|
35
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
type Timestamp is uint40;
|
5
|
+
|
6
|
+
using {
|
7
|
+
gtTimestamp as >,
|
8
|
+
gteTimestamp as >=,
|
9
|
+
ltTimestamp as <,
|
10
|
+
lteTimestamp as <=,
|
11
|
+
eqTimestamp as ==,
|
12
|
+
neTimestamp as !=
|
13
|
+
} for Timestamp global;
|
14
|
+
|
15
|
+
/// @dev return true if Timestamp a is after Timestamp b
|
16
|
+
function gtTimestamp(Timestamp a, Timestamp b) pure returns(bool) { return Timestamp.unwrap(a) > Timestamp.unwrap(b); }
|
17
|
+
/// @dev return true if Timestamp a is after or equal to Timestamp b
|
18
|
+
function gteTimestamp(Timestamp a, Timestamp b) pure returns(bool) { return Timestamp.unwrap(a) >= Timestamp.unwrap(b); }
|
19
|
+
|
20
|
+
/// @dev return true if Timestamp a is before Timestamp b
|
21
|
+
function ltTimestamp(Timestamp a, Timestamp b) pure returns(bool) { return Timestamp.unwrap(a) < Timestamp.unwrap(b); }
|
22
|
+
/// @dev return true if Timestamp a is before or equal to Timestamp b
|
23
|
+
function lteTimestamp(Timestamp a, Timestamp b) pure returns(bool) { return Timestamp.unwrap(a) <= Timestamp.unwrap(b); }
|
24
|
+
|
25
|
+
/// @dev return true if Timestamp a is equal to Timestamp b
|
26
|
+
function eqTimestamp(Timestamp a, Timestamp b) pure returns(bool) { return Timestamp.unwrap(a) == Timestamp.unwrap(b); }
|
27
|
+
/// @dev return true if Timestamp a is not equal to Timestamp b
|
28
|
+
function neTimestamp(Timestamp a, Timestamp b) pure returns(bool) { return Timestamp.unwrap(a) != Timestamp.unwrap(b); }
|
29
|
+
|
30
|
+
/// @dev Converts the uint256 to a Timestamp.
|
31
|
+
function toTimestamp(uint256 timestamp) pure returns(Timestamp) { return Timestamp.wrap(uint40(timestamp));}
|
32
|
+
|
33
|
+
function blockTimestamp() view returns(Timestamp) { return toTimestamp(block.timestamp); }
|
34
|
+
|
35
|
+
/// @dev Return the Timestamp zero (0)
|
36
|
+
function zeroTimestamp() pure returns(Timestamp) { return toTimestamp(0); }
|
37
|
+
|
38
|
+
library TimestampLib {
|
39
|
+
/// @dev return true if Timestamp a is after Timestamp b
|
40
|
+
function gt(Timestamp a, Timestamp b) public pure returns(bool isAfter) { return gtTimestamp(a, b); }
|
41
|
+
/// @dev return true if Timestamp a is after or the same than Timestamp b
|
42
|
+
function gte(Timestamp a, Timestamp b) public pure returns(bool isAfterOrSame) { return gteTimestamp(a, b); }
|
43
|
+
|
44
|
+
/// @dev return true if Timestamp a is before Timestamp b
|
45
|
+
function lt(Timestamp a, Timestamp b) public pure returns(bool isBefore) { return ltTimestamp(a, b); }
|
46
|
+
/// @dev return true if Timestamp a is before or the same than Timestamp b
|
47
|
+
function lte(Timestamp a, Timestamp b) public pure returns(bool isBeforeOrSame) { return lteTimestamp(a, b); }
|
48
|
+
|
49
|
+
/// @dev return true if Timestamp a is equal to Timestamp b
|
50
|
+
function eq(Timestamp a, Timestamp b) public pure returns(bool isSame) { return eqTimestamp(a, b); }
|
51
|
+
/// @dev return true if Timestamp a is not equal to Timestamp b
|
52
|
+
function ne(Timestamp a, Timestamp b) public pure returns(bool isDifferent) { return neTimestamp(a, b); }
|
53
|
+
|
54
|
+
function toInt(Timestamp timestamp) public pure returns(uint256) { return uint256(uint40(Timestamp.unwrap(timestamp))); }
|
55
|
+
}
|