@b3dotfun/sdk 0.0.40 → 0.0.41-alpha.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.
Files changed (227) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +11 -1
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +17 -4
  3. package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +0 -1
  4. package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +0 -1
  5. package/dist/cjs/anyspend/react/components/AnySpendCustom.d.ts +1 -0
  6. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +33 -11
  7. package/dist/cjs/anyspend/react/components/AnySpendNFT.d.ts +2 -1
  8. package/dist/cjs/anyspend/react/components/AnySpendNFT.js +2 -2
  9. package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +0 -1
  10. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
  11. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +6 -3
  12. package/dist/cjs/anyspend/react/components/AnyspendSignatureMint.js +1 -2
  13. package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.js +5 -3
  14. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
  15. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +9 -9
  16. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +80 -10
  17. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
  18. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +40 -37
  19. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +8 -11
  20. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
  21. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +23 -9
  22. package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
  23. package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +10 -6
  24. package/dist/cjs/anyspend/react/components/common/PointsBadge.d.ts +7 -0
  25. package/dist/cjs/anyspend/react/components/common/PointsBadge.js +7 -0
  26. package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
  27. package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.js +14 -0
  28. package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
  29. package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.js +21 -0
  30. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
  31. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +18 -8
  32. package/dist/cjs/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
  33. package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +5 -3
  34. package/dist/cjs/anyspend/react/providers/index.d.ts +1 -0
  35. package/dist/cjs/anyspend/react/providers/index.js +3 -0
  36. package/dist/cjs/anyspend/services/anyspend.d.ts +1 -1
  37. package/dist/cjs/anyspend/services/anyspend.js +2 -0
  38. package/dist/cjs/anyspend/types/api.d.ts +51 -1
  39. package/dist/cjs/anyspend/utils/chain.js +1 -1
  40. package/dist/cjs/anyspend/utils/orderPayload.js +3 -0
  41. package/dist/cjs/bondkit/bondkitToken.d.ts +37 -2
  42. package/dist/cjs/bondkit/bondkitToken.js +268 -2
  43. package/dist/cjs/bondkit/bondkitTokenFactory.d.ts +1 -1
  44. package/dist/cjs/bondkit/bondkitTokenFactory.js +2 -2
  45. package/dist/cjs/bondkit/components/TradingView.js +3 -4
  46. package/dist/cjs/bondkit/config.d.ts +1 -1
  47. package/dist/cjs/bondkit/config.js +5 -2
  48. package/dist/cjs/bondkit/constants.d.ts +4 -0
  49. package/dist/cjs/bondkit/constants.js +6 -1
  50. package/dist/cjs/bondkit/index.d.ts +1 -0
  51. package/dist/cjs/bondkit/index.js +4 -1
  52. package/dist/cjs/bondkit/swapService.d.ts +43 -0
  53. package/dist/cjs/bondkit/swapService.js +376 -0
  54. package/dist/cjs/bondkit/types.d.ts +10 -4
  55. package/dist/cjs/bondkit/types.js +4 -5
  56. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
  57. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +41 -9
  58. package/dist/cjs/global-account/react/components/LinkAccount/LinkAccount.js +63 -3
  59. package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
  60. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +4 -3
  61. package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
  62. package/dist/cjs/global-account/react/hooks/index.js +3 -1
  63. package/dist/cjs/global-account/react/hooks/useAccountAssets.js +5 -2
  64. package/dist/cjs/global-account/react/hooks/useAuthentication.js +2 -3
  65. package/dist/cjs/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
  66. package/dist/cjs/global-account/react/hooks/useGlobalAccount.js +32 -0
  67. package/dist/cjs/global-account/react/hooks/useQueryB3.js +5 -2
  68. package/dist/cjs/global-account/react/hooks/useQueryBSMNT.js +5 -2
  69. package/dist/cjs/global-account/react/hooks/useSimBalance.js +2 -2
  70. package/dist/cjs/global-account/react/hooks/useTokenBalancesByChain.js +7 -1
  71. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +2 -2
  72. package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +28 -24
  73. package/dist/cjs/shared/utils/fetchBalances.d.ts +1 -1
  74. package/dist/esm/anyspend/react/components/AnySpend.d.ts +11 -1
  75. package/dist/esm/anyspend/react/components/AnySpend.js +17 -4
  76. package/dist/esm/anyspend/react/components/AnySpendBondKit.js +0 -1
  77. package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +0 -1
  78. package/dist/esm/anyspend/react/components/AnySpendCustom.d.ts +1 -0
  79. package/dist/esm/anyspend/react/components/AnySpendCustom.js +33 -11
  80. package/dist/esm/anyspend/react/components/AnySpendNFT.d.ts +2 -1
  81. package/dist/esm/anyspend/react/components/AnySpendNFT.js +2 -2
  82. package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +0 -1
  83. package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
  84. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +6 -3
  85. package/dist/esm/anyspend/react/components/AnyspendSignatureMint.js +1 -2
  86. package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.js +6 -4
  87. package/dist/esm/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
  88. package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +9 -9
  89. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +80 -10
  90. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
  91. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +40 -37
  92. package/dist/esm/anyspend/react/components/common/OrderDetails.js +8 -11
  93. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
  94. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +23 -9
  95. package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
  96. package/dist/esm/anyspend/react/components/common/PanelOnramp.js +10 -6
  97. package/dist/esm/anyspend/react/components/common/PointsBadge.d.ts +7 -0
  98. package/dist/esm/anyspend/react/components/common/PointsBadge.js +4 -0
  99. package/dist/esm/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
  100. package/dist/esm/anyspend/react/components/common/PointsDetailPanel.js +8 -0
  101. package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
  102. package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.js +17 -0
  103. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
  104. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +18 -8
  105. package/dist/esm/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
  106. package/dist/esm/anyspend/react/providers/AnyspendProvider.js +5 -3
  107. package/dist/esm/anyspend/react/providers/index.d.ts +1 -0
  108. package/dist/esm/anyspend/react/providers/index.js +1 -0
  109. package/dist/esm/anyspend/services/anyspend.d.ts +1 -1
  110. package/dist/esm/anyspend/services/anyspend.js +2 -0
  111. package/dist/esm/anyspend/types/api.d.ts +51 -1
  112. package/dist/esm/anyspend/utils/chain.js +1 -1
  113. package/dist/esm/anyspend/utils/orderPayload.js +3 -0
  114. package/dist/esm/bondkit/bondkitToken.d.ts +37 -2
  115. package/dist/esm/bondkit/bondkitToken.js +268 -2
  116. package/dist/esm/bondkit/bondkitTokenFactory.d.ts +1 -1
  117. package/dist/esm/bondkit/bondkitTokenFactory.js +2 -2
  118. package/dist/esm/bondkit/components/TradingView.js +3 -4
  119. package/dist/esm/bondkit/config.d.ts +1 -1
  120. package/dist/esm/bondkit/config.js +5 -2
  121. package/dist/esm/bondkit/constants.d.ts +4 -0
  122. package/dist/esm/bondkit/constants.js +5 -0
  123. package/dist/esm/bondkit/index.d.ts +1 -0
  124. package/dist/esm/bondkit/index.js +2 -0
  125. package/dist/esm/bondkit/swapService.d.ts +43 -0
  126. package/dist/esm/bondkit/swapService.js +372 -0
  127. package/dist/esm/bondkit/types.d.ts +10 -4
  128. package/dist/esm/bondkit/types.js +4 -5
  129. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
  130. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +42 -9
  131. package/dist/esm/global-account/react/components/LinkAccount/LinkAccount.js +65 -5
  132. package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
  133. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
  134. package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
  135. package/dist/esm/global-account/react/hooks/index.js +1 -0
  136. package/dist/esm/global-account/react/hooks/useAccountAssets.js +2 -2
  137. package/dist/esm/global-account/react/hooks/useAuthentication.js +2 -3
  138. package/dist/esm/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
  139. package/dist/esm/global-account/react/hooks/useGlobalAccount.js +29 -0
  140. package/dist/esm/global-account/react/hooks/useQueryB3.js +5 -2
  141. package/dist/esm/global-account/react/hooks/useQueryBSMNT.js +5 -2
  142. package/dist/esm/global-account/react/hooks/useSimBalance.js +2 -2
  143. package/dist/esm/global-account/react/hooks/useTokenBalancesByChain.js +4 -1
  144. package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +2 -2
  145. package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +29 -25
  146. package/dist/esm/shared/utils/fetchBalances.d.ts +1 -1
  147. package/dist/styles/index.css +1 -1
  148. package/dist/types/anyspend/react/components/AnySpend.d.ts +11 -1
  149. package/dist/types/anyspend/react/components/AnySpendCustom.d.ts +1 -0
  150. package/dist/types/anyspend/react/components/AnySpendNFT.d.ts +2 -1
  151. package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
  152. package/dist/types/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
  153. package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
  154. package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
  155. package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
  156. package/dist/types/anyspend/react/components/common/PointsBadge.d.ts +7 -0
  157. package/dist/types/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
  158. package/dist/types/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
  159. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
  160. package/dist/types/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
  161. package/dist/types/anyspend/react/providers/index.d.ts +1 -0
  162. package/dist/types/anyspend/services/anyspend.d.ts +1 -1
  163. package/dist/types/anyspend/types/api.d.ts +51 -1
  164. package/dist/types/bondkit/bondkitToken.d.ts +37 -2
  165. package/dist/types/bondkit/bondkitTokenFactory.d.ts +1 -1
  166. package/dist/types/bondkit/config.d.ts +1 -1
  167. package/dist/types/bondkit/constants.d.ts +4 -0
  168. package/dist/types/bondkit/index.d.ts +1 -0
  169. package/dist/types/bondkit/swapService.d.ts +43 -0
  170. package/dist/types/bondkit/types.d.ts +10 -4
  171. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
  172. package/dist/types/global-account/react/hooks/index.d.ts +1 -0
  173. package/dist/types/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
  174. package/dist/types/shared/utils/fetchBalances.d.ts +1 -1
  175. package/package.json +6 -5
  176. package/src/anyspend/react/components/AnySpend.tsx +37 -1
  177. package/src/anyspend/react/components/AnySpendBondKit.tsx +0 -1
  178. package/src/anyspend/react/components/AnySpendBuySpin.tsx +0 -1
  179. package/src/anyspend/react/components/AnySpendCustom.tsx +63 -13
  180. package/src/anyspend/react/components/AnySpendNFT.tsx +3 -0
  181. package/src/anyspend/react/components/AnySpendStakeB3.tsx +0 -1
  182. package/src/anyspend/react/components/AnyspendDepositHype.tsx +22 -0
  183. package/src/anyspend/react/components/AnyspendSignatureMint.tsx +1 -2
  184. package/src/anyspend/react/components/common/ConnectWalletPayment.tsx +7 -4
  185. package/src/anyspend/react/components/common/CryptoPaySection.tsx +13 -8
  186. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +170 -44
  187. package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +61 -45
  188. package/src/anyspend/react/components/common/OrderDetails.tsx +10 -14
  189. package/src/anyspend/react/components/common/OrderTokenAmount.tsx +28 -8
  190. package/src/anyspend/react/components/common/PanelOnramp.tsx +28 -15
  191. package/src/anyspend/react/components/common/PointsBadge.tsx +20 -0
  192. package/src/anyspend/react/components/common/PointsDetailPanel.tsx +55 -0
  193. package/src/anyspend/react/contexts/FeatureFlagsContext.tsx +34 -0
  194. package/src/anyspend/react/hooks/useAnyspendFlow.ts +18 -8
  195. package/src/anyspend/react/hooks/useAnyspendOrderAndTransactions.ts +1 -1
  196. package/src/anyspend/react/hooks/useCoinbaseOnrampOptions.ts +1 -1
  197. package/src/anyspend/react/providers/AnyspendProvider.tsx +11 -6
  198. package/src/anyspend/react/providers/index.ts +1 -0
  199. package/src/anyspend/services/anyspend.ts +3 -1
  200. package/src/anyspend/types/api.ts +51 -1
  201. package/src/anyspend/types/api_req_res.ts +6 -10
  202. package/src/anyspend/utils/chain.ts +1 -1
  203. package/src/anyspend/utils/orderPayload.ts +3 -0
  204. package/src/bondkit/bondkitToken.ts +323 -3
  205. package/src/bondkit/bondkitTokenFactory.ts +2 -2
  206. package/src/bondkit/components/TradingView.tsx +3 -5
  207. package/src/bondkit/config.ts +5 -2
  208. package/src/bondkit/constants.ts +7 -0
  209. package/src/bondkit/index.ts +3 -0
  210. package/src/bondkit/swapService.ts +464 -0
  211. package/src/bondkit/types.ts +12 -5
  212. package/src/global-account/react/components/B3Provider/B3Provider.tsx +55 -15
  213. package/src/global-account/react/components/LinkAccount/LinkAccount.tsx +106 -32
  214. package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +60 -5
  215. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +4 -2
  216. package/src/global-account/react/hooks/index.ts +1 -0
  217. package/src/global-account/react/hooks/useAccountAssets.ts +4 -3
  218. package/src/global-account/react/hooks/useAuthentication.ts +2 -3
  219. package/src/global-account/react/hooks/useGlobalAccount.tsx +36 -0
  220. package/src/global-account/react/hooks/useOneBalance.tsx +1 -1
  221. package/src/global-account/react/hooks/useQueryB3.ts +22 -15
  222. package/src/global-account/react/hooks/useQueryBSMNT.ts +22 -15
  223. package/src/global-account/react/hooks/useSimBalance.ts +2 -2
  224. package/src/global-account/react/hooks/useTokenBalancesByChain.tsx +4 -1
  225. package/src/global-account/react/hooks/useTokenFromUrl.tsx +2 -2
  226. package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +30 -26
  227. package/src/shared/utils/fetchBalances.ts +1 -1
@@ -0,0 +1,464 @@
1
+ import type { Address, Hex, PublicClient, WalletClient } from "viem";
2
+ import {
3
+ createPublicClient,
4
+ encodeAbiParameters,
5
+ formatUnits,
6
+ getContract,
7
+ http,
8
+ parseAbiParameters,
9
+ parseUnits,
10
+ } from "viem";
11
+ import { base } from "viem/chains";
12
+ import { BaseMainnetRpcUrl, Permit2Address, QuoterAddress, UniversalRouterAddress } from "./constants";
13
+ import type { SwapQuote } from "./types";
14
+
15
+ // Minimal ABIs needed for swap functionality
16
+ const UNIVERSAL_ROUTER_ABI = [
17
+ {
18
+ inputs: [
19
+ { name: "commands", type: "bytes" },
20
+ { name: "inputs", type: "bytes[]" },
21
+ { name: "deadline", type: "uint256" },
22
+ ],
23
+ name: "execute",
24
+ outputs: [],
25
+ stateMutability: "payable",
26
+ type: "function",
27
+ },
28
+ ] as const;
29
+
30
+ const QUOTER_ABI = [
31
+ {
32
+ inputs: [
33
+ {
34
+ components: [
35
+ {
36
+ components: [
37
+ { internalType: "Currency", name: "currency0", type: "address" },
38
+ { internalType: "Currency", name: "currency1", type: "address" },
39
+ { internalType: "uint24", name: "fee", type: "uint24" },
40
+ { internalType: "int24", name: "tickSpacing", type: "int24" },
41
+ { internalType: "contract IHooks", name: "hooks", type: "address" },
42
+ ],
43
+ internalType: "struct PoolKey",
44
+ name: "poolKey",
45
+ type: "tuple",
46
+ },
47
+ { internalType: "bool", name: "zeroForOne", type: "bool" },
48
+ { internalType: "uint128", name: "exactAmount", type: "uint128" },
49
+ { internalType: "bytes", name: "hookData", type: "bytes" },
50
+ ],
51
+ internalType: "struct IV4Quoter.QuoteExactSingleParams",
52
+ name: "params",
53
+ type: "tuple",
54
+ },
55
+ ],
56
+ name: "quoteExactInputSingle",
57
+ outputs: [
58
+ { internalType: "uint256", name: "amountOut", type: "uint256" },
59
+ { internalType: "uint256", name: "gasEstimate", type: "uint256" },
60
+ ],
61
+ stateMutability: "nonpayable",
62
+ type: "function",
63
+ },
64
+ ] as const;
65
+
66
+ const ERC20_ABI = [
67
+ {
68
+ inputs: [
69
+ { name: "spender", type: "address" },
70
+ { name: "amount", type: "uint256" },
71
+ ],
72
+ name: "approve",
73
+ outputs: [{ name: "", type: "bool" }],
74
+ stateMutability: "nonpayable",
75
+ type: "function",
76
+ },
77
+ {
78
+ inputs: [
79
+ { name: "owner", type: "address" },
80
+ { name: "spender", type: "address" },
81
+ ],
82
+ name: "allowance",
83
+ outputs: [{ name: "", type: "uint256" }],
84
+ stateMutability: "view",
85
+ type: "function",
86
+ },
87
+ ] as const;
88
+
89
+ const PERMIT2_ABI = [
90
+ {
91
+ inputs: [
92
+ { name: "token", type: "address" },
93
+ { name: "spender", type: "address" },
94
+ { name: "amount", type: "uint160" },
95
+ { name: "expiration", type: "uint48" },
96
+ ],
97
+ name: "approve",
98
+ outputs: [],
99
+ stateMutability: "nonpayable",
100
+ type: "function",
101
+ },
102
+ {
103
+ inputs: [
104
+ { name: "owner", type: "address" },
105
+ { name: "token", type: "address" },
106
+ { name: "spender", type: "address" },
107
+ ],
108
+ name: "allowance",
109
+ outputs: [
110
+ { name: "amount", type: "uint160" },
111
+ { name: "expiration", type: "uint48" },
112
+ { name: "nonce", type: "uint48" },
113
+ ],
114
+ stateMutability: "view",
115
+ type: "function",
116
+ },
117
+ ] as const;
118
+
119
+ const TOKEN_V4_CONFIG_ABI = [
120
+ {
121
+ inputs: [],
122
+ name: "v4Hook",
123
+ outputs: [{ internalType: "address", name: "", type: "address" }],
124
+ stateMutability: "view",
125
+ type: "function",
126
+ },
127
+ {
128
+ inputs: [],
129
+ name: "v4PoolFee",
130
+ outputs: [{ internalType: "uint24", name: "", type: "uint24" }],
131
+ stateMutability: "view",
132
+ type: "function",
133
+ },
134
+ {
135
+ inputs: [],
136
+ name: "v4TickSpacing",
137
+ outputs: [{ internalType: "int24", name: "", type: "int24" }],
138
+ stateMutability: "view",
139
+ type: "function",
140
+ },
141
+ ] as const;
142
+
143
+ // Command and action constants
144
+ const COMMANDS = {
145
+ V4_SWAP: "0x10",
146
+ } as const;
147
+
148
+ const V4_ACTIONS = {
149
+ SWAP_EXACT_IN_SINGLE: 6,
150
+ TAKE_ALL: 15,
151
+ SETTLE_ALL: 12,
152
+ } as const;
153
+
154
+ interface V4PoolConfig {
155
+ hook: string;
156
+ fee: number;
157
+ tickSpacing: number;
158
+ }
159
+
160
+ interface SwapParams {
161
+ tokenIn: Address;
162
+ tokenOut: Address;
163
+ amountIn: string;
164
+ tokenInDecimals: number;
165
+ tokenOutDecimals: number;
166
+ slippageTolerance: number;
167
+ recipient: Address;
168
+ deadline?: number;
169
+ }
170
+
171
+ /**
172
+ * Internal swap service for handling Uniswap V4 swaps between trading token and bondkit token
173
+ */
174
+ export class BondkitSwapService {
175
+ private v4Config: V4PoolConfig | null = null;
176
+ private configInitialized = false;
177
+ private readonly bondkitTokenAddress: Address;
178
+ private readonly publicClient: PublicClient;
179
+
180
+ constructor(bondkitTokenAddress: Address) {
181
+ this.bondkitTokenAddress = bondkitTokenAddress;
182
+ this.publicClient = createPublicClient({
183
+ chain: base,
184
+ transport: http(BaseMainnetRpcUrl),
185
+ }) as PublicClient;
186
+ }
187
+
188
+ /**
189
+ * Initialize V4 pool configuration from bondkit token contract
190
+ */
191
+ private async initializeV4Config(): Promise<void> {
192
+ if (this.configInitialized) {
193
+ return;
194
+ }
195
+
196
+ try {
197
+ const tokenContract = getContract({
198
+ address: this.bondkitTokenAddress,
199
+ abi: TOKEN_V4_CONFIG_ABI,
200
+ client: this.publicClient,
201
+ });
202
+
203
+ const [hook, fee, tickSpacing] = await Promise.all([
204
+ tokenContract.read.v4Hook(),
205
+ tokenContract.read.v4PoolFee(),
206
+ tokenContract.read.v4TickSpacing(),
207
+ ]);
208
+
209
+ this.v4Config = {
210
+ hook: hook as string,
211
+ fee: Number(fee),
212
+ tickSpacing: Number(tickSpacing),
213
+ };
214
+
215
+ this.configInitialized = true;
216
+ } catch (error) {
217
+ console.warn("Failed to initialize V4 configuration:", error);
218
+ // Use fallback configuration
219
+ this.v4Config = {
220
+ hook: "0xB36f4A2FB18b745ef8eD31452781a463d2B3f0cC",
221
+ fee: 30000,
222
+ tickSpacing: 60,
223
+ };
224
+ this.configInitialized = true;
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Get V4 pool configuration
230
+ */
231
+ private async getV4Config(): Promise<V4PoolConfig> {
232
+ await this.initializeV4Config();
233
+ if (!this.v4Config) {
234
+ throw new Error("Failed to initialize V4 configuration");
235
+ }
236
+ return this.v4Config;
237
+ }
238
+
239
+ /**
240
+ * Handle token approvals for swap
241
+ */
242
+ private async handleTokenApprovals(
243
+ tokenAddress: Address,
244
+ amountIn: string,
245
+ walletClient: WalletClient,
246
+ deadline: number,
247
+ ): Promise<void> {
248
+ // Skip approvals for ETH
249
+ if (tokenAddress === "0x0000000000000000000000000000000000000000") {
250
+ return;
251
+ }
252
+
253
+ const userAddress = walletClient.account?.address;
254
+ if (!userAddress) {
255
+ throw new Error("No user address found");
256
+ }
257
+
258
+ const erc20Contract = getContract({
259
+ address: tokenAddress,
260
+ abi: ERC20_ABI,
261
+ client: walletClient,
262
+ });
263
+
264
+ const permit2Contract = getContract({
265
+ address: Permit2Address,
266
+ abi: PERMIT2_ABI,
267
+ client: walletClient,
268
+ });
269
+
270
+ // Check ERC20 allowance to Permit2
271
+ const currentAllowance = (await erc20Contract.read.allowance([userAddress, Permit2Address])) as bigint;
272
+
273
+ const requiredAmount = BigInt(amountIn);
274
+
275
+ if (currentAllowance < requiredAmount) {
276
+ await erc20Contract.write.approve(
277
+ [Permit2Address, BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")],
278
+ {
279
+ account: userAddress,
280
+ chain: base,
281
+ },
282
+ );
283
+ }
284
+
285
+ // Check Permit2 allowance for Universal Router
286
+ const permit2Allowance = (await permit2Contract.read.allowance([
287
+ userAddress,
288
+ tokenAddress,
289
+ UniversalRouterAddress,
290
+ ])) as [bigint, number, number];
291
+
292
+ const [currentPermit2Amount, expiration] = permit2Allowance;
293
+ const currentTime = Math.floor(Date.now() / 1000);
294
+ const isExpired = expiration <= currentTime;
295
+
296
+ if (currentPermit2Amount < requiredAmount || isExpired) {
297
+ await permit2Contract.write.approve(
298
+ [tokenAddress, UniversalRouterAddress, BigInt("0xffffffffffffffffffffffffffffffffffffff"), Number(deadline)],
299
+ {
300
+ account: userAddress,
301
+ chain: base,
302
+ },
303
+ );
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Get swap quote
309
+ */
310
+ async getSwapQuote(params: SwapParams): Promise<SwapQuote | null> {
311
+ try {
312
+ const { tokenIn, tokenOut, amountIn, tokenInDecimals, tokenOutDecimals, slippageTolerance } = params;
313
+
314
+ const v4Config = await this.getV4Config();
315
+ const amountInWei = parseUnits(amountIn, tokenInDecimals);
316
+
317
+ // Determine token order for pool
318
+ const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
319
+ const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
320
+ const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
321
+
322
+ const poolKey = {
323
+ currency0: currency0 as Address,
324
+ currency1: currency1 as Address,
325
+ fee: v4Config.fee,
326
+ tickSpacing: v4Config.tickSpacing,
327
+ hooks: v4Config.hook as Address,
328
+ };
329
+
330
+ const quoteParams = {
331
+ poolKey,
332
+ zeroForOne,
333
+ exactAmount: BigInt(amountInWei.toString()),
334
+ hookData: "0x" as Hex,
335
+ };
336
+
337
+ const { result } = await this.publicClient.simulateContract({
338
+ address: QuoterAddress,
339
+ abi: QUOTER_ABI,
340
+ functionName: "quoteExactInputSingle",
341
+ args: [quoteParams],
342
+ });
343
+
344
+ const [amountOut] = result;
345
+ const amountOutRaw = formatUnits(amountOut, tokenOutDecimals);
346
+ const amountOutFormatted = parseFloat(amountOutRaw).toFixed(Math.min(6, tokenOutDecimals));
347
+
348
+ // Calculate minimum amount out with slippage
349
+ const slippageMultiplier = (100 - slippageTolerance) / 100;
350
+ const amountOutMinRaw = parseFloat(amountOutFormatted) * slippageMultiplier;
351
+ const amountOutMin = amountOutMinRaw.toFixed(tokenOutDecimals);
352
+
353
+ // Simple execution price calculation
354
+ const rate = parseFloat(amountOutFormatted) / parseFloat(amountIn);
355
+ const executionPrice = `1 = ${rate.toFixed(6)}`;
356
+
357
+ return {
358
+ amountOut: amountOutFormatted,
359
+ amountOutMin,
360
+ priceImpact: "0.0", // Simplified
361
+ executionPrice,
362
+ fee: (v4Config.fee / 10000).toString(),
363
+ };
364
+ } catch (error) {
365
+ console.warn("Error getting swap quote:", error);
366
+ return null;
367
+ }
368
+ }
369
+
370
+ /**
371
+ * Execute swap transaction
372
+ */
373
+ async executeSwap(params: SwapParams, walletClient: WalletClient): Promise<string | null> {
374
+ try {
375
+ const { tokenIn, tokenOut, amountIn, tokenInDecimals, tokenOutDecimals, deadline } = params;
376
+
377
+ const swapDeadline = deadline || Math.floor(Date.now() / 1000) + 3600;
378
+
379
+ if (!walletClient.account) {
380
+ throw new Error("Wallet client must have an account");
381
+ }
382
+
383
+ const amountInWei = parseUnits(amountIn, tokenInDecimals);
384
+
385
+ // Handle token approvals
386
+ await this.handleTokenApprovals(tokenIn, amountInWei.toString(), walletClient, swapDeadline);
387
+
388
+ // Get quote for minimum amount out
389
+ const quote = await this.getSwapQuote(params);
390
+ if (!quote) {
391
+ throw new Error("Unable to get swap quote");
392
+ }
393
+
394
+ const amountOutMinimum = parseUnits(quote.amountOutMin, tokenOutDecimals);
395
+ const v4Config = await this.getV4Config();
396
+
397
+ // Determine token order
398
+ const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
399
+ const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
400
+ const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
401
+
402
+ const poolKey = [currency0, currency1, v4Config.fee, v4Config.tickSpacing, v4Config.hook];
403
+
404
+ // Encode V4 actions
405
+ const actions = [
406
+ {
407
+ type: V4_ACTIONS.SWAP_EXACT_IN_SINGLE,
408
+ params: [poolKey, zeroForOne, amountInWei, amountOutMinimum, "0x" as `0x${string}`],
409
+ },
410
+ {
411
+ type: V4_ACTIONS.TAKE_ALL,
412
+ params: [(zeroForOne ? currency1 : currency0) as Address, BigInt(0)],
413
+ },
414
+ {
415
+ type: V4_ACTIONS.SETTLE_ALL,
416
+ params: [(zeroForOne ? currency0 : currency1) as Address, amountInWei],
417
+ },
418
+ ];
419
+
420
+ // Encode actions
421
+ const actionTypes = actions.map(action => action.type);
422
+ const actionsBytes = ("0x" + actionTypes.map(type => type.toString(16).padStart(2, "0")).join("")) as Hex;
423
+
424
+ const actionParams = actions.map(action => {
425
+ switch (action.type) {
426
+ case V4_ACTIONS.SWAP_EXACT_IN_SINGLE:
427
+ return encodeAbiParameters(
428
+ parseAbiParameters("((address,address,uint24,int24,address),bool,uint128,uint128,bytes)"),
429
+ [action.params as any],
430
+ );
431
+ case V4_ACTIONS.TAKE_ALL:
432
+ return encodeAbiParameters(parseAbiParameters("address,uint256"), action.params as [Address, bigint]);
433
+ case V4_ACTIONS.SETTLE_ALL:
434
+ return encodeAbiParameters(parseAbiParameters("address,uint256"), action.params as [Address, bigint]);
435
+ default:
436
+ return "0x00" as Hex;
437
+ }
438
+ });
439
+
440
+ const v4SwapInput = encodeAbiParameters(parseAbiParameters("bytes,bytes[]"), [actionsBytes, actionParams]);
441
+
442
+ const commands = COMMANDS.V4_SWAP;
443
+ const inputs = [v4SwapInput];
444
+
445
+ // Execute swap
446
+ const universalRouter = getContract({
447
+ address: UniversalRouterAddress,
448
+ abi: UNIVERSAL_ROUTER_ABI,
449
+ client: walletClient,
450
+ });
451
+
452
+ const txHash = await universalRouter.write.execute([commands, inputs, BigInt(swapDeadline)], {
453
+ account: walletClient.account,
454
+ chain: base,
455
+ value: tokenIn === "0x0000000000000000000000000000000000000000" ? amountInWei : BigInt(0),
456
+ });
457
+
458
+ return txHash;
459
+ } catch (error) {
460
+ console.warn("Error executing swap:", error);
461
+ return null;
462
+ }
463
+ }
464
+ }
@@ -64,12 +64,11 @@ export type DexMigrationEventArgs = {
64
64
  ethForFeeRecipient: bigint;
65
65
  };
66
66
 
67
- // Enum for Status (used in BondkitToken ABI)
67
+ // Enum for Status (matches contract Status enum exactly)
68
68
  export enum TokenStatus {
69
- Inactive = 0, // Assuming mapping from ABI, verify actual enum values if specified elsewhere
70
- BondingPhase = 1,
71
- DexPhase = 2,
72
- Migrated = 3,
69
+ Uninitialized = 0,
70
+ Bonding = 1,
71
+ Dex = 2,
73
72
  }
74
73
 
75
74
  export interface GetTransactionHistoryOptions {
@@ -101,3 +100,11 @@ export interface TransactionResponse {
101
100
  skip: number;
102
101
  data: Transaction[];
103
102
  }
103
+
104
+ export interface SwapQuote {
105
+ amountOut: string;
106
+ amountOutMin: string;
107
+ priceImpact: string;
108
+ executionPrice: string;
109
+ fee: string;
110
+ }
@@ -1,9 +1,15 @@
1
+ import { Users } from "@b3dotfun/b3-api";
1
2
  import { RelayKitProviderWrapper, TooltipProvider, useAuthStore } from "@b3dotfun/sdk/global-account/react";
2
3
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
3
4
  import { loadGA4Script } from "@b3dotfun/sdk/global-account/utils/analytics";
5
+ import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
4
6
  import { supportedChains } from "@b3dotfun/sdk/shared/constants/chains/supported";
7
+ import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
8
+ import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
9
+ import "@reservoir0x/relay-kit-ui/styles.css";
5
10
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
6
- import { useCallback, useEffect, useState } from "react";
11
+ import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
12
+ import { useCallback, useEffect, useMemo, useState } from "react";
7
13
  import { Toaster } from "sonner";
8
14
  import {
9
15
  getLastAuthProvider,
@@ -18,8 +24,7 @@ import { ClientType, setClientType } from "../../../client-manager";
18
24
  import { StyleRoot } from "../StyleRoot";
19
25
  import { B3Context, B3ContextType } from "./types";
20
26
 
21
- import { Users } from "@b3dotfun/b3-api";
22
- import "@reservoir0x/relay-kit-ui/styles.css";
27
+ const debug = debugB3React("B3Provider");
23
28
 
24
29
  /**
25
30
  * Default permissions configuration for B3 provider
@@ -31,11 +36,6 @@ const DEFAULT_PERMISSIONS = {
31
36
  endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
32
37
  };
33
38
 
34
- export const wagmiConfig = createConfig({
35
- chains: [supportedChains[0], ...supportedChains.slice(1)],
36
- transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http()])) as any,
37
- });
38
-
39
39
  // Create queryClient instance
40
40
  const queryClient = new QueryClient();
41
41
 
@@ -51,6 +51,8 @@ export function B3Provider({
51
51
  simDuneApiKey,
52
52
  toaster,
53
53
  clientType = "rest",
54
+ rpcUrls,
55
+ partnerId,
54
56
  }: {
55
57
  theme: "light" | "dark";
56
58
  children: React.ReactNode;
@@ -63,6 +65,8 @@ export function B3Provider({
63
65
  style?: React.CSSProperties;
64
66
  };
65
67
  clientType?: ClientType;
68
+ rpcUrls?: Record<number, string>;
69
+ partnerId?: string;
66
70
  }) {
67
71
  // Initialize Google Analytics on mount
68
72
  useEffect(() => {
@@ -74,10 +78,45 @@ export function B3Provider({
74
78
  setClientType(clientType);
75
79
  }, [clientType]);
76
80
 
81
+ const ecocystemConfig = useMemo(() => {
82
+ if (!partnerId) return undefined;
83
+
84
+ return {
85
+ ecosystemId: ecosystemWalletId,
86
+ partnerId: partnerId,
87
+ client,
88
+ };
89
+ }, [partnerId]);
90
+
91
+ // Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
92
+ // when parent component passes new object references with same content
93
+ const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
94
+
95
+ /**
96
+ * Creates wagmi config with optional custom RPC URLs
97
+ * @param rpcUrls - Optional mapping of chain IDs to RPC URLs
98
+ */
99
+ const wagmiConfig = useMemo(() => {
100
+ const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
101
+
102
+ return createConfig({
103
+ chains: [supportedChains[0], ...supportedChains.slice(1)],
104
+ transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
105
+ connectors: [
106
+ inAppWalletConnector({
107
+ ...(ecocystemConfig || {}),
108
+ client,
109
+ }),
110
+ // injected(),
111
+ // coinbaseWallet({ appName: "HypeDuel" }),
112
+ ],
113
+ });
114
+ }, [ecocystemConfig, rpcUrlsString]);
115
+
77
116
  return (
78
- <WagmiProvider config={wagmiConfig}>
79
- <QueryClientProvider client={queryClient}>
80
- <ThirdwebProvider>
117
+ <ThirdwebProvider>
118
+ <WagmiProvider config={wagmiConfig}>
119
+ <QueryClientProvider client={queryClient}>
81
120
  <TooltipProvider>
82
121
  <InnerProvider
83
122
  accountOverride={accountOverride}
@@ -94,9 +133,9 @@ export function B3Provider({
94
133
  </RelayKitProviderWrapper>
95
134
  </InnerProvider>
96
135
  </TooltipProvider>
97
- </ThirdwebProvider>
98
- </QueryClientProvider>
99
- </WagmiProvider>
136
+ </QueryClientProvider>
137
+ </WagmiProvider>
138
+ </ThirdwebProvider>
100
139
  );
101
140
  }
102
141
 
@@ -125,6 +164,7 @@ export function InnerProvider({
125
164
  const wallets = useConnectedWallets();
126
165
  const setActiveWallet = useSetActiveWallet();
127
166
  const isAuthenticated = useAuthStore(state => state.isAuthenticated);
167
+ debug("@@wallets", wallets);
128
168
 
129
169
  const [user, setUser] = useState<Users | undefined>(() => {
130
170
  // Try to restore user from localStorage on initialization
@@ -158,7 +198,7 @@ export function InnerProvider({
158
198
  (wallet: Wallet) => {
159
199
  setManuallySelectedWallet(wallet);
160
200
  const account = wallet.getAccount();
161
- console.log("@@gio:setWallet", wallet.id, account?.address);
201
+ debug("@@setWallet", wallet.id, account?.address);
162
202
  setActiveWallet(wallet);
163
203
  },
164
204
  [setManuallySelectedWallet, setActiveWallet],