Skip to content

Commit 242b784

Browse files
author
ACodehunter
committed
docs: add project documentation pages
1 parent 8e8e1be commit 242b784

9 files changed

Lines changed: 1524 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Architecture Deep Dive
2+
3+
Stellar TBA is a multi-contract system that implements Token Bound Accounts (TBAs) on the Stellar blockchain using Soroban smart contracts.
4+
5+
The architecture consists of two layers:
6+
7+
### Layer 1: TBA Infrastructure
8+
The foundational layer that enables any NFT to have its own account:
9+
- **TBA Account Contract**: Individual smart accounts.
10+
- **TBA Registry Contract**: Factory and directory for TBA accounts.
11+
12+
### Layer 2: Reference Application
13+
A complete event ticketing system that demonstrates TBA capabilities:
14+
- **Event Manager Contract**: Event lifecycle management.
15+
- **Ticket Factory Contract**: NFT contract deployment.
16+
- **Ticket NFT Contract**: Event ticket representation.
17+
18+
## System Overview
19+
20+
```mermaid
21+
graph TD
22+
subgraph "Application Layer (Layer 2)"
23+
EM[Event Manager] --> TF[Ticket Factory]
24+
TF --> TN[Ticket NFT]
25+
end
26+
27+
subgraph "Infrastructure Layer (Layer 1)"
28+
TN -- owns --> TA[TBA Account]
29+
TR[TBA Registry] -- deploys --> TA
30+
end
31+
32+
style EM fill:#f9f,stroke:#333,stroke-width:2px
33+
style TR fill:#bbf,stroke:#333,stroke-width:2px
34+
style TA fill:#dfd,stroke:#333,stroke-width:2px
35+
```
36+
37+
---
38+
39+
## Core Components
40+
41+
### 1. TBA Account Contract
42+
**Purpose**: Represents an individual token-bound account owned by a specific NFT.
43+
44+
- One instance per NFT (per salt).
45+
- Controlled by the current NFT owner.
46+
- Uses Soroban's `CustomAccountInterface`.
47+
48+
### 2. TBA Registry Contract
49+
**Purpose**: Factory and directory for creating and tracking TBA accounts.
50+
51+
- Deterministic address calculation.
52+
- Single source of truth for TBA creation.
53+
54+
### 3. Event Manager Contract
55+
**Purpose**: Manages the entire event lifecycle from creation to refunds.
56+
57+
### 4. Ticket NFT Contract
58+
**Purpose**: Represents event tickets as NFTs.
59+
60+
### 5. Ticket Factory Contract
61+
**Purpose**: Deploys isolated Ticket NFT contracts for each event.
62+
63+
---
64+
65+
## Contract Interactions
66+
67+
### Event Creation Flow
68+
69+
```mermaid
70+
sequenceDiagram
71+
participant User
72+
participant EM as Event Manager
73+
participant TF as Ticket Factory
74+
participant TN as Ticket NFT
75+
76+
User->>EM: create_event()
77+
EM->>TF: deploy_ticket()
78+
TF->>TN: deploy()
79+
TN-->>TF: address
80+
TF-->>EM: address
81+
EM-->>User: event_id
82+
```
83+
84+
### Ticket Purchase Flow
85+
86+
```mermaid
87+
sequenceDiagram
88+
participant User
89+
participant EM as Event Manager
90+
participant TN as Ticket NFT
91+
participant TR as TBA Registry
92+
participant TA as TBA Account
93+
94+
User->>EM: purchase()
95+
EM->>EM: Verify funds & event status
96+
EM->>TN: mint(token_id)
97+
EM->>TR: create_account(nft, id, salt)
98+
TR->>TA: deploy()
99+
TA-->>TR: address
100+
TR-->>EM: tba_address
101+
EM-->>User: Success
102+
```
103+
104+
### Refund Claim Flow
105+
106+
```mermaid
107+
sequenceDiagram
108+
participant User
109+
participant EM as Event Manager
110+
participant TN as Ticket NFT
111+
participant TR as TBA Registry
112+
participant TA as TBA Account
113+
participant PT as Payment Token
114+
115+
User->>EM: claim_refund(event_id)
116+
EM->>TN: verify_owner(token_id)
117+
TN-->>EM: Confirmed
118+
EM->>TR: get_account(nft, id, salt)
119+
TR-->>EM: tba_address
120+
EM->>PT: transfer(amount, to: tba_address)
121+
PT-->>TA: Received
122+
EM-->>User: Success
123+
```
124+
125+
> [!TIP]
126+
> **Key Insight**: The refund goes to the TBA account, NOT the user's wallet. If the user transfers the NFT, the new owner gets the refund.
127+
128+
---
129+
130+
## Design Decisions
131+
132+
- **Separate NFT per Event**: Ensuring isolation and scalability.
133+
- **TBA Refunds**: Empowering atomic transfers of tickets and associated assets.
134+
- **One Ticket per User**: Preventing hoarding and ensuring fair distribution.
135+
- **Deterministic Addresses**: Standardizing TBA cross-chain patterns.

0 commit comments

Comments
 (0)