Skip to content

Commit

Permalink
chore: dynamic incentives contract (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
nick134-bit authored Jan 30, 2025
1 parent 266b5b6 commit bc1e831
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
35 changes: 30 additions & 5 deletions components/Pages/Trade/Pools/hooks/usePoolsListQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,25 +47,48 @@ export type PoolsListQueryResponse = {
}

export const usePoolsListQuery = (options?: Parameters<typeof useQuery>[1]) => {
const { chainId, network } = useRecoilValue(chainState)

const { chainId, network, walletChainName } = useRecoilValue(chainState)
const { cosmWasmClient } = useClients(walletChainName)
const config = useConfig(NetworkType.mainnet, chainId)
return useQuery<PoolsListQueryResponse>(
['@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 || {}),
},
)
Expand Down
1 change: 0 additions & 1 deletion public/mainnet/osmosis-1/pools_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"pool_assets": [
{
"chain_id": "osmosis-1",
"id": "sail",
"token_address": "factory/osmo1rckme96ptawr4zwexxj5g5gej9s2dmud8r2t9j0k0prn5mch5g4snzzwjv/sail",
"symbol": "SAIL",
"name": "SAIL",
Expand Down

0 comments on commit bc1e831

Please sign in to comment.