@funkit/connect 10.6.0 → 11.1.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/CHANGELOG.md +46 -0
- package/dist/clients/{chunk-F6P4CN27.js → chunk-2QYQNTOI.js} +161 -18
- package/dist/clients/chunk-5MY7WMEJ.js +20 -0
- package/dist/clients/chunk-63XTVHO3.js +19 -0
- package/dist/clients/chunk-6T6URLBM.js +33 -0
- package/dist/clients/chunk-A44M6EAG.js +160 -0
- package/dist/clients/chunk-A6OXZWCN.js +40 -0
- package/dist/clients/chunk-BPDLF2R6.js +31 -0
- package/dist/clients/chunk-C53FRCUM.js +190 -0
- package/dist/clients/{chunk-6PIIYPQK.js → chunk-EJKHMZW3.js} +4 -327
- package/dist/clients/chunk-FAYBQQNB.js +15 -0
- package/dist/clients/{chunk-3LJQTM37.js → chunk-FNB7OPJI.js} +12 -198
- package/dist/clients/{chunk-2NBYHUIW.js → chunk-HZP4DXIZ.js} +1 -0
- package/dist/clients/chunk-NAVU6W7V.js +89 -0
- package/dist/clients/{chunk-BNMZM23Q.js → chunk-OJZNF6EM.js} +2 -2
- package/dist/clients/{chunk-FJ6GCMJ4.js → chunk-OODIKHYE.js} +3 -1
- package/dist/clients/chunk-PENJ5JGH.js +331 -0
- package/dist/clients/{chunk-TG2AACP2.js → chunk-QIMCURVA.js} +10 -10
- package/dist/clients/{chunk-YFHTV7DT.js → chunk-SH3MHRHX.js} +1 -1
- package/dist/clients/chunk-SO756ELD.js +35 -0
- package/dist/clients/chunk-SYFHMTUO.js +106 -0
- package/dist/clients/chunk-WVM4ZJD2.js +61 -0
- package/dist/clients/{chunk-L2KSNS7H.js → chunk-WZRW6WUM.js} +1 -1
- package/dist/clients/chunk-YMGRBJAS.js +302 -0
- package/dist/clients/chunk-YZSO4EMO.js +44 -0
- package/dist/clients/{chunk-2YWQL3AO.js → chunk-Z7HTQFEO.js} +26 -3
- package/dist/clients/fanatics.js +6 -6
- package/dist/clients/internal/nado/encoding.d.ts +5 -2
- package/dist/clients/internal/nado/encoding.js +4 -25
- package/dist/clients/internal/nado/errors.d.ts +14 -1
- package/dist/clients/internal/nado/errors.js +7 -3
- package/dist/clients/internal/nado/fetch.js +2 -2
- package/dist/clients/internal/nado/gateway.d.ts +19 -41
- package/dist/clients/internal/nado/gateway.js +3 -9
- package/dist/clients/internal/nado/hooks.d.ts +8 -160
- package/dist/clients/internal/nado/hooks.js +13 -124
- package/dist/clients/internal/nado/indexer.js +3 -3
- package/dist/clients/internal/nado/typedData.js +4 -37
- package/dist/clients/internal/nado/withdrawalCallback.d.ts +20 -0
- package/dist/clients/internal/nado/withdrawalCallback.js +20 -0
- package/dist/clients/internal/nado/withdrawalConfig.d.ts +8 -3
- package/dist/clients/internal/nado/withdrawalConfig.js +8 -14
- package/dist/clients/internal/nado/withdrawalErrors.d.ts +14 -0
- package/dist/clients/internal/nado/withdrawalErrors.js +11 -0
- package/dist/clients/internal/nado/withdrawalForm.css +17529 -0
- package/dist/clients/internal/nado/withdrawalForm.d.ts +40 -0
- package/dist/clients/internal/nado/withdrawalForm.js +262 -0
- package/dist/clients/internal/nado/withdrawalStatus.d.ts +41 -0
- package/dist/clients/internal/nado/withdrawalStatus.js +231 -0
- package/dist/clients/internal/nado/withdrawalTypes.d.ts +28 -9
- package/dist/clients/lighter.css +18 -18
- package/dist/clients/lighter.d.ts +29 -1
- package/dist/clients/lighter.js +109 -100
- package/dist/clients/mallard.js +27 -5
- package/dist/clients/nado.d.ts +67 -0
- package/dist/clients/nado.js +73 -0
- package/dist/clients/polymarket/PolymarketDepositAccountDropdown.css +60 -60
- package/dist/clients/polymarket/PolymarketDepositAccountDropdown.js +11 -5
- package/dist/clients/polymarket/createPolymarketDepositConfig.js +3 -2
- package/dist/clients/polymarket/index.css +60 -60
- package/dist/clients/polymarket/index.js +11 -5
- package/dist/clients/polymarket/polymarket.js +2 -1
- package/dist/consts/customers.d.ts +1 -1
- package/dist/domains/swapped.d.ts +1 -10
- package/dist/hooks/track/analytics/events.d.ts +57 -0
- package/dist/hooks/track/analytics/mappers.d.ts +6 -0
- package/dist/hooks/track/analytics/useDepositAnalytics.d.ts +20 -0
- package/dist/hooks/track/useTrack.d.ts +2 -1
- package/dist/hooks/useTokenAndChainDropdown.d.ts +8 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3647 -2728
- package/dist/modals/WithdrawalModal/LighterWithdrawal.d.ts +20 -31
- package/dist/modals/WithdrawalModal/NadoWithdrawalSuccess.d.ts +20 -0
- package/dist/modals/WithdrawalModal/WithdrawAmountInput.d.ts +5 -9
- package/dist/providers/FunkitCheckoutContext/types.d.ts +61 -5
- package/dist/providers/GeneralWalletProvider.d.ts +1 -0
- package/dist/utils/customer.d.ts +349 -0
- package/dist/utils/withdrawal.d.ts +13 -6
- package/dist/wagmi/actions.d.ts +1 -1
- package/dist/wallets/Wallet.d.ts +21 -1
- package/dist/wallets/walletConnectors/index.js +43 -43
- package/package.json +4 -4
- package/dist/clients/chunk-A4WQS6QG.js +0 -207
- package/dist/clients/chunk-OZ3KD24N.js +0 -107
- package/dist/clients/internal/nado/products.d.ts +0 -36
- package/dist/clients/internal/nado/products.js +0 -19
|
@@ -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
|
package/dist/clients/lighter.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
-
AsyncImage
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
AsyncImage,
|
|
4
|
+
sanitizeUrl
|
|
5
|
+
} from "./chunk-HZP4DXIZ.js";
|
|
6
|
+
import "./chunk-OODIKHYE.js";
|
|
6
7
|
import {
|
|
7
8
|
chainMetadataById,
|
|
8
|
-
useFunkitConfig,
|
|
9
9
|
useFunkitConnectChainsById
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-FNB7OPJI.js";
|
|
11
|
+
import {
|
|
12
|
+
useLighterAccountQuery,
|
|
13
|
+
useLighterAccountsQuery
|
|
14
|
+
} from "./chunk-NAVU6W7V.js";
|
|
15
|
+
import {
|
|
16
|
+
useFunkitConfig
|
|
17
|
+
} from "./chunk-C53FRCUM.js";
|
|
11
18
|
import {
|
|
12
19
|
Box
|
|
13
20
|
} from "./chunk-LUHEVXPD.js";
|
|
14
|
-
import "./chunk-UPZNKPYU.js";
|
|
15
21
|
import {
|
|
16
22
|
useFunkitTranslation
|
|
17
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-FAYBQQNB.js";
|
|
24
|
+
import "./chunk-UPZNKPYU.js";
|
|
25
|
+
import "./chunk-2QYQNTOI.js";
|
|
18
26
|
import {
|
|
19
27
|
logger
|
|
20
28
|
} from "./chunk-AHYOV7AV.js";
|
|
@@ -22,18 +30,18 @@ import {
|
|
|
22
30
|
// src/clients/lighter.tsx
|
|
23
31
|
import {
|
|
24
32
|
DirectExecutionType as DirectExecutionType2,
|
|
25
|
-
LIGHTERXYZ_API_KEY
|
|
33
|
+
LIGHTERXYZ_API_KEY,
|
|
26
34
|
createDirectExecution as createDirectExecution2
|
|
27
35
|
} from "@funkit/api-base";
|
|
28
36
|
import { LIGHTER_CHAIN_ID, SOLANA_MAINNET_CHAIN_ID } from "@funkit/chains";
|
|
29
37
|
import { RELAY_LIGHTER_CHAIN_ID as RELAY_LIGHTER_CHAIN_ID2 } from "@funkit/fun-relay";
|
|
30
38
|
import { retry } from "@lifeomic/attempt";
|
|
31
|
-
import { useQuery as
|
|
39
|
+
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
32
40
|
import i18next from "i18next";
|
|
33
41
|
import React4, { useMemo as useMemo2 } from "react";
|
|
34
42
|
import { v4 as uuid2 } from "uuid";
|
|
35
|
-
import { pad, parseUnits as parseUnits3, toHex } from "viem";
|
|
36
|
-
import { arbitrum, base, bsc, mainnet as
|
|
43
|
+
import { pad as pad2, parseUnits as parseUnits3, toHex } from "viem";
|
|
44
|
+
import { arbitrum, base, bsc, mainnet as mainnet2, optimism } from "viem/chains";
|
|
37
45
|
|
|
38
46
|
// src/components/ChainIcon/ChainIcon.tsx
|
|
39
47
|
import React from "react";
|
|
@@ -157,89 +165,15 @@ import { RELAY_LIGHTER_CHAIN_ID } from "@funkit/fun-relay";
|
|
|
157
165
|
import { formatAddress, formatCryptoAndStringify } from "@funkit/utils";
|
|
158
166
|
import { v4 as uuid } from "uuid";
|
|
159
167
|
import React3, {
|
|
160
|
-
useCallback as
|
|
168
|
+
useCallback as useCallback2,
|
|
161
169
|
useEffect,
|
|
162
170
|
useMemo,
|
|
163
171
|
useRef,
|
|
164
172
|
useState
|
|
165
173
|
} from "react";
|
|
166
174
|
import { createPortal } from "react-dom";
|
|
167
|
-
import { parseUnits as parseUnits2 } from "viem";
|
|
168
|
-
import { mainnet as mainnet2 } from "viem/chains";
|
|
169
|
-
|
|
170
|
-
// src/utils/customer.ts
|
|
171
|
-
import { useQuery as useQuery2, useQueryClient } from "@tanstack/react-query";
|
|
172
|
-
import { useCallback as useCallback2 } from "react";
|
|
173
|
-
|
|
174
|
-
// src/consts/customers.ts
|
|
175
|
-
import {
|
|
176
|
-
AAVE_API_KEY,
|
|
177
|
-
AVANTIS_API_KEY,
|
|
178
|
-
BASED_API_KEY,
|
|
179
|
-
BSX_API_KEY,
|
|
180
|
-
ETHEREAL_API_KEY,
|
|
181
|
-
FANATICS_API_KEY,
|
|
182
|
-
HYENA_API_KEY,
|
|
183
|
-
HYPERDASH_API_KEY,
|
|
184
|
-
LIGHTERXYZ_API_KEY,
|
|
185
|
-
MALLARD_API_KEY,
|
|
186
|
-
MONAD_API_KEY,
|
|
187
|
-
MONKEY_TILT_API_KEY,
|
|
188
|
-
NADO_API_KEY,
|
|
189
|
-
OSTIUM_API_KEY,
|
|
190
|
-
PERPL_API_KEY,
|
|
191
|
-
POLYMARKET_API_KEY
|
|
192
|
-
} from "@funkit/api-base";
|
|
175
|
+
import { numberToHex, pad, parseUnits as parseUnits2 } from "viem";
|
|
193
176
|
import { mainnet } from "viem/chains";
|
|
194
|
-
function isLighterxyzCustomer(apiKey) {
|
|
195
|
-
return apiKey === LIGHTERXYZ_API_KEY;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// src/utils/customer.ts
|
|
199
|
-
var LIGHTER_MAIN_ACCOUNT_TYPE = 0;
|
|
200
|
-
var LIGHTER_TRADING_MODE = {
|
|
201
|
-
SIMPLE: 0,
|
|
202
|
-
UNIFIED: 1
|
|
203
|
-
};
|
|
204
|
-
async function getLighterAccountsByL1Address(address) {
|
|
205
|
-
const response = await fetch(
|
|
206
|
-
`https://mainnet.zklighter.elliot.ai/api/v1/accountsByL1Address?l1_address=${address}`
|
|
207
|
-
);
|
|
208
|
-
if (!response.ok) {
|
|
209
|
-
throw new Error(`Failed to fetch lighter accounts: ${response.statusText}`);
|
|
210
|
-
}
|
|
211
|
-
const data = await response.json();
|
|
212
|
-
return data;
|
|
213
|
-
}
|
|
214
|
-
function useLighterAccounts({
|
|
215
|
-
address
|
|
216
|
-
}) {
|
|
217
|
-
const { apiKey } = useFunkitConfig();
|
|
218
|
-
const isLighter = isLighterxyzCustomer(apiKey);
|
|
219
|
-
const enabled = !!address && address !== "0x" && isLighter;
|
|
220
|
-
const query = useQuery2({
|
|
221
|
-
queryKey: ["lighterAccounts", address],
|
|
222
|
-
queryFn: () => getLighterAccountsByL1Address(address),
|
|
223
|
-
enabled,
|
|
224
|
-
staleTime: Number.POSITIVE_INFINITY,
|
|
225
|
-
gcTime: Number.POSITIVE_INFINITY,
|
|
226
|
-
retry: false,
|
|
227
|
-
// allows us to always refetch the data but return the previous data until the new data is fetched
|
|
228
|
-
refetchOnMount: "always"
|
|
229
|
-
});
|
|
230
|
-
const subAccounts = query.data?.sub_accounts;
|
|
231
|
-
const mainAccount = subAccounts?.find(
|
|
232
|
-
(account) => account.account_type === LIGHTER_MAIN_ACCOUNT_TYPE
|
|
233
|
-
);
|
|
234
|
-
return {
|
|
235
|
-
...query,
|
|
236
|
-
mainAccountIndex: mainAccount?.index?.toString(),
|
|
237
|
-
// False until the accounts load — consumers fall back to the simple-mode
|
|
238
|
-
// UI (both USDC variants shown) while the trading mode is unknown.
|
|
239
|
-
isUnifiedTradingMode: mainAccount?.account_trading_mode === LIGHTER_TRADING_MODE.UNIFIED,
|
|
240
|
-
subAccounts
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
177
|
|
|
244
178
|
// src/utils/lighter.ts
|
|
245
179
|
import {
|
|
@@ -300,6 +234,23 @@ function isLighterWithdrawalRateLimitError(error) {
|
|
|
300
234
|
return message.includes("23004") || message.includes("23005") || message.includes("rate limit") || message.includes("ratelimit");
|
|
301
235
|
}
|
|
302
236
|
|
|
237
|
+
// src/utils/tokenIconUrl.ts
|
|
238
|
+
var getLocalTokenIconUrl = (symbol) => {
|
|
239
|
+
return ASSET_LOGO_SRCS[symbol.toUpperCase()] || `https://sdk-cdn.fun.xyz/images/${encodeURIComponent(symbol.toLowerCase())}.svg`;
|
|
240
|
+
};
|
|
241
|
+
var getTokenIconUrl = (symbol, tokens) => {
|
|
242
|
+
if (tokens) {
|
|
243
|
+
const token = tokens.find(
|
|
244
|
+
(token2) => token2.tokenSymbol.toLowerCase() === symbol.toLowerCase()
|
|
245
|
+
);
|
|
246
|
+
if (token) {
|
|
247
|
+
return sanitizeUrl(token.iconSrc) ?? getLocalTokenIconUrl(symbol);
|
|
248
|
+
}
|
|
249
|
+
return getLocalTokenIconUrl(symbol);
|
|
250
|
+
}
|
|
251
|
+
return getLocalTokenIconUrl(symbol);
|
|
252
|
+
};
|
|
253
|
+
|
|
303
254
|
// src/utils/timeFormat.ts
|
|
304
255
|
import { formatSecondsToReadableForm } from "@funkit/utils";
|
|
305
256
|
function formatSecondsTranslated(seconds, t, specifyUnderMinute = false, omitSeconds = false) {
|
|
@@ -315,6 +266,7 @@ function formatSecondsTranslated(seconds, t, specifyUnderMinute = false, omitSec
|
|
|
315
266
|
// src/modals/WithdrawalModal/LighterWithdrawal.tsx
|
|
316
267
|
var LIGHTER_FAST_METHOD_ID = "lighter-fast";
|
|
317
268
|
var LIGHTER_SECURE_METHOD_ID = "lighter-secure";
|
|
269
|
+
var LIGHTER_USDC_SPOT_SYMBOL = "USDC (Spot)";
|
|
318
270
|
var LIGHTER_ROUTE_TYPE = {
|
|
319
271
|
PERPS: 0,
|
|
320
272
|
SPOT: 1
|
|
@@ -350,7 +302,7 @@ async function getLighterWithdrawalDelay() {
|
|
|
350
302
|
}
|
|
351
303
|
function useLighterSecureDelayText() {
|
|
352
304
|
const { t } = useFunkitTranslation();
|
|
353
|
-
const query =
|
|
305
|
+
const query = useQuery2({
|
|
354
306
|
queryKey: ["lighterWithdrawalDelay"],
|
|
355
307
|
queryFn: getLighterWithdrawalDelay,
|
|
356
308
|
staleTime: 6e4,
|
|
@@ -526,7 +478,7 @@ async function trackLighterSecureWithdrawal({
|
|
|
526
478
|
const estTotalUsd = Number(withdrawalUSD);
|
|
527
479
|
const safeAmount = truncateToDecimals(amountTokenUnits, decimals);
|
|
528
480
|
const baseUnitAmount = parseUnits3(safeAmount, decimals).toString();
|
|
529
|
-
const fromTokenAddress =
|
|
481
|
+
const fromTokenAddress = pad2(toHex(assetIndex), { size: 20 });
|
|
530
482
|
await createDirectExecution2({
|
|
531
483
|
apiKey,
|
|
532
484
|
logger,
|
|
@@ -539,7 +491,7 @@ async function trackLighterSecureWithdrawal({
|
|
|
539
491
|
recipientAddr,
|
|
540
492
|
fromChainId: LIGHTER_CHAIN_ID.toString(),
|
|
541
493
|
fromTokenAddress,
|
|
542
|
-
toChainId:
|
|
494
|
+
toChainId: mainnet2.id.toString(),
|
|
543
495
|
toTokenAddress: mainnetTokenAddress,
|
|
544
496
|
fromAmountBaseUnit: baseUnitAmount,
|
|
545
497
|
toAmountBaseUnit: baseUnitAmount,
|
|
@@ -556,7 +508,7 @@ async function trackLighterSecureWithdrawal({
|
|
|
556
508
|
initSettings: {
|
|
557
509
|
config: {
|
|
558
510
|
targetAsset: mainnetTokenAddress,
|
|
559
|
-
targetChain:
|
|
511
|
+
targetChain: mainnet2.id.toString(),
|
|
560
512
|
targetAssetTicker: symbol
|
|
561
513
|
}
|
|
562
514
|
},
|
|
@@ -619,7 +571,7 @@ function buildSecureWithdrawalCallback({
|
|
|
619
571
|
txHash
|
|
620
572
|
});
|
|
621
573
|
void trackLighterSecureWithdrawal({
|
|
622
|
-
apiKey:
|
|
574
|
+
apiKey: LIGHTERXYZ_API_KEY,
|
|
623
575
|
// Secure locks the destination to the connected wallet, so the L1
|
|
624
576
|
// recipient address doubles as the userId for tracking purposes.
|
|
625
577
|
userId: destinationAddress,
|
|
@@ -645,10 +597,12 @@ function createLighterSecureWithdrawalConfig(config) {
|
|
|
645
597
|
modalTitle: config.modalTitle ?? i18next.t("withdrawal.withdraw"),
|
|
646
598
|
disableConnectedWallet: config.disableConnectedWallet,
|
|
647
599
|
onBeforeSign: config.onBeforeSign,
|
|
600
|
+
sourceTokens: config.sourceTokens,
|
|
601
|
+
withdrawalSourceTokenBalance: config.withdrawalSourceTokenBalance,
|
|
648
602
|
withdrawCallback: buildSecureWithdrawalCallback({
|
|
649
603
|
exec: config.sendLighterSecureWithdrawal
|
|
650
604
|
}),
|
|
651
|
-
sourceChainId:
|
|
605
|
+
sourceChainId: mainnet2.id.toString(),
|
|
652
606
|
sourceTokenSymbol: "USDC",
|
|
653
607
|
defaultReceiveToken: "USDC",
|
|
654
608
|
sourceTokenAddress: MAINNET_USDC,
|
|
@@ -657,13 +611,46 @@ function createLighterSecureWithdrawalConfig(config) {
|
|
|
657
611
|
getMinWithdrawalAmount: config.getMinWithdrawalAmount
|
|
658
612
|
};
|
|
659
613
|
}
|
|
614
|
+
function buildLighterSourceTokenOptions({
|
|
615
|
+
isSecure,
|
|
616
|
+
lighterAssets,
|
|
617
|
+
isUnifiedTradingMode = false
|
|
618
|
+
}) {
|
|
619
|
+
const usdcOption = {
|
|
620
|
+
symbol: "USDC",
|
|
621
|
+
label: isUnifiedTradingMode ? "USDC" : "USDC (Perps)",
|
|
622
|
+
iconSrc: getTokenIconUrl("USDC")
|
|
623
|
+
};
|
|
624
|
+
if (!isSecure) {
|
|
625
|
+
return [usdcOption];
|
|
626
|
+
}
|
|
627
|
+
const spotOptions = lighterAssets.filter(
|
|
628
|
+
(asset) => !(isUnifiedTradingMode && asset.symbol.toUpperCase() === "USDC")
|
|
629
|
+
).map((asset) => {
|
|
630
|
+
if (asset.symbol.toUpperCase() === "USDC") {
|
|
631
|
+
return {
|
|
632
|
+
symbol: LIGHTER_USDC_SPOT_SYMBOL,
|
|
633
|
+
label: LIGHTER_USDC_SPOT_SYMBOL,
|
|
634
|
+
iconSrc: getTokenIconUrl("USDC")
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
return {
|
|
638
|
+
symbol: asset.symbol,
|
|
639
|
+
label: asset.symbol,
|
|
640
|
+
iconSrc: getTokenIconUrl(asset.symbol)
|
|
641
|
+
};
|
|
642
|
+
});
|
|
643
|
+
return [usdcOption, ...spotOptions];
|
|
644
|
+
}
|
|
660
645
|
function buildLighterFastWalletWithdrawalConfig({
|
|
661
646
|
signerClient,
|
|
662
647
|
accountIndex,
|
|
663
648
|
modalTitle,
|
|
664
649
|
disableConnectedWallet,
|
|
665
650
|
iconSrc,
|
|
666
|
-
onBeforeSign
|
|
651
|
+
onBeforeSign,
|
|
652
|
+
isUnifiedTradingMode,
|
|
653
|
+
withdrawalSourceTokenBalance
|
|
667
654
|
}) {
|
|
668
655
|
const adaptedWallet = createLighterAdaptedWallet({
|
|
669
656
|
signerClient,
|
|
@@ -691,6 +678,12 @@ function buildLighterFastWalletWithdrawalConfig({
|
|
|
691
678
|
wallet,
|
|
692
679
|
sourceChainId: RELAY_LIGHTER_CHAIN_ID2,
|
|
693
680
|
sourceTokenSymbol: "USDC",
|
|
681
|
+
sourceTokens: buildLighterSourceTokenOptions({
|
|
682
|
+
isSecure: false,
|
|
683
|
+
lighterAssets: [],
|
|
684
|
+
isUnifiedTradingMode
|
|
685
|
+
}),
|
|
686
|
+
withdrawalSourceTokenBalance,
|
|
694
687
|
defaultReceiveToken: "USDC",
|
|
695
688
|
sourceTokenAddress: LIGHTER_USDC_PERPS_ADDRESS,
|
|
696
689
|
iconSrc: iconSrc ?? "https://sdk-cdn.fun.xyz/images/logos/lighter.png",
|
|
@@ -716,13 +709,14 @@ var LIGHTER_FAST_PREVIEW_CHAIN_IDS = [
|
|
|
716
709
|
bsc.id,
|
|
717
710
|
SOLANA_MAINNET_CHAIN_ID
|
|
718
711
|
];
|
|
719
|
-
var LIGHTER_SECURE_PREVIEW_CHAIN_IDS = [
|
|
712
|
+
var LIGHTER_SECURE_PREVIEW_CHAIN_IDS = [mainnet2.id];
|
|
720
713
|
function buildLighterMultiMethodConfig({
|
|
721
714
|
config,
|
|
722
715
|
accountIndex,
|
|
723
716
|
t,
|
|
724
717
|
secureDelayText,
|
|
725
|
-
isUnifiedTradingMode
|
|
718
|
+
isUnifiedTradingMode,
|
|
719
|
+
assets
|
|
726
720
|
}) {
|
|
727
721
|
const fastConfig = buildLighterFastWalletWithdrawalConfig({
|
|
728
722
|
signerClient: config.signerClient,
|
|
@@ -730,10 +724,18 @@ function buildLighterMultiMethodConfig({
|
|
|
730
724
|
modalTitle: config.modalTitle,
|
|
731
725
|
disableConnectedWallet: config.disableConnectedWallet,
|
|
732
726
|
iconSrc: config.fastIconSrc,
|
|
733
|
-
onBeforeSign: config.onBeforeSign
|
|
727
|
+
onBeforeSign: config.onBeforeSign,
|
|
728
|
+
isUnifiedTradingMode,
|
|
729
|
+
withdrawalSourceTokenBalance: config.withdrawalSourceTokenBalance
|
|
734
730
|
});
|
|
735
731
|
const secureConfig = createLighterSecureWithdrawalConfig({
|
|
736
732
|
accountIndex,
|
|
733
|
+
sourceTokens: buildLighterSourceTokenOptions({
|
|
734
|
+
isSecure: true,
|
|
735
|
+
lighterAssets: assets,
|
|
736
|
+
isUnifiedTradingMode
|
|
737
|
+
}),
|
|
738
|
+
withdrawalSourceTokenBalance: config.withdrawalSourceTokenBalance,
|
|
737
739
|
modalTitle: config.modalTitle,
|
|
738
740
|
disableConnectedWallet: config.disableConnectedWallet,
|
|
739
741
|
iconSrc: config.secureIconSrc,
|
|
@@ -778,11 +780,16 @@ function buildLighterMultiMethodConfig({
|
|
|
778
780
|
}
|
|
779
781
|
function useLighterWithdrawalConfig(config) {
|
|
780
782
|
const { t } = useFunkitTranslation();
|
|
781
|
-
const { mainAccountIndex, isUnifiedTradingMode } =
|
|
783
|
+
const { mainAccountIndex, isUnifiedTradingMode } = useLighterAccountsQuery({
|
|
782
784
|
address: config?.l1Address
|
|
783
785
|
});
|
|
784
786
|
const accountIndex = mainAccountIndex && /^\d+$/.test(mainAccountIndex) ? mainAccountIndex : void 0;
|
|
785
787
|
const secureDelayText = useLighterSecureDelayText();
|
|
788
|
+
const { account } = useLighterAccountQuery(
|
|
789
|
+
// Validated numeric above, so the template-literal narrowing is safe.
|
|
790
|
+
accountIndex ? { by: "index", value: accountIndex } : null
|
|
791
|
+
);
|
|
792
|
+
const assets = useMemo2(() => account?.assets ?? [], [account]);
|
|
786
793
|
return useMemo2(() => {
|
|
787
794
|
if (!config || !accountIndex) {
|
|
788
795
|
return null;
|
|
@@ -792,15 +799,17 @@ function useLighterWithdrawalConfig(config) {
|
|
|
792
799
|
accountIndex,
|
|
793
800
|
t,
|
|
794
801
|
secureDelayText,
|
|
795
|
-
isUnifiedTradingMode
|
|
802
|
+
isUnifiedTradingMode,
|
|
803
|
+
assets
|
|
796
804
|
});
|
|
797
|
-
}, [config, accountIndex, t, secureDelayText, isUnifiedTradingMode]);
|
|
805
|
+
}, [config, accountIndex, t, secureDelayText, isUnifiedTradingMode, assets]);
|
|
798
806
|
}
|
|
799
807
|
export {
|
|
800
808
|
LIGHTER_DEFAULT_SECURE_MIN_WITHDRAWAL_AMOUNTS,
|
|
801
809
|
LIGHTER_ROUTE_TYPE,
|
|
802
810
|
LIGHTER_WITHDRAW_ABI,
|
|
803
811
|
buildLighterL1WithdrawTransaction,
|
|
812
|
+
buildLighterSourceTokenOptions,
|
|
804
813
|
createLighterSecureWithdrawalConfig,
|
|
805
814
|
isLighterWithdrawalRateLimitError,
|
|
806
815
|
lighterWithdrawBaseUnits,
|
package/dist/clients/mallard.js
CHANGED
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
import {
|
|
3
3
|
getAccount,
|
|
4
4
|
sendTransaction,
|
|
5
|
+
signMessage,
|
|
6
|
+
signTypedData,
|
|
5
7
|
switchChain,
|
|
6
8
|
waitForTransactionReceipt
|
|
7
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-OODIKHYE.js";
|
|
10
|
+
import {
|
|
11
|
+
useFunkitTranslation
|
|
12
|
+
} from "./chunk-FAYBQQNB.js";
|
|
8
13
|
import {
|
|
9
14
|
useAccount,
|
|
10
15
|
useConfig
|
|
11
16
|
} from "./chunk-UPZNKPYU.js";
|
|
12
|
-
import
|
|
13
|
-
useFunkitTranslation
|
|
14
|
-
} from "./chunk-F6P4CN27.js";
|
|
17
|
+
import "./chunk-2QYQNTOI.js";
|
|
15
18
|
import {
|
|
16
19
|
logger
|
|
17
20
|
} from "./chunk-AHYOV7AV.js";
|
|
@@ -131,7 +134,26 @@ function createConnectedWalletWithdrawalClient(config, ownerAddress, sourceChain
|
|
|
131
134
|
hash: txHash,
|
|
132
135
|
chainId
|
|
133
136
|
})
|
|
134
|
-
)
|
|
137
|
+
),
|
|
138
|
+
// Gasless (EIP-3009/permit) relay routes return a typed-data signature
|
|
139
|
+
// step instead of a transaction — sign it with the connected wallet.
|
|
140
|
+
signTypedData: async (typedData) => {
|
|
141
|
+
const domainChainId = typedData.domain?.chainId;
|
|
142
|
+
if (domainChainId != null) {
|
|
143
|
+
await ensureOnChain(Number(domainChainId));
|
|
144
|
+
}
|
|
145
|
+
return signTypedData(config, {
|
|
146
|
+
account: ownerAddress,
|
|
147
|
+
domain: typedData.domain,
|
|
148
|
+
types: typedData.types,
|
|
149
|
+
primaryType: typedData.primaryType,
|
|
150
|
+
message: typedData.message
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
signMessage: (message) => signMessage(config, {
|
|
154
|
+
account: ownerAddress,
|
|
155
|
+
message: typeof message === "string" ? message : { raw: message.raw }
|
|
156
|
+
})
|
|
135
157
|
};
|
|
136
158
|
}
|
|
137
159
|
function useMallardWithdrawalConfig(config) {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nado withdrawals — the public integration surface.
|
|
3
|
+
*
|
|
4
|
+
* Pass the returned config to the withdrawal modal; the SDK renders the Nado
|
|
5
|
+
* enter-amount screen, signs Nado's gasless `withdraw_collateral_v2` against a
|
|
6
|
+
* Fun deposit address, and routes the settled funds to the user's destination.
|
|
7
|
+
*
|
|
8
|
+
* Everything an integrator touches is exported from this file and nowhere else —
|
|
9
|
+
* not the root entry. Anything they don't stays in `clients/internal/nado/`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const nado = useNadoWithdrawalConfig(
|
|
14
|
+
* isConnected
|
|
15
|
+
* ? { sourceTokens: NADO_SOURCE_TOKENS, sourceTokenSymbol: 'USDT0' }
|
|
16
|
+
* : null,
|
|
17
|
+
* )
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { SourceTokenOption, TokenInfo } from '../providers/FunkitCheckoutContext/types';
|
|
21
|
+
import { type NadoWithdrawalConfig } from './internal/nado/withdrawalConfig';
|
|
22
|
+
export interface NadoWithdrawalOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Nado's withdrawable assets. Each option must carry
|
|
25
|
+
* `customData: { type: 'nado', productId }` and `asset.decimals` — the product
|
|
26
|
+
* id addresses the subaccount balance and the decimals scale the signed
|
|
27
|
+
* amount, so an option missing either is skipped.
|
|
28
|
+
*/
|
|
29
|
+
sourceTokens: SourceTokenOption[];
|
|
30
|
+
/** Symbol of the initially selected option; must match one in {@link sourceTokens}. */
|
|
31
|
+
sourceTokenSymbol: string;
|
|
32
|
+
/**
|
|
33
|
+
* Active subaccount's name as your subaccount state holds it (`default`,
|
|
34
|
+
* `default_1`, …) — not the profile label the user sees, and not a decoded
|
|
35
|
+
* engine value. The SDK packs it with the connected wallet. Defaults to
|
|
36
|
+
* `default`; `''` is a different subaccount, and over 12 bytes disables the
|
|
37
|
+
* config.
|
|
38
|
+
*/
|
|
39
|
+
subaccountName?: string;
|
|
40
|
+
modalTitle?: string;
|
|
41
|
+
iconSrc?: null | string;
|
|
42
|
+
disableConnectedWallet?: boolean;
|
|
43
|
+
/** Token pre-selected in the receive dropdown. Defaults to the source token. */
|
|
44
|
+
defaultReceiveToken?: string;
|
|
45
|
+
/** Awaited after the user commits, before any nonce fetch or signature. Throw to abort. */
|
|
46
|
+
onBeforeSign?: () => Promise<void> | void;
|
|
47
|
+
getMinWithdrawalUSD?: (asset: TokenInfo) => number;
|
|
48
|
+
getMaxWithdrawalUSD?: (asset: TokenInfo) => number;
|
|
49
|
+
/**
|
|
50
|
+
* Minimum withdrawal in token units per source symbol. Preferred over
|
|
51
|
+
* {@link NadoWithdrawalOptions.getMinWithdrawalUSD} here — the floor is the
|
|
52
|
+
* sequencer fee, which Nado charges per asset, not per dollar.
|
|
53
|
+
*/
|
|
54
|
+
getMinWithdrawalAmount?: (symbol: string) => number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Withdrawal config for a Nado subaccount, or `null` while one can't be built —
|
|
58
|
+
* keep the withdraw entry point disabled until it resolves.
|
|
59
|
+
*
|
|
60
|
+
* Null means the wallet is disconnected, `options` is null, or
|
|
61
|
+
* `sourceTokenSymbol` names no entry in `sourceTokens` that carries an `asset`.
|
|
62
|
+
* The last is a wiring bug and is not logged, so check it first if the button
|
|
63
|
+
* never enables.
|
|
64
|
+
*/
|
|
65
|
+
export declare function useNadoWithdrawalConfig(options: NadoWithdrawalOptions | null): NadoWithdrawalConfig | null;
|
|
66
|
+
export type { NadoWithdrawalConfig } from './internal/nado/withdrawalConfig';
|
|
67
|
+
export type { NadoWithdrawalCustomerConfig, NadoWithdrawalCustomerData, } from './internal/nado/withdrawalTypes';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
createNadoWithdrawalCallback
|
|
4
|
+
} from "./chunk-YMGRBJAS.js";
|
|
5
|
+
import "./chunk-YZSO4EMO.js";
|
|
6
|
+
import "./chunk-WVM4ZJD2.js";
|
|
7
|
+
import "./chunk-63XTVHO3.js";
|
|
8
|
+
import {
|
|
9
|
+
resolveNadoSubaccount
|
|
10
|
+
} from "./chunk-A6OXZWCN.js";
|
|
11
|
+
import "./chunk-SO756ELD.js";
|
|
12
|
+
import "./chunk-6T6URLBM.js";
|
|
13
|
+
import "./chunk-A44M6EAG.js";
|
|
14
|
+
import {
|
|
15
|
+
INK_CHAIN_ID
|
|
16
|
+
} from "./chunk-II5CZTBC.js";
|
|
17
|
+
import "./chunk-WZRW6WUM.js";
|
|
18
|
+
import "./chunk-Z7HTQFEO.js";
|
|
19
|
+
import "./chunk-OODIKHYE.js";
|
|
20
|
+
import {
|
|
21
|
+
useAccount,
|
|
22
|
+
useConfig
|
|
23
|
+
} from "./chunk-UPZNKPYU.js";
|
|
24
|
+
import {
|
|
25
|
+
i18n_default
|
|
26
|
+
} from "./chunk-2QYQNTOI.js";
|
|
27
|
+
import "./chunk-PENJ5JGH.js";
|
|
28
|
+
import "./chunk-AHYOV7AV.js";
|
|
29
|
+
|
|
30
|
+
// src/clients/nado.tsx
|
|
31
|
+
import { useMemo } from "react";
|
|
32
|
+
function useNadoWithdrawalConfig(options) {
|
|
33
|
+
const { address: walletAddress } = useAccount();
|
|
34
|
+
const wagmiConfig = useConfig();
|
|
35
|
+
const subaccountName = options?.subaccountName;
|
|
36
|
+
const subaccount = useMemo(
|
|
37
|
+
() => resolveNadoSubaccount(walletAddress, subaccountName),
|
|
38
|
+
[walletAddress, subaccountName]
|
|
39
|
+
);
|
|
40
|
+
const withdrawCallback = useMemo(
|
|
41
|
+
() => walletAddress && subaccount ? createNadoWithdrawalCallback({
|
|
42
|
+
walletAddress,
|
|
43
|
+
subaccount,
|
|
44
|
+
wagmiConfig
|
|
45
|
+
}) : void 0,
|
|
46
|
+
[walletAddress, subaccount, wagmiConfig]
|
|
47
|
+
);
|
|
48
|
+
const sourceTokenAddress = options?.sourceTokens?.find(
|
|
49
|
+
(option) => option.symbol === options.sourceTokenSymbol
|
|
50
|
+
)?.asset?.tokenAddress;
|
|
51
|
+
if (!options || !walletAddress || !subaccount || !withdrawCallback || !sourceTokenAddress) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
modalTitle: options.modalTitle ?? i18n_default.t("withdrawal.withdraw"),
|
|
56
|
+
iconSrc: options.iconSrc,
|
|
57
|
+
disableConnectedWallet: options.disableConnectedWallet,
|
|
58
|
+
onBeforeSign: options.onBeforeSign,
|
|
59
|
+
sourceChainId: INK_CHAIN_ID.toString(),
|
|
60
|
+
sourceTokens: options.sourceTokens,
|
|
61
|
+
sourceTokenSymbol: options.sourceTokenSymbol,
|
|
62
|
+
sourceTokenAddress,
|
|
63
|
+
defaultReceiveToken: options.defaultReceiveToken ?? options.sourceTokenSymbol,
|
|
64
|
+
getMinWithdrawalUSD: options.getMinWithdrawalUSD,
|
|
65
|
+
getMaxWithdrawalUSD: options.getMaxWithdrawalUSD,
|
|
66
|
+
getMinWithdrawalAmount: options.getMinWithdrawalAmount,
|
|
67
|
+
withdrawCallback,
|
|
68
|
+
customerConfig: { customerName: "nado", walletAddress, subaccount }
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
useNadoWithdrawalConfig
|
|
73
|
+
};
|