@etherisc/gif-next 0.0.2-e876b87-961 → 0.0.2-e8a628e-326
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/README.md +90 -7
 - package/artifacts/contracts/accounting/AccountingService.sol/AccountingService.dbg.json +4 -0
 - package/artifacts/contracts/accounting/AccountingService.sol/AccountingService.json +1075 -0
 - package/artifacts/contracts/accounting/AccountingServiceManager.sol/AccountingServiceManager.dbg.json +4 -0
 - package/artifacts/contracts/accounting/AccountingServiceManager.sol/AccountingServiceManager.json +790 -0
 - package/artifacts/contracts/accounting/IAccountingService.sol/IAccountingService.dbg.json +4 -0
 - package/artifacts/contracts/accounting/IAccountingService.sol/IAccountingService.json +843 -0
 - package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.dbg.json +1 -1
 - package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.json +640 -269
 - package/artifacts/contracts/authorization/AccessAdminLib.sol/AccessAdminLib.dbg.json +4 -0
 - package/artifacts/contracts/authorization/AccessAdminLib.sol/AccessAdminLib.json +1289 -0
 - package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.dbg.json +1 -1
 - package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.json +202 -5
 - package/artifacts/contracts/authorization/Authorization.sol/Authorization.dbg.json +1 -1
 - package/artifacts/contracts/authorization/Authorization.sol/Authorization.json +409 -33
 - package/artifacts/contracts/authorization/IAccess.sol/IAccess.dbg.json +1 -1
 - package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.dbg.json +1 -1
 - package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.json +525 -213
 - package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.dbg.json +1 -1
 - package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.json +179 -19
 - package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.dbg.json +1 -1
 - package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.json +246 -16
 - package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.dbg.json +1 -1
 - package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.json +420 -27
 - package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.dbg.json +1 -1
 - package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.json +132 -290
 - package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.dbg.json +1 -1
 - package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.json +381 -46
 - package/artifacts/contracts/distribution/Distribution.sol/Distribution.dbg.json +1 -1
 - package/artifacts/contracts/distribution/Distribution.sol/Distribution.json +64 -163
 - package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.dbg.json +1 -1
 - package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.json +585 -231
 - package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.json +170 -78
 - package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
 - package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.json +44 -125
 - package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.dbg.json +1 -1
 - package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.json +401 -78
 - package/artifacts/contracts/examples/fire/DamageLevel.sol/DamageLevelLib.dbg.json +1 -1
 - package/artifacts/contracts/examples/fire/FirePool.sol/FirePool.dbg.json +1 -1
 - package/artifacts/contracts/examples/fire/FirePool.sol/FirePool.json +160 -214
 - package/artifacts/contracts/examples/fire/FirePoolAuthorization.sol/FirePoolAuthorization.dbg.json +1 -1
 - package/artifacts/contracts/examples/fire/FirePoolAuthorization.sol/FirePoolAuthorization.json +380 -45
 - package/artifacts/contracts/examples/fire/FireProduct.sol/FireProduct.dbg.json +1 -1
 - package/artifacts/contracts/examples/fire/FireProduct.sol/FireProduct.json +308 -327
 - package/artifacts/contracts/examples/fire/FireProductAuthorization.sol/FireProductAuthorization.dbg.json +1 -1
 - package/artifacts/contracts/examples/fire/FireProductAuthorization.sol/FireProductAuthorization.json +380 -45
 - package/artifacts/contracts/examples/fire/FireUSD.sol/FireUSD.dbg.json +1 -1
 - package/artifacts/contracts/examples/unpermissioned/SimpleDistribution.sol/SimpleDistribution.dbg.json +1 -1
 - package/artifacts/contracts/examples/unpermissioned/SimpleDistribution.sol/SimpleDistribution.json +215 -247
 - package/artifacts/contracts/examples/unpermissioned/SimpleDistributionAuthorization.sol/SimpleDistributionAuthorization.dbg.json +4 -0
 - package/artifacts/contracts/examples/unpermissioned/SimpleDistributionAuthorization.sol/SimpleDistributionAuthorization.json +805 -0
 - package/artifacts/contracts/examples/unpermissioned/SimpleOracle.sol/SimpleOracle.dbg.json +1 -1
 - package/artifacts/contracts/examples/unpermissioned/SimpleOracle.sol/SimpleOracle.json +95 -155
 - package/artifacts/contracts/examples/unpermissioned/SimplePool.sol/SimplePool.dbg.json +1 -1
 - package/artifacts/contracts/examples/unpermissioned/SimplePool.sol/SimplePool.json +278 -223
 - package/artifacts/contracts/examples/unpermissioned/SimplePoolAuthorization.sol/SimplePoolAuthorization.dbg.json +4 -0
 - package/artifacts/contracts/examples/unpermissioned/SimplePoolAuthorization.sol/SimplePoolAuthorization.json +805 -0
 - package/artifacts/contracts/examples/unpermissioned/SimpleProduct.sol/SimpleProduct.dbg.json +1 -1
 - package/artifacts/contracts/examples/unpermissioned/SimpleProduct.sol/SimpleProduct.json +944 -454
 - package/artifacts/contracts/examples/unpermissioned/SimpleProductAuthorization.sol/SimpleProductAuthorization.dbg.json +4 -0
 - package/artifacts/contracts/examples/unpermissioned/SimpleProductAuthorization.sol/SimpleProductAuthorization.json +805 -0
 - package/artifacts/contracts/instance/BaseStore.sol/BaseStore.dbg.json +4 -0
 - package/artifacts/contracts/instance/BaseStore.sol/BaseStore.json +498 -0
 - package/artifacts/contracts/instance/BundleSet.sol/BundleSet.dbg.json +1 -1
 - package/artifacts/contracts/instance/BundleSet.sol/BundleSet.json +193 -45
 - package/artifacts/contracts/instance/IBaseStore.sol/IBaseStore.dbg.json +4 -0
 - package/artifacts/contracts/instance/IBaseStore.sol/IBaseStore.json +470 -0
 - package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
 - package/artifacts/contracts/instance/IInstance.sol/IInstance.json +541 -50
 - package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
 - package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +407 -17
 - package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
 - package/artifacts/contracts/instance/Instance.sol/Instance.json +606 -106
 - package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.dbg.json +1 -1
 - package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.json +990 -359
 - package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.dbg.json +1 -1
 - package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.json +337 -61
 - package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
 - package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +1069 -481
 - package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
 - package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +424 -81
 - package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +102 -52
 - package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +1 -1
 - package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +648 -948
 - package/artifacts/contracts/instance/ProductStore.sol/ProductStore.dbg.json +4 -0
 - package/artifacts/contracts/instance/ProductStore.sol/ProductStore.json +1759 -0
 - package/artifacts/contracts/instance/RiskSet.sol/RiskSet.dbg.json +4 -0
 - package/artifacts/contracts/instance/RiskSet.sol/RiskSet.json +866 -0
 - package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.dbg.json +1 -1
 - package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.json +8 -8
 - package/artifacts/contracts/instance/base/Cloneable.sol/Cloneable.dbg.json +1 -1
 - package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.dbg.json +1 -1
 - package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.json +2 -2
 - package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.dbg.json +1 -1
 - package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.json +2 -2
 - package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.dbg.json +1 -1
 - package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.json +16 -5
 - package/artifacts/contracts/instance/base/ObjectSetHelperLib.sol/ObjectSetHelperLib.dbg.json +4 -0
 - package/artifacts/contracts/instance/base/ObjectSetHelperLib.sol/ObjectSetHelperLib.json +168 -0
 - 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/mock/Dip.sol/Dip.dbg.json +1 -1
 - package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.dbg.json +1 -1
 - package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.json +83 -165
 - package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.dbg.json +1 -1
 - package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.json +379 -47
 - package/artifacts/contracts/oracle/IOracle.sol/IOracle.dbg.json +1 -1
 - package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.dbg.json +1 -1
 - package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.json +48 -64
 - package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.dbg.json +1 -1
 - package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.json +56 -3
 - package/artifacts/contracts/oracle/Oracle.sol/Oracle.dbg.json +1 -1
 - package/artifacts/contracts/oracle/Oracle.sol/Oracle.json +67 -101
 - package/artifacts/contracts/oracle/OracleService.sol/OracleService.dbg.json +1 -1
 - package/artifacts/contracts/oracle/OracleService.sol/OracleService.json +157 -81
 - package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.json +134 -46
 - package/artifacts/contracts/pool/BasicPool.sol/BasicPool.dbg.json +1 -1
 - package/artifacts/contracts/pool/BasicPool.sol/BasicPool.json +106 -163
 - package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.dbg.json +1 -1
 - package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.json +380 -45
 - package/artifacts/contracts/pool/BundleService.sol/BundleService.dbg.json +1 -1
 - package/artifacts/contracts/pool/BundleService.sol/BundleService.json +317 -344
 - package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.json +125 -93
 - package/artifacts/contracts/pool/IBundleService.sol/IBundleService.dbg.json +1 -1
 - package/artifacts/contracts/pool/IBundleService.sol/IBundleService.json +219 -146
 - package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
 - package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.json +63 -118
 - package/artifacts/contracts/pool/IPoolService.sol/IPoolService.dbg.json +1 -1
 - package/artifacts/contracts/pool/IPoolService.sol/IPoolService.json +380 -214
 - package/artifacts/contracts/pool/Pool.sol/Pool.dbg.json +1 -1
 - package/artifacts/contracts/pool/Pool.sol/Pool.json +76 -149
 - package/artifacts/contracts/pool/PoolLib.sol/PoolLib.dbg.json +4 -0
 - package/artifacts/contracts/pool/PoolLib.sol/PoolLib.json +522 -0
 - package/artifacts/contracts/pool/PoolService.sol/PoolService.dbg.json +1 -1
 - package/artifacts/contracts/pool/PoolService.sol/PoolService.json +621 -413
 - package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.json +168 -68
 - package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.dbg.json +1 -1
 - package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.json +327 -62
 - package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.json +123 -43
 - package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.dbg.json +1 -1
 - package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.json +199 -213
 - package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.dbg.json +1 -1
 - package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.json +380 -45
 - package/artifacts/contracts/product/ClaimService.sol/ClaimService.dbg.json +1 -1
 - package/artifacts/contracts/product/ClaimService.sol/ClaimService.json +294 -189
 - package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.json +134 -86
 - package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.dbg.json +1 -1
 - package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.json +268 -10
 - package/artifacts/contracts/product/IClaimService.sol/IClaimService.dbg.json +1 -1
 - package/artifacts/contracts/product/IClaimService.sol/IClaimService.json +181 -19
 - package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.dbg.json +1 -1
 - package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.json +167 -56
 - package/artifacts/contracts/product/IPricingService.sol/IPricingService.dbg.json +1 -1
 - package/artifacts/contracts/product/IPricingService.sol/IPricingService.json +77 -3
 - package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.dbg.json +1 -1
 - package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.json +175 -171
 - package/artifacts/contracts/product/IRiskService.sol/IRiskService.dbg.json +1 -1
 - package/artifacts/contracts/product/IRiskService.sol/IRiskService.json +258 -22
 - package/artifacts/contracts/product/PolicyService.sol/PolicyService.dbg.json +1 -1
 - package/artifacts/contracts/product/PolicyService.sol/PolicyService.json +296 -194
 - package/artifacts/contracts/product/PolicyServiceLib.sol/PolicyServiceLib.dbg.json +4 -0
 - package/artifacts/contracts/product/PolicyServiceLib.sol/PolicyServiceLib.json +783 -0
 - package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.json +150 -78
 - package/artifacts/contracts/product/PricingService.sol/PricingService.dbg.json +1 -1
 - package/artifacts/contracts/product/PricingService.sol/PricingService.json +139 -114
 - package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.json +112 -60
 - package/artifacts/contracts/product/Product.sol/Product.dbg.json +1 -1
 - package/artifacts/contracts/product/Product.sol/Product.json +193 -207
 - package/artifacts/contracts/product/RiskService.sol/RiskService.dbg.json +1 -1
 - package/artifacts/contracts/product/RiskService.sol/RiskService.json +338 -87
 - package/artifacts/contracts/product/RiskServiceManager.sol/RiskServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/product/RiskServiceManager.sol/RiskServiceManager.json +123 -43
 - package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
 - package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
 - package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
 - package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +78 -19
 - package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
 - package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +56 -3
 - package/artifacts/contracts/registry/IRelease.sol/IRelease.dbg.json +4 -0
 - package/artifacts/contracts/registry/IRelease.sol/IRelease.json +24 -0
 - 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 +116 -57
 - package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.dbg.json +1 -1
 - package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.json +727 -453
 - package/artifacts/contracts/registry/RegistryAuthorization.sol/RegistryAuthorization.dbg.json +4 -0
 - package/artifacts/contracts/registry/RegistryAuthorization.sol/RegistryAuthorization.json +1074 -0
 - package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
 - package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +89 -37
 - package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +99 -39
 - package/artifacts/contracts/registry/ReleaseAdmin.sol/ReleaseAdmin.dbg.json +4 -0
 - package/artifacts/contracts/registry/ReleaseAdmin.sol/ReleaseAdmin.json +2152 -0
 - package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.dbg.json +1 -1
 - package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.json +2 -2
 - package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.dbg.json +1 -1
 - package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.json +386 -64
 - package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.dbg.json +1 -1
 - package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.json +437 -26
 - package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
 - package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +120 -60
 - package/artifacts/contracts/shared/Component.sol/Component.dbg.json +1 -1
 - package/artifacts/contracts/shared/Component.sol/Component.json +66 -86
 - package/artifacts/contracts/shared/ComponentService.sol/ComponentService.dbg.json +1 -1
 - package/artifacts/contracts/shared/ComponentService.sol/ComponentService.json +308 -542
 - package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.json +136 -84
 - package/artifacts/contracts/shared/ContractLib.sol/ContractLib.dbg.json +1 -1
 - package/artifacts/contracts/shared/ContractLib.sol/ContractLib.json +544 -4
 - package/artifacts/contracts/shared/ContractLib.sol/IInstanceAdminHelper.dbg.json +4 -0
 - package/artifacts/contracts/shared/ContractLib.sol/IInstanceAdminHelper.json +24 -0
 - package/artifacts/contracts/shared/ContractLib.sol/ITargetHelper.dbg.json +4 -0
 - package/artifacts/contracts/shared/ContractLib.sol/ITargetHelper.json +30 -0
 - package/artifacts/contracts/shared/ContractLib.sol/ITokenRegistryHelper.dbg.json +4 -0
 - package/artifacts/contracts/shared/ContractLib.sol/ITokenRegistryHelper.json +40 -0
 - package/artifacts/contracts/shared/IComponent.sol/IComponent.dbg.json +1 -1
 - package/artifacts/contracts/shared/IComponent.sol/IComponent.json +48 -50
 - package/artifacts/contracts/shared/IComponentService.sol/IComponentService.dbg.json +1 -1
 - package/artifacts/contracts/shared/IComponentService.sol/IComponentService.json +171 -356
 - package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.dbg.json +1 -1
 - package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.json +48 -64
 - package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
 - package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.json +43 -6
 - package/artifacts/contracts/shared/ILifecycle.sol/ILifecycle.dbg.json +1 -1
 - package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
 - package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +19 -0
 - 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/IRegisterable.sol/IRegisterable.json +139 -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/IService.sol/IService.json +56 -3
 - package/artifacts/contracts/shared/InitializableERC165.sol/InitializableERC165.dbg.json +1 -1
 - package/artifacts/contracts/shared/InitializableERC165.sol/InitializableERC165.json +2 -2
 - package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.dbg.json +1 -1
 - package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.json +66 -100
 - package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
 - package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.json +43 -6
 - package/artifacts/contracts/shared/Lifecycle.sol/Lifecycle.dbg.json +1 -1
 - package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.dbg.json +1 -1
 - package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.json +2 -2
 - package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
 - package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +21 -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/Registerable.sol/Registerable.dbg.json +1 -1
 - package/artifacts/contracts/shared/Registerable.sol/Registerable.json +137 -62
 - 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 +51 -11
 - package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
 - package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +289 -112
 - package/artifacts/contracts/shared/TokenHandler.sol/TokenHandlerBase.dbg.json +4 -0
 - package/artifacts/contracts/shared/TokenHandler.sol/TokenHandlerBase.json +484 -0
 - package/artifacts/contracts/shared/TokenHandlerDeployerLib.sol/TokenHandlerDeployerLib.dbg.json +1 -1
 - package/artifacts/contracts/shared/TokenHandlerDeployerLib.sol/TokenHandlerDeployerLib.json +70 -30
 - package/artifacts/contracts/staking/IStaking.sol/IStaking.dbg.json +1 -1
 - package/artifacts/contracts/staking/IStaking.sol/IStaking.json +1446 -154
 - package/artifacts/contracts/staking/IStakingService.sol/IStakingService.dbg.json +1 -1
 - package/artifacts/contracts/staking/IStakingService.sol/IStakingService.json +214 -110
 - package/artifacts/contracts/staking/ITargetLimitHandler.sol/ITargetLimitHandler.dbg.json +4 -0
 - package/artifacts/contracts/staking/ITargetLimitHandler.sol/ITargetLimitHandler.json +50 -0
 - package/artifacts/contracts/staking/Staking.sol/Staking.dbg.json +1 -1
 - package/artifacts/contracts/staking/Staking.sol/Staking.json +1583 -286
 - package/artifacts/contracts/staking/StakingLib.sol/StakingLib.dbg.json +4 -0
 - package/artifacts/contracts/staking/StakingLib.sol/StakingLib.json +470 -0
 - package/artifacts/contracts/staking/StakingManager.sol/StakingManager.dbg.json +1 -1
 - package/artifacts/contracts/staking/StakingManager.sol/StakingManager.json +140 -69
 - package/artifacts/contracts/staking/StakingReader.sol/StakingReader.dbg.json +1 -1
 - package/artifacts/contracts/staking/StakingReader.sol/StakingReader.json +294 -177
 - package/artifacts/contracts/staking/StakingService.sol/StakingService.dbg.json +1 -1
 - package/artifacts/contracts/staking/StakingService.sol/StakingService.json +257 -162
 - package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.dbg.json +1 -1
 - package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.json +102 -46
 - package/artifacts/contracts/staking/StakingStore.sol/StakingStore.dbg.json +1 -1
 - package/artifacts/contracts/staking/StakingStore.sol/StakingStore.json +1632 -818
 - package/artifacts/contracts/staking/TargetHandler.sol/TargetHandler.dbg.json +4 -0
 - package/artifacts/contracts/staking/TargetHandler.sol/TargetHandler.json +309 -0
 - package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.dbg.json +1 -1
 - package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.json +160 -88
 - package/artifacts/contracts/type/AddressSet.sol/LibAddressSet.dbg.json +1 -1
 - package/artifacts/contracts/type/Amount.sol/AmountLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Amount.sol/AmountLib.json +11 -11
 - package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.json +45 -19
 - package/artifacts/contracts/type/ChainId.sol/ChainIdLib.dbg.json +4 -0
 - package/artifacts/contracts/type/ChainId.sol/ChainIdLib.json +193 -0
 - package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
 - package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.json +2 -2
 - package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
 - package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.json +2 -2
 - package/artifacts/contracts/type/Fee.sol/FeeLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Fee.sol/FeeLib.json +94 -38
 - package/artifacts/contracts/type/Key32.sol/Key32Lib.dbg.json +1 -1
 - package/artifacts/contracts/type/Key32.sol/Key32Lib.json +2 -2
 - package/artifacts/contracts/type/Key32Set.sol/LibKey32Set.dbg.json +4 -0
 - package/artifacts/contracts/type/Key32Set.sol/LibKey32Set.json +33 -0
 - package/artifacts/contracts/type/NftId.sol/NftIdLib.dbg.json +1 -1
 - package/artifacts/contracts/type/NftId.sol/NftIdLib.json +23 -4
 - package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
 - package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.json +2 -2
 - package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
 - package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.json +33 -31
 - package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
 - package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.json +2 -2
 - package/artifacts/contracts/type/Referral.sol/ReferralLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Referral.sol/ReferralLib.json +2 -2
 - package/artifacts/contracts/type/RequestId.sol/RequestIdLib.dbg.json +1 -1
 - package/artifacts/contracts/type/RequestId.sol/RequestIdLib.json +2 -2
 - package/artifacts/contracts/type/RiskId.sol/RiskIdLib.dbg.json +1 -1
 - package/artifacts/contracts/type/RiskId.sol/RiskIdLib.json +69 -7
 - package/artifacts/contracts/type/RoleId.sol/RoleIdLib.dbg.json +1 -1
 - package/artifacts/contracts/type/RoleId.sol/RoleIdLib.json +42 -157
 - package/artifacts/contracts/type/Seconds.sol/SecondsLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Seconds.sol/SecondsLib.json +45 -2
 - package/artifacts/contracts/type/Selector.sol/SelectorLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Selector.sol/SelectorLib.json +21 -2
 - package/artifacts/contracts/type/Selector.sol/SelectorSetLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Selector.sol/SelectorSetLib.json +2 -2
 - package/artifacts/contracts/type/StateId.sol/StateIdLib.dbg.json +1 -1
 - package/artifacts/contracts/type/String.sol/StrLib.dbg.json +1 -1
 - package/artifacts/contracts/type/String.sol/StrLib.json +50 -2
 - package/artifacts/contracts/type/Timestamp.sol/TimestampLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Timestamp.sol/TimestampLib.json +3 -3
 - package/artifacts/contracts/type/UFixed.sol/UFixedLib.dbg.json +1 -1
 - package/artifacts/contracts/type/UFixed.sol/UFixedLib.json +61 -37
 - package/artifacts/contracts/type/Version.sol/VersionLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Version.sol/VersionLib.json +2 -21
 - package/artifacts/contracts/type/Version.sol/VersionPartLib.dbg.json +1 -1
 - package/artifacts/contracts/type/Version.sol/VersionPartLib.json +101 -2
 - package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.dbg.json +1 -1
 - package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.json +10 -0
 - package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.dbg.json +1 -1
 - package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.json +79 -25
 - package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
 - package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +15 -2
 - package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.dbg.json +1 -1
 - package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.json +10 -0
 - package/contracts/accounting/AccountingService.sol +274 -0
 - package/contracts/accounting/AccountingServiceManager.sol +38 -0
 - package/contracts/accounting/IAccountingService.sol +47 -0
 - package/contracts/authorization/AccessAdmin.sol +429 -245
 - package/contracts/authorization/AccessAdminLib.sol +396 -0
 - package/contracts/authorization/AccessManagerCloneable.sol +146 -4
 - package/contracts/authorization/Authorization.sol +142 -262
 - package/contracts/authorization/IAccess.sol +25 -7
 - package/contracts/authorization/IAccessAdmin.sol +87 -80
 - package/contracts/authorization/IAuthorization.sol +9 -43
 - package/contracts/authorization/IServiceAuthorization.sol +55 -17
 - package/contracts/authorization/ServiceAuthorization.sol +248 -34
 - package/contracts/distribution/BasicDistribution.sol +18 -16
 - package/contracts/distribution/BasicDistributionAuthorization.sol +30 -10
 - package/contracts/distribution/Distribution.sol +43 -81
 - package/contracts/distribution/DistributionService.sol +192 -99
 - package/contracts/distribution/DistributionServiceManager.sol +1 -1
 - package/contracts/distribution/IDistributionComponent.sol +3 -10
 - package/contracts/distribution/IDistributionService.sol +38 -24
 - package/contracts/examples/fire/FirePool.sol +21 -8
 - package/contracts/examples/fire/FirePoolAuthorization.sol +2 -1
 - package/contracts/examples/fire/FireProduct.sol +38 -20
 - package/contracts/examples/fire/FireProductAuthorization.sol +2 -1
 - package/contracts/examples/unpermissioned/SimpleDistribution.sol +39 -8
 - package/contracts/examples/unpermissioned/SimpleDistributionAuthorization.sol +28 -0
 - package/contracts/examples/unpermissioned/SimpleOracle.sol +4 -8
 - package/contracts/examples/unpermissioned/SimplePool.sol +32 -6
 - package/contracts/examples/unpermissioned/SimplePoolAuthorization.sol +28 -0
 - package/contracts/examples/unpermissioned/SimpleProduct.sol +132 -46
 - package/contracts/examples/unpermissioned/SimpleProductAuthorization.sol +28 -0
 - package/contracts/instance/BaseStore.sol +97 -0
 - package/contracts/instance/BundleSet.sol +42 -38
 - package/contracts/instance/IBaseStore.sol +43 -0
 - package/contracts/instance/IInstance.sol +109 -19
 - package/contracts/instance/IInstanceService.sol +61 -14
 - package/contracts/instance/Instance.sol +191 -65
 - package/contracts/instance/InstanceAdmin.sol +271 -171
 - package/contracts/instance/InstanceAuthorizationV3.sol +139 -58
 - package/contracts/instance/InstanceReader.sol +451 -312
 - package/contracts/instance/InstanceService.sol +315 -214
 - package/contracts/instance/InstanceServiceManager.sol +1 -1
 - package/contracts/instance/InstanceStore.sol +14 -30
 - package/contracts/instance/ProductStore.sol +110 -0
 - package/contracts/instance/RiskSet.sol +126 -0
 - package/contracts/instance/TargetNames.sol +10 -0
 - package/contracts/instance/base/BalanceStore.sol +4 -6
 - package/contracts/instance/base/ObjectCounter.sol +1 -2
 - package/contracts/instance/base/ObjectLifecycle.sol +6 -8
 - package/contracts/instance/base/ObjectSet.sol +31 -33
 - package/contracts/instance/base/ObjectSetHelperLib.sol +30 -0
 - package/contracts/instance/module/IBundle.sol +6 -5
 - package/contracts/instance/module/IComponents.sol +20 -9
 - package/contracts/instance/module/IDistribution.sol +21 -8
 - package/contracts/instance/module/IPolicy.sol +28 -7
 - package/contracts/instance/module/IRisk.sol +5 -0
 - package/contracts/oracle/BasicOracle.sol +2 -4
 - package/contracts/oracle/BasicOracleAuthorization.sol +15 -8
 - package/contracts/oracle/IOracle.sol +9 -4
 - package/contracts/oracle/Oracle.sol +3 -5
 - package/contracts/oracle/OracleService.sol +98 -79
 - package/contracts/oracle/OracleServiceManager.sol +1 -1
 - package/contracts/pool/BasicPool.sol +25 -17
 - package/contracts/pool/BasicPoolAuthorization.sol +34 -10
 - package/contracts/pool/BundleService.sol +75 -182
 - package/contracts/pool/BundleServiceManager.sol +1 -1
 - package/contracts/pool/IBundleService.sol +28 -55
 - package/contracts/pool/IPoolComponent.sol +1 -7
 - package/contracts/pool/IPoolService.sol +65 -62
 - package/contracts/pool/Pool.sol +109 -111
 - package/contracts/pool/PoolLib.sol +341 -0
 - package/contracts/pool/PoolService.sol +299 -229
 - package/contracts/pool/PoolServiceManager.sol +1 -1
 - package/contracts/product/ApplicationService.sol +93 -25
 - package/contracts/product/ApplicationServiceManager.sol +1 -1
 - package/contracts/product/BasicProduct.sol +9 -13
 - package/contracts/product/BasicProductAuthorization.sol +32 -11
 - package/contracts/product/ClaimService.sol +221 -207
 - package/contracts/product/ClaimServiceManager.sol +1 -1
 - package/contracts/product/IApplicationService.sol +28 -3
 - package/contracts/product/IClaimService.sol +18 -5
 - package/contracts/product/IPolicyService.sol +34 -12
 - package/contracts/product/IPricingService.sol +1 -0
 - package/contracts/product/IProductComponent.sol +4 -1
 - package/contracts/product/IRiskService.sol +25 -10
 - package/contracts/product/PolicyService.sol +258 -304
 - package/contracts/product/PolicyServiceLib.sol +139 -0
 - package/contracts/product/PolicyServiceManager.sol +1 -1
 - package/contracts/product/PricingService.sol +52 -46
 - package/contracts/product/PricingServiceManager.sol +3 -3
 - package/contracts/product/Product.sol +104 -66
 - package/contracts/product/RiskService.sol +128 -34
 - package/contracts/product/RiskServiceManager.sol +1 -1
 - package/contracts/registry/ChainNft.sol +4 -2
 - package/contracts/registry/IRegistry.sol +25 -24
 - package/contracts/registry/IRelease.sol +29 -0
 - package/contracts/registry/Registry.sol +31 -12
 - package/contracts/registry/RegistryAdmin.sol +107 -364
 - package/contracts/registry/RegistryAuthorization.sol +336 -0
 - package/contracts/registry/RegistryService.sol +4 -4
 - package/contracts/registry/RegistryServiceManager.sol +1 -1
 - package/contracts/registry/ReleaseAdmin.sol +195 -0
 - package/contracts/registry/ReleaseLifecycle.sol +2 -0
 - package/contracts/registry/ReleaseRegistry.sol +158 -134
 - package/contracts/registry/ServiceAuthorizationV3.sol +200 -52
 - package/contracts/registry/TokenRegistry.sol +61 -59
 - package/contracts/shared/Component.sol +56 -113
 - package/contracts/shared/ComponentService.sol +392 -406
 - package/contracts/shared/ComponentServiceManager.sol +1 -1
 - package/contracts/shared/ContractLib.sol +277 -3
 - package/contracts/shared/IComponent.sol +2 -18
 - package/contracts/shared/IComponentService.sol +28 -38
 - package/contracts/shared/IInstanceLinkedComponent.sol +0 -11
 - package/contracts/shared/IKeyValueStore.sol +9 -1
 - package/contracts/shared/INftOwnable.sol +2 -0
 - package/contracts/shared/IRegisterable.sol +15 -5
 - package/contracts/shared/IService.sol +3 -5
 - package/contracts/shared/InitializableERC165.sol +9 -1
 - package/contracts/shared/InstanceLinkedComponent.sol +8 -27
 - package/contracts/shared/KeyValueStore.sol +3 -3
 - package/contracts/shared/NftOwnable.sol +8 -6
 - package/contracts/shared/PolicyHolder.sol +4 -3
 - package/contracts/shared/Registerable.sol +41 -20
 - package/contracts/shared/RegistryLinked.sol +7 -13
 - package/contracts/shared/Service.sol +13 -30
 - package/contracts/shared/TokenHandler.sol +264 -105
 - package/contracts/shared/TokenHandlerDeployerLib.sol +10 -2
 - package/contracts/staking/IStaking.sol +271 -72
 - package/contracts/staking/IStakingService.sol +45 -75
 - package/contracts/staking/ITargetLimitHandler.sol +17 -0
 - package/contracts/staking/Staking.sol +521 -220
 - package/contracts/staking/{StakeManagerLib.sol → StakingLib.sol} +55 -84
 - package/contracts/staking/StakingManager.sol +4 -3
 - package/contracts/staking/StakingReader.sol +58 -77
 - package/contracts/staking/StakingService.sol +62 -148
 - package/contracts/staking/StakingServiceManager.sol +6 -4
 - package/contracts/staking/StakingStore.sol +1093 -330
 - package/contracts/staking/TargetHandler.sol +132 -0
 - package/contracts/staking/TargetManagerLib.sol +69 -46
 - package/contracts/type/Amount.sol +4 -0
 - package/contracts/type/Blocknumber.sol +15 -15
 - package/contracts/type/ChainId.sol +101 -0
 - package/contracts/type/Fee.sol +8 -8
 - package/contracts/type/Key32.sol +2 -2
 - package/contracts/type/Key32Set.sol +62 -0
 - package/contracts/type/NftId.sol +6 -0
 - package/contracts/type/ObjectType.sol +69 -38
 - package/contracts/type/RiskId.sol +26 -8
 - package/contracts/type/RoleId.sol +63 -45
 - package/contracts/type/Seconds.sol +19 -0
 - package/contracts/type/Selector.sol +5 -0
 - package/contracts/type/String.sol +12 -0
 - package/contracts/type/Timestamp.sol +4 -7
 - package/contracts/type/UFixed.sol +35 -127
 - package/contracts/type/Version.sol +54 -5
 - package/contracts/upgradeability/IVersionable.sol +3 -0
 - package/contracts/upgradeability/ProxyManager.sol +26 -12
 - package/contracts/upgradeability/UpgradableProxyWithAdmin.sol +12 -2
 - package/contracts/upgradeability/Versionable.sol +6 -3
 - package/package.json +4 -4
 - package/artifacts/contracts/authorization/ReleaseAccessManager.sol/ReleaseAccessManager.dbg.json +0 -4
 - package/artifacts/contracts/authorization/ReleaseAccessManager.sol/ReleaseAccessManager.json +0 -1196
 - package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +0 -4
 - package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +0 -129
 - package/artifacts/contracts/shared/ComponentServiceHelperLib.sol/ComponentServiceHelperLib.dbg.json +0 -4
 - package/artifacts/contracts/shared/ComponentServiceHelperLib.sol/ComponentServiceHelperLib.json +0 -206
 - package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.dbg.json +0 -4
 - package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.json +0 -474
 - package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.dbg.json +0 -4
 - package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.json +0 -440
 - package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.dbg.json +0 -4
 - package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.json +0 -205
 - package/artifacts/contracts/type/UFixed.sol/MathLib.dbg.json +0 -4
 - package/artifacts/contracts/type/UFixed.sol/MathLib.json +0 -16
 - package/contracts/authorization/ReleaseAccessManager.sol +0 -38
 - package/contracts/instance/module/IAccess.sol +0 -46
 - package/contracts/shared/ComponentServiceHelperLib.sol +0 -118
 - package/contracts/shared/ComponentVerifyingService.sol +0 -126
 - package/contracts/staking/StakingLifecycle.sol +0 -23
 
| 
         @@ -1,33 +1,39 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            // SPDX-License-Identifier: Apache-2.0
         
     | 
| 
       2 
2 
     | 
    
         
             
            pragma solidity ^0.8.20;
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            import { 
     | 
| 
       5 
     | 
    
         
            -
            import {IInstance} from "../instance/IInstance.sol";
         
     | 
| 
      
 4 
     | 
    
         
            +
            import {IAccountingService} from "../accounting/IAccountingService.sol";
         
     | 
| 
       6 
5 
     | 
    
         
             
            import {IComponentService} from "../shared/IComponentService.sol";
         
     | 
| 
      
 6 
     | 
    
         
            +
            import {IDistribution} from "../instance/module/IDistribution.sol";
         
     | 
| 
      
 7 
     | 
    
         
            +
            import {IDistributionService} from "./IDistributionService.sol";
         
     | 
| 
      
 8 
     | 
    
         
            +
            import {IInstance} from "../instance/IInstance.sol";
         
     | 
| 
       7 
9 
     | 
    
         
             
            import {IInstanceService} from "../instance/IInstanceService.sol";
         
     | 
| 
      
 10 
     | 
    
         
            +
            import {IRegistry} from "../registry/IRegistry.sol";
         
     | 
| 
       8 
11 
     | 
    
         
             
            import {IRegistryService} from "../registry/IRegistryService.sol";
         
     | 
| 
       9 
     | 
    
         
            -
            import {InstanceReader} from "../instance/InstanceReader.sol";
         
     | 
| 
       10 
12 
     | 
    
         
             
            import {IComponents} from "../instance/module/IComponents.sol";
         
     | 
| 
       11 
13 
     | 
    
         
             
            import {IPolicy} from "../instance/module/IPolicy.sol";
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
15 
     | 
    
         
             
            import {Amount, AmountLib} from "../type/Amount.sol";
         
     | 
| 
      
 16 
     | 
    
         
            +
            import {ContractLib} from "../shared/ContractLib.sol";
         
     | 
| 
      
 17 
     | 
    
         
            +
            import {DistributorType, DistributorTypeLib} from "../type/DistributorType.sol";
         
     | 
| 
       14 
18 
     | 
    
         
             
            import {NftId, NftIdLib} from "../type/NftId.sol";
         
     | 
| 
       15 
19 
     | 
    
         
             
            import {KEEP_STATE} from "../type/StateId.sol";
         
     | 
| 
       16 
     | 
    
         
            -
            import {ObjectType, COMPONENT, DISTRIBUTION, INSTANCE, DISTRIBUTION, DISTRIBUTOR, REGISTRY} from "../type/ObjectType.sol";
         
     | 
| 
       17 
     | 
    
         
            -
            import { 
     | 
| 
       18 
     | 
    
         
            -
            import {IDistributionService} from "./IDistributionService.sol";
         
     | 
| 
       19 
     | 
    
         
            -
            import {UFixed} from "../type/UFixed.sol";
         
     | 
| 
       20 
     | 
    
         
            -
            import {DistributorType, DistributorTypeLib} from "../type/DistributorType.sol";
         
     | 
| 
       21 
     | 
    
         
            -
            import {ReferralId, ReferralLib} from "../type/Referral.sol";
         
     | 
| 
       22 
     | 
    
         
            -
            import {Timestamp, TimestampLib} from "../type/Timestamp.sol";
         
     | 
| 
       23 
     | 
    
         
            -
            import {IDistribution} from "../instance/module/IDistribution.sol";
         
     | 
| 
      
 20 
     | 
    
         
            +
            import {ObjectType, ACCOUNTING, COMPONENT, DISTRIBUTION, INSTANCE, DISTRIBUTION, DISTRIBUTOR, REGISTRY} from "../type/ObjectType.sol";
         
     | 
| 
      
 21 
     | 
    
         
            +
            import {InstanceReader} from "../instance/InstanceReader.sol";
         
     | 
| 
       24 
22 
     | 
    
         
             
            import {InstanceStore} from "../instance/InstanceStore.sol";
         
     | 
| 
      
 23 
     | 
    
         
            +
            // TODO PoolLib feels wrong, should likely go in a component type independent lib
         
     | 
| 
      
 24 
     | 
    
         
            +
            import {PoolLib} from "../pool/PoolLib.sol";
         
     | 
| 
      
 25 
     | 
    
         
            +
            import {ReferralId, ReferralStatus, ReferralLib, REFERRAL_OK, REFERRAL_ERROR_UNKNOWN, REFERRAL_ERROR_EXPIRED, REFERRAL_ERROR_EXHAUSTED} from "../type/Referral.sol";
         
     | 
| 
      
 26 
     | 
    
         
            +
            import {Seconds} from "../type/Seconds.sol";
         
     | 
| 
      
 27 
     | 
    
         
            +
            import {Service} from "../shared/Service.sol";
         
     | 
| 
      
 28 
     | 
    
         
            +
            import {Timestamp, TimestampLib} from "../type/Timestamp.sol";
         
     | 
| 
      
 29 
     | 
    
         
            +
            import {UFixed, UFixedLib} from "../type/UFixed.sol";
         
     | 
| 
       25 
30 
     | 
    
         | 
| 
       26 
31 
     | 
    
         | 
| 
       27 
32 
     | 
    
         
             
            contract DistributionService is
         
     | 
| 
       28 
     | 
    
         
            -
                 
     | 
| 
      
 33 
     | 
    
         
            +
                Service,
         
     | 
| 
       29 
34 
     | 
    
         
             
                IDistributionService
         
     | 
| 
       30 
35 
     | 
    
         
             
            {
         
     | 
| 
      
 36 
     | 
    
         
            +
                IAccountingService private _accountingService;
         
     | 
| 
       31 
37 
     | 
    
         
             
                IComponentService private _componentService;
         
     | 
| 
       32 
38 
     | 
    
         
             
                IInstanceService private _instanceService;
         
     | 
| 
       33 
39 
     | 
    
         
             
                IRegistryService private _registryService;
         
     | 
| 
         @@ -41,12 +47,13 @@ contract DistributionService is 
     | 
|
| 
       41 
47 
     | 
    
         
             
                    initializer()
         
     | 
| 
       42 
48 
     | 
    
         
             
                {
         
     | 
| 
       43 
49 
     | 
    
         
             
                    (
         
     | 
| 
       44 
     | 
    
         
            -
                        address  
     | 
| 
       45 
     | 
    
         
            -
                        address  
     | 
| 
      
 50 
     | 
    
         
            +
                        address authority,
         
     | 
| 
      
 51 
     | 
    
         
            +
                        address registry
         
     | 
| 
       46 
52 
     | 
    
         
             
                    ) = abi.decode(data, (address, address));
         
     | 
| 
       47 
53 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
                     
     | 
| 
      
 54 
     | 
    
         
            +
                    __Service_init(authority, registry, owner);
         
     | 
| 
       49 
55 
     | 
    
         | 
| 
      
 56 
     | 
    
         
            +
                    _accountingService = IAccountingService(_getServiceAddress(ACCOUNTING()));
         
     | 
| 
       50 
57 
     | 
    
         
             
                    _componentService = IComponentService(_getServiceAddress(COMPONENT()));
         
     | 
| 
       51 
58 
     | 
    
         
             
                    _instanceService = IInstanceService(_getServiceAddress(INSTANCE()));
         
     | 
| 
       52 
59 
     | 
    
         
             
                    _registryService = IRegistryService(_getServiceAddress(REGISTRY()));
         
     | 
| 
         @@ -61,47 +68,51 @@ contract DistributionService is 
     | 
|
| 
       61 
68 
     | 
    
         
             
                    UFixed maxDiscountPercentage,
         
     | 
| 
       62 
69 
     | 
    
         
             
                    UFixed commissionPercentage,
         
     | 
| 
       63 
70 
     | 
    
         
             
                    uint32 maxReferralCount,
         
     | 
| 
       64 
     | 
    
         
            -
                     
     | 
| 
      
 71 
     | 
    
         
            +
                    Seconds maxReferralLifetime,
         
     | 
| 
       65 
72 
     | 
    
         
             
                    bool allowSelfReferrals,
         
     | 
| 
       66 
73 
     | 
    
         
             
                    bool allowRenewals,
         
     | 
| 
       67 
74 
     | 
    
         
             
                    bytes memory data
         
     | 
| 
       68 
75 
     | 
    
         
             
                )
         
     | 
| 
       69 
76 
     | 
    
         
             
                    external
         
     | 
| 
      
 77 
     | 
    
         
            +
                    virtual
         
     | 
| 
      
 78 
     | 
    
         
            +
                    restricted()
         
     | 
| 
       70 
79 
     | 
    
         
             
                    returns (DistributorType distributorType)
         
     | 
| 
       71 
80 
     | 
    
         
             
                {
         
     | 
| 
       72 
     | 
    
         
            -
                    (NftId distributionNftId 
     | 
| 
       73 
     | 
    
         
            -
                    InstanceReader instanceReader = instance.getInstanceReader();
         
     | 
| 
      
 81 
     | 
    
         
            +
                    (NftId distributionNftId, IInstance instance) = _getAndVerifyActiveDistribution();
         
     | 
| 
       74 
82 
     | 
    
         | 
| 
       75 
83 
     | 
    
         
             
                    {
         
     | 
| 
       76 
     | 
    
         
            -
                        NftId productNftId =  
     | 
| 
       77 
     | 
    
         
            -
                        IComponents. 
     | 
| 
      
 84 
     | 
    
         
            +
                        NftId productNftId = getRegistry().getParentNftId(distributionNftId);
         
     | 
| 
      
 85 
     | 
    
         
            +
                        IComponents.FeeInfo memory feeInfo = instance.getInstanceReader().getFeeInfo(productNftId);
         
     | 
| 
       78 
86 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
                        UFixed variableDistributionFees =  
     | 
| 
       80 
     | 
    
         
            -
                        UFixed variableFeesPartsTotal =  
     | 
| 
      
 87 
     | 
    
         
            +
                        UFixed variableDistributionFees = feeInfo.distributionFee.fractionalFee;
         
     | 
| 
      
 88 
     | 
    
         
            +
                        UFixed variableFeesPartsTotal = feeInfo.minDistributionOwnerFee.fractionalFee + commissionPercentage;
         
     | 
| 
       81 
89 
     | 
    
         | 
| 
       82 
90 
     | 
    
         
             
                        if (variableFeesPartsTotal > variableDistributionFees) {
         
     | 
| 
       83 
91 
     | 
    
         
             
                            revert ErrorDistributionServiceVariableFeesTooHight(variableDistributionFees.toInt1000(), variableFeesPartsTotal.toInt1000());
         
     | 
| 
       84 
92 
     | 
    
         
             
                        }
         
     | 
| 
       85 
93 
     | 
    
         
             
                        UFixed maxDiscountPercentageLimit = variableDistributionFees - variableFeesPartsTotal;
         
     | 
| 
       86 
94 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
                        if (maxDiscountPercentage 
     | 
| 
      
 95 
     | 
    
         
            +
                        if (maxDiscountPercentage > maxDiscountPercentageLimit) {
         
     | 
| 
       88 
96 
     | 
    
         
             
                            revert ErrorDistributionServiceMaxDiscountTooHigh(maxDiscountPercentage.toInt1000(), maxDiscountPercentageLimit.toInt1000());
         
     | 
| 
       89 
97 
     | 
    
         
             
                        }
         
     | 
| 
       90 
98 
     | 
    
         
             
                    }
         
     | 
| 
       91 
99 
     | 
    
         | 
| 
       92 
100 
     | 
    
         
             
                    distributorType = DistributorTypeLib.toDistributorType(distributionNftId, name);
         
     | 
| 
       93 
     | 
    
         
            -
                    IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo(
         
     | 
| 
       94 
     | 
    
         
            -
                        name,
         
     | 
| 
       95 
     | 
    
         
            -
                         
     | 
| 
       96 
     | 
    
         
            -
                         
     | 
| 
       97 
     | 
    
         
            -
                         
     | 
| 
       98 
     | 
    
         
            -
                         
     | 
| 
       99 
     | 
    
         
            -
                         
     | 
| 
       100 
     | 
    
         
            -
                         
     | 
| 
       101 
     | 
    
         
            -
                         
     | 
| 
       102 
     | 
    
         
            -
                         
     | 
| 
      
 101 
     | 
    
         
            +
                    IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo({
         
     | 
| 
      
 102 
     | 
    
         
            +
                        name: name,
         
     | 
| 
      
 103 
     | 
    
         
            +
                        distributionNftId: distributionNftId,
         
     | 
| 
      
 104 
     | 
    
         
            +
                        minDiscountPercentage: minDiscountPercentage,
         
     | 
| 
      
 105 
     | 
    
         
            +
                        maxDiscountPercentage: maxDiscountPercentage,
         
     | 
| 
      
 106 
     | 
    
         
            +
                        commissionPercentage: commissionPercentage,
         
     | 
| 
      
 107 
     | 
    
         
            +
                        maxReferralCount: maxReferralCount,
         
     | 
| 
      
 108 
     | 
    
         
            +
                        maxReferralLifetime: maxReferralLifetime,
         
     | 
| 
      
 109 
     | 
    
         
            +
                        allowSelfReferrals: allowSelfReferrals,
         
     | 
| 
      
 110 
     | 
    
         
            +
                        allowRenewals: allowRenewals,
         
     | 
| 
      
 111 
     | 
    
         
            +
                        data: data});
         
     | 
| 
       103 
112 
     | 
    
         | 
| 
       104 
113 
     | 
    
         
             
                    instance.getInstanceStore().createDistributorType(distributorType, info);
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                    emit LogDistributionServiceDistributorTypeCreated(distributionNftId, name);
         
     | 
| 
       105 
116 
     | 
    
         
             
                }
         
     | 
| 
       106 
117 
     | 
    
         | 
| 
       107 
118 
     | 
    
         | 
| 
         @@ -112,9 +123,11 @@ contract DistributionService is 
     | 
|
| 
       112 
123 
     | 
    
         
             
                )
         
     | 
| 
       113 
124 
     | 
    
         
             
                    external 
         
     | 
| 
       114 
125 
     | 
    
         
             
                    virtual
         
     | 
| 
      
 126 
     | 
    
         
            +
                    restricted()
         
     | 
| 
       115 
127 
     | 
    
         
             
                    returns (NftId distributorNftId)
         
     | 
| 
       116 
128 
     | 
    
         
             
                {
         
     | 
| 
       117 
     | 
    
         
            -
                    (NftId distributionNftId 
     | 
| 
      
 129 
     | 
    
         
            +
                    (NftId distributionNftId, IInstance instance) = _getAndVerifyActiveDistribution();
         
     | 
| 
      
 130 
     | 
    
         
            +
                    _checkDistributionType(instance.getInstanceReader(), distributorType, distributionNftId);
         
     | 
| 
       118 
131 
     | 
    
         | 
| 
       119 
132 
     | 
    
         
             
                    distributorNftId = _registryService.registerDistributor(
         
     | 
| 
       120 
133 
     | 
    
         
             
                        IRegistry.ObjectInfo(
         
     | 
| 
         @@ -127,30 +140,38 @@ contract DistributionService is 
     | 
|
| 
       127 
140 
     | 
    
         
             
                            ""
         
     | 
| 
       128 
141 
     | 
    
         
             
                        ));
         
     | 
| 
       129 
142 
     | 
    
         | 
| 
       130 
     | 
    
         
            -
                    IDistribution.DistributorInfo memory info = IDistribution.DistributorInfo(
         
     | 
| 
       131 
     | 
    
         
            -
                        distributorType,
         
     | 
| 
       132 
     | 
    
         
            -
                        true,  
     | 
| 
       133 
     | 
    
         
            -
                         
     | 
| 
       134 
     | 
    
         
            -
                         
     | 
| 
      
 143 
     | 
    
         
            +
                    IDistribution.DistributorInfo memory info = IDistribution.DistributorInfo({
         
     | 
| 
      
 144 
     | 
    
         
            +
                        distributorType: distributorType,
         
     | 
| 
      
 145 
     | 
    
         
            +
                        active: true, 
         
     | 
| 
      
 146 
     | 
    
         
            +
                        numPoliciesSold: 0,
         
     | 
| 
      
 147 
     | 
    
         
            +
                        data: data});
         
     | 
| 
       135 
148 
     | 
    
         | 
| 
       136 
149 
     | 
    
         
             
                    instance.getInstanceStore().createDistributor(distributorNftId, info);
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                    emit LogDistributionServiceDistributorCreated(distributionNftId, distributorNftId, distributorType, distributor);
         
     | 
| 
       137 
152 
     | 
    
         
             
                }
         
     | 
| 
       138 
153 
     | 
    
         | 
| 
       139 
     | 
    
         
            -
                 
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
                 
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
                 
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
      
 154 
     | 
    
         
            +
                function changeDistributorType(
         
     | 
| 
      
 155 
     | 
    
         
            +
                    NftId distributorNftId,
         
     | 
| 
      
 156 
     | 
    
         
            +
                    DistributorType newDistributorType,
         
     | 
| 
      
 157 
     | 
    
         
            +
                    bytes memory data
         
     | 
| 
      
 158 
     | 
    
         
            +
                )
         
     | 
| 
      
 159 
     | 
    
         
            +
                    external
         
     | 
| 
      
 160 
     | 
    
         
            +
                    virtual
         
     | 
| 
      
 161 
     | 
    
         
            +
                    restricted()
         
     | 
| 
      
 162 
     | 
    
         
            +
                {
         
     | 
| 
      
 163 
     | 
    
         
            +
                    _checkNftType(distributorNftId, DISTRIBUTOR());
         
     | 
| 
      
 164 
     | 
    
         
            +
                    (NftId distributionNftId, IInstance instance) = _getAndVerifyActiveDistribution();
         
     | 
| 
      
 165 
     | 
    
         
            +
                    _checkDistributionType(instance.getInstanceReader(), newDistributorType, distributionNftId);
         
     | 
| 
      
 166 
     | 
    
         
            +
                    
         
     | 
| 
      
 167 
     | 
    
         
            +
                    IDistribution.DistributorInfo memory distributorInfo = instance.getInstanceReader().getDistributorInfo(distributorNftId);
         
     | 
| 
      
 168 
     | 
    
         
            +
                    DistributorType oldDistributorType = distributorInfo.distributorType;
         
     | 
| 
      
 169 
     | 
    
         
            +
                    distributorInfo.distributorType = newDistributorType;
         
     | 
| 
      
 170 
     | 
    
         
            +
                    distributorInfo.data = data;
         
     | 
| 
      
 171 
     | 
    
         
            +
                    instance.getInstanceStore().updateDistributor(distributorNftId, distributorInfo, KEEP_STATE());
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                    emit LogDistributionServiceDistributorTypeChanged(distributorNftId, oldDistributorType, newDistributorType);
         
     | 
| 
      
 174 
     | 
    
         
            +
                }
         
     | 
| 
       154 
175 
     | 
    
         | 
| 
       155 
176 
     | 
    
         | 
| 
       156 
177 
     | 
    
         
             
                function createReferral(
         
     | 
| 
         @@ -163,16 +184,22 @@ contract DistributionService is 
     | 
|
| 
       163 
184 
     | 
    
         
             
                )
         
     | 
| 
       164 
185 
     | 
    
         
             
                    external
         
     | 
| 
       165 
186 
     | 
    
         
             
                    virtual
         
     | 
| 
      
 187 
     | 
    
         
            +
                    restricted()
         
     | 
| 
       166 
188 
     | 
    
         
             
                    onlyNftOfType(distributorNftId, DISTRIBUTOR())
         
     | 
| 
       167 
189 
     | 
    
         
             
                    returns (ReferralId referralId)
         
     | 
| 
       168 
190 
     | 
    
         
             
                {
         
     | 
| 
       169 
     | 
    
         
            -
                    (NftId distributionNftId 
     | 
| 
      
 191 
     | 
    
         
            +
                    (NftId distributionNftId, IInstance instance) = _getAndVerifyActiveDistribution();
         
     | 
| 
       170 
192 
     | 
    
         | 
| 
       171 
193 
     | 
    
         
             
                    if (bytes(code).length == 0) {
         
     | 
| 
       172 
     | 
    
         
            -
                        revert  
     | 
| 
      
 194 
     | 
    
         
            +
                        revert ErrorDistributionServiceInvalidReferral();
         
     | 
| 
      
 195 
     | 
    
         
            +
                    }
         
     | 
| 
      
 196 
     | 
    
         
            +
                    if (expiryAt.eqz() || expiryAt < TimestampLib.current()) {
         
     | 
| 
      
 197 
     | 
    
         
            +
                        revert ErrorDistributionServiceExpirationInvalid(expiryAt);
         
     | 
| 
       173 
198 
     | 
    
         
             
                    }
         
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
                    NftId distributorDistributionNftId = getRegistry().getParentNftId(distributorNftId);
         
     | 
| 
      
 201 
     | 
    
         
            +
                    if (distributorDistributionNftId != distributionNftId) {
         
     | 
| 
      
 202 
     | 
    
         
            +
                        revert ErrorDistributionServiceDistributorDistributionMismatch(distributorNftId, distributorDistributionNftId, distributionNftId);
         
     | 
| 
       176 
203 
     | 
    
         
             
                    }
         
     | 
| 
       177 
204 
     | 
    
         | 
| 
       178 
205 
     | 
    
         
             
                    {
         
     | 
| 
         @@ -181,32 +208,35 @@ contract DistributionService is 
     | 
|
| 
       181 
208 
     | 
    
         
             
                        IDistribution.DistributorTypeInfo memory distributorTypeData = instanceReader.getDistributorTypeInfo(distributorType);
         
     | 
| 
       182 
209 
     | 
    
         | 
| 
       183 
210 
     | 
    
         
             
                        if (distributorTypeData.maxReferralCount < maxReferrals) {
         
     | 
| 
       184 
     | 
    
         
            -
                            revert  
     | 
| 
      
 211 
     | 
    
         
            +
                            revert ErrorDistributionServiceMaxReferralsExceeded(distributorTypeData.maxReferralCount, maxReferrals);
         
     | 
| 
       185 
212 
     | 
    
         
             
                        }
         
     | 
| 
       186 
213 
     | 
    
         
             
                        if (distributorTypeData.minDiscountPercentage > discountPercentage) {
         
     | 
| 
       187 
     | 
    
         
            -
                            revert  
     | 
| 
      
 214 
     | 
    
         
            +
                            revert ErrorDistributionServiceDiscountTooLow(distributorTypeData.minDiscountPercentage, discountPercentage);
         
     | 
| 
       188 
215 
     | 
    
         
             
                        }
         
     | 
| 
       189 
216 
     | 
    
         
             
                        if (distributorTypeData.maxDiscountPercentage < discountPercentage) {
         
     | 
| 
       190 
     | 
    
         
            -
                            revert  
     | 
| 
      
 217 
     | 
    
         
            +
                            revert ErrorDistributionServiceDiscountTooHigh(distributorTypeData.maxDiscountPercentage, discountPercentage);
         
     | 
| 
       191 
218 
     | 
    
         
             
                        }
         
     | 
| 
       192 
     | 
    
         
            -
                        if (expiryAt.toInt() - TimestampLib. 
     | 
| 
       193 
     | 
    
         
            -
                            revert  
     | 
| 
      
 219 
     | 
    
         
            +
                        if (expiryAt.toInt() - TimestampLib.current().toInt() > distributorTypeData.maxReferralLifetime.toInt()) {
         
     | 
| 
      
 220 
     | 
    
         
            +
                            revert ErrorDistributionServiceExpiryTooLong(distributorTypeData.maxReferralLifetime, expiryAt);
         
     | 
| 
       194 
221 
     | 
    
         
             
                        }
         
     | 
| 
       195 
222 
     | 
    
         
             
                    }
         
     | 
| 
       196 
223 
     | 
    
         | 
| 
       197 
224 
     | 
    
         
             
                    {
         
     | 
| 
       198 
225 
     | 
    
         
             
                        referralId = ReferralLib.toReferralId(distributionNftId, code);
         
     | 
| 
       199 
     | 
    
         
            -
                        IDistribution.ReferralInfo memory info = IDistribution.ReferralInfo(
         
     | 
| 
       200 
     | 
    
         
            -
                             
     | 
| 
       201 
     | 
    
         
            -
                             
     | 
| 
       202 
     | 
    
         
            -
                             
     | 
| 
       203 
     | 
    
         
            -
                             
     | 
| 
       204 
     | 
    
         
            -
                             
     | 
| 
       205 
     | 
    
         
            -
                             
     | 
| 
       206 
     | 
    
         
            -
                             
     | 
| 
       207 
     | 
    
         
            -
             
     | 
| 
      
 226 
     | 
    
         
            +
                        IDistribution.ReferralInfo memory info = IDistribution.ReferralInfo({
         
     | 
| 
      
 227 
     | 
    
         
            +
                            distributionNftId: distributionNftId,
         
     | 
| 
      
 228 
     | 
    
         
            +
                            distributorNftId: distributorNftId,
         
     | 
| 
      
 229 
     | 
    
         
            +
                            referralCode: code,
         
     | 
| 
      
 230 
     | 
    
         
            +
                            discountPercentage: discountPercentage,
         
     | 
| 
      
 231 
     | 
    
         
            +
                            maxReferrals: maxReferrals,
         
     | 
| 
      
 232 
     | 
    
         
            +
                            usedReferrals: 0, 
         
     | 
| 
      
 233 
     | 
    
         
            +
                            expiryAt: expiryAt,
         
     | 
| 
      
 234 
     | 
    
         
            +
                            data: data
         
     | 
| 
      
 235 
     | 
    
         
            +
                        });
         
     | 
| 
       208 
236 
     | 
    
         | 
| 
       209 
237 
     | 
    
         
             
                        instance.getInstanceStore().createReferral(referralId, info);
         
     | 
| 
      
 238 
     | 
    
         
            +
             
     | 
| 
      
 239 
     | 
    
         
            +
                        emit LogDistributionServiceReferralCreated(distributionNftId, distributorNftId, referralId, code);
         
     | 
| 
       210 
240 
     | 
    
         
             
                    }
         
     | 
| 
       211 
241 
     | 
    
         
             
                }
         
     | 
| 
       212 
242 
     | 
    
         | 
| 
         @@ -221,14 +251,14 @@ contract DistributionService is 
     | 
|
| 
       221 
251 
     | 
    
         
             
                    onlyNftOfType(distributionNftId, DISTRIBUTION())
         
     | 
| 
       222 
252 
     | 
    
         
             
                {
         
     | 
| 
       223 
253 
     | 
    
         
             
                    if (referralIsValid(distributionNftId, referralId)) {
         
     | 
| 
       224 
     | 
    
         
            -
                         
     | 
| 
       225 
     | 
    
         
            -
                        IRegistry.ObjectInfo memory distributionInfo = registry.getObjectInfo(distributionNftId);
         
     | 
| 
       226 
     | 
    
         
            -
                        IInstance instance = _getInstanceForComponent(registry, distributionInfo);
         
     | 
| 
      
 254 
     | 
    
         
            +
                        IInstance instance = IInstance(ContractLib.getInstanceForComponent(getRegistry(), distributionNftId));
         
     | 
| 
       227 
255 
     | 
    
         | 
| 
       228 
256 
     | 
    
         
             
                        // update book keeping for referral info
         
     | 
| 
       229 
257 
     | 
    
         
             
                        IDistribution.ReferralInfo memory referralInfo = instance.getInstanceReader().getReferralInfo(referralId);
         
     | 
| 
       230 
258 
     | 
    
         
             
                        referralInfo.usedReferrals += 1;
         
     | 
| 
       231 
259 
     | 
    
         
             
                        instance.getInstanceStore().updateReferral(referralId, referralInfo, KEEP_STATE());
         
     | 
| 
      
 260 
     | 
    
         
            +
             
     | 
| 
      
 261 
     | 
    
         
            +
                        emit LogDistributionServiceReferralProcessed(distributionNftId, referralInfo.distributorNftId, referralId, referralInfo.usedReferrals);
         
     | 
| 
       232 
262 
     | 
    
         
             
                    }
         
     | 
| 
       233 
263 
     | 
    
         
             
                }
         
     | 
| 
       234 
264 
     | 
    
         | 
| 
         @@ -242,9 +272,7 @@ contract DistributionService is 
     | 
|
| 
       242 
272 
     | 
    
         
             
                    restricted()
         
     | 
| 
       243 
273 
     | 
    
         
             
                    onlyNftOfType(distributionNftId, DISTRIBUTION())
         
     | 
| 
       244 
274 
     | 
    
         
             
                {
         
     | 
| 
       245 
     | 
    
         
            -
                     
     | 
| 
       246 
     | 
    
         
            -
                    IRegistry.ObjectInfo memory distributionInfo = registry.getObjectInfo(distributionNftId);
         
     | 
| 
       247 
     | 
    
         
            -
                    IInstance instance = _getInstanceForComponent(registry, distributionInfo);
         
     | 
| 
      
 275 
     | 
    
         
            +
                    IInstance instance = IInstance(ContractLib.getInstanceForComponent(getRegistry(), distributionNftId));
         
     | 
| 
       248 
276 
     | 
    
         
             
                    InstanceReader reader = instance.getInstanceReader();
         
     | 
| 
       249 
277 
     | 
    
         
             
                    InstanceStore store = instance.getInstanceStore();
         
     | 
| 
       250 
278 
     | 
    
         | 
| 
         @@ -256,12 +284,12 @@ contract DistributionService is 
     | 
|
| 
       256 
284 
     | 
    
         | 
| 
       257 
285 
     | 
    
         
             
                        // increase distribution balance by commission amount and distribution owner fee
         
     | 
| 
       258 
286 
     | 
    
         
             
                        Amount commissionAmount = premium.commissionAmount;
         
     | 
| 
       259 
     | 
    
         
            -
                         
     | 
| 
      
 287 
     | 
    
         
            +
                        _accountingService.increaseDistributionBalance(store, distributionNftId, commissionAmount, distributionOwnerFee);
         
     | 
| 
       260 
288 
     | 
    
         | 
| 
       261 
289 
     | 
    
         
             
                        // update book keeping for referral info
         
     | 
| 
       262 
290 
     | 
    
         
             
                        IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
         
     | 
| 
       263 
291 
     | 
    
         | 
| 
       264 
     | 
    
         
            -
                         
     | 
| 
      
 292 
     | 
    
         
            +
                        _accountingService.increaseDistributorBalance(store, referralInfo.distributorNftId, AmountLib.zero(), commissionAmount);
         
     | 
| 
       265 
293 
     | 
    
         | 
| 
       266 
294 
     | 
    
         
             
                        // update book keeping for distributor info
         
     | 
| 
       267 
295 
     | 
    
         
             
                        IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
         
     | 
| 
         @@ -269,32 +297,34 @@ contract DistributionService is 
     | 
|
| 
       269 
297 
     | 
    
         
             
                        store.updateDistributor(referralInfo.distributorNftId, distributorInfo, KEEP_STATE());
         
     | 
| 
       270 
298 
     | 
    
         
             
                    } else {
         
     | 
| 
       271 
299 
     | 
    
         
             
                        // increase distribution balance by distribution owner fee
         
     | 
| 
       272 
     | 
    
         
            -
                         
     | 
| 
      
 300 
     | 
    
         
            +
                        _accountingService.increaseDistributionBalance(store, distributionNftId, AmountLib.zero(), distributionOwnerFee);
         
     | 
| 
       273 
301 
     | 
    
         
             
                    }
         
     | 
| 
      
 302 
     | 
    
         
            +
             
     | 
| 
      
 303 
     | 
    
         
            +
                    emit LogDistributionServiceSaleProcessed(distributionNftId, referralId);
         
     | 
| 
       274 
304 
     | 
    
         
             
                }
         
     | 
| 
       275 
305 
     | 
    
         | 
| 
       276 
306 
     | 
    
         
             
                /// @inheritdoc IDistributionService
         
     | 
| 
       277 
307 
     | 
    
         
             
                function withdrawCommission(NftId distributorNftId, Amount amount) 
         
     | 
| 
       278 
308 
     | 
    
         
             
                    public 
         
     | 
| 
       279 
309 
     | 
    
         
             
                    virtual
         
     | 
| 
       280 
     | 
    
         
            -
                     
     | 
| 
      
 310 
     | 
    
         
            +
                    restricted()
         
     | 
| 
       281 
311 
     | 
    
         
             
                    onlyNftOfType(distributorNftId, DISTRIBUTOR())
         
     | 
| 
       282 
312 
     | 
    
         
             
                    returns (Amount withdrawnAmount) 
         
     | 
| 
       283 
313 
     | 
    
         
             
                {
         
     | 
| 
       284 
     | 
    
         
            -
                    (NftId distributionNftId 
     | 
| 
      
 314 
     | 
    
         
            +
                    (NftId distributionNftId, IInstance instance) = _getAndVerifyActiveDistribution();
         
     | 
| 
       285 
315 
     | 
    
         
             
                    InstanceReader reader = instance.getInstanceReader();
         
     | 
| 
       286 
316 
     | 
    
         | 
| 
       287 
317 
     | 
    
         
             
                    IComponents.ComponentInfo memory distributionInfo = reader.getComponentInfo(distributionNftId);
         
     | 
| 
       288 
     | 
    
         
            -
                    address distributionWallet = distributionInfo. 
     | 
| 
      
 318 
     | 
    
         
            +
                    // address distributionWallet = distributionInfo.tokenHandler.getWallet();
         
     | 
| 
       289 
319 
     | 
    
         | 
| 
       290 
320 
     | 
    
         
             
                    Amount commissionAmount = reader.getFeeAmount(distributorNftId);
         
     | 
| 
       291 
321 
     | 
    
         | 
| 
       292 
322 
     | 
    
         
             
                    // determine withdrawn amount
         
     | 
| 
       293 
323 
     | 
    
         
             
                    withdrawnAmount = amount;
         
     | 
| 
       294 
     | 
    
         
            -
                    if (withdrawnAmount 
     | 
| 
      
 324 
     | 
    
         
            +
                    if (withdrawnAmount >= AmountLib.max()) {
         
     | 
| 
       295 
325 
     | 
    
         
             
                        withdrawnAmount = commissionAmount;
         
     | 
| 
       296 
326 
     | 
    
         
             
                    } else {
         
     | 
| 
       297 
     | 
    
         
            -
                        if (withdrawnAmount 
     | 
| 
      
 327 
     | 
    
         
            +
                        if (withdrawnAmount > commissionAmount) {
         
     | 
| 
       298 
328 
     | 
    
         
             
                            revert ErrorDistributionServiceCommissionWithdrawAmountExceedsLimit(withdrawnAmount, commissionAmount);
         
     | 
| 
       299 
329 
     | 
    
         
             
                        }
         
     | 
| 
       300 
330 
     | 
    
         
             
                    }
         
     | 
| 
         @@ -303,21 +333,22 @@ contract DistributionService is 
     | 
|
| 
       303 
333 
     | 
    
         
             
                    {
         
     | 
| 
       304 
334 
     | 
    
         
             
                        InstanceStore store = instance.getInstanceStore();
         
     | 
| 
       305 
335 
     | 
    
         
             
                        // decrease fee counter for distribution balance
         
     | 
| 
       306 
     | 
    
         
            -
                         
     | 
| 
      
 336 
     | 
    
         
            +
                        _accountingService.decreaseDistributionBalance(store, distributionNftId, withdrawnAmount, AmountLib.zero());
         
     | 
| 
       307 
337 
     | 
    
         
             
                        // decrease fee counter for distributor fee
         
     | 
| 
       308 
     | 
    
         
            -
                         
     | 
| 
      
 338 
     | 
    
         
            +
                        _accountingService.decreaseDistributorBalance(store, distributorNftId, AmountLib.zero(), withdrawnAmount);
         
     | 
| 
       309 
339 
     | 
    
         
             
                    }
         
     | 
| 
       310 
340 
     | 
    
         | 
| 
       311 
341 
     | 
    
         
             
                    // transfer amount to distributor
         
     | 
| 
       312 
342 
     | 
    
         
             
                    {
         
     | 
| 
       313 
343 
     | 
    
         
             
                        address distributor = getRegistry().ownerOf(distributorNftId);
         
     | 
| 
       314 
     | 
    
         
            -
                        emit LogDistributionServiceCommissionWithdrawn(distributorNftId, distributor, address(distributionInfo. 
     | 
| 
       315 
     | 
    
         
            -
                        distributionInfo.tokenHandler. 
     | 
| 
      
 344 
     | 
    
         
            +
                        emit LogDistributionServiceCommissionWithdrawn(distributorNftId, distributor, address(distributionInfo.tokenHandler.TOKEN()), withdrawnAmount);
         
     | 
| 
      
 345 
     | 
    
         
            +
                        distributionInfo.tokenHandler.pushToken(distributor, withdrawnAmount);
         
     | 
| 
       316 
346 
     | 
    
         
             
                    }
         
     | 
| 
       317 
347 
     | 
    
         
             
                }
         
     | 
| 
       318 
348 
     | 
    
         | 
| 
       319 
349 
     | 
    
         
             
                function referralIsValid(NftId distributionNftId, ReferralId referralId) 
         
     | 
| 
       320 
350 
     | 
    
         
             
                    public 
         
     | 
| 
      
 351 
     | 
    
         
            +
                    virtual
         
     | 
| 
       321 
352 
     | 
    
         
             
                    view 
         
     | 
| 
       322 
353 
     | 
    
         
             
                    onlyNftOfType(distributionNftId, DISTRIBUTION())
         
     | 
| 
       323 
354 
     | 
    
         
             
                    returns (bool isValid) 
         
     | 
| 
         @@ -326,29 +357,91 @@ contract DistributionService is 
     | 
|
| 
       326 
357 
     | 
    
         
             
                        return false;
         
     | 
| 
       327 
358 
     | 
    
         
             
                    }
         
     | 
| 
       328 
359 
     | 
    
         | 
| 
       329 
     | 
    
         
            -
                     
     | 
| 
       330 
     | 
    
         
            -
                    IRegistry.ObjectInfo memory distributionInfo = registry.getObjectInfo(distributionNftId);
         
     | 
| 
       331 
     | 
    
         
            -
                    IInstance instance = _getInstanceForComponent(registry, distributionInfo);
         
     | 
| 
      
 360 
     | 
    
         
            +
                    IInstance instance = IInstance(ContractLib.getInstanceForComponent(getRegistry(), distributionNftId));
         
     | 
| 
       332 
361 
     | 
    
         
             
                    IDistribution.ReferralInfo memory info = instance.getInstanceReader().getReferralInfo(referralId);
         
     | 
| 
       333 
362 
     | 
    
         | 
| 
       334 
363 
     | 
    
         
             
                    if (info.distributorNftId.eqz()) {
         
     | 
| 
       335 
364 
     | 
    
         
             
                        return false;
         
     | 
| 
       336 
365 
     | 
    
         
             
                    }
         
     | 
| 
       337 
366 
     | 
    
         | 
| 
       338 
     | 
    
         
            -
                     
     | 
| 
      
 367 
     | 
    
         
            +
                    // ensure the referral was created on the same distribution
         
     | 
| 
      
 368 
     | 
    
         
            +
                    if(info.distributionNftId != distributionNftId) {
         
     | 
| 
      
 369 
     | 
    
         
            +
                        revert ErrorDistributionServiceReferralDistributionMismatch(referralId, info.distributionNftId, distributionNftId);
         
     | 
| 
      
 370 
     | 
    
         
            +
                    }
         
     | 
| 
      
 371 
     | 
    
         
            +
             
     | 
| 
      
 372 
     | 
    
         
            +
                    isValid = info.expiryAt.eqz() || (info.expiryAt.gtz() && TimestampLib.current() <= info.expiryAt);
         
     | 
| 
       339 
373 
     | 
    
         
             
                    isValid = isValid && info.usedReferrals < info.maxReferrals;
         
     | 
| 
       340 
374 
     | 
    
         
             
                }
         
     | 
| 
       341 
375 
     | 
    
         | 
| 
       342 
     | 
    
         
            -
             
     | 
| 
      
 376 
     | 
    
         
            +
             
     | 
| 
      
 377 
     | 
    
         
            +
                function getDiscountPercentage(
         
     | 
| 
      
 378 
     | 
    
         
            +
                    InstanceReader instanceReader,
         
     | 
| 
      
 379 
     | 
    
         
            +
                    ReferralId referralId
         
     | 
| 
      
 380 
     | 
    
         
            +
                )
         
     | 
| 
      
 381 
     | 
    
         
            +
                    external
         
     | 
| 
      
 382 
     | 
    
         
            +
                    virtual
         
     | 
| 
      
 383 
     | 
    
         
            +
                    view 
         
     | 
| 
      
 384 
     | 
    
         
            +
                    returns (
         
     | 
| 
      
 385 
     | 
    
         
            +
                        UFixed discountPercentage, 
         
     | 
| 
      
 386 
     | 
    
         
            +
                        ReferralStatus status
         
     | 
| 
      
 387 
     | 
    
         
            +
                    )
         
     | 
| 
      
 388 
     | 
    
         
            +
                { 
         
     | 
| 
      
 389 
     | 
    
         
            +
                    IDistribution.ReferralInfo memory info = instanceReader.getReferralInfo(
         
     | 
| 
      
 390 
     | 
    
         
            +
                        referralId);        
         
     | 
| 
      
 391 
     | 
    
         
            +
             
     | 
| 
      
 392 
     | 
    
         
            +
                    if (info.expiryAt.eqz()) {
         
     | 
| 
      
 393 
     | 
    
         
            +
                        return (
         
     | 
| 
      
 394 
     | 
    
         
            +
                            UFixedLib.zero(),
         
     | 
| 
      
 395 
     | 
    
         
            +
                            REFERRAL_ERROR_UNKNOWN());
         
     | 
| 
      
 396 
     | 
    
         
            +
                    }
         
     | 
| 
      
 397 
     | 
    
         
            +
             
     | 
| 
      
 398 
     | 
    
         
            +
                    if (info.expiryAt < TimestampLib.current()) {
         
     | 
| 
      
 399 
     | 
    
         
            +
                        return (
         
     | 
| 
      
 400 
     | 
    
         
            +
                            UFixedLib.zero(),
         
     | 
| 
      
 401 
     | 
    
         
            +
                            REFERRAL_ERROR_EXPIRED());
         
     | 
| 
      
 402 
     | 
    
         
            +
                    }
         
     | 
| 
      
 403 
     | 
    
         
            +
             
     | 
| 
      
 404 
     | 
    
         
            +
                    if (info.usedReferrals >= info.maxReferrals) {
         
     | 
| 
      
 405 
     | 
    
         
            +
                        return (
         
     | 
| 
      
 406 
     | 
    
         
            +
                            UFixedLib.zero(),
         
     | 
| 
      
 407 
     | 
    
         
            +
                            REFERRAL_ERROR_EXHAUSTED());
         
     | 
| 
      
 408 
     | 
    
         
            +
                    }
         
     | 
| 
      
 409 
     | 
    
         
            +
             
     | 
| 
      
 410 
     | 
    
         
            +
                    return (
         
     | 
| 
      
 411 
     | 
    
         
            +
                        info.discountPercentage,
         
     | 
| 
      
 412 
     | 
    
         
            +
                        REFERRAL_OK()
         
     | 
| 
      
 413 
     | 
    
         
            +
                    );
         
     | 
| 
      
 414 
     | 
    
         
            +
             
     | 
| 
      
 415 
     | 
    
         
            +
                }
         
     | 
| 
      
 416 
     | 
    
         
            +
             
     | 
| 
      
 417 
     | 
    
         
            +
             
     | 
| 
      
 418 
     | 
    
         
            +
                function _checkDistributionType(InstanceReader instanceReader, DistributorType distributorType, NftId expectedDistributionNftId) 
         
     | 
| 
      
 419 
     | 
    
         
            +
                    internal
         
     | 
| 
      
 420 
     | 
    
         
            +
                    view 
         
     | 
| 
      
 421 
     | 
    
         
            +
                {
         
     | 
| 
      
 422 
     | 
    
         
            +
                    // enfore distributor type belongs to the calling distribution
         
     | 
| 
      
 423 
     | 
    
         
            +
                    NftId distributorTypeDistributionNftId = instanceReader.getDistributorTypeInfo(distributorType).distributionNftId;
         
     | 
| 
      
 424 
     | 
    
         
            +
             
     | 
| 
      
 425 
     | 
    
         
            +
                    if (distributorTypeDistributionNftId != expectedDistributionNftId) {
         
     | 
| 
      
 426 
     | 
    
         
            +
                        revert ErrorDistributionServiceDistributorTypeDistributionMismatch(distributorType, distributorTypeDistributionNftId, expectedDistributionNftId);
         
     | 
| 
      
 427 
     | 
    
         
            +
                    }
         
     | 
| 
      
 428 
     | 
    
         
            +
                }
         
     | 
| 
      
 429 
     | 
    
         
            +
             
     | 
| 
      
 430 
     | 
    
         
            +
             
     | 
| 
      
 431 
     | 
    
         
            +
             
     | 
| 
      
 432 
     | 
    
         
            +
                function _getAndVerifyActiveDistribution()
         
     | 
| 
       343 
433 
     | 
    
         
             
                    internal
         
     | 
| 
      
 434 
     | 
    
         
            +
                    virtual
         
     | 
| 
       344 
435 
     | 
    
         
             
                    view
         
     | 
| 
       345 
     | 
    
         
            -
                    returns( 
     | 
| 
      
 436 
     | 
    
         
            +
                    returns (
         
     | 
| 
      
 437 
     | 
    
         
            +
                        NftId poolNftId,
         
     | 
| 
      
 438 
     | 
    
         
            +
                        IInstance instance
         
     | 
| 
      
 439 
     | 
    
         
            +
                    )
         
     | 
| 
       346 
440 
     | 
    
         
             
                {
         
     | 
| 
       347 
     | 
    
         
            -
                     
     | 
| 
       348 
     | 
    
         
            -
                    address instanceAddress = getRegistry().getObjectAddress(instanceNftId);
         
     | 
| 
       349 
     | 
    
         
            -
                    return IInstance(instanceAddress);
         
     | 
| 
      
 441 
     | 
    
         
            +
                    return PoolLib.getAndVerifyActiveComponent(getRegistry(), msg.sender, DISTRIBUTION());
         
     | 
| 
       350 
442 
     | 
    
         
             
                }
         
     | 
| 
       351 
443 
     | 
    
         | 
| 
      
 444 
     | 
    
         
            +
             
     | 
| 
       352 
445 
     | 
    
         
             
                function _getDomain() internal pure override returns(ObjectType) {
         
     | 
| 
       353 
446 
     | 
    
         
             
                    return DISTRIBUTION();
         
     | 
| 
       354 
447 
     | 
    
         
             
                }
         
     | 
| 
         @@ -17,7 +17,7 @@ contract DistributionServiceManager is ProxyManager { 
     | 
|
| 
       17 
17 
     | 
    
         
             
                ) 
         
     | 
| 
       18 
18 
     | 
    
         
             
                {
         
     | 
| 
       19 
19 
     | 
    
         
             
                    DistributionService svc = new DistributionService{salt: salt}();
         
     | 
| 
       20 
     | 
    
         
            -
                    bytes memory data = abi.encode( 
     | 
| 
      
 20 
     | 
    
         
            +
                    bytes memory data = abi.encode(authority, registry);
         
     | 
| 
       21 
21 
     | 
    
         
             
                    IVersionable versionable = initialize(
         
     | 
| 
       22 
22 
     | 
    
         
             
                        registry,
         
     | 
| 
       23 
23 
     | 
    
         
             
                        address(svc), 
         
     | 
| 
         @@ -1,25 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            // SPDX-License-Identifier: Apache-2.0
         
     | 
| 
       2 
2 
     | 
    
         
             
            pragma solidity ^0.8.20;
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            import {Amount} from "../type/Amount.sol";
         
     | 
| 
       5 
4 
     | 
    
         
             
            import {IInstanceLinkedComponent} from "../shared/IInstanceLinkedComponent.sol";
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            import {Amount} from "../type/Amount.sol";
         
     | 
| 
       6 
7 
     | 
    
         
             
            import {NftId} from "../type/NftId.sol";
         
     | 
| 
       7 
8 
     | 
    
         
             
            import {ReferralId, ReferralStatus} from "../type/Referral.sol";
         
     | 
| 
       8 
9 
     | 
    
         
             
            import {UFixed} from "../type/UFixed.sol";
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            interface IDistributionComponent is IInstanceLinkedComponent {
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                error ErrorDistributionAlreadyDistributor(address distributor, NftId distributorNftId);
         
     | 
| 
      
 12 
     | 
    
         
            +
            interface IDistributionComponent is IInstanceLinkedComponent {
         
     | 
| 
       14 
13 
     | 
    
         | 
| 
       15 
14 
     | 
    
         
             
                event LogDistributorUpdated(address to, address operator);
         
     | 
| 
       16 
15 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                /// @dev Returns true iff the provided address is registered as a distributor with this distribution component.
         
     | 
| 
       18 
     | 
    
         
            -
                function isDistributor(address candidate) external view returns (bool);
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                /// @dev Returns the distributor Nft Id for the provided address
         
     | 
| 
       21 
     | 
    
         
            -
                function getDistributorNftId(address distributor) external view returns (NftId distributorNftId);
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
16 
     | 
    
         
             
                function getDiscountPercentage(
         
     | 
| 
       24 
17 
     | 
    
         
             
                    string memory referralCode
         
     | 
| 
       25 
18 
     | 
    
         
             
                ) external view returns (UFixed discountPercentage, ReferralStatus status);
         
     | 
| 
         @@ -1,40 +1,51 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            // SPDX-License-Identifier: Apache-2.0
         
     | 
| 
       2 
2 
     | 
    
         
             
            pragma solidity ^0.8.20;
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            import {Amount} from "../type/Amount.sol";
         
     | 
| 
       5 
     | 
    
         
            -
            import {NftId} from "../type/NftId.sol";
         
     | 
| 
       6 
4 
     | 
    
         
             
            import {IPolicy} from "../instance/module/IPolicy.sol";
         
     | 
| 
       7 
5 
     | 
    
         
             
            import {IService} from "../shared/IService.sol";
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            import {Amount} from "../type/Amount.sol";
         
     | 
| 
       9 
8 
     | 
    
         
             
            import {DistributorType} from "../type/DistributorType.sol";
         
     | 
| 
       10 
     | 
    
         
            -
            import { 
     | 
| 
      
 9 
     | 
    
         
            +
            import {InstanceReader} from "../instance/InstanceReader.sol";
         
     | 
| 
      
 10 
     | 
    
         
            +
            import {NftId} from "../type/NftId.sol";
         
     | 
| 
      
 11 
     | 
    
         
            +
            import {ReferralId, ReferralStatus} from "../type/Referral.sol";
         
     | 
| 
      
 12 
     | 
    
         
            +
            import {Seconds} from "../type/Seconds.sol";
         
     | 
| 
       11 
13 
     | 
    
         
             
            import {Timestamp} from "../type/Timestamp.sol";
         
     | 
| 
      
 14 
     | 
    
         
            +
            import {UFixed} from "../type/UFixed.sol";
         
     | 
| 
       12 
15 
     | 
    
         | 
| 
       13 
16 
     | 
    
         | 
| 
       14 
17 
     | 
    
         
             
            interface IDistributionService is IService {
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
18 
     | 
    
         
             
                error ErrorDistributionServiceCallerNotRegistered(address caller);
         
     | 
| 
       17 
     | 
    
         
            -
                error  
     | 
| 
       18 
     | 
    
         
            -
                error  
     | 
| 
       19 
     | 
    
         
            -
                error  
     | 
| 
       20 
     | 
    
         
            -
                error  
     | 
| 
       21 
     | 
    
         
            -
                error  
     | 
| 
       22 
     | 
    
         
            -
                error  
     | 
| 
       23 
     | 
    
         
            -
                error  
     | 
| 
       24 
     | 
    
         
            -
                error  
     | 
| 
       25 
     | 
    
         
            -
                error  
     | 
| 
       26 
     | 
    
         
            -
                error  
     | 
| 
       27 
     | 
    
         
            -
                error  
     | 
| 
      
 19 
     | 
    
         
            +
                error ErrorDistributionServiceParentNftIdNotInstance(NftId nftId, NftId parentNftId);
         
     | 
| 
      
 20 
     | 
    
         
            +
                error ErrorDistributionServiceCallerNotDistributor(address caller);
         
     | 
| 
      
 21 
     | 
    
         
            +
                error ErrorDistributionServiceInvalidReferralId(ReferralId referralId);
         
     | 
| 
      
 22 
     | 
    
         
            +
                error ErrorDistributionServiceMaxReferralsExceeded(uint256 limit, uint256 maxReferrals);
         
     | 
| 
      
 23 
     | 
    
         
            +
                error ErrorDistributionServiceDiscountTooLow(UFixed minDiscountPercentage, UFixed discountPercentage);
         
     | 
| 
      
 24 
     | 
    
         
            +
                error ErrorDistributionServiceDiscountTooHigh(UFixed maxDiscountPercentage, UFixed discountPercentage);
         
     | 
| 
      
 25 
     | 
    
         
            +
                error ErrorDistributionServiceExpiryTooLong(Seconds maxReferralLifetime, Timestamp expiryAt);
         
     | 
| 
      
 26 
     | 
    
         
            +
                error ErrorDistributionServiceInvalidReferral();
         
     | 
| 
      
 27 
     | 
    
         
            +
                error ErrorDistributionServiceExpirationInvalid(Timestamp expiryAt);
         
     | 
| 
      
 28 
     | 
    
         
            +
                error ErrorDistributionServiceCommissionTooHigh(uint256 commissionPercentage, uint256 maxCommissionPercentage);
         
     | 
| 
      
 29 
     | 
    
         
            +
                error ErrorDistributionServiceMinFeeTooHigh(uint256 minFee, uint256 limit);
         
     | 
| 
      
 30 
     | 
    
         
            +
                error ErrorDistributionServiceDistributorTypeDistributionMismatch(DistributorType distributorType, NftId distributorTypeDistributionNftId, NftId distributionNftId);
         
     | 
| 
      
 31 
     | 
    
         
            +
                error ErrorDistributionServiceDistributorDistributionMismatch(NftId distributorNftId, NftId distributorDistributionNftId, NftId distributionNftId);
         
     | 
| 
       28 
32 
     | 
    
         | 
| 
       29 
33 
     | 
    
         
             
                error ErrorDistributionServiceCommissionWithdrawAmountExceedsLimit(Amount amount, Amount limit);
         
     | 
| 
       30 
34 
     | 
    
         | 
| 
       31 
35 
     | 
    
         
             
                error ErrorDistributionServiceVariableFeesTooHight(uint256 maxDiscountPercentage, uint256 limit);
         
     | 
| 
       32 
36 
     | 
    
         
             
                error ErrorDistributionServiceMaxDiscountTooHigh(uint256 maxDiscountPercentage, uint256 limit);
         
     | 
| 
       33 
37 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                error  
     | 
| 
      
 38 
     | 
    
         
            +
                error ErrorDistributionServiceReferralInvalid(NftId distributionNftId, ReferralId referralId);
         
     | 
| 
       35 
39 
     | 
    
         
             
                error ErrorDistributionServiceInvalidFeeTransferred(Amount transferredDistributionFeeAmount, Amount expectedDistributionFeeAmount);
         
     | 
| 
      
 40 
     | 
    
         
            +
                error ErrorDistributionServiceReferralDistributionMismatch(ReferralId referralId, NftId referralDistributionNft, NftId distributionNftId);
         
     | 
| 
       36 
41 
     | 
    
         | 
| 
       37 
42 
     | 
    
         
             
                event LogDistributionServiceCommissionWithdrawn(NftId distributorNftId, address recipient, address tokenAddress, Amount amount);
         
     | 
| 
      
 43 
     | 
    
         
            +
                event LogDistributionServiceDistributorTypeCreated(NftId distributionNftId, string name);
         
     | 
| 
      
 44 
     | 
    
         
            +
                event LogDistributionServiceDistributorCreated(NftId distributionNftId, NftId distributorNftId, DistributorType distributorType, address distributor);
         
     | 
| 
      
 45 
     | 
    
         
            +
                event LogDistributionServiceDistributorTypeChanged(NftId distributorNftId, DistributorType oldDistributorType, DistributorType newDistributorType);
         
     | 
| 
      
 46 
     | 
    
         
            +
                event LogDistributionServiceReferralCreated(NftId distributionNftId, NftId distributorNftId, ReferralId referralId, string code);
         
     | 
| 
      
 47 
     | 
    
         
            +
                event LogDistributionServiceReferralProcessed(NftId distributionNftId, NftId distributorNftId, ReferralId referralId, uint32 usedReferrals);
         
     | 
| 
      
 48 
     | 
    
         
            +
                event LogDistributionServiceSaleProcessed(NftId distributionNftId, ReferralId referralId);
         
     | 
| 
       38 
49 
     | 
    
         | 
| 
       39 
50 
     | 
    
         
             
                function createDistributorType(
         
     | 
| 
       40 
51 
     | 
    
         
             
                    string memory name,
         
     | 
| 
         @@ -42,7 +53,7 @@ interface IDistributionService is IService { 
     | 
|
| 
       42 
53 
     | 
    
         
             
                    UFixed maxDiscountPercentage,
         
     | 
| 
       43 
54 
     | 
    
         
             
                    UFixed commissionPercentage,
         
     | 
| 
       44 
55 
     | 
    
         
             
                    uint32 maxReferralCount,
         
     | 
| 
       45 
     | 
    
         
            -
                     
     | 
| 
      
 56 
     | 
    
         
            +
                    Seconds maxReferralLifetime,
         
     | 
| 
       46 
57 
     | 
    
         
             
                    bool allowSelfReferrals,
         
     | 
| 
       47 
58 
     | 
    
         
             
                    bool allowRenewals,
         
     | 
| 
       48 
59 
     | 
    
         
             
                    bytes memory data
         
     | 
| 
         @@ -56,12 +67,11 @@ interface IDistributionService is IService { 
     | 
|
| 
       56 
67 
     | 
    
         
             
                    bytes memory data
         
     | 
| 
       57 
68 
     | 
    
         
             
                ) external returns (NftId distributorNftId);
         
     | 
| 
       58 
69 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
                 
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                 
     | 
| 
       64 
     | 
    
         
            -
                // ) external;
         
     | 
| 
      
 70 
     | 
    
         
            +
                function changeDistributorType(
         
     | 
| 
      
 71 
     | 
    
         
            +
                    NftId distributorNftId,
         
     | 
| 
      
 72 
     | 
    
         
            +
                    DistributorType newDistributorType,
         
     | 
| 
      
 73 
     | 
    
         
            +
                    bytes memory data
         
     | 
| 
      
 74 
     | 
    
         
            +
                ) external;
         
     | 
| 
       65 
75 
     | 
    
         | 
| 
       66 
76 
     | 
    
         
             
                function createReferral(
         
     | 
| 
       67 
77 
     | 
    
         
             
                    NftId distributorNftId,
         
     | 
| 
         @@ -98,4 +108,8 @@ interface IDistributionService is IService { 
     | 
|
| 
       98 
108 
     | 
    
         
             
                /// @param amount the amount to withdraw. If set to AMOUNT_MAX, the full commission available is withdrawn
         
     | 
| 
       99 
109 
     | 
    
         
             
                /// @return withdrawnAmount the effective withdrawn amount
         
     | 
| 
       100 
110 
     | 
    
         
             
                function withdrawCommission(NftId distributorNftId, Amount amount) external returns (Amount withdrawnAmount);
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                /// @dev Returns the discount percentage for the provided referral code.
         
     | 
| 
      
 113 
     | 
    
         
            +
                /// The function retuns both the percentage and the status of the referral code.
         
     | 
| 
      
 114 
     | 
    
         
            +
                function getDiscountPercentage(InstanceReader instanceReader, ReferralId referralId) external view returns (UFixed discountPercentage, ReferralStatus status);
         
     | 
| 
       101 
115 
     | 
    
         
             
            }
         
     |