Skip to content

Commit 47047e8

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

File tree

23 files changed

+589
-175
lines changed

23 files changed

+589
-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/useGetAsset/__snapshots__/index.spec.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ exports[`useGetAsset > returns the correct asset 1`] = `
3737
"disabledTokenActions": [],
3838
"exchangeRateVTokens": "49.589181233",
3939
"isBorrowable": true,
40+
"isBorrowableByUser": true,
4041
"isCollateralOfUser": true,
4142
"liquidationThresholdPercentage": 50,
4243
"liquidityCents": "8036465875",

apps/evm/src/clients/api/queries/useGetPool/__snapshots__/index.spec.tsx.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ exports[`useGetPool > returns the correct asset 1`] = `
3939
"disabledTokenActions": [],
4040
"exchangeRateVTokens": "49.589181233",
4141
"isBorrowable": true,
42+
"isBorrowableByUser": true,
4243
"isCollateralOfUser": true,
4344
"liquidationThresholdPercentage": 50,
4445
"liquidityCents": "8036465875",
@@ -151,6 +152,7 @@ exports[`useGetPool > returns the correct asset 1`] = `
151152
],
152153
"exchangeRateVTokens": "1",
153154
"isBorrowable": false,
155+
"isBorrowableByUser": false,
154156
"isCollateralOfUser": false,
155157
"liquidationThresholdPercentage": 80,
156158
"liquidityCents": "1702951959",
@@ -278,6 +280,7 @@ exports[`useGetPool > returns the correct asset 1`] = `
278280
],
279281
"exchangeRateVTokens": "0.981982",
280282
"isBorrowable": true,
283+
"isBorrowableByUser": true,
281284
"isCollateralOfUser": false,
282285
"liquidationThresholdPercentage": 80,
283286
"liquidityCents": "5534102886",
@@ -397,6 +400,7 @@ exports[`useGetPool > returns the correct asset 1`] = `
397400
],
398401
"exchangeRateVTokens": "1.000003",
399402
"isBorrowable": true,
403+
"isBorrowableByUser": true,
400404
"isCollateralOfUser": false,
401405
"liquidationThresholdPercentage": 80,
402406
"liquidityCents": "3654492935",

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

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

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

Lines changed: 42 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 42 additions & 0 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) => {

0 commit comments

Comments
 (0)