@funkit/connect 11.3.0 → 11.4.1

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 (71) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/clients/{chunk-DGBIV3ZS.js → chunk-B7UU2ETA.js} +0 -13
  3. package/dist/clients/{chunk-L2XMI4EX.js → chunk-BB5FHA47.js} +13 -12
  4. package/dist/clients/chunk-MSLPLXR2.js +30 -0
  5. package/dist/clients/{chunk-QQEGNLGD.js → chunk-TYG42JRZ.js} +4 -4
  6. package/dist/clients/{chunk-46L2KJJ4.js → chunk-UMU5S2WF.js} +34 -43
  7. package/dist/clients/internal/nado/withdrawalCallback.js +4 -11
  8. package/dist/clients/internal/nado/withdrawalConfig.d.ts +3 -1
  9. package/dist/clients/internal/nado/withdrawalConfig.js +2 -3
  10. package/dist/clients/internal/nado/withdrawalErrors.d.ts +6 -10
  11. package/dist/clients/internal/nado/withdrawalErrors.js +1 -2
  12. package/dist/clients/internal/nado/withdrawalForm.css +44 -36
  13. package/dist/clients/internal/nado/withdrawalForm.d.ts +1 -1
  14. package/dist/clients/internal/nado/withdrawalForm.js +20 -73
  15. package/dist/clients/internal/nado/withdrawalStatus.js +4 -8
  16. package/dist/clients/lighter.css +44 -36
  17. package/dist/clients/lighter.d.ts +0 -31
  18. package/dist/clients/lighter.js +10 -102
  19. package/dist/clients/nado.d.ts +3 -1
  20. package/dist/clients/nado.js +8 -15
  21. package/dist/clients/polymarket/PolymarketDepositAccountDropdown.css +47 -39
  22. package/dist/clients/polymarket/PolymarketDepositAccountDropdown.js +4 -4
  23. package/dist/clients/polymarket/index.css +47 -39
  24. package/dist/clients/polymarket/index.js +9 -9
  25. package/dist/components/Dropdown/BaseDropdown.css.d.ts +1 -0
  26. package/dist/components/Dropdown/BaseDropdown.d.ts +0 -1
  27. package/dist/domains/checkout.d.ts +6 -1
  28. package/dist/hooks/track/analytics/events.d.ts +19 -9
  29. package/dist/hooks/track/analytics/resolveExecutionProgressContext.d.ts +1 -0
  30. package/dist/hooks/track/analytics/useDepositAnalytics.d.ts +11 -3
  31. package/dist/hooks/track/analytics/useTrackExecutionProgressEvents.d.ts +3 -33
  32. package/dist/hooks/track/useTrackV2.d.ts +2 -0
  33. package/dist/hooks/useAssetPrice.d.ts +1 -6
  34. package/dist/hooks/useBluvo.d.ts +7 -2
  35. package/dist/index.css +44 -36
  36. package/dist/index.js +922 -1205
  37. package/dist/modals/WithdrawalModal/LighterWithdrawal.d.ts +5 -11
  38. package/dist/providers/FunkitCheckoutContext/types.d.ts +1 -1
  39. package/dist/providers/FunkitStatsigProvider.d.ts +1 -1
  40. package/dist/utils/withdrawal.d.ts +1 -21
  41. package/dist/wallets/walletConnectors/index.js +32 -32
  42. package/package.json +6 -6
  43. package/dist/clients/chunk-2576N7PQ.js +0 -44
  44. package/dist/clients/chunk-3P2C436B.js +0 -20
  45. package/dist/clients/chunk-63XTVHO3.js +0 -19
  46. package/dist/clients/chunk-6T6URLBM.js +0 -33
  47. package/dist/clients/chunk-FM7SFGAV.js +0 -106
  48. package/dist/clients/chunk-JFDRLSYM.js +0 -42
  49. package/dist/clients/chunk-TZGKB6WY.js +0 -160
  50. package/dist/clients/chunk-VIAEAD75.js +0 -61
  51. package/dist/clients/chunk-WZRW6WUM.js +0 -112
  52. package/dist/clients/chunk-Z7HTQFEO.js +0 -69
  53. package/dist/clients/internal/nado/consts.d.ts +0 -22
  54. package/dist/clients/internal/nado/consts.js +0 -15
  55. package/dist/clients/internal/nado/encoding.d.ts +0 -25
  56. package/dist/clients/internal/nado/encoding.js +0 -11
  57. package/dist/clients/internal/nado/errors.d.ts +0 -68
  58. package/dist/clients/internal/nado/errors.js +0 -19
  59. package/dist/clients/internal/nado/fetch.d.ts +0 -15
  60. package/dist/clients/internal/nado/fetch.js +0 -9
  61. package/dist/clients/internal/nado/gateway.d.ts +0 -61
  62. package/dist/clients/internal/nado/gateway.js +0 -17
  63. package/dist/clients/internal/nado/hooks.d.ts +0 -208
  64. package/dist/clients/internal/nado/hooks.js +0 -21
  65. package/dist/clients/internal/nado/indexer.d.ts +0 -43
  66. package/dist/clients/internal/nado/indexer.js +0 -13
  67. package/dist/clients/internal/nado/typedData.d.ts +0 -80
  68. package/dist/clients/internal/nado/typedData.js +0 -10
  69. package/dist/clients/internal/nado/withdrawalTypes.d.ts +0 -49
  70. package/dist/clients/internal/nado/withdrawalTypes.js +0 -1
  71. package/dist/utils/safeBigInt.d.ts +0 -5
@@ -11,7 +11,7 @@ import type { CustomWithdrawalConfig, LighterRouteType, TokenInfo, WalletWithdra
11
11
  /** Stable method ids for the Fast / Secure options (used for tracking + switching). */
12
12
  export declare const LIGHTER_FAST_METHOD_ID = "lighter-fast";
13
13
  export declare const LIGHTER_SECURE_METHOD_ID = "lighter-secure";
14
- export { LIGHTER_DEFAULT_SECURE_MIN_WITHDRAWAL_AMOUNTS, LIGHTER_FAST_MAX_WITHDRAWAL_USD, LIGHTER_ROUTE_TYPE, LIGHTER_SECURE_ASSETS_BY_INDEX, LIGHTER_STAKING_POOL_INDEX, LIGHTER_STAKING_THRESHOLD_LIT, LIGHTER_UNSTAKED_FEE_TOKENS, LIGHTER_USDC_SPOT_SYMBOL, getLighterBaseSymbol, getLighterSecureMainnetAddress, resolveLighterAssetIndex, resolveLighterSecureRouteType, resolveLighterSharePrice, resolveLighterUnstakedFeeTokens, } from '@funkit/connect-core/clients/lighter';
14
+ export { LIGHTER_DEFAULT_SECURE_MIN_WITHDRAWAL_AMOUNTS, LIGHTER_FAST_MAX_WITHDRAWAL_USD, LIGHTER_ROUTE_TYPE, LIGHTER_SECURE_ASSETS_BY_INDEX, LIGHTER_STAKING_POOL_INDEX, LIGHTER_STAKING_THRESHOLD_LIT, LIGHTER_UNSTAKED_FEE_TOKENS, LIGHTER_USDC_SPOT_SYMBOL, getLighterBaseSymbol, getLighterSecureMainnetAddress, resolveLighterAssetIndex, resolveLighterSecureRouteType, } from '@funkit/connect-core/clients/lighter';
15
15
  /**
16
16
  * The selected source token as identified on Lighter's own L2, rather than by
17
17
  * its mainnet bridge address — two Secure selections can share one mainnet
@@ -45,23 +45,16 @@ export declare function resolveLighterConfirmedTarget({ isLighterSecure, mainnet
45
45
  export declare function LighterFastMaxExceededMessage({ onSwitchToSecure, }: {
46
46
  onSwitchToSecure: () => void;
47
47
  }): React.JSX.Element;
48
- /**
49
- * Share price for the staking pool, read off the pool's own account. Kept a
50
- * separate query from the user's account: a user's `shares[]` carries entry
51
- * state only, so current value is unobtainable without the pool's NAV.
52
- */
53
- export declare function useLighterStakingSharePrice(enabled: boolean): number | undefined;
54
48
  /**
55
49
  * Fetches the Lighter account for the data the SDK still derives itself:
56
- * `shares` for the unstaked-fee gate, and `assets` to resolve the L2 asset index
57
- * of a Secure selection. Withdrawable balances are the integrator's to supply
58
- * (`withdrawalSourceTokenBalance`), so nothing here computes them.
50
+ * `assets`, to resolve the L2 asset index of a Secure selection. Withdrawable
51
+ * balances are the integrator's to supply (`withdrawalSourceTokenBalance`), so
52
+ * nothing here computes them.
59
53
  */
60
54
  export declare function useLighterWithdrawalBalances({ accountIndex, }: {
61
55
  accountIndex: LighterAccountIndex | undefined;
62
56
  }): {
63
57
  assets: import("@funkit/connect-core").LighterAsset[];
64
- shares: import("@funkit/connect-core").LighterShare[];
65
58
  isLoading: boolean;
66
59
  };
67
60
  type FunkitWithdrawalConfig = WalletWithdrawalConfig | CustomWithdrawalConfig;
@@ -77,6 +70,7 @@ export declare function useLighterWithdrawal(config: FunkitWithdrawalConfig, set
77
70
  connectedAddress: `0x${string}` | undefined;
78
71
  lighterAssets: import("@funkit/connect-core").LighterAsset[];
79
72
  lighterFastUnstakedFee: number;
73
+ isLighterFastUnstakedFeeFetched: boolean;
80
74
  invalidateLighterAccount: () => void;
81
75
  };
82
76
  /**
@@ -3,7 +3,7 @@ import type { LighterRouteType } from '@funkit/connect-core/clients/lighter';
3
3
  import type { ApiCheckoutClientMetadata, ApiFunkitCheckoutActionParams, ApiFunkitCheckoutConfig } from '@funkit/utils';
4
4
  import type { ReactNode } from 'react';
5
5
  import type { Address } from 'viem';
6
- import type { NadoWithdrawalCustomerConfig, NadoWithdrawalCustomerData } from '../../clients/internal/nado/withdrawalTypes';
6
+ import type { NadoWithdrawalCustomerConfig, NadoWithdrawalCustomerData } from '@funkit/connect-core/clients/nado';
7
7
  import type { PaymentMethodInfo } from '../../domains/paymentMethods';
8
8
  import type { CheckoutBlockedReason } from '../../modals/CheckoutModal/CheckoutBlockedReason';
9
9
  import type { WithdrawalClient, WithdrawalTransaction } from '../../wallets/Wallet';
@@ -5,7 +5,7 @@ export declare const STATSIG_CLIENT_KEY: "client-UmFd8WIJljA7cLmZuDqs3X25M8sKd5W
5
5
  export declare const STATSIG_CLIENT_KEY_FUNWHN: "client-UrueDVSY9et85npGccWMFidPs00V5jzTYyzsDKlLAjr";
6
6
  /**
7
7
  * THIS IS THE TEMPORARY CLIENT FOR V2 ANALYTICS. IT DOES NOT CONTAIN ANY CONFIGS.
8
- * DO NOT USE THIS CONTEXT DIRECTLY. USE useTrack.logEventV2 INSTEAD.
8
+ * DO NOT USE THIS CONTEXT DIRECTLY. USE useTrackV2 INSTEAD.
9
9
  */
10
10
  export declare function useFunWhnStatsigClient(): StatsigClient | null;
11
11
  interface FunkitStatsigProviderProps {
@@ -1,24 +1,4 @@
1
- import type { CustomWithdrawalConfig, FunkitWithdrawalConfig, MultiMethodWithdrawalConfig, SourceTokenOption, WalletWithdrawalConfig, WithdrawalSourceTokenBalanceParams } from '../providers/FunkitCheckoutContext';
2
- /**
3
- * Deducts a flat fee (in token units) from a withdrawal input amount, clamped
4
- * at 0. Uses `dnum` fixed-point math so decimal strings straight off the amount
5
- * field stay exact.
6
- */
7
- export declare function deductFlatFee(inputAmount: string, feeTokens: number): string;
8
- /**
9
- * Resolves the integrator's `withdrawalSourceTokenBalance` callback to a numeric
10
- * string. Shared by the withdrawal amount screen and the Swapped cash cap.
11
- *
12
- * Named `resolve*`, not `safeEvaluate*`: it may legitimately not resolve. It
13
- * never throws either way.
14
- *
15
- * - `undefined` means the integrator supplied no callback — distinct from a
16
- * callback returning `0`, which means "nothing withdrawable". Callers that
17
- * only display a number should coalesce to `'0'`.
18
- * - A throw or an unusable value yields `'0'` (with a warn), never `undefined`:
19
- * a broken callback must not silently fall through to another balance source.
20
- */
21
- export declare function resolveWithdrawalSourceTokenBalance(fn: ((params: WithdrawalSourceTokenBalanceParams) => string | number) | undefined, params: WithdrawalSourceTokenBalanceParams): string | undefined;
1
+ import type { CustomWithdrawalConfig, FunkitWithdrawalConfig, MultiMethodWithdrawalConfig, SourceTokenOption, WalletWithdrawalConfig } from '../providers/FunkitCheckoutContext';
22
2
  /**
23
3
  * Type guard to check if withdrawal config uses wallet-based flow
24
4
  */
@@ -32,18 +32,18 @@ import {
32
32
  import {
33
33
  rabbyWallet
34
34
  } from "./chunk-RB66PKPA.js";
35
- import {
36
- ramperWallet
37
- } from "./chunk-OQB55QXP.js";
38
35
  import {
39
36
  rainbowWallet
40
37
  } from "./chunk-W2LCLDPX.js";
41
38
  import {
42
- safeWallet
43
- } from "./chunk-RCY66YHF.js";
39
+ ramperWallet
40
+ } from "./chunk-OQB55QXP.js";
44
41
  import {
45
42
  roninWallet
46
43
  } from "./chunk-YQFGVZGR.js";
44
+ import {
45
+ safeWallet
46
+ } from "./chunk-RCY66YHF.js";
47
47
  import {
48
48
  safeheronWallet
49
49
  } from "./chunk-76S7R2ND.js";
@@ -53,60 +53,63 @@ import {
53
53
  import {
54
54
  subWallet
55
55
  } from "./chunk-NR2OGDHQ.js";
56
- import {
57
- mewWallet
58
- } from "./chunk-MQM45ADF.js";
59
56
  import {
60
57
  ledgerWallet
61
58
  } from "./chunk-RPV27V2Y.js";
59
+ import {
60
+ mewWallet
61
+ } from "./chunk-MQM45ADF.js";
62
62
  import {
63
63
  oktoWallet
64
64
  } from "./chunk-YWOVAU6O.js";
65
65
  import {
66
66
  omniWallet
67
67
  } from "./chunk-2CX7LX4J.js";
68
- import {
69
- oneInchWallet
70
- } from "./chunk-QG6ZHI7B.js";
71
- import {
72
- oneKeyWallet
73
- } from "./chunk-WVT6BBJH.js";
74
68
  import {
75
69
  okxWallet
76
70
  } from "./chunk-KI5Y2BBF.js";
71
+ import {
72
+ oneInchWallet
73
+ } from "./chunk-QG6ZHI7B.js";
77
74
  import {
78
75
  phantomWallet
79
76
  } from "./chunk-QY53O7WG.js";
80
77
  import {
81
- gateWallet
82
- } from "./chunk-JPN6TWIT.js";
78
+ oneKeyWallet
79
+ } from "./chunk-WVT6BBJH.js";
80
+ import {
81
+ frameWallet
82
+ } from "./chunk-BU3ZAT5X.js";
83
83
  import {
84
84
  frontierWallet
85
85
  } from "./chunk-AVDUNQUW.js";
86
86
  import {
87
- coin98Wallet
88
- } from "./chunk-WAHGI5L7.js";
89
- import {
90
- imTokenWallet
91
- } from "./chunk-WNAGGFMG.js";
87
+ gateWallet
88
+ } from "./chunk-JPN6TWIT.js";
92
89
  import {
93
90
  coinbaseWallet
94
91
  } from "./chunk-2DLDAZRH.js";
95
92
  import {
96
93
  injectedWallet
97
94
  } from "./chunk-T6LGKC3F.js";
95
+ import {
96
+ imTokenWallet
97
+ } from "./chunk-WNAGGFMG.js";
98
98
  import {
99
99
  kresusWallet
100
100
  } from "./chunk-RICTB3FA.js";
101
101
  import {
102
102
  metaMaskWallet
103
103
  } from "./chunk-YO2K4MBH.js";
104
- import {
105
- bybitWallet
106
- } from "./chunk-OX37G4YT.js";
107
104
  import {
108
105
  clvWallet
109
106
  } from "./chunk-OEEGYENV.js";
107
+ import {
108
+ coin98Wallet
109
+ } from "./chunk-WAHGI5L7.js";
110
+ import {
111
+ bybitWallet
112
+ } from "./chunk-OX37G4YT.js";
110
113
  import {
111
114
  coreWallet
112
115
  } from "./chunk-4NV5BYRP.js";
@@ -123,23 +126,20 @@ import {
123
126
  foxWallet
124
127
  } from "./chunk-GUQM4QSL.js";
125
128
  import {
126
- frameWallet
127
- } from "./chunk-BU3ZAT5X.js";
129
+ bitgetWallet
130
+ } from "./chunk-TKB2OY6G.js";
128
131
  import {
129
132
  argentWallet
130
133
  } from "./chunk-NTMBEOR2.js";
134
+ import {
135
+ bitskiWallet
136
+ } from "./chunk-7HRFUZFX.js";
131
137
  import {
132
138
  bifrostWallet
133
139
  } from "./chunk-IULPZP2Q.js";
134
- import {
135
- bitgetWallet
136
- } from "./chunk-TKB2OY6G.js";
137
140
  import {
138
141
  bitverseWallet
139
142
  } from "./chunk-NSK6A7TI.js";
140
- import {
141
- bitskiWallet
142
- } from "./chunk-7HRFUZFX.js";
143
143
  import {
144
144
  bloomWallet
145
145
  } from "./chunk-PJ7Y57EH.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funkit/connect",
3
- "version": "11.3.0",
3
+ "version": "11.4.1",
4
4
  "description": "Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.",
5
5
  "files": [
6
6
  "dist",
@@ -101,16 +101,16 @@
101
101
  "motion": "^12.0.11",
102
102
  "qrcode": "1.5.3",
103
103
  "react-i18next": "16.3.3",
104
- "react-remove-scroll": "2.5.7",
104
+ "react-remove-scroll": "^2.7.2",
105
105
  "react-virtuoso": "4.10.1",
106
106
  "ua-parser-js": "^1.0.37",
107
107
  "use-debounce": "^10.0.5",
108
108
  "uuid": "^11.1.1",
109
- "@funkit/api-base": "7.0.0",
109
+ "@funkit/api-base": "7.1.1",
110
110
  "@funkit/chains": "2.2.0",
111
- "@funkit/connect-core": "3.0.0",
112
- "@funkit/fun-relay": "2.11.0",
113
- "@funkit/utils": "4.0.0"
111
+ "@funkit/connect-core": "4.0.0",
112
+ "@funkit/fun-relay": "2.13.0",
113
+ "@funkit/utils": "4.0.1"
114
114
  },
115
115
  "repository": {
116
116
  "type": "git",
@@ -1,44 +0,0 @@
1
- "use client";
2
- import {
3
- INK_CHAIN_ID,
4
- NADO_EIP712_VERIFYING_CONTRACT_ADDRESS
5
- } from "./chunk-3P2C436B.js";
6
-
7
- // src/clients/internal/nado/typedData.ts
8
- var WITHDRAW_COLLATERAL_V2_TYPES = {
9
- WithdrawCollateralV2: [
10
- { name: "sender", type: "bytes32" },
11
- { name: "productId", type: "uint32" },
12
- { name: "amount", type: "uint128" },
13
- { name: "nonce", type: "uint64" },
14
- { name: "sendTo", type: "address" },
15
- // Reserved by Nado — must be signed as 0
16
- { name: "appendix", type: "uint128" }
17
- ]
18
- };
19
- function buildWithdrawCollateralV2TypedData(params) {
20
- return {
21
- domain: {
22
- name: "Nado",
23
- version: "0.0.1",
24
- chainId: INK_CHAIN_ID,
25
- verifyingContract: NADO_EIP712_VERIFYING_CONTRACT_ADDRESS
26
- },
27
- types: WITHDRAW_COLLATERAL_V2_TYPES,
28
- primaryType: "WithdrawCollateralV2",
29
- message: {
30
- sender: params.sender,
31
- productId: params.productId,
32
- amount: params.amount,
33
- nonce: params.nonce,
34
- sendTo: params.sendTo,
35
- appendix: 0n
36
- // set to 0, Nado reserved
37
- }
38
- };
39
- }
40
-
41
- export {
42
- WITHDRAW_COLLATERAL_V2_TYPES,
43
- buildWithdrawCollateralV2TypedData
44
- };
@@ -1,20 +0,0 @@
1
- "use client";
2
-
3
- // src/clients/internal/nado/consts.ts
4
- import { getAddress } from "viem";
5
- import { ink } from "viem/chains";
6
- var INK_CHAIN_ID = ink.id;
7
- var NADO_GATEWAY_URL = "https://gateway.prod.nado.xyz/v1";
8
- var NADO_INDEXER_URL = "https://archive.prod.nado.xyz/v1";
9
- var NADO_EIP712_VERIFYING_CONTRACT_ADDRESS = getAddress(
10
- "0x05ec92D78ED421f3D3Ada77FFdE167106565974E"
11
- );
12
- var NADO_WITHDRAWAL_ACTION_TYPE = "NADO_WITHDRAWAL";
13
-
14
- export {
15
- INK_CHAIN_ID,
16
- NADO_GATEWAY_URL,
17
- NADO_INDEXER_URL,
18
- NADO_EIP712_VERIFYING_CONTRACT_ADDRESS,
19
- NADO_WITHDRAWAL_ACTION_TYPE
20
- };
@@ -1,19 +0,0 @@
1
- "use client";
2
-
3
- // src/utils/safeBigInt.ts
4
- function safeBigInt(value, fallback) {
5
- if (typeof value === "bigint") {
6
- return value;
7
- }
8
- if (typeof value === "number") {
9
- return Number.isFinite(value) && Number.isInteger(value) ? BigInt(value) : fallback;
10
- }
11
- if (typeof value === "string" && /^-?\d+$/.test(value)) {
12
- return BigInt(value);
13
- }
14
- return fallback;
15
- }
16
-
17
- export {
18
- safeBigInt
19
- };
@@ -1,33 +0,0 @@
1
- "use client";
2
-
3
- // src/clients/internal/nado/encoding.ts
4
- import {
5
- concatHex,
6
- formatUnits,
7
- pad,
8
- stringToHex
9
- } from "viem";
10
- var SUBACCOUNT_NAME_BYTES = 12;
11
- var X18_DECIMALS = 18;
12
- function buildNadoSubaccountId(owner, name = "default") {
13
- const nameHex = stringToHex(name);
14
- if ((nameHex.length - 2) / 2 > SUBACCOUNT_NAME_BYTES) {
15
- throw new Error("Nado subaccount name must be 12 bytes or fewer");
16
- }
17
- return concatHex([
18
- owner,
19
- pad(nameHex, { dir: "right", size: SUBACCOUNT_NAME_BYTES })
20
- ]);
21
- }
22
- function x18ToRawBaseUnit(x18Amount, decimals) {
23
- return x18Amount * 10n ** BigInt(decimals) / 10n ** BigInt(X18_DECIMALS);
24
- }
25
- function x18ToTokenUnits(x18Amount, decimals) {
26
- return formatUnits(x18ToRawBaseUnit(x18Amount, decimals), decimals);
27
- }
28
-
29
- export {
30
- buildNadoSubaccountId,
31
- x18ToRawBaseUnit,
32
- x18ToTokenUnits
33
- };
@@ -1,106 +0,0 @@
1
- "use client";
2
- import {
3
- findSettlementForNonce,
4
- getNadoWithdrawalEvents
5
- } from "./chunk-JFDRLSYM.js";
6
- import {
7
- getNadoFeeRates,
8
- getNadoMaxWithdrawable
9
- } from "./chunk-TZGKB6WY.js";
10
- import {
11
- NadoGatewayError
12
- } from "./chunk-Z7HTQFEO.js";
13
-
14
- // src/clients/internal/nado/hooks.ts
15
- import { skipToken, useQuery, useQueryClient } from "@tanstack/react-query";
16
- import { useCallback, useEffect, useReducer } from "react";
17
- var MAX_WITHDRAWABLE_QUERY_KEY = "nadoMaxWithdrawable";
18
- var MAX_WITHDRAWABLE_REFETCH_MS = 3e4;
19
- var FEE_RATES_STALE_MS = 5 * 6e4;
20
- var SETTLEMENT_POLL_MS = 1e4;
21
- var SETTLEMENT_TIMEOUT_MS = 10 * 6e4;
22
- function shouldRetryNadoQuery(failureCount, error) {
23
- if (error instanceof NadoGatewayError && (error.kind === "api" || error.kind === "timeout" || error.httpStatus === 429)) {
24
- return false;
25
- }
26
- return failureCount < 2;
27
- }
28
- function useNadoMaxWithdrawable(params) {
29
- const { productId, sender, spotLeverage } = params;
30
- return useQuery({
31
- queryKey: [MAX_WITHDRAWABLE_QUERY_KEY, sender, productId, spotLeverage],
32
- queryFn: productId !== void 0 && sender ? ({ signal }) => getNadoMaxWithdrawable({ productId, sender, spotLeverage }, signal) : skipToken,
33
- refetchInterval: MAX_WITHDRAWABLE_REFETCH_MS,
34
- retry: shouldRetryNadoQuery,
35
- // Toggling borrow re-keys the query, and the empty gap would flash the
36
- // balance to 0 ("insufficient" past any typed amount), so hold the last
37
- // answer while the next one loads — unless it could read too high.
38
- placeholderData: (previous, previousQuery) => {
39
- const [, previousSender, previousProductId, previousSpotLeverage] = previousQuery?.queryKey ?? [];
40
- const isSameAccountAndProduct = previousSender === sender && previousProductId === productId;
41
- const borrowTurnedOff = previousSpotLeverage === true && !spotLeverage;
42
- return isSameAccountAndProduct && !borrowTurnedOff ? previous : void 0;
43
- }
44
- });
45
- }
46
- function useInvalidateNadoMaxWithdrawable() {
47
- const queryClient = useQueryClient();
48
- return useCallback(() => {
49
- queryClient.invalidateQueries({ queryKey: [MAX_WITHDRAWABLE_QUERY_KEY] });
50
- }, [queryClient]);
51
- }
52
- function useNadoFeeRates(sender) {
53
- return useQuery({
54
- queryKey: ["nadoFeeRates", sender],
55
- queryFn: sender ? ({ signal }) => getNadoFeeRates(sender, signal) : skipToken,
56
- staleTime: FEE_RATES_STALE_MS,
57
- retry: shouldRetryNadoQuery
58
- });
59
- }
60
- function useNadoSettlementStatus(params) {
61
- const { subaccount, nonce, submittedAtMs, enabled } = params;
62
- const isPastTimeout = () => submittedAtMs !== void 0 && Date.now() - submittedAtMs >= SETTLEMENT_TIMEOUT_MS;
63
- const query = useQuery({
64
- queryKey: ["nadoSettlementStatus", subaccount, nonce?.toString()],
65
- queryFn: subaccount && nonce !== void 0 ? async ({ signal }) => {
66
- const { txs } = await getNadoWithdrawalEvents(
67
- { subaccount, limit: 3 },
68
- signal
69
- );
70
- const settlement = findSettlementForNonce(txs, nonce);
71
- return {
72
- isSequenced: settlement !== void 0,
73
- sequencedAt: settlement ? Number(settlement.timestamp) : void 0
74
- };
75
- } : skipToken,
76
- enabled: enabled && submittedAtMs !== void 0,
77
- // Only the 10s interval drives fetches — a sequenced result is final, so
78
- // focus/remount refetches would re-ask an answered question
79
- staleTime: Number.POSITIVE_INFINITY,
80
- // No retry — the next 10s poll is the retry
81
- retry: false,
82
- refetchInterval: (query2) => query2.state.data?.isSequenced || isPastTimeout() ? false : SETTLEMENT_POLL_MS
83
- });
84
- const [, rerenderAtTimeout] = useReducer((n) => n + 1, 0);
85
- useEffect(() => {
86
- if (submittedAtMs === void 0 || !enabled) {
87
- return;
88
- }
89
- const remainingMs = submittedAtMs + SETTLEMENT_TIMEOUT_MS - Date.now();
90
- if (remainingMs <= 0) {
91
- return;
92
- }
93
- const id = setTimeout(rerenderAtTimeout, remainingMs);
94
- return () => clearTimeout(id);
95
- }, [submittedAtMs, enabled]);
96
- const isTimedOut = isPastTimeout() && query.data?.isSequenced !== true;
97
- return { ...query, isTimedOut };
98
- }
99
-
100
- export {
101
- shouldRetryNadoQuery,
102
- useNadoMaxWithdrawable,
103
- useInvalidateNadoMaxWithdrawable,
104
- useNadoFeeRates,
105
- useNadoSettlementStatus
106
- };
@@ -1,42 +0,0 @@
1
- "use client";
2
- import {
3
- NADO_INDEXER_URL
4
- } from "./chunk-3P2C436B.js";
5
- import {
6
- nadoFetch
7
- } from "./chunk-WZRW6WUM.js";
8
- import {
9
- createNadoGatewayError
10
- } from "./chunk-Z7HTQFEO.js";
11
-
12
- // src/clients/internal/nado/indexer.ts
13
- async function getNadoWithdrawalEvents(params, signal) {
14
- const response = await nadoFetch({
15
- uri: NADO_INDEXER_URL,
16
- method: "POST",
17
- body: {
18
- events: {
19
- subaccounts: [params.subaccount],
20
- // v2 is a distinct indexer event type — our executes are all v2
21
- event_types: ["withdraw_collateral", "withdraw_collateral_v2"],
22
- limit: { raw: params.limit ?? 10 }
23
- }
24
- },
25
- signal
26
- });
27
- if ("status" in response && response.status === "failure") {
28
- throw createNadoGatewayError(response, "Nado indexer request failed");
29
- }
30
- return response;
31
- }
32
- function findSettlementForNonce(txs, nonce) {
33
- return txs.find((entry) => {
34
- const payload = entry.tx.withdraw_collateral_v2 ?? entry.tx.withdraw_collateral;
35
- return payload !== void 0 && BigInt(payload.nonce) === nonce;
36
- });
37
- }
38
-
39
- export {
40
- getNadoWithdrawalEvents,
41
- findSettlementForNonce
42
- };
@@ -1,160 +0,0 @@
1
- "use client";
2
- import {
3
- NADO_GATEWAY_URL
4
- } from "./chunk-3P2C436B.js";
5
- import {
6
- nadoFetch
7
- } from "./chunk-WZRW6WUM.js";
8
- import {
9
- NadoGatewayError,
10
- NadoWithdrawalUnconfirmedError,
11
- createNadoGatewayError,
12
- isNadoTransportError,
13
- parseNadoExpectedNonce
14
- } from "./chunk-Z7HTQFEO.js";
15
- import {
16
- logger
17
- } from "./chunk-AHYOV7AV.js";
18
-
19
- // src/clients/internal/nado/gateway.ts
20
- function parseNadoGatewayResponse(response, uri) {
21
- if (response.status !== "success") {
22
- logger.warn("nado:gateway_rejected", {
23
- uri,
24
- error: response.error,
25
- errorCode: response.error_code
26
- });
27
- throw createNadoGatewayError(response, "Nado gateway request failed");
28
- }
29
- return response.data;
30
- }
31
- async function nadoQuery(params, signal) {
32
- const uri = `${NADO_GATEWAY_URL}/query?${new URLSearchParams(params)}`;
33
- const response = await nadoFetch({
34
- uri,
35
- method: "GET",
36
- signal
37
- });
38
- const data = parseNadoGatewayResponse(response, uri);
39
- if (data === void 0) {
40
- throw new NadoGatewayError("Nado returned success without data", {
41
- kind: "api"
42
- });
43
- }
44
- return data;
45
- }
46
- async function getNadoMaxWithdrawable(params, signal) {
47
- const data = await nadoQuery(
48
- {
49
- type: "max_withdrawable",
50
- product_id: params.productId.toString(),
51
- sender: params.sender,
52
- spot_leverage: params.spotLeverage ? "true" : "false"
53
- },
54
- signal
55
- );
56
- return data.max_withdrawable;
57
- }
58
- async function getNadoTxNonce(address) {
59
- const query = () => nadoQuery({ type: "nonces", address });
60
- let data;
61
- try {
62
- data = await query();
63
- } catch (error) {
64
- if (!isNadoTransportError(error)) {
65
- throw error;
66
- }
67
- data = await query();
68
- }
69
- return BigInt(data.tx_nonce);
70
- }
71
- async function getNadoFeeRates(sender, signal) {
72
- return nadoQuery({ type: "fee_rates", sender }, signal);
73
- }
74
- async function executeNadoWithdrawCollateralV2(params) {
75
- const uri = `${NADO_GATEWAY_URL}/execute`;
76
- const body = {
77
- // spot_leverage sits INSIDE the execute object (sibling of tx/signature),
78
- // matching @nadohq's EngineBaseClient — top-level is silently ignored.
79
- withdraw_collateral_v2: {
80
- tx: {
81
- sender: params.sender,
82
- productId: params.productId,
83
- amount: params.amount.toString(),
84
- nonce: params.nonce.toString(),
85
- sendTo: params.sendTo,
86
- appendix: "0"
87
- },
88
- signature: params.signature,
89
- spot_leverage: params.spotLeverage
90
- }
91
- };
92
- try {
93
- const response = await nadoFetch({
94
- uri,
95
- method: "POST",
96
- body
97
- });
98
- parseNadoGatewayResponse(response, uri);
99
- } catch (error) {
100
- if (!isNadoUnansweredError(error)) {
101
- throw error;
102
- }
103
- logger.warn("nado:execute_unanswered", {
104
- uri,
105
- nonce: params.nonce.toString(),
106
- productId: params.productId,
107
- errorKind: error instanceof NadoGatewayError ? error.kind : null
108
- });
109
- await replayNadoWithdrawExecute({ uri, body, nonce: params.nonce });
110
- }
111
- }
112
- function isNadoUnansweredError(error) {
113
- return error instanceof NadoGatewayError && (error.kind === "timeout" || error.kind === "transport");
114
- }
115
- async function replayNadoWithdrawExecute({
116
- uri,
117
- body,
118
- nonce
119
- }) {
120
- try {
121
- const response = await nadoFetch({
122
- uri,
123
- method: "POST",
124
- body
125
- });
126
- parseNadoGatewayResponse(response, uri);
127
- logger.warn("nado:execute_replay_accepted", {
128
- uri,
129
- nonce: nonce.toString()
130
- });
131
- } catch (error) {
132
- const expectedNonce = parseNadoExpectedNonce(error);
133
- if (expectedNonce !== void 0 && expectedNonce > nonce) {
134
- logger.warn("nado:execute_replay_alreadyLanded", {
135
- uri,
136
- nonce: nonce.toString(),
137
- expectedNonce: expectedNonce.toString()
138
- });
139
- return;
140
- }
141
- logger.error(
142
- "nado:execute_replay_unconfirmed",
143
- error instanceof Error ? error : new Error(String(error)),
144
- {
145
- uri,
146
- nonce: nonce.toString(),
147
- expectedNonce: expectedNonce?.toString() ?? null,
148
- errorMessage: error instanceof Error ? error.message : String(error)
149
- }
150
- );
151
- throw new NadoWithdrawalUnconfirmedError();
152
- }
153
- }
154
-
155
- export {
156
- getNadoMaxWithdrawable,
157
- getNadoTxNonce,
158
- getNadoFeeRates,
159
- executeNadoWithdrawCollateralV2
160
- };