@startuml PerennialArchitecture

left to right direction

skinparam linetype ortho
skinparam nodesep 50
skinparam ranksep 60

skinparam note {
    BorderColor black
    BackgroundColor white
    FontColor black
}
skinparam component {
    FontSize 20
}

skinparam collections {
    FontSize 20
}

'Invisible Placeholder'
skinparam artifact {
    BorderColor invisible
    BackgroundColor transparent
    FontSize 10
    FontColor transparent
}

/' Actors '/
actor Liquidators
actor Makers
note left: Liquidity Providers
actor Takers
note left: Traders
actor "Market Operator" as MarketOperator
actor Admin

/' //////////////////////////////////////////////////////////////////
//                           Core Contracts                        //
////////////////////////////////////////////////////////////////// '/

collections Market
note right: In V1 known as Product

component Collateral {
    artifact Placeholder1
}

component MultiInvoker {
    artifact Placeholder2
}
note right: Allows batch calls

component ChainlinkOracle {
    artifact Placeholder3
}

component Incentivizer {
    artifact Placeholder4
}

component Controller {
    artifact Placeholder5
}

component ProductProvider {
    artifact Placeholder6
}

/' //////////////////////////////////////////////////////////////////
//                       Contract Functions                        //
////////////////////////////////////////////////////////////////// '/

/'Collateral'/
rectangle deposit <<depositTo>>
rectangle withdraw <<withdrawTo && withdrawFrom>>
rectangle liquidate <<liquidate>>
rectangle "Settle Account" as settleAccount <<settleAccount>>
note bottom of settleAccount: Moves collateral within the product 
rectangle "Settle Product" as settleProduct <<settleProduct>>
note top: Removes collateral\nfrom the product as fees
rectangle "Resolve Shortfall" as resolveShortfall <<resolveShortfall>>

/'Market'/
rectangle "Open Take Position" as openTake <<openTake>>
rectangle "Close Take Position" as closeTake <<closeTake>>
rectangle "Open Make Position" as openMake <<openMake>>
rectangle "Close Make Position" as closeMake <<closeMake>>

/' //////////////////////////////////////////////////////////////////
//                           Connections                           //
////////////////////////////////////////////////////////////////// '/

'Connections to Collateral contract (Collateral contract functions)'
deposit --> Collateral
withdraw --> Collateral
liquidate --> Collateral
settleAccount --> Collateral
settleProduct --> Collateral
'Calls to Collateral contract functions'
Makers --> deposit
Makers --> withdraw
Liquidators --> liquidate
Market --> settleAccount 
Market --> settleProduct 

'Connections to Market contract (Market functions)'
openMake --> Market
closeMake --> Market
openTake --> Market
closeTake --> Market
'Calls to Market contract functions'
Makers --> openMake 
Makers --> closeMake 
Takers --> openTake
Takers --> closeTake

footer Perennial Protocol Architecture | author: @kamilchmielu
@enduml
