Skip to content

Commit 978490f

Browse files
krzkaczorhasparus
andauthoredMar 16, 2022
[ethers-v5] Fix polymorphism (#648)
* Add test proving that polymorphism doesnt' work for ethers-v5 currently * Fix for clean task * Add `discriminateTypes` argument, hide `contractName` if not true * Add readme note and changeset * Refactor solcjs call in compile-contract.ts * Remove redundant console.log Co-authored-by: hasparus <hasparus@gmail.com>
1 parent 1fdc793 commit 978490f

File tree

71 files changed

+530
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+530
-163
lines changed
 

Diff for: ‎.changeset/lemon-windows-carry.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@typechain/hardhat': major
3+
'@typechain/ethers-v5': major
4+
'typechain': major
5+
---
6+
7+
## What's breaking:
8+
9+
We are not emitting `contractName` fields on contracts and factories anymore.
10+
11+
## Why?
12+
13+
`contractName` breaks polymorphism for example: exact token implementation is not assignable to token interface.
14+
15+
## What do to?
16+
17+
We are adding optional flag `--discriminate-types` to continue emitting `contractName`.

Diff for: ‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ typechain --target=(ethers-v5|truffle-v4|truffle-v5|web3-v1|path-to-custom-targe
8282
- `--out-dir` (optional) - put all generated files to a specific dir.
8383
- `--always-generate-overloads` (optional) - some targets won't generate unnecessary types for overloaded functions by
8484
default, this option forces to always generate them
85+
- `--discriminate-types` (optional) - ethers-v5 will add an artificial field `contractName` that helps discriminate
86+
between contracts
8587

8688
TypeChain always will rewrite existing files. You should not commit them. Read more in FAQ section.
8789

1 commit comments

Comments
 (1)

shashidhar771892 commented on Feb 20, 2023

@shashidhar771892

clean: "hardhat clean & rm-f-tsconfig.build.tsbuildinfo & rm-rf build"
const source = codegenContractFactory(emptyContract, 'abi';

execSync
(
pnpm --package solc@${semver} dlx solcjs --abi ${contractPaths} --bin -o ./contracts/compiled/${dirName};
{
cwd: rootDir;
stdio: ['ignore'-'ignore'- 'inherit'];
}
)


execSync
(
pnpm --package solc@${semver} dlx solcjs --abi ${contractPaths} --bin -o ./contracts/compiled/${dirName};

  {

    cwd: rootDir;
    stdio: ['ignore'- 'ignore'- 'inherit'];

  }

please make sure that the above segments in the scripts/compile-contracts.ts
(57 to 81 lines)

Please sign in to comment.