-
Notifications
You must be signed in to change notification settings - Fork 3
Remove subgraphs and add autovaults on new networks #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a3311b6
Remove subgraphs and add autovaults on new networks
secretmemelocker f98e12a
chore: change path and add adapter filer
antoncoding 2dda9de
chore: lint
antoncoding bb2d7fc
Add indexing vaults card, other fixes
secretmemelocker 95f3844
Network changes
secretmemelocker 4d4a3d0
Share on-chain adapter check logic
secretmemelocker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| import { Abi } from "viem"; | ||
|
|
||
| export const adapterFactoryAbi = [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"parentVault","type":"address"},{"indexed":true,"internalType":"address","name":"morpho","type":"address"},{"indexed":true,"internalType":"address","name":"morphoMarketV1Adapter","type":"address"}],"name":"CreateMorphoMarketV1Adapter","type":"event"},{"inputs":[{"internalType":"address","name":"parentVault","type":"address"},{"internalType":"address","name":"morpho","type":"address"}],"name":"createMorphoMarketV1Adapter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isMorphoMarketV1Adapter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"parentVault","type":"address"},{"internalType":"address","name":"morpho","type":"address"}],"name":"morphoMarketV1Adapter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}] as const satisfies Abi; | ||
| export const adapterFactoryAbi = [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"parentVault","type":"address"},{"indexed":true,"internalType":"address","name":"morphoMarketV1AdapterV2","type":"address"}],"name":"CreateMorphoMarketV1AdapterV2","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"morpho","type":"address"},{"indexed":true,"internalType":"address","name":"adaptiveCurveIrm","type":"address"}],"name":"CreateMorphoMarketV1AdapterV2Factory","type":"event"},{"inputs":[],"name":"adaptiveCurveIrm","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"parentVault","type":"address"}],"name":"createMorphoMarketV1AdapterV2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isMorphoMarketV1AdapterV2","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"morpho","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"parentVault","type":"address"}],"name":"morphoMarketV1AdapterV2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}] as const satisfies Abi; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| import type { Address } from 'viem'; | ||
| import type { VaultV2Details } from '@/data-sources/morpho-api/v2-vaults'; | ||
| import { vaultV2sOwnerQuery } from '@/graphql/morpho-api-queries'; | ||
| import { type SupportedNetworks, networks, isAgentAvailable } from '@/utils/networks'; | ||
| import { morphoGraphqlFetcher } from '@/data-sources/morpho-api/fetchers'; | ||
| import { getDeployedVaults } from '@/utils/vault-storage'; | ||
|
|
||
| // Vault address with network information | ||
| export type UserVaultV2Address = { | ||
| address: string; | ||
| networkId: SupportedNetworks; | ||
| }; | ||
|
|
||
| // User vault with full details and network info | ||
| // This is used by the autovault page to display user's vaults | ||
| export type UserVaultV2 = VaultV2Details & { | ||
| networkId: SupportedNetworks; | ||
| balance?: bigint; // User's redeemable assets (from previewRedeem) | ||
| adapter?: Address; // MorphoMarketV1Adapter address | ||
| }; | ||
|
|
||
| // Lightweight API response for owner lookup | ||
| type VaultV2OwnerItem = { | ||
| address: string; | ||
| owner: { address: string } | null; | ||
| chain: { id: number }; | ||
| }; | ||
|
|
||
| type VaultV2sOwnerApiResponse = { | ||
| data?: { | ||
| vaultV2s?: { | ||
| items: VaultV2OwnerItem[]; | ||
| pageInfo: { | ||
| countTotal: number; | ||
| }; | ||
| }; | ||
| }; | ||
| errors?: { message: string }[]; | ||
| }; | ||
|
|
||
| /** | ||
| * Fetches V2 vaults for a specific network from the Morpho API and filters by owner. | ||
| * Merges with locally cached vaults for newly deployed vaults not yet indexed. | ||
| */ | ||
| export const fetchUserVaultV2Addresses = async (owner: string, network: SupportedNetworks): Promise<UserVaultV2Address[]> => { | ||
| if (!isAgentAvailable(network)) { | ||
| return []; | ||
| } | ||
|
|
||
| const normalizedOwner = owner.toLowerCase(); | ||
| const PAGE_SIZE = 100; | ||
| const apiVaults: UserVaultV2Address[] = []; | ||
| let skip = 0; | ||
| let hasMore = true; | ||
|
|
||
| // Step 1: Get locally cached vaults for this network | ||
| const localVaults = getDeployedVaults(owner) | ||
| .filter((v) => v.chainId === network) | ||
| .map((v) => ({ | ||
| address: v.address, | ||
| networkId: network, | ||
| })); | ||
|
|
||
| // Step 2: Fetch from Morpho API | ||
| try { | ||
| while (hasMore) { | ||
| const response = await morphoGraphqlFetcher<VaultV2sOwnerApiResponse>(vaultV2sOwnerQuery, { | ||
| first: PAGE_SIZE, | ||
| skip, | ||
| }); | ||
|
|
||
| if (!response?.data?.vaultV2s) { | ||
| break; | ||
| } | ||
|
|
||
| const items = response.data.vaultV2s.items; | ||
|
|
||
| for (const vault of items) { | ||
| if (vault.chain.id === network && vault.owner?.address.toLowerCase() === normalizedOwner) { | ||
| apiVaults.push({ | ||
| address: vault.address, | ||
| networkId: network, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| const totalCount = response.data.vaultV2s.pageInfo.countTotal; | ||
| skip += PAGE_SIZE; | ||
| hasMore = skip < totalCount && items.length === PAGE_SIZE; | ||
| } | ||
| } catch (error) { | ||
| console.error(`Error fetching V2 vault addresses for owner ${owner} on network ${network}:`, error); | ||
| } | ||
|
|
||
| // Step 3: Merge and deduplicate | ||
| const seenAddresses = new Set(apiVaults.map((v) => v.address.toLowerCase())); | ||
| const uniqueLocalVaults = localVaults.filter((v) => !seenAddresses.has(v.address.toLowerCase())); | ||
|
|
||
| return [...uniqueLocalVaults, ...apiVaults]; | ||
| }; | ||
|
|
||
| /** | ||
| * Fetches vault addresses from all networks that support V2 vaults. | ||
| * Merges results from Morpho API with locally cached vaults (for newly deployed vaults | ||
| * that haven't been indexed yet). | ||
| */ | ||
| export const fetchUserVaultV2AddressesAllNetworks = async (owner: string): Promise<UserVaultV2Address[]> => { | ||
| const normalizedOwner = owner.toLowerCase(); | ||
| const PAGE_SIZE = 100; | ||
| const apiVaults: UserVaultV2Address[] = []; | ||
| let skip = 0; | ||
| let hasMore = true; | ||
|
|
||
| const supportedNetworkIds = new Set(networks.filter((network) => isAgentAvailable(network.network)).map((network) => network.network)); | ||
|
|
||
| if (supportedNetworkIds.size === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| // Step 1: Get locally cached vaults (recently deployed, may not be indexed yet) | ||
| const localVaults = getDeployedVaults(owner) | ||
| .filter((v) => supportedNetworkIds.has(v.chainId as SupportedNetworks)) | ||
| .map((v) => ({ | ||
| address: v.address, | ||
| networkId: v.chainId as SupportedNetworks, | ||
| })); | ||
|
|
||
| // Step 2: Fetch from Morpho API | ||
| try { | ||
| while (hasMore) { | ||
| const response = await morphoGraphqlFetcher<VaultV2sOwnerApiResponse>(vaultV2sOwnerQuery, { | ||
| first: PAGE_SIZE, | ||
| skip, | ||
| }); | ||
|
|
||
| if (!response?.data?.vaultV2s) { | ||
| break; | ||
| } | ||
|
|
||
| const items = response.data.vaultV2s.items; | ||
|
|
||
| for (const vault of items) { | ||
| if (supportedNetworkIds.has(vault.chain.id as SupportedNetworks) && vault.owner?.address.toLowerCase() === normalizedOwner) { | ||
| apiVaults.push({ | ||
| address: vault.address, | ||
| networkId: vault.chain.id as SupportedNetworks, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| const totalCount = response.data.vaultV2s.pageInfo.countTotal; | ||
| skip += PAGE_SIZE; | ||
| hasMore = skip < totalCount && items.length === PAGE_SIZE; | ||
| } | ||
| } catch (error) { | ||
| console.error('Error fetching V2 vault addresses across networks:', error); | ||
| // Continue with local vaults even if API fails | ||
| } | ||
|
|
||
| // Step 3: Merge and deduplicate (API results take precedence for ordering) | ||
| const seenAddresses = new Set(apiVaults.map((v) => v.address.toLowerCase())); | ||
| const uniqueLocalVaults = localVaults.filter((v) => !seenAddresses.has(v.address.toLowerCase())); | ||
|
|
||
| // Local vaults first (newest), then API vaults | ||
| return [...uniqueLocalVaults, ...apiVaults]; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deduping by address only can drop vaults on other chains.
Same address can exist on multiple networks; include
networkIdin the dedupe key.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents