@funkit/connect 10.6.0 → 11.0.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 (45) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/clients/chunk-2FSEE3AW.js +277 -0
  3. package/dist/clients/chunk-5MY7WMEJ.js +20 -0
  4. package/dist/clients/chunk-6CYZKITE.js +33 -0
  5. package/dist/clients/{chunk-TG2AACP2.js → chunk-C4SHJFOV.js} +2 -2
  6. package/dist/clients/{chunk-3LJQTM37.js → chunk-FNB7OPJI.js} +12 -198
  7. package/dist/clients/{chunk-2NBYHUIW.js → chunk-HZP4DXIZ.js} +1 -0
  8. package/dist/clients/{chunk-F6P4CN27.js → chunk-JD2J5K6S.js} +16 -8
  9. package/dist/clients/chunk-LT4EWLDA.js +30 -0
  10. package/dist/clients/chunk-MGQLVTSH.js +100 -0
  11. package/dist/clients/{chunk-FJ6GCMJ4.js → chunk-OODIKHYE.js} +3 -1
  12. package/dist/clients/chunk-SFDEST63.js +18 -0
  13. package/dist/clients/{chunk-OZ3KD24N.js → chunk-ZCCLJW6F.js} +0 -8
  14. package/dist/clients/fanatics.js +5 -6
  15. package/dist/clients/internal/nado/encoding.js +4 -25
  16. package/dist/clients/internal/nado/gateway.d.ts +0 -21
  17. package/dist/clients/internal/nado/gateway.js +1 -5
  18. package/dist/clients/internal/nado/hooks.d.ts +0 -158
  19. package/dist/clients/internal/nado/hooks.js +10 -121
  20. package/dist/clients/internal/nado/withdrawalConfig.js +3 -13
  21. package/dist/clients/internal/nado/withdrawalForm.css +17529 -0
  22. package/dist/clients/internal/nado/withdrawalForm.d.ts +41 -0
  23. package/dist/clients/internal/nado/withdrawalForm.js +283 -0
  24. package/dist/clients/internal/nado/withdrawalTypes.d.ts +7 -2
  25. package/dist/clients/lighter.d.ts +29 -1
  26. package/dist/clients/lighter.js +105 -99
  27. package/dist/clients/mallard.js +24 -3
  28. package/dist/clients/polymarket/PolymarketDepositAccountDropdown.js +6 -3
  29. package/dist/clients/polymarket/index.js +6 -3
  30. package/dist/domains/swapped.d.ts +1 -10
  31. package/dist/hooks/useTokenAndChainDropdown.d.ts +8 -1
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.js +1369 -892
  34. package/dist/modals/WithdrawalModal/LighterWithdrawal.d.ts +20 -31
  35. package/dist/modals/WithdrawalModal/WithdrawAmountInput.d.ts +5 -9
  36. package/dist/providers/FunkitCheckoutContext/types.d.ts +61 -4
  37. package/dist/utils/customer.d.ts +349 -0
  38. package/dist/utils/withdrawal.d.ts +13 -6
  39. package/dist/wagmi/actions.d.ts +1 -1
  40. package/dist/wallets/Wallet.d.ts +21 -1
  41. package/dist/wallets/walletConnectors/index.js +11 -11
  42. package/package.json +3 -3
  43. package/dist/clients/chunk-A4WQS6QG.js +0 -207
  44. package/dist/clients/internal/nado/products.d.ts +0 -36
  45. package/dist/clients/internal/nado/products.js +0 -19
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Orchestrates the Nado enter-amount screen: joins subaccount balances onto the
3
+ * source tokens declared on the config, tracks the borrow toggle, and exposes
4
+ * the sequencer fee + max-withdrawable in token units.
5
+ *
6
+ * - One-way dependency: never imports from `modals/`; WithdrawalContent maps
7
+ * these outputs onto its own props.
8
+ * - Every react-query call is a no-op (zero traffic) when the config isn't Nado.
9
+ */
10
+ import type { FunkitWithdrawalConfig } from '../../../providers/FunkitCheckoutContext';
11
+ import type { NadoWithdrawalCustomerData } from './withdrawalTypes';
12
+ /** Structurally matches the shared flow's `clientAmountToggle` (no modals import). */
13
+ export interface NadoAmountToggle {
14
+ label: string;
15
+ checked: boolean;
16
+ onChange(enabled: boolean): void;
17
+ }
18
+ export interface UseNadoWithdrawalFormResult {
19
+ isNado: boolean;
20
+ /** Borrow (spot leverage) checkbox, assembled here so shared code holds no Nado state. */
21
+ amountToggle: NadoAmountToggle | undefined;
22
+ /** Max withdrawable for the selection in token units (accounts for the borrow toggle). */
23
+ maxWithdrawableTokenUnits: string | undefined;
24
+ /**
25
+ * Balance the screen shows and the Max button fills: the spot balance, or the
26
+ * borrow-aware max_withdrawable once borrowing is on (which can exceed spot).
27
+ */
28
+ withdrawableBalanceTokenUnits: string;
29
+ /** Sequencer fee in the selected product's token units; hard 0 outside Nado. */
30
+ sequencerFeeTokenAmount: number;
31
+ /** USD price of the selected source token (stables short-circuit to 1); undefined while loading. */
32
+ sourceTokenUsdPrice: number | undefined;
33
+ /** Submit-time customerData for the withdrawal callback; logs the decision. Undefined outside Nado. */
34
+ buildSubmitCustomerData(): NadoWithdrawalCustomerData | undefined;
35
+ }
36
+ export declare function useNadoWithdrawalForm(config: FunkitWithdrawalConfig | null,
37
+ /**
38
+ * The shared active dropdown item, by symbol. The product id is derived from
39
+ * it — tracking a second copy here would leave two selections to keep in sync.
40
+ */
41
+ selectedSourceToken: string | undefined): UseNadoWithdrawalFormResult;
@@ -0,0 +1,283 @@
1
+ "use client";
2
+ import {
3
+ isNadoWithdrawalConfig
4
+ } from "../../chunk-SFDEST63.js";
5
+ import {
6
+ x18ToTokenUnits
7
+ } from "../../chunk-6CYZKITE.js";
8
+ import {
9
+ useNadoFeeRates,
10
+ useNadoMaxWithdrawable,
11
+ useNadoSubaccountBalances
12
+ } from "../../chunk-MGQLVTSH.js";
13
+ import "../../chunk-ZCCLJW6F.js";
14
+ import "../../chunk-BNMZM23Q.js";
15
+ import "../../chunk-II5CZTBC.js";
16
+ import "../../chunk-L2KSNS7H.js";
17
+ import "../../chunk-2YWQL3AO.js";
18
+ import {
19
+ useGeneralWallet
20
+ } from "../../chunk-LT4EWLDA.js";
21
+ import "../../chunk-5MY7WMEJ.js";
22
+ import {
23
+ useFunkitConfig
24
+ } from "../../chunk-2FSEE3AW.js";
25
+ import "../../chunk-UPZNKPYU.js";
26
+ import {
27
+ useFunkitTranslation
28
+ } from "../../chunk-JD2J5K6S.js";
29
+ import {
30
+ logger
31
+ } from "../../chunk-AHYOV7AV.js";
32
+
33
+ // src/clients/internal/nado/withdrawalForm.ts
34
+ import { useEffect, useMemo, useState } from "react";
35
+
36
+ // src/hooks/useAssetPrice.ts
37
+ import {
38
+ getAssetPriceInfo
39
+ } from "@funkit/api-base";
40
+ import {
41
+ convertFunToRelayTokenAddress,
42
+ getRelayAssetPriceInfo
43
+ } from "@funkit/fun-relay";
44
+ import { skipToken, useQuery } from "@tanstack/react-query";
45
+
46
+ // src/hooks/useIsStablecoin.ts
47
+ import { useCallback } from "react";
48
+
49
+ // src/hooks/statsig/useDynamicConfig.ts
50
+ import {
51
+ useDynamicConfig as useCoreDynamicConfig
52
+ } from "@funkit/connect-core";
53
+
54
+ // src/hooks/useUserIpInfo.ts
55
+ import { useUserIpInfo as useCoreUserIpInfo } from "@funkit/connect-core";
56
+
57
+ // src/utils/safeBigInt.ts
58
+ function safeBigInt(value, fallback) {
59
+ if (typeof value === "bigint") {
60
+ return value;
61
+ }
62
+ if (typeof value === "number") {
63
+ return Number.isFinite(value) && Number.isInteger(value) ? BigInt(value) : fallback;
64
+ }
65
+ if (typeof value === "string" && /^-?\d+$/.test(value)) {
66
+ return BigInt(value);
67
+ }
68
+ return fallback;
69
+ }
70
+
71
+ // src/hooks/useUserIpInfo.ts
72
+ function useUserIpInfo() {
73
+ const { isUserLoggedIn } = useGeneralWallet();
74
+ return useCoreUserIpInfo({ logger, enabled: isUserLoggedIn });
75
+ }
76
+
77
+ // src/hooks/statsig/useDynamicConfig.ts
78
+ var useDynamicConfig = (name, options) => {
79
+ const { userIpInfo } = useUserIpInfo();
80
+ return useCoreDynamicConfig(name, {
81
+ bypassCountryCode: options?.bypassCountryCode,
82
+ countryCode: userIpInfo?.alpha2
83
+ });
84
+ };
85
+
86
+ // src/hooks/useIsStablecoin.ts
87
+ var useIsStablecoin = () => {
88
+ const stablecoinSymbols = useDynamicConfig("stablecoinsymbols");
89
+ return useCallback(
90
+ (symbol) => stablecoinSymbols.some(
91
+ (s) => symbol.toLowerCase().includes(s.toLowerCase())
92
+ ),
93
+ [stablecoinSymbols]
94
+ );
95
+ };
96
+
97
+ // src/hooks/useAssetPrice.ts
98
+ async function getFormattedRelayAssetPriceInfo({
99
+ chainId,
100
+ assetTokenAddress
101
+ }) {
102
+ try {
103
+ const relayResponse = await getRelayAssetPriceInfo({
104
+ chainId,
105
+ address: convertFunToRelayTokenAddress(
106
+ assetTokenAddress,
107
+ Number(chainId)
108
+ )
109
+ });
110
+ return {
111
+ unitPrice: relayResponse.price,
112
+ amount: 1,
113
+ total: 1
114
+ };
115
+ } catch (error) {
116
+ logger.error("Unable to fetch token price from Relay", error);
117
+ throw error;
118
+ }
119
+ }
120
+ async function getAssetPriceInfoWithFallback({
121
+ apiKey,
122
+ chainId,
123
+ assetTokenAddress
124
+ }) {
125
+ try {
126
+ return await getAssetPriceInfo({
127
+ apiKey,
128
+ assetTokenAddress,
129
+ chainId,
130
+ logger
131
+ });
132
+ } catch (primaryError) {
133
+ logger.warn(
134
+ "Unable to fetch token price from Primary provider, trying fallback",
135
+ { primaryError }
136
+ );
137
+ return await getFormattedRelayAssetPriceInfo({ chainId, assetTokenAddress });
138
+ }
139
+ }
140
+ function useAssetAddressPrice({
141
+ chainId,
142
+ assetTokenAddress,
143
+ amount = 1,
144
+ refetchInterval = 1e4,
145
+ symbol,
146
+ enabled = true
147
+ }) {
148
+ const { apiKey } = useFunkitConfig();
149
+ const isStablecoin = useIsStablecoin();
150
+ const { data, error, isLoading } = useQuery({
151
+ queryKey: ["getAssetPriceInfo", chainId, assetTokenAddress],
152
+ queryFn: enabled && chainId && assetTokenAddress ? () => getAssetPriceInfoWithFallback({
153
+ apiKey,
154
+ chainId,
155
+ assetTokenAddress
156
+ }) : skipToken,
157
+ refetchInterval
158
+ });
159
+ const unitPrice = symbol && isStablecoin(symbol) ? 1 : data?.unitPrice;
160
+ return {
161
+ error,
162
+ isLoading,
163
+ price: unitPrice !== void 0 ? unitPrice * amount : void 0
164
+ };
165
+ }
166
+
167
+ // src/clients/internal/nado/withdrawalForm.ts
168
+ var PRICE_REFRESH_MS = 6e4;
169
+ function isNadoSourceToken(option) {
170
+ return option.customData?.type === "nado" && option.asset?.decimals !== void 0;
171
+ }
172
+ function useNadoWithdrawalForm(config, selectedSourceToken) {
173
+ const nadoConfig = isNadoWithdrawalConfig(config) ? config : void 0;
174
+ const isNado = !!nadoConfig;
175
+ const subaccount = nadoConfig?.customerConfig.subaccount;
176
+ const [spotLeverage, setSpotLeverage] = useState(false);
177
+ useEffect(() => {
178
+ setSpotLeverage(false);
179
+ }, [subaccount]);
180
+ const { data: subaccountInfo } = useNadoSubaccountBalances(subaccount);
181
+ const { data: feeRates } = useNadoFeeRates(subaccount);
182
+ const balanceX18ByProductId = useMemo(
183
+ () => new Map(
184
+ (subaccountInfo?.spot_balances ?? []).map((b) => [
185
+ b.product_id,
186
+ b.balance.amount
187
+ ])
188
+ ),
189
+ [subaccountInfo]
190
+ );
191
+ const sourceOptions = useMemo(
192
+ () => (nadoConfig?.sourceTokens ?? []).filter(isNadoSourceToken).map(({ asset, customData, symbol, iconSrc }) => {
193
+ const balanceX18 = safeBigInt(
194
+ balanceX18ByProductId.get(customData.productId),
195
+ 0n
196
+ );
197
+ return {
198
+ productId: customData.productId,
199
+ symbol,
200
+ balanceTokenUnits: x18ToTokenUnits(
201
+ (balanceX18 > 0n ? balanceX18 : 0n).toString(),
202
+ asset.decimals
203
+ ),
204
+ decimals: asset.decimals,
205
+ tokenAddress: asset.tokenAddress,
206
+ tokenChainId: asset.tokenChainId,
207
+ iconSrc
208
+ };
209
+ }),
210
+ [nadoConfig?.sourceTokens, balanceX18ByProductId]
211
+ );
212
+ const selectedOption = sourceOptions.find(
213
+ (option) => option.symbol === selectedSourceToken
214
+ );
215
+ const selectedProductId = selectedOption?.productId;
216
+ useEffect(() => {
217
+ if (selectedProductId === void 0) {
218
+ return;
219
+ }
220
+ logger.info("nado:withdrawal:sourceSelected", {
221
+ productId: selectedProductId,
222
+ symbol: selectedSourceToken
223
+ });
224
+ }, [selectedProductId, selectedSourceToken]);
225
+ const { price: sourceTokenUsdPrice } = useAssetAddressPrice({
226
+ chainId: selectedOption?.tokenChainId,
227
+ assetTokenAddress: selectedOption?.tokenAddress,
228
+ symbol: selectedOption?.symbol,
229
+ refetchInterval: PRICE_REFRESH_MS,
230
+ enabled: isNado
231
+ });
232
+ const { data: maxWithdrawableX18 } = useNadoMaxWithdrawable({
233
+ productId: selectedOption?.productId,
234
+ sender: subaccount,
235
+ spotLeverage
236
+ });
237
+ const maxWithdrawableTokenUnits = selectedOption && maxWithdrawableX18 !== void 0 ? x18ToTokenUnits(maxWithdrawableX18, selectedOption.decimals) : void 0;
238
+ const withdrawableBalanceTokenUnits = spotLeverage ? maxWithdrawableTokenUnits ?? selectedOption?.balanceTokenUnits ?? "0" : selectedOption?.balanceTokenUnits ?? "0";
239
+ const sequencerFeeTokenAmount = useMemo(() => {
240
+ if (!isNado || !selectedOption) {
241
+ return 0;
242
+ }
243
+ const feeX18 = feeRates?.withdraw_sequencer_fees?.[selectedOption.productId];
244
+ if (feeX18 === void 0) {
245
+ return 0;
246
+ }
247
+ return Number(x18ToTokenUnits(feeX18, selectedOption.decimals));
248
+ }, [isNado, selectedOption, feeRates]);
249
+ const { t } = useFunkitTranslation();
250
+ const amountToggle = isNado ? {
251
+ label: t("withdrawal.enableBorrowing"),
252
+ checked: spotLeverage,
253
+ onChange: setSpotLeverage
254
+ } : void 0;
255
+ const buildSubmitCustomerData = () => {
256
+ if (!isNado || !selectedOption) {
257
+ return void 0;
258
+ }
259
+ logger.info("nado:withdrawal:submit", {
260
+ productId: selectedOption.productId,
261
+ spotLeverage,
262
+ sequencerFeeTokenAmount
263
+ });
264
+ return {
265
+ customerName: "nado",
266
+ productId: selectedOption.productId,
267
+ spotLeverage,
268
+ sequencerFeeTokenAmount
269
+ };
270
+ };
271
+ return {
272
+ isNado,
273
+ amountToggle,
274
+ maxWithdrawableTokenUnits,
275
+ withdrawableBalanceTokenUnits,
276
+ sequencerFeeTokenAmount,
277
+ sourceTokenUsdPrice,
278
+ buildSubmitCustomerData
279
+ };
280
+ }
281
+ export {
282
+ useNadoWithdrawalForm
283
+ };
@@ -8,13 +8,18 @@
8
8
  import type { Address, Hex } from 'viem';
9
9
  /**
10
10
  * Nado per-submission form selections threaded to the withdrawal callback (the
11
- * static config can't know them). `spotLeverage` must be explicit — Nado treats
12
- * an absent value as borrowing, so `false` fails instead of opening a borrow.
11
+ * static config can't know them).
12
+ * - `spotLeverage` must be explicit — Nado treats an absent value as borrowing,
13
+ * so `false` fails instead of opening a borrow.
14
+ * - `sequencerFeeTokenAmount` pins the fee the screen displayed, so the callback
15
+ * signs the same net amount instead of re-reading a possibly-refreshed cache.
13
16
  */
14
17
  export interface NadoWithdrawalCustomerData {
15
18
  customerName: 'nado';
16
19
  productId: number;
17
20
  spotLeverage: boolean;
21
+ /** Sequencer fee in the product's token units, as shown at submit. */
22
+ sequencerFeeTokenAmount: number;
18
23
  }
19
24
  /**
20
25
  * Nado config-level identity — the hook's **output**, not integrator input.
@@ -14,7 +14,7 @@
14
14
  * caller provides the actual on-chain implementation.
15
15
  */
16
16
  import { type Address } from 'viem';
17
- import type { CustomWithdrawalConfig, LighterRouteType, MultiMethodWithdrawalConfig } from '../providers/FunkitCheckoutContext/types';
17
+ import type { CustomWithdrawalConfig, LighterRouteType, MultiMethodWithdrawalConfig, SourceTokenOption, WithdrawalSourceTokenBalanceParams } from '../providers/FunkitCheckoutContext/types';
18
18
  export { LIGHTER_ROUTE_TYPE } from '../modals/WithdrawalModal/LighterWithdrawal';
19
19
  export type { LighterRouteType } from '../providers/FunkitCheckoutContext/types';
20
20
  export { LIGHTER_WITHDRAW_ABI, buildLighterL1WithdrawTransaction, isLighterWithdrawalRateLimitError, lighterWithdrawBaseUnits, } from '../utils/lighter';
@@ -55,6 +55,12 @@ export interface LighterWithdrawalConfig {
55
55
  /** Pre-built Lighter signer. */
56
56
  signerClient: LighterSigner;
57
57
  sendLighterSecureWithdrawal: LighterSecureWithdrawalExec;
58
+ /**
59
+ * Withdrawable balance for the selected source token, applied to both methods.
60
+ * Lighter's own accounting — it must account for what the SDK cannot see
61
+ * (margin requirements, locked collateral), so the integrator owns it.
62
+ */
63
+ withdrawalSourceTokenBalance?: (params: WithdrawalSourceTokenBalanceParams) => string | number;
58
64
  /**
59
65
  * Returns the minimum Secure withdrawal amount in token units for the given symbol.
60
66
  * Spot USDC is passed as `USDC (Spot)` (perps collateral is plain `USDC`);
@@ -104,6 +110,9 @@ export interface LighterSecureWithdrawalConfig {
104
110
  modalTitle?: string;
105
111
  disableConnectedWallet?: boolean;
106
112
  iconSrc?: string;
113
+ /** Selectable source tokens, built from the account's live asset list. */
114
+ sourceTokens?: SourceTokenOption[];
115
+ withdrawalSourceTokenBalance?: (params: WithdrawalSourceTokenBalanceParams) => string | number;
107
116
  /**
108
117
  * Submit the Secure withdrawal on Lighter's L2. Funds bridge directly to
109
118
  * Ethereum mainnet. No relay/swap — the token withdrawn is the token received.
@@ -156,6 +165,25 @@ export declare function trackLighterSecureWithdrawal({ apiKey, userId, txHash, r
156
165
  }): Promise<void>;
157
166
  /** Single-method config for Lighter's Secure withdrawal (bridge to Ethereum). */
158
167
  export declare function createLighterSecureWithdrawalConfig(config: LighterSecureWithdrawalConfig): CustomWithdrawalConfig;
168
+ /**
169
+ * Builds the source-token options list for the Lighter compound input dropdown.
170
+ *
171
+ * - Fast path: only USDC (Perps).
172
+ * - Secure path: USDC (Perps) (from total_asset_value) + USDC (Spot) when the
173
+ * account carries a spot USDC asset + every non-USDC asset on the account.
174
+ *
175
+ * Unified Trading accounts (`isUnifiedTradingMode`) have a single USDC balance
176
+ * — no spot/perps split — so the perps entry is labeled plain `USDC` and the
177
+ * `USDC (Spot)` entry is hidden on both paths.
178
+ */
179
+ export declare function buildLighterSourceTokenOptions({ isSecure, lighterAssets, isUnifiedTradingMode, }: {
180
+ /** Secure lists every spot asset alongside perps; Fast is perps-only. */
181
+ isSecure: boolean;
182
+ lighterAssets: {
183
+ symbol: string;
184
+ }[];
185
+ isUnifiedTradingMode?: boolean;
186
+ }): SourceTokenOption[];
159
187
  /**
160
188
  * The single React entry point for Lighter withdrawals. Returns a
161
189
  * `MultiMethodWithdrawalConfig` ready to hand to the withdrawal modal, or