Meta-tx updated 2024

Guys, Is there any updated issue about the meta-tx using openzepellin defender ?

the last one that I saw is this: https://github.com/OpenZeppelin/workshops/tree/master/25-defender-metatx-api

In which I did some changes to get the problem "Invalid Request"

:computer: Environment
i'm trying to set all tools to get gasless transaction available. (relay, actions)

:memo:Details

I'm following the demo 25-defender-metatx-api. And whe i'm trying to run yarn relay, i'm getting Invalid request.

Other thing that i'm observing is on the new forewarder abi, nonce was replaced by deadline as well.

:1234: Code to reproduce

const { Defender } = require('@openzeppelin/defender-sdk');
const { ethers } = require('ethers')

const { ForwarderAbi } = require('../src/forwarder');
const ForwarderAddress = require('../deploy.json').ERC2771Forwarder;

async function relay(forwarder, request, signature, whitelist) {
  // Decide if we want to relay this request based on a whitelist
  const accepts = !whitelist || whitelist.includes(request.to);
  if (!accepts) throw new Error(`Rejected request to ${request.to}`);

  const formattedRequest = [
    request.from,
    request.to,
    ethers.BigNumber.from(String(request.value) || "0"),  // Ensure value is a string and default to "0"
    ethers.BigNumber.from(String(request.gas) || "0"),      // Ensure gas is a string and default to "0"
    ethers.BigNumber.from(String(request.nonce) || "0"),  // Ensure nonce is a string and default to "0"
    request.data,
    signature
  ];

  console.log(formattedRequest)

  // Validate request on the forwarder contract
  const valid = await forwarder.verify(request);

  if (!valid) throw new Error(`Invalid request`);
  
  // Send meta-tx through relayer to the forwarder contract
  const gasLimit = (parseInt(request.gas) + 50000).toString();
  return await forwarder.execute(request, signature, { gasLimit });
}

async function handler(event) {

  // Parse webhook payload
  if (!event.request || !event.request.body) throw new Error(`Missing payload`);
  const { request, signature } = event.request.body;
  console.log(`Relaying`, request);
  
  // Initialize Relayer provider and signer, and forwarder contract
  const creds = { ... event };

  const client =  new Defender(creds);

  const provider = client.relaySigner.getProvider();

  const signer = client.relaySigner.getSigner(provider, { speed: 'fast' });

  const forwarder = new ethers.Contract(ForwarderAddress, ForwarderAbi, signer);


  // Relay transaction!
  const tx = await relay(forwarder, request, signature);

  
  console.log(`Sent meta-tx: ${tx.hash}`);
  return { txHash: tx.hash };
}

module.exports = {
  handler,
  relay,
}