@0xsquid/react-hooks 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/images/icons/wallets/index.d.ts +22 -0
- package/{src/assets/images/icons/wallets/index.ts → dist/assets/images/icons/wallets/index.js} +21 -21
- package/dist/assets/images/icons/wallets/index.js.map +1 -0
- package/dist/connectors/ExodusConnector.d.ts +4 -0
- package/{src/connectors/ExodusConnector.ts → dist/connectors/ExodusConnector.js} +3 -3
- package/dist/connectors/ExodusConnector.js.map +1 -0
- package/dist/connectors/LedgerLiveConnector.d.ts +40 -0
- package/dist/connectors/LedgerLiveConnector.js +177 -0
- package/dist/connectors/LedgerLiveConnector.js.map +1 -0
- package/dist/contracts/typechain/factories/ERC20__factory.js +324 -0
- package/dist/contracts/typechain/factories/ERC20__factory.js.map +1 -0
- package/dist/core/constants.d.ts +37 -0
- package/dist/core/constants.js +487 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/externalLinks.d.ts +18 -0
- package/{src/core/externalLinks.ts → dist/core/externalLinks.js} +5 -9
- package/dist/core/externalLinks.js.map +1 -0
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/multicall3.d.ts +16 -0
- package/dist/core/multicall3.js +23 -0
- package/dist/core/multicall3.js.map +1 -0
- package/dist/core/numbers.d.ts +3 -0
- package/dist/core/numbers.js +28 -0
- package/dist/core/numbers.js.map +1 -0
- package/dist/core/providers/CosmosProvider.d.ts +34 -0
- package/dist/core/providers/CosmosProvider.js +12 -0
- package/dist/core/providers/CosmosProvider.js.map +1 -0
- package/dist/core/queries/queries-keys.d.ts +34 -0
- package/dist/core/queries/queries-keys.js +120 -0
- package/dist/core/queries/queries-keys.js.map +1 -0
- package/dist/core/queries/react-query-config.d.ts +3 -0
- package/dist/core/queries/react-query-config.js +11 -0
- package/dist/core/queries/react-query-config.js.map +1 -0
- package/dist/core/types/components.d.ts +14 -0
- package/dist/core/types/components.js +2 -0
- package/dist/core/types/components.js.map +1 -0
- package/dist/core/types/config.d.ts +47 -0
- package/dist/core/types/config.js +2 -0
- package/dist/core/types/config.js.map +1 -0
- package/dist/core/types/dex.d.ts +28 -0
- package/dist/core/types/dex.js +33 -0
- package/dist/core/types/dex.js.map +1 -0
- package/dist/core/types/error.d.ts +44 -0
- package/dist/core/types/error.js +12 -0
- package/dist/core/types/error.js.map +1 -0
- package/dist/core/types/event.d.ts +17 -0
- package/dist/core/types/event.js +2 -0
- package/dist/core/types/event.js.map +1 -0
- package/dist/core/types/route.d.ts +9 -0
- package/dist/core/types/route.js +4 -0
- package/dist/core/types/route.js.map +1 -0
- package/dist/core/types/swap.d.ts +8 -0
- package/dist/core/types/swap.js +2 -0
- package/dist/core/types/swap.js.map +1 -0
- package/dist/core/types/tokens.d.ts +29 -0
- package/dist/core/types/tokens.js +2 -0
- package/dist/core/types/tokens.js.map +1 -0
- package/dist/core/types/transaction.d.ts +68 -0
- package/dist/core/types/transaction.js +38 -0
- package/dist/core/types/transaction.js.map +1 -0
- package/dist/core/types/types.d.ts +30 -0
- package/dist/core/types/types.js +7 -0
- package/dist/core/types/types.js.map +1 -0
- package/dist/core/types/wallet.d.ts +55 -0
- package/dist/core/types/wallet.js +26 -0
- package/dist/core/types/wallet.js.map +1 -0
- package/dist/hooks/chains/useSquidChains.d.ts +12 -0
- package/dist/hooks/chains/useSquidChains.js +45 -0
- package/dist/hooks/chains/useSquidChains.js.map +1 -0
- package/dist/hooks/cosmos/useCosmos.d.ts +33 -0
- package/dist/hooks/cosmos/useCosmos.js +194 -0
- package/dist/hooks/cosmos/useCosmos.js.map +1 -0
- package/dist/hooks/cosmos/useCosmosForChain.d.ts +4 -0
- package/dist/hooks/cosmos/useCosmosForChain.js +22 -0
- package/dist/hooks/cosmos/useCosmosForChain.js.map +1 -0
- package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -7
- package/dist/hooks/index.js +27 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/navigation/useKeyboardNavigation.d.ts +7 -0
- package/dist/hooks/navigation/useKeyboardNavigation.js +69 -0
- package/dist/hooks/navigation/useKeyboardNavigation.js.map +1 -0
- package/dist/hooks/store/useSquidStore.d.ts +105 -0
- package/dist/hooks/store/useSquidStore.js +35 -0
- package/dist/hooks/store/useSquidStore.js.map +1 -0
- package/dist/hooks/swap/useSwap.d.ts +25 -0
- package/dist/hooks/swap/useSwap.js +229 -0
- package/dist/hooks/swap/useSwap.js.map +1 -0
- package/dist/hooks/tokens/useAllTokensWithBalance.d.ts +11 -0
- package/dist/hooks/tokens/useAllTokensWithBalance.js +97 -0
- package/dist/hooks/tokens/useAllTokensWithBalance.js.map +1 -0
- package/dist/hooks/tokens/useBalance.d.ts +34 -0
- package/dist/hooks/tokens/useBalance.js +112 -0
- package/dist/hooks/tokens/useBalance.js.map +1 -0
- package/dist/hooks/tokens/useMultiChainBalance.d.ts +17 -0
- package/dist/hooks/tokens/useMultiChainBalance.js +36 -0
- package/dist/hooks/tokens/useMultiChainBalance.js.map +1 -0
- package/dist/hooks/tokens/usePrices.d.ts +6 -0
- package/dist/hooks/tokens/usePrices.js +42 -0
- package/dist/hooks/tokens/usePrices.js.map +1 -0
- package/dist/hooks/tokens/useSingleTokenPrice.d.ts +10 -0
- package/dist/hooks/tokens/useSingleTokenPrice.js +32 -0
- package/dist/hooks/tokens/useSingleTokenPrice.js.map +1 -0
- package/dist/hooks/tokens/useSquidTokens.d.ts +13 -0
- package/dist/hooks/tokens/useSquidTokens.js +35 -0
- package/dist/hooks/tokens/useSquidTokens.js.map +1 -0
- package/dist/hooks/tokens/useTokensWithBalance.d.ts +7 -0
- package/dist/hooks/tokens/useTokensWithBalance.js +111 -0
- package/dist/hooks/tokens/useTokensWithBalance.js.map +1 -0
- package/dist/hooks/transaction/useEstimate.d.ts +44 -0
- package/dist/hooks/transaction/useEstimate.js +274 -0
- package/dist/hooks/transaction/useEstimate.js.map +1 -0
- package/dist/hooks/transaction/useEstimatePriceImpact.d.ts +7 -0
- package/dist/hooks/transaction/useEstimatePriceImpact.js +26 -0
- package/dist/hooks/transaction/useEstimatePriceImpact.js.map +1 -0
- package/dist/hooks/transaction/useExecuteTransaction.d.ts +20 -0
- package/dist/hooks/transaction/useExecuteTransaction.js +310 -0
- package/dist/hooks/transaction/useExecuteTransaction.js.map +1 -0
- package/dist/hooks/transaction/useExpress.d.ts +5 -0
- package/dist/hooks/transaction/useExpress.js +31 -0
- package/dist/hooks/transaction/useExpress.js.map +1 -0
- package/dist/hooks/transaction/useGetRoute.d.ts +14 -0
- package/dist/hooks/transaction/useGetRoute.js +96 -0
- package/dist/hooks/transaction/useGetRoute.js.map +1 -0
- package/dist/hooks/transaction/useSingleTransaction.d.ts +8 -0
- package/dist/hooks/transaction/useSingleTransaction.js +99 -0
- package/dist/hooks/transaction/useSingleTransaction.js.map +1 -0
- package/dist/hooks/transaction/useTransaction.d.ts +25 -0
- package/dist/hooks/transaction/useTransaction.js +521 -0
- package/dist/hooks/transaction/useTransaction.js.map +1 -0
- package/dist/hooks/user/useUserParams.d.ts +6 -0
- package/dist/hooks/user/useUserParams.js +41 -0
- package/dist/hooks/user/useUserParams.js.map +1 -0
- package/dist/hooks/wallet/useAddToken.d.ts +4 -0
- package/dist/hooks/wallet/useAddToken.js +45 -0
- package/dist/hooks/wallet/useAddToken.js.map +1 -0
- package/dist/hooks/wallet/useAutoConnect.d.ts +6 -0
- package/dist/hooks/wallet/useAutoConnect.js +44 -0
- package/dist/hooks/wallet/useAutoConnect.js.map +1 -0
- package/dist/hooks/wallet/useGnosisContext.d.ts +7 -0
- package/dist/hooks/wallet/useGnosisContext.js +70 -0
- package/dist/hooks/wallet/useGnosisContext.js.map +1 -0
- package/dist/hooks/wallet/useIntegratorContext.d.ts +5 -0
- package/dist/hooks/wallet/useIntegratorContext.js +39 -0
- package/dist/hooks/wallet/useIntegratorContext.js.map +1 -0
- package/dist/hooks/wallet/useMultiChainWallet.d.ts +8 -0
- package/dist/hooks/wallet/useMultiChainWallet.js +113 -0
- package/dist/hooks/wallet/useMultiChainWallet.js.map +1 -0
- package/dist/hooks/wallet/useWallet.d.ts +6 -0
- package/dist/hooks/wallet/useWallet.js +65 -0
- package/dist/hooks/wallet/useWallet.js.map +1 -0
- package/dist/hooks/webapp-router/useSquidRouter.d.ts +11 -0
- package/dist/hooks/webapp-router/useSquidRouter.js +33 -0
- package/dist/hooks/webapp-router/useSquidRouter.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +0 -1
- package/dist/index.js.map +1 -0
- package/dist/provider/index.d.ts +10 -0
- package/dist/provider/index.js +71 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/services/external/analyticsService.d.ts +18 -0
- package/dist/services/external/analyticsService.js +30 -0
- package/dist/services/external/analyticsService.js.map +1 -0
- package/dist/services/external/coingeckoService.d.ts +8 -0
- package/dist/services/external/coingeckoService.js +20 -0
- package/dist/services/external/coingeckoService.js.map +1 -0
- package/dist/services/external/rpcService.d.ts +4 -0
- package/dist/services/external/rpcService.js +145 -0
- package/dist/services/external/rpcService.js.map +1 -0
- package/dist/services/external/secretService.d.ts +28 -0
- package/dist/services/external/secretService.js +129 -0
- package/dist/services/external/secretService.js.map +1 -0
- package/dist/services/index.js +2 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/internal/apiService.d.ts +4 -0
- package/dist/services/internal/apiService.js +7 -0
- package/dist/services/internal/apiService.js.map +1 -0
- package/dist/services/internal/assetsService.d.ts +28 -0
- package/dist/services/internal/assetsService.js +46 -0
- package/dist/services/internal/assetsService.js.map +1 -0
- package/dist/services/internal/configService.d.ts +40 -0
- package/dist/services/internal/configService.js +119 -0
- package/dist/services/internal/configService.js.map +1 -0
- package/dist/services/internal/errorService.d.ts +30 -0
- package/{src/services/internal/errorService.ts → dist/services/internal/errorService.js} +35 -54
- package/dist/services/internal/errorService.js.map +1 -0
- package/dist/services/internal/eventService.d.ts +52 -0
- package/dist/services/internal/eventService.js +66 -0
- package/dist/services/internal/eventService.js.map +1 -0
- package/dist/services/internal/priceService.d.ts +1 -0
- package/dist/services/internal/priceService.js +7 -0
- package/dist/services/internal/priceService.js.map +1 -0
- package/dist/services/internal/transactionService.d.ts +43 -0
- package/dist/services/internal/transactionService.js +172 -0
- package/dist/services/internal/transactionService.js.map +1 -0
- package/dist/services/internal/transactionStatusService.d.ts +28 -0
- package/dist/services/internal/transactionStatusService.js +225 -0
- package/dist/services/internal/transactionStatusService.js.map +1 -0
- package/dist/services/internal/walletService.d.ts +28 -0
- package/dist/services/internal/walletService.js +123 -0
- package/dist/services/internal/walletService.js.map +1 -0
- package/dist/tests/assetsService.test.d.ts +1 -0
- package/dist/tests/assetsService.test.js +130 -0
- package/dist/tests/assetsService.test.js.map +1 -0
- package/dist/tests/configService.test.d.ts +1 -0
- package/dist/tests/configService.test.js +295 -0
- package/dist/tests/configService.test.js.map +1 -0
- package/dist/tests/fetchSquidData.d.ts +6 -0
- package/dist/tests/fetchSquidData.js +27 -0
- package/dist/tests/fetchSquidData.js.map +1 -0
- package/{src/tests/jest-svg-transform.ts → dist/tests/jest-svg-transform.js} +11 -9
- package/dist/tests/jest-svg-transform.js.map +1 -0
- package/dist/tests/sample.json +0 -0
- package/dist/tests/walletService.test.d.ts +1 -0
- package/dist/tests/walletService.test.js +74 -0
- package/dist/tests/walletService.test.js.map +1 -0
- package/package.json +6 -1
- package/.babelrc +0 -7
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -44
- package/CHANGELOG.md +0 -9
- package/jest.config.ts +0 -28
- package/scripts/copyAssets.js +0 -27
- package/scripts/removeBuildTestFolder.js +0 -28
- package/scripts/replacePaths.js +0 -37
- package/src/connectors/LedgerLiveConnector.ts +0 -226
- package/src/contracts/typechain/ERC20.d.ts +0 -441
- package/src/contracts/typechain/factories/ERC20__factory.ts +0 -340
- package/src/core/constants.ts +0 -549
- package/src/core/multicall3.ts +0 -22
- package/src/core/numbers.ts +0 -44
- package/src/core/providers/CosmosProvider.tsx +0 -55
- package/src/core/queries/queries-keys.ts +0 -156
- package/src/core/queries/react-query-config.ts +0 -13
- package/src/core/types/components.ts +0 -16
- package/src/core/types/config.ts +0 -52
- package/src/core/types/dex.ts +0 -31
- package/src/core/types/error.ts +0 -52
- package/src/core/types/event.ts +0 -16
- package/src/core/types/route.ts +0 -21
- package/src/core/types/swap.ts +0 -8
- package/src/core/types/tokens.ts +0 -30
- package/src/core/types/transaction.ts +0 -84
- package/src/core/types/types.ts +0 -37
- package/src/core/types/wallet.ts +0 -83
- package/src/hooks/chains/useSquidChains.ts +0 -66
- package/src/hooks/cosmos/useCosmos.ts +0 -279
- package/src/hooks/cosmos/useCosmosForChain.ts +0 -33
- package/src/hooks/navigation/useKeyboardNavigation.ts +0 -88
- package/src/hooks/store/useSquidStore.ts +0 -80
- package/src/hooks/swap/useSwap.ts +0 -359
- package/src/hooks/tokens/useAllTokensWithBalance.ts +0 -157
- package/src/hooks/tokens/useBalance.ts +0 -180
- package/src/hooks/tokens/useMultiChainBalance.ts +0 -59
- package/src/hooks/tokens/usePrices.ts +0 -52
- package/src/hooks/tokens/useSingleTokenPrice.ts +0 -45
- package/src/hooks/tokens/useSquidTokens.ts +0 -48
- package/src/hooks/tokens/useTokensWithBalance.ts +0 -169
- package/src/hooks/transaction/useEstimate.ts +0 -397
- package/src/hooks/transaction/useEstimatePriceImpact.ts +0 -39
- package/src/hooks/transaction/useExecuteTransaction.ts +0 -440
- package/src/hooks/transaction/useExpress.ts +0 -46
- package/src/hooks/transaction/useGetRoute.ts +0 -145
- package/src/hooks/transaction/useSingleTransaction.ts +0 -155
- package/src/hooks/transaction/useTransaction.ts +0 -734
- package/src/hooks/user/useUserParams.ts +0 -63
- package/src/hooks/wallet/useAddToken.ts +0 -53
- package/src/hooks/wallet/useAutoConnect.ts +0 -56
- package/src/hooks/wallet/useGnosisContext.ts +0 -84
- package/src/hooks/wallet/useIntegratorContext.ts +0 -44
- package/src/hooks/wallet/useMultiChainWallet.ts +0 -146
- package/src/hooks/wallet/useWallet.ts +0 -86
- package/src/hooks/webapp-router/useSquidRouter.ts +0 -42
- package/src/provider/index.tsx +0 -105
- package/src/react-app-env.d.ts +0 -2
- package/src/services/external/analyticsService.ts +0 -46
- package/src/services/external/coingeckoService.ts +0 -35
- package/src/services/external/rpcService.ts +0 -196
- package/src/services/external/secretService.ts +0 -178
- package/src/services/internal/apiService.ts +0 -6
- package/src/services/internal/assetsService.ts +0 -84
- package/src/services/internal/configService.ts +0 -261
- package/src/services/internal/eventService.ts +0 -93
- package/src/services/internal/priceService.ts +0 -10
- package/src/services/internal/transactionService.ts +0 -255
- package/src/services/internal/transactionStatusService.ts +0 -293
- package/src/services/internal/walletService.ts +0 -158
- package/src/tests/assetsService.test.ts +0 -176
- package/src/tests/configService.test.ts +0 -486
- package/src/tests/fetchSquidData.ts +0 -43
- package/src/tests/walletService.test.ts +0 -178
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.json +0 -31
- /package/{src → dist}/assets/images/icons/wallets/binance.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/bitget.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/bitkeep.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/blockchaindotcom.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/brave.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/c98.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/coinbase.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/cosmostation.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/defiConnect.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/exodus.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/fetchai.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/keplr.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/leap.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/metamask.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/okx.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/rabby.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/trustwallet.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/walletConnect.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/wallet_icon.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/xdefi.svg +0 -0
- /package/{src → dist}/assets/images/icons/wallets/zerion.svg +0 -0
- /package/{src → dist}/contracts/typechain/factories/ERC20__factory.d.ts +0 -0
- /package/{src/core/index.ts → dist/core/index.d.ts} +0 -0
- /package/{src/services/index.ts → dist/services/index.d.ts} +0 -0
- /package/{src/tests/sample.json → dist/tests/jest-svg-transform.d.ts} +0 -0
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
import { gasRefundMultiplier } from "@/core/constants";
|
|
2
|
-
import { formatUnitsRounded } from "@/core/numbers";
|
|
3
|
-
import { useSquidStore } from "@/hooks/store/useSquidStore";
|
|
4
|
-
import { useNativeTokenBalanceFromChain } from "@/hooks/tokens/useBalance";
|
|
5
|
-
import { useSingleTokenPrice } from "@/hooks/tokens/useSingleTokenPrice";
|
|
6
|
-
import { useSquidTokens } from "@/hooks/tokens/useSquidTokens";
|
|
7
|
-
import type { Estimate, FeeCost, GasCost } from "@0xsquid/squid-types";
|
|
8
|
-
import { ChainType } from "@0xsquid/squid-types";
|
|
9
|
-
import { BigNumber, constants } from "ethers";
|
|
10
|
-
import { formatUnits } from "ethers/lib/utils";
|
|
11
|
-
import { useMemo } from "react";
|
|
12
|
-
import { useSquidChains } from "../chains/useSquidChains";
|
|
13
|
-
import { useMultiChainBalance } from "../tokens/useMultiChainBalance";
|
|
14
|
-
import { useGetRoute } from "./useGetRoute";
|
|
15
|
-
|
|
16
|
-
export const useEstimate = ({
|
|
17
|
-
squidRoute,
|
|
18
|
-
}: {
|
|
19
|
-
squidRoute: ReturnType<typeof useGetRoute>;
|
|
20
|
-
}) => {
|
|
21
|
-
const { config } = useSquidStore();
|
|
22
|
-
const { balance: nativeTokenBalanceFromChain } =
|
|
23
|
-
useNativeTokenBalanceFromChain();
|
|
24
|
-
const { tokens } = useSquidTokens();
|
|
25
|
-
const { chains } = useSquidChains();
|
|
26
|
-
|
|
27
|
-
const [fromChain, toChain] = useMemo(() => {
|
|
28
|
-
return [
|
|
29
|
-
chains.find((c) => c.chainId === squidRoute.data?.params.fromChain),
|
|
30
|
-
chains.find((c) => c.chainId === squidRoute.data?.params.toChain),
|
|
31
|
-
];
|
|
32
|
-
}, [
|
|
33
|
-
chains,
|
|
34
|
-
squidRoute.data?.params.fromChain,
|
|
35
|
-
squidRoute.data?.params.toChain,
|
|
36
|
-
]);
|
|
37
|
-
|
|
38
|
-
const fromToken = useMemo(
|
|
39
|
-
() => tokens.find((t) => t.address === squidRoute.data?.params.fromToken),
|
|
40
|
-
[tokens, squidRoute.data?.params.fromToken]
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const balanceFormatted =
|
|
44
|
-
useMultiChainBalance({
|
|
45
|
-
chain: fromChain,
|
|
46
|
-
token: fromToken,
|
|
47
|
-
userAddress: squidRoute.data?.params.fromAddress ?? "",
|
|
48
|
-
enabled: !!squidRoute.data,
|
|
49
|
-
}).balance ?? "0";
|
|
50
|
-
|
|
51
|
-
const fromAmount = useMemo(
|
|
52
|
-
() => squidRoute.data?.estimate?.fromAmount ?? undefined,
|
|
53
|
-
[squidRoute.data?.estimate?.fromAmount]
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const fromAmountFormatted = useMemo(
|
|
57
|
-
() => (fromAmount ? formatUnits(fromAmount, fromToken?.decimals) : ""),
|
|
58
|
-
[fromAmount, fromToken?.decimals]
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const sourceChainNativeToken = useMemo(() => {
|
|
62
|
-
return tokens.find(
|
|
63
|
-
(t) =>
|
|
64
|
-
t.symbol === fromChain?.nativeCurrency.symbol &&
|
|
65
|
-
t.chainId == fromChain?.chainId
|
|
66
|
-
);
|
|
67
|
-
}, [tokens, fromChain]);
|
|
68
|
-
|
|
69
|
-
const destChainNativeToken = useMemo(() => {
|
|
70
|
-
return tokens.find(
|
|
71
|
-
(t) =>
|
|
72
|
-
t.symbol === toChain?.nativeCurrency.symbol &&
|
|
73
|
-
t.chainId == toChain?.chainId
|
|
74
|
-
);
|
|
75
|
-
}, [tokens, toChain]);
|
|
76
|
-
|
|
77
|
-
const toAmountUSD = useMemo(
|
|
78
|
-
() => squidRoute.data?.estimate?.toAmountUSD ?? undefined,
|
|
79
|
-
[squidRoute.data?.estimate?.toAmountUSD]
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const toAmountUSDFloat = useMemo(
|
|
83
|
-
() => (toAmountUSD ? parseFloat(toAmountUSD.replace(/,/g, "")) : 0),
|
|
84
|
-
[toAmountUSD]
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const exchangeRate = useMemo(
|
|
88
|
-
() => squidRoute.data?.estimate.exchangeRate ?? "0",
|
|
89
|
-
[squidRoute.data?.estimate.exchangeRate]
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const toAmountMin = useMemo(() => {
|
|
93
|
-
return formatUnits(
|
|
94
|
-
squidRoute.data?.estimate.toAmountMin ?? "0",
|
|
95
|
-
squidRoute.data?.estimate.toToken.decimals
|
|
96
|
-
);
|
|
97
|
-
}, [
|
|
98
|
-
squidRoute.data?.estimate.toAmountMin,
|
|
99
|
-
squidRoute.data?.estimate.toToken.decimals,
|
|
100
|
-
]);
|
|
101
|
-
|
|
102
|
-
const toAmount = useMemo(() => {
|
|
103
|
-
const formattedAmount = formatUnitsRounded(
|
|
104
|
-
squidRoute.data?.estimate.toAmount ?? "0",
|
|
105
|
-
squidRoute.data?.estimate.toToken.decimals,
|
|
106
|
-
14
|
|
107
|
-
);
|
|
108
|
-
return formattedAmount === "0.0" ? "0" : formattedAmount;
|
|
109
|
-
}, [
|
|
110
|
-
squidRoute.data?.estimate.toAmount,
|
|
111
|
-
squidRoute.data?.estimate.toToken.decimals,
|
|
112
|
-
]);
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* At the moment we're only taking the first item
|
|
116
|
-
* of fees array, but keeping the possibility to display multiple fees
|
|
117
|
-
*/
|
|
118
|
-
const crossChainGasFee = useMemo((): FeeCost | undefined => {
|
|
119
|
-
const estimate = squidRoute.data?.estimate as Estimate;
|
|
120
|
-
return estimate?.feeCosts.length > 0 ? estimate?.feeCosts[0] : undefined;
|
|
121
|
-
}, [squidRoute.data?.estimate]);
|
|
122
|
-
|
|
123
|
-
const allFeeCosts = useMemo((): FeeCost[] => {
|
|
124
|
-
const estimate = squidRoute.data?.estimate as Estimate;
|
|
125
|
-
return estimate?.feeCosts ?? [];
|
|
126
|
-
}, [squidRoute.data?.estimate]);
|
|
127
|
-
|
|
128
|
-
const allGasCosts = useMemo((): GasCost[] => {
|
|
129
|
-
const estimate = squidRoute.data?.estimate as Estimate;
|
|
130
|
-
return estimate?.gasCosts ?? [];
|
|
131
|
-
}, [squidRoute.data?.estimate]);
|
|
132
|
-
|
|
133
|
-
const firstGasCost = useMemo(
|
|
134
|
-
(): GasCost | undefined =>
|
|
135
|
-
allGasCosts.length > 0 ? allGasCosts[0] : undefined,
|
|
136
|
-
[allGasCosts]
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
const firstFeeCost = useMemo(
|
|
140
|
-
(): FeeCost | undefined =>
|
|
141
|
-
allFeeCosts.length > 0 ? allFeeCosts[0] : undefined,
|
|
142
|
-
[allFeeCosts]
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const integratorFeeCost = useMemo(
|
|
146
|
-
(): FeeCost | undefined =>
|
|
147
|
-
allFeeCosts.length > 0 && config.collectFees
|
|
148
|
-
? // TODO: This is a hack to get the integrator fee, not mapped in squid types yet
|
|
149
|
-
allFeeCosts.find((f) => (f.name as any) === "Integrator Fee")
|
|
150
|
-
: undefined,
|
|
151
|
-
[allFeeCosts, config]
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
const { getUSDValue } = useSingleTokenPrice(firstFeeCost?.token);
|
|
155
|
-
|
|
156
|
-
const expressFeeCost = useMemo(
|
|
157
|
-
(): FeeCost | undefined =>
|
|
158
|
-
allFeeCosts.length > 0
|
|
159
|
-
? allFeeCosts.find((f) => f.name === "Express Fee")
|
|
160
|
-
: undefined,
|
|
161
|
-
[allFeeCosts]
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
const expectedGasRefundCost = useMemo(
|
|
165
|
-
() =>
|
|
166
|
-
BigNumber.from(firstFeeCost?.amount ?? "0")
|
|
167
|
-
.mul(
|
|
168
|
-
// When source is Cosmos we don't refund any gas
|
|
169
|
-
fromChain?.chainType === ChainType.COSMOS ? 0 : gasRefundMultiplier
|
|
170
|
-
)
|
|
171
|
-
.div(100),
|
|
172
|
-
[firstFeeCost?.amount]
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
const sameTokenBetweenFees = useMemo(
|
|
176
|
-
() =>
|
|
177
|
-
firstFeeCost?.token.address === firstGasCost?.token.address &&
|
|
178
|
-
firstFeeCost?.token.chainId === firstGasCost?.token.chainId,
|
|
179
|
-
[
|
|
180
|
-
firstFeeCost?.token.address,
|
|
181
|
-
firstFeeCost?.token.chainId,
|
|
182
|
-
firstGasCost?.token.address,
|
|
183
|
-
firstGasCost?.token.chainId,
|
|
184
|
-
]
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
// From token is the same as the native chain token
|
|
188
|
-
// TODO: This only works for EVM chains
|
|
189
|
-
const isFromTokenNative = useMemo(() => {
|
|
190
|
-
if (fromToken === undefined || fromChain?.chainId === undefined) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
return fromToken.symbol === fromChain.nativeCurrency.symbol;
|
|
194
|
-
}, [fromToken, fromChain]);
|
|
195
|
-
|
|
196
|
-
const totalNativeFees = useMemo(() => {
|
|
197
|
-
const expressBn = BigNumber.from(expressFeeCost?.amount ?? constants.Zero);
|
|
198
|
-
if (sameTokenBetweenFees) {
|
|
199
|
-
return BigNumber.from(firstFeeCost?.amount ?? constants.Zero)
|
|
200
|
-
.add(BigNumber.from(firstGasCost?.amount ?? constants.Zero))
|
|
201
|
-
.add(expressBn);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return BigNumber.from(firstGasCost?.amount ?? constants.Zero).add(
|
|
205
|
-
expressBn
|
|
206
|
-
);
|
|
207
|
-
}, [
|
|
208
|
-
firstFeeCost?.amount,
|
|
209
|
-
firstGasCost?.amount,
|
|
210
|
-
sameTokenBetweenFees,
|
|
211
|
-
expressFeeCost?.amount,
|
|
212
|
-
]);
|
|
213
|
-
|
|
214
|
-
const totalFeesInNativeTokenPlusRatio = useMemo(() => {
|
|
215
|
-
return totalNativeFees.mul(105).div(100);
|
|
216
|
-
}, [totalNativeFees]);
|
|
217
|
-
|
|
218
|
-
const totalWithRefundEstimate = useMemo(() => {
|
|
219
|
-
const firstFee = {
|
|
220
|
-
BN: BigNumber.from(firstFeeCost?.amount ?? "0"),
|
|
221
|
-
token: firstFeeCost?.token,
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
const expressFee = {
|
|
225
|
-
BN: BigNumber.from(expressFeeCost?.amount ?? "0"),
|
|
226
|
-
token: expressFeeCost?.token,
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
// Big number amount
|
|
230
|
-
const totalBnbAmount = firstFee.BN.add(expressFee.BN).sub(
|
|
231
|
-
expectedGasRefundCost
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
const totalAmount = formatUnits(
|
|
235
|
-
totalBnbAmount,
|
|
236
|
-
firstFee.token?.decimals ?? 18
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
// USD values
|
|
240
|
-
const formattedRefundCost = formatUnits(
|
|
241
|
-
expectedGasRefundCost,
|
|
242
|
-
firstFeeCost?.token.decimals
|
|
243
|
-
);
|
|
244
|
-
const formattedRefundCostUSD = getUSDValue(formattedRefundCost);
|
|
245
|
-
const totalAmountUSD =
|
|
246
|
-
+(firstFeeCost?.amountUsd ?? 0) +
|
|
247
|
-
+(expressFeeCost?.amountUsd ?? 0) -
|
|
248
|
-
+(formattedRefundCostUSD ?? 0);
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
totalAmount,
|
|
252
|
-
totalAmountUSD,
|
|
253
|
-
feeToken: firstFeeCost?.token,
|
|
254
|
-
};
|
|
255
|
-
}, [
|
|
256
|
-
expectedGasRefundCost,
|
|
257
|
-
expressFeeCost?.amount,
|
|
258
|
-
expressFeeCost?.amountUsd,
|
|
259
|
-
expressFeeCost?.token,
|
|
260
|
-
firstFeeCost?.amount,
|
|
261
|
-
firstFeeCost?.amountUsd,
|
|
262
|
-
firstFeeCost?.token,
|
|
263
|
-
getUSDValue,
|
|
264
|
-
]);
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Two cases:
|
|
268
|
-
* 1. If the source token is the same as the native token, check if the balance of native token is less than the (source amount) + (native gas)
|
|
269
|
-
* 2. If the source token is different from the native token, check if the balance of native token is less than (native gas)
|
|
270
|
-
*/
|
|
271
|
-
const fromBalanceEnoughToSwap = useMemo(() => {
|
|
272
|
-
if (squidRoute.isLoading) return true;
|
|
273
|
-
|
|
274
|
-
const fromAmountWei = BigNumber.from(fromAmount ?? constants.Zero);
|
|
275
|
-
const fromBalance = nativeTokenBalanceFromChain.data ?? constants.Zero;
|
|
276
|
-
|
|
277
|
-
if (isFromTokenNative) {
|
|
278
|
-
const fromPlusGas = fromAmountWei.add(totalFeesInNativeTokenPlusRatio);
|
|
279
|
-
if (fromPlusGas.lte(fromBalance)) {
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
} else if (totalFeesInNativeTokenPlusRatio.lte(fromBalance)) {
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return false;
|
|
287
|
-
}, [
|
|
288
|
-
nativeTokenBalanceFromChain.data,
|
|
289
|
-
fromAmount,
|
|
290
|
-
isFromTokenNative,
|
|
291
|
-
squidRoute.isLoading,
|
|
292
|
-
totalFeesInNativeTokenPlusRatio,
|
|
293
|
-
]);
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* In the case where the source token is the same as the native token,
|
|
297
|
-
* we need to advise the user to change the source amount to be less than the balance of native token minus the gas cost
|
|
298
|
-
*/
|
|
299
|
-
const minAmountValueWarnMsg = useMemo(() => {
|
|
300
|
-
if (!isFromTokenNative) {
|
|
301
|
-
return undefined;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const fromBalance = nativeTokenBalanceFromChain.data ?? constants.Zero;
|
|
305
|
-
|
|
306
|
-
const minAmount = fromBalance.sub(totalFeesInNativeTokenPlusRatio);
|
|
307
|
-
|
|
308
|
-
if (minAmount.gt(constants.Zero)) {
|
|
309
|
-
const parsedMinAmount = formatUnits(
|
|
310
|
-
minAmount,
|
|
311
|
-
sourceChainNativeToken?.decimals ?? 18
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
return parsedMinAmount;
|
|
315
|
-
}
|
|
316
|
-
return "0";
|
|
317
|
-
}, [
|
|
318
|
-
nativeTokenBalanceFromChain.data,
|
|
319
|
-
isFromTokenNative,
|
|
320
|
-
sourceChainNativeToken?.decimals,
|
|
321
|
-
totalFeesInNativeTokenPlusRatio,
|
|
322
|
-
]);
|
|
323
|
-
|
|
324
|
-
const proposedGasDestinationAmount = useMemo(() => {
|
|
325
|
-
// Get native token of chain
|
|
326
|
-
const nativeToken = toChain?.nativeCurrency.symbol;
|
|
327
|
-
let gasDestinationAmount = 0;
|
|
328
|
-
switch (nativeToken) {
|
|
329
|
-
case "GLMR":
|
|
330
|
-
gasDestinationAmount = 5.289;
|
|
331
|
-
break;
|
|
332
|
-
case "ETH":
|
|
333
|
-
gasDestinationAmount = 0.0009;
|
|
334
|
-
break;
|
|
335
|
-
case "AVAX":
|
|
336
|
-
gasDestinationAmount = 0.115;
|
|
337
|
-
break;
|
|
338
|
-
case "BNB":
|
|
339
|
-
gasDestinationAmount = 0.00425;
|
|
340
|
-
break;
|
|
341
|
-
case "FTM":
|
|
342
|
-
gasDestinationAmount = 4.45;
|
|
343
|
-
break;
|
|
344
|
-
case "CELO":
|
|
345
|
-
gasDestinationAmount = 3.052;
|
|
346
|
-
break;
|
|
347
|
-
case "KAVA":
|
|
348
|
-
gasDestinationAmount = 2.339;
|
|
349
|
-
break;
|
|
350
|
-
case "MATIC":
|
|
351
|
-
gasDestinationAmount = 1.795;
|
|
352
|
-
break;
|
|
353
|
-
default:
|
|
354
|
-
gasDestinationAmount = 0;
|
|
355
|
-
break;
|
|
356
|
-
}
|
|
357
|
-
return { value: gasDestinationAmount, currency: nativeToken };
|
|
358
|
-
}, [toChain?.nativeCurrency.symbol]);
|
|
359
|
-
|
|
360
|
-
const enoughBalanceToSwap = useMemo(
|
|
361
|
-
() => +balanceFormatted >= 0 && +balanceFormatted > +fromAmountFormatted,
|
|
362
|
-
[balanceFormatted, fromAmountFormatted]
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
return {
|
|
366
|
-
allFeeCosts,
|
|
367
|
-
allGasCosts,
|
|
368
|
-
crossChainGasFee,
|
|
369
|
-
exchangeRate,
|
|
370
|
-
toAmountMin,
|
|
371
|
-
toAmount,
|
|
372
|
-
fromToken,
|
|
373
|
-
toAmountUSD,
|
|
374
|
-
toAmountUSDFloat,
|
|
375
|
-
isFetching: squidRoute.isLoading,
|
|
376
|
-
squidRouteError: squidRoute.error,
|
|
377
|
-
fromAmount,
|
|
378
|
-
fromAmountFormatted,
|
|
379
|
-
estimatedRouteDuration: squidRoute.data?.estimate?.estimatedRouteDuration,
|
|
380
|
-
minAmountValueWarnMsg,
|
|
381
|
-
fromBalanceEnoughToSwap,
|
|
382
|
-
isFromTokenNative,
|
|
383
|
-
firstFeeCost,
|
|
384
|
-
firstGasCost,
|
|
385
|
-
sameTokenBetweenFees,
|
|
386
|
-
totalFeesInNativeTokenPlusRatio,
|
|
387
|
-
totalNativeFees,
|
|
388
|
-
sourceChainNativeToken,
|
|
389
|
-
expressFeeCost,
|
|
390
|
-
proposedGasDestinationAmount,
|
|
391
|
-
expectedGasRefundCost,
|
|
392
|
-
totalWithRefundEstimate,
|
|
393
|
-
destChainNativeToken,
|
|
394
|
-
integratorFeeCost,
|
|
395
|
-
enoughBalanceToSwap,
|
|
396
|
-
};
|
|
397
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useSquidStore } from "@/hooks/store/useSquidStore";
|
|
2
|
-
import { useGetRoute } from "@/hooks/transaction/useGetRoute";
|
|
3
|
-
import { useMemo } from "react";
|
|
4
|
-
|
|
5
|
-
export const useEstimatePriceImpact = ({
|
|
6
|
-
squidRoute,
|
|
7
|
-
}: {
|
|
8
|
-
squidRoute: ReturnType<typeof useGetRoute>;
|
|
9
|
-
}) => {
|
|
10
|
-
const { config } = useSquidStore();
|
|
11
|
-
|
|
12
|
-
const priceImpact = useMemo(
|
|
13
|
-
() => squidRoute.data?.estimate?.aggregatePriceImpact ?? undefined,
|
|
14
|
-
[squidRoute.data?.estimate]
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
const priceImpactStatus = useMemo(() => {
|
|
18
|
-
if (config.priceImpactWarnings !== undefined && priceImpact !== undefined) {
|
|
19
|
-
if (
|
|
20
|
-
+priceImpact >= config.priceImpactWarnings.warning &&
|
|
21
|
-
+priceImpact < config.priceImpactWarnings.critical
|
|
22
|
-
) {
|
|
23
|
-
return "warning";
|
|
24
|
-
}
|
|
25
|
-
if (+priceImpact >= config.priceImpactWarnings.critical) {
|
|
26
|
-
return "critical";
|
|
27
|
-
}
|
|
28
|
-
if (+priceImpact < config.priceImpactWarnings.warning) {
|
|
29
|
-
return "normal";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return undefined;
|
|
33
|
-
}, [config.priceImpactWarnings, priceImpact]);
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
priceImpact,
|
|
37
|
-
priceImpactStatus,
|
|
38
|
-
};
|
|
39
|
-
};
|