@funkit/connect 11.0.0 → 11.2.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 +71 -0
- package/dist/clients/chunk-2576N7PQ.js +44 -0
- package/dist/clients/{chunk-II5CZTBC.js → chunk-3P2C436B.js} +3 -1
- package/dist/clients/chunk-63XTVHO3.js +19 -0
- package/dist/clients/chunk-6QCAWEAT.js +53 -0
- package/dist/clients/{chunk-6CYZKITE.js → chunk-6T6URLBM.js} +1 -1
- package/dist/clients/{chunk-LT4EWLDA.js → chunk-BPDLF2R6.js} +1 -0
- package/dist/clients/{chunk-JD2J5K6S.js → chunk-C45VNQXY.js} +161 -18
- package/dist/clients/chunk-DGBIV3ZS.js +36 -0
- package/dist/clients/{chunk-MGQLVTSH.js → chunk-FM7SFGAV.js} +27 -21
- package/dist/clients/{chunk-6PIIYPQK.js → chunk-IYCZWLAF.js} +5 -327
- package/dist/clients/{chunk-BNMZM23Q.js → chunk-JFDRLSYM.js} +3 -3
- package/dist/clients/chunk-PENJ5JGH.js +331 -0
- package/dist/clients/chunk-QQEGNLGD.js +40 -0
- package/dist/clients/chunk-SU3YSNMB.js +306 -0
- package/dist/clients/chunk-TZGKB6WY.js +160 -0
- package/dist/clients/{chunk-2FSEE3AW.js → chunk-UK64SY6N.js} +2 -89
- package/dist/clients/chunk-VIAEAD75.js +61 -0
- package/dist/clients/{chunk-L2KSNS7H.js → chunk-WZRW6WUM.js} +1 -1
- package/dist/clients/{chunk-C4SHJFOV.js → chunk-XJTRLB7W.js} +9 -9
- package/dist/clients/{chunk-YFHTV7DT.js → chunk-Y7WLUPTX.js} +1 -1
- package/dist/clients/chunk-YUZ3B2Q3.js +15 -0
- package/dist/clients/{chunk-2YWQL3AO.js → chunk-Z7HTQFEO.js} +26 -3
- package/dist/clients/fanatics.js +2 -1
- package/dist/clients/internal/nado/consts.d.ts +6 -0
- package/dist/clients/internal/nado/consts.js +5 -3
- package/dist/clients/internal/nado/encoding.d.ts +5 -2
- package/dist/clients/internal/nado/encoding.js +1 -1
- 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 -20
- package/dist/clients/internal/nado/gateway.js +4 -6
- package/dist/clients/internal/nado/hooks.d.ts +8 -2
- package/dist/clients/internal/nado/hooks.js +10 -10
- package/dist/clients/internal/nado/indexer.js +4 -4
- 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 +7 -3
- 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 +43 -35
- package/dist/clients/internal/nado/withdrawalForm.d.ts +9 -7
- package/dist/clients/internal/nado/withdrawalForm.js +81 -98
- 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 +21 -7
- package/dist/clients/lighter.css +61 -53
- package/dist/clients/lighter.js +8 -7
- package/dist/clients/mallard.js +4 -3
- package/dist/clients/nado.d.ts +67 -0
- package/dist/clients/nado.js +73 -0
- package/dist/clients/polymarket/PolymarketDepositAccountDropdown.css +103 -95
- package/dist/clients/polymarket/PolymarketDepositAccountDropdown.js +9 -6
- package/dist/clients/polymarket/createPolymarketDepositConfig.js +3 -2
- package/dist/clients/polymarket/index.css +103 -95
- package/dist/clients/polymarket/index.js +9 -6
- package/dist/clients/polymarket/polymarket.js +2 -1
- package/dist/components/Dialog/Dialog.d.ts +3 -1
- package/dist/components/Dialog/DialogContent.css.d.ts +6 -0
- package/dist/components/FunCheckbox/FunCheckbox.d.ts +3 -1
- package/dist/components/FunTransactionSummary/PaymentFeesSummary.d.ts +2 -1
- package/dist/consts/customers.d.ts +1 -1
- package/dist/domains/nado.d.ts +11 -2
- package/dist/domains/quoteMode/types.d.ts +16 -0
- package/dist/domains/relay.d.ts +0 -3
- package/dist/hooks/track/analytics/events.d.ts +85 -0
- package/dist/hooks/track/analytics/mappers.d.ts +8 -0
- package/dist/hooks/track/analytics/useDepositAnalytics.d.ts +37 -0
- package/dist/hooks/track/useTrack.d.ts +3 -2
- package/dist/hooks/useFunkitTranslation.d.ts +5 -0
- package/dist/hooks/useTokenAndChainDropdown.d.ts +4 -1
- package/dist/index.css +43 -35
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4414 -3570
- package/dist/modals/CheckoutModal/InputAmount/InputAmount.d.ts +5 -1
- package/dist/modals/CheckoutModal/InputAmount/state.d.ts +13 -0
- package/dist/modals/CheckoutModal/InputAmount/useMeld.d.ts +4 -3
- package/dist/modals/CheckoutModal/InputAmount/utils.d.ts +9 -1
- package/dist/modals/CheckoutModal/MeldQuotes/MeldQuotes.d.ts +3 -1
- package/dist/modals/CheckoutModal/MeldRedirect/MeldRedirect.d.ts +4 -1
- package/dist/modals/CheckoutModal/SourceChange/useBottomBarCloseLabel.d.ts +7 -0
- package/dist/modals/WithdrawalModal/LockedReceiveDisplay.d.ts +22 -0
- package/dist/modals/WithdrawalModal/NadoWithdrawalSuccess.d.ts +20 -0
- package/dist/modals/WithdrawalModal/withdrawalFormHelpers.d.ts +18 -1
- package/dist/modals/WithdrawalModal/withdrawalHooks.d.ts +1 -1
- package/dist/providers/FunkitCheckoutContext/types.d.ts +4 -3
- package/dist/providers/FunkitStatsigProvider.d.ts +7 -0
- package/dist/providers/GeneralWalletProvider.d.ts +1 -0
- package/dist/utils/customer.d.ts +23 -230
- package/dist/utils/withdrawal.d.ts +11 -1
- package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
- package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
- package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
- package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
- package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
- package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
- package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
- package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
- package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
- package/dist/wallets/walletConnectors/index.js +33 -33
- package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
- package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
- package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
- package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
- package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
- package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
- package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
- package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
- package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
- package/package.json +4 -4
- package/dist/clients/chunk-SFDEST63.js +0 -18
- package/dist/clients/chunk-ZCCLJW6F.js +0 -99
- package/dist/wallets/walletConnectors/{chunk-W2LCLDPX.js → chunk-2VP2F6EK.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-IULPZP2Q.js → chunk-4T6ZSRJF.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-WAHGI5L7.js → chunk-6BW3HLBG.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-YO2K4MBH.js → chunk-CCQV2ZET.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-TKB2OY6G.js → chunk-CPI4TD43.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-OX37G4YT.js → chunk-F5XEEVG6.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-JPN6TWIT.js → chunk-HNRB7KJU.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-WKNQMP4A.js → chunk-HTHAK6XB.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-GUQM4QSL.js → chunk-MIQTHJ6X.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-4NV5BYRP.js → chunk-RB3HR4R2.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-SWFF3TWJ.js → chunk-RVOY537T.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-KI5Y2BBF.js → chunk-STVVP43G.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-OEEGYENV.js → chunk-UK7C2JXW.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-YQFGVZGR.js → chunk-VAPGUPHO.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-XCNHV3HS.js → chunk-VTM6EECM.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-NR2OGDHQ.js → chunk-X6CGV36L.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-AVDUNQUW.js → chunk-YEZM4CK4.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-KCRO2AGO.js → chunk-ZNX4EMPB.js} +3 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
isCustomWithdrawalConfig
|
|
4
|
+
} from "./chunk-DGBIV3ZS.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
|
+
};
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
buildWithdrawCollateralV2TypedData
|
|
4
|
+
} from "./chunk-2576N7PQ.js";
|
|
5
|
+
import {
|
|
6
|
+
isExpectedNadoWithdrawalFailure,
|
|
7
|
+
toNadoWithdrawalErrorMessage
|
|
8
|
+
} from "./chunk-VIAEAD75.js";
|
|
9
|
+
import {
|
|
10
|
+
safeBigInt
|
|
11
|
+
} from "./chunk-63XTVHO3.js";
|
|
12
|
+
import {
|
|
13
|
+
deductFlatFee,
|
|
14
|
+
toWithdrawalAmountBaseUnit
|
|
15
|
+
} from "./chunk-DGBIV3ZS.js";
|
|
16
|
+
import {
|
|
17
|
+
x18ToRawBaseUnit
|
|
18
|
+
} from "./chunk-6T6URLBM.js";
|
|
19
|
+
import {
|
|
20
|
+
executeNadoWithdrawCollateralV2,
|
|
21
|
+
getNadoMaxWithdrawable,
|
|
22
|
+
getNadoTxNonce
|
|
23
|
+
} from "./chunk-TZGKB6WY.js";
|
|
24
|
+
import {
|
|
25
|
+
INK_CHAIN_ID,
|
|
26
|
+
NADO_WITHDRAWAL_ACTION_TYPE
|
|
27
|
+
} from "./chunk-3P2C436B.js";
|
|
28
|
+
import {
|
|
29
|
+
NadoGatewayError,
|
|
30
|
+
NadoWithdrawalUnconfirmedError
|
|
31
|
+
} from "./chunk-Z7HTQFEO.js";
|
|
32
|
+
import {
|
|
33
|
+
getAccount,
|
|
34
|
+
signTypedData,
|
|
35
|
+
switchChain
|
|
36
|
+
} from "./chunk-OODIKHYE.js";
|
|
37
|
+
import {
|
|
38
|
+
i18n_default
|
|
39
|
+
} from "./chunk-C45VNQXY.js";
|
|
40
|
+
import {
|
|
41
|
+
generateClientMetadataForTokenTransfer
|
|
42
|
+
} from "./chunk-PENJ5JGH.js";
|
|
43
|
+
import {
|
|
44
|
+
logger
|
|
45
|
+
} from "./chunk-AHYOV7AV.js";
|
|
46
|
+
|
|
47
|
+
// src/clients/internal/nado/withdrawalCallback.ts
|
|
48
|
+
import {
|
|
49
|
+
NADO_API_KEY,
|
|
50
|
+
initializeCheckoutTokenTransferAddress
|
|
51
|
+
} from "@funkit/api-base";
|
|
52
|
+
import { isEVMAddressEquivalent } from "@funkit/utils";
|
|
53
|
+
|
|
54
|
+
// src/utils/signature.ts
|
|
55
|
+
function isUserRejectedError(error) {
|
|
56
|
+
if (!(error instanceof Error)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const regex = /user\s?rejected/gi;
|
|
60
|
+
return regex.test(error.name) || regex.test(error.message);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/clients/internal/nado/withdrawalCallback.ts
|
|
64
|
+
var NadoWithdrawalInputError = class extends Error {
|
|
65
|
+
};
|
|
66
|
+
var NadoWithdrawalUserError = class extends Error {
|
|
67
|
+
};
|
|
68
|
+
function createNadoWithdrawalCallback({
|
|
69
|
+
walletAddress,
|
|
70
|
+
subaccount,
|
|
71
|
+
wagmiConfig
|
|
72
|
+
}) {
|
|
73
|
+
return async (param) => {
|
|
74
|
+
const {
|
|
75
|
+
customerData,
|
|
76
|
+
userInputAmount,
|
|
77
|
+
targetAssetAddress,
|
|
78
|
+
targetChainId,
|
|
79
|
+
destinationAddress
|
|
80
|
+
} = param;
|
|
81
|
+
let step = "validate";
|
|
82
|
+
try {
|
|
83
|
+
if (customerData?.customerName !== "nado" || !userInputAmount) {
|
|
84
|
+
throw new NadoWithdrawalInputError(
|
|
85
|
+
"Missing Nado customerData or userInputAmount"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const {
|
|
89
|
+
spotLeverage,
|
|
90
|
+
sequencerFeeTokenAmount,
|
|
91
|
+
selectedSourceToken: { productId, decimals }
|
|
92
|
+
} = customerData;
|
|
93
|
+
const netTokens = deductFlatFee(userInputAmount, sequencerFeeTokenAmount);
|
|
94
|
+
const netRawAmount = toWithdrawalAmountBaseUnit(netTokens, decimals);
|
|
95
|
+
if (netRawAmount <= 0n) {
|
|
96
|
+
logger.warn("nado:withdrawal:amountTooLow", {
|
|
97
|
+
productId,
|
|
98
|
+
userInputAmount,
|
|
99
|
+
sequencerFeeTokenAmount
|
|
100
|
+
});
|
|
101
|
+
throw new NadoWithdrawalUserError(
|
|
102
|
+
i18n_default.t("withdrawal.nado.errorAmountTooLow")
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
logger.info("nado:withdrawal:start", {
|
|
106
|
+
productId,
|
|
107
|
+
spotLeverage,
|
|
108
|
+
decimals,
|
|
109
|
+
userInputAmount,
|
|
110
|
+
netTokens,
|
|
111
|
+
sequencerFeeTokenAmount,
|
|
112
|
+
targetChainId,
|
|
113
|
+
targetAssetAddress,
|
|
114
|
+
destinationAddress
|
|
115
|
+
});
|
|
116
|
+
await assertWithinMaxWithdrawable({
|
|
117
|
+
subaccount,
|
|
118
|
+
productId,
|
|
119
|
+
decimals,
|
|
120
|
+
spotLeverage,
|
|
121
|
+
netRawAmount
|
|
122
|
+
});
|
|
123
|
+
step = "switchChain";
|
|
124
|
+
await ensureWalletOnInk(wagmiConfig);
|
|
125
|
+
assertOwnerIsSigner({ walletAddress, wagmiConfig });
|
|
126
|
+
step = "uda";
|
|
127
|
+
const transferInit = await initializeCheckoutTokenTransferAddress({
|
|
128
|
+
apiKey: NADO_API_KEY,
|
|
129
|
+
// No Fun user context in a client bundle entry; the owner wallet is the
|
|
130
|
+
// stable per-user id and matches what sourceOfFund records.
|
|
131
|
+
userId: walletAddress,
|
|
132
|
+
recipientAddr: destinationAddress,
|
|
133
|
+
toChainId: targetChainId.toString(),
|
|
134
|
+
toTokenAddress: targetAssetAddress,
|
|
135
|
+
sourceOfFund: `balance|nado|${walletAddress}`,
|
|
136
|
+
// Attribution only — forces a separate UDA from Nado deposits so the
|
|
137
|
+
// direct executions off it are tagged as withdrawals.
|
|
138
|
+
actionType: NADO_WITHDRAWAL_ACTION_TYPE,
|
|
139
|
+
logger,
|
|
140
|
+
clientMetadata: {
|
|
141
|
+
...generateClientMetadataForTokenTransfer(),
|
|
142
|
+
isWithdrawal: true
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const depositAddr = transferInit.depositAddr;
|
|
146
|
+
logger.info("nado:withdrawal:udaGenerated", {
|
|
147
|
+
depositAddr,
|
|
148
|
+
productId,
|
|
149
|
+
destinationAddress
|
|
150
|
+
});
|
|
151
|
+
step = "sign";
|
|
152
|
+
const nonce = await getNadoTxNonce(walletAddress);
|
|
153
|
+
const signature = await signTypedData(wagmiConfig, {
|
|
154
|
+
...buildWithdrawCollateralV2TypedData({
|
|
155
|
+
sender: subaccount,
|
|
156
|
+
productId,
|
|
157
|
+
amount: netRawAmount,
|
|
158
|
+
nonce,
|
|
159
|
+
sendTo: depositAddr
|
|
160
|
+
}),
|
|
161
|
+
account: walletAddress
|
|
162
|
+
});
|
|
163
|
+
logger.info("nado:withdrawal:signed", {
|
|
164
|
+
nonce: nonce.toString(),
|
|
165
|
+
depositAddr,
|
|
166
|
+
productId
|
|
167
|
+
});
|
|
168
|
+
step = "execute";
|
|
169
|
+
await executeNadoWithdrawCollateralV2({
|
|
170
|
+
sender: subaccount,
|
|
171
|
+
productId,
|
|
172
|
+
amount: netRawAmount,
|
|
173
|
+
nonce,
|
|
174
|
+
sendTo: depositAddr,
|
|
175
|
+
signature,
|
|
176
|
+
spotLeverage
|
|
177
|
+
});
|
|
178
|
+
logger.info("nado:withdrawal:executeSubmitted", {
|
|
179
|
+
nonce: nonce.toString(),
|
|
180
|
+
depositAddr,
|
|
181
|
+
productId,
|
|
182
|
+
netRawAmount: netRawAmount.toString()
|
|
183
|
+
});
|
|
184
|
+
return depositAddr;
|
|
185
|
+
} catch (error) {
|
|
186
|
+
throw toThrownWithdrawalError(error, {
|
|
187
|
+
step,
|
|
188
|
+
walletAddress,
|
|
189
|
+
subaccount,
|
|
190
|
+
destinationAddress,
|
|
191
|
+
targetChainId
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async function assertWithinMaxWithdrawable({
|
|
197
|
+
subaccount,
|
|
198
|
+
productId,
|
|
199
|
+
decimals,
|
|
200
|
+
spotLeverage,
|
|
201
|
+
netRawAmount
|
|
202
|
+
}) {
|
|
203
|
+
const maxWithdrawableX18 = await getNadoMaxWithdrawable({
|
|
204
|
+
productId,
|
|
205
|
+
sender: subaccount,
|
|
206
|
+
spotLeverage
|
|
207
|
+
});
|
|
208
|
+
const maxRawAmount = x18ToRawBaseUnit(
|
|
209
|
+
safeBigInt(maxWithdrawableX18, 0n),
|
|
210
|
+
decimals
|
|
211
|
+
);
|
|
212
|
+
if (netRawAmount <= maxRawAmount) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
logger.warn("nado:withdrawal:exceedsMaxWithdrawable", {
|
|
216
|
+
productId,
|
|
217
|
+
spotLeverage,
|
|
218
|
+
netRawAmount: netRawAmount.toString(),
|
|
219
|
+
maxRawAmount: maxRawAmount.toString()
|
|
220
|
+
});
|
|
221
|
+
throw new NadoWithdrawalUserError(
|
|
222
|
+
i18n_default.t("withdrawal.nado.errorBalanceChanged")
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
async function ensureWalletOnInk(wagmiConfig) {
|
|
226
|
+
const connectedChainId = getAccount(wagmiConfig).chainId;
|
|
227
|
+
if (connectedChainId === INK_CHAIN_ID) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
logger.info("nado:withdrawal:switchingChain", {
|
|
231
|
+
fromChainId: connectedChainId ?? null
|
|
232
|
+
});
|
|
233
|
+
try {
|
|
234
|
+
await switchChain(wagmiConfig, { chainId: INK_CHAIN_ID });
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (isUserRejectedError(error)) {
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
logger.warn("nado:withdrawal:switchChainFailed", {
|
|
240
|
+
fromChainId: connectedChainId ?? null,
|
|
241
|
+
errorMessage: error instanceof Error ? error.message : String(error)
|
|
242
|
+
});
|
|
243
|
+
throw new NadoWithdrawalUserError(
|
|
244
|
+
i18n_default.t("withdrawal.nado.errorSwitchChain")
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function assertOwnerIsSigner({
|
|
249
|
+
walletAddress,
|
|
250
|
+
wagmiConfig
|
|
251
|
+
}) {
|
|
252
|
+
const connectedAddress = getAccount(wagmiConfig).address;
|
|
253
|
+
if (connectedAddress && isEVMAddressEquivalent({
|
|
254
|
+
firstAddress: connectedAddress,
|
|
255
|
+
secondAddress: walletAddress
|
|
256
|
+
})) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
logger.warn("nado:withdrawal:signerMismatch", {
|
|
260
|
+
walletAddress,
|
|
261
|
+
connectedAddress: connectedAddress ?? null
|
|
262
|
+
});
|
|
263
|
+
throw new NadoWithdrawalUserError(
|
|
264
|
+
i18n_default.t("withdrawal.nado.errorSignerMismatch")
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
function toThrownWithdrawalError(error, context) {
|
|
268
|
+
const logContext = {
|
|
269
|
+
...context,
|
|
270
|
+
nadoErrorCode: error instanceof NadoGatewayError ? error.errorCode ?? null : null,
|
|
271
|
+
nadoErrorKind: error instanceof NadoGatewayError ? error.kind : null,
|
|
272
|
+
errorMessage: error instanceof Error ? error.message : String(error)
|
|
273
|
+
};
|
|
274
|
+
if (isUserRejectedError(error)) {
|
|
275
|
+
logger.warn("nado:withdrawal:rejected", logContext);
|
|
276
|
+
return error;
|
|
277
|
+
}
|
|
278
|
+
if (error instanceof NadoWithdrawalUserError) {
|
|
279
|
+
return error;
|
|
280
|
+
}
|
|
281
|
+
if (error instanceof NadoWithdrawalInputError) {
|
|
282
|
+
logger.error("nado:withdrawal:invalidInput", error, logContext);
|
|
283
|
+
return new Error(i18n_default.t("withdrawal.nado.errorGeneric"));
|
|
284
|
+
}
|
|
285
|
+
if (error instanceof NadoWithdrawalUnconfirmedError) {
|
|
286
|
+
return new Error(toNadoWithdrawalErrorMessage(error));
|
|
287
|
+
}
|
|
288
|
+
if (!(error instanceof NadoGatewayError)) {
|
|
289
|
+
logger.error(
|
|
290
|
+
"nado:withdrawal:failed",
|
|
291
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
292
|
+
logContext
|
|
293
|
+
);
|
|
294
|
+
return error;
|
|
295
|
+
}
|
|
296
|
+
if (isExpectedNadoWithdrawalFailure(error)) {
|
|
297
|
+
logger.warn("nado:withdrawal:gatewayRejected", logContext);
|
|
298
|
+
} else {
|
|
299
|
+
logger.error("nado:withdrawal:gatewayFailed", error, logContext);
|
|
300
|
+
}
|
|
301
|
+
return new Error(toNadoWithdrawalErrorMessage(error));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export {
|
|
305
|
+
createNadoWithdrawalCallback
|
|
306
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
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,11 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
useFunkitTranslation
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
|
|
6
|
-
// src/utils/customer.ts
|
|
7
|
-
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
8
|
-
import { useCallback } from "react";
|
|
4
|
+
} from "./chunk-YUZ3B2Q3.js";
|
|
9
5
|
|
|
10
6
|
// src/providers/FunkitConfigContext.tsx
|
|
11
7
|
import {
|
|
@@ -189,89 +185,6 @@ function useFunkitConfig() {
|
|
|
189
185
|
return finalFunkitConfig;
|
|
190
186
|
}
|
|
191
187
|
|
|
192
|
-
// src/utils/customer.ts
|
|
193
|
-
var LIGHTER_MAIN_ACCOUNT_TYPE = 0;
|
|
194
|
-
var LIGHTER_TRADING_MODE = {
|
|
195
|
-
SIMPLE: 0,
|
|
196
|
-
UNIFIED: 1
|
|
197
|
-
};
|
|
198
|
-
async function getLighterAccountsByL1Address(address) {
|
|
199
|
-
const response = await fetch(
|
|
200
|
-
`https://mainnet.zklighter.elliot.ai/api/v1/accountsByL1Address?l1_address=${address}`
|
|
201
|
-
);
|
|
202
|
-
if (!response.ok) {
|
|
203
|
-
throw new Error(`Failed to fetch lighter accounts: ${response.statusText}`);
|
|
204
|
-
}
|
|
205
|
-
const data = await response.json();
|
|
206
|
-
return data;
|
|
207
|
-
}
|
|
208
|
-
async function getLighterAccount(lookup, activeOnly) {
|
|
209
|
-
const params = new URLSearchParams({
|
|
210
|
-
by: lookup.by,
|
|
211
|
-
value: String(lookup.value),
|
|
212
|
-
...activeOnly !== void 0 && { active_only: String(activeOnly) }
|
|
213
|
-
});
|
|
214
|
-
const response = await fetch(
|
|
215
|
-
`https://mainnet.zklighter.elliot.ai/api/v1/account?${params}`
|
|
216
|
-
);
|
|
217
|
-
if (!response.ok) {
|
|
218
|
-
throw new Error(`Failed to fetch lighter account: ${response.statusText}`);
|
|
219
|
-
}
|
|
220
|
-
return response.json();
|
|
221
|
-
}
|
|
222
|
-
function useLighterAccountQuery(lookup, options) {
|
|
223
|
-
const enabled = lookup !== null && (lookup.by === "index" ? true : !!lookup.value && lookup.value !== "0x");
|
|
224
|
-
const query = useQuery({
|
|
225
|
-
queryKey: [
|
|
226
|
-
"lighterAccount",
|
|
227
|
-
lookup?.by,
|
|
228
|
-
lookup?.value,
|
|
229
|
-
options?.activeOnly
|
|
230
|
-
],
|
|
231
|
-
// biome-ignore lint/style/noNonNullAssertion: already checked for null
|
|
232
|
-
queryFn: () => getLighterAccount(lookup, options?.activeOnly),
|
|
233
|
-
enabled,
|
|
234
|
-
// Refetch on every (re)mount so reopening the withdraw widget shows a fresh
|
|
235
|
-
// balance after a spot→perps transfer; 10s stale window keeps it current.
|
|
236
|
-
staleTime: 1e4,
|
|
237
|
-
refetchOnMount: "always",
|
|
238
|
-
retry: false
|
|
239
|
-
});
|
|
240
|
-
return {
|
|
241
|
-
...query,
|
|
242
|
-
account: query.data?.accounts?.[0]
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
function useLighterAccountsQuery({
|
|
246
|
-
address
|
|
247
|
-
}) {
|
|
248
|
-
const enabled = !!address && address !== "0x";
|
|
249
|
-
const query = useQuery({
|
|
250
|
-
queryKey: ["lighterAccounts", address],
|
|
251
|
-
queryFn: () => getLighterAccountsByL1Address(address),
|
|
252
|
-
enabled,
|
|
253
|
-
staleTime: Number.POSITIVE_INFINITY,
|
|
254
|
-
gcTime: Number.POSITIVE_INFINITY,
|
|
255
|
-
retry: false,
|
|
256
|
-
// allows us to always refetch the data but return the previous data until the new data is fetched
|
|
257
|
-
refetchOnMount: "always"
|
|
258
|
-
});
|
|
259
|
-
const subAccounts = query.data?.sub_accounts;
|
|
260
|
-
const mainAccount = subAccounts?.find(
|
|
261
|
-
(account) => account.account_type === LIGHTER_MAIN_ACCOUNT_TYPE
|
|
262
|
-
);
|
|
263
|
-
return {
|
|
264
|
-
...query,
|
|
265
|
-
mainAccountIndex: mainAccount?.index?.toString(),
|
|
266
|
-
// False until the accounts load — consumers fall back to the simple-mode
|
|
267
|
-
// UI (both USDC variants shown) while the trading mode is unknown.
|
|
268
|
-
isUnifiedTradingMode: mainAccount?.account_trading_mode === LIGHTER_TRADING_MODE.UNIFIED,
|
|
269
|
-
subAccounts
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
|
|
273
188
|
export {
|
|
274
|
-
useFunkitConfig
|
|
275
|
-
useLighterAccountQuery,
|
|
276
|
-
useLighterAccountsQuery
|
|
189
|
+
useFunkitConfig
|
|
277
190
|
};
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
};
|