Skip to content

Commit 02bfa01

Browse files
committed
fix: update dependencies and enhance functionality
- Upgraded `@filoz/synapse-sdk` to version `0.33.0` and `@wagmi/core` to version `2.22.1`. - Added new actions for session key management and file uploads, including `getExpiry`, `isExpired`, and `upload`. - Introduced hooks for `filsnap` and `usdfc` to streamline wallet interactions and asset watching. - Refactored existing actions and hooks for improved structure and clarity, including updates to metadata handling and error decoding. - Removed deprecated functions and optimized imports across various modules.
1 parent a6e1a8b commit 02bfa01

30 files changed

+1025
-569
lines changed

packages/iso-filecoin-synapse/package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,33 @@
8181
"wagmi": "2.x"
8282
},
8383
"dependencies": {
84-
"@filoz/synapse-sdk": "^0.25.1",
84+
"@filoz/synapse-sdk": "^0.33.0",
8585
"@tanstack/react-query": "^5.90.2",
86-
"@wagmi/core": "2.21.2",
86+
"@wagmi/core": "2.22.1",
8787
"dnum": "^2.15.0",
8888
"ethers": "^6.15.0",
89+
"filsnap-adapter": "^3.3.7",
8990
"iso-filecoin": "workspace:*",
9091
"iso-web": "^1.4.0",
9192
"multiformats": "^13.4.1",
93+
"ox": "^0.9.10",
9294
"zod": "^3.25.0"
9395
},
9496
"devDependencies": {
9597
"@testing-library/react": "^16.2.0",
9698
"@types/mocha": "^10.0.10",
97-
"@types/node": "^24.6.0",
98-
"@types/react": "^19.1.16",
99-
"@types/react-dom": "^19.1.7",
100-
"@wagmi/cli": "^2.6.0",
99+
"@types/node": "^24.7.1",
100+
"@types/react": "^19.2.2",
101+
"@types/react-dom": "^19.2.1",
102+
"@wagmi/cli": "^2.7.0",
101103
"abitype": "^1.1.1",
102104
"assert": "^2.1.0",
103-
"mocha": "^11.7.1",
105+
"mocha": "^11.7.4",
104106
"playwright-test": "^14.1.12",
105-
"react": "^19.1.1",
106-
"react-dom": "^19.1.1",
107+
"react": "^19.2.0",
108+
"react-dom": "^19.2.0",
107109
"type-fest": "^5.0.1",
108-
"typescript": "5.9.2"
110+
"typescript": "5.9.3"
109111
},
110112
"publishConfig": {
111113
"provenance": false
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { TypedData } from 'ox'
2+
import { keccak256, stringToHex } from 'viem'
3+
4+
// EIP-712 Type definitions
5+
export const EIP712_TYPES = {
6+
MetadataEntry: [
7+
{ name: 'key', type: 'string' },
8+
{ name: 'value', type: 'string' },
9+
],
10+
CreateDataSet: [
11+
{ name: 'clientDataSetId', type: 'uint256' },
12+
{ name: 'payee', type: 'address' },
13+
{ name: 'metadata', type: 'MetadataEntry[]' },
14+
],
15+
Cid: [{ name: 'data', type: 'bytes' }],
16+
PieceMetadata: [
17+
{ name: 'pieceIndex', type: 'uint256' },
18+
{ name: 'metadata', type: 'MetadataEntry[]' },
19+
],
20+
AddPieces: [
21+
{ name: 'clientDataSetId', type: 'uint256' },
22+
{ name: 'firstAdded', type: 'uint256' },
23+
{ name: 'pieceData', type: 'Cid[]' },
24+
{ name: 'pieceMetadata', type: 'PieceMetadata[]' },
25+
],
26+
SchedulePieceRemovals: [
27+
{ name: 'clientDataSetId', type: 'uint256' },
28+
{ name: 'pieceIds', type: 'uint256[]' },
29+
],
30+
DeleteDataSet: [{ name: 'clientDataSetId', type: 'uint256' }],
31+
}
32+
33+
export type SessionKeyPermissions =
34+
| 'CreateDataSet'
35+
| 'AddPieces'
36+
| 'SchedulePieceRemovals'
37+
| 'DeleteDataSet'
38+
39+
function typeHash(type: TypedData.encodeType.Value) {
40+
return keccak256(stringToHex(TypedData.encodeType(type)))
41+
}
42+
export const SESSION_KEY_PERMISSIONS: Record<
43+
SessionKeyPermissions,
44+
`0x${string}`
45+
> = {
46+
CreateDataSet: typeHash({
47+
types: EIP712_TYPES,
48+
primaryType: 'CreateDataSet',
49+
}),
50+
AddPieces: typeHash({
51+
types: EIP712_TYPES,
52+
primaryType: 'AddPieces',
53+
}),
54+
SchedulePieceRemovals: typeHash({
55+
types: EIP712_TYPES,
56+
primaryType: 'SchedulePieceRemovals',
57+
}),
58+
DeleteDataSet: typeHash({
59+
types: EIP712_TYPES,
60+
primaryType: 'DeleteDataSet',
61+
}),
62+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * as erc20 from './erc20.js'
2-
export * as payments from './payments.js'
3-
export * as pdp from './pdp.js'
4-
export * as warmStorage from './warm-storage/index.js'
1+
export * as erc20 from './erc20.ts'
2+
export * as payments from './pay/index.ts'
3+
export * as pdp from './pdp.ts'
4+
export * as warmStorage from './warm-storage/index.ts'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './operators.js'
2+
export * from './payments.js'
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import {
2+
type Account,
3+
type Address,
4+
type Chain,
5+
type Client,
6+
maxUint256,
7+
type Transport,
8+
} from 'viem'
9+
import {
10+
type ReadContractErrorType,
11+
readContract,
12+
type SimulateContractErrorType,
13+
simulateContract,
14+
type WriteContractErrorType,
15+
writeContract,
16+
} from 'viem/actions'
17+
import { getChain } from '../../chains.js'
18+
19+
export type OperatorApprovalsOptions = {
20+
/**
21+
* The address of the ERC20 token to query.
22+
* If not provided, the USDFC token address will be used.
23+
*/
24+
token?: Address
25+
/**
26+
* The address of the account to query.
27+
*/
28+
address: Address
29+
/**
30+
* The address of the operator to query.
31+
* If not provided, the Warm Storage contract address will be used.
32+
*/
33+
operator?: Address
34+
}
35+
36+
export type OperatorApprovalsResult = {
37+
isApproved: boolean
38+
rateAllowance: bigint
39+
lockupAllowance: bigint
40+
rateUsed: bigint
41+
lockupUsed: bigint
42+
maxLockupPeriod: bigint
43+
}
44+
45+
/**
46+
* Get the operator approvals from the payments contract.
47+
*
48+
* @param client - The client to use.
49+
* @param options - The options to use.
50+
* @returns The operator approvals.
51+
* @throws - {@link ReadContractErrorType} if the read contract fails.
52+
*/
53+
export async function operatorApprovals(
54+
client: Client<Transport, Chain>,
55+
options: OperatorApprovalsOptions
56+
): Promise<OperatorApprovalsResult> {
57+
const chain = getChain(client.chain.id)
58+
const token = options.token ?? chain.contracts.usdfc.address
59+
const operator = options.operator ?? chain.contracts.storage.address
60+
61+
const operatorApprovals = await readContract(client, {
62+
address: chain.contracts.payments.address,
63+
abi: chain.contracts.payments.abi,
64+
functionName: 'operatorApprovals',
65+
args: [token, options.address, operator],
66+
})
67+
return {
68+
isApproved: operatorApprovals[0],
69+
rateAllowance: operatorApprovals[1],
70+
lockupAllowance: operatorApprovals[2],
71+
rateUsed: operatorApprovals[3],
72+
lockupUsed: operatorApprovals[4],
73+
maxLockupPeriod: operatorApprovals[5],
74+
}
75+
}
76+
77+
export type SetOperatorApprovalOptions = {
78+
/**
79+
* The address of the ERC20 token to query.
80+
* If not provided, the USDFC token address will be used.
81+
*/
82+
token?: Address
83+
/**
84+
* The address of the operator to query.
85+
* If not provided, the Warm Storage contract address will be used.
86+
*/
87+
operator?: Address
88+
/**
89+
* Whether to approve the operator.
90+
*/
91+
approve: boolean
92+
}
93+
94+
/**
95+
* Set the operator approval for the payments contract.
96+
*
97+
* @param client - The client to use.
98+
* @param options - The options to use.
99+
* @returns The hash of the approve transaction.
100+
* @throws - {@link SimulateContractErrorType} if the simulate contract fails.
101+
* @throws - {@link WriteContractErrorType} if the write contract fails.
102+
*/
103+
export async function setOperatorApproval(
104+
client: Client<Transport, Chain, Account>,
105+
options: SetOperatorApprovalOptions
106+
) {
107+
const chain = getChain(client.chain.id)
108+
const token = options.token ?? chain.contracts.usdfc.address
109+
const operator = options.operator ?? chain.contracts.storage.address
110+
111+
const approvals = await operatorApprovals(client, {
112+
token,
113+
address: client.account.address,
114+
operator,
115+
})
116+
117+
const { request } = await simulateContract(client, {
118+
address: chain.contracts.payments.address,
119+
abi: chain.contracts.payments.abi,
120+
functionName: 'setOperatorApproval',
121+
args: [
122+
token,
123+
operator,
124+
options.approve,
125+
options.approve ? maxUint256 : 0n,
126+
options.approve ? maxUint256 : 0n,
127+
approvals.maxLockupPeriod,
128+
],
129+
})
130+
131+
const approve = await writeContract(client, request)
132+
return approve
133+
}

packages/iso-filecoin-synapse/src/actions/payments.ts renamed to packages/iso-filecoin-synapse/src/actions/pay/payments.ts

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import {
1919
type WriteContractErrorType,
2020
writeContract,
2121
} from 'viem/actions'
22-
import { getChain } from '../chains.js'
22+
import { getChain } from '../../chains.js'
2323
import {
2424
EIP712_TYPES,
2525
ERC20_WITH_PERMIT_ABI,
2626
LOCKUP_PERIOD,
27-
} from '../constants.js'
28-
import { erc20 } from './index.js'
27+
} from '../../constants.js'
28+
import { erc20 } from '../index.js'
2929

3030
export type AccountInfoOptions = {
3131
/**
@@ -224,63 +224,6 @@ export async function withdraw(
224224
return hash
225225
}
226226

227-
export type OperatorApprovalsOptions = {
228-
/**
229-
* The address of the ERC20 token to query.
230-
* If not provided, the USDFC token address will be used.
231-
*/
232-
token?: Address
233-
/**
234-
* The address of the account to query.
235-
*/
236-
address: Address
237-
/**
238-
* The address of the operator to query.
239-
* If not provided, the Warm Storage contract address will be used.
240-
*/
241-
operator?: Address
242-
}
243-
244-
export type OperatorApprovalsResult = {
245-
isApproved: boolean
246-
rateAllowance: bigint
247-
lockupAllowance: bigint
248-
rateUsed: bigint
249-
lockupUsed: bigint
250-
maxLockupPeriod: bigint
251-
}
252-
253-
/**
254-
* Get the operator approvals from the payments contract.
255-
* @param client - The client to use.
256-
* @param options - The options to use.
257-
* @returns The operator approvals.
258-
* @throws - {@link ReadContractErrorType} if the read contract fails.
259-
*/
260-
export async function operatorApprovals(
261-
client: Client<Transport, Chain>,
262-
options: OperatorApprovalsOptions
263-
): Promise<OperatorApprovalsResult> {
264-
const chain = getChain(client.chain.id)
265-
const token = options.token ?? chain.contracts.usdfc.address
266-
const operator = options.operator ?? chain.contracts.storage.address
267-
268-
const operatorApprovals = await readContract(client, {
269-
address: chain.contracts.payments.address,
270-
abi: chain.contracts.payments.abi,
271-
functionName: 'operatorApprovals',
272-
args: [token, options.address, operator],
273-
})
274-
return {
275-
isApproved: operatorApprovals[0],
276-
rateAllowance: operatorApprovals[1],
277-
lockupAllowance: operatorApprovals[2],
278-
rateUsed: operatorApprovals[3],
279-
lockupUsed: operatorApprovals[4],
280-
maxLockupPeriod: operatorApprovals[5],
281-
}
282-
}
283-
284227
export type DepositAndApproveOptions = {
285228
/**
286229
* The amount to deposit.

0 commit comments

Comments
 (0)