@b3dotfun/sdk 0.0.40 → 0.0.41-alpha.0
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.d.ts +11 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +17 -4
- package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +0 -1
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +0 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +33 -11
- package/dist/cjs/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +0 -1
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +6 -3
- package/dist/cjs/anyspend/react/components/AnyspendSignatureMint.js +1 -2
- package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.js +5 -3
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +9 -9
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +80 -10
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +40 -37
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +8 -11
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +23 -9
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +10 -6
- package/dist/cjs/anyspend/react/components/common/PointsBadge.d.ts +7 -0
- package/dist/cjs/anyspend/react/components/common/PointsBadge.js +7 -0
- package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.js +14 -0
- package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
- package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.js +21 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +18 -8
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +5 -3
- package/dist/cjs/anyspend/react/providers/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/providers/index.js +3 -0
- package/dist/cjs/anyspend/services/anyspend.d.ts +1 -1
- package/dist/cjs/anyspend/services/anyspend.js +2 -0
- package/dist/cjs/anyspend/types/api.d.ts +51 -1
- package/dist/cjs/anyspend/utils/chain.js +1 -1
- package/dist/cjs/anyspend/utils/orderPayload.js +3 -0
- package/dist/cjs/bondkit/bondkitToken.d.ts +37 -2
- package/dist/cjs/bondkit/bondkitToken.js +268 -2
- package/dist/cjs/bondkit/bondkitTokenFactory.d.ts +1 -1
- package/dist/cjs/bondkit/bondkitTokenFactory.js +2 -2
- package/dist/cjs/bondkit/components/TradingView.js +3 -4
- package/dist/cjs/bondkit/config.d.ts +1 -1
- package/dist/cjs/bondkit/config.js +5 -2
- package/dist/cjs/bondkit/constants.d.ts +4 -0
- package/dist/cjs/bondkit/constants.js +6 -1
- package/dist/cjs/bondkit/index.d.ts +1 -0
- package/dist/cjs/bondkit/index.js +4 -1
- package/dist/cjs/bondkit/swapService.d.ts +43 -0
- package/dist/cjs/bondkit/swapService.js +376 -0
- package/dist/cjs/bondkit/types.d.ts +10 -4
- package/dist/cjs/bondkit/types.js +4 -5
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +41 -9
- package/dist/cjs/global-account/react/components/LinkAccount/LinkAccount.js +63 -3
- package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +4 -3
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/index.js +3 -1
- package/dist/cjs/global-account/react/hooks/useAccountAssets.js +5 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +2 -3
- package/dist/cjs/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
- package/dist/cjs/global-account/react/hooks/useGlobalAccount.js +32 -0
- package/dist/cjs/global-account/react/hooks/useQueryB3.js +5 -2
- package/dist/cjs/global-account/react/hooks/useQueryBSMNT.js +5 -2
- package/dist/cjs/global-account/react/hooks/useSimBalance.js +2 -2
- package/dist/cjs/global-account/react/hooks/useTokenBalancesByChain.js +7 -1
- package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +2 -2
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +28 -24
- package/dist/cjs/shared/utils/fetchBalances.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +11 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +17 -4
- package/dist/esm/anyspend/react/components/AnySpendBondKit.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +33 -11
- package/dist/esm/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +0 -1
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +6 -3
- package/dist/esm/anyspend/react/components/AnyspendSignatureMint.js +1 -2
- package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.js +6 -4
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +9 -9
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +80 -10
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +40 -37
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +8 -11
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +23 -9
- package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +10 -6
- package/dist/esm/anyspend/react/components/common/PointsBadge.d.ts +7 -0
- package/dist/esm/anyspend/react/components/common/PointsBadge.js +4 -0
- package/dist/esm/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
- package/dist/esm/anyspend/react/components/common/PointsDetailPanel.js +8 -0
- package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
- package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.js +17 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +18 -8
- package/dist/esm/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
- package/dist/esm/anyspend/react/providers/AnyspendProvider.js +5 -3
- package/dist/esm/anyspend/react/providers/index.d.ts +1 -0
- package/dist/esm/anyspend/react/providers/index.js +1 -0
- package/dist/esm/anyspend/services/anyspend.d.ts +1 -1
- package/dist/esm/anyspend/services/anyspend.js +2 -0
- package/dist/esm/anyspend/types/api.d.ts +51 -1
- package/dist/esm/anyspend/utils/chain.js +1 -1
- package/dist/esm/anyspend/utils/orderPayload.js +3 -0
- package/dist/esm/bondkit/bondkitToken.d.ts +37 -2
- package/dist/esm/bondkit/bondkitToken.js +268 -2
- package/dist/esm/bondkit/bondkitTokenFactory.d.ts +1 -1
- package/dist/esm/bondkit/bondkitTokenFactory.js +2 -2
- package/dist/esm/bondkit/components/TradingView.js +3 -4
- package/dist/esm/bondkit/config.d.ts +1 -1
- package/dist/esm/bondkit/config.js +5 -2
- package/dist/esm/bondkit/constants.d.ts +4 -0
- package/dist/esm/bondkit/constants.js +5 -0
- package/dist/esm/bondkit/index.d.ts +1 -0
- package/dist/esm/bondkit/index.js +2 -0
- package/dist/esm/bondkit/swapService.d.ts +43 -0
- package/dist/esm/bondkit/swapService.js +372 -0
- package/dist/esm/bondkit/types.d.ts +10 -4
- package/dist/esm/bondkit/types.js +4 -5
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +42 -9
- package/dist/esm/global-account/react/components/LinkAccount/LinkAccount.js +65 -5
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
- package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/index.js +1 -0
- package/dist/esm/global-account/react/hooks/useAccountAssets.js +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +2 -3
- package/dist/esm/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
- package/dist/esm/global-account/react/hooks/useGlobalAccount.js +29 -0
- package/dist/esm/global-account/react/hooks/useQueryB3.js +5 -2
- package/dist/esm/global-account/react/hooks/useQueryBSMNT.js +5 -2
- package/dist/esm/global-account/react/hooks/useSimBalance.js +2 -2
- package/dist/esm/global-account/react/hooks/useTokenBalancesByChain.js +4 -1
- package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +2 -2
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +29 -25
- package/dist/esm/shared/utils/fetchBalances.d.ts +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpend.d.ts +11 -1
- package/dist/types/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/types/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
- package/dist/types/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
- package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
- package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
- package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
- package/dist/types/anyspend/react/components/common/PointsBadge.d.ts +7 -0
- package/dist/types/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
- package/dist/types/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
- package/dist/types/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
- package/dist/types/anyspend/react/providers/index.d.ts +1 -0
- package/dist/types/anyspend/services/anyspend.d.ts +1 -1
- package/dist/types/anyspend/types/api.d.ts +51 -1
- package/dist/types/bondkit/bondkitToken.d.ts +37 -2
- package/dist/types/bondkit/bondkitTokenFactory.d.ts +1 -1
- package/dist/types/bondkit/config.d.ts +1 -1
- package/dist/types/bondkit/constants.d.ts +4 -0
- package/dist/types/bondkit/index.d.ts +1 -0
- package/dist/types/bondkit/swapService.d.ts +43 -0
- package/dist/types/bondkit/types.d.ts +10 -4
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
- package/dist/types/global-account/react/hooks/index.d.ts +1 -0
- package/dist/types/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
- package/dist/types/shared/utils/fetchBalances.d.ts +1 -1
- package/package.json +6 -5
- package/src/anyspend/react/components/AnySpend.tsx +37 -1
- package/src/anyspend/react/components/AnySpendBondKit.tsx +0 -1
- package/src/anyspend/react/components/AnySpendBuySpin.tsx +0 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +63 -13
- package/src/anyspend/react/components/AnySpendNFT.tsx +3 -0
- package/src/anyspend/react/components/AnySpendStakeB3.tsx +0 -1
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +22 -0
- package/src/anyspend/react/components/AnyspendSignatureMint.tsx +1 -2
- package/src/anyspend/react/components/common/ConnectWalletPayment.tsx +7 -4
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +13 -8
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +170 -44
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +61 -45
- package/src/anyspend/react/components/common/OrderDetails.tsx +10 -14
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +28 -8
- package/src/anyspend/react/components/common/PanelOnramp.tsx +28 -15
- package/src/anyspend/react/components/common/PointsBadge.tsx +20 -0
- package/src/anyspend/react/components/common/PointsDetailPanel.tsx +55 -0
- package/src/anyspend/react/contexts/FeatureFlagsContext.tsx +34 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +18 -8
- package/src/anyspend/react/hooks/useAnyspendOrderAndTransactions.ts +1 -1
- package/src/anyspend/react/hooks/useCoinbaseOnrampOptions.ts +1 -1
- package/src/anyspend/react/providers/AnyspendProvider.tsx +11 -6
- package/src/anyspend/react/providers/index.ts +1 -0
- package/src/anyspend/services/anyspend.ts +3 -1
- package/src/anyspend/types/api.ts +51 -1
- package/src/anyspend/types/api_req_res.ts +6 -10
- package/src/anyspend/utils/chain.ts +1 -1
- package/src/anyspend/utils/orderPayload.ts +3 -0
- package/src/bondkit/bondkitToken.ts +323 -3
- package/src/bondkit/bondkitTokenFactory.ts +2 -2
- package/src/bondkit/components/TradingView.tsx +3 -5
- package/src/bondkit/config.ts +5 -2
- package/src/bondkit/constants.ts +7 -0
- package/src/bondkit/index.ts +3 -0
- package/src/bondkit/swapService.ts +464 -0
- package/src/bondkit/types.ts +12 -5
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +55 -15
- package/src/global-account/react/components/LinkAccount/LinkAccount.tsx +106 -32
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +60 -5
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +4 -2
- package/src/global-account/react/hooks/index.ts +1 -0
- package/src/global-account/react/hooks/useAccountAssets.ts +4 -3
- package/src/global-account/react/hooks/useAuthentication.ts +2 -3
- package/src/global-account/react/hooks/useGlobalAccount.tsx +36 -0
- package/src/global-account/react/hooks/useOneBalance.tsx +1 -1
- package/src/global-account/react/hooks/useQueryB3.ts +22 -15
- package/src/global-account/react/hooks/useQueryBSMNT.ts +22 -15
- package/src/global-account/react/hooks/useSimBalance.ts +2 -2
- package/src/global-account/react/hooks/useTokenBalancesByChain.tsx +4 -1
- package/src/global-account/react/hooks/useTokenFromUrl.tsx +2 -2
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +30 -26
- package/src/shared/utils/fetchBalances.ts +1 -1
|
@@ -22,6 +22,7 @@ var PanelView;
|
|
|
22
22
|
PanelView[PanelView["RECIPIENT_SELECTION"] = 3] = "RECIPIENT_SELECTION";
|
|
23
23
|
PanelView[PanelView["ORDER_DETAILS"] = 4] = "ORDER_DETAILS";
|
|
24
24
|
PanelView[PanelView["LOADING"] = 5] = "LOADING";
|
|
25
|
+
PanelView[PanelView["POINTS_DETAIL"] = 6] = "POINTS_DETAIL";
|
|
25
26
|
})(PanelView || (exports.PanelView = PanelView = {}));
|
|
26
27
|
function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, slippage = 0, disableUrlParamManagement = false, }) {
|
|
27
28
|
const searchParams = (0, react_2.useSearchParamsSSR)();
|
|
@@ -110,15 +111,17 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
110
111
|
}
|
|
111
112
|
};
|
|
112
113
|
// Get quote
|
|
113
|
-
|
|
114
|
+
// For fiat payments, always use USDC decimals (6) regardless of selectedSrcToken
|
|
115
|
+
const effectiveDecimals = paymentType === "fiat" ? anyspend_1.USDC_BASE.decimals : selectedSrcToken.decimals;
|
|
116
|
+
const activeInputAmountInWei = (0, viem_1.parseUnits)(srcAmount.replace(/,/g, ""), effectiveDecimals).toString();
|
|
114
117
|
const { anyspendQuote, isLoadingAnyspendQuote, getAnyspendQuoteError } = (0, react_1.useAnyspendQuote)({
|
|
115
118
|
srcChain: paymentType === "fiat" ? chains_1.base.id : selectedSrcChainId,
|
|
116
119
|
dstChain: isDepositMode ? chains_1.base.id : selectedDstChainId, // For deposits, always Base; for swaps, use selected destination
|
|
117
120
|
srcTokenAddress: paymentType === "fiat" ? anyspend_1.USDC_BASE.address : selectedSrcToken.address,
|
|
118
121
|
dstTokenAddress: isDepositMode ? anyspend_1.B3_TOKEN.address : selectedSrcToken.address, // For deposits, always B3
|
|
119
|
-
type: "
|
|
120
|
-
tradeType: "EXACT_INPUT",
|
|
122
|
+
type: "hype_duel",
|
|
121
123
|
amount: activeInputAmountInWei,
|
|
124
|
+
recipientAddress: selectedRecipientAddress,
|
|
122
125
|
onrampVendor: paymentType === "fiat" ? getOnrampVendor(selectedFiatPaymentMethod) : undefined,
|
|
123
126
|
});
|
|
124
127
|
// Get geo options for fiat
|
|
@@ -189,12 +192,19 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
189
192
|
// Handle order completion
|
|
190
193
|
(0, react_3.useEffect)(() => {
|
|
191
194
|
if (oat?.data?.order.status === "executed") {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
195
|
+
// get the actualDstAmount if available from custompayload
|
|
196
|
+
const amount = oat.data.order.payload?.actualDstAmount;
|
|
197
|
+
const formattedActualDstAmount = amount
|
|
198
|
+
? (0, number_1.formatTokenAmount)(BigInt(amount), oat.data.order.metadata.dstToken.decimals)
|
|
199
|
+
: undefined;
|
|
200
|
+
onTransactionSuccess?.(formattedActualDstAmount);
|
|
196
201
|
}
|
|
197
|
-
}, [
|
|
202
|
+
}, [
|
|
203
|
+
oat?.data?.order.status,
|
|
204
|
+
oat?.data?.order.payload,
|
|
205
|
+
onTransactionSuccess,
|
|
206
|
+
oat?.data?.order.metadata.dstToken.decimals,
|
|
207
|
+
]);
|
|
198
208
|
return {
|
|
199
209
|
// State
|
|
200
210
|
activePanel,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
+
import { FeatureFlags } from "../contexts/FeatureFlagsContext";
|
|
2
3
|
interface AnyspendProviderProps {
|
|
3
4
|
children: ReactNode;
|
|
5
|
+
featureFlags?: FeatureFlags;
|
|
4
6
|
}
|
|
5
7
|
/**
|
|
6
8
|
* AnyspendProvider is a top-level provider that wraps your application to provide
|
|
@@ -12,17 +14,18 @@ interface AnyspendProviderProps {
|
|
|
12
14
|
* - Safe to use at the application root
|
|
13
15
|
* - Configures sensible defaults for query caching
|
|
14
16
|
* - Handles Stripe payment redirects and modal state
|
|
17
|
+
* - Provides feature flags configuration
|
|
15
18
|
*
|
|
16
19
|
* @example
|
|
17
20
|
* ```tsx
|
|
18
21
|
* function App() {
|
|
19
22
|
* return (
|
|
20
|
-
* <AnyspendProvider>
|
|
23
|
+
* <AnyspendProvider featureFlags={{ showPoints: true }}>
|
|
21
24
|
* <YourApp />
|
|
22
25
|
* </AnyspendProvider>
|
|
23
26
|
* );
|
|
24
27
|
* }
|
|
25
28
|
* ```
|
|
26
29
|
*/
|
|
27
|
-
export declare const AnyspendProvider: ({ children }: AnyspendProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
export declare const AnyspendProvider: ({ children, featureFlags }: AnyspendProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
28
31
|
export {};
|
|
@@ -6,6 +6,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
6
6
|
const react_1 = require("../../../global-account/react");
|
|
7
7
|
const react_query_1 = require("@tanstack/react-query");
|
|
8
8
|
const react_2 = require("react");
|
|
9
|
+
const FeatureFlagsContext_1 = require("../contexts/FeatureFlagsContext");
|
|
9
10
|
const StripeRedirectHandler_1 = require("./StripeRedirectHandler");
|
|
10
11
|
const defaultQueryClientConfig = {
|
|
11
12
|
defaultOptions: {
|
|
@@ -26,20 +27,21 @@ const defaultQueryClientConfig = {
|
|
|
26
27
|
* - Safe to use at the application root
|
|
27
28
|
* - Configures sensible defaults for query caching
|
|
28
29
|
* - Handles Stripe payment redirects and modal state
|
|
30
|
+
* - Provides feature flags configuration
|
|
29
31
|
*
|
|
30
32
|
* @example
|
|
31
33
|
* ```tsx
|
|
32
34
|
* function App() {
|
|
33
35
|
* return (
|
|
34
|
-
* <AnyspendProvider>
|
|
36
|
+
* <AnyspendProvider featureFlags={{ showPoints: true }}>
|
|
35
37
|
* <YourApp />
|
|
36
38
|
* </AnyspendProvider>
|
|
37
39
|
* );
|
|
38
40
|
* }
|
|
39
41
|
* ```
|
|
40
42
|
*/
|
|
41
|
-
const AnyspendProvider = function AnyspendProvider({ children }) {
|
|
43
|
+
const AnyspendProvider = function AnyspendProvider({ children, featureFlags }) {
|
|
42
44
|
const [queryClient] = (0, react_2.useState)(() => new react_query_1.QueryClient(defaultQueryClientConfig));
|
|
43
|
-
return ((0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsxs)(react_1.TooltipProvider, { children: [(0, jsx_runtime_1.jsx)(StripeRedirectHandler_1.StripeRedirectHandler, {}), children] }) }));
|
|
45
|
+
return ((0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(FeatureFlagsContext_1.FeatureFlagsProvider, { featureFlags: featureFlags, children: (0, jsx_runtime_1.jsxs)(react_1.TooltipProvider, { children: [(0, jsx_runtime_1.jsx)(StripeRedirectHandler_1.StripeRedirectHandler, {}), children] }) }) }));
|
|
44
46
|
};
|
|
45
47
|
exports.AnyspendProvider = AnyspendProvider;
|
|
@@ -14,5 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.useFeatureFlags = void 0;
|
|
17
18
|
__exportStar(require("./AnyspendProvider"), exports);
|
|
18
19
|
__exportStar(require("./StripeRedirectHandler"), exports);
|
|
20
|
+
var FeatureFlagsContext_1 = require("../contexts/FeatureFlagsContext");
|
|
21
|
+
Object.defineProperty(exports, "useFeatureFlags", { enumerable: true, get: function () { return FeatureFlagsContext_1.useFeatureFlags; } });
|
|
@@ -28,7 +28,7 @@ export declare const anyspendService: {
|
|
|
28
28
|
}>;
|
|
29
29
|
getOrderAndTransactions: (orderId: string | undefined) => Promise<GetOrderAndTxsResponse>;
|
|
30
30
|
getOrderHistory: (creatorAddress: string | undefined, limit?: number, offset?: number) => Promise<GetOrderHistoryResponse>;
|
|
31
|
-
getCoinbaseOnrampOptions: (country: string, visitorData?: VisitorData) => Promise<GetCoinbaseOnrampOptionsResponse>;
|
|
31
|
+
getCoinbaseOnrampOptions: (country: string | undefined, visitorData?: VisitorData) => Promise<GetCoinbaseOnrampOptionsResponse>;
|
|
32
32
|
checkStripeSupport: (usdAmount?: string, visitorData?: VisitorData) => Promise<{
|
|
33
33
|
stripeOnramp: boolean;
|
|
34
34
|
stripeWeb2: components["schemas"]["StripeWeb2Support"];
|
|
@@ -69,6 +69,7 @@ exports.anyspendService = {
|
|
|
69
69
|
return data;
|
|
70
70
|
},
|
|
71
71
|
getOrderAndTransactions: async (orderId) => {
|
|
72
|
+
(0, invariant_1.default)(orderId, "orderId is required");
|
|
72
73
|
const response = await fetch(`${constants_1.ANYSPEND_MAINNET_BASE_URL}/orders/${orderId}`);
|
|
73
74
|
const data = await response.json();
|
|
74
75
|
return data;
|
|
@@ -86,6 +87,7 @@ exports.anyspendService = {
|
|
|
86
87
|
return data;
|
|
87
88
|
},
|
|
88
89
|
getCoinbaseOnrampOptions: async (country, visitorData) => {
|
|
90
|
+
(0, invariant_1.default)(country, "country is required");
|
|
89
91
|
const params = new URLSearchParams({
|
|
90
92
|
country,
|
|
91
93
|
// include fingerprintId and requestId in the query params
|
|
@@ -503,11 +503,16 @@ export interface paths {
|
|
|
503
503
|
* @example 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
|
|
504
504
|
*/
|
|
505
505
|
dstTokenAddress: string;
|
|
506
|
+
/**
|
|
507
|
+
* @description Recipient address
|
|
508
|
+
* @example 0x55c71fca5e01cf246718748ae540473e608d0282
|
|
509
|
+
*/
|
|
510
|
+
recipientAddress?: string;
|
|
506
511
|
/**
|
|
507
512
|
* @description Type of trade execution
|
|
508
513
|
* @enum {string}
|
|
509
514
|
*/
|
|
510
|
-
tradeType: "EXACT_INPUT" | "
|
|
515
|
+
tradeType: "EXACT_INPUT" | "EXACT_OUTPUT";
|
|
511
516
|
/**
|
|
512
517
|
* @description Amount to quote
|
|
513
518
|
* @example 1000000000000000000
|
|
@@ -544,6 +549,11 @@ export interface paths {
|
|
|
544
549
|
* @example 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
|
|
545
550
|
*/
|
|
546
551
|
dstTokenAddress: string;
|
|
552
|
+
/**
|
|
553
|
+
* @description Recipient address
|
|
554
|
+
* @example 0x55c71fca5e01cf246718748ae540473e608d0282
|
|
555
|
+
*/
|
|
556
|
+
recipientAddress?: string;
|
|
547
557
|
/** @description Custom payload for execution */
|
|
548
558
|
payload: {
|
|
549
559
|
/** @description Encoded transaction data */
|
|
@@ -567,6 +577,11 @@ export interface paths {
|
|
|
567
577
|
dstChain: number;
|
|
568
578
|
srcTokenAddress: string;
|
|
569
579
|
dstTokenAddress: string;
|
|
580
|
+
/**
|
|
581
|
+
* @description Recipient address
|
|
582
|
+
* @example 0x55c71fca5e01cf246718748ae540473e608d0282
|
|
583
|
+
*/
|
|
584
|
+
recipientAddress?: string;
|
|
570
585
|
/** @enum {string} */
|
|
571
586
|
onrampVendor?: "coinbase" | "stripe" | "stripe-web2";
|
|
572
587
|
contractAddress: string;
|
|
@@ -581,6 +596,11 @@ export interface paths {
|
|
|
581
596
|
dstChain: number;
|
|
582
597
|
srcTokenAddress: string;
|
|
583
598
|
dstTokenAddress: string;
|
|
599
|
+
/**
|
|
600
|
+
* @description Recipient address
|
|
601
|
+
* @example 0x55c71fca5e01cf246718748ae540473e608d0282
|
|
602
|
+
*/
|
|
603
|
+
recipientAddress?: string;
|
|
584
604
|
/** @enum {string} */
|
|
585
605
|
onrampVendor?: "coinbase" | "stripe" | "stripe-web2";
|
|
586
606
|
contractAddress: string;
|
|
@@ -592,6 +612,11 @@ export interface paths {
|
|
|
592
612
|
dstChain: number;
|
|
593
613
|
srcTokenAddress: string;
|
|
594
614
|
dstTokenAddress: string;
|
|
615
|
+
/**
|
|
616
|
+
* @description Recipient address
|
|
617
|
+
* @example 0x55c71fca5e01cf246718748ae540473e608d0282
|
|
618
|
+
*/
|
|
619
|
+
recipientAddress?: string;
|
|
595
620
|
/** @enum {string} */
|
|
596
621
|
onrampVendor?: "coinbase" | "stripe" | "stripe-web2";
|
|
597
622
|
contractAddress: string;
|
|
@@ -622,6 +647,11 @@ export interface paths {
|
|
|
622
647
|
* @example 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
|
|
623
648
|
*/
|
|
624
649
|
dstTokenAddress: string;
|
|
650
|
+
/**
|
|
651
|
+
* @description Recipient address
|
|
652
|
+
* @example 0x55c71fca5e01cf246718748ae540473e608d0282
|
|
653
|
+
*/
|
|
654
|
+
recipientAddress?: string;
|
|
625
655
|
/**
|
|
626
656
|
* @description Amount to quote
|
|
627
657
|
* @example 1000000000000000000
|
|
@@ -798,6 +828,16 @@ export interface paths {
|
|
|
798
828
|
* @example 0
|
|
799
829
|
*/
|
|
800
830
|
userBalance?: string;
|
|
831
|
+
/**
|
|
832
|
+
* @description Anyspend points that will be awarded for the order
|
|
833
|
+
* @example 100
|
|
834
|
+
*/
|
|
835
|
+
pointsAmount?: number;
|
|
836
|
+
/**
|
|
837
|
+
* @description Multiplier applied to points that will be awarded for the order
|
|
838
|
+
* @example 1.5
|
|
839
|
+
*/
|
|
840
|
+
pointsMultiplier?: number;
|
|
801
841
|
};
|
|
802
842
|
/** @example 200 */
|
|
803
843
|
statusCode: number;
|
|
@@ -1077,6 +1117,11 @@ export interface components {
|
|
|
1077
1117
|
* @example 990000
|
|
1078
1118
|
*/
|
|
1079
1119
|
actualDstAmount: string | null;
|
|
1120
|
+
/**
|
|
1121
|
+
* @description Amount in after fee
|
|
1122
|
+
* @example 990000
|
|
1123
|
+
*/
|
|
1124
|
+
amountInAfterFee: string | null;
|
|
1080
1125
|
};
|
|
1081
1126
|
/** @description HypeDuel-specific payload */
|
|
1082
1127
|
HypeDuelPayload: {
|
|
@@ -1090,6 +1135,11 @@ export interface components {
|
|
|
1090
1135
|
* @example 990000
|
|
1091
1136
|
*/
|
|
1092
1137
|
actualDstAmount: string | null;
|
|
1138
|
+
/**
|
|
1139
|
+
* @description Amount in after fee
|
|
1140
|
+
* @example 990000
|
|
1141
|
+
*/
|
|
1142
|
+
amountInAfterFee: string | null;
|
|
1093
1143
|
};
|
|
1094
1144
|
/** @description Custom execution payload */
|
|
1095
1145
|
CustomPayload: {
|
|
@@ -127,7 +127,7 @@ exports.EVM_MAINNET = {
|
|
|
127
127
|
name: chains_1.bsc.name,
|
|
128
128
|
logoUrl: "https://avatars.githubusercontent.com/u/45615063?s=280&v=4",
|
|
129
129
|
type: chain_1.ChainType.EVM,
|
|
130
|
-
nativeRequired: (0, viem_1.parseEther)("0.
|
|
130
|
+
nativeRequired: (0, viem_1.parseEther)("0.0001"),
|
|
131
131
|
canDepositNative: true,
|
|
132
132
|
defaultToken: (0, token_1.getBnbToken)(),
|
|
133
133
|
nativeToken: (0, token_1.getBnbToken)(),
|
|
@@ -9,6 +9,7 @@ const buildPayload = (orderType, params) => {
|
|
|
9
9
|
return {
|
|
10
10
|
expectedDstAmount,
|
|
11
11
|
actualDstAmount: null,
|
|
12
|
+
amountInAfterFee: null,
|
|
12
13
|
};
|
|
13
14
|
case "mint_nft":
|
|
14
15
|
if (nft?.type === "erc1155") {
|
|
@@ -23,6 +24,7 @@ const buildPayload = (orderType, params) => {
|
|
|
23
24
|
return {
|
|
24
25
|
contractAddress: (0, utils_1.normalizeAddress)(nft.contractAddress),
|
|
25
26
|
nftPrice: nft?.price || "",
|
|
27
|
+
tokenId: null,
|
|
26
28
|
contractType: nft?.type,
|
|
27
29
|
};
|
|
28
30
|
}
|
|
@@ -45,6 +47,7 @@ const buildPayload = (orderType, params) => {
|
|
|
45
47
|
return {
|
|
46
48
|
expectedDstAmount,
|
|
47
49
|
actualDstAmount: null,
|
|
50
|
+
amountInAfterFee: null,
|
|
48
51
|
};
|
|
49
52
|
default:
|
|
50
53
|
throw new Error(`Invalid order type: ${orderType}`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Address, EIP1193Provider, GetContractReturnType, Hex, PublicClient, WalletClient } from "viem";
|
|
2
2
|
import { BondkitTokenABI } from "./abis";
|
|
3
|
-
import type { BondkitTokenInitializationConfig, GetTransactionHistoryOptions,
|
|
3
|
+
import type { BondkitTokenInitializationConfig, GetTransactionHistoryOptions, SwapQuote, TokenDetails, TransactionResponse } from "./types";
|
|
4
|
+
import { TokenStatus } from "./types";
|
|
4
5
|
type ExecuteWriteOptions = {
|
|
5
6
|
value?: bigint;
|
|
6
7
|
gas?: bigint;
|
|
@@ -18,7 +19,8 @@ export declare class BondkitToken {
|
|
|
18
19
|
private walletClientInstance;
|
|
19
20
|
private connectedProvider?;
|
|
20
21
|
private tradingToken?;
|
|
21
|
-
|
|
22
|
+
private swapService?;
|
|
23
|
+
constructor(contractAddress: string, walletKey?: string, rpcUrl?: string);
|
|
22
24
|
connect(provider?: EIP1193Provider): boolean;
|
|
23
25
|
/**
|
|
24
26
|
* Connects using an EIP-1193 provider and requests accounts, selecting the first one.
|
|
@@ -69,5 +71,38 @@ export declare class BondkitToken {
|
|
|
69
71
|
migrateToDex(options?: ExecuteWriteOptions): Promise<Hex | undefined>;
|
|
70
72
|
transferTokenOwnership(newOwner: Address, options?: ExecuteWriteOptions): Promise<Hex | undefined>;
|
|
71
73
|
renounceTokenOwnership(options?: ExecuteWriteOptions): Promise<Hex | undefined>;
|
|
74
|
+
/**
|
|
75
|
+
* Get the swap service instance (lazy initialization)
|
|
76
|
+
*/
|
|
77
|
+
private getSwapService;
|
|
78
|
+
/**
|
|
79
|
+
* Check if DEX swapping is available (token must be in Dex phase)
|
|
80
|
+
*/
|
|
81
|
+
isSwapAvailable(): Promise<boolean | undefined>;
|
|
82
|
+
/**
|
|
83
|
+
* Get swap quote for trading token → bondkit token
|
|
84
|
+
*/
|
|
85
|
+
getSwapQuoteForBondkitToken(amountTradingTokenIn: string, slippageTolerance?: number): Promise<SwapQuote | undefined>;
|
|
86
|
+
/**
|
|
87
|
+
* Get swap quote for bondkit token → trading token
|
|
88
|
+
*/
|
|
89
|
+
getSwapQuoteForTradingToken(amountBondkitTokenIn: string, slippageTolerance?: number): Promise<SwapQuote | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Swap trading token for bondkit token
|
|
92
|
+
*/
|
|
93
|
+
swapTradingTokenForBondkitToken(amountTradingTokenIn: string, slippageTolerance?: number, options?: ExecuteWriteOptions): Promise<Hex | undefined>;
|
|
94
|
+
/**
|
|
95
|
+
* Swap bondkit token for trading token
|
|
96
|
+
*/
|
|
97
|
+
swapBondkitTokenForTradingToken(amountBondkitTokenIn: string, slippageTolerance?: number, options?: ExecuteWriteOptions): Promise<Hex | undefined>;
|
|
98
|
+
/**
|
|
99
|
+
* Helper method to get trading token decimals
|
|
100
|
+
*/
|
|
101
|
+
private getTradingTokenDecimals;
|
|
102
|
+
/**
|
|
103
|
+
* Get trading token symbol
|
|
104
|
+
* @param tradingTokenAddress Optional trading token address to avoid fetching it again
|
|
105
|
+
*/
|
|
106
|
+
getTradingTokenSymbol(tradingTokenAddress?: Address): Promise<string | undefined>;
|
|
72
107
|
}
|
|
73
108
|
export {};
|
|
@@ -6,6 +6,8 @@ const accounts_1 = require("viem/accounts");
|
|
|
6
6
|
const chains_1 = require("viem/chains");
|
|
7
7
|
const abis_1 = require("./abis");
|
|
8
8
|
const config_1 = require("./config");
|
|
9
|
+
const swapService_1 = require("./swapService");
|
|
10
|
+
const types_1 = require("./types");
|
|
9
11
|
// Event ABI snippets for decoding
|
|
10
12
|
const boughtEventAbi = abis_1.BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveBuy");
|
|
11
13
|
const soldEventAbi = abis_1.BondkitTokenABI.find(item => item.type === "event" && item.name === "BondingCurveSell");
|
|
@@ -14,8 +16,8 @@ const dexMigrationEventAbi = abis_1.BondkitTokenABI.find(item => item.type === "
|
|
|
14
16
|
const OKX_POLLING_MAX_RETRIES = 60; // 5 minutes with 5 second intervals
|
|
15
17
|
const OKX_POLLING_INTERVAL_MS = 5000; // 5 seconds
|
|
16
18
|
class BondkitToken {
|
|
17
|
-
constructor(contractAddress, walletKey) {
|
|
18
|
-
const sdkConfig = (0, config_1.getConfig)(chains_1.base.id);
|
|
19
|
+
constructor(contractAddress, walletKey, rpcUrl) {
|
|
20
|
+
const sdkConfig = (0, config_1.getConfig)(chains_1.base.id, rpcUrl);
|
|
19
21
|
this.chain = sdkConfig.chain;
|
|
20
22
|
this.rpcUrl = sdkConfig.rpcUrl;
|
|
21
23
|
this.apiEndpoint = sdkConfig.apiEndpoint;
|
|
@@ -558,5 +560,269 @@ class BondkitToken {
|
|
|
558
560
|
async renounceTokenOwnership(options) {
|
|
559
561
|
return this.executeWrite("renounceOwnership", [], options);
|
|
560
562
|
}
|
|
563
|
+
// --- DEX Swap Methods ---
|
|
564
|
+
/**
|
|
565
|
+
* Get the swap service instance (lazy initialization)
|
|
566
|
+
*/
|
|
567
|
+
getSwapService() {
|
|
568
|
+
if (!this.swapService) {
|
|
569
|
+
this.swapService = new swapService_1.BondkitSwapService(this.contractAddress);
|
|
570
|
+
}
|
|
571
|
+
return this.swapService;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Check if DEX swapping is available (token must be in Dex phase)
|
|
575
|
+
*/
|
|
576
|
+
async isSwapAvailable() {
|
|
577
|
+
try {
|
|
578
|
+
const status = await this.currentStatus();
|
|
579
|
+
return status === types_1.TokenStatus.Dex;
|
|
580
|
+
}
|
|
581
|
+
catch (error) {
|
|
582
|
+
console.warn("Error checking swap availability:", error);
|
|
583
|
+
return undefined;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Get swap quote for trading token → bondkit token
|
|
588
|
+
*/
|
|
589
|
+
async getSwapQuoteForBondkitToken(amountTradingTokenIn, slippageTolerance = 0.5) {
|
|
590
|
+
try {
|
|
591
|
+
// Check if swapping is available
|
|
592
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
593
|
+
if (!swapAvailable) {
|
|
594
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
595
|
+
return undefined;
|
|
596
|
+
}
|
|
597
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
598
|
+
if (!tradingTokenAddress) {
|
|
599
|
+
console.warn("Trading token address not available");
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
// Get token details for decimals
|
|
603
|
+
const [tradingTokenDecimals, bondkitTokenDecimals] = await Promise.all([
|
|
604
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
605
|
+
this.decimals(),
|
|
606
|
+
]);
|
|
607
|
+
if (tradingTokenDecimals === undefined || bondkitTokenDecimals === undefined) {
|
|
608
|
+
console.warn("Unable to fetch token decimals");
|
|
609
|
+
return undefined;
|
|
610
|
+
}
|
|
611
|
+
const swapService = this.getSwapService();
|
|
612
|
+
const quote = await swapService.getSwapQuote({
|
|
613
|
+
tokenIn: tradingTokenAddress,
|
|
614
|
+
tokenOut: this.contractAddress,
|
|
615
|
+
amountIn: amountTradingTokenIn,
|
|
616
|
+
tokenInDecimals: tradingTokenDecimals,
|
|
617
|
+
tokenOutDecimals: bondkitTokenDecimals,
|
|
618
|
+
slippageTolerance,
|
|
619
|
+
recipient: this.walletClientInstance.account?.address || "0x0000000000000000000000000000000000000000",
|
|
620
|
+
});
|
|
621
|
+
return quote || undefined;
|
|
622
|
+
}
|
|
623
|
+
catch (error) {
|
|
624
|
+
console.warn("Error getting swap quote for bondkit token:", error);
|
|
625
|
+
return undefined;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Get swap quote for bondkit token → trading token
|
|
630
|
+
*/
|
|
631
|
+
async getSwapQuoteForTradingToken(amountBondkitTokenIn, slippageTolerance = 0.5) {
|
|
632
|
+
try {
|
|
633
|
+
// Check if swapping is available
|
|
634
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
635
|
+
if (!swapAvailable) {
|
|
636
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
637
|
+
return undefined;
|
|
638
|
+
}
|
|
639
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
640
|
+
if (!tradingTokenAddress) {
|
|
641
|
+
console.warn("Trading token address not available");
|
|
642
|
+
return undefined;
|
|
643
|
+
}
|
|
644
|
+
// Get token details for decimals
|
|
645
|
+
const [bondkitTokenDecimals, tradingTokenDecimals] = await Promise.all([
|
|
646
|
+
this.decimals(),
|
|
647
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
648
|
+
]);
|
|
649
|
+
if (bondkitTokenDecimals === undefined || tradingTokenDecimals === undefined) {
|
|
650
|
+
console.warn("Unable to fetch token decimals");
|
|
651
|
+
return undefined;
|
|
652
|
+
}
|
|
653
|
+
const swapService = this.getSwapService();
|
|
654
|
+
const quote = await swapService.getSwapQuote({
|
|
655
|
+
tokenIn: this.contractAddress,
|
|
656
|
+
tokenOut: tradingTokenAddress,
|
|
657
|
+
amountIn: amountBondkitTokenIn,
|
|
658
|
+
tokenInDecimals: bondkitTokenDecimals,
|
|
659
|
+
tokenOutDecimals: tradingTokenDecimals,
|
|
660
|
+
slippageTolerance,
|
|
661
|
+
recipient: this.walletClientInstance.account?.address || "0x0000000000000000000000000000000000000000",
|
|
662
|
+
});
|
|
663
|
+
return quote || undefined;
|
|
664
|
+
}
|
|
665
|
+
catch (error) {
|
|
666
|
+
console.warn("Error getting swap quote for trading token:", error);
|
|
667
|
+
return undefined;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Swap trading token for bondkit token
|
|
672
|
+
*/
|
|
673
|
+
async swapTradingTokenForBondkitToken(amountTradingTokenIn, slippageTolerance = 0.5, options) {
|
|
674
|
+
try {
|
|
675
|
+
// Check if swapping is available
|
|
676
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
677
|
+
if (!swapAvailable) {
|
|
678
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
679
|
+
return undefined;
|
|
680
|
+
}
|
|
681
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
682
|
+
console.warn("Wallet key not set or client not connected for swap operation");
|
|
683
|
+
return undefined;
|
|
684
|
+
}
|
|
685
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
686
|
+
if (!tradingTokenAddress) {
|
|
687
|
+
console.warn("Trading token address not available");
|
|
688
|
+
return undefined;
|
|
689
|
+
}
|
|
690
|
+
// Get token details for decimals
|
|
691
|
+
const [tradingTokenDecimals, bondkitTokenDecimals] = await Promise.all([
|
|
692
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
693
|
+
this.decimals(),
|
|
694
|
+
]);
|
|
695
|
+
if (tradingTokenDecimals === undefined || bondkitTokenDecimals === undefined) {
|
|
696
|
+
console.warn("Unable to fetch token decimals");
|
|
697
|
+
return undefined;
|
|
698
|
+
}
|
|
699
|
+
const recipient = this.walletClientInstance.account?.address ||
|
|
700
|
+
(this.walletKey ? (0, accounts_1.privateKeyToAccount)(this.walletKey).address : undefined);
|
|
701
|
+
if (!recipient) {
|
|
702
|
+
console.warn("Unable to determine recipient address");
|
|
703
|
+
return undefined;
|
|
704
|
+
}
|
|
705
|
+
const swapService = this.getSwapService();
|
|
706
|
+
const txHash = await swapService.executeSwap({
|
|
707
|
+
tokenIn: tradingTokenAddress,
|
|
708
|
+
tokenOut: this.contractAddress,
|
|
709
|
+
amountIn: amountTradingTokenIn,
|
|
710
|
+
tokenInDecimals: tradingTokenDecimals,
|
|
711
|
+
tokenOutDecimals: bondkitTokenDecimals,
|
|
712
|
+
slippageTolerance,
|
|
713
|
+
recipient,
|
|
714
|
+
deadline: (options?.value ? Math.floor(Date.now() / 1000) : 0) + 3600,
|
|
715
|
+
}, this.walletClientInstance);
|
|
716
|
+
return txHash ? txHash : undefined;
|
|
717
|
+
}
|
|
718
|
+
catch (error) {
|
|
719
|
+
console.warn("Error swapping trading token for bondkit token:", error);
|
|
720
|
+
return undefined;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Swap bondkit token for trading token
|
|
725
|
+
*/
|
|
726
|
+
async swapBondkitTokenForTradingToken(amountBondkitTokenIn, slippageTolerance = 0.5, options) {
|
|
727
|
+
try {
|
|
728
|
+
// Check if swapping is available
|
|
729
|
+
const swapAvailable = await this.isSwapAvailable();
|
|
730
|
+
if (!swapAvailable) {
|
|
731
|
+
console.warn("DEX swapping not available - token must be in Dex phase");
|
|
732
|
+
return undefined;
|
|
733
|
+
}
|
|
734
|
+
if (!this.walletClientInstance.account && !this.walletKey) {
|
|
735
|
+
console.warn("Wallet key not set or client not connected for swap operation");
|
|
736
|
+
return undefined;
|
|
737
|
+
}
|
|
738
|
+
const tradingTokenAddress = await this.getTradingTokenAddress();
|
|
739
|
+
if (!tradingTokenAddress) {
|
|
740
|
+
console.warn("Trading token address not available");
|
|
741
|
+
return undefined;
|
|
742
|
+
}
|
|
743
|
+
// Get token details for decimals
|
|
744
|
+
const [bondkitTokenDecimals, tradingTokenDecimals] = await Promise.all([
|
|
745
|
+
this.decimals(),
|
|
746
|
+
this.getTradingTokenDecimals(tradingTokenAddress),
|
|
747
|
+
]);
|
|
748
|
+
if (bondkitTokenDecimals === undefined || tradingTokenDecimals === undefined) {
|
|
749
|
+
console.warn("Unable to fetch token decimals");
|
|
750
|
+
return undefined;
|
|
751
|
+
}
|
|
752
|
+
const recipient = this.walletClientInstance.account?.address ||
|
|
753
|
+
(this.walletKey ? (0, accounts_1.privateKeyToAccount)(this.walletKey).address : undefined);
|
|
754
|
+
if (!recipient) {
|
|
755
|
+
console.warn("Unable to determine recipient address");
|
|
756
|
+
return undefined;
|
|
757
|
+
}
|
|
758
|
+
const swapService = this.getSwapService();
|
|
759
|
+
const txHash = await swapService.executeSwap({
|
|
760
|
+
tokenIn: this.contractAddress,
|
|
761
|
+
tokenOut: tradingTokenAddress,
|
|
762
|
+
amountIn: amountBondkitTokenIn,
|
|
763
|
+
tokenInDecimals: bondkitTokenDecimals,
|
|
764
|
+
tokenOutDecimals: tradingTokenDecimals,
|
|
765
|
+
slippageTolerance,
|
|
766
|
+
recipient,
|
|
767
|
+
deadline: (options?.value ? Math.floor(Date.now() / 1000) : 0) + 3600,
|
|
768
|
+
}, this.walletClientInstance);
|
|
769
|
+
return txHash ? txHash : undefined;
|
|
770
|
+
}
|
|
771
|
+
catch (error) {
|
|
772
|
+
console.warn("Error swapping bondkit token for trading token:", error);
|
|
773
|
+
return undefined;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Helper method to get trading token decimals
|
|
778
|
+
*/
|
|
779
|
+
async getTradingTokenDecimals(tradingTokenAddress) {
|
|
780
|
+
try {
|
|
781
|
+
// ETH has 18 decimals
|
|
782
|
+
if (tradingTokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
783
|
+
return 18;
|
|
784
|
+
}
|
|
785
|
+
// For ERC20 tokens, read decimals from contract
|
|
786
|
+
const tradingTokenContract = (0, viem_1.getContract)({
|
|
787
|
+
address: tradingTokenAddress,
|
|
788
|
+
abi: viem_1.erc20Abi,
|
|
789
|
+
client: this.publicClient,
|
|
790
|
+
});
|
|
791
|
+
const decimals = await tradingTokenContract.read.decimals();
|
|
792
|
+
return Number(decimals);
|
|
793
|
+
}
|
|
794
|
+
catch (error) {
|
|
795
|
+
console.warn("Error fetching trading token decimals:", error);
|
|
796
|
+
return undefined;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Get trading token symbol
|
|
801
|
+
* @param tradingTokenAddress Optional trading token address to avoid fetching it again
|
|
802
|
+
*/
|
|
803
|
+
async getTradingTokenSymbol(tradingTokenAddress) {
|
|
804
|
+
try {
|
|
805
|
+
const tokenAddress = tradingTokenAddress || (await this.getTradingTokenAddress());
|
|
806
|
+
if (!tokenAddress) {
|
|
807
|
+
return undefined;
|
|
808
|
+
}
|
|
809
|
+
// ETH symbol
|
|
810
|
+
if (tokenAddress === "0x0000000000000000000000000000000000000000") {
|
|
811
|
+
return "ETH";
|
|
812
|
+
}
|
|
813
|
+
// For ERC20 tokens, read symbol from contract
|
|
814
|
+
const tradingTokenContract = (0, viem_1.getContract)({
|
|
815
|
+
address: tokenAddress,
|
|
816
|
+
abi: viem_1.erc20Abi,
|
|
817
|
+
client: this.publicClient,
|
|
818
|
+
});
|
|
819
|
+
const symbol = await tradingTokenContract.read.symbol();
|
|
820
|
+
return symbol;
|
|
821
|
+
}
|
|
822
|
+
catch (error) {
|
|
823
|
+
console.warn("Error fetching trading token symbol:", error);
|
|
824
|
+
return undefined;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
561
827
|
}
|
|
562
828
|
exports.BondkitToken = BondkitToken;
|
|
@@ -10,7 +10,7 @@ export declare class BondkitTokenFactory {
|
|
|
10
10
|
private rpcUrl;
|
|
11
11
|
private walletClientInstance;
|
|
12
12
|
private connectedProvider?;
|
|
13
|
-
constructor(chainId: SupportedChainId, walletKey?: string);
|
|
13
|
+
constructor(chainId: SupportedChainId, walletKey?: string, rpcUrl?: string);
|
|
14
14
|
connect(provider?: EIP1193Provider): boolean;
|
|
15
15
|
/**
|
|
16
16
|
* Connects using an EIP-1193 provider and requests accounts, selecting the first one.
|