Skip to content

calculateUploadCosts

calculateUploadCosts(options): OutputType

Defined in: packages/synapse-core/src/utils/calculate-upload-costs.ts:176

Calculate upload costs from already-resolved pricing, account, and data-set state.

Context-specific rates, fees, and lockups are calculated independently and summed. Account debt, available funds, runway, and the execution buffer are then applied exactly once to the aggregate, making this function suitable for both single-copy and multi-copy uploads.

Multi-piece operation fees and lifecycle-reserve replenishments are upper bounds: each supplied piece is treated as a separate add-pieces operation because runtime batch boundaries cannot be inferred from raw sizes alone.

This function performs no network requests and does not mutate its inputs. Callers must resolve existing data-set and payer state at a consistent chain snapshot before calling it.

ParameterTypeDescription
optionsOptionsTypecalculateUploadCosts.OptionsType

OutputType

Aggregated upload costs and funding readiness calculateUploadCosts.OutputType

ValidationError when no contexts are supplied or context state is invalid

import { calculateUploadCosts } from '@filoz/synapse-core/utils'
import { getPriceList } from '@filoz/synapse-core/warm-storage'
import { calibration } from '@filoz/synapse-core/chains'
import { createPublicClient, http } from 'viem'
const client = createPublicClient({
chain: calibration,
transport: http(),
})
const priceList = await getPriceList(client)
const costs = calculateUploadCosts({
contexts: [{ pieceSizes: [1_000_000n], withCDN: false, dataSet: null }],
priceList,
account: {
currentLockupRate: 0n,
debt: 0n,
availableFunds: 0n,
runwayInEpochs: 0n,
fwssMaxApproved: true,
},
})
console.log(costs.depositNeeded)