@b3dotfun/sdk 0.0.51-alpha.2 → 0.0.51-alpha.3

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.
Files changed (24) hide show
  1. package/dist/cjs/anyspend/abis/upsideStaking.d.ts +2058 -0
  2. package/dist/cjs/anyspend/abis/upsideStaking.js +1139 -0
  3. package/dist/cjs/anyspend/react/components/AnySpendStakeUpside.d.ts +11 -0
  4. package/dist/cjs/anyspend/react/components/AnySpendStakeUpside.js +44 -0
  5. package/dist/cjs/global-account/react/components/B3DynamicModal.js +5 -0
  6. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +21 -1
  7. package/dist/cjs/shared/constants/chains/b3Chain.d.ts +9 -3
  8. package/dist/esm/anyspend/abis/upsideStaking.d.ts +2058 -0
  9. package/dist/esm/anyspend/abis/upsideStaking.js +1136 -0
  10. package/dist/esm/anyspend/react/components/AnySpendStakeUpside.d.ts +11 -0
  11. package/dist/esm/anyspend/react/components/AnySpendStakeUpside.js +38 -0
  12. package/dist/esm/global-account/react/components/B3DynamicModal.js +5 -0
  13. package/dist/esm/global-account/react/stores/useModalStore.d.ts +21 -1
  14. package/dist/esm/shared/constants/chains/b3Chain.d.ts +9 -3
  15. package/dist/styles/index.css +1 -1
  16. package/dist/types/anyspend/abis/upsideStaking.d.ts +2058 -0
  17. package/dist/types/anyspend/react/components/AnySpendStakeUpside.d.ts +11 -0
  18. package/dist/types/global-account/react/stores/useModalStore.d.ts +21 -1
  19. package/dist/types/shared/constants/chains/b3Chain.d.ts +9 -3
  20. package/package.json +1 -1
  21. package/src/anyspend/abis/upsideStaking.ts +1137 -0
  22. package/src/anyspend/react/components/AnySpendStakeUpside.tsx +96 -0
  23. package/src/global-account/react/components/B3DynamicModal.tsx +5 -0
  24. package/src/global-account/react/stores/useModalStore.ts +22 -0
@@ -0,0 +1,96 @@
1
+ import { components } from "@b3dotfun/sdk/anyspend/types/api";
2
+ import { StyleRoot } from "@b3dotfun/sdk/global-account/react";
3
+ import { formatTokenAmount } from "@b3dotfun/sdk/shared/utils/number";
4
+ import invariant from "invariant";
5
+ import { encodeFunctionData } from "viem";
6
+ import { base } from "viem/chains";
7
+ import { B3_STAKING_CONTRACT, WETH_STAKING_CONTRACT } from "../../abis/upsideStaking";
8
+ import { AnySpendCustom } from "./AnySpendCustom";
9
+
10
+ function generateEncodedDataForStaking(amount: string, beneficiary: string, poolType: "b3" | "weth"): string {
11
+ invariant(BigInt(amount) > 0, "Amount must be greater than zero");
12
+ if (poolType === "weth") {
13
+ return encodeFunctionData({
14
+ abi: WETH_STAKING_CONTRACT,
15
+ functionName: "stakeFor",
16
+ args: [beneficiary as `0x${string}`, BigInt(amount)],
17
+ });
18
+ } else if (poolType === "b3") {
19
+ return encodeFunctionData({
20
+ abi: B3_STAKING_CONTRACT,
21
+ functionName: "stakeFor",
22
+ args: [beneficiary as `0x${string}`, BigInt(amount)],
23
+ });
24
+ }
25
+ throw new Error("Unsupported pool type");
26
+ }
27
+
28
+ export function AnySpendStakeUpside({
29
+ loadOrder,
30
+ mode = "modal",
31
+ beneficiaryAddress,
32
+ stakeAmount,
33
+ stakingContractAddress,
34
+ token,
35
+ poolType,
36
+ onSuccess,
37
+ }: {
38
+ loadOrder?: string;
39
+ mode?: "modal" | "page";
40
+ beneficiaryAddress: string;
41
+ stakeAmount: string;
42
+ stakingContractAddress: string;
43
+ token: components["schemas"]["Token"];
44
+ poolType: "b3" | "weth";
45
+ onSuccess?: () => void;
46
+ }) {
47
+ const header = () => (
48
+ <>
49
+ <div className="relative mx-auto size-32">
50
+ <img alt="token" className="size-full" src={token.metadata.logoURI || "https://cdn.b3.fun/b3-coin-3d.png"} />
51
+ </div>
52
+ <div className="from-b3-react-background to-as-on-surface-1 mt-[-60px] w-full rounded-t-lg bg-gradient-to-t">
53
+ <div className="h-[60px] w-full" />
54
+ <div className="mb-1 flex w-full flex-col items-center gap-2 p-5">
55
+ <span className="font-sf-rounded text-2xl font-semibold">
56
+ Swap & Stake {stakeAmount ? formatTokenAmount(BigInt(stakeAmount), token.decimals) : ""} {token.symbol}
57
+ </span>
58
+ </div>
59
+ </div>
60
+ </>
61
+ );
62
+
63
+ // Only generate encoded data if we have a valid beneficiary address
64
+ // This is used for the AnySpendCustom swap & stake flow
65
+ if (!beneficiaryAddress || beneficiaryAddress === "") {
66
+ return (
67
+ <StyleRoot>
68
+ <div className="bg-b3-react-background flex w-full flex-col items-center justify-center p-8">
69
+ <p className="font-medium text-yellow-600 dark:text-yellow-400">⚠️ Please connect your wallet to continue.</p>
70
+ </div>
71
+ </StyleRoot>
72
+ );
73
+ }
74
+
75
+ const encodedData = generateEncodedDataForStaking(stakeAmount, beneficiaryAddress, poolType);
76
+
77
+ return (
78
+ <AnySpendCustom
79
+ loadOrder={loadOrder}
80
+ mode={mode}
81
+ recipientAddress={beneficiaryAddress}
82
+ orderType={"custom"}
83
+ dstChainId={base.id}
84
+ dstToken={token}
85
+ dstAmount={stakeAmount}
86
+ contractAddress={stakingContractAddress}
87
+ encodedData={encodedData}
88
+ metadata={{
89
+ action: `stake ${token.symbol}`,
90
+ }}
91
+ header={header}
92
+ onSuccess={onSuccess}
93
+ showRecipient={true}
94
+ />
95
+ );
96
+ }
@@ -9,6 +9,7 @@ import {
9
9
  OrderHistory,
10
10
  } from "@b3dotfun/sdk/anyspend/react";
11
11
  import { AnySpendDepositHype } from "@b3dotfun/sdk/anyspend/react/components/AnyspendDepositHype";
12
+ import { AnySpendStakeUpside } from "@b3dotfun/sdk/anyspend/react/components/AnySpendStakeUpside";
12
13
  import { useIsMobile, useModalStore } from "@b3dotfun/sdk/global-account/react";
13
14
  import { cn } from "@b3dotfun/sdk/shared/utils/cn";
14
15
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
@@ -35,6 +36,7 @@ export function B3DynamicModal() {
35
36
  "anySpendJoinTournament",
36
37
  "anySpendFundTournament",
37
38
  "anySpendStakeB3",
39
+ "anySpendStakeUpside",
38
40
  "anySpendBuySpin",
39
41
  "anySpendOrderHistory",
40
42
  "signInWithB3",
@@ -49,6 +51,7 @@ export function B3DynamicModal() {
49
51
  "anySpendJoinTournament",
50
52
  "anySpendFundTournament",
51
53
  "anySpendStakeB3",
54
+ "anySpendStakeUpside",
52
55
  "anySpendBuySpin",
53
56
  "anySpendSignatureMint",
54
57
  "anySpendBondKit",
@@ -97,6 +100,8 @@ export function B3DynamicModal() {
97
100
  return <OrderHistory onBack={() => {}} mode="modal" />;
98
101
  case "anySpendStakeB3":
99
102
  return <AnySpendStakeB3 {...contentType} mode="modal" />;
103
+ case "anySpendStakeUpside":
104
+ return <AnySpendStakeUpside {...contentType} mode="modal" />;
100
105
  case "anySpendBuySpin":
101
106
  return <AnySpendBuySpin {...contentType} mode="modal" />;
102
107
  case "anySpendSignatureMint":
@@ -223,6 +223,27 @@ export interface AnySpendStakeB3Props extends BaseModalProps {
223
223
  onSuccess?: () => void;
224
224
  }
225
225
 
226
+ /**
227
+ * Props for the AnySpend Stake Contract modal
228
+ * Handles token staking operations to a given contract
229
+ */
230
+ export interface AnySpendStakeUpsideProps extends BaseModalProps {
231
+ /** Modal type identifier */
232
+ type: "anySpendStakeUpside";
233
+ /** Recipient address to stake B3 for */
234
+ beneficiaryAddress: string;
235
+ /** Stake amount */
236
+ stakeAmount: string;
237
+ /** Staking contract address */
238
+ stakingContractAddress: string;
239
+ /** Pool type for staking */
240
+ poolType: "b3" | "weth";
241
+ /** Token address to stake */
242
+ token: components["schemas"]["Token"];
243
+ /** Callback function called when the stake is successful */
244
+ onSuccess?: () => void;
245
+ }
246
+
226
247
  /**
227
248
  * Props for the AnySpend Buy Spin modal
228
249
  * Handles spin wheel entry purchases
@@ -332,6 +353,7 @@ export type ModalContentType =
332
353
  | AnySpendFundTournamentProps
333
354
  | AnySpendOrderHistoryProps
334
355
  | AnySpendStakeB3Props
356
+ | AnySpendStakeUpsideProps
335
357
  | AnySpendBuySpinProps
336
358
  | AnySpendSignatureMintProps
337
359
  | AnySpendBondKitProps