Skip to content

utils

NamespaceDescription
calculateUploadCosts-
createPieceUrl-
createPieceUrlPDP-
InterfaceDescription
MetadataDataSetInternal-
MetadataPieceInternal-
Type AliasDescription
CalculateBufferAmountFromStateOptions-
CalculateRunwayAmountFromStateOptions-
ClaimTokenResponse-
ClaimTokenResponseError-
ClaimTokensOptions-
FormatUnitsOptions-
MetadataArrayThe metadata array is a tuple of two arrays: the keys and the values. Return type from the getAllDataSetMetadata function.
MetadataEntry-
MetadataObject-
StringErrorTypeFOC contracts errors types
VariableDescription
DEFAULT_BUFFER_EPOCHSDefault safety margin in epochs when calculating deposit amounts. Accounts for epoch drift between balance check and on-chain execution.
DEFAULT_RUNWAY_EPOCHSDefault extra runway in epochs beyond the required lockup. 0n means no additional runway beyond the lockup period.
METADATA_LIMITS-
PDP_OFFERING_KEYSCapability keys that are decoded into typed PDPOffering fields. (must match ServiceProviderRegistry.sol REQUIRED_PDP_KEYS)
PDP_OFFERING_KEYS_SETSet of PDP offering keys.
PDPOfferingSchemaZod schema for PDP offering
RETRY_CONSTANTS-
SERVICE_PROVIDER_REGISTRYLimits mirrored from ServiceProviderRegistry.sol. Sync with VERSION in that contract (currently 1.1.0) when upgrading.
SIZE_CONSTANTSData size constants
STRING_ERRORSFOC contracts errors strings
TIME_CONSTANTSTime and size constants
zAddress-
zAddressLoose-
zHex-
zNumberToBigInt-
zPieceCid-
zPieceCidString-
zStringToCid-
FunctionDescription
calculateBufferAmountFromStateCalculate the account funding buffer for transaction execution delay.
calculateLastProofDateCalculate when the last proof should have been submitted based on current time
calculateRunwayAmountFromStateCalculate extra account funding for the requested post-upload runway.
calculateUploadCostsCalculate upload costs from already-resolved pricing, account, and data-set state.
capabilitiesListToObjectConvert capability arrays to object map
claimTokens-
clientFromTransportCreate a Viem public client from a transport configuration
createPieceUrlCreate a piece URL for the CDN or PDP API
createPieceUrlPDPCreate a piece URL for the PDP API
datasetMetadataObjectToEntryConvert a dataset metadata object to an array of metadata entries to be signed.
dateToEpochConvert a JavaScript Date to a Filecoin epoch
decodeAddressCapabilityMatches the behavior of address(uint160(BigEndian.decode(values[i])))
decodePDPCapabilitiesDecode PDP capabilities from keys/values arrays into a PDPOffering object. Based on Curio’s capabilitiesToOffering function.
decodePDPError-
decodePDPOfferingDecode the PDP offering from the provider.
encodePDPCapabilitiesEncode a PDPOffering plus optional user-supplied extras into the (keys[], values[]) tuple consumed by registerProvider / addProduct / updateProduct on ServiceProviderRegistry.
epochsToDaysConvert a number of epochs to whole days (floor division).
epochsToHoursConvert a number of epochs to whole hours (floor division).
epochToDateConvert a Filecoin epoch to a JavaScript Date
fallbackRandIndex-
fallbackRandU256-
formatBalance-
formatFraction-
formatUnits-
isAsyncIterableType guard to check if a value is an AsyncIterable
isProviderExistsRevertCheck 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).
isReadableStreamType guard to check if a value is a ReadableStream
isUint8ArrayCheck if value is Uint8Array
isViemErrorCheck if the error is a viem error
leafCountToRawSizeConvert a PDP data-bearing leaf count to the byte size used by FWSS pricing.
metadataArrayToObject-
parseUnitsParse a value to a bigint.
pieceMetadataObjectToEntryConvert a dataset metadata object to an array of metadata entries to be signed.
pieceSizesToLeafCountSum the PDP data-bearing leaves produced by known raw piece sizes.
randIndexProvides a random index into an array of supplied length (0 <= index < length)
randU256-
rawSizeToLeafCountCalculate the PDP data-bearing leaf count for a known raw piece size.
stringErrorEqualsCheck if the error message equals the expected string
supportsStreamingFetchBodyDetect 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.
timeUntilEpochCalculate the time until a future epoch
transportFromTransportConfigCreate a Viem public client from a transport configuration
validatePieceSizesValidate known raw piece sizes.