@typechain/ethers-v5
Advanced tools
Comparing version 7.2.0 to 8.0.0
# @typechain/ethers-v5 | ||
## 8.0.0 | ||
### Major Changes | ||
- 5c217a6: Changed emitted event types — named events are now used in Contract methods. | ||
- 0e555af: Generate types to `.ts` files instead of `.d.ts` in Ethers v5 and Web3.js targets | ||
### Minor Changes | ||
- 95517e9: Add support for Solidity structs | ||
```ts | ||
// before | ||
function deposit(amount: { token: string; value: BigNumberish }): Promise<ContractTransaction> | ||
// after | ||
export type AmountStruct = { token: string; value: BigNumberish } | ||
function deposit(amount: AmountStruct): Promise<ContractTransaction> | ||
``` | ||
### Patch Changes | ||
- a0b3c4b: Custom generated factories do not require signers now | ||
- aacdcb0: Export EventFilter type along with Event type | ||
- Updated dependencies [0ac4921] | ||
- Updated dependencies [95517e9] | ||
- Updated dependencies [33ee803] | ||
- typechain@6.0.0 | ||
## 7.2.0 | ||
@@ -4,0 +34,0 @@ |
import { EventArgDeclaration, EventDeclaration } from 'typechain'; | ||
export declare function generateEventFilters(events: EventDeclaration[]): string; | ||
export declare function generateEventFilter(event: EventDeclaration, includeNameFilter: boolean): string; | ||
export declare function generateEventTypeExports(events: EventDeclaration[]): string; | ||
@@ -11,1 +10,3 @@ export declare function generateEventTypeExport(event: EventDeclaration, includeArgTypes: boolean): string; | ||
export declare function generateGetEventOverload(event: EventDeclaration): string; | ||
export declare const EVENT_METHOD_OVERRIDES = "\n queryFilter<TEvent extends TypedEvent>(\n event: TypedEventFilter<TEvent>,\n fromBlockOrBlockhash?: string | number | undefined,\n toBlock?: string | number | undefined,\n ): Promise<Array<TEvent>>\n\n listeners<TEvent extends TypedEvent>(eventFilter?: TypedEventFilter<TEvent>): Array<TypedListener<TEvent>>\n listeners(eventName?: string): Array<Listener>\n removeAllListeners<TEvent extends TypedEvent>(eventFilter: TypedEventFilter<TEvent>): this\n removeAllListeners(eventName?: string): this\n off: OnEvent<this>\n on: OnEvent<this>\n once: OnEvent<this>\n removeListener: OnEvent<this>\n"; | ||
export declare const EVENT_IMPORTS: string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateGetEventOverload = exports.generateEventArgType = exports.generateEventInputs = exports.generateEventSignature = exports.generateInterfaceEventDescription = exports.generateEventTypeExport = exports.generateEventTypeExports = exports.generateEventFilter = exports.generateEventFilters = void 0; | ||
exports.EVENT_IMPORTS = exports.EVENT_METHOD_OVERRIDES = exports.generateGetEventOverload = exports.generateEventArgType = exports.generateEventInputs = exports.generateEventSignature = exports.generateInterfaceEventDescription = exports.generateEventTypeExport = exports.generateEventTypeExports = exports.generateEventFilters = void 0; | ||
const typechain_1 = require("typechain"); | ||
@@ -8,24 +8,19 @@ const types_1 = require("./types"); | ||
if (events.length === 1) { | ||
return generateEventFilter(events[0], true); | ||
const event = events[0]; | ||
const typedEventFilter = `${generateEventIdentifier(event, { includeArgTypes: false })}Filter`; | ||
return ` | ||
'${generateEventSignature(event)}'(${generateEventInputs(event.inputs)}): ${typedEventFilter}; | ||
${event.name}(${generateEventInputs(event.inputs)}): ${typedEventFilter}; | ||
`; | ||
} | ||
else { | ||
return events.map((e) => generateEventFilter(e, false)).join('\n'); | ||
return events | ||
.map((event) => { | ||
const typedEventFilter = `${generateEventIdentifier(event, { includeArgTypes: true })}Filter`; | ||
return `'${generateEventSignature(event)}'(${generateEventInputs(event.inputs)}): ${typedEventFilter};`; | ||
}) | ||
.join('\n'); | ||
} | ||
} | ||
exports.generateEventFilters = generateEventFilters; | ||
function generateEventFilter(event, includeNameFilter) { | ||
const components = event.inputs.map((input, i) => { var _a; return ({ name: (_a = input.name) !== null && _a !== void 0 ? _a : `arg${i.toString()}`, type: input.type }); }); | ||
const arrayOutput = types_1.generateOutputComplexTypeAsArray(components); | ||
const objectOutput = types_1.generateOutputComplexTypesAsObject(components) || '{}'; | ||
let filter = ` | ||
'${generateEventSignature(event)}'(${generateEventInputs(event.inputs)}): TypedEventFilter<${arrayOutput}, ${objectOutput}>; | ||
`; | ||
if (includeNameFilter) { | ||
filter += ` | ||
${event.name}(${generateEventInputs(event.inputs)}): TypedEventFilter<${arrayOutput}, ${objectOutput}>; | ||
`; | ||
} | ||
return filter; | ||
} | ||
exports.generateEventFilter = generateEventFilter; | ||
function generateEventTypeExports(events) { | ||
@@ -42,6 +37,9 @@ if (events.length === 1) { | ||
const components = event.inputs.map((input, i) => { var _a; return ({ name: (_a = input.name) !== null && _a !== void 0 ? _a : `arg${i.toString()}`, type: input.type }); }); | ||
const arrayOutput = types_1.generateOutputComplexTypeAsArray(components); | ||
const objectOutput = types_1.generateOutputComplexTypesAsObject(components) || '{}'; | ||
const arrayOutput = (0, types_1.generateOutputComplexTypeAsArray)(components, { useStructs: true }); | ||
const objectOutput = (0, types_1.generateOutputComplexTypesAsObject)(components, { useStructs: true }) || '{}'; | ||
const identifier = generateEventIdentifier(event, { includeArgTypes }); | ||
return ` | ||
export type ${event.name}${includeArgTypes ? event.inputs.map((input) => '_' + input.type.originalType).join('') + '_Event' : 'Event'} = TypedEvent<${arrayOutput} & ${objectOutput}>; | ||
export type ${identifier} = TypedEvent<${arrayOutput}, ${objectOutput}>; | ||
export type ${identifier}Filter = TypedEventFilter<${identifier}>; | ||
`; | ||
@@ -64,3 +62,3 @@ } | ||
.map((arg) => { | ||
return `${arg.name && typechain_1.createPositionalIdentifier(arg.name)}?: ${generateEventArgType(arg)}`; | ||
return `${arg.name && (0, typechain_1.createPositionalIdentifier)(arg.name)}?: ${generateEventArgType(arg)}`; | ||
}) | ||
@@ -71,3 +69,3 @@ .join(', ') + ', '); | ||
function generateEventArgType(eventArg) { | ||
return eventArg.isIndexed ? `${types_1.generateInputType(eventArg.type)} | null` : 'null'; | ||
return eventArg.isIndexed ? `${(0, types_1.generateInputType)({ useStructs: true }, eventArg.type)} | null` : 'null'; | ||
} | ||
@@ -79,2 +77,22 @@ exports.generateEventArgType = generateEventArgType; | ||
exports.generateGetEventOverload = generateGetEventOverload; | ||
function generateEventIdentifier(event, { includeArgTypes } = {}) { | ||
return `${event.name}${includeArgTypes ? event.inputs.map((input) => '_' + input.type.originalType).join('') + '_Event' : 'Event'}`; | ||
} | ||
exports.EVENT_METHOD_OVERRIDES = ` | ||
queryFilter<TEvent extends TypedEvent>( | ||
event: TypedEventFilter<TEvent>, | ||
fromBlockOrBlockhash?: string | number | undefined, | ||
toBlock?: string | number | undefined, | ||
): Promise<Array<TEvent>> | ||
listeners<TEvent extends TypedEvent>(eventFilter?: TypedEventFilter<TEvent>): Array<TypedListener<TEvent>> | ||
listeners(eventName?: string): Array<Listener> | ||
removeAllListeners<TEvent extends TypedEvent>(eventFilter: TypedEventFilter<TEvent>): this | ||
removeAllListeners(eventName?: string): this | ||
off: OnEvent<this> | ||
on: OnEvent<this> | ||
once: OnEvent<this> | ||
removeListener: OnEvent<this> | ||
`; | ||
exports.EVENT_IMPORTS = ['TypedEventFilter', 'TypedEvent', 'TypedListener', 'OnEvent']; | ||
//# sourceMappingURL=events.js.map |
@@ -19,3 +19,3 @@ "use strict"; | ||
function codegenForOverloadedFunctions(options, fns) { | ||
return fns.map((fn) => generateFunction(options, fn, `"${typechain_1.getSignatureForFn(fn)}"`)).join('\n'); | ||
return fns.map((fn) => generateFunction(options, fn, `"${(0, typechain_1.getSignatureForFn)(fn)}"`)).join('\n'); | ||
} | ||
@@ -30,3 +30,3 @@ exports.codegenForOverloadedFunctions = codegenForOverloadedFunctions; | ||
${generateFunctionDocumentation(fn.documentation)} | ||
${overloadedName !== null && overloadedName !== void 0 ? overloadedName : fn.name}(${types_1.generateInputTypes(fn.inputs)}${!options.isStaticCall && !typechain_1.isConstant(fn) && !typechain_1.isConstantFn(fn) | ||
${overloadedName !== null && overloadedName !== void 0 ? overloadedName : fn.name}(${(0, types_1.generateInputTypes)(fn.inputs, { useStructs: true })}${!options.isStaticCall && !(0, typechain_1.isConstant)(fn) && !(0, typechain_1.isConstantFn)(fn) | ||
? `overrides?: ${isPayable(fn) | ||
@@ -36,3 +36,3 @@ ? 'PayableOverrides & { from?: string | Promise<string> }' | ||
: 'overrides?: CallOverrides'}): ${(_a = options.overrideOutput) !== null && _a !== void 0 ? _a : `Promise<${options.isStaticCall || fn.stateMutability === 'pure' || fn.stateMutability === 'view' | ||
? types_1.generateOutputTypes(!!options.returnResultObject, fn.outputs) | ||
? (0, types_1.generateOutputTypes)({ returnResultObject: !!options.returnResultObject, useStructs: true }, fn.outputs) | ||
: 'ContractTransaction'}>`}; | ||
@@ -61,3 +61,3 @@ `; | ||
function generateInterfaceFunctionDescription(fn) { | ||
return `'${typechain_1.getSignatureForFn(fn)}': FunctionFragment;`; | ||
return `'${(0, typechain_1.getSignatureForFn)(fn)}': FunctionFragment;`; | ||
} | ||
@@ -68,3 +68,3 @@ exports.generateInterfaceFunctionDescription = generateInterfaceFunctionDescription; | ||
if (fn.inputs.length) { | ||
methodInputs.push(`values: [${fn.inputs.map((input) => types_1.generateInputType(input.type)).join(', ')}]`); | ||
methodInputs.push(`values: [${fn.inputs.map((input) => (0, types_1.generateInputType)({ useStructs: true }, input.type)).join(', ')}]`); | ||
} | ||
@@ -82,5 +82,5 @@ else { | ||
function generateParamNames(params) { | ||
return params.map((param, index) => (param.name ? typechain_1.createPositionalIdentifier(param.name) : `arg${index}`)).join(', '); | ||
return params.map((param, index) => (param.name ? (0, typechain_1.createPositionalIdentifier)(param.name) : `arg${index}`)).join(', '); | ||
} | ||
exports.generateParamNames = generateParamNames; | ||
//# sourceMappingURL=functions.js.map |
@@ -9,8 +9,9 @@ "use strict"; | ||
const reserved_keywords_1 = require("./reserved-keywords"); | ||
const structs_1 = require("./structs"); | ||
const types_1 = require("./types"); | ||
function codegenContractTypings(contract, codegenConfig) { | ||
const contractImports = ['BaseContract', 'ContractTransaction']; | ||
const allFunctions = lodash_1.values(contract.functions) | ||
.map((fn) => functions_1.codegenFunctions({ returnResultObject: true, codegenConfig }, fn) + | ||
functions_1.codegenFunctions({ isStaticCall: true, codegenConfig }, fn)) | ||
const allFunctions = (0, lodash_1.values)(contract.functions) | ||
.map((fn) => (0, functions_1.codegenFunctions)({ returnResultObject: true, codegenConfig }, fn) + | ||
(0, functions_1.codegenFunctions)({ isStaticCall: true, codegenConfig }, fn)) | ||
.join(''); | ||
@@ -24,7 +25,11 @@ const optionalContractImports = ['Overrides', 'PayableOverrides', 'CallOverrides']; | ||
import { FunctionFragment, EventFragment, Result } from '@ethersproject/abi'; | ||
import type { TypedEventFilter, TypedEvent, TypedListener } from './common'; | ||
import type { ${events_1.EVENT_IMPORTS.join(', ')} } from './common'; | ||
interface ${contract.name}Interface extends ethers.utils.Interface { | ||
${(0, lodash_1.values)(contract.structs) | ||
.map((v) => (0, structs_1.generateStruct)(v[0])) | ||
.join('\n')} | ||
export interface ${contract.name}Interface extends ethers.utils.Interface { | ||
functions: { | ||
${lodash_1.values(contract.functions) | ||
${(0, lodash_1.values)(contract.functions) | ||
.map((v) => v[0]) | ||
@@ -35,3 +40,3 @@ .map(functions_1.generateInterfaceFunctionDescription) | ||
${lodash_1.values(contract.functions) | ||
${(0, lodash_1.values)(contract.functions) | ||
.map((v) => v[0]) | ||
@@ -41,3 +46,3 @@ .map(functions_1.generateEncodeFunctionDataOverload) | ||
${lodash_1.values(contract.functions) | ||
${(0, lodash_1.values)(contract.functions) | ||
.map((v) => v[0]) | ||
@@ -48,3 +53,3 @@ .map(functions_1.generateDecodeFunctionResultOverload) | ||
events: { | ||
${lodash_1.values(contract.events) | ||
${(0, lodash_1.values)(contract.events) | ||
.map((v) => v[0]) | ||
@@ -55,3 +60,3 @@ .map(events_1.generateInterfaceEventDescription) | ||
${lodash_1.values(contract.events) | ||
${(0, lodash_1.values)(contract.events) | ||
.map((v) => v[0]) | ||
@@ -62,5 +67,5 @@ .map(events_1.generateGetEventOverload) | ||
${lodash_1.values(contract.events).map(events_1.generateEventTypeExports).join('\n')} | ||
${(0, lodash_1.values)(contract.events).map(events_1.generateEventTypeExports).join('\n')} | ||
export class ${contract.name} extends BaseContract { | ||
export interface ${contract.name} extends BaseContract { | ||
connect(signerOrProvider: Signer | Provider | string): this; | ||
@@ -70,26 +75,8 @@ attach(addressOrName: string): this; | ||
listeners<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter?: TypedEventFilter<EventArgsArray, EventArgsObject>): Array<TypedListener<EventArgsArray, EventArgsObject>>; | ||
off<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>, listener: TypedListener<EventArgsArray, EventArgsObject>): this; | ||
on<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>, listener: TypedListener<EventArgsArray, EventArgsObject>): this; | ||
once<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>, listener: TypedListener<EventArgsArray, EventArgsObject>): this; | ||
removeListener<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>, listener: TypedListener<EventArgsArray, EventArgsObject>): this; | ||
removeAllListeners<EventArgsArray extends Array<any>, EventArgsObject>(eventFilter: TypedEventFilter<EventArgsArray, EventArgsObject>): this; | ||
interface: ${contract.name}Interface; | ||
listeners(eventName?: string): Array<Listener>; | ||
off(eventName: string, listener: Listener): this; | ||
on(eventName: string, listener: Listener): this; | ||
once(eventName: string, listener: Listener): this; | ||
removeListener(eventName: string, listener: Listener): this; | ||
removeAllListeners(eventName?: string): this; | ||
${events_1.EVENT_METHOD_OVERRIDES} | ||
queryFilter<EventArgsArray extends Array<any>, EventArgsObject>( | ||
event: TypedEventFilter<EventArgsArray, EventArgsObject>, | ||
fromBlockOrBlockhash?: string | number | undefined, | ||
toBlock?: string | number | undefined | ||
): Promise<Array<TypedEvent<EventArgsArray & EventArgsObject>>>; | ||
interface: ${contract.name}Interface; | ||
functions: { | ||
${lodash_1.values(contract.functions) | ||
${(0, lodash_1.values)(contract.functions) | ||
.map(functions_1.codegenFunctions.bind(null, { returnResultObject: true, codegenConfig })) | ||
@@ -99,3 +86,3 @@ .join('\n')} | ||
${lodash_1.values(contract.functions) | ||
${(0, lodash_1.values)(contract.functions) | ||
.filter((f) => !reserved_keywords_1.reservedKeywords.has(f[0].name)) | ||
@@ -106,3 +93,3 @@ .map(functions_1.codegenFunctions.bind(null, { codegenConfig })) | ||
callStatic: { | ||
${lodash_1.values(contract.functions) | ||
${(0, lodash_1.values)(contract.functions) | ||
.map(functions_1.codegenFunctions.bind(null, { isStaticCall: true, codegenConfig })) | ||
@@ -113,7 +100,7 @@ .join('\n')} | ||
filters: { | ||
${lodash_1.values(contract.events).map(events_1.generateEventFilters).join('\n')} | ||
${(0, lodash_1.values)(contract.events).map(events_1.generateEventFilters).join('\n')} | ||
}; | ||
estimateGas: { | ||
${lodash_1.values(contract.functions) | ||
${(0, lodash_1.values)(contract.functions) | ||
.map(functions_1.codegenFunctions.bind(null, { overrideOutput: 'Promise<BigNumber>', codegenConfig })) | ||
@@ -124,3 +111,3 @@ .join('\n')} | ||
populateTransaction: { | ||
${lodash_1.values(contract.functions) | ||
${(0, lodash_1.values)(contract.functions) | ||
.map(functions_1.codegenFunctions.bind(null, { overrideOutput: 'Promise<PopulatedTransaction>', codegenConfig })) | ||
@@ -135,3 +122,3 @@ .join('\n')} | ||
var _a; | ||
const constructorArgs = (contract.constructor[0] ? types_1.generateInputTypes(contract.constructor[0].inputs) : '') + | ||
const constructorArgs = (contract.constructor[0] ? (0, types_1.generateInputTypes)(contract.constructor[0].inputs, { useStructs: true }) : '') + | ||
`overrides?: ${((_a = contract.constructor[0]) === null || _a === void 0 ? void 0 : _a.stateMutability) === 'payable' | ||
@@ -141,3 +128,3 @@ ? 'PayableOverrides & { from?: string | Promise<string> }' | ||
const constructorArgNamesWithoutOverrides = contract.constructor[0] | ||
? functions_1.generateParamNames(contract.constructor[0].inputs) | ||
? (0, functions_1.generateParamNames)(contract.constructor[0].inputs) | ||
: ''; | ||
@@ -221,11 +208,9 @@ const constructorArgNames = constructorArgNamesWithoutOverrides | ||
return ` | ||
constructor( | ||
...args: [signer: Signer] | ConstructorParameters<typeof ContractFactory> | ||
) { | ||
if (args.length === 1) { | ||
super(_abi, _bytecode, args[0]); | ||
} else { | ||
super(...args); | ||
constructor(...args: ${contract.name}ConstructorParams) { | ||
if (isSuperArgs(args)) { | ||
super(...args); | ||
} else { | ||
super(_abi, _bytecode, args[0]); | ||
} | ||
} | ||
} | ||
`; | ||
@@ -271,8 +256,8 @@ } | ||
function generateFactoryConstructorParamsAlias(contract, bytecode) { | ||
const name = `${contract.name}ConstructorParams`; | ||
if (bytecode.linkReferences) { | ||
const name = `${contract.name}ConstructorParams`; | ||
return `\ | ||
return ` | ||
type ${name} = | ||
| [linkLibraryAddresses: ${contract.name}LibraryAddresses, signer?: Signer] | ||
| ConstructorParameters<typeof ContractFactory> | ||
| ConstructorParameters<typeof ContractFactory>; | ||
@@ -287,3 +272,10 @@ const isSuperArgs = ( | ||
} | ||
return ''; | ||
else { | ||
return ` | ||
type ${name} = [signer?: Signer] | ConstructorParameters<typeof ContractFactory>; | ||
const isSuperArgs = (xs: ${name}): xs is ConstructorParameters<typeof ContractFactory> => | ||
xs.length > 1 | ||
`; | ||
} | ||
} | ||
@@ -290,0 +282,0 @@ function generateLibraryAddressesInterface(contract, bytecode) { |
import { AbiOutputParameter, AbiParameter, EvmOutputType, EvmType, TupleType } from 'typechain'; | ||
export declare function generateInputTypes(input: Array<AbiParameter>): string; | ||
export declare function generateOutputTypes(returnResultObject: boolean, outputs: Array<AbiOutputParameter>): string; | ||
export declare function generateInputType(evmType: EvmType): string; | ||
export declare function generateOutputType(evmType: EvmOutputType): string; | ||
interface GenerateTypeOptions { | ||
returnResultObject?: boolean; | ||
useStructs?: boolean; | ||
} | ||
export declare function generateInputTypes(input: Array<AbiParameter>, options: GenerateTypeOptions): string; | ||
export declare function generateOutputTypes(options: GenerateTypeOptions, outputs: Array<AbiOutputParameter>): string; | ||
export declare function generateInputType(options: GenerateTypeOptions, evmType: EvmType): string; | ||
export declare function generateOutputType(options: GenerateTypeOptions, evmType: EvmOutputType): string; | ||
export declare function generateTupleType(tuple: TupleType, generator: (evmType: EvmType) => string): string; | ||
@@ -11,4 +15,5 @@ /** | ||
**/ | ||
export declare function generateOutputComplexType(components: AbiOutputParameter[]): string; | ||
export declare function generateOutputComplexTypeAsArray(components: AbiOutputParameter[]): string; | ||
export declare function generateOutputComplexTypesAsObject(components: AbiOutputParameter[]): string | undefined; | ||
export declare function generateOutputComplexType(components: AbiOutputParameter[], options: GenerateTypeOptions): string; | ||
export declare function generateOutputComplexTypeAsArray(components: AbiOutputParameter[], options: GenerateTypeOptions): string; | ||
export declare function generateOutputComplexTypesAsObject(components: AbiOutputParameter[], options: GenerateTypeOptions): string | undefined; | ||
export {}; |
@@ -5,15 +5,18 @@ "use strict"; | ||
const lodash_1 = require("lodash"); | ||
function generateInputTypes(input) { | ||
const common_1 = require("../common"); | ||
function generateInputTypes(input, options) { | ||
if (input.length === 0) { | ||
return ''; | ||
} | ||
return (input.map((input, index) => `${input.name || `arg${index}`}: ${generateInputType(input.type)}`).join(', ') + ', '); | ||
return (input | ||
.map((input, index) => `${input.name || `arg${index}`}: ${generateInputType(options, input.type)}`) | ||
.join(', ') + ', '); | ||
} | ||
exports.generateInputTypes = generateInputTypes; | ||
function generateOutputTypes(returnResultObject, outputs) { | ||
if (!returnResultObject && outputs.length === 1) { | ||
return generateOutputType(outputs[0].type); | ||
function generateOutputTypes(options, outputs) { | ||
if (!options.returnResultObject && outputs.length === 1) { | ||
return generateOutputType(options, outputs[0].type); | ||
} | ||
else { | ||
return generateOutputComplexType(outputs); | ||
return generateOutputComplexType(outputs, options); | ||
} | ||
@@ -23,3 +26,3 @@ } | ||
// https://docs.ethers.io/ethers.js/html/api-contract.html#types | ||
function generateInputType(evmType) { | ||
function generateInputType(options, evmType) { | ||
switch (evmType.type) { | ||
@@ -37,6 +40,13 @@ case 'integer': | ||
if (evmType.size !== undefined) { | ||
return `[${Array(evmType.size).fill(generateInputType(evmType.itemType)).join(', ')}]`; | ||
return `[${Array(evmType.size) | ||
.fill(generateInputType({ ...options, useStructs: true }, evmType.itemType)) | ||
.join(', ')}]`; | ||
} | ||
else { | ||
return `(${generateInputType(evmType.itemType)})[]`; | ||
if (options.useStructs) { | ||
if (evmType.structName) { | ||
return evmType.structName + common_1.STRUCT_INPUT_POSTFIX + '[]'; | ||
} | ||
} | ||
return `(${generateInputType({ ...options, useStructs: true }, evmType.itemType)})[]`; | ||
} | ||
@@ -48,3 +58,8 @@ case 'boolean': | ||
case 'tuple': | ||
return generateTupleType(evmType, generateInputType); | ||
if (options.useStructs) { | ||
if (evmType.structName) { | ||
return evmType.structName + common_1.STRUCT_INPUT_POSTFIX; | ||
} | ||
} | ||
return generateTupleType(evmType, generateInputType.bind(null, { ...options, useStructs: true })); | ||
case 'unknown': | ||
@@ -55,3 +70,3 @@ return 'any'; | ||
exports.generateInputType = generateInputType; | ||
function generateOutputType(evmType) { | ||
function generateOutputType(options, evmType) { | ||
switch (evmType.type) { | ||
@@ -70,6 +85,13 @@ case 'integer': | ||
if (evmType.size !== undefined) { | ||
return `[${Array(evmType.size).fill(generateOutputType(evmType.itemType)).join(', ')}]`; | ||
return `[${Array(evmType.size) | ||
.fill(generateOutputType({ ...options, useStructs: true }, evmType.itemType)) | ||
.join(', ')}]`; | ||
} | ||
else { | ||
return `(${generateOutputType(evmType.itemType)})[]`; | ||
if (options.useStructs) { | ||
if (evmType.structName) { | ||
return evmType.structName + common_1.STRUCT_OUTPUT_POSTFIX + '[]'; | ||
} | ||
} | ||
return `(${generateOutputType({ ...options, useStructs: true }, evmType.itemType)})[]`; | ||
} | ||
@@ -81,3 +103,8 @@ case 'boolean': | ||
case 'tuple': | ||
return generateOutputComplexType(evmType.components); | ||
if (options.useStructs) { | ||
if (evmType.structName) { | ||
return evmType.structName + common_1.STRUCT_OUTPUT_POSTFIX; | ||
} | ||
} | ||
return generateOutputComplexType(evmType.components, { ...options, useStructs: true }); | ||
case 'unknown': | ||
@@ -96,6 +123,6 @@ return 'any'; | ||
**/ | ||
function generateOutputComplexType(components) { | ||
const existingOutputComponents = lodash_1.compact([ | ||
generateOutputComplexTypeAsArray(components), | ||
generateOutputComplexTypesAsObject(components), | ||
function generateOutputComplexType(components, options) { | ||
const existingOutputComponents = (0, lodash_1.compact)([ | ||
generateOutputComplexTypeAsArray(components, options), | ||
generateOutputComplexTypesAsObject(components, options), | ||
]); | ||
@@ -105,11 +132,12 @@ return existingOutputComponents.join(' & '); | ||
exports.generateOutputComplexType = generateOutputComplexType; | ||
function generateOutputComplexTypeAsArray(components) { | ||
return `[${components.map((t) => generateOutputType(t.type)).join(', ')}]`; | ||
function generateOutputComplexTypeAsArray(components, options) { | ||
return `[${components.map((t) => generateOutputType(options, t.type)).join(', ')}]`; | ||
} | ||
exports.generateOutputComplexTypeAsArray = generateOutputComplexTypeAsArray; | ||
function generateOutputComplexTypesAsObject(components) { | ||
function generateOutputComplexTypesAsObject(components, options) { | ||
let namedElementsCode; | ||
const namedElements = components.filter((e) => !!e.name); | ||
if (namedElements.length > 0) { | ||
namedElementsCode = '{' + namedElements.map((t) => `${t.name}: ${generateOutputType(t.type)}`).join(',') + ' }'; | ||
namedElementsCode = | ||
'{' + namedElements.map((t) => `${t.name}: ${generateOutputType(options, t.type)}`).join(',') + ' }'; | ||
} | ||
@@ -116,0 +144,0 @@ return namedElementsCode; |
export declare const FACTORY_POSTFIX = "__factory"; | ||
export declare const STRUCT_INPUT_POSTFIX = "Struct"; | ||
export declare const STRUCT_OUTPUT_POSTFIX = "StructOutput"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FACTORY_POSTFIX = void 0; | ||
exports.STRUCT_OUTPUT_POSTFIX = exports.STRUCT_INPUT_POSTFIX = exports.FACTORY_POSTFIX = void 0; | ||
exports.FACTORY_POSTFIX = '__factory'; | ||
exports.STRUCT_INPUT_POSTFIX = 'Struct'; | ||
exports.STRUCT_OUTPUT_POSTFIX = 'StructOutput'; | ||
//# sourceMappingURL=common.js.map |
@@ -18,7 +18,7 @@ "use strict"; | ||
const { cwd, outDir, allFiles } = config; | ||
this.outDirAbs = path_1.resolve(cwd, outDir || DEFAULT_OUT_PATH); | ||
this.allContracts = allFiles.map((fp) => typechain_1.normalizeName(typechain_1.getFilename(fp))); | ||
this.outDirAbs = (0, path_1.resolve)(cwd, outDir || DEFAULT_OUT_PATH); | ||
this.allContracts = allFiles.map((fp) => (0, typechain_1.normalizeName)((0, typechain_1.getFilename)(fp))); | ||
} | ||
transformFile(file) { | ||
const fileExt = typechain_1.getFileExtension(file.path); | ||
const fileExt = (0, typechain_1.getFileExtension)(file.path); | ||
// For json files with both ABI and bytecode, both the contract typing and factory can be | ||
@@ -34,4 +34,4 @@ // generated at once. For split files (.abi and .bin) we don't know in which order they will | ||
transformBinFile(file) { | ||
const name = typechain_1.getFilename(file.path); | ||
const bytecode = typechain_1.extractBytecode(file.contents); | ||
const name = (0, typechain_1.getFilename)(file.path); | ||
const bytecode = (0, typechain_1.extractBytecode)(file.contents); | ||
if (!bytecode) { | ||
@@ -50,10 +50,10 @@ return; | ||
transformAbiOrFullJsonFile(file) { | ||
const name = typechain_1.getFilename(file.path); | ||
const abi = typechain_1.extractAbi(file.contents); | ||
const name = (0, typechain_1.getFilename)(file.path); | ||
const abi = (0, typechain_1.extractAbi)(file.contents); | ||
if (abi.length === 0) { | ||
return; | ||
} | ||
const documentation = typechain_1.extractDocumentation(file.contents); | ||
const contract = typechain_1.parse(abi, name, documentation); | ||
const bytecode = typechain_1.extractBytecode(file.contents) || this.bytecodeCache[name]; | ||
const documentation = (0, typechain_1.extractDocumentation)(file.contents); | ||
const contract = (0, typechain_1.parse)(abi, name, documentation); | ||
const bytecode = (0, typechain_1.extractBytecode)(file.contents) || this.bytecodeCache[name]; | ||
if (bytecode) { | ||
@@ -72,4 +72,4 @@ return [ | ||
return { | ||
path: path_1.join(this.outDirAbs, `${contract.name}.d.ts`), | ||
contents: codegen_1.codegenContractTypings(contract, codegenConfig), | ||
path: (0, path_1.join)(this.outDirAbs, `${contract.name}.ts`), | ||
contents: (0, codegen_1.codegenContractTypings)(contract, codegenConfig), | ||
}; | ||
@@ -79,4 +79,4 @@ } | ||
return { | ||
path: path_1.join(this.outDirAbs, 'factories', `${contract.name}${common_1.FACTORY_POSTFIX}.ts`), | ||
contents: codegen_1.codegenContractFactory(contract, abi, bytecode), | ||
path: (0, path_1.join)(this.outDirAbs, 'factories', `${contract.name}${common_1.FACTORY_POSTFIX}.ts`), | ||
contents: (0, codegen_1.codegenContractFactory)(contract, abi, bytecode), | ||
}; | ||
@@ -90,17 +90,17 @@ } | ||
return { | ||
path: path_1.join(this.outDirAbs, 'factories', `${contract.name}${common_1.FACTORY_POSTFIX}.ts`), | ||
contents: codegen_1.codegenAbstractContractFactory(contract, abi), | ||
path: (0, path_1.join)(this.outDirAbs, 'factories', `${contract.name}${common_1.FACTORY_POSTFIX}.ts`), | ||
contents: (0, codegen_1.codegenAbstractContractFactory)(contract, abi), | ||
}; | ||
}); | ||
const hardhatHelper = this.cfg.flags.environment === 'hardhat' | ||
? { path: path_1.join(this.outDirAbs, 'hardhat.d.ts'), contents: hardhat_1.generateHardhatHelper(this.allContracts) } | ||
? { path: (0, path_1.join)(this.outDirAbs, 'hardhat.d.ts'), contents: (0, hardhat_1.generateHardhatHelper)(this.allContracts) } | ||
: undefined; | ||
const allFiles = lodash_1.compact([ | ||
const allFiles = (0, lodash_1.compact)([ | ||
...abstractFactoryFiles, | ||
{ | ||
path: path_1.join(this.outDirAbs, 'common.d.ts'), | ||
contents: fs_1.readFileSync(path_1.join(__dirname, '../static/common.d.ts'), 'utf-8'), | ||
path: (0, path_1.join)(this.outDirAbs, 'common.ts'), | ||
contents: (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../static/common.ts'), 'utf-8'), | ||
}, | ||
{ | ||
path: path_1.join(this.outDirAbs, 'index.ts'), | ||
path: (0, path_1.join)(this.outDirAbs, 'index.ts'), | ||
contents: this.genReExports(), | ||
@@ -114,3 +114,3 @@ }, | ||
const codegen = []; | ||
const allContractsNoDuplicates = lodash_1.uniqBy(this.allContracts, (c) => path_1.basename(c)); | ||
const allContractsNoDuplicates = (0, lodash_1.uniqBy)(this.allContracts, (c) => (0, path_1.basename)(c)); | ||
for (const fileName of allContractsNoDuplicates) { | ||
@@ -117,0 +117,0 @@ const desiredSymbol = fileName; |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "7.2.0", | ||
"version": "8.0.0", | ||
"license": "MIT", | ||
@@ -36,3 +36,3 @@ "repository": "https://github.com/ethereum-ts/Typechain", | ||
"peerDependencies": { | ||
"typechain": "^5.0.0", | ||
"typechain": "^6.0.0", | ||
"typescript": ">=4.0.0", | ||
@@ -47,2 +47,3 @@ "ethers": "^5.1.3", | ||
"test-utils": "1.0.0", | ||
"ethers": "^5.1.3", | ||
"@types/lodash": "^4.14.139" | ||
@@ -49,0 +50,0 @@ }, |
@@ -27,3 +27,3 @@ # Typechain target Ethers-v5 | ||
The main files generated by this target are `<contract-name>.d.ts`. They declare typesafe interfaces for your contracts | ||
The main files generated by this target are `<contract-name>.ts`. They declare typesafe interfaces for your contracts | ||
on top of ethers `Contract` instances: | ||
@@ -30,0 +30,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72935
32
842
4