Skip to content

Commit

Permalink
Merge pull request #665 from etherisc/feature/remove-componentvetifyi…
Browse files Browse the repository at this point in the history
…ngservice

Remove ComponentVerifyingService
  • Loading branch information
matthiaszimmermann authored Sep 3, 2024
2 parents 5b936e6 + 6cbe7cd commit 517baaa
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 211 deletions.
17 changes: 4 additions & 13 deletions contracts/distribution/DistributionService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {IComponents} from "../instance/module/IComponents.sol";
import {IPolicy} from "../instance/module/IPolicy.sol";

import {Amount, AmountLib} from "../type/Amount.sol";
import {ContractLib} from "../shared/ContractLib.sol";
import {DistributorType, DistributorTypeLib} from "../type/DistributorType.sol";
import {NftId, NftIdLib} from "../type/NftId.sol";
import {KEEP_STATE} from "../type/StateId.sol";
Expand Down Expand Up @@ -76,7 +77,6 @@ contract DistributionService is
restricted()
returns (DistributorType distributorType)
{
// _getAndVerifyActiveDistribution
(NftId distributionNftId, IInstance instance) = _getAndVerifyActiveDistribution();

{
Expand Down Expand Up @@ -241,7 +241,7 @@ contract DistributionService is
onlyNftOfType(distributionNftId, DISTRIBUTION())
{
if (referralIsValid(distributionNftId, referralId)) {
IInstance instance = _getInstanceForDistribution(getRegistry(), distributionNftId);
IInstance instance = IInstance(ContractLib.getInstanceForComponent(getRegistry(), distributionNftId));

// update book keeping for referral info
IDistribution.ReferralInfo memory referralInfo = instance.getInstanceReader().getReferralInfo(referralId);
Expand All @@ -260,7 +260,7 @@ contract DistributionService is
restricted()
onlyNftOfType(distributionNftId, DISTRIBUTION())
{
IInstance instance = _getInstanceForDistribution(getRegistry(), distributionNftId);
IInstance instance = IInstance(ContractLib.getInstanceForComponent(getRegistry(), distributionNftId));
InstanceReader reader = instance.getInstanceReader();
InstanceStore store = instance.getInstanceStore();

Expand Down Expand Up @@ -342,7 +342,7 @@ contract DistributionService is
return false;
}

IInstance instance = _getInstanceForDistribution(getRegistry(), distributionNftId);
IInstance instance = IInstance(ContractLib.getInstanceForComponent(getRegistry(), distributionNftId));
IDistribution.ReferralInfo memory info = instance.getInstanceReader().getReferralInfo(referralId);

if (info.distributorNftId.eqz()) {
Expand Down Expand Up @@ -413,15 +413,6 @@ contract DistributionService is
}


function _getInstanceForDistribution(IRegistry registry, NftId distributionNftId)
internal
view
returns(IInstance instance)
{
// TODO refactor to ComponentLib or similar
return PoolLib.getInstanceForComponent(registry, distributionNftId);
}


function _getAndVerifyActiveDistribution()
internal
Expand Down
19 changes: 9 additions & 10 deletions contracts/pool/BundleService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.20;
import {IAccountingService} from "../accounting/IAccountingService.sol";
import {IBundle} from "../instance/module/IBundle.sol";
import {IBundleService} from "./IBundleService.sol";
import {IComponents} from "../instance/module/IComponents.sol";
import {IComponentService} from "../shared/IComponentService.sol";
import {IRegistry} from "../registry/IRegistry.sol";
import {IRegistryService} from "../registry/IRegistryService.sol";
Expand All @@ -13,19 +12,19 @@ import {InstanceStore} from "../instance/InstanceStore.sol";

import {Amount, AmountLib} from "../type/Amount.sol";
import {BundleSet} from "../instance/BundleSet.sol";
import {ComponentVerifyingService} from "../shared/ComponentVerifyingService.sol";
import {Fee} from "../type/Fee.sol";
import {InstanceReader} from "../instance/InstanceReader.sol";
import {NftId, NftIdLib} from "../type/NftId.sol";
import {ObjectType, ACCOUNTING, COMPONENT, POOL, BUNDLE, POLICY, REGISTRY} from "../type/ObjectType.sol";
import {StateId, ACTIVE, PAUSED, CLOSED, KEEP_STATE} from "../type/StateId.sol";
import {PoolLib} from "./PoolLib.sol";
import {Seconds} from "../type/Seconds.sol";
import {Service} from "../shared/Service.sol";
import {StateId, ACTIVE, PAUSED, CLOSED, KEEP_STATE} from "../type/StateId.sol";
import {Timestamp, TimestampLib, zeroTimestamp} from "../type/Timestamp.sol";

string constant BUNDLE_SERVICE_NAME = "BundleService";

contract BundleService is
ComponentVerifyingService,
Service,
IBundleService
{

Expand Down Expand Up @@ -69,7 +68,7 @@ contract BundleService is
{
_checkNftType(bundleNftId, BUNDLE());

(NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
(NftId poolNftId, IInstance instance) = PoolLib.getAndVerifyActivePool(getRegistry(), msg.sender);
InstanceReader instanceReader = instance.getInstanceReader();
IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
if(bundleInfo.poolNftId.eqz()) {
Expand All @@ -96,7 +95,7 @@ contract BundleService is
restricted()
returns(NftId bundleNftId)
{
(NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
(NftId poolNftId, IInstance instance) = PoolLib.getAndVerifyActivePool(getRegistry(), msg.sender);

// register bundle with registry
bundleNftId = _registryService.registerBundle(
Expand Down Expand Up @@ -190,7 +189,7 @@ contract BundleService is
// checks
_checkNftType(bundleNftId, BUNDLE());

(,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
(, IInstance instance) = PoolLib.getAndVerifyActivePool(getRegistry(), msg.sender);

// udpate bundle state
instance.getInstanceStore().updateBundleState(bundleNftId, PAUSED());
Expand All @@ -212,7 +211,7 @@ contract BundleService is
// checks
_checkNftType(bundleNftId, BUNDLE());

(,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
(, IInstance instance) = PoolLib.getAndVerifyActivePool(getRegistry(), msg.sender);

// effects
// udpate bundle state
Expand Down Expand Up @@ -344,7 +343,7 @@ contract BundleService is
// checks
_checkNftType(bundleNftId, BUNDLE());

(NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
(NftId poolNftId, IInstance instance) = PoolLib.getAndVerifyActivePool(getRegistry(), msg.sender);
IBundle.BundleInfo memory bundleInfo = instance.getInstanceReader().getBundleInfo(bundleNftId);
StateId bundleState = instance.getInstanceReader().getBundleState(bundleNftId);

Expand Down
5 changes: 0 additions & 5 deletions contracts/pool/PoolService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
pragma solidity ^0.8.20;

import {IAccountingService} from "../accounting/IAccountingService.sol";
import {IBundle} from "../instance/module/IBundle.sol";
import {IBundleService} from "./IBundleService.sol";
import {IComponents} from "../instance/module/IComponents.sol";
import {IComponentService} from "../shared/IComponentService.sol";
import {IInstance} from "../instance/IInstance.sol";
import {IPolicy} from "../instance/module/IPolicy.sol";
import {IPolicyHolder} from "../shared/IPolicyHolder.sol";
import {IPoolComponent} from "../pool/IPoolComponent.sol";
import {IPoolService} from "./IPoolService.sol";
import {IProductComponent} from "../product/IProductComponent.sol";
Expand All @@ -27,9 +25,6 @@ import {PayoutId} from "../type/PayoutId.sol";
import {PoolLib} from "./PoolLib.sol";
import {Service} from "../shared/Service.sol";
import {TokenHandler} from "../shared/TokenHandler.sol";
import {UFixed} from "../type/UFixed.sol";

string constant POOL_SERVICE_NAME = "PoolService";


contract PoolService is
Expand Down
31 changes: 26 additions & 5 deletions contracts/product/ApplicationService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {IPricingService} from "./IPricingService.sol";
import {IRegistryService} from "../registry/IRegistryService.sol";

import {AmountLib} from "../type/Amount.sol";
import {ContractLib} from "../shared/ContractLib.sol";
import {Seconds} from "../type/Seconds.sol";
import {zeroTimestamp} from "../type/Timestamp.sol";
import {ObjectType, BUNDLE, DISTRIBUTION, PRODUCT, REGISTRY, APPLICATION, POLICY, PRICE} from "../type/ObjectType.sol";
Expand All @@ -19,13 +20,12 @@ import {NftId, NftIdLib} from "../type/NftId.sol";
import {ReferralId} from "../type/Referral.sol";
import {RiskId} from "../type/RiskId.sol";
import {Amount, AmountLib} from "../type/Amount.sol";
import {ComponentVerifyingService} from "../shared/ComponentVerifyingService.sol";
import {Service} from "../shared/Service.sol";
import {InstanceReader} from "../instance/InstanceReader.sol";



contract ApplicationService is
ComponentVerifyingService,
Service,
IApplicationService
{
IDistributionService private _distributionService;
Expand Down Expand Up @@ -155,7 +155,7 @@ contract ApplicationService is
{
_checkNftType(bundleNftId, BUNDLE());

(NftId productNftId,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
(NftId productNftId, IInstance instance) = _getAndVerifyActiveProduct();

// check if provided references are valid and linked to calling product contract
InstanceReader instanceReader = instance.getInstanceReader();
Expand Down Expand Up @@ -265,12 +265,33 @@ contract ApplicationService is
{
_checkNftType(applicationNftId, POLICY());

(,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
(, IInstance instance) = _getAndVerifyActiveProduct();
instance.getInstanceStore().updateApplicationState(applicationNftId, REVOKED());
}

// internal functions

function _getAndVerifyActiveProduct()
internal
view
returns (
NftId productNftId,
IInstance instance
)
{
(
IRegistry.ObjectInfo memory info,
address instanceAddress
) = ContractLib.getAndVerifyComponent(
getRegistry(),
msg.sender,
PRODUCT(),
true); // only active pools

productNftId = info.nftId;
instance = IInstance(instanceAddress);
}


function _getDomain() internal pure override returns(ObjectType) {
return APPLICATION();
Expand Down
1 change: 0 additions & 1 deletion contracts/product/IPolicyService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {IService} from "../shared/IService.sol";

import {Amount} from "../type/Amount.sol";
import {IInstance} from "../instance/IInstance.sol";
import {InstanceReader} from "../instance/InstanceReader.sol";
import {NftId} from "../type/NftId.sol";
import {StateId} from "../type/StateId.sol";
import {Timestamp} from "../type/Timestamp.sol";
Expand Down
3 changes: 0 additions & 3 deletions contracts/product/PolicyService.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

import {IAccountingService} from "../accounting/IAccountingService.sol";
import {IComponentService} from "../shared/IComponentService.sol";
import {IComponents} from "../instance/module/IComponents.sol";
Expand All @@ -26,7 +24,6 @@ import {PolicyServiceLib} from "./PolicyServiceLib.sol";
import {ReferralId} from "../type/Referral.sol";
import {RiskId} from "../type/RiskId.sol";
import {Service} from "../shared/Service.sol";
import {StateId} from "../type/StateId.sol";
import {Timestamp, TimestampLib} from "../type/Timestamp.sol";
import {TokenHandler} from "../shared/TokenHandler.sol";
import {VersionPart} from "../type/Version.sol";
Expand Down
47 changes: 22 additions & 25 deletions contracts/product/PricingService.sol
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {Amount, AmountLib} from "../type/Amount.sol";
import {Seconds} from "../type/Seconds.sol";
import {UFixed, UFixedLib} from "../type/UFixed.sol";
import {ObjectType} from "../type/ObjectType.sol";
import {NftId} from "../type/NftId.sol";
import {Fee} from "../type/Fee.sol";
import {ReferralId} from "../type/Referral.sol";
import {RiskId} from "../type/RiskId.sol";
import {PRODUCT, BUNDLE, DISTRIBUTION, PRICE} from "../type/ObjectType.sol";
import {IRegistry} from "../registry/IRegistry.sol";

import {IProductComponent} from "./IProductComponent.sol";

import {IInstance} from "../instance/IInstance.sol";
import {InstanceReader} from "../instance/InstanceReader.sol";
import {IComponents} from "../instance/module/IComponents.sol";
import {IPolicy} from "../instance/module/IPolicy.sol";
import {IBundle} from "../instance/module/IBundle.sol";
import {IComponents} from "../instance/module/IComponents.sol";
import {IDistribution} from "../instance/module/IDistribution.sol";

import {ComponentVerifyingService} from "../shared/ComponentVerifyingService.sol";

import {IPricingService} from "./IPricingService.sol";
import {IDistributionService} from "../distribution/IDistributionService.sol";
import {IInstance} from "../instance/IInstance.sol";
import {IPolicy} from "../instance/module/IPolicy.sol";
import {IPricingService} from "./IPricingService.sol";
import {IProductComponent} from "./IProductComponent.sol";
import {IRegistry} from "../registry/IRegistry.sol";

import {Amount} from "../type/Amount.sol";
import {BUNDLE, DISTRIBUTION, PRICE, PRODUCT} from "../type/ObjectType.sol";
import {ContractLib} from "../shared/ContractLib.sol";
import {Fee} from "../type/Fee.sol";
import {InstanceReader} from "../instance/InstanceReader.sol";
import {NftId} from "../type/NftId.sol";
import {ObjectType} from "../type/ObjectType.sol";
import {ReferralId} from "../type/Referral.sol";
import {RiskId} from "../type/RiskId.sol";
import {Seconds} from "../type/Seconds.sol";
import {Service} from "../shared/Service.sol";


contract PricingService is
ComponentVerifyingService,
Service,
IPricingService
{
IDistributionService internal _distributionService;
Expand Down Expand Up @@ -81,11 +78,11 @@ contract PricingService is
// verify product
(
IRegistry.ObjectInfo memory registryInfo,
IInstance instance
) = _getAndVerifyComponentInfo(productNftId, PRODUCT(), false);
address instanceAddress
) = ContractLib.getInfoAndInstance(getRegistry(), productNftId, false);

// get instance reader from local instance variable
reader = instance.getInstanceReader();
reader = IInstance(instanceAddress).getInstanceReader();

NftId riskProductNftId = reader.getRiskInfo(riskId).productNftId;
if (productNftId != riskProductNftId) {
Expand Down
Loading

0 comments on commit 517baaa

Please sign in to comment.