@@ -21,89 +21,48 @@ import {
21
21
TestPoolCollection__factory ,
22
22
TestReserveToken__factory ,
23
23
TestSafeERC20Ex__factory ,
24
- TestSystemToken__factory ,
25
- TestTokenGovernance__factory ,
26
24
TestUpgradeable__factory ,
27
25
TokenHolder__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
- contractName : string ;
46
- deploy ( ...args : Parameters < F [ 'deploy' ] > ) : Promise < Contract < F > > ;
47
- attach ( address : string , passedSigner ?: Signer ) : Promise < Contract < F > > ;
48
- }
49
-
50
- const deployOrAttach = < F extends ContractFactory > ( contractName : string , passedSigner ?: Signer ) : ContractBuilder < F > => {
51
- return {
52
- contractName,
53
- deploy : async ( ...args : Parameters < F [ 'deploy' ] > ) : Promise < Contract < F > > => {
54
- const defaultSigner = passedSigner || ( await ethers . getSigners ( ) ) [ 0 ] ;
55
-
56
- return ( await ethers . getContractFactory ( contractName , defaultSigner ) ) . deploy (
57
- ...( args || [ ] )
58
- ) as Contract < F > ;
59
- } ,
60
- attach : attachOnly < F > ( contractName ) . attach
61
- } ;
62
- } ;
63
-
64
- const attachOnly = < F extends ContractFactory > ( contractName : string , passedSigner ?: Signer ) => {
65
- return {
66
- attach : async ( address : string , signer ?: Signer ) : Promise < Contract < F > > => {
67
- const defaultSigner = passedSigner || ( await ethers . getSigners ( ) ) [ 0 ] ;
68
- return ethers . getContractAt ( contractName , address , signer || defaultSigner ) as Contract < F > ;
69
- }
70
- } ;
71
- } ;
72
32
73
33
const getContracts = ( signer ?: Signer ) => ( {
74
34
connect : ( signer : Signer ) => getContracts ( signer ) ,
75
35
76
- /* eslint-disable camelcase */
77
- BancorNetwork : deployOrAttach < BancorNetwork__factory > ( 'BancorNetwork' , signer ) ,
78
- BancorVault : deployOrAttach < BancorVault__factory > ( 'BancorVault' , signer ) ,
79
- ERC20 : deployOrAttach < ERC20__factory > ( 'ERC20' , signer ) ,
80
- PoolCollection : deployOrAttach < PoolCollection__factory > ( 'PoolCollection' , signer ) ,
81
- NetworkSettings : deployOrAttach < NetworkSettings__factory > ( 'NetworkSettings' , signer ) ,
82
- NetworkTokenPool : deployOrAttach < NetworkTokenPool__factory > ( 'NetworkTokenPool' , signer ) ,
83
- PendingWithdrawals : deployOrAttach < PendingWithdrawals__factory > ( 'PendingWithdrawals' , signer ) ,
84
- PoolToken : deployOrAttach < PoolToken__factory > ( 'PoolToken' , signer ) ,
85
- PoolTokenFactory : deployOrAttach < PoolTokenFactory__factory > ( 'PoolTokenFactory' , signer ) ,
86
- ProxyAdmin : deployOrAttach < ProxyAdmin__factory > ( 'ProxyAdmin' , signer ) ,
87
- TestBancorNetwork : deployOrAttach < TestBancorNetwork__factory > ( 'TestBancorNetwork' , signer ) ,
88
- TestERC20Token : deployOrAttach < TestERC20Token__factory > ( 'TestERC20Token' , signer ) ,
89
- TestERC20Burnable : deployOrAttach < TestERC20Burnable__factory > ( 'TestERC20Burnable' , signer ) ,
90
- TestPoolAverageRate : deployOrAttach < TestPoolAverageRate__factory > ( 'TestPoolAverageRate' , signer ) ,
91
- TestPoolCollection : deployOrAttach < TestPoolCollection__factory > ( 'TestPoolCollection' , signer ) ,
92
- TestNetworkTokenPool : deployOrAttach < TestNetworkTokenPool__factory > ( 'TestNetworkTokenPool' , signer ) ,
93
- TestMathEx : deployOrAttach < TestMathEx__factory > ( 'TestMathEx' , signer ) ,
94
- TestOwned : deployOrAttach < TestOwned__factory > ( 'TestOwned' , signer ) ,
95
- TestPendingWithdrawals : deployOrAttach < TestPendingWithdrawals__factory > ( 'TestPendingWithdrawals' , signer ) ,
96
- TestReserveToken : deployOrAttach < TestReserveToken__factory > ( 'TestReserveToken' , signer ) ,
97
- TestSafeERC20Ex : deployOrAttach < TestSafeERC20Ex__factory > ( 'TestSafeERC20Ex' , signer ) ,
98
- TestSystemToken : deployOrAttach < TestSystemToken__factory > ( 'TestSystemToken' , signer ) ,
99
- TestTokenGovernance : deployOrAttach < TestTokenGovernance__factory > ( 'TestTokenGovernance' , signer ) ,
100
- TestUpgradeable : deployOrAttach < TestUpgradeable__factory > ( 'TestUpgradeable' , signer ) ,
101
- TokenHolder : deployOrAttach < TokenHolder__factory > ( 'TokenHolder' , signer ) ,
102
- TransparentUpgradeableProxy : deployOrAttach < TransparentUpgradeableProxy__factory > (
36
+ BancorNetwork : deployOrAttach ( 'BancorNetwork' , BancorNetwork__factory , signer ) ,
37
+ BancorVault : deployOrAttach ( 'BancorVault' , BancorVault__factory , signer ) ,
38
+ ERC20 : deployOrAttach ( 'ERC20' , ERC20__factory , signer ) ,
39
+ PoolCollection : deployOrAttach ( 'PoolCollection' , PoolCollection__factory , signer ) ,
40
+ NetworkSettings : deployOrAttach ( 'NetworkSettings' , NetworkSettings__factory , signer ) ,
41
+ NetworkTokenPool : deployOrAttach ( 'NetworkTokenPool' , NetworkTokenPool__factory , signer ) ,
42
+ PendingWithdrawals : deployOrAttach ( 'PendingWithdrawals' , PendingWithdrawals__factory , signer ) ,
43
+ PoolToken : deployOrAttach ( 'PoolToken' , PoolToken__factory , signer ) ,
44
+ PoolTokenFactory : deployOrAttach ( 'PoolTokenFactory' , PoolTokenFactory__factory , signer ) ,
45
+ ProxyAdmin : deployOrAttach ( 'ProxyAdmin' , ProxyAdmin__factory , signer ) ,
46
+ TestBancorNetwork : deployOrAttach ( 'TestBancorNetwork' , TestBancorNetwork__factory , signer ) ,
47
+ TestERC20Token : deployOrAttach ( 'TestERC20Token' , TestERC20Token__factory , signer ) ,
48
+ TestERC20Burnable : deployOrAttach ( 'TestERC20Burnable' , TestERC20Burnable__factory , signer ) ,
49
+ TestPoolAverageRate : deployOrAttach ( 'TestPoolAverageRate' , TestPoolAverageRate__factory , signer ) ,
50
+ TestPoolCollection : deployOrAttach ( 'TestPoolCollection' , TestPoolCollection__factory , signer ) ,
51
+ TestNetworkTokenPool : deployOrAttach ( 'TestNetworkTokenPool' , TestNetworkTokenPool__factory , signer ) ,
52
+ TestMathEx : deployOrAttach ( 'TestMathEx' , TestMathEx__factory , signer ) ,
53
+ TestOwned : deployOrAttach ( 'TestOwned' , TestOwned__factory , signer ) ,
54
+ TestPendingWithdrawals : deployOrAttach ( 'TestPendingWithdrawals' , TestPendingWithdrawals__factory , signer ) ,
55
+ TestReserveToken : deployOrAttach ( 'TestReserveToken' , TestReserveToken__factory , signer ) ,
56
+ TestSafeERC20Ex : deployOrAttach ( 'TestSafeERC20Ex' , TestSafeERC20Ex__factory , signer ) ,
57
+ TestUpgradeable : deployOrAttach ( 'TestUpgradeable' , TestUpgradeable__factory , signer ) ,
58
+ TokenHolder : deployOrAttach ( 'TokenHolder' , TokenHolder__factory , signer ) ,
59
+ TransparentUpgradeableProxy : deployOrAttach (
103
60
'TransparentUpgradeableProxy' ,
61
+ TransparentUpgradeableProxy__factory ,
104
62
signer
105
63
)
106
- /* eslint-enable camelcase */
107
64
} ) ;
108
65
66
+ export type ContractsType = ReturnType < typeof getContracts > ;
67
+
109
68
export default getContracts ( ) ;
0 commit comments