diff --git a/CHANGELOG.md b/CHANGELOG.md index 21dadaa..6e2b41e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/4337/chains.dart b/lib/src/4337/chains.dart index bb95f38..baf1425 100644 --- a/lib/src/4337/chains.dart +++ b/lib/src/4337/chains.dart @@ -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); +} diff --git a/lib/src/4337/factory.dart b/lib/src/4337/factory.dart index 2a7c135..a9ffb29 100644 --- a/lib/src/4337/factory.dart +++ b/lib/src/4337/factory.dart @@ -46,7 +46,7 @@ class SmartWalletFactory implements SmartWalletFactoryBase { @override Future 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; @@ -70,15 +70,16 @@ class SmartWalletFactory implements SmartWalletFactoryBase { } return _createSafeAccount( - salt, safeWebauthnSharedSigner, module, encodeWebauthnSetup); + salt, safeWebauthnSharedSigner, module, encodeWebauthnSetup, singleton); } @override - Future createSafeAccount(Uint256 salt) { + Future 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 @@ -114,10 +115,11 @@ class SmartWalletFactory implements SmartWalletFactoryBase { Future _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 = @@ -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); diff --git a/lib/src/4337/userop.dart b/lib/src/4337/userop.dart index e4a2502..b9ebc23 100644 --- a/lib/src/4337/userop.dart +++ b/lib/src/4337/userop.dart @@ -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 map) { return UserOperationReceipt( @@ -367,6 +368,7 @@ class UserOperationReceipt { map['success'], map['reason'], List.castFrom(map['logs']), + TransactionReceipt.fromMap(map['receipt']), ); } } @@ -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 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'], + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 3a89b36..30951ec 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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