|
| 1 | +--- |
| 2 | +title: PAYMENT-STREAMS |
| 3 | +name: Payment Streams Protocol for Logos Services |
| 4 | +status: raw |
| 5 | +category: Standards Track |
| 6 | +tags: logos, payment, streams |
| 7 | +editor: Sergei Tikhomirov <[email protected]> |
| 8 | +contributors: |
| 9 | +--- |
| 10 | + |
| 11 | +## Abstract |
| 12 | + |
| 13 | +This document specifies a payment streams protocol for Logos services. |
| 14 | +In this protocol, a payer locks up a deposit that is released gradually to a payee who provides services. |
| 15 | +Either party may withdraw funds at any time. |
| 16 | +The proportion of funds available to each party is determined by the underlying blockchain based on elapsed time. |
| 17 | + |
| 18 | +This approach provides simplicity: |
| 19 | +parties need not store old states or handle dispute closures as required in payment channel protocols. |
| 20 | +The unidirectional nature maps well to use cases where payers and payees have distinct roles. |
| 21 | + |
| 22 | +The protocol is designed to be lightweight, secure, private, and to avoid on-chain communication on every payment. |
| 23 | +It targets Nescience, a privacy-focused blockchain with state separation architecture, |
| 24 | +as the home for its on-chain component. |
| 25 | + |
| 26 | +This document provides a functional specification of the first MVP version of the protocol. |
| 27 | +It clarifies requirements for the MVP and facilitates discussion with Nescience developers |
| 28 | +regarding implementation feasibility, challenges, and integration considerations. |
| 29 | + |
| 30 | +## Motivation |
| 31 | + |
| 32 | +Logos is a privacy-focused tech stack that includes Logos Messaging, Logos Blockchain, and Logos Storage. |
| 33 | + |
| 34 | +Logos Messaging comprises a suite of communication protocols with both P2P and request-response structures. |
| 35 | +While the backbone P2P protocols use tit-for-tat mechanisms, |
| 36 | +we plan to introduce incentivization for auxiliary request-response protocols where client and server roles are well defined. |
| 37 | +One such protocol is Store, |
| 38 | +which allows a client to query historical messages from Logos Messaging relay nodes. |
| 39 | + |
| 40 | +Incentivization requires a payment protocol that is lightweight, secure, private, |
| 41 | +and does not require on-chain communication for every payment. |
| 42 | +After reviewing prior work on related systems including payment channels, streams, e-cash, and tickets, |
| 43 | +we converged on payment streams as the first off-chain payment mechanism. |
| 44 | + |
| 45 | +Nescience is a privacy-focused blockchain under development, planned as part of the Logos Blockchain stack. |
| 46 | +Its core innovation is state separation architecture (NSSA), which enables both transparent and shielded execution. |
| 47 | +Targeting Nescience for the on-chain component of the payment protocol is a natural fit. |
| 48 | +However, Nescience is still in development, and certain architectural aspects remain in progress. |
| 49 | + |
| 50 | +This document aims to provide clarity on MVP payment protocol requirements |
| 51 | +and facilitate discussion with Nescience developers to determine: |
| 52 | +whether the required functionality can be implemented, |
| 53 | +which parts are most challenging and whether they can be simplified, |
| 54 | +and other considerations for integrating Nescience with off-chain payment streams for privacy and scalability. |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +## Related Work |
| 59 | + |
| 60 | +### Sablier Flow |
| 61 | + |
| 62 | +Sablier Flow implements open-ended streaming debt with a rate per second parameter. |
| 63 | +The core formula is: amount owed equals rate per second multiplied by elapsed time. |
| 64 | +Streams have no predetermined end time and accrue continuously. |
| 65 | +Anyone can trigger settlement to realize accrued debt. |
| 66 | +Uses standard ERC-20 tokens. |
| 67 | + |
| 68 | +### Sablier Lockup |
| 69 | + |
| 70 | +Sablier Lockup implements a deposit-to-continuous-emission-to-refund-remainder pattern. |
| 71 | +Streams have fixed duration determined at creation. |
| 72 | +The total deposit amount is locked upfront. |
| 73 | +Tokens are released according to a predetermined schedule. |
| 74 | +Settlement happens automatically based on time. |
| 75 | +Uses singleton stream manager architecture and standard ERC-20 tokens. |
| 76 | + |
| 77 | +### LlamaPay V2 |
| 78 | + |
| 79 | +LlamaPay V2 deploys one vault contract per payer. |
| 80 | +Each vault can manage multiple outgoing streams to different recipients using multiple tokens. |
| 81 | +Streams are open-ended with rate per second accrual. |
| 82 | +The protocol tracks debt when streams exceed available vault balance. |
| 83 | +Either recipient or payer can trigger settlement. |
| 84 | +Includes whitelisting for delegated vault management. |
| 85 | +Uses standard ERC-20 tokens. |
| 86 | +Licensed under AGPL-3.0. |
| 87 | + |
| 88 | +### Superfluid |
| 89 | + |
| 90 | +Superfluid implements real-time finance with continuous money flows. |
| 91 | +Streams are open-ended with rate per second accrual. |
| 92 | +Uses a host-agreements framework: a central host contract routes operations to pluggable agreement contracts. |
| 93 | +Constant Flow Agreement handles streaming, Instant Distribution Agreement handles one-to-many distributions. |
| 94 | +Balances update in real-time; settlement is automatic when balances are queried. |
| 95 | +Requires wrapping standard tokens into Super Tokens. |
| 96 | +Supports one sender streaming to multiple recipients. |
| 97 | + |
| 98 | +### Comparison |
| 99 | + |
| 100 | +| Design Dimension | Sablier Flow | Sablier Lockup | LlamaPay V2 | Superfluid | |
| 101 | +|----------------|--------------|----------------|-------------|------------| |
| 102 | +| Stream duration | Open-ended | Fixed duration | Open-ended | Open-ended | |
| 103 | +| Accrual mechanism | Rate per second, debt tracking | Fixed schedule, no debt | Rate per second, debt tracking | Rate per second, real-time balance | |
| 104 | +| Architecture | Singleton manager | Singleton manager | Per-payer vault | Host-agreements framework | |
| 105 | +| Multi-recipient from one payer | No | No | Yes | Yes | |
| 106 | +| Spending controls | None | Total deposit fixed upfront | None | Solvency checks only | |
| 107 | +| Settlement trigger | Anyone can settle | Automatic time-based | Recipient or payer | Automatic on balance check | |
| 108 | +| Token requirements | Standard ERC-20 | Standard ERC-20 | Standard ERC-20 | Super Tokens only | |
| 109 | + |
| 110 | +Key trade-offs between architectures: |
| 111 | +Singleton managers (Sablier Flow, Sablier Lockup) require separate deposits per stream but provide simpler global state management. |
| 112 | +Per-payer vaults (LlamaPay V2) allow deposit sharing across multiple streams but increase per-payer deployment costs. |
| 113 | +Host-agreements framework (Superfluid) provides extensibility and composability at the cost of complexity and non-standard token requirements. |
| 114 | + |
| 115 | +## Theory and Semantics |
| 116 | + |
| 117 | +### Terminology |
| 118 | + |
| 119 | +| Term | Description | |
| 120 | +|------|-------------| |
| 121 | +| User | The party paying for services (payer) | |
| 122 | +| Provider | The party delivering services and receiving payment (payee) | |
| 123 | +| Vault | User's deposit holding funds that can back multiple streams | |
| 124 | +| Stream | Individual payment flow from vault to one provider, with allocated funds and accrual rate | |
| 125 | +| Allocation | Portion of vault funds committed to back a specific stream | |
| 126 | +| Rate | Amount of tokens per second that accrue to provider while stream is active | |
| 127 | +| Accrual | Process of calculating provider's earned balance based on elapsed time and rate | |
| 128 | +| Claim | Provider retrieving accrued funds from a stream, available at any time from any stream state | |
| 129 | +| Withdraw | User retrieving unallocated funds from vault or unaccrued funds from closed stream | |
| 130 | +| Top-up | User adding funds to a stream's allocation | |
| 131 | + |
| 132 | +### High-level protocol semantics |
| 133 | + |
| 134 | +The overall goal of the protocol is to enable payments for services. |
| 135 | + |
| 136 | +This specification is written with Nescience blockchain as the target platform. |
| 137 | +Nescience provides state separation architecture that enables both transparent and shielded execution. |
| 138 | +The protocol design leverages these privacy capabilities while remaining functionally defined. |
| 139 | + |
| 140 | +We aim for the following high-level requirements: |
| 141 | + |
| 142 | +- Performance: Payments must be efficient in latency and fees. |
| 143 | +- Security: The protocol must limit loss exposure through spending controls. |
| 144 | +- Privacy: The protocol must break links between payments and service provision across providers. |
| 145 | +- Extendability: The protocol must allow simple initial versions that can be enhanced later. |
| 146 | + |
| 147 | + |
| 148 | +### Assumptions |
| 149 | + |
| 150 | +We assume the parties agree on stream parameters before stream creation. |
| 151 | +The discovery protocol provides a way for providers to advertise their services and expected payment, |
| 152 | +or for users and providers to negotiate stream parameters off-chain. |
| 153 | + |
| 154 | +We assume users monitor service delivery and take action when providers stop delivering service. |
| 155 | +Since users are typically online to receive service, |
| 156 | +monitoring service quality and pausing or closing streams when issues arise is not an unreasonable burden. |
| 157 | +The user's risk exposure is bounded by the stream allocation size and the time to detect and respond to service degradation. |
| 158 | + |
| 159 | + |
| 160 | +### Roles and responsibilities |
| 161 | + |
| 162 | +There are two parties: a user (payer) and a service provider (payee). |
| 163 | +Funds flow unidirectionally from user to provider. |
| 164 | + |
| 165 | + |
| 166 | +### Architecture Overview |
| 167 | + |
| 168 | +The protocol uses a two-level architecture: |
| 169 | + |
| 170 | +Vault - User's deposit of funds that can back multiple payment streams. |
| 171 | +A vault holds the total balance available for streaming payments. |
| 172 | +Each user has their own vault. |
| 173 | + |
| 174 | +Stream - Individual payment channel from a vault to one provider. |
| 175 | +When creating a stream, the user allocates a portion of vault funds to back that stream. |
| 176 | +Each stream specifies a rate per second at which funds accrue to the provider. |
| 177 | + |
| 178 | +Relationship: |
| 179 | +One vault can have multiple streams to different providers. |
| 180 | +Each stream belongs to exactly one vault. |
| 181 | +Streams are isolated from each other to prevent linking user activity across providers. |
| 182 | + |
| 183 | +The protocol enforces that total allocated funds across all streams cannot exceed vault balance. |
| 184 | + |
| 185 | + |
| 186 | +### Vault Lifecycle |
| 187 | + |
| 188 | +A vault is created when a user first deposits funds. |
| 189 | +The vault persists as long as the user maintains it. |
| 190 | + |
| 191 | +Vault operations: |
| 192 | + |
| 193 | +Deposit - User adds tokens to the vault. |
| 194 | +The vault balance increases. |
| 195 | + |
| 196 | +Withdraw - User removes unallocated tokens from the vault. |
| 197 | +Only funds not allocated to streams can be withdrawn. |
| 198 | + |
| 199 | +Create Stream - User creates a new stream by allocating a portion of vault funds. |
| 200 | +Allocated funds are committed to back that stream. |
| 201 | + |
| 202 | +Top Up Stream - User increases an existing stream's allocation using vault's available balance. |
| 203 | +The additional amount is allocated from vault to the stream. |
| 204 | + |
| 205 | +Vault invariants: |
| 206 | + |
| 207 | +Sum of all stream allocations must not exceed total deposited balance. |
| 208 | +User can only withdraw funds that are not allocated to streams. |
| 209 | +Vault must maintain sufficient balance to cover all stream allocations. |
| 210 | + |
| 211 | + |
| 212 | +### Stream Lifecycle |
| 213 | + |
| 214 | +A stream exists only when on-chain state is created. |
| 215 | +Off-chain negotiation of stream parameters is handled by a separate discovery protocol. |
| 216 | + |
| 217 | +Stream states: |
| 218 | + |
| 219 | +ACTIVE - Funds accrue to provider at the agreed rate per second. |
| 220 | +PAUSED - Accrual is stopped by user action, stream can be resumed by user. |
| 221 | +DEPLETED - Stream has run out of allocated funds, accrual is stopped automatically. |
| 222 | +CLOSED - Stream is permanently terminated, no further state changes possible. This is the terminal state. |
| 223 | + |
| 224 | +Stream state transitions: |
| 225 | + |
| 226 | +Create - User creates stream in ACTIVE state by allocating funds from vault. |
| 227 | +Pause - User pauses an ACTIVE stream, stopping accrual. |
| 228 | +Resume - User resumes a PAUSED stream, restarting accrual. |
| 229 | +Deplete - Automatic transition from ACTIVE when allocated funds are fully accrued. |
| 230 | +Top Up - User adds funds to stream from ACTIVE, PAUSED, or DEPLETED states, increasing allocation. |
| 231 | +If performed from DEPLETED state, stream transitions to PAUSED. |
| 232 | +If performed from ACTIVE or PAUSED state, stream remains in same state. |
| 233 | +Close - Either user or provider closes stream from any non-CLOSED state. |
| 234 | +Closure is permanent and irreversible. |
| 235 | +CLOSED is the terminal state with no outgoing transitions. |
| 236 | + |
| 237 | +Claim operation: |
| 238 | +Provider can claim accrued funds at any time from any stream state. |
| 239 | +Accrued amount is determined by rate per second multiplied by time in ACTIVE state. |
| 240 | +Claim operation is independent of stream state and does not affect state transitions. |
| 241 | + |
| 242 | +Withdraw operation: |
| 243 | +User can withdraw unaccrued allocated funds only from CLOSED state. |
| 244 | +User can withdraw unallocated funds from vault at any time. |
| 245 | +User cannot withdraw allocated funds from non-CLOSED streams. |
| 246 | + |
| 247 | +Top-up operation: |
| 248 | +User can add funds to a stream from ACTIVE, PAUSED, or DEPLETED states. |
| 249 | +Top-up increases the stream's allocation from vault's available balance. |
| 250 | +Vault must have sufficient unallocated balance to cover the top-up amount. |
| 251 | +If stream is in DEPLETED state, top-up transitions it to PAUSED. |
| 252 | +User must explicitly resume to restart accrual after topping up a depleted stream. |
| 253 | +If stream is in ACTIVE or PAUSED state, top-up increases allocation without changing state. |
| 254 | + |
| 255 | +Stream invariants: |
| 256 | + |
| 257 | +Stream starts in ACTIVE state upon creation. |
| 258 | +Only user can pause, resume, or top up a stream. |
| 259 | +Stream automatically transitions to DEPLETED when allocated funds are fully accrued. |
| 260 | +Either party can close a stream at any time from any non-CLOSED state. |
| 261 | +Provider can only claim funds that have accrued based on elapsed time and rate. |
| 262 | +User's allocated funds remain committed to the stream until stream is closed. |
| 263 | +User can only withdraw stream funds after closing the stream. |
| 264 | + |
| 265 | +## Security and Privacy Considerations |
| 266 | + |
| 267 | +This section will address: |
| 268 | +- Economic security assumptions and spending controls |
| 269 | +- Attack vectors and mitigations |
| 270 | +- Privacy guarantees provided by stream isolation |
| 271 | +- Trust assumptions between users and providers |
| 272 | +- Considerations specific to Nescience state separation architecture |
| 273 | + |
| 274 | +## Open Questions |
| 275 | + |
| 276 | +This section captures unresolved design decisions for discussion with Nescience developers: |
| 277 | + |
| 278 | +- Implementation of vault and stream isolation in Nescience NSSA |
| 279 | +- Enforcement of allocation limits across streams in shielded execution |
| 280 | +- Mechanisms for preventing over-commitment without revealing cross-provider activity |
| 281 | +- State representation and transition enforcement in shielded execution |
| 282 | +- Integration with delivery receipt verification for service quality assurance |
| 283 | + |
| 284 | +## Copyright |
| 285 | + |
| 286 | +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
| 287 | + |
| 288 | +## References |
| 289 | + |
| 290 | +### Informative |
| 291 | + |
| 292 | +- [Sablier Flow](https://github.com/sablier-labs/flow) - Open-ended streaming debt protocol |
| 293 | +- [Sablier Lockup](https://github.com/sablier-labs/lockup) - Fixed-duration streaming protocol |
| 294 | +- [LlamaPay V2](https://github.com/LlamaPay/llamapay-v2) - Per-payer vault streaming protocol |
| 295 | +- [Superfluid Protocol](https://github.com/superfluid-org/protocol-monorepo) - Real-time finance framework |
| 296 | + |
0 commit comments