@b3dotfun/sdk 0.0.23 → 0.0.24

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 (252) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +5 -8
  2. package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +2 -2
  3. package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +35 -28
  4. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -4
  5. package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +35 -28
  6. package/dist/cjs/anyspend/react/components/common/Accordion.d.ts +7 -0
  7. package/dist/cjs/anyspend/react/components/common/Accordion.js +53 -0
  8. package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.js +3 -22
  9. package/dist/cjs/anyspend/react/components/common/FiatPaymentMethod.js +2 -2
  10. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +76 -83
  11. package/dist/cjs/anyspend/react/components/common/OrderStatus.js +1 -1
  12. package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +4 -3
  13. package/dist/cjs/anyspend/react/components/common/PanelOnrampPayment.js +1 -5
  14. package/dist/cjs/anyspend/react/components/common/StepProgress.js +2 -2
  15. package/dist/cjs/anyspend/react/components/common/TokenBalance.js +1 -1
  16. package/dist/cjs/anyspend/react/hooks/useGeoOnrampOptions.d.ts +0 -1
  17. package/dist/cjs/anyspend/react/hooks/useGeoOnrampOptions.js +2 -4
  18. package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +2 -2
  19. package/dist/cjs/anyspend/react/hooks/useStripeSupport.d.ts +0 -1
  20. package/dist/cjs/anyspend/react/hooks/useStripeSupport.js +0 -1
  21. package/dist/cjs/anyspend/utils/chain.js +1 -1
  22. package/dist/cjs/bondkit/abis/BondkitTokenABI.d.ts +1020 -0
  23. package/dist/cjs/bondkit/abis/BondkitTokenABI.js +1332 -0
  24. package/dist/cjs/bondkit/abis/BondkitTokenFactoryABI.d.ts +391 -0
  25. package/dist/cjs/bondkit/abis/BondkitTokenFactoryABI.js +514 -0
  26. package/dist/cjs/bondkit/abis/index.d.ts +2 -0
  27. package/dist/cjs/bondkit/abis/index.js +18 -0
  28. package/dist/cjs/bondkit/bondkitToken.d.ts +68 -0
  29. package/dist/cjs/bondkit/bondkitToken.js +456 -0
  30. package/dist/cjs/bondkit/bondkitTokenFactory.d.ts +60 -0
  31. package/dist/cjs/bondkit/bondkitTokenFactory.js +274 -0
  32. package/dist/cjs/bondkit/components/TradingView.d.ts +3 -0
  33. package/dist/cjs/bondkit/components/TradingView.js +296 -0
  34. package/dist/cjs/bondkit/components/config/cdn.d.ts +42 -0
  35. package/dist/cjs/bondkit/components/config/cdn.js +63 -0
  36. package/dist/cjs/bondkit/components/index.d.ts +5 -0
  37. package/dist/cjs/bondkit/components/index.js +25 -0
  38. package/dist/cjs/bondkit/components/types.d.ts +8 -0
  39. package/dist/cjs/bondkit/components/types.js +5 -0
  40. package/dist/cjs/bondkit/components/utils/cdn-loader.d.ts +24 -0
  41. package/dist/cjs/bondkit/components/utils/cdn-loader.js +73 -0
  42. package/dist/cjs/bondkit/components/utils/format.d.ts +4 -0
  43. package/dist/cjs/bondkit/components/utils/format.js +31 -0
  44. package/dist/cjs/bondkit/config.d.ts +10 -0
  45. package/dist/cjs/bondkit/config.js +18 -0
  46. package/dist/cjs/bondkit/constants.d.ts +3 -0
  47. package/dist/cjs/bondkit/constants.js +5 -0
  48. package/dist/cjs/bondkit/index.d.ts +7 -0
  49. package/dist/cjs/bondkit/index.js +33 -0
  50. package/dist/cjs/bondkit/json_abis/BondkitABI.json +1329 -0
  51. package/dist/cjs/bondkit/json_abis/BondkitFactoryABI.json +511 -0
  52. package/dist/cjs/bondkit/json_abis/index.d.ts +3 -0
  53. package/dist/cjs/bondkit/json_abis/index.js +10 -0
  54. package/dist/cjs/bondkit/json_abis/index.ts +4 -0
  55. package/dist/cjs/bondkit/types.d.ts +77 -0
  56. package/dist/cjs/bondkit/types.js +11 -0
  57. package/dist/cjs/global-account/react/components/B3DynamicModal.js +1 -1
  58. package/dist/cjs/global-account/react/components/MintButton/MintButton.js +0 -1
  59. package/dist/cjs/global-account/react/components/SendERC20Button/SendERC20Button.d.ts +13 -0
  60. package/dist/cjs/global-account/react/components/SendERC20Button/SendERC20Button.js +33 -0
  61. package/dist/cjs/global-account/react/components/SendETHButton/SendETHButton.d.ts +12 -0
  62. package/dist/cjs/global-account/react/components/SendETHButton/SendETHButton.js +23 -0
  63. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +4 -2
  64. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +2 -2
  65. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
  66. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
  67. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -2
  68. package/dist/cjs/global-account/react/components/index.d.ts +2 -0
  69. package/dist/cjs/global-account/react/components/index.js +8 -2
  70. package/dist/cjs/global-account/react/components/ui/scroll-area.js +1 -1
  71. package/dist/cjs/global-account/react/components/ui/tooltip.d.ts +1 -1
  72. package/dist/cjs/global-account/react/hooks/index.d.ts +2 -1
  73. package/dist/cjs/global-account/react/hooks/index.js +18 -3
  74. package/dist/cjs/global-account/react/hooks/useAccountWallet.js +8 -0
  75. package/dist/cjs/global-account/react/hooks/useAuthentication.js +4 -4
  76. package/dist/cjs/global-account/react/hooks/useChainSwitchWithAction.d.ts +1 -2
  77. package/dist/cjs/global-account/react/hooks/useChainSwitchWithAction.js +2 -2
  78. package/dist/cjs/global-account/react/hooks/useFirstEOA.js +9 -7
  79. package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.d.ts +11 -0
  80. package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +160 -0
  81. package/dist/cjs/shared/constants/chains/supported.d.ts +4 -0
  82. package/dist/cjs/shared/constants/chains/supported.js +11 -0
  83. package/dist/cjs/shared/generated/chain-networks.json +1 -1
  84. package/dist/esm/anyspend/react/components/AnySpend.js +5 -8
  85. package/dist/esm/anyspend/react/components/AnySpendBondKit.js +2 -2
  86. package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +37 -30
  87. package/dist/esm/anyspend/react/components/AnySpendCustom.js +4 -4
  88. package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +37 -30
  89. package/dist/esm/anyspend/react/components/common/Accordion.d.ts +7 -0
  90. package/dist/esm/anyspend/react/components/common/Accordion.js +14 -0
  91. package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.js +3 -22
  92. package/dist/esm/anyspend/react/components/common/FiatPaymentMethod.js +2 -2
  93. package/dist/esm/anyspend/react/components/common/OrderDetails.js +79 -86
  94. package/dist/esm/anyspend/react/components/common/OrderStatus.js +1 -1
  95. package/dist/esm/anyspend/react/components/common/PanelOnramp.js +5 -4
  96. package/dist/esm/anyspend/react/components/common/PanelOnrampPayment.js +1 -5
  97. package/dist/esm/anyspend/react/components/common/StepProgress.js +2 -2
  98. package/dist/esm/anyspend/react/components/common/TokenBalance.js +1 -1
  99. package/dist/esm/anyspend/react/hooks/useGeoOnrampOptions.d.ts +0 -1
  100. package/dist/esm/anyspend/react/hooks/useGeoOnrampOptions.js +2 -4
  101. package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +2 -2
  102. package/dist/esm/anyspend/react/hooks/useStripeSupport.d.ts +0 -1
  103. package/dist/esm/anyspend/react/hooks/useStripeSupport.js +0 -1
  104. package/dist/esm/anyspend/utils/chain.js +1 -1
  105. package/dist/esm/bondkit/abis/BondkitTokenABI.d.ts +1020 -0
  106. package/dist/esm/bondkit/abis/BondkitTokenABI.js +1329 -0
  107. package/dist/esm/bondkit/abis/BondkitTokenFactoryABI.d.ts +391 -0
  108. package/dist/esm/bondkit/abis/BondkitTokenFactoryABI.js +511 -0
  109. package/dist/esm/bondkit/abis/index.d.ts +2 -0
  110. package/dist/esm/bondkit/abis/index.js +2 -0
  111. package/dist/esm/bondkit/bondkitToken.d.ts +68 -0
  112. package/dist/esm/bondkit/bondkitToken.js +452 -0
  113. package/dist/esm/bondkit/bondkitTokenFactory.d.ts +60 -0
  114. package/dist/esm/bondkit/bondkitTokenFactory.js +270 -0
  115. package/dist/esm/bondkit/components/TradingView.d.ts +3 -0
  116. package/dist/esm/bondkit/components/TradingView.js +294 -0
  117. package/dist/esm/bondkit/components/config/cdn.d.ts +42 -0
  118. package/dist/esm/bondkit/components/config/cdn.js +55 -0
  119. package/dist/esm/bondkit/components/index.d.ts +5 -0
  120. package/dist/esm/bondkit/components/index.js +4 -0
  121. package/dist/esm/bondkit/components/types.d.ts +8 -0
  122. package/dist/esm/bondkit/components/types.js +4 -0
  123. package/dist/esm/bondkit/components/utils/cdn-loader.d.ts +24 -0
  124. package/dist/esm/bondkit/components/utils/cdn-loader.js +66 -0
  125. package/dist/esm/bondkit/components/utils/format.d.ts +4 -0
  126. package/dist/esm/bondkit/components/utils/format.js +28 -0
  127. package/dist/esm/bondkit/config.d.ts +10 -0
  128. package/dist/esm/bondkit/config.js +14 -0
  129. package/dist/esm/bondkit/constants.d.ts +3 -0
  130. package/dist/esm/bondkit/constants.js +2 -0
  131. package/dist/esm/bondkit/index.d.ts +7 -0
  132. package/dist/esm/bondkit/index.js +12 -0
  133. package/dist/esm/bondkit/json_abis/BondkitABI.json +1329 -0
  134. package/dist/esm/bondkit/json_abis/BondkitFactoryABI.json +511 -0
  135. package/dist/esm/bondkit/json_abis/index.d.ts +3 -0
  136. package/dist/esm/bondkit/json_abis/index.js +3 -0
  137. package/dist/esm/bondkit/json_abis/index.ts +4 -0
  138. package/dist/esm/bondkit/types.d.ts +77 -0
  139. package/dist/esm/bondkit/types.js +8 -0
  140. package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
  141. package/dist/esm/global-account/react/components/MintButton/MintButton.js +0 -1
  142. package/dist/esm/global-account/react/components/SendERC20Button/SendERC20Button.d.ts +13 -0
  143. package/dist/esm/global-account/react/components/SendERC20Button/SendERC20Button.js +30 -0
  144. package/dist/esm/global-account/react/components/SendETHButton/SendETHButton.d.ts +12 -0
  145. package/dist/esm/global-account/react/components/SendETHButton/SendETHButton.js +20 -0
  146. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +4 -2
  147. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +2 -2
  148. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
  149. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
  150. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -2
  151. package/dist/esm/global-account/react/components/index.d.ts +2 -0
  152. package/dist/esm/global-account/react/components/index.js +4 -0
  153. package/dist/esm/global-account/react/components/ui/scroll-area.js +1 -1
  154. package/dist/esm/global-account/react/components/ui/tooltip.d.ts +1 -1
  155. package/dist/esm/global-account/react/hooks/index.d.ts +2 -1
  156. package/dist/esm/global-account/react/hooks/index.js +2 -1
  157. package/dist/esm/global-account/react/hooks/useAccountWallet.js +8 -0
  158. package/dist/esm/global-account/react/hooks/useAuthentication.js +4 -4
  159. package/dist/esm/global-account/react/hooks/useChainSwitchWithAction.d.ts +1 -2
  160. package/dist/esm/global-account/react/hooks/useChainSwitchWithAction.js +2 -2
  161. package/dist/esm/global-account/react/hooks/useFirstEOA.js +9 -7
  162. package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.d.ts +11 -0
  163. package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +154 -0
  164. package/dist/esm/shared/constants/chains/supported.d.ts +4 -0
  165. package/dist/esm/shared/constants/chains/supported.js +10 -0
  166. package/dist/esm/shared/generated/chain-networks.json +1 -1
  167. package/dist/styles/index.css +1 -1
  168. package/dist/types/anyspend/react/components/common/Accordion.d.ts +7 -0
  169. package/dist/types/anyspend/react/hooks/useGeoOnrampOptions.d.ts +0 -1
  170. package/dist/types/anyspend/react/hooks/useSigMint.d.ts +2 -2
  171. package/dist/types/anyspend/react/hooks/useStripeSupport.d.ts +0 -1
  172. package/dist/types/bondkit/abis/BondkitTokenABI.d.ts +1020 -0
  173. package/dist/types/bondkit/abis/BondkitTokenFactoryABI.d.ts +391 -0
  174. package/dist/types/bondkit/abis/index.d.ts +2 -0
  175. package/dist/types/bondkit/bondkitToken.d.ts +68 -0
  176. package/dist/types/bondkit/bondkitTokenFactory.d.ts +60 -0
  177. package/dist/types/bondkit/components/TradingView.d.ts +3 -0
  178. package/dist/types/bondkit/components/config/cdn.d.ts +42 -0
  179. package/dist/types/bondkit/components/index.d.ts +5 -0
  180. package/dist/types/bondkit/components/types.d.ts +8 -0
  181. package/dist/types/bondkit/components/utils/cdn-loader.d.ts +24 -0
  182. package/dist/types/bondkit/components/utils/format.d.ts +4 -0
  183. package/dist/types/bondkit/config.d.ts +10 -0
  184. package/dist/types/bondkit/constants.d.ts +3 -0
  185. package/dist/types/bondkit/index.d.ts +7 -0
  186. package/dist/types/bondkit/json_abis/index.d.ts +3 -0
  187. package/dist/types/bondkit/types.d.ts +77 -0
  188. package/dist/types/global-account/react/components/SendERC20Button/SendERC20Button.d.ts +13 -0
  189. package/dist/types/global-account/react/components/SendETHButton/SendETHButton.d.ts +12 -0
  190. package/dist/types/global-account/react/components/index.d.ts +2 -0
  191. package/dist/types/global-account/react/components/ui/tooltip.d.ts +1 -1
  192. package/dist/types/global-account/react/hooks/index.d.ts +2 -1
  193. package/dist/types/global-account/react/hooks/useChainSwitchWithAction.d.ts +1 -2
  194. package/dist/types/global-account/react/hooks/useUnifiedChainSwitchAndExecute.d.ts +11 -0
  195. package/dist/types/shared/constants/chains/supported.d.ts +4 -0
  196. package/package.json +42 -7
  197. package/src/anyspend/react/components/AnySpend.tsx +5 -23
  198. package/src/anyspend/react/components/AnySpendBondKit.tsx +2 -2
  199. package/src/anyspend/react/components/AnySpendBuySpin.tsx +42 -32
  200. package/src/anyspend/react/components/AnySpendCustom.tsx +7 -13
  201. package/src/anyspend/react/components/AnySpendStakeB3.tsx +44 -34
  202. package/src/anyspend/react/components/common/Accordion.tsx +56 -0
  203. package/src/anyspend/react/components/common/ConnectWalletPayment.tsx +0 -25
  204. package/src/anyspend/react/components/common/FiatPaymentMethod.tsx +1 -2
  205. package/src/anyspend/react/components/common/OrderDetails.tsx +292 -260
  206. package/src/anyspend/react/components/common/OrderStatus.tsx +1 -1
  207. package/src/anyspend/react/components/common/PanelOnramp.tsx +7 -7
  208. package/src/anyspend/react/components/common/PanelOnrampPayment.tsx +0 -6
  209. package/src/anyspend/react/components/common/StepProgress.tsx +2 -2
  210. package/src/anyspend/react/components/common/TokenBalance.tsx +3 -3
  211. package/src/anyspend/react/hooks/useGeoOnrampOptions.ts +2 -4
  212. package/src/anyspend/react/hooks/useStripeSupport.ts +0 -1
  213. package/src/anyspend/utils/chain.ts +1 -1
  214. package/src/bondkit/abis/BondkitTokenABI.ts +1329 -0
  215. package/src/bondkit/abis/BondkitTokenFactoryABI.ts +511 -0
  216. package/src/bondkit/abis/index.ts +2 -0
  217. package/src/bondkit/bondkitToken.ts +539 -0
  218. package/src/bondkit/bondkitTokenFactory.ts +336 -0
  219. package/src/bondkit/components/TradingView.tsx +341 -0
  220. package/src/bondkit/components/config/cdn.ts +63 -0
  221. package/src/bondkit/components/index.ts +5 -0
  222. package/src/bondkit/components/types.ts +9 -0
  223. package/src/bondkit/components/utils/cdn-loader.ts +77 -0
  224. package/src/bondkit/components/utils/format.ts +36 -0
  225. package/src/bondkit/config.ts +26 -0
  226. package/src/bondkit/constants.ts +5 -0
  227. package/src/bondkit/index.ts +16 -0
  228. package/src/bondkit/json_abis/BondkitABI.json +1329 -0
  229. package/src/bondkit/json_abis/BondkitFactoryABI.json +511 -0
  230. package/src/bondkit/json_abis/index.ts +4 -0
  231. package/src/bondkit/types.ts +98 -0
  232. package/src/global-account/react/components/B3DynamicModal.tsx +2 -1
  233. package/src/global-account/react/components/MintButton/MintButton.tsx +0 -1
  234. package/src/global-account/react/components/SendERC20Button/SendERC20Button.tsx +57 -0
  235. package/src/global-account/react/components/SendETHButton/SendETHButton.tsx +37 -0
  236. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +21 -22
  237. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +2 -2
  238. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +1 -1
  239. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +2 -2
  240. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
  241. package/src/global-account/react/components/index.ts +6 -0
  242. package/src/global-account/react/components/ui/scroll-area.tsx +2 -2
  243. package/src/global-account/react/components/ui/tooltip.tsx +1 -1
  244. package/src/global-account/react/hooks/index.ts +2 -1
  245. package/src/global-account/react/hooks/useAccountWallet.tsx +10 -1
  246. package/src/global-account/react/hooks/useAuthentication.ts +4 -4
  247. package/src/global-account/react/hooks/useChainSwitchWithAction.ts +3 -4
  248. package/src/global-account/react/hooks/useFirstEOA.tsx +10 -7
  249. package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +186 -0
  250. package/src/shared/constants/chains/supported.ts +11 -0
  251. package/src/shared/generated/chain-networks.json +1 -1
  252. package/src/styles/index.css +27 -0
@@ -0,0 +1,270 @@
1
+ import { createPublicClient, createWalletClient, custom, decodeEventLog, getContract, http } from "viem";
2
+ import { privateKeyToAccount } from "viem/accounts";
3
+ import { BondkitTokenFactoryABI } from "./abis/index.js";
4
+ import { getConfig } from "./config.js";
5
+ // Define the event ABI snippet for BondkitTokenCreated specifically for decoding
6
+ const bondkitTokenCreatedEventAbi = BondkitTokenFactoryABI.find(item => item.type === "event" && item.name === "BondkitTokenCreated");
7
+ export class BondkitTokenFactory {
8
+ constructor(chainId, walletKey) {
9
+ if (walletKey && !walletKey.startsWith("0x")) {
10
+ this.walletKey = `0x${walletKey}`;
11
+ }
12
+ else if (walletKey) {
13
+ this.walletKey = walletKey;
14
+ }
15
+ const config = getConfig(chainId);
16
+ this.chain = config.chain;
17
+ this.contractAddress = config.factoryAddress;
18
+ this.rpcUrl = config.rpcUrl;
19
+ this.publicClient = createPublicClient({
20
+ chain: this.chain,
21
+ transport: http(this.rpcUrl),
22
+ });
23
+ this.walletClientInstance = createWalletClient({
24
+ chain: this.chain,
25
+ transport: http(this.rpcUrl),
26
+ account: this.walletKey ? privateKeyToAccount(this.walletKey) : undefined,
27
+ });
28
+ this.contract = getContract({
29
+ address: this.contractAddress,
30
+ abi: BondkitTokenFactoryABI,
31
+ client: this.walletClientInstance,
32
+ });
33
+ }
34
+ connect(provider) {
35
+ try {
36
+ const transport = provider ? custom(provider) : http(this.rpcUrl);
37
+ this.connectedProvider = provider;
38
+ this.walletClientInstance = createWalletClient({
39
+ chain: this.chain,
40
+ transport,
41
+ account: this.walletKey ? privateKeyToAccount(this.walletKey) : undefined,
42
+ });
43
+ this.contract = getContract({
44
+ address: this.contractAddress,
45
+ abi: BondkitTokenFactoryABI,
46
+ client: this.walletClientInstance,
47
+ });
48
+ this.publicClient = createPublicClient({
49
+ chain: this.chain,
50
+ transport,
51
+ });
52
+ return true;
53
+ }
54
+ catch (error) {
55
+ console.error("Connection failed:", error);
56
+ return false;
57
+ }
58
+ }
59
+ /**
60
+ * Connects using an EIP-1193 provider and requests accounts, selecting the first one.
61
+ * Enables frontend wallet flows without requiring a private key.
62
+ */
63
+ async connectWithProvider(provider) {
64
+ try {
65
+ const transport = custom(provider);
66
+ this.connectedProvider = provider;
67
+ // Request accounts; fall back to eth_accounts if user already connected
68
+ let addresses = [];
69
+ try {
70
+ const result = await provider.request({ method: "eth_requestAccounts" });
71
+ if (Array.isArray(result))
72
+ addresses = result;
73
+ }
74
+ catch (requestErr) {
75
+ try {
76
+ const result = await provider.request({ method: "eth_accounts" });
77
+ if (Array.isArray(result))
78
+ addresses = result;
79
+ }
80
+ catch (_) { }
81
+ }
82
+ const selectedAccount = (addresses?.[0] ?? undefined);
83
+ this.walletClientInstance = createWalletClient({
84
+ chain: this.chain,
85
+ transport,
86
+ account: selectedAccount,
87
+ });
88
+ this.publicClient = createPublicClient({
89
+ chain: this.chain,
90
+ transport,
91
+ });
92
+ this.contract = getContract({
93
+ address: this.contractAddress,
94
+ abi: BondkitTokenFactoryABI,
95
+ client: this.walletClientInstance,
96
+ });
97
+ return true;
98
+ }
99
+ catch (error) {
100
+ console.error("Connection failed:", error);
101
+ return false;
102
+ }
103
+ }
104
+ /**
105
+ * Ensure we have an account set for write operations.
106
+ * If not, try to resolve from a connected provider and reinitialize the client.
107
+ */
108
+ async ensureWriteAccount() {
109
+ if (this.walletClientInstance.account || this.walletKey)
110
+ return;
111
+ if (!this.connectedProvider)
112
+ return;
113
+ try {
114
+ const addresses = (await this.connectedProvider.request({ method: "eth_accounts" }));
115
+ const selectedAccount = (addresses?.[0] ?? undefined);
116
+ if (selectedAccount) {
117
+ const transport = custom(this.connectedProvider);
118
+ this.walletClientInstance = createWalletClient({
119
+ chain: this.chain,
120
+ transport,
121
+ account: selectedAccount,
122
+ });
123
+ this.contract = getContract({
124
+ address: this.contractAddress,
125
+ abi: BondkitTokenFactoryABI,
126
+ client: this.walletClientInstance,
127
+ });
128
+ }
129
+ }
130
+ catch (_) { }
131
+ }
132
+ // TODO: Implement a more generic handleError based on leaderboards-sdk style if common errors are identified
133
+ async handleError(error, context) {
134
+ const defaultMessage = context ? `Error in ${context}:` : "An error occurred:";
135
+ console.error(defaultMessage, error);
136
+ // You could check for common error signatures here if needed
137
+ // e.g. if (error.data === "0xsomeErrorCode") throw new Error("Specific known error");
138
+ throw error;
139
+ }
140
+ /**
141
+ * Deploys a new Bondkit token using the factory.
142
+ * @param config The configuration for the token to be deployed.
143
+ * @returns The address of the newly created BondkitToken.
144
+ */
145
+ async deployBondkitToken(configArg) {
146
+ if (!this.walletClientInstance.account && !this.walletKey) {
147
+ await this.ensureWriteAccount();
148
+ if (!this.walletClientInstance.account && !this.walletKey) {
149
+ throw new Error("Wallet key not set or client not connected with an account.");
150
+ }
151
+ }
152
+ if (!bondkitTokenCreatedEventAbi) {
153
+ throw new Error("BondkitTokenCreated event ABI not found.");
154
+ }
155
+ try {
156
+ const accountToUse = this.walletKey ? privateKeyToAccount(this.walletKey) : this.walletClientInstance.account;
157
+ if (!accountToUse) {
158
+ throw new Error("Account for transaction could not be determined.");
159
+ }
160
+ const hash = await this.contract.write.deployBondkitToken([configArg], {
161
+ account: accountToUse,
162
+ chain: this.chain,
163
+ });
164
+ console.log("hash", hash);
165
+ const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
166
+ for (const log of receipt.logs) {
167
+ try {
168
+ if (log.topics[0] !== "0x75b2d0aabe689b83d7eb7920447b5ae7bef7f28da01d0beb3e197899392eb0d6") {
169
+ continue;
170
+ }
171
+ const decodedEvent = decodeEventLog({
172
+ abi: BondkitTokenFactoryABI,
173
+ data: log.data,
174
+ topics: log.topics,
175
+ });
176
+ return decodedEvent.args.tokenAddress;
177
+ }
178
+ catch (e) { }
179
+ }
180
+ throw new Error("BondkitTokenCreated event not found in transaction logs.");
181
+ }
182
+ catch (error) {
183
+ return this.handleError(error, "deployBondkitToken");
184
+ }
185
+ }
186
+ /**
187
+ * Gets the configuration of a deployed Bondkit token.
188
+ * @param tokenAddress The address of the Bondkit token.
189
+ * @returns The configuration object for the token.
190
+ */
191
+ async getBondkitTokenConfig(tokenAddress) {
192
+ try {
193
+ const result = await this.contract.read.getBondkitTokenConfig([tokenAddress]);
194
+ return result;
195
+ }
196
+ catch (error) {
197
+ console.error(`Error getting config for token ${tokenAddress}:`, error);
198
+ return undefined;
199
+ }
200
+ }
201
+ /**
202
+ * Gets a list of all Bondkit tokens deployed by this factory.
203
+ * @returns An array of token addresses.
204
+ */
205
+ async getDeployedBondkitTokens() {
206
+ // ABI returns address[] which viem treats as readonly Address[]
207
+ try {
208
+ return await this.contract.read.getDeployedBondkitTokens(); // No arguments if function takes none
209
+ }
210
+ catch (error) {
211
+ console.error("Error getting all deployed tokens:", error);
212
+ return [];
213
+ }
214
+ }
215
+ /**
216
+ * Gets the owner of the factory contract.
217
+ * @returns The address of the owner.
218
+ */
219
+ async getOwner() {
220
+ try {
221
+ return await this.contract.read.owner(); // No arguments if function takes none
222
+ }
223
+ catch (error) {
224
+ console.error("Error getting factory owner:", error);
225
+ return undefined;
226
+ }
227
+ }
228
+ /**
229
+ * Gets the implementation address used for new Bondkit token clones.
230
+ * @returns The address of the BondkitToken implementation contract.
231
+ */
232
+ async getBondkitTokenImplementation() {
233
+ try {
234
+ return await this.contract.read.bondkitTokenImplementation(); // No arguments if function takes none
235
+ }
236
+ catch (error) {
237
+ console.error("Error getting Bondkit token implementation address:", error);
238
+ return undefined;
239
+ }
240
+ }
241
+ // --- Write Methods (Ownership, etc.) --- //
242
+ /**
243
+ * Transfers ownership of the factory contract to a new owner.
244
+ * Requires the current owner to call this method.
245
+ * @param newOwner The address of the new owner.
246
+ * @returns A promise that resolves with the transaction hash.
247
+ */
248
+ async transferOwnership(newOwner) {
249
+ if (!this.walletClientInstance.account && !this.walletKey) {
250
+ await this.ensureWriteAccount();
251
+ if (!this.walletClientInstance.account && !this.walletKey) {
252
+ throw new Error("Wallet key not set or client not connected with an account for write operation.");
253
+ }
254
+ }
255
+ try {
256
+ const accountToUse = this.walletKey ? privateKeyToAccount(this.walletKey) : this.walletClientInstance.account;
257
+ if (!accountToUse) {
258
+ throw new Error("Account for transaction could not be determined.");
259
+ }
260
+ const hash = await this.contract.write.transferOwnership([newOwner], {
261
+ account: accountToUse,
262
+ chain: this.chain,
263
+ });
264
+ return hash;
265
+ }
266
+ catch (error) {
267
+ return this.handleError(error, "transferOwnership");
268
+ }
269
+ }
270
+ }
@@ -0,0 +1,3 @@
1
+ import { TradingViewProps } from "./types";
2
+ declare const TradingView: ({ className, tokenAddress, tokenSymbol }: TradingViewProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default TradingView;
@@ -0,0 +1,294 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { loadScriptFromCDN } from "./utils/cdn-loader.js";
4
+ import { formatNumberSmall } from "./utils/format.js";
5
+ import { Loader2 } from "lucide-react";
6
+ import { useEffect, useRef, useState } from "react";
7
+ // TradingView will be available on window after loading from CDN
8
+ // Datafeed will be implemented inline
9
+ // Mock loading overlay - replace with your actual loading component
10
+ const GifLoadingOverlay = ({ className }) => (_jsx("div", { className: `absolute inset-0 flex items-center justify-center bg-white/50 backdrop-blur-sm ${className || ""}`, children: _jsx(Loader2, { className: "text-secondary-grey h-8 w-8 animate-spin" }) }));
11
+ const TradingView = ({ className, tokenAddress, tokenSymbol }) => {
12
+ const theme = "light";
13
+ // Use token info for the current trade
14
+ const currentTrade = {
15
+ product_id: tokenAddress && tokenSymbol ? `${tokenSymbol}-${tokenAddress}` : "BONDKIT",
16
+ };
17
+ const [tradingViewDefaultInterval, setTradingViewDefaultInterval] = useState("60");
18
+ const [tradingViewTimezone, setTradingViewTimezone] = useState("");
19
+ const chartContainerRef = useRef(null);
20
+ const tvWidgetRef = useRef(null);
21
+ const [chartLoaded, setChartLoaded] = useState(false);
22
+ const [showLoading, setShowLoading] = useState(true);
23
+ const [librariesLoaded, setLibrariesLoaded] = useState(false);
24
+ const isChangingInterval = useRef(false);
25
+ // Load TradingView libraries from CDN
26
+ useEffect(() => {
27
+ const loadLibraries = async () => {
28
+ try {
29
+ // Load TradingView charting library
30
+ await loadScriptFromCDN("/static/charting_library/charting_library.js");
31
+ setLibrariesLoaded(true);
32
+ }
33
+ catch (error) {
34
+ console.error("Failed to load TradingView libraries:", error);
35
+ }
36
+ };
37
+ loadLibraries();
38
+ }, []);
39
+ useEffect(() => {
40
+ if (!chartContainerRef.current || !librariesLoaded)
41
+ return;
42
+ // Create UDF-compatible datafeed that mimics the original UDFCompatibleDatafeed
43
+ const createUDFDatafeed = (baseUrl) => {
44
+ return {
45
+ onReady: (callback) => {
46
+ // Fetch configuration from UDF config endpoint
47
+ fetch(`${baseUrl}/config`)
48
+ .then(response => response.json())
49
+ .then(config => callback(config))
50
+ .catch(() => {
51
+ // Fallback configuration if config endpoint fails
52
+ callback({
53
+ supported_resolutions: ["1", "5", "15", "30", "60", "1D", "1W", "1M"],
54
+ supports_group_request: false,
55
+ supports_marks: false,
56
+ supports_search: false,
57
+ supports_timescale_marks: false,
58
+ });
59
+ });
60
+ },
61
+ searchSymbols: () => { },
62
+ resolveSymbol: (symbolName, onSymbolResolvedCallback) => {
63
+ // Try to fetch symbol info from UDF endpoint
64
+ fetch(`${baseUrl}/symbols?symbol=${symbolName}`)
65
+ .then(response => response.json())
66
+ .then(symbolInfo => onSymbolResolvedCallback(symbolInfo))
67
+ .catch(() => {
68
+ // Fallback symbol info
69
+ onSymbolResolvedCallback({
70
+ name: symbolName,
71
+ ticker: symbolName,
72
+ description: symbolName,
73
+ type: "crypto",
74
+ session: "24x7",
75
+ timezone: "Etc/UTC",
76
+ exchange: "BONDKIT",
77
+ minmov: 1,
78
+ pricescale: 10000,
79
+ has_intraday: true,
80
+ supported_resolutions: ["1", "5", "15", "30", "60", "1D", "1W", "1M"],
81
+ });
82
+ });
83
+ },
84
+ getBars: async (symbolInfo, resolution, periodParams, onHistoryCallback) => {
85
+ try {
86
+ const { from, to, countback } = periodParams;
87
+ // Build URL with parameters matching production
88
+ const params = new URLSearchParams({
89
+ symbol: symbolInfo.ticker,
90
+ resolution: resolution,
91
+ from: from.toString(),
92
+ to: to.toString(),
93
+ currencyCode: "ETH",
94
+ });
95
+ // Add countback if provided
96
+ if (countback) {
97
+ params.append("countback", countback.toString());
98
+ }
99
+ const response = await fetch(`${baseUrl}/history?${params}`);
100
+ if (!response.ok) {
101
+ throw new Error(`HTTP error! status: ${response.status}`);
102
+ }
103
+ const data = await response.json();
104
+ if (data.s === "ok" && data.t && data.t.length > 0) {
105
+ const bars = data.t.map((time, index) => ({
106
+ time: parseInt(time) * 1000, // Convert string to number, then to milliseconds
107
+ open: parseFloat(data.o[index]), // Parse string to number
108
+ high: parseFloat(data.h[index]),
109
+ low: parseFloat(data.l[index]),
110
+ close: parseFloat(data.c[index]),
111
+ volume: data.v ? parseFloat(data.v[index]) : 0, // Parse volume string to number
112
+ }));
113
+ onHistoryCallback(bars, { noData: false });
114
+ }
115
+ else {
116
+ onHistoryCallback([], { noData: true });
117
+ }
118
+ }
119
+ catch (error) {
120
+ console.error("Error fetching bars:", error);
121
+ onHistoryCallback([], { noData: true });
122
+ }
123
+ },
124
+ subscribeBars: () => { },
125
+ unsubscribeBars: () => { },
126
+ };
127
+ };
128
+ const datafeed = createUDFDatafeed("https://b3-udf-worker.sean-430.workers.dev/bondkit/udf");
129
+ // Calculate timeframe for last 2 days
130
+ const currentTime = Math.floor(Date.now() / 1000);
131
+ const twoDaysAgo = currentTime - 2 * 24 * 60 * 60; // 2 days in seconds
132
+ const widgetOptions = {
133
+ timeframe: { from: twoDaysAgo, to: currentTime }, // Show last 2 days
134
+ symbol: currentTrade?.product_id || "BONDKIT",
135
+ datafeed: datafeed,
136
+ interval: tradingViewDefaultInterval,
137
+ container: chartContainerRef.current,
138
+ library_path: "https://cdn.b3.fun/static/charting_library/",
139
+ locale: "en",
140
+ disabled_features: [
141
+ "use_localstorage_for_settings",
142
+ "header_symbol_search",
143
+ "save_chart_properties_to_local_storage",
144
+ "header_compare",
145
+ "vert_touch_drag_scroll",
146
+ ],
147
+ enabled_features: ["study_templates", "hide_left_toolbar_by_default"],
148
+ charts_storage_url: "https://saveload.tradingview.com",
149
+ charts_storage_api_version: "1.1",
150
+ client_id: "tradingview.com",
151
+ user_id: "public_user_id",
152
+ fullscreen: false,
153
+ autosize: true,
154
+ timezone: (tradingViewTimezone || getTimezone()),
155
+ debug: true,
156
+ // Configure time frame buttons in the bottom left
157
+ time_frames: [
158
+ {
159
+ text: "5m",
160
+ resolution: "5",
161
+ description: "5 days in 5 minute intervals",
162
+ title: "5m",
163
+ },
164
+ {
165
+ text: "1h",
166
+ resolution: "60",
167
+ description: "1 week in 1 hour intervals",
168
+ title: "1h",
169
+ },
170
+ {
171
+ text: "1d",
172
+ resolution: "1D",
173
+ description: "1 month in 1 day intervals",
174
+ title: "1d",
175
+ },
176
+ {
177
+ text: "1w",
178
+ resolution: "1W",
179
+ description: "6 months in 1 week intervals",
180
+ title: "1w",
181
+ },
182
+ ],
183
+ overrides: {
184
+ "paneProperties.background": "#FFFFFF",
185
+ "paneProperties.backgroundType": "solid",
186
+ "mainSeriesProperties.candleStyle.upColor": "#4AD50D",
187
+ "mainSeriesProperties.candleStyle.borderUpColor": "#4AD50D",
188
+ "mainSeriesProperties.candleStyle.downColor": "#F04438",
189
+ "mainSeriesProperties.candleStyle.borderDownColor": "#F04438",
190
+ "scalesProperties.fontSize": 10,
191
+ },
192
+ studies_overrides: {
193
+ "volume.volume.color.0": "#80231C",
194
+ "volume.volume.color.1": "#215611",
195
+ },
196
+ loading_screen: {
197
+ backgroundColor: "transparent",
198
+ },
199
+ custom_css_url: "/custom-css/tradingview.css",
200
+ custom_font_family: "'Roboto', sans-serif",
201
+ toolbar_bg: "#FFFFFF",
202
+ theme: "light",
203
+ custom_formatters: {
204
+ priceFormatterFactory: () => {
205
+ return {
206
+ format: (price) => {
207
+ if (price < 0.0001) {
208
+ return formatNumberSmall(price, true);
209
+ }
210
+ return price.toFixed(4);
211
+ },
212
+ };
213
+ },
214
+ },
215
+ };
216
+ const tvWidget = new window.TradingView.widget(widgetOptions);
217
+ tvWidgetRef.current = tvWidget;
218
+ tvWidget.onChartReady(() => {
219
+ setShowLoading(false);
220
+ setChartLoaded(true);
221
+ // Subscribe to interval changes
222
+ tvWidget
223
+ .activeChart()
224
+ .onIntervalChanged()
225
+ .subscribe(null, (interval) => {
226
+ isChangingInterval.current = true;
227
+ setTradingViewDefaultInterval(interval);
228
+ // Reset the flag after a short delay
229
+ setTimeout(() => {
230
+ isChangingInterval.current = false;
231
+ }, 300);
232
+ });
233
+ // Subscribe to timezone changes
234
+ tvWidget
235
+ .activeChart()
236
+ .getTimezoneApi()
237
+ .onTimezoneChanged()
238
+ .subscribe(null, (timezone) => {
239
+ setTradingViewTimezone(timezone);
240
+ });
241
+ });
242
+ return () => {
243
+ if (tvWidgetRef.current) {
244
+ tvWidgetRef.current.remove();
245
+ tvWidgetRef.current = null;
246
+ }
247
+ };
248
+ }, [theme, librariesLoaded]);
249
+ useEffect(() => {
250
+ if (chartLoaded &&
251
+ currentTrade?.product_id &&
252
+ tvWidgetRef.current &&
253
+ !isChangingInterval.current // Only check symbol if we're not changing interval
254
+ ) {
255
+ try {
256
+ const currentSymbol = tvWidgetRef.current.symbolInterval()?.symbol;
257
+ const targetSymbol = currentTrade.product_id;
258
+ // Check if symbols are different (handle both normal and contract address formats)
259
+ const isSameSymbol = currentSymbol === targetSymbol ||
260
+ (currentSymbol && targetSymbol && currentSymbol.split("-")[1] === targetSymbol.split("-")[1]); // Compare contract addresses
261
+ if (!isSameSymbol) {
262
+ setShowLoading(true);
263
+ try {
264
+ tvWidgetRef.current?.setSymbol?.(targetSymbol, tradingViewDefaultInterval, () => {
265
+ setShowLoading(false);
266
+ });
267
+ }
268
+ catch (e) {
269
+ console.error("Error setting symbol:", e);
270
+ setShowLoading(false);
271
+ }
272
+ }
273
+ }
274
+ catch (error) {
275
+ console.error("Error checking symbol:", error);
276
+ }
277
+ }
278
+ }, [chartLoaded, currentTrade?.product_id, tradingViewDefaultInterval]);
279
+ return (_jsxs("div", { className: `relative h-[600px] w-full ${className || ""}`, children: [_jsx("div", { className: "h-full w-full", ref: chartContainerRef }), showLoading && !isChangingInterval.current && _jsx(GifLoadingOverlay, {})] }));
280
+ };
281
+ export default TradingView;
282
+ const getTimezone = () => {
283
+ // Simple timezone detection
284
+ try {
285
+ const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
286
+ if (timezone === "Asia/Saigon") {
287
+ return "Asia/Ho_Chi_Minh";
288
+ }
289
+ return timezone;
290
+ }
291
+ catch (e) {
292
+ return "UTC";
293
+ }
294
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * CDN Configuration
3
+ * Configure your CDN URLs here
4
+ */
5
+ export declare const CDN_CONFIG: {
6
+ readonly baseUrl: string;
7
+ readonly chartingLibrary: {
8
+ readonly basePath: "/static/charting_library";
9
+ readonly files: {
10
+ readonly main: "/charting_library.js";
11
+ readonly esm: "/charting_library.esm.js";
12
+ readonly cjs: "/charting_library.cjs.js";
13
+ readonly standalone: "/charting_library.standalone.js";
14
+ readonly types: "/charting_library.d.ts";
15
+ readonly bundles: "/bundles";
16
+ };
17
+ };
18
+ readonly datafeeds: {
19
+ readonly basePath: "/static/datafeeds";
20
+ readonly udf: "/udf/src/udf-compatible-datafeed.js";
21
+ };
22
+ };
23
+ /**
24
+ * Get full CDN URL for a resource
25
+ */
26
+ export declare function getCDNUrl(path: string): string;
27
+ /**
28
+ * Get TradingView library path for widget configuration
29
+ */
30
+ export declare function getTradingViewLibraryPath(): string;
31
+ /**
32
+ * Check if CDN is enabled (useful for development)
33
+ */
34
+ export declare function isCDNEnabled(): boolean;
35
+ /**
36
+ * Check if we're using a custom CDN domain vs the default R2 URL
37
+ */
38
+ export declare function isUsingCustomDomain(): boolean;
39
+ /**
40
+ * Get library path - Always use CDN since static files are removed
41
+ */
42
+ export declare function getLibraryPath(): string;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * CDN Configuration
3
+ * Configure your CDN URLs here
4
+ */
5
+ export const CDN_CONFIG = {
6
+ // Base CDN URL - will use your custom domain or R2 public URL
7
+ baseUrl: process.env.NEXT_PUBLIC_CDN_URL || "https://cdn.b3.fun",
8
+ // TradingView charting library paths
9
+ chartingLibrary: {
10
+ basePath: "/static/charting_library",
11
+ files: {
12
+ main: "/charting_library.js",
13
+ esm: "/charting_library.esm.js",
14
+ cjs: "/charting_library.cjs.js",
15
+ standalone: "/charting_library.standalone.js",
16
+ types: "/charting_library.d.ts",
17
+ bundles: "/bundles",
18
+ },
19
+ },
20
+ // Datafeeds paths
21
+ datafeeds: {
22
+ basePath: "/static/datafeeds",
23
+ udf: "/udf/src/udf-compatible-datafeed.js",
24
+ },
25
+ };
26
+ /**
27
+ * Get full CDN URL for a resource
28
+ */
29
+ export function getCDNUrl(path) {
30
+ return `${CDN_CONFIG.baseUrl}${path}`;
31
+ }
32
+ /**
33
+ * Get TradingView library path for widget configuration
34
+ */
35
+ export function getTradingViewLibraryPath() {
36
+ return getCDNUrl(CDN_CONFIG.chartingLibrary.basePath + "/");
37
+ }
38
+ /**
39
+ * Check if CDN is enabled (useful for development)
40
+ */
41
+ export function isCDNEnabled() {
42
+ return process.env.NODE_ENV === "production" || process.env.NEXT_PUBLIC_FORCE_CDN === "true";
43
+ }
44
+ /**
45
+ * Check if we're using a custom CDN domain vs the default R2 URL
46
+ */
47
+ export function isUsingCustomDomain() {
48
+ return !!process.env.NEXT_PUBLIC_CDN_URL;
49
+ }
50
+ /**
51
+ * Get library path - Always use CDN since static files are removed
52
+ */
53
+ export function getLibraryPath() {
54
+ return getTradingViewLibraryPath();
55
+ }
@@ -0,0 +1,5 @@
1
+ export { default as TradingView } from "./TradingView";
2
+ export type { TradingViewProps } from "./types";
3
+ export * from "./utils/cdn-loader";
4
+ export * from "./utils/format";
5
+ export * from "./config/cdn";
@@ -0,0 +1,4 @@
1
+ export { default as TradingView } from "./TradingView.js";
2
+ export * from "./utils/cdn-loader.js";
3
+ export * from "./utils/format.js";
4
+ export * from "./config/cdn.js";