@@ -21,67 +21,14 @@ import {
21
21
TestPoolCollection__factory ,
22
22
TestReserveToken__factory ,
23
23
TestSafeERC20Ex__factory ,
24
- TestSystemToken__factory ,
25
24
TestUpgradeable__factory ,
26
25
TokenHolder__factory ,
27
- TestTokenGovernance__factory ,
28
26
TransparentUpgradeableProxy__factory
29
27
} from '../typechain' ;
28
+ import { deployOrAttach } from './ContractBuilder' ;
30
29
31
30
/* eslint-enable camelcase */
32
31
import { Signer } from '@ethersproject/abstract-signer' ;
33
- import { ContractFactory } from '@ethersproject/contracts' ;
34
- import { ethers } from 'hardhat' ;
35
-
36
- type AsyncReturnType < T extends ( ...args : any ) => any > = T extends ( ...args : any ) => Promise < infer U >
37
- ? U
38
- : T extends ( ...args : any ) => infer U
39
- ? U
40
- : any ;
41
-
42
- export type Contract < F extends ContractFactory > = AsyncReturnType < F [ 'deploy' ] > ;
43
-
44
- export interface ContractBuilder < F extends ContractFactory > {
45
- metadata : {
46
- contractName : string ;
47
- abi : unknown ;
48
- bytecode : string ;
49
- } ;
50
- deploy ( ...args : Parameters < F [ 'deploy' ] > ) : Promise < Contract < F > > ;
51
- attach ( address : string , signer ?: Signer ) : Promise < Contract < F > > ;
52
- }
53
-
54
- type FactoryConstructor < F extends ContractFactory > = { new ( signer ?: Signer ) : F ; abi : unknown ; bytecode : string } ;
55
- const deployOrAttach = < F extends ContractFactory > (
56
- contractName : string ,
57
- // @TODO : needs to replace with correctly typed params but it doesn't
58
- // work properly for some reason https://github.com/microsoft/TypeScript/issues/31278
59
- FactoryConstructor : FactoryConstructor < F > ,
60
- initialSigner ?: Signer
61
- ) : ContractBuilder < F > => {
62
- return {
63
- metadata : {
64
- contractName : contractName ,
65
- abi : FactoryConstructor . abi ,
66
- bytecode : FactoryConstructor . bytecode
67
- } ,
68
- deploy : async ( ...args : Parameters < F [ 'deploy' ] > ) : Promise < Contract < F > > => {
69
- const defaultSigner = initialSigner || ( await ethers . getSigners ( ) ) [ 0 ] ;
70
-
71
- return new FactoryConstructor ( defaultSigner ) . deploy ( ...( args || [ ] ) ) as Contract < F > ;
72
- } ,
73
- attach : attachOnly < F > ( FactoryConstructor , initialSigner ) . attach
74
- } ;
75
- } ;
76
-
77
- const attachOnly = < F extends ContractFactory > ( FactoryConstructor : FactoryConstructor < F > , initialSigner ?: Signer ) => {
78
- return {
79
- attach : async ( address : string , signer ?: Signer ) : Promise < Contract < F > > => {
80
- const defaultSigner = initialSigner || ( await ethers . getSigners ( ) ) [ 0 ] ;
81
- return new FactoryConstructor ( signer || defaultSigner ) . attach ( address ) as Contract < F > ;
82
- }
83
- } ;
84
- } ;
85
32
86
33
const getContracts = ( signer ?: Signer ) => ( {
87
34
connect : ( signer : Signer ) => getContracts ( signer ) ,
@@ -107,17 +54,13 @@ const getContracts = (signer?: Signer) => ({
107
54
TestPendingWithdrawals : deployOrAttach ( 'TestPendingWithdrawals' , TestPendingWithdrawals__factory , signer ) ,
108
55
TestReserveToken : deployOrAttach ( 'TestReserveToken' , TestReserveToken__factory , signer ) ,
109
56
TestSafeERC20Ex : deployOrAttach ( 'TestSafeERC20Ex' , TestSafeERC20Ex__factory , signer ) ,
110
- TestSystemToken : deployOrAttach ( 'TestSystemToken' , TestSystemToken__factory , signer ) ,
111
57
TestUpgradeable : deployOrAttach ( 'TestUpgradeable' , TestUpgradeable__factory , signer ) ,
112
- TestTokenGovernance : deployOrAttach ( 'TestTokenGovernance' , TestTokenGovernance__factory , signer ) ,
113
58
TokenHolder : deployOrAttach ( 'TokenHolder' , TokenHolder__factory , signer ) ,
114
59
TransparentUpgradeableProxy : deployOrAttach (
115
60
'TransparentUpgradeableProxy' ,
116
61
TransparentUpgradeableProxy__factory ,
117
62
signer
118
63
)
119
-
120
- /* eslint-enable camelcase */
121
64
} ) ;
122
65
123
66
export type ContractsType = ReturnType < typeof getContracts > ;
0 commit comments