Add debug logging library (#457)

* Add debug logging library

* Lint
pull/461/head
Nam Chu Hoai 3 years ago committed by GitHub
parent c47d42aecd
commit d4c10e2542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      typescript/deploy/package.json
  2. 14
      typescript/deploy/src/deploy.ts
  3. 10
      typescript/deploy/src/router/deploy.ts
  4. 20
      yarn.lock

@ -1,6 +1,7 @@
{
"devDependencies": {
"@typechain/ethers-v5": "~7.0.0",
"@types/debug": "^4.1.7",
"ethers": "^5.4.7",
"prettier": "^2.3.1",
"ts-node": "^10.1.0",
@ -25,6 +26,7 @@
"@types/node": "^16.9.1",
"@types/yargs": "^17.0.10",
"axios": "^0.21.3",
"debug": "^4.3.4",
"yargs": "^17.4.1"
}
}

@ -1,3 +1,4 @@
import { Debugger, debug } from 'debug';
import { ethers } from 'ethers';
import fs from 'fs';
import path from 'path';
@ -20,25 +21,33 @@ import {
getContractVerificationInput,
} from './verify';
export interface DeployerOptions {
logger?: Debugger;
}
// TODO: Make AppDeployer generic on AbacusApp and return instance from deploy()
export abstract class AbacusAppDeployer<Chain extends ChainName, C, A> {
verificationInputs: ChainMap<Chain, ContractVerificationInput[]>;
protected logger: Debugger;
constructor(
protected readonly multiProvider: MultiProvider<Chain>,
protected readonly configMap: ChainMap<Chain, C>,
protected readonly options?: DeployerOptions,
) {
this.verificationInputs = objMap(configMap, () => []);
this.logger = options?.logger || debug('abacus:AppDeployer');
}
abstract deployContracts(chain: Chain, config: C): Promise<A>;
async deploy() {
this.logger('Start Deploy');
this.verificationInputs = objMap(this.configMap, () => []);
const chains = Object.keys(this.configMap) as Chain[];
const chains = this.multiProvider.chains();
const entries: [Chain, A][] = [];
for (const chain of chains) {
console.log(`Deploying to ${chain}...`);
this.logger(`Deploying to ${chain}...`);
const result = await this.deployContracts(chain, this.configMap[chain]);
entries.push([chain, result]);
}
@ -51,6 +60,7 @@ export abstract class AbacusAppDeployer<Chain extends ChainName, C, A> {
factory: F,
args: Parameters<F['deploy']>,
): Promise<ReturnType<F['deploy']>> {
this.logger(`Deploy ${contractName} on ${chain}`);
const chainConnection = this.multiProvider.getChainConnection(chain);
const contract = await factory.deploy(...args, chainConnection.overrides);
await contract.deployTransaction.wait(chainConnection.confirmations);

@ -1,3 +1,5 @@
import { debug } from 'debug';
import {
AbacusConnectionManager,
AbacusConnectionManager__factory,
@ -13,7 +15,7 @@ import {
} from '@abacus-network/sdk';
import { utils } from '@abacus-network/utils';
import { AbacusAppDeployer } from '../deploy';
import { AbacusAppDeployer, DeployerOptions } from '../deploy';
import { Router, RouterConfig } from './types';
@ -30,14 +32,17 @@ export abstract class AbacusRouterDeployer<
multiProvider: MultiProvider<Chain>,
configMap: ChainMap<Chain, Config>,
core?: AbacusCore<Chain>,
options?: DeployerOptions,
) {
super(multiProvider, configMap);
const logger = options?.logger || debug('abacus:RouterDeployer');
super(multiProvider, configMap, { ...options, logger });
this.core = core;
}
async deploy() {
const deploymentOutput = await super.deploy();
this.logger(`Enroll Routers with each other`);
// Make all routers aware of eachother.
await promiseObjAll(
objMap(deploymentOutput, async (local, addresses) => {
@ -47,6 +52,7 @@ export abstract class AbacusRouterDeployer<
remote,
deploymentOutput[remote],
);
this.logger(`Enroll ${remote}'s router on ${local}`);
await localRouter.enrollRemoteRouter(
chainMetadata[remote].id,
utils.addressToBytes32(remoteRouter.address),

@ -105,9 +105,11 @@ __metadata:
"@abacus-network/sdk": ^0.1.1
"@abacus-network/utils": ^0.1.1
"@typechain/ethers-v5": ~7.0.0
"@types/debug": ^4.1.7
"@types/node": ^16.9.1
"@types/yargs": ^17.0.10
axios: ^0.21.3
debug: ^4.3.4
ethers: ^5.4.7
prettier: ^2.3.1
ts-node: ^10.1.0
@ -3478,6 +3480,15 @@ __metadata:
languageName: node
linkType: hard
"@types/debug@npm:^4.1.7":
version: 4.1.7
resolution: "@types/debug@npm:4.1.7"
dependencies:
"@types/ms": "*"
checksum: 0a7b89d8ed72526858f0b61c6fd81f477853e8c4415bb97f48b1b5545248d2ae389931680b94b393b993a7cfe893537a200647d93defe6d87159b96812305adc
languageName: node
linkType: hard
"@types/form-data@npm:0.0.33":
version: 0.0.33
resolution: "@types/form-data@npm:0.0.33"
@ -3561,6 +3572,13 @@ __metadata:
languageName: node
linkType: hard
"@types/ms@npm:*":
version: 0.7.31
resolution: "@types/ms@npm:0.7.31"
checksum: daadd354aedde024cce6f5aa873fefe7b71b22cd0e28632a69e8b677aeb48ae8caa1c60e5919bb781df040d116b01cb4316335167a3fc0ef6a63fa3614c0f6da
languageName: node
linkType: hard
"@types/node-fetch@npm:^2.5.5":
version: 2.6.1
resolution: "@types/node-fetch@npm:2.6.1"
@ -6320,7 +6338,7 @@ __metadata:
languageName: node
linkType: hard
"debug@npm:4, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.3":
"debug@npm:4, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.3, debug@npm:^4.3.4":
version: 4.3.4
resolution: "debug@npm:4.3.4"
dependencies:

Loading…
Cancel
Save