Skip to content

Commit

Permalink
this is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Jun 15, 2022
1 parent 76383a6 commit e813eaf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
2 changes: 0 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ ETHERSCAN_API_KEY=""
GOERLI_SCRIPT_MNEMONIC=""
# Safe to use in the user op test script on goerli
GOERLI_SCRIPT_SAFE_ADDRESS=
# Storage setter to use in the user op test script on goerli
GOERLI_SCRIPT_STORAGE_SETTER_ADDRESS=
# Enable debug in the test script
GOERLI_SCRIPT_DEBUG=true
43 changes: 10 additions & 33 deletions scripts/runOpGoerli.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import { BigNumber } from 'ethers'
import { AddressZero } from '@ethersproject/constants'
import hre, { deployments } from 'hardhat'
import hre from 'hardhat'
import '@nomiclabs/hardhat-ethers'
import {
deployContract,
getTestSafe,
getEip4337Diatomic,
getSafeAtAddress,
getStorageSetterAtAddress,
getTestStorageSetter,
} from '../test/utils/setup'
import { getTestSafe, getEip4337Diatomic, getSafeAtAddress, getStorageSetterAtAddress, getTestStorageSetter } from '../test/utils/setup'
import { buildSignatureBytes, signHash } from '../src/utils/execution'
import {
buildSafeUserOp,
buildSafeUserOpContractCall,
getRequiredPrefund,
calculateSafeOperationHash,
buildUserOperationFromSafeUserOperation,
calculateIntermediateTxHash,
buildSafeUserOpTransaction,
getSupportedEntryPoints,
} from '../src/utils/userOp'
import { parseEther } from '@ethersproject/units'
import { chainId } from '../test/utils/encoding'

const MNEMONIC = process.env.GOERLI_SCRIPT_MNEMONIC
const SAFE_ADDRESS = process.env.GOERLI_SCRIPT_SAFE_ADDRESS
const STORAGE_SETTER_ADDRESS = process.env.GOERLI_SCRIPT_STORAGE_SETTER_ADDRESS
const DEBUG = process.env.GOERLI_SCRIPT_DEBUG || false

const runOp = async () => {
Expand All @@ -38,19 +24,15 @@ const runOp = async () => {
const eip4337Diatomic = await getEip4337Diatomic()
const safe = await (SAFE_ADDRESS ? getSafeAtAddress(SAFE_ADDRESS) : getTestSafe(user1, eip4337Diatomic.address, eip4337Diatomic.address))
const eip4337Safe = eip4337Diatomic.attach(safe.address)
const storageSetter = await (STORAGE_SETTER_ADDRESS ? getStorageSetterAtAddress(STORAGE_SETTER_ADDRESS) : getTestStorageSetter(user1))
const entryPoints = await getSupportedEntryPoints(accountAbstractionProvider)
const safeOp = buildSafeUserOpContractCall(
storageSetter,
'setStorage',
[safe.address],
eip4337Safe.address,
'0',
'0',
entryPoints[0],
false,
{ maxFeePerGas: '10', maxPriorityFeePerGas: '5' },
)
const safeOp = buildSafeUserOp({
nonce: '0',
safe: safe.address,
entryPoint: entryPoints[0],
maxFeePerGas: '4000000000',
maxPriorityFeePerGas: '4000000000',
callGas: '500000',
})
const safeOpHash = calculateSafeOperationHash(eip4337Diatomic.address, safeOp, await chainId())
let signature = buildSignatureBytes([await signHash(user1, safeOpHash)])
signature = `${signature.slice(0, -2)}20`
Expand All @@ -65,7 +47,6 @@ const runOp = async () => {
console.log('Usign account with address:', user1.address)
console.log('Using EIP4337Diatomic deployed at:', eip4337Diatomic.address)
console.log('Using Safe contract deployed at:', safe.address)
console.log('Using StorageSetter deployed at:', storageSetter.address)
console.log('Using entrypoint at:', entryPoints[0])
console.log(
'Encoded validateUserOp call:',
Expand All @@ -74,10 +55,6 @@ const runOp = async () => {
}

await accountAbstractionProvider.send('eth_sendUserOperation', [userOp, entryPoints[0]])

console.log(
await hre.ethers.provider.getStorageAt(storageSetter.address, '0x7373737373737373737373737373737373737373737373737373737373737373'),
)
}

runOp()
7 changes: 6 additions & 1 deletion src/utils/userOp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const buildSafeUserOp = (template: OptionalExceptFor<SafeUserOperation, '
nonce: template.nonce,
entryPoint: template.entryPoint,
callData: template.callData || '0x',
verificationGas: template.verificationGas || '1000000',
verificationGas: template.verificationGas || '300000',
preVerificationGas: template.preVerificationGas || '21000',
callGas: template.callGas || '2000000',
maxFeePerGas: template.maxFeePerGas || '10000000000',
Expand Down Expand Up @@ -151,6 +151,11 @@ export const getRequiredGas = (userOp: UserOperation): string => {
}

export const getRequiredPrefund = (userOp: UserOperation): string => {
console.log({
requiredGas: getRequiredGas(userOp),
requiredPrefund: BigNumber.from(getRequiredGas(userOp)).mul(BigNumber.from(userOp.maxFeePerGas)).toString(),
})

return BigNumber.from(getRequiredGas(userOp)).mul(BigNumber.from(userOp.maxFeePerGas)).toString()
}

Expand Down

0 comments on commit e813eaf

Please sign in to comment.