@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
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
buildWithdrawCollateralV2TypedData
|
|
4
|
+
} from "./chunk-YZSO4EMO.js";
|
|
5
|
+
import {
|
|
6
|
+
isExpectedNadoWithdrawalFailure,
|
|
7
|
+
toNadoWithdrawalErrorMessage
|
|
8
|
+
} from "./chunk-WVM4ZJD2.js";
|
|
9
|
+
import {
|
|
10
|
+
safeBigInt
|
|
11
|
+
} from "./chunk-63XTVHO3.js";
|
|
12
|
+
import {
|
|
13
|
+
deductFlatFee,
|
|
14
|
+
toWithdrawalAmountBaseUnit
|
|
15
|
+
} from "./chunk-SO756ELD.js";
|
|
16
|
+
import {
|
|
17
|
+
x18ToRawBaseUnit
|
|
18
|
+
} from "./chunk-6T6URLBM.js";
|
|
19
|
+
import {
|
|
20
|
+
executeNadoWithdrawCollateralV2,
|
|
21
|
+
getNadoMaxWithdrawable,
|
|
22
|
+
getNadoTxNonce
|
|
23
|
+
} from "./chunk-A44M6EAG.js";
|
|
24
|
+
import {
|
|
25
|
+
INK_CHAIN_ID
|
|
26
|
+
} from "./chunk-II5CZTBC.js";
|
|
27
|
+
import {
|
|
28
|
+
NadoGatewayError,
|
|
29
|
+
NadoWithdrawalUnconfirmedError
|
|
30
|
+
} from "./chunk-Z7HTQFEO.js";
|
|
31
|
+
import {
|
|
32
|
+
getAccount,
|
|
33
|
+
signTypedData,
|
|
34
|
+
switchChain
|
|
35
|
+
} from "./chunk-OODIKHYE.js";
|
|
36
|
+
import {
|
|
37
|
+
i18n_default
|
|
38
|
+
} from "./chunk-2QYQNTOI.js";
|
|
39
|
+
import {
|
|
40
|
+
generateClientMetadataForTokenTransfer
|
|
41
|
+
} from "./chunk-PENJ5JGH.js";
|
|
42
|
+
import {
|
|
43
|
+
logger
|
|
44
|
+
} from "./chunk-AHYOV7AV.js";
|
|
45
|
+
|
|
46
|
+
// src/clients/internal/nado/withdrawalCallback.ts
|
|
47
|
+
import {
|
|
48
|
+
NADO_API_KEY,
|
|
49
|
+
initializeCheckoutTokenTransferAddress
|
|
50
|
+
} from "@funkit/api-base";
|
|
51
|
+
import { isEVMAddressEquivalent } from "@funkit/utils";
|
|
52
|
+
|
|
53
|
+
// src/utils/signature.ts
|
|
54
|
+
function isUserRejectedError(error) {
|
|
55
|
+
if (!(error instanceof Error)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const regex = /user\s?rejected/gi;
|
|
59
|
+
return regex.test(error.name) || regex.test(error.message);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/clients/internal/nado/withdrawalCallback.ts
|
|
63
|
+
var NadoWithdrawalInputError = class extends Error {
|
|
64
|
+
};
|
|
65
|
+
var NadoWithdrawalUserError = class extends Error {
|
|
66
|
+
};
|
|
67
|
+
function createNadoWithdrawalCallback({
|
|
68
|
+
walletAddress,
|
|
69
|
+
subaccount,
|
|
70
|
+
wagmiConfig
|
|
71
|
+
}) {
|
|
72
|
+
return async (param) => {
|
|
73
|
+
const {
|
|
74
|
+
customerData,
|
|
75
|
+
userInputAmount,
|
|
76
|
+
targetAssetAddress,
|
|
77
|
+
targetChainId,
|
|
78
|
+
destinationAddress
|
|
79
|
+
} = param;
|
|
80
|
+
let step = "validate";
|
|
81
|
+
try {
|
|
82
|
+
if (customerData?.customerName !== "nado" || !userInputAmount) {
|
|
83
|
+
throw new NadoWithdrawalInputError(
|
|
84
|
+
"Missing Nado customerData or userInputAmount"
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const {
|
|
88
|
+
spotLeverage,
|
|
89
|
+
sequencerFeeTokenAmount,
|
|
90
|
+
selectedSourceToken: { productId, decimals }
|
|
91
|
+
} = customerData;
|
|
92
|
+
const netTokens = deductFlatFee(userInputAmount, sequencerFeeTokenAmount);
|
|
93
|
+
const netRawAmount = toWithdrawalAmountBaseUnit(netTokens, decimals);
|
|
94
|
+
if (netRawAmount <= 0n) {
|
|
95
|
+
logger.warn("nado:withdrawal:amountTooLow", {
|
|
96
|
+
productId,
|
|
97
|
+
userInputAmount,
|
|
98
|
+
sequencerFeeTokenAmount
|
|
99
|
+
});
|
|
100
|
+
throw new NadoWithdrawalUserError(
|
|
101
|
+
i18n_default.t("withdrawal.nado.errorAmountTooLow")
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
logger.info("nado:withdrawal:start", {
|
|
105
|
+
productId,
|
|
106
|
+
spotLeverage,
|
|
107
|
+
decimals,
|
|
108
|
+
userInputAmount,
|
|
109
|
+
netTokens,
|
|
110
|
+
sequencerFeeTokenAmount,
|
|
111
|
+
targetChainId,
|
|
112
|
+
targetAssetAddress,
|
|
113
|
+
destinationAddress
|
|
114
|
+
});
|
|
115
|
+
await assertWithinMaxWithdrawable({
|
|
116
|
+
subaccount,
|
|
117
|
+
productId,
|
|
118
|
+
decimals,
|
|
119
|
+
spotLeverage,
|
|
120
|
+
netRawAmount
|
|
121
|
+
});
|
|
122
|
+
step = "switchChain";
|
|
123
|
+
await ensureWalletOnInk(wagmiConfig);
|
|
124
|
+
assertOwnerIsSigner({ walletAddress, wagmiConfig });
|
|
125
|
+
step = "uda";
|
|
126
|
+
const transferInit = await initializeCheckoutTokenTransferAddress({
|
|
127
|
+
apiKey: NADO_API_KEY,
|
|
128
|
+
// No Fun user context in a client bundle entry; the owner wallet is the
|
|
129
|
+
// stable per-user id and matches what sourceOfFund records.
|
|
130
|
+
userId: walletAddress,
|
|
131
|
+
recipientAddr: destinationAddress,
|
|
132
|
+
toChainId: targetChainId.toString(),
|
|
133
|
+
toTokenAddress: targetAssetAddress,
|
|
134
|
+
sourceOfFund: `balance|nado|${walletAddress}`,
|
|
135
|
+
logger,
|
|
136
|
+
clientMetadata: {
|
|
137
|
+
...generateClientMetadataForTokenTransfer(),
|
|
138
|
+
isWithdrawal: true
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const depositAddr = transferInit.depositAddr;
|
|
142
|
+
logger.info("nado:withdrawal:udaGenerated", {
|
|
143
|
+
depositAddr,
|
|
144
|
+
productId,
|
|
145
|
+
destinationAddress
|
|
146
|
+
});
|
|
147
|
+
step = "sign";
|
|
148
|
+
const nonce = await getNadoTxNonce(walletAddress);
|
|
149
|
+
const signature = await signTypedData(wagmiConfig, {
|
|
150
|
+
...buildWithdrawCollateralV2TypedData({
|
|
151
|
+
sender: subaccount,
|
|
152
|
+
productId,
|
|
153
|
+
amount: netRawAmount,
|
|
154
|
+
nonce,
|
|
155
|
+
sendTo: depositAddr
|
|
156
|
+
}),
|
|
157
|
+
account: walletAddress
|
|
158
|
+
});
|
|
159
|
+
logger.info("nado:withdrawal:signed", {
|
|
160
|
+
nonce: nonce.toString(),
|
|
161
|
+
depositAddr,
|
|
162
|
+
productId
|
|
163
|
+
});
|
|
164
|
+
step = "execute";
|
|
165
|
+
await executeNadoWithdrawCollateralV2({
|
|
166
|
+
sender: subaccount,
|
|
167
|
+
productId,
|
|
168
|
+
amount: netRawAmount,
|
|
169
|
+
nonce,
|
|
170
|
+
sendTo: depositAddr,
|
|
171
|
+
signature,
|
|
172
|
+
spotLeverage
|
|
173
|
+
});
|
|
174
|
+
logger.info("nado:withdrawal:executeSubmitted", {
|
|
175
|
+
nonce: nonce.toString(),
|
|
176
|
+
depositAddr,
|
|
177
|
+
productId,
|
|
178
|
+
netRawAmount: netRawAmount.toString()
|
|
179
|
+
});
|
|
180
|
+
return depositAddr;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
throw toThrownWithdrawalError(error, {
|
|
183
|
+
step,
|
|
184
|
+
walletAddress,
|
|
185
|
+
subaccount,
|
|
186
|
+
destinationAddress,
|
|
187
|
+
targetChainId
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
async function assertWithinMaxWithdrawable({
|
|
193
|
+
subaccount,
|
|
194
|
+
productId,
|
|
195
|
+
decimals,
|
|
196
|
+
spotLeverage,
|
|
197
|
+
netRawAmount
|
|
198
|
+
}) {
|
|
199
|
+
const maxWithdrawableX18 = await getNadoMaxWithdrawable({
|
|
200
|
+
productId,
|
|
201
|
+
sender: subaccount,
|
|
202
|
+
spotLeverage
|
|
203
|
+
});
|
|
204
|
+
const maxRawAmount = x18ToRawBaseUnit(
|
|
205
|
+
safeBigInt(maxWithdrawableX18, 0n),
|
|
206
|
+
decimals
|
|
207
|
+
);
|
|
208
|
+
if (netRawAmount <= maxRawAmount) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
logger.warn("nado:withdrawal:exceedsMaxWithdrawable", {
|
|
212
|
+
productId,
|
|
213
|
+
spotLeverage,
|
|
214
|
+
netRawAmount: netRawAmount.toString(),
|
|
215
|
+
maxRawAmount: maxRawAmount.toString()
|
|
216
|
+
});
|
|
217
|
+
throw new NadoWithdrawalUserError(
|
|
218
|
+
i18n_default.t("withdrawal.nado.errorBalanceChanged")
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
async function ensureWalletOnInk(wagmiConfig) {
|
|
222
|
+
const connectedChainId = getAccount(wagmiConfig).chainId;
|
|
223
|
+
if (connectedChainId === INK_CHAIN_ID) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
logger.info("nado:withdrawal:switchingChain", {
|
|
227
|
+
fromChainId: connectedChainId ?? null
|
|
228
|
+
});
|
|
229
|
+
try {
|
|
230
|
+
await switchChain(wagmiConfig, { chainId: INK_CHAIN_ID });
|
|
231
|
+
} catch (error) {
|
|
232
|
+
if (isUserRejectedError(error)) {
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
logger.warn("nado:withdrawal:switchChainFailed", {
|
|
236
|
+
fromChainId: connectedChainId ?? null,
|
|
237
|
+
errorMessage: error instanceof Error ? error.message : String(error)
|
|
238
|
+
});
|
|
239
|
+
throw new NadoWithdrawalUserError(
|
|
240
|
+
i18n_default.t("withdrawal.nado.errorSwitchChain")
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function assertOwnerIsSigner({
|
|
245
|
+
walletAddress,
|
|
246
|
+
wagmiConfig
|
|
247
|
+
}) {
|
|
248
|
+
const connectedAddress = getAccount(wagmiConfig).address;
|
|
249
|
+
if (connectedAddress && isEVMAddressEquivalent({
|
|
250
|
+
firstAddress: connectedAddress,
|
|
251
|
+
secondAddress: walletAddress
|
|
252
|
+
})) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
logger.warn("nado:withdrawal:signerMismatch", {
|
|
256
|
+
walletAddress,
|
|
257
|
+
connectedAddress: connectedAddress ?? null
|
|
258
|
+
});
|
|
259
|
+
throw new NadoWithdrawalUserError(
|
|
260
|
+
i18n_default.t("withdrawal.nado.errorSignerMismatch")
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
function toThrownWithdrawalError(error, context) {
|
|
264
|
+
const logContext = {
|
|
265
|
+
...context,
|
|
266
|
+
nadoErrorCode: error instanceof NadoGatewayError ? error.errorCode ?? null : null,
|
|
267
|
+
nadoErrorKind: error instanceof NadoGatewayError ? error.kind : null,
|
|
268
|
+
errorMessage: error instanceof Error ? error.message : String(error)
|
|
269
|
+
};
|
|
270
|
+
if (isUserRejectedError(error)) {
|
|
271
|
+
logger.warn("nado:withdrawal:rejected", logContext);
|
|
272
|
+
return error;
|
|
273
|
+
}
|
|
274
|
+
if (error instanceof NadoWithdrawalUserError) {
|
|
275
|
+
return error;
|
|
276
|
+
}
|
|
277
|
+
if (error instanceof NadoWithdrawalInputError) {
|
|
278
|
+
logger.error("nado:withdrawal:invalidInput", error, logContext);
|
|
279
|
+
return new Error(i18n_default.t("withdrawal.nado.errorGeneric"));
|
|
280
|
+
}
|
|
281
|
+
if (error instanceof NadoWithdrawalUnconfirmedError) {
|
|
282
|
+
return new Error(toNadoWithdrawalErrorMessage(error));
|
|
283
|
+
}
|
|
284
|
+
if (!(error instanceof NadoGatewayError)) {
|
|
285
|
+
logger.error(
|
|
286
|
+
"nado:withdrawal:failed",
|
|
287
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
288
|
+
logContext
|
|
289
|
+
);
|
|
290
|
+
return error;
|
|
291
|
+
}
|
|
292
|
+
if (isExpectedNadoWithdrawalFailure(error)) {
|
|
293
|
+
logger.warn("nado:withdrawal:gatewayRejected", logContext);
|
|
294
|
+
} else {
|
|
295
|
+
logger.error("nado:withdrawal:gatewayFailed", error, logContext);
|
|
296
|
+
}
|
|
297
|
+
return new Error(toNadoWithdrawalErrorMessage(error));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export {
|
|
301
|
+
createNadoWithdrawalCallback
|
|
302
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
INK_CHAIN_ID,
|
|
4
|
+
NADO_EIP712_VERIFYING_CONTRACT_ADDRESS
|
|
5
|
+
} from "./chunk-II5CZTBC.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
|
+
};
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
var NADO_ERROR_CODES = {
|
|
5
5
|
/** Amount would open a borrow with `spot_leverage: "false"`. */
|
|
6
6
|
SPOT_EXECUTE_EXCEEDS_BORROW_LIMIT: 2017,
|
|
7
|
-
/**
|
|
7
|
+
/** Gateway-level nonce rejection. A consumed `tx_nonce` reverts in the EVM
|
|
8
|
+
* instead — see `EVM_REVERT`. */
|
|
8
9
|
INVALID_NONCE: 2022,
|
|
9
10
|
/** Subaccount has never deposited, so it doesn't exist on Nado yet. */
|
|
10
11
|
NO_PRIOR_DEPOSIT: 2024,
|
|
@@ -13,7 +14,10 @@ var NADO_ERROR_CODES = {
|
|
|
13
14
|
/** Fast-withdrawal validator signatures not aggregated yet. */
|
|
14
15
|
NOT_ENOUGH_FAST_WITHDRAWAL_SIGNATURES: 3005,
|
|
15
16
|
/** Protocol 24h withdrawal limit exceeded. */
|
|
16
|
-
WITHDRAW_RISK: 4004
|
|
17
|
+
WITHDRAW_RISK: 4004,
|
|
18
|
+
/** Catch-all EVM revert — the reason lives in the message, not the code.
|
|
19
|
+
* A consumed `tx_nonce` lands here (see `parseNadoExpectedNonce`). */
|
|
20
|
+
EVM_REVERT: 4003
|
|
17
21
|
};
|
|
18
22
|
var NadoGatewayError = class extends Error {
|
|
19
23
|
constructor(message, options) {
|
|
@@ -24,6 +28,12 @@ var NadoGatewayError = class extends Error {
|
|
|
24
28
|
this.httpStatus = options.httpStatus;
|
|
25
29
|
}
|
|
26
30
|
};
|
|
31
|
+
var NadoWithdrawalUnconfirmedError = class extends Error {
|
|
32
|
+
constructor(message = "Nado withdrawal outcome could not be confirmed") {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "NadoWithdrawalUnconfirmedError";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
27
37
|
function isNadoTransportError(error) {
|
|
28
38
|
return error instanceof NadoGatewayError && error.kind === "transport";
|
|
29
39
|
}
|
|
@@ -36,11 +46,24 @@ function createNadoGatewayError(response, fallbackMessage) {
|
|
|
36
46
|
function isNadoErrorCode(error, code) {
|
|
37
47
|
return error instanceof NadoGatewayError && error.errorCode === code;
|
|
38
48
|
}
|
|
49
|
+
var NADO_EXPECTED_NONCE_PATTERN = /Invalid nonce: expected:\s*(\d+)/;
|
|
50
|
+
function parseNadoExpectedNonce(error) {
|
|
51
|
+
if (!(error instanceof NadoGatewayError) || error.errorCode !== NADO_ERROR_CODES.EVM_REVERT) {
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
const captured = error.message.match(NADO_EXPECTED_NONCE_PATTERN)?.[1];
|
|
55
|
+
if (captured === void 0) {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
return BigInt(captured);
|
|
59
|
+
}
|
|
39
60
|
|
|
40
61
|
export {
|
|
41
62
|
NADO_ERROR_CODES,
|
|
42
63
|
NadoGatewayError,
|
|
64
|
+
NadoWithdrawalUnconfirmedError,
|
|
43
65
|
isNadoTransportError,
|
|
44
66
|
createNadoGatewayError,
|
|
45
|
-
isNadoErrorCode
|
|
67
|
+
isNadoErrorCode,
|
|
68
|
+
parseNadoExpectedNonce
|
|
46
69
|
};
|
package/dist/clients/fanatics.js
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
import {
|
|
3
3
|
AsyncImage,
|
|
4
4
|
preloadRemoteImages
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-HZP4DXIZ.js";
|
|
6
|
+
import {
|
|
7
|
+
FUN_ORG_NAME
|
|
8
|
+
} from "./chunk-5MY7WMEJ.js";
|
|
6
9
|
import {
|
|
7
10
|
Box,
|
|
8
11
|
Text
|
|
9
12
|
} from "./chunk-LUHEVXPD.js";
|
|
10
13
|
import {
|
|
11
14
|
useFunkitTranslation
|
|
12
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-FAYBQQNB.js";
|
|
16
|
+
import "./chunk-2QYQNTOI.js";
|
|
13
17
|
import "./chunk-AHYOV7AV.js";
|
|
14
18
|
|
|
15
19
|
// src/clients/fanatics.tsx
|
|
@@ -128,10 +132,6 @@ var CashIcon = ({ size = 16 }) => {
|
|
|
128
132
|
);
|
|
129
133
|
};
|
|
130
134
|
|
|
131
|
-
// src/consts/funkit.ts
|
|
132
|
-
import { FUNKIT_CONNECT_CHECKOUT_NATIVE_CURRENCY_ADDRESS } from "@funkit/chains";
|
|
133
|
-
var FUN_ORG_NAME = "Fun.xyz";
|
|
134
|
-
|
|
135
135
|
// src/clients/fanatics.tsx
|
|
136
136
|
var BaseBanner = ({
|
|
137
137
|
title,
|
|
@@ -16,7 +16,10 @@ export declare function buildNadoSubaccountId(owner: Address, name?: string): He
|
|
|
16
16
|
* x18 query amount → raw base units. Floors — never rounds up — so a
|
|
17
17
|
* converted `max_withdrawable` can't exceed the true maximum. Same semantics
|
|
18
18
|
* as Nado's own frontend, which floors at submit (`BigNumber.ROUND_DOWN`).
|
|
19
|
+
*
|
|
20
|
+
* Takes a bigint so it cannot throw: parsing a gateway string stays at the one
|
|
21
|
+
* boundary that receives it (`safeBigInt`).
|
|
19
22
|
*/
|
|
20
|
-
export declare function x18ToRawBaseUnit(x18Amount:
|
|
23
|
+
export declare function x18ToRawBaseUnit(x18Amount: bigint, decimals: number): bigint;
|
|
21
24
|
/** x18-scaled query amount → human token units, floored at native decimals. */
|
|
22
|
-
export declare function x18ToTokenUnits(x18Amount:
|
|
25
|
+
export declare function x18ToTokenUnits(x18Amount: bigint, decimals: number): string;
|
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
// src/clients/internal/nado/encoding.ts
|
|
4
2
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 BigInt(x18Amount) * 10n ** BigInt(decimals) / 10n ** BigInt(X18_DECIMALS);
|
|
24
|
-
}
|
|
25
|
-
function x18ToTokenUnits(x18Amount, decimals) {
|
|
26
|
-
return formatUnits(x18ToRawBaseUnit(x18Amount, decimals), decimals);
|
|
27
|
-
}
|
|
3
|
+
buildNadoSubaccountId,
|
|
4
|
+
x18ToRawBaseUnit,
|
|
5
|
+
x18ToTokenUnits
|
|
6
|
+
} from "../../chunk-6T6URLBM.js";
|
|
28
7
|
export {
|
|
29
8
|
buildNadoSubaccountId,
|
|
30
9
|
x18ToRawBaseUnit,
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
export declare const NADO_ERROR_CODES: {
|
|
11
11
|
/** Amount would open a borrow with `spot_leverage: "false"`. */
|
|
12
12
|
readonly SPOT_EXECUTE_EXCEEDS_BORROW_LIMIT: 2017;
|
|
13
|
-
/**
|
|
13
|
+
/** Gateway-level nonce rejection. A consumed `tx_nonce` reverts in the EVM
|
|
14
|
+
* instead — see `EVM_REVERT`. */
|
|
14
15
|
readonly INVALID_NONCE: 2022;
|
|
15
16
|
/** Subaccount has never deposited, so it doesn't exist on Nado yet. */
|
|
16
17
|
readonly NO_PRIOR_DEPOSIT: 2024;
|
|
@@ -20,6 +21,9 @@ export declare const NADO_ERROR_CODES: {
|
|
|
20
21
|
readonly NOT_ENOUGH_FAST_WITHDRAWAL_SIGNATURES: 3005;
|
|
21
22
|
/** Protocol 24h withdrawal limit exceeded. */
|
|
22
23
|
readonly WITHDRAW_RISK: 4004;
|
|
24
|
+
/** Catch-all EVM revert — the reason lives in the message, not the code.
|
|
25
|
+
* A consumed `tx_nonce` lands here (see `parseNadoExpectedNonce`). */
|
|
26
|
+
readonly EVM_REVERT: 4003;
|
|
23
27
|
};
|
|
24
28
|
export type NadoErrorCode = (typeof NADO_ERROR_CODES)[keyof typeof NADO_ERROR_CODES];
|
|
25
29
|
/**
|
|
@@ -44,6 +48,14 @@ export declare class NadoGatewayError extends Error {
|
|
|
44
48
|
httpStatus?: number;
|
|
45
49
|
});
|
|
46
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* A submit went unanswered and its replay didn't settle the question — the
|
|
53
|
+
* withdrawal may or may not have landed. Distinct from a plain failure because
|
|
54
|
+
* the user must not be told to retry: a fresh nonce would withdraw twice.
|
|
55
|
+
*/
|
|
56
|
+
export declare class NadoWithdrawalUnconfirmedError extends Error {
|
|
57
|
+
constructor(message?: string);
|
|
58
|
+
}
|
|
47
59
|
/** Request never completed — safe to retry. Excludes timeouts: a retry after
|
|
48
60
|
* a 30s stall would hold the user another 30s. */
|
|
49
61
|
export declare function isNadoTransportError(error: unknown): boolean;
|
|
@@ -53,3 +65,4 @@ export declare function createNadoGatewayError(response: {
|
|
|
53
65
|
error_code?: number;
|
|
54
66
|
}, fallbackMessage: string): NadoGatewayError;
|
|
55
67
|
export declare function isNadoErrorCode(error: unknown, code: NadoErrorCode): boolean;
|
|
68
|
+
export declare function parseNadoExpectedNonce(error: unknown): bigint | undefined;
|
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
import {
|
|
3
3
|
NADO_ERROR_CODES,
|
|
4
4
|
NadoGatewayError,
|
|
5
|
+
NadoWithdrawalUnconfirmedError,
|
|
5
6
|
createNadoGatewayError,
|
|
6
7
|
isNadoErrorCode,
|
|
7
|
-
isNadoTransportError
|
|
8
|
-
|
|
8
|
+
isNadoTransportError,
|
|
9
|
+
parseNadoExpectedNonce
|
|
10
|
+
} from "../../chunk-Z7HTQFEO.js";
|
|
9
11
|
export {
|
|
10
12
|
NADO_ERROR_CODES,
|
|
11
13
|
NadoGatewayError,
|
|
14
|
+
NadoWithdrawalUnconfirmedError,
|
|
12
15
|
createNadoGatewayError,
|
|
13
16
|
isNadoErrorCode,
|
|
14
|
-
isNadoTransportError
|
|
17
|
+
isNadoTransportError,
|
|
18
|
+
parseNadoExpectedNonce
|
|
15
19
|
};
|
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
* Nado gateway client: the queries and the withdraw execute used by the
|
|
3
3
|
* withdrawal flow.
|
|
4
4
|
*
|
|
5
|
-
* Flow composition: `
|
|
6
|
-
*
|
|
5
|
+
* Flow composition: `max_withdrawable` / `fee_rates` feed the enter-amount
|
|
6
|
+
* screen → `nonces` immediately before signing → execute
|
|
7
7
|
* `withdraw_collateral_v2` with `sendTo` = the Fun deposit address → the
|
|
8
|
-
* indexer poll (indexer.ts) confirms sequencing, then checkout tracking
|
|
9
|
-
*
|
|
8
|
+
* indexer poll (indexer.ts) confirms sequencing, then checkout tracking takes
|
|
9
|
+
* over once funds arrive.
|
|
10
10
|
*
|
|
11
11
|
* @see {@link https://docs.nado.xyz/developer-resources/api/gateway | Nado gateway API}
|
|
12
12
|
*/
|
|
13
13
|
import type { Address, Hex } from 'viem';
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Largest withdrawal (x18) the subaccount can make, measured against prod:
|
|
16
|
+
* `(spot_leverage ? initial_health : min(spot, initial_health)) − sequencer_fee`
|
|
17
|
+
*
|
|
18
|
+
* - Already net of the fee: `max + fee` is debited, `max` is what arrives — so
|
|
19
|
+
* the screen adds it back (`withdrawalForm.ts`).
|
|
20
|
+
* - Health-bound, so no sum of spot balances can replace it: an open perp cuts
|
|
21
|
+
* the max without moving any balance.
|
|
22
|
+
*/
|
|
15
23
|
export declare function getNadoMaxWithdrawable(params: {
|
|
16
24
|
productId: number;
|
|
17
25
|
sender: Hex;
|
|
@@ -28,40 +36,6 @@ export interface NadoFeeRates {
|
|
|
28
36
|
withdraw_sequencer_fees: string[];
|
|
29
37
|
}
|
|
30
38
|
export declare function getNadoFeeRates(sender: Hex, signal?: AbortSignal): Promise<NadoFeeRates>;
|
|
31
|
-
export interface NadoSpotBalance {
|
|
32
|
-
product_id: number;
|
|
33
|
-
/** x18-normalized; negative when the balance is a borrow. */
|
|
34
|
-
balance: {
|
|
35
|
-
amount: string;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export interface NadoSubaccountInfo {
|
|
39
|
-
/** False until the subaccount's first deposit lands on Nado. */
|
|
40
|
-
exists: boolean;
|
|
41
|
-
spot_balances: NadoSpotBalance[];
|
|
42
|
-
}
|
|
43
|
-
export declare function getNadoSubaccountInfo(subaccount: Hex, signal?: AbortSignal): Promise<NadoSubaccountInfo>;
|
|
44
|
-
export interface NadoSpotProduct {
|
|
45
|
-
product_id: number;
|
|
46
|
-
config: {
|
|
47
|
-
token: string;
|
|
48
|
-
/** Product-default withdraw sequencer fee, x18 token units. */
|
|
49
|
-
withdraw_fee_x18: string;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export declare function getNadoAllProducts(signal?: AbortSignal): Promise<{
|
|
53
|
-
spot_products: NadoSpotProduct[];
|
|
54
|
-
}>;
|
|
55
|
-
export interface NadoSymbolInfo {
|
|
56
|
-
type: 'spot' | 'perp';
|
|
57
|
-
product_id: number;
|
|
58
|
-
symbol: string;
|
|
59
|
-
trading_status: string;
|
|
60
|
-
}
|
|
61
|
-
/** Keyed by symbol. The quote asset (USDT0, product 0) is not included. */
|
|
62
|
-
export declare function getNadoSymbols(signal?: AbortSignal): Promise<{
|
|
63
|
-
symbols: Record<string, NadoSymbolInfo>;
|
|
64
|
-
}>;
|
|
65
39
|
export interface ExecuteWithdrawCollateralV2Params {
|
|
66
40
|
/** Subaccount id per Nado's spec (see `buildNadoSubaccountId`). */
|
|
67
41
|
sender: Hex;
|
|
@@ -77,7 +51,11 @@ export interface ExecuteWithdrawCollateralV2Params {
|
|
|
77
51
|
}
|
|
78
52
|
/**
|
|
79
53
|
* Submit a signed `withdraw_collateral_v2`; resolves on gateway acceptance,
|
|
80
|
-
* on-chain settlement follows asynchronously.
|
|
81
|
-
*
|
|
54
|
+
* on-chain settlement follows asynchronously.
|
|
55
|
+
*
|
|
56
|
+
* A timeout means "no answer", not "didn't happen", so it replays the
|
|
57
|
+
* identical payload rather than surfacing an ambiguous failure. `tx_nonce` is
|
|
58
|
+
* a sequential counter, so the replay either fills the same slot or is
|
|
59
|
+
* rejected — it can never withdraw twice.
|
|
82
60
|
*/
|
|
83
61
|
export declare function executeNadoWithdrawCollateralV2(params: ExecuteWithdrawCollateralV2Params): Promise<void>;
|
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
executeNadoWithdrawCollateralV2,
|
|
4
|
-
getNadoAllProducts,
|
|
5
4
|
getNadoFeeRates,
|
|
6
5
|
getNadoMaxWithdrawable,
|
|
7
|
-
getNadoSubaccountInfo,
|
|
8
|
-
getNadoSymbols,
|
|
9
6
|
getNadoTxNonce
|
|
10
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-A44M6EAG.js";
|
|
11
8
|
import "../../chunk-II5CZTBC.js";
|
|
12
|
-
import "../../chunk-
|
|
13
|
-
import "../../chunk-
|
|
9
|
+
import "../../chunk-WZRW6WUM.js";
|
|
10
|
+
import "../../chunk-Z7HTQFEO.js";
|
|
14
11
|
import "../../chunk-AHYOV7AV.js";
|
|
15
12
|
export {
|
|
16
13
|
executeNadoWithdrawCollateralV2,
|
|
17
|
-
getNadoAllProducts,
|
|
18
14
|
getNadoFeeRates,
|
|
19
15
|
getNadoMaxWithdrawable,
|
|
20
|
-
getNadoSubaccountInfo,
|
|
21
|
-
getNadoSymbols,
|
|
22
16
|
getNadoTxNonce
|
|
23
17
|
};
|