Skip to content

Commit

Permalink
add transaction receipt to sendOp response
Browse files Browse the repository at this point in the history
  • Loading branch information
code-z2 committed Nov 2, 2024
1 parent 2c098f4 commit f756eb5
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.7

* Add surpport for user defined safe singleton
* Add transaction receipt to user operation receipt

## 0.1.6

* Remove repetated function call in safe plugin
Expand Down
15 changes: 15 additions & 0 deletions lib/src/4337/chains.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,18 @@ class Safe4337ModuleAddress {
}
}
}

class SafeSingletonAddress {
static SafeSingletonAddress l1 =
SafeSingletonAddress(Constants.safeSingletonAddress);

static SafeSingletonAddress l2 =
SafeSingletonAddress(Constants.safeL2SingletonAddress);

static SafeSingletonAddress custom(EthereumAddress address) =>
SafeSingletonAddress(address);

final EthereumAddress address;

SafeSingletonAddress(this.address);
}
20 changes: 11 additions & 9 deletions lib/src/4337/factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SmartWalletFactory implements SmartWalletFactoryBase {
@override
Future<SmartWallet> createSafeAccountWithPasskey(PassKeyPair keyPair,
Uint256 salt, EthereumAddress safeWebauthnSharedSigner,
[EthereumAddress? p256Verifier]) {
[EthereumAddress? p256Verifier, SafeSingletonAddress? singleton]) {
final module = Safe4337ModuleAddress.fromVersion(_chain.entrypoint.version);
final verifier = p256Verifier ?? Constants.p256VerifierAddress;

Expand All @@ -70,15 +70,16 @@ class SmartWalletFactory implements SmartWalletFactoryBase {
}

return _createSafeAccount(
salt, safeWebauthnSharedSigner, module, encodeWebauthnSetup);
salt, safeWebauthnSharedSigner, module, encodeWebauthnSetup, singleton);
}

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

return _createSafeAccount(salt, signer, module);
return _createSafeAccount(salt, signer, module, null, singleton);
}

@override
Expand Down Expand Up @@ -114,10 +115,11 @@ class SmartWalletFactory implements SmartWalletFactoryBase {

Future<SmartWallet> _createSafeAccount(
Uint256 salt, EthereumAddress signer, Safe4337ModuleAddress module,
[Uint8List Function(Uint8List Function())? setup]) async {
final singleton = _chain.chainId == 1
? Constants.safeSingletonAddress
: Constants.safeL2SingletonAddress;
[Uint8List Function(Uint8List Function())? setup,
SafeSingletonAddress? singleton]) async {
singleton = _chain.chainId == 1
? SafeSingletonAddress.l1
: singleton ?? SafeSingletonAddress.l2;

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

// Predict the address of the Safe account
final address = _safeProxyFactory.getPredictedSafe(
initializer, salt, creation, singleton);
initializer, salt, creation, singleton.address);

// Encode the call data for the `createProxyWithNonce` function
// This function is used to create the Safe account with the given initializer data and salt
Expand Down
74 changes: 63 additions & 11 deletions lib/src/4337/userop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,20 @@ class UserOperationReceipt {
final bool success;
String? reason;
final List logs;
final TransactionReceipt txReceipt;

UserOperationReceipt(
this.userOpHash,
this.entrypoint,
this.sender,
this.nonce,
this.paymaster,
this.actualGasCost,
this.actualGasUsed,
this.success,
this.reason,
this.logs,
);
this.userOpHash,
this.entrypoint,
this.sender,
this.nonce,
this.paymaster,
this.actualGasCost,
this.actualGasUsed,
this.success,
this.reason,
this.logs,
this.txReceipt);

factory UserOperationReceipt.fromMap(Map<String, dynamic> map) {
return UserOperationReceipt(
Expand All @@ -367,6 +368,7 @@ class UserOperationReceipt {
map['success'],
map['reason'],
List.castFrom(map['logs']),
TransactionReceipt.fromMap(map['txReceipt']),
);
}
}
Expand Down Expand Up @@ -413,3 +415,53 @@ class UserOperationResponse {
"can't find useroperation with hash $userOpHash", timeout);
}
}

class TransactionReceipt {
final String transactionHash;
final String transactionIndex;
final String blockHash;
final String blockNumber;
final String from;
final String to;
final String cumulativeGasUsed;
final String gasUsed;
final String? contractAddress;
final List logs;
final String? logsBloom;
final String status;
final String effectiveGasPrice;

TransactionReceipt(
this.transactionHash,
this.transactionIndex,
this.blockHash,
this.blockNumber,
this.from,
this.to,
this.cumulativeGasUsed,
this.gasUsed,
this.contractAddress,
this.logs,
this.logsBloom,
this.status,
this.effectiveGasPrice,
);

factory TransactionReceipt.fromMap(Map<String, dynamic> map) {
return TransactionReceipt(
map['transactionHash'],
map['transactionIndex'],
map['blockHash'],
map['blockNumber'],
map['from'],
map['to'],
map['cumulativeGasUsed'],
map['gasUsed'],
map['contractAddress'],
List.castFrom(map['logs']),
map['logsBloom'],
map['status'],
map['effectiveGasPrice'],
);
}
}
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.6
version: 0.1.7
documentation: https://docs.variance.space
homepage: https://variance.space
repository: https://github.com/vaariance/variance-dart
Expand Down

0 comments on commit f756eb5

Please sign in to comment.