@filoz/synapse-react 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/src/calibration.d.ts +1 -2
  2. package/dist/src/calibration.d.ts.map +1 -1
  3. package/dist/src/calibration.js.map +1 -1
  4. package/dist/src/erc20.d.ts +6 -7
  5. package/dist/src/erc20.d.ts.map +1 -1
  6. package/dist/src/erc20.js +1 -1
  7. package/dist/src/erc20.js.map +1 -1
  8. package/dist/src/filsnap.d.ts.map +1 -1
  9. package/dist/src/filsnap.js +3 -0
  10. package/dist/src/filsnap.js.map +1 -1
  11. package/dist/src/index.d.ts +0 -1
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/index.js +0 -1
  14. package/dist/src/index.js.map +1 -1
  15. package/dist/src/payments/index.d.ts +13 -14
  16. package/dist/src/payments/index.d.ts.map +1 -1
  17. package/dist/src/payments/index.js +19 -20
  18. package/dist/src/payments/index.js.map +1 -1
  19. package/dist/src/payments/use-deposit-and-approve.d.ts +4 -5
  20. package/dist/src/payments/use-deposit-and-approve.d.ts.map +1 -1
  21. package/dist/src/payments/use-deposit-and-approve.js +1 -1
  22. package/dist/src/payments/use-deposit-and-approve.js.map +1 -1
  23. package/dist/src/warm-storage/use-create-data-set.d.ts +11 -5
  24. package/dist/src/warm-storage/use-create-data-set.d.ts.map +1 -1
  25. package/dist/src/warm-storage/use-create-data-set.js +3 -4
  26. package/dist/src/warm-storage/use-create-data-set.js.map +1 -1
  27. package/dist/src/warm-storage/use-data-sets.d.ts +11 -21
  28. package/dist/src/warm-storage/use-data-sets.d.ts.map +1 -1
  29. package/dist/src/warm-storage/use-data-sets.js +6 -22
  30. package/dist/src/warm-storage/use-data-sets.js.map +1 -1
  31. package/dist/src/warm-storage/use-delete-piece.d.ts +3 -3
  32. package/dist/src/warm-storage/use-delete-piece.d.ts.map +1 -1
  33. package/dist/src/warm-storage/use-delete-piece.js +6 -5
  34. package/dist/src/warm-storage/use-delete-piece.js.map +1 -1
  35. package/dist/src/warm-storage/use-providers.d.ts +3 -3
  36. package/dist/src/warm-storage/use-providers.d.ts.map +1 -1
  37. package/dist/src/warm-storage/use-providers.js +2 -2
  38. package/dist/src/warm-storage/use-providers.js.map +1 -1
  39. package/dist/src/warm-storage/use-service-price.d.ts +4 -4
  40. package/dist/src/warm-storage/use-service-price.d.ts.map +1 -1
  41. package/dist/src/warm-storage/use-service-price.js +2 -2
  42. package/dist/src/warm-storage/use-service-price.js.map +1 -1
  43. package/dist/src/warm-storage/use-upload.d.ts +10 -2
  44. package/dist/src/warm-storage/use-upload.d.ts.map +1 -1
  45. package/dist/src/warm-storage/use-upload.js +2 -2
  46. package/dist/src/warm-storage/use-upload.js.map +1 -1
  47. package/package.json +23 -9
  48. package/src/calibration.ts +3 -5
  49. package/src/erc20.ts +7 -7
  50. package/src/filsnap.ts +4 -0
  51. package/src/index.ts +0 -1
  52. package/src/payments/index.ts +36 -59
  53. package/src/payments/use-deposit-and-approve.ts +8 -12
  54. package/src/warm-storage/use-create-data-set.ts +6 -7
  55. package/src/warm-storage/use-data-sets.ts +7 -29
  56. package/src/warm-storage/use-delete-piece.ts +8 -6
  57. package/src/warm-storage/use-providers.ts +3 -3
  58. package/src/warm-storage/use-service-price.ts +8 -8
  59. package/src/warm-storage/use-upload.ts +2 -3
@@ -7,12 +7,12 @@ import { waitForTransactionReceipt } from 'viem/actions'
7
7
  import { useAccount, useChainId, useConfig } from 'wagmi'
8
8
  import { getConnectorClient } from 'wagmi/actions'
9
9
 
10
- type UseDepositVariables = Pick<DepositAndApproveOptions, 'amount'>
11
- interface UseDepositAndApproveProps extends Omit<DepositAndApproveOptions, 'amount'> {
10
+ export type UseDepositAndApproveVariables = Pick<DepositAndApproveOptions, 'amount'>
11
+ export interface UseDepositAndApproveProps extends Omit<DepositAndApproveOptions, 'amount'> {
12
12
  /**
13
13
  * The mutation options.
14
14
  */
15
- mutation?: Omit<MutateOptions<TransactionReceipt, Error, UseDepositVariables>, 'mutationFn'>
15
+ mutation?: Omit<MutateOptions<TransactionReceipt, Error, UseDepositAndApproveVariables>, 'mutationFn'>
16
16
  /**
17
17
  * The callback to call when the hash is available.
18
18
  */
@@ -20,14 +20,10 @@ interface UseDepositAndApproveProps extends Omit<DepositAndApproveOptions, 'amou
20
20
  }
21
21
 
22
22
  /**
23
- * Deposit ERC20 tokens into the payments contract.
23
+ * Deposit and approve ERC20 tokens into the payments contract.
24
24
  *
25
- * @param props - The props for the deposit.
26
- * @param props.address - The address of the account to deposit from.
27
- * @param props.token - The address of the ERC20 token to deposit.
28
- * @param props.mutation - The mutation options.
29
- * @param props.onHash - The callback to call when the hash is available.
30
- * @returns The deposit mutation.
25
+ * @param props - The props for the deposit. {@link UseDepositAndApproveProps}
26
+ * @returns The deposit and approve mutation.
31
27
  */
32
28
  export function useDepositAndApprove(props?: UseDepositAndApproveProps) {
33
29
  const config = useConfig()
@@ -39,7 +35,7 @@ export function useDepositAndApprove(props?: UseDepositAndApproveProps) {
39
35
  const from = props?.address ?? account.address
40
36
 
41
37
  return useMutation({
42
- mutationFn: async ({ amount }: UseDepositVariables) => {
38
+ mutationFn: async ({ amount }: UseDepositAndApproveVariables) => {
43
39
  const client = await getConnectorClient(config, {
44
40
  account: account.address,
45
41
  chainId,
@@ -61,7 +57,7 @@ export function useDepositAndApprove(props?: UseDepositAndApproveProps) {
61
57
  queryKey: ['synapse-erc20-balance', from, token],
62
58
  })
63
59
  queryClient.invalidateQueries({
64
- queryKey: ['synapse-payments-operator-approvals', from, token, chain.contracts.storage.address],
60
+ queryKey: ['synapse-payments-operator-approvals', from, token, chain.contracts.fwss.address],
65
61
  })
66
62
 
67
63
  return transactionReceipt
@@ -1,6 +1,5 @@
1
- import type { DataSetCreatedResponse } from '@filoz/synapse-core/sp'
2
1
  import * as SP from '@filoz/synapse-core/sp'
3
- import { createDataSet, type PDPProvider } from '@filoz/synapse-core/warm-storage'
2
+ import type { PDPProvider } from '@filoz/synapse-core/sp-registry'
4
3
  import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
5
4
  import { useAccount, useChainId, useConfig } from 'wagmi'
6
5
  import { getConnectorClient } from 'wagmi/actions'
@@ -10,7 +9,7 @@ export interface UseCreateDataSetProps {
10
9
  * The callback to call when the hash is available.
11
10
  */
12
11
  onHash?: (hash: string) => void
13
- mutation?: Omit<MutateOptions<DataSetCreatedResponse, Error, UseCreateDataSetVariables>, 'mutationFn'>
12
+ mutation?: Omit<MutateOptions<SP.waitForCreateDataSet.ReturnType, Error, UseCreateDataSetVariables>, 'mutationFn'>
14
13
  }
15
14
 
16
15
  export interface UseCreateDataSetVariables {
@@ -21,7 +20,7 @@ export interface UseCreateDataSetVariables {
21
20
  cdn: boolean
22
21
  }
23
22
 
24
- export type UseCreateDataSetResult = DataSetCreatedResponse
23
+ export type UseCreateDataSetResult = SP.waitForCreateDataSet.ReturnType
25
24
 
26
25
  export function useCreateDataSet(props: UseCreateDataSetProps) {
27
26
  const config = useConfig()
@@ -36,10 +35,10 @@ export function useCreateDataSet(props: UseCreateDataSetProps) {
36
35
  chainId,
37
36
  })
38
37
 
39
- const { txHash, statusUrl } = await createDataSet(connectorClient, {
38
+ const { txHash, statusUrl } = await SP.createDataSet(connectorClient, {
40
39
  payee: provider.payee,
41
40
  payer: account.address,
42
- endpoint: provider.pdp.serviceURL,
41
+ serviceURL: provider.pdp.serviceURL,
43
42
  cdn,
44
43
  // metadata: {
45
44
  // title: 'Test Data Set',
@@ -48,7 +47,7 @@ export function useCreateDataSet(props: UseCreateDataSetProps) {
48
47
  })
49
48
  props?.onHash?.(txHash)
50
49
 
51
- const dataSet = await SP.pollForDataSetCreationStatus({ statusUrl })
50
+ const dataSet = await SP.waitForCreateDataSet({ statusUrl })
52
51
 
53
52
  queryClient.invalidateQueries({
54
53
  queryKey: ['synapse-warm-storage-data-sets', account.address],
@@ -1,15 +1,10 @@
1
- import { getChain } from '@filoz/synapse-core/chains'
2
- import { type MetadataObject, metadataArrayToObject } from '@filoz/synapse-core/utils'
3
- import { type DataSet, getDataSets, getPieces, type Piece } from '@filoz/synapse-core/warm-storage'
1
+ import { getPiecesWithMetadata } from '@filoz/synapse-core/pdp-verifier'
2
+ import { getPdpDataSets, type PdpDataSet, type PieceWithMetadata } from '@filoz/synapse-core/warm-storage'
4
3
  import { skipToken, type UseQueryOptions, useQuery } from '@tanstack/react-query'
5
- import type { Simplify } from 'type-fest'
6
4
  import type { Address } from 'viem'
7
- import { readContract } from 'viem/actions'
8
- import { useChainId, useConfig } from 'wagmi'
5
+ import { useConfig } from 'wagmi'
9
6
 
10
- export type PieceWithMetadata = Simplify<Piece & { metadata: MetadataObject }>
11
-
12
- export interface DataSetWithPieces extends DataSet {
7
+ export interface DataSetWithPieces extends PdpDataSet {
13
8
  pieces: PieceWithMetadata[]
14
9
  }
15
10
 
@@ -22,39 +17,22 @@ export interface UseDataSetsProps {
22
17
 
23
18
  export function useDataSets(props: UseDataSetsProps) {
24
19
  const config = useConfig()
25
- const chainId = useChainId()
26
20
  const address = props.address
27
- const chain = getChain(chainId)
28
21
  return useQuery({
29
22
  queryKey: ['synapse-warm-storage-data-sets', address],
30
23
  queryFn: address
31
24
  ? async () => {
32
- const dataSets = await getDataSets(config.getClient(), { address })
25
+ const dataSets = await getPdpDataSets(config.getClient(), { address })
33
26
  const dataSetsWithPieces = await Promise.all(
34
27
  dataSets.map(async (dataSet) => {
35
- const piecesPaginated = await getPieces(config.getClient(), {
28
+ const result = await getPiecesWithMetadata(config.getClient(), {
36
29
  dataSet,
37
30
  address,
38
31
  })
39
32
 
40
- const piecesWithMetadata = await Promise.all(
41
- piecesPaginated.pieces.map(async (piece) => {
42
- const metadata = await readContract(config.getClient(), {
43
- address: chain.contracts.storageView.address,
44
- abi: chain.contracts.storageView.abi,
45
- functionName: 'getAllPieceMetadata',
46
- args: [dataSet.dataSetId, BigInt(piece.id)],
47
- })
48
- return {
49
- ...piece,
50
- metadata: metadataArrayToObject(metadata),
51
- }
52
- })
53
- )
54
-
55
33
  return {
56
34
  ...dataSet,
57
- pieces: piecesWithMetadata,
35
+ pieces: result.pieces,
58
36
  }
59
37
  })
60
38
  )
@@ -1,8 +1,10 @@
1
1
  import { getChain } from '@filoz/synapse-core/chains'
2
2
  import type { SessionKey } from '@filoz/synapse-core/session-key'
3
- import { type DataSet, deletePiece, pollForDeletePieceStatus } from '@filoz/synapse-core/warm-storage'
3
+ import * as SP from '@filoz/synapse-core/sp'
4
+ import type { PdpDataSet } from '@filoz/synapse-core/warm-storage'
4
5
  import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
5
6
  import type { TransactionReceipt } from 'viem'
7
+ import { waitForTransactionReceipt } from 'viem/actions'
6
8
  import { useAccount, useChainId, useConfig } from 'wagmi'
7
9
  import { getConnectorClient } from 'wagmi/actions'
8
10
 
@@ -16,7 +18,7 @@ export interface UseDeletePieceProps {
16
18
  }
17
19
 
18
20
  export interface UseDeletePieceVariables {
19
- dataSet: DataSet
21
+ dataSet: PdpDataSet
20
22
  pieceId: bigint
21
23
  }
22
24
  export function useDeletePiece(props: UseDeletePieceProps) {
@@ -39,15 +41,15 @@ export function useDeletePiece(props: UseDeletePieceProps) {
39
41
  connectorClient = props?.sessionKey.client(chain, client.transport)
40
42
  }
41
43
 
42
- const deletePieceRsp = await deletePiece(connectorClient, {
43
- endpoint: dataSet.pdp.serviceURL,
44
+ const deletePieceRsp = await SP.schedulePieceDeletion(connectorClient, {
45
+ serviceURL: dataSet.provider.pdp.serviceURL,
44
46
  dataSetId: dataSet.dataSetId,
45
47
  clientDataSetId: dataSet.clientDataSetId,
46
48
  pieceId,
47
49
  })
48
50
 
49
- props?.onHash?.(deletePieceRsp.txHash)
50
- const rsp = await pollForDeletePieceStatus(client, deletePieceRsp)
51
+ props?.onHash?.(deletePieceRsp.hash)
52
+ const rsp = await waitForTransactionReceipt(client, deletePieceRsp)
51
53
 
52
54
  queryClient.invalidateQueries({
53
55
  queryKey: ['synapse-warm-storage-data-sets', account.address],
@@ -1,4 +1,4 @@
1
- import { type PDPProvider, readProviders } from '@filoz/synapse-core/warm-storage'
1
+ import { getApprovedPDPProviders } from '@filoz/synapse-core/sp-registry'
2
2
  import { type UseQueryOptions, useQuery } from '@tanstack/react-query'
3
3
  import { useConfig } from 'wagmi'
4
4
 
@@ -6,7 +6,7 @@ export interface UseProvidersProps {
6
6
  query?: Omit<UseQueryOptions<UseProvidersResult>, 'queryKey' | 'queryFn'>
7
7
  }
8
8
 
9
- export type UseProvidersResult = PDPProvider[]
9
+ export type UseProvidersResult = getApprovedPDPProviders.OutputType
10
10
 
11
11
  export function useProviders(props?: UseProvidersProps) {
12
12
  const config = useConfig()
@@ -15,7 +15,7 @@ export function useProviders(props?: UseProvidersProps) {
15
15
  ...props?.query,
16
16
  queryKey: ['synapse-warm-storage-providers'],
17
17
  queryFn: () => {
18
- return readProviders(config.getClient())
18
+ return getApprovedPDPProviders(config.getClient())
19
19
  },
20
20
  })
21
21
  }
@@ -1,18 +1,18 @@
1
- import { type ServicePriceResult, servicePrice } from '@filoz/synapse-core/warm-storage'
1
+ import { getServicePrice } from '@filoz/synapse-core/warm-storage'
2
2
  import { type UseQueryOptions, useQuery } from '@tanstack/react-query'
3
3
  import { useConfig } from 'wagmi'
4
4
 
5
5
  /**
6
- * The props for the useServicePrice hook.
6
+ * The result for the useServicePrice hook.
7
7
  */
8
- export interface UseServicePriceProps {
9
- query?: Omit<UseQueryOptions<ServicePriceResult>, 'queryKey' | 'queryFn'>
10
- }
8
+ export type UseServicePriceResult = getServicePrice.OutputType
11
9
 
12
10
  /**
13
- * The result for the useServicePrice hook.
11
+ * The props for the useServicePrice hook.
14
12
  */
15
- export type UseServicePriceResult = ServicePriceResult
13
+ export interface UseServicePriceProps {
14
+ query?: Omit<UseQueryOptions<UseServicePriceResult>, 'queryKey' | 'queryFn'>
15
+ }
16
16
 
17
17
  /**
18
18
  * Get the service price for the warm storage.
@@ -27,7 +27,7 @@ export function useServicePrice(props?: UseServicePriceProps) {
27
27
  ...props?.query,
28
28
  queryKey: ['synapse-warm-storage-get-service-price'],
29
29
  queryFn: async () => {
30
- const result = await servicePrice(config.getClient())
30
+ const result = await getServicePrice(config.getClient())
31
31
  return result
32
32
  },
33
33
  })
@@ -1,8 +1,7 @@
1
1
  import { getChain } from '@filoz/synapse-core/chains'
2
2
  import type { SessionKey } from '@filoz/synapse-core/session-key'
3
- import type { AddPiecesSuccess } from '@filoz/synapse-core/sp'
4
3
  import * as SP from '@filoz/synapse-core/sp'
5
- import { upload } from '@filoz/synapse-core/warm-storage'
4
+ import { type AddPiecesSuccess, upload } from '@filoz/synapse-core/sp'
6
5
  import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
7
6
  import { useAccount, useChainId, useConfig } from 'wagmi'
8
7
  import { getConnectorClient } from 'wagmi/actions'
@@ -45,7 +44,7 @@ export function useUpload(props: UseUploadProps) {
45
44
  })
46
45
 
47
46
  props?.onHash?.(uploadRsp.txHash)
48
- const rsp = await SP.pollForAddPiecesStatus(uploadRsp)
47
+ const rsp = await SP.waitForAddPieces(uploadRsp)
49
48
 
50
49
  queryClient.invalidateQueries({
51
50
  queryKey: ['synapse-warm-storage-data-sets', account.address],