Value undefined only in AutoTask

I have an AutoTask that is triggered from a sentinel, and when i run it locally, everything works perfectly, but when It is triggered via the match condition of an event, i get an error that doesnt make sense.

:computer: Environment

Sentinel -> AutoTask -> Relayer

:memo:Details
Error message when triggered from sentinel:

invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.6.2)

This error happens when at the contract function call.
I have console.log()'d the output of every variable and they are all correct, so i am at quite a loss here. Any suggestions?

:1234: Code to reproduce

const { utils, Contract } = require('ethers');
const { DefenderRelaySigner, DefenderRelayProvider } = require('defender-relay-client/lib/ethers');

const tokenMapping = {
  '0x114B697750CE6efd7D935F019d2460984Bc76942': '0xe48C74833ce6f18A8e54f73f1D02B8E9f9Ff8Caa',
}

const ABI = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"nft","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"}],"name":"BridgedNFT","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address[]","name":"nfts","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"BridgedNFTs","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"BridgedToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address[]","name":"tokens","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"BridgedTokens","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RELAYER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address[]","name":"_nfts","type":"address[]"},{"internalType":"uint256[]","name":"_ids","type":"uint256[]"}],"name":"batchBridgeNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address[]","name":"_tokens","type":"address[]"},{"internalType":"uint256[]","name":"_amounts","type":"uint256[]"}],"name":"batchBridgeToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"_nft","type":"address"},{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"bridgeNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"bridgeToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"bridgeable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"disableAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"enableAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"}]

const ingressAddress = '0x5f332f313E873E6D1d51F7853f4a6AD0446D0907';

exports.main = async function(signer, match) {
  const contract = new Contract(ingressAddress, ABI, signer);
  switch (match.signature) {
    case 'BridgedToken(address,address,uint256)': {
      const [to, sourceToken, amount] = match.args;
      console.log(to, sourceToken, tokenMapping[sourceToken], amount);
      const txRes = await contract.bridgeToken(to, tokenMapping[sourceToken], utils.parseUnits(amount, 0));
      await txRes.wait(1);
      return txRes.hash;
    }
    default: {
      console.log("No matching signature", match);
    }
  }
}

exports.handler = async function(event) {
  const provider = new DefenderRelayProvider(event);
  const signer = new DefenderRelaySigner(event, provider, { speed: 'fast' });
  return exports.main(signer, event.request.body.matchReasons[0]);
}

// To run locally (this code will not be executed in Autotasks)
if (require.main === module) {
  require('dotenv').config();
  const { DEFENDER_API_KEY: apiKey, DEFENDER_API_SECRET: apiSecret } = process.env;

  const request = {
    body: {
      matchReasons: [
        {
          type: 'event',
          signature: 'BridgedToken(address,address,uint256)',
          address: '0xba9564732102222bdbf54b931d783afce52053c5',
          args: [
            '0x4082e997Ec720A4894EFec53b0d9AabfeeA44cBE',
            '0x114B697750CE6efd7D935F019d2460984Bc76942',
            '1'
          ],
          params: {
            from: '0x4082e997Ec720A4894EFec53b0d9AabfeeA44cBE',
            token: '0x114B697750CE6efd7D935F019d2460984Bc76942',
            amount: '1'
          }
        }
      ]
    }
  }

  exports.handler({ apiKey, apiSecret, request })
    .then(() => process.exit(0))
    .catch(error => { console.error(error); process.exit(1); });
}

Upon much longer inspection... the function is working perfectly... but the UI shows the BigNumber error from something else... maybe the return value?

@DirtyCajunRice

Welcome to the community!

Thanks for reaching out and sorry for the inconvenience!

Thanks for detailed steps.

Just to confirm this error happens when you visit Autotask Run page to check execution result/logs or when you visit specific relayer page?

Best Regards,
Zeljko

It is when looking at the run logs. They are all showing error with the error message above, but the entire process worked… so the only thing i can think of is there is some return value dying at the end messing up the UI? Its not the end of the world, but it makes it kinda hard to know when there actually is an issue haha

@zeljko I am also getting a very similar error. My transaction succeeds and I can see my smart contract upgraded but Autotask gives me an error. I am using relayer for gasless tx.

The logs says

2022-06-27T04:55:12.108Z	INFO	Relaying {
  from: '0xd99cBeb2f62935Ef3e451Aaf8Bf669e6474De46D',
  to: '0x6a5c9776d259f76aa445fc4FCC0cF14843f3DE74',
  value: '0',
  gas: '614468',
  nonce: '2',
  data: '0x296f4e16000000000000000000000000f4757e6b3f6abb71c52f494151e82307f6cec2f100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000062b9381f00000000000000000000000000000000000000000000000000000000000151800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee00000000000000000000000000000000000000000000000014d1120d7b16000000000000000000000000000000000000000000000000000014d1120d7b1600000000000000000000000000000000000000000000000000000000000000000000'
}
ERROR	Invoke Error 	{"errorType":"Error","errorMessage":"invalid BigNumber value (argument=\"value\", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.6.2)","code":"INVALID_ARGUMENT","reason":"invalid BigNumber value","argument":"value","stack":["Error: invalid BigNumber value (argument=\"value\", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.6.2)

If you see the value is 0 in the relayer transaction.

I am curious to know if I am doing something wrong?

@DirtyCajunRice

Seems like that underlying problem is when Relayer with EIP1559 policy is used with DefenderRelaySigner.

Until this is resolved quick fix is to set Relayer policies to use legacy transactions(uncheck "Send EIP1559 Transactions by default" policy).
Please let me know if this helps.

Best,
Zeljko

@shrimalmadhur

Thanks for reporting issues.

Are you using DefenderRelaySigner that is connected with Relayer that is sending EIP1559 transactions? This can be found by visiting the relayer page and checking Policies.

If that's the case then the problem is the same as reported by @DirtyCajunRice.
Quick fix is to uncheck "Send EIP1559 Transactions by default" policy.
We are working on a solution for this issue.

Best,
Zeljko

@zeljko that did it. Thanks. Really appreciate your help. Is there any timeline for supporting the EIP 1559 by default case?

@shrimalmadhur
We are targeting this week to support them within Autotasks by releasing updated Autotask dependencies that would include defender-relay-client version 1.25.0.

I will notify you when this is pushed. We are targeting Thursday/Friday.

Best,
Zeljko

@DirtyCajunRice @shrimalmadhur

Just to inform you that we have released a new version of Defender that includes the latest version of defender-relay-client as an autotask dependency.

This enables usage of relayer with EIP1559 policy within autotasks.

In order to make this work you would need to recreate autotasks(create new ones with needed logic).

Note: We are working on a solution for upgrading autotask dependencies without recreating them.

Best,
Zeljko

2 Likes

It eventually just stopped doing it ironically. I am glad that it brought up an edge case for yall though!

Thank you for the help :slight_smile: