@etherisc/gif-next 0.0.2-836a512-798 → 0.0.2-839b2a2-792

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 (149) hide show
  1. package/README.md +8 -0
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +1 -1
  4. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
  5. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
  6. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +1 -1
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  10. package/artifacts/contracts/components/Pool.sol/Pool.json +5 -5
  11. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  12. package/artifacts/contracts/components/Product.sol/Product.json +5 -5
  13. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
  15. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
  17. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
  19. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
  21. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
  29. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +2 -2
  33. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +2 -2
  35. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  36. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
  37. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  38. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
  39. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  40. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +137 -21
  41. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  42. package/artifacts/contracts/instance/Instance.sol/Instance.json +175 -35
  43. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  44. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  45. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  46. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  47. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  48. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  49. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +2 -21
  50. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  51. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +65 -10
  52. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  53. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  54. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +1 -1
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +2 -21
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +47 -0
  59. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  60. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  61. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +1 -1
  62. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +1 -1
  63. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +2 -2
  64. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  65. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  66. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  67. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  68. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  69. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  70. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  71. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  72. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  73. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  74. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +14 -14
  75. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +1 -1
  76. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +1 -1
  77. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +135 -0
  78. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  79. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +2 -2
  80. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +1 -1
  81. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +135 -0
  82. package/artifacts/contracts/mock/Dip.sol/DIP.dbg.json +4 -0
  83. package/artifacts/contracts/mock/Dip.sol/DIP.json +338 -0
  84. package/artifacts/contracts/mock/TestPool.sol/TestPool.dbg.json +4 -0
  85. package/artifacts/contracts/mock/TestPool.sol/TestPool.json +294 -0
  86. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.dbg.json +4 -0
  87. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.json +384 -0
  88. package/artifacts/contracts/mock/Usdc.sol/USDC.dbg.json +4 -0
  89. package/artifacts/contracts/mock/Usdc.sol/USDC.json +338 -0
  90. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  91. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  92. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  93. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  94. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  95. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  96. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  97. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  98. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  99. package/artifacts/contracts/registry/Registry.sol/Registry.json +10 -10
  100. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  101. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  102. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  103. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
  104. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  105. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
  106. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  107. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
  108. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  109. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  110. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  111. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  112. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  113. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +2 -2
  114. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
  115. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +37 -11
  116. package/contracts/components/Component.sol +12 -12
  117. package/contracts/components/IPool.sol +6 -2
  118. package/contracts/components/IProduct.sol +7 -2
  119. package/contracts/components/Pool.sol +14 -7
  120. package/contracts/components/Product.sol +14 -6
  121. package/contracts/experiment/statemachine/Dummy.sol +12 -18
  122. package/contracts/experiment/statemachine/ISM.sol +7 -2
  123. package/contracts/experiment/statemachine/SM.sol +15 -12
  124. package/contracts/experiment/statemachine/SimpleStateMachine.sol +11 -4
  125. package/contracts/instance/IInstance.sol +4 -1
  126. package/contracts/instance/Instance.sol +8 -5
  127. package/contracts/instance/component/ComponentModule.sol +55 -35
  128. package/contracts/instance/component/IComponent.sol +12 -14
  129. package/contracts/instance/lifecycle/ILifecycle.sol +32 -17
  130. package/contracts/instance/lifecycle/LifecycleModule.sol +28 -31
  131. package/contracts/instance/policy/IPolicy.sol +0 -2
  132. package/contracts/instance/policy/PolicyModule.sol +14 -7
  133. package/contracts/instance/pool/IPoolModule.sol +3 -2
  134. package/contracts/instance/pool/PoolModule.sol +11 -12
  135. package/contracts/instance/product/ProductService.sol +30 -12
  136. package/contracts/instance/treasury/ITreasury.sol +43 -25
  137. package/contracts/instance/treasury/TokenHandler.sol +1 -4
  138. package/contracts/instance/treasury/TreasuryModule.sol +82 -45
  139. package/contracts/mock/Dip.sol +26 -0
  140. package/contracts/mock/TestPool.sol +16 -0
  141. package/contracts/mock/TestProduct.sol +39 -0
  142. package/contracts/mock/Usdc.sol +26 -0
  143. package/contracts/registry/IRegistry.sol +0 -2
  144. package/contracts/registry/Registry.sol +7 -2
  145. package/contracts/types/Fee.sol +6 -4
  146. package/contracts/types/ObjectType.sol +77 -20
  147. package/contracts/types/StateId.sol +68 -23
  148. package/contracts/types/UFixed.sol +18 -14
  149. package/package.json +4 -2
@@ -7,13 +7,11 @@ import {StateId, ACTIVE, PAUSED, ARCHIVED, CLOSED, APPLIED, REVOKED, DECLINED} f
7
7
  import {ILifecycleModule} from "./ILifecycle.sol";
8
8
 
9
9
  contract LifecycleModule is ILifecycleModule {
10
+ mapping(ObjectType objectType => StateId initialState)
11
+ private _initialState;
10
12
 
11
- mapping(ObjectType objectType => StateId initialState) private _initialState;
12
-
13
- mapping(ObjectType objectType =>
14
- mapping(StateId stateFrom =>
15
- mapping(StateId stateTo => bool isValid))) private _isValidTransition;
16
-
13
+ mapping(ObjectType objectType => mapping(StateId stateFrom => mapping(StateId stateTo => bool isValid)))
14
+ private _isValidTransition;
17
15
 
18
16
  constructor() {
19
17
  _setupComponentLifecycle(PRODUCT());
@@ -24,22 +22,27 @@ contract LifecycleModule is ILifecycleModule {
24
22
  _setupPolicyLifecycle();
25
23
  }
26
24
 
27
-
28
- function checkAndLogTransition(NftId nftId, ObjectType objectType, StateId fromId, StateId toId)
29
- public
30
- returns(StateId)
31
- // add only currentcontract? would that work?
25
+ function checkAndLogTransition(
26
+ NftId nftId,
27
+ ObjectType objectType,
28
+ StateId fromId,
29
+ StateId toId
30
+ ) public returns (StateId) // add only currentcontract? would that work?
32
31
  {
33
- if(!_isValidTransition[objectType][fromId][toId]) {
32
+ if (!_isValidTransition[objectType][fromId][toId]) {
34
33
  revert ErrorInvalidStateTransition(nftId, objectType, fromId, toId);
35
34
  }
36
35
 
37
- if(objectType == POLICY()) {
36
+ if (objectType == POLICY()) {
38
37
  emit LogPolicyStateChanged(nftId, fromId, toId);
39
- } else if(objectType == BUNDLE()) {
38
+ } else if (objectType == BUNDLE()) {
40
39
  emit LogBundleStateChanged(nftId, fromId, toId);
41
- } else if(objectType == PRODUCT() || objectType == ORACLE() || objectType == POOL()) {
42
- emit LogComponentStateChanged(nftId, objectType, fromId, toId);
40
+ } else if (
41
+ objectType == PRODUCT() ||
42
+ objectType == ORACLE() ||
43
+ objectType == POOL()
44
+ ) {
45
+ emit LogComponentStateChanged(nftId, objectType, fromId, toId);
43
46
  } else {
44
47
  revert ErrorNoLifecycle(nftId, objectType);
45
48
  }
@@ -47,24 +50,20 @@ contract LifecycleModule is ILifecycleModule {
47
50
  return toId;
48
51
  }
49
52
 
50
- function getInitialState(ObjectType objectType)
51
- public
52
- view
53
- returns(StateId)
54
- {
53
+ function getInitialState(
54
+ ObjectType objectType
55
+ ) public view returns (StateId) {
55
56
  return _initialState[objectType];
56
57
  }
57
58
 
58
-
59
- function isValidTransition(ObjectType objectType, StateId fromId, StateId toId)
60
- public
61
- view
62
- returns(bool)
63
- {
59
+ function isValidTransition(
60
+ ObjectType objectType,
61
+ StateId fromId,
62
+ StateId toId
63
+ ) public view returns (bool) {
64
64
  return _isValidTransition[objectType][fromId][toId];
65
65
  }
66
66
 
67
-
68
67
  function _setupComponentLifecycle(ObjectType objectType) internal {
69
68
  _initialState[objectType] = ACTIVE();
70
69
  _isValidTransition[objectType][ACTIVE()][PAUSED()] = true;
@@ -72,7 +71,6 @@ contract LifecycleModule is ILifecycleModule {
72
71
  _isValidTransition[objectType][PAUSED()][ARCHIVED()] = true;
73
72
  }
74
73
 
75
-
76
74
  function _setupBundleLifecycle() internal {
77
75
  _initialState[BUNDLE()] = ACTIVE();
78
76
  _isValidTransition[BUNDLE()][ACTIVE()][PAUSED()] = true;
@@ -80,7 +78,6 @@ contract LifecycleModule is ILifecycleModule {
80
78
  _isValidTransition[BUNDLE()][PAUSED()][CLOSED()] = true;
81
79
  }
82
80
 
83
-
84
81
  function _setupPolicyLifecycle() internal {
85
82
  _initialState[POLICY()] = APPLIED();
86
83
  _isValidTransition[POLICY()][APPLIED()][REVOKED()] = true;
@@ -88,4 +85,4 @@ contract LifecycleModule is ILifecycleModule {
88
85
  _isValidTransition[POLICY()][APPLIED()][ACTIVE()] = true;
89
86
  _isValidTransition[POLICY()][ACTIVE()][CLOSED()] = true;
90
87
  }
91
- }
88
+ }
@@ -9,7 +9,6 @@ import {StateId} from "../../types/StateId.sol";
9
9
 
10
10
  // TODO check if there is value to introuce IContract and let IPolicy derive from IContract
11
11
  interface IPolicy {
12
-
13
12
  struct PolicyInfo {
14
13
  NftId nftId;
15
14
  StateId state; // applied, withdrawn, rejected, active, closed
@@ -27,7 +26,6 @@ interface IPolicy {
27
26
  }
28
27
 
29
28
  interface IPolicyModule is IOwnable, IRegistryLinked, IPolicy {
30
-
31
29
  function createApplication(
32
30
  IRegistry.RegistryInfo memory productInfo,
33
31
  address applicationOwner,
@@ -13,10 +13,7 @@ import {NftId, NftIdLib} from "../../types/NftId.sol";
13
13
 
14
14
  import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
15
15
 
16
- abstract contract PolicyModule is
17
- IRegistryLinked,
18
- IPolicyModule
19
- {
16
+ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
20
17
  using NftIdLib for NftId;
21
18
 
22
19
  mapping(NftId nftId => PolicyInfo info) private _policyInfo;
@@ -58,7 +55,8 @@ abstract contract PolicyModule is
58
55
  nftId = this.getRegistry().registerObjectForInstance(
59
56
  productInfo.nftId,
60
57
  POLICY(),
61
- applicationOwner);
58
+ applicationOwner
59
+ );
62
60
 
63
61
  _policyInfo[nftId] = PolicyInfo(
64
62
  nftId,
@@ -67,7 +65,9 @@ abstract contract PolicyModule is
67
65
  premiumAmount,
68
66
  0, // premium paid amount
69
67
  lifetime,
68
+ // solhint-disable-next-line not-rely-on-time
70
69
  block.timestamp, // createdAt
70
+ // solhint-disable-next-line not-rely-on-time
71
71
  block.timestamp, // updatedAt
72
72
  0, // activatedAt
73
73
  0, // expiredAt
@@ -82,15 +82,22 @@ abstract contract PolicyModule is
82
82
  function processPremium(NftId nftId) external override onlyProductService2 {
83
83
  PolicyInfo storage info = _policyInfo[nftId];
84
84
  info.premiumPaidAmount = info.premiumAmount;
85
+ // solhint-disable-next-line not-rely-on-time
85
86
  info.updatedAt = block.timestamp;
86
87
  }
87
88
 
88
-
89
89
  function activate(NftId nftId) external override onlyProductService2 {
90
90
  PolicyInfo storage info = _policyInfo[nftId];
91
+ // solhint-disable-next-line not-rely-on-time
91
92
  info.activatedAt = block.timestamp;
93
+ // solhint-disable-next-line not-rely-on-time
92
94
  info.expiredAt = block.timestamp + info.lifetime;
93
- info.state = _lifecycleModule.checkAndLogTransition(nftId, POLICY(), info.state, ACTIVE());
95
+ info.state = _lifecycleModule.checkAndLogTransition(
96
+ nftId,
97
+ POLICY(),
98
+ info.state,
99
+ ACTIVE()
100
+ );
94
101
  }
95
102
 
96
103
  function getBundleNftForPolicy(
@@ -13,10 +13,11 @@ interface IPool {
13
13
  }
14
14
 
15
15
  interface IPoolModule is IOwnable, IRegistryLinked, IPool {
16
-
17
16
  function underwrite(NftId policyNftId, NftId productNftId) external;
18
17
 
19
18
  function registerPool(NftId nftId) external;
20
19
 
21
- function getPoolInfo(NftId nftId) external view returns (PoolInfo memory info);
20
+ function getPoolInfo(
21
+ NftId nftId
22
+ ) external view returns (PoolInfo memory info);
22
23
  }
@@ -34,10 +34,7 @@ abstract contract PoolModule is IPoolModule {
34
34
  _productService = IProductService(productService);
35
35
  }
36
36
 
37
- function registerPool(NftId nftId)
38
- public
39
- override
40
- {
37
+ function registerPool(NftId nftId) public override {
41
38
  require(_poolInfo[nftId].nftId.eqz(), "ERROR:PL-001:ALREADY_CREATED");
42
39
 
43
40
  _poolInfo[nftId] = PoolInfo(
@@ -50,16 +47,18 @@ abstract contract PoolModule is IPoolModule {
50
47
  function underwrite(
51
48
  NftId policyNftId,
52
49
  NftId productNftId
53
- )
54
- external
55
- override
56
- onlyProductService
57
- {
58
- IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(policyNftId);
50
+ ) external override onlyProductService {
51
+ IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(
52
+ policyNftId
53
+ );
59
54
  require(policyInfo.nftId == policyNftId, "ERROR:PL-002:POLICY_UNKNOWN");
60
55
 
61
- ITreasuryModule.ProductSetup memory product = _treasuryModule.getProductSetup(productNftId);
62
- require(product.productNftId == productNftId, "ERROR:PL-003:PRODUCT_SETUP_MISSING");
56
+ ITreasuryModule.ProductSetup memory product = _treasuryModule
57
+ .getProductSetup(productNftId);
58
+ require(
59
+ product.productNftId == productNftId,
60
+ "ERROR:PL-003:PRODUCT_SETUP_MISSING"
61
+ );
63
62
 
64
63
  NftId poolNftId = product.poolNftId;
65
64
  PoolInfo storage poolInfo = _poolInfo[poolNftId];
@@ -17,7 +17,12 @@ import {NftId, NftIdLib} from "../../types/NftId.sol";
17
17
  contract ProductService is RegistryLinked, IProductService {
18
18
  using NftIdLib for NftId;
19
19
 
20
- constructor(address registry) RegistryLinked(registry) {}
20
+ constructor(
21
+ address registry
22
+ ) RegistryLinked(registry) // solhint-disable-next-line no-empty-blocks
23
+ {
24
+
25
+ }
21
26
 
22
27
  function createApplication(
23
28
  address applicationOwner,
@@ -29,10 +34,14 @@ contract ProductService is RegistryLinked, IProductService {
29
34
  // same as only registered product
30
35
  NftId productNftId = _registry.getNftId(msg.sender);
31
36
  require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
32
- IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
37
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
38
+ productNftId
39
+ );
33
40
  require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
34
41
 
35
- IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
42
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
43
+ productInfo.parentNftId
44
+ );
36
45
  require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
37
46
  require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
38
47
 
@@ -54,10 +63,14 @@ contract ProductService is RegistryLinked, IProductService {
54
63
  // same as only registered product
55
64
  NftId productNftId = _registry.getNftId(msg.sender);
56
65
  require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
57
- IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
66
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
67
+ productNftId
68
+ );
58
69
  require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
59
70
 
60
- IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
71
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
72
+ productInfo.parentNftId
73
+ );
61
74
  require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
62
75
  require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
63
76
 
@@ -73,19 +86,20 @@ contract ProductService is RegistryLinked, IProductService {
73
86
  // add logging
74
87
  }
75
88
 
76
- function collectPremium(NftId policyNftId)
77
- external
78
- override
79
- {
89
+ function collectPremium(NftId policyNftId) external override {
80
90
  // validation same as other functions, eg underwrite
81
91
  // TODO unify validation into modifier and/or other suitable approaches
82
92
  // same as only registered product
83
93
  NftId productNftId = _registry.getNftId(msg.sender);
84
94
  require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
85
- IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
95
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
96
+ productNftId
97
+ );
86
98
  require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
87
99
 
88
- IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
100
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
101
+ productInfo.parentNftId
102
+ );
89
103
  require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
90
104
  require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
91
105
 
@@ -101,8 +115,12 @@ contract ProductService is RegistryLinked, IProductService {
101
115
  // TODO add logging
102
116
  }
103
117
 
104
- function close(NftId policyNftId) external override {}
118
+ function close(
119
+ NftId policyNftId
120
+ ) external override // solhint-disable-next-line no-empty-blocks
121
+ {
105
122
 
123
+ }
106
124
  }
107
125
 
108
126
  abstract contract ProductModule is IProductModule {
@@ -12,16 +12,11 @@ import {Fee} from "../../types/Fee.sol";
12
12
  import {TokenHandler} from "./TokenHandler.sol";
13
13
 
14
14
  interface ITreasury {
15
-
16
15
  // TODO add events
17
16
  // TODO add errors
18
17
  }
19
18
 
20
- interface ITreasuryModule is
21
- IRegistryLinked,
22
- ITreasury
23
- {
24
-
19
+ interface ITreasuryModule is IRegistryLinked, ITreasury {
25
20
  struct ProductSetup {
26
21
  NftId productNftId;
27
22
  NftId distributorNftId;
@@ -47,27 +42,50 @@ interface ITreasuryModule is
47
42
  }
48
43
 
49
44
  function registerProduct(
50
- NftId productNftId,
51
- NftId distributorNftId,
52
- NftId poolNftId,
53
- IERC20 token,
54
- address wallet,
55
- Fee memory policyFee,
56
- Fee memory processingFee
57
- )
58
- external;
45
+ NftId productNftId,
46
+ NftId distributorNftId,
47
+ NftId poolNftId,
48
+ IERC20 token,
49
+ address wallet,
50
+ Fee memory policyFee,
51
+ Fee memory processingFee
52
+ ) external;
53
+
54
+ function setProductFees(
55
+ NftId productNftId,
56
+ Fee memory policyFee,
57
+ Fee memory processingFee
58
+ ) external;
59
59
 
60
60
  function registerPool(
61
- NftId poolNftId,
62
- address wallet,
63
- Fee memory stakingFee,
64
- Fee memory performanceFee
65
- )
66
- external;
61
+ NftId poolNftId,
62
+ address wallet,
63
+ Fee memory stakingFee,
64
+ Fee memory performanceFee
65
+ ) external;
67
66
 
68
- function getTokenHandler(NftId productNftId) external view returns(TokenHandler tokenHandler);
69
- function getProductSetup(NftId productNftId) external view returns(ProductSetup memory setup);
70
- function getPoolSetup(NftId poolNftId) external view returns(PoolSetup memory setup);
67
+ function setPoolFees(
68
+ NftId poolNftId,
69
+ Fee memory stakingFee,
70
+ Fee memory performanceFee
71
+ ) external;
71
72
 
72
73
  function processPremium(NftId policyNftId, NftId productNftId) external;
73
- }
74
+
75
+ function getTokenHandler(
76
+ NftId productNftId
77
+ ) external view returns (TokenHandler tokenHandler);
78
+
79
+ function getProductSetup(
80
+ NftId productNftId
81
+ ) external view returns (ProductSetup memory setup);
82
+
83
+ function getPoolSetup(
84
+ NftId poolNftId
85
+ ) external view returns (PoolSetup memory setup);
86
+
87
+ function calculateFeeAmount(
88
+ uint256 amount,
89
+ Fee memory fee
90
+ ) external pure returns (uint256 feeAmount, uint256 netAmount);
91
+ }
@@ -4,7 +4,6 @@ pragma solidity ^0.8.19;
4
4
  import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5
5
 
6
6
  contract TokenHandler {
7
-
8
7
  // TODO use oz safeTransferFrom
9
8
 
10
9
  IERC20 _token;
@@ -18,9 +17,7 @@ contract TokenHandler {
18
17
  address from,
19
18
  address to,
20
19
  uint256 amount
21
- )
22
- external
23
- // TODO add authz (only treasury)
20
+ ) external // TODO add authz (only treasury)
24
21
  {
25
22
  _token.transferFrom(from, to, amount);
26
23
  }
@@ -5,7 +5,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5
5
 
6
6
  import {NftId} from "../../types/NftId.sol";
7
7
  import {Fee, feeIsZero} from "../../types/Fee.sol";
8
- import {UFixed} from "../../types/UFixed.sol";
8
+ import {UFixed, UFixedMathLib} from "../../types/UFixed.sol";
9
9
  import {IProductComponent} from "../../components/IProduct.sol";
10
10
  import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
11
11
  import {TokenHandler} from "./TokenHandler.sol";
@@ -13,9 +13,9 @@ import {ITreasuryModule} from "./ITreasury.sol";
13
13
  import {TokenHandler} from "./TokenHandler.sol";
14
14
 
15
15
  abstract contract TreasuryModule is ITreasuryModule {
16
-
17
16
  mapping(NftId productNftId => ProductSetup setup) private _productSetup;
18
- mapping(NftId distributorNftId => DistributorSetup setup) private _distributorSetup;
17
+ mapping(NftId distributorNftId => DistributorSetup setup)
18
+ private _distributorSetup;
19
19
  mapping(NftId poolNftId => PoolSetup setup) private _poolSetup;
20
20
 
21
21
  IPolicyModule private _policyModule;
@@ -32,10 +32,7 @@ abstract contract TreasuryModule is ITreasuryModule {
32
32
  address wallet,
33
33
  Fee memory policyFee,
34
34
  Fee memory processingFee
35
- )
36
- external
37
- override
38
- // TODO add authz (only component module)
35
+ ) external override // TODO add authz (only component module)
39
36
  {
40
37
  // TODO add validation
41
38
 
@@ -56,15 +53,27 @@ abstract contract TreasuryModule is ITreasuryModule {
56
53
  // TODO add logging
57
54
  }
58
55
 
56
+ function setProductFees(
57
+ NftId productNftId,
58
+ Fee memory policyFee,
59
+ Fee memory processingFee
60
+ ) external override // TODO add authz (only component owner service)
61
+ {
62
+ // TODO add validation
63
+
64
+ ProductSetup storage setup = _productSetup[productNftId];
65
+ setup.policyFee = policyFee;
66
+ setup.processingFee = processingFee;
67
+
68
+ // TODO add logging
69
+ }
70
+
59
71
  function registerPool(
60
- NftId poolNftId,
61
- address wallet,
62
- Fee memory stakingFee,
63
- Fee memory performanceFee
64
- )
65
- external
66
- override
67
- // TODO add authz (only component module)
72
+ NftId poolNftId,
73
+ address wallet,
74
+ Fee memory stakingFee,
75
+ Fee memory performanceFee
76
+ ) external override // TODO add authz (only component module)
68
77
  {
69
78
  // TODO add validation
70
79
 
@@ -78,54 +87,82 @@ abstract contract TreasuryModule is ITreasuryModule {
78
87
  // TODO add logging
79
88
  }
80
89
 
81
- function getTokenHandler(NftId productNftId)
82
- external
83
- view
84
- override
85
- returns(TokenHandler tokenHandler)
90
+ function setPoolFees(
91
+ NftId poolNftId,
92
+ Fee memory stakingFee,
93
+ Fee memory performanceFee
94
+ ) external override // TODO add authz (only component owner service)
86
95
  {
96
+ // TODO add validation
97
+
98
+ PoolSetup storage setup = _poolSetup[poolNftId];
99
+ setup.stakingFee = stakingFee;
100
+ setup.performanceFee = performanceFee;
101
+
102
+ // TODO add logging
103
+ }
104
+
105
+ function getTokenHandler(
106
+ NftId productNftId
107
+ ) external view override returns (TokenHandler tokenHandler) {
87
108
  return _productSetup[productNftId].tokenHandler;
88
109
  }
89
110
 
90
- function getProductSetup(NftId productNftId)
91
- external
92
- view
93
- override
94
- returns(ProductSetup memory setup)
95
- {
111
+ function getProductSetup(
112
+ NftId productNftId
113
+ ) external view override returns (ProductSetup memory setup) {
96
114
  return _productSetup[productNftId];
97
115
  }
98
116
 
99
- function getPoolSetup(NftId poolNftId)
100
- external
101
- view
102
- override
103
- returns(PoolSetup memory setup)
104
- {
117
+ function getPoolSetup(
118
+ NftId poolNftId
119
+ ) external view override returns (PoolSetup memory setup) {
105
120
  return _poolSetup[poolNftId];
106
121
  }
107
122
 
108
-
109
- function processPremium(NftId policyNftId, NftId productNftId)
110
- external
111
- override
112
- // TODO add authz (only product service)
123
+ function processPremium(
124
+ NftId policyNftId,
125
+ NftId productNftId
126
+ ) external override // TODO add authz (only product service)
113
127
  {
114
- IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(policyNftId);
115
- require(policyInfo.nftId == policyNftId, "ERROR:TRS-020:POLICY_UNKNOWN");
128
+ IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(
129
+ policyNftId
130
+ );
131
+ require(
132
+ policyInfo.nftId == policyNftId,
133
+ "ERROR:TRS-020:POLICY_UNKNOWN"
134
+ );
116
135
 
117
136
  ProductSetup memory product = _productSetup[productNftId];
118
-
119
137
  TokenHandler tokenHandler = product.tokenHandler;
120
138
  address policyOwner = this.getRegistry().getOwner(policyNftId);
121
139
  address poolWallet = _poolSetup[product.poolNftId].wallet;
122
140
  // TODO add validation
123
141
 
124
- if(feeIsZero(product.policyFee)) {
125
- tokenHandler.transfer(policyOwner, poolWallet, policyInfo.premiumAmount);
142
+ if (feeIsZero(product.policyFee)) {
143
+ tokenHandler.transfer(
144
+ policyOwner,
145
+ poolWallet,
146
+ policyInfo.premiumAmount
147
+ );
126
148
  } else {
127
- // TODO add fee handling
128
- tokenHandler.transfer(policyOwner, poolWallet, policyInfo.premiumAmount);
149
+ (uint256 feeAmount, uint256 netAmount) = calculateFeeAmount(
150
+ policyInfo.premiumAmount,
151
+ product.policyFee
152
+ );
153
+
154
+ tokenHandler.transfer(policyOwner, product.wallet, feeAmount);
155
+ tokenHandler.transfer(policyOwner, poolWallet, netAmount);
129
156
  }
130
157
  }
131
- }
158
+
159
+ function calculateFeeAmount(
160
+ uint256 amount,
161
+ Fee memory fee
162
+ ) public pure override returns (uint256 feeAmount, uint256 netAmount) {
163
+ UFixed fractionalAmount = UFixedMathLib.itof(amount) *
164
+ fee.fractionalFee;
165
+ feeAmount = UFixedMathLib.ftoi(fractionalAmount) + fee.fixedFee;
166
+ netAmount = amount - feeAmount;
167
+ }
168
+ }
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+
6
+ contract DIP is ERC20 {
7
+
8
+ // https://etherscan.io/token/0xc719d010b63e5bbf2c0551872cd5316ed26acd83#readContract
9
+ string public constant NAME = "Decentralized Insurance Protocol - DUMMY";
10
+ string public constant SYMBOL = "DIP";
11
+ uint8 public constant DECIMALS = 18;
12
+ uint256 public constant INITIAL_SUPPLY = 10**9 * 10**DECIMALS; // 1 Billion 1'000'000'000
13
+ // decimals == 18 (openzeppelin erc20 default)
14
+ constructor()
15
+ ERC20(NAME, SYMBOL)
16
+ {
17
+ _mint(
18
+ _msgSender(),
19
+ INITIAL_SUPPLY
20
+ );
21
+ }
22
+
23
+ function decimals() public pure override returns(uint8) {
24
+ return DECIMALS;
25
+ }
26
+ }
@@ -0,0 +1,16 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {Fee, zeroFee} from "../../contracts/types/Fee.sol";
5
+ import {Pool} from "../../contracts/components/Pool.sol";
6
+
7
+
8
+ contract TestPool is Pool {
9
+
10
+ constructor(address registry, address instance, address token)
11
+ // feeless pool (no staking fee, no performance fee)
12
+ Pool(registry, instance, token, zeroFee(), zeroFee())
13
+ // solhint-disable-next-line no-empty-blocks
14
+ {}
15
+
16
+ }