Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Paymaster #28

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading