From 1235d6839d9bceb131c927aeced4cd53f6bc7a4d Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 1 Apr 2026 12:35:19 +0100 Subject: [PATCH 1/6] feat!: rename getProviderIds to getEndorsedProviderIds and getApprovedProviders to getApprovedProvidersIds --- ...er-ids.ts => get-endorsed-provider-ids.ts} | 69 ++++++++++--------- .../synapse-core/src/endorsements/index.ts | 8 +-- .../src/sp-registry/get-pdp-providers.ts | 8 +-- .../fetch-provider-selection-input.ts | 4 +- ...iders.ts => get-approved-providers-ids.ts} | 46 ++++++------- .../synapse-core/src/warm-storage/index.ts | 2 +- .../src/warm-storage/location-types.ts | 6 +- .../src/warm-storage/select-providers.ts | 20 +++--- .../fetch-provider-selection-input.test.ts | 10 +-- .../test/get-approved-providers.test.ts | 16 ++--- .../test/get-provider-ids.test.ts | 36 +++++----- .../test/select-providers.test.ts | 54 +++++++-------- 12 files changed, 143 insertions(+), 136 deletions(-) rename packages/synapse-core/src/endorsements/{get-provider-ids.ts => get-endorsed-provider-ids.ts} (50%) rename packages/synapse-core/src/warm-storage/{get-approved-providers.ts => get-approved-providers-ids.ts} (65%) diff --git a/packages/synapse-core/src/endorsements/get-provider-ids.ts b/packages/synapse-core/src/endorsements/get-endorsed-provider-ids.ts similarity index 50% rename from packages/synapse-core/src/endorsements/get-provider-ids.ts rename to packages/synapse-core/src/endorsements/get-endorsed-provider-ids.ts index ff939e54..8fd9516f 100644 --- a/packages/synapse-core/src/endorsements/get-provider-ids.ts +++ b/packages/synapse-core/src/endorsements/get-endorsed-provider-ids.ts @@ -13,7 +13,7 @@ import type { providerIdSetAbi } from '../abis/generated.ts' import { asChain } from '../chains.ts' import type { ActionCallChain } from '../types.ts' -export namespace getProviderIds { +export namespace getEndorsedProviderIds { export type OptionsType = { /** Endorsements contract address. If not provided, the default is the endorsements contract address for the chain. */ contractAddress?: Address @@ -25,8 +25,8 @@ export namespace getProviderIds { 'getProviderIds' > - /** Set of endorsed provider IDs */ - export type OutputType = Set + /** Array of endorsed provider IDs */ + export type OutputType = bigint[] export type ErrorType = asChain.ErrorType | ReadContractErrorType } @@ -35,13 +35,13 @@ export namespace getProviderIds { * Get all endorsed provider IDs * * @param client - The client to use to get the endorsed providers. - * @param options - {@link getProviderIds.OptionsType} - * @returns Set of endorsed provider IDs {@link getProviderIds.OutputType} - * @throws Errors {@link getProviderIds.ErrorType} + * @param options - {@link getEndorsedProviderIds.OptionsType} + * @returns Array of endorsed provider IDs {@link getEndorsedProviderIds.OutputType} + * @throws Errors {@link getEndorsedProviderIds.ErrorType} * * @example * ```ts - * import { getProviderIds } from '@filoz/synapse-core/endorsements' + * import { getEndorsedProviderIds } from '@filoz/synapse-core/endorsements' * import { createPublicClient, http } from 'viem' * import { calibration } from '@filoz/synapse-core/chains' * @@ -50,46 +50,46 @@ export namespace getProviderIds { * transport: http(), * }) * - * const providerIds = await getProviderIds(client) + * const providerIds = await getEndorsedProviderIds(client) * * console.log(providerIds) * ``` */ -export async function getProviderIds( +export async function getEndorsedProviderIds( client: Client, - options: getProviderIds.OptionsType = {} -): Promise { + options: getEndorsedProviderIds.OptionsType = {} +): Promise { const data = await readContract( client, - getProviderIdsCall({ + getEndorsedProviderIdsCall({ chain: client.chain, contractAddress: options.contractAddress, }) ) - return parseGetProviderIds(data) + return parseGetEndorsedProviderIds(data) } -export namespace getProviderIdsCall { - export type OptionsType = Simplify +export namespace getEndorsedProviderIdsCall { + export type OptionsType = Simplify export type ErrorType = asChain.ErrorType export type OutputType = ContractFunctionParameters } /** - * Create a call to the getProviderIds function + * Create a call to the getEndorsedProviderIds function * - * This function is used to create a call to the getProviderIds function for use with the multicall or readContract function. + * This function is used to create a call to the getEndorsedProviderIds function for use with the multicall or readContract function. * - * To get the same output type as the action, use {@link parseGetProviderIds} to transform the contract output. + * To get the same output type as the action, use {@link parseGetEndorsedProviderIds} to transform the contract output. * - * @param options - {@link getProviderIdsCall.OptionsType} - * @returns The call to the getProviderIds function {@link getProviderIdsCall.OutputType} - * @throws Errors {@link getProviderIdsCall.ErrorType} + * @param options - {@link getEndorsedProviderIdsCall.OptionsType} + * @returns The call to the getProviderIds function {@link getEndorsedProviderIdsCall.OutputType} + * @throws Errors {@link getEndorsedProviderIdsCall.ErrorType} * * @example * ```ts - * import { getProviderIdsCall } from '@filoz/synapse-core/endorsements' + * import { getEndorsedProviderIdsCall } from '@filoz/synapse-core/endorsements' * import { createPublicClient, http } from 'viem' * import { multicall } from 'viem/actions' * import { calibration } from '@filoz/synapse-core/chains' @@ -101,37 +101,40 @@ export namespace getProviderIdsCall { * * const results = await multicall(client, { * contracts: [ - * getProviderIdsCall({ chain: calibration }), + * getEndorsedProviderIdsCall({ chain: calibration }), * ], * }) * * console.log(results[0]) * ``` */ -export function getProviderIdsCall(options: getProviderIdsCall.OptionsType) { +export function getEndorsedProviderIdsCall(options: getEndorsedProviderIdsCall.OptionsType) { const chain = asChain(options.chain) return { abi: chain.contracts.endorsements.abi, address: options.contractAddress ?? chain.contracts.endorsements.address, functionName: 'getProviderIds', args: [], - } satisfies getProviderIdsCall.OutputType + } satisfies getEndorsedProviderIdsCall.OutputType } /** - * Parse the result of the getProviderIds function + * Parse the result of the getEndorsedProviderIds function * - * @param data - The result of the getProviderIds function {@link getProviderIds.ContractOutputType} - * @returns Set of endorsed provider IDs {@link getProviderIds.OutputType} + * @param data - The result of the getEndorsedProviderIds function {@link getEndorsedProviderIds.ContractOutputType} + * @returns Array of endorsed provider IDs {@link getEndorsedProviderIds.OutputType} * * @example * ```ts - * import { parseGetProviderIds } from '@filoz/synapse-core/endorsements' + * import { parseGetEndorsedProviderIds } from '@filoz/synapse-core/endorsements' * - * const providerIds = parseGetProviderIds([1n, 2n, 1n]) - * console.log(providerIds) // Set { 1n, 2n } + * const providerIds = parseGetEndorsedProviderIds([1n, 2n, 1n]) + * console.log(providerIds) // [1n, 2n] * ``` */ -export function parseGetProviderIds(data: getProviderIds.ContractOutputType): getProviderIds.OutputType { - return new Set(data) +export function parseGetEndorsedProviderIds( + data: getEndorsedProviderIds.ContractOutputType +): getEndorsedProviderIds.OutputType { + // deduplicate provider IDs + return Array.from(new Set(data)) } diff --git a/packages/synapse-core/src/endorsements/index.ts b/packages/synapse-core/src/endorsements/index.ts index 590e4ec3..105acd87 100644 --- a/packages/synapse-core/src/endorsements/index.ts +++ b/packages/synapse-core/src/endorsements/index.ts @@ -1,5 +1,5 @@ export { - getProviderIds, - getProviderIdsCall, - parseGetProviderIds, -} from './get-provider-ids.ts' + getEndorsedProviderIds, + getEndorsedProviderIdsCall, + parseGetEndorsedProviderIds, +} from './get-endorsed-provider-ids.ts' diff --git a/packages/synapse-core/src/sp-registry/get-pdp-providers.ts b/packages/synapse-core/src/sp-registry/get-pdp-providers.ts index 98d2165d..67507602 100644 --- a/packages/synapse-core/src/sp-registry/get-pdp-providers.ts +++ b/packages/synapse-core/src/sp-registry/get-pdp-providers.ts @@ -13,7 +13,7 @@ import { multicall, readContract } from 'viem/actions' import type { serviceProviderRegistry as serviceProviderRegistryAbi } from '../abis/index.ts' import { asChain } from '../chains.ts' import type { ActionCallChain } from '../types.ts' -import { getApprovedProvidersCall } from '../warm-storage/get-approved-providers.ts' +import { getApprovedProvidersIdsCall } from '../warm-storage/get-approved-providers-ids.ts' import { getPDPProviderCall, parsePDPProvider } from './get-pdp-provider.ts' import type { getProvidersByProductType } from './get-providers-by-product-type.ts' import { type PDPProvider, PRODUCTS, type ProviderWithProduct } from './types.ts' @@ -151,7 +151,7 @@ export namespace getApprovedPDPProviders { export type ErrorType = | asChain.ErrorType | MulticallErrorType - | getApprovedProvidersCall.ErrorType + | getApprovedProvidersIdsCall.ErrorType | getPDPProvidersCall.ErrorType } @@ -193,7 +193,7 @@ export async function getApprovedPDPProviders( limit: 100n, contractAddress: options.contractAddress, }), - getApprovedProvidersCall({ + getApprovedProvidersIdsCall({ chain: client.chain, }), ], @@ -223,7 +223,7 @@ export namespace getPDPProvidersByIds { export type ErrorType = | asChain.ErrorType | MulticallErrorType - | getApprovedProvidersCall.ErrorType + | getApprovedProvidersIdsCall.ErrorType | getPDPProvidersCall.ErrorType } diff --git a/packages/synapse-core/src/warm-storage/fetch-provider-selection-input.ts b/packages/synapse-core/src/warm-storage/fetch-provider-selection-input.ts index 7c46bc5b..37080203 100644 --- a/packages/synapse-core/src/warm-storage/fetch-provider-selection-input.ts +++ b/packages/synapse-core/src/warm-storage/fetch-provider-selection-input.ts @@ -1,5 +1,5 @@ import type { Address, Chain, Client, Transport } from 'viem' -import { getProviderIds } from '../endorsements/get-provider-ids.ts' +import { getEndorsedProviderIds } from '../endorsements/get-endorsed-provider-ids.ts' import { getApprovedPDPProviders } from '../sp-registry/get-pdp-providers.ts' import { getPdpDataSets } from './get-pdp-data-sets.ts' import type { ProviderSelectionInput } from './location-types.ts' @@ -34,7 +34,7 @@ export async function fetchProviderSelectionInput( ): Promise { const [providers, endorsedIds, pdpDataSets] = await Promise.all([ getApprovedPDPProviders(client), - getProviderIds(client), + getEndorsedProviderIds(client), getPdpDataSets(client, { address: options.address }), ]) diff --git a/packages/synapse-core/src/warm-storage/get-approved-providers.ts b/packages/synapse-core/src/warm-storage/get-approved-providers-ids.ts similarity index 65% rename from packages/synapse-core/src/warm-storage/get-approved-providers.ts rename to packages/synapse-core/src/warm-storage/get-approved-providers-ids.ts index 1c5aa456..b4a54dcb 100644 --- a/packages/synapse-core/src/warm-storage/get-approved-providers.ts +++ b/packages/synapse-core/src/warm-storage/get-approved-providers-ids.ts @@ -13,7 +13,7 @@ import type { fwssView as storageViewAbi } from '../abis/index.ts' import { asChain } from '../chains.ts' import type { ActionCallChain } from '../types.ts' -export namespace getApprovedProviders { +export namespace getApprovedProvidersIds { export type OptionsType = { /** Starting index (0-based). Use 0 to start from beginning. Defaults to 0. */ offset?: bigint @@ -36,19 +36,19 @@ export namespace getApprovedProviders { } /** - * Get approved provider IDs with optional pagination + * Get all approved provider IDs with optional pagination * * For large lists, use pagination to avoid gas limit issues. If limit=0, * returns all remaining providers starting from offset. * * @param client - The client to use to get the approved providers. - * @param options - {@link getApprovedProviders.OptionsType} - * @returns Array of approved provider IDs {@link getApprovedProviders.OutputType} - * @throws Errors {@link getApprovedProviders.ErrorType} + * @param options - {@link getApprovedProvidersIds.OptionsType} + * @returns Array of approved provider IDs {@link getApprovedProvidersIds.OutputType} + * @throws Errors {@link getApprovedProvidersIds.ErrorType} * * @example * ```ts - * import { getApprovedProviders } from '@filoz/synapse-core/warm-storage' + * import { getApprovedProvidersIds } from '@filoz/synapse-core/warm-storage' * import { createPublicClient, http } from 'viem' * import { calibration } from '@filoz/synapse-core/chains' * @@ -58,7 +58,7 @@ export namespace getApprovedProviders { * }) * * // Get first 100 providers - * const providerIds = await getApprovedProviders(client, { + * const providerIds = await getApprovedProvidersIds(client, { * offset: 0n, * limit: 100n, * }) @@ -66,39 +66,39 @@ export namespace getApprovedProviders { * console.log(providerIds) * ``` */ -export async function getApprovedProviders( +export async function getApprovedProvidersIds( client: Client, - options: getApprovedProviders.OptionsType = {} -): Promise { + options: getApprovedProvidersIds.OptionsType = {} +): Promise { const data = await readContract( client, - getApprovedProvidersCall({ + getApprovedProvidersIdsCall({ chain: client.chain, offset: options.offset, limit: options.limit, contractAddress: options.contractAddress, }) ) - return data as getApprovedProviders.OutputType + return data as getApprovedProvidersIds.OutputType } -export namespace getApprovedProvidersCall { - export type OptionsType = Simplify +export namespace getApprovedProvidersIdsCall { + export type OptionsType = Simplify export type ErrorType = asChain.ErrorType export type OutputType = ContractFunctionParameters } /** - * Create a call to the {@link getApprovedProviders} function for use with the Viem multicall, readContract, or simulateContract functions. + * Create a call to the {@link getApprovedProvidersIds} function for use with the Viem multicall, readContract, or simulateContract functions. * - * @param options - {@link getApprovedProvidersCall.OptionsType} - * @returns Call object {@link getApprovedProvidersCall.OutputType} - * @throws Errors {@link getApprovedProvidersCall.ErrorType} + * @param options - {@link getApprovedProvidersIdsCall.OptionsType} + * @returns Call object {@link getApprovedProvidersIdsCall.OutputType} + * @throws Errors {@link getApprovedProvidersIdsCall.ErrorType} * * @example * ```ts - * import { getApprovedProvidersCall } from '@filoz/synapse-core/warm-storage' + * import { getApprovedProvidersIdsCall } from '@filoz/synapse-core/warm-storage' * import { createPublicClient, http } from 'viem' * import { multicall } from 'viem/actions' * import { calibration } from '@filoz/synapse-core/chains' @@ -111,20 +111,20 @@ export namespace getApprovedProvidersCall { * // Paginate through providers in batches of 50 * const results = await multicall(client, { * contracts: [ - * getApprovedProvidersCall({ chain: calibration, offset: 0n, limit: 50n }), - * getApprovedProvidersCall({ chain: calibration, offset: 50n, limit: 50n }), + * getApprovedProvidersIdsCall({ chain: calibration, offset: 0n, limit: 50n }), + * getApprovedProvidersIdsCall({ chain: calibration, offset: 50n, limit: 50n }), * ], * }) * * console.log(results) * ``` */ -export function getApprovedProvidersCall(options: getApprovedProvidersCall.OptionsType) { +export function getApprovedProvidersIdsCall(options: getApprovedProvidersIdsCall.OptionsType) { const chain = asChain(options.chain) return { abi: chain.contracts.fwssView.abi, address: options.contractAddress ?? chain.contracts.fwssView.address, functionName: 'getApprovedProviders', args: [options.offset ?? 0n, options.limit ?? 0n], - } satisfies getApprovedProvidersCall.OutputType + } satisfies getApprovedProvidersIdsCall.OutputType } diff --git a/packages/synapse-core/src/warm-storage/index.ts b/packages/synapse-core/src/warm-storage/index.ts index 763f0b41..beb42c6b 100644 --- a/packages/synapse-core/src/warm-storage/index.ts +++ b/packages/synapse-core/src/warm-storage/index.ts @@ -18,7 +18,7 @@ export * from './find-matching-data-sets.ts' export * from './get-account-total-storage-size.ts' export * from './get-all-data-set-metadata.ts' export * from './get-all-piece-metadata.ts' -export * from './get-approved-providers.ts' +export * from './get-approved-providers-ids.ts' export * from './get-client-data-set-ids.ts' export * from './get-client-data-sets.ts' export * from './get-client-data-sets-length.ts' diff --git a/packages/synapse-core/src/warm-storage/location-types.ts b/packages/synapse-core/src/warm-storage/location-types.ts index 80421d56..60a46594 100644 --- a/packages/synapse-core/src/warm-storage/location-types.ts +++ b/packages/synapse-core/src/warm-storage/location-types.ts @@ -34,7 +34,7 @@ export interface SelectionDataSet { * and passes it to selectProviders(). Separating data fetching * from selection keeps selectProviders() pure and testable. * - * The `endorsedIds` set controls pool restriction: + * The `endorsedIds` array controls pool restriction: * - Non-empty: only providers in this set are considered (primary selection) * - Empty: all providers in the `providers` list are considered (secondary selection) */ @@ -43,7 +43,7 @@ export interface ProviderSelectionInput { providers: PDPProvider[] /** Set of endorsed provider IDs (from endorsements.getProviderIds). * Non-empty = restrict to endorsed only. Empty = use all providers. */ - endorsedIds: Set + endorsedIds: bigint[] /** Client's existing datasets with metadata and piece counts */ clientDataSets: SelectionDataSet[] } @@ -56,7 +56,7 @@ export interface ProviderSelectionOptions extends ProviderSelectionInput { /** Number of providers to select (default: 1) */ count?: number /** Provider IDs to exclude (for retry after ping failure or multi-copy exclusion) */ - excludeProviderIds?: Set + excludeProviderIds?: bigint[] /** Desired metadata for dataset matching (empty object matches only empty-metadata datasets) */ metadata?: MetadataObject } diff --git a/packages/synapse-core/src/warm-storage/select-providers.ts b/packages/synapse-core/src/warm-storage/select-providers.ts index 61350b88..890d4876 100644 --- a/packages/synapse-core/src/warm-storage/select-providers.ts +++ b/packages/synapse-core/src/warm-storage/select-providers.ts @@ -26,13 +26,13 @@ import type { ProviderSelectionOptions, ResolvedLocation } from './location-type */ export function selectProviders(options: ProviderSelectionOptions): ResolvedLocation[] { const count = options.count ?? 1 - const excludeProviderIds = options.excludeProviderIds ?? new Set() + const excludeProviderIds = options.excludeProviderIds ?? [] const metadata = options.metadata ?? {} // Determine the eligible pool: restricted to endorsed if endorsedIds is non-empty - const isPoolRestricted = options.endorsedIds.size > 0 + const isPoolRestricted = options.endorsedIds.length > 0 const eligibleProviders = options.providers.filter( - (p) => !excludeProviderIds.has(p.id) && (!isPoolRestricted || options.endorsedIds.has(p.id)) + (p) => !excludeProviderIds.includes(p.id) && (!isPoolRestricted || options.endorsedIds.includes(p.id)) ) if (eligibleProviders.length === 0) { @@ -46,24 +46,24 @@ export function selectProviders(options: ProviderSelectionOptions): ResolvedLoca const matchingDataSets = findMatchingDataSets(eligibleDataSets, metadata) const results: ResolvedLocation[] = [] - const selectedProviderIds = new Set() + const selectedProviderIds: bigint[] = [] for (let i = 0; i < count; i++) { let found = false // Prefer a provider with an existing matching dataset (reuses payment rail) for (const ds of matchingDataSets) { - if (selectedProviderIds.has(ds.providerId)) continue + if (selectedProviderIds.includes(ds.providerId)) continue const provider = providerMap.get(ds.providerId) if (provider == null) continue results.push({ provider, dataSetId: ds.dataSetId, - endorsed: options.endorsedIds.has(ds.providerId), + endorsed: options.endorsedIds.includes(ds.providerId), dataSetMetadata: ds.metadata, }) - selectedProviderIds.add(ds.providerId) + selectedProviderIds.push(ds.providerId) found = true break } @@ -71,14 +71,14 @@ export function selectProviders(options: ProviderSelectionOptions): ResolvedLoca // Otherwise pick any eligible provider (new dataset created on commit) if (!found) { for (const provider of eligibleProviders) { - if (selectedProviderIds.has(provider.id)) continue + if (selectedProviderIds.includes(provider.id)) continue results.push({ provider, dataSetId: null, - endorsed: options.endorsedIds.has(provider.id), + endorsed: options.endorsedIds.includes(provider.id), dataSetMetadata: metadata, }) - selectedProviderIds.add(provider.id) + selectedProviderIds.push(provider.id) found = true break } diff --git a/packages/synapse-core/test/fetch-provider-selection-input.test.ts b/packages/synapse-core/test/fetch-provider-selection-input.test.ts index 1c765bf4..7711d59e 100644 --- a/packages/synapse-core/test/fetch-provider-selection-input.test.ts +++ b/packages/synapse-core/test/fetch-provider-selection-input.test.ts @@ -37,7 +37,7 @@ describe('fetchProviderSelectionInput', () => { assert.ok(result.providers.every((p) => p.pdp != null)) // Endorsed IDs from endorsements contract (empty in basic preset) - assert.ok(result.endorsedIds instanceof Set) + assert.ok(Array.isArray(result.endorsedIds)) // Client datasets populated with piece counts assert.ok(Array.isArray(result.clientDataSets)) @@ -66,7 +66,7 @@ describe('fetchProviderSelectionInput', () => { assert.equal(result.clientDataSets.length, 0) // Providers and endorsedIds still populated assert.ok(result.providers.length > 0) - assert.ok(result.endorsedIds instanceof Set) + assert.ok(Array.isArray(result.endorsedIds)) }) it('populates endorsedIds from endorsements contract', async () => { @@ -89,8 +89,8 @@ describe('fetchProviderSelectionInput', () => { address: ADDRESSES.client1, }) - assert.ok(result.endorsedIds.has(1n)) - assert.ok(result.endorsedIds.has(2n)) - assert.equal(result.endorsedIds.size, 2) + assert.ok(result.endorsedIds.includes(1n)) + assert.ok(result.endorsedIds.includes(2n)) + assert.equal(result.endorsedIds.length, 2) }) }) diff --git a/packages/synapse-core/test/get-approved-providers.test.ts b/packages/synapse-core/test/get-approved-providers.test.ts index 05679680..610d8818 100644 --- a/packages/synapse-core/test/get-approved-providers.test.ts +++ b/packages/synapse-core/test/get-approved-providers.test.ts @@ -3,7 +3,7 @@ import { setup } from 'iso-web/msw' import { createPublicClient, http } from 'viem' import { calibration, mainnet } from '../src/chains.ts' import { JSONRPC, presets } from '../src/mocks/jsonrpc/index.ts' -import { getApprovedProviders, getApprovedProvidersCall } from '../src/warm-storage/get-approved-providers.ts' +import { getApprovedProvidersIds, getApprovedProvidersIdsCall } from '../src/warm-storage/get-approved-providers-ids.ts' describe('getApprovedProviders', () => { const server = setup() @@ -22,7 +22,7 @@ describe('getApprovedProviders', () => { describe('getApprovedProvidersCall', () => { it('should create call with calibration chain defaults', () => { - const call = getApprovedProvidersCall({ + const call = getApprovedProvidersIdsCall({ chain: calibration, }) @@ -33,7 +33,7 @@ describe('getApprovedProviders', () => { }) it('should create call with mainnet chain defaults', () => { - const call = getApprovedProvidersCall({ + const call = getApprovedProvidersIdsCall({ chain: mainnet, }) @@ -44,7 +44,7 @@ describe('getApprovedProviders', () => { }) it('should use custom offset and limit', () => { - const call = getApprovedProvidersCall({ + const call = getApprovedProvidersIdsCall({ chain: calibration, offset: 10n, limit: 50n, @@ -55,7 +55,7 @@ describe('getApprovedProviders', () => { it('should use custom address when provided', () => { const customAddress = '0x1234567890123456789012345678901234567890' - const call = getApprovedProvidersCall({ + const call = getApprovedProvidersIdsCall({ chain: calibration, contractAddress: customAddress, }) @@ -73,7 +73,7 @@ describe('getApprovedProviders', () => { transport: http(), }) - const providerIds = await getApprovedProviders(client) + const providerIds = await getApprovedProvidersIds(client) assert.deepEqual(providerIds, [1n, 2n]) }) @@ -99,7 +99,7 @@ describe('getApprovedProviders', () => { transport: http(), }) - const providerIds = await getApprovedProviders(client, { + const providerIds = await getApprovedProvidersIds(client, { offset: 5n, limit: 10n, }) @@ -123,7 +123,7 @@ describe('getApprovedProviders', () => { transport: http(), }) - const providerIds = await getApprovedProviders(client) + const providerIds = await getApprovedProvidersIds(client) assert.deepEqual(providerIds, []) }) diff --git a/packages/synapse-core/test/get-provider-ids.test.ts b/packages/synapse-core/test/get-provider-ids.test.ts index d6cb3250..71a99d19 100644 --- a/packages/synapse-core/test/get-provider-ids.test.ts +++ b/packages/synapse-core/test/get-provider-ids.test.ts @@ -2,10 +2,14 @@ import assert from 'assert' import { setup } from 'iso-web/msw' import { createPublicClient, http } from 'viem' import { calibration, mainnet } from '../src/chains.ts' -import { getProviderIds, getProviderIdsCall, parseGetProviderIds } from '../src/endorsements/get-provider-ids.ts' +import { + getEndorsedProviderIds, + getEndorsedProviderIdsCall, + parseGetEndorsedProviderIds, +} from '../src/endorsements/get-endorsed-provider-ids.ts' import { JSONRPC, presets } from '../src/mocks/jsonrpc/index.ts' -describe('getProviderIds', () => { +describe('getEndorsedProviderIds', () => { const server = setup() before(async () => { @@ -20,9 +24,9 @@ describe('getProviderIds', () => { server.resetHandlers() }) - describe('getProviderIdsCall', () => { + describe('getEndorsedProviderIdsCall', () => { it('should create call with calibration chain defaults', () => { - const call = getProviderIdsCall({ + const call = getEndorsedProviderIdsCall({ chain: calibration, }) @@ -33,7 +37,7 @@ describe('getProviderIds', () => { }) it('should create call with mainnet chain defaults', () => { - const call = getProviderIdsCall({ + const call = getEndorsedProviderIdsCall({ chain: mainnet, }) @@ -45,7 +49,7 @@ describe('getProviderIds', () => { it('should use custom address when provided', () => { const customAddress = '0x1234567890123456789012345678901234567890' - const call = getProviderIdsCall({ + const call = getEndorsedProviderIdsCall({ chain: calibration, contractAddress: customAddress, }) @@ -54,21 +58,21 @@ describe('getProviderIds', () => { }) }) - describe('parseGetProviderIds', () => { + describe('parseGetEndorsedProviderIds', () => { it('should convert array to Set', () => { const data = [1n, 2n, 3n] - const result = parseGetProviderIds(data) - assert.deepEqual(result, new Set([1n, 2n, 3n])) + const result = parseGetEndorsedProviderIds(data) + assert.deepEqual(result, [1n, 2n, 3n]) }) it('should deduplicate provider IDs', () => { const data = [1n, 2n, 1n, 3n, 2n] - const result = parseGetProviderIds(data) - assert.deepEqual(result, new Set([1n, 2n, 3n])) + const result = parseGetEndorsedProviderIds(data) + assert.deepEqual(result, [1n, 2n, 3n]) }) }) - describe('getProviderIds (with mocked RPC)', () => { + describe('getEndorsedProviderIds (with mocked RPC)', () => { it('should fetch endorsed provider IDs', async () => { server.use( JSONRPC({ @@ -85,9 +89,9 @@ describe('getProviderIds', () => { transport: http(), }) - const providerIds = await getProviderIds(client) + const providerIds = await getEndorsedProviderIds(client) - assert.deepEqual(providerIds, new Set([1n, 2n, 3n])) + assert.deepEqual(providerIds, [1n, 2n, 3n]) }) it('should return empty Set when no providers endorsed', async () => { @@ -106,9 +110,9 @@ describe('getProviderIds', () => { transport: http(), }) - const providerIds = await getProviderIds(client) + const providerIds = await getEndorsedProviderIds(client) - assert.deepEqual(providerIds, new Set()) + assert.deepEqual(providerIds, []) }) }) }) diff --git a/packages/synapse-core/test/select-providers.test.ts b/packages/synapse-core/test/select-providers.test.ts index 15a9dfe8..7f9cb78d 100644 --- a/packages/synapse-core/test/select-providers.test.ts +++ b/packages/synapse-core/test/select-providers.test.ts @@ -50,7 +50,7 @@ describe('selectProviders', () => { it('returns empty when no providers available', () => { const result = selectProviders({ providers: [], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], }) assert.equal(result.length, 0) @@ -59,9 +59,9 @@ describe('selectProviders', () => { it('returns empty when all providers are excluded', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], - excludeProviderIds: new Set([1n, 2n]), + excludeProviderIds: [1n, 2n], }) assert.equal(result.length, 0) }) @@ -69,7 +69,7 @@ describe('selectProviders', () => { it('selects provider with new dataset when no existing datasets', () => { const result = selectProviders({ providers: [provider1], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], metadata: { source: 'app' }, }) @@ -83,7 +83,7 @@ describe('selectProviders', () => { it('respects count option', () => { const result = selectProviders({ providers: [provider1, provider2, provider3], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], count: 2, }) @@ -93,7 +93,7 @@ describe('selectProviders', () => { it('returns fewer than count if not enough providers', () => { const result = selectProviders({ providers: [provider1], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], count: 3, }) @@ -103,7 +103,7 @@ describe('selectProviders', () => { it('selects different providers for each result', () => { const result = selectProviders({ providers: [provider1, provider2, provider3], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], count: 3, }) @@ -116,7 +116,7 @@ describe('selectProviders', () => { it('restricts to endorsed providers when endorsedIds is non-empty', () => { const result = selectProviders({ providers: [provider1, provider2, provider3], - endorsedIds: new Set([1n]), + endorsedIds: [1n], clientDataSets: [], }) assert.equal(result.length, 1) @@ -127,7 +127,7 @@ describe('selectProviders', () => { it('prefers existing dataset on endorsed provider', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set([1n]), + endorsedIds: [1n], clientDataSets: [ makeDataSet({ dataSetId: 10n, @@ -154,7 +154,7 @@ describe('selectProviders', () => { it('creates new dataset when endorsed provider has no matching datasets', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set([1n]), + endorsedIds: [1n], clientDataSets: [ makeDataSet({ dataSetId: 20n, @@ -174,7 +174,7 @@ describe('selectProviders', () => { it('defaults metadata to empty object when not provided', () => { const result = selectProviders({ providers: [provider1], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], }) assert.equal(result.length, 1) @@ -184,7 +184,7 @@ describe('selectProviders', () => { it('ignores non-endorsed providers when endorsedIds is non-empty', () => { const result = selectProviders({ providers: [provider1, provider2, provider3], - endorsedIds: new Set([1n]), + endorsedIds: [1n], clientDataSets: [ makeDataSet({ dataSetId: 20n, @@ -203,7 +203,7 @@ describe('selectProviders', () => { it('uses all providers when endorsedIds is empty', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [ makeDataSet({ dataSetId: 20n, @@ -222,7 +222,7 @@ describe('selectProviders', () => { it('creates new dataset when pool is unrestricted and no matching datasets', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], metadata: { source: 'app' }, }) @@ -236,7 +236,7 @@ describe('selectProviders', () => { it('selects multiple providers from the same pool', () => { const result = selectProviders({ providers: [provider1, provider2, provider3], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], metadata: { source: 'app' }, count: 2, @@ -248,7 +248,7 @@ describe('selectProviders', () => { it('reuses existing datasets across multiple providers', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [ makeDataSet({ dataSetId: 10n, @@ -276,7 +276,7 @@ describe('selectProviders', () => { it('falls through to new dataset when existing datasets are exhausted', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [ makeDataSet({ dataSetId: 10n, @@ -303,7 +303,7 @@ describe('selectProviders', () => { it('prefers dataset with pieces over empty dataset on same provider', () => { const result = selectProviders({ providers: [provider1], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [ makeDataSet({ dataSetId: 5n, @@ -326,7 +326,7 @@ describe('selectProviders', () => { it('prefers older dataset when both have pieces', () => { const result = selectProviders({ providers: [provider1], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [ makeDataSet({ dataSetId: 10n, @@ -351,7 +351,7 @@ describe('selectProviders', () => { it('only considers datasets matching requested metadata', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [ makeDataSet({ dataSetId: 10n, @@ -376,7 +376,7 @@ describe('selectProviders', () => { it('creates new dataset when metadata does not match any existing', () => { const result = selectProviders({ providers: [provider1], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [ makeDataSet({ dataSetId: 10n, @@ -396,9 +396,9 @@ describe('selectProviders', () => { it('excludes specified provider IDs', () => { const result = selectProviders({ providers: [provider1, provider2, provider3], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], - excludeProviderIds: new Set([1n]), + excludeProviderIds: [1n], }) assert.equal(result.length, 1) assert.notEqual(result[0].provider.id, 1n) @@ -407,9 +407,9 @@ describe('selectProviders', () => { it('excludes endorsed provider when specified', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set([1n]), + endorsedIds: [1n], clientDataSets: [], - excludeProviderIds: new Set([1n]), + excludeProviderIds: [1n], }) // Provider 1 excluded, and endorsedIds restricts pool to only endorsed // So no providers are eligible @@ -421,7 +421,7 @@ describe('selectProviders', () => { it('marks endorsed providers correctly', () => { const result = selectProviders({ providers: [provider1, provider2, provider3], - endorsedIds: new Set([2n]), + endorsedIds: [2n], clientDataSets: [], count: 3, }) @@ -434,7 +434,7 @@ describe('selectProviders', () => { it('marks all as non-endorsed when endorsedIds is empty', () => { const result = selectProviders({ providers: [provider1, provider2], - endorsedIds: new Set(), + endorsedIds: [], clientDataSets: [], count: 2, }) From 61a1a4583d1ec9714e282aadb7f8fbaadbf94dec Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 1 Apr 2026 12:42:16 +0100 Subject: [PATCH 2/6] fix: update getApprovedProviderIds and getEndorsedProviderIds with array return type --- packages/synapse-sdk/src/storage/context.ts | 14 +++++++------- packages/synapse-sdk/src/warm-storage/service.ts | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/synapse-sdk/src/storage/context.ts b/packages/synapse-sdk/src/storage/context.ts index 46fb018f..098b6310 100644 --- a/packages/synapse-sdk/src/storage/context.ts +++ b/packages/synapse-sdk/src/storage/context.ts @@ -273,7 +273,7 @@ export class StorageContext { synapse: options.synapse, metadata: options.metadata ?? {}, count, - excludeProviderIds: new Set(options.excludeProviderIds ?? []), + excludeProviderIds: options.excludeProviderIds ?? [], requireEndorsedPrimary: true, }) } @@ -390,7 +390,7 @@ export class StorageContext { synapse, metadata: requestedMetadata, count: 1, - excludeProviderIds: new Set(options.excludeProviderIds ?? []), + excludeProviderIds: options.excludeProviderIds ?? [], requireEndorsedPrimary: false, }) if (results.length === 0) { @@ -563,7 +563,7 @@ export class StorageContext { synapse: Synapse metadata: Record count: number - excludeProviderIds: Set + excludeProviderIds: bigint[] requireEndorsedPrimary: boolean }): Promise { const { synapse, metadata, count, requireEndorsedPrimary } = options @@ -576,7 +576,7 @@ export class StorageContext { // Inline ping-retry loop: select a candidate from core, ping it, // exclude on failure, re-select. One outer iteration per copy needed. const results: ProviderSelectionResult[] = [] - const excludeProviderIds = new Set(options.excludeProviderIds) + const excludeProviderIds = options.excludeProviderIds for (let i = 0; i < count; i++) { const endorsedSlot = requireEndorsedPrimary && i === 0 @@ -588,7 +588,7 @@ export class StorageContext { for (;;) { const candidates = selectProviders({ ...input, - endorsedIds: endorsedSlot ? input.endorsedIds : new Set(), + endorsedIds: endorsedSlot ? input.endorsedIds : [], count: 1, excludeProviderIds, metadata, @@ -600,7 +600,7 @@ export class StorageContext { try { await SP.ping(candidate.provider.pdp.serviceURL) results.push(StorageContext.toProviderSelectionResult(candidate)) - excludeProviderIds.add(candidate.provider.id) + excludeProviderIds.push(candidate.provider.id) found = true break } catch (error) { @@ -608,7 +608,7 @@ export class StorageContext { `Provider ${candidate.provider.serviceProvider} (ID: ${candidate.provider.id}) failed ping:`, error instanceof Error ? error.message : String(error) ) - excludeProviderIds.add(candidate.provider.id) + excludeProviderIds.push(candidate.provider.id) pingFailures++ } } diff --git a/packages/synapse-sdk/src/warm-storage/service.ts b/packages/synapse-sdk/src/warm-storage/service.ts index 885ceb67..e08fb835 100644 --- a/packages/synapse-sdk/src/warm-storage/service.ts +++ b/packages/synapse-sdk/src/warm-storage/service.ts @@ -27,7 +27,7 @@ import { getAllDataSetMetadata, getAllDataSetMetadataCall, getAllPieceMetadata, - getApprovedProviders, + getApprovedProviderIds, getClientDataSets, getDataSet, getServicePrice, @@ -365,7 +365,7 @@ export class WarmStorageService { */ async removeApprovedProvider(options: { providerId: bigint }): Promise { // First, we need to find the index of this provider in the array - const approvedIds = await getApprovedProviders(this._client) + const approvedIds = await getApprovedProviderIds(this._client) const index = approvedIds.indexOf(options.providerId) if (index === -1) { @@ -379,8 +379,8 @@ export class WarmStorageService { * Get list of approved provider IDs * @returns Array of approved provider IDs */ - async getApprovedProviderIds(): Promise { - return getApprovedProviders(this._client) + async getApprovedProviderIds(): Promise { + return getApprovedProviderIds(this._client) } /** From ad0700f525b41585c2bf6096351a30f54ddfc165 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 1 Apr 2026 12:42:30 +0100 Subject: [PATCH 3/6] fix: rename getApprovedProvidersIds to getApprovedProviderIds and update related imports --- .../src/sp-registry/get-pdp-providers.ts | 8 ++-- ...rs-ids.ts => get-approved-provider-ids.ts} | 44 +++++++++---------- .../synapse-core/src/warm-storage/index.ts | 2 +- .../test/get-approved-providers.test.ts | 16 +++---- 4 files changed, 35 insertions(+), 35 deletions(-) rename packages/synapse-core/src/warm-storage/{get-approved-providers-ids.ts => get-approved-provider-ids.ts} (66%) diff --git a/packages/synapse-core/src/sp-registry/get-pdp-providers.ts b/packages/synapse-core/src/sp-registry/get-pdp-providers.ts index 67507602..082cacff 100644 --- a/packages/synapse-core/src/sp-registry/get-pdp-providers.ts +++ b/packages/synapse-core/src/sp-registry/get-pdp-providers.ts @@ -13,7 +13,7 @@ import { multicall, readContract } from 'viem/actions' import type { serviceProviderRegistry as serviceProviderRegistryAbi } from '../abis/index.ts' import { asChain } from '../chains.ts' import type { ActionCallChain } from '../types.ts' -import { getApprovedProvidersIdsCall } from '../warm-storage/get-approved-providers-ids.ts' +import { getApprovedProviderIdsCall } from '../warm-storage/get-approved-provider-ids.ts' import { getPDPProviderCall, parsePDPProvider } from './get-pdp-provider.ts' import type { getProvidersByProductType } from './get-providers-by-product-type.ts' import { type PDPProvider, PRODUCTS, type ProviderWithProduct } from './types.ts' @@ -151,7 +151,7 @@ export namespace getApprovedPDPProviders { export type ErrorType = | asChain.ErrorType | MulticallErrorType - | getApprovedProvidersIdsCall.ErrorType + | getApprovedProviderIdsCall.ErrorType | getPDPProvidersCall.ErrorType } @@ -193,7 +193,7 @@ export async function getApprovedPDPProviders( limit: 100n, contractAddress: options.contractAddress, }), - getApprovedProvidersIdsCall({ + getApprovedProviderIdsCall({ chain: client.chain, }), ], @@ -223,7 +223,7 @@ export namespace getPDPProvidersByIds { export type ErrorType = | asChain.ErrorType | MulticallErrorType - | getApprovedProvidersIdsCall.ErrorType + | getApprovedProviderIdsCall.ErrorType | getPDPProvidersCall.ErrorType } diff --git a/packages/synapse-core/src/warm-storage/get-approved-providers-ids.ts b/packages/synapse-core/src/warm-storage/get-approved-provider-ids.ts similarity index 66% rename from packages/synapse-core/src/warm-storage/get-approved-providers-ids.ts rename to packages/synapse-core/src/warm-storage/get-approved-provider-ids.ts index b4a54dcb..eef22291 100644 --- a/packages/synapse-core/src/warm-storage/get-approved-providers-ids.ts +++ b/packages/synapse-core/src/warm-storage/get-approved-provider-ids.ts @@ -13,7 +13,7 @@ import type { fwssView as storageViewAbi } from '../abis/index.ts' import { asChain } from '../chains.ts' import type { ActionCallChain } from '../types.ts' -export namespace getApprovedProvidersIds { +export namespace getApprovedProviderIds { export type OptionsType = { /** Starting index (0-based). Use 0 to start from beginning. Defaults to 0. */ offset?: bigint @@ -42,13 +42,13 @@ export namespace getApprovedProvidersIds { * returns all remaining providers starting from offset. * * @param client - The client to use to get the approved providers. - * @param options - {@link getApprovedProvidersIds.OptionsType} - * @returns Array of approved provider IDs {@link getApprovedProvidersIds.OutputType} - * @throws Errors {@link getApprovedProvidersIds.ErrorType} + * @param options - {@link getApprovedProviderIds.OptionsType} + * @returns Array of approved provider IDs {@link getApprovedProviderIds.OutputType} + * @throws Errors {@link getApprovedProviderIds.ErrorType} * * @example * ```ts - * import { getApprovedProvidersIds } from '@filoz/synapse-core/warm-storage' + * import { getApprovedProviderIds } from '@filoz/synapse-core/warm-storage' * import { createPublicClient, http } from 'viem' * import { calibration } from '@filoz/synapse-core/chains' * @@ -58,7 +58,7 @@ export namespace getApprovedProvidersIds { * }) * * // Get first 100 providers - * const providerIds = await getApprovedProvidersIds(client, { + * const providerIds = await getApprovedProviderIds(client, { * offset: 0n, * limit: 100n, * }) @@ -66,39 +66,39 @@ export namespace getApprovedProvidersIds { * console.log(providerIds) * ``` */ -export async function getApprovedProvidersIds( +export async function getApprovedProviderIds( client: Client, - options: getApprovedProvidersIds.OptionsType = {} -): Promise { + options: getApprovedProviderIds.OptionsType = {} +): Promise { const data = await readContract( client, - getApprovedProvidersIdsCall({ + getApprovedProviderIdsCall({ chain: client.chain, offset: options.offset, limit: options.limit, contractAddress: options.contractAddress, }) ) - return data as getApprovedProvidersIds.OutputType + return data as getApprovedProviderIds.OutputType } -export namespace getApprovedProvidersIdsCall { - export type OptionsType = Simplify +export namespace getApprovedProviderIdsCall { + export type OptionsType = Simplify export type ErrorType = asChain.ErrorType export type OutputType = ContractFunctionParameters } /** - * Create a call to the {@link getApprovedProvidersIds} function for use with the Viem multicall, readContract, or simulateContract functions. + * Create a call to the {@link getApprovedProviderIds} function for use with the Viem multicall, readContract, or simulateContract functions. * - * @param options - {@link getApprovedProvidersIdsCall.OptionsType} - * @returns Call object {@link getApprovedProvidersIdsCall.OutputType} - * @throws Errors {@link getApprovedProvidersIdsCall.ErrorType} + * @param options - {@link getApprovedProviderIdsCall.OptionsType} + * @returns Call object {@link getApprovedProviderIdsCall.OutputType} + * @throws Errors {@link getApprovedProviderIdsCall.ErrorType} * * @example * ```ts - * import { getApprovedProvidersIdsCall } from '@filoz/synapse-core/warm-storage' + * import { getApprovedProviderIdsCall } from '@filoz/synapse-core/warm-storage' * import { createPublicClient, http } from 'viem' * import { multicall } from 'viem/actions' * import { calibration } from '@filoz/synapse-core/chains' @@ -111,20 +111,20 @@ export namespace getApprovedProvidersIdsCall { * // Paginate through providers in batches of 50 * const results = await multicall(client, { * contracts: [ - * getApprovedProvidersIdsCall({ chain: calibration, offset: 0n, limit: 50n }), - * getApprovedProvidersIdsCall({ chain: calibration, offset: 50n, limit: 50n }), + * getApprovedProviderIdsCall({ chain: calibration, offset: 0n, limit: 50n }), + * getApprovedProviderIdsCall({ chain: calibration, offset: 50n, limit: 50n }), * ], * }) * * console.log(results) * ``` */ -export function getApprovedProvidersIdsCall(options: getApprovedProvidersIdsCall.OptionsType) { +export function getApprovedProviderIdsCall(options: getApprovedProviderIdsCall.OptionsType) { const chain = asChain(options.chain) return { abi: chain.contracts.fwssView.abi, address: options.contractAddress ?? chain.contracts.fwssView.address, functionName: 'getApprovedProviders', args: [options.offset ?? 0n, options.limit ?? 0n], - } satisfies getApprovedProvidersIdsCall.OutputType + } satisfies getApprovedProviderIdsCall.OutputType } diff --git a/packages/synapse-core/src/warm-storage/index.ts b/packages/synapse-core/src/warm-storage/index.ts index beb42c6b..2b137834 100644 --- a/packages/synapse-core/src/warm-storage/index.ts +++ b/packages/synapse-core/src/warm-storage/index.ts @@ -18,7 +18,7 @@ export * from './find-matching-data-sets.ts' export * from './get-account-total-storage-size.ts' export * from './get-all-data-set-metadata.ts' export * from './get-all-piece-metadata.ts' -export * from './get-approved-providers-ids.ts' +export * from './get-approved-provider-ids.ts' export * from './get-client-data-set-ids.ts' export * from './get-client-data-sets.ts' export * from './get-client-data-sets-length.ts' diff --git a/packages/synapse-core/test/get-approved-providers.test.ts b/packages/synapse-core/test/get-approved-providers.test.ts index 610d8818..05e84d6c 100644 --- a/packages/synapse-core/test/get-approved-providers.test.ts +++ b/packages/synapse-core/test/get-approved-providers.test.ts @@ -3,7 +3,7 @@ import { setup } from 'iso-web/msw' import { createPublicClient, http } from 'viem' import { calibration, mainnet } from '../src/chains.ts' import { JSONRPC, presets } from '../src/mocks/jsonrpc/index.ts' -import { getApprovedProvidersIds, getApprovedProvidersIdsCall } from '../src/warm-storage/get-approved-providers-ids.ts' +import { getApprovedProviderIds, getApprovedProviderIdsCall } from '../src/warm-storage/get-approved-provider-ids.ts' describe('getApprovedProviders', () => { const server = setup() @@ -22,7 +22,7 @@ describe('getApprovedProviders', () => { describe('getApprovedProvidersCall', () => { it('should create call with calibration chain defaults', () => { - const call = getApprovedProvidersIdsCall({ + const call = getApprovedProviderIdsCall({ chain: calibration, }) @@ -33,7 +33,7 @@ describe('getApprovedProviders', () => { }) it('should create call with mainnet chain defaults', () => { - const call = getApprovedProvidersIdsCall({ + const call = getApprovedProviderIdsCall({ chain: mainnet, }) @@ -44,7 +44,7 @@ describe('getApprovedProviders', () => { }) it('should use custom offset and limit', () => { - const call = getApprovedProvidersIdsCall({ + const call = getApprovedProviderIdsCall({ chain: calibration, offset: 10n, limit: 50n, @@ -55,7 +55,7 @@ describe('getApprovedProviders', () => { it('should use custom address when provided', () => { const customAddress = '0x1234567890123456789012345678901234567890' - const call = getApprovedProvidersIdsCall({ + const call = getApprovedProviderIdsCall({ chain: calibration, contractAddress: customAddress, }) @@ -73,7 +73,7 @@ describe('getApprovedProviders', () => { transport: http(), }) - const providerIds = await getApprovedProvidersIds(client) + const providerIds = await getApprovedProviderIds(client) assert.deepEqual(providerIds, [1n, 2n]) }) @@ -99,7 +99,7 @@ describe('getApprovedProviders', () => { transport: http(), }) - const providerIds = await getApprovedProvidersIds(client, { + const providerIds = await getApprovedProviderIds(client, { offset: 5n, limit: 10n, }) @@ -123,7 +123,7 @@ describe('getApprovedProviders', () => { transport: http(), }) - const providerIds = await getApprovedProvidersIds(client) + const providerIds = await getApprovedProviderIds(client) assert.deepEqual(providerIds, []) }) From 8379a2bae0897e49f0f04305faa5486a941e3ad7 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Wed, 1 Apr 2026 12:58:33 +0100 Subject: [PATCH 4/6] docs: update endorsedIds and excludeProviderIds to use arrays for consistency --- .../docs/developer-guides/storage/storage-context.mdx | 6 +++--- docs/src/content/docs/developer-guides/synapse-core.mdx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/content/docs/developer-guides/storage/storage-context.mdx b/docs/src/content/docs/developer-guides/storage/storage-context.mdx index bf971c50..8727cc13 100644 --- a/docs/src/content/docs/developer-guides/storage/storage-context.mdx +++ b/docs/src/content/docs/developer-guides/storage/storage-context.mdx @@ -209,7 +209,7 @@ import { privateKeyToAccount } from "viem/accounts" import type { Hex } from "viem"; const synapse = Synapse.create({ account: privateKeyToAccount("0x..."), source: "my-app" }) const contexts = await synapse.storage.createContexts({ - copies: 2, + copies: 2, metadata: { source: "my-app" }, }) const [primary, secondary] = contexts @@ -496,9 +496,9 @@ const [primary] = selectProviders({ // Secondary: pass empty set to allow any approved provider const [secondary] = selectProviders({ ...input, - endorsedIds: new Set(), + endorsedIds: [], count: 1, - excludeProviderIds: new Set([primary.provider.id]), + excludeProviderIds: [primary.provider.id], metadata: { source: "my-app" }, }) ``` diff --git a/docs/src/content/docs/developer-guides/synapse-core.mdx b/docs/src/content/docs/developer-guides/synapse-core.mdx index 127f1c77..8efcc725 100644 --- a/docs/src/content/docs/developer-guides/synapse-core.mdx +++ b/docs/src/content/docs/developer-guides/synapse-core.mdx @@ -108,7 +108,7 @@ const publicClient = createPublicClient({ chain: calibration, transport: http() import * as warmStorage from "@filoz/synapse-core/warm-storage" // List approved providers -const providers = await warmStorage.getApprovedProviders(publicClient) +const providers = await warmStorage.getApprovedProviderIds(publicClient) console.log(providers) // bigint[] — approved provider IDs ``` From 6470cad78015a890ebe63982bb68def72dfabc8b Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 2 Apr 2026 14:07:02 +0100 Subject: [PATCH 5/6] fix: keep the clone to new provider ids array Co-authored-by: Rod Vagg --- packages/synapse-sdk/src/storage/context.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/synapse-sdk/src/storage/context.ts b/packages/synapse-sdk/src/storage/context.ts index 098b6310..d1084777 100644 --- a/packages/synapse-sdk/src/storage/context.ts +++ b/packages/synapse-sdk/src/storage/context.ts @@ -576,7 +576,7 @@ export class StorageContext { // Inline ping-retry loop: select a candidate from core, ping it, // exclude on failure, re-select. One outer iteration per copy needed. const results: ProviderSelectionResult[] = [] - const excludeProviderIds = options.excludeProviderIds + const excludeProviderIds = [...options.excludeProviderIds] for (let i = 0; i < count; i++) { const endorsedSlot = requireEndorsedPrimary && i === 0 From a94b19cd713f8c0dd80338d209c8787235e480f9 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 2 Apr 2026 14:07:14 +0100 Subject: [PATCH 6/6] chore: update providers ids new names and return type in more places Co-authored-by: Rod Vagg Update packages/synapse-core/test/get-provider-ids.test.ts Co-authored-by: Rod Vagg Update packages/synapse-core/src/endorsements/get-endorsed-provider-ids.ts Co-authored-by: Rod Vagg --- .../synapse-core/src/endorsements/get-endorsed-provider-ids.ts | 2 +- packages/synapse-core/src/warm-storage/location-types.ts | 2 +- packages/synapse-core/test/get-provider-ids.test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/synapse-core/src/endorsements/get-endorsed-provider-ids.ts b/packages/synapse-core/src/endorsements/get-endorsed-provider-ids.ts index 8fd9516f..d02a5c42 100644 --- a/packages/synapse-core/src/endorsements/get-endorsed-provider-ids.ts +++ b/packages/synapse-core/src/endorsements/get-endorsed-provider-ids.ts @@ -84,7 +84,7 @@ export namespace getEndorsedProviderIdsCall { * To get the same output type as the action, use {@link parseGetEndorsedProviderIds} to transform the contract output. * * @param options - {@link getEndorsedProviderIdsCall.OptionsType} - * @returns The call to the getProviderIds function {@link getEndorsedProviderIdsCall.OutputType} + * @returns The call to the getEndorsedProviderIdsCall function {@link getEndorsedProviderIdsCall.OutputType} * @throws Errors {@link getEndorsedProviderIdsCall.ErrorType} * * @example diff --git a/packages/synapse-core/src/warm-storage/location-types.ts b/packages/synapse-core/src/warm-storage/location-types.ts index 60a46594..75a63538 100644 --- a/packages/synapse-core/src/warm-storage/location-types.ts +++ b/packages/synapse-core/src/warm-storage/location-types.ts @@ -41,7 +41,7 @@ export interface SelectionDataSet { export interface ProviderSelectionInput { /** Available PDP providers (typically from getApprovedPDPProviders) */ providers: PDPProvider[] - /** Set of endorsed provider IDs (from endorsements.getProviderIds). + /** Array of endorsed provider IDs (from endorsements.getProviderIds). * Non-empty = restrict to endorsed only. Empty = use all providers. */ endorsedIds: bigint[] /** Client's existing datasets with metadata and piece counts */ diff --git a/packages/synapse-core/test/get-provider-ids.test.ts b/packages/synapse-core/test/get-provider-ids.test.ts index 71a99d19..9be66bb9 100644 --- a/packages/synapse-core/test/get-provider-ids.test.ts +++ b/packages/synapse-core/test/get-provider-ids.test.ts @@ -94,7 +94,7 @@ describe('getEndorsedProviderIds', () => { assert.deepEqual(providerIds, [1n, 2n, 3n]) }) - it('should return empty Set when no providers endorsed', async () => { + it('should return empty array when no providers endorsed', async () => { server.use( JSONRPC({ ...presets.basic,