@smoothsend/sdk 2.3.1 → 2.3.3
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/index.cjs +146 -97
- package/dist/avax/index.cjs.map +1 -1
- package/dist/avax/index.d.ts +22 -441
- package/dist/avax/index.d.ts.map +1 -1
- package/dist/avax/index.js +146 -98
- package/dist/avax/index.js.map +1 -1
- package/dist/avax/useSmoothSendAvax.d.ts +12 -1
- package/dist/avax/useSmoothSendAvax.d.ts.map +1 -1
- package/dist/avax/useSmoothSendWrite.d.ts +23 -0
- package/dist/avax/useSmoothSendWrite.d.ts.map +1 -0
- package/dist/avax-entry.d.ts +1 -1
- package/dist/avax-entry.d.ts.map +1 -1
- package/dist/chunks/shared-viO0MYao.d.ts +459 -0
- package/dist/index.cjs +105 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +105 -97
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3307,6 +3307,7 @@ function useSmoothSendAvax(params) {
|
|
|
3307
3307
|
}
|
|
3308
3308
|
const submitter = useMemo(() => new SmoothSendAvaxSubmitter({ apiKey, network }), [apiKey, network]);
|
|
3309
3309
|
const [discovered, setDiscovered] = useState(null);
|
|
3310
|
+
const [isPending, setIsPending] = useState(false);
|
|
3310
3311
|
useEffect(() => {
|
|
3311
3312
|
submitter.getPublicAaDefaults().then(setDiscovered).catch(err => {
|
|
3312
3313
|
console.warn('[SmoothSend AVAX] Auto-discovery failed:', err);
|
|
@@ -3316,108 +3317,114 @@ function useSmoothSendAvax(params) {
|
|
|
3316
3317
|
const paymasterAddress = (network === 'mainnet' ? discovered?.paymasterMainnet : discovered?.paymasterFuji);
|
|
3317
3318
|
const { publicClient, walletClient } = params;
|
|
3318
3319
|
const submitCall = useCallback(async (params) => {
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
throw new Error('[SmoothSend AVAX] walletClient missing (wagmi useWalletClient)');
|
|
3324
|
-
}
|
|
3325
|
-
if (!smartAccountAddressProp && !accountFactory) {
|
|
3326
|
-
throw new Error('[SmoothSend AVAX] No smartAccountAddress or accountFactory provided. Pass them to SmoothSendAvaxProvider or useSmoothSendAvax hook.');
|
|
3327
|
-
}
|
|
3328
|
-
const account = walletClient.account;
|
|
3329
|
-
if (!account) {
|
|
3330
|
-
throw new Error('[SmoothSend AVAX] walletClient.account missing — connect wallet (wagmi useWalletClient)');
|
|
3331
|
-
}
|
|
3332
|
-
const ownerAddress = account.address;
|
|
3333
|
-
const chainId = Number(publicClient.chain?.id ?? (await publicClient.getChainId()));
|
|
3334
|
-
const entryPoint = (await submitter.getSupportedEntryPoints())[0];
|
|
3335
|
-
let sender;
|
|
3336
|
-
if (accountFactory) {
|
|
3337
|
-
const predicted = await predictSimpleAccountAddress({
|
|
3338
|
-
publicClient,
|
|
3339
|
-
factory: accountFactory,
|
|
3340
|
-
owner: ownerAddress,
|
|
3341
|
-
salt: accountSalt,
|
|
3342
|
-
});
|
|
3343
|
-
if (smartAccountAddressProp &&
|
|
3344
|
-
predicted.toLowerCase() !== smartAccountAddressProp.toLowerCase()) {
|
|
3345
|
-
throw new Error(`[SmoothSend AVAX] smartAccountAddress ${smartAccountAddressProp} does not match factory prediction ${predicted}`);
|
|
3320
|
+
setIsPending(true);
|
|
3321
|
+
try {
|
|
3322
|
+
if (!publicClient) {
|
|
3323
|
+
throw new Error('[SmoothSend AVAX] publicClient missing (wagmi usePublicClient)');
|
|
3346
3324
|
}
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
else {
|
|
3350
|
-
sender = smartAccountAddressProp;
|
|
3351
|
-
}
|
|
3352
|
-
const code = await publicClient.getBytecode({ address: sender });
|
|
3353
|
-
const deployed = typeof code === 'string' &&
|
|
3354
|
-
code !== '0x' &&
|
|
3355
|
-
code.length > 2;
|
|
3356
|
-
let nonce;
|
|
3357
|
-
let factory;
|
|
3358
|
-
let factoryData;
|
|
3359
|
-
if (!deployed) {
|
|
3360
|
-
if (!accountFactory) {
|
|
3361
|
-
throw new Error('[SmoothSend AVAX] No bytecode at sender — pass accountFactory so the paymaster can sponsor deploy + call in one UserOp');
|
|
3325
|
+
if (!walletClient) {
|
|
3326
|
+
throw new Error('[SmoothSend AVAX] walletClient missing (wagmi useWalletClient)');
|
|
3362
3327
|
}
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
factoryData = encodeCreateAccountFactoryData(ownerAddress, accountSalt);
|
|
3366
|
-
}
|
|
3367
|
-
else {
|
|
3368
|
-
nonce = await readAvaxSenderNonce({
|
|
3369
|
-
publicClient,
|
|
3370
|
-
entryPointAddress: entryPoint,
|
|
3371
|
-
sender,
|
|
3372
|
-
});
|
|
3373
|
-
}
|
|
3374
|
-
let maxFeePerGas = 50n * 10n ** 9n;
|
|
3375
|
-
let maxPriorityFeePerGas = 2n * 10n ** 9n;
|
|
3376
|
-
try {
|
|
3377
|
-
const est = await publicClient.estimateFeesPerGas();
|
|
3378
|
-
if (est.maxFeePerGas)
|
|
3379
|
-
maxFeePerGas = est.maxFeePerGas;
|
|
3380
|
-
if (est.maxPriorityFeePerGas) {
|
|
3381
|
-
maxPriorityFeePerGas = est.maxPriorityFeePerGas;
|
|
3328
|
+
if (!smartAccountAddressProp && !accountFactory) {
|
|
3329
|
+
throw new Error('[SmoothSend AVAX] No smartAccountAddress or accountFactory provided. Pass them to SmoothSendAvaxProvider or useSmoothSendAvax hook.');
|
|
3382
3330
|
}
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
return submitter.submitSponsoredUserOperation({
|
|
3398
|
-
userOp: {
|
|
3399
|
-
sender,
|
|
3400
|
-
nonce: toHex(nonce),
|
|
3401
|
-
callData,
|
|
3402
|
-
maxFeePerGas: toHex(maxFeePerGas),
|
|
3403
|
-
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas),
|
|
3404
|
-
...(factory && factoryData ? { factory, factoryData } : {}),
|
|
3405
|
-
},
|
|
3406
|
-
mode: params.mode ?? 'developer-sponsored',
|
|
3407
|
-
paymaster: params.paymaster,
|
|
3408
|
-
waitForReceipt: params.waitForReceipt,
|
|
3409
|
-
signUserOp: async (op) => {
|
|
3410
|
-
const hash = hashUserOperationAvax({
|
|
3411
|
-
chainId,
|
|
3412
|
-
entryPointAddress: entryPoint,
|
|
3413
|
-
userOperation: op,
|
|
3331
|
+
const account = walletClient.account;
|
|
3332
|
+
if (!account) {
|
|
3333
|
+
throw new Error('[SmoothSend AVAX] walletClient.account missing — connect wallet (wagmi useWalletClient)');
|
|
3334
|
+
}
|
|
3335
|
+
const ownerAddress = account.address;
|
|
3336
|
+
const chainId = Number(publicClient.chain?.id ?? (await publicClient.getChainId()));
|
|
3337
|
+
const entryPoint = (await submitter.getSupportedEntryPoints())[0];
|
|
3338
|
+
let sender;
|
|
3339
|
+
if (accountFactory) {
|
|
3340
|
+
const predicted = await predictSimpleAccountAddress({
|
|
3341
|
+
publicClient,
|
|
3342
|
+
factory: accountFactory,
|
|
3343
|
+
owner: ownerAddress,
|
|
3344
|
+
salt: accountSalt,
|
|
3414
3345
|
});
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3346
|
+
if (smartAccountAddressProp &&
|
|
3347
|
+
predicted.toLowerCase() !== smartAccountAddressProp.toLowerCase()) {
|
|
3348
|
+
throw new Error(`[SmoothSend AVAX] smartAccountAddress ${smartAccountAddressProp} does not match factory prediction ${predicted}`);
|
|
3349
|
+
}
|
|
3350
|
+
sender = predicted;
|
|
3351
|
+
}
|
|
3352
|
+
else {
|
|
3353
|
+
sender = smartAccountAddressProp;
|
|
3354
|
+
}
|
|
3355
|
+
const code = await publicClient.getBytecode({ address: sender });
|
|
3356
|
+
const deployed = typeof code === 'string' &&
|
|
3357
|
+
code !== '0x' &&
|
|
3358
|
+
code.length > 2;
|
|
3359
|
+
let nonce;
|
|
3360
|
+
let factory;
|
|
3361
|
+
let factoryData;
|
|
3362
|
+
if (!deployed) {
|
|
3363
|
+
if (!accountFactory) {
|
|
3364
|
+
throw new Error('[SmoothSend AVAX] No bytecode at sender — pass accountFactory so the paymaster can sponsor deploy + call in one UserOp');
|
|
3365
|
+
}
|
|
3366
|
+
nonce = 0n;
|
|
3367
|
+
factory = accountFactory;
|
|
3368
|
+
factoryData = encodeCreateAccountFactoryData(ownerAddress, accountSalt);
|
|
3369
|
+
}
|
|
3370
|
+
else {
|
|
3371
|
+
nonce = await readAvaxSenderNonce({
|
|
3372
|
+
publicClient,
|
|
3373
|
+
entryPointAddress: entryPoint,
|
|
3374
|
+
sender,
|
|
3418
3375
|
});
|
|
3419
|
-
}
|
|
3420
|
-
|
|
3376
|
+
}
|
|
3377
|
+
let maxFeePerGas = 50n * 10n ** 9n;
|
|
3378
|
+
let maxPriorityFeePerGas = 2n * 10n ** 9n;
|
|
3379
|
+
try {
|
|
3380
|
+
const est = await publicClient.estimateFeesPerGas();
|
|
3381
|
+
if (est.maxFeePerGas)
|
|
3382
|
+
maxFeePerGas = est.maxFeePerGas;
|
|
3383
|
+
if (est.maxPriorityFeePerGas) {
|
|
3384
|
+
maxPriorityFeePerGas = est.maxPriorityFeePerGas;
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
catch {
|
|
3388
|
+
/* chain may not support EIP-1559 estimation */
|
|
3389
|
+
}
|
|
3390
|
+
let callData;
|
|
3391
|
+
if (params.calls && params.calls.length > 0) {
|
|
3392
|
+
callData = encodeAvaxExecuteBatchCalldata(params.calls.map(c => c.to), params.calls.map(c => c.value ?? 0n), params.calls.map(c => c.data ?? '0x'));
|
|
3393
|
+
}
|
|
3394
|
+
else {
|
|
3395
|
+
const target = params.call?.to ?? params.to;
|
|
3396
|
+
if (!target)
|
|
3397
|
+
throw new Error('[SmoothSend AVAX] No target address (to) provided');
|
|
3398
|
+
callData = encodeAvaxExecuteCalldata(target, params.call?.value ?? params.value ?? 0n, params.call?.data ?? params.data ?? '0x');
|
|
3399
|
+
}
|
|
3400
|
+
return await submitter.submitSponsoredUserOperation({
|
|
3401
|
+
userOp: {
|
|
3402
|
+
sender,
|
|
3403
|
+
nonce: toHex(nonce),
|
|
3404
|
+
callData,
|
|
3405
|
+
maxFeePerGas: toHex(maxFeePerGas),
|
|
3406
|
+
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas),
|
|
3407
|
+
...(factory && factoryData ? { factory, factoryData } : {}),
|
|
3408
|
+
},
|
|
3409
|
+
mode: params.mode ?? 'developer-sponsored',
|
|
3410
|
+
paymaster: params.paymaster,
|
|
3411
|
+
waitForReceipt: params.waitForReceipt,
|
|
3412
|
+
signUserOp: async (op) => {
|
|
3413
|
+
const hash = hashUserOperationAvax({
|
|
3414
|
+
chainId,
|
|
3415
|
+
entryPointAddress: entryPoint,
|
|
3416
|
+
userOperation: op,
|
|
3417
|
+
});
|
|
3418
|
+
return walletClient.signMessage({
|
|
3419
|
+
account,
|
|
3420
|
+
message: { raw: hash },
|
|
3421
|
+
});
|
|
3422
|
+
},
|
|
3423
|
+
});
|
|
3424
|
+
}
|
|
3425
|
+
finally {
|
|
3426
|
+
setIsPending(false);
|
|
3427
|
+
}
|
|
3421
3428
|
}, [
|
|
3422
3429
|
accountFactory,
|
|
3423
3430
|
accountSalt,
|
|
@@ -3545,6 +3552,7 @@ function useSmoothSendAvax(params) {
|
|
|
3545
3552
|
estimateUserPaysFee,
|
|
3546
3553
|
paymasterAddress,
|
|
3547
3554
|
discoveredFactory: accountFactory ?? null,
|
|
3555
|
+
isPending,
|
|
3548
3556
|
};
|
|
3549
3557
|
}
|
|
3550
3558
|
|