@etherisc/gif-next 0.0.2-886fd8b → 0.0.2-8872ac5

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.
Files changed (114) hide show
  1. package/README.md +24 -0
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
  4. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
  5. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  8. package/artifacts/contracts/components/Pool.sol/Pool.json +22 -4
  9. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  10. package/artifacts/contracts/components/Product.sol/Product.json +22 -4
  11. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  12. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
  13. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  14. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
  15. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  16. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
  17. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
  19. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
  27. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
  29. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  30. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  31. package/artifacts/contracts/instance/Instance.sol/Instance.json +62 -4
  32. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  33. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  34. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  35. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  36. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  37. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  38. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  39. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +46 -4
  40. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  41. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  42. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  43. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  44. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  45. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  46. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  47. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  48. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  49. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  50. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  51. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  52. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  53. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  54. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  55. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +46 -4
  56. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  57. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  58. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  59. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  60. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  61. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  62. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  63. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  64. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  65. package/artifacts/contracts/registry/Registry.sol/Registry.json +46 -4
  66. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  67. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  68. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  69. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  70. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  71. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
  72. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  73. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +85 -3
  74. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  75. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  76. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  77. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +453 -0
  78. package/contracts/components/Component.sol +16 -18
  79. package/contracts/components/IPool.sol +3 -3
  80. package/contracts/components/IProduct.sol +3 -6
  81. package/contracts/components/Pool.sol +6 -13
  82. package/contracts/components/Product.sol +10 -21
  83. package/contracts/experiment/errors/Require.sol +10 -5
  84. package/contracts/experiment/errors/Revert.sol +13 -8
  85. package/contracts/experiment/inheritance/A.sol +8 -11
  86. package/contracts/experiment/inheritance/B.sol +10 -5
  87. package/contracts/experiment/inheritance/C.sol +11 -5
  88. package/contracts/experiment/inheritance/IA.sol +2 -7
  89. package/contracts/experiment/inheritance/IB.sol +3 -2
  90. package/contracts/experiment/inheritance/IC.sol +4 -3
  91. package/contracts/experiment/types/TypeA.sol +14 -9
  92. package/contracts/experiment/types/TypeB.sol +14 -9
  93. package/contracts/instance/IInstance.sol +1 -3
  94. package/contracts/instance/Instance.sol +13 -13
  95. package/contracts/instance/access/Access.sol +63 -116
  96. package/contracts/instance/access/IAccess.sol +28 -48
  97. package/contracts/instance/component/ComponentModule.sol +70 -103
  98. package/contracts/instance/component/IComponent.sol +30 -52
  99. package/contracts/instance/policy/IPolicy.sol +9 -24
  100. package/contracts/instance/policy/PolicyModule.sol +22 -37
  101. package/contracts/instance/pool/IPoolModule.sol +7 -19
  102. package/contracts/instance/pool/PoolModule.sol +24 -35
  103. package/contracts/instance/product/IProductService.sol +5 -15
  104. package/contracts/instance/product/ProductService.sol +49 -43
  105. package/contracts/registry/ChainNft.sol +23 -61
  106. package/contracts/registry/IChainNft.sol +10 -7
  107. package/contracts/registry/IRegistry.sol +46 -36
  108. package/contracts/registry/Registry.sol +87 -59
  109. package/contracts/types/Blocknumber.sol +118 -0
  110. package/contracts/types/ChainId.sol +24 -10
  111. package/contracts/types/NftId.sol +36 -11
  112. package/contracts/types/Timestamp.sol +102 -0
  113. package/contracts/types/UFixed.sol +205 -0
  114. package/package.json +8 -4
@@ -1,18 +1,15 @@
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 {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
7
6
 
8
7
  import {IProductService} from "../product/IProductService.sol";
9
8
  import {IPolicy, IPolicyModule} from "./IPolicy.sol";
10
- import {NftId, gtz} from "../../types/NftId.sol";
9
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
11
10
 
12
- abstract contract PolicyModule is
13
- IRegistryLinked,
14
- IPolicyModule
15
- {
11
+ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
12
+ using NftIdLib for NftId;
16
13
 
17
14
  mapping(NftId nftId => PolicyInfo info) private _policyInfo;
18
15
  mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
@@ -21,7 +18,10 @@ abstract contract PolicyModule is
21
18
 
22
19
  // TODO find a better place to avoid dupliation
23
20
  modifier onlyProductService2() {
24
- require(address(_productService) == msg.sender, "ERROR:POL-001:NOT_PRODUCT_SERVICE");
21
+ require(
22
+ address(_productService) == msg.sender,
23
+ "ERROR:POL-001:NOT_PRODUCT_SERVICE"
24
+ );
25
25
  _;
26
26
  }
27
27
 
@@ -29,7 +29,6 @@ abstract contract PolicyModule is
29
29
  _productService = IProductService(productService);
30
30
  }
31
31
 
32
-
33
32
  function createApplication(
34
33
  IRegistry.RegistryInfo memory productInfo,
35
34
  address applicationOwner,
@@ -37,22 +36,20 @@ abstract contract PolicyModule is
37
36
  uint256 premiumAmount,
38
37
  uint256 lifetime,
39
38
  NftId bundleNftId
40
- )
41
- external
42
- override
43
- onlyProductService2
44
- returns(NftId nftId)
45
- {
39
+ ) external override onlyProductService2 returns (NftId nftId) {
46
40
  // TODO add parameter validation
47
- if(gtz(bundleNftId)) {
48
- IRegistry.RegistryInfo memory bundleInfo = this.getRegistry().getInfo(bundleNftId);
49
- IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
41
+ if (bundleNftId.gtz()) {
42
+ IRegistry.RegistryInfo memory bundleInfo = this
43
+ .getRegistry()
44
+ .getInfo(bundleNftId);
45
+ // IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
50
46
  }
51
47
 
52
48
  nftId = this.getRegistry().registerObjectForInstance(
53
49
  productInfo.nftId,
54
50
  this.getRegistry().POLICY(),
55
- applicationOwner);
51
+ applicationOwner
52
+ );
56
53
 
57
54
  _policyInfo[nftId] = PolicyInfo(
58
55
  nftId,
@@ -71,12 +68,7 @@ abstract contract PolicyModule is
71
68
  // add logging
72
69
  }
73
70
 
74
-
75
- function activate(NftId nftId)
76
- external
77
- override
78
- onlyProductService2
79
- {
71
+ function activate(NftId nftId) external override onlyProductService2 {
80
72
  PolicyInfo storage info = _policyInfo[nftId];
81
73
  info.activatedAt = block.timestamp;
82
74
  info.expiredAt = block.timestamp + info.lifetime;
@@ -85,22 +77,15 @@ abstract contract PolicyModule is
85
77
  // add logging
86
78
  }
87
79
 
88
-
89
-
90
- function getBundleNftForPolicy(NftId nftId)
91
- external
92
- view
93
- returns(NftId bundleNft)
94
- {
80
+ function getBundleNftForPolicy(
81
+ NftId nftId
82
+ ) external view returns (NftId bundleNft) {
95
83
  return _bundleForPolicy[nftId];
96
84
  }
97
85
 
98
-
99
- function getPolicyInfo(NftId nftId)
100
- external
101
- view
102
- returns(PolicyInfo memory info)
103
- {
86
+ function getPolicyInfo(
87
+ NftId nftId
88
+ ) external view returns (PolicyInfo memory info) {
104
89
  return _policyInfo[nftId];
105
90
  }
106
91
  }
@@ -5,7 +5,6 @@ import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol
5
5
  import {NftId} from "../../types/NftId.sol";
6
6
 
7
7
  interface IPool {
8
-
9
8
  struct PoolInfo {
10
9
  NftId nftId;
11
10
  address wallet;
@@ -15,27 +14,16 @@ interface IPool {
15
14
  }
16
15
  }
17
16
 
18
- interface IPoolModule is
19
- IOwnable,
20
- IRegistryLinked,
21
- IPool
22
- {
23
-
24
- function underwrite(
25
- NftId poolNftId,
26
- NftId policyNftId
27
- )
28
- external;
17
+ interface IPoolModule is IOwnable, IRegistryLinked, IPool {
18
+ function underwrite(NftId poolNftId, NftId policyNftId) external;
29
19
 
30
20
  function createPoolInfo(
31
21
  NftId nftId,
32
22
  address wallet,
33
23
  address token
34
- )
35
- external;
24
+ ) external;
36
25
 
37
- function getPoolInfo(NftId nftId)
38
- external
39
- view
40
- returns(PoolInfo memory info);
41
- }
26
+ function getPoolInfo(
27
+ NftId nftId
28
+ ) external view returns (PoolInfo memory info);
29
+ }
@@ -5,19 +5,22 @@ 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, eqz} from "../../types/NftId.sol";
8
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
9
9
 
10
- abstract contract PoolModule is
11
- IPoolModule
12
- {
13
- uint256 public constant INITIAL_CAPITAL = 10000*10**6;
10
+ abstract contract PoolModule is IPoolModule {
11
+ using NftIdLib for NftId;
12
+
13
+ uint256 public constant INITIAL_CAPITAL = 10000 * 10 ** 6;
14
14
 
15
15
  mapping(NftId nftId => PoolInfo info) private _poolInfo;
16
16
 
17
17
  IProductService private _productService;
18
18
 
19
19
  modifier onlyProductService() {
20
- require(address(_productService) == msg.sender, "ERROR:POL-001:NOT_PRODUCT_SERVICE");
20
+ require(
21
+ address(_productService) == msg.sender,
22
+ "ERROR:POL-001:NOT_PRODUCT_SERVICE"
23
+ );
21
24
  _;
22
25
  }
23
26
 
@@ -29,13 +32,8 @@ abstract contract PoolModule is
29
32
  NftId nftId,
30
33
  address wallet,
31
34
  address token
32
- )
33
- public
34
- override
35
- {
36
- require(
37
- eqz(_poolInfo[nftId].nftId),
38
- "ERROR:PL-001:ALREADY_CREATED");
35
+ ) public override {
36
+ require(_poolInfo[nftId].nftId.eqz(), "ERROR:PL-001:ALREADY_CREATED");
39
37
 
40
38
  _poolInfo[nftId] = PoolInfo(
41
39
  nftId,
@@ -44,41 +42,32 @@ abstract contract PoolModule is
44
42
  INITIAL_CAPITAL,
45
43
  0 // locked capital
46
44
  );
47
-
48
45
  }
49
46
 
50
-
51
47
  function underwrite(
52
48
  NftId poolNftId,
53
49
  NftId policyNftId
54
- )
55
- external
56
- override
57
- onlyProductService
58
- {
50
+ ) external override onlyProductService {
59
51
  PoolInfo storage poolInfo = _poolInfo[poolNftId];
60
- require(
61
- poolInfo.nftId == poolNftId,
62
- "ERROR:PL-002:POOL_UNKNOWN");
52
+ require(poolInfo.nftId == poolNftId, "ERROR:PL-002:POOL_UNKNOWN");
63
53
 
64
54
  IPolicyModule policyModule = IPolicyModule(address(this));
65
- IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(policyNftId);
55
+ IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(
56
+ policyNftId
57
+ );
66
58
 
67
59
  require(
68
- poolInfo.capital - poolInfo.lockedCapital >= policyInfo.sumInsuredAmount,
69
- "ERROR:PL-003:CAPACITY_TOO_LOW");
60
+ poolInfo.capital - poolInfo.lockedCapital >=
61
+ policyInfo.sumInsuredAmount,
62
+ "ERROR:PL-003:CAPACITY_TOO_LOW"
63
+ );
70
64
 
71
65
  poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
72
66
  }
73
67
 
74
-
75
- function getPoolInfo(NftId nftId)
76
- external
77
- view
78
- override
79
- returns(PoolInfo memory info)
80
- {
68
+ function getPoolInfo(
69
+ NftId nftId
70
+ ) external view override returns (PoolInfo memory info) {
81
71
  info = _poolInfo[nftId];
82
72
  }
83
-
84
- }
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
- interface IProductModule is
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";
@@ -11,17 +10,13 @@ import {RegistryLinked} from "../../registry/Registry.sol";
11
10
  import {IProductService, IProductModule} from "./IProductService.sol";
12
11
  import {IComponentModule} from "../../instance/component/IComponent.sol";
13
12
  import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
14
- import {NftId, gtz} from "../../types/NftId.sol";
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
- {
21
- constructor(address registry)
22
- RegistryLinked(registry)
23
- { }
16
+ contract ProductService is RegistryLinked, IProductService {
17
+ using NftIdLib for NftId;
24
18
 
19
+ constructor(address registry) RegistryLinked(registry) {}
25
20
 
26
21
  function createApplication(
27
22
  address applicationOwner,
@@ -29,20 +24,26 @@ contract ProductService is
29
24
  uint256 premiumAmount,
30
25
  uint256 lifetime,
31
26
  NftId bundleNftId
32
- )
33
- external
34
- override
35
- returns(NftId nftId)
36
- {
27
+ ) external override returns (NftId nftId) {
37
28
  // same as only registered product
38
29
  NftId productNftId = _registry.getNftId(msg.sender);
39
- require(gtz(productNftId), "ERROR_PRODUCT_UNKNOWN");
40
- IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
41
- require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
42
-
43
- IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
44
- require(gtz(instanceInfo.nftId), "ERROR_INSTANCE_UNKNOWN");
45
- require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
30
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
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
+ );
42
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
43
+ require(
44
+ instanceInfo.objectType == _registry.INSTANCE(),
45
+ "ERROR_NOT_INSTANCE"
46
+ );
46
47
 
47
48
  IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
48
49
  nftId = policyModule.createApplication(
@@ -51,34 +52,42 @@ contract ProductService is
51
52
  sumInsuredAmount,
52
53
  premiumAmount,
53
54
  lifetime,
54
- bundleNftId);
55
+ bundleNftId
56
+ );
55
57
 
56
58
  // add logging
57
59
  }
58
60
 
59
- function underwrite(NftId nftId)
60
- external
61
- override
62
- {
61
+ function underwrite(NftId nftId) external override {
63
62
  // same as only registered product
64
63
  NftId productNftId = _registry.getNftId(msg.sender);
65
- require(gtz(productNftId), "ERROR_PRODUCT_UNKNOWN");
66
- IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
67
- require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
68
-
69
- IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
70
- require(gtz(instanceInfo.nftId), "ERROR_INSTANCE_UNKNOWN");
71
- require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
64
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
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
+ );
76
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
77
+ require(
78
+ instanceInfo.objectType == _registry.INSTANCE(),
79
+ "ERROR_NOT_INSTANCE"
80
+ );
72
81
 
73
82
  // get responsible pool
74
- IComponentModule componentModule = IComponentModule(instanceInfo.objectAddress);
83
+ IComponentModule componentModule = IComponentModule(
84
+ instanceInfo.objectAddress
85
+ );
75
86
  NftId poolNftId = componentModule.getPoolNftId(productNftId);
76
87
 
77
88
  // lock capital (and update pool accounting)
78
89
  IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
79
- poolModule.underwrite(
80
- poolNftId,
81
- nftId);
90
+ poolModule.underwrite(poolNftId, nftId);
82
91
 
83
92
  // activate policy
84
93
  IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
@@ -90,17 +99,14 @@ contract ProductService is
90
99
  function close(NftId nftId) external override {}
91
100
  }
92
101
 
93
- abstract contract ProductModule is
94
- IProductModule
95
- {
102
+ abstract contract ProductModule is IProductModule {
96
103
  IProductService private _productService;
97
104
 
98
105
  constructor(address productService) {
99
106
  _productService = IProductService(productService);
100
107
  }
101
108
 
102
- function getProductService() external view returns(IProductService) {
109
+ function getProductService() external view returns (IProductService) {
103
110
  return _productService;
104
111
  }
105
-
106
- }
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
- function setURI(uint256 tokenId, string memory uri)
86
- external
87
- override
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
- function tokenURI(uint256 tokenId)
108
- public
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 view returns(uint256) {
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 = (_idNext * _chainIdMultiplier + _chainIdInt) * 100 + _chainIdDigits;
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
- IERC721Enumerable
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
- function totalMinted() external view returns(uint256);
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
  }