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