@b3dotfun/sdk 0.0.25-alpha.0 → 0.0.25-alpha.2

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 (32) hide show
  1. package/dist/cjs/bondkit/abis/BondkitTokenABI.d.ts +301 -73
  2. package/dist/cjs/bondkit/abis/BondkitTokenABI.js +296 -920
  3. package/dist/cjs/bondkit/abis/BondkitTokenFactoryABI.d.ts +253 -19
  4. package/dist/cjs/bondkit/abis/BondkitTokenFactoryABI.js +189 -370
  5. package/dist/cjs/bondkit/bondkitToken.d.ts +7 -4
  6. package/dist/cjs/bondkit/bondkitToken.js +85 -10
  7. package/dist/cjs/bondkit/constants.js +1 -1
  8. package/dist/cjs/bondkit/json_abis/BondkitABI.json +297 -913
  9. package/dist/cjs/bondkit/json_abis/BondkitFactoryABI.json +191 -368
  10. package/dist/cjs/bondkit/types.d.ts +7 -2
  11. package/dist/esm/bondkit/abis/BondkitTokenABI.d.ts +301 -73
  12. package/dist/esm/bondkit/abis/BondkitTokenABI.js +296 -920
  13. package/dist/esm/bondkit/abis/BondkitTokenFactoryABI.d.ts +253 -19
  14. package/dist/esm/bondkit/abis/BondkitTokenFactoryABI.js +189 -370
  15. package/dist/esm/bondkit/bondkitToken.d.ts +7 -4
  16. package/dist/esm/bondkit/bondkitToken.js +86 -11
  17. package/dist/esm/bondkit/constants.js +1 -1
  18. package/dist/esm/bondkit/json_abis/BondkitABI.json +297 -913
  19. package/dist/esm/bondkit/json_abis/BondkitFactoryABI.json +191 -368
  20. package/dist/esm/bondkit/types.d.ts +7 -2
  21. package/dist/types/bondkit/abis/BondkitTokenABI.d.ts +301 -73
  22. package/dist/types/bondkit/abis/BondkitTokenFactoryABI.d.ts +253 -19
  23. package/dist/types/bondkit/bondkitToken.d.ts +7 -4
  24. package/dist/types/bondkit/types.d.ts +7 -2
  25. package/package.json +1 -1
  26. package/src/bondkit/abis/BondkitTokenABI.ts +296 -920
  27. package/src/bondkit/abis/BondkitTokenFactoryABI.ts +189 -370
  28. package/src/bondkit/bondkitToken.ts +102 -14
  29. package/src/bondkit/constants.ts +1 -1
  30. package/src/bondkit/json_abis/BondkitABI.json +297 -913
  31. package/src/bondkit/json_abis/BondkitFactoryABI.json +191 -368
  32. package/src/bondkit/types.ts +7 -2
@@ -5,21 +5,21 @@ import type {
5
5
  GetContractReturnType,
6
6
  Hex,
7
7
  PublicClient,
8
- WalletClient,
9
8
  Transport,
9
+ WalletClient,
10
10
  } from "viem";
11
- import { createPublicClient, createWalletClient, custom, getContract, http, parseEther } from "viem";
11
+ import { createPublicClient, createWalletClient, custom, erc20Abi, getContract, http, parseEther } from "viem";
12
12
  import { privateKeyToAccount } from "viem/accounts";
13
+ import { base } from "viem/chains";
13
14
  import { BondkitTokenABI } from "./abis";
14
15
  import { getConfig } from "./config";
15
16
  import type {
16
- TokenDetails,
17
- TokenStatus,
18
17
  BondkitTokenInitializationConfig,
19
18
  GetTransactionHistoryOptions,
19
+ TokenDetails,
20
+ TokenStatus,
20
21
  TransactionResponse,
21
22
  } from "./types";
22
- import { base } from "viem/chains";
23
23
 
24
24
  // Event ABI snippets for decoding
25
25
  const boughtEventAbi = BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveBuy");
@@ -48,6 +48,7 @@ export class BondkitToken {
48
48
  private apiEndpoint: string;
49
49
  private walletClientInstance: WalletClient;
50
50
  private connectedProvider?: EIP1193Provider;
51
+ private tradingToken?: Address;
51
52
 
52
53
  constructor(contractAddress: string, walletKey?: string) {
53
54
  const sdkConfig = getConfig(base.id);
@@ -82,6 +83,10 @@ export class BondkitToken {
82
83
  abi: BondkitTokenABI,
83
84
  client: this.walletClientInstance,
84
85
  });
86
+
87
+ this.contract.read.tradingToken().then(tradingToken => {
88
+ this.tradingToken = tradingToken as Address;
89
+ });
85
90
  }
86
91
 
87
92
  public connect(provider?: EIP1193Provider): boolean {
@@ -216,6 +221,44 @@ export class BondkitToken {
216
221
  }
217
222
  }
218
223
 
224
+ public async getTradingTokenBalanceOf(account: Address): Promise<bigint | undefined> {
225
+ try {
226
+ if (!this.tradingToken) {
227
+ console.warn("Trading token address not available");
228
+ return undefined;
229
+ }
230
+
231
+ // If trading token is ETH (zero address), get ETH balance
232
+ if (this.tradingToken === "0x0000000000000000000000000000000000000000") {
233
+ return await this.publicClient.getBalance({ address: account });
234
+ }
235
+
236
+ // For ERC20 trading tokens, get token balance
237
+ const tradingTokenContract = getContract({
238
+ address: this.tradingToken as Address,
239
+ abi: erc20Abi,
240
+ client: this.publicClient, // Use public client for read operations
241
+ });
242
+
243
+ return await tradingTokenContract.read.balanceOf([account]);
244
+ } catch (error) {
245
+ console.warn(`Error fetching trading token balance for ${account}:`, error);
246
+ return undefined;
247
+ }
248
+ }
249
+
250
+ public async getTradingTokenAddress(): Promise<Address | undefined> {
251
+ try {
252
+ if (!this.tradingToken) {
253
+ this.tradingToken = (await this.contract.read.tradingToken()) as Address;
254
+ }
255
+ return this.tradingToken;
256
+ } catch (error) {
257
+ console.warn("Error fetching trading token address:", error);
258
+ return undefined;
259
+ }
260
+ }
261
+
219
262
  public async allowance(owner: Address, spender: Address): Promise<bigint | undefined> {
220
263
  try {
221
264
  return await this.contract.read.allowance([owner, spender]);
@@ -299,11 +342,11 @@ export class BondkitToken {
299
342
  }
300
343
  }
301
344
 
302
- public async getAmountOfEthToSell(tokenAmount: bigint): Promise<bigint | undefined> {
345
+ public async getAmountOfTradingTokensToSell(amount: bigint): Promise<bigint | undefined> {
303
346
  try {
304
- return await this.contract.read.getAmountOfEthToSell([tokenAmount]);
347
+ return await this.contract.read.getAmountOfTradingTokensToSell([amount]);
305
348
  } catch (e) {
306
- console.warn("Error in getAmountOfEthToSell:", e);
349
+ console.warn("Error in getAmountOfTradingTokensToSell:", e);
307
350
  return undefined;
308
351
  }
309
352
  }
@@ -317,11 +360,11 @@ export class BondkitToken {
317
360
  }
318
361
  }
319
362
 
320
- public async totalEthRaisedBonding(): Promise<bigint | undefined> {
363
+ public async totalRaisedBonding(): Promise<bigint | undefined> {
321
364
  try {
322
- return await this.contract.read.totalEthRaisedBonding();
365
+ return await this.contract.read.totalRaisedBonding();
323
366
  } catch (e) {
324
- console.warn("Error fetching totalEthRaisedBonding:", e);
367
+ console.warn("Error fetching totalRaisedBonding:", e);
325
368
  return undefined;
326
369
  }
327
370
  }
@@ -505,13 +548,58 @@ export class BondkitToken {
505
548
 
506
549
  /** Buy tokens with ETH. Payable function. */
507
550
  public async buy(
551
+ amount: bigint | string,
508
552
  minTokensOut: bigint,
509
- ethAmount: bigint | string,
510
553
  options?: ExecuteWriteOptions,
511
554
  ): Promise<Hex | undefined> {
512
555
  if (!boughtEventAbi) console.warn("Bought event ABI not found for event decoding.");
513
- const value = typeof ethAmount === "string" ? parseEther(ethAmount) : ethAmount;
514
- return this.executeWrite("buy", [minTokensOut], { ...options, value });
556
+
557
+ if (this.tradingToken === "0x0000000000000000000000000000000000000000") {
558
+ const value = typeof amount === "string" ? parseEther(amount) : amount;
559
+ return this.executeWrite("buy", [minTokensOut], { ...options, value });
560
+ } else {
561
+ // For ERC20 trading tokens, we need to approve first, then call buy
562
+ const tradingTokenContract = getContract({
563
+ address: this.tradingToken as Address,
564
+ abi: erc20Abi,
565
+ client: this.walletClientInstance,
566
+ });
567
+
568
+ const currentAllowance = await tradingTokenContract.read.allowance([
569
+ this.walletClientInstance.account?.address as Address,
570
+ this.contractAddress as Address,
571
+ ]);
572
+
573
+ const amountBigInt = typeof amount === "string" ? parseEther(amount) : BigInt(amount);
574
+
575
+ if (currentAllowance < amountBigInt) {
576
+ // Get account for the approve transaction
577
+ const accountToUse = this.walletKey ? privateKeyToAccount(this.walletKey) : this.walletClientInstance.account;
578
+ if (!accountToUse) throw new Error("Account for transaction could not be determined.");
579
+
580
+ // Create approve options with required fields but without value (ERC20 approve doesn't need ETH)
581
+ const approveOptions: any = {
582
+ account: accountToUse,
583
+ chain: this.chain,
584
+ };
585
+
586
+ // Add optional transaction parameters if provided
587
+ if (options?.gas !== undefined) approveOptions.gas = options.gas;
588
+ if (options?.maxFeePerGas !== undefined) approveOptions.maxFeePerGas = options.maxFeePerGas;
589
+ if (options?.maxPriorityFeePerGas !== undefined)
590
+ approveOptions.maxPriorityFeePerGas = options.maxPriorityFeePerGas;
591
+
592
+ const approveTx = await tradingTokenContract.write.approve(
593
+ [this.contractAddress as Address, amountBigInt],
594
+ approveOptions,
595
+ );
596
+
597
+ await this.publicClient.waitForTransactionReceipt({ hash: approveTx });
598
+ }
599
+
600
+ // Now call the buy function with the trading token amount
601
+ return this.executeWrite("buy", [amountBigInt, minTokensOut], options);
602
+ }
515
603
  }
516
604
 
517
605
  /** Sell tokens for ETH. */
@@ -1,5 +1,5 @@
1
1
  import type { Address } from "viem";
2
2
 
3
- export const BaseBondkitTokenFactoryContractAddress: Address = "0x2d9876CCee96771F91D53e0bc4F7f4044d3bE345";
3
+ export const BaseBondkitTokenFactoryContractAddress: Address = "0x0ccA36e9BE8Fdf456dE4BC20b378B1560Aeb6653";
4
4
 
5
5
  export const BaseMainnetRpcUrl = "https://base-rpc.publicnode.com";