@smoothsend/sdk 2.3.3 → 2.3.4
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/avax/SmoothSendAvaxClient.d.ts +4 -2
- package/dist/avax/SmoothSendAvaxClient.d.ts.map +1 -1
- package/dist/avax/index.cjs +114 -28
- package/dist/avax/index.cjs.map +1 -1
- package/dist/avax/index.d.ts +57 -6
- package/dist/avax/index.d.ts.map +1 -1
- package/dist/avax/index.js +113 -29
- package/dist/avax/index.js.map +1 -1
- package/dist/avax/privySigner.d.ts +12 -0
- package/dist/avax/privySigner.d.ts.map +1 -0
- package/dist/avax/types.d.ts +6 -0
- package/dist/avax/types.d.ts.map +1 -1
- package/dist/avax/useSmoothSendAvax.d.ts +6 -2
- package/dist/avax/useSmoothSendAvax.d.ts.map +1 -1
- package/dist/avax/useSmoothSendPrivyWrite.d.ts +35 -0
- package/dist/avax/useSmoothSendPrivyWrite.d.ts.map +1 -0
- package/dist/avax/useSmoothSendWrite.d.ts +11 -4
- package/dist/avax/useSmoothSendWrite.d.ts.map +1 -1
- package/dist/avax-entry.d.ts +1 -1
- package/dist/avax-entry.d.ts.map +1 -1
- package/dist/chunks/shared-Cgb7mhwI.d.ts +471 -0
- package/dist/index.cjs +43 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +43 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import { PublicClient, WalletClient, Address, Hex } from 'viem';
|
|
2
|
+
import { UserOperation } from 'viem/account-abstraction';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* AVAX / ERC-4337 v0.7 types aligned with `chains/avax/bundler` API shapes.
|
|
8
|
+
*/
|
|
9
|
+
type AvaxSponsorshipMode = 'developer-sponsored' | 'user-pays-erc20';
|
|
10
|
+
type UserOpSignerAvax = (args: {
|
|
11
|
+
hash: `0x${string}`;
|
|
12
|
+
chainId: number;
|
|
13
|
+
entryPoint: `0x${string}`;
|
|
14
|
+
sender: `0x${string}`;
|
|
15
|
+
}) => Promise<string>;
|
|
16
|
+
/** Unpacked UserOperation as accepted by the bundler JSON-RPC + paymaster/sign */
|
|
17
|
+
interface UserOperationAvax {
|
|
18
|
+
sender: string;
|
|
19
|
+
nonce: string;
|
|
20
|
+
factory?: string;
|
|
21
|
+
factoryData?: string;
|
|
22
|
+
initCode?: string;
|
|
23
|
+
callData: string;
|
|
24
|
+
callGasLimit?: string;
|
|
25
|
+
verificationGasLimit?: string;
|
|
26
|
+
preVerificationGas?: string;
|
|
27
|
+
maxFeePerGas?: string;
|
|
28
|
+
maxPriorityFeePerGas?: string;
|
|
29
|
+
paymaster?: string;
|
|
30
|
+
paymasterVerificationGasLimit?: string;
|
|
31
|
+
paymasterPostOpGasLimit?: string;
|
|
32
|
+
paymasterData?: string;
|
|
33
|
+
accountGasLimits?: string;
|
|
34
|
+
gasFees?: string;
|
|
35
|
+
paymasterAndData?: string;
|
|
36
|
+
/** Empty (`0x`) until the wallet/account signs the hash UserOp */
|
|
37
|
+
signature: string;
|
|
38
|
+
}
|
|
39
|
+
interface GasEstimateAvax {
|
|
40
|
+
preVerificationGas: string;
|
|
41
|
+
verificationGasLimit: string;
|
|
42
|
+
callGasLimit: string;
|
|
43
|
+
paymasterVerificationGasLimit?: string;
|
|
44
|
+
paymasterPostOpGasLimit?: string;
|
|
45
|
+
}
|
|
46
|
+
interface PaymasterSignRequestAvax {
|
|
47
|
+
mode: AvaxSponsorshipMode;
|
|
48
|
+
userOp: UserOperationAvax;
|
|
49
|
+
token?: string;
|
|
50
|
+
receiver?: string;
|
|
51
|
+
precheckBalance?: boolean;
|
|
52
|
+
prepaymentRequired?: boolean;
|
|
53
|
+
allowAnyBundler?: boolean;
|
|
54
|
+
sponsorUUID?: string;
|
|
55
|
+
}
|
|
56
|
+
interface AvaxFeePreview {
|
|
57
|
+
predictedGasCostWei: string;
|
|
58
|
+
predictedTokenFee: string;
|
|
59
|
+
minTokenFee: string;
|
|
60
|
+
variableTokenFee: string;
|
|
61
|
+
floorApplied: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface AvaxHashTypes {
|
|
64
|
+
sendUserOperationResult?: 'userOpHash';
|
|
65
|
+
explorerTxLinkRequires?: 'transactionHash';
|
|
66
|
+
userOpHash?: 'userOpHash';
|
|
67
|
+
transactionHash?: 'transactionHash';
|
|
68
|
+
}
|
|
69
|
+
interface PaymasterSignResponseAvax {
|
|
70
|
+
success: boolean;
|
|
71
|
+
requestId?: string;
|
|
72
|
+
network?: string;
|
|
73
|
+
hashTypes?: AvaxHashTypes;
|
|
74
|
+
paymasterAndData: string;
|
|
75
|
+
paymasterData?: string;
|
|
76
|
+
signature?: string;
|
|
77
|
+
exchangeRate?: string;
|
|
78
|
+
feePreview?: AvaxFeePreview;
|
|
79
|
+
paymasterDataParts?: Record<string, string>;
|
|
80
|
+
error?: string;
|
|
81
|
+
}
|
|
82
|
+
interface UserOperationReceiptAvax {
|
|
83
|
+
userOpHash: string;
|
|
84
|
+
sender: string;
|
|
85
|
+
nonce: string;
|
|
86
|
+
paymaster: string;
|
|
87
|
+
success: boolean;
|
|
88
|
+
actualGasCost: string;
|
|
89
|
+
actualGasUsed: string;
|
|
90
|
+
reason?: string;
|
|
91
|
+
logs: unknown[];
|
|
92
|
+
receipt: {
|
|
93
|
+
transactionHash: string;
|
|
94
|
+
blockNumber: number;
|
|
95
|
+
blockHash: string;
|
|
96
|
+
};
|
|
97
|
+
hashTypes?: AvaxHashTypes;
|
|
98
|
+
}
|
|
99
|
+
/** Partial UserOp before estimate/paymaster (signature optional, usually `0x` until wallet signs). */
|
|
100
|
+
type SponsoredUserOpDraftAvax = Omit<UserOperationAvax, 'signature'> & {
|
|
101
|
+
signature?: string;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Public gateway defaults for Avalanche AA (no API key).
|
|
106
|
+
*/
|
|
107
|
+
/** Canonical ERC-4337 EntryPoint v0.7 on Fuji / Avalanche C-Chain */
|
|
108
|
+
declare const ENTRY_POINT_V07_ADDRESS: "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
|
|
109
|
+
type AvaxAaPublicDefaults = {
|
|
110
|
+
success?: boolean;
|
|
111
|
+
simpleAccountFactoryFuji: `0x${string}` | null;
|
|
112
|
+
simpleAccountFactoryMainnet: `0x${string}` | null;
|
|
113
|
+
entryPointV07: typeof ENTRY_POINT_V07_ADDRESS;
|
|
114
|
+
paymasterFuji: `0x${string}` | null;
|
|
115
|
+
paymasterMainnet: `0x${string}` | null;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Fetch SimpleAccount factory and Paymaster hints from SmoothSend gateway (GET; no auth).
|
|
119
|
+
*/
|
|
120
|
+
declare function fetchAvaxAaPublicDefaults(gatewayUrl?: string): Promise<AvaxAaPublicDefaults>;
|
|
121
|
+
|
|
122
|
+
/** Options for {@link SmoothSendAvaxSubmitter.submitSponsoredUserOperation} */
|
|
123
|
+
interface SubmitSponsoredAvaxUserOpOptions {
|
|
124
|
+
/** Sender must match your smart account; nonce/callData/fees from your app */
|
|
125
|
+
userOp: SponsoredUserOpDraftAvax;
|
|
126
|
+
/** Wallet / viem / ethers signs the UserOp hash your stack expects */
|
|
127
|
+
signUserOp: (userOp: UserOperationAvax) => Promise<string>;
|
|
128
|
+
mode?: AvaxSponsorshipMode;
|
|
129
|
+
/** Defaults to first entry point from `eth_supportedEntryPoints` */
|
|
130
|
+
entryPoint?: string;
|
|
131
|
+
/** Extra `paymaster/sign` fields (`token`, `receiver`, …) for user-pays-ERC20 */
|
|
132
|
+
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
133
|
+
/** @default true */
|
|
134
|
+
waitForReceipt?: boolean;
|
|
135
|
+
receiptPoll?: {
|
|
136
|
+
pollMs?: number;
|
|
137
|
+
timeoutMs?: number;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
interface EstimateUserPaysFeeAvaxOptions {
|
|
141
|
+
/** Draft UserOperation (same shape as submit flow before signing) */
|
|
142
|
+
userOp: SponsoredUserOpDraftAvax;
|
|
143
|
+
/** Optional entrypoint, defaults to eth_supportedEntryPoints()[0] */
|
|
144
|
+
entryPoint?: string;
|
|
145
|
+
/** Optional paymaster params such as token/receiver overrides */
|
|
146
|
+
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
147
|
+
}
|
|
148
|
+
interface SmoothSendAvaxSubmitterConfig {
|
|
149
|
+
apiKey: string;
|
|
150
|
+
network?: 'testnet' | 'mainnet';
|
|
151
|
+
gatewayUrl?: string;
|
|
152
|
+
timeout?: number;
|
|
153
|
+
/**
|
|
154
|
+
* Gateway chain routing bucket. Default `avalanche` matches `core/gateway` routing.
|
|
155
|
+
*/
|
|
156
|
+
chain?: string;
|
|
157
|
+
/**
|
|
158
|
+
* Public keys (`pk_nogas_*`) require an `Origin` header matching your project's allowed CORS origins.
|
|
159
|
+
* Set this for Node/scripts (e.g. `http://localhost:5173`). Browsers send Origin automatically.
|
|
160
|
+
*/
|
|
161
|
+
corsOrigin?: string;
|
|
162
|
+
}
|
|
163
|
+
declare class SmoothSendAvaxSubmitter {
|
|
164
|
+
private readonly config;
|
|
165
|
+
private readonly http;
|
|
166
|
+
private rpcId;
|
|
167
|
+
constructor(config: SmoothSendAvaxSubmitterConfig);
|
|
168
|
+
getConfig(): Readonly<SmoothSendAvaxSubmitterConfig>;
|
|
169
|
+
/** Merge gas estimate fields into a partial UserOp */
|
|
170
|
+
static applyGasEstimate(userOp: UserOperationAvax, gas: GasEstimateAvax): UserOperationAvax;
|
|
171
|
+
/** Attach packed paymaster data returned from {@link paymasterSign} */
|
|
172
|
+
static applyPaymasterAndData(userOp: UserOperationAvax, paymasterAndData: string): UserOperationAvax;
|
|
173
|
+
getChainId(): Promise<string>;
|
|
174
|
+
getSupportedEntryPoints(): Promise<string[]>;
|
|
175
|
+
estimateUserOperationGas(userOp: UserOperationAvax, entryPoint: string): Promise<GasEstimateAvax>;
|
|
176
|
+
sendUserOperation(userOp: UserOperationAvax, entryPoint: string): Promise<string>;
|
|
177
|
+
getUserOperationReceipt(userOpHash: string): Promise<UserOperationReceiptAvax | null>;
|
|
178
|
+
waitForUserOperationReceipt(userOpHash: string, options?: {
|
|
179
|
+
pollMs?: number;
|
|
180
|
+
timeoutMs?: number;
|
|
181
|
+
}): Promise<UserOperationReceiptAvax | null>;
|
|
182
|
+
paymasterSign(body: PaymasterSignRequestAvax): Promise<PaymasterSignResponseAvax>;
|
|
183
|
+
/**
|
|
184
|
+
* Preflight fee estimate for `user-pays-erc20` mode.
|
|
185
|
+
*
|
|
186
|
+
* This performs:
|
|
187
|
+
* 1) `eth_estimateUserOperationGas`
|
|
188
|
+
* 2) `paymaster/sign` in `user-pays-erc20` mode
|
|
189
|
+
* and returns `feePreview` when available.
|
|
190
|
+
*/
|
|
191
|
+
estimateUserPaysFee(opts: EstimateUserPaysFeeAvaxOptions): Promise<{
|
|
192
|
+
entryPoint: string;
|
|
193
|
+
userOp: UserOperationAvax;
|
|
194
|
+
gas: GasEstimateAvax;
|
|
195
|
+
exchangeRate?: string;
|
|
196
|
+
feePreview?: AvaxFeePreview;
|
|
197
|
+
}>;
|
|
198
|
+
getBundlerHealth(): Promise<unknown>;
|
|
199
|
+
/** Fetch public AA addresses (Factory, Paymaster) from gateway. */
|
|
200
|
+
getPublicAaDefaults(): Promise<AvaxAaPublicDefaults>;
|
|
201
|
+
/**
|
|
202
|
+
* One call: estimate gas → paymaster/sign → merge → your sign → send → (optional) wait for receipt.
|
|
203
|
+
*/
|
|
204
|
+
submitSponsoredUserOperation(opts: SubmitSponsoredAvaxUserOpOptions): Promise<{
|
|
205
|
+
userOpHash: string;
|
|
206
|
+
receipt: UserOperationReceiptAvax | null;
|
|
207
|
+
}>;
|
|
208
|
+
private rpc;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* @alias {@link SmoothSendAvaxSubmitter}
|
|
212
|
+
*/
|
|
213
|
+
declare const AvaxSubmitter: typeof SmoothSendAvaxSubmitter;
|
|
214
|
+
declare function createSmoothSendAvaxSubmitter(config: SmoothSendAvaxSubmitterConfig): SmoothSendAvaxSubmitter;
|
|
215
|
+
|
|
216
|
+
interface SmoothSendAvaxClientConfig {
|
|
217
|
+
apiKey: string;
|
|
218
|
+
network?: 'testnet' | 'mainnet';
|
|
219
|
+
gatewayUrl?: string;
|
|
220
|
+
timeout?: number;
|
|
221
|
+
chain?: string;
|
|
222
|
+
corsOrigin?: string;
|
|
223
|
+
publicClient: PublicClient;
|
|
224
|
+
walletClient?: WalletClient;
|
|
225
|
+
ownerAddress?: Address;
|
|
226
|
+
signUserOpHash?: UserOpSignerAvax;
|
|
227
|
+
smartAccountAddress?: Address;
|
|
228
|
+
accountFactory?: Address;
|
|
229
|
+
accountSalt?: bigint;
|
|
230
|
+
}
|
|
231
|
+
interface SimpleCallInput {
|
|
232
|
+
to: Address;
|
|
233
|
+
data?: Hex;
|
|
234
|
+
value?: bigint;
|
|
235
|
+
}
|
|
236
|
+
declare class SmoothSendAvaxClient {
|
|
237
|
+
readonly submitter: SmoothSendAvaxSubmitter;
|
|
238
|
+
readonly config: SmoothSendAvaxClientConfig;
|
|
239
|
+
constructor(config: SmoothSendAvaxClientConfig);
|
|
240
|
+
submitCall(args: {
|
|
241
|
+
call: SimpleCallInput;
|
|
242
|
+
mode?: AvaxSponsorshipMode;
|
|
243
|
+
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
244
|
+
smartAccountAddress?: Address;
|
|
245
|
+
accountFactory?: Address;
|
|
246
|
+
accountSalt?: bigint;
|
|
247
|
+
waitForReceipt?: boolean;
|
|
248
|
+
}): Promise<{
|
|
249
|
+
userOpHash: string;
|
|
250
|
+
transactionHash: string | undefined;
|
|
251
|
+
receipt: UserOperationReceiptAvax | null;
|
|
252
|
+
}>;
|
|
253
|
+
submitCalls(args: {
|
|
254
|
+
calls: SimpleCallInput[];
|
|
255
|
+
mode?: AvaxSponsorshipMode;
|
|
256
|
+
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
257
|
+
smartAccountAddress?: Address;
|
|
258
|
+
accountFactory?: Address;
|
|
259
|
+
accountSalt?: bigint;
|
|
260
|
+
waitForReceipt?: boolean;
|
|
261
|
+
}): Promise<{
|
|
262
|
+
userOpHash: string;
|
|
263
|
+
transactionHash: string | undefined;
|
|
264
|
+
receipt: UserOperationReceiptAvax | null;
|
|
265
|
+
}>;
|
|
266
|
+
estimateUserPaysFee(args: {
|
|
267
|
+
calls: SimpleCallInput[];
|
|
268
|
+
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
269
|
+
smartAccountAddress?: Address;
|
|
270
|
+
accountFactory?: Address;
|
|
271
|
+
accountSalt?: bigint;
|
|
272
|
+
}): Promise<{
|
|
273
|
+
feePreview?: AvaxFeePreview;
|
|
274
|
+
exchangeRate?: string;
|
|
275
|
+
entryPoint: string;
|
|
276
|
+
}>;
|
|
277
|
+
private buildDraft;
|
|
278
|
+
private signUserOpHash;
|
|
279
|
+
}
|
|
280
|
+
declare function createSmoothSendAvaxClient(config: SmoothSendAvaxClientConfig): SmoothSendAvaxClient;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Viem helpers for ERC-4337 v0.7 + common smart-account `execute` encoding.
|
|
284
|
+
* Peer dependency: `viem` (optional install).
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
/** Typical SimpleAccount-style `execute(dest,value,func)`. */
|
|
288
|
+
declare const avaxExecuteAbi: readonly [{
|
|
289
|
+
readonly name: "execute";
|
|
290
|
+
readonly type: "function";
|
|
291
|
+
readonly stateMutability: "nonpayable";
|
|
292
|
+
readonly inputs: readonly [{
|
|
293
|
+
readonly name: "dest";
|
|
294
|
+
readonly type: "address";
|
|
295
|
+
}, {
|
|
296
|
+
readonly name: "value";
|
|
297
|
+
readonly type: "uint256";
|
|
298
|
+
}, {
|
|
299
|
+
readonly name: "func";
|
|
300
|
+
readonly type: "bytes";
|
|
301
|
+
}];
|
|
302
|
+
readonly outputs: readonly [];
|
|
303
|
+
}, {
|
|
304
|
+
readonly name: "executeBatch";
|
|
305
|
+
readonly type: "function";
|
|
306
|
+
readonly stateMutability: "nonpayable";
|
|
307
|
+
readonly inputs: readonly [{
|
|
308
|
+
readonly name: "dest";
|
|
309
|
+
readonly type: "address[]";
|
|
310
|
+
}, {
|
|
311
|
+
readonly name: "value";
|
|
312
|
+
readonly type: "uint256[]";
|
|
313
|
+
}, {
|
|
314
|
+
readonly name: "func";
|
|
315
|
+
readonly type: "bytes[]";
|
|
316
|
+
}];
|
|
317
|
+
readonly outputs: readonly [];
|
|
318
|
+
}];
|
|
319
|
+
declare function encodeAvaxExecuteCalldata(to: Address, value: bigint, data?: Hex): Hex;
|
|
320
|
+
/** Convert API UserOp → viem shape for {@link getUserOperationHash}. */
|
|
321
|
+
declare function userOperationAvaxToViem(u: UserOperationAvax): UserOperation<'0.7'>;
|
|
322
|
+
declare function hashUserOperationAvax(params: {
|
|
323
|
+
chainId: number;
|
|
324
|
+
entryPointAddress: Address;
|
|
325
|
+
userOperation: UserOperationAvax;
|
|
326
|
+
}): Hex;
|
|
327
|
+
/** EntryPoint v0.7 `getNonce(sender, key)` with key `0`. */
|
|
328
|
+
declare function readAvaxSenderNonce(params: {
|
|
329
|
+
publicClient: PublicClient;
|
|
330
|
+
entryPointAddress: Address;
|
|
331
|
+
sender: Address;
|
|
332
|
+
key?: bigint;
|
|
333
|
+
}): Promise<bigint>;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Standard SimpleAccountFactory (EntryPoint v0.7) helpers for counterfactual address + init calldata.
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
/** Minimal ABI for eth-infinitism–style SimpleAccountFactory. */
|
|
340
|
+
declare const SIMPLE_ACCOUNT_FACTORY_ABI: readonly [{
|
|
341
|
+
readonly inputs: readonly [{
|
|
342
|
+
readonly name: "owner";
|
|
343
|
+
readonly type: "address";
|
|
344
|
+
}, {
|
|
345
|
+
readonly name: "salt";
|
|
346
|
+
readonly type: "uint256";
|
|
347
|
+
}];
|
|
348
|
+
readonly name: "createAccount";
|
|
349
|
+
readonly outputs: readonly [{
|
|
350
|
+
readonly name: "account";
|
|
351
|
+
readonly type: "address";
|
|
352
|
+
}];
|
|
353
|
+
readonly stateMutability: "nonpayable";
|
|
354
|
+
readonly type: "function";
|
|
355
|
+
}, {
|
|
356
|
+
readonly inputs: readonly [{
|
|
357
|
+
readonly name: "owner";
|
|
358
|
+
readonly type: "address";
|
|
359
|
+
}, {
|
|
360
|
+
readonly name: "salt";
|
|
361
|
+
readonly type: "uint256";
|
|
362
|
+
}];
|
|
363
|
+
readonly name: "getAddress";
|
|
364
|
+
readonly outputs: readonly [{
|
|
365
|
+
readonly name: "";
|
|
366
|
+
readonly type: "address";
|
|
367
|
+
}];
|
|
368
|
+
readonly stateMutability: "view";
|
|
369
|
+
readonly type: "function";
|
|
370
|
+
}];
|
|
371
|
+
declare function predictSimpleAccountAddress(params: {
|
|
372
|
+
publicClient: PublicClient;
|
|
373
|
+
factory: Address;
|
|
374
|
+
owner: Address;
|
|
375
|
+
salt?: bigint;
|
|
376
|
+
}): Promise<Address>;
|
|
377
|
+
declare function encodeCreateAccountFactoryData(owner: Address, salt: bigint): Hex;
|
|
378
|
+
|
|
379
|
+
type SmoothSendAvaxContextValue = {
|
|
380
|
+
apiKey: string;
|
|
381
|
+
network: 'testnet' | 'mainnet';
|
|
382
|
+
/** Set when the SCW is already known. If you use `accountFactory`, you can omit this. */
|
|
383
|
+
smartAccountAddress?: Address;
|
|
384
|
+
/**
|
|
385
|
+
* SimpleAccountFactory (v0.7). When set, the hook derives the counterfactual sender via
|
|
386
|
+
* `getAddress(owner, salt)` and, if the account has no code, adds `factory` + `factoryData` so the
|
|
387
|
+
* first sponsored UserOp deploys the SCW and runs `callData` in the same op.
|
|
388
|
+
*/
|
|
389
|
+
accountFactory?: Address;
|
|
390
|
+
accountSalt?: bigint;
|
|
391
|
+
};
|
|
392
|
+
declare function SmoothSendAvaxProvider({ apiKey, network, smartAccountAddress, accountFactory, accountSalt, children, }: {
|
|
393
|
+
apiKey: string;
|
|
394
|
+
network?: 'testnet' | 'mainnet';
|
|
395
|
+
smartAccountAddress?: Address;
|
|
396
|
+
accountFactory?: Address;
|
|
397
|
+
accountSalt?: bigint;
|
|
398
|
+
children: ReactNode;
|
|
399
|
+
}): react_jsx_runtime.JSX.Element;
|
|
400
|
+
declare function useSmoothSendAvaxContext(): SmoothSendAvaxContextValue | null;
|
|
401
|
+
type UseSmoothSendAvaxParams = {
|
|
402
|
+
apiKey?: string;
|
|
403
|
+
network?: 'testnet' | 'mainnet';
|
|
404
|
+
smartAccountAddress?: Address;
|
|
405
|
+
accountFactory?: Address;
|
|
406
|
+
/** @default 0n */
|
|
407
|
+
accountSalt?: bigint;
|
|
408
|
+
/** Optional explicit owner EOA address (useful with non-wagmi signers like Privy). */
|
|
409
|
+
ownerAddress?: Address;
|
|
410
|
+
publicClient: PublicClient | null | undefined;
|
|
411
|
+
walletClient?: WalletClient | null | undefined;
|
|
412
|
+
/** Optional custom signer for userOpHash. When set, walletClient is not required for signing. */
|
|
413
|
+
signUserOpHash?: UserOpSignerAvax;
|
|
414
|
+
};
|
|
415
|
+
declare function useSmoothSendAvax(params: UseSmoothSendAvaxParams): {
|
|
416
|
+
submitter: SmoothSendAvaxSubmitter;
|
|
417
|
+
paymasterAddress: Address | null;
|
|
418
|
+
discoveredFactory: Address | null;
|
|
419
|
+
isPending: boolean;
|
|
420
|
+
submitCall: (args: {
|
|
421
|
+
to?: Address;
|
|
422
|
+
data?: Hex;
|
|
423
|
+
value?: bigint;
|
|
424
|
+
call?: {
|
|
425
|
+
to: Address;
|
|
426
|
+
data?: Hex;
|
|
427
|
+
value?: bigint;
|
|
428
|
+
};
|
|
429
|
+
calls?: {
|
|
430
|
+
to: Address;
|
|
431
|
+
data?: Hex;
|
|
432
|
+
value?: bigint;
|
|
433
|
+
}[];
|
|
434
|
+
mode?: AvaxSponsorshipMode;
|
|
435
|
+
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
436
|
+
waitForReceipt?: boolean;
|
|
437
|
+
}) => ReturnType<SmoothSendAvaxSubmitter['submitSponsoredUserOperation']>;
|
|
438
|
+
submitSponsoredUserOp: (args: {
|
|
439
|
+
calls: Array<{
|
|
440
|
+
to: Address;
|
|
441
|
+
data?: Hex;
|
|
442
|
+
value?: bigint;
|
|
443
|
+
}>;
|
|
444
|
+
sponsorshipMode?: AvaxSponsorshipMode;
|
|
445
|
+
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
446
|
+
waitForReceipt?: boolean;
|
|
447
|
+
}) => ReturnType<SmoothSendAvaxSubmitter['submitSponsoredUserOperation']>;
|
|
448
|
+
estimateUserPaysFee: (args: {
|
|
449
|
+
to?: Address;
|
|
450
|
+
data?: Hex;
|
|
451
|
+
value?: bigint;
|
|
452
|
+
call?: {
|
|
453
|
+
to: Address;
|
|
454
|
+
data?: Hex;
|
|
455
|
+
value?: bigint;
|
|
456
|
+
};
|
|
457
|
+
calls?: {
|
|
458
|
+
to: Address;
|
|
459
|
+
data?: Hex;
|
|
460
|
+
value?: bigint;
|
|
461
|
+
}[];
|
|
462
|
+
paymaster?: Omit<PaymasterSignRequestAvax, 'mode' | 'userOp'>;
|
|
463
|
+
}) => Promise<{
|
|
464
|
+
entryPoint: string;
|
|
465
|
+
feePreview?: AvaxFeePreview;
|
|
466
|
+
exchangeRate?: string;
|
|
467
|
+
}>;
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
export { AvaxSubmitter as A, ENTRY_POINT_V07_ADDRESS as E, SmoothSendAvaxClient as S, SmoothSendAvaxSubmitter as a, createSmoothSendAvaxSubmitter as b, createSmoothSendAvaxClient as c, SmoothSendAvaxProvider as d, useSmoothSendAvaxContext as e, encodeAvaxExecuteCalldata as f, userOperationAvaxToViem as g, hashUserOperationAvax as h, avaxExecuteAbi as i, SIMPLE_ACCOUNT_FACTORY_ABI as j, encodeCreateAccountFactoryData as k, fetchAvaxAaPublicDefaults as l, predictSimpleAccountAddress as p, readAvaxSenderNonce as r, useSmoothSendAvax as u };
|
|
471
|
+
export type { SponsoredUserOpDraftAvax as B, UserOperationAvax as C, UserOperationReceiptAvax as D, UserOpSignerAvax as F, GasEstimateAvax as G, PaymasterSignRequestAvax as P, UseSmoothSendAvaxParams as U, AvaxAaPublicDefaults as m, SmoothSendAvaxSubmitterConfig as n, SmoothSendAvaxClientConfig as o, SimpleCallInput as q, EstimateUserPaysFeeAvaxOptions as s, SubmitSponsoredAvaxUserOpOptions as t, SmoothSendAvaxContextValue as v, AvaxFeePreview as w, AvaxHashTypes as x, AvaxSponsorshipMode as y, PaymasterSignResponseAvax as z };
|
package/dist/index.cjs
CHANGED
|
@@ -3116,7 +3116,11 @@ class SmoothSendAvaxClient {
|
|
|
3116
3116
|
entryPointAddress: built.entryPoint,
|
|
3117
3117
|
userOperation: op
|
|
3118
3118
|
});
|
|
3119
|
-
return this.signUserOpHash(hash
|
|
3119
|
+
return this.signUserOpHash(hash, {
|
|
3120
|
+
chainId: built.chainId,
|
|
3121
|
+
entryPoint: built.entryPoint,
|
|
3122
|
+
sender: built.userOp.sender,
|
|
3123
|
+
});
|
|
3120
3124
|
}
|
|
3121
3125
|
});
|
|
3122
3126
|
return {
|
|
@@ -3147,11 +3151,10 @@ class SmoothSendAvaxClient {
|
|
|
3147
3151
|
}
|
|
3148
3152
|
async buildDraft(calls, overrides) {
|
|
3149
3153
|
const { publicClient, walletClient } = this.config;
|
|
3150
|
-
const
|
|
3151
|
-
if (!
|
|
3152
|
-
throw new Error('[SmoothSend AVAX] walletClient.account
|
|
3154
|
+
const ownerAddress = (this.config.ownerAddress ?? walletClient?.account?.address);
|
|
3155
|
+
if (!ownerAddress) {
|
|
3156
|
+
throw new Error('[SmoothSend AVAX] ownerAddress missing — provide ownerAddress or walletClient.account');
|
|
3153
3157
|
}
|
|
3154
|
-
const ownerAddress = account.address;
|
|
3155
3158
|
const defaults = await this.submitter.getPublicAaDefaults().catch(() => null);
|
|
3156
3159
|
const accountFactory = overrides?.accountFactory ??
|
|
3157
3160
|
this.config.accountFactory ??
|
|
@@ -3231,14 +3234,21 @@ class SmoothSendAvaxClient {
|
|
|
3231
3234
|
entryPoint
|
|
3232
3235
|
};
|
|
3233
3236
|
}
|
|
3234
|
-
async signUserOpHash(hash) {
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
+
async signUserOpHash(hash, context) {
|
|
3238
|
+
if (this.config.signUserOpHash) {
|
|
3239
|
+
return this.config.signUserOpHash({
|
|
3240
|
+
hash,
|
|
3241
|
+
chainId: context.chainId,
|
|
3242
|
+
entryPoint: context.entryPoint,
|
|
3243
|
+
sender: context.sender,
|
|
3244
|
+
});
|
|
3245
|
+
}
|
|
3246
|
+
const walletClient = this.config.walletClient;
|
|
3247
|
+
const account = walletClient?.account;
|
|
3248
|
+
if (!walletClient || !account) {
|
|
3237
3249
|
throw new Error('[SmoothSend AVAX] walletClient.account missing');
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
message: { raw: hash }
|
|
3241
|
-
});
|
|
3250
|
+
}
|
|
3251
|
+
return walletClient.signMessage({ account, message: { raw: hash } });
|
|
3242
3252
|
}
|
|
3243
3253
|
}
|
|
3244
3254
|
function createSmoothSendAvaxClient(config) {
|
|
@@ -3320,23 +3330,25 @@ function useSmoothSendAvax(params) {
|
|
|
3320
3330
|
const accountFactory = accountFactoryProp ?? (network === 'mainnet' ? discovered?.simpleAccountFactoryMainnet : discovered?.simpleAccountFactoryFuji);
|
|
3321
3331
|
const paymasterAddress = (network === 'mainnet' ? discovered?.paymasterMainnet : discovered?.paymasterFuji);
|
|
3322
3332
|
const { publicClient, walletClient } = params;
|
|
3333
|
+
const ownerAddressFromParams = params.ownerAddress;
|
|
3334
|
+
const signUserOpHash = params.signUserOpHash;
|
|
3323
3335
|
const submitCall = react.useCallback(async (params) => {
|
|
3324
3336
|
setIsPending(true);
|
|
3325
3337
|
try {
|
|
3326
3338
|
if (!publicClient) {
|
|
3327
3339
|
throw new Error('[SmoothSend AVAX] publicClient missing (wagmi usePublicClient)');
|
|
3328
3340
|
}
|
|
3329
|
-
if (!walletClient) {
|
|
3341
|
+
if (!walletClient && !signUserOpHash) {
|
|
3330
3342
|
throw new Error('[SmoothSend AVAX] walletClient missing (wagmi useWalletClient)');
|
|
3331
3343
|
}
|
|
3332
3344
|
if (!smartAccountAddressProp && !accountFactory) {
|
|
3333
3345
|
throw new Error('[SmoothSend AVAX] No smartAccountAddress or accountFactory provided. Pass them to SmoothSendAvaxProvider or useSmoothSendAvax hook.');
|
|
3334
3346
|
}
|
|
3335
|
-
const account = walletClient
|
|
3336
|
-
|
|
3337
|
-
|
|
3347
|
+
const account = walletClient?.account;
|
|
3348
|
+
const ownerAddress = (ownerAddressFromParams ?? account?.address);
|
|
3349
|
+
if (!ownerAddress) {
|
|
3350
|
+
throw new Error('[SmoothSend AVAX] ownerAddress missing — provide ownerAddress or walletClient.account');
|
|
3338
3351
|
}
|
|
3339
|
-
const ownerAddress = account.address;
|
|
3340
3352
|
const chainId = Number(publicClient.chain?.id ?? (await publicClient.getChainId()));
|
|
3341
3353
|
const entryPoint = (await submitter.getSupportedEntryPoints())[0];
|
|
3342
3354
|
let sender;
|
|
@@ -3419,10 +3431,13 @@ function useSmoothSendAvax(params) {
|
|
|
3419
3431
|
entryPointAddress: entryPoint,
|
|
3420
3432
|
userOperation: op,
|
|
3421
3433
|
});
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3434
|
+
if (signUserOpHash) {
|
|
3435
|
+
return signUserOpHash({ hash, chainId, entryPoint, sender });
|
|
3436
|
+
}
|
|
3437
|
+
if (!walletClient || !account) {
|
|
3438
|
+
throw new Error('[SmoothSend AVAX] walletClient/account missing for signature');
|
|
3439
|
+
}
|
|
3440
|
+
return walletClient.signMessage({ account, message: { raw: hash } });
|
|
3426
3441
|
},
|
|
3427
3442
|
});
|
|
3428
3443
|
}
|
|
@@ -3432,7 +3447,9 @@ function useSmoothSendAvax(params) {
|
|
|
3432
3447
|
}, [
|
|
3433
3448
|
accountFactory,
|
|
3434
3449
|
accountSalt,
|
|
3450
|
+
ownerAddressFromParams,
|
|
3435
3451
|
publicClient,
|
|
3452
|
+
signUserOpHash,
|
|
3436
3453
|
smartAccountAddressProp,
|
|
3437
3454
|
submitter,
|
|
3438
3455
|
walletClient,
|
|
@@ -3452,17 +3469,14 @@ function useSmoothSendAvax(params) {
|
|
|
3452
3469
|
if (!publicClient) {
|
|
3453
3470
|
throw new Error('[SmoothSend AVAX] publicClient missing (wagmi usePublicClient)');
|
|
3454
3471
|
}
|
|
3455
|
-
if (!walletClient) {
|
|
3456
|
-
throw new Error('[SmoothSend AVAX] walletClient missing (wagmi useWalletClient)');
|
|
3457
|
-
}
|
|
3458
3472
|
if (!smartAccountAddressProp && !accountFactory) {
|
|
3459
3473
|
throw new Error('[SmoothSend AVAX] No smartAccountAddress or accountFactory provided. Pass them to SmoothSendAvaxProvider or useSmoothSendAvax hook.');
|
|
3460
3474
|
}
|
|
3461
|
-
const account = walletClient
|
|
3462
|
-
|
|
3463
|
-
|
|
3475
|
+
const account = walletClient?.account;
|
|
3476
|
+
const ownerAddress = (ownerAddressFromParams ?? account?.address);
|
|
3477
|
+
if (!ownerAddress) {
|
|
3478
|
+
throw new Error('[SmoothSend AVAX] ownerAddress missing — provide ownerAddress or walletClient.account');
|
|
3464
3479
|
}
|
|
3465
|
-
const ownerAddress = account.address;
|
|
3466
3480
|
let sender;
|
|
3467
3481
|
if (accountFactory) {
|
|
3468
3482
|
const predicted = await predictSimpleAccountAddress({
|
|
@@ -3544,6 +3558,7 @@ function useSmoothSendAvax(params) {
|
|
|
3544
3558
|
}, [
|
|
3545
3559
|
accountFactory,
|
|
3546
3560
|
accountSalt,
|
|
3561
|
+
ownerAddressFromParams,
|
|
3547
3562
|
publicClient,
|
|
3548
3563
|
smartAccountAddressProp,
|
|
3549
3564
|
submitter,
|