@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
@@ -5,13 +5,16 @@ import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol
|
|
5
5
|
import {IProductService} from "../product/IProductService.sol";
|
6
6
|
import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
|
7
7
|
import {IPoolModule} from "./IPoolModule.sol";
|
8
|
+
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
8
9
|
|
9
10
|
abstract contract PoolModule is
|
10
11
|
IPoolModule
|
11
12
|
{
|
13
|
+
using NftIdLib for NftId;
|
14
|
+
|
12
15
|
uint256 public constant INITIAL_CAPITAL = 10000*10**6;
|
13
16
|
|
14
|
-
mapping(
|
17
|
+
mapping(NftId nftId => PoolInfo info) private _poolInfo;
|
15
18
|
|
16
19
|
IProductService private _productService;
|
17
20
|
|
@@ -25,7 +28,7 @@ abstract contract PoolModule is
|
|
25
28
|
}
|
26
29
|
|
27
30
|
function createPoolInfo(
|
28
|
-
|
31
|
+
NftId nftId,
|
29
32
|
address wallet,
|
30
33
|
address token
|
31
34
|
)
|
@@ -33,7 +36,7 @@ abstract contract PoolModule is
|
|
33
36
|
override
|
34
37
|
{
|
35
38
|
require(
|
36
|
-
_poolInfo[nftId].nftId
|
39
|
+
_poolInfo[nftId].nftId.eqz(),
|
37
40
|
"ERROR:PL-001:ALREADY_CREATED");
|
38
41
|
|
39
42
|
_poolInfo[nftId] = PoolInfo(
|
@@ -48,8 +51,8 @@ abstract contract PoolModule is
|
|
48
51
|
|
49
52
|
|
50
53
|
function underwrite(
|
51
|
-
|
52
|
-
|
54
|
+
NftId poolNftId,
|
55
|
+
NftId policyNftId
|
53
56
|
)
|
54
57
|
external
|
55
58
|
override
|
@@ -71,7 +74,7 @@ abstract contract PoolModule is
|
|
71
74
|
}
|
72
75
|
|
73
76
|
|
74
|
-
function getPoolInfo(
|
77
|
+
function getPoolInfo(NftId nftId)
|
75
78
|
external
|
76
79
|
view
|
77
80
|
override
|
@@ -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
|
|
9
10
|
// TODO or name this IProtectionService to have Product be something more generic (loan, savings account, ...)
|
@@ -16,17 +17,17 @@ interface IProductService is
|
|
16
17
|
uint256 sumInsuredAmount,
|
17
18
|
uint256 premiumAmount,
|
18
19
|
uint256 lifetime,
|
19
|
-
|
20
|
+
NftId bundleNftId
|
20
21
|
)
|
21
22
|
external
|
22
|
-
returns(
|
23
|
+
returns(NftId nftId);
|
23
24
|
|
24
25
|
// function revoke(unit256 nftId) external;
|
25
26
|
|
26
|
-
function underwrite(
|
27
|
+
function underwrite(NftId nftId) external;
|
27
28
|
// function decline(uint256 nftId) external;
|
28
29
|
// function expire(uint256 nftId) external;
|
29
|
-
function close(
|
30
|
+
function close(NftId nftId) external;
|
30
31
|
|
31
32
|
// function collectPremium(uint256 nftId, uint256 premiumAmount) external;
|
32
33
|
|
@@ -11,12 +11,15 @@ import {RegistryLinked} from "../../registry/Registry.sol";
|
|
11
11
|
import {IProductService, IProductModule} from "./IProductService.sol";
|
12
12
|
import {IComponentModule} from "../../instance/component/IComponent.sol";
|
13
13
|
import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
|
14
|
+
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
14
15
|
|
15
16
|
// TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
|
16
17
|
contract ProductService is
|
17
18
|
RegistryLinked,
|
18
19
|
IProductService
|
19
20
|
{
|
21
|
+
using NftIdLib for NftId;
|
22
|
+
|
20
23
|
constructor(address registry)
|
21
24
|
RegistryLinked(registry)
|
22
25
|
{ }
|
@@ -27,20 +30,20 @@ contract ProductService is
|
|
27
30
|
uint256 sumInsuredAmount,
|
28
31
|
uint256 premiumAmount,
|
29
32
|
uint256 lifetime,
|
30
|
-
|
33
|
+
NftId bundleNftId
|
31
34
|
)
|
32
35
|
external
|
33
36
|
override
|
34
|
-
returns(
|
37
|
+
returns(NftId nftId)
|
35
38
|
{
|
36
39
|
// same as only registered product
|
37
|
-
|
38
|
-
require(productNftId
|
40
|
+
NftId productNftId = _registry.getNftId(msg.sender);
|
41
|
+
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
39
42
|
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
|
40
43
|
require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
|
41
44
|
|
42
45
|
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
|
43
|
-
require(instanceInfo.nftId
|
46
|
+
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
44
47
|
require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
|
45
48
|
|
46
49
|
IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
|
@@ -55,23 +58,23 @@ contract ProductService is
|
|
55
58
|
// add logging
|
56
59
|
}
|
57
60
|
|
58
|
-
function underwrite(
|
61
|
+
function underwrite(NftId nftId)
|
59
62
|
external
|
60
63
|
override
|
61
64
|
{
|
62
65
|
// same as only registered product
|
63
|
-
|
64
|
-
require(productNftId
|
66
|
+
NftId productNftId = _registry.getNftId(msg.sender);
|
67
|
+
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
65
68
|
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
|
66
69
|
require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
|
67
70
|
|
68
71
|
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
|
69
|
-
require(instanceInfo.nftId
|
72
|
+
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
70
73
|
require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
|
71
74
|
|
72
75
|
// get responsible pool
|
73
76
|
IComponentModule componentModule = IComponentModule(instanceInfo.objectAddress);
|
74
|
-
|
77
|
+
NftId poolNftId = componentModule.getPoolNftId(productNftId);
|
75
78
|
|
76
79
|
// lock capital (and update pool accounting)
|
77
80
|
IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
|
@@ -86,7 +89,7 @@ contract ProductService is
|
|
86
89
|
// add logging
|
87
90
|
}
|
88
91
|
|
89
|
-
function close(
|
92
|
+
function close(NftId nftId) external override {}
|
90
93
|
}
|
91
94
|
|
92
95
|
abstract contract ProductModule is
|
@@ -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,24 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
// bytes5 (uint40) allows for chain ids up to 13 digits
|
5
|
+
type ChainId is bytes5;
|
6
|
+
|
7
|
+
// type bindings
|
8
|
+
using {
|
9
|
+
eqChainId as ==,
|
10
|
+
neChainId as !=,
|
11
|
+
ChainIdLib.toInt
|
12
|
+
} for ChainId global;
|
13
|
+
|
14
|
+
// general pure free functions
|
15
|
+
function toChainId(uint256 chainId) pure returns(ChainId) { return ChainId.wrap(bytes5(uint40(chainId))); }
|
16
|
+
|
17
|
+
// pure free functions for operators
|
18
|
+
function eqChainId(ChainId a, ChainId b) pure returns(bool isSame) { return ChainId.unwrap(a) == ChainId.unwrap(b); }
|
19
|
+
function neChainId(ChainId a, ChainId b) pure returns(bool isDifferent) { return ChainId.unwrap(a) != ChainId.unwrap(b); }
|
20
|
+
|
21
|
+
// library functions that operate on user defined type
|
22
|
+
library ChainIdLib {
|
23
|
+
function toInt(ChainId chainId) internal pure returns(uint256) { return uint256(uint40(ChainId.unwrap(chainId))); }
|
24
|
+
}
|
@@ -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
|
+
}
|