From bc1e831a760076c3d85897413f71ea6c58947c07 Mon Sep 17 00:00:00 2001 From: nick134 <76399455+nick134-bit@users.noreply.github.com> Date: Thu, 30 Jan 2025 15:58:35 +0100 Subject: [PATCH] chore: dynamic incentives contract (#616) --- .../Trade/Pools/hooks/usePoolsListQuery.ts | 35 ++++++++++++++++--- public/mainnet/osmosis-1/pools_list.json | 1 - 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/components/Pages/Trade/Pools/hooks/usePoolsListQuery.ts b/components/Pages/Trade/Pools/hooks/usePoolsListQuery.ts index a73edb8d..48269baa 100644 --- a/components/Pages/Trade/Pools/hooks/usePoolsListQuery.ts +++ b/components/Pages/Trade/Pools/hooks/usePoolsListQuery.ts @@ -2,7 +2,9 @@ import { useQuery } from 'react-query' import { PoolLiquidityState } from 'components/Pages/Trade/Pools/hooks/useQueryPoolsLiquidity' import { useRecoilValue } from 'recoil' -import { chainState } from 'state/chainState' +import { chainState, NetworkType } from 'state/chainState' +import { useConfig } from '../../../Bonding/hooks/useDashboardData' +import { useClients } from '../../../../../hooks/useClients' export type TokenInfo = { fromRegistry?: boolean @@ -45,25 +47,48 @@ export type PoolsListQueryResponse = { } export const usePoolsListQuery = (options?: Parameters[1]) => { - const { chainId, network } = useRecoilValue(chainState) - + const { chainId, network, walletChainName } = useRecoilValue(chainState) + const { cosmWasmClient } = useClients(walletChainName) + const config = useConfig(NetworkType.mainnet, chainId) return useQuery( ['@pools-list', chainId, network], async () => { const url = `/${network}/${chainId}${process.env.NEXT_PUBLIC_POOLS_LIST_URL}` const response = await fetch(url) const tokenList = await response.json() + const incentivesFactoryAddress = config?.data?.incentive_factory + let incentivesContracts = {} + if (incentivesFactoryAddress) { + const responseIncentives = await cosmWasmClient.queryContractSmart(incentivesFactoryAddress, { + incentives: { + limit: 100 + } + }) + for (const pool of tokenList.pools) { + const poolIncentives = responseIncentives.find(incentive => String.fromCharCode(...incentive.lp_reference).trim() == pool.lp_token.trim()) + if (poolIncentives) { + incentivesContracts[pool.swap_address] = poolIncentives.incentive_address + } + } + } + + const pools = tokenList.pools.map(pool => ({ + ...pool, + staking_address: incentivesContracts[pool.swap_address] || pool.staking_address || "", + })) + tokenList.pools = pools return { ...tokenList, - poolsById: tokenList.pools.reduce((poolsById, pool) => ((poolsById[pool.pool_id] = pool), poolsById), + poolsById: pools.reduce((poolsById, pool) => ((poolsById[pool.pool_id] = pool), poolsById), {}), baseToken: tokenList.base_token, } }, { retry: 5, - enabled: Boolean(chainId), + enabled: Boolean(chainId) && Boolean(cosmWasmClient), refetchOnMount: false, + cacheTime: 4 * 60 * 60 * 1000, ...(options || {}), }, ) diff --git a/public/mainnet/osmosis-1/pools_list.json b/public/mainnet/osmosis-1/pools_list.json index 53ac0137..ae46f4f2 100644 --- a/public/mainnet/osmosis-1/pools_list.json +++ b/public/mainnet/osmosis-1/pools_list.json @@ -92,7 +92,6 @@ "pool_assets": [ { "chain_id": "osmosis-1", - "id": "sail", "token_address": "factory/osmo1rckme96ptawr4zwexxj5g5gej9s2dmud8r2t9j0k0prn5mch5g4snzzwjv/sail", "symbol": "SAIL", "name": "SAIL",