diff --git a/pages/_app.page.tsx b/pages/_app.page.tsx
index 9e9c15c364..3a4dad47f9 100644
--- a/pages/_app.page.tsx
+++ b/pages/_app.page.tsx
@@ -17,7 +17,6 @@ import { TransactionEventHandler } from 'src/components/TransactionEventHandler'
import { GasStationProvider } from 'src/components/transactions/GasStation/GasStationProvider';
import { AppDataProvider } from 'src/hooks/app-data-provider/useAppDataProvider';
import { ModalContextProvider } from 'src/hooks/useModal';
-import { PermissionProvider } from 'src/hooks/usePermissions';
import { Web3ContextProvider } from 'src/libs/web3-data-provider/Web3Provider';
import { useRootStore } from 'src/store/root';
import { SharedDependenciesProvider } from 'src/ui-config/SharedDependenciesProvider';
@@ -139,31 +138,29 @@ export default function MyApp(props: MyAppProps) {
-
-
-
-
-
- {getLayout()}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ {getLayout()}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pages/index.page.tsx b/pages/index.page.tsx
index d7bb8439c6..f934df8fbd 100644
--- a/pages/index.page.tsx
+++ b/pages/index.page.tsx
@@ -3,7 +3,6 @@ import { Box, Typography } from '@mui/material';
import { useEffect, useState } from 'react';
import StyledToggleButton from 'src/components/StyledToggleButton';
import StyledToggleButtonGroup from 'src/components/StyledToggleButtonGroup';
-import { usePermissions } from 'src/hooks/usePermissions';
import { useProtocolDataContext } from 'src/hooks/useProtocolDataContext';
import { useRootStore } from 'src/store/root';
@@ -17,7 +16,6 @@ import { DashboardTopPanel } from '../src/modules/dashboard/DashboardTopPanel';
export default function Home() {
const { currentAccount, loading: web3Loading } = useWeb3Context();
const { currentMarket } = useProtocolDataContext();
- const { isPermissionsLoading } = usePermissions();
const trackEvent = useRootStore((store) => store.trackEvent);
const [mode, setMode] = useState<'supply' | 'borrow' | ''>('supply');
@@ -33,7 +31,7 @@ export default function Home() {
- {currentAccount && !isPermissionsLoading && (
+ {currentAccount && (
)}
- {currentAccount && !isPermissionsLoading ? (
+ {currentAccount ? (
) : (
diff --git a/pages/v3-migration.page.tsx b/pages/v3-migration.page.tsx
index 988093d268..e0ecce54ab 100644
--- a/pages/v3-migration.page.tsx
+++ b/pages/v3-migration.page.tsx
@@ -1,14 +1,15 @@
import { Trans } from '@lingui/macro';
-import { Box, Divider, useMediaQuery, useTheme } from '@mui/material';
+import { Box } from '@mui/material';
import dynamic from 'next/dynamic';
-import { useEffect, useMemo } from 'react';
+import { useRouter } from 'next/router';
+import { useEffect, useState } from 'react';
import { ConnectWalletPaper } from 'src/components/ConnectWalletPaper';
import { ContentContainer } from 'src/components/ContentContainer';
+import { getMarketInfoById } from 'src/components/MarketSwitcher';
import { useUserMigrationReserves } from 'src/hooks/migration/useUserMigrationReserves';
import { useUserSummaryAfterMigration } from 'src/hooks/migration/useUserSummaryAfterMigration';
import { useUserPoolReservesHumanized } from 'src/hooks/pool/useUserPoolReserves';
import { useUserSummaryAndIncentives } from 'src/hooks/pool/useUserSummaryAndIncentives';
-import { usePermissions } from 'src/hooks/usePermissions';
import { MainLayout } from 'src/layouts/MainLayout';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { DashboardContentNoData } from 'src/modules/dashboard/DashboardContentNoData';
@@ -20,6 +21,12 @@ import { MigrationLists } from 'src/modules/migration/MigrationLists';
import { MigrationTopPanel } from 'src/modules/migration/MigrationTopPanel';
import { selectCurrentChainIdV3MarketData } from 'src/store/poolSelectors';
import { useRootStore } from 'src/store/root';
+import {
+ CustomMarket,
+ getNetworkConfig,
+ MarketDataType,
+ marketsData,
+} from 'src/utils/marketsAndNetworksConfig';
const MigrateV3Modal = dynamic(() =>
import('src/components/transactions/MigrateV3/MigrateV3Modal').then(
@@ -27,11 +34,38 @@ const MigrateV3Modal = dynamic(() =>
)
);
+const AAVE_MARKETS_TO_MIGRATE = Object.keys(marketsData)
+ .map((key) => {
+ const market = marketsData[key];
+ return {
+ ...market,
+ };
+ })
+ .filter((market) => market.addresses.V3_MIGRATOR);
+
+const selectableMarkets = [
+ {
+ title: 'Aave V2 Markets',
+ markets: AAVE_MARKETS_TO_MIGRATE,
+ },
+];
+
export default function V3Migration() {
const { currentAccount, loading: web3Loading } = useWeb3Context();
- const currentChainId = useRootStore((store) => store.currentChainId);
- const currentNetworkConfig = useRootStore((store) => store.currentNetworkConfig);
- const currentMarketData = useRootStore((store) => store.currentMarketData);
+ const router = useRouter();
+ const [fromMarketData, setFromMarketData] = useState(() => {
+ if (router.query.market) {
+ const { market } = getMarketInfoById(router.query.market as CustomMarket);
+ const migrationMarket = AAVE_MARKETS_TO_MIGRATE.find(
+ (migrationMarket) =>
+ migrationMarket.isFork === market.isFork && migrationMarket.chainId === market.chainId
+ );
+ if (migrationMarket) {
+ return market;
+ }
+ }
+ return AAVE_MARKETS_TO_MIGRATE[0];
+ });
const {
selectAllSupply,
selectAllBorrow,
@@ -41,29 +75,22 @@ export default function V3Migration() {
selectedMigrationBorrowAssets: selectedBorrowAssets,
resetMigrationSelectedAssets,
enforceAsCollateral,
- getMigrationExceptionSupplyBalances,
} = useRootStore();
- const { isPermissionsLoading } = usePermissions();
- const theme = useTheme();
- const downToSM = useMediaQuery(theme.breakpoints.down('sm'));
-
- const toMarketData = selectCurrentChainIdV3MarketData(currentChainId, currentNetworkConfig);
- const fromMarketData = currentMarketData;
+ const toMarketData = selectCurrentChainIdV3MarketData(
+ fromMarketData.chainId,
+ getNetworkConfig(fromMarketData.chainId)
+ );
const { data: userMigrationReserves, isLoading: userMigrationReservesLoading } =
- useUserMigrationReserves(currentMarketData, toMarketData);
+ useUserMigrationReserves(fromMarketData, toMarketData);
- const supplyReserves = useMemo(
- () => userMigrationReserves?.supplyReserves || [],
- [userMigrationReserves]
- );
+ const supplyReserves = userMigrationReserves?.supplyReserves || [];
const borrowReserves = userMigrationReserves?.borrowReserves || [];
const isolatedReserveV3 = userMigrationReserves?.isolatedReserveV3;
const { data: fromUserSummaryAndIncentives, isLoading: fromUserSummaryAndIncentivesLoading } =
useUserSummaryAndIncentives(fromMarketData);
- const fromHealthFactor = fromUserSummaryAndIncentives?.healthFactor || '0';
const { data: toUserReservesData, isLoading: toUserReservesDataLoading } =
useUserPoolReservesHumanized(toMarketData);
@@ -81,12 +108,6 @@ export default function V3Migration() {
toUserSummaryForMigrationLoading ||
userSummaryAfterMigrationLoading;
- useEffect(() => {
- if (getMigrationExceptionSupplyBalances && supplyReserves.length > 0) {
- getMigrationExceptionSupplyBalances(supplyReserves);
- }
- }, [getMigrationExceptionSupplyBalances, supplyReserves]);
-
useEffect(() => {
if (resetMigrationSelectedAssets) {
resetMigrationSelectedAssets();
@@ -108,115 +129,129 @@ export default function V3Migration() {
};
const userControlledCollateral =
- Object.keys(selectedSupplyAssets).length > 1 &&
+ selectedSupplyAssets.length > 1 &&
toUserSummaryForMigration &&
toUserSummaryForMigration.totalCollateralMarketReferenceCurrency == '0';
+ const changeFromMarketData = (marketData: MarketDataType) => {
+ resetMigrationSelectedAssets();
+ setFromMarketData(marketData);
+ };
+
+ const bottomPanelProps = fromUserSummaryAndIncentives &&
+ toUserSummaryForMigration && {
+ fromUserSummaryBeforeMigration: fromUserSummaryAndIncentives,
+ toUserSummaryBeforeMigration: toUserSummaryForMigration,
+ };
+
return (
<>
- {currentAccount && !isPermissionsLoading ? (
+ {currentAccount ? (
- 0}
- isBorrowPositionsAvailable={borrowReserves.length > 0}
- onSelectAllSupplies={handleToggleAllSupply}
- onSelectAllBorrows={handleToggleAllBorrow}
- emodeCategoryId={toUserEModeCategoryId}
- isolatedReserveV3={isolatedReserveV3}
- supplyReserves={supplyReserves}
- borrowReserves={borrowReserves}
- suppliesPositions={
- <>
- {loading ? (
- <>
-
-
- >
- ) : supplyReserves.length > 0 ? (
- supplyReserves.map((reserve) => (
-
- selectedAsset.underlyingAsset == reserve.underlyingAsset
- ) >= 0
- }
- enableAsCollateral={() =>
- enabledAsCollateral(reserve.canBeEnforced, reserve.underlyingAsset)
- }
- userControlledCollateral={userControlledCollateral}
- canBeEnforced={
- toUserSummaryForMigration &&
- toUserSummaryForMigration.totalCollateralMarketReferenceCurrency == '0' &&
- reserve.canBeEnforced
- }
- userReserve={reserve}
- amount={reserve.underlyingBalance}
- amountInUSD={reserve.underlyingBalanceUSD}
- onCheckboxClick={() => {
- toggleSelectedSupplyPosition(reserve.underlyingAsset);
- }}
- enabledAsCollateral={reserve.usageAsCollateralEnabledOnUserV3}
- isIsolated={reserve.isolatedOnV3}
- enteringIsolation={isolatedReserveV3?.enteringIsolationMode || false}
- v3Rates={reserve.v3Rates}
- disabled={reserve.migrationDisabled}
- isSupplyList
- />
- ))
- ) : (
-
- Nothing supplied yet} />
-
- )}
- >
- }
- borrowsPositions={
- <>
- {loading ? (
- <>
-
-
- >
- ) : borrowReserves.length > 0 ? (
- borrowReserves.map((reserve) => (
-
- ))
- ) : (
-
- Nothing borrowed yet} />
-
- )}
- >
- }
- />
-
- {!downToSM && }
-
- {userSummaryAfterMigration && (
+
+ 0}
+ isBorrowPositionsAvailable={borrowReserves.length > 0}
+ onSelectAllSupplies={handleToggleAllSupply}
+ onSelectAllBorrows={handleToggleAllBorrow}
+ emodeCategoryId={toUserEModeCategoryId}
+ isolatedReserveV3={isolatedReserveV3}
+ supplyReserves={supplyReserves}
+ borrowReserves={borrowReserves}
+ suppliesPositions={
+ <>
+ {loading ? (
+ <>
+
+
+ >
+ ) : supplyReserves.length > 0 ? (
+ supplyReserves.map((reserve) => (
+
+ selectedAsset.underlyingAsset == reserve.underlyingAsset
+ ) >= 0
+ }
+ enableAsCollateral={() =>
+ enabledAsCollateral(reserve.canBeEnforced, reserve.underlyingAsset)
+ }
+ userControlledCollateral={userControlledCollateral}
+ canBeEnforced={
+ toUserSummaryForMigration &&
+ toUserSummaryForMigration.totalCollateralMarketReferenceCurrency == '0' &&
+ reserve.canBeEnforced
+ }
+ userReserve={reserve}
+ amount={reserve.underlyingBalance}
+ amountInUSD={reserve.underlyingBalanceUSD}
+ onCheckboxClick={() => {
+ toggleSelectedSupplyPosition(reserve.underlyingAsset);
+ }}
+ enabledAsCollateral={reserve.usageAsCollateralEnabledOnUserV3}
+ isIsolated={reserve.isolatedOnV3}
+ enteringIsolation={isolatedReserveV3?.enteringIsolationMode || false}
+ v3Rates={reserve.v3Rates}
+ disabled={reserve.migrationDisabled}
+ isSupplyList
+ />
+ ))
+ ) : (
+
+ Nothing supplied yet} />
+
+ )}
+ >
+ }
+ borrowsPositions={
+ <>
+ {loading ? (
+ <>
+
+
+ >
+ ) : borrowReserves.length > 0 ? (
+ borrowReserves.map((reserve) => (
+
+ ))
+ ) : (
+
+ Nothing borrowed yet} />
+
+ )}
+ >
+ }
/>
- )}
+
) : (
{
const [isCollapse, setIsCollapse] = useState(
localStorageName ? localStorage.getItem(localStorageName) === 'true' : false
@@ -88,10 +90,12 @@ export const ListWrapper = ({
return (
({
+ sx={{
mt: withTopMargin ? 4 : 0,
- border: `1px solid ${theme.palette.divider}`,
- })}
+ border: 1,
+ borderColor: 'divider',
+ ...paperSx,
+ }}
>
`/v3-migration/?market=${marketName}`,
dynamicRenderedProposal: (proposalId: number) =>
`/governance/v3/proposal?proposalId=${proposalId}`,
reserveOverview: (underlyingAsset: string, marketName: CustomMarket) =>
diff --git a/src/components/transactions/Borrow/BorrowModal.tsx b/src/components/transactions/Borrow/BorrowModal.tsx
index 1d8caa4135..119dd25448 100644
--- a/src/components/transactions/Borrow/BorrowModal.tsx
+++ b/src/components/transactions/Borrow/BorrowModal.tsx
@@ -1,4 +1,3 @@
-import { PERMISSION } from '@aave/contract-helpers';
import { Trans } from '@lingui/macro';
import React, { useState } from 'react';
import { UserAuthenticated } from 'src/components/UserAuthenticated';
@@ -38,7 +37,6 @@ export const BorrowModal = () => {
title={Borrow}
underlyingAsset={args.underlyingAsset}
keepWrappedSymbol={!borrowUnWrapped}
- requiredPermission={PERMISSION.BORROWER}
>
{(params) => (
diff --git a/src/components/transactions/FlowCommons/ModalWrapper.tsx b/src/components/transactions/FlowCommons/ModalWrapper.tsx
index fe2608d2a2..21beff9f41 100644
--- a/src/components/transactions/FlowCommons/ModalWrapper.tsx
+++ b/src/components/transactions/FlowCommons/ModalWrapper.tsx
@@ -1,4 +1,4 @@
-import { API_ETH_MOCK_ADDRESS, PERMISSION } from '@aave/contract-helpers';
+import { API_ETH_MOCK_ADDRESS } from '@aave/contract-helpers';
import React from 'react';
import { ReactElement } from 'react-markdown/lib/react-markdown';
import {
@@ -10,10 +10,9 @@ import { useWalletBalances } from 'src/hooks/app-data-provider/useWalletBalances
import { AssetCapsProvider } from 'src/hooks/useAssetCaps';
import { useIsWrongNetwork } from 'src/hooks/useIsWrongNetwork';
import { useModalContext } from 'src/hooks/useModal';
-import { usePermissions } from 'src/hooks/usePermissions';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { useRootStore } from 'src/store/root';
-import { getNetworkConfig, isFeatureEnabled } from 'src/utils/marketsAndNetworksConfig';
+import { getNetworkConfig } from 'src/utils/marketsAndNetworksConfig';
import { GENERAL } from 'src/utils/mixPanelEvents';
import { TxModalTitle } from '../FlowCommons/TxModalTitle';
@@ -38,7 +37,6 @@ export const ModalWrapper: React.FC<{
// if true wETH will stay wETH otherwise wETH will be returned as ETH
keepWrappedSymbol?: boolean;
hideTitleSymbol?: boolean;
- requiredPermission?: PERMISSION;
children: (props: ModalWrapperProps) => React.ReactNode;
action?: string;
}> = ({
@@ -47,7 +45,6 @@ export const ModalWrapper: React.FC<{
children,
requiredChainId: _requiredChainId,
title,
- requiredPermission,
keepWrappedSymbol,
}) => {
const { readOnlyModeAddress } = useWeb3Context();
@@ -56,7 +53,6 @@ export const ModalWrapper: React.FC<{
const { walletBalances } = useWalletBalances(currentMarketData);
const { user, reserves } = useAppDataContext();
const { txError, mainTxState } = useModalContext();
- const { permissions } = usePermissions();
const { isWrongNetwork, requiredChainId } = useIsWrongNetwork(_requiredChainId);
@@ -64,15 +60,6 @@ export const ModalWrapper: React.FC<{
return ;
}
- if (
- requiredPermission &&
- isFeatureEnabled.permissions(currentMarketData) &&
- !permissions.includes(requiredPermission) &&
- currentMarketData.permissionComponent
- ) {
- return <>{currentMarketData.permissionComponent}>;
- }
-
const poolReserve = reserves.find((reserve) => {
if (underlyingAsset.toLowerCase() === API_ETH_MOCK_ADDRESS.toLowerCase())
return reserve.isWrappedBaseAsset;
diff --git a/src/components/transactions/MigrateV3/MigrateV3ModalContent.tsx b/src/components/transactions/MigrateV3/MigrateV3ModalContent.tsx
index e081a9d86f..e1d3b25d2f 100644
--- a/src/components/transactions/MigrateV3/MigrateV3ModalContent.tsx
+++ b/src/components/transactions/MigrateV3/MigrateV3ModalContent.tsx
@@ -32,6 +32,15 @@ export const MigrateV3ModalContent = ({
toUserSummaryForMigration,
userMigrationReserves,
}: MigrationV3ModalContentProps) => {
+ const currentChainId = useRootStore((store) => store.currentChainId);
+ const setCurrentMarket = useRootStore((store) => store.setCurrentMarket);
+ const currentMarket = useRootStore((store) => store.currentMarket);
+
+ const { gasLimit, mainTxState: migrateTxState, txError, closeWithCb } = useModalContext();
+ const { chainId: connectedChainId, readOnlyModeAddress } = useWeb3Context();
+ const router = useRouter();
+ const networkConfig = getNetworkConfig(currentChainId);
+
const { supplyPositions, borrowPositions } = useRootStore(
useCallback(
(state) => ({
@@ -50,15 +59,6 @@ export const MigrateV3ModalContent = ({
)
);
- const currentChainId = useRootStore((store) => store.currentChainId);
- const setCurrentMarket = useRootStore((store) => store.setCurrentMarket);
- const currentMarket = useRootStore((store) => store.currentMarket);
-
- const { gasLimit, mainTxState: migrateTxState, txError } = useModalContext();
- const { chainId: connectedChainId, readOnlyModeAddress } = useWeb3Context();
- const router = useRouter();
- const networkConfig = getNetworkConfig(currentChainId);
-
const supplyAssets = supplyPositions.map((supplyAsset) => {
return {
underlyingAsset: supplyAsset.underlyingAsset,
@@ -90,11 +90,11 @@ export const MigrateV3ModalContent = ({
return ;
}
- const handleRoute = () => {
- if (currentMarket === CustomMarket.proto_polygon) {
+ const handleRoute = (market: CustomMarket) => {
+ if (market === CustomMarket.proto_polygon) {
setCurrentMarket('proto_polygon_v3' as CustomMarket);
router.push(`/?marketName=${CustomMarket.proto_polygon_v3}`);
- } else if (currentMarket === CustomMarket.proto_avalanche) {
+ } else if (market === CustomMarket.proto_avalanche) {
setCurrentMarket('proto_avalanche_v3' as CustomMarket);
router.push(`/?marketName=${CustomMarket.proto_avalanche_v3}`);
} else {
@@ -103,12 +103,16 @@ export const MigrateV3ModalContent = ({
}
};
+ const handleGoToDashboard = () => {
+ closeWithCb(() => handleRoute(currentMarket));
+ };
+
if (migrateTxState.success) {
return (
-
diff --git a/src/components/transactions/Repay/RepayModal.tsx b/src/components/transactions/Repay/RepayModal.tsx
index b5f69f4b72..1b7595a723 100644
--- a/src/components/transactions/Repay/RepayModal.tsx
+++ b/src/components/transactions/Repay/RepayModal.tsx
@@ -1,4 +1,4 @@
-import { InterestRate, PERMISSION } from '@aave/contract-helpers';
+import { InterestRate } from '@aave/contract-helpers';
import { Trans } from '@lingui/macro';
import React, { useState } from 'react';
import { UserAuthenticated } from 'src/components/UserAuthenticated';
@@ -45,11 +45,7 @@ export const RepayModal = () => {
return (
- Repay}
- underlyingAsset={args.underlyingAsset}
- requiredPermission={PERMISSION.BORROWER}
- >
+ Repay} underlyingAsset={args.underlyingAsset}>
{(params) => {
return (
diff --git a/src/components/transactions/Supply/SupplyModal.tsx b/src/components/transactions/Supply/SupplyModal.tsx
index 1a360545ea..9f6e8b6a06 100644
--- a/src/components/transactions/Supply/SupplyModal.tsx
+++ b/src/components/transactions/Supply/SupplyModal.tsx
@@ -1,4 +1,3 @@
-import { PERMISSION } from '@aave/contract-helpers';
import { Trans } from '@lingui/macro';
import React from 'react';
import { UserAuthenticated } from 'src/components/UserAuthenticated';
@@ -19,7 +18,6 @@ export const SupplyModal = () => {
action="supply"
title={Supply}
underlyingAsset={args.underlyingAsset}
- requiredPermission={PERMISSION.DEPOSITOR}
>
{(params) => (
diff --git a/src/components/transactions/Withdraw/WithdrawModal.tsx b/src/components/transactions/Withdraw/WithdrawModal.tsx
index 5bf6ce870d..ee6fdfe4f1 100644
--- a/src/components/transactions/Withdraw/WithdrawModal.tsx
+++ b/src/components/transactions/Withdraw/WithdrawModal.tsx
@@ -1,4 +1,3 @@
-import { PERMISSION } from '@aave/contract-helpers';
import { Trans } from '@lingui/macro';
import React, { useState } from 'react';
import { UserAuthenticated } from 'src/components/UserAuthenticated';
@@ -40,7 +39,6 @@ export const WithdrawModal = () => {
title={Withdraw}
underlyingAsset={args.underlyingAsset}
keepWrappedSymbol={!withdrawUnWrapped}
- requiredPermission={PERMISSION.DEPOSITOR}
>
{(params) => (
diff --git a/src/hooks/migration/useMigrationExceptionsSupplyBalance.ts b/src/hooks/migration/useMigrationExceptionsSupplyBalance.ts
new file mode 100644
index 0000000000..a1a984198c
--- /dev/null
+++ b/src/hooks/migration/useMigrationExceptionsSupplyBalance.ts
@@ -0,0 +1,30 @@
+import { useQuery } from '@tanstack/react-query';
+import { MigrationSupplyException } from 'src/store/v3MigrationSlice';
+import { MarketDataType } from 'src/ui-config/marketsConfig';
+import { queryKeysFactory } from 'src/ui-config/queries';
+import { useSharedDependencies } from 'src/ui-config/SharedDependenciesProvider';
+import invariant from 'tiny-invariant';
+
+export const useMigrationExceptionsSupplyBalance = (
+ fromMarketData: MarketDataType,
+ toMarketData: MarketDataType,
+ supplyExceptions?: MigrationSupplyException[]
+) => {
+ const { migrationService } = useSharedDependencies();
+ return useQuery({
+ queryKey: queryKeysFactory.migrationExceptions(
+ supplyExceptions || [],
+ fromMarketData,
+ toMarketData
+ ),
+ queryFn: () => {
+ invariant(supplyExceptions, 'Supply exceptions are required');
+ return migrationService.getMigrationExceptionSupplyBalances(
+ supplyExceptions,
+ fromMarketData,
+ toMarketData
+ );
+ },
+ enabled: !!supplyExceptions,
+ });
+};
diff --git a/src/hooks/migration/useUserMigrationReserves.ts b/src/hooks/migration/useUserMigrationReserves.ts
index 53d1485501..ef06c10454 100644
--- a/src/hooks/migration/useUserMigrationReserves.ts
+++ b/src/hooks/migration/useUserMigrationReserves.ts
@@ -32,6 +32,7 @@ import {
useUserSummaryAndIncentives,
} from '../pool/useUserSummaryAndIncentives';
import { combineQueries, SimplifiedUseQueryResult } from '../pool/utils';
+import { useMigrationExceptionsSupplyBalance } from './useMigrationExceptionsSupplyBalance';
export type SupplyMigrationReserve = ComputedUserReserve & {
usageAsCollateralEnabledOnUserV3: boolean;
@@ -62,7 +63,6 @@ const select = memoize(
toReservesIncentivesData: ReservesIncentiveDataHumanized[],
fromUserSummaryAndIncentives: UserSummaryAndIncentives,
migrationExceptions: Record,
- exceptionsBalancesLoading: boolean,
selectedMigrationSupplyAssets: MigrationSelectedAsset[]
): UserMigrationReserves => {
const { userReservesData: userReserveV3Data, ...v3ReservesUserSummary } =
@@ -89,13 +89,11 @@ const select = memoize(
const definitiveAssets = selectDefinitiveSupplyAssetForMigration(
selectedMigrationSupplyAssets,
migrationExceptions,
- exceptionsBalancesLoading,
v3ReservesMap
);
if (definitiveAssets.length > 0) {
const underlyingAssetAddress = selectMigrationUnderlyingAssetWithExceptions(
migrationExceptions,
- exceptionsBalancesLoading,
definitiveAssets[0]
);
const definitiveAsset = v3ReservesMap[underlyingAssetAddress];
@@ -119,7 +117,6 @@ const select = memoize(
let migrationDisabled: MigrationDisabled | undefined;
const underlyingAssetAddress = selectMigrationUnderlyingAssetWithExceptions(
migrationExceptions,
- exceptionsBalancesLoading,
userReserve
);
@@ -253,8 +250,18 @@ export const useUserMigrationReserves = (
const toReservesIncentivesDataQuery = usePoolReservesIncentivesHumanized(migrationTo);
const fromUserSummaryAndIncentives = useUserSummaryAndIncentives(migrationFrom);
- const migrationExceptions = useRootStore((store) => store.migrationExceptions);
- const exceptionsBalancesLoading = useRootStore((store) => store.exceptionsBalancesLoading);
+ const userReservesV2Data = fromUserSummaryAndIncentives.data?.userReservesData;
+
+ const supplyReserves = userReservesV2Data?.filter(
+ (userReserve) => userReserve.underlyingBalance !== '0'
+ );
+
+ const migrationsExceptionsQuery = useMigrationExceptionsSupplyBalance(
+ migrationFrom,
+ migrationTo,
+ supplyReserves
+ );
+
const selectedMigrationSupplyAssets = useRootStore(
(store) => store.selectedMigrationSupplyAssets
);
@@ -263,15 +270,15 @@ export const useUserMigrationReserves = (
toReservesData: ReservesDataHumanized,
toUserReservesData: UserReservesDataHumanized,
toReservesIncentivesData: ReservesIncentiveDataHumanized[],
- fromUserSummaryAndIncentives: UserSummaryAndIncentives
+ fromUserSummaryAndIncentives: UserSummaryAndIncentives,
+ migrationsExceptions: Record
) => {
return select(
toReservesData,
toUserReservesData,
toReservesIncentivesData,
fromUserSummaryAndIncentives,
- migrationExceptions,
- exceptionsBalancesLoading,
+ migrationsExceptions,
selectedMigrationSupplyAssets
);
};
@@ -282,6 +289,7 @@ export const useUserMigrationReserves = (
toUserReservesDataQuery,
toReservesIncentivesDataQuery,
fromUserSummaryAndIncentives,
+ migrationsExceptionsQuery,
] as const,
selector
);
diff --git a/src/hooks/migration/useUserSummaryAfterMigration.ts b/src/hooks/migration/useUserSummaryAfterMigration.ts
index ed41f1a505..684c9ee8a8 100644
--- a/src/hooks/migration/useUserSummaryAfterMigration.ts
+++ b/src/hooks/migration/useUserSummaryAfterMigration.ts
@@ -19,11 +19,22 @@ import {
} from 'src/store/v3MigrationSlice';
import { MarketDataType } from 'src/ui-config/marketsConfig';
-import { combineQueries } from '../pool/utils';
+import { combineQueries, SimplifiedUseQueryResult } from '../pool/utils';
+import { useMigrationExceptionsSupplyBalance } from './useMigrationExceptionsSupplyBalance';
import { usePoolReserve } from './usePoolReserve';
import { UserMigrationReserves, useUserMigrationReserves } from './useUserMigrationReserves';
import { UserSummaryForMigration, useUserSummaryForMigration } from './useUserSummaryForMigration';
+export interface UserSummaryAfterMigration {
+ fromUserSummaryAfterMigration: UserSummaryForMigration;
+ toUserSummaryAfterMigration: {
+ healthFactor: string;
+ currentLoanToValue: string;
+ totalCollateralMarketReferenceCurrency: string;
+ totalBorrowsMarketReferenceCurrency: string;
+ };
+}
+
const select = memoize(
(
userMigrationReserves: UserMigrationReserves,
@@ -200,11 +211,16 @@ const select = memoize(
export const useUserSummaryAfterMigration = (
fromMarket: MarketDataType,
toMarket: MarketDataType
-) => {
+): SimplifiedUseQueryResult => {
const userMigrationReservesQuery = useUserMigrationReserves(fromMarket, toMarket);
const toUserSummary = useUserSummaryForMigration(toMarket);
const fromPoolReserve = usePoolReserve(fromMarket);
const toPoolReserve = usePoolReserve(toMarket);
+ const migrationExceptionsQuery = useMigrationExceptionsSupplyBalance(
+ fromMarket,
+ toMarket,
+ userMigrationReservesQuery.data?.supplyReserves
+ );
const selectedMigrationBorrowAssets = useRootStore(
(store) => store.selectedMigrationBorrowAssets
@@ -212,13 +228,13 @@ export const useUserSummaryAfterMigration = (
const selectedMigrationSupplyAssets = useRootStore(
(store) => store.selectedMigrationSupplyAssets
);
- const migrationExceptions = useRootStore((store) => store.migrationExceptions);
const selector = (
userMigrationReserves: UserMigrationReserves,
fromPoolReserve: PoolReserve,
toPoolReserve: PoolReserve,
- toUserSummary: UserSummaryForMigration
+ toUserSummary: UserSummaryForMigration,
+ migrationExceptions: Record
) => {
return select(
userMigrationReserves,
@@ -232,7 +248,13 @@ export const useUserSummaryAfterMigration = (
};
return combineQueries(
- [userMigrationReservesQuery, fromPoolReserve, toPoolReserve, toUserSummary] as const,
+ [
+ userMigrationReservesQuery,
+ fromPoolReserve,
+ toPoolReserve,
+ toUserSummary,
+ migrationExceptionsQuery,
+ ] as const,
selector
);
};
diff --git a/src/hooks/useModal.tsx b/src/hooks/useModal.tsx
index 1258776e05..a2409ea26f 100644
--- a/src/hooks/useModal.tsx
+++ b/src/hooks/useModal.tsx
@@ -55,6 +55,8 @@ export type TxStateType = {
success?: boolean;
};
+type CallbackFn = () => void;
+
export interface ModalContextType {
openSupply: (
underlyingAsset: string,
@@ -112,6 +114,7 @@ export interface ModalContextType {
representatives: Array<{ chainId: ChainId; representative: string }>
) => void;
close: () => void;
+ closeWithCb: (callback: CallbackFn) => void;
type?: ModalType;
args: T;
mainTxState: TxStateType;
@@ -335,6 +338,10 @@ export const ModalContextProvider: React.FC = ({ children }) => {
setTxError(undefined);
setSwitchNetworkError(undefined);
},
+ closeWithCb: (callback) => {
+ close();
+ callback();
+ },
type,
args,
approvalTxState,
diff --git a/src/layouts/AppFooter.tsx b/src/layouts/AppFooter.tsx
index 69fa64beb2..ab98fcc6a1 100644
--- a/src/layouts/AppFooter.tsx
+++ b/src/layouts/AppFooter.tsx
@@ -80,7 +80,7 @@ export function AppFooter() {
},
},
{
- href: '',
+ href: '/',
label: Manage analytics,
key: 'Manage analytics',
onClick: (event: React.MouseEvent) => {
diff --git a/src/layouts/MobileMenu.tsx b/src/layouts/MobileMenu.tsx
index 93563bc473..74937ad5d2 100644
--- a/src/layouts/MobileMenu.tsx
+++ b/src/layouts/MobileMenu.tsx
@@ -82,6 +82,16 @@ export const MobileMenu = ({ open, setOpen, headerHeight }: MobileMenuProps) =>
Links}>
+ setOpen(false)}
+ >
+
+ Migrate to Aave V3
+
+
{moreNavigation.map((item, index) => (
diff --git a/src/layouts/MoreMenu.tsx b/src/layouts/MoreMenu.tsx
index 801349ebb3..c9e7fccee5 100644
--- a/src/layouts/MoreMenu.tsx
+++ b/src/layouts/MoreMenu.tsx
@@ -1,7 +1,7 @@
import { DotsHorizontalIcon } from '@heroicons/react/solid';
import { Trans } from '@lingui/macro';
import { useLingui } from '@lingui/react';
-import { Button, ListItemIcon, ListItemText, SvgIcon } from '@mui/material';
+import { Button, ListItemIcon, ListItemText, SvgIcon, Typography } from '@mui/material';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import React from 'react';
@@ -61,6 +61,11 @@ export function MoreMenu() {
onClose={handleClose}
keepMounted={true}
>
+
{moreNavigation.map((item, index) => (
);
};
diff --git a/src/modules/migration/MigrationList.tsx b/src/modules/migration/MigrationList.tsx
index 24ab1ca787..f9014bb5c9 100644
--- a/src/modules/migration/MigrationList.tsx
+++ b/src/modules/migration/MigrationList.tsx
@@ -83,9 +83,10 @@ export const MigrationList = ({
return (
-
+
{titleComponent}
{isolatedReserveV3 && !isolatedReserveV3.enteringIsolationMode && (
diff --git a/src/modules/migration/MigrationLists.tsx b/src/modules/migration/MigrationLists.tsx
index 179c103589..5181ec7977 100644
--- a/src/modules/migration/MigrationLists.tsx
+++ b/src/modules/migration/MigrationLists.tsx
@@ -1,5 +1,5 @@
import { Trans } from '@lingui/macro';
-import { Box } from '@mui/material';
+import { Paper, Typography } from '@mui/material';
import { ReactNode } from 'react';
import {
BorrowMigrationReserve,
@@ -53,20 +53,32 @@ export const MigrationLists = ({
computeSelections(borrowReserves, selectedBorrowAssets);
return (
-
+
+ Assets to migrate
+
Select v2 supplies to migrate}
+ titleComponent={Supplied assets}
emodeCategoryId={emodeCategoryId}
withCollateral
disabled={allSuppliesDisabled}
@@ -83,12 +95,12 @@ export const MigrationLists = ({
isAvailable={isBorrowPositionsAvailable}
withBorrow
disabled={allBorrowsDisabled}
- titleComponent={Select v2 borrows to migrate}
+ titleComponent={Borrowed assets}
numSelected={activeBorrowSelections.length || 0}
numAvailable={borrowReserves.length || 0}
>
{borrowsPositions}
-
+
);
};
diff --git a/src/modules/migration/MigrationMarketCard.tsx b/src/modules/migration/MigrationMarketCard.tsx
new file mode 100644
index 0000000000..24a8795387
--- /dev/null
+++ b/src/modules/migration/MigrationMarketCard.tsx
@@ -0,0 +1,168 @@
+import { ArrowNarrowRightIcon } from '@heroicons/react/solid';
+import { KeyboardArrowDown, KeyboardArrowUp } from '@mui/icons-material';
+import {
+ Avatar,
+ Badge,
+ Box,
+ Divider,
+ IconButton,
+ Menu,
+ MenuItem,
+ Skeleton,
+ SvgIcon,
+ Typography,
+} from '@mui/material';
+import { FC, useState } from 'react';
+import { HealthFactorNumber } from 'src/components/HealthFactorNumber';
+import { MarketDataType } from 'src/ui-config/marketsConfig';
+import { getNetworkConfig } from 'src/utils/marketsAndNetworksConfig';
+
+const formatMarketName = (market: MarketDataType) => {
+ return `Aave ${market.v3 ? 'V3' : 'V2'} - ${market.marketTitle}${market.isFork ? ' Fork' : ''}`;
+};
+
+type MigrationMarketCardProps = {
+ marketData: MarketDataType;
+ userSummaryAfterMigration?: {
+ healthFactor: string;
+ };
+ userSummaryBeforeMigration?: {
+ healthFactor: string;
+ };
+ selectableMarkets?: SelectableMarkets;
+ setFromMarketData?: (marketData: MarketDataType) => void;
+ loading?: boolean;
+};
+
+export type SelectableMarkets = Array<{
+ title: string;
+ markets: MarketDataType[];
+}>;
+
+export const MigrationMarketCard: FC = ({
+ marketData,
+ userSummaryAfterMigration,
+ userSummaryBeforeMigration,
+ selectableMarkets,
+ setFromMarketData,
+ loading,
+}) => {
+ const [anchorEl, setAnchorEl] = useState(null);
+ const open = Boolean(anchorEl);
+ const handleClick = (event: React.MouseEvent) => {
+ setAnchorEl(event.currentTarget);
+ };
+ const handleClose = () => {
+ setAnchorEl(null);
+ };
+ const handleSelectedMarket = (marketData: MarketDataType) => {
+ setFromMarketData && setFromMarketData(marketData);
+ setAnchorEl(null);
+ };
+ const networkConfig = getNetworkConfig(marketData.chainId);
+ return (
+
+
+ From
+
+
+
+ }
+ >
+
+
+
+ {formatMarketName(marketData)}
+
+ {selectableMarkets && setFromMarketData && (
+ <>
+
+ {open ? : }
+
+
+ >
+ )}
+
+
+
+ Health Factor
+
+
+ {!loading && userSummaryBeforeMigration ? (
+
+ ) : (
+
+ )}
+
+
+
+ {!loading && userSummaryAfterMigration ? (
+
+ ) : (
+
+ )}
+
+
+
+
+ );
+};
diff --git a/src/modules/migration/MigrationSelectionBox.tsx b/src/modules/migration/MigrationSelectionBox.tsx
index 6b31b06024..c5508a75e0 100644
--- a/src/modules/migration/MigrationSelectionBox.tsx
+++ b/src/modules/migration/MigrationSelectionBox.tsx
@@ -1,5 +1,5 @@
import { CheckIcon, MinusSmIcon } from '@heroicons/react/solid';
-import { Box, SvgIcon, Typography, useTheme } from '@mui/material';
+import { Box, SvgIcon, useTheme } from '@mui/material';
import { ListHeaderTitle } from 'src/components/lists/ListHeaderTitle';
interface MigrationSelectionBoxProps {
@@ -31,46 +31,42 @@ export const MigrationSelectionBox = ({
if (disabled) {
return (
-
-
-
+
);
}
return (
-
- {allSelected ? (
-
-
-
-
-
- ) : numSelected !== 0 ? (
-
-
-
-
-
- ) : (
-
- )}
-
+ {allSelected ? (
+
+
+
+
+
+ ) : numSelected !== 0 ? (
+
+
+
+
+
+ ) : (
+
+ )}
);
};
diff --git a/src/modules/migration/MigrationTopPanel.tsx b/src/modules/migration/MigrationTopPanel.tsx
index cf529b8a78..cc216f3117 100644
--- a/src/modules/migration/MigrationTopPanel.tsx
+++ b/src/modules/migration/MigrationTopPanel.tsx
@@ -3,18 +3,10 @@ import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackOutlined';
import { Box, Button, SvgIcon, useMediaQuery, useTheme } from '@mui/material';
import { useRouter } from 'next/router';
import { ROUTES } from 'src/components/primitives/Link';
-import { PageTitle } from 'src/components/TopInfoPanel/PageTitle';
import { TopInfoPanel } from 'src/components/TopInfoPanel/TopInfoPanel';
-import { getMarketHelpData, getMarketInfoById, MarketLogo } from '../../components/MarketSwitcher';
-import { useProtocolDataContext } from '../../hooks/useProtocolDataContext';
-
export const MigrationTopPanel = () => {
const router = useRouter();
- const { currentMarket } = useProtocolDataContext();
- const { market, network } = getMarketInfoById(currentMarket);
- const marketNaming = getMarketHelpData(market.marketTitle);
-
const theme = useTheme();
const downToSM = useMediaQuery(theme.breakpoints.down('sm'));
@@ -50,22 +42,6 @@ export const MigrationTopPanel = () => {
Go Back
-
-
-
- Migrate to{' '}
- {market.marketTitle === 'Ethereum AMM' ? 'Ethereum' : market.marketTitle} v3
- Market
-
-
- }
- />
}
/>
diff --git a/src/modules/reserve-overview/ReserveActions.tsx b/src/modules/reserve-overview/ReserveActions.tsx
index 7136a7c135..3e9e67e812 100644
--- a/src/modules/reserve-overview/ReserveActions.tsx
+++ b/src/modules/reserve-overview/ReserveActions.tsx
@@ -27,7 +27,6 @@ import {
} from 'src/hooks/app-data-provider/useAppDataProvider';
import { useWalletBalances } from 'src/hooks/app-data-provider/useWalletBalances';
import { useModalContext } from 'src/hooks/useModal';
-import { usePermissions } from 'src/hooks/usePermissions';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { BuyWithFiat } from 'src/modules/staking/BuyWithFiat';
import { useRootStore } from 'src/store/root';
@@ -65,7 +64,6 @@ export const ReserveActions = ({ reserve }: ReserveActionsProps) => {
const [selectedAsset, setSelectedAsset] = useState(reserve.symbol);
const { currentAccount, loading: loadingWeb3Context } = useWeb3Context();
- const { isPermissionsLoading } = usePermissions();
const { openBorrow, openSupply } = useModalContext();
const currentMarket = useRootStore((store) => store.currentMarket);
const currentNetworkConfig = useRootStore((store) => store.currentNetworkConfig);
@@ -132,7 +130,7 @@ export const ReserveActions = ({ reserve }: ReserveActionsProps) => {
reserve,
});
- if (!currentAccount && !isPermissionsLoading) {
+ if (!currentAccount) {
return ;
}
diff --git a/src/services/MigrationService.ts b/src/services/MigrationService.ts
new file mode 100644
index 0000000000..569248ed65
--- /dev/null
+++ b/src/services/MigrationService.ts
@@ -0,0 +1,67 @@
+import { Pool, V3MigrationHelperService } from '@aave/contract-helpers';
+import { Provider } from '@ethersproject/providers';
+import {
+ MIGRATION_ASSETS_EXCEPTIONS,
+ MigrationException,
+ MigrationSupplyException,
+} from 'src/store/v3MigrationSlice';
+import { MarketDataType } from 'src/ui-config/marketsConfig';
+import { getNetworkConfig } from 'src/utils/marketsAndNetworksConfig';
+import invariant from 'tiny-invariant';
+
+export class MigrationService {
+ constructor(private readonly getProvider: (chainId: number) => Provider) {}
+
+ private getMigrationService(fromMarketData: MarketDataType, toMarketData: MarketDataType) {
+ invariant(
+ fromMarketData.addresses.V3_MIGRATOR,
+ 'V3_MIGRATOR address is not defined in fromMarketData'
+ );
+ invariant(fromMarketData.chainId === toMarketData.chainId, 'ChainId mismatch');
+ const provider = this.getProvider(toMarketData.chainId);
+ const toPool = new Pool(provider, {
+ POOL: toMarketData.addresses.LENDING_POOL,
+ REPAY_WITH_COLLATERAL_ADAPTER: toMarketData.addresses.REPAY_WITH_COLLATERAL_ADAPTER,
+ SWAP_COLLATERAL_ADAPTER: toMarketData.addresses.SWAP_COLLATERAL_ADAPTER,
+ WETH_GATEWAY: toMarketData.addresses.WETH_GATEWAY,
+ L2_ENCODER: toMarketData.addresses.L2_ENCODER,
+ });
+ return new V3MigrationHelperService(provider, fromMarketData.addresses.V3_MIGRATOR, toPool);
+ }
+
+ async getMigrationExceptionSupplyBalances(
+ migrationSupplyException: MigrationSupplyException[],
+ fromMarketData: MarketDataType,
+ toMarketData: MarketDataType
+ ) {
+ const networkConfig = getNetworkConfig(fromMarketData.chainId);
+ const chainId = networkConfig.underlyingChainId || fromMarketData.chainId;
+ const exceptions = MIGRATION_ASSETS_EXCEPTIONS[chainId] || [];
+ const filteredSuppliesForExceptions = migrationSupplyException.filter(
+ (supply) =>
+ exceptions.indexOf(supply.underlyingAsset) >= 0 && supply.scaledATokenBalance !== '0'
+ );
+ const migrationExceptions: Record = {};
+ if (filteredSuppliesForExceptions.length !== 0) {
+ const migrationService = this.getMigrationService(fromMarketData, toMarketData);
+ const mappedSupplies = filteredSuppliesForExceptions.map(
+ ({ scaledATokenBalance, underlyingAsset }) => {
+ return migrationService.getMigrationSupply({
+ amount: scaledATokenBalance,
+ asset: underlyingAsset,
+ });
+ }
+ );
+ const result = await Promise.all(mappedSupplies);
+ result.forEach(([asset, amount], index) => {
+ const v2UnderlyingAsset = filteredSuppliesForExceptions[index].underlyingAsset;
+ migrationExceptions[v2UnderlyingAsset] = {
+ v2UnderlyingAsset,
+ v3UnderlyingAsset: asset.toLowerCase(),
+ amount: amount.toString(),
+ };
+ });
+ }
+ return migrationExceptions;
+ }
+}
diff --git a/src/store/v3MigrationSelectors.ts b/src/store/v3MigrationSelectors.ts
index b852fd7f8f..8e62d22222 100644
--- a/src/store/v3MigrationSelectors.ts
+++ b/src/store/v3MigrationSelectors.ts
@@ -132,7 +132,6 @@ export const selectSplittedBorrowsForMigration = (userReserves: FormattedUserRes
export const selectDefinitiveSupplyAssetForMigration = (
selectedMigrationSupplyAssets: MigrationSelectedAsset[],
migrationExceptions: Record,
- exceptionsBalancesLoading: boolean,
userReservesV3Map: Record<
string,
ComputedUserReserve
@@ -149,13 +148,11 @@ export const selectDefinitiveSupplyAssetForMigration = (
const nonIsolatedAssets = selectedMigrationSupplyAssets.filter((supplyAsset) => {
const underlyingAssetAddress = selectMigrationUnderlyingAssetWithExceptions(
migrationExceptions,
- exceptionsBalancesLoading,
supplyAsset
);
const v3UserReserve = userReservesV3Map[underlyingAssetAddress];
const v3ReserveBalanceWithExceptions = selectMigrationAssetBalanceWithExceptions(
migrationExceptions,
- exceptionsBalancesLoading,
v3UserReserve
);
if (v3UserReserve) {
@@ -172,13 +169,11 @@ export const selectDefinitiveSupplyAssetForMigration = (
const isolatedAssets = selectedMigrationSupplyAssets.filter((supplyAsset) => {
const underlyingAssetAddress = selectMigrationUnderlyingAssetWithExceptions(
migrationExceptions,
- exceptionsBalancesLoading,
supplyAsset
);
const v3UserReserve = userReservesV3Map[underlyingAssetAddress];
const v3ReserveBalanceWithExceptions = selectMigrationAssetBalanceWithExceptions(
migrationExceptions,
- exceptionsBalancesLoading,
v3UserReserve
);
return v3ReserveBalanceWithExceptions == '0' && v3UserReserve.reserve.isIsolated;
@@ -212,13 +207,12 @@ export enum MigrationDisabled {
export const selectMigrationUnderlyingAssetWithExceptions = (
migrationExceptions: Record,
- exceptionsBalancesLoading: boolean,
reserve: {
underlyingAsset: string;
}
): string => {
const defaultUnderlyingAsset = reserve?.underlyingAsset;
- if (!exceptionsBalancesLoading && migrationExceptions[defaultUnderlyingAsset]) {
+ if (migrationExceptions[defaultUnderlyingAsset]) {
return migrationExceptions[defaultUnderlyingAsset].v3UnderlyingAsset;
}
return defaultUnderlyingAsset;
@@ -238,7 +232,6 @@ export const selectMigrationUnderluingAssetWithExceptionsByV3Key = (
export const selectMigrationAssetBalanceWithExceptions = (
migrationExceptions: Record,
- exceptionsBalancesLoading: boolean,
reserve: {
underlyingAsset: string;
underlyingBalance: string;
@@ -246,15 +239,11 @@ export const selectMigrationAssetBalanceWithExceptions = (
) => {
const underlyingAssetAddress = selectMigrationUnderlyingAssetWithExceptions(
migrationExceptions,
- exceptionsBalancesLoading,
reserve
);
- if (!exceptionsBalancesLoading) {
- const exceptionAsset = migrationExceptions[underlyingAssetAddress];
- if (exceptionAsset) {
- return exceptionAsset.amount;
- }
- return reserve.underlyingBalance;
+ const exceptionAsset = migrationExceptions[underlyingAssetAddress];
+ if (exceptionAsset) {
+ return exceptionAsset.amount;
}
return reserve.underlyingBalance;
};
diff --git a/src/store/v3MigrationSlice.ts b/src/store/v3MigrationSlice.ts
index 1087835191..4f128dda43 100644
--- a/src/store/v3MigrationSlice.ts
+++ b/src/store/v3MigrationSlice.ts
@@ -43,12 +43,12 @@ export type MigrationSelectedBorrowAsset = {
interestRate: InterestRate;
};
-type MigrationSupplyException = {
+export type MigrationSupplyException = {
underlyingAsset: string;
scaledATokenBalance: string;
};
-const MIGRATION_ASSETS_EXCEPTIONS: Record = {
+export const MIGRATION_ASSETS_EXCEPTIONS: Record = {
[1]: ['0xae7ab96520de3a18e5e111b5eaab095312d7fe84'],
};
@@ -60,11 +60,9 @@ export type MigrationException = {
export type V3MigrationSlice = {
//STATE
- exceptionsBalancesLoading: boolean;
selectedMigrationSupplyAssets: MigrationSelectedAsset[];
selectedMigrationBorrowAssets: MigrationSelectedBorrowAsset[];
migrationServiceInstances: Record;
- migrationExceptions: Record;
timestamp: number;
approvalPermitsForMigrationAssets: Array;
// ACTIONS
@@ -95,7 +93,6 @@ export type V3MigrationSlice = {
enforceAsCollateral: (underlyingAsset: string) => void;
selectAllBorrow: (borrowReserves: BorrowMigrationReserve[]) => void;
selectAllSupply: (supplyReserves: SupplyMigrationReserve[]) => void;
- getMigrationExceptionSupplyBalances: (supplies: MigrationSupplyException[]) => void;
};
export const createV3MigrationSlice: StateCreator<
@@ -105,11 +102,9 @@ export const createV3MigrationSlice: StateCreator<
V3MigrationSlice
> = (set, get) => {
return {
- exceptionsBalancesLoading: false,
selectedMigrationSupplyAssets: [],
selectedMigrationBorrowAssets: [],
migrationServiceInstances: {},
- migrationExceptions: {},
timestamp: 0,
approvalPermitsForMigrationAssets: [],
generatePermitPayloadForMigrationSupplyAsset: async ({ amount, underlyingAsset, deadline }) => {
@@ -384,46 +379,5 @@ export const createV3MigrationSlice: StateCreator<
});
return newMigratorInstance;
},
- getMigrationExceptionSupplyBalances: async (supplies) => {
- const chainId = get().currentNetworkConfig.underlyingChainId || get().currentChainId;
- const currentChainIdExceptions = MIGRATION_ASSETS_EXCEPTIONS[chainId];
- if (
- currentChainIdExceptions &&
- currentChainIdExceptions.length > 0 &&
- !get().exceptionsBalancesLoading &&
- Object.keys(get().migrationExceptions).length == 0
- ) {
- set({ exceptionsBalancesLoading: true });
- const filteredSuppliesForExceptions = supplies.filter(
- (supply) =>
- currentChainIdExceptions.indexOf(supply.underlyingAsset) >= 0 &&
- supply.scaledATokenBalance !== '0'
- );
- if (filteredSuppliesForExceptions.length > 0) {
- set({ exceptionsBalancesLoading: true });
- const mappedSupplies = filteredSuppliesForExceptions.map(
- ({ scaledATokenBalance, underlyingAsset }) => {
- return get()
- .getMigrationServiceInstance()
- .getMigrationSupply({ amount: scaledATokenBalance, asset: underlyingAsset });
- }
- );
- const supplyBalancesV3 = await Promise.all(mappedSupplies);
- set((state) =>
- produce(state, (draft) => {
- supplyBalancesV3.forEach(([asset, amount], index) => {
- const v2UnderlyingAsset = filteredSuppliesForExceptions[index].underlyingAsset;
- draft.migrationExceptions[v2UnderlyingAsset] = {
- v2UnderlyingAsset,
- v3UnderlyingAsset: asset.toLowerCase(),
- amount: amount.toString(),
- };
- });
- draft.exceptionsBalancesLoading = false;
- })
- );
- }
- }
- },
};
};
diff --git a/src/ui-config/SharedDependenciesProvider.tsx b/src/ui-config/SharedDependenciesProvider.tsx
index 1b6f48ddc4..0e4c0c5708 100644
--- a/src/ui-config/SharedDependenciesProvider.tsx
+++ b/src/ui-config/SharedDependenciesProvider.tsx
@@ -4,6 +4,7 @@ import { DelegationTokenService } from 'src/services/DelegationTokenService';
import { ERC20Service } from 'src/services/Erc20Service';
import { GovernanceService } from 'src/services/GovernanceService';
import { GovernanceV3Service } from 'src/services/GovernanceV3Service';
+import { MigrationService } from 'src/services/MigrationService';
import { StkAbptMigrationService } from 'src/services/StkAbptMigrationService';
import { TokenWrapperService } from 'src/services/TokenWrapperService';
import { UiGhoService } from 'src/services/UiGhoService';
@@ -33,6 +34,7 @@ interface SharedDependenciesContext {
uiGhoService: UiGhoService;
delegationTokenService: DelegationTokenService;
stkAbptMigrationService: StkAbptMigrationService;
+ migrationService: MigrationService;
erc20Service: ERC20Service;
}
@@ -64,6 +66,7 @@ export const SharedDependenciesProvider: React.FC = ({ children }) => {
const approvedAmountService = new ApprovedAmountService(getProvider);
const delegationTokenService = new DelegationTokenService(getGovernanceProvider);
const stkAbptMigrationService = new StkAbptMigrationService();
+ const migrationService = new MigrationService(getProvider);
const uiPoolService = new UiPoolService(getProvider);
const uiIncentivesService = new UiIncentivesService(getProvider);
@@ -91,6 +94,7 @@ export const SharedDependenciesProvider: React.FC = ({ children }) => {
uiGhoService,
delegationTokenService,
stkAbptMigrationService,
+ migrationService,
erc20Service,
}}
>
diff --git a/src/ui-config/queries.ts b/src/ui-config/queries.ts
index 4dac9d412e..c9f58bdb09 100644
--- a/src/ui-config/queries.ts
+++ b/src/ui-config/queries.ts
@@ -1,3 +1,5 @@
+import { MigrationSupplyException } from 'src/store/v3MigrationSlice';
+
import { MarketDataType } from './marketsConfig';
import { TokenInfo } from './TokenList';
@@ -144,6 +146,15 @@ export const queryKeysFactory = {
chainId,
'tokenDelegatees',
],
+ migrationExceptions: (
+ suplies: MigrationSupplyException[],
+ marketFrom: MarketDataType,
+ marketTo: MarketDataType
+ ) => [
+ ...suplies.map((supply) => supply.underlyingAsset),
+ ...queryKeysFactory.market(marketFrom),
+ ...queryKeysFactory.market(marketTo),
+ ],
tokensBalance: (tokenList: TokenInfo[], chainId: number, user: string) => [
...queryKeysFactory.user(user),
tokenList.map((elem) => elem.address),
diff --git a/src/utils/theme.tsx b/src/utils/theme.tsx
index b9369a632d..adee35697d 100644
--- a/src/utils/theme.tsx
+++ b/src/utils/theme.tsx
@@ -82,6 +82,7 @@ declare module '@mui/material/styles' {
interface BreakpointOverrides {
xsm: true;
xxl: true;
+ mdlg: true;
}
}
@@ -130,7 +131,7 @@ export const getDesignTokens = (mode: 'light' | 'dark') => {
return {
breakpoints: {
keys: ['xs', 'xsm', 'sm', 'md', 'lg', 'xl', 'xxl'],
- values: { xs: 0, xsm: 640, sm: 760, md: 960, lg: 1280, xl: 1575, xxl: 1800 },
+ values: { xs: 0, xsm: 640, sm: 760, md: 960, mdlg: 1125, lg: 1280, xl: 1575, xxl: 1800 },
},
palette: {
mode,