@whisk/steakhouse 0.0.4 → 0.0.5

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 (63) hide show
  1. package/dist/client.d.ts +1 -12
  2. package/dist/client.js +1 -10
  3. package/dist/client.js.map +1 -1
  4. package/dist/index.d.ts +6 -5
  5. package/dist/index.js +1 -4
  6. package/dist/index.js.map +1 -1
  7. package/dist/metadata/types.d.ts +3 -1
  8. package/dist/metadata/vaults.js +17 -15
  9. package/dist/metadata/vaults.js.map +1 -1
  10. package/dist/queries/fragments/vaultDetail.d.ts +265 -0
  11. package/dist/queries/fragments/vaultDetail.js +148 -0
  12. package/dist/queries/fragments/vaultDetail.js.map +1 -0
  13. package/dist/queries/getDetailedVault.d.ts +591 -0
  14. package/dist/queries/getDetailedVault.js +92 -0
  15. package/dist/queries/getDetailedVault.js.map +1 -0
  16. package/dist/queries/getVaults.d.ts +274 -13
  17. package/dist/queries/getVaults.js +36 -10
  18. package/dist/queries/getVaults.js.map +1 -1
  19. package/dist/queries/index.d.ts +6 -5
  20. package/dist/queries/index.js +6 -8
  21. package/dist/queries/index.js.map +1 -1
  22. package/dist/queries/steakhouseMetadata.d.ts +13 -0
  23. package/dist/queries/steakhouseMetadata.js +12 -0
  24. package/dist/queries/steakhouseMetadata.js.map +1 -0
  25. package/dist/queries/types.d.ts +2 -4
  26. package/dist/react/hooks/index.d.ts +8 -5
  27. package/dist/react/hooks/index.js +2 -0
  28. package/dist/react/hooks/index.js.map +1 -1
  29. package/dist/react/hooks/useDetailedVault.d.ts +12 -0
  30. package/dist/react/hooks/useDetailedVault.js +16 -0
  31. package/dist/react/hooks/useDetailedVault.js.map +1 -0
  32. package/dist/react/hooks/useSteakhouseQuery.d.ts +2 -4
  33. package/dist/react/hooks/useSteakhouseQuery.js +1 -1
  34. package/dist/react/hooks/useSteakhouseQuery.js.map +1 -1
  35. package/dist/react/hooks/useVaults.d.ts +7 -14
  36. package/dist/react/hooks/useVaults.js +3 -1
  37. package/dist/react/hooks/useVaults.js.map +1 -1
  38. package/dist/react/index.d.ts +8 -5
  39. package/dist/react/index.js +1 -8
  40. package/dist/react/index.js.map +1 -1
  41. package/dist/react/provider.d.ts +3 -5
  42. package/package.json +3 -3
  43. package/src/client.ts +3 -19
  44. package/src/index.ts +1 -2
  45. package/src/metadata/types.ts +3 -1
  46. package/src/metadata/vaults.ts +17 -17
  47. package/src/queries/fragments/vaultDetail.ts +151 -0
  48. package/src/queries/getDetailedVault.test.ts +212 -0
  49. package/src/queries/getDetailedVault.ts +132 -0
  50. package/src/queries/getVaults.test.ts +186 -0
  51. package/src/queries/getVaults.ts +62 -13
  52. package/src/queries/index.ts +9 -7
  53. package/src/queries/steakhouseMetadata.ts +19 -0
  54. package/src/react/hooks/index.ts +1 -0
  55. package/src/react/hooks/useDetailedVault.ts +19 -0
  56. package/src/react/hooks/useSteakhouseQuery.ts +3 -3
  57. package/src/react/hooks/useVaults.ts +7 -2
  58. package/src/react/index.ts +1 -6
  59. package/dist/queries/fragments/vault.d.ts +0 -19
  60. package/dist/queries/fragments/vault.js +0 -16
  61. package/dist/queries/fragments/vault.js.map +0 -1
  62. package/src/client.test.ts +0 -27
  63. package/src/queries/fragments/vault.ts +0 -15
@@ -0,0 +1,186 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest"
2
+ import { createMockClient } from "../../test/mocks.js"
3
+ import { getVaults } from "./getVaults.js"
4
+
5
+ // Mock the metadata module
6
+ vi.mock("../metadata/vaults.js", () => ({
7
+ ALL_VAULTS: [
8
+ {
9
+ chainId: 1,
10
+ address: "0x1111111111111111111111111111111111111111",
11
+ protocol: "morpho_v1",
12
+ name: "Steakhouse USDC",
13
+ description: "A USDC vault",
14
+ tag: "featured",
15
+ },
16
+ {
17
+ chainId: 1,
18
+ address: "0x2222222222222222222222222222222222222222",
19
+ protocol: "morpho_v1",
20
+ name: "Steakhouse ETH",
21
+ },
22
+ {
23
+ chainId: 8453,
24
+ address: "0x3333333333333333333333333333333333333333",
25
+ protocol: "morpho_v2",
26
+ },
27
+ {
28
+ chainId: 1,
29
+ address: "0x4444444444444444444444444444444444444444",
30
+ protocol: "morpho_v1",
31
+ isHidden: true, // Should be excluded
32
+ },
33
+ ],
34
+ }))
35
+
36
+ function createMockVaultResponse(vaults: Array<{ vaultAddress: string }>) {
37
+ return {
38
+ erc4626Vaults: {
39
+ items: vaults.map((v) => ({
40
+ chain: { id: 1, name: "Ethereum", icon: "https://chain.icon" },
41
+ vaultAddress: v.vaultAddress,
42
+ name: "API Vault Name",
43
+ symbol: "VAULT",
44
+ decimals: 18,
45
+ asset: {
46
+ address: "0xasset",
47
+ symbol: "USDC",
48
+ name: "USD Coin",
49
+ icon: "https://icon.url",
50
+ priceUsd: 1.0,
51
+ decimals: 6,
52
+ },
53
+ totalAssets: { raw: "1000000000000", formatted: "1000000", usd: 1000000 },
54
+ totalLiquidity: { formatted: "500000", usd: 500000 },
55
+ apy: { base: 0.05, total: 0.08, rewards: [], fee: 0.1 },
56
+ performanceFee: 0.1,
57
+ feeRecipientAddress: "0xfee",
58
+ ownerAddress: "0xowner",
59
+ curatorAddress: "0xcurator",
60
+ guardianAddress: "0xguardian",
61
+ metadata: {
62
+ description: "A vault",
63
+ image: null,
64
+ forumLink: null,
65
+ curator: null,
66
+ curators: [],
67
+ },
68
+ marketAllocations: [],
69
+ riskAssessment: { steakhouse: { score: 0.8, rating: "A" } },
70
+ })),
71
+ },
72
+ }
73
+ }
74
+
75
+ describe("getVaults", () => {
76
+ beforeEach(() => {
77
+ vi.clearAllMocks()
78
+ })
79
+
80
+ it("returns empty array when no vaults in whitelist match filter", async () => {
81
+ const client = createMockClient({ erc4626Vaults: { items: [] } })
82
+
83
+ // Filter for a chain with no vaults
84
+ const result = await getVaults(client, { chainId: 999 })
85
+
86
+ expect(result).toEqual([])
87
+ // Should not call API if no vaults match
88
+ expect(client.query).not.toHaveBeenCalled()
89
+ })
90
+
91
+ it("filters vaults by chainId", async () => {
92
+ const client = createMockClient(
93
+ createMockVaultResponse([
94
+ { vaultAddress: "0x1111111111111111111111111111111111111111" },
95
+ { vaultAddress: "0x2222222222222222222222222222222222222222" },
96
+ ]),
97
+ )
98
+
99
+ const result = await getVaults(client, { chainId: 1 })
100
+
101
+ expect(result).toHaveLength(2)
102
+ expect(client.query).toHaveBeenCalledWith(
103
+ expect.anything(),
104
+ expect.objectContaining({
105
+ where: expect.objectContaining({
106
+ keys: expect.arrayContaining([
107
+ expect.objectContaining({
108
+ chainId: 1,
109
+ vaultAddress: "0x1111111111111111111111111111111111111111",
110
+ protocol: "morpho_v1",
111
+ }),
112
+ expect.objectContaining({
113
+ chainId: 1,
114
+ vaultAddress: "0x2222222222222222222222222222222222222222",
115
+ protocol: "morpho_v1",
116
+ }),
117
+ ]),
118
+ }),
119
+ }),
120
+ )
121
+ })
122
+
123
+ it("excludes hidden vaults from whitelist", async () => {
124
+ const client = createMockClient(
125
+ createMockVaultResponse([
126
+ { vaultAddress: "0x1111111111111111111111111111111111111111" },
127
+ { vaultAddress: "0x2222222222222222222222222222222222222222" },
128
+ ]),
129
+ )
130
+
131
+ await getVaults(client, { chainId: 1 })
132
+
133
+ // Should not include the hidden vault (0x4444...)
134
+ const call = vi.mocked(client.query).mock.calls[0]
135
+ const keys = call[1].where.keys as Array<{ vaultAddress: string }>
136
+ expect(keys.map((k) => k.vaultAddress)).not.toContain(
137
+ "0x4444444444444444444444444444444444444444",
138
+ )
139
+ })
140
+
141
+ it("augments results with steakhouse metadata", async () => {
142
+ const client = createMockClient(
143
+ createMockVaultResponse([{ vaultAddress: "0x1111111111111111111111111111111111111111" }]),
144
+ )
145
+
146
+ const result = await getVaults(client, { chainId: 1 })
147
+
148
+ expect(result[0].steakhouseMetadata).toEqual({
149
+ name: "Steakhouse USDC",
150
+ description: "A USDC vault",
151
+ tag: "featured",
152
+ protocol: "morpho_v1",
153
+ })
154
+ })
155
+
156
+ it("handles vaults without metadata overrides", async () => {
157
+ const client = createMockClient(
158
+ createMockVaultResponse([{ vaultAddress: "0x3333333333333333333333333333333333333333" }]),
159
+ )
160
+
161
+ const result = await getVaults(client, { chainId: 8453 })
162
+
163
+ expect(result[0].steakhouseMetadata).toEqual({
164
+ protocol: "morpho_v2",
165
+ })
166
+ })
167
+
168
+ it("returns all non-hidden vaults when no chainId filter", async () => {
169
+ const client = createMockClient(
170
+ createMockVaultResponse([
171
+ { vaultAddress: "0x1111111111111111111111111111111111111111" },
172
+ { vaultAddress: "0x2222222222222222222222222222222222222222" },
173
+ { vaultAddress: "0x3333333333333333333333333333333333333333" },
174
+ ]),
175
+ )
176
+
177
+ await getVaults(client)
178
+
179
+ expect(client.query).toHaveBeenCalledWith(
180
+ expect.anything(),
181
+ expect.objectContaining({
182
+ limit: 3, // 3 non-hidden vaults
183
+ }),
184
+ )
185
+ })
186
+ })
@@ -1,28 +1,77 @@
1
- import { graphql, type ResultOf } from "@whisk/graphql"
2
- import type { VariablesOf } from "gql.tada"
1
+ import { graphql } from "@whisk/graphql"
3
2
  import type { SteakhouseClient } from "../client.js"
4
- import { vaultFragment } from "./fragments/vault.js"
3
+ import type { Address, VaultConfig } from "../metadata/types.js"
4
+ import { ALL_VAULTS } from "../metadata/vaults.js"
5
+ import { type VaultDetail, vaultDetailFragment } from "./fragments/vaultDetail.js"
6
+ import { buildSteakhouseMetadata, type SteakhouseMetadata } from "./steakhouseMetadata.js"
5
7
 
6
- export const vaultQuery = graphql(
8
+ /** GraphQL query for fetching Steakhouse vaults */
9
+ export const vaultsQuery = graphql(
7
10
  `
8
- query GetVaults($limit: Int!) {
9
- morphoVaults(limit: $limit) {
11
+ query GetVaults($where: Erc4626VaultFilter, $limit: Int) {
12
+ erc4626Vaults(where: $where, limit: $limit) {
10
13
  items {
11
- ...VaultFragment
14
+ ...VaultDetailFragment
12
15
  }
13
16
  }
14
17
  }
15
18
  `,
16
- [vaultFragment],
19
+ [vaultDetailFragment],
17
20
  )
18
21
 
19
- export type GetVaultsVariables = VariablesOf<typeof vaultQuery>
20
- export type GetVaultsResult = ResultOf<typeof vaultQuery>["morphoVaults"]["items"]
22
+ export type GetVaultsVariables = {
23
+ /** Filter by chain ID */
24
+ chainId?: number
25
+ }
26
+
27
+ /** Vault with Steakhouse metadata */
28
+ export type VaultWithMetadata = VaultDetail & {
29
+ steakhouseMetadata?: SteakhouseMetadata
30
+ }
21
31
 
32
+ export type GetVaultsResult = VaultWithMetadata[]
33
+
34
+ /**
35
+ * Get all Steakhouse-curated vaults.
36
+ * Results are filtered to the SDK whitelist and augmented with Steakhouse metadata.
37
+ */
22
38
  export async function getVaults(
23
39
  client: SteakhouseClient,
24
- variables: GetVaultsVariables,
40
+ variables: GetVaultsVariables = {},
25
41
  ): Promise<GetVaultsResult> {
26
- const result = await client.query(vaultQuery, variables)
27
- return result.morphoVaults.items
42
+ const { chainId } = variables
43
+
44
+ const filteredVaults = ALL_VAULTS.filter(
45
+ (v) => !v.isHidden && (!chainId || v.chainId === chainId),
46
+ )
47
+
48
+ if (filteredVaults.length === 0) {
49
+ return []
50
+ }
51
+
52
+ // Build keys array for erc4626Vaults filter
53
+ const keys = filteredVaults.map((v) => ({
54
+ chainId: v.chainId,
55
+ vaultAddress: v.address,
56
+ protocol: v.protocol,
57
+ }))
58
+
59
+ const result = await client.query(vaultsQuery, {
60
+ where: { keys },
61
+ limit: keys.length,
62
+ })
63
+
64
+ const metadataMap = new Map<Address, VaultConfig>(
65
+ filteredVaults.map((v) => [v.address.toLowerCase() as Address, v]),
66
+ )
67
+
68
+ return result.erc4626Vaults.items
69
+ .filter((vault): vault is NonNullable<typeof vault> => vault !== null)
70
+ .map((vault) => {
71
+ const config = metadataMap.get(vault.vaultAddress.toLowerCase() as Address)
72
+ if (config) {
73
+ return { ...vault, steakhouseMetadata: buildSteakhouseMetadata(config) }
74
+ }
75
+ return vault
76
+ })
28
77
  }
@@ -1,8 +1,10 @@
1
- export { type Vault, vaultFragment } from "./fragments/vault.js"
2
- export {
3
- type GetVaultsResult,
4
- type GetVaultsVariables,
5
- getVaults,
6
- vaultQuery,
7
- } from "./getVaults.js"
1
+ // Fragments
2
+ export { type VaultDetail, vaultDetailFragment } from "./fragments/vaultDetail.js"
3
+ // Queries
4
+ export * from "./getDetailedVault.js"
5
+ export * from "./getVaults.js"
6
+ // Shared
7
+ export { buildSteakhouseMetadata, type SteakhouseMetadata } from "./steakhouseMetadata.js"
8
+
9
+ // Types
8
10
  export type { SteakhouseQueryFn } from "./types.js"
@@ -0,0 +1,19 @@
1
+ import type { VaultConfig } from "../metadata/types.js"
2
+
3
+ /** Steakhouse-specific metadata augmented onto vault data */
4
+ export type SteakhouseMetadata = {
5
+ name?: string
6
+ description?: string
7
+ tag?: VaultConfig["tag"]
8
+ protocol: VaultConfig["protocol"]
9
+ }
10
+
11
+ /** Build metadata object from vault config */
12
+ export function buildSteakhouseMetadata(config: VaultConfig): SteakhouseMetadata {
13
+ return {
14
+ protocol: config.protocol,
15
+ ...(config.name !== undefined && { name: config.name }),
16
+ ...(config.description !== undefined && { description: config.description }),
17
+ ...(config.tag !== undefined && { tag: config.tag }),
18
+ }
19
+ }
@@ -1,2 +1,3 @@
1
+ export { useDetailedVault } from "./useDetailedVault.js"
1
2
  export { useSteakhouseQuery } from "./useSteakhouseQuery.js"
2
3
  export { useVaults } from "./useVaults.js"
@@ -0,0 +1,19 @@
1
+ "use client"
2
+
3
+ import type { UseQueryResult } from "@tanstack/react-query"
4
+ import {
5
+ type GetDetailedVaultResult,
6
+ type GetDetailedVaultVariables,
7
+ getDetailedVault,
8
+ } from "../../queries/getDetailedVault.js"
9
+ import { useSteakhouseQuery } from "./useSteakhouseQuery.js"
10
+
11
+ export function useDetailedVault(
12
+ variables: GetDetailedVaultVariables,
13
+ ): UseQueryResult<GetDetailedVaultResult, Error> {
14
+ return useSteakhouseQuery({
15
+ queryName: "detailedVault",
16
+ queryFn: getDetailedVault,
17
+ variables,
18
+ })
19
+ }
@@ -1,6 +1,6 @@
1
1
  "use client"
2
2
 
3
- import { useQuery } from "@tanstack/react-query"
3
+ import { type UseQueryResult, useQuery } from "@tanstack/react-query"
4
4
  import type { SteakhouseQueryFn } from "../../queries/types.js"
5
5
  import { useSteakhouse } from "../provider.js"
6
6
 
@@ -8,10 +8,10 @@ export function useSteakhouseQuery<TData, TVariables>(options: {
8
8
  queryName: string
9
9
  queryFn: SteakhouseQueryFn<TData, TVariables>
10
10
  variables: TVariables
11
- }) {
11
+ }): UseQueryResult<TData, Error> {
12
12
  const { client } = useSteakhouse()
13
13
  return useQuery({
14
- queryKey: [options.queryName, options.variables],
14
+ queryKey: ["steakhouse", options.queryName, options.variables],
15
15
  queryFn: () => options.queryFn(client, options.variables),
16
16
  })
17
17
  }
@@ -1,9 +1,14 @@
1
1
  "use client"
2
2
 
3
- import { type GetVaultsVariables, getVaults } from "../../queries/getVaults.js"
3
+ import type { UseQueryResult } from "@tanstack/react-query"
4
+ import {
5
+ type GetVaultsResult,
6
+ type GetVaultsVariables,
7
+ getVaults,
8
+ } from "../../queries/getVaults.js"
4
9
  import { useSteakhouseQuery } from "./useSteakhouseQuery.js"
5
10
 
6
- export function useVaults(variables: GetVaultsVariables) {
11
+ export function useVaults(variables: GetVaultsVariables): UseQueryResult<GetVaultsResult, Error> {
7
12
  return useSteakhouseQuery({
8
13
  queryName: "vaults",
9
14
  queryFn: getVaults,
@@ -1,7 +1,2 @@
1
1
  export * from "./hooks/index.js"
2
- export {
3
- type SteakhouseContextValue,
4
- SteakhouseProvider,
5
- type SteakhouseProviderProps,
6
- useSteakhouse,
7
- } from "./provider.js"
2
+ export * from "./provider.js"
@@ -1,19 +0,0 @@
1
- import * as gql_tada from 'gql.tada';
2
- import { FragmentOf } from '@whisk/graphql';
3
-
4
- declare const vaultFragment: gql_tada.TadaDocumentNode<{
5
- chain: {
6
- id: number;
7
- };
8
- vaultAddress: `0x${string}`;
9
- totalSupplied: {
10
- raw: bigint;
11
- };
12
- }, {}, {
13
- fragment: "VaultFragment";
14
- on: "MorphoVault";
15
- masked: false;
16
- }>;
17
- type Vault = FragmentOf<typeof vaultFragment>;
18
-
19
- export { type Vault, vaultFragment };
@@ -1,16 +0,0 @@
1
- import { graphql } from "@whisk/graphql";
2
- const vaultFragment = graphql(`
3
- fragment VaultFragment on MorphoVault {
4
- chain {
5
- id
6
- }
7
- vaultAddress
8
- totalSupplied {
9
- raw
10
- }
11
- }
12
- `);
13
- export {
14
- vaultFragment
15
- };
16
- //# sourceMappingURL=vault.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/queries/fragments/vault.ts"],"sourcesContent":["import { type FragmentOf, graphql } from \"@whisk/graphql\"\n\nexport const vaultFragment = graphql(`\n fragment VaultFragment on MorphoVault {\n chain {\n id\n }\n vaultAddress\n totalSupplied {\n raw\n }\n }\n`)\n\nexport type Vault = FragmentOf<typeof vaultFragment>\n"],"mappings":"AAAA,SAA0B,eAAe;AAElC,MAAM,gBAAgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAUpC;","names":[]}
@@ -1,27 +0,0 @@
1
- import { describe, expect, it } from "vitest"
2
- import { SteakhouseClient } from "./client.js"
3
-
4
- describe("SteakhouseClient", () => {
5
- it("creates client with config", () => {
6
- const client = new SteakhouseClient({
7
- apiKey: "test-key",
8
- })
9
- expect(client).toBeDefined()
10
- })
11
-
12
- it("creates client with custom url", () => {
13
- const client = new SteakhouseClient({
14
- apiKey: "test-key",
15
- url: "https://custom.api.example.com/graphql",
16
- })
17
- expect(client).toBeDefined()
18
- })
19
-
20
- it("creates client with debug mode", () => {
21
- const client = new SteakhouseClient({
22
- apiKey: "test-key",
23
- debug: true,
24
- })
25
- expect(client).toBeDefined()
26
- })
27
- })
@@ -1,15 +0,0 @@
1
- import { type FragmentOf, graphql } from "@whisk/graphql"
2
-
3
- export const vaultFragment = graphql(`
4
- fragment VaultFragment on MorphoVault {
5
- chain {
6
- id
7
- }
8
- vaultAddress
9
- totalSupplied {
10
- raw
11
- }
12
- }
13
- `)
14
-
15
- export type Vault = FragmentOf<typeof vaultFragment>