Skip to content

Commit

Permalink
docs: Add sequence diagram for lend and borrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Teolhyn authored Sep 12, 2024
1 parent 73efaaa commit 0d800ad
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,74 @@ Format Rust code
```bash
cargo fmt
```

# Architecture

## Lending flow
```mermaid
sequenceDiagram
box rgb(33,66,99)
participant UI
end
box rgb(33,33,99)
participant LendingPool
participant LoanManager
end
box rgb(33,66,33)
participant PriceOracle
end
UI->>LendingPool: get_balance()
LendingPool-->>UI: Balance
UI->>LoanManager: get_price()
LoanManager->>PriceOracle: last_price(Token)
PriceOracle-->>LoanManager: PriceData
LoanManager-->>UI: Price
UI->>LendingPool: get_interest_rate()
LendingPool->>LoanManager: get_interest_rate(Pool)
LoanManager-->>LendingPool: Interest rate
LendingPool-->>UI: Interest rate
UI->>LendingPool: deposit()
LendingPool-->>UI: OK/Error
```
## Borrow flow
```mermaid
sequenceDiagram
box rgb(33,66,99)
participant UI
end
box rgb(33,33,99)
participant LendingPool
participant LoanManager
end
box rgb(33,66,33)
participant PriceOracle
end
UI->>LendingPool: get_available_balance()
LendingPool-->>UI: Available Balance
UI->>LendingPool: get_interest_rate()
LendingPool->>LoanManager: get_interest_rate(Pool)
LoanManager-->>UI: Interest rate
UI->>LoanManager: get_price()
LoanManager->>PriceOracle: last_price(Token)
PriceOracle-->>LoanManager: PriceData
LoanManager-->>UI: Price
UI->>LoanManager: init_loan(token_borrow, borrow_amount, token_collat, collat_amount)
loop calculate_health_factor()
LoanManager->>PriceOracle: last_price(token_borrow)
PriceOracle-->>LoanManager: PriceData
LoanManager->>PriceOracle: last_price(token_collat)
PriceOracle-->>LoanManager: PriceData
LoanManager->>LoanManager: Check that health-factor is over minimum threshold
end
LoanManager-->>LendingPool: deposit_collateral()
LoanManager-->>LendingPool: borrow()
LoanManager-->>UI: OK/Error
```

0 comments on commit 0d800ad

Please sign in to comment.