eth-infinitism/bundler

HandleOps reverted with paymasterAndData

sreeshmashaji opened this issue · 1 comments

import {
SimpleAccountFactory__factory,
EntryPoint__factory,
DepositPaymaster__factory,
DepositPaymaster,
EntryPoint,
} from "@account-abstraction/contracts";
const { abi1 } = require("./abi1")
import { DeterministicDeployer, HttpRpcClient, SimpleAccountAPI } from "@account-abstraction/sdk";
import { BytesLike, ethers, } from "ethers";
import { abi, bytecode } from '../artifacts/contracts/TestToken.sol/TestToken.json'
import { abi as oracleabi, bytecode as oracleBytecode } from '../artifacts/contracts/TestOracle.sol/TestOracle.json'
import { DepositPaymasterAPI } from "./DepositPaymasterApi";
import { resolveProperties } from "@ethersproject/properties";

describe('paymaster', function () {
let provider = new ethers.providers.JsonRpcProvider("https://polygon-mumbai.g.alchemy.com/v2/HncKchA59IsmRnWlOMaNq3YYSCp5DIr0");
const private_key = "7a8daa8561f32e139966ac8d35359af89be277c8707aa630ce71f24bfa8c2fee"
const signer = new ethers.Wallet(private_key, provider)
let entryPointAddress = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
let api: SimpleAccountAPI;
let paymaster: DepositPaymaster;

let testToken: ethers.Contract;
let factoryAddress: string;
let ownerAA: string
let entryPoint: EntryPoint;
let api2:SimpleAccountAPI

let bundlerProvider: HttpRpcClient
const age_address = "0xa7C90b6C4ab446B4C193fc65771eFAf06f52105d";
const payAddress="0x3d62238e6EBEE2631b9E7593CaC3E5F55C6e6fb6"

it("paymaster deploy", async function () {
DeterministicDeployer.init(provider)
factoryAddress = await DeterministicDeployer.deploy(new SimpleAccountFactory__factory(), 0, [entryPointAddress])

   entryPoint = await new EntryPoint__factory(signer).attach(entryPointAddress);
  // paymaster = await new DepositPaymaster__factory(signer).deploy(entryPoint.address)
  
  paymaster = await new DepositPaymaster__factory(signer).attach(payAddress)
  console.log(paymaster.address);
  // await paymaster.deployed();
  // paymaster should stake at entry point
   await paymaster.addStake(1000000, { value: ethers.utils.parseEther('1'), gasLimit: 1e6 })
 await entryPoint.depositTo(paymaster.address, { value: ethers.utils.parseEther('1'), gasLimit: 1e6 })

})
it("deploy token and oracle", async function () {

  const tokenName = "USDT test";
  const tokenSymbol = "USDT";
  const price = 1; // 1 ETH = 1 USDT
  
  const TestToken = new ethers.ContractFactory(abi, bytecode, signer);
  testToken = await TestToken.deploy(tokenName, tokenSymbol);

  const oracleAddr = "0xF4eF2BF0F10f7A931840c9d6E61448D492bd0667"
  const testOracle = new ethers.Contract(oracleAddr, oracleabi, signer)
  console.log("testToken: %s, testOracle: %s", testToken.address, testOracle.address);
  // const depositPaymaster = await DepositPaymaster__factory.connect(paymaster.address, signer);
  await paymaster.addToken(testToken.address, testOracle.address);

})
it("next phase", async function () {
const approve = await testToken.allowance(signer.address, paymaster.address)
const tx = await testToken.approve(paymaster.address, ethers.utils.parseEther('1000000'))
console.log('owner approve USDT to deposit paymaster, ', tx.hash);
await tx.wait()

})

it("api and op", async function () {

  api = new SimpleAccountAPI({
      provider,
      entryPointAddress:entryPoint.address,
      owner: signer,
      factoryAddress,
  })
  ownerAA = await api.getAccountAddress()
  console.log('ownerAA', ownerAA);

  const ownerAAUSDTBalance = await testToken.balanceOf(ownerAA)
  if (ownerAAUSDTBalance.lt(ethers.utils.parseEther('10'))) {
      const tx = await testToken.transfer(ownerAA, ethers.utils.parseEther('100000'))
      console.log('owner transfer 100000000 USDT to ownerAA, ', tx.hash);
      await tx.wait()
  }
  const ownerDepositInfo = await paymaster.depositInfo(testToken.address, ownerAA);
  console.log("deposit",ownerDepositInfo);
  
  if (ethers.utils.parseEther('10').gt(ownerDepositInfo.amount)) { // prepare deposit
      const tx = await paymaster.addDepositFor(testToken.address, ownerAA, ethers.utils.parseEther('10000'));
      console.log('owner deposit 10000 USDT, ', tx.hash);
      await tx.wait();
  }

})

it("allowance and send bundler", async function () {
const bundlerUrl = "http://localhost:3000/rpc"
bundlerProvider = new HttpRpcClient(bundlerUrl, entryPoint.address, provider.network.chainId)
const allowance = await testToken.allowance(ownerAA, paymaster.address)
console.log('allowance of ownerAA to depositMaster, ', ethers.utils.formatEther(allowance));

})

it('send oue op', async function () {
const paymasterAPI = new DepositPaymasterAPI(paymaster.address, testToken.address);
const gasPrice = await provider.getGasPrice();
api2 = new SimpleAccountAPI({
provider: provider,
entryPointAddress:entryPoint.address,
owner: signer,
factoryAddress,
paymasterAPI
})
const age_interface = new ethers.utils.Interface(abi1)
const unsignedTransferOP = await resolveProperties(await api2.createUnsignedUserOp({
target: age_address,
data: age_interface.encodeFunctionData('setId', ['7']),
maxFeePerGas: gasPrice, maxPriorityFeePerGas: gasPrice
}))
// unsignedTransferOP.paymasterAndData="0x"
// console.log("recepient addr",receiptAddress)
// const userOpHash = await api2.getUserOpHash(unsignedTransferOP)
// const signature = await api2.signUserOpHash(userOpHash)
// unsignedTransferOP.signature = signature
const be="0x416908b6618B72fBEa9F08F0a4F49b634f14F471"
// const {signedOp,signature} =await resolveProperties( await api2.signUserOp(unsignedTransferOP));
// console.log("use", signature);
// await bundlerProvider.sendUserOpToBundler(unsignedTransferOP)
const op = await api2.signUserOp(unsignedTransferOP);
console.log("op", op)
await entryPoint.handleOps([op],be);
})

})

this code works with no paymaster and data. but after adding paymaster and data all the test is passedd.But the the setId function is not called .HandleOps reverted

async getPaymasterAndData(userOp: Partial): Promise<string | undefined> {
return this.addr + this.token.substring(2);
}

this is paymasterAndData .

Is there any solution for this?

sorry for late response. did you manage to solve the problem?
it is very hard to read it that way. can you send a link we can try to run the test?