Skip to content

Commit 0d529e2

Browse files
authored
feat!: change params to options object and remove withIpni (#601)
1 parent 67a17ee commit 0d529e2

43 files changed

Lines changed: 1582 additions & 1752 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/src/content/docs/developer-guides/migration-guide.md

Lines changed: 113 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,129 @@ If you are coming from an earlier version of any of the Synapse packages, you wi
99

1010
---
1111

12-
## `@filoz/synapse-sdk` 0.37.0
12+
## 0.37.0
1313

14-
<!-- Check out the [changelog](/changelog-sdk/version/0-37-0/) for more information. -->
14+
`synapse-sdk` moved to a viem-first API, removed deprecated modules/methods, and standardized method signatures around options objects plus `bigint` identifiers.
1515

16-
The main entrypoint `@filoz/synapse-sdk` no longer export all the other modules, from this version onwards it will only export the `Synapse` class, constants and types. Check [reference](/reference/filoz/synapse-sdk/synapse/toc/) for the current exports.
16+
### Action: Migrate from `ethers` setup to `viem` setup
1717

18-
### Action: Change `import` statements
18+
```ts
19+
// before
20+
import { Synapse } from '@filoz/synapse-sdk'
21+
22+
const synapse = await Synapse.create({
23+
privateKey: PRIVATE_KEY,
24+
rpcURL: 'https://api.calibration.node.glif.io/rpc/v1'
25+
})
26+
27+
// after
28+
import { calibration } from '@filoz/synapse-sdk'
29+
import { privateKeyToAccount } from 'viem/accounts'
30+
import { http } from 'viem'
31+
import { Synapse } from '@filoz/synapse-sdk'
32+
33+
const synapse = Synapse.create({
34+
account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),
35+
chain: calibration, // optional
36+
transport: http() // optional
37+
})
38+
```
39+
40+
### Action: Remove deprecated SDK module imports
41+
42+
The following subpath exports were removed from `@filoz/synapse-sdk`:
43+
44+
- `@filoz/synapse-sdk/pdp`
45+
- `@filoz/synapse-sdk/subgraph`
46+
- `@filoz/synapse-sdk/telemetry`
1947

2048
```ts
21-
// before
22-
import {
23-
PaymentService,
24-
PDPAuthHelper,
25-
PDPServer,
26-
PDPVerifier,
27-
SessionKey,
28-
StorageContext,
29-
StorageManager,
30-
WarmStorageService
31-
} from '@filoz/synapse-sdk'
32-
33-
// after
34-
import { PaymentService } from '@filoz/synapse-sdk/payments'
49+
// before
3550
import { PDPAuthHelper, PDPServer, PDPVerifier } from '@filoz/synapse-sdk/pdp'
36-
import { SessionKey } from '@filoz/synapse-sdk/session'
37-
import { StorageContext, StorageManager } from '@filoz/synapse-sdk/manager'
51+
import { SubgraphService } from '@filoz/synapse-sdk/subgraph'
52+
import { getGlobalTelemetry } from '@filoz/synapse-sdk/telemetry'
53+
54+
// after
55+
import { Synapse } from '@filoz/synapse-sdk'
56+
import { PaymentsService } from '@filoz/synapse-sdk/payments'
57+
import { SPRegistryService } from '@filoz/synapse-sdk/sp-registry'
58+
import { StorageContext, StorageManager } from '@filoz/synapse-sdk/storage'
3859
import { WarmStorageService } from '@filoz/synapse-sdk/warm-storage'
60+
```
61+
62+
### Action: Convert positional parameters to object parameters
3963

64+
Most service methods now take an options object. IDs are now `bigint` in the public API.
65+
66+
```ts
67+
// before
68+
await synapse.storage.download(pieceCid, { withCDN: true })
69+
await synapse.payments.allowance(spender)
70+
await synapse.payments.settle(12, 5000)
71+
await synapse.providers.getProvider(1)
72+
73+
// after
74+
await synapse.storage.download({ pieceCid, withCDN: true })
75+
await synapse.payments.allowance({ spender })
76+
await synapse.payments.settle({ railId: 12n, untilEpoch: 5000n })
77+
await synapse.providers.getProvider({ providerId: 1n })
4078
```
4179

80+
This change applies broadly across:
81+
82+
- `PaymentsService`
83+
- `WarmStorageService`
84+
- `SPRegistryService`
85+
- retrievers and storage download APIs
86+
87+
### Action: Replace removed deprecated methods
88+
89+
Deprecated methods that were previously shimmed were removed from `Synapse`.
90+
91+
```ts
92+
// before
93+
const storage = await synapse.createStorage({ providerId: 1 })
94+
const data = await synapse.download(pieceCid)
95+
const info = await synapse.getStorageInfo()
96+
97+
// after
98+
const context = await synapse.storage.createContext({ providerId: 1n })
99+
const data = await synapse.storage.download({ pieceCid })
100+
const info = await synapse.storage.getStorageInfo()
101+
```
102+
103+
### Action: Update dataset and callback assumptions
104+
105+
```ts
106+
// before
107+
if (dataSet.currentPieceCount > 0) {
108+
// ...
109+
}
110+
111+
callbacks: {
112+
onPieceAdded: () => {},
113+
onPieceConfirmed: () => {}
114+
}
115+
116+
// after
117+
if (dataSet.activePieceCount > 0n) {
118+
// ...
119+
}
120+
121+
callbacks: {
122+
onPiecesAdded: (txHash, pieces) => {},
123+
onPiecesConfirmed: (dataSetId, pieces) => {}
124+
}
125+
```
126+
127+
### Migration checklist for this range
128+
129+
1. Replace `ethers`-based initialization (`privateKey`/`provider`/`signer`) with viem (`account` + `transport` + `chain`).
130+
2. Remove imports from `@filoz/synapse-sdk/pdp`, `@filoz/synapse-sdk/subgraph`, and `@filoz/synapse-sdk/telemetry`.
131+
3. Migrate method calls to options-object style and switch numeric IDs to `bigint`.
132+
4. Replace removed deprecated methods (`synapse.createStorage`, `synapse.download`, `synapse.getStorageInfo`) with `synapse.storage.*`.
133+
5. Update dataset field usage (`currentPieceCount` -> `activePieceCount`) and callback names (`onPieceAdded`/`onPieceConfirmed` -> plural callbacks).
134+
42135
## 0.24.0+
43136

44137
### Terminology Update

docs/src/content/docs/developer-guides/payments/payment-operations.mdx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
4949
import { TOKENS } from "@filoz/synapse-sdk";
5050

5151
const amount = parseUnits("100");
52-
const hash = await synapse.payments.depositWithPermit(amount);
52+
const hash = await synapse.payments.depositWithPermit({ amount });
5353
await synapse.client.waitForTransactionReceipt({ hash });
5454
```
5555

@@ -63,7 +63,7 @@ If you cannot use permit-based deposits, you can use the traditional two-transac
6363
await usdfc.approve(paymentAddress, depositAmount);
6464

6565
// 2. Deposit
66-
await synapse.payments.deposit(depositAmount);
66+
await synapse.payments.deposit({ amount });
6767
```
6868

6969
This requires two transactions and higher gas costs. Use `depositWithPermit` instead.
@@ -101,7 +101,7 @@ import { privateKeyToAccount } from 'viem/accounts'
101101
const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
102102
// ---cut---
103103
const info = await synapse.payments.accountInfo();
104-
await synapse.payments.withdraw(info.availableFunds);
104+
await synapse.payments.withdraw({ amount: info.availableFunds });
105105
```
106106

107107
## Approving Operators
@@ -134,12 +134,7 @@ const rateAllowance = monthlyPricePerTiB / TIME_CONSTANTS.EPOCHS_PER_MONTH;
134134
const lockupAllowance = monthlyPricePerTiB * months;
135135
const maxLockupPeriod = TIME_CONSTANTS.EPOCHS_PER_MONTH;
136136

137-
await synapse.payments.approveService(
138-
calibration.contracts.fwss.address,
139-
rateAllowance,
140-
lockupAllowance,
141-
maxLockupPeriod
142-
);
137+
await synapse.payments.approveService();
143138
```
144139

145140
### Revoking an Operator
@@ -152,7 +147,7 @@ import { Synapse, calibration } from "@filoz/synapse-sdk";
152147
import { privateKeyToAccount } from 'viem/accounts'
153148
const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
154149
// ---cut---
155-
await synapse.payments.revokeService(calibration.contracts.fwss.address);
150+
await synapse.payments.revokeService();
156151
```
157152

158153
### Checking Operator Approvals
@@ -163,7 +158,7 @@ import { Synapse, calibration } from "@filoz/synapse-sdk";
163158
import { privateKeyToAccount } from 'viem/accounts'
164159
const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
165160
// ---cut---
166-
const approval = await synapse.payments.serviceApproval(calibration.contracts.fwss.address);
161+
const approval = await synapse.payments.serviceApproval();
167162

168163
console.log("Approved:", approval.isApproved);
169164
console.log(

docs/src/content/docs/developer-guides/payments/rails-settlement.mdx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ import { privateKeyToAccount } from 'viem/accounts'
116116
const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
117117
const railId = null as unknown as bigint;
118118
// ---cut---
119-
const railInfo = await synapse.payments.getRail(railId);
119+
const railInfo = await synapse.payments.getRail({ railId });
120120
console.log("Rail details:", {
121121
from: railInfo.from,
122122
to: railInfo.to,
@@ -150,12 +150,12 @@ const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
150150
const railId = 1n;
151151
// ---cut---
152152
// Automatically handles both active and terminated rails
153-
const hash1 = await synapse.payments.settleAuto(railId);
153+
const hash1 = await synapse.payments.settleAuto({ railId });
154154
await synapse.client.waitForTransactionReceipt({ hash: hash1 });
155155
console.log("Rail settled successfully");
156156

157157
// For active rails, you can specify the epoch to settle up to
158-
const hash2 = await synapse.payments.settleAuto(railId, 1000n);
158+
const hash2 = await synapse.payments.settleAuto({ railId, untilEpoch: 1000n });
159159
await synapse.client.waitForTransactionReceipt({ hash: hash2 });
160160
console.log("Rail settled successfully up to epoch 1000");
161161
```
@@ -176,7 +176,7 @@ const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
176176
const railId = 1n;
177177
// ---cut---
178178
// Settle a specific rail (requires settlement fee)
179-
const hash = await synapse.payments.settle(railId);
179+
const hash = await synapse.payments.settle({ railId });
180180
await synapse.client.waitForTransactionReceipt({ hash });
181181
console.log("Rail settled successfully");
182182
```
@@ -197,7 +197,7 @@ const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
197197
const railId = 1n;
198198
// ---cut---
199199
const targetEpoch = 1000n; // Ensure it's not in the future
200-
const hash = await synapse.payments.settle(railId, targetEpoch);
200+
const hash = await synapse.payments.settle({ railId, untilEpoch: targetEpoch });
201201
await synapse.client.waitForTransactionReceipt({ hash });
202202
```
203203

@@ -220,11 +220,11 @@ const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
220220
const railId = 1n;
221221
// ---cut---
222222
// Check if rail is terminated
223-
const railInfo = await synapse.payments.getRail(railId);
223+
const railInfo = await synapse.payments.getRail({ railId });
224224
if (railInfo.endEpoch > 0) {
225225
console.log(`Rail terminated at epoch ${railInfo.endEpoch}`);
226226
// Settle the terminated rail
227-
const hash = await synapse.payments.settleTerminatedRail(railId);
227+
const hash = await synapse.payments.settleTerminatedRail({ railId });
228228
await synapse.client.waitForTransactionReceipt({ hash });
229229
console.log("Terminated rail settled and closed");
230230
}
@@ -244,7 +244,7 @@ const synapse = Synapse.create({ account: privateKeyToAccount('0x...') });
244244
const railId = 1n;
245245
// ---cut---
246246
// Preview settlement to current epoch
247-
const amounts = await synapse.payments.getSettlementAmounts(railId);
247+
const amounts = await synapse.payments.getSettlementAmounts({ railId });
248248
const totalSettledAmount = formatUnits(amounts.totalSettledAmount);
249249
const totalNetPayeeAmount = formatUnits(amounts.totalNetPayeeAmount);
250250
const totalOperatorCommission = formatUnits(amounts.totalOperatorCommission);
@@ -259,14 +259,11 @@ console.log(` Settled up to epoch: ${finalSettledEpoch}`);
259259
console.log(` Note: ${note}`);
260260

261261
// Preview partial settlement to a specific past epoch
262-
const targetEpoch = 1000n; // Must be less than or equal to current epoch
263-
const partialAmounts = await synapse.payments.getSettlementAmounts(
264-
railId,
265-
targetEpoch
266-
);
262+
const untilEpoch = 1000n; // Must be less than or equal to current epoch
263+
const partialAmounts = await synapse.payments.getSettlementAmounts({ railId, untilEpoch });
267264
const partialTotalSettledAmount = formatUnits(partialAmounts.totalSettledAmount);
268265
console.log(
269-
`Partial settlement to epoch ${targetEpoch} -`,
266+
`Partial settlement to epoch ${untilEpoch} -`,
270267
`would settle: ${partialTotalSettledAmount} USDFC`
271268
);
272269
```
@@ -290,13 +287,13 @@ async function settleAllIncomingRails() {
290287
for (const rail of rails) {
291288
try {
292289
// Check if settlement is worthwhile
293-
const amounts = await synapse.payments.getSettlementAmounts(rail.railId);
290+
const amounts = await synapse.payments.getSettlementAmounts({ railId: rail.railId });
294291

295292
// Only settle if amount exceeds threshold (e.g., $10)
296293
const threshold = parseUnits("10"); // 10 USDFC
297294
if (amounts.totalNetPayeeAmount > threshold) {
298295
// settleAuto handles both active and terminated rails
299-
const hash = await synapse.payments.settleAuto(rail.railId);
296+
const hash = await synapse.payments.settleAuto({ railId: rail.railId });
300297
await synapse.client.waitForTransactionReceipt({ hash });
301298
console.log(
302299
`Settled rail ${rail.railId} for ${formatUnits(amounts.totalNetPayeeAmount)} USDFC`
@@ -328,7 +325,7 @@ async function prepareForWithdrawal() {
328325

329326
// Settle all rails to update balance (settleAuto handles both active and terminated)
330327
for (const rail of rails) {
331-
const hash = await synapse.payments.settleAuto(rail.railId);
328+
const hash = await synapse.payments.settleAuto({ railId: rail.railId });
332329
await synapse.client.waitForTransactionReceipt({ hash });
333330
}
334331

@@ -347,7 +344,7 @@ Common settlement errors and solutions:
347344

348345
```typescript
349346
try {
350-
await synapse.payments.settle(railId);
347+
await synapse.payments.settle({railId});
351348
} catch (error) {
352349
if (error.message.includes("InsufficientNativeTokenForBurn")) {
353350
console.error("Insufficient FIL for settlement fee (0.0013 FIL required)");

docs/src/content/docs/developer-guides/storage/storage-context.mdx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,8 @@ export interface UploadCallbacks {
156156
onUploadComplete?: (pieceCid: PieceCID) => void;
157157
/** Called when the service provider has added the piece(s) and submitted the transaction to the chain */
158158
onPiecesAdded?: (transaction?: Hex, pieces?: { pieceCid: PieceCID }[]) => void;
159-
/** @deprecated Use onPiecesAdded instead */
160-
onPieceAdded?: (transaction?: Hex) => void;
161159
/** Called when the service provider agrees that the piece addition(s) are confirmed on-chain */
162160
onPiecesConfirmed?: (dataSetId: number, pieces: PieceRecord[]) => void;
163-
/** @deprecated Use onPiecesConfirmed instead */
164-
onPieceConfirmed?: (pieceIds: number[]) => void;
165161
}
166162

167163
/**
@@ -233,7 +229,7 @@ const conversationId = "1234567890";
233229

234230
const data = new TextEncoder().encode("Deep research on decentralization...")
235231

236-
const preflight = await storageContext.preflightUpload(data.length);
232+
const preflight = await storageContext.preflightUpload({ size: data.length });
237233

238234
console.log("Estimated costs:", preflight.estimatedCost);
239235
console.log("Allowance sufficient:", preflight.allowanceCheck.sufficient);
@@ -265,16 +261,16 @@ const { pieceCid, size, pieceId } = await storageContext.upload(data, {
265261
},
266262
});
267263

268-
const receivedData = await storageContext.download(pieceCid);
264+
const receivedData = await storageContext.download({ pieceCid });
269265

270266
console.log(`Received data: ${new TextDecoder().decode(receivedData)}`);
271267

272268
// Get the list of piece CIDs in the current data set by querying the provider
273-
const pieceCids = await storageContext.getDataSetPieces();
269+
const pieceCids = await Array.fromAsync(storageContext.getPieces());
274270
console.log(`Piece CIDs: ${pieceCids.map((cid) => cid.toString()).join(", ")}`);
275271

276272
// Check the status of a piece on the service provider
277-
const status = await storageContext.pieceStatus(pieceCid);
273+
const status = await storageContext.pieceStatus({ pieceCid });
278274
console.log(`Piece exists: ${status.exists}`);
279275
console.log(`Data set last proven: ${status.dataSetLastProven}`);
280276
console.log(`Data set next proof due: ${status.dataSetNextProofDue}`);
@@ -361,7 +357,7 @@ for await (const piece of storageContext.getPieces()) {
361357
}
362358

363359
// Delete the first piece
364-
await storageContext.deletePiece(pieces[0].pieceId);
360+
await storageContext.deletePiece({ piece: pieces[0].pieceId });
365361
console.log(
366362
`Piece ${pieces[0].pieceCid} (ID: ${pieces[0].pieceId}) deleted successfully`
367363
);

0 commit comments

Comments
 (0)