@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.
- package/dist/cjs/anyspend/react/components/AnySpend.js +5 -8
- package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +35 -28
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -4
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +35 -28
- package/dist/cjs/anyspend/react/components/common/Accordion.d.ts +7 -0
- package/dist/cjs/anyspend/react/components/common/Accordion.js +53 -0
- package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.js +3 -22
- package/dist/cjs/anyspend/react/components/common/FiatPaymentMethod.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +76 -83
- package/dist/cjs/anyspend/react/components/common/OrderStatus.js +1 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +4 -3
- package/dist/cjs/anyspend/react/components/common/PanelOnrampPayment.js +1 -5
- package/dist/cjs/anyspend/react/components/common/StepProgress.js +2 -2
- package/dist/cjs/anyspend/react/components/common/TokenBalance.js +1 -1
- package/dist/cjs/anyspend/react/hooks/useGeoOnrampOptions.d.ts +0 -1
- package/dist/cjs/anyspend/react/hooks/useGeoOnrampOptions.js +2 -4
- package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +2 -2
- package/dist/cjs/anyspend/react/hooks/useStripeSupport.d.ts +0 -1
- package/dist/cjs/anyspend/react/hooks/useStripeSupport.js +0 -1
- package/dist/cjs/anyspend/utils/chain.js +1 -1
- package/dist/cjs/bondkit/abis/BondkitTokenABI.d.ts +1020 -0
- package/dist/cjs/bondkit/abis/BondkitTokenABI.js +1332 -0
- package/dist/cjs/bondkit/abis/BondkitTokenFactoryABI.d.ts +391 -0
- package/dist/cjs/bondkit/abis/BondkitTokenFactoryABI.js +514 -0
- package/dist/cjs/bondkit/abis/index.d.ts +2 -0
- package/dist/cjs/bondkit/abis/index.js +18 -0
- package/dist/cjs/bondkit/bondkitToken.d.ts +68 -0
- package/dist/cjs/bondkit/bondkitToken.js +456 -0
- package/dist/cjs/bondkit/bondkitTokenFactory.d.ts +60 -0
- package/dist/cjs/bondkit/bondkitTokenFactory.js +274 -0
- package/dist/cjs/bondkit/components/TradingView.d.ts +3 -0
- package/dist/cjs/bondkit/components/TradingView.js +296 -0
- package/dist/cjs/bondkit/components/config/cdn.d.ts +42 -0
- package/dist/cjs/bondkit/components/config/cdn.js +63 -0
- package/dist/cjs/bondkit/components/index.d.ts +5 -0
- package/dist/cjs/bondkit/components/index.js +25 -0
- package/dist/cjs/bondkit/components/types.d.ts +8 -0
- package/dist/cjs/bondkit/components/types.js +5 -0
- package/dist/cjs/bondkit/components/utils/cdn-loader.d.ts +24 -0
- package/dist/cjs/bondkit/components/utils/cdn-loader.js +73 -0
- package/dist/cjs/bondkit/components/utils/format.d.ts +4 -0
- package/dist/cjs/bondkit/components/utils/format.js +31 -0
- package/dist/cjs/bondkit/config.d.ts +10 -0
- package/dist/cjs/bondkit/config.js +18 -0
- package/dist/cjs/bondkit/constants.d.ts +3 -0
- package/dist/cjs/bondkit/constants.js +5 -0
- package/dist/cjs/bondkit/index.d.ts +7 -0
- package/dist/cjs/bondkit/index.js +33 -0
- package/dist/cjs/bondkit/json_abis/BondkitABI.json +1329 -0
- package/dist/cjs/bondkit/json_abis/BondkitFactoryABI.json +511 -0
- package/dist/cjs/bondkit/json_abis/index.d.ts +3 -0
- package/dist/cjs/bondkit/json_abis/index.js +10 -0
- package/dist/cjs/bondkit/json_abis/index.ts +4 -0
- package/dist/cjs/bondkit/types.d.ts +77 -0
- package/dist/cjs/bondkit/types.js +11 -0
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/cjs/global-account/react/components/MintButton/MintButton.js +0 -1
- package/dist/cjs/global-account/react/components/SendERC20Button/SendERC20Button.d.ts +13 -0
- package/dist/cjs/global-account/react/components/SendERC20Button/SendERC20Button.js +33 -0
- package/dist/cjs/global-account/react/components/SendETHButton/SendETHButton.d.ts +12 -0
- package/dist/cjs/global-account/react/components/SendETHButton/SendETHButton.js +23 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +4 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +2 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -2
- package/dist/cjs/global-account/react/components/index.d.ts +2 -0
- package/dist/cjs/global-account/react/components/index.js +8 -2
- package/dist/cjs/global-account/react/components/ui/scroll-area.js +1 -1
- package/dist/cjs/global-account/react/components/ui/tooltip.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/index.d.ts +2 -1
- package/dist/cjs/global-account/react/hooks/index.js +18 -3
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +8 -0
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +4 -4
- package/dist/cjs/global-account/react/hooks/useChainSwitchWithAction.d.ts +1 -2
- package/dist/cjs/global-account/react/hooks/useChainSwitchWithAction.js +2 -2
- package/dist/cjs/global-account/react/hooks/useFirstEOA.js +9 -7
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.d.ts +11 -0
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +160 -0
- package/dist/cjs/shared/constants/chains/supported.d.ts +4 -0
- package/dist/cjs/shared/constants/chains/supported.js +11 -0
- package/dist/cjs/shared/generated/chain-networks.json +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +5 -8
- package/dist/esm/anyspend/react/components/AnySpendBondKit.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +37 -30
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +4 -4
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +37 -30
- package/dist/esm/anyspend/react/components/common/Accordion.d.ts +7 -0
- package/dist/esm/anyspend/react/components/common/Accordion.js +14 -0
- package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.js +3 -22
- package/dist/esm/anyspend/react/components/common/FiatPaymentMethod.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +79 -86
- package/dist/esm/anyspend/react/components/common/OrderStatus.js +1 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +5 -4
- package/dist/esm/anyspend/react/components/common/PanelOnrampPayment.js +1 -5
- package/dist/esm/anyspend/react/components/common/StepProgress.js +2 -2
- package/dist/esm/anyspend/react/components/common/TokenBalance.js +1 -1
- package/dist/esm/anyspend/react/hooks/useGeoOnrampOptions.d.ts +0 -1
- package/dist/esm/anyspend/react/hooks/useGeoOnrampOptions.js +2 -4
- package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +2 -2
- package/dist/esm/anyspend/react/hooks/useStripeSupport.d.ts +0 -1
- package/dist/esm/anyspend/react/hooks/useStripeSupport.js +0 -1
- package/dist/esm/anyspend/utils/chain.js +1 -1
- package/dist/esm/bondkit/abis/BondkitTokenABI.d.ts +1020 -0
- package/dist/esm/bondkit/abis/BondkitTokenABI.js +1329 -0
- package/dist/esm/bondkit/abis/BondkitTokenFactoryABI.d.ts +391 -0
- package/dist/esm/bondkit/abis/BondkitTokenFactoryABI.js +511 -0
- package/dist/esm/bondkit/abis/index.d.ts +2 -0
- package/dist/esm/bondkit/abis/index.js +2 -0
- package/dist/esm/bondkit/bondkitToken.d.ts +68 -0
- package/dist/esm/bondkit/bondkitToken.js +452 -0
- package/dist/esm/bondkit/bondkitTokenFactory.d.ts +60 -0
- package/dist/esm/bondkit/bondkitTokenFactory.js +270 -0
- package/dist/esm/bondkit/components/TradingView.d.ts +3 -0
- package/dist/esm/bondkit/components/TradingView.js +294 -0
- package/dist/esm/bondkit/components/config/cdn.d.ts +42 -0
- package/dist/esm/bondkit/components/config/cdn.js +55 -0
- package/dist/esm/bondkit/components/index.d.ts +5 -0
- package/dist/esm/bondkit/components/index.js +4 -0
- package/dist/esm/bondkit/components/types.d.ts +8 -0
- package/dist/esm/bondkit/components/types.js +4 -0
- package/dist/esm/bondkit/components/utils/cdn-loader.d.ts +24 -0
- package/dist/esm/bondkit/components/utils/cdn-loader.js +66 -0
- package/dist/esm/bondkit/components/utils/format.d.ts +4 -0
- package/dist/esm/bondkit/components/utils/format.js +28 -0
- package/dist/esm/bondkit/config.d.ts +10 -0
- package/dist/esm/bondkit/config.js +14 -0
- package/dist/esm/bondkit/constants.d.ts +3 -0
- package/dist/esm/bondkit/constants.js +2 -0
- package/dist/esm/bondkit/index.d.ts +7 -0
- package/dist/esm/bondkit/index.js +12 -0
- package/dist/esm/bondkit/json_abis/BondkitABI.json +1329 -0
- package/dist/esm/bondkit/json_abis/BondkitFactoryABI.json +511 -0
- package/dist/esm/bondkit/json_abis/index.d.ts +3 -0
- package/dist/esm/bondkit/json_abis/index.js +3 -0
- package/dist/esm/bondkit/json_abis/index.ts +4 -0
- package/dist/esm/bondkit/types.d.ts +77 -0
- package/dist/esm/bondkit/types.js +8 -0
- package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/esm/global-account/react/components/MintButton/MintButton.js +0 -1
- package/dist/esm/global-account/react/components/SendERC20Button/SendERC20Button.d.ts +13 -0
- package/dist/esm/global-account/react/components/SendERC20Button/SendERC20Button.js +30 -0
- package/dist/esm/global-account/react/components/SendETHButton/SendETHButton.d.ts +12 -0
- package/dist/esm/global-account/react/components/SendETHButton/SendETHButton.js +20 -0
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +4 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -2
- package/dist/esm/global-account/react/components/index.d.ts +2 -0
- package/dist/esm/global-account/react/components/index.js +4 -0
- package/dist/esm/global-account/react/components/ui/scroll-area.js +1 -1
- package/dist/esm/global-account/react/components/ui/tooltip.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +2 -1
- package/dist/esm/global-account/react/hooks/index.js +2 -1
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +8 -0
- package/dist/esm/global-account/react/hooks/useAuthentication.js +4 -4
- package/dist/esm/global-account/react/hooks/useChainSwitchWithAction.d.ts +1 -2
- package/dist/esm/global-account/react/hooks/useChainSwitchWithAction.js +2 -2
- package/dist/esm/global-account/react/hooks/useFirstEOA.js +9 -7
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.d.ts +11 -0
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +154 -0
- package/dist/esm/shared/constants/chains/supported.d.ts +4 -0
- package/dist/esm/shared/constants/chains/supported.js +10 -0
- package/dist/esm/shared/generated/chain-networks.json +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/common/Accordion.d.ts +7 -0
- package/dist/types/anyspend/react/hooks/useGeoOnrampOptions.d.ts +0 -1
- package/dist/types/anyspend/react/hooks/useSigMint.d.ts +2 -2
- package/dist/types/anyspend/react/hooks/useStripeSupport.d.ts +0 -1
- package/dist/types/bondkit/abis/BondkitTokenABI.d.ts +1020 -0
- package/dist/types/bondkit/abis/BondkitTokenFactoryABI.d.ts +391 -0
- package/dist/types/bondkit/abis/index.d.ts +2 -0
- package/dist/types/bondkit/bondkitToken.d.ts +68 -0
- package/dist/types/bondkit/bondkitTokenFactory.d.ts +60 -0
- package/dist/types/bondkit/components/TradingView.d.ts +3 -0
- package/dist/types/bondkit/components/config/cdn.d.ts +42 -0
- package/dist/types/bondkit/components/index.d.ts +5 -0
- package/dist/types/bondkit/components/types.d.ts +8 -0
- package/dist/types/bondkit/components/utils/cdn-loader.d.ts +24 -0
- package/dist/types/bondkit/components/utils/format.d.ts +4 -0
- package/dist/types/bondkit/config.d.ts +10 -0
- package/dist/types/bondkit/constants.d.ts +3 -0
- package/dist/types/bondkit/index.d.ts +7 -0
- package/dist/types/bondkit/json_abis/index.d.ts +3 -0
- package/dist/types/bondkit/types.d.ts +77 -0
- package/dist/types/global-account/react/components/SendERC20Button/SendERC20Button.d.ts +13 -0
- package/dist/types/global-account/react/components/SendETHButton/SendETHButton.d.ts +12 -0
- package/dist/types/global-account/react/components/index.d.ts +2 -0
- package/dist/types/global-account/react/components/ui/tooltip.d.ts +1 -1
- package/dist/types/global-account/react/hooks/index.d.ts +2 -1
- package/dist/types/global-account/react/hooks/useChainSwitchWithAction.d.ts +1 -2
- package/dist/types/global-account/react/hooks/useUnifiedChainSwitchAndExecute.d.ts +11 -0
- package/dist/types/shared/constants/chains/supported.d.ts +4 -0
- package/package.json +42 -7
- package/src/anyspend/react/components/AnySpend.tsx +5 -23
- package/src/anyspend/react/components/AnySpendBondKit.tsx +2 -2
- package/src/anyspend/react/components/AnySpendBuySpin.tsx +42 -32
- package/src/anyspend/react/components/AnySpendCustom.tsx +7 -13
- package/src/anyspend/react/components/AnySpendStakeB3.tsx +44 -34
- package/src/anyspend/react/components/common/Accordion.tsx +56 -0
- package/src/anyspend/react/components/common/ConnectWalletPayment.tsx +0 -25
- package/src/anyspend/react/components/common/FiatPaymentMethod.tsx +1 -2
- package/src/anyspend/react/components/common/OrderDetails.tsx +292 -260
- package/src/anyspend/react/components/common/OrderStatus.tsx +1 -1
- package/src/anyspend/react/components/common/PanelOnramp.tsx +7 -7
- package/src/anyspend/react/components/common/PanelOnrampPayment.tsx +0 -6
- package/src/anyspend/react/components/common/StepProgress.tsx +2 -2
- package/src/anyspend/react/components/common/TokenBalance.tsx +3 -3
- package/src/anyspend/react/hooks/useGeoOnrampOptions.ts +2 -4
- package/src/anyspend/react/hooks/useStripeSupport.ts +0 -1
- package/src/anyspend/utils/chain.ts +1 -1
- package/src/bondkit/abis/BondkitTokenABI.ts +1329 -0
- package/src/bondkit/abis/BondkitTokenFactoryABI.ts +511 -0
- package/src/bondkit/abis/index.ts +2 -0
- package/src/bondkit/bondkitToken.ts +539 -0
- package/src/bondkit/bondkitTokenFactory.ts +336 -0
- package/src/bondkit/components/TradingView.tsx +341 -0
- package/src/bondkit/components/config/cdn.ts +63 -0
- package/src/bondkit/components/index.ts +5 -0
- package/src/bondkit/components/types.ts +9 -0
- package/src/bondkit/components/utils/cdn-loader.ts +77 -0
- package/src/bondkit/components/utils/format.ts +36 -0
- package/src/bondkit/config.ts +26 -0
- package/src/bondkit/constants.ts +5 -0
- package/src/bondkit/index.ts +16 -0
- package/src/bondkit/json_abis/BondkitABI.json +1329 -0
- package/src/bondkit/json_abis/BondkitFactoryABI.json +511 -0
- package/src/bondkit/json_abis/index.ts +4 -0
- package/src/bondkit/types.ts +98 -0
- package/src/global-account/react/components/B3DynamicModal.tsx +2 -1
- package/src/global-account/react/components/MintButton/MintButton.tsx +0 -1
- package/src/global-account/react/components/SendERC20Button/SendERC20Button.tsx +57 -0
- package/src/global-account/react/components/SendETHButton/SendETHButton.tsx +37 -0
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +21 -22
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
- package/src/global-account/react/components/index.ts +6 -0
- package/src/global-account/react/components/ui/scroll-area.tsx +2 -2
- package/src/global-account/react/components/ui/tooltip.tsx +1 -1
- package/src/global-account/react/hooks/index.ts +2 -1
- package/src/global-account/react/hooks/useAccountWallet.tsx +10 -1
- package/src/global-account/react/hooks/useAuthentication.ts +4 -4
- package/src/global-account/react/hooks/useChainSwitchWithAction.ts +3 -4
- package/src/global-account/react/hooks/useFirstEOA.tsx +10 -7
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +186 -0
- package/src/shared/constants/chains/supported.ts +11 -0
- package/src/shared/generated/chain-networks.json +1 -1
- package/src/styles/index.css +27 -0
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Address,
|
|
3
|
+
Chain,
|
|
4
|
+
EIP1193Provider,
|
|
5
|
+
GetContractReturnType,
|
|
6
|
+
Hex,
|
|
7
|
+
PublicClient,
|
|
8
|
+
WalletClient,
|
|
9
|
+
Transport,
|
|
10
|
+
} from "viem";
|
|
11
|
+
import { createPublicClient, createWalletClient, custom, getContract, http, parseEther } from "viem";
|
|
12
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
13
|
+
import { BondkitTokenABI } from "./abis";
|
|
14
|
+
import { getConfig } from "./config";
|
|
15
|
+
import type {
|
|
16
|
+
TokenDetails,
|
|
17
|
+
TokenStatus,
|
|
18
|
+
BondkitTokenInitializationConfig,
|
|
19
|
+
GetTransactionHistoryOptions,
|
|
20
|
+
TransactionResponse,
|
|
21
|
+
} from "./types";
|
|
22
|
+
import { base } from "viem/chains";
|
|
23
|
+
|
|
24
|
+
// Event ABI snippets for decoding
|
|
25
|
+
const boughtEventAbi = BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveBuy");
|
|
26
|
+
const soldEventAbi = BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveSell");
|
|
27
|
+
const dexMigrationEventAbi = BondkitTokenABI.find(
|
|
28
|
+
item => item.type === "event" && item.name === "BondkitTokenMigrated",
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// Define a type for the options that can be passed to executeWrite
|
|
32
|
+
// This mirrors common properties from viem's WriteContractParameters but makes them optional
|
|
33
|
+
type ExecuteWriteOptions = {
|
|
34
|
+
value?: bigint;
|
|
35
|
+
gas?: bigint;
|
|
36
|
+
maxFeePerGas?: bigint;
|
|
37
|
+
maxPriorityFeePerGas?: bigint;
|
|
38
|
+
// Potentially add nonce or other parameters if needed
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export class BondkitToken {
|
|
42
|
+
public contract: GetContractReturnType<typeof BondkitTokenABI, WalletClient>;
|
|
43
|
+
public publicClient: PublicClient;
|
|
44
|
+
public contractAddress: Hex;
|
|
45
|
+
private chain: Chain;
|
|
46
|
+
private walletKey?: Hex;
|
|
47
|
+
private rpcUrl: string;
|
|
48
|
+
private apiEndpoint: string;
|
|
49
|
+
private walletClientInstance: WalletClient;
|
|
50
|
+
private connectedProvider?: EIP1193Provider;
|
|
51
|
+
|
|
52
|
+
constructor(contractAddress: string, walletKey?: string) {
|
|
53
|
+
const sdkConfig = getConfig(base.id);
|
|
54
|
+
this.chain = sdkConfig.chain;
|
|
55
|
+
this.rpcUrl = sdkConfig.rpcUrl;
|
|
56
|
+
this.apiEndpoint = sdkConfig.apiEndpoint;
|
|
57
|
+
|
|
58
|
+
if (walletKey && !walletKey.startsWith("0x")) {
|
|
59
|
+
this.walletKey = `0x${walletKey}` as Hex;
|
|
60
|
+
} else if (walletKey) {
|
|
61
|
+
this.walletKey = walletKey as Hex;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!contractAddress || !contractAddress.startsWith("0x")) {
|
|
65
|
+
throw new Error("Valid contract address is required for BondkitToken.");
|
|
66
|
+
}
|
|
67
|
+
this.contractAddress = contractAddress as Hex;
|
|
68
|
+
|
|
69
|
+
this.publicClient = createPublicClient({
|
|
70
|
+
chain: this.chain,
|
|
71
|
+
transport: http(this.rpcUrl),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
this.walletClientInstance = createWalletClient({
|
|
75
|
+
chain: this.chain,
|
|
76
|
+
transport: http(this.rpcUrl),
|
|
77
|
+
account: this.walletKey ? privateKeyToAccount(this.walletKey) : undefined,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.contract = getContract({
|
|
81
|
+
address: this.contractAddress,
|
|
82
|
+
abi: BondkitTokenABI,
|
|
83
|
+
client: this.walletClientInstance,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public connect(provider?: EIP1193Provider): boolean {
|
|
88
|
+
try {
|
|
89
|
+
const transport: Transport = provider ? custom(provider) : http(this.rpcUrl);
|
|
90
|
+
|
|
91
|
+
this.connectedProvider = provider;
|
|
92
|
+
|
|
93
|
+
this.walletClientInstance = createWalletClient({
|
|
94
|
+
chain: this.chain,
|
|
95
|
+
transport,
|
|
96
|
+
account: this.walletKey ? privateKeyToAccount(this.walletKey) : undefined,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
this.publicClient = createPublicClient({
|
|
100
|
+
chain: this.chain,
|
|
101
|
+
transport,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
this.contract = getContract({
|
|
105
|
+
address: this.contractAddress,
|
|
106
|
+
abi: BondkitTokenABI,
|
|
107
|
+
client: this.walletClientInstance,
|
|
108
|
+
});
|
|
109
|
+
return true;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error("Connection failed:", error);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Connects using an EIP-1193 provider and requests accounts, selecting the first one.
|
|
118
|
+
* Enables frontend wallet flows without requiring a private key.
|
|
119
|
+
*/
|
|
120
|
+
public async connectWithProvider(provider: EIP1193Provider): Promise<boolean> {
|
|
121
|
+
try {
|
|
122
|
+
const transport: Transport = custom(provider);
|
|
123
|
+
this.connectedProvider = provider;
|
|
124
|
+
|
|
125
|
+
// Try to request accounts (prompt user if needed)
|
|
126
|
+
let addresses: string[] = [];
|
|
127
|
+
try {
|
|
128
|
+
const result = await provider.request({ method: "eth_requestAccounts" });
|
|
129
|
+
if (Array.isArray(result)) addresses = result as string[];
|
|
130
|
+
} catch (requestErr) {
|
|
131
|
+
try {
|
|
132
|
+
const result = await provider.request({ method: "eth_accounts" });
|
|
133
|
+
if (Array.isArray(result)) addresses = result as string[];
|
|
134
|
+
} catch (_) {
|
|
135
|
+
// ignore
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const selectedAccount = (addresses?.[0] ?? undefined) as Address | undefined;
|
|
140
|
+
|
|
141
|
+
this.walletClientInstance = createWalletClient({
|
|
142
|
+
chain: this.chain,
|
|
143
|
+
transport,
|
|
144
|
+
account: selectedAccount,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
this.publicClient = createPublicClient({
|
|
148
|
+
chain: this.chain,
|
|
149
|
+
transport,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
this.contract = getContract({
|
|
153
|
+
address: this.contractAddress,
|
|
154
|
+
abi: BondkitTokenABI,
|
|
155
|
+
client: this.walletClientInstance,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
return true;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error("Connection failed:", error);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private async handleError(error: any, context?: string): Promise<never> {
|
|
166
|
+
const defaultMessage = context ? `Error in ${context}:` : "An error occurred:";
|
|
167
|
+
console.error(defaultMessage, error);
|
|
168
|
+
// TODO: Add more specific error checks based on BondkitTokenABI error types if needed
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// --- Read Methods (ERC20 + Custom) --- //
|
|
173
|
+
public async name(): Promise<string | undefined> {
|
|
174
|
+
try {
|
|
175
|
+
return await this.contract.read.name();
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.warn("Error fetching token name:", error);
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public async symbol(): Promise<string | undefined> {
|
|
183
|
+
try {
|
|
184
|
+
return await this.contract.read.symbol();
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.warn("Error fetching token symbol:", error);
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public async decimals(): Promise<number | undefined> {
|
|
192
|
+
try {
|
|
193
|
+
const dec = await this.contract.read.decimals();
|
|
194
|
+
return Number(dec);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.warn("Error fetching token decimals:", error);
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public async totalSupply(): Promise<bigint | undefined> {
|
|
202
|
+
try {
|
|
203
|
+
return await this.contract.read.totalSupply();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.warn("Error fetching token total supply:", error);
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public async balanceOf(account: Address): Promise<bigint | undefined> {
|
|
211
|
+
try {
|
|
212
|
+
return await this.contract.read.balanceOf([account]);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
console.warn(`Error fetching balance for ${account}:`, error);
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
public async allowance(owner: Address, spender: Address): Promise<bigint | undefined> {
|
|
220
|
+
try {
|
|
221
|
+
return await this.contract.read.allowance([owner, spender]);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
console.warn(`Error fetching allowance for owner ${owner} and spender ${spender}:`, error);
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
public async owner(): Promise<Address | undefined> {
|
|
229
|
+
try {
|
|
230
|
+
return await this.contract.read.owner();
|
|
231
|
+
} catch (error) {
|
|
232
|
+
console.warn("Error fetching token owner or 'owner' function might not exist:", error);
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public async getTokenDetails(): Promise<TokenDetails | undefined> {
|
|
238
|
+
try {
|
|
239
|
+
const [name, symbol, decimals, totalSupply, owner] = await Promise.all([
|
|
240
|
+
this.name(),
|
|
241
|
+
this.symbol(),
|
|
242
|
+
this.decimals(),
|
|
243
|
+
this.totalSupply(),
|
|
244
|
+
this.owner(),
|
|
245
|
+
]);
|
|
246
|
+
if (name === undefined || symbol === undefined || decimals === undefined || totalSupply === undefined) {
|
|
247
|
+
console.warn("Failed to retrieve all essential token details.");
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
name,
|
|
252
|
+
symbol,
|
|
253
|
+
decimals,
|
|
254
|
+
totalSupply,
|
|
255
|
+
owner: owner || "0x0000000000000000000000000000000000000000",
|
|
256
|
+
};
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.warn("Error in getTokenDetails:", error);
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// --- Bondkit Specific Read Methods ---
|
|
264
|
+
public async feeRecipient(): Promise<Address | undefined> {
|
|
265
|
+
try {
|
|
266
|
+
return await this.contract.read.feeRecipient();
|
|
267
|
+
} catch (e) {
|
|
268
|
+
console.warn("Error fetching feeRecipient:", e);
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
public async currentStatus(): Promise<TokenStatus | undefined> {
|
|
274
|
+
try {
|
|
275
|
+
const status = await this.contract.read.currentStatus();
|
|
276
|
+
return status as TokenStatus;
|
|
277
|
+
} catch (e) {
|
|
278
|
+
console.warn("Error fetching currentStatus:", e);
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
public async getCurrentPhase(): Promise<string | undefined> {
|
|
284
|
+
try {
|
|
285
|
+
return await this.contract.read.getCurrentPhase();
|
|
286
|
+
} catch (e) {
|
|
287
|
+
console.warn("Error fetching getCurrentPhase:", e);
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public async getAmountOfTokensToBuy(ethAmount: bigint | string): Promise<bigint | undefined> {
|
|
293
|
+
try {
|
|
294
|
+
const value = typeof ethAmount === "string" ? parseEther(ethAmount) : ethAmount;
|
|
295
|
+
return await this.contract.read.getAmountOfTokensToBuy([value]);
|
|
296
|
+
} catch (e) {
|
|
297
|
+
console.warn("Error in getAmountOfTokensToBuy:", e);
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
public async getAmountOfEthToSell(tokenAmount: bigint): Promise<bigint | undefined> {
|
|
303
|
+
try {
|
|
304
|
+
return await this.contract.read.getAmountOfEthToSell([tokenAmount]);
|
|
305
|
+
} catch (e) {
|
|
306
|
+
console.warn("Error in getAmountOfEthToSell:", e);
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
public async getCurrentBondingCurvePricePerToken(): Promise<bigint | undefined> {
|
|
312
|
+
try {
|
|
313
|
+
return await this.contract.read.getCurrentBondingCurvePricePerToken();
|
|
314
|
+
} catch (e) {
|
|
315
|
+
console.warn("Error fetching current bonding curve price:", e);
|
|
316
|
+
return undefined;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public async totalEthRaisedBonding(): Promise<bigint | undefined> {
|
|
321
|
+
try {
|
|
322
|
+
return await this.contract.read.totalEthRaisedBonding();
|
|
323
|
+
} catch (e) {
|
|
324
|
+
console.warn("Error fetching totalEthRaisedBonding:", e);
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
public async getTotalSupply(): Promise<bigint | undefined> {
|
|
330
|
+
try {
|
|
331
|
+
return await this.contract.read.totalSupply();
|
|
332
|
+
} catch (e) {
|
|
333
|
+
console.warn("Error fetching total supply:", e);
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
public async getPaginatedHolders(
|
|
339
|
+
startIndex: bigint,
|
|
340
|
+
count = BigInt(1000),
|
|
341
|
+
): Promise<{ address: Address; balance: bigint }[]> {
|
|
342
|
+
try {
|
|
343
|
+
const response = await this.contract.read.getPaginatedHolders([startIndex, count]);
|
|
344
|
+
const holders = response[0] as Address[];
|
|
345
|
+
const balances = response[1] as bigint[];
|
|
346
|
+
|
|
347
|
+
return holders.map((holder, index) => ({
|
|
348
|
+
address: holder as Address,
|
|
349
|
+
balance: balances[index] as bigint,
|
|
350
|
+
}));
|
|
351
|
+
} catch (e) {
|
|
352
|
+
console.warn("Error fetching paginated holders:", e);
|
|
353
|
+
return [];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
public async getBondingProgress(): Promise<
|
|
358
|
+
| {
|
|
359
|
+
progress: number;
|
|
360
|
+
raised: number;
|
|
361
|
+
threshold: number;
|
|
362
|
+
}
|
|
363
|
+
| undefined
|
|
364
|
+
> {
|
|
365
|
+
try {
|
|
366
|
+
const [progress, raised, threshold] = await this.contract.read.getBondingProgressPercent();
|
|
367
|
+
return {
|
|
368
|
+
progress: Number(progress) / 100,
|
|
369
|
+
raised: Number(raised),
|
|
370
|
+
threshold: Number(threshold),
|
|
371
|
+
};
|
|
372
|
+
} catch (e) {
|
|
373
|
+
console.warn("Error fetching bonding progress percent:", e);
|
|
374
|
+
return undefined;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// --- Transaction History --- //
|
|
379
|
+
public async getTransactionHistory(options?: GetTransactionHistoryOptions): Promise<TransactionResponse | undefined> {
|
|
380
|
+
try {
|
|
381
|
+
const { userAddress, type, from, to, limit, offset } = options || {};
|
|
382
|
+
const response = await fetch(this.apiEndpoint, {
|
|
383
|
+
method: "POST",
|
|
384
|
+
headers: {
|
|
385
|
+
"Content-Type": "application/json",
|
|
386
|
+
"X-service-method": "getTransactionHistory",
|
|
387
|
+
},
|
|
388
|
+
body: JSON.stringify({
|
|
389
|
+
contractAddress: this.contractAddress,
|
|
390
|
+
chainId: this.chain.id,
|
|
391
|
+
userAddress,
|
|
392
|
+
type,
|
|
393
|
+
from,
|
|
394
|
+
to: to || Date.now(),
|
|
395
|
+
limit: limit || 50,
|
|
396
|
+
offset,
|
|
397
|
+
}),
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
if (!response.ok) {
|
|
401
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const result: TransactionResponse = await response.json();
|
|
405
|
+
return result;
|
|
406
|
+
} catch (e) {
|
|
407
|
+
console.warn("Error fetching transaction history:", e);
|
|
408
|
+
return undefined;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// --- Write Methods --- //
|
|
413
|
+
private async executeWrite(
|
|
414
|
+
functionName: string,
|
|
415
|
+
args: any[],
|
|
416
|
+
options?: ExecuteWriteOptions,
|
|
417
|
+
): Promise<Hex | undefined> {
|
|
418
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
419
|
+
// Try to resolve an account from a connected EIP-1193 provider on-demand
|
|
420
|
+
if (this.connectedProvider) {
|
|
421
|
+
try {
|
|
422
|
+
const addresses = (await this.connectedProvider.request({ method: "eth_accounts" })) as string[];
|
|
423
|
+
const selectedAccount = (addresses?.[0] ?? undefined) as Address | undefined;
|
|
424
|
+
if (selectedAccount) {
|
|
425
|
+
const transport: Transport = custom(this.connectedProvider);
|
|
426
|
+
this.walletClientInstance = createWalletClient({
|
|
427
|
+
chain: this.chain,
|
|
428
|
+
transport,
|
|
429
|
+
account: selectedAccount,
|
|
430
|
+
});
|
|
431
|
+
this.contract = getContract({
|
|
432
|
+
address: this.contractAddress,
|
|
433
|
+
abi: BondkitTokenABI,
|
|
434
|
+
client: this.walletClientInstance,
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
} catch (_) {}
|
|
438
|
+
}
|
|
439
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
440
|
+
throw new Error("Wallet key not set or client not connected for write operation.");
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const accountToUse = this.walletKey ? privateKeyToAccount(this.walletKey) : this.walletClientInstance.account;
|
|
444
|
+
if (!accountToUse) throw new Error("Account for transaction could not be determined.");
|
|
445
|
+
|
|
446
|
+
try {
|
|
447
|
+
let maxFee = options?.maxFeePerGas;
|
|
448
|
+
let priorityFee = options?.maxPriorityFeePerGas;
|
|
449
|
+
|
|
450
|
+
if (maxFee === undefined || priorityFee === undefined) {
|
|
451
|
+
try {
|
|
452
|
+
const feeEstimates = await this.publicClient.estimateFeesPerGas();
|
|
453
|
+
if (maxFee === undefined) {
|
|
454
|
+
maxFee = feeEstimates.maxFeePerGas;
|
|
455
|
+
}
|
|
456
|
+
if (priorityFee === undefined) {
|
|
457
|
+
priorityFee = feeEstimates.maxPriorityFeePerGas;
|
|
458
|
+
}
|
|
459
|
+
} catch (feeError) {
|
|
460
|
+
console.warn("Could not estimate fees, will rely on wallet defaults or provided values:", feeError);
|
|
461
|
+
maxFee = maxFee ?? undefined;
|
|
462
|
+
priorityFee = priorityFee ?? undefined;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const transactionOptions: any = {
|
|
467
|
+
account: accountToUse,
|
|
468
|
+
chain: this.chain,
|
|
469
|
+
};
|
|
470
|
+
if (options?.value !== undefined) transactionOptions.value = options.value;
|
|
471
|
+
if (options?.gas !== undefined) transactionOptions.gas = options.gas;
|
|
472
|
+
if (maxFee !== undefined) transactionOptions.maxFeePerGas = maxFee;
|
|
473
|
+
if (priorityFee !== undefined) transactionOptions.maxPriorityFeePerGas = priorityFee;
|
|
474
|
+
|
|
475
|
+
const hash = await (this.contract.write as any)[functionName](args, transactionOptions);
|
|
476
|
+
return hash;
|
|
477
|
+
} catch (error) {
|
|
478
|
+
return this.handleError(error, functionName);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
public async initialize(
|
|
483
|
+
config: BondkitTokenInitializationConfig,
|
|
484
|
+
options?: ExecuteWriteOptions,
|
|
485
|
+
): Promise<Hex | undefined> {
|
|
486
|
+
return this.executeWrite("initialize", [config], options);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
public async transfer(to: Address, amount: bigint, options?: ExecuteWriteOptions): Promise<Hex | undefined> {
|
|
490
|
+
return this.executeWrite("transfer", [to, amount], options);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
public async approve(spender: Address, amount: bigint, options?: ExecuteWriteOptions): Promise<Hex | undefined> {
|
|
494
|
+
return this.executeWrite("approve", [spender, amount], options);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
public async transferFrom(
|
|
498
|
+
from: Address,
|
|
499
|
+
to: Address,
|
|
500
|
+
amount: bigint,
|
|
501
|
+
options?: ExecuteWriteOptions,
|
|
502
|
+
): Promise<Hex | undefined> {
|
|
503
|
+
return this.executeWrite("transferFrom", [from, to, amount], options);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** Buy tokens with ETH. Payable function. */
|
|
507
|
+
public async buy(
|
|
508
|
+
minTokensOut: bigint,
|
|
509
|
+
ethAmount: bigint | string,
|
|
510
|
+
options?: ExecuteWriteOptions,
|
|
511
|
+
): Promise<Hex | undefined> {
|
|
512
|
+
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 });
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/** Sell tokens for ETH. */
|
|
518
|
+
public async sell(tokenAmount: bigint, minEthOut: bigint, options?: ExecuteWriteOptions): Promise<Hex | undefined> {
|
|
519
|
+
if (!soldEventAbi) console.warn("Sold event ABI not found for event decoding.");
|
|
520
|
+
return this.executeWrite("sell", [tokenAmount, minEthOut], options);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** Migrate liquidity to DEX. Only callable by owner/migrationAdmin based on typical patterns. */
|
|
524
|
+
public async migrateToDex(options?: ExecuteWriteOptions): Promise<Hex | undefined> {
|
|
525
|
+
if (!dexMigrationEventAbi) console.warn("DexMigration event ABI not found for event decoding.");
|
|
526
|
+
return this.executeWrite("migrateToDex", [], options);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
public async transferTokenOwnership(newOwner: Address, options?: ExecuteWriteOptions): Promise<Hex | undefined> {
|
|
530
|
+
return this.executeWrite("transferOwnership", [newOwner], options);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
public async renounceTokenOwnership(options?: ExecuteWriteOptions): Promise<Hex | undefined> {
|
|
534
|
+
return this.executeWrite("renounceOwnership", [], options);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// TODO: Add other specific write methods from BondkitTokenABI.ts
|
|
538
|
+
// e.g., setBondingCurve (if it exists and is external), updateArtistAddress, etc.
|
|
539
|
+
}
|