Skip to content

Commit

Permalink
refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaszimmermann committed Jul 11, 2022
1 parent 65bac9e commit 673aac3
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 60 deletions.
1 change: 1 addition & 0 deletions contracts/components/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import "./IComponent.sol";

interface IOracle is IComponent {

event LogOracleCreated (address oracleAddress);
event LogOracleProposed (uint256 id);
event LogOracleApproved (uint256 id);
Expand Down
1 change: 1 addition & 0 deletions contracts/components/IProduct.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import "./IComponent.sol";

interface IProduct is IComponent {

event LogProductCreated (address productAddress);
event LogProductProposed (uint256 id);
event LogProductApproved (uint256 id);
Expand Down
7 changes: 4 additions & 3 deletions contracts/components/IRiskpool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "./IComponent.sol";
import "../modules/IBundle.sol";

interface IRiskpool is IComponent {

event LogRiskpoolCreated (address riskpoolAddress);
event LogRiskpoolProposed (uint256 id);
event LogRiskpoolApproved (uint256 id);
Expand All @@ -18,15 +19,15 @@ interface IRiskpool is IComponent {
function preparePayout(bytes32 processId, uint256 payoutId, uint256 amount) external;
function executePayout(bytes32 processId, uint256 payoutId) external;

function getFilterDataStructure() external view returns(string memory);

function getCollateralizationDecimals() external view returns (uint256);
function getCollateralizationLevel() external view returns (uint256);

function getFilterDataStructure() external view returns(string memory);

function bundles() external view returns(uint256);
function getBundle(uint256 idx) external view returns(IBundle.Bundle memory);

function getCapacity() external view returns(uint256);
function getTotalValueLocked() external view returns(uint256);
function getPrice() external view returns(uint256);
function getBalance() external view returns(uint256);
}
66 changes: 52 additions & 14 deletions contracts/components/Product.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.0;

import "./IProduct.sol";
import "./Component.sol";
import "../modules/IPolicy.sol";
import "../services/IInstanceService.sol";
import "../services/IProductService.sol";

Expand All @@ -11,8 +12,8 @@ abstract contract Product is
Component
{
address private _policyFlow;
IProductService private _productService;
IInstanceService private _instanceService;
IProductService internal _productService;
IInstanceService internal _instanceService;

modifier onlyPolicyHolder(bytes32 policyId) {
address policyHolder = _instanceService.getMetadata(policyId).owner;
Expand Down Expand Up @@ -81,26 +82,39 @@ abstract contract Product is
)
internal
{
_productService.newApplication(owner, processId, premiumAmount, sumInsuredAmount, metaData, applicationData);
_productService.newApplication(
owner,
processId,
premiumAmount,
sumInsuredAmount,
metaData,
applicationData);
}

function _decline(bytes32 processId) internal {
_productService.decline(processId);
}

function _underwrite(bytes32 processId) internal {
_productService.underwrite(processId);
function _underwrite(bytes32 processId) internal returns(bool success) {
success = _productService.underwrite(processId);
}

function _expire(bytes32 processId) internal {
_productService.expire(processId);
}

function _newClaim(bytes32 processId, bytes memory data)
function _newClaim(
bytes32 processId,
uint256 claimAmount,
bytes memory data
)
internal
returns (uint256 claimId)
{
claimId = _productService.newClaim(processId, data);
claimId = _productService.newClaim(
processId,
claimAmount,
data);
}

function _declineClaim(bytes32 processId, uint256 claimId) internal {
Expand All @@ -116,7 +130,11 @@ abstract contract Product is
internal
returns (uint256 _payoutId)
{
_payoutId = _productService.confirmClaim(processId, claimId, payoutAmount, data);
_payoutId = _productService.confirmClaim(
processId,
claimId,
payoutAmount,
data);
}

function _processPayout(
Expand Down Expand Up @@ -148,15 +166,35 @@ abstract contract Product is
);
}

function _getApplicationData(bytes32 processId) internal view returns (bytes memory _data) {
return _instanceService.getApplication(processId).data;
function _getApplication(bytes32 processId)
internal
view
returns (IPolicy.Application memory application)
{
return _instanceService.getApplication(processId);
}

function _getClaimData(bytes32 processId, uint256 claimId) internal view returns (bytes memory _data) {
return _instanceService.getClaim(processId, claimId).data;
function _getPolicy(bytes32 processId)
internal
view
returns (IPolicy.Policy memory policy)
{
return _instanceService.getPolicy(processId);
}

function _getPayoutData(bytes32 processId, uint256 payoutId) internal view returns (bytes memory _data) {
return _instanceService.getPayout(processId, payoutId).data;
function _getClaim(bytes32 processId, uint256 claimId)
internal
view
returns (IPolicy.Claim memory claim)
{
return _instanceService.getClaim(processId, claimId);
}

function _getPayout(bytes32 processId, uint256 payoutId)
internal
view
returns (IPolicy.Payout memory payout)
{
return _instanceService.getPayout(processId, payoutId);
}
}
28 changes: 1 addition & 27 deletions contracts/modules/IPolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ interface IPolicy {

struct Claim {
ClaimState state;
uint256 claimAmount;
bytes data;
uint256 createdAt;
uint256 updatedAt;
Expand Down Expand Up @@ -182,31 +183,4 @@ interface IPolicy {
uint256 payoutId,
IPolicy.PayoutState state
) external;

function getMetadata(bytes32 processId)
external
view
returns (IPolicy.Metadata memory metadata);

function getApplication(bytes32 processId)
external
view
returns (IPolicy.Application memory application);

function getPolicy(bytes32 processId)
external
view
returns (IPolicy.Policy memory policy);

function getClaim(bytes32 processId, uint256 claimId)
external
view
returns (IPolicy.Claim memory claim);

function getPayout(bytes32 processId, uint256 payoutId)
external
view
returns (IPolicy.Payout memory payout);

function getProcessIdCount() external view returns (uint256 count);
}
5 changes: 4 additions & 1 deletion contracts/modules/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
pragma solidity ^0.8.0;

interface IPool {


event LogRiskpoolCollateralizationFailed(uint256 riskpoolId, bytes32 processId, uint256 amount);
event LogRiskpoolCollateralizationSucceed(uint256 riskpoolId, bytes32 processId, uint256 amount);

function setRiskpoolForProduct(uint256 productId, uint256 riskpoolId) external;
function underwrite(bytes32 processId) external returns(bool success);
function expire(bytes32 processId) external;
Expand Down
30 changes: 15 additions & 15 deletions contracts/modules/IQuery.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ pragma solidity ^0.8.0;
interface IQuery {

struct OracleRequest {
bytes data;
bytes32 bpKey;
string callbackMethodName;
address callbackContractAddress;
bytes32 processId;
uint256 responsibleOracleId;
address callbackContractAddress;
string callbackMethodName;
bytes data;
uint256 createdAt;
}

event LogOracleRequested(
bytes32 bpKey,
bytes32 processId,
uint256 requestId,
uint256 responsibleOracleId
);

event LogOracleResponded(
bytes32 bpKey,
bytes32 processId,
uint256 requestId,
address responder,
bool success
);

function request(
bytes32 _bpKey,
bytes calldata _input,
string calldata _callbackMethodName,
address _callbackContractAddress,
uint256 _responsibleOracleId
) external returns (uint256 _requestId);
bytes32 processId,
bytes calldata input,
string calldata callbackMethodName,
address callbackContractAddress,
uint256 responsibleOracleId
) external returns (uint256 requestId);

function respond(
uint256 _requestId,
address _responder,
bytes calldata _data
uint256 requestId,
address responder,
bytes calldata data
) external;

}
2 changes: 2 additions & 0 deletions contracts/services/IInstanceService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "./IComponentOwnerService.sol";
import "./IInstanceOperatorService.sol";
import "./IOracleService.sol";
import "./IProductService.sol";
import "./IRiskpoolService.sol";

interface IInstanceService {

Expand All @@ -18,6 +19,7 @@ interface IInstanceService {
function getInstanceOperatorService() external view returns(IInstanceOperatorService service);
function getOracleService() external view returns(IOracleService service);
function getProductService() external view returns(IProductService service);
function getRiskpoolService() external view returns(IRiskpoolService service);

// access
function productOwnerRole() external view returns(bytes32 role);
Expand Down
1 change: 1 addition & 0 deletions contracts/services/IProductService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IProductService {

function newClaim(
bytes32 processId,
uint256 claimAmount,
bytes calldata data
) external returns (uint256 claimId);

Expand Down

0 comments on commit 673aac3

Please sign in to comment.