@etherisc/gif-next 0.0.2-d64ea51-772 → 0.0.2-d8b116d-201

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. package/README.md +43 -0
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +2 -2
  5. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +2 -2
  9. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +16 -11
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +13 -8
  14. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
  15. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
  16. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  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/ISM.sol/ISM.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  34. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +1 -1
  35. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +1 -1
  36. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  37. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +750 -0
  38. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  39. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.json +185 -0
  40. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
  41. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  42. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +20 -0
  43. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  44. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/Instance.sol/Instance.json +52 -32
  46. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  47. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +2 -2
  48. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  49. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +38 -28
  50. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  51. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +2 -2
  52. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  53. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +2 -2
  54. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  55. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +272 -0
  56. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  57. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  58. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  59. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  60. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  61. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  62. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  63. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  64. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  65. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  66. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  67. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  68. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  69. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  70. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +2 -2
  71. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  72. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +2 -2
  73. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  74. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +2 -2
  75. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  76. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  78. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +21 -0
  79. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  80. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +59 -14
  82. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +20 -8
  84. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +24 -24
  86. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +13 -13
  88. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  89. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  90. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  91. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  92. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  93. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  94. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
  95. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  96. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
  97. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  98. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  99. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  100. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  101. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  102. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  103. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  104. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  105. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  106. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  107. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  108. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  109. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  110. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  111. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  112. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  113. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  114. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  115. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  116. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  117. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  118. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  119. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  120. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  121. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  122. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  123. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  124. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  125. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  126. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  127. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  128. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  129. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  130. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  131. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  132. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  133. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  134. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  135. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  136. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  137. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  138. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  139. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  140. package/contracts/components/IPoolComponent.sol +1 -1
  141. package/contracts/components/Pool.sol +7 -6
  142. package/contracts/components/Product.sol +1 -0
  143. package/contracts/instance/BundleManager.sol +143 -0
  144. package/contracts/instance/Cloneable.sol +47 -0
  145. package/contracts/instance/InstanceService.sol +3 -0
  146. package/contracts/instance/ObjectManager.sol +95 -0
  147. package/contracts/instance/module/ISetup.sol +2 -1
  148. package/contracts/instance/service/IPoolService.sol +2 -0
  149. package/contracts/instance/service/PoolService.sol +15 -12
  150. package/contracts/instance/service/ProductService.sol +2 -4
  151. package/contracts/types/NftIdSet.sol +26 -24
  152. package/package.json +1 -1
@@ -5,7 +5,6 @@ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IER
5
5
 
6
6
  import {Fee} from "../../types/Fee.sol";
7
7
  import {NftId} from "../../types/NftId.sol";
8
- import {LibNftIdSet} from "../../types/NftIdSet.sol";
9
8
  import {UFixed} from "../../types/UFixed.sol";
10
9
  import {TokenHandler} from "../../shared/TokenHandler.sol";
11
10
 
@@ -21,6 +20,7 @@ interface ISetup {
21
20
  Fee poolFee; // pool fee on net premium
22
21
  Fee stakingFee; // pool fee on staked capital from investor
23
22
  Fee performanceFee; // pool fee on profits from capital investors
23
+ bool isIntercepting; // intercepts nft transfers (for products)
24
24
  address wallet;
25
25
  }
26
26
 
@@ -40,6 +40,7 @@ interface ISetup {
40
40
  Fee stakingFee; // pool fee on staked capital from investor
41
41
  Fee performanceFee; // pool fee on profits from capital investors
42
42
  bool isIntercepting; // intercepts nft transfers (for bundles)
43
+ bool isConfirmingApplication; // confirms applications before they are underwritten
43
44
  address wallet;
44
45
  }
45
46
  }
@@ -8,6 +8,8 @@ import {IService} from "../../shared/IService.sol";
8
8
  import {IBundle} from "../module/IBundle.sol";
9
9
 
10
10
  interface IPoolService is IService {
11
+ error ErrorIPoolServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
12
+
11
13
  function setFees(
12
14
  Fee memory poolFee,
13
15
  Fee memory stakingFee,
@@ -28,7 +28,6 @@ import {IRegistryService} from "../../registry/IRegistryService.sol";
28
28
  import {InstanceService} from "../InstanceService.sol";
29
29
  import {InstanceReader} from "../InstanceReader.sol";
30
30
 
31
-
32
31
  string constant POOL_SERVICE_NAME = "PoolService";
33
32
 
34
33
  contract PoolService is
@@ -136,13 +135,11 @@ contract PoolService is
136
135
 
137
136
  // TODO add bundle to pool in instance
138
137
 
139
- // TODO collect capital
140
- // _processStakingByTreasury(
141
- // instanceReader,
142
- // zeroNftId(),
143
- // poolNftId,
144
- // bundleNftId,
145
- // stakingAmount);
138
+ _processStakingByTreasury(
139
+ instanceReader,
140
+ poolNftId,
141
+ bundleNftId,
142
+ stakingAmount);
146
143
 
147
144
  // TODO add logging
148
145
  }
@@ -178,7 +175,6 @@ contract PoolService is
178
175
 
179
176
  function _processStakingByTreasury(
180
177
  InstanceReader instanceReader,
181
- NftId productNftId,
182
178
  NftId poolNftId,
183
179
  NftId bundleNftId,
184
180
  uint256 stakingAmount
@@ -187,15 +183,22 @@ contract PoolService is
187
183
  {
188
184
  // process token transfer(s)
189
185
  if(stakingAmount > 0) {
190
- TokenHandler tokenHandler = TokenHandler(instanceReader.getTokenHandler(productNftId));
191
- address bundleOwner = getRegistry().ownerOf(bundleNftId);
192
186
  ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
193
-
187
+ TokenHandler tokenHandler = poolInfo.tokenHandler;
188
+ address bundleOwner = getRegistry().ownerOf(bundleNftId);
189
+ Fee memory stakingFee = poolInfo.stakingFee;
190
+
194
191
  tokenHandler.transfer(
195
192
  bundleOwner,
196
193
  poolInfo.wallet,
197
194
  stakingAmount
198
195
  );
196
+
197
+
198
+ if (! FeeLib.feeIsZero(stakingFee)) {
199
+ (uint256 stakingFeeAmount, uint256 netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
200
+ // TODO: track staking fees in pool's state (issue #177)
201
+ }
199
202
  }
200
203
  }
201
204
  }
@@ -323,8 +323,7 @@ contract ProductService is ComponentServiceBase, IProductService {
323
323
  returns (IBundle.BundleInfo memory)
324
324
  {
325
325
  bundleInfo.lockedAmount += collateralAmount;
326
- // FIXME: this
327
- // instance.collateralizePolicy(bundleNftId, policyNftId, collateralAmount);
326
+ // TODO: track policy associated to bundle in bundlemanager (tbd) and how much is locked for it
328
327
  return bundleInfo;
329
328
  }
330
329
 
@@ -432,8 +431,7 @@ contract ProductService is ComponentServiceBase, IProductService {
432
431
  NftId poolNftId = bundleInfo.poolNftId;
433
432
  ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
434
433
 
435
- // FIXME: use poolInfo.isVerifying ???
436
- if(poolInfo.isIntercepting) {
434
+ if(poolInfo.isConfirmingApplication) {
437
435
  _underwriteByPool(
438
436
  poolNftId,
439
437
  policyNftId,
@@ -11,35 +11,37 @@ library LibNftIdSet {
11
11
  mapping(NftId nftid => uint256 index) at;
12
12
  }
13
13
 
14
- function add(Set storage set, NftId nftId) external returns(bool added) {
15
- if (set.at[nftId] == 0) {
16
- set.ids.push(nftId);
17
- set.at[nftId] = set.ids.length;
18
- return true;
19
- } else {
20
- return false;
14
+ error ErrorNftIdSetAlreadyAdded(NftId nftId);
15
+ error ErrorNftIdSetNotInSet(NftId nftId);
16
+
17
+
18
+ function add(Set storage set, NftId nftId) external {
19
+ if (set.at[nftId] > 0) {
20
+ revert ErrorNftIdSetAlreadyAdded(nftId);
21
21
  }
22
+
23
+ set.ids.push(nftId);
24
+ set.at[nftId] = set.ids.length;
22
25
  }
23
26
 
24
- function remove(Set storage set, NftId nftId) external returns(bool removed) {
27
+ function remove(Set storage set, NftId nftId) external {
25
28
  uint256 nftIdIndex = set.at[nftId];
26
29
 
27
- if (nftIdIndex > 0) {
28
- uint256 toDeleteIndex = nftIdIndex - 1;
29
- uint256 lastIndex = set.ids.length - 1;
30
-
31
- if (lastIndex != toDeleteIndex) {
32
- NftId lastId = set.ids[lastIndex];
33
- set.ids[toDeleteIndex] = lastId;
34
- set.at[lastId] = nftIdIndex; // Replace lastValue's index to valueIndex
35
- }
36
-
37
- set.ids.pop();
38
- delete set.at[nftId];
39
- return true;
40
- } else {
41
- return false;
30
+ if (nftIdIndex == 0) {
31
+ revert ErrorNftIdSetNotInSet(nftId);
42
32
  }
33
+
34
+ uint256 toDeleteIndex = nftIdIndex - 1;
35
+ uint256 lastIndex = set.ids.length - 1;
36
+
37
+ if (lastIndex != toDeleteIndex) {
38
+ NftId lastId = set.ids[lastIndex];
39
+ set.ids[toDeleteIndex] = lastId;
40
+ set.at[lastId] = nftIdIndex; // Replace lastValue's index to valueIndex
41
+ }
42
+
43
+ set.ids.pop();
44
+ delete set.at[nftId];
43
45
  }
44
46
 
45
47
  function isEmpty(Set storage set) external view returns(bool empty) {
@@ -50,7 +52,7 @@ library LibNftIdSet {
50
52
  return set.at[nftId] > 0;
51
53
  }
52
54
 
53
- function getLength(Set storage set) external view returns(uint256 length) {
55
+ function size(Set storage set) external view returns(uint256 length) {
54
56
  return set.ids.length;
55
57
  }
56
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etherisc/gif-next",
3
- "version": "0.0.2-d64ea51-772",
3
+ "version": "0.0.2-d8b116d-201",
4
4
  "description": "This is the repository for the next version of the Generic Insurance Framework (GIF) smart contracts. ",
5
5
  "main": "index.js",
6
6
  "scripts": {