@@ -66,7 +66,7 @@ private struct TokenPaymasterConfig
66
66
new TokenPaymasterConfig ( )
67
67
{
68
68
ChainId = 8453 ,
69
- PaymasterAddress = "0x0c6199eE133EB4ff8a6bbD03370336C5A5d9D536 " ,
69
+ PaymasterAddress = "0xff4d12b1f8d276aa4a9e8cc80539e806791bfe28 " ,
70
70
TokenAddress = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" ,
71
71
BalanceStorageSlot = 9
72
72
}
@@ -125,8 +125,8 @@ public static async Task<SmartWallet> Create(
125
125
126
126
var entryPointVersion = Utils . GetEntryPointVersion ( entryPoint ) ;
127
127
128
- bundlerUrl ??= entryPointVersion == 6 ? $ "https:// { chainId } .bundler.thirdweb.com" : $ "https://{ chainId } .bundler.thirdweb.com/v2";
129
- paymasterUrl ??= entryPointVersion == 6 ? $ "https:// { chainId } .bundler.thirdweb.com" : $ "https://{ chainId } .bundler.thirdweb.com/v2";
128
+ bundlerUrl ??= $ "https://{ chainId } .bundler.thirdweb.com/v2";
129
+ paymasterUrl ??= $ "https://{ chainId } .bundler.thirdweb.com/v2";
130
130
factoryAddress ??= entryPointVersion == 6 ? Constants . DEFAULT_FACTORY_ADDRESS_V06 : Constants . DEFAULT_FACTORY_ADDRESS_V07 ;
131
131
132
132
ThirdwebContract entryPointContract = null ;
@@ -160,9 +160,6 @@ public static async Task<SmartWallet> Create(
160
160
{
161
161
throw new InvalidOperationException ( "Token paymaster chain ID does not match the smart account chain ID." ) ;
162
162
}
163
-
164
- // TODO: Re-enable token paymasters
165
- throw new InvalidOperationException ( "Token paymasters are currently disabled." ) ;
166
163
}
167
164
168
165
return new SmartWallet (
@@ -199,9 +196,8 @@ public async Task SwitchNetwork(BigInteger chainId)
199
196
200
197
this . _chainId = chainId ;
201
198
202
- var entryPointVersion = Utils . GetEntryPointVersion ( this . _entryPointContract ? . Address ) ;
203
- this . _bundlerUrl = entryPointVersion == 6 ? $ "https://{ chainId } .bundler.thirdweb.com" : $ "https://{ chainId } .bundler.thirdweb.com/v2";
204
- this . _paymasterUrl = entryPointVersion == 6 ? $ "https://{ chainId } .bundler.thirdweb.com" : $ "https://{ chainId } .bundler.thirdweb.com/v2";
199
+ this . _bundlerUrl = this . _bundlerUrl . Contains ( ".thirdweb.com" ) ? $ "https://{ chainId } .bundler.thirdweb.com/v2" : this . _bundlerUrl ;
200
+ this . _paymasterUrl = this . _paymasterUrl . Contains ( ".thirdweb.com" ) ? $ "https://{ chainId } .bundler.thirdweb.com/v2" : this . _paymasterUrl ;
205
201
if ( ! Utils . IsZkSync ( chainId ) )
206
202
{
207
203
this . _entryPointContract = await ThirdwebContract . Create ( this . Client , this . _entryPointContract . Address , chainId , this . _entryPointContract . Abi ) . ConfigureAwait ( false ) ;
@@ -314,6 +310,7 @@ private async Task<object> SignUserOp(ThirdwebTransactionInput transactionInput,
314
310
_ = await tokenContract . ERC20_Approve ( this , this . _erc20PaymasterAddress , BigInteger . Pow ( 2 , 96 ) - 1 ) . ConfigureAwait ( false ) ;
315
311
}
316
312
this . _isApproved = true ;
313
+ await ThirdwebTask . Delay ( 1000 ) . ConfigureAwait ( false ) ;
317
314
( initCode , factory , factoryData ) = await this . GetInitCode ( ) . ConfigureAwait ( false ) ;
318
315
}
319
316
catch ( Exception e )
@@ -370,7 +367,7 @@ private async Task<object> SignUserOp(ThirdwebTransactionInput transactionInput,
370
367
Nonce = await this . GetNonce ( ) . ConfigureAwait ( false ) ,
371
368
InitCode = initCode ,
372
369
CallData = executeInput . Data . HexToBytes ( ) ,
373
- CallGasLimit = 0 ,
370
+ CallGasLimit = transactionInput . Gas == null ? 0 : 21000 + transactionInput . Gas . Value ,
374
371
VerificationGasLimit = 0 ,
375
372
PreVerificationGas = 0 ,
376
373
MaxFeePerGas = maxFee ,
@@ -379,20 +376,24 @@ private async Task<object> SignUserOp(ThirdwebTransactionInput transactionInput,
379
376
Signature = Constants . DUMMY_SIG . HexToBytes ( ) ,
380
377
} ;
381
378
382
- // Update paymaster data if any
383
-
384
- partialUserOp . PaymasterAndData = ( await this . GetPaymasterAndData ( requestId , EncodeUserOperation ( partialUserOp ) , simulation ) . ConfigureAwait ( false ) ) . PaymasterAndData . HexToBytes ( ) ;
379
+ // Update paymaster data and gas
385
380
386
- // Estimate gas
381
+ var pmSponsorResult = await this . GetPaymasterAndData ( requestId , EncodeUserOperation ( partialUserOp ) , simulation ) . ConfigureAwait ( false ) ;
382
+ partialUserOp . PaymasterAndData = pmSponsorResult . PaymasterAndData . HexToBytes ( ) ;
387
383
388
- var gasEstimates = await BundlerClient . EthEstimateUserOperationGas ( this . Client , this . _bundlerUrl , requestId , EncodeUserOperation ( partialUserOp ) , this . _entryPointContract . Address ) ;
389
- partialUserOp . CallGasLimit = Math . Max ( ( long ) ( 50000 + new HexBigInteger ( gasEstimates . CallGasLimit ) . Value ) , ( long ? ) transactionInput . Gas ? . Value ?? 0 ) ;
390
- partialUserOp . VerificationGasLimit = new HexBigInteger ( gasEstimates . VerificationGasLimit ) . Value ;
391
- partialUserOp . PreVerificationGas = new HexBigInteger ( gasEstimates . PreVerificationGas ) . Value ;
392
-
393
- // Update paymaster data if any
394
-
395
- partialUserOp . PaymasterAndData = ( await this . GetPaymasterAndData ( requestId , EncodeUserOperation ( partialUserOp ) , simulation ) . ConfigureAwait ( false ) ) . PaymasterAndData . HexToBytes ( ) ;
384
+ if ( pmSponsorResult . VerificationGasLimit == null || pmSponsorResult . PreVerificationGas == null )
385
+ {
386
+ var gasEstimates = await BundlerClient . EthEstimateUserOperationGas ( this . Client , this . _bundlerUrl , requestId , EncodeUserOperation ( partialUserOp ) , this . _entryPointContract . Address ) ;
387
+ partialUserOp . CallGasLimit = new HexBigInteger ( gasEstimates . CallGasLimit ) . Value ;
388
+ partialUserOp . VerificationGasLimit = new HexBigInteger ( gasEstimates . VerificationGasLimit ) . Value ;
389
+ partialUserOp . PreVerificationGas = new HexBigInteger ( gasEstimates . PreVerificationGas ) . Value ;
390
+ }
391
+ else
392
+ {
393
+ partialUserOp . CallGasLimit = new HexBigInteger ( pmSponsorResult . CallGasLimit ) . Value ;
394
+ partialUserOp . VerificationGasLimit = new HexBigInteger ( pmSponsorResult . VerificationGasLimit ) . Value ;
395
+ partialUserOp . PreVerificationGas = new HexBigInteger ( pmSponsorResult . PreVerificationGas ) . Value ;
396
+ }
396
397
397
398
// Hash, sign and encode the user operation
398
399
@@ -435,6 +436,12 @@ private async Task<object> SignUserOp(ThirdwebTransactionInput transactionInput,
435
436
436
437
// Update Paymaster Data / Estimate gas
437
438
439
+ var pmSponsorResult = await this . GetPaymasterAndData ( requestId , EncodeUserOperation ( partialUserOp ) , simulation ) . ConfigureAwait ( false ) ;
440
+ partialUserOp . Paymaster = pmSponsorResult . Paymaster ;
441
+ partialUserOp . PaymasterData = pmSponsorResult . PaymasterData ? . HexToBytes ( ) ?? Array . Empty < byte > ( ) ;
442
+
443
+ Dictionary < string , object > stateDict = null ;
444
+
438
445
if ( this . UseERC20Paymaster && ! this . _isApproving )
439
446
{
440
447
var abiEncoder = new ABIEncode ( ) ;
@@ -444,31 +451,28 @@ private async Task<object> SignUserOp(ThirdwebTransactionInput transactionInput,
444
451
{
445
452
{ new Sha3Keccack ( ) . CalculateHash ( slotBytes ) . BytesToHex ( ) . ToString ( ) , desiredBalance . ToHexBigInteger ( ) . HexValue . HexToBytes32 ( ) . BytesToHex ( ) }
446
453
} ;
447
- var stateDict = new Dictionary < string , object > { { this . _erc20PaymasterToken , new { stateDiff = storageDict } } } ;
448
- var res = await this . GetPaymasterAndData ( requestId , EncodeUserOperation ( partialUserOp ) , simulation ) . ConfigureAwait ( false ) ;
449
- partialUserOp . Paymaster = res . Paymaster ;
450
- partialUserOp . PaymasterData = res . PaymasterData . HexToBytes ( ) ;
454
+ stateDict = new Dictionary < string , object > { { this . _erc20PaymasterToken , new { stateDiff = storageDict } } } ;
455
+ }
456
+ else
457
+ {
458
+ partialUserOp . PreVerificationGas = new HexBigInteger ( pmSponsorResult . PreVerificationGas ?? "0x0" ) . Value ;
459
+ partialUserOp . VerificationGasLimit = new HexBigInteger ( pmSponsorResult . VerificationGasLimit ?? "0x0" ) . Value ;
460
+ partialUserOp . CallGasLimit = new HexBigInteger ( pmSponsorResult . CallGasLimit ?? "0x0" ) . Value ;
461
+ partialUserOp . PaymasterVerificationGasLimit = new HexBigInteger ( pmSponsorResult . PaymasterVerificationGasLimit ?? "0x0" ) . Value ;
462
+ partialUserOp . PaymasterPostOpGasLimit = new HexBigInteger ( pmSponsorResult . PaymasterPostOpGasLimit ?? "0x0" ) . Value ;
463
+ }
451
464
465
+ if ( partialUserOp . PreVerificationGas == 0 || partialUserOp . VerificationGasLimit == 0 )
466
+ {
452
467
var gasEstimates = await BundlerClient
453
468
. EthEstimateUserOperationGas ( this . Client , this . _bundlerUrl , requestId , EncodeUserOperation ( partialUserOp ) , this . _entryPointContract . Address , stateDict )
454
469
. ConfigureAwait ( false ) ;
455
- partialUserOp . CallGasLimit = 21000 + new HexBigInteger ( gasEstimates . CallGasLimit ) . Value ;
470
+ partialUserOp . CallGasLimit = new HexBigInteger ( gasEstimates . CallGasLimit ) . Value ;
456
471
partialUserOp . VerificationGasLimit = new HexBigInteger ( gasEstimates . VerificationGasLimit ) . Value ;
457
472
partialUserOp . PreVerificationGas = new HexBigInteger ( gasEstimates . PreVerificationGas ) . Value ;
458
473
partialUserOp . PaymasterVerificationGasLimit = new HexBigInteger ( gasEstimates . PaymasterVerificationGasLimit ) . Value ;
459
474
partialUserOp . PaymasterPostOpGasLimit = new HexBigInteger ( gasEstimates . PaymasterPostOpGasLimit ) . Value ;
460
475
}
461
- else
462
- {
463
- var res = await this . GetPaymasterAndData ( requestId , EncodeUserOperation ( partialUserOp ) , simulation ) . ConfigureAwait ( false ) ;
464
- partialUserOp . Paymaster = res . Paymaster ;
465
- partialUserOp . PaymasterData = res . PaymasterData ? . HexToBytes ( ) ?? Array . Empty < byte > ( ) ;
466
- partialUserOp . PreVerificationGas = new HexBigInteger ( res . PreVerificationGas ?? "0x0" ) . Value ;
467
- partialUserOp . VerificationGasLimit = new HexBigInteger ( res . VerificationGasLimit ?? "0x0" ) . Value ;
468
- partialUserOp . CallGasLimit = new HexBigInteger ( res . CallGasLimit ?? "0x0" ) . Value ;
469
- partialUserOp . PaymasterVerificationGasLimit = new HexBigInteger ( res . PaymasterVerificationGasLimit ?? "0x0" ) . Value ;
470
- partialUserOp . PaymasterPostOpGasLimit = new HexBigInteger ( res . PaymasterPostOpGasLimit ?? "0x0" ) . Value ;
471
- }
472
476
473
477
// Hash, sign and encode the user operation
474
478
0 commit comments