Skip to content

Commit

Permalink
fix: verifying paymaster sponsorship
Browse files Browse the repository at this point in the history
  • Loading branch information
code-z2 committed Dec 12, 2024
1 parent 7851262 commit 73b3bbe
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 57 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.9

* Fix user-operation modififications post paymaster sponsorship

## 0.1.8

* Fix incorrect useroperation receipt map key
Expand Down
32 changes: 16 additions & 16 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.19.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -300,18 +300,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
url: "https://pub.dev"
source: hosted
version: "10.0.5"
version: "10.0.7"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
version: "3.0.8"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -580,7 +580,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
version: "0.0.0"
source_span:
dependency: transitive
description:
Expand All @@ -601,10 +601,10 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.12.0"
stream_channel:
dependency: "direct overridden"
description:
Expand All @@ -625,10 +625,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.3.0"
term_glyph:
dependency: transitive
description:
Expand All @@ -641,10 +641,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.7.3"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -683,7 +683,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.6"
version: "0.1.9"
vector_math:
dependency: transitive
description:
Expand All @@ -696,10 +696,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
url: "https://pub.dev"
source: hosted
version: "14.2.5"
version: "14.3.0"
wallet:
dependency: transitive
description:
Expand Down
29 changes: 12 additions & 17 deletions lib/src/4337/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,31 +148,26 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase {

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

Future<UserOperation> _prepareAndSignOperation(UserOperation op) async {
final prepared = await prepareUserOperation(op);
return signUserOperation(prepared);
}
prepareUserOperation(op)
.then(applyCustomGasSettings)
.then(sponsorUserOperation)
.then(signUserOperation)
.then(sendSignedUserOperation);

@override
Future<UserOperation> prepareUserOperation(UserOperation op,
{bool update = true}) async {
op = await _updateIfNeeded(op, update);
op = await _applyPlugins(op);
if (update) op = await _updateUserOperation(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> sponsorUserOperation(UserOperation op) async {
if (hasPlugin('paymaster')) {
op = await plugin<Paymaster>('paymaster').intercept(op);
}
return op;
}

@override
Expand Down
8 changes: 7 additions & 1 deletion lib/src/interfaces/smart_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ abstract class SmartWalletBase {
void dangerouslySetInitCode(Uint8List code);

/// Prepares a user operation by updating it with the latest nonce and gas prices,
/// intercepting it with a paymaster (if enabled), and validating it.
///
/// [op] is the user operation to prepare.
/// [update] is a flag indicating whether to update the user operation with the
Expand All @@ -90,6 +89,13 @@ abstract class SmartWalletBase {
Future<UserOperation> prepareUserOperation(UserOperation op,
{bool update = true});

/// Sponsors a user operation by intercepting it with the paymaster plugin, if present.
///
/// [op] is the user operation to sponsor.
///
/// Returns a [Future] that resolves to the sponsored [UserOperation] object.
Future<UserOperation> sponsorUserOperation(UserOperation op);

/// Asynchronously transfers native Token (ETH) to the specified recipient with the given amount.
///
/// Parameters:
Expand Down
31 changes: 9 additions & 22 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834
sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7"
url: "https://pub.dev"
source: hosted
version: "72.0.0"
_macros:
dependency: transitive
description: dart
source: sdk
version: "0.3.2"
version: "67.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139
sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d"
url: "https://pub.dev"
source: hosted
version: "6.7.0"
version: "6.4.1"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -154,10 +149,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.19.0"
convert:
dependency: transitive
description:
Expand All @@ -178,10 +173,10 @@ packages:
dependency: transitive
description:
name: dart_style
sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab"
sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9"
url: "https://pub.dev"
source: hosted
version: "2.3.7"
version: "2.3.6"
eip1559:
dependency: "direct main"
description:
Expand Down Expand Up @@ -328,14 +323,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
macros:
dependency: transitive
description:
name: macros
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
url: "https://pub.dev"
source: hosted
version: "0.1.2-main.4"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -500,7 +487,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
version: "0.0.0"
source_gen:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: variance_dart
description: An Account Abstraction (4337) Development kit, for quickly building mobile web3 apps and smart wallets.
version: 0.1.8
version: 0.1.9
documentation: https://docs.variance.space
homepage: https://variance.space
repository: https://github.com/vaariance/variance-dart
Expand Down

0 comments on commit 73b3bbe

Please sign in to comment.