-
Notifications
You must be signed in to change notification settings - Fork 6
/
useCreateContracts.tsx
83 lines (75 loc) · 1.86 KB
/
useCreateContracts.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { ConfigProps } from "data/types"
import { useWalletClient, usePublicClient } from "wagmi"
import { getContract } from "viem"
export const useCreateContracts = (config: ConfigProps) => {
const { data: walletClient } = useWalletClient()
const publicClient = usePublicClient()
const chain = config.chain.id
const stakerSigner = (() => {
if (!config.staker || !publicClient) return
return getContract({
address: config.staker.address as `0x${string}`,
abi: config.staker.abi,
client: {
wallet: walletClient,
public: publicClient
}
}
)
})()
const cellarSigner = (() => {
if (!publicClient) return
return getContract( {
address: config.cellar.address as `0x${string}`,
abi: config.cellar.abi,
client: {
wallet: walletClient,
public: publicClient
}
}
)
})()
const stakerContract = (() => {
if (!config.staker || !publicClient) return
return getContract( {
address: config.staker.address as `0x${string}`,
abi: config.staker.abi,
client: {
public: publicClient
}
}
)
})()
const cellarContract = (() => {
if (!publicClient) return
return getContract( {
address: config.cellar.address as `0x${string}`,
abi: config.cellar.abi,
client: {
public: publicClient
}
}
)
})()
const cellarRouterSigner = (() => {
if (!publicClient) return
return getContract( {
address: config.cellarRouter.address as `0x${string}`,
abi: config.cellarRouter.abi,
client: {
public: publicClient,
wallet: walletClient
}
}
)
})()
const contracts = {
stakerSigner,
cellarSigner,
stakerContract,
cellarContract,
cellarRouterSigner,
chain,
}
return contracts
}