Open krzkaczor opened 2 years ago
that would be awesome. would that be possible to use the same name of the Struct defined in the solidity contract?
Is it currently not possible to import structs exported from typechain?
@mrwillis it is. This issue is about dropping TypedEvent
thing.
@krzkaczor sorry for the abuse of this thread. I'm unable to import structs for example in internal libraries, not linked. The default behaviour seems to export the contract type in index.ts
export type { BaseFillOrder} from "./BaseFillOrder";
but this file BaseFillOrder.ts
has an internal library called LibOrder.sol
which is represented in a namespace like
export declare namespace LibOrder {
export type OrderStruct = {
marketHash: BytesLike;
baseToken: string;
totalBetSize: BigNumberish;
percentageOdds: BigNumberish;
expiry: BigNumberish;
salt: BigNumberish;
maker: string;
executor: string;
isMakerBettingOutcomeOne: boolean;
};
export type OrderStructOutput = [
string,
string,
BigNumber,
BigNumber,
BigNumber,
BigNumber,
string,
string,
boolean
] & {
marketHash: string;
baseToken: string;
totalBetSize: BigNumber;
percentageOdds: BigNumber;
expiry: BigNumber;
salt: BigNumber;
maker: string;
executor: string;
isMakerBettingOutcomeOne: boolean;
};
}
which actually does not get exported.
If the export looked like in index.ts
export type { BaseFillOrder, LibOrder} from "./BaseFillOrder";
It is importable into consuming code. Does it make sense? I can put together a repro repo
I have the same issue as @mrwillis
There is an issue that if event does not have some params name declared, named props for them are not created by ethers e.g. event Transfer(address indexed from, address indexed, uint)
is decoded as:
{
...
args: [
'0x362fA9D0bCa5D19f743Db50738345ce2b40eC99f',
'0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168',
BigNumber { value: "1195383028069068722922", hex: "0x40cd45a29e3ba452ea" },
from: '0x362fA9D0bCa5D19f743Db50738345ce2b40eC99f' // only from is available
]
}
I want to share my workaround to anyone landing on this page after struggling to use a typechain struct type as model :
contract :
struct NFToken { IERC721 implem; uint256 id; }
type generated :
type NFTokenStructOutput = [string, BigNumber] & { implem: string; id: BigNumber; }
How I create my model :
type NFT = Omit<NFTokenStructOutput, keyof [string, BigNumber]>
Hope that helps
Currently we generate event types like this:
This is fine if user wants to use this for for filters etc. but often events (and structs) doubles as "models" in a different part of the software. I propose we export them additionally in a more user friendly format that enables to reuse them in different part of the sourcecode: