@funkit/connect 12.6.0 → 12.8.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 +40 -0
- package/dist/__private__/index.d.ts +3 -0
- package/dist/clients/{chunk-F36IJA7V.js → chunk-4OOCXIMA.js} +1 -1
- package/dist/clients/chunk-I5GSXPFE.js +182 -0
- package/dist/clients/{chunk-IAIRECDV.js → chunk-R6E3NH5A.js} +1 -1
- package/dist/clients/{chunk-VE6QD5IM.js → chunk-RAJJSGNT.js} +1 -1
- package/dist/clients/chunk-YD27ZAJB.js +296 -0
- package/dist/clients/internal/nado/withdrawalCallback.js +3 -3
- package/dist/clients/internal/nado/withdrawalForm.css +81 -81
- package/dist/clients/internal/nado/withdrawalForm.js +3 -2
- package/dist/clients/lighter.css +81 -81
- package/dist/clients/lighter.js +1 -1
- package/dist/clients/nado.js +3 -3
- package/dist/clients/polymarket/createPolymarketDepositConfig.js +3 -3
- package/dist/clients/polymarket/index.js +3 -3
- package/dist/clients/polymarket/polymarket.js +2 -2
- package/dist/components/ModalHeightAnimationLayer/FunCheckoutModalHeightAnimationWrapper.d.ts +1 -1
- package/dist/consts/bluvo.d.ts +7 -19
- package/dist/consts/centralExchange.d.ts +2 -0
- package/dist/hooks/useExchangeOptions.d.ts +9 -4
- package/dist/index.css +159 -159
- package/dist/index.d.ts +3 -1
- package/dist/index.js +21442 -21351
- package/dist/interfaces/solanaWallet.d.ts +5 -0
- package/dist/modals/CheckoutModal/Brokerage/BrokerageTwoFA.d.ts +2 -1
- package/dist/modals/CheckoutModal/Brokerage/ConnectExchange.d.ts +2 -1
- package/dist/modals/CheckoutModal/Brokerage/SelectBrokerage.d.ts +2 -1
- package/dist/modals/CheckoutModal/CheckoutComplete/CheckoutComplete.d.ts +2 -1
- package/dist/modals/CheckoutModal/ConfirmationStep/ConfirmationStep.d.ts +2 -1
- package/dist/modals/CheckoutModal/InputAmount/InputAmount.d.ts +2 -1
- package/dist/modals/CheckoutModal/InputAmount/InputAmountLoaded.d.ts +2 -1
- package/dist/modals/CheckoutModal/InputAmount/useMeld.d.ts +2 -1
- package/dist/modals/CheckoutModal/LightningInvoice/LightningInvoice.d.ts +2 -1
- package/dist/modals/CheckoutModal/LoadingAccount.d.ts +2 -1
- package/dist/modals/CheckoutModal/MeldCurrencySelect/MeldCurrencySelect.d.ts +2 -1
- package/dist/modals/CheckoutModal/MeldQuotes/MeldQuotes.d.ts +2 -1
- package/dist/modals/CheckoutModal/MeldRedirect/MeldRedirect.d.ts +2 -1
- package/dist/modals/CheckoutModal/SelectAsset/SelectAsset.d.ts +2 -1
- package/dist/modals/CheckoutModal/SourceChange/SourceChange.d.ts +2 -1
- package/dist/modals/CheckoutModal/SwappedIframe/SwappedIframeController.d.ts +2 -1
- package/dist/modals/CheckoutModal/TransferToken/TransferToken.d.ts +2 -1
- package/dist/modals/CheckoutModal/VirtualFiatAccount/BridgeCustomer.d.ts +2 -1
- package/dist/modals/CheckoutModal/VirtualFiatAccount/BridgeKyc.d.ts +2 -1
- package/dist/modals/CheckoutModal/VirtualFiatAccount/ErrorScreen.d.ts +2 -1
- package/dist/modals/CheckoutModal/VirtualFiatAccount/FiatAccountDetail.d.ts +2 -1
- package/dist/modals/CheckoutModal/VirtualFiatAccount/KycIframe.d.ts +2 -1
- package/dist/modals/CheckoutModal/VirtualFiatAccount/VirtualFiatAccount.d.ts +2 -1
- package/dist/modals/CheckoutModal/Withdrawal/WithdrawalComplete.d.ts +2 -1
- package/dist/modals/CheckoutModal/Withdrawal/WithdrawalEnterAmount.d.ts +2 -1
- package/dist/modals/CheckoutModal/stepTransition.d.ts +1 -13
- package/dist/modals/CheckoutModal/stepTransition.shared.d.ts +16 -0
- package/dist/modals/WithdrawalModal/ErrorMessage.d.ts +2 -2
- package/dist/modals/WithdrawalModal/RecipientAddress.d.ts +4 -2
- package/dist/modals/WithdrawalModal/withdrawalHooks.d.ts +3 -1
- package/dist/providers/FunkitQuoteContext.d.ts +7 -4
- package/dist/shadow-css.js +1 -1
- package/dist/utils/solanaRelayWallet.d.ts +13 -5
- package/dist/wallets/Wallet.d.ts +9 -0
- package/dist/wallets/solanaWithdrawal.d.ts +17 -0
- package/dist/wallets/walletConnectors/index.js +30 -30
- package/package.json +12 -6
- package/dist/clients/chunk-PENJ5JGH.js +0 -331
- package/dist/components/FunPayments/icons/gemini.d.ts +0 -5
- package/dist/components/Icons/GeminiIcon.d.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @funkit/connect
|
|
2
2
|
|
|
3
|
+
## 12.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4a034f0: Internal change to support error reporting in @funkit/connect-js. No behavior change for consumers of this package.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 5590ffb: Internal refactor of the checkout modal's step modules. No behavior change for consumers of this package.
|
|
12
|
+
- Updated dependencies [cb6342b]
|
|
13
|
+
- @funkit/connect-core@8.1.1
|
|
14
|
+
|
|
15
|
+
## 12.7.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- 3c85052: Offer Coinbase as an exchange deposit option through Swapped Connect, alongside Bybit, and allow the Bluvo exchange option to be switched off remotely.
|
|
20
|
+
- 2f0e952: The Solana signer types (`SolanaSigner`, `SolanaSignTransaction`, `SolanaSignAndSendTransaction`, `SolanaConnection`) are exported from `@funkit/connect`, and `@solana/web3.js` is declared as an optional peer dependency.
|
|
21
|
+
- 84f1fcf: Withdrawals can now be signed by a connected Solana wallet via `useSolanaWithdrawalConfig`, which takes a `SolanaWalletSigner` with only the wallet's address, connection and signing method.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 6a3294e: Internal cleanup behind the approval-method toggle; no consumer-facing change.
|
|
26
|
+
- db448a0: No consumer-facing behavior changes.
|
|
27
|
+
- 47a12cb: Coming-soon exchange rows now always show in the exchange list regardless of which exchange rail is enabled, and Gemini was removed from the list.
|
|
28
|
+
- 9568a4b: Hide the exchange payment option when no exchange provider is enabled, instead of opening an empty list.
|
|
29
|
+
- f1b7950: The withdrawal recipient's "Use connected wallet" shortcut now offers a connected Solana wallet as well as an EVM one, and hides itself when both are connected.
|
|
30
|
+
- 1f8c0a7: Withdrawal amounts from a Solana source token now show their real USD value instead of being priced at a dollar.
|
|
31
|
+
- Updated dependencies [3c85052]
|
|
32
|
+
- Updated dependencies [3c85052]
|
|
33
|
+
- Updated dependencies [cbfe8c1]
|
|
34
|
+
- Updated dependencies [db448a0]
|
|
35
|
+
- Updated dependencies [812fa52]
|
|
36
|
+
- Updated dependencies [9b10caf]
|
|
37
|
+
- Updated dependencies [84f1fcf]
|
|
38
|
+
- Updated dependencies [5babe4e]
|
|
39
|
+
- Updated dependencies [c2c7331]
|
|
40
|
+
- @funkit/connect-core@8.1.0
|
|
41
|
+
- @funkit/api-base@8.4.0
|
|
42
|
+
|
|
3
43
|
## 12.6.0
|
|
4
44
|
|
|
5
45
|
### Minor Changes
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { DevEmbed } from '../modals/DevTest/DevEmbed';
|
|
2
|
+
import { getCurrentSdkVersion } from '../providers/useFingerprint';
|
|
2
3
|
export declare const __private__: {
|
|
3
4
|
dialog: string;
|
|
4
5
|
dialogMobile: string;
|
|
5
6
|
DevEmbed: typeof DevEmbed;
|
|
7
|
+
getCurrentSdkVersion: typeof getCurrentSdkVersion;
|
|
8
|
+
logger: import("@funkit/connect-core").FunLogger;
|
|
6
9
|
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/domains/paymentMethods.ts
|
|
4
|
+
import { PaymentMethod } from "@funkit/connect-core";
|
|
5
|
+
import { exhaustiveCheck, formatAddress } from "@funkit/utils";
|
|
6
|
+
|
|
7
|
+
// src/consts/bluvo.tsx
|
|
8
|
+
import {
|
|
9
|
+
ETHEREAL_API_KEY,
|
|
10
|
+
FormOfPaymentType
|
|
11
|
+
} from "@funkit/api-base";
|
|
12
|
+
import React3 from "react";
|
|
13
|
+
|
|
14
|
+
// src/components/Icons/BybitIcon.tsx
|
|
15
|
+
import React from "react";
|
|
16
|
+
var BybitIcon = ({ size = 24 }) => {
|
|
17
|
+
return /* @__PURE__ */ React.createElement(
|
|
18
|
+
"svg",
|
|
19
|
+
{
|
|
20
|
+
width: size,
|
|
21
|
+
height: size,
|
|
22
|
+
viewBox: "0 0 20 20",
|
|
23
|
+
fill: "none",
|
|
24
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
25
|
+
},
|
|
26
|
+
/* @__PURE__ */ React.createElement("rect", { width: "20", height: "20", rx: "4", fill: "#0B0E11" }),
|
|
27
|
+
/* @__PURE__ */ React.createElement("g", { transform: "translate(2 6.78) scale(0.184)" }, /* @__PURE__ */ React.createElement("path", { d: "M62.0083 25.3572V3H66.5022V25.3572H62.0083Z", fill: "#F7A600" }), /* @__PURE__ */ React.createElement(
|
|
28
|
+
"path",
|
|
29
|
+
{
|
|
30
|
+
d: "M9.63407 31.9983H0V9.64111H9.24666C13.7406 9.64111 16.3591 12.0903 16.3591 15.9214C16.3591 18.4013 14.6774 20.0039 13.5134 20.5375C14.9028 21.1652 16.6813 22.5779 16.6813 25.5624C16.6813 29.7373 13.7406 31.9983 9.63407 31.9983ZM8.89096 13.5355H4.4939V18.6852H8.89096C10.7981 18.6852 11.8652 17.6488 11.8652 16.1095C11.8652 14.5719 10.7981 13.5355 8.89096 13.5355ZM9.18151 22.6104H4.4939V28.1056H9.18151C11.2189 28.1056 12.1874 26.8503 12.1874 25.3418C12.1874 23.835 11.2171 22.6104 9.18151 22.6104Z",
|
|
31
|
+
fill: "white"
|
|
32
|
+
}
|
|
33
|
+
), /* @__PURE__ */ React.createElement(
|
|
34
|
+
"path",
|
|
35
|
+
{
|
|
36
|
+
d: "M30.3882 22.8293V31.9983H25.926V22.8293L19.0073 9.64111H23.8886L28.1888 18.6527L32.4239 9.64111H37.3052L30.3882 22.8293Z",
|
|
37
|
+
fill: "white"
|
|
38
|
+
}
|
|
39
|
+
), /* @__PURE__ */ React.createElement(
|
|
40
|
+
"path",
|
|
41
|
+
{
|
|
42
|
+
d: "M50.0457 31.9983H40.4116V9.64111H49.6583C54.1522 9.64111 56.7707 12.0903 56.7707 15.9214C56.7707 18.4013 55.089 20.0039 53.925 20.5375C55.3144 21.1652 57.093 22.5779 57.093 25.5624C57.093 29.7373 54.1522 31.9983 50.0457 31.9983ZM49.3026 13.5355H44.9055V18.6852H49.3026C51.2097 18.6852 52.2768 17.6488 52.2768 16.1095C52.2768 14.5719 51.2097 13.5355 49.3026 13.5355ZM49.5931 22.6104H44.9055V28.1056H49.5931C51.6305 28.1056 52.599 26.8503 52.599 25.3418C52.599 23.835 51.6305 22.6104 49.5931 22.6104Z",
|
|
43
|
+
fill: "white"
|
|
44
|
+
}
|
|
45
|
+
), /* @__PURE__ */ React.createElement(
|
|
46
|
+
"path",
|
|
47
|
+
{
|
|
48
|
+
d: "M80.986 13.5355V32H76.4921V13.5355H70.4785V9.64111H86.9996V13.5355H80.986Z",
|
|
49
|
+
fill: "white"
|
|
50
|
+
}
|
|
51
|
+
))
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/components/Icons/CoinbaseIcon.tsx
|
|
56
|
+
import React2 from "react";
|
|
57
|
+
var CoinbaseIcon = ({ size = 24 }) => {
|
|
58
|
+
return /* @__PURE__ */ React2.createElement(
|
|
59
|
+
"svg",
|
|
60
|
+
{
|
|
61
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
62
|
+
width: size,
|
|
63
|
+
height: size,
|
|
64
|
+
viewBox: "0 0 20 20",
|
|
65
|
+
fill: "none"
|
|
66
|
+
},
|
|
67
|
+
/* @__PURE__ */ React2.createElement("rect", { width: "20", height: "20", rx: "4", fill: "#2C5FF6" }),
|
|
68
|
+
/* @__PURE__ */ React2.createElement(
|
|
69
|
+
"path",
|
|
70
|
+
{
|
|
71
|
+
d: "M9.99 13.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5c1.76 0 3.22 1.305 3.46 3h3.52A7.005 7.005 0 0 0 9.99 3c-3.86 0-7 3.14-7 7s3.14 7 7 7c3.69 0 6.725-2.87 6.98-6.5h-3.52c-.24 1.695-1.7 3-3.46 3Z",
|
|
72
|
+
fill: "#fff"
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/consts/bluvo.tsx
|
|
79
|
+
var BLUVO_MIN_DEPOSIT_BY_CUSTOMER = {
|
|
80
|
+
[ETHEREAL_API_KEY]: 15
|
|
81
|
+
};
|
|
82
|
+
var BLUVO_EXCHANGES = {
|
|
83
|
+
coinbase: {
|
|
84
|
+
icon: (size) => /* @__PURE__ */ React3.createElement(CoinbaseIcon, { size }),
|
|
85
|
+
name: "Coinbase"
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
function getExchangeName(brokerType) {
|
|
89
|
+
return BLUVO_EXCHANGES[brokerType].name;
|
|
90
|
+
}
|
|
91
|
+
var FOP_COMPONENT_ICONS = {
|
|
92
|
+
[FormOfPaymentType.BYBIT]: (size) => /* @__PURE__ */ React3.createElement(BybitIcon, { size }),
|
|
93
|
+
[FormOfPaymentType.COINBASE_EXCHANGE]: (size) => /* @__PURE__ */ React3.createElement(CoinbaseIcon, { size })
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/domains/paymentMethods.ts
|
|
97
|
+
function createPaymentMethodInfo(params) {
|
|
98
|
+
switch (params.paymentMethod) {
|
|
99
|
+
case PaymentMethod.CARD:
|
|
100
|
+
return {
|
|
101
|
+
paymentMethod: PaymentMethod.CARD,
|
|
102
|
+
title: params.titleCustomization,
|
|
103
|
+
description: ""
|
|
104
|
+
};
|
|
105
|
+
case PaymentMethod.ACCOUNT_BALANCE:
|
|
106
|
+
return {
|
|
107
|
+
paymentMethod: PaymentMethod.ACCOUNT_BALANCE,
|
|
108
|
+
title: "Your Wallet",
|
|
109
|
+
description: formatAddress(params.walletAddress || "")
|
|
110
|
+
};
|
|
111
|
+
case PaymentMethod.BROKERAGE:
|
|
112
|
+
return {
|
|
113
|
+
paymentMethod: PaymentMethod.BROKERAGE,
|
|
114
|
+
title: getExchangeName(params.exchange),
|
|
115
|
+
description: "",
|
|
116
|
+
deviceId: params.deviceId,
|
|
117
|
+
exchange: params.exchange
|
|
118
|
+
};
|
|
119
|
+
case PaymentMethod.TOKEN_TRANSFER:
|
|
120
|
+
return {
|
|
121
|
+
// this is an arbitrary value for Polymarket.
|
|
122
|
+
paymentMethod: PaymentMethod.TOKEN_TRANSFER,
|
|
123
|
+
title: "QR Code Transfer",
|
|
124
|
+
description: ""
|
|
125
|
+
};
|
|
126
|
+
case PaymentMethod.BITCOIN_LIGHTNING:
|
|
127
|
+
return {
|
|
128
|
+
paymentMethod: PaymentMethod.BITCOIN_LIGHTNING,
|
|
129
|
+
title: "Bitcoin Lightning",
|
|
130
|
+
description: ""
|
|
131
|
+
};
|
|
132
|
+
case PaymentMethod.CASH_APP_LIGHTNING:
|
|
133
|
+
return {
|
|
134
|
+
paymentMethod: PaymentMethod.CASH_APP_LIGHTNING,
|
|
135
|
+
title: "Cash App",
|
|
136
|
+
description: ""
|
|
137
|
+
};
|
|
138
|
+
case PaymentMethod.VIRTUAL_BANK:
|
|
139
|
+
return {
|
|
140
|
+
paymentMethod: PaymentMethod.VIRTUAL_BANK,
|
|
141
|
+
title: "Fiat Account",
|
|
142
|
+
description: "",
|
|
143
|
+
matchingFiatAccount: params.matchingFiatAccount,
|
|
144
|
+
bridgeCustomer: params.bridgeCustomer
|
|
145
|
+
};
|
|
146
|
+
default:
|
|
147
|
+
exhaustiveCheck(params);
|
|
148
|
+
return {};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/domains/clientMetadata.ts
|
|
153
|
+
function generateClientMetadataForTokenTransfer() {
|
|
154
|
+
return {
|
|
155
|
+
id: "",
|
|
156
|
+
startTimestampMs: 0,
|
|
157
|
+
finalDollarValue: 0,
|
|
158
|
+
latestQuote: null,
|
|
159
|
+
depositAddress: null,
|
|
160
|
+
initSettings: {
|
|
161
|
+
config: {
|
|
162
|
+
targetAsset: "0x",
|
|
163
|
+
targetChain: "",
|
|
164
|
+
targetAssetTicker: "",
|
|
165
|
+
checkoutItemTitle: ""
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
selectedSourceAssetInfo: {
|
|
169
|
+
address: "0x",
|
|
170
|
+
symbol: "",
|
|
171
|
+
chainId: "",
|
|
172
|
+
iconSrc: null
|
|
173
|
+
},
|
|
174
|
+
selectedPaymentMethodInfo: createPaymentMethodInfo({
|
|
175
|
+
paymentMethod: PaymentMethod.TOKEN_TRANSFER
|
|
176
|
+
})
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export {
|
|
181
|
+
generateClientMetadataForTokenTransfer
|
|
182
|
+
};
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
toWithdrawalAmountBaseUnit
|
|
4
|
+
} from "./chunk-4DBUYTEE.js";
|
|
5
|
+
import {
|
|
6
|
+
isExpectedNadoWithdrawalFailure,
|
|
7
|
+
toNadoWithdrawalErrorMessage
|
|
8
|
+
} from "./chunk-B5KCBBSV.js";
|
|
9
|
+
import {
|
|
10
|
+
getAccount,
|
|
11
|
+
signTypedData,
|
|
12
|
+
switchChain
|
|
13
|
+
} from "./chunk-OODIKHYE.js";
|
|
14
|
+
import {
|
|
15
|
+
i18n_default
|
|
16
|
+
} from "./chunk-7GPRX32F.js";
|
|
17
|
+
import {
|
|
18
|
+
generateClientMetadataForTokenTransfer
|
|
19
|
+
} from "./chunk-I5GSXPFE.js";
|
|
20
|
+
import {
|
|
21
|
+
logger
|
|
22
|
+
} from "./chunk-AHYOV7AV.js";
|
|
23
|
+
|
|
24
|
+
// src/clients/internal/nado/withdrawalCallback.ts
|
|
25
|
+
import {
|
|
26
|
+
NADO_API_KEY,
|
|
27
|
+
initializeCheckoutTokenTransferAddress
|
|
28
|
+
} from "@funkit/api-base";
|
|
29
|
+
import {
|
|
30
|
+
deductFlatFee,
|
|
31
|
+
normalizeRecipientAddress,
|
|
32
|
+
safeBigInt
|
|
33
|
+
} from "@funkit/connect-core";
|
|
34
|
+
import {
|
|
35
|
+
INK_CHAIN_ID,
|
|
36
|
+
NADO_WITHDRAWAL_ACTION_TYPE,
|
|
37
|
+
NadoGatewayError,
|
|
38
|
+
NadoWithdrawalUnconfirmedError,
|
|
39
|
+
buildWithdrawCollateralV2TypedData,
|
|
40
|
+
executeNadoWithdrawCollateralV2,
|
|
41
|
+
getNadoMaxWithdrawable,
|
|
42
|
+
getNadoTxNonce,
|
|
43
|
+
x18ToRawBaseUnit
|
|
44
|
+
} from "@funkit/connect-core/clients/nado";
|
|
45
|
+
import { isAddressEquivalent } from "@funkit/utils";
|
|
46
|
+
|
|
47
|
+
// src/utils/signature.ts
|
|
48
|
+
import { isSwitchChainError, isUserRejectedError } from "@funkit/connect-core";
|
|
49
|
+
|
|
50
|
+
// src/clients/internal/nado/withdrawalCallback.ts
|
|
51
|
+
var NadoWithdrawalInputError = class extends Error {
|
|
52
|
+
};
|
|
53
|
+
var NadoWithdrawalUserError = class extends Error {
|
|
54
|
+
};
|
|
55
|
+
function createNadoWithdrawalCallback({
|
|
56
|
+
walletAddress,
|
|
57
|
+
subaccount,
|
|
58
|
+
wagmiConfig
|
|
59
|
+
}) {
|
|
60
|
+
return async (param) => {
|
|
61
|
+
const {
|
|
62
|
+
customerData,
|
|
63
|
+
userInputAmount,
|
|
64
|
+
targetAssetAddress,
|
|
65
|
+
targetChainId,
|
|
66
|
+
destinationAddress
|
|
67
|
+
} = param;
|
|
68
|
+
const recipientAddr = normalizeRecipientAddress(destinationAddress);
|
|
69
|
+
let step = "validate";
|
|
70
|
+
try {
|
|
71
|
+
if (customerData?.customerName !== "nado" || !userInputAmount) {
|
|
72
|
+
throw new NadoWithdrawalInputError(
|
|
73
|
+
"Missing Nado customerData or userInputAmount"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const {
|
|
77
|
+
spotLeverage,
|
|
78
|
+
sequencerFeeTokenAmount,
|
|
79
|
+
selectedSourceToken: { productId, decimals }
|
|
80
|
+
} = customerData;
|
|
81
|
+
const netTokens = deductFlatFee(userInputAmount, sequencerFeeTokenAmount);
|
|
82
|
+
const netRawAmount = toWithdrawalAmountBaseUnit(netTokens, decimals);
|
|
83
|
+
if (netRawAmount <= 0n) {
|
|
84
|
+
logger.warn("nado:withdrawal:amountTooLow", {
|
|
85
|
+
productId,
|
|
86
|
+
userInputAmount,
|
|
87
|
+
sequencerFeeTokenAmount
|
|
88
|
+
});
|
|
89
|
+
throw new NadoWithdrawalUserError(
|
|
90
|
+
i18n_default.t("withdrawal.nado.errorAmountTooLow")
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
logger.info("nado:withdrawal:start", {
|
|
94
|
+
productId,
|
|
95
|
+
spotLeverage,
|
|
96
|
+
decimals,
|
|
97
|
+
userInputAmount,
|
|
98
|
+
netTokens,
|
|
99
|
+
sequencerFeeTokenAmount,
|
|
100
|
+
targetChainId,
|
|
101
|
+
targetAssetAddress,
|
|
102
|
+
destinationAddress: recipientAddr
|
|
103
|
+
});
|
|
104
|
+
await assertWithinMaxWithdrawable({
|
|
105
|
+
subaccount,
|
|
106
|
+
productId,
|
|
107
|
+
decimals,
|
|
108
|
+
spotLeverage,
|
|
109
|
+
netRawAmount
|
|
110
|
+
});
|
|
111
|
+
step = "switchChain";
|
|
112
|
+
await ensureWalletOnInk(wagmiConfig);
|
|
113
|
+
assertOwnerIsSigner({ walletAddress, wagmiConfig });
|
|
114
|
+
step = "uda";
|
|
115
|
+
const transferInit = await initializeCheckoutTokenTransferAddress({
|
|
116
|
+
apiKey: NADO_API_KEY,
|
|
117
|
+
// No Fun user context in a client bundle entry; the owner wallet is the
|
|
118
|
+
// stable per-user id and matches what sourceOfFund records.
|
|
119
|
+
userId: walletAddress,
|
|
120
|
+
recipientAddr,
|
|
121
|
+
toChainId: targetChainId.toString(),
|
|
122
|
+
toTokenAddress: targetAssetAddress,
|
|
123
|
+
sourceOfFund: `balance|nado|${walletAddress}`,
|
|
124
|
+
// Attribution only — forces a separate UDA from Nado deposits so the
|
|
125
|
+
// direct executions off it are tagged as withdrawals.
|
|
126
|
+
actionType: NADO_WITHDRAWAL_ACTION_TYPE,
|
|
127
|
+
logger,
|
|
128
|
+
clientMetadata: {
|
|
129
|
+
...generateClientMetadataForTokenTransfer(),
|
|
130
|
+
isWithdrawal: true
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const depositAddr = transferInit.depositAddr;
|
|
134
|
+
logger.info("nado:withdrawal:udaGenerated", {
|
|
135
|
+
depositAddr,
|
|
136
|
+
productId,
|
|
137
|
+
destinationAddress: recipientAddr
|
|
138
|
+
});
|
|
139
|
+
step = "sign";
|
|
140
|
+
const nonce = await getNadoTxNonce(walletAddress, { logger });
|
|
141
|
+
const signature = await signTypedData(wagmiConfig, {
|
|
142
|
+
...buildWithdrawCollateralV2TypedData({
|
|
143
|
+
sender: subaccount,
|
|
144
|
+
productId,
|
|
145
|
+
amount: netRawAmount,
|
|
146
|
+
nonce,
|
|
147
|
+
sendTo: depositAddr
|
|
148
|
+
}),
|
|
149
|
+
account: walletAddress
|
|
150
|
+
});
|
|
151
|
+
logger.info("nado:withdrawal:signed", {
|
|
152
|
+
nonce: nonce.toString(),
|
|
153
|
+
depositAddr,
|
|
154
|
+
productId
|
|
155
|
+
});
|
|
156
|
+
step = "execute";
|
|
157
|
+
await executeNadoWithdrawCollateralV2(
|
|
158
|
+
{
|
|
159
|
+
sender: subaccount,
|
|
160
|
+
productId,
|
|
161
|
+
amount: netRawAmount,
|
|
162
|
+
nonce,
|
|
163
|
+
sendTo: depositAddr,
|
|
164
|
+
signature,
|
|
165
|
+
spotLeverage
|
|
166
|
+
},
|
|
167
|
+
{ logger }
|
|
168
|
+
);
|
|
169
|
+
logger.info("nado:withdrawal:executeSubmitted", {
|
|
170
|
+
nonce: nonce.toString(),
|
|
171
|
+
depositAddr,
|
|
172
|
+
productId,
|
|
173
|
+
netRawAmount: netRawAmount.toString()
|
|
174
|
+
});
|
|
175
|
+
return depositAddr;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
throw toThrownWithdrawalError(error, {
|
|
178
|
+
step,
|
|
179
|
+
walletAddress,
|
|
180
|
+
subaccount,
|
|
181
|
+
destinationAddress: recipientAddr,
|
|
182
|
+
targetChainId
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async function assertWithinMaxWithdrawable({
|
|
188
|
+
subaccount,
|
|
189
|
+
productId,
|
|
190
|
+
decimals,
|
|
191
|
+
spotLeverage,
|
|
192
|
+
netRawAmount
|
|
193
|
+
}) {
|
|
194
|
+
const maxWithdrawableX18 = await getNadoMaxWithdrawable(
|
|
195
|
+
{ productId, sender: subaccount, spotLeverage },
|
|
196
|
+
{ logger }
|
|
197
|
+
);
|
|
198
|
+
const maxRawAmount = x18ToRawBaseUnit(
|
|
199
|
+
safeBigInt(maxWithdrawableX18, 0n),
|
|
200
|
+
decimals
|
|
201
|
+
);
|
|
202
|
+
if (netRawAmount <= maxRawAmount) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
logger.warn("nado:withdrawal:exceedsMaxWithdrawable", {
|
|
206
|
+
productId,
|
|
207
|
+
spotLeverage,
|
|
208
|
+
netRawAmount: netRawAmount.toString(),
|
|
209
|
+
maxRawAmount: maxRawAmount.toString()
|
|
210
|
+
});
|
|
211
|
+
throw new NadoWithdrawalUserError(
|
|
212
|
+
i18n_default.t("withdrawal.nado.errorBalanceChanged")
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
async function ensureWalletOnInk(wagmiConfig) {
|
|
216
|
+
const connectedChainId = getAccount(wagmiConfig).chainId;
|
|
217
|
+
if (connectedChainId === INK_CHAIN_ID) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
logger.info("nado:withdrawal:switchingChain", {
|
|
221
|
+
fromChainId: connectedChainId ?? null
|
|
222
|
+
});
|
|
223
|
+
try {
|
|
224
|
+
await switchChain(wagmiConfig, { chainId: INK_CHAIN_ID });
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (isUserRejectedError(error)) {
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
logger.warn("nado:withdrawal:switchChainFailed", {
|
|
230
|
+
fromChainId: connectedChainId ?? null,
|
|
231
|
+
errorMessage: error instanceof Error ? error.message : String(error)
|
|
232
|
+
});
|
|
233
|
+
throw new NadoWithdrawalUserError(
|
|
234
|
+
i18n_default.t("withdrawal.nado.errorSwitchChain")
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function assertOwnerIsSigner({
|
|
239
|
+
walletAddress,
|
|
240
|
+
wagmiConfig
|
|
241
|
+
}) {
|
|
242
|
+
const connectedAddress = getAccount(wagmiConfig).address;
|
|
243
|
+
if (connectedAddress && isAddressEquivalent({
|
|
244
|
+
firstAddress: connectedAddress,
|
|
245
|
+
secondAddress: walletAddress
|
|
246
|
+
})) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
logger.warn("nado:withdrawal:signerMismatch", {
|
|
250
|
+
walletAddress,
|
|
251
|
+
connectedAddress: connectedAddress ?? null
|
|
252
|
+
});
|
|
253
|
+
throw new NadoWithdrawalUserError(
|
|
254
|
+
i18n_default.t("withdrawal.nado.errorSignerMismatch")
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
function toThrownWithdrawalError(error, context) {
|
|
258
|
+
const logContext = {
|
|
259
|
+
...context,
|
|
260
|
+
nadoErrorCode: error instanceof NadoGatewayError ? error.errorCode ?? null : null,
|
|
261
|
+
nadoErrorKind: error instanceof NadoGatewayError ? error.kind : null,
|
|
262
|
+
errorMessage: error instanceof Error ? error.message : String(error)
|
|
263
|
+
};
|
|
264
|
+
if (isUserRejectedError(error)) {
|
|
265
|
+
logger.warn("nado:withdrawal:rejected", logContext);
|
|
266
|
+
return error;
|
|
267
|
+
}
|
|
268
|
+
if (error instanceof NadoWithdrawalUserError) {
|
|
269
|
+
return error;
|
|
270
|
+
}
|
|
271
|
+
if (error instanceof NadoWithdrawalInputError) {
|
|
272
|
+
logger.error("nado:withdrawal:invalidInput", error, logContext);
|
|
273
|
+
return new Error(i18n_default.t("withdrawal.nado.errorGeneric"));
|
|
274
|
+
}
|
|
275
|
+
if (error instanceof NadoWithdrawalUnconfirmedError) {
|
|
276
|
+
return new Error(toNadoWithdrawalErrorMessage(error));
|
|
277
|
+
}
|
|
278
|
+
if (!(error instanceof NadoGatewayError)) {
|
|
279
|
+
logger.error(
|
|
280
|
+
"nado:withdrawal:failed",
|
|
281
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
282
|
+
logContext
|
|
283
|
+
);
|
|
284
|
+
return error;
|
|
285
|
+
}
|
|
286
|
+
if (isExpectedNadoWithdrawalFailure(error)) {
|
|
287
|
+
logger.warn("nado:withdrawal:gatewayRejected", logContext);
|
|
288
|
+
} else {
|
|
289
|
+
logger.error("nado:withdrawal:gatewayFailed", error, logContext);
|
|
290
|
+
}
|
|
291
|
+
return new Error(toNadoWithdrawalErrorMessage(error));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export {
|
|
295
|
+
createNadoWithdrawalCallback
|
|
296
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
createNadoWithdrawalCallback
|
|
4
|
-
} from "../../chunk-
|
|
5
|
-
import "../../chunk-B5KCBBSV.js";
|
|
4
|
+
} from "../../chunk-YD27ZAJB.js";
|
|
6
5
|
import "../../chunk-4DBUYTEE.js";
|
|
6
|
+
import "../../chunk-B5KCBBSV.js";
|
|
7
7
|
import "../../chunk-OODIKHYE.js";
|
|
8
8
|
import "../../chunk-7GPRX32F.js";
|
|
9
|
-
import "../../chunk-
|
|
9
|
+
import "../../chunk-I5GSXPFE.js";
|
|
10
10
|
import "../../chunk-AHYOV7AV.js";
|
|
11
11
|
export {
|
|
12
12
|
createNadoWithdrawalCallback
|