@b3dotfun/sdk 0.1.2-alpha.3 → 0.1.2-alpha.4

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.
@@ -18,6 +18,7 @@ export interface AnySpendCustomExactInProps {
18
18
  sourceTokenChainId?: number;
19
19
  destinationToken: components["schemas"]["Token"];
20
20
  destinationChainId: number;
21
+ destinationTokenAmount?: string;
21
22
  onSuccess?: (amount: string) => void;
22
23
  onOpenCustomModal?: () => void;
23
24
  mainFooter?: React.ReactNode;
@@ -33,7 +33,7 @@ function AnySpendCustomExactIn(props) {
33
33
  const fingerprintConfig = (0, AnySpendFingerprintWrapper_1.getFingerprintConfig)();
34
34
  return ((0, jsx_runtime_1.jsx)(AnySpendFingerprintWrapper_1.AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: (0, jsx_runtime_1.jsx)(AnySpendCustomExactInInner, { ...props }) }));
35
35
  }
36
- function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, destinationToken, destinationChainId, onSuccess, onOpenCustomModal, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, customExactInConfig, orderType = "custom_exact_in", minDestinationAmount, header, returnToHomeUrl, customRecipientLabel, returnHomeLabel, classes, }) {
36
+ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, destinationToken, destinationChainId, onSuccess, onOpenCustomModal, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, customExactInConfig, destinationTokenAmount, orderType = "custom_exact_in", minDestinationAmount, header, returnToHomeUrl, customRecipientLabel, returnHomeLabel, classes, }) {
37
37
  const actionLabel = customExactInConfig?.action ?? "Custom Execution";
38
38
  const DESTINATION_TOKEN_DETAILS = {
39
39
  SYMBOL: destinationToken.symbol ?? "TOKEN",
@@ -66,6 +66,17 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
66
66
  }
67
67
  }
68
68
  }, [preferEoa, connectedEOAWallet, setActiveWallet]);
69
+ // Prefill destination amount if provided (for EXACT_OUTPUT mode)
70
+ const appliedDestinationAmount = (0, react_4.useRef)(false);
71
+ (0, react_4.useEffect)(() => {
72
+ if (destinationTokenAmount && !appliedDestinationAmount.current) {
73
+ appliedDestinationAmount.current = true;
74
+ // Convert wei to human-readable format
75
+ const formattedAmount = (0, number_1.formatUnits)(destinationTokenAmount, destinationToken.decimals);
76
+ setDstAmountInput(formattedAmount);
77
+ setIsSrcInputDirty(false); // Switch to EXACT_OUTPUT mode
78
+ }
79
+ }, [destinationTokenAmount, destinationToken.decimals, setDstAmountInput, setIsSrcInputDirty]);
69
80
  const selectedRecipientOrDefault = selectedRecipientAddress ?? recipientAddress;
70
81
  const expectedDstAmountRaw = anyspendQuote?.data?.currencyOut?.amount ?? "0";
71
82
  const buildCustomPayload = (_recipient) => {
@@ -1,5 +1,5 @@
1
1
  import { components } from "../../../anyspend/types/api";
2
- export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientAddress, sourceTokenAddress, sourceTokenChainId, stakingContractAddress, token, onSuccess, }: {
2
+ export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientAddress, sourceTokenAddress, sourceTokenChainId, destinationTokenAmount, stakingContractAddress, token, onSuccess, }: {
3
3
  loadOrder?: string;
4
4
  mode?: "modal" | "page";
5
5
  recipientAddress: string;
@@ -7,5 +7,6 @@ export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientA
7
7
  sourceTokenChainId?: number;
8
8
  stakingContractAddress: string;
9
9
  token: components["schemas"]["Token"];
10
+ destinationTokenAmount?: string;
10
11
  onSuccess?: (amount: string) => void;
11
12
  }): import("react/jsx-runtime").JSX.Element | null;
@@ -17,7 +17,7 @@ const STAKE_FOR_FUNCTION_ABI = JSON.stringify([
17
17
  outputs: [],
18
18
  },
19
19
  ]);
20
- function AnySpendStakeUpsideExactIn({ loadOrder, mode = "modal", recipientAddress, sourceTokenAddress, sourceTokenChainId, stakingContractAddress, token, onSuccess, }) {
20
+ function AnySpendStakeUpsideExactIn({ loadOrder, mode = "modal", recipientAddress, sourceTokenAddress, sourceTokenChainId, destinationTokenAmount, stakingContractAddress, token, onSuccess, }) {
21
21
  if (!recipientAddress)
22
22
  return null;
23
23
  const header = () => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { className: "from-b3-react-background to-as-on-surface-1 w-full rounded-t-lg bg-gradient-to-t", children: (0, jsx_runtime_1.jsx)("div", { className: "mb-1 flex w-full flex-col items-center gap-2", children: (0, jsx_runtime_1.jsxs)("span", { className: "font-sf-rounded text-2xl font-semibold", children: ["Swap & Stake ", token.symbol, " (Exact In)"] }) }) }) }));
@@ -29,5 +29,5 @@ function AnySpendStakeUpsideExactIn({ loadOrder, mode = "modal", recipientAddres
29
29
  spenderAddress: stakingContractAddress,
30
30
  action: `stake ${token.symbol}`,
31
31
  };
32
- return ((0, jsx_runtime_1.jsx)(AnySpendCustomExactIn_1.AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: sourceTokenChainId, destinationToken: token, destinationChainId: chains_1.base.id, customExactInConfig: customExactInConfig, header: header, onSuccess: onSuccess }));
32
+ return ((0, jsx_runtime_1.jsx)(AnySpendCustomExactIn_1.AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: sourceTokenChainId, destinationToken: token, destinationChainId: chains_1.base.id, destinationTokenAmount: destinationTokenAmount, customExactInConfig: customExactInConfig, header: header, onSuccess: onSuccess }));
33
33
  }
@@ -306,6 +306,8 @@ export interface AnySpendDepositUpsideProps extends BaseModalProps {
306
306
  depositContractAddress: string;
307
307
  /** Token to deposit */
308
308
  token: components["schemas"]["Token"];
309
+ /** The exact amount of destination tokens to receive, in wei. This will pre-fill the output amount and switch to an exact output swap. */
310
+ destinationTokenAmount?: string;
309
311
  /** Callback function called when the deposit is successful */
310
312
  onSuccess?: () => void;
311
313
  }
@@ -18,6 +18,7 @@ export interface AnySpendCustomExactInProps {
18
18
  sourceTokenChainId?: number;
19
19
  destinationToken: components["schemas"]["Token"];
20
20
  destinationChainId: number;
21
+ destinationTokenAmount?: string;
21
22
  onSuccess?: (amount: string) => void;
22
23
  onOpenCustomModal?: () => void;
23
24
  mainFooter?: React.ReactNode;
@@ -27,7 +27,7 @@ export function AnySpendCustomExactIn(props) {
27
27
  const fingerprintConfig = getFingerprintConfig();
28
28
  return (_jsx(AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: _jsx(AnySpendCustomExactInInner, { ...props }) }));
29
29
  }
30
- function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, destinationToken, destinationChainId, onSuccess, onOpenCustomModal, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, customExactInConfig, orderType = "custom_exact_in", minDestinationAmount, header, returnToHomeUrl, customRecipientLabel, returnHomeLabel, classes, }) {
30
+ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, destinationToken, destinationChainId, onSuccess, onOpenCustomModal, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, customExactInConfig, destinationTokenAmount, orderType = "custom_exact_in", minDestinationAmount, header, returnToHomeUrl, customRecipientLabel, returnHomeLabel, classes, }) {
31
31
  const actionLabel = customExactInConfig?.action ?? "Custom Execution";
32
32
  const DESTINATION_TOKEN_DETAILS = {
33
33
  SYMBOL: destinationToken.symbol ?? "TOKEN",
@@ -60,6 +60,17 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
60
60
  }
61
61
  }
62
62
  }, [preferEoa, connectedEOAWallet, setActiveWallet]);
63
+ // Prefill destination amount if provided (for EXACT_OUTPUT mode)
64
+ const appliedDestinationAmount = useRef(false);
65
+ useEffect(() => {
66
+ if (destinationTokenAmount && !appliedDestinationAmount.current) {
67
+ appliedDestinationAmount.current = true;
68
+ // Convert wei to human-readable format
69
+ const formattedAmount = formatUnits(destinationTokenAmount, destinationToken.decimals);
70
+ setDstAmountInput(formattedAmount);
71
+ setIsSrcInputDirty(false); // Switch to EXACT_OUTPUT mode
72
+ }
73
+ }, [destinationTokenAmount, destinationToken.decimals, setDstAmountInput, setIsSrcInputDirty]);
63
74
  const selectedRecipientOrDefault = selectedRecipientAddress ?? recipientAddress;
64
75
  const expectedDstAmountRaw = anyspendQuote?.data?.currencyOut?.amount ?? "0";
65
76
  const buildCustomPayload = (_recipient) => {
@@ -1,5 +1,5 @@
1
1
  import { components } from "../../../anyspend/types/api";
2
- export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientAddress, sourceTokenAddress, sourceTokenChainId, stakingContractAddress, token, onSuccess, }: {
2
+ export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientAddress, sourceTokenAddress, sourceTokenChainId, destinationTokenAmount, stakingContractAddress, token, onSuccess, }: {
3
3
  loadOrder?: string;
4
4
  mode?: "modal" | "page";
5
5
  recipientAddress: string;
@@ -7,5 +7,6 @@ export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientA
7
7
  sourceTokenChainId?: number;
8
8
  stakingContractAddress: string;
9
9
  token: components["schemas"]["Token"];
10
+ destinationTokenAmount?: string;
10
11
  onSuccess?: (amount: string) => void;
11
12
  }): import("react/jsx-runtime").JSX.Element | null;
@@ -14,7 +14,7 @@ const STAKE_FOR_FUNCTION_ABI = JSON.stringify([
14
14
  outputs: [],
15
15
  },
16
16
  ]);
17
- export function AnySpendStakeUpsideExactIn({ loadOrder, mode = "modal", recipientAddress, sourceTokenAddress, sourceTokenChainId, stakingContractAddress, token, onSuccess, }) {
17
+ export function AnySpendStakeUpsideExactIn({ loadOrder, mode = "modal", recipientAddress, sourceTokenAddress, sourceTokenChainId, destinationTokenAmount, stakingContractAddress, token, onSuccess, }) {
18
18
  if (!recipientAddress)
19
19
  return null;
20
20
  const header = () => (_jsx(_Fragment, { children: _jsx("div", { className: "from-b3-react-background to-as-on-surface-1 w-full rounded-t-lg bg-gradient-to-t", children: _jsx("div", { className: "mb-1 flex w-full flex-col items-center gap-2", children: _jsxs("span", { className: "font-sf-rounded text-2xl font-semibold", children: ["Swap & Stake ", token.symbol, " (Exact In)"] }) }) }) }));
@@ -26,5 +26,5 @@ export function AnySpendStakeUpsideExactIn({ loadOrder, mode = "modal", recipien
26
26
  spenderAddress: stakingContractAddress,
27
27
  action: `stake ${token.symbol}`,
28
28
  };
29
- return (_jsx(AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: sourceTokenChainId, destinationToken: token, destinationChainId: base.id, customExactInConfig: customExactInConfig, header: header, onSuccess: onSuccess }));
29
+ return (_jsx(AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: sourceTokenChainId, destinationToken: token, destinationChainId: base.id, destinationTokenAmount: destinationTokenAmount, customExactInConfig: customExactInConfig, header: header, onSuccess: onSuccess }));
30
30
  }
@@ -306,6 +306,8 @@ export interface AnySpendDepositUpsideProps extends BaseModalProps {
306
306
  depositContractAddress: string;
307
307
  /** Token to deposit */
308
308
  token: components["schemas"]["Token"];
309
+ /** The exact amount of destination tokens to receive, in wei. This will pre-fill the output amount and switch to an exact output swap. */
310
+ destinationTokenAmount?: string;
309
311
  /** Callback function called when the deposit is successful */
310
312
  onSuccess?: () => void;
311
313
  }
@@ -18,6 +18,7 @@ export interface AnySpendCustomExactInProps {
18
18
  sourceTokenChainId?: number;
19
19
  destinationToken: components["schemas"]["Token"];
20
20
  destinationChainId: number;
21
+ destinationTokenAmount?: string;
21
22
  onSuccess?: (amount: string) => void;
22
23
  onOpenCustomModal?: () => void;
23
24
  mainFooter?: React.ReactNode;
@@ -1,5 +1,5 @@
1
1
  import { components } from "@b3dotfun/sdk/anyspend/types/api";
2
- export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientAddress, sourceTokenAddress, sourceTokenChainId, stakingContractAddress, token, onSuccess, }: {
2
+ export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientAddress, sourceTokenAddress, sourceTokenChainId, destinationTokenAmount, stakingContractAddress, token, onSuccess, }: {
3
3
  loadOrder?: string;
4
4
  mode?: "modal" | "page";
5
5
  recipientAddress: string;
@@ -7,5 +7,6 @@ export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientA
7
7
  sourceTokenChainId?: number;
8
8
  stakingContractAddress: string;
9
9
  token: components["schemas"]["Token"];
10
+ destinationTokenAmount?: string;
10
11
  onSuccess?: (amount: string) => void;
11
12
  }): import("react/jsx-runtime").JSX.Element | null;
@@ -306,6 +306,8 @@ export interface AnySpendDepositUpsideProps extends BaseModalProps {
306
306
  depositContractAddress: string;
307
307
  /** Token to deposit */
308
308
  token: components["schemas"]["Token"];
309
+ /** The exact amount of destination tokens to receive, in wei. This will pre-fill the output amount and switch to an exact output swap. */
310
+ destinationTokenAmount?: string;
309
311
  /** Callback function called when the deposit is successful */
310
312
  onSuccess?: () => void;
311
313
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.1.2-alpha.3",
3
+ "version": "0.1.2-alpha.4",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -12,11 +12,11 @@ import {
12
12
  } from "@b3dotfun/sdk/global-account/react";
13
13
  import { cn } from "@b3dotfun/sdk/shared/utils/cn";
14
14
  import { formatUnits } from "@b3dotfun/sdk/shared/utils/number";
15
- import type { AnySpendCustomExactInClasses } from "./types/classes";
16
15
  import invariant from "invariant";
17
16
  import { ArrowDown, Loader2 } from "lucide-react";
18
17
  import { motion } from "motion/react";
19
18
  import { useEffect, useMemo, useRef } from "react";
19
+ import type { AnySpendCustomExactInClasses } from "./types/classes";
20
20
 
21
21
  import { useSetActiveWallet } from "thirdweb/react";
22
22
  import { B3_TOKEN } from "../../constants";
@@ -53,6 +53,7 @@ export interface AnySpendCustomExactInProps {
53
53
  sourceTokenChainId?: number;
54
54
  destinationToken: components["schemas"]["Token"];
55
55
  destinationChainId: number;
56
+ destinationTokenAmount?: string;
56
57
  onSuccess?: (amount: string) => void;
57
58
  onOpenCustomModal?: () => void;
58
59
  mainFooter?: React.ReactNode;
@@ -105,6 +106,7 @@ function AnySpendCustomExactInInner({
105
106
  customUsdInputValues,
106
107
  preferEoa,
107
108
  customExactInConfig,
109
+ destinationTokenAmount,
108
110
  orderType = "custom_exact_in",
109
111
  minDestinationAmount,
110
112
  header,
@@ -194,6 +196,18 @@ function AnySpendCustomExactInInner({
194
196
  }
195
197
  }, [preferEoa, connectedEOAWallet, setActiveWallet]);
196
198
 
199
+ // Prefill destination amount if provided (for EXACT_OUTPUT mode)
200
+ const appliedDestinationAmount = useRef(false);
201
+ useEffect(() => {
202
+ if (destinationTokenAmount && !appliedDestinationAmount.current) {
203
+ appliedDestinationAmount.current = true;
204
+ // Convert wei to human-readable format
205
+ const formattedAmount = formatUnits(destinationTokenAmount, destinationToken.decimals);
206
+ setDstAmountInput(formattedAmount);
207
+ setIsSrcInputDirty(false); // Switch to EXACT_OUTPUT mode
208
+ }
209
+ }, [destinationTokenAmount, destinationToken.decimals, setDstAmountInput, setIsSrcInputDirty]);
210
+
197
211
  const selectedRecipientOrDefault = selectedRecipientAddress ?? recipientAddress;
198
212
 
199
213
  const expectedDstAmountRaw = anyspendQuote?.data?.currencyOut?.amount ?? "0";
@@ -22,6 +22,7 @@ export function AnySpendStakeUpsideExactIn({
22
22
  recipientAddress,
23
23
  sourceTokenAddress,
24
24
  sourceTokenChainId,
25
+ destinationTokenAmount,
25
26
  stakingContractAddress,
26
27
  token,
27
28
  onSuccess,
@@ -33,6 +34,7 @@ export function AnySpendStakeUpsideExactIn({
33
34
  sourceTokenChainId?: number;
34
35
  stakingContractAddress: string;
35
36
  token: components["schemas"]["Token"];
37
+ destinationTokenAmount?: string;
36
38
  onSuccess?: (amount: string) => void;
37
39
  }) {
38
40
  if (!recipientAddress) return null;
@@ -65,6 +67,7 @@ export function AnySpendStakeUpsideExactIn({
65
67
  sourceTokenChainId={sourceTokenChainId}
66
68
  destinationToken={token}
67
69
  destinationChainId={base.id}
70
+ destinationTokenAmount={destinationTokenAmount}
68
71
  customExactInConfig={customExactInConfig}
69
72
  header={header}
70
73
  onSuccess={onSuccess}
@@ -323,6 +323,8 @@ export interface AnySpendDepositUpsideProps extends BaseModalProps {
323
323
  depositContractAddress: string;
324
324
  /** Token to deposit */
325
325
  token: components["schemas"]["Token"];
326
+ /** The exact amount of destination tokens to receive, in wei. This will pre-fill the output amount and switch to an exact output swap. */
327
+ destinationTokenAmount?: string;
326
328
  /** Callback function called when the deposit is successful */
327
329
  onSuccess?: () => void;
328
330
  }