@etherisc/gif-next 0.0.2-f2df3e2-873 → 0.0.2-f398177-971
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/Component.json +37 -6
- package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
- package/artifacts/contracts/components/Distribution.sol/Distribution.json +44 -13
- package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IComponent.sol/IComponent.json +37 -6
- package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +44 -13
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +55 -24
- package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +52 -21
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +55 -24
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +52 -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 +252 -2210
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +21 -38
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +346 -2685
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +67 -49
- 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 +219 -53
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +59 -220
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +32 -117
- 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 +37 -13
- 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 +2 -2
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +2 -2
- package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
- 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 +75 -217
- package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +33 -66
- package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +155 -133
- package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +35 -64
- package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +463 -119
- package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +109 -42
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +181 -399
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +81 -94
- package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +11 -145
- package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +79 -30
- package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +229 -88
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +23 -273
- package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +40 -326
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +265 -32
- 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 +5 -13
- package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +213 -443
- package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +74 -75
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +439 -54
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +84 -37
- 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 +55 -31
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +22 -35
- 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 -13
- 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 +17 -25
- 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 +2 -2
- 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 +5 -13
- 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 +5 -13
- 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 +17 -25
- 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 +1 -1
- package/artifacts/contracts/types/Amount.sol/AmountLib.json +100 -4
- 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 +2 -2
- 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 +42 -18
- 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 +2 -2
- 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/Timestamp.sol/TimestampLib.dbg.json +1 -1
- 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 +21 -2
- package/contracts/components/Distribution.sol +5 -4
- package/contracts/components/IComponent.sol +16 -2
- package/contracts/components/IPoolComponent.sol +7 -6
- package/contracts/components/IProductComponent.sol +5 -4
- package/contracts/components/Pool.sol +8 -8
- package/contracts/components/Product.sol +21 -17
- package/contracts/instance/IInstance.sol +28 -53
- package/contracts/instance/IInstanceService.sol +15 -10
- package/contracts/instance/Instance.sol +90 -171
- package/contracts/instance/InstanceAccessManager.sol +35 -21
- package/contracts/instance/InstanceAuthorizationsLib.sol +308 -0
- package/contracts/instance/InstanceReader.sol +56 -5
- package/contracts/instance/InstanceService.sol +96 -266
- package/contracts/instance/InstanceStore.sol +212 -0
- package/contracts/instance/ObjectManager.sol +1 -1
- package/contracts/instance/base/ComponentService.sol +47 -20
- package/contracts/instance/base/KeyValueStore.sol +0 -31
- package/contracts/instance/base/Lifecycle.sol +7 -4
- package/contracts/instance/module/IComponents.sol +3 -3
- package/contracts/instance/module/IDistribution.sol +3 -2
- package/contracts/instance/module/IPolicy.sol +5 -5
- package/contracts/instance/service/ApplicationService.sol +58 -227
- package/contracts/instance/service/BundleService.sol +65 -119
- package/contracts/instance/service/ClaimService.sol +232 -34
- package/contracts/instance/service/DistributionService.sol +51 -134
- package/contracts/instance/service/IApplicationService.sol +5 -21
- package/contracts/instance/service/IBundleService.sol +32 -10
- package/contracts/instance/service/IClaimService.sol +37 -39
- package/contracts/instance/service/IDistributionService.sol +10 -22
- package/contracts/instance/service/IPolicyService.sol +15 -72
- package/contracts/instance/service/IPoolService.sol +18 -3
- package/contracts/instance/service/IPricingService.sol +37 -0
- package/contracts/instance/service/PolicyService.sol +112 -277
- package/contracts/instance/service/PoolService.sol +121 -21
- package/contracts/instance/service/PricingService.sol +275 -0
- package/contracts/instance/service/PricingServiceManager.sol +51 -0
- package/contracts/instance/service/ProductService.sol +10 -10
- package/contracts/registry/IRegistryService.sol +0 -2
- package/contracts/registry/RegistryService.sol +14 -10
- package/contracts/shared/IPolicyHolder.sol +23 -9
- package/contracts/shared/IRegistryLinked.sol +0 -1
- package/contracts/shared/IService.sol +2 -0
- 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/TokenHandler.sol +4 -2
- package/contracts/types/Amount.sol +44 -0
- package/contracts/types/Fee.sol +7 -6
- package/contracts/types/ObjectType.sol +5 -1
- package/package.json +1 -1
- package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +0 -4
- /package/contracts/{instance → shared}/AccessManagerUpgradeableInitializeable.sol +0 -0
| @@ -18,7 +18,7 @@ import {Amount, AmountLib} from "../../types/Amount.sol"; | |
| 18 18 | 
             
            import {ClaimId, ClaimIdLib} from "../../types/ClaimId.sol";
         | 
| 19 19 | 
             
            import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
         | 
| 20 20 | 
             
            import {UFixed, UFixedLib} from "../../types/UFixed.sol";
         | 
| 21 | 
            -
            import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE, CLAIM} from "../../types/ObjectType.sol";
         | 
| 21 | 
            +
            import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE, CLAIM, PRICE} from "../../types/ObjectType.sol";
         | 
| 22 22 | 
             
            import {APPLIED, COLLATERALIZED, ACTIVE, KEEP_STATE, CLOSED, DECLINED, CONFIRMED} from "../../types/StateId.sol";
         | 
| 23 23 | 
             
            import {NftId, NftIdLib} from "../../types/NftId.sol";
         | 
| 24 24 | 
             
            import {PayoutId, PayoutIdLib} from "../../types/PayoutId.sol";
         | 
| @@ -33,10 +33,10 @@ import {IDistributionService} from "./IDistributionService.sol"; | |
| 33 33 | 
             
            import {InstanceReader} from "../InstanceReader.sol";
         | 
| 34 34 | 
             
            import {IPolicyService} from "./IPolicyService.sol";
         | 
| 35 35 | 
             
            import {IPoolService} from "./IPoolService.sol";
         | 
| 36 | 
            +
            import {IPricingService} from "./IPricingService.sol";
         | 
| 36 37 | 
             
            import {IService} from "../../shared/IService.sol";
         | 
| 37 38 | 
             
            import {Service} from "../../shared/Service.sol";
         | 
| 38 39 |  | 
| 39 | 
            -
             | 
| 40 40 | 
             
            contract PolicyService is
         | 
| 41 41 | 
             
                ComponentService, 
         | 
| 42 42 | 
             
                IPolicyService
         | 
| @@ -49,6 +49,7 @@ contract PolicyService is | |
| 49 49 | 
             
                IClaimService internal _claimService;
         | 
| 50 50 | 
             
                IDistributionService internal _distributionService;
         | 
| 51 51 | 
             
                IPoolService internal _poolService;
         | 
| 52 | 
            +
                IPricingService internal _pricingService;
         | 
| 52 53 |  | 
| 53 54 | 
             
                event LogProductServiceSender(address sender);
         | 
| 54 55 |  | 
| @@ -72,6 +73,7 @@ contract PolicyService is | |
| 72 73 | 
             
                    _claimService = IClaimService(getRegistry().getServiceAddress(CLAIM(), majorVersion));
         | 
| 73 74 | 
             
                    _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), majorVersion));
         | 
| 74 75 | 
             
                    _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), majorVersion));
         | 
| 76 | 
            +
                    _pricingService = IPricingService(getRegistry().getServiceAddress(PRICE(), majorVersion));
         | 
| 75 77 |  | 
| 76 78 | 
             
                    registerInterface(type(IPolicyService).interfaceId);
         | 
| 77 79 | 
             
                }
         | 
| @@ -84,7 +86,7 @@ contract PolicyService is | |
| 84 86 |  | 
| 85 87 | 
             
                function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
         | 
| 86 88 | 
             
                    IRegistry.ObjectInfo memory productInfo;
         | 
| 87 | 
            -
                    (, productInfo,) =  | 
| 89 | 
            +
                    (, productInfo,) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
         | 
| 88 90 | 
             
                    product = Product(productInfo.objectAddress);
         | 
| 89 91 | 
             
                }
         | 
| 90 92 |  | 
| @@ -95,7 +97,7 @@ contract PolicyService is | |
| 95 97 | 
             
                    external
         | 
| 96 98 | 
             
                    override
         | 
| 97 99 | 
             
                {
         | 
| 98 | 
            -
                     | 
| 100 | 
            +
                    revert();
         | 
| 99 101 | 
             
                }
         | 
| 100 102 |  | 
| 101 103 |  | 
| @@ -109,15 +111,22 @@ contract PolicyService is | |
| 109 111 | 
             
                    virtual override
         | 
| 110 112 | 
             
                {
         | 
| 111 113 | 
             
                    // check caller is registered product
         | 
| 112 | 
            -
                    (NftId productNftId,, IInstance instance) =  | 
| 114 | 
            +
                    (NftId productNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
         | 
| 113 115 | 
             
                    InstanceReader instanceReader = instance.getInstanceReader();
         | 
| 114 116 |  | 
| 115 117 | 
             
                    // check policy matches with calling product
         | 
| 116 118 | 
             
                    IPolicy.PolicyInfo memory applicationInfo = instanceReader.getPolicyInfo(applicationNftId);
         | 
| 117 | 
            -
                     | 
| 119 | 
            +
                    if(applicationInfo.productNftId != productNftId) {
         | 
| 120 | 
            +
                        revert ErrorPolicyServicePolicyProductMismatch(
         | 
| 121 | 
            +
                            applicationNftId, 
         | 
| 122 | 
            +
                            applicationInfo.productNftId, 
         | 
| 123 | 
            +
                            productNftId);
         | 
| 124 | 
            +
                    }
         | 
| 118 125 |  | 
| 119 126 | 
             
                    // check policy is in state applied
         | 
| 120 | 
            -
                     | 
| 127 | 
            +
                    if (instanceReader.getPolicyState(applicationNftId) != APPLIED()) {
         | 
| 128 | 
            +
                        revert ErrorPolicyServicePolicyStateNotApplied(applicationNftId);
         | 
| 129 | 
            +
                    }
         | 
| 121 130 |  | 
| 122 131 | 
             
                    StateId newPolicyState = COLLATERALIZED();
         | 
| 123 132 |  | 
| @@ -129,7 +138,7 @@ contract PolicyService is | |
| 129 138 | 
             
                    }
         | 
| 130 139 |  | 
| 131 140 | 
             
                    // lock bundle collateral
         | 
| 132 | 
            -
                     | 
| 141 | 
            +
                    Amount netPremiumAmount = AmountLib.zero(); // > 0 if immediate premium payment 
         | 
| 133 142 |  | 
| 134 143 | 
             
                    // optional collection of premium
         | 
| 135 144 | 
             
                    if(requirePremiumPayment) {
         | 
| @@ -138,11 +147,11 @@ contract PolicyService is | |
| 138 147 | 
             
                            applicationNftId, 
         | 
| 139 148 | 
             
                            applicationInfo.premiumAmount);
         | 
| 140 149 |  | 
| 141 | 
            -
                        applicationInfo.premiumPaidAmount  | 
| 150 | 
            +
                        applicationInfo.premiumPaidAmount = applicationInfo.premiumPaidAmount + applicationInfo.premiumAmount;
         | 
| 142 151 | 
             
                    }
         | 
| 143 152 |  | 
| 144 153 | 
             
                    // store updated policy info
         | 
| 145 | 
            -
                    instance.updatePolicy(applicationNftId, applicationInfo, newPolicyState);
         | 
| 154 | 
            +
                    instance.getInstanceStore().updatePolicy(applicationNftId, applicationInfo, newPolicyState);
         | 
| 146 155 |  | 
| 147 156 | 
             
                    // lock collateral and update pool and bundle book keeping
         | 
| 148 157 | 
             
                    // pool retention level: fraction of sum insured that product will cover from pool funds directly
         | 
| @@ -160,33 +169,46 @@ contract PolicyService is | |
| 160 169 | 
             
                }
         | 
| 161 170 |  | 
| 162 171 |  | 
| 163 | 
            -
                function calculateRequiredCollateral( | 
| 164 | 
            -
                    UFixed  | 
| 165 | 
            -
                     | 
| 166 | 
            -
             | 
| 172 | 
            +
                function calculateRequiredCollateral(
         | 
| 173 | 
            +
                    UFixed collateralizationLevel, 
         | 
| 174 | 
            +
                    Amount sumInsuredAmount
         | 
| 175 | 
            +
                )
         | 
| 176 | 
            +
                    public 
         | 
| 177 | 
            +
                    pure 
         | 
| 178 | 
            +
                    virtual 
         | 
| 179 | 
            +
                    returns(Amount collateralAmount)
         | 
| 180 | 
            +
                {
         | 
| 181 | 
            +
                    UFixed collateralUFixed =  collateralizationLevel * sumInsuredAmount.toUFixed();
         | 
| 182 | 
            +
                    return AmountLib.toAmount(collateralUFixed.toInt());
         | 
| 167 183 | 
             
                } 
         | 
| 168 184 |  | 
| 169 | 
            -
                function collectPremium( | 
| 185 | 
            +
                function collectPremium(
         | 
| 186 | 
            +
                    NftId policyNftId, 
         | 
| 187 | 
            +
                    Timestamp activateAt
         | 
| 188 | 
            +
                )
         | 
| 189 | 
            +
                    external 
         | 
| 190 | 
            +
                    virtual
         | 
| 191 | 
            +
                {
         | 
| 170 192 | 
             
                    // check caller is registered product
         | 
| 171 | 
            -
                    (NftId productNftId,, IInstance instance) =  | 
| 193 | 
            +
                    (NftId productNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
         | 
| 172 194 | 
             
                    InstanceReader instanceReader = instance.getInstanceReader();
         | 
| 173 195 | 
             
                    IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
         | 
| 174 196 |  | 
| 175 197 | 
             
                    if (policyInfo.premiumPaidAmount == policyInfo.premiumAmount) {
         | 
| 176 | 
            -
                        revert  | 
| 198 | 
            +
                        revert ErrorPolicyServicePremiumAlreadyPaid(policyNftId, policyInfo.premiumPaidAmount);
         | 
| 177 199 | 
             
                    }
         | 
| 178 200 |  | 
| 179 | 
            -
                     | 
| 201 | 
            +
                    Amount unpaidPremiumAmount = policyInfo.premiumAmount - policyInfo.premiumPaidAmount;
         | 
| 180 202 |  | 
| 181 | 
            -
                     | 
| 203 | 
            +
                    Amount netPremiumAmount = _processPremiumByTreasury(
         | 
| 182 204 | 
             
                            instance, 
         | 
| 183 205 | 
             
                            policyNftId, 
         | 
| 184 206 | 
             
                            unpaidPremiumAmount);
         | 
| 185 207 |  | 
| 186 | 
            -
                    policyInfo.premiumPaidAmount  | 
| 208 | 
            +
                    policyInfo.premiumPaidAmount = policyInfo.premiumPaidAmount + unpaidPremiumAmount;
         | 
| 187 209 |  | 
| 188 210 | 
             
                    _bundleService.increaseBalance(instance, policyInfo.bundleNftId, netPremiumAmount);
         | 
| 189 | 
            -
                    instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
         | 
| 211 | 
            +
                    instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
         | 
| 190 212 |  | 
| 191 213 | 
             
                    if(activateAt.gtz() && policyInfo.activatedAt.eqz()) {
         | 
| 192 214 | 
             
                        activate(policyNftId, activateAt);
         | 
| @@ -197,7 +219,7 @@ contract PolicyService is | |
| 197 219 |  | 
| 198 220 | 
             
                function activate(NftId policyNftId, Timestamp activateAt) public override {
         | 
| 199 221 | 
             
                    // check caller is registered product
         | 
| 200 | 
            -
                    (,, IInstance instance) =  | 
| 222 | 
            +
                    (,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
         | 
| 201 223 | 
             
                    InstanceReader instanceReader = instance.getInstanceReader();
         | 
| 202 224 |  | 
| 203 225 | 
             
                    IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
         | 
| @@ -209,7 +231,7 @@ contract PolicyService is | |
| 209 231 | 
             
                    policyInfo.activatedAt = activateAt;
         | 
| 210 232 | 
             
                    policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
         | 
| 211 233 |  | 
| 212 | 
            -
                    instance.updatePolicy(policyNftId, policyInfo, ACTIVE());
         | 
| 234 | 
            +
                    instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, ACTIVE());
         | 
| 213 235 |  | 
| 214 236 | 
             
                    // TODO: add logging
         | 
| 215 237 | 
             
                }
         | 
| @@ -231,7 +253,7 @@ contract PolicyService is | |
| 231 253 | 
             
                    external 
         | 
| 232 254 | 
             
                    override
         | 
| 233 255 | 
             
                {
         | 
| 234 | 
            -
                    (,, IInstance instance) =  | 
| 256 | 
            +
                    (,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
         | 
| 235 257 | 
             
                    InstanceReader instanceReader = instance.getInstanceReader();
         | 
| 236 258 |  | 
| 237 259 | 
             
                    IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
         | 
| @@ -250,8 +272,8 @@ contract PolicyService is | |
| 250 272 | 
             
                    }
         | 
| 251 273 |  | 
| 252 274 | 
             
                    // TODO consider to allow for underpaid premiums (with the effects of reducing max payouts accordingly)
         | 
| 253 | 
            -
                    if (policyInfo.premiumAmount  | 
| 254 | 
            -
                        revert  | 
| 275 | 
            +
                    if (!(policyInfo.premiumAmount == policyInfo.premiumPaidAmount)) {
         | 
| 276 | 
            +
                        revert ErrorPolicyServicePremiumNotFullyPaid(policyNftId, policyInfo.premiumAmount, policyInfo.premiumPaidAmount);
         | 
| 255 277 | 
             
                    }
         | 
| 256 278 |  | 
| 257 279 | 
             
                    if (policyInfo.openClaimsCount > 0) {
         | 
| @@ -265,277 +287,90 @@ contract PolicyService is | |
| 265 287 | 
             
                        policyNftId, 
         | 
| 266 288 | 
             
                        policyInfo);
         | 
| 267 289 |  | 
| 268 | 
            -
                    instance.updatePolicy(policyNftId, policyInfo, CLOSED());
         | 
| 290 | 
            +
                    instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, CLOSED());
         | 
| 269 291 | 
             
                }
         | 
| 270 292 |  | 
| 271 | 
            -
             | 
| 272 | 
            -
             | 
| 273 | 
            -
                     | 
| 274 | 
            -
                     | 
| 293 | 
            +
             | 
| 294 | 
            +
                function _processPremiumByTreasury(
         | 
| 295 | 
            +
                    IInstance instance,
         | 
| 296 | 
            +
                    NftId policyNftId,
         | 
| 297 | 
            +
                    Amount premiumExpectedAmount
         | 
| 275 298 | 
             
                )
         | 
| 276 | 
            -
                     | 
| 277 | 
            -
                     | 
| 278 | 
            -
                    returns (ClaimId claimId)
         | 
| 299 | 
            +
                    internal
         | 
| 300 | 
            +
                    returns (Amount netPremiumAmount)
         | 
| 279 301 | 
             
                {
         | 
| 280 | 
            -
                    (
         | 
| 281 | 
            -
             | 
| 282 | 
            -
                         | 
| 283 | 
            -
                        IPolicy.PolicyInfo memory policyInfo
         | 
| 284 | 
            -
                    ) = _verifyCallerWithPolicy(policyNftId);
         | 
| 285 | 
            -
             | 
| 286 | 
            -
                    // check policy is in its active period
         | 
| 287 | 
            -
                    if(policyInfo.activatedAt.eqz() || TimestampLib.blockTimestamp() >= policyInfo.expiredAt) {
         | 
| 288 | 
            -
                        revert ErrorPolicyServicePolicyNotOpen(policyNftId);
         | 
| 302 | 
            +
                    // process token transfer(s)
         | 
| 303 | 
            +
                    if(premiumExpectedAmount.eqz()) {
         | 
| 304 | 
            +
                        return AmountLib.zero();
         | 
| 289 305 | 
             
                    }
         | 
| 290 306 |  | 
| 291 | 
            -
                     | 
| 292 | 
            -
                     | 
| 293 | 
            -
             | 
| 307 | 
            +
                    NftId productNftId = getRegistry().getObjectInfo(policyNftId).parentNftId;
         | 
| 308 | 
            +
                    IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
         | 
| 309 | 
            +
                    IPolicy.Premium memory premium = _pricingService.calculatePremium(
         | 
| 310 | 
            +
                        productNftId,
         | 
| 311 | 
            +
                        policyInfo.riskId,
         | 
| 312 | 
            +
                        policyInfo.sumInsuredAmount,
         | 
| 313 | 
            +
                        policyInfo.lifetime,
         | 
| 314 | 
            +
                        policyInfo.applicationData,
         | 
| 315 | 
            +
                        policyInfo.bundleNftId,
         | 
| 316 | 
            +
                        policyInfo.referralId
         | 
| 317 | 
            +
                        );
         | 
| 318 | 
            +
             | 
| 319 | 
            +
                    if (premium.premiumAmount != premiumExpectedAmount.toInt()) {
         | 
| 320 | 
            +
                        revert ErrorPolicyServicePremiumMismatch(
         | 
| 294 321 | 
             
                            policyNftId, 
         | 
| 295 | 
            -
                             | 
| 296 | 
            -
                            AmountLib.toAmount( | 
| 322 | 
            +
                            premiumExpectedAmount, 
         | 
| 323 | 
            +
                            AmountLib.toAmount(premium.premiumAmount));
         | 
| 297 324 | 
             
                    }
         | 
| 298 325 |  | 
| 299 | 
            -
                     | 
| 300 | 
            -
                     | 
| 301 | 
            -
                     | 
| 302 | 
            -
             | 
| 303 | 
            -
             | 
| 304 | 
            -
                    policyInfo.claimsCount += 1;
         | 
| 305 | 
            -
                    policyInfo.openClaimsCount += 1;
         | 
| 306 | 
            -
                    instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
         | 
| 307 | 
            -
             | 
| 308 | 
            -
                    emit LogPolicyServiceClaimSubmitted(policyNftId, claimId, claimAmount);
         | 
| 309 | 
            -
                }
         | 
| 310 | 
            -
             | 
| 311 | 
            -
                function confirmClaim(
         | 
| 312 | 
            -
                    NftId policyNftId, 
         | 
| 313 | 
            -
                    ClaimId claimId,
         | 
| 314 | 
            -
                    Amount confirmedAmount
         | 
| 315 | 
            -
                )
         | 
| 316 | 
            -
                    external
         | 
| 317 | 
            -
                {
         | 
| 318 | 
            -
                    (
         | 
| 319 | 
            -
                        IInstance instance,
         | 
| 320 | 
            -
                        InstanceReader instanceReader,
         | 
| 321 | 
            -
                        IPolicy.PolicyInfo memory policyInfo
         | 
| 322 | 
            -
                    ) = _verifyCallerWithPolicy(policyNftId);
         | 
| 323 | 
            -
             | 
| 324 | 
            -
                    // check/update claim info
         | 
| 325 | 
            -
                    _claimService.confirm(instance, instanceReader, policyNftId, claimId, confirmedAmount);
         | 
| 326 | 
            -
             | 
| 327 | 
            -
                    // update and save policy info with instance
         | 
| 328 | 
            -
                    instance.updatePolicy(policyNftId, policyInfo, CONFIRMED());
         | 
| 329 | 
            -
             | 
| 330 | 
            -
                    emit LogPolicyServiceClaimConfirmed(policyNftId, claimId, confirmedAmount);
         | 
| 331 | 
            -
                }
         | 
| 332 | 
            -
             | 
| 333 | 
            -
                function declineClaim(
         | 
| 334 | 
            -
                    NftId policyNftId, 
         | 
| 335 | 
            -
                    ClaimId claimId
         | 
| 336 | 
            -
                )
         | 
| 337 | 
            -
                    external
         | 
| 338 | 
            -
                {
         | 
| 339 | 
            -
                    (
         | 
| 340 | 
            -
                        IInstance instance,
         | 
| 341 | 
            -
                        InstanceReader instanceReader,
         | 
| 342 | 
            -
                        IPolicy.PolicyInfo memory policyInfo
         | 
| 343 | 
            -
                    ) = _verifyCallerWithPolicy(policyNftId);
         | 
| 344 | 
            -
             | 
| 345 | 
            -
                    // check/update claim info
         | 
| 346 | 
            -
                    _claimService.decline(instance, instanceReader, policyNftId, claimId);
         | 
| 347 | 
            -
             | 
| 348 | 
            -
                    // update and save policy info with instance
         | 
| 349 | 
            -
                    policyInfo.openClaimsCount -= 1;
         | 
| 350 | 
            -
                    instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
         | 
| 351 | 
            -
             | 
| 352 | 
            -
                    emit LogPolicyServiceClaimDeclined(policyNftId, claimId);
         | 
| 353 | 
            -
                }
         | 
| 354 | 
            -
             | 
| 355 | 
            -
                function closeClaim(
         | 
| 356 | 
            -
                    NftId policyNftId, 
         | 
| 357 | 
            -
                    ClaimId claimId
         | 
| 358 | 
            -
                )
         | 
| 359 | 
            -
                    external
         | 
| 360 | 
            -
                {
         | 
| 361 | 
            -
                    (
         | 
| 362 | 
            -
                        IInstance instance,
         | 
| 363 | 
            -
                        InstanceReader instanceReader,
         | 
| 364 | 
            -
                        IPolicy.PolicyInfo memory policyInfo
         | 
| 365 | 
            -
                    ) = _verifyCallerWithPolicy(policyNftId);
         | 
| 366 | 
            -
             | 
| 367 | 
            -
                    // check/update claim info
         | 
| 368 | 
            -
                    _claimService.close(instance, instanceReader, policyNftId, claimId);
         | 
| 369 | 
            -
             | 
| 370 | 
            -
                    // update and save policy info with instance
         | 
| 371 | 
            -
                    policyInfo.openClaimsCount -= 1;
         | 
| 372 | 
            -
                    instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
         | 
| 373 | 
            -
             | 
| 374 | 
            -
                    emit LogPolicyServiceClaimClosed(policyNftId, claimId);
         | 
| 375 | 
            -
                }
         | 
| 376 | 
            -
             | 
| 377 | 
            -
                function createPayout(
         | 
| 378 | 
            -
                    NftId policyNftId, 
         | 
| 379 | 
            -
                    ClaimId claimId,
         | 
| 380 | 
            -
                    Amount amount,
         | 
| 381 | 
            -
                    bytes memory data
         | 
| 382 | 
            -
                )
         | 
| 383 | 
            -
                    external
         | 
| 384 | 
            -
                    returns (PayoutId payoutId)
         | 
| 385 | 
            -
                {
         | 
| 386 | 
            -
                    (
         | 
| 387 | 
            -
                        IInstance instance,
         | 
| 388 | 
            -
                        InstanceReader instanceReader,
         | 
| 389 | 
            -
                        IPolicy.PolicyInfo memory policyInfo
         | 
| 390 | 
            -
                    ) = _verifyCallerWithPolicy(policyNftId);
         | 
| 391 | 
            -
             | 
| 392 | 
            -
                    IPolicy.ClaimInfo memory claimInfo = instanceReader.getClaimInfo(policyNftId, claimId);
         | 
| 393 | 
            -
                    StateId claimState = instanceReader.getClaimState(policyNftId, claimId);
         | 
| 394 | 
            -
             | 
| 395 | 
            -
                    // TODO add checks
         | 
| 396 | 
            -
                    // claim needs to be open
         | 
| 397 | 
            -
                    // claim.paidAmount + amount <= claim.claimAmount
         | 
| 398 | 
            -
             | 
| 399 | 
            -
                    // check/update claim info
         | 
| 400 | 
            -
                    uint8 claimNo = claimInfo.payoutsCount + 1;
         | 
| 401 | 
            -
                    payoutId = PayoutIdLib.toPayoutId(claimId, claimNo);
         | 
| 402 | 
            -
                    _claimService.createPayout(
         | 
| 403 | 
            -
                        instance, 
         | 
| 404 | 
            -
                        policyNftId, 
         | 
| 405 | 
            -
                        payoutId,
         | 
| 406 | 
            -
                        amount,
         | 
| 407 | 
            -
                        data);
         | 
| 408 | 
            -
             | 
| 409 | 
            -
                    // update and save policy info with instance
         | 
| 410 | 
            -
                    policyInfo.payoutAmount.add(amount);
         | 
| 411 | 
            -
                    instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
         | 
| 412 | 
            -
             | 
| 413 | 
            -
                    emit LogPolicyServicePayoutCreated(policyNftId, payoutId, amount);
         | 
| 414 | 
            -
                }
         | 
| 415 | 
            -
             | 
| 416 | 
            -
                function processPayout(
         | 
| 417 | 
            -
                    NftId policyNftId, 
         | 
| 418 | 
            -
                    PayoutId payoutId
         | 
| 419 | 
            -
                )
         | 
| 420 | 
            -
                    external
         | 
| 421 | 
            -
                {
         | 
| 422 | 
            -
                    (
         | 
| 423 | 
            -
                        IInstance instance,
         | 
| 424 | 
            -
                        InstanceReader instanceReader,
         | 
| 425 | 
            -
                        IPolicy.PolicyInfo memory policyInfo
         | 
| 426 | 
            -
                    ) = _verifyCallerWithPolicy(policyNftId);
         | 
| 427 | 
            -
             | 
| 428 | 
            -
                    // check/update claim info
         | 
| 429 | 
            -
                    (
         | 
| 430 | 
            -
                        Amount amount,
         | 
| 431 | 
            -
                        bool payoutIsClosingClaim
         | 
| 432 | 
            -
                    ) = _claimService.processPayout(
         | 
| 433 | 
            -
                        instance, 
         | 
| 434 | 
            -
                        instanceReader, 
         | 
| 435 | 
            -
                        policyNftId, 
         | 
| 436 | 
            -
                        payoutId);
         | 
| 437 | 
            -
             | 
| 438 | 
            -
                    // update policy info if affected by processed payout
         | 
| 439 | 
            -
                    if(payoutIsClosingClaim) {
         | 
| 440 | 
            -
                        policyInfo.openClaimsCount -= 1;
         | 
| 441 | 
            -
                        instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
         | 
| 326 | 
            +
                    address policyOwner = getRegistry().ownerOf(policyNftId);
         | 
| 327 | 
            +
                    ISetup.ProductSetupInfo memory productSetupInfo = instance.getInstanceReader().getProductSetupInfo(productNftId);
         | 
| 328 | 
            +
                    TokenHandler tokenHandler = productSetupInfo.tokenHandler;
         | 
| 329 | 
            +
                    if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premium.premiumAmount) {
         | 
| 330 | 
            +
                        revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premium.premiumAmount);
         | 
| 442 331 | 
             
                    }
         | 
| 443 332 |  | 
| 444 | 
            -
                     | 
| 445 | 
            -
             | 
| 333 | 
            +
                    Amount productFeeAmountToTransfer = AmountLib.toAmount(premium.productFeeFixAmount + premium.productFeeVarAmount);
         | 
| 334 | 
            +
                    Amount distributionFeeAmountToTransfer = AmountLib.toAmount(premium.distributionFeeFixAmount + premium.distributionFeeVarAmount - premium.discountAmount);
         | 
| 335 | 
            +
                    uint256 poolFeeAmountToTransfer = premium.poolFeeFixAmount + premium.poolFeeVarAmount;
         | 
| 336 | 
            +
                    uint256 bundleFeeAmountToTransfer = premium.bundleFeeFixAmount + premium.bundleFeeVarAmount;
         | 
| 337 | 
            +
                    Amount poolAmountToTransfer = AmountLib.toAmount(premium.netPremiumAmount + poolFeeAmountToTransfer + bundleFeeAmountToTransfer);
         | 
| 446 338 |  | 
| 447 | 
            -
             | 
| 448 | 
            -
                    NftId policyNftId
         | 
| 449 | 
            -
                )
         | 
| 450 | 
            -
                    internal
         | 
| 451 | 
            -
                    returns (
         | 
| 452 | 
            -
                        IInstance instance,
         | 
| 453 | 
            -
                        InstanceReader instanceReader,
         | 
| 454 | 
            -
                        IPolicy.PolicyInfo memory policyInfo
         | 
| 455 | 
            -
                    )
         | 
| 456 | 
            -
                {
         | 
| 457 | 
            -
                    NftId productNftId;
         | 
| 458 | 
            -
                    (productNftId,, instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
         | 
| 459 | 
            -
                    instanceReader = instance.getInstanceReader();
         | 
| 460 | 
            -
             | 
| 461 | 
            -
                    // check caller(product) policy match
         | 
| 462 | 
            -
                    policyInfo = instanceReader.getPolicyInfo(policyNftId);
         | 
| 463 | 
            -
                    if(policyInfo.productNftId != productNftId) {
         | 
| 464 | 
            -
                        revert ErrorPolicyServicePolicyProductMismatch(policyNftId, 
         | 
| 465 | 
            -
                        policyInfo.productNftId, 
         | 
| 466 | 
            -
                        productNftId);
         | 
| 467 | 
            -
                    }
         | 
| 468 | 
            -
                }
         | 
| 339 | 
            +
                    netPremiumAmount = AmountLib.toAmount(premium.netPremiumAmount);
         | 
| 469 340 |  | 
| 470 | 
            -
             | 
| 471 | 
            -
                     | 
| 472 | 
            -
                    NftId productNftId
         | 
| 473 | 
            -
                )
         | 
| 474 | 
            -
                    internal
         | 
| 475 | 
            -
                    view
         | 
| 476 | 
            -
                    returns (NftId poolNftid)
         | 
| 477 | 
            -
                {
         | 
| 478 | 
            -
                    InstanceReader instanceReader = instance.getInstanceReader();
         | 
| 479 | 
            -
                    ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
         | 
| 480 | 
            -
                    return productSetupInfo.poolNftId;
         | 
| 481 | 
            -
                }
         | 
| 482 | 
            -
             | 
| 483 | 
            -
             | 
| 484 | 
            -
                function _processPremiumByTreasury(
         | 
| 485 | 
            -
                    IInstance instance,
         | 
| 486 | 
            -
                    NftId policyNftId,
         | 
| 487 | 
            -
                    uint256 premiumExpectedAmount
         | 
| 488 | 
            -
                )
         | 
| 489 | 
            -
                    internal
         | 
| 490 | 
            -
                    returns (uint256 netPremiumAmount)
         | 
| 491 | 
            -
                {
         | 
| 492 | 
            -
                    // process token transfer(s)
         | 
| 493 | 
            -
                    if(premiumExpectedAmount > 0) {
         | 
| 494 | 
            -
                        NftId productNftId = getRegistry().getObjectInfo(policyNftId).parentNftId;
         | 
| 495 | 
            -
                        ISetup.ProductSetupInfo memory productSetupInfo = instance.getInstanceReader().getProductSetupInfo(productNftId);
         | 
| 496 | 
            -
                        IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
         | 
| 497 | 
            -
                        TokenHandler tokenHandler = productSetupInfo.tokenHandler;
         | 
| 498 | 
            -
                        address policyOwner = getRegistry().ownerOf(policyNftId);
         | 
| 499 | 
            -
                        address poolWallet = instance.getInstanceReader().getComponentInfo(productSetupInfo.poolNftId).wallet;
         | 
| 500 | 
            -
                        IPolicy.Premium memory premium = _applicationService.calculatePremium(
         | 
| 501 | 
            -
                            productNftId,
         | 
| 502 | 
            -
                            policyInfo.riskId,
         | 
| 503 | 
            -
                            policyInfo.sumInsuredAmount,
         | 
| 504 | 
            -
                            policyInfo.lifetime,
         | 
| 505 | 
            -
                            policyInfo.applicationData,
         | 
| 506 | 
            -
                            policyInfo.bundleNftId,
         | 
| 507 | 
            -
                            policyInfo.referralId
         | 
| 508 | 
            -
                            );
         | 
| 509 | 
            -
             | 
| 510 | 
            -
                        if (premium.premiumAmount != premiumExpectedAmount) {
         | 
| 511 | 
            -
                            revert ErrorIPolicyServicePremiumMismatch(
         | 
| 512 | 
            -
                                policyNftId, 
         | 
| 513 | 
            -
                                premiumExpectedAmount, 
         | 
| 514 | 
            -
                                premium.premiumAmount);
         | 
| 515 | 
            -
                        }
         | 
| 516 | 
            -
             | 
| 517 | 
            -
                        // move product fee to product wallet
         | 
| 341 | 
            +
                    // move product fee to product wallet
         | 
| 342 | 
            +
                    {
         | 
| 518 343 | 
             
                        address productWallet = productSetupInfo.wallet;
         | 
| 519 | 
            -
                         | 
| 520 | 
            -
             | 
| 521 | 
            -
                        }
         | 
| 522 | 
            -
                        tokenHandler.transfer(policyOwner, productWallet, premium.productFeeFixAmount + premium.productFeeVarAmount);
         | 
| 344 | 
            +
                        tokenHandler.transfer(policyOwner, productWallet, productFeeAmountToTransfer);
         | 
| 345 | 
            +
                    }
         | 
| 523 346 |  | 
| 524 | 
            -
             | 
| 347 | 
            +
                    // move distribution fee to distribution wallet
         | 
| 348 | 
            +
                    {
         | 
| 525 349 | 
             
                        ISetup.DistributionSetupInfo memory distributionSetupInfo = instance.getInstanceReader().getDistributionSetupInfo(productSetupInfo.distributionNftId);
         | 
| 526 350 | 
             
                        address distributionWallet = distributionSetupInfo.wallet;
         | 
| 527 | 
            -
                        uint256 distributionFeeAmountToTransfer = premium.distributionFeeFixAmount + premium.distributionFeeVarAmount - premium.discountAmount;
         | 
| 528 351 | 
             
                        tokenHandler.transfer(policyOwner, distributionWallet, distributionFeeAmountToTransfer);
         | 
| 529 352 | 
             
                        _distributionService.processSale(productSetupInfo.distributionNftId, policyInfo.referralId, premium, distributionFeeAmountToTransfer);
         | 
| 530 | 
            -
             | 
| 531 | 
            -
             | 
| 532 | 
            -
             | 
| 533 | 
            -
             | 
| 534 | 
            -
                         | 
| 535 | 
            -
                         | 
| 536 | 
            -
                         | 
| 353 | 
            +
                    }
         | 
| 354 | 
            +
                    
         | 
| 355 | 
            +
                    // move netpremium, bundleFee and poolFee to pool wallet
         | 
| 356 | 
            +
                    {
         | 
| 357 | 
            +
                        address poolWallet = instance.getInstanceReader().getComponentInfo(productSetupInfo.poolNftId).wallet;
         | 
| 358 | 
            +
                        tokenHandler.transfer(policyOwner, poolWallet, poolAmountToTransfer);
         | 
| 359 | 
            +
                        _poolService.processSale(policyInfo.bundleNftId, premium, poolAmountToTransfer);
         | 
| 360 | 
            +
                    }
         | 
| 361 | 
            +
             | 
| 362 | 
            +
                    // validate total amount transferred
         | 
| 363 | 
            +
                    {
         | 
| 364 | 
            +
                        Amount totalTransferred = distributionFeeAmountToTransfer + poolAmountToTransfer + productFeeAmountToTransfer;
         | 
| 365 | 
            +
             | 
| 366 | 
            +
                        if (premium.premiumAmount != totalTransferred.toInt()) {
         | 
| 367 | 
            +
                            revert ErrorPolicyServiceTransferredPremiumMismatch(
         | 
| 368 | 
            +
                                policyNftId, 
         | 
| 369 | 
            +
                                AmountLib.toAmount(premium.premiumAmount), 
         | 
| 370 | 
            +
                                totalTransferred);
         | 
| 371 | 
            +
                        }
         | 
| 537 372 | 
             
                    }
         | 
| 538 373 |  | 
| 539 374 | 
             
                    // TODO: add logging
         | 
| 540 375 | 
             
                }
         | 
| 541 | 
            -
            }
         | 
| 376 | 
            +
            }
         |