@etherisc/gif-next 0.0.2-bd7444a → 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/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/IProduct.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +2 -2
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +2 -2
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
- 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/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +2 -2
- 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/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +2 -2
- 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/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- 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/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- 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/PoolModule.sol/PoolModule.dbg.json +1 -1
- 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/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 +2 -2
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
- 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/IRegistry.dbg.json +1 -1
- 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/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
- 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 +1 -1
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
- 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 +1 -1
- package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +2 -2
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +15 -2
- package/contracts/components/Component.sol +16 -18
- package/contracts/components/IPool.sol +3 -3
- package/contracts/components/IProduct.sol +3 -6
- package/contracts/components/Pool.sol +6 -13
- package/contracts/components/Product.sol +10 -21
- package/contracts/experiment/errors/Require.sol +10 -5
- package/contracts/experiment/errors/Revert.sol +13 -8
- package/contracts/experiment/inheritance/A.sol +8 -11
- package/contracts/experiment/inheritance/B.sol +10 -5
- package/contracts/experiment/inheritance/C.sol +11 -5
- package/contracts/experiment/inheritance/IA.sol +2 -7
- package/contracts/experiment/inheritance/IB.sol +3 -2
- package/contracts/experiment/inheritance/IC.sol +4 -3
- package/contracts/experiment/types/TypeA.sol +14 -9
- package/contracts/experiment/types/TypeB.sol +14 -9
- package/contracts/instance/IInstance.sol +1 -3
- package/contracts/instance/Instance.sol +13 -13
- package/contracts/instance/access/Access.sol +63 -116
- package/contracts/instance/access/IAccess.sol +28 -48
- package/contracts/instance/component/ComponentModule.sol +63 -98
- package/contracts/instance/component/IComponent.sol +30 -52
- package/contracts/instance/policy/IPolicy.sol +9 -24
- package/contracts/instance/policy/PolicyModule.sol +19 -35
- package/contracts/instance/pool/IPoolModule.sol +7 -19
- package/contracts/instance/pool/PoolModule.sol +22 -35
- package/contracts/instance/product/IProductService.sol +5 -15
- package/contracts/instance/product/ProductService.sol +43 -39
- package/contracts/registry/ChainNft.sol +23 -61
- package/contracts/registry/IChainNft.sol +10 -7
- package/contracts/registry/IRegistry.sol +46 -36
- package/contracts/registry/Registry.sol +80 -53
- package/contracts/types/Blocknumber.sol +76 -18
- package/contracts/types/ChainId.sol +18 -10
- package/contracts/types/NftId.sol +29 -13
- package/contracts/types/Timestamp.sol +63 -16
- package/contracts/types/UFixed.sol +62 -64
- package/package.json +7 -3
@@ -7,19 +7,20 @@ import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
|
|
7
7
|
import {IPoolModule} from "./IPoolModule.sol";
|
8
8
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
9
9
|
|
10
|
-
abstract contract PoolModule is
|
11
|
-
IPoolModule
|
12
|
-
{
|
10
|
+
abstract contract PoolModule is IPoolModule {
|
13
11
|
using NftIdLib for NftId;
|
14
|
-
|
15
|
-
uint256 public constant INITIAL_CAPITAL = 10000*10**6;
|
12
|
+
|
13
|
+
uint256 public constant INITIAL_CAPITAL = 10000 * 10 ** 6;
|
16
14
|
|
17
15
|
mapping(NftId nftId => PoolInfo info) private _poolInfo;
|
18
16
|
|
19
17
|
IProductService private _productService;
|
20
18
|
|
21
19
|
modifier onlyProductService() {
|
22
|
-
require(
|
20
|
+
require(
|
21
|
+
address(_productService) == msg.sender,
|
22
|
+
"ERROR:POL-001:NOT_PRODUCT_SERVICE"
|
23
|
+
);
|
23
24
|
_;
|
24
25
|
}
|
25
26
|
|
@@ -31,13 +32,8 @@ abstract contract PoolModule is
|
|
31
32
|
NftId nftId,
|
32
33
|
address wallet,
|
33
34
|
address token
|
34
|
-
)
|
35
|
-
|
36
|
-
override
|
37
|
-
{
|
38
|
-
require(
|
39
|
-
_poolInfo[nftId].nftId.eqz(),
|
40
|
-
"ERROR:PL-001:ALREADY_CREATED");
|
35
|
+
) public override {
|
36
|
+
require(_poolInfo[nftId].nftId.eqz(), "ERROR:PL-001:ALREADY_CREATED");
|
41
37
|
|
42
38
|
_poolInfo[nftId] = PoolInfo(
|
43
39
|
nftId,
|
@@ -46,41 +42,32 @@ abstract contract PoolModule is
|
|
46
42
|
INITIAL_CAPITAL,
|
47
43
|
0 // locked capital
|
48
44
|
);
|
49
|
-
|
50
45
|
}
|
51
46
|
|
52
|
-
|
53
47
|
function underwrite(
|
54
48
|
NftId poolNftId,
|
55
49
|
NftId policyNftId
|
56
|
-
)
|
57
|
-
external
|
58
|
-
override
|
59
|
-
onlyProductService
|
60
|
-
{
|
50
|
+
) external override onlyProductService {
|
61
51
|
PoolInfo storage poolInfo = _poolInfo[poolNftId];
|
62
|
-
require(
|
63
|
-
poolInfo.nftId == poolNftId,
|
64
|
-
"ERROR:PL-002:POOL_UNKNOWN");
|
52
|
+
require(poolInfo.nftId == poolNftId, "ERROR:PL-002:POOL_UNKNOWN");
|
65
53
|
|
66
54
|
IPolicyModule policyModule = IPolicyModule(address(this));
|
67
|
-
IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(
|
55
|
+
IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(
|
56
|
+
policyNftId
|
57
|
+
);
|
68
58
|
|
69
59
|
require(
|
70
|
-
poolInfo.capital - poolInfo.lockedCapital >=
|
71
|
-
|
60
|
+
poolInfo.capital - poolInfo.lockedCapital >=
|
61
|
+
policyInfo.sumInsuredAmount,
|
62
|
+
"ERROR:PL-003:CAPACITY_TOO_LOW"
|
63
|
+
);
|
72
64
|
|
73
65
|
poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
|
74
66
|
}
|
75
67
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
view
|
80
|
-
override
|
81
|
-
returns(PoolInfo memory info)
|
82
|
-
{
|
68
|
+
function getPoolInfo(
|
69
|
+
NftId nftId
|
70
|
+
) external view override returns (PoolInfo memory info) {
|
83
71
|
info = _poolInfo[nftId];
|
84
72
|
}
|
85
|
-
|
86
|
-
}
|
73
|
+
}
|
@@ -1,30 +1,24 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
|
5
4
|
import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
|
6
5
|
import {IInstance} from "../IInstance.sol";
|
7
6
|
import {NftId} from "../../types/NftId.sol";
|
8
7
|
|
9
|
-
|
10
8
|
// TODO or name this IProtectionService to have Product be something more generic (loan, savings account, ...)
|
11
|
-
interface IProductService is
|
12
|
-
IRegistryLinked
|
13
|
-
{
|
14
|
-
|
9
|
+
interface IProductService is IRegistryLinked {
|
15
10
|
function createApplication(
|
16
11
|
address applicationOwner,
|
17
12
|
uint256 sumInsuredAmount,
|
18
13
|
uint256 premiumAmount,
|
19
14
|
uint256 lifetime,
|
20
15
|
NftId bundleNftId
|
21
|
-
)
|
22
|
-
external
|
23
|
-
returns(NftId nftId);
|
16
|
+
) external returns (NftId nftId);
|
24
17
|
|
25
18
|
// function revoke(unit256 nftId) external;
|
26
19
|
|
27
20
|
function underwrite(NftId nftId) external;
|
21
|
+
|
28
22
|
// function decline(uint256 nftId) external;
|
29
23
|
// function expire(uint256 nftId) external;
|
30
24
|
function close(NftId nftId) external;
|
@@ -37,10 +31,6 @@ interface IProductService is
|
|
37
31
|
// function closeClaim(uint256 nftId, uint256 claimId) external;
|
38
32
|
}
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
IOwnable,
|
43
|
-
IRegistryLinked
|
44
|
-
{
|
45
|
-
function getProductService() external view returns(IProductService);
|
34
|
+
interface IProductModule is IOwnable, IRegistryLinked {
|
35
|
+
function getProductService() external view returns (IProductService);
|
46
36
|
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
|
5
4
|
// import {IProduct} from "../../components/IProduct.sol";
|
6
5
|
// import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
|
7
6
|
// import {IInstance} from "../IInstance.sol";
|
@@ -14,16 +13,10 @@ import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
|
|
14
13
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
15
14
|
|
16
15
|
// TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
|
17
|
-
contract ProductService is
|
18
|
-
RegistryLinked,
|
19
|
-
IProductService
|
20
|
-
{
|
16
|
+
contract ProductService is RegistryLinked, IProductService {
|
21
17
|
using NftIdLib for NftId;
|
22
|
-
|
23
|
-
constructor(address registry)
|
24
|
-
RegistryLinked(registry)
|
25
|
-
{ }
|
26
18
|
|
19
|
+
constructor(address registry) RegistryLinked(registry) {}
|
27
20
|
|
28
21
|
function createApplication(
|
29
22
|
address applicationOwner,
|
@@ -31,20 +24,26 @@ contract ProductService is
|
|
31
24
|
uint256 premiumAmount,
|
32
25
|
uint256 lifetime,
|
33
26
|
NftId bundleNftId
|
34
|
-
)
|
35
|
-
external
|
36
|
-
override
|
37
|
-
returns(NftId nftId)
|
38
|
-
{
|
27
|
+
) external override returns (NftId nftId) {
|
39
28
|
// same as only registered product
|
40
29
|
NftId productNftId = _registry.getNftId(msg.sender);
|
41
30
|
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
42
|
-
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
43
|
-
|
44
|
-
|
45
|
-
|
31
|
+
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
32
|
+
productNftId
|
33
|
+
);
|
34
|
+
require(
|
35
|
+
productInfo.objectType == _registry.PRODUCT(),
|
36
|
+
"ERROR_NOT_PRODUCT"
|
37
|
+
);
|
38
|
+
|
39
|
+
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
|
40
|
+
productInfo.parentNftId
|
41
|
+
);
|
46
42
|
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
47
|
-
require(
|
43
|
+
require(
|
44
|
+
instanceInfo.objectType == _registry.INSTANCE(),
|
45
|
+
"ERROR_NOT_INSTANCE"
|
46
|
+
);
|
48
47
|
|
49
48
|
IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
|
50
49
|
nftId = policyModule.createApplication(
|
@@ -53,34 +52,42 @@ contract ProductService is
|
|
53
52
|
sumInsuredAmount,
|
54
53
|
premiumAmount,
|
55
54
|
lifetime,
|
56
|
-
bundleNftId
|
55
|
+
bundleNftId
|
56
|
+
);
|
57
57
|
|
58
58
|
// add logging
|
59
59
|
}
|
60
60
|
|
61
|
-
function underwrite(NftId nftId)
|
62
|
-
external
|
63
|
-
override
|
64
|
-
{
|
61
|
+
function underwrite(NftId nftId) external override {
|
65
62
|
// same as only registered product
|
66
63
|
NftId productNftId = _registry.getNftId(msg.sender);
|
67
64
|
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
68
|
-
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
69
|
-
|
70
|
-
|
71
|
-
|
65
|
+
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
66
|
+
productNftId
|
67
|
+
);
|
68
|
+
require(
|
69
|
+
productInfo.objectType == _registry.PRODUCT(),
|
70
|
+
"ERROR_NOT_PRODUCT"
|
71
|
+
);
|
72
|
+
|
73
|
+
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
|
74
|
+
productInfo.parentNftId
|
75
|
+
);
|
72
76
|
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
73
|
-
require(
|
77
|
+
require(
|
78
|
+
instanceInfo.objectType == _registry.INSTANCE(),
|
79
|
+
"ERROR_NOT_INSTANCE"
|
80
|
+
);
|
74
81
|
|
75
82
|
// get responsible pool
|
76
|
-
IComponentModule componentModule = IComponentModule(
|
83
|
+
IComponentModule componentModule = IComponentModule(
|
84
|
+
instanceInfo.objectAddress
|
85
|
+
);
|
77
86
|
NftId poolNftId = componentModule.getPoolNftId(productNftId);
|
78
87
|
|
79
88
|
// lock capital (and update pool accounting)
|
80
89
|
IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
|
81
|
-
poolModule.underwrite(
|
82
|
-
poolNftId,
|
83
|
-
nftId);
|
90
|
+
poolModule.underwrite(poolNftId, nftId);
|
84
91
|
|
85
92
|
// activate policy
|
86
93
|
IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
|
@@ -92,17 +99,14 @@ contract ProductService is
|
|
92
99
|
function close(NftId nftId) external override {}
|
93
100
|
}
|
94
101
|
|
95
|
-
abstract contract ProductModule is
|
96
|
-
IProductModule
|
97
|
-
{
|
102
|
+
abstract contract ProductModule is IProductModule {
|
98
103
|
IProductService private _productService;
|
99
104
|
|
100
105
|
constructor(address productService) {
|
101
106
|
_productService = IProductService(productService);
|
102
107
|
}
|
103
108
|
|
104
|
-
function getProductService() external view returns(IProductService) {
|
109
|
+
function getProductService() external view returns (IProductService) {
|
105
110
|
return _productService;
|
106
111
|
}
|
107
|
-
|
108
|
-
}
|
112
|
+
}
|
@@ -4,10 +4,7 @@ pragma solidity ^0.8.19;
|
|
4
4
|
import {ERC721, ERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
|
5
5
|
import {IChainNft} from "./IChainNft.sol";
|
6
6
|
|
7
|
-
contract ChainNft is
|
8
|
-
ERC721Enumerable,
|
9
|
-
IChainNft
|
10
|
-
{
|
7
|
+
contract ChainNft is ERC721Enumerable, IChainNft {
|
11
8
|
string public constant NAME = "Dezentralized Insurance Protocol Registry";
|
12
9
|
string public constant SYMBOL = "DIPR";
|
13
10
|
|
@@ -18,22 +15,18 @@ contract ChainNft is
|
|
18
15
|
address private _registry;
|
19
16
|
|
20
17
|
// only used for _getNextTokenId
|
21
|
-
uint256 internal _chainIdInt;
|
18
|
+
uint256 internal _chainIdInt;
|
22
19
|
uint256 internal _chainIdDigits;
|
23
20
|
uint256 internal _chainIdMultiplier;
|
24
21
|
uint256 internal _idNext;
|
25
22
|
uint256 internal _totalMinted;
|
26
23
|
|
27
|
-
|
28
24
|
modifier onlyRegistry() {
|
29
25
|
require(msg.sender == _registry, "ERROR:NFT-001:CALLER_NOT_REGISTRY");
|
30
26
|
_;
|
31
27
|
}
|
32
28
|
|
33
|
-
|
34
|
-
constructor(address registry)
|
35
|
-
ERC721(NAME, SYMBOL)
|
36
|
-
{
|
29
|
+
constructor(address registry) ERC721(NAME, SYMBOL) {
|
37
30
|
require(registry != address(0), "ERROR:NFT-010:REGISTRY_ZERO");
|
38
31
|
|
39
32
|
_registry = registry;
|
@@ -43,88 +36,59 @@ contract ChainNft is
|
|
43
36
|
_chainIdMultiplier = 10 ** _chainIdDigits;
|
44
37
|
|
45
38
|
// on mainnet/goerli start /1 (reserved for protocol nft) on other chains with 2
|
46
|
-
if(block.chainid == 1 || block.chainid == 5) {
|
39
|
+
if (block.chainid == 1 || block.chainid == 5) {
|
47
40
|
_idNext = 1;
|
48
41
|
} else {
|
49
42
|
_idNext = 2;
|
50
43
|
}
|
51
44
|
}
|
52
45
|
|
53
|
-
|
54
46
|
function mint(
|
55
47
|
address to,
|
56
48
|
string memory uri
|
57
|
-
)
|
58
|
-
external
|
59
|
-
override
|
60
|
-
onlyRegistry
|
61
|
-
returns(uint256 tokenId)
|
62
|
-
{
|
49
|
+
) external override onlyRegistry returns (uint256 tokenId) {
|
63
50
|
tokenId = _getNextTokenId();
|
64
51
|
_totalMinted++;
|
65
52
|
|
66
53
|
_safeMint(to, tokenId);
|
67
54
|
|
68
|
-
if(bytes(uri).length > 0) {
|
55
|
+
if (bytes(uri).length > 0) {
|
69
56
|
_uri[tokenId] = uri;
|
70
57
|
}
|
71
58
|
}
|
72
59
|
|
73
|
-
|
74
|
-
function burn(uint256 tokenId)
|
75
|
-
external
|
76
|
-
override
|
77
|
-
onlyRegistry
|
78
|
-
{
|
60
|
+
function burn(uint256 tokenId) external override onlyRegistry {
|
79
61
|
_requireMinted(tokenId);
|
80
62
|
_burn(tokenId);
|
81
63
|
delete _uri[tokenId];
|
82
64
|
}
|
83
65
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
onlyRegistry
|
89
|
-
{
|
66
|
+
function setURI(
|
67
|
+
uint256 tokenId,
|
68
|
+
string memory uri
|
69
|
+
) external override onlyRegistry {
|
90
70
|
require(bytes(uri).length > 0, "ERROR:CRG-011:URI_EMPTY");
|
91
71
|
|
92
72
|
_requireMinted(tokenId);
|
93
73
|
_uri[tokenId] = uri;
|
94
74
|
}
|
95
75
|
|
96
|
-
|
97
|
-
function exists(uint256 tokenId)
|
98
|
-
external
|
99
|
-
view
|
100
|
-
override
|
101
|
-
returns(bool)
|
102
|
-
{
|
76
|
+
function exists(uint256 tokenId) external view override returns (bool) {
|
103
77
|
return _exists(tokenId);
|
104
78
|
}
|
105
79
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
view
|
110
|
-
override
|
111
|
-
returns(string memory)
|
112
|
-
{
|
80
|
+
function tokenURI(
|
81
|
+
uint256 tokenId
|
82
|
+
) public view override returns (string memory) {
|
113
83
|
_requireMinted(tokenId);
|
114
84
|
return _uri[tokenId];
|
115
85
|
}
|
116
86
|
|
117
|
-
|
118
|
-
function getRegistryAddress()
|
119
|
-
external
|
120
|
-
view
|
121
|
-
override
|
122
|
-
returns(address)
|
123
|
-
{
|
87
|
+
function getRegistryAddress() external view override returns (address) {
|
124
88
|
return _registry;
|
125
89
|
}
|
126
90
|
|
127
|
-
function totalMinted() external override
|
91
|
+
function totalMinted() external view override returns (uint256) {
|
128
92
|
return _totalMinted;
|
129
93
|
}
|
130
94
|
|
@@ -153,17 +117,15 @@ contract ChainNft is
|
|
153
117
|
// (42 * 10 ** 10 + 9876543210) * 100 + 10
|
154
118
|
// (index * 10 ** digits + chainid) * 100 + digits (1 < digits < 100)
|
155
119
|
|
156
|
-
function _getNextTokenId() private returns(uint256 id) {
|
157
|
-
id =
|
120
|
+
function _getNextTokenId() private returns (uint256 id) {
|
121
|
+
id =
|
122
|
+
(_idNext * _chainIdMultiplier + _chainIdInt) *
|
123
|
+
100 +
|
124
|
+
_chainIdDigits;
|
158
125
|
_idNext++;
|
159
126
|
}
|
160
127
|
|
161
|
-
|
162
|
-
function _countDigits(uint256 num)
|
163
|
-
private
|
164
|
-
pure
|
165
|
-
returns (uint256 count)
|
166
|
-
{
|
128
|
+
function _countDigits(uint256 num) private pure returns (uint256 count) {
|
167
129
|
count = 0;
|
168
130
|
while (num != 0) {
|
169
131
|
count++;
|
@@ -3,16 +3,19 @@ pragma solidity ^0.8.19;
|
|
3
3
|
|
4
4
|
import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
|
5
5
|
|
6
|
-
interface IChainNft is
|
7
|
-
|
8
|
-
|
6
|
+
interface IChainNft is IERC721Enumerable {
|
7
|
+
function mint(
|
8
|
+
address to,
|
9
|
+
string memory uri
|
10
|
+
) external returns (uint256 tokenId);
|
9
11
|
|
10
|
-
function mint(address to, string memory uri) external returns(uint256 tokenId);
|
11
12
|
function burn(uint256 tokenId) external;
|
13
|
+
|
12
14
|
function setURI(uint256 tokenId, string memory uri) external;
|
13
15
|
|
14
|
-
function exists(uint256 tokenId) external view returns(bool);
|
15
|
-
|
16
|
+
function exists(uint256 tokenId) external view returns (bool);
|
17
|
+
|
18
|
+
function totalMinted() external view returns (uint256);
|
16
19
|
|
17
|
-
function getRegistryAddress() external view returns(address registry);
|
20
|
+
function getRegistryAddress() external view returns (address registry);
|
18
21
|
}
|
@@ -4,36 +4,34 @@ pragma solidity ^0.8.19;
|
|
4
4
|
import {NftId} from "../types/NftId.sol";
|
5
5
|
|
6
6
|
interface IOwnable {
|
7
|
-
function getOwner() external view returns(address owner);
|
7
|
+
function getOwner() external view returns (address owner);
|
8
8
|
}
|
9
9
|
|
10
10
|
interface IRegistryLinked {
|
11
|
-
|
12
11
|
event LogDebug(uint256 idx, address module, string comment);
|
13
12
|
|
14
|
-
function getRegistry() external view returns(IRegistry registry);
|
13
|
+
function getRegistry() external view returns (IRegistry registry);
|
15
14
|
}
|
16
15
|
|
17
|
-
interface IRegisterable is
|
18
|
-
|
19
|
-
IRegistryLinked
|
20
|
-
{
|
21
|
-
|
22
|
-
function register() external returns(NftId nftId);
|
23
|
-
|
24
|
-
function getNftId() external view returns(NftId nftId);
|
25
|
-
function getParentNftId() external view returns(NftId parentNftId);
|
26
|
-
function getType() external view returns(uint256 objectType);
|
27
|
-
function getData() external view returns(bytes memory data);
|
28
|
-
function isRegisterable() external pure returns(bool);
|
29
|
-
function getInitialOwner() external view returns(address initialOwner);
|
30
|
-
|
31
|
-
function isRegistered() external view returns(bool);
|
32
|
-
}
|
16
|
+
interface IRegisterable is IOwnable, IRegistryLinked {
|
17
|
+
function register() external returns (NftId nftId);
|
33
18
|
|
19
|
+
function getNftId() external view returns (NftId nftId);
|
34
20
|
|
35
|
-
|
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);
|
36
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 {
|
37
35
|
struct RegistryInfo {
|
38
36
|
NftId nftId;
|
39
37
|
NftId parentNftId;
|
@@ -42,29 +40,41 @@ interface IRegistry {
|
|
42
40
|
address initialOwner;
|
43
41
|
}
|
44
42
|
|
45
|
-
function TOKEN() external pure returns(uint256);
|
46
|
-
|
47
|
-
function
|
48
|
-
|
49
|
-
function
|
50
|
-
|
51
|
-
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);
|
52
58
|
|
53
|
-
function register(address objectAddress) external returns(NftId nftId);
|
54
59
|
function registerObjectForInstance(
|
55
60
|
NftId parentNftid,
|
56
61
|
uint256 objectType,
|
57
62
|
address initialOwner
|
58
|
-
)
|
59
|
-
|
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);
|
60
70
|
|
61
|
-
function
|
71
|
+
function getInfo(
|
72
|
+
NftId nftId
|
73
|
+
) external view returns (RegistryInfo memory info);
|
62
74
|
|
63
|
-
function
|
64
|
-
function getInfo(NftId nftId) external view returns(RegistryInfo memory info);
|
65
|
-
function getOwner(NftId nftId) external view returns(address ownerAddress);
|
75
|
+
function getOwner(NftId nftId) external view returns (address ownerAddress);
|
66
76
|
|
67
|
-
function isRegistered(address objectAddress) external view returns(bool);
|
77
|
+
function isRegistered(address objectAddress) external view returns (bool);
|
68
78
|
|
69
|
-
function getNftAddress() external view returns(address nft);
|
79
|
+
function getNftAddress() external view returns (address nft);
|
70
80
|
}
|