From 9f8aa30143f086d00048a950a2a58f0a30b24cd3 Mon Sep 17 00:00:00 2001 From: Mikhail <16622558+mmv08@users.noreply.github.com> Date: Wed, 18 Oct 2023 12:32:41 +0200 Subject: [PATCH] Add test token transfer to runOp script --- 4337/.env.sample | 2 ++ 4337/contracts/test/TestToken.sol | 11 +++++++++++ 4337/hardhat.config.ts | 4 ++-- 4337/package-lock.json | 13 +++++++++++++ 4337/package.json | 1 + 4337/scripts/runOp.ts | 11 +++++++++-- 4337/src/deploy/deploy_eip4337.ts | 9 ++++++++- 7 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 4337/contracts/test/TestToken.sol diff --git a/4337/.env.sample b/4337/.env.sample index c8f664524..ff3d29732 100644 --- a/4337/.env.sample +++ b/4337/.env.sample @@ -19,6 +19,8 @@ SCRIPT_ADD_MODULES_LIB_ADDRESS="" SCRIPT_PROXY_FACTORY_ADDRESS= # Singleton address to use in the user op test script SCRIPT_SAFE_SINGLETON_ADDRESS= +# ERC20 Token to use in the user op test script for testing contract calls +SCRIPT_ERC20_TOKEN_ADDRESS= # Entrypoint address to use for the module deployment DEPLOY_ENTRY_POINT="" \ No newline at end of file diff --git a/4337/contracts/test/TestToken.sol b/4337/contracts/test/TestToken.sol new file mode 100644 index 000000000..908525f15 --- /dev/null +++ b/4337/contracts/test/TestToken.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: LGPL-3.0-only +pragma solidity >=0.8.0; + +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; + +contract HariWillibaldToken is ERC20, ERC20Permit { + constructor(address initialMintDest) ERC20("Hari Willibald Token", "HWT") ERC20Permit("Hari Willibald Token") { + _mint(initialMintDest, 1000000 * 10**decimals()); + } +} diff --git a/4337/hardhat.config.ts b/4337/hardhat.config.ts index 06bc3ad83..5c07dc229 100644 --- a/4337/hardhat.config.ts +++ b/4337/hardhat.config.ts @@ -36,7 +36,7 @@ import './src/tasks/local_verify' import './src/tasks/deploy_contracts' import './src/tasks/show_codesize' -const primarySolidityVersion = SOLIDITY_VERSION || '0.8.14' +const primarySolidityVersion = SOLIDITY_VERSION || '0.8.20' const soliditySettings = !!SOLIDITY_SETTINGS ? JSON.parse(SOLIDITY_SETTINGS) : { optimizer: { enabled: true, runs: 200 } } const userConfig: HardhatUserConfig = { @@ -47,7 +47,7 @@ const userConfig: HardhatUserConfig = { sources: 'contracts', }, solidity: { - compilers: [{ version: primarySolidityVersion, settings: soliditySettings }, { version: '0.6.12' }, { version: '0.5.17' }], + compilers: [{ version: primarySolidityVersion, settings: { evmVersion: 'london', ...soliditySettings }}, { version: '0.6.12' }, { version: '0.5.17' }], }, networks: { hardhat: { diff --git a/4337/package-lock.json b/4337/package-lock.json index 3a02aad2d..a8f91687f 100644 --- a/4337/package-lock.json +++ b/4337/package-lock.json @@ -15,6 +15,7 @@ "@nomiclabs/hardhat-ethers": "^2.0.6", "@nomiclabs/hardhat-etherscan": "^3.1.0", "@nomiclabs/hardhat-waffle": "^2.0.3", + "@openzeppelin/contracts": "^5.0.0", "@types/chai": "^4.3.1", "@types/mocha": "^9.1.1", "@types/node": "^17.0.42", @@ -1424,6 +1425,12 @@ "hardhat": "^2.0.0" } }, + "node_modules/@openzeppelin/contracts": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-5.0.0.tgz", + "integrity": "sha512-bv2sdS6LKqVVMLI5+zqnNrNU/CA+6z6CmwFXm/MzmOPBRSO5reEJN7z0Gbzvs0/bv/MZZXNklubpwy3v2+azsw==", + "dev": true + }, "node_modules/@resolver-engine/core": { "version": "0.3.3", "dev": true, @@ -18399,6 +18406,12 @@ "@types/web3": "1.0.19" } }, + "@openzeppelin/contracts": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-5.0.0.tgz", + "integrity": "sha512-bv2sdS6LKqVVMLI5+zqnNrNU/CA+6z6CmwFXm/MzmOPBRSO5reEJN7z0Gbzvs0/bv/MZZXNklubpwy3v2+azsw==", + "dev": true + }, "@resolver-engine/core": { "version": "0.3.3", "dev": true, diff --git a/4337/package.json b/4337/package.json index 1f1b5ca72..65f724fc2 100644 --- a/4337/package.json +++ b/4337/package.json @@ -46,6 +46,7 @@ "@nomiclabs/hardhat-ethers": "^2.0.6", "@nomiclabs/hardhat-etherscan": "^3.1.0", "@nomiclabs/hardhat-waffle": "^2.0.3", + "@openzeppelin/contracts": "^5.0.0", "@types/chai": "^4.3.1", "@types/mocha": "^9.1.1", "@types/node": "^17.0.42", diff --git a/4337/scripts/runOp.ts b/4337/scripts/runOp.ts index deb0163b0..f896fada3 100644 --- a/4337/scripts/runOp.ts +++ b/4337/scripts/runOp.ts @@ -17,6 +17,7 @@ const SAFE_SINGLETON_ADDRESS = process.env.SCRIPT_SAFE_SINGLETON_ADDRESS!! const PROXY_FACTORY_ADDRESS = process.env.SCRIPT_PROXY_FACTORY_ADDRESS!! const ADD_MODULES_LIB_ADDRESS = process.env.SCRIPT_ADD_MODULES_LIB_ADDRESS!! const MODULE_ADDRESS = process.env.SCRIPT_MODULE_ADDRESS!! +const ERC20_TOKEN_ADDRESS = process.env.SCRIPT_ERC20_TOKEN_ADDRESS!! const INTERFACES = new ethers.utils.Interface([ 'function enableModule(address)', @@ -79,10 +80,16 @@ const runOp = async () => { await(await user1.sendTransaction({to: safe.address, value: ethers.utils.parseEther("0.01")})).wait() } + let toAddress = '0x02270bd144e70cE6963bA02F575776A16184E1E6' + let callData = "0x" + if (ERC20_TOKEN_ADDRESS) { + toAddress = ERC20_TOKEN_ADDRESS + callData = buildData("transfer(address,uint256)", [user1.address, parseEther('1')]) + } const operation = await safe.operate({ - to: '0x02270bd144e70cE6963bA02F575776A16184E1E6', + to: toAddress, value: parseEther('0.0001'), - data: '0x', + data: callData, operation: 0 }) diff --git a/4337/src/deploy/deploy_eip4337.ts b/4337/src/deploy/deploy_eip4337.ts index dbd412534..a7537f47d 100644 --- a/4337/src/deploy/deploy_eip4337.ts +++ b/4337/src/deploy/deploy_eip4337.ts @@ -8,7 +8,7 @@ const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const { deployer } = await getNamedAccounts() const { deploy } = deployments - let entryPointAddress; + let entryPointAddress if (hre.network.name === 'hardhat' || !ENTRY_POINT) { const entryPoint = await deploy('TestEntryPoint', { from: deployer, @@ -36,6 +36,13 @@ const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { entryPointAddress = ENTRY_POINT } + await deploy('HariWillibaldToken', { + from: deployer, + args: [deployer], + log: true, + deterministicDeployment: true, + }) + await deploy('Simple4337Module', { from: deployer, args: [entryPointAddress],