-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.ts
75 lines (61 loc) · 2.45 KB
/
helpers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { HardhatEthersHelpers } from "@nomiclabs/hardhat-ethers/types";
import { Contract, ContractFactory } from "ethers";
import {
readAddressList,
readAggregatePoolList,
readArgs,
readSeparatePoolList,
storeAddressList,
storeAggregatePoolList,
storeArgs,
storeSeparatePoolList,
} from "../scripts/contractAddress";
export const getNetwork = () => {
const hre = require("hardhat");
const { network } = hre;
const _network = network.name == "hardhat" ? "localhost" : network.name;
return _network;
};
/********************************* Store addresses & args *************************************/
export const writeDeployment = (network: string, name: string, _address: string, _args: Array<any>) => {
const addressList = readAddressList();
addressList[network][name] = _address;
storeAddressList(addressList);
const argsList = readArgs();
argsList[network][name] = { address: _address, args: _args };
storeArgs(argsList);
};
export const writeSeparatePool = (network: string, _name: string, _address: string, _args: Array<any>) => {
const spList = readSeparatePoolList();
spList[network].push({ name: _name, address: _address });
storeSeparatePoolList(spList);
const argsList = readArgs();
const finalName = _name + " Separate Pool";
argsList[network][finalName] = { address: _address, args: _args };
storeArgs(argsList);
};
export const writeAggregatePool = (
network: string,
_name: string,
_symbol: string,
_address: string,
_args: Array<any>,
) => {
const apList = readAggregatePoolList();
apList[network].push({ name: _name, symbol: _symbol, address: _address });
storeAggregatePoolList(apList);
const argsList = readArgs();
const finalName = _name + " Aggregate Pool";
argsList[network][finalName] = { address: _address, args: _args };
storeArgs(argsList);
};
/**************************************** Deployment ****************************************/
export const deploy = async (ethers: HardhatEthersHelpers, artifact: string, params: Array<any>) => {
const signers: SignerWithAddress[] = await ethers.getSigners();
const factory: ContractFactory = <ContractFactory>await ethers.getContractFactory(artifact);
let contract: Contract;
if (params.length > 0) contract = await factory.connect(signers[0]).deploy(...params);
else contract = await factory.connect(signers[0]).deploy();
return await contract.deployed();
};