@etherisc/gif-next 0.0.2-f29e479-370 → 0.0.2-f30e0eb-805
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 +68 -89
- package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
- package/artifacts/contracts/components/Distribution.sol/Distribution.json +113 -140
- package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IComponent.sol/IComponent.json +65 -73
- package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +91 -122
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +256 -189
- package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +69 -145
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +279 -245
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +73 -162
- package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
- package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
- package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
- package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +64 -50
- package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
- package/artifacts/contracts/instance/Cloneable.sol/Cloneable.json +5 -0
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +171 -308
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +98 -40
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +260 -379
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +448 -121
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +120 -227
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +148 -161
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +31 -23
- package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
- package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +8 -13
- package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +1 -1
- 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 +40 -10
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +36 -11
- package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +54 -71
- package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +4 -0
- package/artifacts/contracts/instance/module/IComponents.sol/IComponents.json +10 -0
- 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 +161 -62
- package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +33 -25
- package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +137 -140
- package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +12 -12
- package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +3 -3
- package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +2 -2
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +505 -91
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +78 -42
- package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +110 -27
- package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +93 -96
- package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +350 -8
- package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +21 -64
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +81 -0
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +58 -157
- package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +19 -47
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +114 -17
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +17 -9
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +7 -7
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +4 -4
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +15 -2
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +19 -0
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
- package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +18 -0
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +31 -12
- 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 +5 -5
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +3 -3
- package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
- package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +7 -7
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
- 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/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
- 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 +2 -2
- package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
- package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
- package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
- package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
- package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/shared/Registerable.sol/Registerable.json +3 -3
- package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
- package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
- package/artifacts/contracts/shared/Service.sol/Service.json +1 -1
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
- package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
- package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
- 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 +3 -3
- package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
- package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +6 -6
- package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.json +3 -3
- 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/TestVersion.sol/TestVersion.json +2 -2
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
- 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/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
- 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/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 +2 -2
- 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 +17 -4
- 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/Referral.sol/ReferralLib.dbg.json +1 -1
- package/artifacts/contracts/types/Referral.sol/ReferralLib.json +23 -4
- 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 +4 -0
- package/artifacts/contracts/types/Seconds.sol/SecondsLib.json +124 -0
- 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 +25 -7
- package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/MathLib.json +2 -2
- package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +2 -2
- package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
- package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
- package/contracts/components/Component.sol +95 -85
- package/contracts/components/Distribution.sol +12 -19
- package/contracts/components/IComponent.sol +37 -17
- package/contracts/components/IDistributionComponent.sol +1 -22
- package/contracts/components/IPoolComponent.sol +73 -47
- package/contracts/components/IProductComponent.sol +3 -2
- package/contracts/components/Pool.sol +171 -126
- package/contracts/components/Product.sol +26 -18
- package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +13 -0
- package/contracts/instance/BundleManager.sol +7 -5
- package/contracts/instance/Cloneable.sol +7 -2
- package/contracts/instance/IInstance.sol +16 -10
- package/contracts/instance/IInstanceService.sol +18 -5
- package/contracts/instance/Instance.sol +45 -9
- package/contracts/instance/InstanceAccessManager.sol +382 -157
- package/contracts/instance/InstanceReader.sol +7 -10
- package/contracts/instance/InstanceService.sol +174 -155
- package/contracts/instance/ObjectManager.sol +6 -8
- package/contracts/instance/base/ComponentService.sol +5 -5
- package/contracts/instance/base/KeyValueStore.sol +5 -2
- package/contracts/instance/base/Lifecycle.sol +11 -2
- package/contracts/instance/module/IAccess.sol +20 -13
- package/contracts/instance/module/IBundle.sol +2 -1
- package/contracts/instance/module/IComponents.sol +35 -0
- package/contracts/instance/module/IDistribution.sol +2 -1
- package/contracts/instance/module/IPolicy.sol +26 -1
- package/contracts/instance/module/ISetup.sol +7 -22
- package/contracts/instance/service/ApplicationService.sol +123 -41
- package/contracts/instance/service/BundleService.sol +76 -38
- package/contracts/instance/service/DistributionService.sol +139 -47
- package/contracts/instance/service/IApplicationService.sol +7 -7
- package/contracts/instance/service/IBundleService.sol +19 -11
- package/contracts/instance/service/IDistributionService.sol +19 -4
- package/contracts/instance/service/IPolicyService.sol +3 -20
- package/contracts/instance/service/IPoolService.sol +17 -2
- package/contracts/instance/service/PolicyService.sol +59 -132
- package/contracts/instance/service/PoolService.sol +128 -17
- package/contracts/instance/service/ProductService.sol +10 -2
- package/contracts/registry/ChainNft.sol +8 -0
- package/contracts/registry/IRegistry.sol +2 -0
- package/contracts/registry/ITransferInterceptor.sol +1 -0
- package/contracts/registry/Registry.sol +23 -20
- package/contracts/registry/RegistryService.sol +5 -5
- package/contracts/shared/Registerable.sol +2 -2
- package/contracts/shared/TokenHandler.sol +11 -5
- package/contracts/types/Blocknumber.sol +1 -0
- package/contracts/types/Fee.sol +1 -0
- package/contracts/types/NftId.sol +8 -0
- package/contracts/types/ObjectType.sol +1 -0
- package/contracts/types/Referral.sol +4 -0
- package/contracts/types/RoleId.sol +13 -6
- package/contracts/types/Seconds.sol +54 -0
- package/contracts/types/StateId.sol +1 -0
- package/contracts/types/Timestamp.sol +13 -13
- package/contracts/types/UFixed.sol +1 -0
- package/contracts/types/Version.sol +1 -0
- package/package.json +1 -1
| @@ -1,25 +1,27 @@ | |
| 1 1 | 
             
            // SPDX-License-Identifier: Apache-2.0
         | 
| 2 2 | 
             
            pragma solidity ^0.8.19;
         | 
| 3 3 |  | 
| 4 | 
            -
            import { | 
| 4 | 
            +
            import {IBundle} from "../../instance/module/IBundle.sol";
         | 
| 5 | 
            +
            import {IComponents} from "../module/IComponents.sol";
         | 
| 5 6 | 
             
            import {IRegistry} from "../../registry/IRegistry.sol";
         | 
| 6 7 | 
             
            import {IInstance} from "../../instance/IInstance.sol";
         | 
| 7 | 
            -
            import {IBundle} from "../../instance/module/IBundle.sol";
         | 
| 8 8 | 
             
            import {TokenHandler} from "../../instance/module/ITreasury.sol";
         | 
| 9 9 | 
             
            import {ISetup} from "../module/ISetup.sol";
         | 
| 10 10 | 
             
            import {IPolicy} from "../module/IPolicy.sol";
         | 
| 11 11 |  | 
| 12 12 | 
             
            import {IVersionable} from "../../shared/IVersionable.sol";
         | 
| 13 | 
            -
            import {Versionable} from "../../shared/Versionable.sol";
         | 
| 14 13 | 
             
            import {INftOwnable} from "../../shared/INftOwnable.sol";
         | 
| 15 | 
            -
             | 
| 16 14 | 
             
            import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
         | 
| 17 15 | 
             
            import {ObjectType, POOL, BUNDLE} from "../../types/ObjectType.sol";
         | 
| 18 16 | 
             
            import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
         | 
| 17 | 
            +
            import {Pool} from "../../components/Pool.sol";
         | 
| 18 | 
            +
             | 
| 19 19 | 
             
            import {Fee, FeeLib} from "../../types/Fee.sol";
         | 
| 20 | 
            -
            import { | 
| 21 | 
            -
            import { | 
| 20 | 
            +
            import {StateId, ACTIVE, PAUSED, CLOSED, KEEP_STATE} from "../../types/StateId.sol";
         | 
| 21 | 
            +
            import {Seconds} from "../../types/Seconds.sol";
         | 
| 22 22 | 
             
            import {TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
         | 
| 23 | 
            +
            import {Version, VersionLib} from "../../types/Version.sol";
         | 
| 24 | 
            +
            import {Versionable} from "../../shared/Versionable.sol";
         | 
| 23 25 |  | 
| 24 26 | 
             
            import {IService} from "../../shared/IService.sol";
         | 
| 25 27 | 
             
            import {Service} from "../../shared/Service.sol";
         | 
| @@ -63,11 +65,11 @@ contract BundleService is | |
| 63 65 | 
             
                    return BUNDLE();
         | 
| 64 66 | 
             
                }
         | 
| 65 67 |  | 
| 66 | 
            -
                function  | 
| 68 | 
            +
                function create(
         | 
| 67 69 | 
             
                    address owner, 
         | 
| 68 70 | 
             
                    Fee memory fee, 
         | 
| 69 71 | 
             
                    uint256 stakingAmount, 
         | 
| 70 | 
            -
                     | 
| 72 | 
            +
                    Seconds lifetime, 
         | 
| 71 73 | 
             
                    bytes calldata filter
         | 
| 72 74 | 
             
                )
         | 
| 73 75 | 
             
                    external
         | 
| @@ -118,7 +120,7 @@ contract BundleService is | |
| 118 120 | 
             
                    // TODO add logging
         | 
| 119 121 | 
             
                }
         | 
| 120 122 |  | 
| 121 | 
            -
                function  | 
| 123 | 
            +
                function setFee(
         | 
| 122 124 | 
             
                    NftId bundleNftId,
         | 
| 123 125 | 
             
                    Fee memory fee
         | 
| 124 126 | 
             
                )
         | 
| @@ -138,30 +140,6 @@ contract BundleService is | |
| 138 140 | 
             
                    instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
         | 
| 139 141 | 
             
                }
         | 
| 140 142 |  | 
| 141 | 
            -
                function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state) 
         | 
| 142 | 
            -
                    external
         | 
| 143 | 
            -
                    onlyService
         | 
| 144 | 
            -
                {
         | 
| 145 | 
            -
                    IRegistry.ObjectInfo memory instanceInfo = getRegistry().getObjectInfo(instanceNftId);
         | 
| 146 | 
            -
                    IInstance instance = IInstance(instanceInfo.objectAddress);
         | 
| 147 | 
            -
                    instance.updateBundle(bundleNftId, bundleInfo, state);
         | 
| 148 | 
            -
                } 
         | 
| 149 | 
            -
             | 
| 150 | 
            -
                function lockBundle(NftId bundleNftId) 
         | 
| 151 | 
            -
                    external
         | 
| 152 | 
            -
                {
         | 
| 153 | 
            -
                    (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
         | 
| 154 | 
            -
                    BundleManager bundleManager = instance.getBundleManager();
         | 
| 155 | 
            -
                    bundleManager.lock(bundleNftId);
         | 
| 156 | 
            -
                }
         | 
| 157 | 
            -
             | 
| 158 | 
            -
                function unlockBundle(NftId bundleNftId) 
         | 
| 159 | 
            -
                    external
         | 
| 160 | 
            -
                {
         | 
| 161 | 
            -
                    (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
         | 
| 162 | 
            -
                    BundleManager bundleManager = instance.getBundleManager();
         | 
| 163 | 
            -
                    bundleManager.unlock(bundleNftId);
         | 
| 164 | 
            -
                }
         | 
| 165 143 |  | 
| 166 144 | 
             
                function lockCollateral(
         | 
| 167 145 | 
             
                    IInstance instance,
         | 
| @@ -190,6 +168,64 @@ contract BundleService is | |
| 190 168 | 
             
                    linkPolicy(instance, policyNftId);
         | 
| 191 169 | 
             
                }
         | 
| 192 170 |  | 
| 171 | 
            +
             | 
| 172 | 
            +
                function lock(NftId bundleNftId) 
         | 
| 173 | 
            +
                    external
         | 
| 174 | 
            +
                    virtual
         | 
| 175 | 
            +
                {
         | 
| 176 | 
            +
                    (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                    // udpate bundle state
         | 
| 179 | 
            +
                    instance.updateBundleState(bundleNftId, PAUSED());
         | 
| 180 | 
            +
             | 
| 181 | 
            +
                    // update set of active bundles
         | 
| 182 | 
            +
                    BundleManager bundleManager = instance.getBundleManager();
         | 
| 183 | 
            +
                    bundleManager.lock(bundleNftId);
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                    emit LogBundleServiceBundleLocked(bundleNftId);
         | 
| 186 | 
            +
                }
         | 
| 187 | 
            +
             | 
| 188 | 
            +
             | 
| 189 | 
            +
                function unlock(NftId bundleNftId) 
         | 
| 190 | 
            +
                    external
         | 
| 191 | 
            +
                    virtual
         | 
| 192 | 
            +
                {
         | 
| 193 | 
            +
                    (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
         | 
| 194 | 
            +
             | 
| 195 | 
            +
                    // udpate bundle state
         | 
| 196 | 
            +
                    instance.updateBundleState(bundleNftId, ACTIVE());
         | 
| 197 | 
            +
             | 
| 198 | 
            +
                    // update set of active bundles
         | 
| 199 | 
            +
                    BundleManager bundleManager = instance.getBundleManager();
         | 
| 200 | 
            +
                    bundleManager.unlock(bundleNftId);
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                    emit LogBundleServiceBundleActivated(bundleNftId);
         | 
| 203 | 
            +
                }
         | 
| 204 | 
            +
             | 
| 205 | 
            +
             | 
| 206 | 
            +
                function close(NftId bundleNftId) 
         | 
| 207 | 
            +
                    external
         | 
| 208 | 
            +
                    virtual
         | 
| 209 | 
            +
                {
         | 
| 210 | 
            +
                    (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
         | 
| 211 | 
            +
             | 
| 212 | 
            +
                    // udpate bundle state
         | 
| 213 | 
            +
                    instance.updateBundleState(bundleNftId, CLOSED());
         | 
| 214 | 
            +
             | 
| 215 | 
            +
                    // ensure no open policies attached to bundle
         | 
| 216 | 
            +
                    BundleManager bundleManager = instance.getBundleManager();
         | 
| 217 | 
            +
                    uint256 openPolicies = bundleManager.activePolicies(bundleNftId);
         | 
| 218 | 
            +
                    if(openPolicies > 0) {
         | 
| 219 | 
            +
                        revert ErrorBundleServiceBundleWithOpenPolicies(bundleNftId, openPolicies);
         | 
| 220 | 
            +
                    }
         | 
| 221 | 
            +
             | 
| 222 | 
            +
                    // update set of active bundles
         | 
| 223 | 
            +
                    bundleManager.lock(bundleNftId);
         | 
| 224 | 
            +
             | 
| 225 | 
            +
                    emit LogBundleServiceBundleClosed(bundleNftId);
         | 
| 226 | 
            +
                }
         | 
| 227 | 
            +
             | 
| 228 | 
            +
             | 
| 193 229 | 
             
                function increaseBalance(IInstance instance,
         | 
| 194 230 | 
             
                    NftId bundleNftId, 
         | 
| 195 231 | 
             
                    uint256 amount
         | 
| @@ -234,7 +270,7 @@ contract BundleService is | |
| 234 270 |  | 
| 235 271 | 
             
                    // ensure policy has not yet been activated
         | 
| 236 272 | 
             
                    if (policyInfo.activatedAt.gtz()) {
         | 
| 237 | 
            -
                        revert BundleManager. | 
| 273 | 
            +
                        revert BundleManager.ErrorBundleManagerPolicyAlreadyActivated(policyNftId);
         | 
| 238 274 | 
             
                    }
         | 
| 239 275 |  | 
| 240 276 | 
             
                    BundleManager bundleManager = instance.getBundleManager();
         | 
| @@ -277,18 +313,20 @@ contract BundleService is | |
| 277 313 | 
             
                {
         | 
| 278 314 | 
             
                    // process token transfer(s)
         | 
| 279 315 | 
             
                    if(stakingAmount > 0) {
         | 
| 280 | 
            -
                         | 
| 281 | 
            -
                         | 
| 316 | 
            +
                        IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
         | 
| 317 | 
            +
                        IComponents.PoolInfo memory poolInfo = abi.decode(
         | 
| 318 | 
            +
                            componentInfo.data, (IComponents.PoolInfo));
         | 
| 319 | 
            +
             | 
| 320 | 
            +
                        TokenHandler tokenHandler = componentInfo.tokenHandler;
         | 
| 282 321 | 
             
                        address bundleOwner = getRegistry().ownerOf(bundleNftId);
         | 
| 283 322 | 
             
                        Fee memory stakingFee = poolInfo.stakingFee;
         | 
| 284 323 |  | 
| 285 324 | 
             
                        tokenHandler.transfer(
         | 
| 286 325 | 
             
                            bundleOwner,
         | 
| 287 | 
            -
                             | 
| 326 | 
            +
                            componentInfo.wallet,
         | 
| 288 327 | 
             
                            stakingAmount
         | 
| 289 328 | 
             
                        );
         | 
| 290 329 |  | 
| 291 | 
            -
             | 
| 292 330 | 
             
                        if (! FeeLib.feeIsZero(stakingFee)) {
         | 
| 293 331 | 
             
                            (uint256 stakingFeeAmount, uint256 netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
         | 
| 294 332 | 
             
                            // TODO: track staking fees in pool's state (issue #177)
         | 
| @@ -6,13 +6,15 @@ import {IInstance} from "../../instance/IInstance.sol"; | |
| 6 6 | 
             
            import {InstanceAccessManager} from "../InstanceAccessManager.sol";
         | 
| 7 7 | 
             
            import {InstanceReader} from "../../instance/InstanceReader.sol";
         | 
| 8 8 | 
             
            import {ISetup} from "../../instance/module/ISetup.sol";
         | 
| 9 | 
            +
            import {IPolicy} from "../module/IPolicy.sol";
         | 
| 9 10 |  | 
| 10 11 | 
             
            import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
         | 
| 11 12 | 
             
            import {Fee, FeeLib} from "../../types/Fee.sol";
         | 
| 12 | 
            -
            import {DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.sol";
         | 
| 13 | 
            +
            import {PRODUCT_SERVICE_ROLE, DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.sol";
         | 
| 13 14 | 
             
            import {KEEP_STATE} from "../../types/StateId.sol";
         | 
| 14 15 | 
             
            import {ObjectType, DISTRIBUTION, INSTANCE, DISTRIBUTION, DISTRIBUTOR} from "../../types/ObjectType.sol";
         | 
| 15 16 | 
             
            import {Version, VersionLib} from "../../types/Version.sol";
         | 
| 17 | 
            +
            import {RoleId} from "../../types/RoleId.sol";
         | 
| 16 18 |  | 
| 17 19 | 
             
            import {IVersionable} from "../../shared/IVersionable.sol";
         | 
| 18 20 | 
             
            import {Versionable} from "../../shared/Versionable.sol";
         | 
| @@ -41,6 +43,7 @@ contract DistributionService is | |
| 41 43 | 
             
                using TimestampLib for Timestamp;
         | 
| 42 44 | 
             
                using UFixedLib for UFixed;
         | 
| 43 45 | 
             
                using FeeLib for Fee;
         | 
| 46 | 
            +
                using ReferralLib for ReferralId;
         | 
| 44 47 |  | 
| 45 48 | 
             
                address internal _registryAddress;
         | 
| 46 49 |  | 
| @@ -85,21 +88,43 @@ contract DistributionService is | |
| 85 88 | 
             
                    distributionNftId = distributionInfo.nftId;
         | 
| 86 89 |  | 
| 87 90 | 
             
                    instance.createDistributionSetup(distributionNftId, distribution.getSetupInfo());
         | 
| 88 | 
            -
                     | 
| 89 | 
            -
                     | 
| 91 | 
            +
                    // TODO move to distribution?
         | 
| 92 | 
            +
                    bytes4[][] memory selectors = new bytes4[][](2);
         | 
| 93 | 
            +
                    selectors[0] = new bytes4[](1);
         | 
| 94 | 
            +
                    selectors[1] = new bytes4[](2);
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                    selectors[0][0] = IDistributionComponent.setFees.selector;
         | 
| 97 | 
            +
                    selectors[1][0] = IDistributionComponent.processRenewal.selector;
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                    RoleId[] memory roles = new RoleId[](2);
         | 
| 100 | 
            +
                    roles[0] = DISTRIBUTION_OWNER_ROLE();
         | 
| 101 | 
            +
                    roles[1] = PRODUCT_SERVICE_ROLE();
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                    getInstanceService().createGifTarget(
         | 
| 104 | 
            +
                        instanceNftId, 
         | 
| 105 | 
            +
                        distributionAddress, 
         | 
| 106 | 
            +
                        distribution.getName(), 
         | 
| 107 | 
            +
                        selectors, 
         | 
| 108 | 
            +
                        roles);
         | 
| 90 109 | 
             
                }
         | 
| 91 110 |  | 
| 92 111 | 
             
                function setFees(
         | 
| 112 | 
            +
                    Fee memory minDistributionOwnerFee,
         | 
| 93 113 | 
             
                    Fee memory distributionFee
         | 
| 94 114 | 
             
                )
         | 
| 95 115 | 
             
                    external
         | 
| 96 116 | 
             
                    override
         | 
| 97 117 | 
             
                {
         | 
| 118 | 
            +
                    if (minDistributionOwnerFee.fractionalFee > distributionFee.fractionalFee) {
         | 
| 119 | 
            +
                        revert ErrorIDistributionServiceMinFeeTooHigh(minDistributionOwnerFee.fractionalFee.toInt(), distributionFee.fractionalFee.toInt());
         | 
| 120 | 
            +
                    }
         | 
| 121 | 
            +
             | 
| 98 122 | 
             
                    (IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(DISTRIBUTION());
         | 
| 99 123 | 
             
                    InstanceReader instanceReader = instance.getInstanceReader();
         | 
| 100 124 | 
             
                    NftId distributionNftId = info.nftId;
         | 
| 101 125 |  | 
| 102 126 | 
             
                    ISetup.DistributionSetupInfo memory distSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
         | 
| 127 | 
            +
                    distSetupInfo.minDistributionOwnerFee = minDistributionOwnerFee;
         | 
| 103 128 | 
             
                    distSetupInfo.distributionFee = distributionFee;
         | 
| 104 129 |  | 
| 105 130 | 
             
                    instance.updateDistributionSetup(distributionNftId, distSetupInfo, KEEP_STATE());
         | 
| @@ -122,13 +147,11 @@ contract DistributionService is | |
| 122 147 | 
             
                    (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
         | 
| 123 148 |  | 
| 124 149 | 
             
                    {
         | 
| 125 | 
            -
                        if (commissionPercentage > maxDiscountPercentage) {
         | 
| 126 | 
            -
                            revert ErrorIDistributionServiceCommissionTooHigh(commissionPercentage.toInt(), maxDiscountPercentage.toInt());
         | 
| 127 | 
            -
                        }
         | 
| 128 | 
            -
             | 
| 129 150 | 
             
                        ISetup.DistributionSetupInfo memory setupInfo = instance.getInstanceReader().getDistributionSetupInfo(distributionNftId);
         | 
| 130 | 
            -
                         | 
| 131 | 
            -
             | 
| 151 | 
            +
                        UFixed variableFeesPartsTotal = setupInfo.minDistributionOwnerFee.fractionalFee.add(commissionPercentage);
         | 
| 152 | 
            +
                        UFixed maxDiscountPercentageLimit = setupInfo.distributionFee.fractionalFee.sub(variableFeesPartsTotal);
         | 
| 153 | 
            +
                        if (maxDiscountPercentage.gt(maxDiscountPercentageLimit)) {
         | 
| 154 | 
            +
                            revert ErrorIDistributionServiceMaxDiscountTooHigh(maxDiscountPercentage.toInt(), maxDiscountPercentageLimit.toInt());
         | 
| 132 155 | 
             
                        }
         | 
| 133 156 | 
             
                    }
         | 
| 134 157 |  | 
| @@ -173,7 +196,9 @@ contract DistributionService is | |
| 173 196 | 
             
                    IDistribution.DistributorInfo memory info = IDistribution.DistributorInfo(
         | 
| 174 197 | 
             
                        distributorType,
         | 
| 175 198 | 
             
                        true, // active
         | 
| 176 | 
            -
                        data | 
| 199 | 
            +
                        data,
         | 
| 200 | 
            +
                        0,
         | 
| 201 | 
            +
                        0);
         | 
| 177 202 |  | 
| 178 203 | 
             
                    instance.createDistributor(distributorNftId, info);
         | 
| 179 204 | 
             
                }
         | 
| @@ -185,13 +210,11 @@ contract DistributionService is | |
| 185 210 | 
             
                ) external virtual
         | 
| 186 211 | 
             
                {
         | 
| 187 212 | 
             
                    (,, IInstance instance) = _getAndVerifyCallingDistribution();
         | 
| 188 | 
            -
             | 
| 189 | 
            -
                    IDistribution.DistributorInfo memory  | 
| 190 | 
            -
             | 
| 191 | 
            -
             | 
| 192 | 
            -
             | 
| 193 | 
            -
             | 
| 194 | 
            -
                    instance.updateDistributor(distributorNftId, info, KEEP_STATE());
         | 
| 213 | 
            +
                    InstanceReader instanceReader = instance.getInstanceReader();
         | 
| 214 | 
            +
                    IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
         | 
| 215 | 
            +
                    distributorInfo.distributorType = distributorType;
         | 
| 216 | 
            +
                    distributorInfo.data = data;
         | 
| 217 | 
            +
                    instance.updateDistributor(distributorNftId, distributorInfo, KEEP_STATE());
         | 
| 195 218 | 
             
                }
         | 
| 196 219 |  | 
| 197 220 |  | 
| @@ -217,8 +240,8 @@ contract DistributionService is | |
| 217 240 | 
             
                    }
         | 
| 218 241 |  | 
| 219 242 | 
             
                    InstanceReader instanceReader = instance.getInstanceReader();
         | 
| 220 | 
            -
                    IDistribution.DistributorInfo memory  | 
| 221 | 
            -
                    DistributorType distributorType =  | 
| 243 | 
            +
                    IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
         | 
| 244 | 
            +
                    DistributorType distributorType = distributorInfo.distributorType;
         | 
| 222 245 | 
             
                    IDistribution.DistributorTypeInfo memory distributorTypeData = instanceReader.getDistributorTypeInfo(distributorType);
         | 
| 223 246 |  | 
| 224 247 | 
             
                    if (distributorTypeData.maxReferralCount < maxReferrals) {
         | 
| @@ -250,53 +273,122 @@ contract DistributionService is | |
| 250 273 | 
             
                }
         | 
| 251 274 |  | 
| 252 275 | 
             
                function processSale(
         | 
| 276 | 
            +
                    NftId distributionNftId,
         | 
| 253 277 | 
             
                    ReferralId referralId,
         | 
| 254 | 
            -
                     | 
| 278 | 
            +
                    IPolicy.Premium memory premium,
         | 
| 279 | 
            +
                    uint256 transferredDistributionFeeAmount
         | 
| 255 280 | 
             
                )
         | 
| 256 281 | 
             
                    external
         | 
| 257 282 | 
             
                    virtual
         | 
| 258 283 | 
             
                {
         | 
| 259 | 
            -
                     | 
| 260 | 
            -
                     | 
| 261 | 
            -
             | 
| 262 | 
            -
                     | 
| 263 | 
            -
             | 
| 264 | 
            -
                     | 
| 265 | 
            -
             | 
| 266 | 
            -
                     | 
| 284 | 
            +
                    bool isReferral = ! referralId.eqz();
         | 
| 285 | 
            +
                    bool referralValid = referralIsValid(distributionNftId, referralId);
         | 
| 286 | 
            +
             | 
| 287 | 
            +
                    if (isReferral && ! referralValid) {
         | 
| 288 | 
            +
                        revert ErrorIDistributionServiceReferralInvalid(distributionNftId, referralId);
         | 
| 289 | 
            +
                    }
         | 
| 290 | 
            +
             | 
| 291 | 
            +
                    (, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
         | 
| 292 | 
            +
                    InstanceReader reader = instance.getInstanceReader();
         | 
| 293 | 
            +
                    IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
         | 
| 294 | 
            +
                    IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
         | 
| 295 | 
            +
                    ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
         | 
| 296 | 
            +
                    
         | 
| 297 | 
            +
                    uint256 distributionOwnerFee = premium.distributionOwnerFeeFixAmount + premium.distributionOwnerFeeVarAmount;
         | 
| 298 | 
            +
                    uint256 commissionAmount = premium.commissionAmount;
         | 
| 299 | 
            +
             | 
| 300 | 
            +
                    if (transferredDistributionFeeAmount != distributionOwnerFee + commissionAmount) {
         | 
| 301 | 
            +
                        revert ErrorIDistributionServiceInvalidFeeTransferred(transferredDistributionFeeAmount, distributionOwnerFee + commissionAmount);
         | 
| 302 | 
            +
                    }
         | 
| 303 | 
            +
             | 
| 304 | 
            +
             | 
| 305 | 
            +
                    if (distributionOwnerFee > 0) {
         | 
| 306 | 
            +
                        setupInfo.sumDistributionOwnerFees += distributionOwnerFee;
         | 
| 307 | 
            +
                        instance.updateDistributionSetup(distributionNftId, setupInfo, KEEP_STATE());
         | 
| 308 | 
            +
                    }
         | 
| 309 | 
            +
             | 
| 310 | 
            +
                    if (isReferral) {
         | 
| 311 | 
            +
                        referralInfo.usedReferrals += 1;
         | 
| 312 | 
            +
                        instance.updateReferral(referralId.toKey32(), referralInfo, KEEP_STATE());
         | 
| 313 | 
            +
             | 
| 314 | 
            +
                        if (commissionAmount > 0) {
         | 
| 315 | 
            +
                            distributorInfo.sumCommisions += commissionAmount;
         | 
| 316 | 
            +
                            distributorInfo.numPoliciesSold += 1;
         | 
| 317 | 
            +
                            instance.updateDistributor(referralInfo.distributorNftId, distributorInfo, KEEP_STATE());
         | 
| 318 | 
            +
                        }
         | 
| 319 | 
            +
                    }
         | 
| 267 320 | 
             
                }
         | 
| 268 321 |  | 
| 269 322 | 
             
                function calculateFeeAmount(
         | 
| 270 323 | 
             
                    NftId distributionNftId,
         | 
| 271 324 | 
             
                    ReferralId referralId,
         | 
| 272 | 
            -
                     | 
| 325 | 
            +
                    IPolicy.Premium memory premium
         | 
| 273 326 | 
             
                )
         | 
| 274 327 | 
             
                    external
         | 
| 275 328 | 
             
                    virtual
         | 
| 276 329 | 
             
                    view 
         | 
| 277 | 
            -
                    returns ( | 
| 330 | 
            +
                    returns (IPolicy.Premium memory finalPremium)
         | 
| 278 331 | 
             
                {
         | 
| 279 | 
            -
                    ( | 
| 332 | 
            +
                    (, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
         | 
| 280 333 | 
             
                    InstanceReader reader = instance.getInstanceReader();
         | 
| 281 | 
            -
             | 
| 282 | 
            -
                    // calculate  | 
| 334 | 
            +
                    
         | 
| 335 | 
            +
                    // first calculate all fixed and variable fees for the distribution - this will defined the fullPremium
         | 
| 283 336 | 
             
                    ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
         | 
| 284 | 
            -
                    Fee memory  | 
| 285 | 
            -
                     | 
| 286 | 
            -
             | 
| 287 | 
            -
                     | 
| 288 | 
            -
             | 
| 289 | 
            -
                         | 
| 290 | 
            -
             | 
| 291 | 
            -
             | 
| 292 | 
            -
             | 
| 293 | 
            -
                         | 
| 294 | 
            -
             | 
| 295 | 
            -
                         | 
| 296 | 
            -
                    } | 
| 297 | 
            -
             | 
| 337 | 
            +
                    Fee memory distributionFee = setupInfo.distributionFee;
         | 
| 338 | 
            +
                    Fee memory minDistributionOwnerFee = setupInfo.minDistributionOwnerFee;
         | 
| 339 | 
            +
                    uint256 distributionFeeVarAmount = (UFixedLib.toUFixed(premium.netPremiumAmount) * distributionFee.fractionalFee).toInt();
         | 
| 340 | 
            +
                    premium.distributionFeeVarAmount = distributionFeeVarAmount;
         | 
| 341 | 
            +
                    premium.fullPremiumAmount += distributionFeeVarAmount;
         | 
| 342 | 
            +
                        
         | 
| 343 | 
            +
                    // if the referral is not valid, then the distribution owner gets everything
         | 
| 344 | 
            +
                    if (! referralIsValid(distributionNftId, referralId)) {
         | 
| 345 | 
            +
                        premium.distributionOwnerFeeFixAmount = premium.distributionFeeFixAmount;
         | 
| 346 | 
            +
                        premium.distributionOwnerFeeVarAmount = premium.distributionFeeVarAmount;
         | 
| 347 | 
            +
                        premium.premiumAmount = premium.fullPremiumAmount;
         | 
| 348 | 
            +
                        return premium;
         | 
| 349 | 
            +
                    }
         | 
| 350 | 
            +
             | 
| 351 | 
            +
                    // if the referral is valid, the the commission and discount are calculated based in the full premium
         | 
| 352 | 
            +
                    // the remaing amount goes to the distribution owner
         | 
| 353 | 
            +
                    {
         | 
| 354 | 
            +
                        IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
         | 
| 355 | 
            +
                        IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
         | 
| 356 | 
            +
                        IDistribution.DistributorTypeInfo memory distributorTypeInfo = reader.getDistributorTypeInfo(distributorInfo.distributorType);
         | 
| 357 | 
            +
             | 
| 358 | 
            +
                        uint256 commissionAmount = UFixedLib.toUFixed(premium.netPremiumAmount).mul(distributorTypeInfo.commissionPercentage).toInt();
         | 
| 359 | 
            +
                        premium.commissionAmount = commissionAmount;
         | 
| 360 | 
            +
                        premium.discountAmount = UFixedLib.toUFixed(premium.fullPremiumAmount).mul(referralInfo.discountPercentage).toInt();
         | 
| 361 | 
            +
                        premium.distributionOwnerFeeFixAmount = minDistributionOwnerFee.fixedFee;
         | 
| 362 | 
            +
                        premium.distributionOwnerFeeVarAmount = distributionFeeVarAmount - commissionAmount - premium.discountAmount;
         | 
| 363 | 
            +
                        premium.premiumAmount = premium.fullPremiumAmount - premium.discountAmount;
         | 
| 364 | 
            +
                    }
         | 
| 365 | 
            +
             | 
| 366 | 
            +
                    // sanity check to validate the fee calculation
         | 
| 367 | 
            +
                    if (premium.distributionOwnerFeeFixAmount < minDistributionOwnerFee.fixedFee) {
         | 
| 368 | 
            +
                        revert ErrorIDistributionServiceFeeCalculationMismatch(
         | 
| 369 | 
            +
                            premium.distributionFeeFixAmount,
         | 
| 370 | 
            +
                            premium.distributionFeeVarAmount,
         | 
| 371 | 
            +
                            premium.distributionOwnerFeeFixAmount,
         | 
| 372 | 
            +
                            premium.distributionOwnerFeeVarAmount,
         | 
| 373 | 
            +
                            premium.commissionAmount,
         | 
| 374 | 
            +
                            premium.discountAmount
         | 
| 375 | 
            +
                        );
         | 
| 376 | 
            +
                    }
         | 
| 377 | 
            +
                    if ((premium.distributionFeeVarAmount) != (premium.discountAmount + premium.distributionOwnerFeeVarAmount + premium.commissionAmount)) {
         | 
| 378 | 
            +
                        revert ErrorIDistributionServiceFeeCalculationMismatch(
         | 
| 379 | 
            +
                            premium.distributionFeeFixAmount,
         | 
| 380 | 
            +
                            premium.distributionFeeVarAmount,
         | 
| 381 | 
            +
                            premium.distributionOwnerFeeFixAmount,
         | 
| 382 | 
            +
                            premium.distributionOwnerFeeVarAmount,
         | 
| 383 | 
            +
                            premium.commissionAmount,
         | 
| 384 | 
            +
                            premium.discountAmount
         | 
| 385 | 
            +
                        );
         | 
| 386 | 
            +
                    }
         | 
| 387 | 
            +
                    
         | 
| 388 | 
            +
                    return premium; 
         | 
| 298 389 | 
             
                }
         | 
| 299 390 |  | 
| 391 | 
            +
                // TODO: zero should return false
         | 
| 300 392 | 
             
                function referralIsValid(NftId distributionNftId, ReferralId referralId) public view returns (bool isValid) {
         | 
| 301 393 | 
             
                    (address distributionAddress, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
         | 
| 302 394 | 
             
                    IDistribution.ReferralInfo memory info = instance.getInstanceReader().getReferralInfo(referralId);
         | 
| @@ -1,12 +1,14 @@ | |
| 1 1 | 
             
            // SPDX-License-Identifier: Apache-2.0
         | 
| 2 2 | 
             
            pragma solidity ^0.8.19;
         | 
| 3 3 |  | 
| 4 | 
            +
            import {IPolicy} from "../module/IPolicy.sol";
         | 
| 4 5 | 
             
            import {IRisk} from "../module/IRisk.sol";
         | 
| 5 6 | 
             
            import {IService} from "../../shared/IService.sol";
         | 
| 6 7 |  | 
| 7 8 | 
             
            import {NftId} from "../../types/NftId.sol";
         | 
| 8 9 | 
             
            import {ReferralId} from "../../types/Referral.sol";
         | 
| 9 10 | 
             
            import {RiskId} from "../../types/RiskId.sol";
         | 
| 11 | 
            +
            import {Seconds} from "../../types/Seconds.sol";
         | 
| 10 12 | 
             
            import {StateId} from "../../types/StateId.sol";
         | 
| 11 13 | 
             
            import {Timestamp} from "../../types/Timestamp.sol";
         | 
| 12 14 | 
             
            import {UFixed} from "../../types/UFixed.sol";
         | 
| @@ -17,6 +19,7 @@ import {Fee} from "../../types/Fee.sol"; | |
| 17 19 | 
             
            interface IApplicationService is IService {
         | 
| 18 20 |  | 
| 19 21 | 
             
                error IApplicationServicePolicyNotApplied(NftId applicationNftId);
         | 
| 22 | 
            +
                error IApplicationServiceBundlePoolMismatch(NftId bundleNftId, NftId bundlePoolNftId, NftId poolNftId);
         | 
| 20 23 |  | 
| 21 24 | 
             
                /// @dev creates a new application based on the specified attributes
         | 
| 22 25 | 
             
                /// may only be called by a product component
         | 
| @@ -24,7 +27,7 @@ interface IApplicationService is IService { | |
| 24 27 | 
             
                    address applicationOwner,
         | 
| 25 28 | 
             
                    RiskId riskId,
         | 
| 26 29 | 
             
                    uint256 sumInsuredAmount,
         | 
| 27 | 
            -
                     | 
| 30 | 
            +
                    Seconds lifetime,
         | 
| 28 31 | 
             
                    NftId bundleNftId,
         | 
| 29 32 | 
             
                    ReferralId referralId,
         | 
| 30 33 | 
             
                    bytes memory applicationData
         | 
| @@ -63,9 +66,10 @@ interface IApplicationService is IService { | |
| 63 66 | 
             
                /// @dev calculates the premium amount for the specified attributes
         | 
| 64 67 | 
             
                /// also returns the various fee components involved with creating a policy
         | 
| 65 68 | 
             
                function calculatePremium(
         | 
| 69 | 
            +
                    NftId productNftId,
         | 
| 66 70 | 
             
                    RiskId riskId,
         | 
| 67 71 | 
             
                    uint256 sumInsuredAmount,
         | 
| 68 | 
            -
                     | 
| 72 | 
            +
                    Seconds lifetime,
         | 
| 69 73 | 
             
                    bytes memory applicationData,
         | 
| 70 74 | 
             
                    NftId bundleNftId,
         | 
| 71 75 | 
             
                    ReferralId referralId
         | 
| @@ -73,10 +77,6 @@ interface IApplicationService is IService { | |
| 73 77 | 
             
                    external
         | 
| 74 78 | 
             
                    view
         | 
| 75 79 | 
             
                    returns (
         | 
| 76 | 
            -
                         | 
| 77 | 
            -
                        uint256 distributionFeeAmount,
         | 
| 78 | 
            -
                        uint256 productFeeAmount,
         | 
| 79 | 
            -
                        uint256 poolFeeAmount,
         | 
| 80 | 
            -
                        uint256 bundleFeeAmount
         | 
| 80 | 
            +
                        IPolicy.Premium memory premium
         | 
| 81 81 | 
             
                    );
         | 
| 82 82 | 
             
            }
         | 
| @@ -3,28 +3,36 @@ pragma solidity ^0.8.19; | |
| 3 3 |  | 
| 4 4 | 
             
            import {NftId} from "../../types/NftId.sol";
         | 
| 5 5 | 
             
            import {Fee} from "../../types/Fee.sol";
         | 
| 6 | 
            -
            import {StateId} from "../../types/StateId.sol";
         | 
| 7 6 | 
             
            import {IService} from "../../shared/IService.sol";
         | 
| 8 7 | 
             
            import {IBundle} from "../module/IBundle.sol";
         | 
| 9 8 | 
             
            import {IInstance} from "../../instance/IInstance.sol";
         | 
| 9 | 
            +
            import {Seconds} from "../../types/Seconds.sol";
         | 
| 10 | 
            +
            import {StateId} from "../../types/StateId.sol";
         | 
| 10 11 |  | 
| 11 12 | 
             
            interface IBundleService is IService {
         | 
| 12 | 
            -
                error ErrorIBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
         | 
| 13 13 |  | 
| 14 | 
            -
                 | 
| 14 | 
            +
                event LogBundleServiceBundleActivated(NftId bundleNftId);
         | 
| 15 | 
            +
                event LogBundleServiceBundleLocked(NftId bundleNftId);
         | 
| 16 | 
            +
                event LogBundleServiceBundleClosed(NftId bundleNftId);
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                error ErrorBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
         | 
| 19 | 
            +
                error ErrorBundleServiceBundleNotOpen(NftId bundleNftId, StateId state);
         | 
| 20 | 
            +
                error ErrorBundleServiceBundleWithOpenPolicies(NftId bundleNftId, uint256 openPoliciesCount);
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                function create(
         | 
| 15 23 | 
             
                    address owner,
         | 
| 16 24 | 
             
                    Fee memory fee, 
         | 
| 17 25 | 
             
                    uint256 amount,
         | 
| 18 | 
            -
                     | 
| 26 | 
            +
                    Seconds lifetime, 
         | 
| 19 27 | 
             
                    bytes calldata filter
         | 
| 20 28 | 
             
                ) external returns(NftId bundleNftId);
         | 
| 21 29 |  | 
| 22 | 
            -
             | 
| 30 | 
            +
             | 
| 31 | 
            +
                function setFee(
         | 
| 23 32 | 
             
                    NftId bundleNftId,
         | 
| 24 33 | 
             
                    Fee memory fee
         | 
| 25 34 | 
             
                ) external;
         | 
| 26 35 |  | 
| 27 | 
            -
                function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state) external;
         | 
| 28 36 |  | 
| 29 37 | 
             
                function lockCollateral(
         | 
| 30 38 | 
             
                    IInstance instanceNftId, 
         | 
| @@ -42,13 +50,13 @@ interface IBundleService is IService { | |
| 42 50 |  | 
| 43 51 | 
             
                function closePolicy(IInstance instance, NftId policyNftId, NftId bundleNftId, uint256 collateralAmount) external;
         | 
| 44 52 |  | 
| 45 | 
            -
                // function  | 
| 53 | 
            +
                // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
         | 
| 46 54 |  | 
| 47 | 
            -
                // function  | 
| 55 | 
            +
                // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
         | 
| 48 56 |  | 
| 49 | 
            -
                function  | 
| 57 | 
            +
                function lock(NftId bundleNftId) external;
         | 
| 50 58 |  | 
| 51 | 
            -
                function  | 
| 59 | 
            +
                function unlock(NftId bundleNftId) external;
         | 
| 52 60 |  | 
| 53 | 
            -
                 | 
| 61 | 
            +
                function close(NftId bundleNftId) external;
         | 
| 54 62 | 
             
            }
         | 
| @@ -3,6 +3,7 @@ pragma solidity ^0.8.19; | |
| 3 3 |  | 
| 4 4 | 
             
            import {NftId} from "../../types/NftId.sol";
         | 
| 5 5 | 
             
            import {Fee} from "../../types/Fee.sol";
         | 
| 6 | 
            +
            import {IPolicy} from "../module/IPolicy.sol";
         | 
| 6 7 | 
             
            import {IService} from "../../shared/IService.sol";
         | 
| 7 8 | 
             
            import {UFixed} from "../../types/UFixed.sol";
         | 
| 8 9 | 
             
            import {DistributorType} from "../../types/DistributorType.sol";
         | 
| @@ -21,9 +22,21 @@ interface IDistributionService is IService { | |
| 21 22 | 
             
                error ErrorIDistributionServiceInvalidReferral(string code);
         | 
| 22 23 | 
             
                error ErrorIDistributionServiceExpirationInvalid(Timestamp expiryAt);
         | 
| 23 24 | 
             
                error ErrorIDistributionServiceCommissionTooHigh(uint256 commissionPercentage, uint256 maxCommissionPercentage);
         | 
| 24 | 
            -
                error  | 
| 25 | 
            +
                error ErrorIDistributionServiceMinFeeTooHigh(uint256 minFee, uint256 limit);
         | 
| 26 | 
            +
                error ErrorIDistributionServiceMaxDiscountTooHigh(uint256 maxDiscountPercentage, uint256 limit);
         | 
| 27 | 
            +
                error ErrorIDistributionServiceFeeCalculationMismatch(
         | 
| 28 | 
            +
                            uint256 distributionFeeFixAmount,
         | 
| 29 | 
            +
                            uint256 distributionFeeVarAmount,
         | 
| 30 | 
            +
                            uint256 distributionOwnerFeeFixAmount,
         | 
| 31 | 
            +
                            uint256 distributionOwnerFeeVarAmount,
         | 
| 32 | 
            +
                            uint256 commissionAmount,
         | 
| 33 | 
            +
                            uint256 discountAmount
         | 
| 34 | 
            +
                        );
         | 
| 35 | 
            +
                error ErrorIDistributionServiceReferralInvalid(NftId distributionNftId, ReferralId referralId);
         | 
| 36 | 
            +
                error ErrorIDistributionServiceInvalidFeeTransferred(uint256 transferredDistributionFeeAmount, uint256 expectedDistributionFeeAmount);
         | 
| 25 37 |  | 
| 26 38 | 
             
                function setFees(
         | 
| 39 | 
            +
                    Fee memory minDistributionOwnerFee,
         | 
| 27 40 | 
             
                    Fee memory distributionFee
         | 
| 28 41 | 
             
                ) external;
         | 
| 29 42 |  | 
| @@ -66,15 +79,17 @@ interface IDistributionService is IService { | |
| 66 79 |  | 
| 67 80 | 
             
                /// @dev callback from product service when selling a policy for a specific referralId
         | 
| 68 81 | 
             
                function processSale(
         | 
| 82 | 
            +
                    NftId distributionNftId,
         | 
| 69 83 | 
             
                    ReferralId referralId,
         | 
| 70 | 
            -
                     | 
| 84 | 
            +
                    IPolicy.Premium memory premium,
         | 
| 85 | 
            +
                    uint256 transferredDistributionFeeAmount
         | 
| 71 86 | 
             
                ) external;
         | 
| 72 87 |  | 
| 73 88 | 
             
                function calculateFeeAmount(
         | 
| 74 89 | 
             
                    NftId distributionNftId,
         | 
| 75 90 | 
             
                    ReferralId referralId,
         | 
| 76 | 
            -
                     | 
| 77 | 
            -
                ) external view returns ( | 
| 91 | 
            +
                    IPolicy.Premium memory premium
         | 
| 92 | 
            +
                ) external view returns (IPolicy.Premium memory finalPremium);
         | 
| 78 93 |  | 
| 79 94 | 
             
                function referralIsValid(
         | 
| 80 95 | 
             
                    NftId distributorNftId,
         |