diff --git a/src/components/Modals/HLS/Manage/Deposit.tsx b/src/components/Modals/HLS/Manage/Deposit.tsx index 5c840a21..c41b58af 100644 --- a/src/components/Modals/HLS/Manage/Deposit.tsx +++ b/src/components/Modals/HLS/Manage/Deposit.tsx @@ -9,7 +9,7 @@ import Text from 'components/common/Text' import TokenInputWithSlider from 'components/common/TokenInput/TokenInputWithSlider' import { BN_ZERO } from 'constants/math' import useAllAssets from 'hooks/assets/useAllAssets' -import useDepositActions from 'hooks/HLS/useDepositActions' +import useDepositActions from 'hooks/hls/useDepositActions' import useBorrowAsset from 'hooks/useBorrowAsset' import useCurrentWalletBalance from 'hooks/useCurrentWalletBalance' import useHealthComputer from 'hooks/useHealthComputer' diff --git a/src/components/hls/Staking/Table/Columns/Manage.tsx b/src/components/hls/Staking/Table/Columns/Manage.tsx index dd83a271..616b996e 100644 --- a/src/components/hls/Staking/Table/Columns/Manage.tsx +++ b/src/components/hls/Staking/Table/Columns/Manage.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from 'react' import DropDownButton from 'components/common/Button/DropDownButton' import { ArrowDownLine, Cross, HandCoins, Plus, Scale } from 'components/common/Icons' -import useCloseHlsStakingPosition from 'hooks/HLS/useClosePositionActions' +import useCloseHlsStakingPosition from 'hooks/hls/useClosePositionActions' import useStore from 'store' export const MANAGE_META = { id: 'manage' } diff --git a/src/configs/chains/neutron/pion-1.ts b/src/configs/chains/neutron/pion-1.ts index b17fba0a..8e425b96 100644 --- a/src/configs/chains/neutron/pion-1.ts +++ b/src/configs/chains/neutron/pion-1.ts @@ -32,6 +32,7 @@ const Pion1: ChainConfig = { pyth: 'neutron15ldst8t80982akgr8w8ekcytejzkmfpgdkeq4xgtge48qs7435jqp87u3t', }, endpoints: { + routes: 'https://app.astroport.fi/api/routes', rest: 'https://rest-palvus.pion-1.ntrn.tech/', rpc: 'https://rpc-palvus.pion-1.ntrn.tech/', swap: 'https://testnet-neutron.astroport.fi/swap', diff --git a/src/configs/chains/osmosis/devnet.ts b/src/configs/chains/osmosis/devnet.ts index e1fe7301..540a840e 100644 --- a/src/configs/chains/osmosis/devnet.ts +++ b/src/configs/chains/osmosis/devnet.ts @@ -1,5 +1,5 @@ -import { ChainInfoID } from 'types/enums/wallet' import { NETWORK } from 'types/enums/network' +import { ChainInfoID } from 'types/enums/wallet' import Osmosis1 from './osmosis-1' diff --git a/src/configs/chains/osmosis/osmosis-1.ts b/src/configs/chains/osmosis/osmosis-1.ts index f86cd5d7..ff6600f0 100644 --- a/src/configs/chains/osmosis/osmosis-1.ts +++ b/src/configs/chains/osmosis/osmosis-1.ts @@ -135,6 +135,7 @@ const Osmosis1: ChainConfig = { rest: 'https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/', swap: 'https://app.osmosis.zone', explorer: 'https://www.mintscan.io/osmosis/transactions/', + routes: 'https://sqs.osmosis.zone/router', pools: (process.env.NEXT_PUBLIC_OSMOSIS_REST || 'https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/') + diff --git a/src/hooks/HLS/useClosePositionActions.ts b/src/hooks/hls/useClosePositionActions.ts similarity index 100% rename from src/hooks/HLS/useClosePositionActions.ts rename to src/hooks/hls/useClosePositionActions.ts diff --git a/src/hooks/HLS/useDepositActions.ts b/src/hooks/hls/useDepositActions.ts similarity index 100% rename from src/hooks/HLS/useDepositActions.ts rename to src/hooks/hls/useDepositActions.ts diff --git a/src/hooks/trade/useRoutes.ts b/src/hooks/trade/useRoutes.ts new file mode 100644 index 00000000..c804fd76 --- /dev/null +++ b/src/hooks/trade/useRoutes.ts @@ -0,0 +1,66 @@ +import useSWR from 'swr' + +import useChainConfig from 'hooks/useChainConfig' +import { ChainInfoID } from 'types/enums/wallet' +import { BN } from 'utils/helpers' + +export default function useRoutes(denomIn: string, denomOut: string, amount: BigNumber) { + const chainConfig = useChainConfig() + const isOsmosis = [ChainInfoID.Osmosis1, ChainInfoID.OsmosisDevnet].includes(chainConfig.id) + + const osmosisRoute = useSWR( + isOsmosis && + `${chainConfig.endpoints.routes}/quote?tokenIn=${denomIn}&tokenOutDenom=${denomOut}&amount=${amount}`, + async (url: string) => { + try { + const resp = await fetch(url) + const route = (await resp.json()) as OsmosisRouteResponse + + return { + priceImpact: BN(route.price_impact), + fee: BN(route.effective_fee), + route: { + osmo: { + swaps: route.route[0].pools.map((pool) => ({ + pool_id: pool.id.toString(), + to: pool.token_out_denom, + })), + }, + }, + } + } catch { + return null + } + }, + ) + + const astroportRoute = useSWR( + !isOsmosis && + `${chainConfig.endpoints.routes}?start=${denomIn}&end=${denomOut}&amount=${amount}&chainId=${chainConfig.id}&limit=1`, + async (url: string) => { + try { + const resp = await fetch(url) + const route = (await resp.json())[0] as AstroportRouteResponse + + return { + priceImpact: BN(route.price_impact), + fee: BN(0), // TODO: Fees are not implemented yet on Astroport endpoint + route: { + astro: { + swaps: route.swaps.map((swap) => ({ + from: swap.from, + to: swap.to, + })), + }, + }, + } + } catch (e) { + return null + } + }, + ) + + if (isOsmosis) return osmosisRoute + + return astroportRoute +} diff --git a/src/types/interfaces/chain.d.ts b/src/types/interfaces/chain.d.ts index 37555ace..2ceaa596 100644 --- a/src/types/interfaces/chain.d.ts +++ b/src/types/interfaces/chain.d.ts @@ -29,6 +29,7 @@ interface ChainConfig { swap: string explorer: string pools: string + routes: string aprs: { vaults: string stride: string diff --git a/src/types/interfaces/route.d.ts b/src/types/interfaces/route.d.ts index cbd0f1c5..59fff097 100644 --- a/src/types/interfaces/route.d.ts +++ b/src/types/interfaces/route.d.ts @@ -11,3 +11,79 @@ type Page = | 'hls-staking' | 'governance' | 'execute' + +type OsmosisRouteResponse = { + amount_in: { + denom: string + amount: string + } + amount_out: string + route: OsmosisRoute[] + effective_fee: string + price_impact: string +} + +type OsmosisRoute = { + pools: OsmosisRoutePool[] + 'has-cw-pool': boolean + out_amount: string + in_amount: string +} + +type OsmosisRoutePool = { + id: number + type: number + balances: [] + spread_factor: string + token_out_denom: string + taker_fee: string +} + +type SwapRouteInfo = { + priceImpact: BigNumber + fee: BigNumber + route: OsmosisSwap | AstroportSwap +} + +type OsmosisSwap = { + osmo: { + swaps: { + pool_id: string + to: string + }[] + } +} + +type AstroportSwap = { + astro: { + swaps: { + from: string + to: string + }[] + } +} + +type AstroportRouteResponse = { + id: string + swaps: AstroportRoute[] + denom_in: string + decimals_in: number + price_in: number + value_in: string + amount_in: string + denom_out: string + decimals_out: number + price_out: number + value_out: string + amount_out: string + price_difference: number + price_impact: number +} + +type AstroportRoute = { + contract_addr: string + from: string + to: string + type: string + illiquid: boolean +}