Skip to content

Commit 528c6fa

Browse files
ZenGround0rvaggSgtPooki
authored
chore: move to the version of synapse-sdk on next branch (#146)
* Explicitly declare direct dep rather than rely on synapse * cdn endEpoch removed from ds info * 10 day grace period => 30 day grace period * fix: plumb --warm-storage-address through `payments setup` * fix: check lockup period during allowance check * chore: update to synapse@next tag, fix test failures & update more lockup mismatches * post rebase wip * Update synapse to v0.35.0 * Make things compile with add piece and create all in one * chore: fix onPieceAdded txHash * fix test --------- Co-authored-by: zenground0 <[email protected]> Co-authored-by: Rod Vagg <[email protected]> Co-authored-by: Russell Dempsey <[email protected]>
1 parent 0e80256 commit 528c6fa

File tree

20 files changed

+80
-111
lines changed

20 files changed

+80
-111
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@
9797
"homepage": "https://github.com/filecoin-project/filecoin-pin#readme",
9898
"dependencies": {
9999
"@clack/prompts": "^0.11.0",
100-
"@filoz/synapse-sdk": "^0.34.0",
100+
"@filoz/synapse-sdk": "^0.35.0",
101101
"@helia/unixfs": "^6.0.1",
102102
"@ipld/car": "^5.4.2",
103103
"commander": "^14.0.1",
104+
"ethers": "^6.15.0",
104105
"fastify": "^5.6.0",
105106
"helia": "^6.0.1",
106107
"it-to-buffer": "^4.0.10",

src/add/add.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ export async function runAdd(options: AddOptions): Promise<AddResult> {
164164
onProviderSelected: (provider) => {
165165
spinner.message(`Connecting to storage provider: ${provider.name || provider.serviceProvider}...`)
166166
},
167-
onDataSetCreationStarted: (transaction) => {
168-
spinner.message(`Creating data set (tx: ${transaction.hash.slice(0, 10)}...)`)
169-
},
170167
onDataSetResolved: (info) => {
171168
if (info.isExisting) {
172169
spinner.message(`Using existing data set #${info.dataSetId}`)

src/add/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { CLIAuthOptions } from '../utils/cli-auth.js'
44
export interface AddOptions extends CLIAuthOptions {
55
filePath: string
66
bare?: boolean
7-
/** Auto-fund: automatically ensure minimum 10 days of runway */
7+
/** Auto-fund: automatically ensure minimum 30 days of runway */
88
autoFund?: boolean
99
}
1010

src/common/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
22
* Minimum runway in days to ensure WarmStorage can cover costs. Used when `--auto-fund` is passed to import or add commands
33
*/
4-
export const MIN_RUNWAY_DAYS = 10
4+
export const MIN_RUNWAY_DAYS = 30

src/common/upload-flow.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Synapse } from '@filoz/synapse-sdk'
99
import type { CID } from 'multiformats/cid'
1010
import pc from 'picocolors'
1111
import type { Logger } from 'pino'
12-
import type { PaymentCapacityCheck } from '../core/payments/index.js'
12+
import { DEFAULT_LOCKUP_DAYS, type PaymentCapacityCheck } from '../core/payments/index.js'
1313
import { cleanupSynapseService, type SynapseService } from '../core/synapse/index.js'
1414
import { checkUploadReadiness, executeUpload, getDownloadURL, type SynapseUploadResult } from '../core/upload/index.js'
1515
import { formatUSDFC } from '../core/utils/format.js'
@@ -48,7 +48,7 @@ export interface UploadFlowResult extends SynapseUploadResult {
4848

4949
/**
5050
* Perform auto-funding if requested
51-
* Automatically ensures a minimum of 10 days of runway based on current usage + new file requirements
51+
* Automatically ensures a minimum of 30 days of runway based on current usage + new file requirements
5252
*
5353
* @param synapse - Initialized Synapse instance
5454
* @param fileSize - Size of file being uploaded (in bytes)
@@ -207,7 +207,7 @@ function displayPaymentIssues(capacityCheck: PaymentCapacityCheck, fileSize: num
207207
log.indent(
208208
`Required deposit: ${formatUSDFC(capacityCheck.required.lockupAllowance + capacityCheck.required.lockupAllowance / 10n)} USDFC`
209209
)
210-
log.indent(pc.gray('(includes 10-day safety reserve)'))
210+
log.indent(pc.gray(`(includes ${DEFAULT_LOCKUP_DAYS}-day safety reserve)`))
211211
log.line('')
212212

213213
log.line(pc.bold('Suggested actions:'))

src/core/payments/index.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { isSessionKeyMode } from '../synapse/index.js'
2222
// Constants
2323
export const USDFC_DECIMALS = 18
2424
const MIN_FIL_FOR_GAS = ethers.parseEther('0.1') // Minimum FIL padding for gas
25-
export const DEFAULT_LOCKUP_DAYS = 10 // WarmStorage requires 10 days lockup
25+
export const DEFAULT_LOCKUP_DAYS = 30 // WarmStorage requires 30 days lockup
2626

2727
// Maximum allowances for trusted WarmStorage service
2828
// Using MaxUint256 which MetaMask displays as "Unlimited"
@@ -381,7 +381,7 @@ export async function setServiceApprovals(
381381
): Promise<string> {
382382
const warmStorageAddress = synapse.getWarmStorageAddress()
383383

384-
// Max lockup period is always 10 days worth of epochs for WarmStorage
384+
// Max lockup period is always 30 days worth of epochs for WarmStorage
385385
const maxLockupPeriod = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
386386

387387
// Set the service approval
@@ -415,9 +415,11 @@ export async function checkAllowances(synapse: Synapse): Promise<{
415415
// Get current allowances
416416
const currentAllowances = await synapse.payments.serviceApproval(warmStorageAddress, TOKENS.USDFC)
417417

418-
// Check if we need to update (not at max)
418+
// Check if we need to update (not at max or max lockup period is not enough)
419419
const needsUpdate =
420-
currentAllowances.rateAllowance < MAX_RATE_ALLOWANCE || currentAllowances.lockupAllowance < MAX_LOCKUP_ALLOWANCE
420+
currentAllowances.rateAllowance < MAX_RATE_ALLOWANCE ||
421+
currentAllowances.lockupAllowance < MAX_LOCKUP_ALLOWANCE ||
422+
currentAllowances.maxLockupPeriod < BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
421423

422424
return {
423425
needsUpdate,
@@ -537,9 +539,9 @@ export function calculateStorageAllowances(storageTiB: number, pricePerTiBPerEpo
537539
// Calculate rate allowance (per epoch payment)
538540
const rateAllowance = (pricePerTiBPerEpoch * BigInt(scaledStorage)) / BigInt(scale)
539541

540-
// Calculate lockup allowance (10 days worth)
541-
const epochsIn10Days = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
542-
const lockupAllowance = rateAllowance * epochsIn10Days
542+
// Calculate lockup allowance
543+
const epochsInLockupDays = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
544+
const lockupAllowance = rateAllowance * epochsInLockupDays
543545

544546
return {
545547
rateAllowance,
@@ -580,7 +582,7 @@ export function calculateActualCapacity(rateAllowance: bigint, pricePerTiBPerEpo
580582
* Calculate storage capacity from USDFC amount
581583
*
582584
* Determines how much storage can be purchased with a given USDFC amount,
583-
* accounting for the 10-day lockup period.
585+
* accounting for the 30-day lockup period.
584586
*
585587
* @param usdfcAmount - Amount of USDFC in its smallest unit
586588
* @param pricePerTiBPerEpoch - Current pricing from storage service
@@ -589,17 +591,17 @@ export function calculateActualCapacity(rateAllowance: bigint, pricePerTiBPerEpo
589591
export function calculateStorageFromUSDFC(usdfcAmount: bigint, pricePerTiBPerEpoch: bigint): number {
590592
if (pricePerTiBPerEpoch === 0n) return 0
591593

592-
// Calculate how much this covers for 10 days
593-
const epochsIn10Days = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
594-
const ratePerEpoch = usdfcAmount / epochsIn10Days
594+
// Calculate how much this covers for lockup
595+
const epochsInLockupDays = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
596+
const ratePerEpoch = usdfcAmount / epochsInLockupDays
595597

596598
return calculateActualCapacity(ratePerEpoch, pricePerTiBPerEpoch)
597599
}
598600

599601
/**
600602
* Compute the additional deposit required to fund current usage for a duration.
601603
*
602-
* The WarmStorage service maintains ~10 days of lockup (lockupUsed) and draws future
604+
* The WarmStorage service maintains ~30 days of lockup (lockupUsed) and draws future
603605
* lockups from the available deposit (deposited - lockupUsed). To keep the current
604606
* rails alive for N days, ensure available >= N days of spend at the current rateUsed.
605607
*
@@ -808,7 +810,7 @@ export function computeAdjustmentForExactDaysWithPiece(
808810
* treating WarmStorage as fully trusted with max allowances, i.e. not
809811
* accounting for allowance limits. If usage limits need to be accounted for
810812
* then the capacity can be capped by either deposit or allowances.
811-
* This function accounts for the 10-day lockup requirement.
813+
* This function accounts for the 30-day lockup requirement.
812814
*
813815
* @param depositAmount - Amount deposited in USDFC
814816
* @param pricePerTiBPerEpoch - Current pricing from storage service
@@ -837,22 +839,22 @@ export function calculateDepositCapacity(
837839
}
838840

839841
// With infinite allowances, deposit is the only limiting factor
840-
// Deposit needs to cover: lockup (10 days) + at least some buffer
841-
const epochsIn10Days = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
842+
// Deposit needs to cover: lockup (30 days) + at least some buffer
843+
const epochsInLockupDays = BigInt(DEFAULT_LOCKUP_DAYS) * TIME_CONSTANTS.EPOCHS_PER_DAY
842844
const epochsPerMonth = TIME_CONSTANTS.EPOCHS_PER_MONTH
843845

844846
// Maximum storage we can support with this deposit
845847
// Reserve 10% for buffer beyond the lockup
846848
// Calculate max rate per epoch we can afford with deposit
847-
const maxRatePerEpoch = (depositAmount * BUFFER_DENOMINATOR) / (epochsIn10Days * BUFFER_NUMERATOR)
849+
const maxRatePerEpoch = (depositAmount * BUFFER_DENOMINATOR) / (epochsInLockupDays * BUFFER_NUMERATOR)
848850

849851
// Convert to storage capacity
850852
const tibPerMonth = calculateActualCapacity(maxRatePerEpoch, pricePerTiBPerEpoch)
851853
const gibPerMonth = tibPerMonth * 1024
852854

853855
// Calculate the actual costs for this capacity
854856
const monthlyPayment = maxRatePerEpoch * epochsPerMonth
855-
const requiredLockup = maxRatePerEpoch * epochsIn10Days
857+
const requiredLockup = maxRatePerEpoch * epochsInLockupDays
856858
const totalRequired = withBuffer(requiredLockup)
857859

858860
return {

src/core/synapse/index.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type ProviderInfo,
66
RPC_URLS,
77
type StorageContext,
8-
type StorageCreationCallbacks,
8+
type StorageContextCallbacks,
99
type StorageServiceOptions,
1010
Synapse,
1111
type SynapseOptions,
@@ -144,11 +144,6 @@ export interface DatasetOptions {
144144
metadata?: Record<string, string>
145145
}
146146

147-
/**
148-
* Progress callbacks for tracking dataset and provider selection.
149-
*/
150-
export type StorageProgressCallbacks = Omit<StorageCreationCallbacks, 'onDataSetCreationProgress'>
151-
152147
/**
153148
* Options for creating a storage context.
154149
*/
@@ -161,7 +156,7 @@ export interface CreateStorageContextOptions {
161156
/**
162157
* Progress callbacks for tracking creation.
163158
*/
164-
callbacks?: StorageProgressCallbacks
159+
callbacks?: StorageContextCallbacks
165160

166161
/**
167162
* Override provider selection by address.
@@ -440,7 +435,7 @@ export async function createStorageContext(
440435
* Callbacks provide visibility into the storage lifecycle
441436
* These are crucial for debugging and monitoring in production
442437
*/
443-
const callbacks: StorageCreationCallbacks = {
438+
const callbacks: StorageContextCallbacks = {
444439
onProviderSelected: (provider) => {
445440
currentProviderInfo = provider
446441

@@ -471,29 +466,6 @@ export async function createStorageContext(
471466

472467
options?.callbacks?.onDataSetResolved?.(info)
473468
},
474-
onDataSetCreationStarted: (transaction, statusUrl) => {
475-
logger.info(
476-
{
477-
event: 'synapse.storage.data_set_creation_started',
478-
txHash: transaction.hash,
479-
statusUrl,
480-
},
481-
'Data set creation transaction submitted'
482-
)
483-
484-
options?.callbacks?.onDataSetCreationStarted?.(transaction)
485-
},
486-
onDataSetCreationProgress: (status) => {
487-
logger.info(
488-
{
489-
event: 'synapse.storage.data_set_creation_progress',
490-
transactionMined: status.transactionMined,
491-
dataSetLive: status.dataSetLive,
492-
elapsedMs: status.elapsedMs,
493-
},
494-
'Data set creation progress'
495-
)
496-
},
497469
}
498470

499471
sdkOptions.callbacks = callbacks

src/core/upload/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ export async function executeUpload(
205205
onUploadComplete: (pieceCid) => {
206206
callbacks?.onUploadComplete?.(pieceCid)
207207
},
208-
onPieceAdded: (transaction) => {
209-
if (transaction?.hash) {
210-
transactionHash = transaction.hash
208+
onPieceAdded: (txHash) => {
209+
if (txHash) {
210+
transactionHash = txHash
211211
}
212-
callbacks?.onPieceAdded?.(transaction)
212+
callbacks?.onPieceAdded?.(txHash)
213213
},
214214
onPieceConfirmed: (pieceIds) => {
215215
callbacks?.onPieceConfirmed?.(pieceIds)

src/core/upload/synapse.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ export async function uploadToSynapse(
8787
callbacks?.onUploadComplete?.(pieceCid)
8888
},
8989

90-
onPieceAdded: (transaction) => {
91-
if (transaction != null) {
90+
onPieceAdded: (txHash) => {
91+
if (txHash != null) {
9292
logger.info(
9393
{
9494
event: 'synapse.upload.piece_added',
9595
contextId,
96-
txHash: transaction.hash,
96+
txHash: txHash,
9797
},
9898
'Piece addition transaction submitted'
9999
)
@@ -106,7 +106,7 @@ export async function uploadToSynapse(
106106
'Piece added to data set'
107107
)
108108
}
109-
callbacks?.onPieceAdded?.(transaction)
109+
callbacks?.onPieceAdded?.(txHash)
110110
},
111111

112112
onPieceConfirmed: (pieceIds) => {

src/data-set/inspect.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ function formatPaymentToken(tokenAddress: string): string {
6262
* Format storage price in USDFC per TiB per month
6363
* Always shows TiB/month for consistency, with appropriate precision
6464
*/
65-
function formatStoragePrice(pricePerTiBPerMonth: bigint): string {
65+
function formatStoragePrice(pricePerTiBPerDay: bigint): string {
6666
try {
67-
const priceInUSDFC = parseFloat(ethers.formatUnits(pricePerTiBPerMonth, 18))
67+
const priceInUSDFC = parseFloat(ethers.formatUnits(pricePerTiBPerDay, 18))
6868

6969
// Handle very small prices that would show as 0.0000
7070
if (priceInUSDFC < 0.0001) {
71-
return '< 0.0001 USDFC/TiB/month'
71+
return '< 0.0001 USDFC/TiB/day'
7272
}
7373

7474
// For prices >= 0.0001, show with appropriate precision
7575
if (priceInUSDFC >= 1) {
76-
return `${priceInUSDFC.toFixed(2)} USDFC/TiB/month`
76+
return `${priceInUSDFC.toFixed(2)} USDFC/TiB/day`
7777
} else if (priceInUSDFC >= 0.01) {
78-
return `${priceInUSDFC.toFixed(4)} USDFC/TiB/month`
78+
return `${priceInUSDFC.toFixed(4)} USDFC/TiB/day`
7979
} else {
80-
return `${priceInUSDFC.toFixed(6)} USDFC/TiB/month`
80+
return `${priceInUSDFC.toFixed(6)} USDFC/TiB/day`
8181
}
8282
} catch {
8383
return pc.red('invalid price')
@@ -235,7 +235,7 @@ export function displayDataSetStatus(ctx: DataSetInspectionContext, dataSetId: n
235235
log.indent(`Service URL: ${pdpData.serviceURL}`)
236236
log.indent(`Min piece size: ${formatBytes(BigInt(pdpData.minPieceSizeInBytes))}`)
237237
log.indent(`Max piece size: ${formatBytes(BigInt(pdpData.maxPieceSizeInBytes))}`)
238-
log.indent(`Storage price: ${formatStoragePrice(pdpData.storagePricePerTibPerMonth)}`)
238+
log.indent(`Storage price: ${formatStoragePrice(pdpData.storagePricePerTibPerDay)}`)
239239
log.indent(`Min proving period: ${pdpData.minProvingPeriodInEpochs} epochs`)
240240
log.indent(`Location: ${pdpData.location}`)
241241
log.indent(`Payment token: ${formatPaymentToken(pdpData.paymentTokenAddress)}`)
@@ -244,9 +244,6 @@ export function displayDataSetStatus(ctx: DataSetInspectionContext, dataSetId: n
244244
if (base.pdpEndEpoch > 0) {
245245
log.indent(pc.yellow(`PDP payments ended @ epoch ${base.pdpEndEpoch}`))
246246
}
247-
if (base.cdnEndEpoch > 0) {
248-
log.indent(pc.yellow(`CDN payments ended @ epoch ${base.cdnEndEpoch}`))
249-
}
250247

251248
log.line('')
252249
log.line(pc.bold('Metadata'))

0 commit comments

Comments
 (0)