Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions packages/synapse-core/src/abis/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,19 @@ export const filecoinWarmStorageServiceStateViewAbi = [
],
stateMutability: 'nonpayable',
},
{
type: 'function',
inputs: [
{ name: 'payer', internalType: 'address', type: 'address' },
{ name: 'offset', internalType: 'uint256', type: 'uint256' },
{ name: 'limit', internalType: 'uint256', type: 'uint256' },
],
name: 'clientDataSets',
outputs: [
{ name: 'dataSetIds', internalType: 'uint256[]', type: 'uint256[]' },
],
stateMutability: 'view',
},
{
type: 'function',
inputs: [{ name: 'payer', internalType: 'address', type: 'address' }],
Expand Down Expand Up @@ -3307,6 +3320,36 @@ export const filecoinWarmStorageServiceStateViewAbi = [
outputs: [{ name: 'count', internalType: 'uint256', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
inputs: [
{ name: 'client', internalType: 'address', type: 'address' },
{ name: 'offset', internalType: 'uint256', type: 'uint256' },
{ name: 'limit', internalType: 'uint256', type: 'uint256' },
],
name: 'getClientDataSets',
outputs: [
{
name: 'infos',
internalType: 'struct FilecoinWarmStorageService.DataSetInfoView[]',
type: 'tuple[]',
components: [
{ name: 'pdpRailId', internalType: 'uint256', type: 'uint256' },
{ name: 'cacheMissRailId', internalType: 'uint256', type: 'uint256' },
{ name: 'cdnRailId', internalType: 'uint256', type: 'uint256' },
{ name: 'payer', internalType: 'address', type: 'address' },
{ name: 'payee', internalType: 'address', type: 'address' },
{ name: 'serviceProvider', internalType: 'address', type: 'address' },
{ name: 'commissionBps', internalType: 'uint256', type: 'uint256' },
{ name: 'clientDataSetId', internalType: 'uint256', type: 'uint256' },
{ name: 'pdpEndEpoch', internalType: 'uint256', type: 'uint256' },
{ name: 'providerId', internalType: 'uint256', type: 'uint256' },
{ name: 'dataSetId', internalType: 'uint256', type: 'uint256' },
],
},
],
stateMutability: 'view',
},
{
type: 'function',
inputs: [{ name: 'client', internalType: 'address', type: 'address' }],
Expand All @@ -3333,6 +3376,13 @@ export const filecoinWarmStorageServiceStateViewAbi = [
],
stateMutability: 'view',
},
{
type: 'function',
inputs: [{ name: 'payer', internalType: 'address', type: 'address' }],
name: 'getClientDataSetsLength',
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
inputs: [],
Expand Down Expand Up @@ -3562,6 +3612,13 @@ export const pdpVerifierAbi = [
],
stateMutability: 'nonpayable',
},
{
type: 'function',
inputs: [],
name: 'FIL_SYBIL_FEE',
outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }],
stateMutability: 'pure',
},
{
type: 'function',
inputs: [],
Expand Down Expand Up @@ -3748,6 +3805,25 @@ export const pdpVerifierAbi = [
],
stateMutability: 'view',
},
{
type: 'function',
inputs: [
{ name: 'setId', internalType: 'uint256', type: 'uint256' },
{
name: 'pieceCid',
internalType: 'struct Cids.Cid',
type: 'tuple',
components: [{ name: 'data', internalType: 'bytes', type: 'bytes' }],
},
{ name: 'startPieceId', internalType: 'uint256', type: 'uint256' },
{ name: 'limit', internalType: 'uint256', type: 'uint256' },
],
name: 'findPieceIdsByCid',
outputs: [
{ name: 'pieceIds', internalType: 'uint256[]', type: 'uint256[]' },
],
stateMutability: 'view',
},
{
type: 'function',
inputs: [{ name: 'setId', internalType: 'uint256', type: 'uint256' }],
Expand Down
3 changes: 3 additions & 0 deletions packages/synapse-core/src/mocks/jsonrpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ export const presets = {
getPDPConfig: () => {
return [BigInt(2880), BigInt(60), BigInt(1), BigInt(0)]
},
getClientDataSetsLength: () => {
return [1n]
},
},
pdpVerifier: {
dataSetLive: () => [true],
Expand Down
13 changes: 13 additions & 0 deletions packages/synapse-core/src/mocks/jsonrpc/warm-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type getAllPieceMetadata = ExtractAbiFunction<typeof Abis.fwssView, 'getA
export type getPieceMetadata = ExtractAbiFunction<typeof Abis.fwssView, 'getPieceMetadata'>
export type clientNonces = ExtractAbiFunction<typeof Abis.fwssView, 'clientNonces'>
export type getPDPConfig = ExtractAbiFunction<typeof Abis.fwssView, 'getPDPConfig'>
export type getClientDataSetsLength = ExtractAbiFunction<typeof Abis.fwssView, 'getClientDataSetsLength'>

export interface WarmStorageViewOptions {
isProviderApproved?: (args: AbiToType<isProviderApproved['inputs']>) => AbiToType<isProviderApproved['outputs']>
Expand All @@ -36,6 +37,9 @@ export interface WarmStorageViewOptions {
getPieceMetadata?: (args: AbiToType<getPieceMetadata['inputs']>) => AbiToType<getPieceMetadata['outputs']>
clientNonces?: (args: AbiToType<clientNonces['inputs']>) => AbiToType<clientNonces['outputs']>
getPDPConfig?: (args: AbiToType<getPDPConfig['inputs']>) => AbiToType<getPDPConfig['outputs']>
getClientDataSetsLength?: (
args: AbiToType<getClientDataSetsLength['inputs']>
) => AbiToType<getClientDataSetsLength['outputs']>
}

/**
Expand Down Expand Up @@ -346,6 +350,15 @@ export function warmStorageViewCallHandler(data: Hex, options: JSONRPCOptions):
options.warmStorageView.getPDPConfig(args)
)
}
case 'getClientDataSetsLength': {
if (!options.warmStorageView?.getClientDataSetsLength) {
throw new Error('Warm Storage View: getClientDataSetsLength is not defined')
}
return encodeAbiParameters(
Abis.fwssView.find((abi) => abi.type === 'function' && abi.name === 'getClientDataSetsLength')!.outputs,
options.warmStorageView.getClientDataSetsLength(args)
)
}

default: {
throw new Error(`Warm Storage View: unknown function: ${functionName} with args: ${args}`)
Expand Down
139 changes: 139 additions & 0 deletions packages/synapse-core/src/warm-storage/get-client-data-set-ids.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import type { Simplify } from 'type-fest'
import type {
Address,
Chain,
Client,
ContractFunctionParameters,
ContractFunctionReturnType,
ReadContractErrorType,
Transport,
} from 'viem'
import { readContract } from 'viem/actions'
import type { fwssView as storageViewAbi } from '../abis/index.ts'
import { asChain } from '../chains.ts'
import type { ActionCallChain } from '../types.ts'

export namespace getClientDataSetIds {
export type OptionsType = {
/** Client address to fetch data set IDs for. */
address: Address
/** Starting index (0-based). Use 0 to start from beginning. Defaults to 0. */
offset?: bigint
/** Maximum number of dataset IDs to return. Use 0 to get all remaining IDs. Defaults to 0. */
limit?: bigint
/** Warm storage contract address. If not provided, the default is the storage view contract address for the chain. */
contractAddress?: Address
}

export type ContractOutputType = ContractFunctionReturnType<
typeof storageViewAbi,
'pure' | 'view',
'clientDataSets',
[Address, bigint, bigint]
>

/** Array of client data set IDs */
export type OutputType = bigint[]

export type ErrorType = asChain.ErrorType | ReadContractErrorType
}

/**
* Get client data set IDs with optional pagination
*
* For large lists, use pagination to avoid gas limit issues. If limit=0,
* returns all remaining IDs starting from offset.
*
* @param client - The client to use to get data set IDs.
* @param options - {@link getClientDataSetIds.OptionsType}
* @returns Array of data set IDs {@link getClientDataSetIds.OutputType}
* @throws Errors {@link getClientDataSetIds.ErrorType}
*
* @example
* ```ts
* import { getClientDataSetIds } from '@filoz/synapse-core/warm-storage'
* import { createPublicClient, http } from 'viem'
* import { calibration } from '@filoz/synapse-core/chains'
*
* const client = createPublicClient({
* chain: calibration,
* transport: http(),
* })
*
* // Get first 100 dataset IDs
* const ids = await getClientDataSetIds(client, {
* address: '0x0000000000000000000000000000000000000000',
* offset: 0n,
* limit: 100n,
* })
*
* console.log(ids)
* ```
*/
export async function getClientDataSetIds(
client: Client<Transport, Chain>,
options: getClientDataSetIds.OptionsType
): Promise<getClientDataSetIds.OutputType> {
const data = await readContract(
client,
getClientDataSetIdsCall({
chain: client.chain,
address: options.address,
offset: options.offset,
limit: options.limit,
contractAddress: options.contractAddress,
})
)
return data as getClientDataSetIds.OutputType
}

export namespace getClientDataSetIdsCall {
export type OptionsType = Simplify<getClientDataSetIds.OptionsType & ActionCallChain>
export type ErrorType = asChain.ErrorType
export type OutputType = ContractFunctionParameters<
typeof storageViewAbi,
'pure' | 'view',
'clientDataSets',
[Address, bigint, bigint]
>
}

/**
* Create a call to the {@link getClientDataSetIds} function for use with the Viem multicall, readContract, or simulateContract functions.
*
* @param options - {@link getClientDataSetIdsCall.OptionsType}
* @returns The call to the clientDataSets function {@link getClientDataSetIdsCall.OutputType}
* @throws Errors {@link getClientDataSetIdsCall.ErrorType}
*
* @example
* ```ts
* import { getClientDataSetIdsCall } from '@filoz/synapse-core/warm-storage'
* import { createPublicClient, http } from 'viem'
* import { multicall } from 'viem/actions'
* import { calibration } from '@filoz/synapse-core/chains'
*
* const client = createPublicClient({
* chain: calibration,
* transport: http(),
* })
*
* // Paginate through IDs in batches of 50
* const results = await multicall(client, {
* contracts: [
* getClientDataSetIdsCall({ chain: calibration, address: '0x...', offset: 0n, limit: 50n }),
* getClientDataSetIdsCall({ chain: calibration, address: '0x...', offset: 50n, limit: 50n }),
* ],
* })
*
* console.log(results)
* ```
*/
export function getClientDataSetIdsCall(options: getClientDataSetIdsCall.OptionsType) {
const chain = asChain(options.chain)
return {
abi: chain.contracts.fwssView.abi,
address: options.contractAddress ?? chain.contracts.fwssView.address,
functionName: 'clientDataSets',
args: [options.address, options.offset ?? 0n, options.limit ?? 0n],
} satisfies getClientDataSetIdsCall.OutputType
}
Loading