@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
@@ -1,6 +1,6 @@
1
1
  import type { Address, EIP1193Provider, GetContractReturnType, Hex, PublicClient, WalletClient } from "viem";
2
2
  import { BondkitTokenABI } from "./abis";
3
- import type { TokenDetails, TokenStatus, BondkitTokenInitializationConfig, GetTransactionHistoryOptions, TransactionResponse } from "./types";
3
+ import type { BondkitTokenInitializationConfig, GetTransactionHistoryOptions, TokenDetails, TokenStatus, TransactionResponse } from "./types";
4
4
  type ExecuteWriteOptions = {
5
5
  value?: bigint;
6
6
  gas?: bigint;
@@ -17,6 +17,7 @@ export declare class BondkitToken {
17
17
  private apiEndpoint;
18
18
  private walletClientInstance;
19
19
  private connectedProvider?;
20
+ private tradingToken?;
20
21
  constructor(contractAddress: string, walletKey?: string);
21
22
  connect(provider?: EIP1193Provider): boolean;
22
23
  /**
@@ -30,6 +31,8 @@ export declare class BondkitToken {
30
31
  decimals(): Promise<number | undefined>;
31
32
  totalSupply(): Promise<bigint | undefined>;
32
33
  balanceOf(account: Address): Promise<bigint | undefined>;
34
+ getTradingTokenBalanceOf(account: Address): Promise<bigint | undefined>;
35
+ getTradingTokenAddress(): Promise<Address | undefined>;
33
36
  allowance(owner: Address, spender: Address): Promise<bigint | undefined>;
34
37
  owner(): Promise<Address | undefined>;
35
38
  getTokenDetails(): Promise<TokenDetails | undefined>;
@@ -37,9 +40,9 @@ export declare class BondkitToken {
37
40
  currentStatus(): Promise<TokenStatus | undefined>;
38
41
  getCurrentPhase(): Promise<string | undefined>;
39
42
  getAmountOfTokensToBuy(ethAmount: bigint | string): Promise<bigint | undefined>;
40
- getAmountOfEthToSell(tokenAmount: bigint): Promise<bigint | undefined>;
43
+ getAmountOfTradingTokensToSell(amount: bigint): Promise<bigint | undefined>;
41
44
  getCurrentBondingCurvePricePerToken(): Promise<bigint | undefined>;
42
- totalEthRaisedBonding(): Promise<bigint | undefined>;
45
+ totalRaisedBonding(): Promise<bigint | undefined>;
43
46
  getTotalSupply(): Promise<bigint | undefined>;
44
47
  getPaginatedHolders(startIndex: bigint, count?: bigint): Promise<{
45
48
  address: Address;
@@ -57,7 +60,7 @@ export declare class BondkitToken {
57
60
  approve(spender: Address, amount: bigint, options?: ExecuteWriteOptions): Promise<Hex | undefined>;
58
61
  transferFrom(from: Address, to: Address, amount: bigint, options?: ExecuteWriteOptions): Promise<Hex | undefined>;
59
62
  /** Buy tokens with ETH. Payable function. */
60
- buy(minTokensOut: bigint, ethAmount: bigint | string, options?: ExecuteWriteOptions): Promise<Hex | undefined>;
63
+ buy(amount: bigint | string, minTokensOut: bigint, options?: ExecuteWriteOptions): Promise<Hex | undefined>;
61
64
  /** Sell tokens for ETH. */
62
65
  sell(tokenAmount: bigint, minEthOut: bigint, options?: ExecuteWriteOptions): Promise<Hex | undefined>;
63
66
  /** Migrate liquidity to DEX. Only callable by owner/migrationAdmin based on typical patterns. */
@@ -1,8 +1,8 @@
1
- import { createPublicClient, createWalletClient, custom, getContract, http, parseEther } from "viem";
1
+ import { createPublicClient, createWalletClient, custom, erc20Abi, getContract, http, parseEther } from "viem";
2
2
  import { privateKeyToAccount } from "viem/accounts";
3
+ import { base } from "viem/chains";
3
4
  import { BondkitTokenABI } from "./abis/index.js";
4
5
  import { getConfig } from "./config.js";
5
- import { base } from "viem/chains";
6
6
  // Event ABI snippets for decoding
7
7
  const boughtEventAbi = BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveBuy");
8
8
  const soldEventAbi = BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveSell");
@@ -37,6 +37,9 @@ export class BondkitToken {
37
37
  abi: BondkitTokenABI,
38
38
  client: this.walletClientInstance,
39
39
  });
40
+ this.contract.read.tradingToken().then(tradingToken => {
41
+ this.tradingToken = tradingToken;
42
+ });
40
43
  }
41
44
  connect(provider) {
42
45
  try {
@@ -163,6 +166,41 @@ export class BondkitToken {
163
166
  return undefined;
164
167
  }
165
168
  }
169
+ async getTradingTokenBalanceOf(account) {
170
+ try {
171
+ if (!this.tradingToken) {
172
+ console.warn("Trading token address not available");
173
+ return undefined;
174
+ }
175
+ // If trading token is ETH (zero address), get ETH balance
176
+ if (this.tradingToken === "0x0000000000000000000000000000000000000000") {
177
+ return await this.publicClient.getBalance({ address: account });
178
+ }
179
+ // For ERC20 trading tokens, get token balance
180
+ const tradingTokenContract = getContract({
181
+ address: this.tradingToken,
182
+ abi: erc20Abi,
183
+ client: this.publicClient, // Use public client for read operations
184
+ });
185
+ return await tradingTokenContract.read.balanceOf([account]);
186
+ }
187
+ catch (error) {
188
+ console.warn(`Error fetching trading token balance for ${account}:`, error);
189
+ return undefined;
190
+ }
191
+ }
192
+ async getTradingTokenAddress() {
193
+ try {
194
+ if (!this.tradingToken) {
195
+ this.tradingToken = (await this.contract.read.tradingToken());
196
+ }
197
+ return this.tradingToken;
198
+ }
199
+ catch (error) {
200
+ console.warn("Error fetching trading token address:", error);
201
+ return undefined;
202
+ }
203
+ }
166
204
  async allowance(owner, spender) {
167
205
  try {
168
206
  return await this.contract.read.allowance([owner, spender]);
@@ -246,12 +284,12 @@ export class BondkitToken {
246
284
  return undefined;
247
285
  }
248
286
  }
249
- async getAmountOfEthToSell(tokenAmount) {
287
+ async getAmountOfTradingTokensToSell(amount) {
250
288
  try {
251
- return await this.contract.read.getAmountOfEthToSell([tokenAmount]);
289
+ return await this.contract.read.getAmountOfTradingTokensToSell([amount]);
252
290
  }
253
291
  catch (e) {
254
- console.warn("Error in getAmountOfEthToSell:", e);
292
+ console.warn("Error in getAmountOfTradingTokensToSell:", e);
255
293
  return undefined;
256
294
  }
257
295
  }
@@ -264,12 +302,12 @@ export class BondkitToken {
264
302
  return undefined;
265
303
  }
266
304
  }
267
- async totalEthRaisedBonding() {
305
+ async totalRaisedBonding() {
268
306
  try {
269
- return await this.contract.read.totalEthRaisedBonding();
307
+ return await this.contract.read.totalRaisedBonding();
270
308
  }
271
309
  catch (e) {
272
- console.warn("Error fetching totalEthRaisedBonding:", e);
310
+ console.warn("Error fetching totalRaisedBonding:", e);
273
311
  return undefined;
274
312
  }
275
313
  }
@@ -425,11 +463,48 @@ export class BondkitToken {
425
463
  return this.executeWrite("transferFrom", [from, to, amount], options);
426
464
  }
427
465
  /** Buy tokens with ETH. Payable function. */
428
- async buy(minTokensOut, ethAmount, options) {
466
+ async buy(amount, minTokensOut, options) {
429
467
  if (!boughtEventAbi)
430
468
  console.warn("Bought event ABI not found for event decoding.");
431
- const value = typeof ethAmount === "string" ? parseEther(ethAmount) : ethAmount;
432
- return this.executeWrite("buy", [minTokensOut], { ...options, value });
469
+ if (this.tradingToken === "0x0000000000000000000000000000000000000000") {
470
+ const value = typeof amount === "string" ? parseEther(amount) : amount;
471
+ return this.executeWrite("buy", [minTokensOut], { ...options, value });
472
+ }
473
+ else {
474
+ // For ERC20 trading tokens, we need to approve first, then call buy
475
+ const tradingTokenContract = getContract({
476
+ address: this.tradingToken,
477
+ abi: erc20Abi,
478
+ client: this.walletClientInstance,
479
+ });
480
+ const currentAllowance = await tradingTokenContract.read.allowance([
481
+ this.walletClientInstance.account?.address,
482
+ this.contractAddress,
483
+ ]);
484
+ const amountBigInt = typeof amount === "string" ? parseEther(amount) : BigInt(amount);
485
+ if (currentAllowance < amountBigInt) {
486
+ // Get account for the approve transaction
487
+ const accountToUse = this.walletKey ? privateKeyToAccount(this.walletKey) : this.walletClientInstance.account;
488
+ if (!accountToUse)
489
+ throw new Error("Account for transaction could not be determined.");
490
+ // Create approve options with required fields but without value (ERC20 approve doesn't need ETH)
491
+ const approveOptions = {
492
+ account: accountToUse,
493
+ chain: this.chain,
494
+ };
495
+ // Add optional transaction parameters if provided
496
+ if (options?.gas !== undefined)
497
+ approveOptions.gas = options.gas;
498
+ if (options?.maxFeePerGas !== undefined)
499
+ approveOptions.maxFeePerGas = options.maxFeePerGas;
500
+ if (options?.maxPriorityFeePerGas !== undefined)
501
+ approveOptions.maxPriorityFeePerGas = options.maxPriorityFeePerGas;
502
+ const approveTx = await tradingTokenContract.write.approve([this.contractAddress, amountBigInt], approveOptions);
503
+ await this.publicClient.waitForTransactionReceipt({ hash: approveTx });
504
+ }
505
+ // Now call the buy function with the trading token amount
506
+ return this.executeWrite("buy", [amountBigInt, minTokensOut], options);
507
+ }
433
508
  }
434
509
  /** Sell tokens for ETH. */
435
510
  async sell(tokenAmount, minEthOut, options) {
@@ -1,2 +1,2 @@
1
- export const BaseBondkitTokenFactoryContractAddress = "0x2d9876CCee96771F91D53e0bc4F7f4044d3bE345";
1
+ export const BaseBondkitTokenFactoryContractAddress = "0x0ccA36e9BE8Fdf456dE4BC20b378B1560Aeb6653";
2
2
  export const BaseMainnetRpcUrl = "https://base-rpc.publicnode.com";