Skip to content

Commit

Permalink
Add test token transfer to runOp script
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Oct 18, 2023
1 parent 06c2936 commit 9f8aa30
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 5 deletions.
2 changes: 2 additions & 0 deletions 4337/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
11 changes: 11 additions & 0 deletions 4337/contracts/test/TestToken.sol
Original file line number Diff line number Diff line change
@@ -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());
}
}
4 changes: 2 additions & 2 deletions 4337/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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: {
Expand Down
13 changes: 13 additions & 0 deletions 4337/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions 4337/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 9 additions & 2 deletions 4337/scripts/runOp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down Expand Up @@ -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
})

Expand Down
9 changes: 8 additions & 1 deletion 4337/src/deploy/deploy_eip4337.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 9f8aa30

Please sign in to comment.