Skip to content

utils

Namespace Description
calculateUploadCosts -
createPieceUrl -
createPieceUrlFilBeam -
createPieceUrlPDP -
dedupePieces -
Interface Description
MetadataDataSetInternal -
MetadataPieceInternal -
Type Alias Description
CalculateBufferAmountFromStateOptions -
CalculateRunwayAmountFromStateOptions -
ClaimTokenResponse -
ClaimTokenResponseError -
ClaimTokensOptions -
DroppedPiece An input removed by dedupePieces because an earlier input has the same PieceCID.
FormatUnitsOptions -
Limit A function that runs a task once fewer than its limit of tasks are running.
MetadataArray The metadata array is a tuple of two arrays: the keys and the values. Return type from the getAllDataSetMetadata function.
MetadataEntry -
MetadataObject -
StringErrorType FOC contracts errors types
Variable Description
DEFAULT_BUFFER_EPOCHS Default safety margin in epochs when calculating deposit amounts. Accounts for epoch drift between balance check and on-chain execution.
DEFAULT_RUNWAY_EPOCHS Default extra runway in epochs beyond the required lockup. 0n means no additional runway beyond the lockup period.
METADATA_LIMITS -
PDP_OFFERING_KEYS Capability keys that are decoded into typed PDPOffering fields. (must match ServiceProviderRegistry.sol REQUIRED_PDP_KEYS)
PDP_OFFERING_KEYS_SET Set of PDP offering keys.
PDPOfferingSchema Zod schema for PDP offering
RETRY_CONSTANTS -
SERVICE_PROVIDER_REGISTRY Limits mirrored from ServiceProviderRegistry.sol. Sync with VERSION in that contract (currently 1.1.0) when upgrading.
SIZE_CONSTANTS Data size constants
STRING_ERRORS FOC contracts errors strings
TIME_CONSTANTS Time and size constants
zAddress -
zAddressLoose -
zHex -
zNumberToBigInt -
zPieceCid -
zPieceCidString -
zStringToCid -
Function Description
calculateBufferAmountFromState Calculate the account funding buffer for transaction execution delay.
calculateLastProofDate Calculate when the last proof should have been submitted based on current time
calculateRunwayAmountFromState Calculate extra account funding for the requested post-upload runway.
calculateUploadCosts Calculate upload costs from already-resolved pricing, account, and data-set state.
capabilitiesListToObject Convert capability arrays to object map
claimTokens -
clientFromTransport Create a Viem public client from a transport configuration
createLimit Create a limit that runs at most concurrency tasks at a time, in call order.
createPieceUrl Create a piece URL for the CDN or PDP API
createPieceUrlFilBeam Create a piece URL for FilBeam.
createPieceUrlPDP Create a piece URL for the PDP API
datasetMetadataObjectToEntry Convert a dataset metadata object to an array of metadata entries to be signed.
dateToEpoch Convert a JavaScript Date to a Filecoin epoch
decodeAddressCapability Matches the behavior of address(uint160(BigEndian.decode(values[i])))
decodePDPCapabilities Decode PDP capabilities from keys/values arrays into a PDPOffering object. Based on Curio’s capabilitiesToOffering function.
decodePDPError -
decodePDPOffering Decode the PDP offering from the provider.
dedupePieces Remove inputs whose PieceCID already appeared earlier in the array.
encodePDPCapabilities Encode a PDPOffering plus optional user-supplied extras into the (keys[], values[]) tuple consumed by registerProvider / addProduct / updateProduct on ServiceProviderRegistry.
epochsToDays Convert a number of epochs to whole days (floor division).
epochsToHours Convert a number of epochs to whole hours (floor division).
epochToDate Convert a Filecoin epoch to a JavaScript Date
fallbackRandIndex -
fallbackRandU256 -
formatBalance -
formatFraction -
formatUnits -
getPayerAddress Get the address that pays for an account’s storage: a session key signs as itself, but its root wallet pays.
isAsyncIterable Type guard to check if a value is an AsyncIterable
isProviderExistsRevert Check whether the given error is a revert emitted by the ServiceProviderRegistry.providerExists modifier (i.e. the provider ID is out of range or maps to an unoccupied storage slot).
isReadableStream Type guard to check if a value is a ReadableStream
isUint8Array Check if value is Uint8Array
isViemError Check if the error is a viem error
leafCountToRawSize Convert a PDP data-bearing leaf count to the byte size used by FWSS pricing.
mapWithLimit Like Promise.all(items.map(fn)), but runs at most concurrency calls at a time.
metadataArrayToObject -
parseUnits Parse a value to a bigint.
pieceMetadataObjectToEntry Convert a dataset metadata object to an array of metadata entries to be signed.
pieceSizesToLeafCount Sum the PDP data-bearing leaves produced by known raw piece sizes.
randIndex Provides a random index into an array of supplied length (0 <= index < length)
randU256 -
rawSizeToLeafCount Calculate the PDP data-bearing leaf count for a known raw piece size.
stringErrorEquals Check if the error message equals the expected string
supportsStreamingFetchBody Detect whether the current environment supports ReadableStream as a fetch request body. Firefox stringifies the stream to “[object ReadableStream]” instead of consuming it, and Safari silently ignores the stream body and the duplex option. This check catches both: a browser that stringifies will set Content-Type to text/plain (string body), and one that ignores duplex will fail the duplexAccessed gate. The try/catch handles any future browser that throws on the Request constructor.
timeUntilEpoch Calculate the time until a future epoch
transportFromTransportConfig Create a Viem public client from a transport configuration
validatePieceSizes Validate known raw piece sizes.