@b3dotfun/sdk 0.0.29-alpha.4 → 0.0.29-alpha.5
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/AnyspendDepositHype.js +6 -2
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +3 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +5 -3
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +6 -2
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +4 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +5 -3
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +9 -3
- package/src/anyspend/react/components/common/OrderDetails.tsx +4 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +8 -2
|
@@ -27,6 +27,7 @@ const RecipientSelection_1 = require("./common/RecipientSelection");
|
|
|
27
27
|
const escrow_1 = require("../../../anyspend/abis/escrow");
|
|
28
28
|
const lucide_react_1 = require("lucide-react");
|
|
29
29
|
const PanelOnramp_1 = require("./common/PanelOnramp");
|
|
30
|
+
const SLIPPAGE_PERCENT = 3;
|
|
30
31
|
function generateEncodedDataForDepositHype(amount, beneficiary) {
|
|
31
32
|
(0, invariant_1.default)(BigInt(amount) > 0, "Amount must be greater than zero");
|
|
32
33
|
const encodedData = (0, viem_1.encodeFunctionData)({
|
|
@@ -50,6 +51,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
50
51
|
onTransactionSuccess: onSuccess,
|
|
51
52
|
sourceTokenAddress,
|
|
52
53
|
sourceTokenChainId,
|
|
54
|
+
slippage: SLIPPAGE_PERCENT,
|
|
53
55
|
});
|
|
54
56
|
// Button state logic
|
|
55
57
|
const btnInfo = (0, react_3.useMemo)(() => {
|
|
@@ -133,7 +135,10 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
133
135
|
(0, invariant_1.default)(selectedRecipientAddress, "Recipient address is not found");
|
|
134
136
|
(0, invariant_1.default)(depositContractAddress, "Deposit contract address is not found");
|
|
135
137
|
const srcAmountBigInt = BigInt(activeInputAmountInWei);
|
|
136
|
-
|
|
138
|
+
// TODO: temp subtract 3% for slippage
|
|
139
|
+
const originalDepositAmountWei = anyspendQuote.data?.currencyOut?.amount || "0";
|
|
140
|
+
const depositAmountWei = ((BigInt(originalDepositAmountWei) * BigInt(100 - SLIPPAGE_PERCENT)) /
|
|
141
|
+
BigInt(100)).toString();
|
|
137
142
|
const encodedData = generateEncodedDataForDepositHype(depositAmountWei, selectedRecipientAddress);
|
|
138
143
|
createOrder({
|
|
139
144
|
recipientAddress: selectedRecipientAddress,
|
|
@@ -240,7 +245,6 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
240
245
|
setSelectedFiatPaymentMethod(method);
|
|
241
246
|
setActivePanel(useAnyspendFlow_1.PanelView.MAIN);
|
|
242
247
|
}, srcAmountOnRamp: srcAmount }));
|
|
243
|
-
console.log("activePanel", activePanel, orderId, oat);
|
|
244
248
|
// If showing token selection, render with panel transitions
|
|
245
249
|
return ((0, jsx_runtime_1.jsx)(react_1.StyleRoot, { children: (0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)("anyspend-container font-inter mx-auto w-full max-w-[460px]", mode === "page" &&
|
|
246
250
|
"bg-as-surface-primary border-as-border-secondary overflow-hidden rounded-2xl border shadow-xl"), children: (0, jsx_runtime_1.jsx)(react_1.TransitionPanel, { activeIndex: orderId
|
|
@@ -49,6 +49,9 @@ function getOrderSuccessText({ order, tournament, formattedActualDstAmount, dstT
|
|
|
49
49
|
actionText = `funded ${tournament?.name}`;
|
|
50
50
|
return `Successfully ${actionText}`;
|
|
51
51
|
case "custom":
|
|
52
|
+
if (order.metadata.action === anyspend_1.DEPOSIT_HYPE_ACTION) {
|
|
53
|
+
return `Successfully deposited ${(0, number_1.formatTokenAmount)(BigInt(order.payload?.amount || "0"), 18)} HYPE to ${recipient}`;
|
|
54
|
+
}
|
|
52
55
|
actionText = order.metadata.action || `executed contract`;
|
|
53
56
|
return `Successfully ${actionText}`;
|
|
54
57
|
default:
|
|
@@ -18,8 +18,9 @@ interface UseAnyspendFlowProps {
|
|
|
18
18
|
onTransactionSuccess?: () => void;
|
|
19
19
|
sourceTokenAddress?: string;
|
|
20
20
|
sourceTokenChainId?: number;
|
|
21
|
+
slippage?: number;
|
|
21
22
|
}
|
|
22
|
-
export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrder, isDepositMode, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, }: UseAnyspendFlowProps): {
|
|
23
|
+
export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrder, isDepositMode, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, slippage, }: UseAnyspendFlowProps): {
|
|
23
24
|
activePanel: PanelView;
|
|
24
25
|
setActivePanel: import("react").Dispatch<import("react").SetStateAction<PanelView>>;
|
|
25
26
|
orderId: string | undefined;
|
|
@@ -22,7 +22,7 @@ var PanelView;
|
|
|
22
22
|
PanelView[PanelView["ORDER_DETAILS"] = 4] = "ORDER_DETAILS";
|
|
23
23
|
PanelView[PanelView["LOADING"] = 5] = "LOADING";
|
|
24
24
|
})(PanelView || (exports.PanelView = PanelView = {}));
|
|
25
|
-
function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, }) {
|
|
25
|
+
function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, slippage = 0, }) {
|
|
26
26
|
const searchParams = (0, react_2.useSearchParamsSSR)();
|
|
27
27
|
const router = (0, react_2.useRouter)();
|
|
28
28
|
// Panel and order state
|
|
@@ -103,13 +103,15 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
103
103
|
if (anyspendQuote?.data?.currencyOut?.amount && anyspendQuote.data.currencyOut.currency?.decimals) {
|
|
104
104
|
const amount = anyspendQuote.data.currencyOut.amount;
|
|
105
105
|
const decimals = anyspendQuote.data.currencyOut.currency.decimals;
|
|
106
|
-
|
|
106
|
+
// Apply slippage (0-100) - reduce amount by slippage percentageFixed slippage value
|
|
107
|
+
const amountWithSlippage = (BigInt(amount) * BigInt(100 - slippage)) / BigInt(100);
|
|
108
|
+
const formattedAmount = (0, number_1.formatTokenAmount)(amountWithSlippage, decimals, 6, false);
|
|
107
109
|
setDstAmount(formattedAmount);
|
|
108
110
|
}
|
|
109
111
|
else {
|
|
110
112
|
setDstAmount("");
|
|
111
113
|
}
|
|
112
|
-
}, [anyspendQuote]);
|
|
114
|
+
}, [anyspendQuote, slippage]);
|
|
113
115
|
// Update useEffect for URL parameter to not override loadOrder
|
|
114
116
|
(0, react_3.useEffect)(() => {
|
|
115
117
|
if (loadOrder)
|
|
@@ -21,6 +21,7 @@ import { RecipientSelection } from "./common/RecipientSelection.js";
|
|
|
21
21
|
import { ESCROW_ABI } from "../../../anyspend/abis/escrow.js";
|
|
22
22
|
import { ArrowDown } from "lucide-react";
|
|
23
23
|
import { PanelOnramp } from "./common/PanelOnramp.js";
|
|
24
|
+
const SLIPPAGE_PERCENT = 3;
|
|
24
25
|
function generateEncodedDataForDepositHype(amount, beneficiary) {
|
|
25
26
|
invariant(BigInt(amount) > 0, "Amount must be greater than zero");
|
|
26
27
|
const encodedData = encodeFunctionData({
|
|
@@ -44,6 +45,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
44
45
|
onTransactionSuccess: onSuccess,
|
|
45
46
|
sourceTokenAddress,
|
|
46
47
|
sourceTokenChainId,
|
|
48
|
+
slippage: SLIPPAGE_PERCENT,
|
|
47
49
|
});
|
|
48
50
|
// Button state logic
|
|
49
51
|
const btnInfo = useMemo(() => {
|
|
@@ -127,7 +129,10 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
127
129
|
invariant(selectedRecipientAddress, "Recipient address is not found");
|
|
128
130
|
invariant(depositContractAddress, "Deposit contract address is not found");
|
|
129
131
|
const srcAmountBigInt = BigInt(activeInputAmountInWei);
|
|
130
|
-
|
|
132
|
+
// TODO: temp subtract 3% for slippage
|
|
133
|
+
const originalDepositAmountWei = anyspendQuote.data?.currencyOut?.amount || "0";
|
|
134
|
+
const depositAmountWei = ((BigInt(originalDepositAmountWei) * BigInt(100 - SLIPPAGE_PERCENT)) /
|
|
135
|
+
BigInt(100)).toString();
|
|
131
136
|
const encodedData = generateEncodedDataForDepositHype(depositAmountWei, selectedRecipientAddress);
|
|
132
137
|
createOrder({
|
|
133
138
|
recipientAddress: selectedRecipientAddress,
|
|
@@ -234,7 +239,6 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
234
239
|
setSelectedFiatPaymentMethod(method);
|
|
235
240
|
setActivePanel(PanelView.MAIN);
|
|
236
241
|
}, srcAmountOnRamp: srcAmount }));
|
|
237
|
-
console.log("activePanel", activePanel, orderId, oat);
|
|
238
242
|
// If showing token selection, render with panel transitions
|
|
239
243
|
return (_jsx(StyleRoot, { children: _jsx("div", { className: cn("anyspend-container font-inter mx-auto w-full max-w-[460px]", mode === "page" &&
|
|
240
244
|
"bg-as-surface-primary border-as-border-secondary overflow-hidden rounded-2xl border shadow-xl"), children: _jsx(TransitionPanel, { activeIndex: orderId
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { ALL_CHAINS, getChainName, getErrorDisplay, getExplorerTxUrl, getPaymentUrl, getStatusDisplay, isNativeToken, RELAY_ETH_ADDRESS, RELAY_SOLANA_MAINNET_CHAIN_ID, } from "../../../../anyspend/index.js";
|
|
3
|
+
import { ALL_CHAINS, DEPOSIT_HYPE_ACTION, getChainName, getErrorDisplay, getExplorerTxUrl, getPaymentUrl, getStatusDisplay, isNativeToken, RELAY_ETH_ADDRESS, RELAY_SOLANA_MAINNET_CHAIN_ID, } from "../../../../anyspend/index.js";
|
|
4
4
|
import { Badge, Button, CopyToClipboard, ShinyButton, Skeleton, TextLoop, TextShimmer, useAccountWallet, useModalStore, useProfile, useUnifiedChainSwitchAndExecute, } from "../../../../global-account/react/index.js";
|
|
5
5
|
import { useRouter, useSearchParams } from "../../../../shared/react/hooks/index.js";
|
|
6
6
|
import { cn } from "../../../../shared/utils/index.js";
|
|
@@ -43,6 +43,9 @@ function getOrderSuccessText({ order, tournament, formattedActualDstAmount, dstT
|
|
|
43
43
|
actionText = `funded ${tournament?.name}`;
|
|
44
44
|
return `Successfully ${actionText}`;
|
|
45
45
|
case "custom":
|
|
46
|
+
if (order.metadata.action === DEPOSIT_HYPE_ACTION) {
|
|
47
|
+
return `Successfully deposited ${formatTokenAmount(BigInt(order.payload?.amount || "0"), 18)} HYPE to ${recipient}`;
|
|
48
|
+
}
|
|
46
49
|
actionText = order.metadata.action || `executed contract`;
|
|
47
50
|
return `Successfully ${actionText}`;
|
|
48
51
|
default:
|
|
@@ -18,8 +18,9 @@ interface UseAnyspendFlowProps {
|
|
|
18
18
|
onTransactionSuccess?: () => void;
|
|
19
19
|
sourceTokenAddress?: string;
|
|
20
20
|
sourceTokenChainId?: number;
|
|
21
|
+
slippage?: number;
|
|
21
22
|
}
|
|
22
|
-
export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrder, isDepositMode, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, }: UseAnyspendFlowProps): {
|
|
23
|
+
export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrder, isDepositMode, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, slippage, }: UseAnyspendFlowProps): {
|
|
23
24
|
activePanel: PanelView;
|
|
24
25
|
setActivePanel: import("react").Dispatch<import("react").SetStateAction<PanelView>>;
|
|
25
26
|
orderId: string | undefined;
|
|
@@ -18,7 +18,7 @@ export var PanelView;
|
|
|
18
18
|
PanelView[PanelView["ORDER_DETAILS"] = 4] = "ORDER_DETAILS";
|
|
19
19
|
PanelView[PanelView["LOADING"] = 5] = "LOADING";
|
|
20
20
|
})(PanelView || (PanelView = {}));
|
|
21
|
-
export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, }) {
|
|
21
|
+
export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, slippage = 0, }) {
|
|
22
22
|
const searchParams = useSearchParamsSSR();
|
|
23
23
|
const router = useRouter();
|
|
24
24
|
// Panel and order state
|
|
@@ -99,13 +99,15 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
99
99
|
if (anyspendQuote?.data?.currencyOut?.amount && anyspendQuote.data.currencyOut.currency?.decimals) {
|
|
100
100
|
const amount = anyspendQuote.data.currencyOut.amount;
|
|
101
101
|
const decimals = anyspendQuote.data.currencyOut.currency.decimals;
|
|
102
|
-
|
|
102
|
+
// Apply slippage (0-100) - reduce amount by slippage percentageFixed slippage value
|
|
103
|
+
const amountWithSlippage = (BigInt(amount) * BigInt(100 - slippage)) / BigInt(100);
|
|
104
|
+
const formattedAmount = formatTokenAmount(amountWithSlippage, decimals, 6, false);
|
|
103
105
|
setDstAmount(formattedAmount);
|
|
104
106
|
}
|
|
105
107
|
else {
|
|
106
108
|
setDstAmount("");
|
|
107
109
|
}
|
|
108
|
-
}, [anyspendQuote]);
|
|
110
|
+
}, [anyspendQuote, slippage]);
|
|
109
111
|
// Update useEffect for URL parameter to not override loadOrder
|
|
110
112
|
useEffect(() => {
|
|
111
113
|
if (loadOrder)
|
|
@@ -18,8 +18,9 @@ interface UseAnyspendFlowProps {
|
|
|
18
18
|
onTransactionSuccess?: () => void;
|
|
19
19
|
sourceTokenAddress?: string;
|
|
20
20
|
sourceTokenChainId?: number;
|
|
21
|
+
slippage?: number;
|
|
21
22
|
}
|
|
22
|
-
export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrder, isDepositMode, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, }: UseAnyspendFlowProps): {
|
|
23
|
+
export declare function useAnyspendFlow({ paymentType, recipientAddress, loadOrder, isDepositMode, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, slippage, }: UseAnyspendFlowProps): {
|
|
23
24
|
activePanel: PanelView;
|
|
24
25
|
setActivePanel: import("react").Dispatch<import("react").SetStateAction<PanelView>>;
|
|
25
26
|
orderId: string | undefined;
|
package/package.json
CHANGED
|
@@ -22,6 +22,8 @@ import { ESCROW_ABI } from "@b3dotfun/sdk/anyspend/abis/escrow";
|
|
|
22
22
|
import { ArrowDown } from "lucide-react";
|
|
23
23
|
import { PanelOnramp } from "./common/PanelOnramp";
|
|
24
24
|
|
|
25
|
+
const SLIPPAGE_PERCENT = 3;
|
|
26
|
+
|
|
25
27
|
function generateEncodedDataForDepositHype(amount: string, beneficiary: string): string {
|
|
26
28
|
invariant(BigInt(amount) > 0, "Amount must be greater than zero");
|
|
27
29
|
const encodedData = encodeFunctionData({
|
|
@@ -107,6 +109,7 @@ function AnySpendDepositHypeInner({
|
|
|
107
109
|
onTransactionSuccess: onSuccess,
|
|
108
110
|
sourceTokenAddress,
|
|
109
111
|
sourceTokenChainId,
|
|
112
|
+
slippage: SLIPPAGE_PERCENT,
|
|
110
113
|
});
|
|
111
114
|
|
|
112
115
|
// Button state logic
|
|
@@ -308,7 +311,12 @@ function AnySpendDepositHypeInner({
|
|
|
308
311
|
invariant(depositContractAddress, "Deposit contract address is not found");
|
|
309
312
|
|
|
310
313
|
const srcAmountBigInt = BigInt(activeInputAmountInWei);
|
|
311
|
-
|
|
314
|
+
// TODO: temp subtract 3% for slippage
|
|
315
|
+
const originalDepositAmountWei = anyspendQuote.data?.currencyOut?.amount || "0";
|
|
316
|
+
const depositAmountWei = (
|
|
317
|
+
(BigInt(originalDepositAmountWei) * BigInt(100 - SLIPPAGE_PERCENT)) /
|
|
318
|
+
BigInt(100)
|
|
319
|
+
).toString();
|
|
312
320
|
const encodedData = generateEncodedDataForDepositHype(depositAmountWei, selectedRecipientAddress);
|
|
313
321
|
|
|
314
322
|
createOrder({
|
|
@@ -472,8 +480,6 @@ function AnySpendDepositHypeInner({
|
|
|
472
480
|
/>
|
|
473
481
|
);
|
|
474
482
|
|
|
475
|
-
console.log("activePanel", activePanel, orderId, oat);
|
|
476
|
-
|
|
477
483
|
// If showing token selection, render with panel transitions
|
|
478
484
|
return (
|
|
479
485
|
<StyleRoot>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
ALL_CHAINS,
|
|
5
|
+
DEPOSIT_HYPE_ACTION,
|
|
5
6
|
getChainName,
|
|
6
7
|
getErrorDisplay,
|
|
7
8
|
getExplorerTxUrl,
|
|
@@ -97,6 +98,9 @@ function getOrderSuccessText({
|
|
|
97
98
|
actionText = `funded ${tournament?.name}`;
|
|
98
99
|
return `Successfully ${actionText}`;
|
|
99
100
|
case "custom":
|
|
101
|
+
if (order.metadata.action === DEPOSIT_HYPE_ACTION) {
|
|
102
|
+
return `Successfully deposited ${formatTokenAmount(BigInt(order.payload?.amount || "0"), 18)} HYPE to ${recipient}`;
|
|
103
|
+
}
|
|
100
104
|
actionText = order.metadata.action || `executed contract`;
|
|
101
105
|
return `Successfully ${actionText}`;
|
|
102
106
|
default:
|
|
@@ -35,6 +35,7 @@ interface UseAnyspendFlowProps {
|
|
|
35
35
|
onTransactionSuccess?: () => void;
|
|
36
36
|
sourceTokenAddress?: string;
|
|
37
37
|
sourceTokenChainId?: number;
|
|
38
|
+
slippage?: number;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export function useAnyspendFlow({
|
|
@@ -46,6 +47,7 @@ export function useAnyspendFlow({
|
|
|
46
47
|
onTransactionSuccess,
|
|
47
48
|
sourceTokenAddress,
|
|
48
49
|
sourceTokenChainId,
|
|
50
|
+
slippage = 0,
|
|
49
51
|
}: UseAnyspendFlowProps) {
|
|
50
52
|
const searchParams = useSearchParamsSSR();
|
|
51
53
|
const router = useRouter();
|
|
@@ -144,12 +146,16 @@ export function useAnyspendFlow({
|
|
|
144
146
|
if (anyspendQuote?.data?.currencyOut?.amount && anyspendQuote.data.currencyOut.currency?.decimals) {
|
|
145
147
|
const amount = anyspendQuote.data.currencyOut.amount;
|
|
146
148
|
const decimals = anyspendQuote.data.currencyOut.currency.decimals;
|
|
147
|
-
|
|
149
|
+
|
|
150
|
+
// Apply slippage (0-100) - reduce amount by slippage percentageFixed slippage value
|
|
151
|
+
const amountWithSlippage = (BigInt(amount) * BigInt(100 - slippage)) / BigInt(100);
|
|
152
|
+
|
|
153
|
+
const formattedAmount = formatTokenAmount(amountWithSlippage, decimals, 6, false);
|
|
148
154
|
setDstAmount(formattedAmount);
|
|
149
155
|
} else {
|
|
150
156
|
setDstAmount("");
|
|
151
157
|
}
|
|
152
|
-
}, [anyspendQuote]);
|
|
158
|
+
}, [anyspendQuote, slippage]);
|
|
153
159
|
|
|
154
160
|
// Update useEffect for URL parameter to not override loadOrder
|
|
155
161
|
useEffect(() => {
|