Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
114328f
refactor: sdk integrated in market page
AGMASO Sep 26, 2025
940cdf4
chore: clean code
AGMASO Sep 26, 2025
fcb1a39
fix: simplified icon fetch logic & clean code
AGMASO Sep 29, 2025
92eeffd
fix: build error
AGMASO Sep 29, 2025
a80c04b
fix: build error
AGMASO Sep 29, 2025
4a5e1fe
fix: build error
AGMASO Sep 29, 2025
eff6ed6
chore: clean code
AGMASO Sep 30, 2025
8653eb9
chore: clean code
AGMASO Sep 30, 2025
75769d3
refactor: integrate sdk into reserve-overview. missing few flags from…
AGMASO Oct 3, 2025
be28f80
fix: show disabled only for > 0 amounts
AGMASO Oct 3, 2025
c4d503f
Merge branch 'refactor/sdk-in-markets' into refactor/reserve-overview…
AGMASO Oct 3, 2025
9f5d624
fix: solved issue on tokenIcons in reserve-overview page
AGMASO Oct 6, 2025
47ec420
fix: clean code
AGMASO Oct 6, 2025
18dadae
fix: clean code
AGMASO Oct 6, 2025
27eb9b8
fix: clean code
AGMASO Oct 6, 2025
8f7da60
chore: clean code
AGMASO Oct 7, 2025
2e502e9
feat: added interest Rate Strategy Address to link, after updated sdk
AGMASO Oct 8, 2025
d3d3e45
fix: use typescript guards
AGMASO Oct 10, 2025
3610842
fix: simplified code
AGMASO Oct 10, 2025
4e83b97
refactor: move incentives calculation to parent component
AGMASO Oct 10, 2025
de6b877
chore: clean code
AGMASO Oct 13, 2025
cdc1ae9
Merge branch 'refactor/sdk-in-markets' into refactor/reserve-overview…
AGMASO Oct 13, 2025
f8fa340
feat: added Pts-ethena tokens to mapping
AGMASO Oct 21, 2025
5b6f0ee
chore: trigger rebuild
AGMASO Oct 21, 2025
ca6db43
Merge remote-tracking branch 'origin/refactor/sdk-in-markets' into re…
AGMASO Oct 21, 2025
21ca830
chore: bump aave-sdk versions
AGMASO Nov 5, 2025
d31da54
fix: isolationdebtceiling values displaying correct now
AGMASO Nov 5, 2025
2ea35f5
Merge branch 'main' into refactor/reserve-overview-page-sdk
AGMASO Nov 27, 2025
16ed69e
fix: build error
AGMASO Nov 27, 2025
764c8d5
feat: refactoring in progress, being supply refactored using sdk, mis…
AGMASO Dec 1, 2025
5266fab
refactor: supplyactions sdk refactored
AGMASO Dec 2, 2025
958a5e2
feat: supply flow refactored with usdt reset and permit
AGMASO Dec 2, 2025
1bad771
feat: refactor borrow flow; functionality complete, pending polish an…
AGMASO Dec 3, 2025
c968b2e
feat: refactored actions on reserve-overview page
AGMASO Dec 4, 2025
a98e4f0
chore: clean code
AGMASO Dec 4, 2025
084653d
Merge branch 'main' into refactor/actions-reserve-overview
AGMASO Dec 4, 2025
348e536
fix: build error
AGMASO Dec 4, 2025
d27958e
fix: fixed usd value and healthFactor calculation in supplywrappedTok…
AGMASO Dec 4, 2025
bfa28e2
fix: build error
AGMASO Dec 4, 2025
a0d2d38
Merge branch 'main' into refactor/actions-reserve-overview
AGMASO Dec 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pages/_app.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ const BridgeModal = dynamic(() =>
const BorrowModal = dynamic(() =>
import('src/components/transactions/Borrow/BorrowModal').then((module) => module.BorrowModal)
);
const BorrowModalSDK = dynamic(() =>
import('src/components/transactions/Borrow/BorrowModalSDK').then(
(module) => module.BorrowModalSDK
)
);
const ClaimRewardsModal = dynamic(() =>
import('src/components/transactions/ClaimRewards/ClaimRewardsModal').then(
(module) => module.ClaimRewardsModal
Expand All @@ -71,6 +76,11 @@ const RepayModal = dynamic(() =>
const SupplyModal = dynamic(() =>
import('src/components/transactions/Supply/SupplyModal').then((module) => module.SupplyModal)
);
const SupplyModalSDK = dynamic(() =>
import('src/components/transactions/Supply/SupplyModalSDK').then(
(module) => module.SupplyModalSDK
)
);
const WithdrawModal = dynamic(() =>
import('src/components/transactions/Withdraw/WithdrawModal').then(
(module) => module.WithdrawModal
Expand Down Expand Up @@ -168,8 +178,10 @@ export default function MyApp(props: MyAppProps) {
<GasStationProvider>
{getLayout(<Component {...pageProps} />)}
<SupplyModal />
<SupplyModalSDK />
<WithdrawModal />
<BorrowModal />
<BorrowModalSDK />
<RepayModal />
<CollateralChangeModal />
<ClaimRewardsModal />
Expand Down
18 changes: 3 additions & 15 deletions pages/reserve-overview.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
import StyledToggleButton from 'src/components/StyledToggleButton';
import StyledToggleButtonGroup from 'src/components/StyledToggleButtonGroup';
import {
ComputedReserveData,
ReserveWithId,
useAppDataContext,
} from 'src/hooks/app-data-provider/useAppDataProvider';
import { AssetCapsProvider } from 'src/hooks/useAssetCaps';
import { ReserveWithId, useAppDataContext } from 'src/hooks/app-data-provider/useAppDataProvider';
import { AssetCapsProviderSDK } from 'src/hooks/useAssetCapsSDK';
import { MainLayout } from 'src/layouts/MainLayout';
import { ReserveActions } from 'src/modules/reserve-overview/ReserveActions';
Expand Down Expand Up @@ -46,7 +41,7 @@ const UnStakeModal = dynamic(() =>

export default function ReserveOverview() {
const router = useRouter();
const { supplyReserves, reserves } = useAppDataContext();
const { supplyReserves } = useAppDataContext();
const underlyingAsset = router.query.underlyingAsset as string;

const [mode, setMode] = useState<'overview' | 'actions' | ''>('overview');
Expand All @@ -57,10 +52,6 @@ export default function ReserveOverview() {
return reserve.underlyingToken.address.toLowerCase() === underlyingAsset?.toLowerCase();
}) as ReserveWithId;

//With Reserves
const reserveLegacy = reserves.find((reserve) => {
return reserve.underlyingAsset.toLowerCase() === underlyingAsset?.toLowerCase();
}) as ComputedReserveData;
const [pageEventCalled, setPageEventCalled] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -127,10 +118,7 @@ export default function ReserveOverview() {
width: { xs: '100%', lg: '416px' },
}}
>
{/* Wrapped in AssetCapsProvider to provide the data using legacy method to avoid braking actions */}
<AssetCapsProvider asset={reserveLegacy}>
<ReserveActions reserve={reserveLegacy} />
</AssetCapsProvider>
<ReserveActions reserve={reserve} />
</Box>
</Box>
</ContentContainer>
Expand Down
232 changes: 232 additions & 0 deletions src/components/transactions/Borrow/BorrowActionsSDK.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
import { bigDecimal, ChainId, evmAddress } from '@aave/client';
import { approveBorrowCreditDelegation, borrow } from '@aave/client/actions';
import { sendWith } from '@aave/client/viem';
import {
API_ETH_MOCK_ADDRESS,
gasLimitRecommendations,
ProtocolAction,
} from '@aave/contract-helpers';
import { valueToBigNumber } from '@aave/math-utils';
import { Trans } from '@lingui/macro';
import { BoxProps } from '@mui/material';
import { useQueryClient } from '@tanstack/react-query';
import { client } from 'pages/_app.page';
import React, { useEffect, useState } from 'react';
import { ReserveWithId, useAppDataContext } from 'src/hooks/app-data-provider/useAppDataProvider';
import { useModalContext } from 'src/hooks/useModal';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { useRootStore } from 'src/store/root';
import { getErrorTextFromError, TxAction } from 'src/ui-config/errorMapping';
import { queryKeysFactory } from 'src/ui-config/queries';
import { wagmiConfig } from 'src/ui-config/wagmiConfig';
import { getWalletClient } from 'wagmi/actions';
import { useShallow } from 'zustand/shallow';

import { TxActionsWrapper } from '../TxActionsWrapper';
import { APPROVE_DELEGATION_GAS_LIMIT } from '../utils';

export interface BorrowActionsPropsSDK extends BoxProps {
poolReserve: ReserveWithId;
amountToBorrow: string;
poolAddress: string;
isWrongNetwork: boolean;
symbol: string;
borrowNative: boolean;
blocked: boolean;
}

export const BorrowActionsSDK = React.memo(
({
symbol,
poolReserve,
amountToBorrow,
poolAddress,
isWrongNetwork,
borrowNative,
blocked,
sx,
}: BorrowActionsPropsSDK) => {
const [currentMarketData, addTransaction] = useRootStore(
useShallow((state) => [state.currentMarketData, state.addTransaction])
);
const {
approvalTxState,
mainTxState,
loadingTxns,
setMainTxState,
setTxError,
setGasLimit,
setLoadingTxns,
setApprovalTxState,
} = useModalContext();

const queryClient = useQueryClient();
const { borrowReserves } = useAppDataContext();
const { currentAccount, chainId: userChainId } = useWeb3Context();
const [requiresApproval, setRequiresApproval] = useState(
borrowNative && poolAddress === API_ETH_MOCK_ADDRESS
);
useEffect(() => {
setRequiresApproval(
borrowNative && poolAddress === API_ETH_MOCK_ADDRESS && !approvalTxState.success
);
}, [borrowNative, poolAddress, approvalTxState.success]);

const handleApproval = async () => {
if (!currentAccount) return;
try {
setApprovalTxState({ ...approvalTxState, loading: true });
const walletClient = await getWalletClient(wagmiConfig, {
chainId: currentMarketData.chainId ?? userChainId,
});
if (!walletClient) {
throw new Error('Wallet client not available');
}

const approvalResult = await approveBorrowCreditDelegation(client, {
market: evmAddress(currentMarketData.addresses.LENDING_POOL),
underlyingToken: evmAddress(poolReserve.underlyingToken.address),
amount: bigDecimal(amountToBorrow),
user: evmAddress(currentAccount),
delegatee: evmAddress(currentMarketData.addresses.WETH_GATEWAY ?? currentAccount),
chainId: (currentMarketData.chainId ?? userChainId) as ChainId,
}).andThen(sendWith(walletClient));

if (approvalResult.isErr()) {
const parsedError = getErrorTextFromError(
approvalResult.error as Error,
TxAction.APPROVAL,
false
);
setTxError(parsedError);
setApprovalTxState({ txHash: undefined, loading: false });
return;
}

const txHash = String(approvalResult.value);
setApprovalTxState({ txHash, loading: false, success: true });
setRequiresApproval(false);
setTxError(undefined);
} catch (error) {
const parsedError = getErrorTextFromError(error as Error, TxAction.APPROVAL, false);
setTxError(parsedError);
setApprovalTxState({ txHash: undefined, loading: false });
}
};

useEffect(() => {
let borrowGasLimit = Number(gasLimitRecommendations[ProtocolAction.borrow].recommended);
if (requiresApproval && !approvalTxState.success) {
borrowGasLimit += Number(APPROVE_DELEGATION_GAS_LIMIT);
}
setGasLimit(borrowGasLimit.toString());
}, [requiresApproval, approvalTxState.success, setGasLimit]);

const handleAction = async () => {
if (!amountToBorrow || Number(amountToBorrow) === 0) return;
if (requiresApproval && !approvalTxState.success) {
setTxError(
getErrorTextFromError(
new Error('Approval required before borrowing'),
TxAction.APPROVAL,
false
)
);
return;
}
try {
setLoadingTxns(true);
setMainTxState({ ...mainTxState, loading: true });
setTxError(undefined);

const walletClient = await getWalletClient(wagmiConfig, {
chainId: currentMarketData.chainId ?? userChainId,
});

if (!walletClient) {
throw new Error('Wallet client not available');
}
const amountInput = borrowNative
? { native: bigDecimal(amountToBorrow) }
: {
erc20: {
currency: evmAddress(poolAddress),
value: bigDecimal(amountToBorrow),
},
};

const result = await borrow(client, {
market: evmAddress(currentMarketData.addresses.LENDING_POOL),
amount: amountInput,
sender: evmAddress(currentAccount),
chainId: (currentMarketData.chainId ?? userChainId) as ChainId,
})
.andThen(sendWith(walletClient))
.andThen(client.waitForTransaction);
if (result.isErr()) {
const parsedError = getErrorTextFromError(
result.error as Error,
TxAction.MAIN_ACTION,
false
);
setTxError(parsedError);
setMainTxState({ txHash: undefined, loading: false });
return;
}

const txHash = String(result.value);
setMainTxState({
txHash,
loading: false,
success: true,
});

addTransaction(txHash, {
action: ProtocolAction.borrow,
txState: 'success',
asset: poolAddress,
amount: amountToBorrow,
assetName: symbol,
amountUsd: (() => {
const reserve = borrowReserves.find(
(r) => r.underlyingToken.address.toLowerCase() === poolAddress.toLowerCase()
);
return reserve
? valueToBigNumber(amountToBorrow).multipliedBy(reserve.usdExchangeRate).toString()
: undefined;
})(),
});

queryClient.invalidateQueries({ queryKey: queryKeysFactory.pool });
queryClient.invalidateQueries({ queryKey: queryKeysFactory.gho });
} catch (error) {
const parsedError = getErrorTextFromError(error as Error, TxAction.MAIN_ACTION, false);
setTxError(parsedError);
setMainTxState({
txHash: undefined,
loading: false,
});
} finally {
setLoadingTxns(false);
}
};

return (
<TxActionsWrapper
blocked={blocked}
mainTxState={mainTxState}
approvalTxState={approvalTxState}
requiresAmount={true}
amount={amountToBorrow}
isWrongNetwork={isWrongNetwork}
handleAction={handleAction}
actionText={<Trans>Borrow {symbol}</Trans>}
actionInProgressText={<Trans>Borrowing {symbol}</Trans>}
handleApproval={requiresApproval ? handleApproval : undefined}
requiresApproval={requiresApproval}
preparingTransactions={loadingTxns}
sx={sx}
/>
);
}
);
Loading
Loading