calculateUploadCosts
calculateUploadCosts(
options):OutputType
Defined in: packages/synapse-core/src/utils/calculate-upload-costs.ts:179
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.
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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options | OptionsType | calculateUploadCosts.OptionsType |
Returns
Section titled “Returns”Aggregated upload costs and funding readiness calculateUploadCosts.OutputType
Throws
Section titled “Throws”ValidationError when no contexts are supplied or context state is invalid
Example
Section titled “Example”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)