@smoothsend/sdk 2.3.0 → 2.3.2

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/index.js CHANGED
@@ -3086,6 +3086,9 @@ class SmoothSendAvaxClient {
3086
3086
  calls: [args.call],
3087
3087
  mode: args.mode,
3088
3088
  paymaster: args.paymaster,
3089
+ smartAccountAddress: args.smartAccountAddress,
3090
+ accountFactory: args.accountFactory,
3091
+ accountSalt: args.accountSalt,
3089
3092
  waitForReceipt: args.waitForReceipt
3090
3093
  });
3091
3094
  }
@@ -3093,7 +3096,11 @@ class SmoothSendAvaxClient {
3093
3096
  if (args.calls.length === 0) {
3094
3097
  throw new Error('[SmoothSend AVAX] No calls provided');
3095
3098
  }
3096
- const built = await this.buildDraft(args.calls);
3099
+ const built = await this.buildDraft(args.calls, {
3100
+ smartAccountAddress: args.smartAccountAddress,
3101
+ accountFactory: args.accountFactory,
3102
+ accountSalt: args.accountSalt
3103
+ });
3097
3104
  const result = await this.submitter.submitSponsoredUserOperation({
3098
3105
  userOp: built.userOp,
3099
3106
  mode: args.mode ?? 'developer-sponsored',
@@ -3118,7 +3125,11 @@ class SmoothSendAvaxClient {
3118
3125
  if (args.calls.length === 0) {
3119
3126
  throw new Error('[SmoothSend AVAX] No calls provided');
3120
3127
  }
3121
- const built = await this.buildDraft(args.calls);
3128
+ const built = await this.buildDraft(args.calls, {
3129
+ smartAccountAddress: args.smartAccountAddress,
3130
+ accountFactory: args.accountFactory,
3131
+ accountSalt: args.accountSalt
3132
+ });
3122
3133
  const estimate = await this.submitter.estimateUserPaysFee({
3123
3134
  userOp: built.userOp,
3124
3135
  entryPoint: built.entryPoint,
@@ -3130,7 +3141,7 @@ class SmoothSendAvaxClient {
3130
3141
  entryPoint: estimate.entryPoint
3131
3142
  };
3132
3143
  }
3133
- async buildDraft(calls) {
3144
+ async buildDraft(calls, overrides) {
3134
3145
  const { publicClient, walletClient } = this.config;
3135
3146
  const account = walletClient.account;
3136
3147
  if (!account) {
@@ -3138,11 +3149,14 @@ class SmoothSendAvaxClient {
3138
3149
  }
3139
3150
  const ownerAddress = account.address;
3140
3151
  const defaults = await this.submitter.getPublicAaDefaults().catch(() => null);
3141
- const accountFactory = this.config.accountFactory ??
3152
+ const accountFactory = overrides?.accountFactory ??
3153
+ this.config.accountFactory ??
3142
3154
  ((this.config.network ?? 'testnet') === 'mainnet'
3143
3155
  ? defaults?.simpleAccountFactoryMainnet
3144
3156
  : defaults?.simpleAccountFactoryFuji) ??
3145
3157
  undefined;
3158
+ const accountSalt = overrides?.accountSalt ?? this.config.accountSalt ?? 0n;
3159
+ const smartAccountAddress = overrides?.smartAccountAddress ?? this.config.smartAccountAddress;
3146
3160
  const chainId = Number(publicClient.chain?.id ?? (await publicClient.getChainId()));
3147
3161
  const entryPoint = (await this.submitter.getSupportedEntryPoints())[0];
3148
3162
  let sender;
@@ -3151,16 +3165,16 @@ class SmoothSendAvaxClient {
3151
3165
  publicClient,
3152
3166
  factory: accountFactory,
3153
3167
  owner: ownerAddress,
3154
- salt: this.config.accountSalt ?? 0n
3168
+ salt: accountSalt
3155
3169
  });
3156
- if (this.config.smartAccountAddress &&
3157
- predicted.toLowerCase() !== this.config.smartAccountAddress.toLowerCase()) {
3158
- throw new Error(`[SmoothSend AVAX] smartAccountAddress ${this.config.smartAccountAddress} does not match factory prediction ${predicted}`);
3170
+ if (smartAccountAddress &&
3171
+ predicted.toLowerCase() !== smartAccountAddress.toLowerCase()) {
3172
+ throw new Error(`[SmoothSend AVAX] smartAccountAddress ${smartAccountAddress} does not match factory prediction ${predicted}`);
3159
3173
  }
3160
3174
  sender = predicted;
3161
3175
  }
3162
- else if (this.config.smartAccountAddress) {
3163
- sender = this.config.smartAccountAddress;
3176
+ else if (smartAccountAddress) {
3177
+ sender = smartAccountAddress;
3164
3178
  }
3165
3179
  else {
3166
3180
  throw new Error('[SmoothSend AVAX] Provide smartAccountAddress or accountFactory (or use gateway public defaults).');
@@ -3176,7 +3190,7 @@ class SmoothSendAvaxClient {
3176
3190
  }
3177
3191
  nonce = 0n;
3178
3192
  factory = accountFactory;
3179
- factoryData = encodeCreateAccountFactoryData(ownerAddress, this.config.accountSalt ?? 0n);
3193
+ factoryData = encodeCreateAccountFactoryData(ownerAddress, accountSalt);
3180
3194
  }
3181
3195
  else {
3182
3196
  nonce = await readAvaxSenderNonce({
@@ -3293,6 +3307,7 @@ function useSmoothSendAvax(params) {
3293
3307
  }
3294
3308
  const submitter = useMemo(() => new SmoothSendAvaxSubmitter({ apiKey, network }), [apiKey, network]);
3295
3309
  const [discovered, setDiscovered] = useState(null);
3310
+ const [isPending, setIsPending] = useState(false);
3296
3311
  useEffect(() => {
3297
3312
  submitter.getPublicAaDefaults().then(setDiscovered).catch(err => {
3298
3313
  console.warn('[SmoothSend AVAX] Auto-discovery failed:', err);
@@ -3302,108 +3317,114 @@ function useSmoothSendAvax(params) {
3302
3317
  const paymasterAddress = (network === 'mainnet' ? discovered?.paymasterMainnet : discovered?.paymasterFuji);
3303
3318
  const { publicClient, walletClient } = params;
3304
3319
  const submitCall = useCallback(async (params) => {
3305
- if (!publicClient) {
3306
- throw new Error('[SmoothSend AVAX] publicClient missing (wagmi usePublicClient)');
3307
- }
3308
- if (!walletClient) {
3309
- throw new Error('[SmoothSend AVAX] walletClient missing (wagmi useWalletClient)');
3310
- }
3311
- if (!smartAccountAddressProp && !accountFactory) {
3312
- throw new Error('[SmoothSend AVAX] No smartAccountAddress or accountFactory provided. Pass them to SmoothSendAvaxProvider or useSmoothSendAvax hook.');
3313
- }
3314
- const account = walletClient.account;
3315
- if (!account) {
3316
- throw new Error('[SmoothSend AVAX] walletClient.account missing — connect wallet (wagmi useWalletClient)');
3317
- }
3318
- const ownerAddress = account.address;
3319
- const chainId = Number(publicClient.chain?.id ?? (await publicClient.getChainId()));
3320
- const entryPoint = (await submitter.getSupportedEntryPoints())[0];
3321
- let sender;
3322
- if (accountFactory) {
3323
- const predicted = await predictSimpleAccountAddress({
3324
- publicClient,
3325
- factory: accountFactory,
3326
- owner: ownerAddress,
3327
- salt: accountSalt,
3328
- });
3329
- if (smartAccountAddressProp &&
3330
- predicted.toLowerCase() !== smartAccountAddressProp.toLowerCase()) {
3331
- 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)');
3332
3324
  }
3333
- sender = predicted;
3334
- }
3335
- else {
3336
- sender = smartAccountAddressProp;
3337
- }
3338
- const code = await publicClient.getBytecode({ address: sender });
3339
- const deployed = typeof code === 'string' &&
3340
- code !== '0x' &&
3341
- code.length > 2;
3342
- let nonce;
3343
- let factory;
3344
- let factoryData;
3345
- if (!deployed) {
3346
- if (!accountFactory) {
3347
- 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)');
3348
3327
  }
3349
- nonce = 0n;
3350
- factory = accountFactory;
3351
- factoryData = encodeCreateAccountFactoryData(ownerAddress, accountSalt);
3352
- }
3353
- else {
3354
- nonce = await readAvaxSenderNonce({
3355
- publicClient,
3356
- entryPointAddress: entryPoint,
3357
- sender,
3358
- });
3359
- }
3360
- let maxFeePerGas = 50n * 10n ** 9n;
3361
- let maxPriorityFeePerGas = 2n * 10n ** 9n;
3362
- try {
3363
- const est = await publicClient.estimateFeesPerGas();
3364
- if (est.maxFeePerGas)
3365
- maxFeePerGas = est.maxFeePerGas;
3366
- if (est.maxPriorityFeePerGas) {
3367
- 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.');
3368
3330
  }
3369
- }
3370
- catch {
3371
- /* chain may not support EIP-1559 estimation */
3372
- }
3373
- let callData;
3374
- if (params.calls && params.calls.length > 0) {
3375
- callData = encodeAvaxExecuteBatchCalldata(params.calls.map(c => c.to), params.calls.map(c => c.value ?? 0n), params.calls.map(c => c.data ?? '0x'));
3376
- }
3377
- else {
3378
- const target = params.call?.to ?? params.to;
3379
- if (!target)
3380
- throw new Error('[SmoothSend AVAX] No target address (to) provided');
3381
- callData = encodeAvaxExecuteCalldata(target, params.call?.value ?? params.value ?? 0n, params.call?.data ?? params.data ?? '0x');
3382
- }
3383
- return submitter.submitSponsoredUserOperation({
3384
- userOp: {
3385
- sender,
3386
- nonce: toHex(nonce),
3387
- callData,
3388
- maxFeePerGas: toHex(maxFeePerGas),
3389
- maxPriorityFeePerGas: toHex(maxPriorityFeePerGas),
3390
- ...(factory && factoryData ? { factory, factoryData } : {}),
3391
- },
3392
- mode: params.mode ?? 'developer-sponsored',
3393
- paymaster: params.paymaster,
3394
- waitForReceipt: params.waitForReceipt,
3395
- signUserOp: async (op) => {
3396
- const hash = hashUserOperationAvax({
3397
- chainId,
3398
- entryPointAddress: entryPoint,
3399
- 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,
3400
3345
  });
3401
- return walletClient.signMessage({
3402
- account,
3403
- message: { raw: hash },
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,
3404
3375
  });
3405
- },
3406
- });
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
+ }
3407
3428
  }, [
3408
3429
  accountFactory,
3409
3430
  accountSalt,
@@ -3531,6 +3552,7 @@ function useSmoothSendAvax(params) {
3531
3552
  estimateUserPaysFee,
3532
3553
  paymasterAddress,
3533
3554
  discoveredFactory: accountFactory ?? null,
3555
+ isPending,
3534
3556
  };
3535
3557
  }
3536
3558