/
blockchain.ts
52 lines (41 loc) · 2.55 KB
/
blockchain.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
import * as path from "path";
import { CompilerOutput } from "solc";
import { EthersProvider } from "@augurproject/ethersjs-provider";
import { DeployerConfigurationOverwrite, CreateDeployerConfiguration, EthersFastSubmitWallet } from "@augurproject/core";
import { ContractAddresses } from "@augurproject/artifacts";
import { ContractDependenciesEthers } from "contract-dependencies-ethers";
import { ContractDependenciesGnosis } from "contract-dependencies-gnosis";
import { IGnosisRelayAPI } from '@augurproject/gnosis-relay-api';
import { ContractDeployer } from "@augurproject/core";
import { Account } from "../constants";
const augurCorePath = path.join(__dirname, "../../../augur-core/");
const root = path.join(augurCorePath, "../augur-artifacts/src");
const flashDeployerConfigurationDefaults: DeployerConfigurationOverwrite = {
contractInputPath: path.join(root, 'contracts.json'),
contractAddressesOutputPath: path.join(root, 'addresses.json'),
uploadBlockNumbersOutputPath: path.join(root, 'upload-block-numbers.json'),
};
export interface UsefulContractObjects {
provider: EthersProvider;
signer: EthersFastSubmitWallet;
dependencies: ContractDependenciesEthers;
addresses: ContractAddresses;
}
export async function deployContracts(provider: EthersProvider, accounts: Account[], compiledContracts: CompilerOutput, config: DeployerConfigurationOverwrite): Promise<UsefulContractObjects> {
config = Object.assign({}, flashDeployerConfigurationDefaults, config);
const deployerConfiguration = CreateDeployerConfiguration(config);
const signer = await makeSigner(accounts[0], provider);
const dependencies = makeDependencies(accounts[0], provider, signer);
const contractDeployer = new ContractDeployer(deployerConfiguration, dependencies, provider.provider, signer, compiledContracts);
const addresses = await contractDeployer.deploy();
return { provider, signer, dependencies, addresses };
}
export async function makeSigner(account: Account, provider: EthersProvider) {
return EthersFastSubmitWallet.create(account.secretKey, provider);
}
export function makeDependencies(account: Account, provider: EthersProvider, signer: EthersFastSubmitWallet) {
return new ContractDependenciesEthers(provider, signer, account.publicKey);
}
export function makeGnosisDependencies(provider: EthersProvider, gnosisRelay: IGnosisRelayAPI, signer: EthersFastSubmitWallet, gasToken?: string, gasPrice?: BigNumber, safeAddress?: string, address?: string) {
return new ContractDependenciesGnosis(provider, gnosisRelay, signer, gasToken, gasPrice, safeAddress, address);
}