Skip to content

Commit

Permalink
fix: Paymaster (#28)
Browse files Browse the repository at this point in the history
* fix: do not modify any of the fields of the user operation after the paymaster signs over it

* keep the functions leaner
  • Loading branch information
LiorAgnin authored Dec 12, 2024
1 parent c5b52da commit 7851262
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.5"
version: "0.1.6"
vector_math:
dependency: transitive
description:
Expand Down
30 changes: 19 additions & 11 deletions lib/src/4337/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,33 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase {

@override
Future<UserOperationResponse> sendUserOperation(UserOperation op) =>
prepareUserOperation(op)
.then(applyCustomGasSettings)
.then(signUserOperation)
.then(sendSignedUserOperation);
_prepareAndSignOperation(op).then(sendSignedUserOperation);

Future<UserOperation> _prepareAndSignOperation(UserOperation op) async {
final prepared = await prepareUserOperation(op);
return signUserOperation(prepared);
}

@override
Future<UserOperation> prepareUserOperation(UserOperation op,
{bool update = true}) async {
// Update the user operation with the latest nonce and gas prices if needed
if (update) op = await _updateUserOperation(op);
// If the 'paymaster' plugin is enabled, intercept the user operation
if (hasPlugin('paymaster')) {
op = await plugin<Paymaster>('paymaster').intercept(op);
}
// Validate the user operation
op = await _updateIfNeeded(op, update);
op = await _applyPlugins(op);
op.validate(op.nonce > BigInt.zero, initCode);
return op;
}

Future<UserOperation> _updateIfNeeded(UserOperation op, bool update) async {
if (!update) return op;
op = await _updateUserOperation(op);
return applyCustomGasSettings(op);
}

Future<UserOperation> _applyPlugins(UserOperation op) async {
if (!hasPlugin('paymaster')) return op;
return plugin<Paymaster>('paymaster').intercept(op);
}

@override
Future<UserOperation> signUserOperation(UserOperation op,
{int? index}) async {
Expand Down

0 comments on commit 7851262

Please sign in to comment.