Skip to content
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

feat: lp values #619

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const getPoolFlowData = async (
const poolAsset = poolAssets.find((asset) => asset.denom === flow.denom)
const tokenSymbol = poolAsset?.symbol
const logoURI = poolAsset?.logoURI
const price = prices[tokenSymbol]
const price = prices[tokenSymbol] || prices[poolAsset.denom]
return {
...flow,
tokenSymbol,
Expand Down Expand Up @@ -235,7 +235,7 @@ export const useIncentivePoolInfo = (
}, [tokenList, loading, pools, chainId, tokenList?.tokens, config, prices])

const { data: flowPoolData, isLoading } = useQuery(
['apr', currentEpochData, pools, poolAssets],
['apr', currentChainPrefix],
() => getPoolFlowData(
client,
pools,
Expand All @@ -251,6 +251,8 @@ export const useIncentivePoolInfo = (
Boolean(poolAssets) &&
Boolean(prices) &&
!isConfigLoading,
cacheTime: 1 * 60 * 60 * 1000,
staleTime: 10 * 60 * 1000,
},
)
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const useQueryIncentiveContracts = (cosmWasmClient: CosmWasmClient): Arra
Boolean(config) &&
Boolean(config?.incentive_factory) &&
!isConfigLoading,
cacheTime: 1 * 60* 60 * 1000,
staleTime: 10 * 60 * 1000,
},
)
return data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useCheckIncentiveSnapshots = (cosmWasmClient: CosmWasmClient,
const epochId = currentEpochData?.currentEpoch?.epoch.id
const incentiveAddresses = useQueryIncentiveContracts(cosmWasmClient)
const { data } = useQuery(
['useCheckIncentiveSnapshots', incentiveAddresses, epochId],
['useCheckIncentiveSnapshots', incentiveAddresses],
async () => await fetchCheckIncentiveSnapshots(
cosmWasmClient, epochId, incentiveAddresses,
),
Expand Down
10 changes: 7 additions & 3 deletions components/Pages/Trade/Liquidity/hooks/useRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ const aggregateRewards = (rewards: RewardData[]): RewardInfo[] => {
return {
amount,
dollarValue: 0,
info: isContract
? { token: { contract_addr: id } }
: { native_token: { denom: id } },
info: {
native: null,
...(isContract
? { token: { contract_addr: id } }
: { native_token: { denom: id } }
)
},
}
})
}
Expand Down
1 change: 1 addition & 0 deletions components/Pages/Trade/Pools/hooks/usePoolsListQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type TokenInfo = {
tags: string[]
denom: string
native: boolean
traces?: any[]
}

export type TokenInfoWithReward = TokenInfo & {
Expand Down
40 changes: 39 additions & 1 deletion hooks/usePrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { useRecoilValue } from 'recoil'
import { chainState } from 'state/chainState'
import { convertMicroDenomToDenom } from 'util/conversion/index'

import { getPoolFromAPI } from '../services/useAPI'
import { getPoolFromAPI, getPricesFromPoolsAPIbyDenom } from '../services/useAPI'
import { CHAIN_NAMES } from '../constants'

type Params = {
token: TokenInfo
Expand Down Expand Up @@ -93,6 +94,33 @@ const getPrices = async ({
const prices = {}
const baseTokenPrice = coingeckoPrices[baseToken.id]?.usd

const chainTokenMap = new Map<string, Array<{base_denom: string, denom: string}>>()

for (const token of tokens) {
if (!token?.fromRegistry || !token.traces?.length) {
continue
}

const ibcTrace = token.traces.find(
trace => trace.type === 'ibc' &&
CHAIN_NAMES.includes(trace.counterparty.chain_name)
)

if (!ibcTrace) {
continue
}

const chainName = ibcTrace.counterparty.chain_name
if (!chainTokenMap.has(chainName)) {
chainTokenMap.set(chainName, [])
}

chainTokenMap.get(chainName)?.push({
base_denom: ibcTrace.counterparty.base_denom,
denom: token.denom
})
}

for (const token of tokens) {
if (token?.fromRegistry) {
continue
Expand Down Expand Up @@ -131,6 +159,16 @@ const getPrices = async ({
}
}
}
for (const chainName of chainTokenMap.keys()) {
const tokenPairs = chainTokenMap.get(chainName)
for (const { base_denom, denom } of tokenPairs) {
const apiPrice = await getPricesFromPoolsAPIbyDenom(base_denom, chainName)
if (apiPrice) {
prices[denom] = apiPrice.price
}
}
}
console.log('prices', prices)
return prices
}

Expand Down
7 changes: 5 additions & 2 deletions hooks/useTokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const useTokenList = () => {
continue
}
const denom = native ? asset.base : asset.address || asset.base
const logoURI = asset.logo_URIs?.svg || asset.logo_URIs?.png || asset.images?.[0]?.svg || asset.images?.[0]?.png || ''
const logoURI = asset.logo_URIs?.svg || asset.logo_URIs?.png || asset.images?.[0]?.svg || asset.images?.[0]?.png || asset.name.includes("LP") ? "/logos/whale-placeholder.svg" : ""
const traces = asset.traces || []
const tmpAssetOBJ: any = { denom,
id: asset.coingecko_id || '',
token_address: asset.address || asset.base,
Expand All @@ -57,7 +58,9 @@ export const useTokenList = () => {
logoURI,
tags: native ? ['native'] : [''],
native,
fromRegistry: true }
fromRegistry: true,
traces
}
const res = Array.from(tokenMapBySymbol.values())
if (denom && !res.find((token) => token.denom === denom)) {
tokenMapBySymbol.set(asset.symbol, tmpAssetOBJ)
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
"@cosmjs/encoding": "0.32.2",
"@cosmjs/launchpad": "0.27.1",
"@cosmjs/proto-signing": "0.32.2",
"@cosmos-kit/cosmostation": "^2.14.5",
"@cosmos-kit/galaxy-station": "^2.12.1",
"@cosmos-kit/keplr": "^2.14.6",
"@cosmos-kit/leap": "^2.14.6",
"@cosmos-kit/ninji": "^2.13.6",
"@cosmos-kit/okxwallet": "^2.11.5",
"@cosmos-kit/react-lite": "^2.15.6",
"@cosmos-kit/shell": "^2.13.6",
"@cosmos-kit/station": "^2.12.5",
"@cosmos-kit/cosmostation": "^2.14.6",
"@cosmos-kit/galaxy-station": "^2.13.7",
"@cosmos-kit/keplr": "^2.14.7",
"@cosmos-kit/leap": "^2.14.7",
"@cosmos-kit/ninji": "^2.13.7",
"@cosmos-kit/okxwallet": "^2.11.6",
"@cosmos-kit/react-lite": "^2.15.8",
"@cosmos-kit/shell": "^2.13.7",
"@cosmos-kit/station": "^2.12.6",
"@emotion/react": "^11",
"@emotion/styled": "^11",
"@injectivelabs/sdk-ts": "1.14.13",
Expand All @@ -42,7 +42,7 @@
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"bignumber.js": "^9.1.2",
"chain-registry": "^1.69.103",
"chain-registry": "^1.69.123",
"dayjs": "^1.11.13",
"eslint-plugin-import-helpers": "^1.3.1",
"intercept-stdout": "^0.1.2",
Expand Down
32 changes: 32 additions & 0 deletions public/logos/whale-placeholder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions services/useAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,34 @@ export const getPricesAPI = async (ids: Array<string>) => {
return null
}
}
export const getPricesFromPoolsAPI = async (tokenlist: Array<any>, chainName: string) => {
try {
const response = await fetchWithTimeout(`${await getFastestAPI()}/api/prices/pools/${chainName}`, 20000)
const json = JSON.parse(await response.text())
let out = []
for (const token of tokenlist) {
const poolData = json?.data[token?.name] || json?.data[token?.denom] || json?.data[token?.symbol]
if (poolData) {
out.push(poolData)
}
}
return out
} catch (e) {
console.log('Unable to fetch -', e)
return null
}
}

export const getPricesFromPoolsAPIbyDenom = async (denom: string, chainName: string) => {
try {
const response = await fetchWithTimeout(`${await getFastestAPI()}/api/prices/pools/${chainName}`, 20000)
const json = JSON.parse(await response.text())
return json.data.byToken[denom] || null
} catch (e) {
console.log('Unable to fetch -', e)
return null
}
}

export const createEndpointOptions = async (chains: any) => {
const endpoints: Record<string, any> = {}
Expand Down
Loading