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