You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+134-9Lines changed: 134 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,15 @@ The Synapse SDK provides an interface to Filecoin's decentralized services ecosy
20
20
21
21
The SDK handles all the complexity of blockchain interactions, provider selection, and data management, so you can focus on building your application.
22
22
23
+
### Key Concepts
24
+
25
+
-**Service Contracts**: Smart contracts that manage specific services (like storage). Currently, **Warm Storage** is the primary service contract that handles storage operations and payment validation.
26
+
-**Payment Rails**: Automated payment streams between clients and service providers, managed by the Payments contract. When you create a data set in Warm Storage, it automatically creates corresponding payment rails.
27
+
-**Data Sets**: Collections of stored data managed by Warm Storage. Each data set has an associated payment rail that handles the ongoing storage payments.
28
+
-**Pieces**: Individual units of data identified by PieceCID (content-addressed identifiers). Multiple pieces can be added to a data set for storage.
29
+
-**PDP (Proof of Data Possession)**: The cryptographic protocol that verifies storage providers are actually storing the data they claim to store. Providers must periodically prove they possess the data.
30
+
-**Validators**: Service contracts (like Warm Storage) act as validators for payment settlements, ensuring services are delivered before payments are released.
31
+
23
32
## Installation
24
33
25
34
```bash
@@ -59,6 +68,7 @@ Note: `ethers` v6 is a peer dependency and must be installed separately.
-`revokeService(service, token?)` - Revoke service operator approval, returns `TransactionResponse`
301
324
-`serviceApproval(service, token?)` - Check service approval status and allowances
302
325
326
+
**Rail Settlement:**
327
+
-`getRailsAsPayer(token?)` - Get all payment rails where wallet is the payer, returns `RailInfo[]` with `{railId, isTerminated, endEpoch}` (endEpoch is 0 for active rails)
328
+
-`getRailsAsPayee(token?)` - Get all payment rails where wallet is the payee (recipient), returns `RailInfo[]`
329
+
-`getRail(railId)` - Get detailed rail information, returns `{token, from, to, operator, validator, paymentRate, lockupPeriod, lockupFixed, settledUpTo, endEpoch, commissionRateBps, serviceFeeRecipient}`. Throws if rail doesn't exist.
330
+
-`settle(railId, untilEpoch?)` - Settle a payment rail up to specified epoch (must be <= current epoch; defaults to current if not specified), automatically includes settlement fee (0.0013 FIL), returns `TransactionResponse`
331
+
-`settleTerminatedRail(railId)` - Emergency settlement for terminated rails only - bypasses Warm Storage (or other validator) validation to ensure payment even if the validator contract is buggy (pays in full), returns `TransactionResponse`
332
+
-`getSettlementAmounts(railId, untilEpoch?)` - Preview settlement amounts without executing (untilEpoch must be <= current epoch; defaults to current), returns `SettlementResult` with `{totalSettledAmount, totalNetPayeeAmount, totalOperatorCommission, finalSettledEpoch, note}`
333
+
-`settleAuto(railId, untilEpoch?)` - Automatically detect rail status and settle appropriately (untilEpoch must be <= current epoch for active rails)
334
+
303
335
#### Storage Context Methods
304
336
305
337
A `StorageContext` (previously `StorageService`) represents a connection to a specific service provider and data set. Create one with `synapse.storage.createContext()`.
@@ -437,16 +469,13 @@ const result = await context.upload(data, {
@@ -593,6 +622,57 @@ All components can be imported and used independently for advanced use cases. Th
593
622
594
623
Direct interface to the Payments contract for token operations and operator approvals.
595
624
625
+
#### Understanding Payment Rails
626
+
627
+
Payment rails are continuous payment streams between clients and service providers that are created automatically when data sets are established. Each data set has associated payment rails (one for PDP storage, optionally additional ones for CDN services).
628
+
629
+
**How Rails Work:**
630
+
631
+
Rails ensure reliable payments through a simple lockup mechanism:
632
+
633
+
1.**The Lockup Requirement**: When you create a data set (storage), the system calculates how much balance you need to maintain:
634
+
- Formula: `lockup = paymentRate × lockupPeriod` (e.g., 10 days worth of payments)
0 commit comments