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

V0.1.6 update #27

Merged
merged 6 commits into from
Nov 4, 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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.1.8

* Fix incorrect useroperation receipt map key
* Fix safeSingleton type incosistency in create account

## 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);
}
22 changes: 12 additions & 10 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,13 +130,13 @@ 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
final initCallData = _safeProxyFactory.self
.function("createProxyWithNonce")
.encodeCall([singleton, initializer, salt.value]);
.encodeCall([singleton.address, initializer, salt.value]);

// Generate the initialization code by combining the account factory address and the encoded call data
final initCode = _getInitCode(initCallData);
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['receipt']),
);
}
}
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.8
documentation: https://docs.variance.space
homepage: https://variance.space
repository: https://github.com/vaariance/variance-dart
Expand Down
Loading