@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,456 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BondkitToken = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const accounts_1 = require("viem/accounts");
|
|
6
|
+
const abis_1 = require("./abis");
|
|
7
|
+
const config_1 = require("./config");
|
|
8
|
+
const chains_1 = require("viem/chains");
|
|
9
|
+
// Event ABI snippets for decoding
|
|
10
|
+
const boughtEventAbi = abis_1.BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveBuy");
|
|
11
|
+
const soldEventAbi = abis_1.BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveSell");
|
|
12
|
+
const dexMigrationEventAbi = abis_1.BondkitTokenABI.find(item => item.type === "event" && item.name === "BondkitTokenMigrated");
|
|
13
|
+
class BondkitToken {
|
|
14
|
+
constructor(contractAddress, walletKey) {
|
|
15
|
+
const sdkConfig = (0, config_1.getConfig)(chains_1.base.id);
|
|
16
|
+
this.chain = sdkConfig.chain;
|
|
17
|
+
this.rpcUrl = sdkConfig.rpcUrl;
|
|
18
|
+
this.apiEndpoint = sdkConfig.apiEndpoint;
|
|
19
|
+
if (walletKey && !walletKey.startsWith("0x")) {
|
|
20
|
+
this.walletKey = `0x${walletKey}`;
|
|
21
|
+
}
|
|
22
|
+
else if (walletKey) {
|
|
23
|
+
this.walletKey = walletKey;
|
|
24
|
+
}
|
|
25
|
+
if (!contractAddress || !contractAddress.startsWith("0x")) {
|
|
26
|
+
throw new Error("Valid contract address is required for BondkitToken.");
|
|
27
|
+
}
|
|
28
|
+
this.contractAddress = contractAddress;
|
|
29
|
+
this.publicClient = (0, viem_1.createPublicClient)({
|
|
30
|
+
chain: this.chain,
|
|
31
|
+
transport: (0, viem_1.http)(this.rpcUrl),
|
|
32
|
+
});
|
|
33
|
+
this.walletClientInstance = (0, viem_1.createWalletClient)({
|
|
34
|
+
chain: this.chain,
|
|
35
|
+
transport: (0, viem_1.http)(this.rpcUrl),
|
|
36
|
+
account: this.walletKey ? (0, accounts_1.privateKeyToAccount)(this.walletKey) : undefined,
|
|
37
|
+
});
|
|
38
|
+
this.contract = (0, viem_1.getContract)({
|
|
39
|
+
address: this.contractAddress,
|
|
40
|
+
abi: abis_1.BondkitTokenABI,
|
|
41
|
+
client: this.walletClientInstance,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
connect(provider) {
|
|
45
|
+
try {
|
|
46
|
+
const transport = provider ? (0, viem_1.custom)(provider) : (0, viem_1.http)(this.rpcUrl);
|
|
47
|
+
this.connectedProvider = provider;
|
|
48
|
+
this.walletClientInstance = (0, viem_1.createWalletClient)({
|
|
49
|
+
chain: this.chain,
|
|
50
|
+
transport,
|
|
51
|
+
account: this.walletKey ? (0, accounts_1.privateKeyToAccount)(this.walletKey) : undefined,
|
|
52
|
+
});
|
|
53
|
+
this.publicClient = (0, viem_1.createPublicClient)({
|
|
54
|
+
chain: this.chain,
|
|
55
|
+
transport,
|
|
56
|
+
});
|
|
57
|
+
this.contract = (0, viem_1.getContract)({
|
|
58
|
+
address: this.contractAddress,
|
|
59
|
+
abi: abis_1.BondkitTokenABI,
|
|
60
|
+
client: this.walletClientInstance,
|
|
61
|
+
});
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error("Connection failed:", error);
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Connects using an EIP-1193 provider and requests accounts, selecting the first one.
|
|
71
|
+
* Enables frontend wallet flows without requiring a private key.
|
|
72
|
+
*/
|
|
73
|
+
async connectWithProvider(provider) {
|
|
74
|
+
try {
|
|
75
|
+
const transport = (0, viem_1.custom)(provider);
|
|
76
|
+
this.connectedProvider = provider;
|
|
77
|
+
// Try to request accounts (prompt user if needed)
|
|
78
|
+
let addresses = [];
|
|
79
|
+
try {
|
|
80
|
+
const result = await provider.request({ method: "eth_requestAccounts" });
|
|
81
|
+
if (Array.isArray(result))
|
|
82
|
+
addresses = result;
|
|
83
|
+
}
|
|
84
|
+
catch (requestErr) {
|
|
85
|
+
try {
|
|
86
|
+
const result = await provider.request({ method: "eth_accounts" });
|
|
87
|
+
if (Array.isArray(result))
|
|
88
|
+
addresses = result;
|
|
89
|
+
}
|
|
90
|
+
catch (_) {
|
|
91
|
+
// ignore
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const selectedAccount = (addresses?.[0] ?? undefined);
|
|
95
|
+
this.walletClientInstance = (0, viem_1.createWalletClient)({
|
|
96
|
+
chain: this.chain,
|
|
97
|
+
transport,
|
|
98
|
+
account: selectedAccount,
|
|
99
|
+
});
|
|
100
|
+
this.publicClient = (0, viem_1.createPublicClient)({
|
|
101
|
+
chain: this.chain,
|
|
102
|
+
transport,
|
|
103
|
+
});
|
|
104
|
+
this.contract = (0, viem_1.getContract)({
|
|
105
|
+
address: this.contractAddress,
|
|
106
|
+
abi: abis_1.BondkitTokenABI,
|
|
107
|
+
client: this.walletClientInstance,
|
|
108
|
+
});
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error("Connection failed:", error);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async handleError(error, context) {
|
|
117
|
+
const defaultMessage = context ? `Error in ${context}:` : "An error occurred:";
|
|
118
|
+
console.error(defaultMessage, error);
|
|
119
|
+
// TODO: Add more specific error checks based on BondkitTokenABI error types if needed
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
// --- Read Methods (ERC20 + Custom) --- //
|
|
123
|
+
async name() {
|
|
124
|
+
try {
|
|
125
|
+
return await this.contract.read.name();
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.warn("Error fetching token name:", error);
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async symbol() {
|
|
133
|
+
try {
|
|
134
|
+
return await this.contract.read.symbol();
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.warn("Error fetching token symbol:", error);
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async decimals() {
|
|
142
|
+
try {
|
|
143
|
+
const dec = await this.contract.read.decimals();
|
|
144
|
+
return Number(dec);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.warn("Error fetching token decimals:", error);
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async totalSupply() {
|
|
152
|
+
try {
|
|
153
|
+
return await this.contract.read.totalSupply();
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.warn("Error fetching token total supply:", error);
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async balanceOf(account) {
|
|
161
|
+
try {
|
|
162
|
+
return await this.contract.read.balanceOf([account]);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.warn(`Error fetching balance for ${account}:`, error);
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async allowance(owner, spender) {
|
|
170
|
+
try {
|
|
171
|
+
return await this.contract.read.allowance([owner, spender]);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.warn(`Error fetching allowance for owner ${owner} and spender ${spender}:`, error);
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async owner() {
|
|
179
|
+
try {
|
|
180
|
+
return await this.contract.read.owner();
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.warn("Error fetching token owner or 'owner' function might not exist:", error);
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async getTokenDetails() {
|
|
188
|
+
try {
|
|
189
|
+
const [name, symbol, decimals, totalSupply, owner] = await Promise.all([
|
|
190
|
+
this.name(),
|
|
191
|
+
this.symbol(),
|
|
192
|
+
this.decimals(),
|
|
193
|
+
this.totalSupply(),
|
|
194
|
+
this.owner(),
|
|
195
|
+
]);
|
|
196
|
+
if (name === undefined || symbol === undefined || decimals === undefined || totalSupply === undefined) {
|
|
197
|
+
console.warn("Failed to retrieve all essential token details.");
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
name,
|
|
202
|
+
symbol,
|
|
203
|
+
decimals,
|
|
204
|
+
totalSupply,
|
|
205
|
+
owner: owner || "0x0000000000000000000000000000000000000000",
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
console.warn("Error in getTokenDetails:", error);
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// --- Bondkit Specific Read Methods ---
|
|
214
|
+
async feeRecipient() {
|
|
215
|
+
try {
|
|
216
|
+
return await this.contract.read.feeRecipient();
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
console.warn("Error fetching feeRecipient:", e);
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async currentStatus() {
|
|
224
|
+
try {
|
|
225
|
+
const status = await this.contract.read.currentStatus();
|
|
226
|
+
return status;
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
console.warn("Error fetching currentStatus:", e);
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async getCurrentPhase() {
|
|
234
|
+
try {
|
|
235
|
+
return await this.contract.read.getCurrentPhase();
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
console.warn("Error fetching getCurrentPhase:", e);
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async getAmountOfTokensToBuy(ethAmount) {
|
|
243
|
+
try {
|
|
244
|
+
const value = typeof ethAmount === "string" ? (0, viem_1.parseEther)(ethAmount) : ethAmount;
|
|
245
|
+
return await this.contract.read.getAmountOfTokensToBuy([value]);
|
|
246
|
+
}
|
|
247
|
+
catch (e) {
|
|
248
|
+
console.warn("Error in getAmountOfTokensToBuy:", e);
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async getAmountOfEthToSell(tokenAmount) {
|
|
253
|
+
try {
|
|
254
|
+
return await this.contract.read.getAmountOfEthToSell([tokenAmount]);
|
|
255
|
+
}
|
|
256
|
+
catch (e) {
|
|
257
|
+
console.warn("Error in getAmountOfEthToSell:", e);
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async getCurrentBondingCurvePricePerToken() {
|
|
262
|
+
try {
|
|
263
|
+
return await this.contract.read.getCurrentBondingCurvePricePerToken();
|
|
264
|
+
}
|
|
265
|
+
catch (e) {
|
|
266
|
+
console.warn("Error fetching current bonding curve price:", e);
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async totalEthRaisedBonding() {
|
|
271
|
+
try {
|
|
272
|
+
return await this.contract.read.totalEthRaisedBonding();
|
|
273
|
+
}
|
|
274
|
+
catch (e) {
|
|
275
|
+
console.warn("Error fetching totalEthRaisedBonding:", e);
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async getTotalSupply() {
|
|
280
|
+
try {
|
|
281
|
+
return await this.contract.read.totalSupply();
|
|
282
|
+
}
|
|
283
|
+
catch (e) {
|
|
284
|
+
console.warn("Error fetching total supply:", e);
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async getPaginatedHolders(startIndex, count = BigInt(1000)) {
|
|
289
|
+
try {
|
|
290
|
+
const response = await this.contract.read.getPaginatedHolders([startIndex, count]);
|
|
291
|
+
const holders = response[0];
|
|
292
|
+
const balances = response[1];
|
|
293
|
+
return holders.map((holder, index) => ({
|
|
294
|
+
address: holder,
|
|
295
|
+
balance: balances[index],
|
|
296
|
+
}));
|
|
297
|
+
}
|
|
298
|
+
catch (e) {
|
|
299
|
+
console.warn("Error fetching paginated holders:", e);
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async getBondingProgress() {
|
|
304
|
+
try {
|
|
305
|
+
const [progress, raised, threshold] = await this.contract.read.getBondingProgressPercent();
|
|
306
|
+
return {
|
|
307
|
+
progress: Number(progress) / 100,
|
|
308
|
+
raised: Number(raised),
|
|
309
|
+
threshold: Number(threshold),
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
catch (e) {
|
|
313
|
+
console.warn("Error fetching bonding progress percent:", e);
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// --- Transaction History --- //
|
|
318
|
+
async getTransactionHistory(options) {
|
|
319
|
+
try {
|
|
320
|
+
const { userAddress, type, from, to, limit, offset } = options || {};
|
|
321
|
+
const response = await fetch(this.apiEndpoint, {
|
|
322
|
+
method: "POST",
|
|
323
|
+
headers: {
|
|
324
|
+
"Content-Type": "application/json",
|
|
325
|
+
"X-service-method": "getTransactionHistory",
|
|
326
|
+
},
|
|
327
|
+
body: JSON.stringify({
|
|
328
|
+
contractAddress: this.contractAddress,
|
|
329
|
+
chainId: this.chain.id,
|
|
330
|
+
userAddress,
|
|
331
|
+
type,
|
|
332
|
+
from,
|
|
333
|
+
to: to || Date.now(),
|
|
334
|
+
limit: limit || 50,
|
|
335
|
+
offset,
|
|
336
|
+
}),
|
|
337
|
+
});
|
|
338
|
+
if (!response.ok) {
|
|
339
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
340
|
+
}
|
|
341
|
+
const result = await response.json();
|
|
342
|
+
return result;
|
|
343
|
+
}
|
|
344
|
+
catch (e) {
|
|
345
|
+
console.warn("Error fetching transaction history:", e);
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
// --- Write Methods --- //
|
|
350
|
+
async executeWrite(functionName, args, options) {
|
|
351
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
352
|
+
// Try to resolve an account from a connected EIP-1193 provider on-demand
|
|
353
|
+
if (this.connectedProvider) {
|
|
354
|
+
try {
|
|
355
|
+
const addresses = (await this.connectedProvider.request({ method: "eth_accounts" }));
|
|
356
|
+
const selectedAccount = (addresses?.[0] ?? undefined);
|
|
357
|
+
if (selectedAccount) {
|
|
358
|
+
const transport = (0, viem_1.custom)(this.connectedProvider);
|
|
359
|
+
this.walletClientInstance = (0, viem_1.createWalletClient)({
|
|
360
|
+
chain: this.chain,
|
|
361
|
+
transport,
|
|
362
|
+
account: selectedAccount,
|
|
363
|
+
});
|
|
364
|
+
this.contract = (0, viem_1.getContract)({
|
|
365
|
+
address: this.contractAddress,
|
|
366
|
+
abi: abis_1.BondkitTokenABI,
|
|
367
|
+
client: this.walletClientInstance,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
catch (_) { }
|
|
372
|
+
}
|
|
373
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
374
|
+
throw new Error("Wallet key not set or client not connected for write operation.");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const accountToUse = this.walletKey ? (0, accounts_1.privateKeyToAccount)(this.walletKey) : this.walletClientInstance.account;
|
|
378
|
+
if (!accountToUse)
|
|
379
|
+
throw new Error("Account for transaction could not be determined.");
|
|
380
|
+
try {
|
|
381
|
+
let maxFee = options?.maxFeePerGas;
|
|
382
|
+
let priorityFee = options?.maxPriorityFeePerGas;
|
|
383
|
+
if (maxFee === undefined || priorityFee === undefined) {
|
|
384
|
+
try {
|
|
385
|
+
const feeEstimates = await this.publicClient.estimateFeesPerGas();
|
|
386
|
+
if (maxFee === undefined) {
|
|
387
|
+
maxFee = feeEstimates.maxFeePerGas;
|
|
388
|
+
}
|
|
389
|
+
if (priorityFee === undefined) {
|
|
390
|
+
priorityFee = feeEstimates.maxPriorityFeePerGas;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
catch (feeError) {
|
|
394
|
+
console.warn("Could not estimate fees, will rely on wallet defaults or provided values:", feeError);
|
|
395
|
+
maxFee = maxFee ?? undefined;
|
|
396
|
+
priorityFee = priorityFee ?? undefined;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const transactionOptions = {
|
|
400
|
+
account: accountToUse,
|
|
401
|
+
chain: this.chain,
|
|
402
|
+
};
|
|
403
|
+
if (options?.value !== undefined)
|
|
404
|
+
transactionOptions.value = options.value;
|
|
405
|
+
if (options?.gas !== undefined)
|
|
406
|
+
transactionOptions.gas = options.gas;
|
|
407
|
+
if (maxFee !== undefined)
|
|
408
|
+
transactionOptions.maxFeePerGas = maxFee;
|
|
409
|
+
if (priorityFee !== undefined)
|
|
410
|
+
transactionOptions.maxPriorityFeePerGas = priorityFee;
|
|
411
|
+
const hash = await this.contract.write[functionName](args, transactionOptions);
|
|
412
|
+
return hash;
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
return this.handleError(error, functionName);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
async initialize(config, options) {
|
|
419
|
+
return this.executeWrite("initialize", [config], options);
|
|
420
|
+
}
|
|
421
|
+
async transfer(to, amount, options) {
|
|
422
|
+
return this.executeWrite("transfer", [to, amount], options);
|
|
423
|
+
}
|
|
424
|
+
async approve(spender, amount, options) {
|
|
425
|
+
return this.executeWrite("approve", [spender, amount], options);
|
|
426
|
+
}
|
|
427
|
+
async transferFrom(from, to, amount, options) {
|
|
428
|
+
return this.executeWrite("transferFrom", [from, to, amount], options);
|
|
429
|
+
}
|
|
430
|
+
/** Buy tokens with ETH. Payable function. */
|
|
431
|
+
async buy(minTokensOut, ethAmount, options) {
|
|
432
|
+
if (!boughtEventAbi)
|
|
433
|
+
console.warn("Bought event ABI not found for event decoding.");
|
|
434
|
+
const value = typeof ethAmount === "string" ? (0, viem_1.parseEther)(ethAmount) : ethAmount;
|
|
435
|
+
return this.executeWrite("buy", [minTokensOut], { ...options, value });
|
|
436
|
+
}
|
|
437
|
+
/** Sell tokens for ETH. */
|
|
438
|
+
async sell(tokenAmount, minEthOut, options) {
|
|
439
|
+
if (!soldEventAbi)
|
|
440
|
+
console.warn("Sold event ABI not found for event decoding.");
|
|
441
|
+
return this.executeWrite("sell", [tokenAmount, minEthOut], options);
|
|
442
|
+
}
|
|
443
|
+
/** Migrate liquidity to DEX. Only callable by owner/migrationAdmin based on typical patterns. */
|
|
444
|
+
async migrateToDex(options) {
|
|
445
|
+
if (!dexMigrationEventAbi)
|
|
446
|
+
console.warn("DexMigration event ABI not found for event decoding.");
|
|
447
|
+
return this.executeWrite("migrateToDex", [], options);
|
|
448
|
+
}
|
|
449
|
+
async transferTokenOwnership(newOwner, options) {
|
|
450
|
+
return this.executeWrite("transferOwnership", [newOwner], options);
|
|
451
|
+
}
|
|
452
|
+
async renounceTokenOwnership(options) {
|
|
453
|
+
return this.executeWrite("renounceOwnership", [], options);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
exports.BondkitToken = BondkitToken;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Address, EIP1193Provider, Hex } from "viem";
|
|
2
|
+
import { SupportedChainId } from "./config";
|
|
3
|
+
import type { BondkitTokenConfig } from "./types";
|
|
4
|
+
export declare class BondkitTokenFactory {
|
|
5
|
+
private contract;
|
|
6
|
+
private publicClient;
|
|
7
|
+
private contractAddress;
|
|
8
|
+
private chain;
|
|
9
|
+
private walletKey?;
|
|
10
|
+
private rpcUrl;
|
|
11
|
+
private walletClientInstance;
|
|
12
|
+
private connectedProvider?;
|
|
13
|
+
constructor(chainId: SupportedChainId, walletKey?: string);
|
|
14
|
+
connect(provider?: EIP1193Provider): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Connects using an EIP-1193 provider and requests accounts, selecting the first one.
|
|
17
|
+
* Enables frontend wallet flows without requiring a private key.
|
|
18
|
+
*/
|
|
19
|
+
connectWithProvider(provider: EIP1193Provider): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Ensure we have an account set for write operations.
|
|
22
|
+
* If not, try to resolve from a connected provider and reinitialize the client.
|
|
23
|
+
*/
|
|
24
|
+
private ensureWriteAccount;
|
|
25
|
+
private handleError;
|
|
26
|
+
/**
|
|
27
|
+
* Deploys a new Bondkit token using the factory.
|
|
28
|
+
* @param config The configuration for the token to be deployed.
|
|
29
|
+
* @returns The address of the newly created BondkitToken.
|
|
30
|
+
*/
|
|
31
|
+
deployBondkitToken(configArg: BondkitTokenConfig): Promise<Address>;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the configuration of a deployed Bondkit token.
|
|
34
|
+
* @param tokenAddress The address of the Bondkit token.
|
|
35
|
+
* @returns The configuration object for the token.
|
|
36
|
+
*/
|
|
37
|
+
getBondkitTokenConfig(tokenAddress: Address): Promise<BondkitTokenConfig | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets a list of all Bondkit tokens deployed by this factory.
|
|
40
|
+
* @returns An array of token addresses.
|
|
41
|
+
*/
|
|
42
|
+
getDeployedBondkitTokens(): Promise<readonly Address[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the owner of the factory contract.
|
|
45
|
+
* @returns The address of the owner.
|
|
46
|
+
*/
|
|
47
|
+
getOwner(): Promise<Address | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Gets the implementation address used for new Bondkit token clones.
|
|
50
|
+
* @returns The address of the BondkitToken implementation contract.
|
|
51
|
+
*/
|
|
52
|
+
getBondkitTokenImplementation(): Promise<Address | undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Transfers ownership of the factory contract to a new owner.
|
|
55
|
+
* Requires the current owner to call this method.
|
|
56
|
+
* @param newOwner The address of the new owner.
|
|
57
|
+
* @returns A promise that resolves with the transaction hash.
|
|
58
|
+
*/
|
|
59
|
+
transferOwnership(newOwner: Address): Promise<Hex | undefined>;
|
|
60
|
+
}
|