@typechain/ethers-v5
Advanced tools
Comparing version 10.2.1 to 11.0.0
@@ -85,2 +85,3 @@ "use strict"; | ||
// generate a simplified factory, that allows to interact with deployed contract instances. | ||
const moduleSuffix = this.cfg.flags.node16Modules ? '.js' : ''; | ||
const abstractFactoryFiles = Object.keys(this.contractsWithoutBytecode).map((contractName) => { | ||
@@ -90,3 +91,3 @@ const { contract, abi } = this.contractsWithoutBytecode[contractName]; | ||
path: (0, path_1.join)(this.outDirAbs, 'factories', ...contract.path, `${contract.name}${common_1.FACTORY_POSTFIX}.ts`), | ||
contents: (0, codegen_1.codegenAbstractContractFactory)(contract, abi), | ||
contents: (0, codegen_1.codegenAbstractContractFactory)(contract, abi, moduleSuffix), | ||
}; | ||
@@ -102,4 +103,4 @@ }); | ||
: undefined; | ||
const typesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles, { typeOnly: true }); | ||
const factoriesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles.map((s) => `factories/${s}`), { typeOnly: false, postfix: common_1.FACTORY_POSTFIX }); | ||
const typesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles, { typeOnly: true, moduleSuffix }); | ||
const factoriesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles.map((s) => `factories/${s}`), { typeOnly: false, postfix: common_1.FACTORY_POSTFIX, moduleSuffix }); | ||
const allBarrels = typesBarrels.concat(factoriesBarrels); | ||
@@ -109,3 +110,3 @@ const [rootIndexes, otherBarrels] = (0, lodash_1.partition)(allBarrels, (fd) => fd.path === 'index.ts'); | ||
path: (0, path_1.join)(this.outDirAbs, 'index.ts'), | ||
contents: createRootIndexContent(rootIndexes, this.allFiles), | ||
contents: createRootIndexContent(rootIndexes, this.allFiles, moduleSuffix), | ||
}; | ||
@@ -127,3 +128,3 @@ const allFiles = (0, lodash_1.compact)([ | ||
// root index.ts reexports also from deeper paths | ||
function createRootIndexContent(rootIndexes, paths) { | ||
function createRootIndexContent(rootIndexes, paths, moduleSuffix = '') { | ||
const contracts = paths.map(typechain_1.parseContractPath); | ||
@@ -133,4 +134,4 @@ const rootReexports = (0, lodash_1.uniqBy)(Object.values(contracts), (c) => c.name).flatMap((c) => { | ||
return [ | ||
`export type { ${c.name} } from './${path}';`, | ||
`export { ${c.name}${common_1.FACTORY_POSTFIX} } from './factories/${path}${common_1.FACTORY_POSTFIX}';`, | ||
`export type { ${c.name} } from './${path}${moduleSuffix}';`, | ||
`export { ${c.name}${common_1.FACTORY_POSTFIX} } from './factories/${path}${common_1.FACTORY_POSTFIX}${moduleSuffix}';`, | ||
]; | ||
@@ -137,0 +138,0 @@ }); |
@@ -30,5 +30,3 @@ "use strict"; | ||
${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) | ||
? 'PayableOverrides & { from?: PromiseOrValue<string> }' | ||
: 'Overrides & { from?: PromiseOrValue<string> }'}` | ||
? `overrides?: ${isPayable(fn) ? 'PayableOverrides & { from?: string }' : 'Overrides & { from?: string }'}` | ||
: 'overrides?: CallOverrides'}): ${(_a = options.overrideOutput) !== null && _a !== void 0 ? _a : `Promise<${options.isStaticCall || fn.stateMutability === 'pure' || fn.stateMutability === 'view' | ||
@@ -35,0 +33,0 @@ ? (0, types_1.generateOutputTypes)({ returnResultObject: !!options.returnResultObject, useStructs: true }, fn.outputs) |
import { BytecodeWithLinkReferences, CodegenConfig, Contract } from 'typechain'; | ||
export declare function codegenContractTypings(contract: Contract, codegenConfig: CodegenConfig): string; | ||
export declare function codegenContractFactory(codegenConfig: CodegenConfig, contract: Contract, abi: any, bytecode?: BytecodeWithLinkReferences): string; | ||
export declare function codegenAbstractContractFactory(contract: Contract, abi: any): string; | ||
export declare function codegenAbstractContractFactory(contract: Contract, abi: any, moduleSuffix: string): string; |
@@ -90,5 +90,5 @@ "use strict"; | ||
}`; | ||
const commonPath = contract.path.length | ||
? `${new Array(contract.path.length).fill('..').join('/')}/common` | ||
: './common'; | ||
const moduleSuffix = codegenConfig.node16Modules ? '.js' : ''; | ||
const commonPath = (contract.path.length ? `${new Array(contract.path.length).fill('..').join('/')}/common` : './common') + | ||
moduleSuffix; | ||
const imports = (0, typechain_1.createImportsForUsedIdentifiers)({ | ||
@@ -110,3 +110,3 @@ 'type ethers': [ | ||
'type @ethersproject/providers': ['Listener', 'Provider'], | ||
[`type ${commonPath}`]: [...events_1.EVENT_IMPORTS, 'PromiseOrValue'], | ||
[`type ${commonPath}`]: [...events_1.EVENT_IMPORTS], | ||
}, source); | ||
@@ -118,6 +118,7 @@ return imports + source; | ||
var _a; | ||
const moduleSuffix = codegenConfig.node16Modules ? '.js' : ''; | ||
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' | ||
? 'PayableOverrides & { from?: PromiseOrValue<string> }' | ||
: 'Overrides & { from?: PromiseOrValue<string> }'}`; | ||
? 'PayableOverrides & { from?: string }' | ||
: 'Overrides & { from?: string }'}`; | ||
const constructorArgNamesWithoutOverrides = contract.constructor[0] | ||
@@ -130,5 +131,5 @@ ? (0, functions_1.generateParamNames)(contract.constructor[0].inputs) | ||
if (!bytecode) | ||
return codegenAbstractContractFactory(contract, abi); | ||
return codegenAbstractContractFactory(contract, abi, moduleSuffix); | ||
// tsc with noUnusedLocals would complain about unused imports | ||
const { body, header } = codegenCommonContractFactory(contract, abi); | ||
const { body, header } = codegenCommonContractFactory(contract, abi, moduleSuffix); | ||
const source = ` | ||
@@ -163,3 +164,2 @@ ${header} | ||
`; | ||
const commonPath = `${new Array(contract.path.length + 1).fill('..').join('/')}/common`; | ||
const imports = (0, typechain_1.createImportsForUsedIdentifiers)({ | ||
@@ -177,3 +177,2 @@ ethers: [ | ||
'type @ethersproject/providers': ['Provider', 'TransactionRequest'], | ||
[`type ${commonPath}`]: ['PromiseOrValue'], | ||
}, source); | ||
@@ -183,4 +182,4 @@ return imports + source; | ||
exports.codegenContractFactory = codegenContractFactory; | ||
function codegenAbstractContractFactory(contract, abi) { | ||
const { body, header } = codegenCommonContractFactory(contract, abi); | ||
function codegenAbstractContractFactory(contract, abi, moduleSuffix) { | ||
const { body, header } = codegenCommonContractFactory(contract, abi, moduleSuffix); | ||
return ` | ||
@@ -197,3 +196,3 @@ import { Contract, Signer, utils } from "ethers"; | ||
exports.codegenAbstractContractFactory = codegenAbstractContractFactory; | ||
function codegenCommonContractFactory(contract, abi) { | ||
function codegenCommonContractFactory(contract, abi, moduleSuffix) { | ||
var _a; | ||
@@ -207,3 +206,7 @@ const imports = new Set([contract.name, contract.name + 'Interface']); | ||
}); | ||
const contractTypesImportPath = [...Array(contract.path.length + 1).fill('..'), ...contract.path, contract.name].join('/'); | ||
const contractTypesImportPath = [ | ||
...Array(contract.path.length + 1).fill('..'), | ||
...contract.path, | ||
contract.name + moduleSuffix, | ||
].join('/'); | ||
const header = ` | ||
@@ -210,0 +213,0 @@ import type { ${[...imports.values()].join(', ')} } from "${contractTypesImportPath}"; |
@@ -28,16 +28,16 @@ "use strict"; | ||
case 'integer': | ||
return wrapInPromiseOrValue('BigNumberish'); | ||
return 'BigNumberish'; | ||
case 'uinteger': | ||
return wrapInPromiseOrValue('BigNumberish'); | ||
return 'BigNumberish'; | ||
case 'address': | ||
return wrapInPromiseOrValue('string'); | ||
return 'string'; | ||
case 'bytes': | ||
case 'dynamic-bytes': | ||
return wrapInPromiseOrValue('BytesLike'); | ||
return 'BytesLike'; | ||
case 'array': | ||
return generateArrayOrTupleType(generateInputType(options, evmType.itemType), evmType.size); | ||
case 'boolean': | ||
return wrapInPromiseOrValue('boolean'); | ||
return 'boolean'; | ||
case 'string': | ||
return wrapInPromiseOrValue('string'); | ||
return 'string'; | ||
case 'tuple': | ||
@@ -119,5 +119,2 @@ if (evmType.structName && options.useStructs) { | ||
} | ||
function wrapInPromiseOrValue(str) { | ||
return `PromiseOrValue<${str}>`; | ||
} | ||
//# sourceMappingURL=types.js.map |
@@ -85,2 +85,3 @@ "use strict"; | ||
// generate a simplified factory, that allows to interact with deployed contract instances. | ||
const moduleSuffix = this.cfg.flags.node16Modules ? '.js' : ''; | ||
const abstractFactoryFiles = Object.keys(this.contractsWithoutBytecode).map((contractName) => { | ||
@@ -90,3 +91,3 @@ const { contract, abi } = this.contractsWithoutBytecode[contractName]; | ||
path: (0, path_1.join)(this.outDirAbs, 'factories', ...contract.path, `${contract.name}${common_1.FACTORY_POSTFIX}.ts`), | ||
contents: (0, codegen_1.codegenAbstractContractFactory)(contract, abi), | ||
contents: (0, codegen_1.codegenAbstractContractFactory)(contract, abi, moduleSuffix), | ||
}; | ||
@@ -102,4 +103,4 @@ }); | ||
: undefined; | ||
const typesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles, { typeOnly: true }); | ||
const factoriesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles.map((s) => `factories/${s}`), { typeOnly: false, postfix: common_1.FACTORY_POSTFIX }); | ||
const typesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles, { typeOnly: true, moduleSuffix }); | ||
const factoriesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles.map((s) => `factories/${s}`), { typeOnly: false, postfix: common_1.FACTORY_POSTFIX, moduleSuffix }); | ||
const allBarrels = typesBarrels.concat(factoriesBarrels); | ||
@@ -109,3 +110,3 @@ const [rootIndexes, otherBarrels] = (0, lodash_1.partition)(allBarrels, (fd) => fd.path === 'index.ts'); | ||
path: (0, path_1.join)(this.outDirAbs, 'index.ts'), | ||
contents: createRootIndexContent(rootIndexes, this.allFiles), | ||
contents: createRootIndexContent(rootIndexes, this.allFiles, moduleSuffix), | ||
}; | ||
@@ -127,3 +128,3 @@ const allFiles = (0, lodash_1.compact)([ | ||
// root index.ts reexports also from deeper paths | ||
function createRootIndexContent(rootIndexes, paths) { | ||
function createRootIndexContent(rootIndexes, paths, moduleSuffix = '') { | ||
const contracts = paths.map(typechain_1.parseContractPath); | ||
@@ -133,4 +134,4 @@ const rootReexports = (0, lodash_1.uniqBy)(Object.values(contracts), (c) => c.name).flatMap((c) => { | ||
return [ | ||
`export type { ${c.name} } from './${path}';`, | ||
`export { ${c.name}${common_1.FACTORY_POSTFIX} } from './factories/${path}${common_1.FACTORY_POSTFIX}';`, | ||
`export type { ${c.name} } from './${path}${moduleSuffix}';`, | ||
`export { ${c.name}${common_1.FACTORY_POSTFIX} } from './factories/${path}${common_1.FACTORY_POSTFIX}${moduleSuffix}';`, | ||
]; | ||
@@ -137,0 +138,0 @@ }); |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "10.2.1", | ||
"version": "11.0.0", | ||
"license": "MIT", | ||
@@ -28,3 +28,3 @@ "repository": "https://github.com/ethereum-ts/Typechain", | ||
"ethers": "^5.1.3", | ||
"typechain": "^8.1.1", | ||
"typechain": "^8.2.0", | ||
"typescript": ">=4.3.0" | ||
@@ -39,3 +39,3 @@ }, | ||
"test-utils": "1.0.0", | ||
"typechain": "^8.1.1", | ||
"typechain": "^8.2.0", | ||
"typescript": ">=4.3.0", | ||
@@ -42,0 +42,0 @@ "@types/proxyquire": "^1.3.28", |
@@ -27,4 +27,4 @@ # Typechain target Ethers-v5 | ||
The main files generated by this target are `<contract-name>.ts`. They declare typesafe interfaces for your contracts | ||
on top of ethers `Contract` instances: | ||
The main files generated by this target are `<contract-name>.ts`. They declare typesafe interfaces for your contracts on | ||
top of ethers `Contract` instances: | ||
@@ -31,0 +31,0 @@ - typed contract's methods, available both at `contract.someMethod(...)` and `contract.functions.someMethod(...)` |
@@ -28,3 +28,1 @@ import type { Listener } from '@ethersproject/providers' | ||
export type GetARGsTypeFromFactory<F> = F extends MinEthersFactory<any, any> ? Parameters<F['deploy']> : never | ||
export type PromiseOrValue<T> = T | Promise<T> |
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
87653
1106