Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Human generated abi format created with ethers v6 throws an error #4479

Closed
big-zak opened this issue Nov 25, 2023 · 5 comments
Closed

Human generated abi format created with ethers v6 throws an error #4479

big-zak opened this issue Nov 25, 2023 · 5 comments
Assignees
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@big-zak
Copy link

big-zak commented Nov 25, 2023

Ethers Version

6.8.1

Search Terms

abi, contract

Describe the Problem

I created a script which converts solidity abi to a human readable format, specifically multicall3's abi, but after, using the new abi resulted in an error below:

TypeError: mCallContract.tryAggregate is not a function. (In 'mCallContract.tryAggregate(revertOnError, inputs)', 'mCallContract.tryAggregate.staticCall' is undefined) —

Code Snippet

let mCallContract = new Contract(mCallContractAddr, multicall3Abi)
let resultsArr =  await mCallContract.tryAggregate.staticCall(revertOnError, inputs)

Contract ABI

`["function aggregate(tuple(address,bytes)(address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes[] returnData)","function aggregate3(tuple(address,bool,bytes)(address target, bool allowFailure, bytes callData)[] calls) payable returns (tuple(bool,bytes)(bool success, bytes returnData)[] returnData)","function aggregate3Value(tuple(address,bool,uint256,bytes)(address target, bool allowFailure, uint256 value, bytes callData)[] calls) payable returns (tuple(bool,bytes)(bool success, bytes returnData)[] returnData)","function blockAndAggregate(tuple(address,bytes)(address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes32 blockHash, tuple(bool,bytes)(bool success, bytes returnData)[] returnData)","function getBasefee() view returns (uint256 basefee)","function getBlockHash(uint256 blockNumber) view returns (bytes32 blockHash)","function getBlockNumber() view returns (uint256 blockNumber)","function getChainId() view returns (uint256 chainid)","function getCurrentBlockCoinbase() view returns (address coinbase)","function getCurrentBlockDifficulty() view returns (uint256 difficulty)","function getCurrentBlockGasLimit() view returns (uint256 gaslimit)","function getCurrentBlockTimestamp() view returns (uint256 timestamp)","function getEthBalance(address addr) view returns (uint256 balance)","function getLastBlockHash() view returns (bytes32 blockHash)","function tryAggregate(bool requireSuccess, tuple(address,bytes)(address target, bytes callData)[] calls) payable returns (tuple(bool,bytes)(bool success, bytes returnData)[] returnData)","function tryBlockAndAggregate(bool requireSuccess, tuple(address,bytes)(address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes32 blockHash, tuple(bool,bytes)(bool success, bytes returnData)[] returnData)"]`

Errors

TypeError: mCallContract.tryAggregate is not a function. (In 'mCallContract.tryAggregate(revertOnError, inputs)', 'mCallContract.tryAggregate.staticCall' is undefined) —

Environment

No response

Environment (Other)

No response

@big-zak big-zak added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Nov 25, 2023
@ricmoo
Copy link
Member

ricmoo commented Nov 25, 2023

There seems to be some typos in the ABI; how did you use ethers to generate these? This might be related to #4329. I'll bump that issue up in priority and link it to this one.

The fixed ABI is:

  const abi = [
      "function aggregate((address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes[] returnData)",
      "function aggregate3((address target, bool allowFailure, bytes callData)[] calls) payable returns ((bool success, bytes returnData)[] returnData)",
      "function aggregate3Value((address target, bool allowFailure, uint256 value, bytes callData)[] calls) payable returns ((bool success, bytes returnData)[] returnData)",
      "function blockAndAggregate((address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes32 blockHash, (bool success, bytes returnData)[] returnData)",
      "function getBasefee() view returns (uint256 basefee)",
      "function getBlockHash(uint256 blockNumber) view returns (bytes32 blockHash)",
      "function getBlockNumber() view returns (uint256 blockNumber)",
      "function getChainId() view returns (uint256 chainid)",
      "function getCurrentBlockCoinbase() view returns (address coinbase)",
      "function getCurrentBlockDifficulty() view returns (uint256 difficulty)",
      "function getCurrentBlockGasLimit() view returns (uint256 gaslimit)",
      "function getCurrentBlockTimestamp() view returns (uint256 timestamp)",
      "function getEthBalance(address addr) view returns (uint256 balance)",
      "function getLastBlockHash() view returns (bytes32 blockHash)",
      "function tryAggregate(bool requireSuccess, (address target, bytes callData)[] calls) payable returns ((bool success, bytes returnData)[] returnData)",
      "function tryBlockAndAggregate(bool requireSuccess, (address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes32 blockHash, (bool success, bytes returnData)[] returnData)"
  ];

@ricmoo ricmoo added bug Verified to be an issue. on-deck This Enhancement or Bug is currently being worked on. minor-bump Planned for the next minor version bump. next-patch Issues scheduled for the next arch release. and removed investigate Under investigation and may be a bug. labels Nov 25, 2023
@big-zak
Copy link
Author

big-zak commented Nov 25, 2023

I automatically generated it, the code I used is below:

const path = require("path")
const fg = require("fast-glob")
const fsp = require('fs/promises');
const { Interface: eInterface } = require("ethers")

const ABIsPath =  path.resolve(path.dirname(__dirname), "src/data/abi")
const optimizedABIPath =  path.resolve(path.dirname(__dirname), "src/data/abi_min")

const run = async () => {

    let dataArr = await fg(`${ABIsPath}/**/*.json`)

    console.log(`Optimizing ABI files in ${ABIsPath}`)

    for(let abiPath of dataArr){

        console.log()
        console.log(`Processing ABI File: ${abiPath}`)
        
        let abiData;
        try{ abiData = require(abiPath) } catch(e) { continue; }

        let filename = path.basename(abiPath)

        let fileSubDir = abiPath.replace(ABIsPath, "")

        let outPath = path.join(optimizedABIPath, fileSubDir)

        let outDir = path.dirname(outPath)

        await fsp.mkdir(outDir, { recursive: true })

        const iface = new eInterface(abiData)

        console.log()
        let minAbi = iface.format(false)

        console.log(`Saving Optimized ABI at ${outPath}`)

        await fsp.writeFile(outPath, JSON.stringify(minAbi))
        console.log()
    }
}

run()

@ricmoo
Copy link
Member

ricmoo commented Nov 25, 2023

Thanks!

I've added a fix to the current 6.9-WIP. If I can't get it out today I'll port it back to the latest 6.8 as a patch and get it out tonight.

@ricmoo
Copy link
Member

ricmoo commented Nov 27, 2023

This has been fixed in 6.9.0.

You will have to regenerate those ABIs in the latest version, but then all should be peachy. Please let me know if you have any more issues.

Thanks! :)

@ricmoo ricmoo closed this as completed Nov 27, 2023
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. minor-bump Planned for the next minor version bump. next-patch Issues scheduled for the next arch release. labels Nov 27, 2023
@bot-papi
Copy link

bot-papi commented Dec 1, 2023

Thanks so much

rrw-zilliqa added a commit to Zilliqa/ethers.js that referenced this issue Apr 29, 2024
* docs: fixed typo in jsdocs for Wallet.createRandom (ethers-io#4461)

* admin: added diff scripts for build page

* admin: updated dist files

* Added safe and finalized provider events (ethers-io#3921).

* tests: bumped Node versions for testing (ethers-io#4451)

* admin: style fix (ethers-io#4356)

* More robust FallbackProvider broadcast (ethers-io#4186, ethers-io#4297, ethers-io#4442).

* Account for provider config weight when kicking off a request in FallbackProvider (ethers-io#4298).

* Fixed ParamType formatting causing bad tuple full and minimal ABI output (ethers-io#4329, ethers-io#4479).

* Added Base network to AlchemyProvider (ethers-io#4384).

* Add auto-detected static network support to providers and allow customizing socket provider options (ethers-io#4199, ethers-io#4418, ethers-io#4441).

* Use provider-specified suggested priority fee when available, otherwise fallback onto existing logic of 1 gwei (ethers-io#4463).

* admin: updated dist files

* admin: update changelog after build-clean

* docs: Fixed some grammar in getting-started (ethers-io#4486, ethers-io#4487, ethers-io#4488)

* Fix uncatchable issue when sending transactions over JSON-RPC and provide some retry-recovery for missing v (ethers-io#4513).

* admin: update dist files

* Fix Base58 padding for string representation of binary data (ethers-io#4527).

* admin: updated dist files

* Limit decoded result imflation ratio from ABI-encoded data (ethers-io#4537).

* admin: updated dist files

* Better debugging output on fetch errors.

* docs: added StaticJsonRpcProvider to migration docs

* Fixed typo in Error string (ethers-io#4539).

* Fix EIP-712 type aliases for uint and int (ethers-io#4541).

* Added additional sepolia testnets.

* Updated third-party provider network URLs (ethers-io#4542).

* admin: updated dist files

* Fixed normalization and abstracted EIP-712 Array parsing (ethers-io#4541).

* admin: updated dist files

* tests: added testing for correct thrid-party URLs

* Updated thrid-part provider URLs for QuickNode.

* tests: rename test suite to follow naming convention

* admin: updated dist files

* Normalize EIP-712 types before computing the payload (ethers-io#4541).

* tests: add tests for EIP-712 payload aliases

* admin: updated dist files

---------

Co-authored-by: Richard Moore <me@ricmoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

3 participants