From be77afbfa57e78968e12a82ea1b165d899cde544 Mon Sep 17 00:00:00 2001 From: antoncoding Date: Sun, 8 Mar 2026 16:41:16 +0800 Subject: [PATCH 1/5] refactor: leverage hook --- app/tools/page.tsx | 38 +- .../leverage/leverageWithErc4626Deposit.ts | 219 ++++++ src/hooks/leverage/leverageWithSwap.ts | 449 +++++++++++ src/hooks/leverage/math.ts | 30 +- src/hooks/leverage/transaction-shared.ts | 55 ++ src/hooks/useBorrowTransaction.ts | 23 +- src/hooks/useLeverageTransaction.ts | 732 ++++-------------- src/hooks/useMultiMarketSupply.ts | 4 +- src/hooks/useSupplyMarket.ts | 6 +- .../withdraw-collateral-and-repay.tsx | 2 +- .../add-collateral-and-leverage.tsx | 44 +- .../remove-collateral-and-deleverage.tsx | 6 +- 12 files changed, 938 insertions(+), 670 deletions(-) create mode 100644 src/hooks/leverage/leverageWithErc4626Deposit.ts create mode 100644 src/hooks/leverage/leverageWithSwap.ts create mode 100644 src/hooks/leverage/transaction-shared.ts diff --git a/app/tools/page.tsx b/app/tools/page.tsx index 998b78c2..c4eff89c 100644 --- a/app/tools/page.tsx +++ b/app/tools/page.tsx @@ -12,7 +12,7 @@ import { useMorphoAuthorization } from '@/hooks/useMorphoAuthorization'; import { useStyledToast } from '@/hooks/useStyledToast'; import { toUserFacingTransactionErrorMessage } from '@/utils/transaction-errors'; import { getBundlerV2, MONARCH_TX_IDENTIFIER } from '@/utils/morpho'; -import { getNetworkName, SupportedNetworks } from '@/utils/networks'; +import { getNetworkName, type SupportedNetworks } from '@/utils/networks'; import NetworkFilter from '@/features/markets/components/filters/network-filter'; export default function ToolsPage() { @@ -159,14 +159,16 @@ export default function ToolsPage() { }) + MONARCH_TX_IDENTIFIER) as `0x${string}`, value: 0n, chainId: selectedChainId, - }).catch((error: unknown) => { - const userFacingMessage = toUserFacingTransactionErrorMessage(error, 'Failed to submit Bundler V2 asset sweep.'); - if (userFacingMessage !== 'User rejected transaction.') { - toast.error('Asset sweep failed', userFacingMessage); - } - }).finally(() => { - setIsSweepConfirmModalOpen(false); - }); + }) + .catch((error: unknown) => { + const userFacingMessage = toUserFacingTransactionErrorMessage(error, 'Failed to submit Bundler V2 asset sweep.'); + if (userFacingMessage !== 'User rejected transaction.') { + toast.error('Asset sweep failed', userFacingMessage); + } + }) + .finally(() => { + setIsSweepConfirmModalOpen(false); + }); }; const getInputClassName = () => { @@ -277,9 +279,7 @@ export default function ToolsPage() { Executes via Bundler V2 multicall on the selected network: erc20Transfer(asset, yourWallet, maxUint256).

-

- ⚠️ This transfers only what Bundler V2 already holds for the asset address. -

+

⚠️ This transfers only what Bundler V2 already holds for the asset address.

@@ -292,7 +292,10 @@ export default function ToolsPage() { />
-
@@ -360,7 +361,10 @@ export default function ToolsPage() { -