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

SOV-4539 fetch pool data from indexer #1050

Open
wants to merge 10 commits into
base: develop
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
5 changes: 0 additions & 5 deletions .changeset/brown-bobcats-burn.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/lazy-adults-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sovryn/sdk': patch
---

SOV-4539: fetch pools from indexer
6 changes: 6 additions & 0 deletions .changeset/serious-llamas-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'frontend': patch
'@sovryn/sdex': patch
---

chore: change bob testnet rpc address
6 changes: 6 additions & 0 deletions apps/frontend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# frontend

## 1.1.27

### Patch Changes

- 58350fd0: Adjust homepage banners

## 1.1.26

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "1.1.26",
"version": "1.1.27",
"homepage": ".",
"private": true,
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { FC, useEffect, useState } from 'react';

import { CrocEnv } from '@sovryn/sdex';
import { Pool } from '@sovryn/sdk';
import { Decimal } from '@sovryn/utils';

import { BOB_CHAIN_ID } from '../../../../config/chains';

import { AmountRenderer } from '../../../2_molecules/AmountRenderer/AmountRenderer';
import { AssetPairRenderer } from '../../../2_molecules/AssetPairRenderer/AssetPairRenderer';
import { loadIndexer } from '../../../../lib/indexer';
import { decimalic } from '../../../../utils/math';
import { AmbientLiquidityPool } from '../../MarketMakingPage/components/AmbientMarketMaking/utils/AmbientLiquidityPool';
import { AmbientLiquidityPoolDictionary } from '../../MarketMakingPage/components/AmbientMarketMaking/utils/AmbientLiquidityPoolDictionary';
import { Claim } from '../hooks/useClaimLp';

type ClaimableItemProps = {
Expand All @@ -18,7 +18,7 @@ type ClaimableItemProps = {

export const ClaimableItem: FC<ClaimableItemProps> = ({ item }) => {
const [loading, setLoading] = useState<boolean>(false);
const [pool, setPool] = useState<AmbientLiquidityPool | null>(null);
const [pool, setPool] = useState<Pool | null>(null);
const [liqBase, setLiqBase] = useState<Decimal>(Decimal.ZERO);
const [liqQuote, setLiqQuote] = useState<Decimal>(Decimal.ZERO);

Expand All @@ -27,14 +27,19 @@ export const ClaimableItem: FC<ClaimableItemProps> = ({ item }) => {
try {
setLoading(true);
const env = new CrocEnv(BOB_CHAIN_ID);
const amm = AmbientLiquidityPoolDictionary.list(BOB_CHAIN_ID).find(
p => p.lpTokenAddress?.toLowerCase() === item.token.toLowerCase(),
const pools = await loadIndexer(BOB_CHAIN_ID).pools.list();
const amm = pools.find(
p => p.extra.lpToken?.toLowerCase() === item.token.toLowerCase(),
);
setPool(amm!);
if (!amm) {
return;
}
const p = env.pool(amm.baseAddress, amm.quoteAddress, amm.poolIndex);
const p = env.pool(
amm.base.address,
amm.quote.address,
amm.extra.poolIdx,
);

const [spotPrice, baseDecimals, quoteDecimals] = await Promise.all([
p.spotPrice(),
Expand All @@ -47,6 +52,7 @@ export const ClaimableItem: FC<ClaimableItemProps> = ({ item }) => {
(Number(item.amount) * Math.sqrt(spotPrice)).toFixed(0),
).toUnits(baseDecimals),
);

setLiqQuote(
decimalic(
(Number(item.amount) / Math.sqrt(spotPrice)).toFixed(0),
Expand All @@ -69,16 +75,16 @@ export const ClaimableItem: FC<ClaimableItemProps> = ({ item }) => {
<div className="first:mt-4 mb-2 px-4 py-2 bg-gray-70 flex flex-row space-x-4 items-center justify-between text-xs rounded">
<div className="basis-1/3">
<AssetPairRenderer
asset1={pool?.quote}
asset2={pool?.base}
asset1={pool.quote.symbol}
asset2={pool.base.symbol}
chainId={BOB_CHAIN_ID}
/>
</div>
<div className="basis-1/3">
<AmountRenderer value={liqBase} suffix={pool?.base} />
<AmountRenderer value={liqBase} suffix={pool.base.symbol} />
</div>
<div className="basis-1/3">
<AmountRenderer value={liqQuote} suffix={pool?.quote} />
<AmountRenderer value={liqQuote} suffix={pool.quote.symbol} />
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,33 @@ import { RSK_CHAIN_ID } from '../../../../../config/chains';

import { MarketMakingNetworkBanner } from '../../../../2_molecules/MarketMakingNetworkBanner/MarketMakingNetworkBanner';
import { BOB_STORAGE_KEY } from '../../../../2_molecules/MarketMakingNetworkBanner/MarketMakingNetworkBanner.constants';
import { useCacheCall } from '../../../../../hooks';
import { useCurrentChain } from '../../../../../hooks/useChainStore';
import { loadIndexer } from '../../../../../lib/indexer';
import { translations } from '../../../../../locales/i18n';
import { AmbientPoolsTable } from './components/AmbientPoolsTable/AmbientPoolsTable';
import { PoolListGroup } from './utils/AmbientLiquidityPool';
import { AmbientLiquidityPoolDictionary } from './utils/AmbientLiquidityPoolDictionary';

export const AmbientMarketMaking: FC = () => {
const chainId = useCurrentChain();
const newPools = useMemo(
() => AmbientLiquidityPoolDictionary.list(chainId, PoolListGroup.new),
const { value } = useCacheCall(
'mm',
chainId,
async () => {
return (await loadIndexer(chainId).pools.list()).sort((a, b) =>
a.base.symbol < b.base.symbol ? -1 : 1,
);
},
[chainId],
[],
);
const allPools = useMemo(
() => AmbientLiquidityPoolDictionary.list(chainId),
[chainId],

const newPools = useMemo(
() => (value ?? []).filter(pool => pool.featured),
[value],
);

const allPools = useMemo(() => value ?? [], [value]);

return (
<>
<Helmet>
Expand All @@ -37,6 +47,7 @@ export const AmbientMarketMaking: FC = () => {
requiredChainId={RSK_CHAIN_ID}
storageKey={BOB_STORAGE_KEY}
/>

<div className="text-gray-10 mt-6 mb-4 sm:mt-9">
<Heading className="text-center mb-1 lg:mb-3 text-base lg:text-2xl">
{t(translations.ambientMarketMaking.title)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React from 'react';

import { t } from 'i18next';

import { numberToChainId } from '@sovryn/ethers-provider';
import { Pool } from '@sovryn/sdk';
import { HelperButton } from '@sovryn/ui';

import { AmountRenderer } from '../../../../../../2_molecules/AmountRenderer/AmountRenderer';
import { TransactionIdRenderer } from '../../../../../../2_molecules/TransactionIdRenderer/TransactionIdRenderer';
import { translations } from '../../../../../../../locales/i18n';
import { AmbientPosition } from '../../AmbientMarketMaking.types';
import { AmbientLiquidityPool } from '../../utils/AmbientLiquidityPool';
import { AmbientPoolPositionClaimFees } from './components/AmbientPoolPositionClaimFees/AmbientPoolPositionClaimFees';
import { AmbientPoolPositionWithdraw } from './components/AmbientPoolPositionWithdraw/AmbientPoolPositionWithdraw';
import { AmbientPoolReposition } from './components/AmbientPoolReposition/AmbientPoolReposition';
Expand All @@ -17,14 +18,14 @@ import { AmbientPositionPrices } from './components/AmbientPositionPrices/Ambien
import { AmbientPositionStatus } from './components/AmbientPositionStatus/AmbientPositionStatus';
import { AmbientPositionValue } from './components/AmbientPositionValue/AmbientPositionValue';

export const COLUMNS_CONFIG = (pool: AmbientLiquidityPool) => [
export const COLUMNS_CONFIG = (pool: Pool) => [
{
id: 'positionID',
title: t(translations.ambientMarketMaking.positionsTable.positionID),
cellRenderer: (position: AmbientPosition) => (
<TransactionIdRenderer
hash={position.transactionHash}
chainId={pool.chainId}
chainId={numberToChainId(pool.chainId)}
/>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import React, { FC } from 'react';

import { t } from 'i18next';

import { numberToChainId } from '@sovryn/ethers-provider';
import { Pool } from '@sovryn/sdk';
import { HelperButton, SimpleTableRow, Table } from '@sovryn/ui';

import { AmountRenderer } from '../../../../../../2_molecules/AmountRenderer/AmountRenderer';
import { TransactionIdRenderer } from '../../../../../../2_molecules/TransactionIdRenderer/TransactionIdRenderer';
import { useIsMobile } from '../../../../../../../hooks/useIsMobile';
import { translations } from '../../../../../../../locales/i18n';
import { useGetAmbientPositions } from '../../hooks/useGetAmbientPositions';
import { AmbientLiquidityPool } from '../../utils/AmbientLiquidityPool';
import { COLUMNS_CONFIG } from './AmbientPoolPositions.constants';
import styles from './AmbientPoolPositions.module.css';
import { AmbientPoolPositionClaimFees } from './components/AmbientPoolPositionClaimFees/AmbientPoolPositionClaimFees';
Expand All @@ -20,7 +21,7 @@ import { AmbientPositionStatus } from './components/AmbientPositionStatus/Ambien
import { AmbientPositionValue } from './components/AmbientPositionValue/AmbientPositionValue';

type AmbientPoolPositionsProps = {
pool: AmbientLiquidityPool;
pool: Pool;
};

export const AmbientPoolPositions: FC<AmbientPoolPositionsProps> = ({
Expand All @@ -41,7 +42,7 @@ export const AmbientPoolPositions: FC<AmbientPoolPositionsProps> = ({
value={
<TransactionIdRenderer
hash={position.transactionHash}
chainId={pool.chainId}
chainId={numberToChainId(pool.chainId)}
/>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React, { FC, useCallback, useState } from 'react';

import { t } from 'i18next';

import { Pool } from '@sovryn/sdk';
import { ButtonSize, ButtonStyle, Button } from '@sovryn/ui';

import { useMaintenance } from '../../../../../../../../../hooks/useMaintenance';
import { translations } from '../../../../../../../../../locales/i18n';
import { BobClaimFeesModal } from '../../../../../BobClaimFeesModal/BobClaimFeesModal';
import { AmbientPosition } from '../../../../AmbientMarketMaking.types';
import { AmbientLiquidityPool } from '../../../../utils/AmbientLiquidityPool';

type AmbientPoolPositionClaimFeesProps = {
pool: AmbientLiquidityPool;
pool: Pool;
position: AmbientPosition;
className?: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React, { FC, useCallback, useState } from 'react';

import { t } from 'i18next';

import { Pool } from '@sovryn/sdk';
import { ButtonSize, ButtonStyle, Button } from '@sovryn/ui';

import { useMaintenance } from '../../../../../../../../../hooks/useMaintenance';
import { translations } from '../../../../../../../../../locales/i18n';
import { BobWithdrawModal } from '../../../../../BobWIthdrawModal/BobWithdrawModal';
import { AmbientPosition } from '../../../../AmbientMarketMaking.types';
import { AmbientLiquidityPool } from '../../../../utils/AmbientLiquidityPool';

type AmbientPoolPositionWithdrawProps = {
pool: AmbientLiquidityPool;
pool: Pool;
position: AmbientPosition;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import React, { FC, useCallback, useState } from 'react';

import { t } from 'i18next';

import { Pool } from '@sovryn/sdk';
import { ButtonSize, ButtonStyle, Button } from '@sovryn/ui';

import { useMaintenance } from '../../../../../../../../../hooks/useMaintenance';
import { translations } from '../../../../../../../../../locales/i18n';
import { DepositContextProvider } from '../../../../../BobDepositModal/contexts/BobDepositModalContext';
import { BobRepositionModal } from '../../../../../BobRepositionModal/BobRepositionModal';
import { AmbientPosition } from '../../../../AmbientMarketMaking.types';
import { AmbientLiquidityPool } from '../../../../utils/AmbientLiquidityPool';
import { usePositionStatus } from '../../hooks/usePositionStatus';

type AmbientPoolRepositionProps = {
pool: AmbientLiquidityPool;
pool: Pool;
position: AmbientPosition;
className?: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React, { FC } from 'react';

import { numberToChainId } from '@sovryn/ethers-provider';
import { Pool } from '@sovryn/sdk';

import { AmountRenderer } from '../../../../../../../../2_molecules/AmountRenderer/AmountRenderer';
import { useIsMounted } from '../../../../../../../../../hooks/useIsMounted';
import { useTokenDetailsByAsset } from '../../../../../../../../../hooks/useTokenDetailsByAsset';
import { decimalic } from '../../../../../../../../../utils/math';
import { AmbientPosition } from '../../../../AmbientMarketMaking.types';
import { AmbientLiquidityPool } from '../../../../utils/AmbientLiquidityPool';
import { useAmbientPositionBalance } from '../../hooks/useAmbientPositionBalance';

type AmbientPositionBalanceProps = {
pool: AmbientLiquidityPool;
pool: Pool;
position: AmbientPosition;
};

Expand All @@ -18,8 +20,14 @@ export const AmbientPositionBalance: FC<AmbientPositionBalanceProps> = ({
pool,
}) => {
const isMounted = useIsMounted();
const baseToken = useTokenDetailsByAsset(pool.base, pool.chainId);
const quoteToken = useTokenDetailsByAsset(pool.quote, pool.chainId);
const baseToken = useTokenDetailsByAsset(
pool.base.symbol,
numberToChainId(pool.chainId),
);
const quoteToken = useTokenDetailsByAsset(
pool.quote.symbol,
numberToChainId(pool.chainId),
);
const result = useAmbientPositionBalance(pool, position);
if (!result || !isMounted()) {
return null;
Expand All @@ -31,13 +39,13 @@ export const AmbientPositionBalance: FC<AmbientPositionBalanceProps> = ({
value={decimalic(result?.positionLiqBase || '0').toUnits(
baseToken?.decimals,
)}
suffix={pool.base}
suffix={pool.base.symbol}
/>
<AmountRenderer
value={decimalic(result?.positionLiqQuote || '0').toUnits(
quoteToken?.decimals,
)}
suffix={pool.quote}
suffix={pool.quote.symbol}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import React, { FC, useCallback, useMemo } from 'react';

import { MIN_TICK, MAX_TICK, tickToPrice, toDisplayPrice } from '@sovryn/sdex';
import { Pool } from '@sovryn/sdk';

import { AmountRenderer } from '../../../../../../../../2_molecules/AmountRenderer/AmountRenderer';
import { PoolPositionType } from '../../../../../../MarketMakingPage.types';
import { useGetPoolInfo } from '../../../../../BobDepositModal/hooks/useGetPoolInfo';
import { useGetTokenDecimals } from '../../../../../BobWIthdrawModal/hooks/useGetTokenDecimals';
import { AmbientPosition } from '../../../../AmbientMarketMaking.types';
import { AmbientLiquidityPool } from '../../../../utils/AmbientLiquidityPool';

type AmbientPositionPricesProps = {
pool: AmbientLiquidityPool;
pool: Pool;
position: AmbientPosition;
};

Expand All @@ -25,25 +23,19 @@ export const AmbientPositionPrices: FC<AmbientPositionPricesProps> = ({
[position],
);

const { poolTokens } = useGetPoolInfo(pool.base, pool.quote);
const { baseTokenDecimals, quoteTokenDecimals } = useGetTokenDecimals(
poolTokens?.tokenA,
poolTokens?.tokenB,
);

const renderAmountRenderer = useCallback(
(tick: number) => (
<AmountRenderer
value={toDisplayPrice(
tickToPrice(tick),
baseTokenDecimals,
quoteTokenDecimals,
pool.base.decimals,
pool.quote.decimals,
true,
)}
suffix={pool.quote}
suffix={pool.quote.symbol}
/>
),
[baseTokenDecimals, quoteTokenDecimals, pool.quote],
[pool.base.decimals, pool.quote.decimals, pool.quote.symbol],
);

if (isAmbient) {
Expand Down
Loading