@b3dotfun/sdk 0.0.7-alpha.25 → 0.0.7-alpha.27
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/index.d.ts +0 -2
- package/dist/cjs/anyspend/index.js +0 -4
- package/dist/cjs/anyspend/react/components/AnySpend.js +49 -48
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +39 -38
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +0 -40
- package/dist/cjs/anyspend/react/components/common/OrderHistory.js +6 -6
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +7 -7
- package/dist/cjs/anyspend/react/components/common/PanelOnrampPayment.js +9 -8
- package/dist/cjs/anyspend/react/components/common/PaymentStripeWeb2.js +14 -13
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampOrderStatus.js +0 -1
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +13 -12
- package/dist/cjs/anyspend/react/hooks/index.d.ts +0 -2
- package/dist/cjs/anyspend/react/hooks/index.js +0 -2
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +0 -70
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +0 -70
- package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +2 -2
- package/dist/cjs/anyspend/services/anyspend.d.ts +1 -39
- package/dist/cjs/anyspend/services/anyspend.js +0 -13
- package/dist/cjs/anyspend/types/index.d.ts +0 -1
- package/dist/cjs/anyspend/types/index.js +0 -1
- package/dist/cjs/anyspend/types/order.d.ts +0 -200
- package/dist/cjs/anyspend/types/order.js +1 -6
- package/dist/cjs/anyspend/types/req-res/createOrder.d.ts +0 -235
- package/dist/cjs/anyspend/types/req-res/getOrderAndTransactions.d.ts +0 -305
- package/dist/cjs/anyspend/types/req-res/getOrderHistory.d.ts +0 -235
- package/dist/cjs/anyspend/types/req-res/index.d.ts +0 -1
- package/dist/cjs/anyspend/types/req-res/index.js +0 -1
- package/dist/cjs/anyspend/utils/format.js +0 -4
- package/dist/cjs/global-account/react/components/custom/Button.d.ts +2 -2
- package/dist/cjs/global-account/react/components/ui/button.d.ts +1 -1
- package/dist/cjs/global-account/react/components/ui/command.d.ts +7 -7
- package/dist/cjs/shared/constants/chains/b3Chain.d.ts +1 -1
- package/dist/cjs/shared/constants/chains/supported.d.ts +14 -14
- package/dist/cjs/shared/utils/insights.d.ts +1 -1
- package/dist/cjs/shared/utils/simplehash.d.ts +2 -2
- package/dist/esm/anyspend/index.d.ts +0 -2
- package/dist/esm/anyspend/index.js +0 -4
- package/dist/esm/anyspend/react/components/AnySpend.js +2 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +2 -1
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +0 -40
- package/dist/esm/anyspend/react/components/common/OrderHistory.js +1 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +1 -1
- package/dist/esm/anyspend/react/components/common/PanelOnrampPayment.js +2 -1
- package/dist/esm/anyspend/react/components/common/PaymentStripeWeb2.js +2 -1
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampOrderStatus.js +0 -1
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +2 -1
- package/dist/esm/anyspend/react/hooks/index.d.ts +0 -2
- package/dist/esm/anyspend/react/hooks/index.js +0 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +0 -70
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +0 -70
- package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +2 -2
- package/dist/esm/anyspend/services/anyspend.d.ts +1 -39
- package/dist/esm/anyspend/services/anyspend.js +0 -13
- package/dist/esm/anyspend/types/index.d.ts +0 -1
- package/dist/esm/anyspend/types/index.js +0 -1
- package/dist/esm/anyspend/types/order.d.ts +0 -200
- package/dist/esm/anyspend/types/order.js +1 -6
- package/dist/esm/anyspend/types/req-res/createOrder.d.ts +0 -235
- package/dist/esm/anyspend/types/req-res/getOrderAndTransactions.d.ts +0 -305
- package/dist/esm/anyspend/types/req-res/getOrderHistory.d.ts +0 -235
- package/dist/esm/anyspend/types/req-res/index.d.ts +0 -1
- package/dist/esm/anyspend/types/req-res/index.js +0 -1
- package/dist/esm/anyspend/utils/format.js +0 -4
- package/dist/esm/global-account/react/components/custom/Button.d.ts +2 -2
- package/dist/esm/global-account/react/components/ui/button.d.ts +1 -1
- package/dist/esm/global-account/react/components/ui/command.d.ts +7 -7
- package/dist/esm/shared/constants/chains/b3Chain.d.ts +1 -1
- package/dist/esm/shared/constants/chains/supported.d.ts +14 -14
- package/dist/esm/shared/utils/insights.d.ts +1 -1
- package/dist/esm/shared/utils/simplehash.d.ts +2 -2
- package/dist/types/anyspend/index.d.ts +0 -2
- package/dist/types/anyspend/react/hooks/index.d.ts +0 -2
- package/dist/types/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +0 -70
- package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +0 -70
- package/dist/types/anyspend/react/hooks/useSigMint.d.ts +2 -2
- package/dist/types/anyspend/services/anyspend.d.ts +1 -39
- package/dist/types/anyspend/types/index.d.ts +0 -1
- package/dist/types/anyspend/types/order.d.ts +0 -200
- package/dist/types/anyspend/types/req-res/createOrder.d.ts +0 -235
- package/dist/types/anyspend/types/req-res/getOrderAndTransactions.d.ts +0 -305
- package/dist/types/anyspend/types/req-res/getOrderHistory.d.ts +0 -235
- package/dist/types/anyspend/types/req-res/index.d.ts +0 -1
- package/dist/types/global-account/react/components/custom/Button.d.ts +2 -2
- package/dist/types/global-account/react/components/ui/button.d.ts +1 -1
- package/dist/types/global-account/react/components/ui/command.d.ts +7 -7
- package/dist/types/shared/constants/chains/b3Chain.d.ts +1 -1
- package/dist/types/shared/constants/chains/supported.d.ts +14 -14
- package/dist/types/shared/utils/insights.d.ts +1 -1
- package/dist/types/shared/utils/simplehash.d.ts +2 -2
- package/package.json +1 -1
- package/src/anyspend/index.ts +0 -6
- package/src/anyspend/react/components/AnySpend.tsx +2 -6
- package/src/anyspend/react/components/AnySpendCustom.tsx +4 -2
- package/src/anyspend/react/components/common/OrderDetails.tsx +0 -46
- package/src/anyspend/react/components/common/OrderHistory.tsx +1 -1
- package/src/anyspend/react/components/common/PanelOnramp.tsx +1 -1
- package/src/anyspend/react/components/common/PanelOnrampPayment.tsx +2 -10
- package/src/anyspend/react/components/common/PaymentStripeWeb2.tsx +2 -1
- package/src/anyspend/react/components/webview/WebviewOnrampOrderStatus.tsx +0 -1
- package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +1 -3
- package/src/anyspend/react/hooks/index.ts +0 -2
- package/src/anyspend/services/anyspend.ts +0 -18
- package/src/anyspend/types/index.ts +0 -1
- package/src/anyspend/types/order.ts +1 -8
- package/src/anyspend/types/req-res/index.ts +0 -1
- package/src/anyspend/utils/format.ts +0 -5
- package/dist/cjs/anyspend/react/hooks/useAnyspendSendPermitData.d.ts +0 -16
- package/dist/cjs/anyspend/react/hooks/useAnyspendSendPermitData.js +0 -39
- package/dist/cjs/anyspend/react/hooks/usePermitData.d.ts +0 -92
- package/dist/cjs/anyspend/react/hooks/usePermitData.js +0 -158
- package/dist/cjs/anyspend/types/permit.d.ts +0 -21
- package/dist/cjs/anyspend/types/permit.js +0 -11
- package/dist/cjs/anyspend/types/req-res/sendPermitData.d.ts +0 -66
- package/dist/cjs/anyspend/types/req-res/sendPermitData.js +0 -11
- package/dist/esm/anyspend/react/hooks/useAnyspendSendPermitData.d.ts +0 -16
- package/dist/esm/anyspend/react/hooks/useAnyspendSendPermitData.js +0 -36
- package/dist/esm/anyspend/react/hooks/usePermitData.d.ts +0 -92
- package/dist/esm/anyspend/react/hooks/usePermitData.js +0 -154
- package/dist/esm/anyspend/types/permit.d.ts +0 -21
- package/dist/esm/anyspend/types/permit.js +0 -8
- package/dist/esm/anyspend/types/req-res/sendPermitData.d.ts +0 -66
- package/dist/esm/anyspend/types/req-res/sendPermitData.js +0 -8
- package/dist/types/anyspend/react/hooks/useAnyspendSendPermitData.d.ts +0 -16
- package/dist/types/anyspend/react/hooks/usePermitData.d.ts +0 -92
- package/dist/types/anyspend/types/permit.d.ts +0 -21
- package/dist/types/anyspend/types/req-res/sendPermitData.d.ts +0 -66
- package/src/anyspend/react/hooks/useAnyspendSendPermitData.ts +0 -38
- package/src/anyspend/react/hooks/usePermitData.ts +0 -183
- package/src/anyspend/types/permit.ts +0 -10
- package/src/anyspend/types/req-res/sendPermitData.ts +0 -10
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { chainIdToPublicClient, getMulticall3Address, isEvmChain, isNativeToken } from "@b3dotfun/sdk/anyspend/utils";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import { Address, Hex } from "viem";
|
|
4
|
-
import { ABI_USDC_BASE } from "@b3dotfun/sdk/anyspend/abis/abi-usdc-base";
|
|
5
|
-
|
|
6
|
-
export type GetPermitDataParams = {
|
|
7
|
-
chainId: number;
|
|
8
|
-
tokenAddress: Hex;
|
|
9
|
-
ownerAddress: Hex | undefined;
|
|
10
|
-
amount: bigint;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// EIP-5267 ABI for eip712Domain function
|
|
14
|
-
const EIP5267_ABI = [
|
|
15
|
-
{
|
|
16
|
-
inputs: [],
|
|
17
|
-
name: "eip712Domain",
|
|
18
|
-
outputs: [
|
|
19
|
-
{ name: "fields", type: "bytes1" },
|
|
20
|
-
{ name: "name", type: "string" },
|
|
21
|
-
{ name: "version", type: "string" },
|
|
22
|
-
{ name: "chainId", type: "uint256" },
|
|
23
|
-
{ name: "verifyingContract", type: "address" },
|
|
24
|
-
{ name: "salt", type: "bytes32" },
|
|
25
|
-
],
|
|
26
|
-
stateMutability: "view",
|
|
27
|
-
type: "function",
|
|
28
|
-
},
|
|
29
|
-
] as const;
|
|
30
|
-
|
|
31
|
-
export async function getPermitData(p: GetPermitDataParams) {
|
|
32
|
-
console.log("Start getting permit data...");
|
|
33
|
-
|
|
34
|
-
if (!isEvmChain(p.chainId) || isNativeToken(p.tokenAddress) || !p.ownerAddress) {
|
|
35
|
-
return {
|
|
36
|
-
canPermit: false,
|
|
37
|
-
data: null,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const publicClient = chainIdToPublicClient(p.chainId);
|
|
42
|
-
|
|
43
|
-
const balance = await publicClient.readContract({
|
|
44
|
-
address: p.tokenAddress,
|
|
45
|
-
abi: ABI_USDC_BASE,
|
|
46
|
-
functionName: "balanceOf",
|
|
47
|
-
args: [p.ownerAddress],
|
|
48
|
-
});
|
|
49
|
-
if (balance < p.amount) {
|
|
50
|
-
return {
|
|
51
|
-
canPermit: false,
|
|
52
|
-
data: null,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Domain parameters
|
|
57
|
-
let name: string;
|
|
58
|
-
let version: string = "1"; // Default version for EIP-2612 (used by Uniswap V2 reference implementation)
|
|
59
|
-
|
|
60
|
-
// Try to get domain information using EIP-5267 (eip712Domain function)
|
|
61
|
-
try {
|
|
62
|
-
const domainData = await publicClient.readContract({
|
|
63
|
-
address: p.tokenAddress,
|
|
64
|
-
abi: EIP5267_ABI,
|
|
65
|
-
functionName: "eip712Domain",
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
console.log("Found EIP-5267 eip712Domain function");
|
|
69
|
-
name = domainData[1]; // name is the second return value
|
|
70
|
-
version = domainData[2]; // version is the third return value
|
|
71
|
-
|
|
72
|
-
console.log("Contract domain data from EIP-5267:");
|
|
73
|
-
console.log("- name:", name);
|
|
74
|
-
console.log("- version:", version);
|
|
75
|
-
console.log("- chainId:", domainData[3]);
|
|
76
|
-
console.log("- verifyingContract:", domainData[4]);
|
|
77
|
-
} catch (error) {
|
|
78
|
-
console.log("[EIP-5267] eip712Domain function not found, falling back to individual calls");
|
|
79
|
-
|
|
80
|
-
// Fallback: get name from contract
|
|
81
|
-
name = await publicClient.readContract({
|
|
82
|
-
address: p.tokenAddress,
|
|
83
|
-
abi: ABI_USDC_BASE,
|
|
84
|
-
functionName: "name",
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// Try to get version from contract
|
|
88
|
-
try {
|
|
89
|
-
version = await publicClient.readContract({
|
|
90
|
-
address: p.tokenAddress,
|
|
91
|
-
abi: ABI_USDC_BASE,
|
|
92
|
-
functionName: "version",
|
|
93
|
-
});
|
|
94
|
-
} catch (error) {
|
|
95
|
-
console.log(`Function "version" not found, using default version "1" (standard for EIP-2612)`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Fetch the PERMIT_TYPEHASH - important for ensuring our structure matches the contract
|
|
100
|
-
const permitTypeHash = await publicClient
|
|
101
|
-
.readContract({
|
|
102
|
-
address: p.tokenAddress,
|
|
103
|
-
abi: ABI_USDC_BASE,
|
|
104
|
-
functionName: "PERMIT_TYPEHASH",
|
|
105
|
-
})
|
|
106
|
-
.catch(() => {
|
|
107
|
-
console.log("PERMIT_TYPEHASH not directly accessible, using standard EIP-2612 value");
|
|
108
|
-
return "0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9" as `0x${string}`;
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// Fetch the DOMAIN_SEPARATOR - critical for signature validation
|
|
112
|
-
const contractDomainSeparator = await publicClient.readContract({
|
|
113
|
-
address: p.tokenAddress,
|
|
114
|
-
abi: ABI_USDC_BASE,
|
|
115
|
-
functionName: "DOMAIN_SEPARATOR",
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
console.log("Contract name:", name);
|
|
119
|
-
console.log("Contract version:", version);
|
|
120
|
-
console.log("Contract PERMIT_TYPEHASH:", permitTypeHash);
|
|
121
|
-
console.log("Contract DOMAIN_SEPARATOR:", contractDomainSeparator);
|
|
122
|
-
|
|
123
|
-
// Domain data for EIP-712 signature
|
|
124
|
-
const domain = {
|
|
125
|
-
name,
|
|
126
|
-
version,
|
|
127
|
-
chainId: p.chainId,
|
|
128
|
-
verifyingContract: p.tokenAddress,
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// EIP-2612 Permit type definition
|
|
132
|
-
// This must match the structure used to compute the PERMIT_TYPEHASH in the contract
|
|
133
|
-
const PermitType = [
|
|
134
|
-
{ name: "owner", type: "address" },
|
|
135
|
-
{ name: "spender", type: "address" },
|
|
136
|
-
{ name: "value", type: "uint256" },
|
|
137
|
-
{ name: "nonce", type: "uint256" },
|
|
138
|
-
{ name: "deadline", type: "uint256" },
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
const multicall3 = getMulticall3Address(p.chainId);
|
|
142
|
-
|
|
143
|
-
const nonce = await publicClient.readContract({
|
|
144
|
-
address: p.tokenAddress,
|
|
145
|
-
abi: ABI_USDC_BASE,
|
|
146
|
-
functionName: "nonces",
|
|
147
|
-
args: [p.ownerAddress],
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const deadlineInSeconds = BigInt(Math.floor(Date.now() / 1000) + 60 * 60); // 60 minutes
|
|
151
|
-
|
|
152
|
-
// Permit data to sign
|
|
153
|
-
const messageToSign = {
|
|
154
|
-
owner: p.ownerAddress,
|
|
155
|
-
spender: multicall3 as Address,
|
|
156
|
-
value: p.amount,
|
|
157
|
-
nonce,
|
|
158
|
-
deadline: deadlineInSeconds,
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
canPermit: true,
|
|
163
|
-
data: {
|
|
164
|
-
domain,
|
|
165
|
-
types: { Permit: PermitType },
|
|
166
|
-
messageToSign,
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function usePermitData(p: GetPermitDataParams) {
|
|
172
|
-
const { data, isLoading, error, refetch } = useQuery({
|
|
173
|
-
queryKey: ["usePermitData", p.chainId, p.tokenAddress],
|
|
174
|
-
queryFn: () => getPermitData(p),
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
return {
|
|
178
|
-
permitData: data,
|
|
179
|
-
isCheckingPermit: isLoading,
|
|
180
|
-
checkPermitError: error,
|
|
181
|
-
recheckPermit: refetch,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { zPermit } from "../permit";
|
|
3
|
-
|
|
4
|
-
export const zSendPermitDataRequest = z.object({
|
|
5
|
-
body: z.object({
|
|
6
|
-
orderId: z.string(),
|
|
7
|
-
permitData: zPermit,
|
|
8
|
-
}),
|
|
9
|
-
});
|
|
10
|
-
export type SendPermitDataRequestBody = z.infer<typeof zSendPermitDataRequest.shape.body>;
|