@etherisc/gif-next 0.0.2-f30e0eb-805 → 0.0.2-f398177-971
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +6 -83
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/Component.json +47 -6
- package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
- package/artifacts/contracts/components/Distribution.sol/Distribution.json +70 -13
- package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IComponent.sol/IComponent.json +137 -6
- package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +144 -13
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +161 -20
- package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +151 -20
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +71 -20
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +62 -21
- package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
- package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +2 -2
- package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +310 -2004
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +101 -52
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +425 -2757
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +95 -58
- package/artifacts/contracts/instance/InstanceAuthorizationsLib.sol/InstanceAuthorizationsLib.dbg.json +4 -0
- package/artifacts/contracts/instance/InstanceAuthorizationsLib.sol/InstanceAuthorizationsLib.json +124 -0
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +348 -58
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +153 -207
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +38 -83
- package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +4 -0
- package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +2788 -0
- package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
- package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +2 -2
- package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +113 -34
- package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +8 -8
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +6 -6
- package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +6 -6
- package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
- package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
- package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +186 -236
- package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +38 -55
- package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +377 -182
- package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +74 -39
- package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +713 -83
- package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +147 -32
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +266 -442
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +82 -107
- package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +111 -174
- package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +233 -128
- package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +385 -51
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +109 -282
- package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +210 -99
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +682 -33
- package/artifacts/contracts/instance/service/IPricingService.sol/IPricingService.dbg.json +4 -0
- package/artifacts/contracts/instance/service/IPricingService.sol/IPricingService.json +510 -0
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +85 -27
- package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +420 -160
- package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +104 -53
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +880 -82
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +90 -39
- package/artifacts/contracts/instance/service/PricingService.sol/PricingService.dbg.json +4 -0
- package/artifacts/contracts/instance/service/PricingService.sol/PricingService.json +1004 -0
- package/artifacts/contracts/instance/service/PricingServiceManager.sol/PricingServiceManager.dbg.json +4 -0
- package/artifacts/contracts/instance/service/PricingServiceManager.sol/PricingServiceManager.json +688 -0
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +144 -57
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +28 -37
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +5 -37
- package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.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/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +22 -49
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +21 -34
- package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
- package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +23 -11
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +10 -23
- package/artifacts/contracts/shared/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
- package/artifacts/contracts/{instance → shared}/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +3 -3
- package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
- package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +0 -13
- package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
- package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.json +69 -9
- package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +0 -13
- package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.json +0 -13
- package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
- package/artifacts/contracts/shared/IService.sol/IService.json +85 -27
- package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
- package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +6 -19
- package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
- package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +80 -26
- package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
- package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +14 -27
- package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/shared/Registerable.sol/Registerable.json +6 -19
- package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -15
- package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
- package/artifacts/contracts/shared/Service.sol/Service.json +91 -28
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +24 -6
- package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
- package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
- package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
- package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +6 -19
- package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
- package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
- package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.json +106 -39
- package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
- package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
- package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
- package/artifacts/contracts/types/Amount.sol/AmountLib.dbg.json +4 -0
- package/artifacts/contracts/types/Amount.sol/AmountLib.json +281 -0
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.json +83 -4
- package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
- package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
- package/artifacts/contracts/types/Fee.sol/FeeLib.json +74 -19
- package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
- package/artifacts/contracts/types/Key32.sol/Key32Lib.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/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
- package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
- package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
- package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.json +116 -7
- package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
- package/artifacts/contracts/types/Referral.sol/ReferralLib.json +2 -2
- package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
- package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
- package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +1 -1
- package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +17 -4
- package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
- package/contracts/components/Component.sol +25 -4
- package/contracts/components/Distribution.sol +11 -6
- package/contracts/components/IComponent.sol +19 -3
- package/contracts/components/IPoolComponent.sol +8 -7
- package/contracts/components/IProductComponent.sol +5 -4
- package/contracts/components/Pool.sol +17 -14
- package/contracts/components/Product.sol +144 -62
- package/contracts/instance/BundleManager.sol +3 -4
- package/contracts/instance/IInstance.sol +32 -53
- package/contracts/instance/IInstanceService.sol +15 -14
- package/contracts/instance/Instance.sol +107 -205
- package/contracts/instance/InstanceAccessManager.sol +44 -25
- package/contracts/instance/InstanceAuthorizationsLib.sol +308 -0
- package/contracts/instance/InstanceReader.sol +85 -7
- package/contracts/instance/InstanceService.sol +102 -289
- package/contracts/instance/InstanceStore.sol +212 -0
- package/contracts/instance/ObjectManager.sol +1 -1
- package/contracts/instance/base/ComponentService.sol +53 -39
- package/contracts/instance/base/KeyValueStore.sol +8 -34
- package/contracts/instance/base/Lifecycle.sol +15 -4
- package/contracts/instance/module/IAccess.sol +2 -2
- package/contracts/instance/module/IBundle.sol +6 -4
- package/contracts/instance/module/IComponents.sol +7 -1
- package/contracts/instance/module/IDistribution.sol +3 -2
- package/contracts/instance/module/IPolicy.sol +13 -8
- package/contracts/instance/service/ApplicationService.sol +62 -226
- package/contracts/instance/service/BundleService.sol +172 -126
- package/contracts/instance/service/ClaimService.sol +318 -32
- package/contracts/instance/service/DistributionService.sol +71 -190
- package/contracts/instance/service/IApplicationService.sol +8 -28
- package/contracts/instance/service/IBundleService.sol +82 -26
- package/contracts/instance/service/IClaimService.sol +52 -23
- package/contracts/instance/service/IDistributionService.sol +11 -22
- package/contracts/instance/service/IPolicyService.sol +24 -16
- package/contracts/instance/service/IPoolService.sol +82 -3
- package/contracts/instance/service/IPricingService.sol +37 -0
- package/contracts/instance/service/PolicyService.sol +152 -179
- package/contracts/instance/service/PoolService.sol +239 -56
- package/contracts/instance/service/PricingService.sol +275 -0
- package/contracts/instance/service/PricingServiceManager.sol +51 -0
- package/contracts/instance/service/ProductService.sol +27 -58
- package/contracts/registry/IRegistryService.sol +2 -3
- package/contracts/registry/RegistryService.sol +24 -21
- package/contracts/registry/ReleaseManager.sol +20 -18
- package/contracts/shared/IPolicyHolder.sol +23 -9
- package/contracts/shared/IRegistryLinked.sol +0 -1
- package/contracts/shared/IService.sol +6 -6
- package/contracts/shared/NftOwnable.sol +0 -2
- package/contracts/shared/PolicyHolder.sol +30 -17
- package/contracts/shared/Registerable.sol +10 -9
- package/contracts/shared/RegistryLinked.sol +0 -5
- package/contracts/shared/Service.sol +21 -7
- package/contracts/shared/TokenHandler.sol +4 -2
- package/contracts/test/TestService.sol +1 -1
- package/contracts/types/Amount.sol +109 -0
- package/contracts/types/ClaimId.sol +25 -2
- package/contracts/types/Fee.sol +16 -8
- package/contracts/types/ObjectType.sol +9 -5
- package/contracts/types/PayoutId.sol +33 -5
- package/contracts/types/StateId.sol +6 -2
- package/contracts/types/Timestamp.sol +5 -0
- package/package.json +1 -1
- package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +0 -4
- /package/contracts/{instance → shared}/AccessManagerUpgradeableInitializeable.sol +0 -0
@@ -13,6 +13,7 @@ import {IVersionable} from "../../shared/IVersionable.sol";
|
|
13
13
|
import {Versionable} from "../../shared/Versionable.sol";
|
14
14
|
import {INftOwnable} from "../../shared/INftOwnable.sol";
|
15
15
|
|
16
|
+
import {Amount, AmountLib} from "../../types/Amount.sol";
|
16
17
|
import {Fee, FeeLib} from "../../types/Fee.sol";
|
17
18
|
import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
|
18
19
|
import {ObjectType, POOL, BUNDLE} from "../../types/ObjectType.sol";
|
@@ -20,6 +21,7 @@ import {PUBLIC_ROLE, POOL_OWNER_ROLE, POLICY_SERVICE_ROLE, RoleId} from "../../t
|
|
20
21
|
import {Fee, FeeLib} from "../../types/Fee.sol";
|
21
22
|
import {Version, VersionLib} from "../../types/Version.sol";
|
22
23
|
import {KEEP_STATE, StateId} from "../../types/StateId.sol";
|
24
|
+
import {Seconds} from "../../types/Seconds.sol";
|
23
25
|
import {TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
|
24
26
|
import {Version, VersionLib} from "../../types/Version.sol";
|
25
27
|
|
@@ -27,6 +29,7 @@ import {IService} from "../../shared/IService.sol";
|
|
27
29
|
import {Service} from "../../shared/Service.sol";
|
28
30
|
import {BundleManager} from "../BundleManager.sol";
|
29
31
|
import {ComponentService} from "../base/ComponentService.sol";
|
32
|
+
import {IBundleService} from "./IBundleService.sol";
|
30
33
|
import {IPoolService} from "./IPoolService.sol";
|
31
34
|
import {IRegistryService} from "../../registry/IRegistryService.sol";
|
32
35
|
import {InstanceService} from "../InstanceService.sol";
|
@@ -41,8 +44,9 @@ contract PoolService is
|
|
41
44
|
IPoolService
|
42
45
|
{
|
43
46
|
using NftIdLib for NftId;
|
47
|
+
using AmountLib for Amount;
|
44
48
|
|
45
|
-
|
49
|
+
IBundleService internal _bundleService;
|
46
50
|
|
47
51
|
function _initialize(
|
48
52
|
address owner,
|
@@ -57,54 +61,17 @@ contract PoolService is
|
|
57
61
|
(registryAddress, initialOwner) = abi.decode(data, (address, address));
|
58
62
|
// TODO while PoolService is not deployed in PoolServiceManager constructor
|
59
63
|
// owner is PoolServiceManager deployer
|
60
|
-
initializeService(registryAddress, owner);
|
64
|
+
initializeService(registryAddress, address(0), owner);
|
65
|
+
|
66
|
+
_bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), getVersion().toMajorPart()));
|
67
|
+
|
61
68
|
registerInterface(type(IPoolService).interfaceId);
|
62
69
|
}
|
63
70
|
|
64
|
-
function getDomain() public pure override
|
71
|
+
function getDomain() public pure override returns(ObjectType) {
|
65
72
|
return POOL();
|
66
73
|
}
|
67
74
|
|
68
|
-
/*function register(address poolAddress)
|
69
|
-
external
|
70
|
-
returns(NftId poolNftId)
|
71
|
-
{
|
72
|
-
(
|
73
|
-
IComponent component,
|
74
|
-
address owner,
|
75
|
-
IInstance instance,
|
76
|
-
NftId instanceNftId
|
77
|
-
) = _checkComponentForRegistration(
|
78
|
-
poolAddress,
|
79
|
-
POOL(),
|
80
|
-
POOL_OWNER_ROLE());
|
81
|
-
|
82
|
-
IPoolComponent pool = IPoolComponent(poolAddress);
|
83
|
-
IRegistry.ObjectInfo memory registryInfo = getRegistryService().registerPool(pool, owner);
|
84
|
-
pool.linkToRegisteredNftId();
|
85
|
-
poolNftId = registryInfo.nftId;
|
86
|
-
|
87
|
-
instance.createPoolSetup(poolNftId, pool.getSetupInfo());
|
88
|
-
|
89
|
-
bytes4[][] memory selectors = new bytes4[][](2);
|
90
|
-
selectors[0] = new bytes4[](1);
|
91
|
-
selectors[1] = new bytes4[](1);
|
92
|
-
|
93
|
-
selectors[0][0] = IPoolComponent.setFees.selector;
|
94
|
-
selectors[1][0] = IPoolComponent.verifyApplication.selector;
|
95
|
-
|
96
|
-
RoleId[] memory roles = new RoleId[](2);
|
97
|
-
roles[0] = POOL_OWNER_ROLE();
|
98
|
-
roles[1] = POLICY_SERVICE_ROLE();
|
99
|
-
|
100
|
-
getInstanceService().createGifTarget(
|
101
|
-
instanceNftId,
|
102
|
-
poolAddress,
|
103
|
-
pool.getName(),
|
104
|
-
selectors,
|
105
|
-
roles);
|
106
|
-
}*/
|
107
|
-
|
108
75
|
function register(address poolAddress)
|
109
76
|
external
|
110
77
|
returns(NftId poolNftId)
|
@@ -129,7 +96,7 @@ contract PoolService is
|
|
129
96
|
componentInfo.tokenHandler = new TokenHandler(address(componentInfo.token));
|
130
97
|
|
131
98
|
// save amended component info with instance
|
132
|
-
instance.createPoolSetup(poolNftId, componentInfo);
|
99
|
+
instance.getInstanceStore().createPoolSetup(poolNftId, componentInfo);
|
133
100
|
|
134
101
|
bytes4[][] memory selectors = new bytes4[][](2);
|
135
102
|
selectors[0] = new bytes4[](1);
|
@@ -151,21 +118,20 @@ contract PoolService is
|
|
151
118
|
}
|
152
119
|
|
153
120
|
|
154
|
-
function setMaxCapitalAmount(
|
121
|
+
function setMaxCapitalAmount(Amount maxCapitalAmount)
|
155
122
|
external
|
156
123
|
virtual
|
157
124
|
{
|
158
|
-
(
|
125
|
+
(NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
|
159
126
|
InstanceReader instanceReader = instance.getInstanceReader();
|
160
|
-
NftId poolNftId = registryInfo.nftId;
|
161
127
|
|
162
128
|
IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
|
163
129
|
IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
|
164
|
-
|
130
|
+
Amount previousMaxCapitalAmount = poolInfo.maxCapitalAmount;
|
165
131
|
|
166
132
|
poolInfo.maxCapitalAmount = maxCapitalAmount;
|
167
133
|
componentInfo.data = abi.encode(poolInfo);
|
168
|
-
instance.updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
|
134
|
+
instance.getInstanceStore().updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
|
169
135
|
|
170
136
|
emit LogPoolServiceMaxCapitalAmountUpdated(poolNftId, previousMaxCapitalAmount, maxCapitalAmount);
|
171
137
|
}
|
@@ -174,9 +140,8 @@ contract PoolService is
|
|
174
140
|
external
|
175
141
|
virtual
|
176
142
|
{
|
177
|
-
(
|
143
|
+
(NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
|
178
144
|
InstanceReader instanceReader = instance.getInstanceReader();
|
179
|
-
NftId poolNftId = registryInfo.nftId;
|
180
145
|
|
181
146
|
IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
|
182
147
|
IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
|
@@ -188,7 +153,7 @@ contract PoolService is
|
|
188
153
|
|
189
154
|
poolInfo.bundleOwnerRole = bundleOwnerRole;
|
190
155
|
componentInfo.data = abi.encode(poolInfo);
|
191
|
-
instance.updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
|
156
|
+
instance.getInstanceStore().updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
|
192
157
|
|
193
158
|
emit LogPoolServiceBundleOwnerRoleSet(poolNftId, bundleOwnerRole);
|
194
159
|
}
|
@@ -202,9 +167,8 @@ contract PoolService is
|
|
202
167
|
external
|
203
168
|
virtual
|
204
169
|
{
|
205
|
-
(
|
170
|
+
(NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
|
206
171
|
InstanceReader instanceReader = instance.getInstanceReader();
|
207
|
-
NftId poolNftId = registryInfo.nftId;
|
208
172
|
|
209
173
|
IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
|
210
174
|
IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
|
@@ -213,8 +177,227 @@ contract PoolService is
|
|
213
177
|
poolInfo.stakingFee = stakingFee;
|
214
178
|
poolInfo.performanceFee = performanceFee;
|
215
179
|
componentInfo.data = abi.encode(poolInfo);
|
216
|
-
instance.updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
|
180
|
+
instance.getInstanceStore().updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
|
217
181
|
|
218
182
|
// TODO add logging
|
219
183
|
}
|
220
|
-
|
184
|
+
|
185
|
+
|
186
|
+
function createBundle(
|
187
|
+
address owner, // initial bundle owner
|
188
|
+
Fee memory fee, // fees deducted from premium that go to bundle owner
|
189
|
+
Amount stakingAmount, // staking amount - staking fees result in initial bundle capital
|
190
|
+
Seconds lifetime, // initial duration for which new policies are covered
|
191
|
+
bytes calldata filter // optional use case specific criteria that define if a policy may be covered by this bundle
|
192
|
+
)
|
193
|
+
external
|
194
|
+
virtual
|
195
|
+
returns(NftId bundleNftId)
|
196
|
+
{
|
197
|
+
(NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
|
198
|
+
InstanceReader instanceReader = instance.getInstanceReader();
|
199
|
+
|
200
|
+
// pool fee book keeping
|
201
|
+
IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
|
202
|
+
Amount stakingNetAmount = _processStakingFees(componentInfo, stakingAmount);
|
203
|
+
|
204
|
+
bundleNftId = _bundleService.create(
|
205
|
+
instance,
|
206
|
+
poolNftId,
|
207
|
+
owner,
|
208
|
+
fee,
|
209
|
+
stakingNetAmount,
|
210
|
+
lifetime,
|
211
|
+
filter);
|
212
|
+
|
213
|
+
// collect tokens from bundle owner
|
214
|
+
_transferStakingAmount(componentInfo, owner, stakingAmount);
|
215
|
+
|
216
|
+
emit LogPoolServiceBundleCreated(instance.getNftId(), poolNftId, bundleNftId);
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
function closeBundle(NftId bundleNftId)
|
221
|
+
external
|
222
|
+
virtual
|
223
|
+
{
|
224
|
+
(NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
|
225
|
+
|
226
|
+
// TODO book keeping for pool collateral released outside of retention level
|
227
|
+
|
228
|
+
// releasing collateral in bundle
|
229
|
+
_bundleService.close(instance, bundleNftId);
|
230
|
+
|
231
|
+
// TODO get performance fee for pool, transfer of remaining funds + bundle fees to bundle owner
|
232
|
+
|
233
|
+
emit LogPoolServiceBundleClosed(instance.getNftId(), poolNftId, bundleNftId);
|
234
|
+
}
|
235
|
+
|
236
|
+
function processSale(
|
237
|
+
NftId bundleNftId,
|
238
|
+
IPolicy.Premium memory premium,
|
239
|
+
Amount actualAmountTransferred
|
240
|
+
)
|
241
|
+
external
|
242
|
+
virtual
|
243
|
+
{
|
244
|
+
IRegistry registry = getRegistry();
|
245
|
+
IRegistry.ObjectInfo memory bundleObjectInfo = registry.getObjectInfo(bundleNftId);
|
246
|
+
IRegistry.ObjectInfo memory poolObjectInfo = registry.getObjectInfo(bundleObjectInfo.parentNftId);
|
247
|
+
IRegistry.ObjectInfo memory instanceObjectInfo = registry.getObjectInfo(poolObjectInfo.parentNftId);
|
248
|
+
IInstance instance = IInstance(instanceObjectInfo.objectAddress);
|
249
|
+
|
250
|
+
Amount poolFeeAmount = AmountLib.toAmount(premium.poolFeeFixAmount + premium.poolFeeVarAmount);
|
251
|
+
Amount bundleFeeAmount = AmountLib.toAmount(premium.bundleFeeFixAmount + premium.bundleFeeVarAmount);
|
252
|
+
Amount expectedTransferAmount = AmountLib.toAmount(premium.netPremiumAmount) + poolFeeAmount + bundleFeeAmount;
|
253
|
+
if (!(actualAmountTransferred == expectedTransferAmount)) {
|
254
|
+
revert ErrorPoolServiceInvalidTransferAmount(expectedTransferAmount, actualAmountTransferred);
|
255
|
+
}
|
256
|
+
|
257
|
+
// update pool fee balance
|
258
|
+
if (poolFeeAmount.gtz()) {
|
259
|
+
IComponents.ComponentInfo memory poolComponentInfo = instance.getInstanceReader().getComponentInfo(poolObjectInfo.nftId);
|
260
|
+
poolComponentInfo.feeAmount = poolComponentInfo.feeAmount.add(poolFeeAmount);
|
261
|
+
instance.getInstanceStore().updatePoolSetup(poolObjectInfo.nftId, poolComponentInfo, KEEP_STATE());
|
262
|
+
}
|
263
|
+
|
264
|
+
if (bundleFeeAmount.gtz()) {
|
265
|
+
_bundleService.updateBundleFees(instance, bundleNftId, bundleFeeAmount);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
function lockCollateral(
|
270
|
+
IInstance instance,
|
271
|
+
NftId productNftId,
|
272
|
+
NftId applicationNftId,
|
273
|
+
IPolicy.PolicyInfo memory applicationInfo,
|
274
|
+
Amount premiumAmount // premium amount after product and distribution fees
|
275
|
+
)
|
276
|
+
external
|
277
|
+
virtual
|
278
|
+
// TODO add restricted and granting for policy service
|
279
|
+
{
|
280
|
+
InstanceReader instanceReader = instance.getInstanceReader();
|
281
|
+
NftId poolNftId = instanceReader.getProductSetupInfo(productNftId).poolNftId;
|
282
|
+
NftId bundleNftId = applicationInfo.bundleNftId;
|
283
|
+
|
284
|
+
// TODO move this check to application creation and don't repeat this here
|
285
|
+
// ensure that pool for bundle from application matches with pool for product of application
|
286
|
+
IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
|
287
|
+
if(bundleInfo.poolNftId != poolNftId) {
|
288
|
+
revert ErrorPoolServiceBundlePoolMismatch(bundleInfo.poolNftId, poolNftId);
|
289
|
+
}
|
290
|
+
|
291
|
+
IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
|
292
|
+
IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
|
293
|
+
|
294
|
+
// TODO add correct required collateral calculation (collateralization level mibht be != 1, retention level might be < 1)
|
295
|
+
Amount collateralAmount = applicationInfo.sumInsuredAmount;
|
296
|
+
|
297
|
+
// TODO add correct net premium calculation (pool fee might be > 0)
|
298
|
+
Amount premiumAfterPoolFeeAmount = premiumAmount;
|
299
|
+
|
300
|
+
// lock collateral amount from involvedd bundle
|
301
|
+
_bundleService.lockCollateral(
|
302
|
+
instance,
|
303
|
+
applicationNftId,
|
304
|
+
bundleNftId,
|
305
|
+
collateralAmount,
|
306
|
+
premiumAfterPoolFeeAmount);
|
307
|
+
|
308
|
+
// also verify/confirm application by pool if necessary
|
309
|
+
if(poolInfo.isVerifyingApplications) {
|
310
|
+
address poolAddress = getRegistry().getObjectInfo(poolNftId).objectAddress;
|
311
|
+
IPoolComponent(poolAddress).verifyApplication(
|
312
|
+
applicationNftId,
|
313
|
+
applicationInfo.applicationData,
|
314
|
+
bundleNftId,
|
315
|
+
bundleInfo.filter,
|
316
|
+
collateralAmount);
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
|
321
|
+
function reduceCollateral(
|
322
|
+
IInstance instance,
|
323
|
+
NftId policyNftId,
|
324
|
+
IPolicy.PolicyInfo memory policyInfo,
|
325
|
+
Amount payoutAmount
|
326
|
+
)
|
327
|
+
external
|
328
|
+
virtual
|
329
|
+
// TODO add restricted and granting for claim service
|
330
|
+
{
|
331
|
+
_bundleService.releaseCollateral(
|
332
|
+
instance,
|
333
|
+
policyNftId,
|
334
|
+
policyInfo.bundleNftId,
|
335
|
+
payoutAmount);
|
336
|
+
}
|
337
|
+
|
338
|
+
|
339
|
+
/// @dev releases the remaining collateral linked to the specified policy
|
340
|
+
/// may only be called by the policy service for unlocked pool components
|
341
|
+
function releaseCollateral(
|
342
|
+
IInstance instance,
|
343
|
+
NftId policyNftId,
|
344
|
+
IPolicy.PolicyInfo memory policyInfo
|
345
|
+
)
|
346
|
+
external
|
347
|
+
virtual
|
348
|
+
// TODO add restricted and granting for policy service
|
349
|
+
{
|
350
|
+
_bundleService.releaseCollateral(
|
351
|
+
instance,
|
352
|
+
policyNftId,
|
353
|
+
policyInfo.bundleNftId,
|
354
|
+
policyInfo.sumInsuredAmount - policyInfo.claimAmount);
|
355
|
+
|
356
|
+
_bundleService.unlinkPolicy(
|
357
|
+
instance,
|
358
|
+
policyNftId);
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
function _processStakingFees(
|
363
|
+
IComponents.ComponentInfo memory componentInfo,
|
364
|
+
Amount stakingAmount
|
365
|
+
)
|
366
|
+
internal
|
367
|
+
returns (Amount stakingNetAmount)
|
368
|
+
{
|
369
|
+
stakingNetAmount = stakingAmount;
|
370
|
+
|
371
|
+
// check if any staking fees apply
|
372
|
+
Fee memory stakingFee = abi.decode(componentInfo.data, (IComponents.PoolInfo)).stakingFee;
|
373
|
+
if (FeeLib.gtz(stakingFee)) {
|
374
|
+
(Amount feeAmount, Amount netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
|
375
|
+
stakingNetAmount = netAmount;
|
376
|
+
|
377
|
+
// TODO update fee balance for pool
|
378
|
+
}
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
// TODO create (I)TreasuryService that deals with all gif related token transfers
|
383
|
+
/// @dev transfers the specified amount from the bundle owner to the pool's wallet
|
384
|
+
function _transferStakingAmount(
|
385
|
+
IComponents.ComponentInfo memory componentInfo,
|
386
|
+
address bundleOwner,
|
387
|
+
Amount stakingAmount
|
388
|
+
)
|
389
|
+
internal
|
390
|
+
{
|
391
|
+
TokenHandler tokenHandler = componentInfo.tokenHandler;
|
392
|
+
address poolWallet = componentInfo.wallet;
|
393
|
+
|
394
|
+
if(stakingAmount.gtz()) {
|
395
|
+
tokenHandler.transfer(
|
396
|
+
bundleOwner,
|
397
|
+
poolWallet,
|
398
|
+
stakingAmount
|
399
|
+
);
|
400
|
+
}
|
401
|
+
}
|
402
|
+
|
403
|
+
}
|
@@ -0,0 +1,275 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {Seconds} from "../../types/Seconds.sol";
|
5
|
+
import {UFixed, UFixedLib} from "../../types/UFixed.sol";
|
6
|
+
import {ObjectType} from "../../types/ObjectType.sol";
|
7
|
+
import {NftId} from "../../types/NftId.sol";
|
8
|
+
import {Fee} from "../../types/Fee.sol";
|
9
|
+
import {ReferralId} from "../../types/Referral.sol";
|
10
|
+
import {RiskId} from "../../types/RiskId.sol";
|
11
|
+
import {PRODUCT, DISTRIBUTION, PRICE} from "../../types/ObjectType.sol";
|
12
|
+
import {Amount} from "../../types/Amount.sol";
|
13
|
+
import {IRegistry} from "../../registry/IRegistry.sol";
|
14
|
+
|
15
|
+
import {IProductComponent} from "../../components/IProductComponent.sol";
|
16
|
+
|
17
|
+
import {IInstance} from "../IInstance.sol";
|
18
|
+
import {InstanceReader} from "../InstanceReader.sol";
|
19
|
+
import {IComponents} from "../module/IComponents.sol";
|
20
|
+
import {IPolicy} from "../module/IPolicy.sol";
|
21
|
+
import {IBundle} from "../module/IBundle.sol";
|
22
|
+
import {ISetup} from "../module/ISetup.sol";
|
23
|
+
import {IDistribution} from "../module/IDistribution.sol";
|
24
|
+
|
25
|
+
import {ComponentService} from "../base/ComponentService.sol";
|
26
|
+
|
27
|
+
import {IPricingService} from "./IPricingService.sol";
|
28
|
+
import {IDistributionService} from "./IDistributionService.sol";
|
29
|
+
|
30
|
+
|
31
|
+
contract PricingService is
|
32
|
+
ComponentService,
|
33
|
+
IPricingService
|
34
|
+
{
|
35
|
+
using UFixedLib for UFixed;
|
36
|
+
|
37
|
+
IDistributionService internal _distributionService;
|
38
|
+
|
39
|
+
|
40
|
+
function _initialize(
|
41
|
+
address owner,
|
42
|
+
bytes memory data
|
43
|
+
)
|
44
|
+
internal
|
45
|
+
virtual override
|
46
|
+
initializer()
|
47
|
+
{
|
48
|
+
// TODO check this, might no longer be the way, refactor if necessary
|
49
|
+
address registryAddress;
|
50
|
+
address initialOwner;
|
51
|
+
(registryAddress, initialOwner) = abi.decode(data, (address, address));
|
52
|
+
|
53
|
+
initializeService(registryAddress, address(0), owner);
|
54
|
+
registerInterface(type(IPricingService).interfaceId);
|
55
|
+
|
56
|
+
_distributionService = IDistributionService(_getServiceAddress(DISTRIBUTION()));
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
function getDomain() public pure override returns(ObjectType) {
|
61
|
+
return PRICE();
|
62
|
+
}
|
63
|
+
|
64
|
+
/// @dev calculates the premium amount for the specified attributes
|
65
|
+
/// also returns the various fee components involved with creating a policy
|
66
|
+
function calculatePremium(
|
67
|
+
NftId productNftId,
|
68
|
+
RiskId riskId,
|
69
|
+
Amount sumInsuredAmount,
|
70
|
+
Seconds lifetime,
|
71
|
+
bytes memory applicationData,
|
72
|
+
NftId bundleNftId,
|
73
|
+
ReferralId referralId
|
74
|
+
)
|
75
|
+
external
|
76
|
+
view
|
77
|
+
virtual override
|
78
|
+
returns (
|
79
|
+
IPolicy.Premium memory premium
|
80
|
+
)
|
81
|
+
{
|
82
|
+
InstanceReader reader;
|
83
|
+
Amount netPremiumAmount;
|
84
|
+
|
85
|
+
{
|
86
|
+
// verify product
|
87
|
+
(
|
88
|
+
IRegistry.ObjectInfo memory productInfo,
|
89
|
+
IInstance instance
|
90
|
+
) = _getAndVerifyComponentInfoAndInstance(productNftId, PRODUCT());
|
91
|
+
|
92
|
+
reader = instance.getInstanceReader();
|
93
|
+
|
94
|
+
// calculate net premium
|
95
|
+
netPremiumAmount = IProductComponent(productInfo.objectAddress).calculateNetPremium(
|
96
|
+
sumInsuredAmount,
|
97
|
+
riskId,
|
98
|
+
lifetime,
|
99
|
+
applicationData
|
100
|
+
);
|
101
|
+
}
|
102
|
+
|
103
|
+
{
|
104
|
+
// get configurations for all involed objects
|
105
|
+
ISetup.ProductSetupInfo memory productSetup = reader.getProductSetupInfo(productNftId);
|
106
|
+
|
107
|
+
bytes memory componentData = reader.getComponentInfo(productSetup.poolNftId).data;
|
108
|
+
IComponents.PoolInfo memory poolInfo = abi.decode(componentData, (IComponents.PoolInfo));
|
109
|
+
|
110
|
+
IBundle.BundleInfo memory bundleInfo = reader.getBundleInfo(bundleNftId);
|
111
|
+
if(bundleInfo.poolNftId != productSetup.poolNftId) {
|
112
|
+
revert ErrorIPricingServiceBundlePoolMismatch(bundleNftId, bundleInfo.poolNftId, productSetup.poolNftId);
|
113
|
+
}
|
114
|
+
|
115
|
+
NftId distributionNftId = productSetup.distributionNftId;
|
116
|
+
ISetup.DistributionSetupInfo memory distSetup = reader.getDistributionSetupInfo(distributionNftId);
|
117
|
+
|
118
|
+
// calculate premium, order is important
|
119
|
+
premium = _getFixedFeeAmounts(
|
120
|
+
netPremiumAmount,
|
121
|
+
productSetup,
|
122
|
+
poolInfo,
|
123
|
+
distSetup,
|
124
|
+
bundleInfo
|
125
|
+
);
|
126
|
+
|
127
|
+
premium = _calculateVariableFeeAmounts(
|
128
|
+
premium,
|
129
|
+
productSetup,
|
130
|
+
poolInfo,
|
131
|
+
distSetup,
|
132
|
+
bundleInfo
|
133
|
+
);
|
134
|
+
|
135
|
+
premium = _calculateDistributionOwnerFeeAmount(
|
136
|
+
premium,
|
137
|
+
distSetup,
|
138
|
+
referralId,
|
139
|
+
distributionNftId,
|
140
|
+
reader
|
141
|
+
);
|
142
|
+
|
143
|
+
// sanity check to validate the fee calculation
|
144
|
+
if (premium.distributionOwnerFeeFixAmount < distSetup.minDistributionOwnerFee.fixedFee) {
|
145
|
+
revert ErrorIPricingServiceFeeCalculationMismatch(
|
146
|
+
premium.distributionFeeFixAmount,
|
147
|
+
premium.distributionFeeVarAmount,
|
148
|
+
premium.distributionOwnerFeeFixAmount,
|
149
|
+
premium.distributionOwnerFeeVarAmount,
|
150
|
+
premium.commissionAmount,
|
151
|
+
premium.discountAmount
|
152
|
+
);
|
153
|
+
}
|
154
|
+
|
155
|
+
if ((premium.distributionFeeVarAmount) != (premium.discountAmount + premium.distributionOwnerFeeVarAmount + premium.commissionAmount)) {
|
156
|
+
revert ErrorIPricingServiceFeeCalculationMismatch(
|
157
|
+
premium.distributionFeeFixAmount,
|
158
|
+
premium.distributionFeeVarAmount,
|
159
|
+
premium.distributionOwnerFeeFixAmount,
|
160
|
+
premium.distributionOwnerFeeVarAmount,
|
161
|
+
premium.commissionAmount,
|
162
|
+
premium.discountAmount
|
163
|
+
);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
// internal functions
|
169
|
+
function _getFixedFeeAmounts(
|
170
|
+
Amount netPremiumAmount,
|
171
|
+
ISetup.ProductSetupInfo memory productInfo,
|
172
|
+
IComponents.PoolInfo memory poolInfo,
|
173
|
+
ISetup.DistributionSetupInfo memory distInfo,
|
174
|
+
IBundle.BundleInfo memory bundleInfo
|
175
|
+
)
|
176
|
+
internal
|
177
|
+
view
|
178
|
+
returns (
|
179
|
+
IPolicy.Premium memory premium
|
180
|
+
)
|
181
|
+
{
|
182
|
+
// initial premium amount is the net premium
|
183
|
+
premium.netPremiumAmount = netPremiumAmount.toInt();
|
184
|
+
premium.fullPremiumAmount = netPremiumAmount.toInt();
|
185
|
+
|
186
|
+
uint256 t = productInfo.productFee.fixedFee;
|
187
|
+
premium.productFeeFixAmount = t;
|
188
|
+
premium.fullPremiumAmount += t;
|
189
|
+
|
190
|
+
t = poolInfo.poolFee.fixedFee;
|
191
|
+
premium.poolFeeFixAmount = t;
|
192
|
+
premium.fullPremiumAmount += t;
|
193
|
+
|
194
|
+
t = bundleInfo.fee.fixedFee;
|
195
|
+
premium.bundleFeeFixAmount = t;
|
196
|
+
premium.fullPremiumAmount += t;
|
197
|
+
|
198
|
+
t = distInfo.distributionFee.fixedFee;
|
199
|
+
premium.distributionFeeFixAmount = t;
|
200
|
+
premium.fullPremiumAmount += t;
|
201
|
+
}
|
202
|
+
|
203
|
+
function _calculateVariableFeeAmounts(
|
204
|
+
IPolicy.Premium memory premium,
|
205
|
+
ISetup.ProductSetupInfo memory productInfo,
|
206
|
+
IComponents.PoolInfo memory poolInfo,
|
207
|
+
ISetup.DistributionSetupInfo memory distInfo,
|
208
|
+
IBundle.BundleInfo memory bundleInfo
|
209
|
+
)
|
210
|
+
internal
|
211
|
+
view
|
212
|
+
returns (
|
213
|
+
IPolicy.Premium memory intermadiatePremium
|
214
|
+
)
|
215
|
+
{
|
216
|
+
UFixed netPremiumAmount = UFixedLib.toUFixed(premium.netPremiumAmount);
|
217
|
+
|
218
|
+
uint256 t = (netPremiumAmount * productInfo.productFee.fractionalFee).toInt();
|
219
|
+
premium.productFeeVarAmount = t;
|
220
|
+
premium.fullPremiumAmount += t;
|
221
|
+
|
222
|
+
t = (netPremiumAmount * poolInfo.poolFee.fractionalFee).toInt();
|
223
|
+
premium.poolFeeVarAmount = t;
|
224
|
+
premium.fullPremiumAmount += t;
|
225
|
+
|
226
|
+
t = (netPremiumAmount * bundleInfo.fee.fractionalFee).toInt();
|
227
|
+
premium.bundleFeeVarAmount = t;
|
228
|
+
premium.fullPremiumAmount += t;
|
229
|
+
|
230
|
+
t = (netPremiumAmount * distInfo.distributionFee.fractionalFee).toInt();
|
231
|
+
premium.distributionFeeVarAmount = t;
|
232
|
+
premium.fullPremiumAmount += t;
|
233
|
+
|
234
|
+
return premium;
|
235
|
+
}
|
236
|
+
|
237
|
+
function _calculateDistributionOwnerFeeAmount(
|
238
|
+
IPolicy.Premium memory premium,
|
239
|
+
ISetup.DistributionSetupInfo memory distInfo,
|
240
|
+
ReferralId referralId,
|
241
|
+
NftId distributionNftId,
|
242
|
+
InstanceReader reader
|
243
|
+
)
|
244
|
+
internal
|
245
|
+
view
|
246
|
+
returns (IPolicy.Premium memory finalPremium)
|
247
|
+
{
|
248
|
+
// if the referral is not valid, then the distribution owner gets everything
|
249
|
+
if (! _distributionService.referralIsValid(distributionNftId, referralId)) {
|
250
|
+
premium.distributionOwnerFeeFixAmount = premium.distributionFeeFixAmount;
|
251
|
+
premium.distributionOwnerFeeVarAmount = premium.distributionFeeVarAmount;
|
252
|
+
premium.premiumAmount = premium.fullPremiumAmount;
|
253
|
+
return premium;
|
254
|
+
}
|
255
|
+
|
256
|
+
Fee memory minDistributionOwnerFee = distInfo.minDistributionOwnerFee;
|
257
|
+
|
258
|
+
// if the referral is valid, the the commission and discount are calculated based in the full premium
|
259
|
+
// the remaing amount goes to the distribution owner
|
260
|
+
{
|
261
|
+
IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
|
262
|
+
IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
|
263
|
+
IDistribution.DistributorTypeInfo memory distributorTypeInfo = reader.getDistributorTypeInfo(distributorInfo.distributorType);
|
264
|
+
|
265
|
+
uint256 commissionAmount = UFixedLib.toUFixed(premium.netPremiumAmount).mul(distributorTypeInfo.commissionPercentage).toInt();
|
266
|
+
premium.commissionAmount = commissionAmount;
|
267
|
+
premium.discountAmount = UFixedLib.toUFixed(premium.fullPremiumAmount).mul(referralInfo.discountPercentage).toInt();
|
268
|
+
premium.distributionOwnerFeeFixAmount = distInfo.minDistributionOwnerFee.fixedFee;
|
269
|
+
premium.distributionOwnerFeeVarAmount = premium.distributionFeeVarAmount - commissionAmount - premium.discountAmount;
|
270
|
+
premium.premiumAmount = premium.fullPremiumAmount - premium.discountAmount;
|
271
|
+
}
|
272
|
+
|
273
|
+
return premium;
|
274
|
+
}
|
275
|
+
}
|