Skip to content

Commit 183b276

Browse files
authored
Merge pull request #83 from bancorprotocol/legacy_contracts
2 parents 44e505b + a79ecf5 commit 183b276

20 files changed

+246
-201
lines changed

packages/v2/components/Contracts.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { ethers } from 'hardhat';
2-
import { Contract as OldContract, ContractFactory, Overrides as OldOverrides } from '@ethersproject/contracts';
31
import { Signer } from '@ethersproject/abstract-signer';
4-
2+
import { Contract as OldContract, ContractFactory, Overrides as OldOverrides } from '@ethersproject/contracts';
3+
import { ethers } from 'hardhat';
54
import {
65
BancorNetwork__factory,
76
BancorX__factory,

packages/v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"hardhat": "2.6.4"
4040
},
4141
"devDependencies": {
42-
"@bancor/token-governance": "bancorprotocol/token-governance",
42+
"@bancor/token-governance": "^0.1.4",
4343
"@ethersproject/hardware-wallets": "^5.4.0",
4444
"@nomiclabs/hardhat-ethers": "^2.0.2",
4545
"@nomiclabs/hardhat-etherscan": "^2.1.6",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* eslint-enable camelcase */
2+
import { Signer } from '@ethersproject/abstract-signer';
3+
import { ContractFactory } from '@ethersproject/contracts';
4+
import { ethers } from 'hardhat';
5+
6+
type AsyncReturnType<T extends (...args: any) => any> = T extends (...args: any) => Promise<infer U>
7+
? U
8+
: T extends (...args: any) => infer U
9+
? U
10+
: any;
11+
12+
export type Contract<F extends ContractFactory> = AsyncReturnType<F['deploy']>;
13+
14+
export interface ContractBuilder<F extends ContractFactory> {
15+
metadata: {
16+
contractName: string;
17+
abi: unknown;
18+
bytecode: string;
19+
};
20+
deploy(...args: Parameters<F['deploy']>): Promise<Contract<F>>;
21+
attach(address: string, signer?: Signer): Promise<Contract<F>>;
22+
}
23+
24+
export type FactoryConstructor<F extends ContractFactory> = {
25+
new (signer?: Signer): F;
26+
abi: unknown;
27+
bytecode: string;
28+
};
29+
30+
export const deployOrAttach = <F extends ContractFactory>(
31+
contractName: string,
32+
// @TODO: needs to replace with correctly typed params but it doesn't
33+
// work properly for some reason https://github.com/microsoft/TypeScript/issues/31278
34+
FactoryConstructor: FactoryConstructor<F>,
35+
initialSigner?: Signer
36+
): ContractBuilder<F> => {
37+
return {
38+
metadata: {
39+
contractName: contractName,
40+
abi: FactoryConstructor.abi,
41+
bytecode: FactoryConstructor.bytecode
42+
},
43+
deploy: async (...args: Parameters<F['deploy']>): Promise<Contract<F>> => {
44+
const defaultSigner = initialSigner || (await ethers.getSigners())[0];
45+
46+
return new FactoryConstructor(defaultSigner).deploy(...(args || [])) as Contract<F>;
47+
},
48+
attach: attachOnly<F>(FactoryConstructor, initialSigner).attach
49+
};
50+
};
51+
52+
export const attachOnly = <F extends ContractFactory>(
53+
FactoryConstructor: FactoryConstructor<F>,
54+
initialSigner?: Signer
55+
) => {
56+
return {
57+
attach: async (address: string, signer?: Signer): Promise<Contract<F>> => {
58+
const defaultSigner = initialSigner || (await ethers.getSigners())[0];
59+
return new FactoryConstructor(signer || defaultSigner).attach(address) as Contract<F>;
60+
}
61+
};
62+
};

packages/v3/components/Contracts.ts

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,67 +21,14 @@ import {
2121
TestPoolCollection__factory,
2222
TestReserveToken__factory,
2323
TestSafeERC20Ex__factory,
24-
TestSystemToken__factory,
2524
TestUpgradeable__factory,
2625
TokenHolder__factory,
27-
TestTokenGovernance__factory,
2826
TransparentUpgradeableProxy__factory
2927
} from '../typechain';
28+
import { deployOrAttach } from './ContractBuilder';
3029

3130
/* eslint-enable camelcase */
3231
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-
};
8532

8633
const getContracts = (signer?: Signer) => ({
8734
connect: (signer: Signer) => getContracts(signer),
@@ -107,17 +54,13 @@ const getContracts = (signer?: Signer) => ({
10754
TestPendingWithdrawals: deployOrAttach('TestPendingWithdrawals', TestPendingWithdrawals__factory, signer),
10855
TestReserveToken: deployOrAttach('TestReserveToken', TestReserveToken__factory, signer),
10956
TestSafeERC20Ex: deployOrAttach('TestSafeERC20Ex', TestSafeERC20Ex__factory, signer),
110-
TestSystemToken: deployOrAttach('TestSystemToken', TestSystemToken__factory, signer),
11157
TestUpgradeable: deployOrAttach('TestUpgradeable', TestUpgradeable__factory, signer),
112-
TestTokenGovernance: deployOrAttach('TestTokenGovernance', TestTokenGovernance__factory, signer),
11358
TokenHolder: deployOrAttach('TokenHolder', TokenHolder__factory, signer),
11459
TransparentUpgradeableProxy: deployOrAttach(
11560
'TransparentUpgradeableProxy',
11661
TransparentUpgradeableProxy__factory,
11762
signer
11863
)
119-
120-
/* eslint-enable camelcase */
12164
});
12265

12366
export type ContractsType = ReturnType<typeof getContracts>;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable camelcase */
2+
import { deployOrAttach } from './ContractBuilder';
3+
import {
4+
TokenGovernance__factory,
5+
SmartToken__factory as NetworkToken__factory,
6+
SmartToken as NetworkToken,
7+
DSToken__factory as GovToken__factory,
8+
DSToken as GovToken
9+
} from '@bancor/token-governance';
10+
import { Signer } from '@ethersproject/abstract-signer';
11+
12+
export { NetworkToken, GovToken };
13+
14+
/* eslint-enable camelcase */
15+
16+
const getContracts = (signer?: Signer) => ({
17+
connect: (signer: Signer) => getContracts(signer),
18+
19+
TokenGovernance: deployOrAttach('TokenGovernance', TokenGovernance__factory, signer),
20+
NetworkToken: deployOrAttach('BNTToken', NetworkToken__factory, signer),
21+
GovToken: deployOrAttach('vBNTToken', GovToken__factory, signer)
22+
});
23+
24+
export type ContractsType = ReturnType<typeof getContracts>;
25+
26+
export default getContracts();

packages/v3/contracts/helpers/TestSystemToken.sol

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/v3/contracts/helpers/TestTokenGovernance.sol

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/v3/contracts/token/interfaces/IReserveToken.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity 0.7.6;
55
* @dev This contract is used to represent reserve tokens, which are tokens that can either be regular ERC20 tokens or
66
* native ETH (represented by the NATIVE_TOKEN_ADDRESS address)
77
*
8-
* Please note that this interface is intentionally doesn't inherit from IERC20, so that it'd be possible to effectively
8+
* Please note that this interface intentionally doesn't inherit from IERC20, so that it'd be possible to effectively
99
* override its balanceOf() function in the ReserveToken library
1010
*/
1111
interface IReserveToken {

packages/v3/migration/engine/Execution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ContractBuilder, Contract } from '../../components/Contracts';
1+
import { ContractBuilder, Contract } from '../../components/ContractBuilder';
22
import { ProxyAdmin } from '../../typechain';
33
import { Engine } from './Engine';
44
import { log } from './Logger';

packages/v3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"hardhat": "2.6.4"
4343
},
4444
"devDependencies": {
45-
"@bancor/token-governance/0.7.6": "bancorprotocol/token-governance#solc-0.7.6",
45+
"@bancor/token-governance": "^0.1.4",
4646
"@ethersproject/hardware-wallets": "^5.4.0",
4747
"@nomiclabs/hardhat-ethers": "^2.0.2",
4848
"@nomiclabs/hardhat-etherscan": "^2.1.6",

0 commit comments

Comments
 (0)