Skip to content

Commit

Permalink
fix: useGetPools hook
Browse files Browse the repository at this point in the history
  • Loading branch information
therealemjy committed Dec 16, 2024
1 parent b4b9d2a commit f12a609
Show file tree
Hide file tree
Showing 14 changed files with 376 additions and 1,490 deletions.
39 changes: 39 additions & 0 deletions apps/evm/__mocks__/@venusprotocol/chains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ChainId } from '__mocks__/models/chains';
import { isolatedPool, legacyCorePool } from '__mocks__/models/pools';
import { bnb, eth } from '__mocks__/models/tokens';
export { ChainId } from '__mocks__/models/chains';

export const chainMetadata = {
[ChainId.BSC_MAINNET]: {
name: 'BNB Chain',
logoSrc: 'fake-logo-src-bsc-mainnet',
explorerUrl: 'https://bscscan.com',
layerZeroScanUrl: 'https://layerzeroscan.com',
blockTimeMs: 3000,
blocksPerDay: 28800,
corePoolComptrollerContractAddress: legacyCorePool.comptrollerAddress,
nativeToken: bnb,
},
[ChainId.BSC_TESTNET]: {
name: 'BNB testnet',
logoSrc: 'fake-logo-src-bsc-testnet',
explorerUrl: 'https://testnet.bscscan.com',
layerZeroScanUrl: 'https://testnet.layerzeroscan.com',
blockTimeMs: 3000,
blocksPerDay: 28800,
corePoolComptrollerContractAddress: legacyCorePool.comptrollerAddress,
nativeToken: bnb,
},
[ChainId.ETHEREUM]: {
name: 'Ethereum',
logoSrc: 'fake-logo-src-bsc-ethereum',
explorerUrl: 'https://etherscan.io',
layerZeroScanUrl: 'https://layerzeroscan.com',
blockTimeMs: 12000,
blocksPerDay: 7200,
corePoolComptrollerContractAddress: isolatedPool.comptrollerAddress,
lstPoolComptrollerContractAddress: '0xF522cd0360EF8c2FF48B648d53EA1717Ec0F3Ac3',
lstPoolVWstEthContractAddress: '0x4a240F0ee138697726C8a3E43eFE6Ac3593432CB',
nativeToken: eth,
},
};
1,283 changes: 0 additions & 1,283 deletions apps/evm/src/__mocks__/api/markets.json

This file was deleted.

5 changes: 5 additions & 0 deletions apps/evm/src/__mocks__/models/chains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum ChainId {
BSC_MAINNET = 56,
BSC_TESTNET = 97,
ETHEREUM = 1,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import {
getPoolLiquidationIncentive,
} from 'clients/api/queries/getPoolLiquidationIncentive';
import FunctionKey from 'constants/functionKey';
import { useGetChainMetadata } from 'hooks/useGetChainMetadata';
import {
useGetIsolatedPoolComptrollerContract,
useGetLegacyPoolComptrollerContract,
} from 'libs/contracts';
import { useChainId } from 'libs/wallet';
import { ChainId } from 'types';
import { areAddressesEqual, callOrThrow } from 'utilities';
import type { ChainId } from 'types';
import { callOrThrow, isPoolIsolated } from 'utilities';

interface TrimmedGetPoolLiquidationIncentiveInput
extends Omit<GetPoolLiquidationIncentiveInput, 'poolComptrollerContract'> {
Expand All @@ -40,19 +39,21 @@ export const useGetPoolLiquidationIncentive = (
options?: Partial<Options>,
) => {
const { chainId } = useChainId();
const { corePoolComptrollerContractAddress } = useGetChainMetadata();

const legacyPoolComptrollerContract = useGetLegacyPoolComptrollerContract();
const isolatedPoolComptrollerContract = useGetIsolatedPoolComptrollerContract({
address: poolComptrollerContractAddress,
passSigner: false,
});

const poolComptrollerContract =
areAddressesEqual(corePoolComptrollerContractAddress, poolComptrollerContractAddress) &&
(chainId === ChainId.BSC_MAINNET || chainId === ChainId.BSC_TESTNET)
? legacyPoolComptrollerContract
: isolatedPoolComptrollerContract;
const isIsolated = isPoolIsolated({
chainId,
comptrollerAddress: poolComptrollerContractAddress,
});

const poolComptrollerContract = isIsolated
? isolatedPoolComptrollerContract
: legacyPoolComptrollerContract;

return useQuery({
queryKey: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,75 @@ import type {
VenusLens,
} from 'libs/contracts';

export const fakeGetPriceOutput = BN.from('0x30f7dc8a6370b000');
const userLegacyCollateralizedVTokenAddresses = [
'0x08e0A5575De71037aE36AbfAfb516595fE68e5e4',
'0x162D005F0Fff510E54958Cfc5CF32A3180A84aab',
'0x171B468b52d7027F12cEF90cd065d6776a25E24e',
'0x2E7222e51c0f6e98610A1543Aa3836E092CDe62c',
'0x35566ED3AF9E537Be487C98b1811cDf95ad0C32b',
'0x3619bdDc61189F33365CC572DF3a68FB3b316516',
'0x3A00d9B02781f47d033BAd62edc55fBF8D083Fb0',
'0x6AF3Fdb3282c5bb6926269Db10837fa8Aec67C04',
'0x6d6F697e34145Bb95c54E77482d97cc261Dc237E',
'0x74469281310195A04840Daf6EdF576F559a3dE80',
'0xb6e9322C49FD75a367Fcb17B0Fcd62C5070EbCBe',
'0xb7526572FFE56AB9D7489838Bf2E18e3323b441A',
'0xD5C4C2e2facBEB59D0216D0595d63FcDc6F9A1a7',
'0xF06e662a00796c122AaAE935EC4F0Be3F74f5636',
'0x4C94e67d239aD585275Fdd3246Ab82c8a2668564',
'0x5e68913fbbfb91af30366ab1B21324410b49a308',
'0x80CC30811e362aC9aB857C3d7875CbcCc0b65750',
'0xa109DE0abaeefC521Ec29D89eA42E64F37A6882E',
'0xe237aA131E7B004aC88CB808Fa56AF3dc4C408f1',
'0xe507B30C41E9e375BCe05197c1e09fc9ee40c0f6',
'0x0bFE4e0B8A2a096A27e5B18b078d25be57C08634',
'0x1958035231E125830bA5d17D168cEa07Bb42184a',
];

const userIsolatedCollateralizedVTokenAddresses = [
'0x4c94e67d239ad585275fdd3246ab82c8a2668564',
'0x5e68913fbbfb91af30366ab1b21324410b49a308',
'0x80cc30811e362ac9ab857c3d7875cbccc0b65750',
'0xa109de0abaeefc521ec29d89ea42e64f37a6882e',
'0xb677e080148368eeee70fa3865d07e92c6500174',
'0xb7cac5ef82cb7f9197ee184779bdc52c5490c02a',
'0x1958035231e125830ba5d17d168cea07bb42184a',
'0xdedf3b2bcf25d0023115fd71a0f8221c91c92b1a',
'0x231ded0dfc99634e52ee1a1329586bc970d773b3',
'0x57a664dd7f1de19545fee9c86c949e3bf43d6d47',
'0x644a149853e5507adf3e682218b8ac86cdd62951',
'0x75aa42c832a8911b77219dbebabbb40040d16987',
'0xd5b20708d8f0fca52cb609938d0594c4e32e5dad',
'0xeffe7874c345ae877c1d893cd5160ddd359b24da',
'0x3af2be7abef0f840b196d99d79f4b803a5db14a1',
'0x170d3b2da05cc2124334240fb34ad1359e34c562',
'0x3338988d0beb4419acb8fe624218754053362d06',
'0x899ddf81dfbbf5889a16d075c352f2b959dd24a4',
'0x410286c43a525e1dcc7468a9b091c111c8324cd1',
'0xd804f74fe21290d213c46610ab171f7c2eeebde7',
'0xee543d5de2dbb5b07675fc72831a2f1812428393',
];

const userCollateralizedVTokenAddresses = [
...userLegacyCollateralizedVTokenAddresses,
...userIsolatedCollateralizedVTokenAddresses,
];

const vTokenBalancesAllMock = async (vTokenAddresses: string[]) =>
vTokenAddresses.map(vTokenAddress => ({
vToken: vTokenAddress,
balanceOf: BN.from('4000000000000000000'),
balanceOfUnderlying: BN.from('2000000000000000000'),
borrowBalanceCurrent: BN.from('100000000000000000'),
tokenBalance: BN.from('40000000000000000000'),
tokenAllowance: BN.from('50000000000000000000'),
}));
vTokenAddresses.map(vTokenAddress => {
const isUserCollateral = userCollateralizedVTokenAddresses.some(
a => a.toLowerCase() === vTokenAddress.toLowerCase(),
);

return {
vToken: vTokenAddress,
balanceOf: BN.from(isUserCollateral ? '4000000000000000000' : 0),
balanceOfUnderlying: BN.from('2000000000000000000'),
borrowBalanceCurrent: BN.from(isUserCollateral ? '100000000000000000' : 0),
tokenBalance: BN.from('40000000000000000000'),
tokenAllowance: BN.from('50000000000000000000'),
};
});

export const fakeVenusLensContract = {
callStatic: {
Expand All @@ -42,18 +100,11 @@ export const fakeVaiControllerContract = {
} as unknown as VaiController;

export const fakeIsolatedPoolComptrollerContract = {
getAssetsIn: async () => [
'0x501a91b995Bd41177503A1A4144F3D25BFF869e1',
'0x2517A3bEe42EA8f628926849B04870260164b555',
],
getAssetsIn: async () => userIsolatedCollateralizedVTokenAddresses,
} as unknown as IsolatedPoolComptroller;

export const fakeLegacyPoolComptrollerContract = {
getAssetsIn: async () => [
'0x08e0A5575De71037aE36AbfAfb516595fE68e5e4',
'0x162D005F0Fff510E54958Cfc5CF32A3180A84aab',
'0x171B468b52d7027F12cEF90cd065d6776a25E24e',
],
getAssetsIn: async () => userLegacyCollateralizedVTokenAddresses,
} as unknown as LegacyPoolComptroller;

export const fakePrimeContract = {
Expand Down
Loading

0 comments on commit f12a609

Please sign in to comment.