diff --git a/CHANGELOG.md b/CHANGELOG.md index d0b7f10..68e9240 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.1.3 + +* replace Simple account with Alchemy light account +* hardcoded safe proxy creation code to reduce network requests +* add light account abi and signature prefix +* separate constants from chains + ## 0.1.2 * Update web3-signers diff --git a/README.md b/README.md index da60629..7b31cd4 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,9 @@ In order to create a smart wallet client you need to set up a signer, which will > You have to use the correct signer for the type of account you want to create. -1. `PrivateKeys` - use with simple accounts and safe accounts only +1. `PrivateKeys` - use with light accounts and safe accounts only 2. `Passkey` - use with p256 smart accounts and safe Passkey accounts only -3. `EOA Wallet (Seed Phrases)` - use with simple smart accounts and safe accounts only +3. `EOA Wallet (Seed Phrases)` - use with light smart accounts and safe accounts only 4. `HardWare Signers (Secure Enclave/Keystore)` - use with p256 smart accounts only ### Smart Wallet Factory @@ -88,11 +88,11 @@ The smart wallet factory handles the creation of smart wallet instances. Make su final SmartWalletFactory smartWalletFactory = SmartWalletFactory(chain, signer); ``` -#### To Create a Simple Smart Account +#### To Create an Alchemy Light Account ```dart -final Smartwallet wallet = await smartWalletFactory.createSimpleAccount(salt); -print("simple wallet address: ${wallet.address.hex}"); +final Smartwallet wallet = await smartWalletFactory.createAlchemyLightAccount(salt); +print("light account wallet address: ${wallet.address.hex}"); ``` #### To create a P256 Smart Account (Secure Enclave/Keystore) diff --git a/example/lib/providers/wallet_provider.dart b/example/lib/providers/wallet_provider.dart index f640d00..fe2358f 100644 --- a/example/lib/providers/wallet_provider.dart +++ b/example/lib/providers/wallet_provider.dart @@ -76,7 +76,7 @@ class WalletProvider extends ChangeNotifier { } Future createEOAWallet() async { - _chain.accountFactory = Constants.simpleAccountFactoryAddressv06; + _chain.accountFactory = Constants.lightAccountFactoryAddressv06; final signer = EOAWallet.createWallet(); log("signer: ${signer.getAddress()}"); @@ -86,7 +86,7 @@ class WalletProvider extends ChangeNotifier { .keccak256(EthereumAddress.fromHex(signer.getAddress()).addressBytes))); try { - _wallet = await walletFactory.createSimpleAccount(salt); + _wallet = await walletFactory.createAlchemyLightAccount(salt); log("wallet created ${_wallet?.address.hex} "); } catch (e) { _errorMessage = e.toString(); @@ -111,7 +111,7 @@ class WalletProvider extends ChangeNotifier { log("pk salt: ${salt.toHex()}"); try { - _wallet = await walletFactory.createSimpleAccount(salt); + _wallet = await walletFactory.createAlchemyLightAccount(salt); log("pk wallet created ${_wallet?.address.hex} "); } catch (e) { _errorMessage = e.toString(); diff --git a/example/pubspec.lock b/example/pubspec.lock index ef71a61..664766e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,10 +5,10 @@ packages: dependency: transitive description: name: ansicolor - sha256: "8bf17a8ff6ea17499e40a2d2542c2f481cd7615760c6d34065cb22bfd22e6880" + sha256: "50e982d500bc863e1d703448afdbf9e5a72eb48840a4f766fa361ffd6877055f" url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.0.3" archive: dependency: transitive description: @@ -29,10 +29,10 @@ packages: dependency: transitive description: name: asn1lib - sha256: "58082b3f0dca697204dbab0ef9ff208bfaea7767ea771076af9a343488428dda" + sha256: "6b151826fcc95ff246cd219a0bf4c753ea14f4081ad71c61939becf3aba27f70" url: "https://pub.dev" source: hosted - version: "1.5.3" + version: "1.5.5" async: dependency: transitive description: @@ -45,10 +45,10 @@ packages: dependency: transitive description: name: blockchain_utils - sha256: "699d72427447814bd574b95b0d3baf9b2c0ec9c9b82deef3c6264c6f5efa4406" + sha256: ebb6c336ba0120de0982c50d8bc597cb494a530bd22bd462895bb5cebde405af url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.4.0" boolean_selector: dependency: transitive description: @@ -105,22 +105,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.1" - corbado_frontend_api_client: - dependency: transitive - description: - name: corbado_frontend_api_client - sha256: a6d65fc0da88f2e6a6e95251de0b67735556128c5d96c9b609e7b18010a6f6c1 - url: "https://pub.dev" - source: hosted - version: "1.1.0" crypto: dependency: transitive description: name: crypto - sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27 url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" csslib: dependency: transitive description: @@ -165,10 +157,10 @@ packages: dependency: transitive description: name: ffi - sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" + sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6" url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" file: dependency: transitive description: @@ -210,10 +202,10 @@ packages: dependency: "direct main" description: name: flutter_native_splash - sha256: edf39bcf4d74aca1eb2c1e43c3e445fd9f494013df7f0da752fefe72020eedc0 + sha256: aa06fec78de2190f3db4319dd60fdc8d12b2626e93ef9828633928c2dcaea840 url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.1" flutter_screenutil: dependency: "direct main" description: @@ -236,10 +228,10 @@ packages: dependency: "direct main" description: name: fluttertoast - sha256: "81b68579e23fcbcada2db3d50302813d2371664afe6165bc78148050ab94bf66" + sha256: "95f349437aeebe524ef7d6c9bde3e6b4772717cf46a0eb6a3ceaddc740b297cc" url: "https://pub.dev" source: hosted - version: "8.2.5" + version: "8.2.8" google_fonts: dependency: "direct main" description: @@ -260,10 +252,10 @@ packages: dependency: transitive description: name: http - sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" + sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.2.2" http_parser: dependency: transitive description: @@ -280,22 +272,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.2.0" - intl: - dependency: transitive - description: - name: intl - sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" - url: "https://pub.dev" - source: hosted - version: "0.18.1" js: dependency: transitive description: name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "0.7.1" json_annotation: dependency: transitive description: @@ -376,54 +360,46 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" - openapi_generator_annotations: - dependency: transitive - description: - name: openapi_generator_annotations - sha256: "46f1fb675029d78e19ce9143e70ce414d738b0f6c45c49c004b4b3afdb405a5c" - url: "https://pub.dev" - source: hosted - version: "4.13.1" passkeys: dependency: transitive description: name: passkeys - sha256: "59e50b21746aff90cbc56145174caa3b99523f449e42f7d8aa2199ec09c511cd" + sha256: c14264d11c6cf631296b21760c0411b26a5e223511cab9387d4b8c551189c34c url: "https://pub.dev" source: hosted - version: "2.0.8" + version: "2.1.0" passkeys_android: dependency: transitive description: name: passkeys_android - sha256: "9dc0b84dad03329ff2f3be18bedecf1b8de9309c8e9cda6ef821dc88556a126d" + sha256: e7f6aa1131b0c0e954bb50d0b59e9bbf6fb8eb0a6a1c282d6af982df5d746b51 url: "https://pub.dev" source: hosted - version: "2.0.4" + version: "2.1.0" passkeys_ios: dependency: transitive description: name: passkeys_ios - sha256: "411b10c3cd159c9601426d47b2dc5aa4dd1e34ef69deefaac01ff81712ea6064" + sha256: "1e23e40efd12867725443923a72914c11f926dce8623757b45ed2d7a16e95731" url: "https://pub.dev" source: hosted - version: "2.0.3" + version: "2.1.0" passkeys_platform_interface: dependency: transitive description: name: passkeys_platform_interface - sha256: a1f1f5c637049f68350cf43323df9689be2e86fe5822a6e098362e7f6168351e + sha256: e32fbac05561a1c3ab439a504e7c19daf96b8339fd6bcbdac40e2ed9281add57 url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.1.0" passkeys_web: dependency: transitive description: name: passkeys_web - sha256: "1c7815020332b9be1af4df67686826a91b6dd29fea53be947d6082654abd6280" + sha256: e09df6485e851581848ce3481c56bb2be571a12137c13325373bdfa519a9387a url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.1.0" path: dependency: transitive description: @@ -436,18 +412,18 @@ packages: dependency: "direct main" description: name: path_provider - sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161 + sha256: fec0d61223fba3154d87759e3cc27fe2c8dc498f6386c6d6fc80d1afdd1bf378 url: "https://pub.dev" source: hosted - version: "2.1.3" + version: "2.1.4" path_provider_android: dependency: transitive description: name: path_provider_android - sha256: "9c96da072b421e98183f9ea7464898428e764bc0ce5567f27ec8693442e72514" + sha256: "6f01f8e37ec30b07bc424b4deabac37cacb1bc7e2e515ad74486039918a37eb7" url: "https://pub.dev" source: hosted - version: "2.2.5" + version: "2.2.10" path_provider_foundation: dependency: transitive description: @@ -476,10 +452,10 @@ packages: dependency: transitive description: name: path_provider_windows - sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" + sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7 url: "https://pub.dev" source: hosted - version: "2.2.1" + version: "2.3.0" petitparser: dependency: transitive description: @@ -492,10 +468,10 @@ packages: dependency: transitive description: name: platform - sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65" url: "https://pub.dev" source: hosted - version: "3.1.4" + version: "3.1.5" plugin_platform_interface: dependency: transitive description: @@ -524,10 +500,10 @@ packages: dependency: transitive description: name: qr - sha256: "64957a3930367bf97cc211a5af99551d630f2f4625e38af10edd6b19131b64b3" + sha256: "5a1d2586170e172b8a8c8470bbbffd5eb0cd38a66c0d77155ea138d3af3a4445" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" qr_flutter: dependency: "direct main" description: @@ -548,58 +524,58 @@ packages: dependency: "direct main" description: name: shared_preferences - sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180 + sha256: "746e5369a43170c25816cc472ee016d3a66bc13fcf430c0bc41ad7b4b2922051" url: "https://pub.dev" source: hosted - version: "2.2.3" + version: "2.3.2" shared_preferences_android: dependency: transitive description: name: shared_preferences_android - sha256: "93d0ec9dd902d85f326068e6a899487d1f65ffcd5798721a95330b26c8131577" + sha256: "480ba4345773f56acda9abf5f50bd966f581dac5d514e5fc4a18c62976bbba7e" url: "https://pub.dev" source: hosted - version: "2.2.3" + version: "2.3.2" shared_preferences_foundation: dependency: transitive description: name: shared_preferences_foundation - sha256: "0a8a893bf4fd1152f93fec03a415d11c27c74454d96e2318a7ac38dd18683ab7" + sha256: "07e050c7cd39bad516f8d64c455f04508d09df104be326d8c02551590a0d513d" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.5.3" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux - sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa" + sha256: "580abfd40f415611503cae30adf626e6656dfb2f0cee8f465ece7b6defb40f2f" url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.4.1" shared_preferences_platform_interface: dependency: transitive description: name: shared_preferences_platform_interface - sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b" + sha256: "57cbf196c486bc2cf1f02b85784932c6094376284b3ad5779d1b1c6c6a816b80" url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.4.1" shared_preferences_web: dependency: transitive description: name: shared_preferences_web - sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a" + sha256: d2ca4132d3946fec2184261726b355836a82c33d7d5b67af32692aff18a4684e url: "https://pub.dev" source: hosted - version: "2.3.0" + version: "2.4.2" shared_preferences_windows: dependency: transitive description: name: shared_preferences_windows - sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59" + sha256: "94ef0f72b2d71bc3e700e025db3710911bd51a71cefb65cc609dd0d9a982e3c1" url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.4.1" sky_engine: dependency: transitive description: flutter @@ -681,10 +657,10 @@ packages: dependency: transitive description: name: ua_client_hints - sha256: "8401d7bec261f61b3d3b61cd877653ddf840de2d9e07bd164f34588572aa0c8b" + sha256: dfea54a1b4d259c057d0f33f198094cf4e09e1a21d347baadbe6dbd3d820c0d4 url: "https://pub.dev" source: hosted - version: "1.2.2" + version: "1.4.0" universal_io: dependency: transitive description: @@ -697,17 +673,17 @@ packages: dependency: transitive description: name: uuid - sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8" + sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff url: "https://pub.dev" source: hosted - version: "4.4.0" + version: "4.5.1" variance_dart: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.1.2" + version: "0.1.3" vector_math: dependency: transitive description: @@ -736,18 +712,18 @@ packages: dependency: transitive description: name: web - sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "1.1.0" web3_signers: dependency: "direct main" description: name: web3_signers - sha256: de57dbdde9bbaa3c503adb169b082f6342f502b7492420a7365d5fa979283ab0 + sha256: "455acf0207ef6edc5937a73edd57ce94f028b41856c07193be23e282d542d625" url: "https://pub.dev" source: hosted - version: "0.0.12" + version: "0.0.14-alpha-01" web3dart: dependency: "direct main" description: @@ -756,22 +732,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.7.3" - win32: - dependency: transitive - description: - name: win32 - sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4 - url: "https://pub.dev" - source: hosted - version: "5.5.1" xdg_directories: dependency: transitive description: name: xdg_directories - sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d + sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.1.0" xml: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 03b61bb..4a202f8 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: fluttertoast: ^8.2.4 variance_dart: path: ../ - web3_signers: ^0.0.6 + web3_signers: ^0.0.14-alpha-01 dev_dependencies: flutter_test: diff --git a/lib/src/4337/chains.dart b/lib/src/4337/chains.dart index 4c26a7f..d26cebe 100644 --- a/lib/src/4337/chains.dart +++ b/lib/src/4337/chains.dart @@ -65,77 +65,75 @@ class Chain { //predefined Chains you can use class Chains { static Map chains = { - Network.ethereum: Chain( + Network.mainnet: Chain( chainId: 1, explorer: "https://etherscan.io/", jsonRpcUrl: "https://rpc.ankr.com/eth", - entrypoint: EntryPointAddress.v06, + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, ), Network.polygon: Chain( chainId: 137, explorer: "https://polygonscan.com/", jsonRpcUrl: "https://rpc.ankr.com/polygon", - entrypoint: EntryPointAddress.v06, + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, ), Network.optimism: Chain( chainId: 10, explorer: "https://explorer.optimism.io", jsonRpcUrl: "https://rpc.ankr.com/optimism", - entrypoint: EntryPointAddress.v06, + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, ), Network.base: Chain( chainId: 8453, explorer: "https://basescan.org", jsonRpcUrl: "https://rpc.ankr.com/base", - entrypoint: EntryPointAddress.v06, + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, ), - Network.arbitrumOne: Chain( + Network.arbitrum: Chain( chainId: 42161, explorer: "https://arbiscan.io/", jsonRpcUrl: "https://rpc.ankr.com/arbitrum", - entrypoint: EntryPointAddress.v06, + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, ), Network.linea: Chain( - chainId: 59144, - explorer: "https://lineascan.build/", - jsonRpcUrl: "https://rpc.linea.build", - entrypoint: EntryPointAddress.v06), - Network.opBnB: Chain( - chainId: 204, - explorer: "http://opbnbscan.com/", - jsonRpcUrl: "https://opbnb-mainnet-rpc.bnbchain.org", - entrypoint: EntryPointAddress.v06, + chainId: 59144, + explorer: "https://lineascan.build/", + jsonRpcUrl: "https://rpc.linea.build", + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, ), Network.scroll: Chain( chainId: 534352, explorer: "https://scrollscan.com/", jsonRpcUrl: "https://rpc.ankr.com/scroll", - entrypoint: EntryPointAddress.v06, + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, + ), + Network.fuse: Chain( + chainId: 122, + explorer: "https://explorer.fuse.io", + jsonRpcUrl: "https://rpc.fuse.io", + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, ), Network.sepolia: Chain( chainId: 11155111, explorer: "https://sepolia.etherscan.io/", jsonRpcUrl: "https://rpc.ankr.com/eth_sepolia", - entrypoint: EntryPointAddress.v06, - ), - Network.mumbai: Chain( - chainId: 80001, - explorer: "https://mumbai.polygonscan.com/", - jsonRpcUrl: "https://rpc.ankr.com/polygon_mumbai", - entrypoint: EntryPointAddress.v06, + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, ), Network.baseTestnet: Chain( chainId: 84532, explorer: "https://sepolia.basescan.org/", jsonRpcUrl: "https://rpc.ankr.com/base_sepolia", - entrypoint: EntryPointAddress.v06, - ), - Network.localhost: Chain( - chainId: 1337, - explorer: "http://localhost:8545", - jsonRpcUrl: "http://localhost:8545", - bundlerUrl: "http://localhost:3000/rpc", - entrypoint: EntryPointAddress.v06, + entrypoint: EntryPointAddress.v07, + accountFactory: Constants.safeProxyFactoryAddress, ) }; @@ -159,53 +157,20 @@ class Chains { } } -class Constants { - static EthereumAddress entrypointv06 = - EthereumAddress.fromHex("0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"); - static EthereumAddress entrypointv07 = - EthereumAddress.fromHex("0x0000000071727De22E5E9d8BAf0edAc6f37da032"); - static EthereumAddress zeroAddress = - EthereumAddress.fromHex("0x0000000000000000000000000000000000000000"); - static final EthereumAddress simpleAccountFactoryAddressv06 = - EthereumAddress.fromHex("0x9406Cc6185a346906296840746125a0E44976454"); - static final EthereumAddress simpleAccountFactoryAddressv07 = - EthereumAddress.fromHex("0x91E60e0613810449d098b0b5Ec8b51A0FE8c8985"); - static final EthereumAddress safeProxyFactoryAddress = - EthereumAddress.fromHex("0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"); - static final EthereumAddress safe4337ModuleAddressv06 = - EthereumAddress.fromHex("0xa581c4A4DB7175302464fF3C06380BC3270b4037"); - static final EthereumAddress safe4337ModuleAddressv07 = - EthereumAddress.fromHex("0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226"); - static final EthereumAddress safeSingletonAddress = - EthereumAddress.fromHex("0x41675C099F32341bf84BFc5382aF534df5C7461a"); - static final EthereumAddress safeModuleSetupAddressv06 = - EthereumAddress.fromHex("0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb"); - static final EthereumAddress safeModuleSetupAddressv07 = - EthereumAddress.fromHex("0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47"); - static final EthereumAddress safeMultiSendaddress = - EthereumAddress.fromHex("0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526"); - - Constants._(); -} - enum Network { // mainnet - ethereum, + mainnet, polygon, optimism, base, - arbitrumOne, + arbitrum, linea, - opBnB, scroll, + fuse, // testnet sepolia, - mumbai, baseTestnet, - - // localhost - localhost } /// Represents the address of an EntryPoint contract on the Ethereum blockchain. diff --git a/lib/src/4337/factory.dart b/lib/src/4337/factory.dart index f049f40..0acac55 100644 --- a/lib/src/4337/factory.dart +++ b/lib/src/4337/factory.dart @@ -43,8 +43,8 @@ class SmartWalletFactory implements SmartWalletFactoryBase { chainId: _chain.chainId, rpc: _jsonRpc.rpc); - /// A getter for the SimpleAccountFactory contract instance. - _SimpleAccountFactory get _simpleAccountfactory => _SimpleAccountFactory( + /// A getter for the LightAccountFactory contract instance. + _LightAccountFactory get _lightAccountfactory => _LightAccountFactory( address: _chain.accountFactory!, chainId: _chain.chainId, rpc: _jsonRpc.rpc); @@ -95,24 +95,27 @@ class SmartWalletFactory implements SmartWalletFactoryBase { } @override - Future createSimpleAccount(Uint256 salt, [int? index]) async { + Future createAlchemyLightAccount(Uint256 salt, + [int? index]) async { final signer = EthereumAddress.fromHex(_signer.getAddress(index: index ?? 0)); - // Get the predicted address of the simple account - final address = await _simpleAccountfactory.getAddress(signer, salt.value); + // Get the predicted address of the light account + final address = await _lightAccountfactory + .getAddress((owner: signer, salt: salt.value)); // Encode the call data for the `createAccount` function - // This function is used to create the simple account with the given signer address and salt - final initCalldata = _simpleAccountfactory.self + // This function is used to create the light account with the given signer address and salt + final initCalldata = _lightAccountfactory.self .function('createAccount') .encodeCall([signer, salt.value]); // Generate the initialization code by combining the account factory address and the encoded call data final initCode = _getInitCode(initCalldata); - // Create the SmartWallet instance for the simple account - return _createAccount(_chain, address, initCode); + // Create the SmartWallet instance for the light account + return _createAccount( + _chain, address, initCode, Constants.defaultBytePrefix); } @override @@ -137,8 +140,9 @@ class SmartWalletFactory implements SmartWalletFactoryBase { /// /// Returns a [SmartWallet] instance representing the created account. SmartWallet _createAccount( - Chain chain, EthereumAddress address, Uint8List initCalldata) { - final wallet = SmartWallet(chain, address, initCalldata) + Chain chain, EthereumAddress address, Uint8List initCalldata, + [Uint8List? prefix]) { + final wallet = SmartWallet(chain, address, initCalldata, prefix) ..addPlugin('signer', _signer) ..addPlugin('bundler', _bundler) ..addPlugin('jsonRpc', _jsonRpc) @@ -188,8 +192,8 @@ class SmartWalletFactory implements SmartWalletFactoryBase { .function('createP256Account') .encodeCall([salt.value, creation]); final initCode = _getInitCode(initCalldata); - final address = - await _p256Accountfactory.getP256AccountAddress(salt.value, creation); + final address = await _p256Accountfactory + .getP256AccountAddress((salt: salt.value, creation: creation)); return _createAccount(_chain, address, initCode); } @@ -228,8 +232,8 @@ class SmartWalletFactory implements SmartWalletFactoryBase { .function('createP256Account') .encodeCall([salt.value, creation]); final initCode = _getInitCode(initCalldata); - final address = - await _p256Accountfactory.getP256AccountAddress(salt.value, creation); + final address = await _p256Accountfactory + .getP256AccountAddress((salt: salt.value, creation: creation)); return _createAccount(_chain, address, initCode); } diff --git a/lib/src/4337/safe.dart b/lib/src/4337/safe.dart index 064214e..f0aa190 100644 --- a/lib/src/4337/safe.dart +++ b/lib/src/4337/safe.dart @@ -20,27 +20,29 @@ class _SafePlugin extends Safe4337Module implements Safe4337ModuleBase { /// [blockInfo] is the current blockInformation including the timestamp and baseFee. /// /// Returns a HexString representing the encoded signature with a validity period. - String getSafeSignature(String signature, BlockInformation blockInfo) { - final timestamp = blockInfo.timestamp.millisecondsSinceEpoch ~/ 1000; - - String validAfter = (timestamp - 3600).toRadixString(16); - validAfter = '0' * (12 - validAfter.length) + validAfter; + String getSafeSignature(T signature, BlockInformation blockInfo) { + late Uint8List signatureBytes; - String validUntil = (timestamp + 3600).toRadixString(16); - validUntil = '0' * (12 - validUntil.length) + validUntil; + if (signature is Uint8List) { + signatureBytes = signature; + } else if (signature is String && signature.startsWith('0x')) { + signatureBytes = hexToBytes(signature); + } else { + throw ArgumentError('Unsupported signature type'); + } + final timestamp = blockInfo.timestamp.millisecondsSinceEpoch ~/ 1000; - int v = int.parse(signature.substring(130, 132), radix: 16); + String validAfter = (timestamp - 3600).toRadixString(16).padLeft(12, '0'); + String validUntil = (timestamp + 3600).toRadixString(16).padLeft(12, '0'); + int v = signatureBytes[64]; if (v >= 27 && v <= 30) { v += 4; } - String modifiedV = v.toRadixString(16); - if (modifiedV.length == 1) { - modifiedV = '0$modifiedV'; - } - - return '0x$validAfter$validUntil${signature.substring(2, 130)}$modifiedV'; + String modifiedV = v.toRadixString(16).padLeft(2, '0'); + String hexSignature = hexlify(signatureBytes.sublist(0, 64)); + return '0x$validAfter$validUntil$hexSignature$modifiedV'; } /// Computes the hash of a Safe UserOperation. @@ -52,31 +54,35 @@ class _SafePlugin extends Safe4337Module implements Safe4337ModuleBase { Future getSafeOperationHash( UserOperation op, BlockInformation blockInfo) async { if (self.address == Safe4337ModuleAddress.v07.address) { - return getOperationHash$2([ + return getOperationHash$2(( + userOp: [ + op.sender, + op.nonce, + op.initCode, + op.callData, + packUints(op.verificationGasLimit, op.callGasLimit), + op.preVerificationGas, + packUints(op.maxPriorityFeePerGas, op.maxFeePerGas), + op.paymasterAndData, + hexToBytes(getSafeSignature(op.signature, blockInfo)) + ] + )); + } + return getOperationHash(( + userOp: [ op.sender, op.nonce, op.initCode, op.callData, - packUints(op.verificationGasLimit, op.callGasLimit), + op.callGasLimit, + op.verificationGasLimit, op.preVerificationGas, - packUints(op.maxPriorityFeePerGas, op.maxFeePerGas), + op.maxFeePerGas, + op.maxPriorityFeePerGas, op.paymasterAndData, hexToBytes(getSafeSignature(op.signature, blockInfo)) - ]); - } - return getOperationHash([ - op.sender, - op.nonce, - op.initCode, - op.callData, - op.callGasLimit, - op.verificationGasLimit, - op.preVerificationGas, - op.maxFeePerGas, - op.maxPriorityFeePerGas, - op.paymasterAndData, - hexToBytes(getSafeSignature(op.signature, blockInfo)) - ]); + ] + )); } Uint8List getSafeMultisendCallData(List recipients, diff --git a/lib/src/4337/wallet.dart b/lib/src/4337/wallet.dart index c5a6da0..bca90e4 100644 --- a/lib/src/4337/wallet.dart +++ b/lib/src/4337/wallet.dart @@ -25,7 +25,7 @@ part of '../../variance_dart.dart'; /// final response = await wallet.send(recipient, amount); /// ``` class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase { - /// The blockchain chain configuration. + /// The chain configuration. final Chain _chain; /// The address of the Smart Wallet. @@ -34,12 +34,18 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase { /// The initialization code for deploying the Smart Wallet contract. Uint8List _initCode; + /// Defines the signer type for Alchemy Light Accounts. + final Uint8List _prefix; + /// Creates a new instance of the [SmartWallet] class. /// /// [_chain] is an object representing the blockchain chain configuration. /// [_walletAddress] is the address of the Smart Wallet. /// [_initCode] is the initialization code for deploying the Smart Wallet contract. - SmartWallet(this._chain, this._walletAddress, this._initCode); + /// [prefix] is the signature prefix for signing light account transactions. + SmartWallet(this._chain, this._walletAddress, this._initCode, + [Uint8List? signaturePrefix]) + : _prefix = signaturePrefix ?? Uint8List(0); @override EthereumAddress get address => _walletAddress; @@ -65,7 +71,8 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase { String? get toHex => _walletAddress.hexEip55; @override - String get dummySignature => plugin('signer').dummySignature; + String get dummySignature => + plugin('signer').getDummySignature(prefix: hexlify(_prefix)); /// Returns the estimated gas required for deploying the Smart Wallet contract. /// @@ -179,12 +186,11 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase { // Sign the operation hash using the 'signer' plugin final signature = await plugin('signer').personalSign(opHash, index: index); - final signatureHex = hexlify(signature); // Append the signature validity period if the 'safe' plugin is enabled op.signature = isSafe - ? plugin<_SafePlugin>('safe').getSafeSignature(signatureHex, blockInfo) - : signatureHex; + ? plugin<_SafePlugin>('safe').getSafeSignature(signature, blockInfo) + : hexlify(_prefix + signature); return op; } diff --git a/lib/src/abis/abis.dart b/lib/src/abis/abis.dart index 6b08f08..e916e00 100644 --- a/lib/src/abis/abis.dart +++ b/lib/src/abis/abis.dart @@ -1,4 +1,4 @@ -export 'simpleAccountFactory.g.dart'; +export 'lightAccountFactory.g.dart'; export 'p256AccountFactory.g.dart'; export 'safeProxyFactory.g.dart'; export 'safe4337Module.g.dart'; diff --git a/lib/src/abis/entrypoint.g.dart b/lib/src/abis/entrypoint.g.dart index 38ded38..0dff15a 100644 --- a/lib/src/abis/entrypoint.g.dart +++ b/lib/src/abis/entrypoint.g.dart @@ -1,5 +1,8 @@ -// Generated code, do not modify. Run `build_runner build` to re-generate! -// @dart=2.12 +// @dart=3.0 +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_local_variable, unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:web3dart/web3dart.dart' as _i1; import 'dart:typed_data' as _i2; @@ -42,17 +45,19 @@ class Entrypoint extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future _validateSenderAndPaymaster( - _i2.Uint8List initCode, - _i1.EthereumAddress sender, - _i2.Uint8List paymasterAndData, { + ({ + _i2.Uint8List initCode, + _i1.EthereumAddress sender, + _i2.Uint8List paymasterAndData + }) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[1]; assert(checkSignature(function, '957122ab')); final params = [ - initCode, - sender, - paymasterAndData, + args.initCode, + args.sender, + args.paymasterAndData, ]; final response = await read( function, @@ -65,13 +70,13 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future addStake( - BigInt unstakeDelaySec, { + ({BigInt unstakeDelaySec}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[2]; assert(checkSignature(function, '0396cb60')); - final params = [unstakeDelaySec]; + final params = [args.unstakeDelaySec]; return write( credentials, transaction, @@ -84,12 +89,12 @@ class Entrypoint extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future balanceOf( - _i1.EthereumAddress account, { + ({_i1.EthereumAddress account}) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[3]; assert(checkSignature(function, '70a08231')); - final params = [account]; + final params = [args.account]; final response = await read( function, params, @@ -102,13 +107,13 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future depositTo( - _i1.EthereumAddress account, { + ({_i1.EthereumAddress account}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[4]; assert(checkSignature(function, 'b760faf9')); - final params = [account]; + final params = [args.account]; return write( credentials, transaction, @@ -121,12 +126,12 @@ class Entrypoint extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future deposits( - _i1.EthereumAddress $param6, { + ({_i1.EthereumAddress $param6}) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[5]; assert(checkSignature(function, 'fc7e286d')); - final params = [$param6]; + final params = [args.$param6]; final response = await read( function, params, @@ -139,12 +144,12 @@ class Entrypoint extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future getDepositInfo( - _i1.EthereumAddress account, { + ({_i1.EthereumAddress account}) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[6]; assert(checkSignature(function, '5287ce12')); - final params = [account]; + final params = [args.account]; final response = await read( function, params, @@ -157,15 +162,14 @@ class Entrypoint extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future getNonce( - _i1.EthereumAddress sender, - BigInt key, { + ({_i1.EthereumAddress sender, BigInt key}) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[7]; assert(checkSignature(function, '35567e1a')); final params = [ - sender, - key, + args.sender, + args.key, ]; final response = await read( function, @@ -179,13 +183,13 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future getSenderAddress( - _i2.Uint8List initCode, { + ({_i2.Uint8List initCode}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[8]; assert(checkSignature(function, '9b249f69')); - final params = [initCode]; + final params = [args.initCode]; return write( credentials, transaction, @@ -198,12 +202,12 @@ class Entrypoint extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i2.Uint8List> getUserOpHash( - dynamic userOp, { + ({dynamic userOp}) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[9]; assert(checkSignature(function, 'a6193531')); - final params = [userOp]; + final params = [args.userOp]; final response = await read( function, params, @@ -216,16 +220,15 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future handleAggregatedOps( - List opsPerAggregator, - _i1.EthereumAddress beneficiary, { + ({List opsPerAggregator, _i1.EthereumAddress beneficiary}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[10]; assert(checkSignature(function, '4b1d7cf5')); final params = [ - opsPerAggregator, - beneficiary, + args.opsPerAggregator, + args.beneficiary, ]; return write( credentials, @@ -239,16 +242,15 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future handleOps( - List ops, - _i1.EthereumAddress beneficiary, { + ({List ops, _i1.EthereumAddress beneficiary}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[11]; assert(checkSignature(function, '1fad948c')); final params = [ - ops, - beneficiary, + args.ops, + args.beneficiary, ]; return write( credentials, @@ -262,13 +264,13 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future incrementNonce( - BigInt key, { + ({BigInt key}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[12]; assert(checkSignature(function, '0bd28e3b')); - final params = [key]; + final params = [args.key]; return write( credentials, transaction, @@ -281,18 +283,16 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future innerHandleOp( - _i2.Uint8List callData, - dynamic opInfo, - _i2.Uint8List context, { + ({_i2.Uint8List callData, dynamic opInfo, _i2.Uint8List context}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[13]; assert(checkSignature(function, '1d732756')); final params = [ - callData, - opInfo, - context, + args.callData, + args.opInfo, + args.context, ]; return write( credentials, @@ -306,15 +306,14 @@ class Entrypoint extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future nonceSequenceNumber( - _i1.EthereumAddress $param20, - BigInt $param21, { + ({_i1.EthereumAddress $param20, BigInt $param21}) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[14]; assert(checkSignature(function, '1b2e01b8')); final params = [ - $param20, - $param21, + args.$param20, + args.$param21, ]; final response = await read( function, @@ -328,18 +327,20 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future simulateHandleOp( - dynamic op, - _i1.EthereumAddress target, - _i2.Uint8List targetCallData, { + ({ + dynamic op, + _i1.EthereumAddress target, + _i2.Uint8List targetCallData + }) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[15]; assert(checkSignature(function, 'd6383f94')); final params = [ - op, - target, - targetCallData, + args.op, + args.target, + args.targetCallData, ]; return write( credentials, @@ -353,13 +354,13 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future simulateValidation( - dynamic userOp, { + ({dynamic userOp}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[16]; assert(checkSignature(function, 'ee219423')); - final params = [userOp]; + final params = [args.userOp]; return write( credentials, transaction, @@ -390,13 +391,13 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future withdrawStake( - _i1.EthereumAddress withdrawAddress, { + ({_i1.EthereumAddress withdrawAddress}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[18]; assert(checkSignature(function, 'c23a5cea')); - final params = [withdrawAddress]; + final params = [args.withdrawAddress]; return write( credentials, transaction, @@ -409,16 +410,15 @@ class Entrypoint extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future withdrawTo( - _i1.EthereumAddress withdrawAddress, - BigInt withdrawAmount, { + ({_i1.EthereumAddress withdrawAddress, BigInt withdrawAmount}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[19]; assert(checkSignature(function, '205c2878')); final params = [ - withdrawAddress, - withdrawAmount, + args.withdrawAddress, + args.withdrawAmount, ]; return write( credentials, diff --git a/lib/src/abis/lightAccountFactory.abi.json b/lib/src/abis/lightAccountFactory.abi.json new file mode 100644 index 0000000..aa2c2da --- /dev/null +++ b/lib/src/abis/lightAccountFactory.abi.json @@ -0,0 +1,217 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { + "internalType": "contract IEntryPoint", + "name": "entryPoint", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { "internalType": "address", "name": "target", "type": "address" } + ], + "name": "AddressEmptyCode", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "AddressInsufficientBalance", + "type": "error" + }, + { "inputs": [], "name": "FailedInnerCall", "type": "error" }, + { "inputs": [], "name": "InvalidAction", "type": "error" }, + { + "inputs": [ + { "internalType": "address", "name": "entryPoint", "type": "address" } + ], + "name": "InvalidEntryPoint", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "OwnableInvalidOwner", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "OwnableUnauthorizedAccount", + "type": "error" + }, + { + "inputs": [ + { "internalType": "address", "name": "token", "type": "address" } + ], + "name": "SafeERC20FailedOperation", + "type": "error" + }, + { "inputs": [], "name": "TransferFailed", "type": "error" }, + { "inputs": [], "name": "ZeroAddressNotAllowed", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferStarted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [], + "name": "ACCOUNT_IMPLEMENTATION", + "outputs": [ + { "internalType": "contract LightAccount", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ENTRY_POINT", + "outputs": [ + { "internalType": "contract IEntryPoint", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "unstakeDelay", "type": "uint32" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "addStake", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "uint256", "name": "salt", "type": "uint256" } + ], + "name": "createAccount", + "outputs": [ + { + "internalType": "contract LightAccount", + "name": "account", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "uint256", "name": "salt", "type": "uint256" } + ], + "name": "getAddress", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingOwner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "unlockStake", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address payable", "name": "to", "type": "address" }, + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address payable", "name": "to", "type": "address" } + ], + "name": "withdrawStake", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { "stateMutability": "payable", "type": "receive" } +] diff --git a/lib/src/abis/lightAccountFactory.g.dart b/lib/src/abis/lightAccountFactory.g.dart new file mode 100644 index 0000000..0283b9e --- /dev/null +++ b/lib/src/abis/lightAccountFactory.g.dart @@ -0,0 +1,340 @@ +// @dart=3.0 +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_local_variable, unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:web3dart/web3dart.dart' as _i1; + +final _contractAbi = _i1.ContractAbi.fromJson( + '[{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"contract IEntryPoint","name":"entryPoint","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InvalidAction","type":"error"},{"inputs":[{"internalType":"address","name":"entryPoint","type":"address"}],"name":"InvalidEntryPoint","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"ZeroAddressNotAllowed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"ACCOUNT_IMPLEMENTATION","outputs":[{"internalType":"contract LightAccount","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ENTRY_POINT","outputs":[{"internalType":"contract IEntryPoint","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"unstakeDelay","type":"uint32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"addStake","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"salt","type":"uint256"}],"name":"createAccount","outputs":[{"internalType":"contract LightAccount","name":"account","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"salt","type":"uint256"}],"name":"getAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unlockStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"to","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"to","type":"address"}],"name":"withdrawStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]', + 'LightAccountFactory', +); + +class LightAccountFactory extends _i1.GeneratedContract { + LightAccountFactory({ + required _i1.EthereumAddress address, + required _i1.Web3Client client, + int? chainId, + }) : super( + _i1.DeployedContract( + _contractAbi, + address, + ), + client, + chainId, + ); + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> ACCOUNT_IMPLEMENTATION( + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[1]; + assert(checkSignature(function, '290ab984')); + final params = []; + final response = await read( + function, + params, + atBlock, + ); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> ENTRY_POINT({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[2]; + assert(checkSignature(function, '94430fa5')); + final params = []; + final response = await read( + function, + params, + atBlock, + ); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future acceptOwnership({ + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[3]; + assert(checkSignature(function, '79ba5097')); + final params = []; + return write( + credentials, + transaction, + function, + params, + ); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future addStake( + ({BigInt unstakeDelay, BigInt amount}) args, { + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[4]; + assert(checkSignature(function, 'fbb1c3d4')); + final params = [ + args.unstakeDelay, + args.amount, + ]; + return write( + credentials, + transaction, + function, + params, + ); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future createAccount( + ({_i1.EthereumAddress owner, BigInt salt}) args, { + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[5]; + assert(checkSignature(function, '5fbfb9cf')); + final params = [ + args.owner, + args.salt, + ]; + return write( + credentials, + transaction, + function, + params, + ); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> getAddress( + ({_i1.EthereumAddress owner, BigInt salt}) args, { + _i1.BlockNum? atBlock, + }) async { + final function = self.abi.functions[6]; + assert(checkSignature(function, '8cb84e18')); + final params = [ + args.owner, + args.salt, + ]; + final response = await read( + function, + params, + atBlock, + ); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> owner({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[7]; + assert(checkSignature(function, '8da5cb5b')); + final params = []; + final response = await read( + function, + params, + atBlock, + ); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> pendingOwner({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[8]; + assert(checkSignature(function, 'e30c3978')); + final params = []; + final response = await read( + function, + params, + atBlock, + ); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future renounceOwnership({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[9]; + assert(checkSignature(function, '715018a6')); + final params = []; + final response = await read( + function, + params, + atBlock, + ); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future transferOwnership( + ({_i1.EthereumAddress newOwner}) args, { + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[10]; + assert(checkSignature(function, 'f2fde38b')); + final params = [args.newOwner]; + return write( + credentials, + transaction, + function, + params, + ); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future unlockStake({ + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[11]; + assert(checkSignature(function, 'bb9fe6bf')); + final params = []; + return write( + credentials, + transaction, + function, + params, + ); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future withdraw( + ({_i1.EthereumAddress to, _i1.EthereumAddress token, BigInt amount}) args, { + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[12]; + assert(checkSignature(function, 'd9caed12')); + final params = [ + args.to, + args.token, + args.amount, + ]; + return write( + credentials, + transaction, + function, + params, + ); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future withdrawStake( + ({_i1.EthereumAddress to}) args, { + required _i1.Credentials credentials, + _i1.Transaction? transaction, + }) async { + final function = self.abi.functions[13]; + assert(checkSignature(function, 'c23a5cea')); + final params = [args.to]; + return write( + credentials, + transaction, + function, + params, + ); + } + + /// Returns a live stream of all OwnershipTransferStarted events emitted by this contract. + Stream ownershipTransferStartedEvents({ + _i1.BlockNum? fromBlock, + _i1.BlockNum? toBlock, + }) { + final event = self.event('OwnershipTransferStarted'); + final filter = _i1.FilterOptions.events( + contract: self, + event: event, + fromBlock: fromBlock, + toBlock: toBlock, + ); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults( + result.topics!, + result.data!, + ); + return OwnershipTransferStarted( + decoded, + result, + ); + }); + } + + /// Returns a live stream of all OwnershipTransferred events emitted by this contract. + Stream ownershipTransferredEvents({ + _i1.BlockNum? fromBlock, + _i1.BlockNum? toBlock, + }) { + final event = self.event('OwnershipTransferred'); + final filter = _i1.FilterOptions.events( + contract: self, + event: event, + fromBlock: fromBlock, + toBlock: toBlock, + ); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults( + result.topics!, + result.data!, + ); + return OwnershipTransferred( + decoded, + result, + ); + }); + } +} + +class OwnershipTransferStarted { + OwnershipTransferStarted( + List response, + this.event, + ) : previousOwner = (response[0] as _i1.EthereumAddress), + newOwner = (response[1] as _i1.EthereumAddress); + + final _i1.EthereumAddress previousOwner; + + final _i1.EthereumAddress newOwner; + + final _i1.FilterEvent event; +} + +class OwnershipTransferred { + OwnershipTransferred( + List response, + this.event, + ) : previousOwner = (response[0] as _i1.EthereumAddress), + newOwner = (response[1] as _i1.EthereumAddress); + + final _i1.EthereumAddress previousOwner; + + final _i1.EthereumAddress newOwner; + + final _i1.FilterEvent event; +} diff --git a/lib/src/abis/p256AccountFactory.g.dart b/lib/src/abis/p256AccountFactory.g.dart index fa5031c..1befcb7 100644 --- a/lib/src/abis/p256AccountFactory.g.dart +++ b/lib/src/abis/p256AccountFactory.g.dart @@ -1,5 +1,8 @@ -// Generated code, do not modify. Run `build_runner build` to re-generate! -// @dart=2.12 +// @dart=3.0 +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_local_variable, unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:web3dart/web3dart.dart' as _i1; import 'dart:typed_data' as _i2; @@ -27,16 +30,15 @@ class P256AccountFactory extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future createP256Account( - BigInt salt, - _i2.Uint8List creation, { + ({BigInt salt, _i2.Uint8List creation}) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[1]; assert(checkSignature(function, '8bb4387f')); final params = [ - salt, - creation, + args.salt, + args.creation, ]; return write( credentials, @@ -50,15 +52,14 @@ class P256AccountFactory extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i1.EthereumAddress> getP256AccountAddress( - BigInt salt, - _i2.Uint8List creation, { + ({BigInt salt, _i2.Uint8List creation}) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[2]; assert(checkSignature(function, '28ef50f0')); final params = [ - salt, - creation, + args.salt, + args.creation, ]; final response = await read( function, diff --git a/lib/src/abis/safe4337Module.g.dart b/lib/src/abis/safe4337Module.g.dart index affc039..1a4e087 100644 --- a/lib/src/abis/safe4337Module.g.dart +++ b/lib/src/abis/safe4337Module.g.dart @@ -1,5 +1,8 @@ -// Generated code, do not modify. Run `build_runner build` to re-generate! -// @dart=2.12 +// @dart=3.0 +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_local_variable, unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:web3dart/web3dart.dart' as _i1; import 'dart:typed_data' as _i2; @@ -58,20 +61,22 @@ class Safe4337Module extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future executeUserOp( - _i1.EthereumAddress to, - BigInt value, - _i2.Uint8List data, - BigInt operation, { + ({ + _i1.EthereumAddress to, + BigInt value, + _i2.Uint8List data, + BigInt operation + }) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[3]; assert(checkSignature(function, '7bb37428')); final params = [ - to, - value, - data, - operation, + args.to, + args.value, + args.data, + args.operation, ]; return write( credentials, @@ -85,20 +90,22 @@ class Safe4337Module extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future executeUserOpWithErrorString( - _i1.EthereumAddress to, - BigInt value, - _i2.Uint8List data, - BigInt operation, { + ({ + _i1.EthereumAddress to, + BigInt value, + _i2.Uint8List data, + BigInt operation + }) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[4]; assert(checkSignature(function, '541d63c8')); final params = [ - to, - value, - data, - operation, + args.to, + args.value, + args.data, + args.operation, ]; return write( credentials, @@ -112,12 +119,12 @@ class Safe4337Module extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i2.Uint8List> getOperationHash( - dynamic userOp, { + ({dynamic userOp}) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[5]; assert(checkSignature(function, 'b25f3776')); - final params = [userOp]; + final params = [args.userOp]; final response = await read( function, params, @@ -130,12 +137,12 @@ class Safe4337Module extends _i1.GeneratedContract { /// set, the function will be evaluated in the specified block. By default, the /// latest on-chain block will be used. Future<_i2.Uint8List> getOperationHash$2( - dynamic userOp, { + ({dynamic userOp}) args, { _i1.BlockNum? atBlock, }) async { final function = self.abi.functions[6]; assert(checkSignature(function, 'bbe5dc4f')); - final params = [userOp]; + final params = [args.userOp]; final response = await read( function, params, diff --git a/lib/src/abis/safeProxyFactory.g.dart b/lib/src/abis/safeProxyFactory.g.dart index 7790cbd..fb435a5 100644 --- a/lib/src/abis/safeProxyFactory.g.dart +++ b/lib/src/abis/safeProxyFactory.g.dart @@ -1,5 +1,8 @@ -// Generated code, do not modify. Run `build_runner build` to re-generate! -// @dart=2.12 +// @dart=3.0 +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_local_variable, unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:web3dart/web3dart.dart' as _i1; import 'dart:typed_data' as _i2; @@ -27,18 +30,20 @@ class SafeProxyFactory extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future createChainSpecificProxyWithNonce( - _i1.EthereumAddress _singleton, - _i2.Uint8List initializer, - BigInt saltNonce, { + ({ + _i1.EthereumAddress singleton, + _i2.Uint8List initializer, + BigInt saltNonce + }) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[0]; assert(checkSignature(function, 'ec9e80bb')); final params = [ - _singleton, - initializer, - saltNonce, + args.singleton, + args.initializer, + args.saltNonce, ]; return write( credentials, @@ -52,20 +57,22 @@ class SafeProxyFactory extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future createProxyWithCallback( - _i1.EthereumAddress _singleton, - _i2.Uint8List initializer, - BigInt saltNonce, - _i1.EthereumAddress callback, { + ({ + _i1.EthereumAddress singleton, + _i2.Uint8List initializer, + BigInt saltNonce, + _i1.EthereumAddress callback + }) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[1]; assert(checkSignature(function, 'd18af54d')); final params = [ - _singleton, - initializer, - saltNonce, - callback, + args.singleton, + args.initializer, + args.saltNonce, + args.callback, ]; return write( credentials, @@ -79,18 +86,20 @@ class SafeProxyFactory extends _i1.GeneratedContract { /// like the gas price, nonce and max gas. The `data` and `to` fields will be /// set by the contract. Future createProxyWithNonce( - _i1.EthereumAddress _singleton, - _i2.Uint8List initializer, - BigInt saltNonce, { + ({ + _i1.EthereumAddress singleton, + _i2.Uint8List initializer, + BigInt saltNonce + }) args, { required _i1.Credentials credentials, _i1.Transaction? transaction, }) async { final function = self.abi.functions[2]; assert(checkSignature(function, '1688f0b9')); final params = [ - _singleton, - initializer, - saltNonce, + args.singleton, + args.initializer, + args.saltNonce, ]; return write( credentials, diff --git a/lib/src/abis/simpleAccountFactory.abi.json b/lib/src/abis/simpleAccountFactory.abi.json deleted file mode 100644 index 0e5bc9b..0000000 --- a/lib/src/abis/simpleAccountFactory.abi.json +++ /dev/null @@ -1,74 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "contract IEntryPoint", - "name": "_entryPoint", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [], - "name": "accountImplementation", - "outputs": [ - { - "internalType": "contract SimpleAccount", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - } - ], - "name": "createAccount", - "outputs": [ - { - "internalType": "contract SimpleAccount", - "name": "ret", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - } - ], - "name": "getAddress", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - } -] diff --git a/lib/src/abis/simpleAccountFactory.g.dart b/lib/src/abis/simpleAccountFactory.g.dart deleted file mode 100644 index b452414..0000000 --- a/lib/src/abis/simpleAccountFactory.g.dart +++ /dev/null @@ -1,85 +0,0 @@ -// Generated code, do not modify. Run `build_runner build` to re-generate! -// @dart=2.12 -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:web3dart/web3dart.dart' as _i1; - -final _contractAbi = _i1.ContractAbi.fromJson( - '[{"inputs":[{"internalType":"contract IEntryPoint","name":"_entryPoint","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"accountImplementation","outputs":[{"internalType":"contract SimpleAccount","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"salt","type":"uint256"}],"name":"createAccount","outputs":[{"internalType":"contract SimpleAccount","name":"ret","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"salt","type":"uint256"}],"name":"getAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]', - 'SimpleAccountFactory', -); - -class SimpleAccountFactory extends _i1.GeneratedContract { - SimpleAccountFactory({ - required _i1.EthereumAddress address, - required _i1.Web3Client client, - int? chainId, - }) : super( - _i1.DeployedContract( - _contractAbi, - address, - ), - client, - chainId, - ); - - /// The optional [atBlock] parameter can be used to view historical data. When - /// set, the function will be evaluated in the specified block. By default, the - /// latest on-chain block will be used. - Future<_i1.EthereumAddress> accountImplementation( - {_i1.BlockNum? atBlock}) async { - final function = self.abi.functions[1]; - assert(checkSignature(function, '11464fbe')); - final params = []; - final response = await read( - function, - params, - atBlock, - ); - return (response[0] as _i1.EthereumAddress); - } - - /// The optional [transaction] parameter can be used to override parameters - /// like the gas price, nonce and max gas. The `data` and `to` fields will be - /// set by the contract. - Future createAccount( - _i1.EthereumAddress owner, - BigInt salt, { - required _i1.Credentials credentials, - _i1.Transaction? transaction, - }) async { - final function = self.abi.functions[2]; - assert(checkSignature(function, '5fbfb9cf')); - final params = [ - owner, - salt, - ]; - return write( - credentials, - transaction, - function, - params, - ); - } - - /// The optional [atBlock] parameter can be used to view historical data. When - /// set, the function will be evaluated in the specified block. By default, the - /// latest on-chain block will be used. - Future<_i1.EthereumAddress> getAddress( - _i1.EthereumAddress owner, - BigInt salt, { - _i1.BlockNum? atBlock, - }) async { - final function = self.abi.functions[3]; - assert(checkSignature(function, '8cb84e18')); - final params = [ - owner, - salt, - ]; - final response = await read( - function, - params, - atBlock, - ); - return (response[0] as _i1.EthereumAddress); - } -} diff --git a/lib/src/common/constants.dart b/lib/src/common/constants.dart new file mode 100644 index 0000000..1b16477 --- /dev/null +++ b/lib/src/common/constants.dart @@ -0,0 +1,31 @@ +part of '../../variance_dart.dart'; + +class Constants { + static EthereumAddress entrypointv06 = + EthereumAddress.fromHex("0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"); + static EthereumAddress entrypointv07 = + EthereumAddress.fromHex("0x0000000071727De22E5E9d8BAf0edAc6f37da032"); + static EthereumAddress zeroAddress = + EthereumAddress.fromHex("0x0000000000000000000000000000000000000000"); + static final EthereumAddress lightAccountFactoryAddressv06 = + EthereumAddress.fromHex("0x00004EC70002a32400f8ae005A26081065620D20"); + static final EthereumAddress lightAccountFactoryAddressv07 = + EthereumAddress.fromHex("0x0000000000400CdFef5E2714E63d8040b700BC24"); + static final EthereumAddress safeProxyFactoryAddress = + EthereumAddress.fromHex("0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"); + static final EthereumAddress safe4337ModuleAddressv06 = + EthereumAddress.fromHex("0xa581c4A4DB7175302464fF3C06380BC3270b4037"); + static final EthereumAddress safe4337ModuleAddressv07 = + EthereumAddress.fromHex("0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226"); + static final EthereumAddress safeSingletonAddress = + EthereumAddress.fromHex("0x41675C099F32341bf84BFc5382aF534df5C7461a"); + static final EthereumAddress safeModuleSetupAddressv06 = + EthereumAddress.fromHex("0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb"); + static final EthereumAddress safeModuleSetupAddressv07 = + EthereumAddress.fromHex("0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47"); + static final EthereumAddress safeMultiSendaddress = + EthereumAddress.fromHex("0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526"); + static final defaultBytePrefix = Uint8List(1); + + Constants._(); +} diff --git a/lib/src/common/factories.dart b/lib/src/common/factories.dart index ced8352..84f70dc 100644 --- a/lib/src/common/factories.dart +++ b/lib/src/common/factories.dart @@ -34,6 +34,13 @@ class _SafeProxyFactory extends SafeProxyFactory required RPCBase rpc, }) : super(client: Web3Client.custom(rpc)); + /// Returns the proxy creation code without making a network request + @override + Future proxyCreationCode({BlockNum? atBlock}) async { + return hexToBytes( + "0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564"); + } + /// Generates the initializer data for deploying a new Safe contract. /// /// [owners] is an iterable of owner addresses for the Safe. @@ -98,17 +105,17 @@ class _SafeProxyFactory extends SafeProxyFactory } } -/// A class that extends [SimpleAccountFactory] and implements [SimpleAccountFactoryBase]. -/// It creates an instance of [SimpleAccountFactory] with a custom [RPCBase] client. -/// Used to create instances of [SmartWallet] for simple accounts. -class _SimpleAccountFactory extends SimpleAccountFactory - implements SimpleAccountFactoryBase { - /// Creates a new instance of [_SimpleAccountFactory]. +/// A class that extends [LightAccountFactory] and implements [LightAccountFactoryBase]. +/// It creates an instance of [LightAccountFactory] with a custom [RPCBase] client. +/// Used to create instances of [SmartWallet] for light accounts. +class _LightAccountFactory extends LightAccountFactory + implements LightAccountFactoryBase { + /// Creates a new instance of [_LightAccountFactory]. /// - /// [address] is the address of the simple account factory. + /// [address] is the address of the light account factory. /// [chainId] is the ID of the blockchain chain. /// [rpc] is the [RPCBase] client used for communication with the blockchain. - _SimpleAccountFactory({ + _LightAccountFactory({ required super.address, super.chainId, required RPCBase rpc, diff --git a/lib/src/interfaces/account_factories.dart b/lib/src/interfaces/account_factories.dart index 837cb40..91343d0 100644 --- a/lib/src/interfaces/account_factories.dart +++ b/lib/src/interfaces/account_factories.dart @@ -4,11 +4,10 @@ part of 'interfaces.dart'; /// /// This class defines the common interface for interacting with an Ethereum smart contract /// responsible for creating and managing accounts. -abstract class SimpleAccountFactoryBase { +abstract class LightAccountFactoryBase { /// Retrieves the Ethereum address associated with a standard account. Future getAddress( - EthereumAddress owner, - BigInt salt, { + ({EthereumAddress owner, BigInt salt}) args, { BlockNum? atBlock, }); } @@ -16,8 +15,7 @@ abstract class SimpleAccountFactoryBase { abstract class P256AccountFactoryBase { /// Retrieves the Ethereum address associated with a standard p256 account. Future getP256AccountAddress( - BigInt salt, - Uint8List creation, { + ({BigInt salt, Uint8List creation}) args, { BlockNum? atBlock, }); } @@ -26,9 +24,11 @@ abstract class SafeProxyFactoryBase { Future proxyCreationCode({BlockNum? atBlock}); Future createProxyWithNonce( - EthereumAddress singleton, - Uint8List initializer, - BigInt saltNonce, { + ({ + EthereumAddress singleton, + Uint8List initializer, + BigInt saltNonce + }) args, { required Credentials credentials, Transaction? transaction, }); diff --git a/lib/src/interfaces/safe_module.dart b/lib/src/interfaces/safe_module.dart index 49ee651..d4f217e 100644 --- a/lib/src/interfaces/safe_module.dart +++ b/lib/src/interfaces/safe_module.dart @@ -5,25 +5,29 @@ abstract class Safe4337ModuleBase { Future SUPPORTED_ENTRYPOINT({BlockNum? atBlock}); Future executeUserOpWithErrorString( - EthereumAddress to, - BigInt value, - Uint8List data, - BigInt operation, { + ({ + EthereumAddress to, + BigInt value, + Uint8List data, + BigInt operation + }) args, { required Credentials credentials, Transaction? transaction, }); Future executeUserOp( - EthereumAddress to, - BigInt value, - Uint8List data, - BigInt operation, { + ({ + EthereumAddress to, + BigInt value, + Uint8List data, + BigInt operation + }) args, { required Credentials credentials, Transaction? transaction, }); Future getOperationHash( - dynamic userOp, { + ({dynamic userOp}) args, { BlockNum? atBlock, }); } diff --git a/lib/src/interfaces/smart_wallet_factory.dart b/lib/src/interfaces/smart_wallet_factory.dart index 5004038..49ea6d3 100644 --- a/lib/src/interfaces/smart_wallet_factory.dart +++ b/lib/src/interfaces/smart_wallet_factory.dart @@ -25,14 +25,14 @@ abstract class SmartWalletFactoryBase { Future createSafeAccount(Uint256 salt); - /// Creates a new simple account with the provided salt and optional index. + /// Creates a new light account with the provided salt and optional index. /// /// [salt] is the salt value used in the account creation process. /// [index] is an optional index value for the signer address. /// /// Returns a [Future] that resolves to a [SmartWallet] instance representing - /// the created simple account. - Future createSimpleAccount(Uint256 salt, [int? index]); + /// the created light account. + Future createAlchemyLightAccount(Uint256 salt, [int? index]); /// Creates a new vendor account with the provided address and initialization code. /// diff --git a/lib/variance_dart.dart b/lib/variance_dart.dart index ceae157..ea2bb58 100644 --- a/lib/variance_dart.dart +++ b/lib/variance_dart.dart @@ -23,6 +23,7 @@ part 'src/4337/providers.dart'; part 'src/4337/safe.dart'; part 'src/4337/userop.dart'; part 'src/4337/wallet.dart'; +part 'src/common//constants.dart'; part 'src/common/contract.dart'; part 'src/common/factories.dart'; part 'src/common/mixins.dart'; diff --git a/pubspec.lock b/pubspec.lock index 9f17a7d..d0a0948 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -29,10 +29,10 @@ packages: dependency: transitive description: name: asn1lib - sha256: "58082b3f0dca697204dbab0ef9ff208bfaea7767ea771076af9a343488428dda" + sha256: "6b151826fcc95ff246cd219a0bf4c753ea14f4081ad71c61939becf3aba27f70" url: "https://pub.dev" source: hosted - version: "1.5.3" + version: "1.5.5" async: dependency: transitive description: @@ -45,10 +45,10 @@ packages: dependency: transitive description: name: blockchain_utils - sha256: "699d72427447814bd574b95b0d3baf9b2c0ec9c9b82deef3c6264c6f5efa4406" + sha256: ebb6c336ba0120de0982c50d8bc597cb494a530bd22bd462895bb5cebde405af url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.4.0" boolean_selector: dependency: transitive description: @@ -101,10 +101,10 @@ packages: dependency: transitive description: name: build_runner_core - sha256: "4ae8ffe5ac758da294ecf1802f2aff01558d8b1b00616aa7538ea9a8a5d50799" + sha256: e3c79f69a64bdfcd8a776a3c28db4eb6e3fb5356d013ae5eb2e52007706d5dbe url: "https://pub.dev" source: hosted - version: "7.3.0" + version: "7.3.1" built_collection: dependency: transitive description: @@ -137,14 +137,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" - clock: - dependency: transitive - description: - name: clock - sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf - url: "https://pub.dev" - source: hosted - version: "1.1.1" code_builder: dependency: transitive description: @@ -169,22 +161,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.1" - corbado_frontend_api_client: - dependency: transitive - description: - name: corbado_frontend_api_client - sha256: a6d65fc0da88f2e6a6e95251de0b67735556128c5d96c9b609e7b18010a6f6c1 - url: "https://pub.dev" - source: hosted - version: "1.1.0" crypto: dependency: transitive description: name: crypto - sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27 url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" dart_style: dependency: transitive description: @@ -263,18 +247,18 @@ packages: dependency: transitive description: name: graphs - sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.2" http: dependency: "direct main" description: name: http - sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" + sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.2.2" http_multi_server: dependency: transitive description: @@ -291,14 +275,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" - intl: - dependency: transitive - description: - name: intl - sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" - url: "https://pub.dev" - source: hosted - version: "0.18.1" io: dependency: transitive description: @@ -311,10 +287,10 @@ packages: dependency: transitive description: name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "0.7.1" json_annotation: dependency: transitive description: @@ -375,10 +351,10 @@ packages: dependency: transitive description: name: mime - sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" + sha256: "801fd0b26f14a4a58ccb09d5892c3fbdeff209594300a542492cf13fba9d247a" url: "https://pub.dev" source: hosted - version: "1.0.5" + version: "1.0.6" mockito: dependency: "direct dev" description: @@ -387,14 +363,6 @@ packages: url: "https://pub.dev" source: hosted version: "5.4.4" - openapi_generator_annotations: - dependency: transitive - description: - name: openapi_generator_annotations - sha256: "46f1fb675029d78e19ce9143e70ce414d738b0f6c45c49c004b4b3afdb405a5c" - url: "https://pub.dev" - source: hosted - version: "4.13.1" package_config: dependency: transitive description: @@ -407,42 +375,42 @@ packages: dependency: transitive description: name: passkeys - sha256: "59e50b21746aff90cbc56145174caa3b99523f449e42f7d8aa2199ec09c511cd" + sha256: c14264d11c6cf631296b21760c0411b26a5e223511cab9387d4b8c551189c34c url: "https://pub.dev" source: hosted - version: "2.0.8" + version: "2.1.0" passkeys_android: dependency: transitive description: name: passkeys_android - sha256: "9dc0b84dad03329ff2f3be18bedecf1b8de9309c8e9cda6ef821dc88556a126d" + sha256: e7f6aa1131b0c0e954bb50d0b59e9bbf6fb8eb0a6a1c282d6af982df5d746b51 url: "https://pub.dev" source: hosted - version: "2.0.4" + version: "2.1.0" passkeys_ios: dependency: transitive description: name: passkeys_ios - sha256: "411b10c3cd159c9601426d47b2dc5aa4dd1e34ef69deefaac01ff81712ea6064" + sha256: "1e23e40efd12867725443923a72914c11f926dce8623757b45ed2d7a16e95731" url: "https://pub.dev" source: hosted - version: "2.0.3" + version: "2.1.0" passkeys_platform_interface: dependency: transitive description: name: passkeys_platform_interface - sha256: a1f1f5c637049f68350cf43323df9689be2e86fe5822a6e098362e7f6168351e + sha256: e32fbac05561a1c3ab439a504e7c19daf96b8339fd6bcbdac40e2ed9281add57 url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.1.0" passkeys_web: dependency: transitive description: name: passkeys_web - sha256: "1c7815020332b9be1af4df67686826a91b6dd29fea53be947d6082654abd6280" + sha256: e09df6485e851581848ce3481c56bb2be571a12137c13325373bdfa519a9387a url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.1.0" path: dependency: transitive description: @@ -548,10 +516,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: transitive description: @@ -572,10 +540,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: @@ -612,18 +580,18 @@ packages: dependency: transitive description: name: ua_client_hints - sha256: "8401d7bec261f61b3d3b61cd877653ddf840de2d9e07bd164f34588572aa0c8b" + sha256: dfea54a1b4d259c057d0f33f198094cf4e09e1a21d347baadbe6dbd3d820c0d4 url: "https://pub.dev" source: hosted - version: "1.2.2" + version: "1.4.0" uuid: dependency: transitive description: name: uuid - sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8" + sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff url: "https://pub.dev" source: hosted - version: "4.4.0" + version: "4.5.1" vector_math: dependency: transitive description: @@ -652,18 +620,18 @@ packages: dependency: transitive description: name: web - sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "1.1.0" web3_signers: dependency: "direct main" description: name: web3_signers - sha256: de57dbdde9bbaa3c503adb169b082f6342f502b7492420a7365d5fa979283ab0 + sha256: "455acf0207ef6edc5937a73edd57ce94f028b41856c07193be23e282d542d625" url: "https://pub.dev" source: hosted - version: "0.0.12" + version: "0.0.14-alpha-01" web3dart: dependency: "direct main" description: @@ -684,18 +652,18 @@ packages: dependency: transitive description: name: web_socket - sha256: "24301d8c293ce6fe327ffe6f59d8fd8834735f0ec36e4fd383ec7ff8a64aa078" + sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83" url: "https://pub.dev" source: hosted - version: "0.1.5" + version: "0.1.6" web_socket_channel: dependency: transitive description: name: web_socket_channel - sha256: a2d56211ee4d35d9b344d9d4ce60f362e4f5d1aafb988302906bd732bc731276 + sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f" url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.0.1" yaml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5d76728..443daaf 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.2 +version: 0.1.3 documentation: https://docs.variance.space homepage: https://variance.space repository: https://github.com/vaariance/variance-dart @@ -20,7 +20,7 @@ dependencies: sdk: flutter web3dart: ^2.7.3 http: ^1.2.0 - web3_signers: ^0.0.12 + web3_signers: ^0.0.14-alpha-01 dev_dependencies: web3dart_builders: ^0.1.2