Skip to content

Commit

Permalink
Qa/round 1 (#372)
Browse files Browse the repository at this point in the history
* wip

* add useRewardsDistributors

* round 1 qa
  • Loading branch information
jmzwar authored Jul 21, 2024
1 parent bc4328c commit a02d466
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 64 deletions.
1 change: 1 addition & 0 deletions liquidity/lib/useRewardsDistributors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useRewardsDistributors';
11 changes: 11 additions & 0 deletions liquidity/lib/useRewardsDistributors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@snx-v3/useRewardsDistributors",
"private": true,
"main": "index.ts",
"version": "0.0.1",
"dependencies": {
"@snx-v3/contracts": "workspace:*",
"@snx-v3/useBlockchain": "workspace:*",
"@tanstack/react-query": "^5.8.3"
}
}
19 changes: 19 additions & 0 deletions liquidity/lib/useRewardsDistributors/useRewardsDistributors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Network, useNetwork } from '@snx-v3/useBlockchain';
import { useQuery } from '@tanstack/react-query';
import { importRewardsDistributors } from '@snx-v3/contracts';

export function useRewardsDistributors(customNetwork?: Network) {
const { network } = useNetwork();
const targetNetwork = customNetwork || network;

return useQuery({
queryKey: [`${targetNetwork?.id}-${targetNetwork?.preset}`, 'RewardsDistributors'],
queryFn: async function () {
if (!targetNetwork) throw new Error('useRewardsDistributors should be disabled');

return importRewardsDistributors(targetNetwork?.id, targetNetwork?.preset);
},
enabled: Boolean(targetNetwork),
staleTime: Infinity,
});
}
1 change: 1 addition & 0 deletions liquidity/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@snx-v3/usePoolsList": "workspace:*",
"@snx-v3/useRepay": "workspace:*",
"@snx-v3/useRewards": "workspace:^",
"@snx-v3/useRewardsDistributors": "workspace:^",
"@snx-v3/useSystemToken": "workspace:*",
"@snx-v3/useTokenBalance": "workspace:*",
"@snx-v3/useTransferAccountId": "workspace:*",
Expand Down
73 changes: 48 additions & 25 deletions liquidity/ui/src/components/Pools/PoolCards/PoolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface PoolCardProps {
collateralAprs: any[];
};
balances?: Wei[];
rewardsPayoutTokens?: string[];
}

export const PoolCard = ({
Expand All @@ -65,6 +66,7 @@ export const PoolCard = ({
collateralTypes,
collateralPrices,
balances,
rewardsPayoutTokens,
}: PoolCardProps) => {
const navigate = useNavigate();
const [queryParams] = useSearchParams();
Expand Down Expand Up @@ -164,7 +166,23 @@ export const PoolCard = ({
?.concat('%')}`
: '-'}
</Text>
<Tooltip label="Apr is averaged over the trailing 28 days and is comprised of both performance and rewards.">
<Tooltip
label={
<Flex direction="column">
<Text color="white" fontFamily="heading" fontSize="sm" lineHeight={5}>
Rewards Available
</Text>
{rewardsPayoutTokens?.map((token) => (
<Flex key={token} alignItems="center" mt={1}>
<TokenIcon mr={1} width={16} height={16} mt={1} symbol={token} />
<Text mt={1} fontSize="sm" lineHeight={5}>
{token}
</Text>
</Flex>
))}
</Flex>
}
>
<Flex>
<Sparkles w="18px" h="18px" mb={0.5} />
</Flex>
Expand Down Expand Up @@ -279,10 +297,36 @@ export const PoolCard = ({

const { apr28d, apr28dRewards, apr28dPnl } = collateralApr;

const onClick = async () => {
try {
if (!currentNetwork) {
connect();
return;
}

if (currentNetwork.id !== network.id) {
if (!(await setNetwork(network.id))) {
return;
}
}

queryParams.set('manageAction', 'deposit');
navigate({
pathname: `/positions/${type.symbol}/${pool.id}`,
search: queryParams.toString(),
});
} catch (error) {}
};

return (
<Tr key={type.tokenAddress}>
<Td border="none" px={4} w="20%">
<Flex minWidth="120px" alignItems="center">
<Flex
minWidth="120px"
alignItems="center"
_hover={{ textDecoration: 'underline', cursor: 'pointer' }}
onClick={onClick}
>
<TokenIcon w={26} h={26} symbol={type.symbol} />
<Flex flexDirection="column" ml={3} mr="auto">
<Text
Expand Down Expand Up @@ -383,28 +427,7 @@ export const PoolCard = ({
</Td>
<Td border="none" textAlign="right" pl={4} pr={0}>
<Button
onClick={async (e) => {
try {
e.stopPropagation();

if (!currentNetwork) {
connect();
return;
}

if (currentNetwork.id !== network.id) {
if (!(await setNetwork(network.id))) {
return;
}
}

queryParams.set('manageAction', 'deposit');
navigate({
pathname: `/positions/${type.symbol}/${pool.id}`,
search: queryParams.toString(),
});
} catch (error) {}
}}
onClick={onClick}
size="sm"
height="32px"
py="10px"
Expand All @@ -416,7 +439,7 @@ export const PoolCard = ({
fontSize="14px"
lineHeight="20px"
>
Deposit
{!currentNetwork ? 'Connect Wallet' : 'Deposit'}
</Button>
</Td>
</Tr>
Expand Down
14 changes: 1 addition & 13 deletions liquidity/ui/src/components/Pools/PoolCards/TorosPoolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from '@chakra-ui/react';
import { NetworkIcon } from '@snx-v3/useBlockchain';
import { TokenIcon } from '../../TokenIcon';
import { Sparkles } from '@snx-v3/icons';
import { Tooltip } from '@snx-v3/Tooltip';

interface TorosPoolCardProps {
Expand All @@ -44,17 +43,7 @@ export function TorosPoolCard({ tvl, apy }: TorosPoolCardProps) {
width="calc(100% - 2px)"
height="calc(100% - 2px)"
/>
<Flex
position="relative"
onClick={() => {
window.open('https://toros.finance/synthetix-usdc-andromeda-yield', '_blank');
}}
flexDir="column"
rounded="base"
bg="navy.700"
_hover={{ cursor: 'pointer', bg: 'whiteAlpha.50', textDecoration: 'none' }}
p={6}
>
<Flex position="relative" flexDir="column" rounded="base" bg="navy.700" p={6}>
<Flex
flexDir={['column', 'row']}
w="100%"
Expand Down Expand Up @@ -195,7 +184,6 @@ export function TorosPoolCard({ tvl, apy }: TorosPoolCardProps) {
minWidth="100px"
>
{apy}%
<Sparkles w="14px" h="14px" mb={1} ml="0.5px" mt="1px" />
</Text>
</Td>
<Td border="none" textAlign="right" px={0}>
Expand Down
61 changes: 44 additions & 17 deletions liquidity/ui/src/components/Pools/PoolsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ARBITRUM, BASE_ANDROMEDA } from '@snx-v3/useBlockchain';
import { isBaseAndromeda } from '@snx-v3/isBaseAndromeda';
import { useTokenBalances } from '@snx-v3/useTokenBalance';
import { useGetUSDTokens } from '@snx-v3/useGetUSDTokens';
import { useRewardsDistributors } from '@snx-v3/useRewardsDistributors';

export const PoolsList = () => {
const [state, dispatch] = useReducer(poolsReducer, { collateral: [], chain: [] });
Expand Down Expand Up @@ -54,6 +55,14 @@ export const PoolsList = () => {
BASE_ANDROMEDA
);

// Arb Rewards
const { data: ArbitrumRewards, isLoading: isArbitrumRewardsLoading } =
useRewardsDistributors(ARBITRUM);

// Base Rewards
const { data: BaseRewards, isLoading: isBaseRewardsLoading } =
useRewardsDistributors(BASE_ANDROMEDA);

const { collateral, chain } = state;

const showToros =
Expand All @@ -66,7 +75,9 @@ export const PoolsList = () => {
isBaseCollateralLoading ||
isArbCollateralLoading ||
isArbitrumBalancesLoading ||
isBaseBalancesLoading;
isBaseBalancesLoading ||
isArbitrumRewardsLoading ||
isBaseRewardsLoading;

const filteredPools = useMemo(() => {
return (
Expand All @@ -88,6 +99,7 @@ export const PoolsList = () => {
}));

const balances = network.id === ARBITRUM.id ? ArbitrumTokenBalances : BaseTokenBalances;
const rewardsDistributors = network.id === ARBITRUM.id ? ArbitrumRewards : BaseRewards;

return {
network,
Expand All @@ -96,6 +108,7 @@ export const PoolsList = () => {
collateralDeposited,
collateralTypes,
balances,
rewardsDistributors,
};
})
.filter((pool) => {
Expand Down Expand Up @@ -133,6 +146,8 @@ export const PoolsList = () => {
data?.synthetixPools,
ArbitrumTokenBalances,
BaseTokenBalances,
ArbitrumRewards,
BaseRewards,
]);

return (
Expand All @@ -150,21 +165,32 @@ export const PoolsList = () => {
<TorosPoolCard tvl={data?.toros.tvl || ''} apy={data?.toros.apy} />
)}
{!isLoading &&
filteredPools.map(({ network, poolInfo, apr, collateralTypes, balances }) => {
const { pool } = poolInfo[0];

return (
<PoolCard
key={network.hexId}
collateralTypes={collateralTypes}
collateralPrices={collateralPrices}
apr={apr}
network={network}
pool={pool}
balances={balances}
/>
);
})}
filteredPools.map(
({ network, poolInfo, apr, collateralTypes, balances, rewardsDistributors }) => {
const { pool } = poolInfo[0];

const rewardsPayoutTokens = [
...new Set(
rewardsDistributors?.map(({ payoutToken }: any) =>
payoutToken.symbol.toUpperCase()
)
),
] as string[];

return (
<PoolCard
key={network.hexId}
collateralTypes={collateralTypes}
collateralPrices={collateralPrices}
apr={apr}
network={network}
pool={pool}
balances={balances}
rewardsPayoutTokens={rewardsPayoutTokens}
/>
);
}
)}

{!isLoading && !filteredPools.length && (
<Flex flexDir="column" alignItems="center">
Expand Down Expand Up @@ -216,7 +242,8 @@ function poolsReducer(state: PoolsFilterState, action: PoolsFilterAction): Pools
if (action.payload?.collateral) {
return {
...state,
collateral: [...state.collateral, action.payload.collateral],
// Only one collateral active at once
collateral: [action.payload.collateral],
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@ export function PositionRow({
poolId,
});

const onClick = () => {
queryParams.set('manageAction', debt.gt(0) ? 'repay' : 'claim');
navigate({
pathname: `/positions/${collateralType.symbol}/${poolId}`,
search: queryParams.toString(),
});
};

return (
<Tr borderBottomWidth={final ? 'none' : '1px'}>
<Td border="none">
<Fade in>
<Flex alignItems="center">
<Flex
alignItems="center"
_hover={{ textDecoration: 'underline', cursor: 'pointer' }}
onClick={onClick}
>
<TokenIcon symbol={collateralType.symbol} />
<Flex flexDirection="column" ml={3}>
<Text
Expand Down Expand Up @@ -89,13 +101,7 @@ export function PositionRow({
fontSize="0.75rem"
lineHeight="1rem"
cursor="pointer"
onClick={() => {
queryParams.set('manageAction', debt.gt(0) ? 'repay' : 'claim');
navigate({
pathname: `/positions/${collateralType.symbol}/${poolId}`,
search: queryParams.toString(),
});
}}
onClick={onClick}
>
{debt.gt(0) ? 'Repay Debt' : 'Claim Credit'}
</Text>
Expand All @@ -109,7 +115,6 @@ export function PositionRow({
<Text color="white" fontSize="sm" lineHeight="1.25rem" fontFamily="heading">
{debt.gt(0) ? (cRatio.toNumber() * 100).toFixed(2) + '%' : 'Infinite'}
</Text>

<CRatioBadge
cRatio={cRatio.toNumber() * 100}
liquidationCratio={(collateralType?.liquidationRatioD18?.toNumber() || 0) * 100}
Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5829,6 +5829,7 @@ __metadata:
"@snx-v3/usePoolsList": "workspace:*"
"@snx-v3/useRepay": "workspace:*"
"@snx-v3/useRewards": "workspace:^"
"@snx-v3/useRewardsDistributors": "workspace:^"
"@snx-v3/useSystemToken": "workspace:*"
"@snx-v3/useTokenBalance": "workspace:*"
"@snx-v3/useTransferAccountId": "workspace:*"
Expand Down Expand Up @@ -6667,6 +6668,16 @@ __metadata:
languageName: unknown
linkType: soft

"@snx-v3/useRewardsDistributors@workspace:^, @snx-v3/useRewardsDistributors@workspace:liquidity/lib/useRewardsDistributors":
version: 0.0.0-use.local
resolution: "@snx-v3/useRewardsDistributors@workspace:liquidity/lib/useRewardsDistributors"
dependencies:
"@snx-v3/contracts": "workspace:*"
"@snx-v3/useBlockchain": "workspace:*"
"@tanstack/react-query": "npm:^5.8.3"
languageName: unknown
linkType: soft

"@snx-v3/useSpotMarketProxy@workspace:*, @snx-v3/useSpotMarketProxy@workspace:liquidity/lib/useSpotMarketProxy":
version: 0.0.0-use.local
resolution: "@snx-v3/useSpotMarketProxy@workspace:liquidity/lib/useSpotMarketProxy"
Expand Down

0 comments on commit a02d466

Please sign in to comment.