-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add staked pools gauges request
- Loading branch information
1 parent
3eedf99
commit 918b47a
Showing
6 changed files
with
201 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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,95 @@ | ||
import { useQuery, UseQueryOptions } from '@tanstack/vue-query'; | ||
|
||
import QUERY_KEYS from '@/constants/queryKeys'; | ||
import { subgraphRequest } from '@/lib/utils/subgraph'; | ||
import { configService } from '@/services/config/config.service'; | ||
|
||
/** | ||
* TYPES | ||
*/ | ||
export type PoolsGauges = { | ||
__name: 'PoolGauges'; | ||
pools: { | ||
preferentialGauge: { | ||
id: string | null; | ||
}; | ||
gauges: { | ||
id: string; | ||
relativeWeightCap: string; | ||
}[]; | ||
address: string; | ||
}[]; | ||
}; | ||
|
||
type QueryOptions = UseQueryOptions<PoolsGauges>; | ||
|
||
/** | ||
* Fetches all gauges for a given pool and specifies which gauge is the | ||
* preferential gauge. | ||
*/ | ||
export default function usePoolsGaugesQuery( | ||
poolAddresses: Ref<string[] | undefined>, | ||
options: UseQueryOptions<PoolsGauges> = {} | ||
) { | ||
/** | ||
* QUERY KEY | ||
*/ | ||
const queryKey = reactive(QUERY_KEYS.Pools.Gauges(poolAddresses)); | ||
|
||
/** | ||
* COMPUTED | ||
*/ | ||
const enabled = computed((): boolean => !!poolAddresses?.value?.length); | ||
|
||
const subgraphQuery = computed(() => ({ | ||
__name: 'PoolGauges', | ||
pools: { | ||
__args: { | ||
where: { | ||
address_in: poolAddresses.value?.map(address => | ||
address.toLowerCase() | ||
), | ||
}, | ||
}, | ||
preferentialGauge: { | ||
id: true, | ||
}, | ||
gauges: { | ||
id: true, | ||
relativeWeightCap: true, | ||
}, | ||
address: true, | ||
}, | ||
})); | ||
|
||
/** | ||
* QUERY FUNCTION | ||
*/ | ||
const queryFn = async () => { | ||
try { | ||
return await subgraphRequest<PoolsGauges[]>({ | ||
url: configService.network.subgraphs.gauge, | ||
query: subgraphQuery.value, | ||
}); | ||
} catch (error) { | ||
console.error( | ||
`Failed to fetch pool gauge for pools: ${poolAddresses.value}`, | ||
{ | ||
cause: error, | ||
} | ||
); | ||
throw error; | ||
} | ||
}; | ||
|
||
/** | ||
* QUERY OPTIONS | ||
*/ | ||
const queryOptions = reactive({ | ||
enabled, | ||
refetchOnWindowFocus: false, | ||
...options, | ||
}); | ||
|
||
return useQuery<PoolsGauges>(queryKey, queryFn, queryOptions as QueryOptions); | ||
} |
This file contains 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 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 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