Skip to content

Commit

Permalink
adjust/add sequence diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
rapidddenis committed Apr 7, 2024
1 parent bee9ac9 commit 62310aa
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 52 deletions.
39 changes: 17 additions & 22 deletions docs_manual/application.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
# ApplicationService sequences

## calculatePremium
## create

```mermaid
sequenceDiagram
actor C as Caller
participant AS as ApplicationService
participant P as Product
participant DS as DistributionService
participant IR as InstanceReader
participant RS as RegistryService
participant R as Registry
participant PS as PricingService
participant IS as InstanceStore
C ->> AS: calculatePremium(productNftId, sumInsured, referral, [...])
AS ->> P: calculateNetPremium(sumInsured)
P ->> AS: netPremium
AS ->> AS: _getFixedFeeAmounts()
AS ->> IR: getProductSetupInfo()<br/> getPoolSetupInfo() <br/> getBundleInfo() <br/> getDistributionSetupInfo()
AS ->> AS: _calculateVariableFeeAmounts
AS ->> DS: calculateFeeAmount(distributionNftId, referral, netPremium, (intermediary)premium)
DS ->> IR: getDistributionSetupInfo()
DS ->> DS: calculate distribution fee and full premium
DS ->> DS: referralIsValid()
DS ->> IR: getReferralInfo()<br/> getDistributorInfo<br/> getDistributorTypeInfo()
opt if referral is valid
DS ->> DS: calculate discount, comission based on referral
end
DS ->> DS: calculate distribution owner fee and final premium
DS ->> AS: premium (final)
AS ->> C: premium
```
C ->> AS: create()
AS ->> RS: registerPolicy(objectInfo)
RS ->> +R: register(objectInfo)
R ->> R: mint NFT
R ->> -RS: policyNftId
RS ->> AS: policyNftId
AS ->> +PS: calculatePremium(productNftId, sumInsured, referralId, [...])
PS ->> -AS: premium
AS ->> IS: createApplication(policyNftId, policyInfo)
AS ->> C: policyNftId
```
31 changes: 1 addition & 30 deletions docs_manual/distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,4 @@ sequenceDiagram
DS -->> I: createReferral(ReferralId, IDistribution.ReferralInfo)
DS ->> D: ReferralId
D ->> C: ReferralId
```

## processSale

```mermaid
sequenceDiagram
actor C as Caller
participant PS as PolicyService
participant AS as ApplicationService
participant DS as DistributionService
participant IR as InstanceReader
participant I as Instance
C ->> PS: underwrite(policy, premiumAmount)
PS -->> +PS: check preconditions
PS -->> PS: calculate fees
PS ->> +AS: calculateFeeAmount(referralId, premiumAmount)
AS ->> -PS: feeAmount
PS -->> -PS: move tokens
PS ->> DS: processSale(referralId, premiumAmount)
DS ->> IR: getReferralInfo()
IR ->> DS: IDistribution.ReferralInfo
DS ->> DS: update referral usage in IDistribution.ReferralInfo
DS -->> I: update IDistribution.ReferralInfo
DS ->> DS: calculate distributor commission<br> and fee for distribution owner
DS -->> I: update IDistribution.DistributorInfo
DS -->> I: update ISetup.DistributionSetupInfo
DS ->> PS:
PS ->> C: netPremiumAmount
```
```
29 changes: 29 additions & 0 deletions docs_manual/policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# PolicyService sequences

## collateralize

```mermaid
sequenceDiagram
actor C as Caller
participant PS as PolicyService
participant PRS as PricingService
participant TH as TokenHandler
participant DS as DistributionService
participant POS as PoolService
participant IS as InstanceStore
participant IR as InstanceReader
C ->> PS: collateralize(policy, premiumAmount)
PS ->> IR: getPolicyInfo
PS ->> IR: getPolicyState
opt if require premium payment
PS ->> +PRS: calculatePremium(productNftId, sumInsured, referralId, [...])
PRS ->> -PS: premium
PS ->> TH: transfer(productFee)
PS ->> TH: transfer(distributionFee)
PS ->> DS: processSale(distributionNftId, referallId, premium, distributionFee)
PS ->> TH: transfer(poolFee)
PS ->> POS: processSale(bundleNftId, premium, poolFee)
end
PS ->> IS: updatePolicy(policyNftId, policyInfo, policyState)
```
26 changes: 26 additions & 0 deletions docs_manual/pricing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# PricingService sequences

## calculatePremium

```mermaid
sequenceDiagram
actor C as Caller
participant PS as PricingService
participant P as Product
participant DS as DistributionService
participant IR as InstanceReader
C ->> PS: calculatePremium(productNftId, sumInsured, referralId, [...])
PS ->> P: calculateNetPremium(sumInsured, [...])
P ->> PS: netPremium
PS ->> IR: getProductSetupInfo()<br/> getPoolSetupInfo() <br/> getBundleInfo() <br/> getDistributionSetupInfo()
PS ->> PS: _getFixedFeeAmounts()
PS ->> PS: _calculateVariableFeeAmounts()
PS ->> +PS: _calculateDistributionOwnerFeeAmount()
PS ->> DS: referralIsValid(referralId)
opt if referral is valid
PS ->> IR: getReferralInfo()<br/> getDistributorInfo<br/> getDistributorTypeInfo()
PS ->> -PS: calculate discount, comission based on referral
end
PS ->> C: premium
```

0 comments on commit 62310aa

Please sign in to comment.