TypeChain icon indicating copy to clipboard operation
TypeChain copied to clipboard

When using with `@nomiclabs/hardhat-vyper`, resulting factories from vyper sources do not have correct ContractInterface type

Open penandlim opened this issue 3 years ago • 2 comments

Can be replicated with below repo.

https://github.com/penandlim/TestVyperPlugins

After successfully generating types, there are typescript errors in build/typechain/factories/HelloVyper.vy/HelloVyper__factory.ts. Due to this type error, running test task results in errors.

npm ci
npx hardhat compile --no-typechain && npx hardhat typechain
npx hardhat test

Looks like gas properties inside the abis are set to number but ContractInterface expects it to be string

I've found this issue from last year on hardhat side but dont seem like much was done at the time.

https://github.com/NomicFoundation/hardhat/issues/1696

penandlim avatar Apr 22 '22 03:04 penandlim

Stumbled upon this same issue, and for now manually updated the typechain *__factory.ts files such that:

const _abiNoGas = _abi.map( (element) => {
  const {["gas"]: _, ...withoutGas } = element;
  return withoutGas;
});

And set to use _abiNoGas instead of _abi.

It fixes two issues:

  1. typescript complaints that the gas field isn't a string
  2. Even if you stringify the gas field, the auto-generated gas estimation was actually incorrect - so contract function calls reverted (via hardhat/ethers) unless a large {gasLimit} was manually provided.

frontier159 avatar May 25 '22 03:05 frontier159

@krzkaczor thoughts on a proposed solution? https://github.com/dethcrypto/TypeChain/pull/711

This fixes for me locally. @penandlim would you be able to test? Can git clone this branch: https://github.com/frontier159/TypeChain/tree/feature/exclude_gas_from_abi

And then in your project add it locally to yarn/npm/whatever:

npm install --save-dev file:/path/to/TypeChain/packages/target-ethers-v5

And your testVyper.ts needs a small tweak

  beforeEach(async () => {
//    const factory: HelloVyper__factory = new HelloVyper__factory()
    const factory: HelloVyper__factory = await ethers.getContractFactory("HelloVyper")
    testContract = (await factory.deploy()) as HelloVyper
  })

But then works ok:

npx hardhat test

No need to generate any newer typings.


  HelloSolidity
    setGreeting
      ✔ Sets and prints Greeting

  HelloVyper
    setGreeting
      ✔ Sets and prints Greeting


  2 passing (436ms)

frontier159 avatar Jun 07 '22 04:06 frontier159

This can be closed now: https://github.com/NomicFoundation/hardhat/pull/2879

frontier159 avatar Aug 19 '22 06:08 frontier159