Skip to content

Commit e859787

Browse files
committed
feat: add logic to E-mode tab
1 parent 01cb0ed commit e859787

File tree

18 files changed

+484
-175
lines changed

18 files changed

+484
-175
lines changed

apps/evm/src/__mocks__/models/asset.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const assetData: Asset[] = [
2424
supplierCount: 100,
2525
borrowerCount: 10,
2626
isBorrowable: true,
27+
isBorrowableByUser: true,
2728
exchangeRateVTokens: new BigNumber(49.589181233),
2829
userWalletBalanceTokens: new BigNumber('100'),
2930
userWalletBalanceCents: new BigNumber('12786'),
@@ -94,6 +95,7 @@ export const assetData: Asset[] = [
9495
supplierCount: 100,
9596
borrowerCount: 10,
9697
isBorrowable: false,
98+
isBorrowableByUser: false,
9799
exchangeRateVTokens: new BigNumber(1),
98100
userWalletBalanceTokens: new BigNumber('0'),
99101
userWalletBalanceCents: new BigNumber('0'),
@@ -182,6 +184,7 @@ export const assetData: Asset[] = [
182184
supplierCount: 100,
183185
borrowerCount: 10,
184186
isBorrowable: true,
187+
isBorrowableByUser: true,
185188
exchangeRateVTokens: new BigNumber(0.981982),
186189
userWalletBalanceTokens: new BigNumber('900'),
187190
userWalletBalanceCents: new BigNumber('90000'),
@@ -266,6 +269,7 @@ export const assetData: Asset[] = [
266269
supplierCount: 100,
267270
borrowerCount: 10,
268271
isBorrowable: true,
272+
isBorrowableByUser: true,
269273
exchangeRateVTokens: new BigNumber(1.000003),
270274
userWalletBalanceTokens: new BigNumber('110'),
271275
userWalletBalanceCents: new BigNumber('11000'),

apps/evm/src/clients/api/queries/useGetPools/__tests__/__snapshots__/index.eMode.spec.ts.snap

Lines changed: 33 additions & 76 deletions
Large diffs are not rendered by default.

apps/evm/src/clients/api/queries/useGetPools/getPools/formatOutput/generateFakeEModeGroup.tsx renamed to apps/evm/src/clients/api/queries/useGetPools/getPools/formatOutput/generateFakeEModeGroup/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,11 @@ export const generateFakeEModeGroup = ({
6666
: convertFactorFromSmartContract({
6767
factor: new BigNumber(market.collateralFactorMantissa),
6868
}) + 0.1,
69-
liquidationThresholdPercentage: liquidationThresholdPercentage + 12,
70-
liquidationPenaltyPercentage: liquidationThresholdPercentage - 50,
69+
liquidationThresholdPercentage: i > 3 ? 0 : liquidationThresholdPercentage + 12,
70+
liquidationPenaltyPercentage: i > 3 ? 0 : liquidationThresholdPercentage - 50,
7171
liquidityCents: liquidityTokens.multipliedBy(100).toNumber(),
7272
liquidityTokens,
73-
isBorrowable:
74-
underlyingToken.symbol !== 'XVS' &&
75-
underlyingToken.symbol !== 'BTCB' &&
76-
underlyingToken.symbol !== 'BUSD',
73+
isBorrowable: i > 3,
7774
};
7875

7976
return [...acc, assetSettings];

apps/evm/src/clients/api/queries/useGetPools/getPools/formatOutput/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const formatOutput = ({
8080
name: 'DeFi',
8181
tokens,
8282
chainId,
83-
apiMarkets: apiPool.markets.slice(2, 8),
83+
apiMarkets: apiPool.markets.slice(5, 12),
8484
}),
8585
generateFakeEModeGroup({
8686
id: 2,
@@ -153,6 +153,8 @@ export const formatOutput = ({
153153
factor: new BigNumber(market.collateralFactorMantissa),
154154
});
155155

156+
const isBorrowable = true; // TODO: fetch from API
157+
156158
let userCollateralFactor = collateralFactor;
157159
let isCollateralOfUser = !!userCollateralVTokenAddresses.some(address =>
158160
areAddressesEqual(address, vToken.address),
@@ -163,6 +165,7 @@ export const formatOutput = ({
163165
);
164166

165167
let userLiquidationThresholdPercentage = liquidationThresholdPercentage;
168+
let isBorrowableByUser = isBorrowable;
166169

167170
if (userEModeGroup) {
168171
const eModeAssetSettings = userEModeGroup.assetSettings.find(settings =>
@@ -175,6 +178,10 @@ export const formatOutput = ({
175178
// If user has enabled an E-mode group and that asset is not in it, then it doesn't count as a user collateral
176179
0;
177180

181+
// If user has enabled an E-mode group and that asset is not in it, or is not borrowable in
182+
// it, then it can't be borrowed by the user
183+
isBorrowableByUser = eModeAssetSettings?.isBorrowable || false;
184+
178185
userLiquidationThresholdPercentage =
179186
eModeAssetSettings?.liquidationThresholdPercentage ?? liquidationThresholdPercentage;
180187

@@ -322,7 +329,8 @@ export const formatOutput = ({
322329
userWalletBalanceCents,
323330
userCollateralFactor,
324331
userLiquidationThresholdPercentage,
325-
isBorrowable: true, // TODO: get from API
332+
isBorrowable, // TODO: get from API
333+
isBorrowableByUser,
326334
// This will be calculated after all assets have been formatted
327335
userPercentOfLimit: 0,
328336
isCollateralOfUser,

apps/evm/src/components/InfoIcon/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Icon, type IconName } from '../Icon';
55
import { Tooltip } from '../Tooltip';
66

77
export interface InfoIconProps {
8-
tooltip: string | React.ReactElement;
8+
tooltip: string | React.ReactNode;
99
iconName?: IconName;
1010
iconClassName?: string;
1111
className?: string;

apps/evm/src/components/Tooltip/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { TooltipContent } from './TooltipContent';
1313

1414
export interface TooltipProps extends TooltipPrimitiveProps {
1515
className?: string;
16-
content: string | React.ReactElement;
16+
content: string | React.ReactNode;
1717
}
1818

1919
export const Tooltip = ({ className, content, children, ...props }: TooltipProps) => {

apps/evm/src/libs/translations/translations/en.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,16 +688,25 @@
688688
"pool": {
689689
"eMode": {
690690
"group": {
691+
"cannotDisable": {
692+
"tooltip": {
693+
"blockingPositions": "You can't disable this e-mode group because you have borrow positions with assets that can't be borrowed from the pool. <Link>Show my positions</Link>",
694+
"notEnoughCollateral": "You can't disable this e-mode group because your total collateral value would not cover your total borrow balance"
695+
}
696+
},
691697
"cannotEnable": {
692698
"modal": {
693699
"description": "You will need to close the following borrow positions in order to enable the <WhiteText>{{ eModeGroupName }}</WhiteText> E-mode group:",
694700
"repayButtonLabel": "Repay",
695701
"title": "Your positions"
696702
},
697-
"tooltip": "You can't enable this E-mode group because you have borrow positions with assets that don't belong in that group. <Link>Show my positions</Link>"
703+
"tooltip": {
704+
"blockingPositions": "You can't enable this e-mode group because you have borrow positions with assets that don't belong in that group. <Link>Show my positions</Link>",
705+
"notEnoughCollateral": "You can't enable this e-mode group because your total collateral value would not cover your total borrow balance"
706+
}
698707
},
708+
"disableButtonLabel": "Disable",
699709
"enableButtonLabel": "Enable",
700-
"enabledButtonLabel": "Enabled",
701710
"healthFactor": "Health factor:",
702711
"switchButtonLabel": "Switch"
703712
},

apps/evm/src/pages/Account/PoolPositions/Tables/EModeHeader/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export const EModeHeader: React.FC<EModeHeaderProps> = ({
2828
},
2929
});
3030

31-
console.log('rendered');
32-
3331
return (
3432
<Link
3533
className={cn(

apps/evm/src/pages/Pool/Assets/index.tsx

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,34 @@ export interface AssetsProps {
77
pool: Pool;
88
}
99

10-
export const Assets: React.FC<AssetsProps> = ({ pool }) => {
11-
return (
12-
<div className="space-y-6">
13-
<PoolStats pools={[pool]} stats={['supply', 'borrow', 'liquidity', 'assetCount']} />
10+
export const Assets: React.FC<AssetsProps> = ({ pool }) => (
11+
<div className="space-y-6">
12+
<PoolStats pools={[pool]} stats={['supply', 'borrow', 'liquidity', 'assetCount']} />
1413

15-
<MarketTable
16-
pools={[pool]}
17-
breakpoint="lg"
18-
columns={[
19-
'asset',
20-
'supplyBalance',
21-
'labeledSupplyApy',
22-
'borrowBalance',
23-
'labeledBorrowApy',
24-
'liquidity',
25-
]}
26-
initialOrder={{
27-
orderBy: 'labeledSupplyApy',
28-
orderDirection: 'desc',
29-
}}
30-
header={
31-
pool.eModeGroups.length > 0 && (
32-
<EModeBanner
33-
className="lg:mt-4"
34-
poolComptrollerContractAddress={pool.comptrollerAddress}
35-
enabledEModeGroupName={pool.userEModeGroup?.name}
36-
/>
37-
)
38-
}
39-
/>
40-
</div>
41-
);
42-
};
14+
<MarketTable
15+
pools={[pool]}
16+
breakpoint="lg"
17+
columns={[
18+
'asset',
19+
'supplyBalance',
20+
'labeledSupplyApy',
21+
'borrowBalance',
22+
'labeledBorrowApy',
23+
'liquidity',
24+
]}
25+
initialOrder={{
26+
orderBy: 'labeledSupplyApy',
27+
orderDirection: 'desc',
28+
}}
29+
header={
30+
pool.eModeGroups.length > 0 && (
31+
<EModeBanner
32+
className="lg:mt-4"
33+
poolComptrollerContractAddress={pool.comptrollerAddress}
34+
enabledEModeGroupName={pool.userEModeGroup?.name}
35+
/>
36+
)
37+
}
38+
/>
39+
</div>
40+
);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export const getHypotheticalAssetValues = ({
2+
userSupplyBalanceCents,
3+
userBorrowBalanceCents,
4+
isBorrowable,
5+
isCollateralOfUser,
6+
collateralFactor,
7+
liquidationThresholdPercentage,
8+
}: {
9+
userSupplyBalanceCents: number;
10+
userBorrowBalanceCents: number;
11+
isBorrowable: boolean;
12+
isCollateralOfUser: boolean;
13+
collateralFactor: number;
14+
liquidationThresholdPercentage: number;
15+
}) => {
16+
let isBlocking = false;
17+
let liquidationThresholdCents = 0;
18+
let borrowLimitCents = 0;
19+
let borrowBalanceCents = 0;
20+
21+
if (!isBorrowable && userBorrowBalanceCents > 0) {
22+
isBlocking = true;
23+
}
24+
25+
if (isBorrowable) {
26+
borrowBalanceCents += userBorrowBalanceCents;
27+
}
28+
29+
if (!!collateralFactor && !!liquidationThresholdPercentage && isCollateralOfUser) {
30+
borrowLimitCents += userSupplyBalanceCents * collateralFactor;
31+
32+
liquidationThresholdCents += (userSupplyBalanceCents * liquidationThresholdPercentage) / 100;
33+
}
34+
35+
return {
36+
isBlocking,
37+
liquidationThresholdCents,
38+
borrowLimitCents,
39+
borrowBalanceCents,
40+
};
41+
};

0 commit comments

Comments
 (0)