@0xsquid/react-hooks 8.4.1-beta-onchain-exec-with-sig.0 → 8.4.1-beta-interactive-to-amount.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.
Files changed (28) hide show
  1. package/dist/core/queries/queries-keys.d.ts +1 -1
  2. package/dist/core/types/route.d.ts +1 -1
  3. package/dist/hooks/store/useSquidStore.d.ts +2 -1
  4. package/dist/hooks/swap/useSwap.d.ts +4 -2
  5. package/dist/hooks/transaction/useGetRoute.d.ts +1 -0
  6. package/dist/{index-D3m1pR9o.js → index-Bg7CS2Uo.js} +54 -28
  7. package/dist/index-Bg7CS2Uo.js.map +1 -0
  8. package/dist/{index-BwyqlDlg.js → index-DnkELFs9.js} +54 -29
  9. package/dist/index-DnkELFs9.js.map +1 -0
  10. package/dist/{index.es-BxbRmlQ1.js → index.es-BQGUcysL.js} +2 -2
  11. package/dist/{index.es-BxbRmlQ1.js.map → index.es-BQGUcysL.js.map} +1 -1
  12. package/dist/{index.es-BqHGfsIC.js → index.es-tWag56u3.js} +2 -2
  13. package/dist/{index.es-BqHGfsIC.js.map → index.es-tWag56u3.js.map} +1 -1
  14. package/dist/index.esm.js +1 -1
  15. package/dist/index.js +2 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/{secretService-y3m09F3S.js → secretService-BXleHutG.js} +2 -2
  18. package/dist/{secretService-y3m09F3S.js.map → secretService-BXleHutG.js.map} +1 -1
  19. package/dist/{secretService-CpimyAc7.js → secretService-Bs5SPC6i.js} +2 -2
  20. package/dist/{secretService-CpimyAc7.js.map → secretService-Bs5SPC6i.js.map} +1 -1
  21. package/dist/services/internal/transactionService.d.ts +7 -0
  22. package/dist/{stellarService.client-BYqhRu1u.js → stellarService.client-TTYw1-aB.js} +2 -2
  23. package/dist/{stellarService.client-BYqhRu1u.js.map → stellarService.client-TTYw1-aB.js.map} +1 -1
  24. package/dist/{stellarService.client-DBurXZXn.js → stellarService.client-li6iEHAu.js} +2 -2
  25. package/dist/{stellarService.client-DBurXZXn.js.map → stellarService.client-li6iEHAu.js.map} +1 -1
  26. package/package.json +2 -2
  27. package/dist/index-BwyqlDlg.js.map +0 -1
  28. package/dist/index-D3m1pR9o.js.map +0 -1
@@ -54,7 +54,7 @@ export declare const keys: () => {
54
54
  tokenData: (token?: TokenWithBalance) => (string | undefined)[];
55
55
  balance: (chainId?: number | string, tokenAddress?: string, userAddress?: string) => (string | number | undefined)[];
56
56
  allTokensBalance: (address: string | undefined, chainType: ChainType | undefined, direction?: SwapDirection) => (string | undefined)[];
57
- transaction: (fromChainId: string | undefined, toChainId: string | undefined, toTokenAddress: string | undefined, fromTokenAddress: string | undefined, price: string | undefined, slippage: SlippageOption | undefined, getGasOnDestination: boolean | undefined, sourceUserAddress: string | undefined, degenMode: boolean | undefined, destinationAddress: string | undefined, fallbackAddress: string | undefined, quoteOnly: boolean | undefined, fromChainType: ChainType | undefined, preHook: AppConfig["preHook"] | undefined, postHook: AppConfig["postHook"] | undefined, overrideGasRefundAddress: AppConfig["overrideGasRefundAddress"] | undefined) => (string | number | boolean | Omit<import("@0xsquid/squid-types").Hook, "fundAmount" | "fundToken"> | undefined)[];
57
+ transaction: (fromChainId: string | undefined, toChainId: string | undefined, toTokenAddress: string | undefined, fromTokenAddress: string | undefined, fromAmount: string | undefined, toAmount: string | undefined, slippage: SlippageOption | undefined, getGasOnDestination: boolean | undefined, sourceUserAddress: string | undefined, degenMode: boolean | undefined, destinationAddress: string | undefined, fallbackAddress: string | undefined, quoteOnly: boolean | undefined, fromChainType: ChainType | undefined, preHook: AppConfig["preHook"] | undefined, postHook: AppConfig["postHook"] | undefined, overrideGasRefundAddress: AppConfig["overrideGasRefundAddress"] | undefined) => (string | number | boolean | Omit<import("@0xsquid/squid-types").Hook, "fundAmount" | "fundToken"> | undefined)[];
58
58
  swapTransactionStatus: (transactionId: string | undefined) => (string | undefined)[];
59
59
  fiatToCryptoStatus: (transactionId?: string) => (string | undefined)[];
60
60
  sendTransactionStatus: (txHash: string | undefined, chainId: string | undefined) => (string | undefined)[];
@@ -1,4 +1,4 @@
1
1
  import { RouteRequest as SquidRouteRequest } from "@0xsquid/squid-types";
2
2
  export type RouteRequest = SquidRouteRequest & {
3
- overrideGasRefundAddress?: string;
3
+ toAmount?: string;
4
4
  };
@@ -21,7 +21,8 @@ export interface ConfigState {
21
21
  }
22
22
  export declare const useConfigStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ConfigState>>;
23
23
  interface TransactionState {
24
- fromPrice?: string;
24
+ fromAmount?: string;
25
+ toAmount?: string;
25
26
  txLocalId?: string;
26
27
  transactions: Record<string, TransactionParams>;
27
28
  currentTransaction?: TransactionParams;
@@ -7,8 +7,10 @@ export declare const useSwap: () => {
7
7
  };
8
8
  onSwapChange: (inputSwapParams: SwapParams) => SwapParams;
9
9
  invertSwaps: (() => SwapParams) | undefined;
10
- fromPrice: string | undefined;
11
- fromPriceChanged: (price: string) => void;
10
+ fromAmount: string | undefined;
11
+ toAmount: string | undefined;
12
+ fromAmountChanged: (amount: string) => void;
13
+ toAmountChanged: (amount: string) => void;
12
14
  toToken: import("../../core").Token | undefined;
13
15
  fromToken: import("../../core").Token | undefined;
14
16
  fromChain: import("@0xsquid/squid-types").ChainData | undefined;
@@ -16,6 +16,7 @@ export declare const useGetRoute: () => import("@tanstack/react-query").UseMutat
16
16
  sourceUserAddress: string | undefined;
17
17
  destinationAddress: string | undefined;
18
18
  fromPrice: string | undefined;
19
+ toPrice: string | undefined;
19
20
  bypassGuardrails: RouteRequest["bypassGuardrails"] | undefined;
20
21
  quoteOnly: boolean | undefined;
21
22
  fromChainType: ChainType | undefined;
@@ -21137,11 +21137,17 @@ function isOnChainTxData(squidData) {
21137
21137
  return [
21138
21138
  squidTypes.SquidDataType.OnChainExecution,
21139
21139
  squidTypes.SquidDataType.DepositAddressWithSignature,
21140
- // TODO: update types
21141
- // SquidDataType.OnChainExecutionWithSignature
21142
- "ON_CHAIN_EXECUTION_WITH_SIGNATURE",
21143
21140
  ].includes(squidData.type);
21144
21141
  }
21142
+ /**
21143
+ * Checks if a route is of type deposit-with-signature
21144
+ *
21145
+ * deposit-with-signature routes are on-chain routes
21146
+ * that require a signature from the user to execute
21147
+ */
21148
+ function isDepositWithSignatureTxData(squidData) {
21149
+ return squidData.type === squidTypes.SquidDataType.DepositAddressWithSignature;
21150
+ }
21145
21151
  function getHistoryTransactionId(tx) {
21146
21152
  switch (tx.txType) {
21147
21153
  case exports.HistoryTxType.SWAP:
@@ -22300,14 +22306,15 @@ const keys = () => ({
22300
22306
  // ============
22301
22307
  // Transactions
22302
22308
  // ============
22303
- transaction: (fromChainId, toChainId, toTokenAddress, fromTokenAddress, price, slippage, getGasOnDestination, sourceUserAddress, degenMode, destinationAddress, fallbackAddress, quoteOnly, fromChainType, preHook, postHook, overrideGasRefundAddress) => [
22309
+ transaction: (fromChainId, toChainId, toTokenAddress, fromTokenAddress, fromAmount, toAmount, slippage, getGasOnDestination, sourceUserAddress, degenMode, destinationAddress, fallbackAddress, quoteOnly, fromChainType, preHook, postHook, overrideGasRefundAddress) => [
22304
22310
  ...keys().transactions(),
22305
22311
  exports.QueryKeys.Transaction,
22306
22312
  fromChainId,
22307
22313
  toChainId,
22308
22314
  toTokenAddress,
22309
22315
  fromTokenAddress,
22310
- price,
22316
+ fromAmount,
22317
+ toAmount,
22311
22318
  slippage,
22312
22319
  getGasOnDestination,
22313
22320
  sourceUserAddress,
@@ -23172,7 +23179,7 @@ const filterViewableTokens = (tokens, config, direction) => {
23172
23179
  };
23173
23180
  const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
23174
23181
  const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
23175
- const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-y3m09F3S.js'); });
23182
+ const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-BXleHutG.js'); });
23176
23183
  return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
23177
23184
  };
23178
23185
  function getTokenAssetsKey(token) {
@@ -25029,10 +25036,7 @@ const useConfigStore = zustand.create(() => ({
25029
25036
  isInitialized: false,
25030
25037
  }));
25031
25038
  const useTransactionStore = zustand.create((set, get) => ({
25032
- fromPrice: undefined,
25033
- txLocalId: undefined,
25034
25039
  transactions: {},
25035
- currentTransaction: undefined,
25036
25040
  setTransactionState(txId, tx) {
25037
25041
  if (!txId)
25038
25042
  return;
@@ -26488,7 +26492,7 @@ function useStellarWallets() {
26488
26492
  try {
26489
26493
  const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
26490
26494
  const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module');
26491
- const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-DBurXZXn.js'); });
26495
+ const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-li6iEHAu.js'); });
26492
26496
  const modules = [...initializeAllModules(), new LedgerModule()];
26493
26497
  const promises = modules.map(async (module) => {
26494
26498
  const isAvailable = await module.isAvailable();
@@ -27387,7 +27391,8 @@ const useMultiChainWallet = (chain) => {
27387
27391
 
27388
27392
  const useSwap = () => {
27389
27393
  const { initialAssets, defaultTokensPerChain, disabledChains, availableChains, } = useConfigStore((state) => state.config);
27390
- const fromPrice = useTransactionStore((state) => state.fromPrice);
27394
+ const fromAmount = useTransactionStore((state) => state.fromAmount);
27395
+ const toAmount = useTransactionStore((state) => state.toAmount);
27391
27396
  const { swapRoute } = useSwapRoutePersistStore();
27392
27397
  const { tokens } = useSquidTokens();
27393
27398
  const queryClient = reactQuery.useQueryClient();
@@ -27445,8 +27450,17 @@ const useSwap = () => {
27445
27450
  }),
27446
27451
  };
27447
27452
  }, [destAddressData, destAddressEnsData.data, toChain?.chainType]);
27448
- const fromPriceChanged = React.useCallback((price) => {
27449
- useTransactionStore.setState({ fromPrice: price || undefined });
27453
+ const fromAmountChanged = React.useCallback((amount) => {
27454
+ useTransactionStore.setState({
27455
+ fromAmount: amount || undefined,
27456
+ toAmount: undefined,
27457
+ });
27458
+ }, []);
27459
+ const toAmountChanged = React.useCallback((amount) => {
27460
+ useTransactionStore.setState({
27461
+ toAmount: amount || undefined,
27462
+ fromAmount: undefined,
27463
+ });
27450
27464
  }, []);
27451
27465
  /**
27452
27466
  * When user changes something from the SwapView
@@ -27587,8 +27601,10 @@ const useSwap = () => {
27587
27601
  tokenItems,
27588
27602
  onSwapChange,
27589
27603
  invertSwaps,
27590
- fromPrice,
27591
- fromPriceChanged,
27604
+ fromAmount,
27605
+ toAmount,
27606
+ fromAmountChanged,
27607
+ toAmountChanged,
27592
27608
  toToken,
27593
27609
  fromToken,
27594
27610
  fromChain,
@@ -27988,7 +28004,7 @@ function hederaWalletConnect(parameters) {
27988
28004
  const optionalChains = config.chains.map((x) => x.id);
27989
28005
  if (!optionalChains.length)
27990
28006
  return;
27991
- const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-BxbRmlQ1.js'); });
28007
+ const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-BQGUcysL.js'); });
27992
28008
  const rawProvider = await EthereumProvider.init({
27993
28009
  ...restParameters,
27994
28010
  disableProviderPing: true,
@@ -32112,7 +32128,7 @@ const useApproval = ({ squidRoute, }) => {
32112
32128
  const publicClient = wagmi.usePublicClient();
32113
32129
  const queryClient = reactQuery.useQueryClient();
32114
32130
  const squid = useSquidStore((state) => state.squid);
32115
- const { fromChain, fromToken, fromPrice, isSameChain } = useSwap();
32131
+ const { fromChain, fromToken, fromAmount, toAmount, isSameChain } = useSwap();
32116
32132
  const { evmSigner } = useSigner({ chain: fromChain });
32117
32133
  const { connector: activeConnector } = wagmi.useAccount();
32118
32134
  const { getChainType } = useSquidChains();
@@ -32285,7 +32301,7 @@ const useApproval = ({ squidRoute, }) => {
32285
32301
  // This is to ensure we're using the latest expiry timestamp
32286
32302
  if (squidRoute) {
32287
32303
  queryClient.refetchQueries({
32288
- 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,
32304
+ queryKey: keys().transaction(squidRoute.params.fromChain, squidRoute.params.toChain, squidRoute.params.toToken, squidRoute.params.fromToken, fromAmount, toAmount, 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,
32289
32305
  // TODO: update types
32290
32306
  squidRoute.params?.overrideGasRefundAddress),
32291
32307
  });
@@ -36098,8 +36114,12 @@ const useGetRoute = () => {
36098
36114
  * These data will be used to trigger the transaction
36099
36115
  * @returns {Route} Route data
36100
36116
  */
36101
- return reactQuery.useMutation(async ({ fromChain, toChain, fromToken, toToken, sourceUserAddress, destinationAddress, fromPrice, bypassGuardrails, quoteOnly, fromChainType, postHook, preHook, overrideGasRefundAddress, }) => {
36102
- if (!fromChain || !toChain || !fromToken || !toToken || !fromPrice) {
36117
+ return reactQuery.useMutation(async ({ fromChain, toChain, fromToken, toToken, sourceUserAddress, destinationAddress, fromPrice = "", toPrice = "", bypassGuardrails, quoteOnly, fromChainType, postHook, preHook, overrideGasRefundAddress, }) => {
36118
+ if (!fromChain ||
36119
+ !toChain ||
36120
+ !fromToken ||
36121
+ !toToken ||
36122
+ (!fromPrice && !toPrice)) {
36103
36123
  return undefined;
36104
36124
  }
36105
36125
  // Dispatch requestQuote event
@@ -36109,6 +36129,7 @@ const useGetRoute = () => {
36109
36129
  fromToken: fromToken.address,
36110
36130
  toToken: toToken.address,
36111
36131
  fromAmount: fromPrice,
36132
+ toAmount: toPrice,
36112
36133
  fromAddress: sourceUserAddress,
36113
36134
  toAddress: destinationAddress,
36114
36135
  });
@@ -36117,6 +36138,7 @@ const useGetRoute = () => {
36117
36138
  const fromTokenAddress = fromToken.address;
36118
36139
  const toTokenAddress = toToken.address;
36119
36140
  const fromAmount = parseToBigInt(fromPrice?.toString() ?? "0", fromToken?.decimals).toString();
36141
+ const toAmount = parseToBigInt(toPrice?.toString() ?? "0", toToken?.decimals).toString();
36120
36142
  const fromAddress = sourceUserAddress ??
36121
36143
  chainTypeToZeroAddressMap[fromChainType ?? squidTypes.ChainType.EVM];
36122
36144
  const params = {
@@ -36124,6 +36146,7 @@ const useGetRoute = () => {
36124
36146
  fromToken: fromTokenAddress,
36125
36147
  fromAddress,
36126
36148
  fromAmount,
36149
+ toAmount,
36127
36150
  toChain,
36128
36151
  toToken: toTokenAddress,
36129
36152
  toAddress: destinationAddress ?? "",
@@ -36145,7 +36168,7 @@ const useGetRoute = () => {
36145
36168
  });
36146
36169
  // Cache the route data
36147
36170
  // Useful when the getRoute mutation is called from another hook
36148
- 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);
36171
+ queryClient.setQueryData(keys().transaction(fromChain, toChain, toToken.address, fromToken.address, fromPrice, toPrice, config.slippage, config.enableGetGasOnDestination, sourceUserAddress, config.degenMode, destinationAddress, swapRoute?.fallbackAddress, quoteOnly, fromChainType, config.preHook, config.postHook, overrideGasRefundAddress), route);
36149
36172
  return route;
36150
36173
  });
36151
36174
  };
@@ -36159,7 +36182,7 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
36159
36182
  const depositRefundAddress = useSwapRoutePersistStore((store) => store.swapRoute?.depositRefundAddress);
36160
36183
  const { isAvailableAsPaymentMethod, isEnabled: isDepositAddressEnabled } = useDepositAddress();
36161
36184
  const getRouteMutation = useGetRoute();
36162
- const { fromChain, toChain, fromPrice, destinationAddress: { address: destinationAddress } = {}, fromToken, toToken, } = useSwap();
36185
+ const { fromChain, toChain, fromAmount, toAmount, destinationAddress: { address: destinationAddress } = {}, fromToken, toToken, } = useSwap();
36163
36186
  const { connectedAddress: { address: sourceConnectedAddress }, } = useMultiChainWallet(fromChain);
36164
36187
  // When the payment method is deposit address, users can specify a refund address on the source chain
36165
36188
  // Tokens will be sent to this address in case of swap failure
@@ -36168,12 +36191,13 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
36168
36191
  const sourceUserAddress = isDepositAddressEnabled && isAvailableAsPaymentMethod
36169
36192
  ? depositRefundAddress ?? sourceConnectedAddress
36170
36193
  : sourceConnectedAddress;
36171
- 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), [
36194
+ const squidRouteQueryKeys = React.useMemo(() => keys().transaction(fromChain?.chainId, toChain?.chainId, toToken?.address, fromToken?.address, fromAmount, toAmount, config.slippage, config.enableGetGasOnDestination, sourceUserAddress, config.degenMode, destinationAddress, fallbackAddress, quoteOnly, fromChain?.chainType, config.preHook, config.postHook, config.overrideGasRefundAddress), [
36172
36195
  fromChain?.chainId,
36173
36196
  toChain?.chainId,
36174
36197
  toToken?.address,
36175
36198
  fromToken?.address,
36176
- fromPrice,
36199
+ fromAmount,
36200
+ toAmount,
36177
36201
  config.slippage,
36178
36202
  config.enableGetGasOnDestination,
36179
36203
  sourceUserAddress,
@@ -36189,8 +36213,8 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
36189
36213
  const queryEnabled = enabled != undefined
36190
36214
  ? enabled
36191
36215
  : squid !== undefined &&
36192
- fromPrice !== undefined &&
36193
- fromPrice !== "0" &&
36216
+ ((fromAmount !== undefined && fromAmount !== "0") ||
36217
+ (toAmount !== undefined && toAmount !== "0")) &&
36194
36218
  toChain?.chainId !== undefined &&
36195
36219
  toToken?.address !== undefined;
36196
36220
  const queryClient = reactQuery.useQueryClient();
@@ -36208,7 +36232,8 @@ refetchIntervalInBackground = false, refetchInterval = 30000, quoteOnly = true,
36208
36232
  toToken,
36209
36233
  sourceUserAddress,
36210
36234
  destinationAddress,
36211
- fromPrice,
36235
+ fromPrice: fromAmount,
36236
+ toPrice: toAmount,
36212
36237
  bypassGuardrails: config.degenMode,
36213
36238
  quoteOnly,
36214
36239
  fromChainType: fromChain?.chainType,
@@ -37017,6 +37042,7 @@ exports.isChainflipBridgeTransaction = isChainflipBridgeTransaction;
37017
37042
  exports.isCoralBridgeAction = isCoralBridgeAction;
37018
37043
  exports.isCosmosAddressValid = isCosmosAddressValid;
37019
37044
  exports.isDepositRoute = isDepositRoute;
37045
+ exports.isDepositWithSignatureTxData = isDepositWithSignatureTxData;
37020
37046
  exports.isEmptyObject = isEmptyObject;
37021
37047
  exports.isEvmChainNotSupportedError = isEvmChainNotSupportedError;
37022
37048
  exports.isEvmosChain = isEvmosChain;
@@ -37151,4 +37177,4 @@ exports.useXrplTrustLine = useXrplTrustLine;
37151
37177
  exports.waitForReceiptWithRetry = waitForReceiptWithRetry;
37152
37178
  exports.walletIconBaseUrl = walletIconBaseUrl;
37153
37179
  exports.walletSupportsChainType = walletSupportsChainType;
37154
- //# sourceMappingURL=index-D3m1pR9o.js.map
37180
+ //# sourceMappingURL=index-Bg7CS2Uo.js.map