|
| 1 | +--- |
| 2 | +id: "lockup" |
| 3 | +sidebar_position: 1 |
| 4 | +title: "Lockup" |
| 5 | +--- |
| 6 | + |
| 7 | +This section focuses on the architecture of accounts created or used in the most important instructions of the Lockup |
| 8 | +program. |
| 9 | + |
| 10 | +## Account architecture |
| 11 | + |
| 12 | +### Sablier Lockup program |
| 13 | + |
| 14 | +The `sablier_lockup` program implements these main functionalities: |
| 15 | + |
| 16 | +- `initialize` |
| 17 | +- `create_with_timestamps_ll` |
| 18 | +- `cancel` |
| 19 | +- `withdraw` |
| 20 | +- `renounce` |
| 21 | + |
| 22 | +We will go into the details and specifics of each one later. For now, we will focus only on the accounts being created. |
| 23 | + |
| 24 | +```mermaid |
| 25 | +flowchart TD |
| 26 | + A[Sablier Lockup Program] --> B[initialize] |
| 27 | + A --> C[create_with_timestamps_ll] |
| 28 | + A --> D[cancel] |
| 29 | + A --> E[withdraw] |
| 30 | + A --> F[renounce] |
| 31 | +``` |
| 32 | + |
| 33 | +### `initialize` Instruction |
| 34 | + |
| 35 | +```mermaid |
| 36 | +flowchart TD |
| 37 | + A[Initializer] -->|calls| B[initialize] |
| 38 | +
|
| 39 | + B --> |creates| C((treasury)) |
| 40 | + B --> |creates| D((nft_collection_ata)) |
| 41 | + B --> |creates| E((nft_collection_data)) |
| 42 | + B --> |creates| F((nft_collection_master_edition)) |
| 43 | + B --> |creates| G((nft_collection_metadata)) |
| 44 | + B --> |creates| H((nft_collection_mint)) |
| 45 | +``` |
| 46 | + |
| 47 | +- **NFT collection data PDA**: stores collection configuration and metadata |
| 48 | +- **NFT collection mint PDA**: serves as the master mint authority for all stream NFTs |
| 49 | +- **NFT collection metadata PDA**: created via Metaplex CPI |
| 50 | +- **NFT collection master edition PDA**: created via Metaplex CPI |
| 51 | +- **NFT collection ATA**: associated token account owned by treasury to hold the collection NFT token |
| 52 | + |
| 53 | +The |
| 54 | +[Treasury PDA](https://github.com/sablier-labs/solsab/blob/e1085fe87ea3d02556156ee446e820d150af483e/programs/lockup/src/state/treasury.rs#L5-L10) |
| 55 | +stores this data: |
| 56 | + |
| 57 | +```mermaid |
| 58 | +flowchart TD |
| 59 | + C((treasury)) --> C1([fee_collector]) |
| 60 | + C --> C2([chainlink_program]) |
| 61 | + C --> C3([chainlink_sol_usd_feed]) |
| 62 | +``` |
| 63 | + |
| 64 | +### `create_with_timestamps_ll` Instruction |
| 65 | + |
| 66 | +#### Pre-existing accounts required: |
| 67 | + |
| 68 | +- Deposit Token |
| 69 | +- NFT Collection |
| 70 | + |
| 71 | +```mermaid |
| 72 | +flowchart TD |
| 73 | + A[Sender] -->|calls| B[create_with_timestamps_ll] |
| 74 | +
|
| 75 | + B --> |creates| C((stream_nft_mint)) |
| 76 | + C0((nft_collection_mint)) -.-> |authority for| C |
| 77 | + B --> |creates| D((stream_data)) |
| 78 | + B --> |creates| H((stream_data_ata)) |
| 79 | + H -.-> |for| H1((deposit_token_mint)) |
| 80 | +
|
| 81 | + B --> |creates| C1((recipient_stream_nft_ata)) |
| 82 | + B --> |creates| C2((stream_nft_master_edition)) |
| 83 | + B --> |creates| C3((stream_nft_metadata)) |
| 84 | +``` |
| 85 | + |
| 86 | +The **Stream NFT Mint** also serves as the "Stream ID" for the `cancel`, `renounce`, and `withdraw` instructions. |
| 87 | + |
| 88 | +Each |
| 89 | +[Stream Data](https://github.com/sablier-labs/solsab/blob/e1085fe87ea3d02556156ee446e820d150af483e/programs/lockup/src/state/lockup.rs#L14-L24) |
| 90 | +account stores the following parameters: |
| 91 | + |
| 92 | +```mermaid |
| 93 | +flowchart TD |
| 94 | + A((Stream Data)) |
| 95 | + A --> A1([amounts]) |
| 96 | + A --> A2([deposit_token_mint]) |
| 97 | + A --> A3([is_cancelable]) |
| 98 | + A --> A4([is_depleted]) |
| 99 | + A --> A5([salt]) |
| 100 | + A --> A6([sender]) |
| 101 | + A --> A7([timestamps]) |
| 102 | + A --> A8([was_canceled]) |
| 103 | +``` |
| 104 | + |
| 105 | +Each |
| 106 | +[amount](https://github.com/sablier-labs/solsab/blob/e1085fe87ea3d02556156ee446e820d150af483e/programs/lockup/src/state/lockup.rs#L4-L10) |
| 107 | +data structure consists of the following components: |
| 108 | + |
| 109 | +```mermaid |
| 110 | +flowchart TD |
| 111 | + A([amounts]) |
| 112 | + A --> A1([deposited]) |
| 113 | + A --> A2([withdrawn]) |
| 114 | + A --> A3([refunded]) |
| 115 | +``` |
| 116 | + |
| 117 | +Each |
| 118 | +[timestamps](https://github.com/sablier-labs/solsab/blob/e1085fe87ea3d02556156ee446e820d150af483e/programs/lockup/src/state/lockup.rs#L28-L32) |
| 119 | +data structure consists of the following components: |
| 120 | + |
| 121 | +```mermaid |
| 122 | +flowchart TD |
| 123 | + A([timestamps]) |
| 124 | + A --> A1([cliff]) |
| 125 | + A --> A2([end]) |
| 126 | + A --> A3([start]) |
| 127 | +``` |
| 128 | + |
| 129 | +## The Flow of the Deposit Token |
| 130 | + |
| 131 | +### `create_with_timestamps_ll` Instruction |
| 132 | + |
| 133 | +```mermaid |
| 134 | +sequenceDiagram |
| 135 | + actor Sender |
| 136 | + participant Lockup |
| 137 | + participant TokenProgram as Token Program |
| 138 | + participant Accounts as Token Accounts<br/>Sender ATA & StreamData ATA |
| 139 | +
|
| 140 | + Sender->>Lockup: create_with_timestamps_ll() |
| 141 | + Lockup->>TokenProgram: CPI: transfer() |
| 142 | + TokenProgram-->>Accounts: Move tokens<br/>Sender ATA → StreamData ATA |
| 143 | +``` |
| 144 | + |
| 145 | +### `cancel` Instruction |
| 146 | + |
| 147 | +Only the sender can cancel a stream. |
| 148 | + |
| 149 | +```mermaid |
| 150 | +sequenceDiagram |
| 151 | + actor Sender |
| 152 | + participant Lockup |
| 153 | + participant TokenProgram as Token Program |
| 154 | + participant Accounts as Token Accounts<br/> StreamData ATA & Sender ATA |
| 155 | +
|
| 156 | + Sender->>Lockup: cancel() |
| 157 | + Lockup->>TokenProgram: CPI: transfer() |
| 158 | + TokenProgram-->>Accounts: Move tokens<br/> StreamData ATA → Sender ATA |
| 159 | +``` |
| 160 | + |
| 161 | +### `withdraw` Instruction |
| 162 | + |
| 163 | +```mermaid |
| 164 | +sequenceDiagram |
| 165 | + actor Recipient |
| 166 | + participant Lockup |
| 167 | + participant TokenProgram as Token Program |
| 168 | + participant Accounts as Token Accounts<br/> StreamData ATA & WithdrawalRecipient ATA |
| 169 | +
|
| 170 | + Recipient->>Lockup: withdraw(withdrawal_recipient) |
| 171 | + Lockup->>TokenProgram: CPI: transfer() |
| 172 | + TokenProgram -->> Accounts: Move tokens<br/> StreamData ATA → WithdrawalRecipient ATA |
| 173 | +``` |
0 commit comments