@funkit/connect 11.4.0 → 11.5.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 +63 -0
- package/dist/clients/{chunk-5MY7WMEJ.js → chunk-3U55HYGJ.js} +2 -2
- package/dist/clients/{chunk-BPDLF2R6.js → chunk-DSZHYQPX.js} +1 -1
- package/dist/clients/chunk-MSLPLXR2.js +30 -0
- package/dist/clients/{chunk-3Y5EIONT.js → chunk-UMU5S2WF.js} +30 -39
- package/dist/clients/chunk-WCQ6HJ27.js +13 -0
- package/dist/clients/{chunk-XJTRLB7W.js → chunk-ZEDRWRYA.js} +15 -13
- package/dist/clients/fanatics.js +4 -4
- package/dist/clients/internal/nado/withdrawalCallback.js +2 -9
- package/dist/clients/internal/nado/withdrawalConfig.d.ts +4 -9
- package/dist/clients/internal/nado/withdrawalConfig.js +3 -7
- package/dist/clients/internal/nado/withdrawalErrors.d.ts +6 -10
- package/dist/clients/internal/nado/withdrawalErrors.js +1 -2
- package/dist/clients/internal/nado/withdrawalForm.css +82 -74
- package/dist/clients/internal/nado/withdrawalForm.d.ts +1 -1
- package/dist/clients/internal/nado/withdrawalForm.js +12 -45
- package/dist/clients/internal/nado/withdrawalStatus.d.ts +1 -15
- package/dist/clients/internal/nado/withdrawalStatus.js +11 -61
- package/dist/clients/lighter.css +260 -252
- package/dist/clients/lighter.js +6 -9
- package/dist/clients/nado.d.ts +2 -2
- package/dist/clients/nado.js +10 -16
- package/dist/clients/polymarket/PolymarketDepositAccountDropdown.css +263 -255
- package/dist/clients/polymarket/PolymarketDepositAccountDropdown.js +3 -3
- package/dist/clients/polymarket/index.css +263 -255
- package/dist/clients/polymarket/index.js +3 -3
- package/dist/components/Dropdown/BaseDropdown.css.d.ts +1 -0
- package/dist/components/Dropdown/BaseDropdown.d.ts +0 -1
- package/dist/consts/funkit.d.ts +2 -0
- package/dist/hooks/track/analytics/events.d.ts +35 -3
- package/dist/hooks/track/analytics/resolveExecutionProgressContext.d.ts +1 -0
- package/dist/hooks/track/analytics/useDepositAnalytics.d.ts +11 -3
- package/dist/hooks/track/analytics/useTrackExecutionProgressEvents.d.ts +1 -0
- package/dist/hooks/track/analytics/useWithdrawalAnalytics.d.ts +24 -1
- package/dist/hooks/useBluvo.d.ts +7 -2
- package/dist/hooks/useSwappedTheme.d.ts +3 -0
- package/dist/index.css +93 -85
- package/dist/index.js +12822 -12797
- package/dist/modals/WithdrawalModal/LighterWithdrawal.d.ts +5 -11
- package/dist/modals/WithdrawalModal/RecipientAddress.d.ts +3 -1
- package/dist/modals/WithdrawalModal/WithdrawAmountInput.d.ts +3 -1
- package/dist/providers/FunkitCheckoutContext/types.d.ts +1 -1
- package/dist/providers/FunkitProvider.d.ts +1 -0
- package/dist/shadow/adoptStyles.d.ts +5 -0
- package/dist/shadow-css.d.ts +1 -0
- package/dist/shadow-css.js +2 -0
- package/dist/utils/swapped.d.ts +8 -6
- package/dist/wallets/walletConnectors/index.js +9 -9
- package/package.json +11 -6
- package/shadow-css/package.json +3 -0
- package/dist/clients/chunk-2576N7PQ.js +0 -44
- package/dist/clients/chunk-3P2C436B.js +0 -20
- package/dist/clients/chunk-63XTVHO3.js +0 -19
- package/dist/clients/chunk-6T6URLBM.js +0 -33
- package/dist/clients/chunk-EQFVPSR2.js +0 -40
- package/dist/clients/chunk-FM7SFGAV.js +0 -106
- package/dist/clients/chunk-JFDRLSYM.js +0 -42
- package/dist/clients/chunk-TZGKB6WY.js +0 -160
- package/dist/clients/chunk-VIAEAD75.js +0 -61
- package/dist/clients/chunk-WZRW6WUM.js +0 -112
- package/dist/clients/chunk-Z7HTQFEO.js +0 -69
- package/dist/clients/internal/nado/consts.d.ts +0 -22
- package/dist/clients/internal/nado/consts.js +0 -15
- package/dist/clients/internal/nado/encoding.d.ts +0 -25
- package/dist/clients/internal/nado/encoding.js +0 -11
- package/dist/clients/internal/nado/errors.d.ts +0 -68
- package/dist/clients/internal/nado/errors.js +0 -19
- package/dist/clients/internal/nado/fetch.d.ts +0 -15
- package/dist/clients/internal/nado/fetch.js +0 -9
- package/dist/clients/internal/nado/gateway.d.ts +0 -61
- package/dist/clients/internal/nado/gateway.js +0 -17
- package/dist/clients/internal/nado/hooks.d.ts +0 -208
- package/dist/clients/internal/nado/hooks.js +0 -21
- package/dist/clients/internal/nado/indexer.d.ts +0 -43
- package/dist/clients/internal/nado/indexer.js +0 -13
- package/dist/clients/internal/nado/typedData.d.ts +0 -80
- package/dist/clients/internal/nado/typedData.js +0 -10
- package/dist/clients/internal/nado/withdrawalTypes.d.ts +0 -49
- package/dist/clients/internal/nado/withdrawalTypes.js +0 -1
- package/dist/utils/safeBigInt.d.ts +0 -5
package/dist/utils/swapped.d.ts
CHANGED
|
@@ -2,14 +2,16 @@ import type { SwappedTheme } from '@funkit/connect-core';
|
|
|
2
2
|
import type { ThemeVars } from '../css/sprinkles.css';
|
|
3
3
|
export { getFormOfPaymentDisplayName, getSavedFormOfPaymentDisplayName, getSavedFormOfPaymentIcon, getSwappedIcon, getSwappedOrigin, isSavedFormOfPaymentType, isSwappedOrigin, SWAPPED_CARD_BRANDS, } from '@funkit/connect-core';
|
|
4
4
|
export type { SwappedTheme };
|
|
5
|
-
export declare function resolveCssValue(value: string): string;
|
|
6
|
-
export declare function resolveObjectCssVars<T extends object>(obj: T): T;
|
|
5
|
+
export declare function resolveCssValue(value: string, scope: Element | null): string;
|
|
6
|
+
export declare function resolveObjectCssVars<T extends object>(obj: T, scope: Element | null): T;
|
|
7
7
|
/**
|
|
8
8
|
* Builds the SwappedTheme payload from a ThemeVars object. Pure — it does not
|
|
9
|
-
* touch the DOM, so it is safe to share across platforms.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* touch the DOM, so it is safe to share across platforms.
|
|
10
|
+
*
|
|
11
|
+
* Pass an already-resolved theme: `topbarPaddingX` is composed as
|
|
12
|
+
* `calc(<token> + 6px)`, and {@link resolveCssValue} only matches values that
|
|
13
|
+
* are entirely a `var(...)` ref, so anything wrapped in `calc()` here can no
|
|
14
|
+
* longer be resolved afterwards. Web callers use {@link resolveObjectCssVars}.
|
|
13
15
|
*/
|
|
14
16
|
export declare function buildSwappedTheme(theme: ThemeVars & {
|
|
15
17
|
customFontFamily?: {
|
|
@@ -101,12 +101,12 @@ import {
|
|
|
101
101
|
import {
|
|
102
102
|
ledgerWallet
|
|
103
103
|
} from "./chunk-RPV27V2Y.js";
|
|
104
|
-
import {
|
|
105
|
-
braveWallet
|
|
106
|
-
} from "./chunk-DS73TZ6O.js";
|
|
107
104
|
import {
|
|
108
105
|
clvWallet
|
|
109
106
|
} from "./chunk-UK7C2JXW.js";
|
|
107
|
+
import {
|
|
108
|
+
braveWallet
|
|
109
|
+
} from "./chunk-DS73TZ6O.js";
|
|
110
110
|
import {
|
|
111
111
|
coin98Wallet
|
|
112
112
|
} from "./chunk-6BW3HLBG.js";
|
|
@@ -128,18 +128,18 @@ import {
|
|
|
128
128
|
import {
|
|
129
129
|
argentWallet
|
|
130
130
|
} from "./chunk-NTMBEOR2.js";
|
|
131
|
-
import {
|
|
132
|
-
bitgetWallet
|
|
133
|
-
} from "./chunk-CPI4TD43.js";
|
|
134
|
-
import {
|
|
135
|
-
bitskiWallet
|
|
136
|
-
} from "./chunk-7HRFUZFX.js";
|
|
137
131
|
import {
|
|
138
132
|
bifrostWallet
|
|
139
133
|
} from "./chunk-4T6ZSRJF.js";
|
|
134
|
+
import {
|
|
135
|
+
bitgetWallet
|
|
136
|
+
} from "./chunk-CPI4TD43.js";
|
|
140
137
|
import {
|
|
141
138
|
bitverseWallet
|
|
142
139
|
} 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,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funkit/connect",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.5.0",
|
|
4
4
|
"description": "Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"styles.css",
|
|
8
8
|
"wallets",
|
|
9
|
+
"shadow-css",
|
|
9
10
|
"CHANGELOG.md"
|
|
10
11
|
],
|
|
11
12
|
"type": "module",
|
|
12
13
|
"exports": {
|
|
13
14
|
".": "./dist/index.js",
|
|
14
15
|
"./styles.css": "./dist/index.css",
|
|
16
|
+
"./shadow-css": {
|
|
17
|
+
"types": "./dist/shadow-css.d.ts",
|
|
18
|
+
"default": "./dist/shadow-css.js"
|
|
19
|
+
},
|
|
15
20
|
"./wallets": "./dist/wallets/walletConnectors/index.js",
|
|
16
21
|
"./clients/internal/*": null,
|
|
17
22
|
"./clients/*": "./dist/clients/*.js",
|
|
@@ -101,16 +106,16 @@
|
|
|
101
106
|
"motion": "^12.0.11",
|
|
102
107
|
"qrcode": "1.5.3",
|
|
103
108
|
"react-i18next": "16.3.3",
|
|
104
|
-
"react-remove-scroll": "2.
|
|
109
|
+
"react-remove-scroll": "^2.7.2",
|
|
105
110
|
"react-virtuoso": "4.10.1",
|
|
106
111
|
"ua-parser-js": "^1.0.37",
|
|
107
112
|
"use-debounce": "^10.0.5",
|
|
108
113
|
"uuid": "^11.1.1",
|
|
109
|
-
"@funkit/api-base": "7.1.
|
|
114
|
+
"@funkit/api-base": "7.1.2",
|
|
110
115
|
"@funkit/chains": "2.2.0",
|
|
111
|
-
"@funkit/
|
|
112
|
-
"@funkit/
|
|
113
|
-
"@funkit/
|
|
116
|
+
"@funkit/connect-core": "4.1.0",
|
|
117
|
+
"@funkit/utils": "4.0.1",
|
|
118
|
+
"@funkit/fun-relay": "2.14.0"
|
|
114
119
|
},
|
|
115
120
|
"repository": {
|
|
116
121
|
"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,40 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
isCustomWithdrawalConfig
|
|
4
|
-
} from "./chunk-B7UU2ETA.js";
|
|
5
|
-
import {
|
|
6
|
-
buildNadoSubaccountId
|
|
7
|
-
} from "./chunk-6T6URLBM.js";
|
|
8
|
-
import {
|
|
9
|
-
logger
|
|
10
|
-
} from "./chunk-AHYOV7AV.js";
|
|
11
|
-
|
|
12
|
-
// src/clients/internal/nado/withdrawalConfig.ts
|
|
13
|
-
var HEX_SHAPED_SUBACCOUNT_NAME = /^(?:[0-9a-f]{2})+$/i;
|
|
14
|
-
function isNadoWithdrawalConfig(config) {
|
|
15
|
-
return !!config && isCustomWithdrawalConfig(config) && config.customerConfig?.customerName === "nado";
|
|
16
|
-
}
|
|
17
|
-
function resolveNadoSubaccount(walletAddress, subaccountName) {
|
|
18
|
-
if (!walletAddress) {
|
|
19
|
-
return void 0;
|
|
20
|
-
}
|
|
21
|
-
if (subaccountName && HEX_SHAPED_SUBACCOUNT_NAME.test(subaccountName)) {
|
|
22
|
-
logger.warn("nado:withdrawal:hexShapedSubaccountName", {
|
|
23
|
-
name: subaccountName
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
return buildNadoSubaccountId(walletAddress, subaccountName);
|
|
28
|
-
} catch (err) {
|
|
29
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
30
|
-
logger.error("nado:withdrawal:invalidSubaccountName", error, {
|
|
31
|
-
name: subaccountName
|
|
32
|
-
});
|
|
33
|
-
return void 0;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
isNadoWithdrawalConfig,
|
|
39
|
-
resolveNadoSubaccount
|
|
40
|
-
};
|
|
@@ -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
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
NADO_ERROR_CODES,
|
|
4
|
-
NadoGatewayError,
|
|
5
|
-
NadoWithdrawalUnconfirmedError,
|
|
6
|
-
parseNadoExpectedNonce
|
|
7
|
-
} from "./chunk-Z7HTQFEO.js";
|
|
8
|
-
import {
|
|
9
|
-
i18n_default
|
|
10
|
-
} from "./chunk-C45VNQXY.js";
|
|
11
|
-
|
|
12
|
-
// src/clients/internal/nado/withdrawalErrors.ts
|
|
13
|
-
var EXPECTED_WITHDRAWAL_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
14
|
-
NADO_ERROR_CODES.SPOT_EXECUTE_EXCEEDS_BORROW_LIMIT,
|
|
15
|
-
NADO_ERROR_CODES.INVALID_NONCE,
|
|
16
|
-
NADO_ERROR_CODES.NO_PRIOR_DEPOSIT,
|
|
17
|
-
NADO_ERROR_CODES.WITHDRAW_RISK
|
|
18
|
-
]);
|
|
19
|
-
function isExpectedNadoWithdrawalFailure(error) {
|
|
20
|
-
if (!(error instanceof NadoGatewayError)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
if (parseNadoExpectedNonce(error) !== void 0) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
return error.kind === "transport" || error.kind === "timeout" || error.httpStatus === 429 || error.errorCode !== void 0 && EXPECTED_WITHDRAWAL_ERROR_CODES.has(error.errorCode);
|
|
27
|
-
}
|
|
28
|
-
function toNadoWithdrawalErrorMessage(error) {
|
|
29
|
-
if (error instanceof NadoWithdrawalUnconfirmedError) {
|
|
30
|
-
return i18n_default.t("withdrawal.nado.errorUnconfirmed");
|
|
31
|
-
}
|
|
32
|
-
if (!(error instanceof NadoGatewayError)) {
|
|
33
|
-
return i18n_default.t("withdrawal.nado.errorGeneric");
|
|
34
|
-
}
|
|
35
|
-
if (parseNadoExpectedNonce(error) !== void 0) {
|
|
36
|
-
return i18n_default.t("withdrawal.nado.errorInvalidNonce");
|
|
37
|
-
}
|
|
38
|
-
if (error.kind === "transport" || error.kind === "timeout") {
|
|
39
|
-
return i18n_default.t("withdrawal.nado.errorNetwork");
|
|
40
|
-
}
|
|
41
|
-
if (error.httpStatus === 429) {
|
|
42
|
-
return i18n_default.t("withdrawal.nado.errorRateLimited");
|
|
43
|
-
}
|
|
44
|
-
switch (error.errorCode) {
|
|
45
|
-
case NADO_ERROR_CODES.SPOT_EXECUTE_EXCEEDS_BORROW_LIMIT:
|
|
46
|
-
return i18n_default.t("withdrawal.nado.errorExceedsBorrowLimit");
|
|
47
|
-
case NADO_ERROR_CODES.INVALID_NONCE:
|
|
48
|
-
return i18n_default.t("withdrawal.nado.errorInvalidNonce");
|
|
49
|
-
case NADO_ERROR_CODES.NO_PRIOR_DEPOSIT:
|
|
50
|
-
return i18n_default.t("withdrawal.nado.errorNoPriorDeposit");
|
|
51
|
-
case NADO_ERROR_CODES.WITHDRAW_RISK:
|
|
52
|
-
return i18n_default.t("withdrawal.nado.errorWithdrawRisk");
|
|
53
|
-
default:
|
|
54
|
-
return i18n_default.t("withdrawal.nado.errorGeneric");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export {
|
|
59
|
-
isExpectedNadoWithdrawalFailure,
|
|
60
|
-
toNadoWithdrawalErrorMessage
|
|
61
|
-
};
|