Skip to content

Commit f756eb5

Browse files
committed
add transaction receipt to sendOp response
1 parent 2c098f4 commit f756eb5

File tree

5 files changed

+95
-21
lines changed

5 files changed

+95
-21
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.1.7
2+
3+
* Add surpport for user defined safe singleton
4+
* Add transaction receipt to user operation receipt
5+
16
## 0.1.6
27

38
* Remove repetated function call in safe plugin

lib/src/4337/chains.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,18 @@ class Safe4337ModuleAddress {
248248
}
249249
}
250250
}
251+
252+
class SafeSingletonAddress {
253+
static SafeSingletonAddress l1 =
254+
SafeSingletonAddress(Constants.safeSingletonAddress);
255+
256+
static SafeSingletonAddress l2 =
257+
SafeSingletonAddress(Constants.safeL2SingletonAddress);
258+
259+
static SafeSingletonAddress custom(EthereumAddress address) =>
260+
SafeSingletonAddress(address);
261+
262+
final EthereumAddress address;
263+
264+
SafeSingletonAddress(this.address);
265+
}

lib/src/4337/factory.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SmartWalletFactory implements SmartWalletFactoryBase {
4646
@override
4747
Future<SmartWallet> createSafeAccountWithPasskey(PassKeyPair keyPair,
4848
Uint256 salt, EthereumAddress safeWebauthnSharedSigner,
49-
[EthereumAddress? p256Verifier]) {
49+
[EthereumAddress? p256Verifier, SafeSingletonAddress? singleton]) {
5050
final module = Safe4337ModuleAddress.fromVersion(_chain.entrypoint.version);
5151
final verifier = p256Verifier ?? Constants.p256VerifierAddress;
5252

@@ -70,15 +70,16 @@ class SmartWalletFactory implements SmartWalletFactoryBase {
7070
}
7171

7272
return _createSafeAccount(
73-
salt, safeWebauthnSharedSigner, module, encodeWebauthnSetup);
73+
salt, safeWebauthnSharedSigner, module, encodeWebauthnSetup, singleton);
7474
}
7575

7676
@override
77-
Future<SmartWallet> createSafeAccount(Uint256 salt) {
77+
Future<SmartWallet> createSafeAccount(Uint256 salt,
78+
[SafeSingletonAddress? singleton]) {
7879
final signer = EthereumAddress.fromHex(_signer.getAddress());
7980
final module = Safe4337ModuleAddress.fromVersion(_chain.entrypoint.version);
8081

81-
return _createSafeAccount(salt, signer, module);
82+
return _createSafeAccount(salt, signer, module, null, singleton);
8283
}
8384

8485
@override
@@ -114,10 +115,11 @@ class SmartWalletFactory implements SmartWalletFactoryBase {
114115

115116
Future<SmartWallet> _createSafeAccount(
116117
Uint256 salt, EthereumAddress signer, Safe4337ModuleAddress module,
117-
[Uint8List Function(Uint8List Function())? setup]) async {
118-
final singleton = _chain.chainId == 1
119-
? Constants.safeSingletonAddress
120-
: Constants.safeL2SingletonAddress;
118+
[Uint8List Function(Uint8List Function())? setup,
119+
SafeSingletonAddress? singleton]) async {
120+
singleton = _chain.chainId == 1
121+
? SafeSingletonAddress.l1
122+
: singleton ?? SafeSingletonAddress.l2;
121123

122124
// Get the initializer data for the Safe account
123125
final initializer =
@@ -128,7 +130,7 @@ class SmartWalletFactory implements SmartWalletFactoryBase {
128130

129131
// Predict the address of the Safe account
130132
final address = _safeProxyFactory.getPredictedSafe(
131-
initializer, salt, creation, singleton);
133+
initializer, salt, creation, singleton.address);
132134

133135
// Encode the call data for the `createProxyWithNonce` function
134136
// This function is used to create the Safe account with the given initializer data and salt

lib/src/4337/userop.dart

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,20 @@ class UserOperationReceipt {
341341
final bool success;
342342
String? reason;
343343
final List logs;
344+
final TransactionReceipt txReceipt;
344345

345346
UserOperationReceipt(
346-
this.userOpHash,
347-
this.entrypoint,
348-
this.sender,
349-
this.nonce,
350-
this.paymaster,
351-
this.actualGasCost,
352-
this.actualGasUsed,
353-
this.success,
354-
this.reason,
355-
this.logs,
356-
);
347+
this.userOpHash,
348+
this.entrypoint,
349+
this.sender,
350+
this.nonce,
351+
this.paymaster,
352+
this.actualGasCost,
353+
this.actualGasUsed,
354+
this.success,
355+
this.reason,
356+
this.logs,
357+
this.txReceipt);
357358

358359
factory UserOperationReceipt.fromMap(Map<String, dynamic> map) {
359360
return UserOperationReceipt(
@@ -367,6 +368,7 @@ class UserOperationReceipt {
367368
map['success'],
368369
map['reason'],
369370
List.castFrom(map['logs']),
371+
TransactionReceipt.fromMap(map['txReceipt']),
370372
);
371373
}
372374
}
@@ -413,3 +415,53 @@ class UserOperationResponse {
413415
"can't find useroperation with hash $userOpHash", timeout);
414416
}
415417
}
418+
419+
class TransactionReceipt {
420+
final String transactionHash;
421+
final String transactionIndex;
422+
final String blockHash;
423+
final String blockNumber;
424+
final String from;
425+
final String to;
426+
final String cumulativeGasUsed;
427+
final String gasUsed;
428+
final String? contractAddress;
429+
final List logs;
430+
final String? logsBloom;
431+
final String status;
432+
final String effectiveGasPrice;
433+
434+
TransactionReceipt(
435+
this.transactionHash,
436+
this.transactionIndex,
437+
this.blockHash,
438+
this.blockNumber,
439+
this.from,
440+
this.to,
441+
this.cumulativeGasUsed,
442+
this.gasUsed,
443+
this.contractAddress,
444+
this.logs,
445+
this.logsBloom,
446+
this.status,
447+
this.effectiveGasPrice,
448+
);
449+
450+
factory TransactionReceipt.fromMap(Map<String, dynamic> map) {
451+
return TransactionReceipt(
452+
map['transactionHash'],
453+
map['transactionIndex'],
454+
map['blockHash'],
455+
map['blockNumber'],
456+
map['from'],
457+
map['to'],
458+
map['cumulativeGasUsed'],
459+
map['gasUsed'],
460+
map['contractAddress'],
461+
List.castFrom(map['logs']),
462+
map['logsBloom'],
463+
map['status'],
464+
map['effectiveGasPrice'],
465+
);
466+
}
467+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: variance_dart
22
description: An Account Abstraction (4337) Development kit, for quickly building mobile web3 apps and smart wallets.
3-
version: 0.1.6
3+
version: 0.1.7
44
documentation: https://docs.variance.space
55
homepage: https://variance.space
66
repository: https://github.com/vaariance/variance-dart

0 commit comments

Comments
 (0)