@0xsquid/react-hooks 8.5.1-beta-stellar-tempo.0 → 8.6.0
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/core/constants.d.ts +0 -3
- package/dist/core/externalLinks.d.ts +1 -1
- package/dist/core/queries/queries-keys.d.ts +1 -1
- package/dist/core/types/config.d.ts +10 -2
- package/dist/core/types/event.d.ts +4 -0
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/swap/useUrlSwapParams.d.ts +10 -0
- package/dist/hooks/transaction/send/useEstimateSendTransactionGas.d.ts +2 -10
- package/dist/hooks/transaction/useEstimate.d.ts +12 -7
- package/dist/hooks/user/useUserParams.d.ts +4 -0
- package/dist/{index-BSX11dad.js → index-BvAot66c.js} +317 -298
- package/dist/index-BvAot66c.js.map +1 -0
- package/dist/{index-XR8ODWxH.js → index-Ck3Byj7H.js} +313 -298
- package/dist/index-Ck3Byj7H.js.map +1 -0
- package/dist/{index.es-CczeKjuj.js → index.es-83oSJcJe.js} +2 -2
- package/dist/{index.es-CczeKjuj.js.map → index.es-83oSJcJe.js.map} +1 -1
- package/dist/{index.es-CkrP1GZJ.js → index.es-C_BgGjLx.js} +2 -2
- package/dist/{index.es-CkrP1GZJ.js.map → index.es-C_BgGjLx.js.map} +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/{secretService-ChCrHmS3.js → secretService-Cj_HK_on.js} +2 -2
- package/dist/{secretService-ChCrHmS3.js.map → secretService-Cj_HK_on.js.map} +1 -1
- package/dist/{secretService-ScgDU3bX.js → secretService-zFFQM-jC.js} +2 -2
- package/dist/{secretService-ScgDU3bX.js.map → secretService-zFFQM-jC.js.map} +1 -1
- package/dist/server.d.ts +1 -0
- package/dist/server.esm.js +100 -0
- package/dist/server.esm.js.map +1 -0
- package/dist/server.js +111 -0
- package/dist/server.js.map +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/internal/assetsService.d.ts +2 -2
- package/dist/services/internal/configService.d.ts +2 -1
- package/dist/services/internal/estimateService.d.ts +28 -15
- package/dist/services/internal/eventService.d.ts +4 -0
- package/dist/services/internal/urlParamsService.d.ts +19 -0
- package/dist/{stellarService.client-D65n-wCV.js → stellarService.client-CBzr6pLs.js} +2 -2
- package/dist/{stellarService.client-D65n-wCV.js.map → stellarService.client-CBzr6pLs.js.map} +1 -1
- package/dist/{stellarService.client-BaDOSK8x.js → stellarService.client-CI86BfjV.js} +2 -2
- package/dist/{stellarService.client-BaDOSK8x.js.map → stellarService.client-CI86BfjV.js.map} +1 -1
- package/dist/tests/urlParamsService.test.d.ts +1 -0
- package/package.json +13 -1
- package/dist/hooks/tokens/useSourceChainGasToken.d.ts +0 -10
- package/dist/hooks/transaction/useTempoFeeCheck.d.ts +0 -11
- package/dist/index-BSX11dad.js.map +0 -1
- package/dist/index-XR8ODWxH.js.map +0 -1
- package/dist/services/internal/tempoService.d.ts +0 -38
|
@@ -57,7 +57,7 @@ function _interopNamespaceDefault(e) {
|
|
|
57
57
|
var bitcoin__namespace = /*#__PURE__*/_interopNamespaceDefault(bitcoin);
|
|
58
58
|
var ecc__namespace = /*#__PURE__*/_interopNamespaceDefault(ecc);
|
|
59
59
|
|
|
60
|
-
const squidApiBaseUrl = "https://api.
|
|
60
|
+
const squidApiBaseUrl = "https://v2.api.squidrouter.com";
|
|
61
61
|
|
|
62
62
|
const WALLETCONNECT_PROJECT_ID = "db6a4f6ff58e4172b2fd52f01360bc49";
|
|
63
63
|
const WALLETCONNECT_WALLET_IDS = {
|
|
@@ -145,9 +145,6 @@ const CHAIN_IDS = {
|
|
|
145
145
|
SONEIUM: "1868",
|
|
146
146
|
PEAQ: "3338",
|
|
147
147
|
HEDERA: "295",
|
|
148
|
-
MANTRA: "5888",
|
|
149
|
-
CITREA: "4114",
|
|
150
|
-
TEMPO: "4217",
|
|
151
148
|
// others
|
|
152
149
|
BITCOIN: "bitcoin",
|
|
153
150
|
SOLANA: "solana-mainnet-beta",
|
|
@@ -22412,7 +22409,7 @@ const keys = () => ({
|
|
|
22412
22409
|
// ============
|
|
22413
22410
|
// Transactions
|
|
22414
22411
|
// ============
|
|
22415
|
-
transaction: (fromChainId, toChainId, toTokenAddress, fromTokenAddress, price, slippage, sourceUserAddress, degenMode, destinationAddress, fallbackAddress, quoteOnly, fromChainType, preHook, postHook, overrideGasRefundAddress) => [
|
|
22412
|
+
transaction: (fromChainId, toChainId, toTokenAddress, fromTokenAddress, price, slippage, getGasOnDestination, sourceUserAddress, degenMode, destinationAddress, fallbackAddress, quoteOnly, fromChainType, preHook, postHook, overrideGasRefundAddress) => [
|
|
22416
22413
|
...keys().transactions(),
|
|
22417
22414
|
exports.QueryKeys.Transaction,
|
|
22418
22415
|
fromChainId,
|
|
@@ -22421,6 +22418,7 @@ const keys = () => ({
|
|
|
22421
22418
|
fromTokenAddress,
|
|
22422
22419
|
price,
|
|
22423
22420
|
slippage,
|
|
22421
|
+
getGasOnDestination,
|
|
22424
22422
|
sourceUserAddress,
|
|
22425
22423
|
degenMode,
|
|
22426
22424
|
destinationAddress,
|
|
@@ -22597,11 +22595,19 @@ const getPrefixKey = (key) => {
|
|
|
22597
22595
|
}
|
|
22598
22596
|
};
|
|
22599
22597
|
|
|
22598
|
+
const isNamedTokenConfig = (t) => "networkName" in t;
|
|
22599
|
+
const resolveChainIdFromAsset = (asset, chains) => {
|
|
22600
|
+
const chainId = isNamedTokenConfig(asset)
|
|
22601
|
+
? chains.find((c) => c.networkName.toLowerCase() === asset.networkName.toLowerCase())?.chainId
|
|
22602
|
+
: asset.chainId;
|
|
22603
|
+
return chains.some((c) => c.chainId === chainId) ? chainId : undefined;
|
|
22604
|
+
};
|
|
22600
22605
|
const getConfigWithDefaults = (config) => {
|
|
22601
22606
|
return {
|
|
22602
22607
|
integratorId: get$2(config, "integratorId", defaultConfigValues.integratorId),
|
|
22603
22608
|
slippage: get$2(config, "slippage", defaultConfigValues.slippage),
|
|
22604
22609
|
collectFees: get$2(config, "collectFees", defaultConfigValues.collectFees),
|
|
22610
|
+
enableGetGasOnDestination: get$2(config, "enableGetGasOnDestination", defaultConfigValues.enableGetGasOnDestination),
|
|
22605
22611
|
apiUrl: get$2(config, "apiUrl", defaultConfigValues.apiUrl),
|
|
22606
22612
|
priceImpactWarnings: get$2(config, "priceImpactWarnings", defaultConfigValues.priceImpactWarnings),
|
|
22607
22613
|
initialAssets: get$2(config, "initialAssets", defaultConfigValues.initialAssets),
|
|
@@ -22724,15 +22730,20 @@ const getInitialOrDefaultTokenAddressForChain = ({ tokens, config, chainId, dire
|
|
|
22724
22730
|
* @returns The initial token address if found; otherwise, the default token address.
|
|
22725
22731
|
*/
|
|
22726
22732
|
const getInitialTokenAddressForChain = ({ chainId, config, direction, tokens, unavailableTokenAddress, }) => {
|
|
22727
|
-
|
|
22728
|
-
|
|
22729
|
-
|
|
22730
|
-
|
|
22731
|
-
|
|
22732
|
-
|
|
22733
|
-
|
|
22734
|
-
|
|
22735
|
-
|
|
22733
|
+
const initialAsset = config.initialAssets?.[direction];
|
|
22734
|
+
if (!initialAsset)
|
|
22735
|
+
return undefined;
|
|
22736
|
+
if (isNamedTokenConfig(initialAsset)) {
|
|
22737
|
+
if (!initialAsset.symbol)
|
|
22738
|
+
return undefined;
|
|
22739
|
+
return tokens.find((t) => t.chainId === chainId &&
|
|
22740
|
+
t.symbol.toLowerCase() === initialAsset.symbol.toLowerCase())?.address;
|
|
22741
|
+
}
|
|
22742
|
+
if (initialAsset.chainId === chainId &&
|
|
22743
|
+
initialAsset.address !== unavailableTokenAddress &&
|
|
22744
|
+
tokens.some((t) => t.chainId === initialAsset.chainId &&
|
|
22745
|
+
t.address.toLowerCase() === initialAsset.address.toLowerCase())) {
|
|
22746
|
+
return initialAsset.address;
|
|
22736
22747
|
}
|
|
22737
22748
|
};
|
|
22738
22749
|
/**
|
|
@@ -22777,15 +22788,14 @@ const getInitialChainIdFromConfig = ({ config, direction, chains = [], }) => {
|
|
|
22777
22788
|
return undefined;
|
|
22778
22789
|
const supportedChainIds = getSupportedChainIdsForDirection(chains.map((c) => c.chainId), config, direction);
|
|
22779
22790
|
const availableChains = chains.filter((c) => supportedChainIds.includes(c.chainId));
|
|
22780
|
-
|
|
22781
|
-
|
|
22782
|
-
|
|
22783
|
-
|
|
22791
|
+
const initialAsset = config.initialAssets?.[direction];
|
|
22792
|
+
if (!initialAsset)
|
|
22793
|
+
return undefined;
|
|
22794
|
+
if (isNamedTokenConfig(initialAsset)) {
|
|
22795
|
+
return availableChains.find((c) => c.networkName.toLowerCase() === initialAsset.networkName.toLowerCase())?.chainId;
|
|
22784
22796
|
}
|
|
22785
|
-
if (
|
|
22786
|
-
|
|
22787
|
-
availableChains.some((c) => c.chainId === String(config.initialAssets?.to?.chainId))) {
|
|
22788
|
-
return String(config.initialAssets.to.chainId);
|
|
22797
|
+
if (availableChains.some((c) => c.chainId === initialAsset.chainId)) {
|
|
22798
|
+
return initialAsset.chainId;
|
|
22789
22799
|
}
|
|
22790
22800
|
return undefined;
|
|
22791
22801
|
};
|
|
@@ -23091,8 +23101,8 @@ const sortAllTokens = (tokenA, tokenB) => {
|
|
|
23091
23101
|
return 0;
|
|
23092
23102
|
};
|
|
23093
23103
|
const findToken = (tokens, chainId, address) => tokens.find((t) => t.chainId === chainId && t.address === address);
|
|
23094
|
-
const findNativeToken = (tokens, chain) => tokens.find((t) => t.symbol.toUpperCase() === chain
|
|
23095
|
-
t.chainId == chain
|
|
23104
|
+
const findNativeToken = (tokens, chain) => tokens.find((t) => t.symbol.toUpperCase() === chain?.nativeCurrency.symbol.toUpperCase() &&
|
|
23105
|
+
t.chainId == chain?.chainId);
|
|
23096
23106
|
const normalizeIbcAddress = (address) => {
|
|
23097
23107
|
if (!address.toLowerCase().startsWith("ibc/")) {
|
|
23098
23108
|
return address;
|
|
@@ -23303,7 +23313,7 @@ const filterViewableTokens = (tokens, config, direction) => {
|
|
|
23303
23313
|
};
|
|
23304
23314
|
const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
|
|
23305
23315
|
const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
|
|
23306
|
-
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-
|
|
23316
|
+
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-Cj_HK_on.js'); });
|
|
23307
23317
|
return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
|
|
23308
23318
|
};
|
|
23309
23319
|
function getTokenAssetsKey(token) {
|
|
@@ -24994,7 +25004,7 @@ class OnrampService {
|
|
|
24994
25004
|
});
|
|
24995
25005
|
return data;
|
|
24996
25006
|
}
|
|
24997
|
-
async getConfiguration({ chains
|
|
25007
|
+
async getConfiguration({ chains, tokens, }) {
|
|
24998
25008
|
const { data } = await axios.get(`${this.baseUrl}/config`);
|
|
24999
25009
|
// Filter supportedCryptos to only include tokens that match our provided tokens
|
|
25000
25010
|
const filteredCryptos = data.supportedCryptos.filter((supportedCrypto) => tokens.some((token) => token.address.toLowerCase() ===
|
|
@@ -25999,6 +26009,88 @@ function isHistoryTransactionEnded({ txType, data, }) {
|
|
|
25999
26009
|
}
|
|
26000
26010
|
}
|
|
26001
26011
|
|
|
26012
|
+
/**
|
|
26013
|
+
* Parses URL search params into an initialAssets config object.
|
|
26014
|
+
*
|
|
26015
|
+
* Supports two formats:
|
|
26016
|
+
* - Legacy: ?chains=fromId,toId&tokens=fromAddr,toAddr
|
|
26017
|
+
* - Pretty: ?fromChain=ethereum&fromToken=eth&toChain=polygon&toToken=usdc
|
|
26018
|
+
* - Collapsed chain/token: when both from/to chains or tokens are the same,
|
|
26019
|
+
* they are collapsed into a single param:
|
|
26020
|
+
* - ?chain=ethereum -> from and to chains are both ethereum
|
|
26021
|
+
* - ?token=eth -> from and to tokens are both eth
|
|
26022
|
+
*/
|
|
26023
|
+
const parseInitialAssetsFromUrl = (searchParams) => {
|
|
26024
|
+
// Legacy format
|
|
26025
|
+
if (searchParams.has("chains") || searchParams.has("tokens")) {
|
|
26026
|
+
const [fromTokenAddress, toTokenAddress] = searchParams.get("tokens")?.split(",") ?? [];
|
|
26027
|
+
const [fromChainId, toChainId] = searchParams.get("chains")?.split(",") ?? [];
|
|
26028
|
+
const from = fromChainId && fromTokenAddress
|
|
26029
|
+
? { chainId: fromChainId, address: fromTokenAddress }
|
|
26030
|
+
: undefined;
|
|
26031
|
+
const to = toChainId && toTokenAddress
|
|
26032
|
+
? { chainId: toChainId, address: toTokenAddress }
|
|
26033
|
+
: undefined;
|
|
26034
|
+
return { from, to };
|
|
26035
|
+
}
|
|
26036
|
+
// Pretty format
|
|
26037
|
+
const chainParam = searchParams.get("chain")?.toLowerCase();
|
|
26038
|
+
const tokenParam = searchParams.get("token")?.toLowerCase();
|
|
26039
|
+
const fromChainParam = searchParams.get("fromChain")?.toLowerCase() ?? chainParam;
|
|
26040
|
+
const toTokenExplicit = searchParams.get("toToken")?.toLowerCase();
|
|
26041
|
+
// ?chain=X falls back for toChain when toToken is explicit (same-chain bridge shorthand)
|
|
26042
|
+
const toChainParam = searchParams.get("toChain")?.toLowerCase() ??
|
|
26043
|
+
(toTokenExplicit ? chainParam : undefined);
|
|
26044
|
+
const fromTokenParam = searchParams.get("fromToken")?.toLowerCase() ?? tokenParam;
|
|
26045
|
+
const toTokenParam = toTokenExplicit ?? (toChainParam ? tokenParam : undefined);
|
|
26046
|
+
const from = fromChainParam
|
|
26047
|
+
? { networkName: fromChainParam, symbol: fromTokenParam }
|
|
26048
|
+
: undefined;
|
|
26049
|
+
const to = toChainParam
|
|
26050
|
+
? { networkName: toChainParam, symbol: toTokenParam }
|
|
26051
|
+
: undefined;
|
|
26052
|
+
return { from, to };
|
|
26053
|
+
};
|
|
26054
|
+
/**
|
|
26055
|
+
* Builds URL search params from a `swapParamsChanged` event detail.
|
|
26056
|
+
* Uses the pretty format, collapsing chain/token params when both sides match.
|
|
26057
|
+
*/
|
|
26058
|
+
const buildUrlSearchParamsFromSwapEvent = (swapParams) => {
|
|
26059
|
+
const fromNetworkName = swapParams.fromNetworkName?.toLowerCase();
|
|
26060
|
+
const toNetworkName = swapParams.toNetworkName?.toLowerCase();
|
|
26061
|
+
const fromTokenSymbol = swapParams.fromTokenSymbol?.toLowerCase();
|
|
26062
|
+
const toTokenSymbol = swapParams.toTokenSymbol?.toLowerCase();
|
|
26063
|
+
const params = new URLSearchParams();
|
|
26064
|
+
const bothResolved = fromNetworkName && fromTokenSymbol && toNetworkName && toTokenSymbol;
|
|
26065
|
+
if (bothResolved) {
|
|
26066
|
+
if (fromNetworkName === toNetworkName) {
|
|
26067
|
+
params.set("chain", fromNetworkName);
|
|
26068
|
+
}
|
|
26069
|
+
else {
|
|
26070
|
+
params.set("fromChain", fromNetworkName);
|
|
26071
|
+
params.set("toChain", toNetworkName);
|
|
26072
|
+
}
|
|
26073
|
+
if (fromTokenSymbol === toTokenSymbol) {
|
|
26074
|
+
params.set("token", fromTokenSymbol);
|
|
26075
|
+
}
|
|
26076
|
+
else {
|
|
26077
|
+
params.set("fromToken", fromTokenSymbol);
|
|
26078
|
+
params.set("toToken", toTokenSymbol);
|
|
26079
|
+
}
|
|
26080
|
+
}
|
|
26081
|
+
else {
|
|
26082
|
+
if (fromNetworkName && fromTokenSymbol) {
|
|
26083
|
+
params.set("fromChain", fromNetworkName);
|
|
26084
|
+
params.set("fromToken", fromTokenSymbol);
|
|
26085
|
+
}
|
|
26086
|
+
if (toNetworkName && toTokenSymbol) {
|
|
26087
|
+
params.set("toChain", toNetworkName);
|
|
26088
|
+
params.set("toToken", toTokenSymbol);
|
|
26089
|
+
}
|
|
26090
|
+
}
|
|
26091
|
+
return params;
|
|
26092
|
+
};
|
|
26093
|
+
|
|
26002
26094
|
// Memoized map to store chain data, calculated only once
|
|
26003
26095
|
let memoizedChainsByIdMap = null;
|
|
26004
26096
|
// Optimize calculation to prevent unnecessary re-renders
|
|
@@ -26619,7 +26711,7 @@ function useStellarWallets() {
|
|
|
26619
26711
|
try {
|
|
26620
26712
|
const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
|
|
26621
26713
|
const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module');
|
|
26622
|
-
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-
|
|
26714
|
+
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-CBzr6pLs.js'); });
|
|
26623
26715
|
const modules = [...initializeAllModules(), new LedgerModule()];
|
|
26624
26716
|
const promises = modules.map(async (module) => {
|
|
26625
26717
|
const isAvailable = await module.isAvailable();
|
|
@@ -27523,20 +27615,14 @@ const useSwap = () => {
|
|
|
27523
27615
|
const { tokens } = useSquidTokens();
|
|
27524
27616
|
const queryClient = reactQuery.useQueryClient();
|
|
27525
27617
|
const { chains, supportedDestinationChains, supportedSourceChains } = useSquidChains();
|
|
27526
|
-
const sourceChainId = React.useMemo(() => swapRoute?.fromChainId
|
|
27527
|
-
(
|
|
27528
|
-
initialAssets
|
|
27529
|
-
|
|
27530
|
-
|
|
27531
|
-
initialAssets?.
|
|
27532
|
-
|
|
27533
|
-
|
|
27534
|
-
(supportedDestinationChains.find((c) => c.chainId === initialAssets?.to?.chainId) &&
|
|
27535
|
-
initialAssets?.to?.chainId), [
|
|
27536
|
-
swapRoute?.toChainId,
|
|
27537
|
-
supportedDestinationChains,
|
|
27538
|
-
initialAssets?.to?.chainId,
|
|
27539
|
-
]);
|
|
27618
|
+
const sourceChainId = React.useMemo(() => swapRoute?.fromChainId ??
|
|
27619
|
+
(initialAssets?.from
|
|
27620
|
+
? resolveChainIdFromAsset(initialAssets.from, supportedSourceChains)
|
|
27621
|
+
: undefined), [swapRoute?.fromChainId, supportedSourceChains, initialAssets?.from]);
|
|
27622
|
+
const destChainId = React.useMemo(() => swapRoute?.toChainId ??
|
|
27623
|
+
(initialAssets?.to
|
|
27624
|
+
? resolveChainIdFromAsset(initialAssets.to, supportedDestinationChains)
|
|
27625
|
+
: undefined), [swapRoute?.toChainId, supportedDestinationChains, initialAssets?.to]);
|
|
27540
27626
|
const fromChain = React.useMemo(() => supportedSourceChains.find((c) => c.chainId === swapRoute?.fromChainId), [swapRoute?.fromChainId, supportedSourceChains]);
|
|
27541
27627
|
const toChain = React.useMemo(() => supportedDestinationChains.find((c) => c.chainId === swapRoute?.toChainId), [swapRoute?.toChainId, supportedDestinationChains]);
|
|
27542
27628
|
const fromTokens = React.useMemo(() => getTokensForChain(tokens, sourceChainId), [tokens, sourceChainId]);
|
|
@@ -27597,11 +27683,30 @@ const useSwap = () => {
|
|
|
27597
27683
|
queryClient,
|
|
27598
27684
|
connectedSourceAddress: connectedSourceAddress.address,
|
|
27599
27685
|
});
|
|
27686
|
+
const { fromChainId, toChainId, fromTokenAddress, toTokenAddress } = newSwapParams;
|
|
27687
|
+
const fromChainData = fromChainId
|
|
27688
|
+
? chains.find((c) => c.chainId === fromChainId)
|
|
27689
|
+
: undefined;
|
|
27690
|
+
const toChainData = toChainId
|
|
27691
|
+
? chains.find((c) => c.chainId === toChainId)
|
|
27692
|
+
: undefined;
|
|
27693
|
+
const fromTokenData = fromChainId && fromTokenAddress
|
|
27694
|
+
? tokens.find((t) => t.chainId === fromChainId &&
|
|
27695
|
+
t.address.toLowerCase() === fromTokenAddress.toLowerCase())
|
|
27696
|
+
: undefined;
|
|
27697
|
+
const toTokenData = toChainId && toTokenAddress
|
|
27698
|
+
? tokens.find((t) => t.chainId === toChainId &&
|
|
27699
|
+
t.address.toLowerCase() === toTokenAddress.toLowerCase())
|
|
27700
|
+
: undefined;
|
|
27600
27701
|
WidgetEvents.getInstance().dispatchSwapParamsChanged({
|
|
27601
|
-
fromChainId
|
|
27602
|
-
toChainId
|
|
27603
|
-
fromTokenAddress
|
|
27604
|
-
toTokenAddress
|
|
27702
|
+
fromChainId,
|
|
27703
|
+
toChainId,
|
|
27704
|
+
fromTokenAddress,
|
|
27705
|
+
toTokenAddress,
|
|
27706
|
+
fromNetworkName: fromChainData?.networkName,
|
|
27707
|
+
toNetworkName: toChainData?.networkName,
|
|
27708
|
+
fromTokenSymbol: fromTokenData?.symbol,
|
|
27709
|
+
toTokenSymbol: toTokenData?.symbol,
|
|
27605
27710
|
});
|
|
27606
27711
|
useSwapRoutePersistStore.setState({
|
|
27607
27712
|
swapRoute: newSwapParams,
|
|
@@ -29441,8 +29546,6 @@ function useNativeTokenForChain(chain) {
|
|
|
29441
29546
|
}
|
|
29442
29547
|
};
|
|
29443
29548
|
const nativeTokenForChainType = React.useMemo(() => {
|
|
29444
|
-
if (!chain)
|
|
29445
|
-
return undefined;
|
|
29446
29549
|
return findNativeToken(getTokensForChainType(), chain);
|
|
29447
29550
|
}, [chain]);
|
|
29448
29551
|
return { nativeToken: nativeTokenForChainType };
|
|
@@ -29926,7 +30029,7 @@ function hederaWalletConnect(parameters) {
|
|
|
29926
30029
|
const optionalChains = config.chains.map((x) => x.id);
|
|
29927
30030
|
if (!optionalChains.length)
|
|
29928
30031
|
return;
|
|
29929
|
-
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-
|
|
30032
|
+
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-C_BgGjLx.js'); });
|
|
29930
30033
|
const rawProvider = await EthereumProvider.init({
|
|
29931
30034
|
...restParameters,
|
|
29932
30035
|
disableProviderPing: true,
|
|
@@ -30668,6 +30771,28 @@ function useDepositAddress(squidRoute) {
|
|
|
30668
30771
|
};
|
|
30669
30772
|
}
|
|
30670
30773
|
|
|
30774
|
+
/**
|
|
30775
|
+
* Reads initial swap assets from URL params on mount, and keeps the URL in
|
|
30776
|
+
* sync with swap param changes emitted by the widget.
|
|
30777
|
+
*/
|
|
30778
|
+
const useUrlSwapParams = () => {
|
|
30779
|
+
const initialAssets = React.useMemo(() => typeof window !== "undefined"
|
|
30780
|
+
? parseInitialAssetsFromUrl(new URLSearchParams(window.location.search))
|
|
30781
|
+
: undefined, []);
|
|
30782
|
+
React.useEffect(() => {
|
|
30783
|
+
const onSwapParamsChanged = (event) => {
|
|
30784
|
+
const params = buildUrlSearchParamsFromSwapEvent(event?.detail);
|
|
30785
|
+
const qs = params.toString();
|
|
30786
|
+
history.pushState({}, "", qs ? "?" + qs : location.pathname);
|
|
30787
|
+
};
|
|
30788
|
+
WidgetEvents.getInstance().listenToWidget("swapParamsChanged", onSwapParamsChanged);
|
|
30789
|
+
return () => {
|
|
30790
|
+
WidgetEvents.getInstance().removeWidgetListener("swapParamsChanged", onSwapParamsChanged);
|
|
30791
|
+
};
|
|
30792
|
+
}, []);
|
|
30793
|
+
return { initialAssets };
|
|
30794
|
+
};
|
|
30795
|
+
|
|
30671
30796
|
const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, queryOptions, }) => {
|
|
30672
30797
|
const { evmChains, cosmosChains, suiChains, xrplChains, stellarChains } = useSquidChains(direction);
|
|
30673
30798
|
const { evmTokens, cosmosTokens, solanaTokens, bitcoinTokens, suiTokens, xrplTokens, stellarTokens, } = useSquidTokens(direction);
|
|
@@ -31052,143 +31177,6 @@ const useSingleTokenPrice = (tokenData) => {
|
|
|
31052
31177
|
return { tokenPrice, getUSDValue };
|
|
31053
31178
|
};
|
|
31054
31179
|
|
|
31055
|
-
const TEMPO_FEE_MANAGER_ADDRESS = "0xfeec000000000000000000000000000000000000";
|
|
31056
|
-
const feeManagerAbi = [
|
|
31057
|
-
{
|
|
31058
|
-
name: "userTokens",
|
|
31059
|
-
type: "function",
|
|
31060
|
-
stateMutability: "view",
|
|
31061
|
-
inputs: [{ type: "address", name: "user" }],
|
|
31062
|
-
outputs: [{ type: "address" }],
|
|
31063
|
-
},
|
|
31064
|
-
];
|
|
31065
|
-
const isTempoChain = (chainId) => chainId === CHAIN_IDS.TEMPO;
|
|
31066
|
-
/**
|
|
31067
|
-
* Convert a fee amount from virtual USD (18 decimals, attodollars)
|
|
31068
|
-
* to 6-decimal TIP-20 stablecoin units (microdollars).
|
|
31069
|
-
* All TIP-20 tokens on Tempo have 6 decimals.
|
|
31070
|
-
*/
|
|
31071
|
-
const convertTempoFeeToStablecoinUnits = (feeIn18Dec) => feeIn18Dec / BigInt(10 ** 12);
|
|
31072
|
-
|
|
31073
|
-
const BALANCE_QUERY_STALE_TIME = 10_000;
|
|
31074
|
-
/**
|
|
31075
|
-
* Returns raw on-chain gas token data for Tempo chains, or null when the source
|
|
31076
|
-
* chain is not Tempo.
|
|
31077
|
-
*/
|
|
31078
|
-
const useTempoFeeCheck = ({ fromChain, fromToken, }) => {
|
|
31079
|
-
const { connectedAddresses } = useWallet();
|
|
31080
|
-
const evmAddress = parseEvmAddress(connectedAddresses[squidTypes.ChainType.EVM]);
|
|
31081
|
-
const isTempo = isTempoChain(fromChain?.chainId);
|
|
31082
|
-
const chainId = Number(fromChain?.chainId);
|
|
31083
|
-
// Read account-level gas token preference from FeeManager precompile
|
|
31084
|
-
// See docs: https://docs.tempo.xyz/protocol/fees/spec-fee#account-level
|
|
31085
|
-
const { data: accountGasTokenAddress } = wagmi.useReadContract({
|
|
31086
|
-
address: TEMPO_FEE_MANAGER_ADDRESS,
|
|
31087
|
-
abi: feeManagerAbi,
|
|
31088
|
-
functionName: "userTokens",
|
|
31089
|
-
args: evmAddress ? [evmAddress] : undefined,
|
|
31090
|
-
chainId,
|
|
31091
|
-
query: {
|
|
31092
|
-
enabled: isTempo && !!evmAddress,
|
|
31093
|
-
staleTime: 30_000,
|
|
31094
|
-
},
|
|
31095
|
-
});
|
|
31096
|
-
const hasAccountFeePreference = !!accountGasTokenAddress &&
|
|
31097
|
-
// By default, the zero address is returned when the user has no preference set
|
|
31098
|
-
viem.zeroAddress.toLowerCase() !== accountGasTokenAddress.toLowerCase();
|
|
31099
|
-
// Fetch balance of the account-preferred gas token (if set)
|
|
31100
|
-
const { data: accountGasTokenBalance } = wagmi.useBalance({
|
|
31101
|
-
address: evmAddress,
|
|
31102
|
-
token: hasAccountFeePreference ? accountGasTokenAddress : undefined,
|
|
31103
|
-
chainId,
|
|
31104
|
-
query: {
|
|
31105
|
-
enabled: isTempo && hasAccountFeePreference && !!evmAddress,
|
|
31106
|
-
staleTime: BALANCE_QUERY_STALE_TIME,
|
|
31107
|
-
},
|
|
31108
|
-
});
|
|
31109
|
-
const fromTokenAddress = parseEvmAddress(fromToken?.address);
|
|
31110
|
-
const { data: fromTokenBalance } = wagmi.useBalance({
|
|
31111
|
-
address: evmAddress,
|
|
31112
|
-
token: fromTokenAddress,
|
|
31113
|
-
chainId,
|
|
31114
|
-
query: {
|
|
31115
|
-
enabled: isTempo && !!evmAddress,
|
|
31116
|
-
staleTime: BALANCE_QUERY_STALE_TIME,
|
|
31117
|
-
},
|
|
31118
|
-
});
|
|
31119
|
-
if (!isTempo)
|
|
31120
|
-
return null;
|
|
31121
|
-
if (hasAccountFeePreference) {
|
|
31122
|
-
if (!accountGasTokenAddress || !accountGasTokenBalance)
|
|
31123
|
-
return null;
|
|
31124
|
-
return {
|
|
31125
|
-
gasTokenAddress: accountGasTokenAddress,
|
|
31126
|
-
gasBalance: accountGasTokenBalance.value,
|
|
31127
|
-
};
|
|
31128
|
-
}
|
|
31129
|
-
if (!fromTokenAddress || !fromTokenBalance)
|
|
31130
|
-
return null;
|
|
31131
|
-
return {
|
|
31132
|
-
gasTokenAddress: fromTokenAddress,
|
|
31133
|
-
gasBalance: fromTokenBalance.value,
|
|
31134
|
-
};
|
|
31135
|
-
};
|
|
31136
|
-
|
|
31137
|
-
function useSourceChainGasToken({ fromChain, fromToken, }) {
|
|
31138
|
-
const { nativeToken } = useNativeTokenForChain(fromChain);
|
|
31139
|
-
const { evmTokens } = useSquidTokens();
|
|
31140
|
-
const { nativeBalance } = useNativeBalance(fromChain);
|
|
31141
|
-
const tempoFeeData = useTempoFeeCheck({ fromChain, fromToken });
|
|
31142
|
-
const chainFeeParams = React.useMemo(() => {
|
|
31143
|
-
if (fromToken?.address == null ||
|
|
31144
|
-
fromChain?.chainId == null ||
|
|
31145
|
-
nativeBalance?.value == null) {
|
|
31146
|
-
return null;
|
|
31147
|
-
}
|
|
31148
|
-
if (isTempoChain(fromChain.chainId)) {
|
|
31149
|
-
if (!tempoFeeData)
|
|
31150
|
-
return null;
|
|
31151
|
-
const fromTokenPaysNetworkFee = tempoFeeData.gasTokenAddress.toLowerCase() ===
|
|
31152
|
-
fromToken.address.toLowerCase();
|
|
31153
|
-
return {
|
|
31154
|
-
fromTokenPaysNetworkFee,
|
|
31155
|
-
gasTokenBalanceWei: tempoFeeData.gasBalance,
|
|
31156
|
-
normalizeFee: convertTempoFeeToStablecoinUnits,
|
|
31157
|
-
};
|
|
31158
|
-
}
|
|
31159
|
-
return {
|
|
31160
|
-
fromTokenPaysNetworkFee: fromToken.address.toLowerCase() ===
|
|
31161
|
-
chainTypeToNativeTokenAddressMap[fromToken.type].toLowerCase(),
|
|
31162
|
-
gasTokenBalanceWei: nativeBalance.value,
|
|
31163
|
-
normalizeFee: (fee) => fee,
|
|
31164
|
-
};
|
|
31165
|
-
}, [
|
|
31166
|
-
fromToken?.address,
|
|
31167
|
-
fromToken?.type,
|
|
31168
|
-
fromChain?.chainId,
|
|
31169
|
-
nativeBalance?.value,
|
|
31170
|
-
tempoFeeData,
|
|
31171
|
-
]);
|
|
31172
|
-
const gasToken = React.useMemo(() => {
|
|
31173
|
-
if (fromChain?.chainId == null || fromToken?.address == null)
|
|
31174
|
-
return undefined;
|
|
31175
|
-
if (isTempoChain(fromChain.chainId)) {
|
|
31176
|
-
if (!tempoFeeData)
|
|
31177
|
-
return undefined;
|
|
31178
|
-
return evmTokens.find((t) => t.chainId === fromChain.chainId &&
|
|
31179
|
-
t.address.toLowerCase() === tempoFeeData.gasTokenAddress.toLowerCase());
|
|
31180
|
-
}
|
|
31181
|
-
return nativeToken;
|
|
31182
|
-
}, [
|
|
31183
|
-
fromChain?.chainId,
|
|
31184
|
-
fromToken?.address,
|
|
31185
|
-
nativeToken,
|
|
31186
|
-
tempoFeeData,
|
|
31187
|
-
evmTokens,
|
|
31188
|
-
]);
|
|
31189
|
-
return { gasToken, chainFeeParams };
|
|
31190
|
-
}
|
|
31191
|
-
|
|
31192
31180
|
const MAX_COINGECKO_QUERY_TOKENS = 100;
|
|
31193
31181
|
const fetchHistoricalData = async (coingeckoId, timeFrame) => {
|
|
31194
31182
|
const now = Math.floor(Date.now() / 1000);
|
|
@@ -31339,23 +31327,24 @@ const calculateTotalNativeFees = ({ expressFeeCost, firstFeeCost, firstGasCost,
|
|
|
31339
31327
|
(sameTokenBetweenFees
|
|
31340
31328
|
? BigInt(firstFeeCost?.amount ?? "0") + BigInt(firstGasCost?.amount ?? "0")
|
|
31341
31329
|
: BigInt(firstGasCost?.amount ?? "0"));
|
|
31342
|
-
const
|
|
31343
|
-
|
|
31344
|
-
|
|
31345
|
-
|
|
31346
|
-
|
|
31347
|
-
|
|
31348
|
-
|
|
31349
|
-
|
|
31350
|
-
|
|
31351
|
-
|
|
31352
|
-
|
|
31353
|
-
|
|
31354
|
-
|
|
31355
|
-
|
|
31356
|
-
|
|
31357
|
-
|
|
31358
|
-
}
|
|
31330
|
+
const isFromBalanceEnoughToSwap = ({ isFromTokenNative, fromAmount, totalFeesInNativeTokenPlusRatio, nativeTokenBalanceFromChainWei, }) => {
|
|
31331
|
+
const fromAmountBigInt = BigInt(fromAmount ?? "0");
|
|
31332
|
+
const totalFeesInNativeTokenPlusRatioBigInt = totalFeesInNativeTokenPlusRatio;
|
|
31333
|
+
const nativeTokenBalanceFromChainWeiBigInt = nativeTokenBalanceFromChainWei;
|
|
31334
|
+
return isFromTokenNative
|
|
31335
|
+
? fromAmountBigInt + totalFeesInNativeTokenPlusRatioBigInt <=
|
|
31336
|
+
nativeTokenBalanceFromChainWeiBigInt
|
|
31337
|
+
: totalFeesInNativeTokenPlusRatioBigInt <=
|
|
31338
|
+
nativeTokenBalanceFromChainWeiBigInt;
|
|
31339
|
+
};
|
|
31340
|
+
const calculateMinAmountValueWarnMsg = ({ isFromTokenNative, nativeTokenBalanceFromChainWei, sourceChainNativeTokenDecimals, totalFeesInNativeTokenPlusRatio, }) => isFromTokenNative
|
|
31341
|
+
? (() => {
|
|
31342
|
+
const minAmount = nativeTokenBalanceFromChainWei - totalFeesInNativeTokenPlusRatio;
|
|
31343
|
+
return minAmount > BigInt(0)
|
|
31344
|
+
? formatBNToReadable(minAmount, sourceChainNativeTokenDecimals)
|
|
31345
|
+
: "0";
|
|
31346
|
+
})()
|
|
31347
|
+
: undefined;
|
|
31359
31348
|
/**
|
|
31360
31349
|
* Calculates the estimated duration of a route
|
|
31361
31350
|
*
|
|
@@ -31394,10 +31383,12 @@ const formatEstimatedRouteDuration = ({ estimatedRouteDuration, isSingleChainRou
|
|
|
31394
31383
|
* @returns {Object} An object containing various estimate results and calculations, including token information,
|
|
31395
31384
|
* amounts, fees, gas costs, and other relevant data for the transaction.
|
|
31396
31385
|
*/
|
|
31397
|
-
const calculateEstimateResults = ({ squidRoute, tokens, fromChain, toChain, collectFees,
|
|
31386
|
+
const calculateEstimateResults = ({ squidRoute, tokens, fromChain, toChain, collectFees, nativeTokenBalanceFromChainWei, }) => {
|
|
31398
31387
|
const fromToken = findToken(tokens, squidRoute?.params.fromChain, squidRoute?.params.fromToken);
|
|
31399
31388
|
const fromAmount = squidRoute?.estimate?.fromAmount;
|
|
31400
31389
|
const fromAmountFormatted = formatAmount(fromAmount, fromToken?.decimals);
|
|
31390
|
+
const sourceChainNativeToken = findNativeToken(tokens, fromChain);
|
|
31391
|
+
const destChainNativeToken = findNativeToken(tokens, toChain);
|
|
31401
31392
|
const toAmountUSD = squidRoute?.estimate?.toAmountUSD;
|
|
31402
31393
|
const exchangeRate = squidRoute?.estimate.exchangeRate ?? "0";
|
|
31403
31394
|
const toAmountMinUSD = squidRoute?.estimate.toAmountMinUSD ?? "0";
|
|
@@ -31416,6 +31407,10 @@ const calculateEstimateResults = ({ squidRoute, tokens, fromChain, toChain, coll
|
|
|
31416
31407
|
const expectedGasRefundCostUSD = convertTokenAmountToUSD(formatBNToReadable(expectedGasRefundCost, firstFeeCost?.token.decimals ?? 18), firstFeeCost?.token.usdPrice ?? "0");
|
|
31417
31408
|
const sameTokenBetweenFees = firstFeeCost?.token.address === firstGasCost?.token.address &&
|
|
31418
31409
|
firstFeeCost?.token.chainId === firstGasCost?.token.chainId;
|
|
31410
|
+
const isFromTokenNative =
|
|
31411
|
+
// TODO: temporary fix, currently nativeCurrency.symbol is not always in uppercase
|
|
31412
|
+
fromToken?.symbol.toUpperCase() ===
|
|
31413
|
+
fromChain?.nativeCurrency.symbol.toUpperCase();
|
|
31419
31414
|
const totalNativeFees = calculateTotalNativeFees({
|
|
31420
31415
|
expressFeeCost,
|
|
31421
31416
|
firstFeeCost,
|
|
@@ -31423,32 +31418,30 @@ const calculateEstimateResults = ({ squidRoute, tokens, fromChain, toChain, coll
|
|
|
31423
31418
|
sameTokenBetweenFees,
|
|
31424
31419
|
});
|
|
31425
31420
|
const totalFeesInNativeTokenPlusRatio = (totalNativeFees * BigInt(110)) / BigInt(100);
|
|
31426
|
-
const
|
|
31427
|
-
|
|
31428
|
-
chainFeeParams,
|
|
31421
|
+
const fromBalanceEnoughToSwap = isFromBalanceEnoughToSwap({
|
|
31422
|
+
isFromTokenNative,
|
|
31429
31423
|
fromAmount,
|
|
31430
|
-
|
|
31424
|
+
fromTokenDecimals: fromToken?.decimals,
|
|
31425
|
+
totalFeesInNativeTokenPlusRatio,
|
|
31426
|
+
nativeTokenBalanceFromChainWei,
|
|
31431
31427
|
});
|
|
31432
31428
|
const minAmountValueWarnMsg = calculateMinAmountValueWarnMsg({
|
|
31433
|
-
|
|
31434
|
-
|
|
31435
|
-
|
|
31429
|
+
isFromTokenNative,
|
|
31430
|
+
nativeTokenBalanceFromChainWei,
|
|
31431
|
+
sourceChainNativeTokenDecimals: sourceChainNativeToken?.decimals,
|
|
31432
|
+
totalFeesInNativeTokenPlusRatio,
|
|
31436
31433
|
});
|
|
31437
31434
|
const isSingleChainRoute = fromChain?.chainId === toChain?.chainId;
|
|
31438
31435
|
const estimatedRouteDuration = formatEstimatedRouteDuration({
|
|
31439
31436
|
estimatedRouteDuration: squidRoute?.estimate?.estimatedRouteDuration,
|
|
31440
31437
|
isSingleChainRoute,
|
|
31441
31438
|
});
|
|
31442
|
-
// native fees + fromAmount (if native)
|
|
31443
|
-
const totalGasBalanceNeeded = networkFeesWei +
|
|
31444
|
-
BigInt(chainFeeParams?.fromTokenPaysNetworkFee ? fromAmount ?? 0 : 0);
|
|
31445
|
-
const gasBalanceNeeded = gasToken
|
|
31446
|
-
? formatBNToReadable(totalGasBalanceNeeded, gasToken.decimals)
|
|
31447
|
-
: undefined;
|
|
31448
31439
|
return {
|
|
31449
31440
|
fromToken,
|
|
31450
31441
|
fromAmount,
|
|
31451
31442
|
fromAmountFormatted,
|
|
31443
|
+
sourceChainNativeToken,
|
|
31444
|
+
destChainNativeToken,
|
|
31452
31445
|
toAmountUSD,
|
|
31453
31446
|
exchangeRate,
|
|
31454
31447
|
toAmountMinUSD,
|
|
@@ -31463,12 +31456,12 @@ const calculateEstimateResults = ({ squidRoute, tokens, fromChain, toChain, coll
|
|
|
31463
31456
|
expectedGasRefundCost,
|
|
31464
31457
|
expectedGasRefundCostUSD,
|
|
31465
31458
|
sameTokenBetweenFees,
|
|
31466
|
-
|
|
31459
|
+
isFromTokenNative,
|
|
31467
31460
|
totalNativeFees,
|
|
31468
|
-
|
|
31461
|
+
totalFeesInNativeTokenPlusRatio,
|
|
31462
|
+
fromBalanceEnoughToSwap,
|
|
31469
31463
|
minAmountValueWarnMsg,
|
|
31470
31464
|
estimatedRouteDuration,
|
|
31471
|
-
gasBalanceNeeded,
|
|
31472
31465
|
};
|
|
31473
31466
|
};
|
|
31474
31467
|
/**
|
|
@@ -31502,6 +31495,28 @@ const calculateTotalWithRefundEstimate = (allFeeCosts, expectedGasRefundCost, ge
|
|
|
31502
31495
|
feeToken: firstFeeCost?.token,
|
|
31503
31496
|
};
|
|
31504
31497
|
};
|
|
31498
|
+
/**
|
|
31499
|
+
* Calculates the proposed gas amount for the destination chain.
|
|
31500
|
+
*
|
|
31501
|
+
* @param destChainNativeToken - The symbol of the native token for the destination chain.
|
|
31502
|
+
* @returns An object containing the proposed gas amount value and the currency symbol.
|
|
31503
|
+
*/
|
|
31504
|
+
const getProposedGasDestinationAmount = (destChainNativeToken) => {
|
|
31505
|
+
const gasAmounts = {
|
|
31506
|
+
GLMR: 5.289,
|
|
31507
|
+
ETH: 0.0009,
|
|
31508
|
+
AVAX: 0.115,
|
|
31509
|
+
BNB: 0.00425,
|
|
31510
|
+
FTM: 4.45,
|
|
31511
|
+
CELO: 3.052,
|
|
31512
|
+
KAVA: 2.339,
|
|
31513
|
+
MATIC: 1.795,
|
|
31514
|
+
};
|
|
31515
|
+
return {
|
|
31516
|
+
value: gasAmounts[destChainNativeToken ?? ""] ?? 0,
|
|
31517
|
+
currency: destChainNativeToken,
|
|
31518
|
+
};
|
|
31519
|
+
};
|
|
31505
31520
|
|
|
31506
31521
|
function useSendTransactionGas({ chain, token, from, }) {
|
|
31507
31522
|
return reactQuery.useQuery({
|
|
@@ -31523,11 +31538,7 @@ function useSendTransactionGas({ chain, token, from, }) {
|
|
|
31523
31538
|
// Some RPC providers require the sender to have enough balance, otherwise estimation reverts
|
|
31524
31539
|
// so we'll try to use the user provided address when possible
|
|
31525
31540
|
const sender = from || dummyAddress;
|
|
31526
|
-
|
|
31527
|
-
// We can simulate an ERC20 transfer instead
|
|
31528
|
-
const supportsNativeTransfers = chain.chainId !== CHAIN_IDS.TEMPO;
|
|
31529
|
-
const isNativeToken = token.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase();
|
|
31530
|
-
if (isNativeToken && supportsNativeTransfers) {
|
|
31541
|
+
if (token.address.toLowerCase() === nativeEvmTokenAddress.toLowerCase()) {
|
|
31531
31542
|
const gas = await client.estimateGas({
|
|
31532
31543
|
from: sender,
|
|
31533
31544
|
to: dummyAddress,
|
|
@@ -31547,14 +31558,7 @@ function useSendTransactionGas({ chain, token, from, }) {
|
|
|
31547
31558
|
data,
|
|
31548
31559
|
chainId: chain.chainId,
|
|
31549
31560
|
});
|
|
31550
|
-
|
|
31551
|
-
// Tempo fees are denominated in virtual USD (18 dec, 1e-18 USD units).
|
|
31552
|
-
// Convert to 6-dec stablecoin units so all callers receive a
|
|
31553
|
-
// consistent unit without needing to know about the chain.
|
|
31554
|
-
if (chain.chainId === CHAIN_IDS.TEMPO) {
|
|
31555
|
-
return convertTempoFeeToStablecoinUnits(feeWei);
|
|
31556
|
-
}
|
|
31557
|
-
return feeWei;
|
|
31561
|
+
return gas * maxFeePerGas;
|
|
31558
31562
|
}
|
|
31559
31563
|
case squidTypes.ChainType.COSMOS: {
|
|
31560
31564
|
// TODO: get gas estimation from backend
|
|
@@ -31601,33 +31605,19 @@ function useEstimateSendTransaction({ chain, token, amount, balance, from, }) {
|
|
|
31601
31605
|
token,
|
|
31602
31606
|
from,
|
|
31603
31607
|
});
|
|
31604
|
-
const {
|
|
31605
|
-
|
|
31606
|
-
|
|
31607
|
-
});
|
|
31608
|
-
const gasBalanceEnough = React.useMemo(() => {
|
|
31609
|
-
if (!amount || !token?.decimals)
|
|
31608
|
+
const { nativeBalance } = useNativeBalance(chain);
|
|
31609
|
+
const isNativeBalanceEnoughToPayGasFees = React.useMemo(() => {
|
|
31610
|
+
if (!nativeBalance?.value || !amount || !token?.decimals) {
|
|
31610
31611
|
return false;
|
|
31611
|
-
|
|
31612
|
-
|
|
31613
|
-
|
|
31614
|
-
|
|
31615
|
-
|
|
31616
|
-
|
|
31617
|
-
|
|
31618
|
-
|
|
31619
|
-
|
|
31620
|
-
// native fees + fromAmount (if native)
|
|
31621
|
-
const totalGasBalanceNeeded = estimatedGas +
|
|
31622
|
-
parseToBigInt(chainFeeParams?.fromTokenPaysNetworkFee ? amount ?? "0" : "0", token.decimals);
|
|
31623
|
-
return formatBNToReadable(totalGasBalanceNeeded, gasToken.decimals);
|
|
31624
|
-
}, [
|
|
31625
|
-
amount,
|
|
31626
|
-
chainFeeParams?.fromTokenPaysNetworkFee,
|
|
31627
|
-
estimatedGas,
|
|
31628
|
-
gasToken?.decimals,
|
|
31629
|
-
token?.decimals,
|
|
31630
|
-
]);
|
|
31612
|
+
}
|
|
31613
|
+
const isTokenNative = token.address.toLowerCase() ===
|
|
31614
|
+
chainTypeToNativeTokenAddressMap[token.type].toLowerCase();
|
|
31615
|
+
if (isTokenNative) {
|
|
31616
|
+
return (parseToBigInt(amount, token.decimals) + estimatedGas <=
|
|
31617
|
+
nativeBalance.value);
|
|
31618
|
+
}
|
|
31619
|
+
return estimatedGas <= nativeBalance.value;
|
|
31620
|
+
}, [amount, estimatedGas, nativeBalance?.value, token]);
|
|
31631
31621
|
const isBalanceEnough = React.useMemo(() => {
|
|
31632
31622
|
if (token?.decimals == null || !balance || !amount)
|
|
31633
31623
|
return false;
|
|
@@ -31635,21 +31625,28 @@ function useEstimateSendTransaction({ chain, token, amount, balance, from, }) {
|
|
|
31635
31625
|
parseToBigInt(amount, token.decimals));
|
|
31636
31626
|
}, [amount, balance, token?.decimals]);
|
|
31637
31627
|
const minAmountValueWarnMsg = React.useMemo(() => {
|
|
31638
|
-
if (!token?.address || !
|
|
31628
|
+
if (!token?.address || !nativeBalance?.value || !estimatedGas)
|
|
31639
31629
|
return undefined;
|
|
31630
|
+
const isFromTokenNative = token.address.toLowerCase() ===
|
|
31631
|
+
chainTypeToNativeTokenAddressMap[token.type].toLowerCase();
|
|
31640
31632
|
return calculateMinAmountValueWarnMsg({
|
|
31641
|
-
|
|
31642
|
-
|
|
31643
|
-
|
|
31633
|
+
isFromTokenNative,
|
|
31634
|
+
nativeTokenBalanceFromChainWei: nativeBalance.value,
|
|
31635
|
+
sourceChainNativeTokenDecimals: nativeBalance.decimals,
|
|
31636
|
+
totalFeesInNativeTokenPlusRatio: estimatedGas,
|
|
31644
31637
|
});
|
|
31645
|
-
}, [
|
|
31638
|
+
}, [
|
|
31639
|
+
estimatedGas,
|
|
31640
|
+
nativeBalance?.decimals,
|
|
31641
|
+
nativeBalance?.value,
|
|
31642
|
+
token?.address,
|
|
31643
|
+
token?.type,
|
|
31644
|
+
]);
|
|
31646
31645
|
return {
|
|
31647
31646
|
estimatedGas,
|
|
31648
|
-
gasBalanceNeeded,
|
|
31649
31647
|
isBalanceEnough,
|
|
31650
|
-
tokenPaysNetworkFee: chainFeeParams?.fromTokenPaysNetworkFee ?? false,
|
|
31651
31648
|
isLoading,
|
|
31652
|
-
|
|
31649
|
+
isNativeBalanceEnoughToPayGasFees,
|
|
31653
31650
|
minAmountValueWarnMsg,
|
|
31654
31651
|
};
|
|
31655
31652
|
}
|
|
@@ -32711,7 +32708,7 @@ const useApproval = ({ squidRoute, }) => {
|
|
|
32711
32708
|
// This is to ensure we're using the latest expiry timestamp
|
|
32712
32709
|
if (squidRoute) {
|
|
32713
32710
|
queryClient.refetchQueries({
|
|
32714
|
-
queryKey: keys().transaction(squidRoute.params.fromChain, squidRoute.params.toChain, squidRoute.params.toToken, squidRoute.params.fromToken, fromPrice, squidRoute.params.slippage, squidRoute.params.fromAddress, squidRoute.params.bypassGuardrails, squidRoute.params.toAddress, squidRoute.params.fallbackAddresses?.[0]?.address, squidRoute.params.quoteOnly, getChainType(squidRoute.params.fromChain), squidRoute.params.preHook, squidRoute.params.postHook,
|
|
32711
|
+
queryKey: keys().transaction(squidRoute.params.fromChain, squidRoute.params.toChain, squidRoute.params.toToken, squidRoute.params.fromToken, fromPrice, squidRoute.params.slippage, squidRoute.params.receiveGasOnDestination, squidRoute.params.fromAddress, squidRoute.params.bypassGuardrails, squidRoute.params.toAddress, squidRoute.params.fallbackAddresses?.[0]?.address, squidRoute.params.quoteOnly, getChainType(squidRoute.params.fromChain), squidRoute.params.preHook, squidRoute.params.postHook,
|
|
32715
32712
|
// TODO: update types
|
|
32716
32713
|
squidRoute.params?.overrideGasRefundAddress),
|
|
32717
32714
|
});
|
|
@@ -32730,30 +32727,17 @@ const AXELAR_PROVIDER_IMAGE_URL = "https://raw.githubusercontent.com/0xsquid/ass
|
|
|
32730
32727
|
const useEstimate = (squidRoute) => {
|
|
32731
32728
|
const collectFees = useConfigStore((state) => state.config.collectFees);
|
|
32732
32729
|
const { tokens } = useSquidTokens();
|
|
32733
|
-
const { fromChain, toChain
|
|
32734
|
-
const
|
|
32735
|
-
const { chainFeeParams, gasToken } = useSourceChainGasToken({
|
|
32736
|
-
fromChain,
|
|
32737
|
-
fromToken,
|
|
32738
|
-
});
|
|
32730
|
+
const { fromChain, toChain } = useSwap();
|
|
32731
|
+
const { nativeBalance } = useNativeBalance(fromChain);
|
|
32739
32732
|
const estimateResults = React.useMemo(() => calculateEstimateResults({
|
|
32740
32733
|
squidRoute,
|
|
32741
32734
|
tokens,
|
|
32742
32735
|
fromChain,
|
|
32743
32736
|
toChain,
|
|
32744
32737
|
collectFees: !!collectFees && collectFees.fee > 0,
|
|
32745
|
-
|
|
32746
|
-
|
|
32747
|
-
|
|
32748
|
-
squidRoute,
|
|
32749
|
-
tokens,
|
|
32750
|
-
fromChain,
|
|
32751
|
-
toChain,
|
|
32752
|
-
collectFees,
|
|
32753
|
-
chainFeeParams,
|
|
32754
|
-
gasToken,
|
|
32755
|
-
]);
|
|
32756
|
-
const fromBalanceFormatted = useMultiChainBalance({
|
|
32738
|
+
nativeTokenBalanceFromChainWei: nativeBalance?.value ?? BigInt("0"),
|
|
32739
|
+
}), [squidRoute, tokens, fromChain, toChain, collectFees, nativeBalance]);
|
|
32740
|
+
const balanceFormatted = useMultiChainBalance({
|
|
32757
32741
|
chain: fromChain,
|
|
32758
32742
|
token: estimateResults.fromToken,
|
|
32759
32743
|
userAddress: squidRoute?.params.fromAddress ?? "",
|
|
@@ -32765,6 +32749,7 @@ const useEstimate = (squidRoute) => {
|
|
|
32765
32749
|
estimateResults.expectedGasRefundCost,
|
|
32766
32750
|
getUSDValue,
|
|
32767
32751
|
]);
|
|
32752
|
+
const proposedGasDestinationAmount = React.useMemo(() => getProposedGasDestinationAmount(estimateResults.destChainNativeToken?.symbol), [estimateResults.destChainNativeToken]);
|
|
32768
32753
|
const { feeCostsFormatted, totalFeeCostsUsd } = React.useMemo(() => {
|
|
32769
32754
|
const feeCosts = squidRoute?.estimate.feeCosts ?? [];
|
|
32770
32755
|
const feeCostsRenamed = [];
|
|
@@ -32823,21 +32808,21 @@ const useEstimate = (squidRoute) => {
|
|
|
32823
32808
|
totalFeeCostsUsd: totalFeeCostsUsdFormatted,
|
|
32824
32809
|
};
|
|
32825
32810
|
}, [squidRoute?.estimate.feeCosts]);
|
|
32826
|
-
const slippageFormatted =
|
|
32827
|
-
|
|
32828
|
-
|
|
32829
|
-
|
|
32830
|
-
|
|
32831
|
-
|
|
32811
|
+
const slippageFormatted =
|
|
32812
|
+
// TODO: update types
|
|
32813
|
+
Number(squidRoute?.estimate?.aggregateSlippage ?? 0).toFixed(2) +
|
|
32814
|
+
"%";
|
|
32815
|
+
const enoughBalanceToSwap = +balanceFormatted >= 0 &&
|
|
32816
|
+
+balanceFormatted > +estimateResults.fromAmountFormatted;
|
|
32832
32817
|
return {
|
|
32833
32818
|
...estimateResults,
|
|
32834
|
-
|
|
32819
|
+
balanceFormatted,
|
|
32835
32820
|
slippageFormatted,
|
|
32836
32821
|
totalWithRefundEstimate,
|
|
32837
|
-
|
|
32822
|
+
proposedGasDestinationAmount,
|
|
32823
|
+
enoughBalanceToSwap,
|
|
32838
32824
|
feeCostsFormatted,
|
|
32839
32825
|
totalFeeCostsUsd,
|
|
32840
|
-
gasToken,
|
|
32841
32826
|
};
|
|
32842
32827
|
};
|
|
32843
32828
|
|
|
@@ -36605,7 +36590,7 @@ const useGetRoute = () => {
|
|
|
36605
36590
|
});
|
|
36606
36591
|
// Cache the route data
|
|
36607
36592
|
// Useful when the getRoute mutation is called from another hook
|
|
36608
|
-
queryClient.setQueryData(keys().transaction(fromChain, toChain, toToken.address, fromToken.address, fromPrice, config.slippage, sourceUserAddress, config.degenMode, destinationAddress, swapRoute?.fallbackAddress, quoteOnly, fromChainType, config.preHook, config.postHook, overrideGasRefundAddress), route);
|
|
36593
|
+
queryClient.setQueryData(keys().transaction(fromChain, toChain, toToken.address, fromToken.address, fromPrice, config.slippage, config.enableGetGasOnDestination, sourceUserAddress, config.degenMode, destinationAddress, swapRoute?.fallbackAddress, quoteOnly, fromChainType, config.preHook, config.postHook, overrideGasRefundAddress), route);
|
|
36609
36594
|
return route;
|
|
36610
36595
|
});
|
|
36611
36596
|
};
|
|
@@ -36628,13 +36613,14 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
|
|
|
36628
36613
|
const sourceUserAddress = isDepositAddressEnabled && isAvailableAsPaymentMethod
|
|
36629
36614
|
? depositRefundAddress ?? sourceConnectedAddress
|
|
36630
36615
|
: sourceConnectedAddress;
|
|
36631
|
-
const squidRouteQueryKeys = React.useMemo(() => keys().transaction(fromChain?.chainId, toChain?.chainId, toToken?.address, fromToken?.address, fromPrice, config.slippage, sourceUserAddress, config.degenMode, destinationAddress, fallbackAddress, quoteOnly, fromChain?.chainType, config.preHook, config.postHook, config.overrideGasRefundAddress), [
|
|
36616
|
+
const squidRouteQueryKeys = React.useMemo(() => keys().transaction(fromChain?.chainId, toChain?.chainId, toToken?.address, fromToken?.address, fromPrice, config.slippage, config.enableGetGasOnDestination, sourceUserAddress, config.degenMode, destinationAddress, fallbackAddress, quoteOnly, fromChain?.chainType, config.preHook, config.postHook, config.overrideGasRefundAddress), [
|
|
36632
36617
|
fromChain?.chainId,
|
|
36633
36618
|
toChain?.chainId,
|
|
36634
36619
|
toToken?.address,
|
|
36635
36620
|
fromToken?.address,
|
|
36636
36621
|
fromPrice,
|
|
36637
36622
|
config.slippage,
|
|
36623
|
+
config.enableGetGasOnDestination,
|
|
36638
36624
|
sourceUserAddress,
|
|
36639
36625
|
config.degenMode,
|
|
36640
36626
|
destinationAddress,
|
|
@@ -36906,6 +36892,35 @@ const useAvatar = (seed = zeroAddress) => {
|
|
|
36906
36892
|
return avatar || "";
|
|
36907
36893
|
};
|
|
36908
36894
|
|
|
36895
|
+
const useUserParams = () => {
|
|
36896
|
+
const enableGetGasOnDestination = useConfigStore((state) => state.config.enableGetGasOnDestination);
|
|
36897
|
+
const { fromToken, toToken, toChain, fromChain } = useSwap();
|
|
36898
|
+
// =============
|
|
36899
|
+
// GAS
|
|
36900
|
+
// =============
|
|
36901
|
+
const getGasOnDestSupportedForThisRoute = React.useMemo(() =>
|
|
36902
|
+
// Not supporting get gas on dest for same chains
|
|
36903
|
+
fromChain?.chainId !== toChain?.chainId &&
|
|
36904
|
+
// If the destination chain is cosmos, we don't support getting gas there
|
|
36905
|
+
toChain?.chainType !== squidTypes.ChainType.COSMOS &&
|
|
36906
|
+
// Not supporting get gas on dest for same tokens (bridge)
|
|
36907
|
+
((fromToken?.subGraphIds?.some((sgi) => !!toToken?.subGraphIds?.includes(sgi)) &&
|
|
36908
|
+
toToken?.subGraphIds?.some((sgi) => !!fromToken?.subGraphIds?.includes(sgi))) ||
|
|
36909
|
+
// Except for uusdc -> uusdc
|
|
36910
|
+
(fromToken?.subGraphIds?.includes("uusdc") &&
|
|
36911
|
+
toToken?.subGraphIds?.includes("uusdc"))), [
|
|
36912
|
+
fromChain?.chainId,
|
|
36913
|
+
fromToken?.subGraphIds,
|
|
36914
|
+
toChain?.chainId,
|
|
36915
|
+
toToken?.subGraphIds,
|
|
36916
|
+
toChain?.chainType,
|
|
36917
|
+
]);
|
|
36918
|
+
return {
|
|
36919
|
+
gasEnabled: enableGetGasOnDestination && getGasOnDestSupportedForThisRoute,
|
|
36920
|
+
getGasOnDestSupportedForThisRoute,
|
|
36921
|
+
};
|
|
36922
|
+
};
|
|
36923
|
+
|
|
36909
36924
|
const useAddToken = (chainToCompare, tokenToCompare) => {
|
|
36910
36925
|
const { chain: currentEvmChain } = wagmi.useAccount();
|
|
36911
36926
|
const { connector } = wagmi.useAccount();
|
|
@@ -37353,6 +37368,7 @@ exports.addTokenToWallet = addTokenToWallet;
|
|
|
37353
37368
|
exports.areSameAddress = areSameAddress;
|
|
37354
37369
|
exports.areTokenSymbolsCompatible = areTokenSymbolsCompatible;
|
|
37355
37370
|
exports.assetsBaseUrl = assetsBaseUrl;
|
|
37371
|
+
exports.buildUrlSearchParamsFromSwapEvent = buildUrlSearchParamsFromSwapEvent;
|
|
37356
37372
|
exports.buildXrplTrustSetTx = buildXrplTrustSetTx;
|
|
37357
37373
|
exports.calculateTotal24hChange = calculateTotal24hChange;
|
|
37358
37374
|
exports.calculateTotalUsdBalanceUSD = calculateTotalUsdBalanceUSD;
|
|
@@ -37485,12 +37501,14 @@ exports.normalizeError = normalizeError;
|
|
|
37485
37501
|
exports.normalizeIbcAddress = normalizeIbcAddress;
|
|
37486
37502
|
exports.normalizeTokenSymbol = normalizeTokenSymbol;
|
|
37487
37503
|
exports.parseEvmAddress = parseEvmAddress;
|
|
37504
|
+
exports.parseInitialAssetsFromUrl = parseInitialAssetsFromUrl;
|
|
37488
37505
|
exports.parseToBigInt = parseToBigInt;
|
|
37489
37506
|
exports.parseXrplPaymentTx = parseXrplPaymentTx;
|
|
37490
37507
|
exports.parseXrplTokenAddress = parseXrplTokenAddress;
|
|
37491
37508
|
exports.populateWallets = populateWallets;
|
|
37492
37509
|
exports.randomIntFromInterval = randomIntFromInterval;
|
|
37493
37510
|
exports.redirectToExtensionsStore = redirectToExtensionsStore;
|
|
37511
|
+
exports.resolveChainIdFromAsset = resolveChainIdFromAsset;
|
|
37494
37512
|
exports.roundNumericValue = roundNumericValue;
|
|
37495
37513
|
exports.scaleHbarToWei = scaleHbarToWei;
|
|
37496
37514
|
exports.scaleWeiToHbar = scaleWeiToHbar;
|
|
@@ -37567,7 +37585,6 @@ exports.useSendTransactionStore = useSendTransactionStore;
|
|
|
37567
37585
|
exports.useSigner = useSigner;
|
|
37568
37586
|
exports.useSingleTokenPrice = useSingleTokenPrice;
|
|
37569
37587
|
exports.useSolanaNativeBalance = useSolanaNativeBalance;
|
|
37570
|
-
exports.useSourceChainGasToken = useSourceChainGasToken;
|
|
37571
37588
|
exports.useSquid = useSquid;
|
|
37572
37589
|
exports.useSquidChains = useSquidChains;
|
|
37573
37590
|
exports.useSquidQueryClient = useSquidQueryClient;
|
|
@@ -37584,6 +37601,8 @@ exports.useSwapTransactionStatus = useSwapTransactionStatus;
|
|
|
37584
37601
|
exports.useTokensData = useTokensData;
|
|
37585
37602
|
exports.useTrackSearchEmpty = useTrackSearchEmpty;
|
|
37586
37603
|
exports.useTransactionStore = useTransactionStore;
|
|
37604
|
+
exports.useUrlSwapParams = useUrlSwapParams;
|
|
37605
|
+
exports.useUserParams = useUserParams;
|
|
37587
37606
|
exports.useWallet = useWallet;
|
|
37588
37607
|
exports.useWalletStore = useWalletStore;
|
|
37589
37608
|
exports.useWallets = useWallets;
|
|
@@ -37592,4 +37611,4 @@ exports.useXrplTrustLine = useXrplTrustLine;
|
|
|
37592
37611
|
exports.waitForReceiptWithRetry = waitForReceiptWithRetry;
|
|
37593
37612
|
exports.walletIconBaseUrl = walletIconBaseUrl;
|
|
37594
37613
|
exports.walletSupportsChainType = walletSupportsChainType;
|
|
37595
|
-
//# sourceMappingURL=index-
|
|
37614
|
+
//# sourceMappingURL=index-BvAot66c.js.map
|