Add hardhat task to abacus-deploy (#211)

pull/233/head
Asa Oines 3 years ago committed by GitHub
parent 4d0a7793eb
commit 7eb7e54184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 78
      package-lock.json
  2. 24
      typescript/abacus-deploy/config/environments/local/chains.ts
  3. 13
      typescript/abacus-deploy/config/environments/local/core.ts
  4. 97
      typescript/abacus-deploy/hardhat.config.ts
  5. 7
      typescript/abacus-deploy/package.json
  6. 31
      typescript/abacus-deploy/scripts/utils.ts
  7. 18
      typescript/abacus-deploy/src/bridge/BridgeContracts.ts
  8. 24
      typescript/abacus-deploy/src/bridge/BridgeDeploy.ts
  9. 10
      typescript/abacus-deploy/src/common/BeaconProxy.ts
  10. 51
      typescript/abacus-deploy/src/common/CommonDeploy.ts
  11. 19
      typescript/abacus-deploy/src/core/CoreContracts.ts
  12. 23
      typescript/abacus-deploy/src/core/CoreDeploy.ts
  13. 11
      typescript/abacus-deploy/src/core/implementation.ts
  14. 8
      typescript/abacus-deploy/src/governance/GovernanceContracts.ts
  15. 21
      typescript/abacus-deploy/src/governance/GovernanceDeploy.ts
  16. 4
      typescript/abacus-deploy/src/utils/utils.ts
  17. 3
      typescript/abacus-deploy/test/bridge.test.ts
  18. 3
      typescript/abacus-deploy/test/core.test.ts
  19. 3
      typescript/abacus-deploy/test/governance.test.ts

78
package-lock.json generated

@ -16,10 +16,6 @@
"typescript/abacus-deploy"
]
},
"node_modules/@abacus-network/abacus-deploy": {
"resolved": "typescript/abacus-deploy",
"link": true
},
"node_modules/@abacus-network/abacus-sol": {
"resolved": "solidity/abacus-core",
"link": true
@ -32,6 +28,10 @@
"resolved": "typescript/contract-metrics",
"link": true
},
"node_modules/@abacus-network/deploy": {
"resolved": "typescript/abacus-deploy",
"link": true
},
"node_modules/@abacus-network/hardhat": {
"resolved": "typescript/hardhat",
"link": true
@ -24807,7 +24807,7 @@
}
},
"typescript/abacus-deploy": {
"name": "@abacus-network/abacus-deploy",
"name": "@abacus-network/deploy",
"version": "0.0.5",
"license": "MIT OR Apache-2.0",
"dependencies": {
@ -24994,40 +24994,6 @@
}
},
"dependencies": {
"@abacus-network/abacus-deploy": {
"version": "file:typescript/abacus-deploy",
"requires": {
"@abacus-network/sdk": "^0.0.1",
"@abacus-network/ts-interface": "^0.0.1",
"@aws-sdk/client-kms": "3.48.0",
"@ethersproject/experimental": "^5.3.0",
"@nomiclabs/hardhat-ethers": "^2.0.5",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"@typechain/ethers-v5": "~7.0.0",
"@typechain/hardhat": "^2.0.1",
"@types/chai": "^4.2.21",
"@types/mocha": "^9.1.0",
"@types/node": "^16.9.1",
"@types/yargs": "^17.0.8",
"asn1.js": "5.4.1",
"axios": "^0.21.3",
"chai": "^4.3.4",
"dotenv": "^10.0.0",
"ethereum-waffle": "^3.2.2",
"ethers": "^5.4.7",
"hardhat": "^2.8.4",
"prettier": "^2.3.1",
"ts-node": "^10.1.0",
"typechain": "^5.0.0",
"typescript": "^4.3.2",
"yargs": "^17.3.1"
},
"dependencies": {
"@types/node": {
"version": "16.11.26"
}
}
},
"@abacus-network/abacus-sol": {
"version": "file:solidity/abacus-core",
"requires": {
@ -25127,6 +25093,40 @@
}
}
},
"@abacus-network/deploy": {
"version": "file:typescript/abacus-deploy",
"requires": {
"@abacus-network/sdk": "^0.0.1",
"@abacus-network/ts-interface": "^0.0.1",
"@aws-sdk/client-kms": "3.48.0",
"@ethersproject/experimental": "^5.3.0",
"@nomiclabs/hardhat-ethers": "^2.0.5",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"@typechain/ethers-v5": "~7.0.0",
"@typechain/hardhat": "^2.0.1",
"@types/chai": "^4.2.21",
"@types/mocha": "^9.1.0",
"@types/node": "^16.9.1",
"@types/yargs": "^17.0.8",
"asn1.js": "5.4.1",
"axios": "^0.21.3",
"chai": "^4.3.4",
"dotenv": "^10.0.0",
"ethereum-waffle": "^3.2.2",
"ethers": "^5.4.7",
"hardhat": "^2.8.4",
"prettier": "^2.3.1",
"ts-node": "^10.1.0",
"typechain": "^5.0.0",
"typescript": "^4.3.2",
"yargs": "^17.3.1"
},
"dependencies": {
"@types/node": {
"version": "16.11.26"
}
}
},
"@abacus-network/hardhat": {
"version": "file:typescript/hardhat",
"requires": {

@ -0,0 +1,24 @@
import { ethers } from 'ethers';
import { NonceManager } from '@ethersproject/experimental';
import {
alfajores,
kovan,
mumbai,
fuji,
} from '../../../config/networks/testnets';
export const getChains = () => {
// Hardhat account 0
const key =
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
const provider = new ethers.providers.JsonRpcProvider(
'http://127.0.0.1:8545/',
);
const wallet = new ethers.Wallet(key, provider);
const signer = new NonceManager(wallet);
return [alfajores, kovan, fuji, mumbai].map((partial) => {
partial.overrides = {};
partial.confirmations = 1;
return { ...partial, signer };
});
};

@ -0,0 +1,13 @@
import { CoreConfig } from '../../../src/core';
export const core: CoreConfig = {
processGas: 850_000,
reserveGas: 15_000,
validators: {
// Hardhat accounts 1-4
alfajores: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
fuji: '0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc',
kovan: '0x90f79bf6eb2c4f870365e785982e1f101e93b906',
mumbai: '0x15d34aaf54267db7d7c367839aaf71a00a2c6a65',
},
};

@ -1,18 +1,97 @@
import '@nomiclabs/hardhat-waffle';
import { task } from 'hardhat/config';
import { types, utils } from '@abacus-network/utils';
import { sleep } from './src/utils/utils';
import {
getCoreConfig,
getCoreDeploy,
getEnvironmentDirectory,
getChainConfigsRecord,
} from './scripts/utils';
import { CoreDeploy } from './src/core';
const domainSummary = async (deploy: CoreDeploy, domain: types.Domain) => {
const outbox = deploy.outbox(domain);
const [outboxCheckpointRoot, outboxCheckpointIndex] =
await outbox.latestCheckpoint();
const count = (await outbox.tree()).toNumber();
const summary: any = {
domain,
outbox: {
count,
checkpoint: {
root: outboxCheckpointRoot,
index: outboxCheckpointIndex.toNumber(),
},
},
};
const inboxSummary = async (remote: types.Domain) => {
const inbox = deploy.inbox(remote, domain);
const [inboxCheckpointRoot, inboxCheckpointIndex] =
await inbox.latestCheckpoint();
const processFilter = inbox.filters.Process();
const processes = await inbox.queryFilter(processFilter);
return {
domain: remote,
processed: processes.length,
root: inboxCheckpointRoot,
index: inboxCheckpointIndex.toNumber(),
};
};
summary.inboxes = deploy.remotes(domain).map(inboxSummary);
return summary;
};
task('abacus', 'Deploys abacus on top of an already running Harthat Network')
.addParam(
'environment',
'The name of the environment from which to read configs',
)
.setAction(async (args: any) => {
const environment = args.environment;
// Deploy core
const chains = await getChainConfigsRecord(environment);
const config = await getCoreConfig(environment);
const deploy = new CoreDeploy();
await deploy.deploy(chains, config);
// Write configs
deploy.writeOutput(getEnvironmentDirectory(environment));
});
task('kathy', 'Dispatches random abacus messages')
.addParam(
'environment',
'The name of the environment from which to read configs',
)
.setAction(async (args: any) => {
const environment = args.environment;
const deploy = await getCoreDeploy(environment);
const randomElement = (list: types.Domain[]) =>
list[Math.floor(Math.random() * list.length)];
// Generate artificial traffic
while (true) {
const local = randomElement(deploy.domains);
const remote = randomElement(deploy.remotes(local));
const outbox = deploy.outbox(local);
// Values for recipient and message don't matter
await outbox.dispatch(
remote,
utils.addressToBytes32(outbox.address),
'0x1234',
);
console.log(await domainSummary(deploy, local));
await sleep(5000);
}
});
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: {
version: "0.7.6",
},
// For some reason the BridgeRouter is oversized here but not in
// in abacus-xapps.
networks: {
hardhat: {
allowUnlimitedContractSize: true
}
version: '0.7.6',
},
};

@ -14,7 +14,7 @@
"typescript": "^4.3.2"
},
"prepublish": "npm run build",
"name": "@abacus-network/abacus-deploy",
"name": "@abacus-network/deploy",
"version": "0.0.5",
"description": "Abacus deploy tools",
"main": "dist/src/index.js",
@ -23,7 +23,10 @@
"build": "tsc",
"test": "hardhat test",
"check": "tsc --noEmit",
"prettier": "prettier --write ./src ./config ./scripts"
"node": "hardhat node",
"abacus": "hardhat abacus --environment local",
"kathy": "hardhat kathy --environment local",
"prettier": "prettier --write *.ts ./src ./config ./scripts ./test"
},
"author": "Celo Labs Inc.",
"license": "MIT OR Apache-2.0",

@ -116,8 +116,12 @@ export async function getEnvironment(): Promise<DeployEnvironment> {
return (await getArgs().argv).e;
}
export function getEnvironmentDirectory(environment: DeployEnvironment) {
return path.join('./config/environments/', environment);
}
export function getCoreDirectory(environment: DeployEnvironment) {
return path.join('./config/environments', environment, 'core');
return path.join(getEnvironmentDirectory(environment), 'core');
}
export function getCoreContractsDirectory(environment: DeployEnvironment) {
@ -133,7 +137,7 @@ export function getCoreRustDirectory(environment: DeployEnvironment) {
}
export function getBridgeDirectory(environment: DeployEnvironment) {
return path.join('./config/environments', environment, 'bridge');
return path.join(getEnvironmentDirectory(environment), 'bridge');
}
export function getBridgeContractsDirectory(environment: DeployEnvironment) {
@ -145,7 +149,7 @@ export function getBridgeVerificationDirectory(environment: DeployEnvironment) {
}
export function getGovernanceDirectory(environment: DeployEnvironment) {
return path.join('./config/environments', environment, 'governance');
return path.join(getEnvironmentDirectory(environment), 'governance');
}
export function getGovernanceContractsDirectory(
@ -179,7 +183,7 @@ export function getCoreContracts(
const f = (chain: ChainConfig): CoreContracts => {
return CoreContracts.readJson(
path.join(directory, `${chain.name}.json`),
chain.signer.provider! as ethers.providers.JsonRpcProvider,
chain.signer,
);
};
return recordFromArray(chains, f);
@ -194,7 +198,7 @@ export function getBridgeContracts(
for (const chain of chains) {
contracts[chain.domain] = BridgeContracts.readJson(
path.join(directory, `${chain.name}.json`),
chain.signer.provider! as ethers.providers.JsonRpcProvider,
chain.signer,
);
}
return contracts;
@ -209,7 +213,7 @@ export function getGovernanceContracts(
for (const chain of chains) {
contracts[chain.domain] = GovernanceContracts.readJson(
path.join(directory, `${chain.name}.json`),
chain.signer.provider! as ethers.providers.JsonRpcProvider,
chain.signer,
);
}
return contracts;
@ -219,24 +223,27 @@ export async function getCoreDeploy(
environment: DeployEnvironment,
): Promise<CoreDeploy> {
const chains = await getChainConfigsRecord(environment);
const dir = await getCoreContractsDirectory(environment);
return CoreDeploy.readContracts(chains, dir);
return CoreDeploy.readContracts(chains, getEnvironmentDirectory(environment));
}
export async function getBridgeDeploy(
environment: DeployEnvironment,
): Promise<BridgeDeploy> {
const chains = await getChainConfigsRecord(environment);
const dir = await getBridgeContractsDirectory(environment);
return BridgeDeploy.readContracts(chains, dir);
return BridgeDeploy.readContracts(
chains,
getEnvironmentDirectory(environment),
);
}
export async function getGovernanceDeploy(
environment: DeployEnvironment,
): Promise<GovernanceDeploy> {
const chains = await getChainConfigsRecord(environment);
const dir = await getGovernanceContractsDirectory(environment);
return GovernanceDeploy.readContracts(chains, dir);
return GovernanceDeploy.readContracts(
chains,
getEnvironmentDirectory(environment),
);
}
export function getContext(environment: DeployEnvironment): AbacusContext {

@ -21,36 +21,30 @@ export class BridgeContracts extends CommonContracts<BridgeContractAddresses> {
};
}
static readJson(
filepath: string,
provider: ethers.providers.JsonRpcProvider,
): BridgeContracts {
static readJson(filepath: string, signer: ethers.Signer): BridgeContracts {
const contents = fs.readFileSync(filepath, 'utf8');
const addresses: BridgeContractAddresses = JSON.parse(contents);
return BridgeContracts.fromObject(addresses, provider);
return BridgeContracts.fromObject(addresses, signer);
}
static fromObject(
addresses: BridgeContractAddresses,
provider: ethers.providers.JsonRpcProvider,
signer: ethers.Signer,
): BridgeContracts {
const router: BeaconProxy<xapps.BridgeRouter> = BeaconProxy.fromObject(
addresses.router,
xapps.BridgeRouter__factory.abi,
provider,
signer,
);
const token: BeaconProxy<xapps.BridgeToken> = BeaconProxy.fromObject(
addresses.token,
xapps.BridgeToken__factory.abi,
provider,
signer,
);
if (addresses.helper) {
const helper = xapps.ETHHelper__factory.connect(
addresses.helper,
provider,
);
const helper = xapps.ETHHelper__factory.connect(addresses.helper, signer);
return new BridgeContracts(router, token, helper);
}
return new BridgeContracts(router, token);

@ -1,12 +1,11 @@
import path from 'path';
import { ethers } from 'ethers';
import { xapps } from '@abacus-network/ts-interface';
import { types } from '@abacus-network/utils';
import { BridgeConfig } from './types';
import { BridgeInstance } from './BridgeInstance';
import { BridgeContracts } from './BridgeContracts';
import { RouterDeploy } from '../router';
import { CommonDeploy } from '../common';
import { ChainConfig } from '../config';
import { RouterDeploy } from '../router';
export class BridgeDeploy extends RouterDeploy<BridgeInstance, BridgeConfig> {
deployName = 'bridge';
@ -22,18 +21,13 @@ export class BridgeDeploy extends RouterDeploy<BridgeInstance, BridgeConfig> {
chains: Record<types.Domain, ChainConfig>,
directory: string,
): BridgeDeploy {
const deploy = new BridgeDeploy();
const domains = Object.keys(chains).map((d) => parseInt(d));
for (const domain of domains) {
const chain = chains[domain];
const contracts = BridgeContracts.readJson(
path.join(directory, 'bridge', 'contracts', `${chain.name}.json`),
chain.signer.provider! as ethers.providers.JsonRpcProvider,
);
deploy.chains[domain] = chain;
deploy.instances[domain] = new BridgeInstance(chain, contracts);
}
return deploy;
return CommonDeploy.readContractsHelper(
BridgeDeploy,
BridgeInstance,
BridgeContracts.readJson,
chains,
directory,
);
}
token(domain: types.Domain): xapps.BridgeToken {

@ -62,22 +62,22 @@ export class BeaconProxy<T extends ethers.Contract> {
static fromObject<T extends ethers.Contract>(
addresses: ProxiedAddress,
abi: any,
provider: ethers.providers.JsonRpcProvider,
signer: ethers.Signer,
): BeaconProxy<T> {
const implementation = new ethers.Contract(
addresses.implementation,
abi,
provider,
signer,
) as T;
const proxy = core.UpgradeBeaconProxy__factory.connect(
addresses.proxy,
provider,
signer,
);
const beacon = core.UpgradeBeacon__factory.connect(
addresses.beacon,
provider,
signer,
);
const contract = new ethers.Contract(addresses.proxy, abi, provider) as T;
const contract = new ethers.Contract(addresses.proxy, abi, signer) as T;
return new BeaconProxy<T>(implementation, proxy, beacon, contract);
}

@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs';
import { ethers } from 'ethers';
import { types } from '@abacus-network/utils';
import { ChainConfig } from '../config';
import { ChainName, ChainConfig } from '../config';
import { CommonInstance } from './CommonInstance';
import { CommonContracts } from './CommonContracts';
@ -21,6 +21,22 @@ export abstract class CommonDeploy<
abstract deployInstance(domain: types.Domain, config: V): Promise<T>;
abstract deployName: string;
configDirectory(directory: string) {
return path.join(directory, this.deployName);
}
contractsDirectory(directory: string) {
return path.join(this.configDirectory(directory), 'contracts');
}
contractsFilepath(directory: string, chain: ChainName) {
return path.join(this.contractsDirectory(directory), `${chain}.json`);
}
verificationDirectory(directory: string) {
return path.join(this.configDirectory(directory), 'verification');
}
async deploy(chains: Record<types.Domain, ChainConfig>, config: V) {
await this.ready();
if (this.domains.length > 0) throw new Error('cannot deploy twice');
@ -49,6 +65,31 @@ export abstract class CommonDeploy<
);
}
static readContractsHelper<
L extends CommonDeploy<M, any>,
M extends CommonInstance<O>,
O extends CommonContracts<any>,
>(
deployConstructor: { new (): L },
instanceConstructor: { new (chain: ChainConfig, contracts: O): M },
contractsReader: (directory: string, signer: ethers.Signer) => O,
chains: Record<types.Domain, ChainConfig>,
directory: string,
): L {
const deploy = new deployConstructor();
const domains = Object.keys(chains).map((d) => parseInt(d));
for (const domain of domains) {
const chain = chains[domain];
const contracts = contractsReader(
deploy.contractsFilepath(directory, chain.name),
chain.signer,
);
deploy.chains[domain] = chain;
deploy.instances[domain] = new instanceConstructor(chain, contracts);
}
return deploy;
}
writeOutput(directory: string) {
this.writeContracts(directory);
this.writeVerificationInput(directory);
@ -58,9 +99,7 @@ export abstract class CommonDeploy<
for (const domain of this.domains) {
this.instances[domain].contracts.writeJson(
path.join(
directory,
this.deployName,
'contracts',
this.contractsDirectory(directory),
`${this.name(domain)}.json`,
),
);
@ -78,9 +117,7 @@ export abstract class CommonDeploy<
for (const domain of this.domains) {
const verificationInput = this.instances[domain].verificationInput;
const filepath = path.join(
directory,
this.deployName,
'verification',
this.verificationDirectory(directory),
`${this.name(domain)}.json`,
);
this.writeJson(filepath, verificationInput);

@ -34,37 +34,34 @@ export class CoreContracts extends CommonContracts<CoreContractAddresses> {
};
}
static readJson(
filepath: string,
provider: ethers.providers.JsonRpcProvider,
): CoreContracts {
static readJson(filepath: string, signer: ethers.Signer): CoreContracts {
const contents = fs.readFileSync(filepath, 'utf8');
const addresses: CoreContractAddresses = JSON.parse(contents);
return CoreContracts.fromObject(addresses, provider);
return CoreContracts.fromObject(addresses, signer);
}
static fromObject(
addresses: CoreContractAddresses,
provider: ethers.providers.JsonRpcProvider,
signer: ethers.Signer,
): CoreContracts {
const upgradeBeaconController =
core.UpgradeBeaconController__factory.connect(
addresses.upgradeBeaconController,
provider,
signer,
);
const xAppConnectionManager = core.XAppConnectionManager__factory.connect(
addresses.xAppConnectionManager,
provider,
signer,
);
const validatorManager = core.ValidatorManager__factory.connect(
addresses.validatorManager,
provider,
signer,
);
const outbox: BeaconProxy<core.Outbox> = BeaconProxy.fromObject(
addresses.outbox,
core.Outbox__factory.abi,
provider,
signer,
);
const inboxes: Record<types.Domain, BeaconProxy<core.Inbox>> = {};
@ -74,7 +71,7 @@ export class CoreContracts extends CommonContracts<CoreContractAddresses> {
inboxes[domain] = BeaconProxy.fromObject(
addresses.inboxes[domain],
core.Inbox__factory.abi,
provider,
signer,
);
});

@ -1,5 +1,4 @@
import path from 'path';
import { ethers } from 'ethers';
import { types } from '@abacus-network/utils';
import { core } from '@abacus-network/ts-interface';
import { CoreInstance } from './CoreInstance';
@ -42,25 +41,19 @@ export class CoreDeploy extends CommonDeploy<CoreInstance, CoreConfig> {
chains: Record<types.Domain, ChainConfig>,
directory: string,
): CoreDeploy {
const deploy = new CoreDeploy();
const domains = Object.keys(chains).map((d) => parseInt(d));
for (const domain of domains) {
const chain = chains[domain];
const contracts = CoreContracts.readJson(
path.join(directory, 'core', 'contracts', `${chain.name}.json`),
chain.signer.provider! as ethers.providers.JsonRpcProvider,
);
deploy.chains[domain] = chain;
deploy.instances[domain] = new CoreInstance(chain, contracts);
}
return deploy;
return CommonDeploy.readContractsHelper(
CoreDeploy,
CoreInstance,
CoreContracts.readJson,
chains,
directory,
);
}
writeRustConfigs(environment: DeployEnvironment, directory: string) {
for (const domain of this.domains) {
const filepath = path.join(
directory,
this.deployName,
this.configDirectory(directory),
'rust',
`${this.name(domain)}.json`,
);

@ -1,6 +1,5 @@
import { core } from '@abacus-network/ts-interface';
import { types } from '@abacus-network/utils';
import { ethers } from 'ethers';
import { CoreDeploy } from './CoreDeploy';
import { CoreInstance } from './CoreInstance';
import { CoreContracts } from './CoreContracts';
@ -38,10 +37,7 @@ export class ImplementationDeployer {
);
const addresses = this.deploy.instances[domain].contracts.toObject();
addresses.outbox.implementation = implementation.address;
const contracts = CoreContracts.fromObject(
addresses,
signer.provider as ethers.providers.JsonRpcProvider,
);
const contracts = CoreContracts.fromObject(addresses, signer);
const instance = new CoreInstance(this.deploy.chains[domain], contracts);
this.deploy.instances[domain] = instance;
}
@ -65,10 +61,7 @@ export class ImplementationDeployer {
for (const remote of this.deploy.remotes(domain)) {
addresses.inboxes[remote].implementation = implementation.address;
}
const contracts = CoreContracts.fromObject(
addresses,
signer.provider as ethers.providers.JsonRpcProvider,
);
const contracts = CoreContracts.fromObject(addresses, signer);
const instance = new CoreInstance(this.deploy.chains[domain], contracts);
this.deploy.instances[domain] = instance;
}

@ -17,21 +17,21 @@ export class GovernanceContracts extends CommonContracts<GovernanceContractAddre
static readJson(
filepath: string,
provider: ethers.providers.JsonRpcProvider,
signer: ethers.Signer,
): GovernanceContracts {
const contents = fs.readFileSync(filepath, 'utf8');
const addresses: GovernanceContractAddresses = JSON.parse(contents);
return GovernanceContracts.fromObject(addresses, provider);
return GovernanceContracts.fromObject(addresses, signer);
}
static fromObject(
addresses: GovernanceContractAddresses,
provider: ethers.providers.JsonRpcProvider,
signer: ethers.Signer,
): GovernanceContracts {
const router: BeaconProxy<xapps.GovernanceRouter> = BeaconProxy.fromObject(
addresses.router,
xapps.GovernanceRouter__factory.abi,
provider,
signer,
);
return new GovernanceContracts(router);
}

@ -1,7 +1,7 @@
import path from 'path';
import { ethers } from 'ethers';
import { types } from '@abacus-network/utils';
import { xapps } from '@abacus-network/ts-interface';
import { CommonDeploy } from '../common';
import { ChainConfig } from '../config';
import { RouterDeploy } from '../router';
import { GovernanceInstance } from './GovernanceInstance';
@ -38,18 +38,13 @@ export class GovernanceDeploy extends RouterDeploy<
chains: Record<types.Domain, ChainConfig>,
directory: string,
): GovernanceDeploy {
const deploy = new GovernanceDeploy();
const domains = Object.keys(chains).map((d) => parseInt(d));
for (const domain of domains) {
const chain = chains[domain];
const contracts = GovernanceContracts.readJson(
path.join(directory, 'governance', 'contracts', `${chain.name}.json`),
chain.signer.provider! as ethers.providers.JsonRpcProvider,
);
deploy.chains[domain] = chain;
deploy.instances[domain] = new GovernanceInstance(chain, contracts);
}
return deploy;
return CommonDeploy.readContractsHelper(
GovernanceDeploy,
GovernanceInstance,
GovernanceContracts.readJson,
chains,
directory,
);
}
router(domain: types.Domain): xapps.GovernanceRouter {

@ -5,6 +5,10 @@ import path from 'path';
import * as asn1 from 'asn1.js';
import { ethers } from 'ethers';
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
/**
* Map an async function over a list xs with a given concurrency level
*

@ -50,8 +50,7 @@ describe('bridge', async () => {
});
it('writes', async () => {
bridge.writeContracts(outputDir);
bridge.writeVerificationInput(outputDir);
bridge.writeOutput(outputDir);
});
it('reads', async () => {

@ -32,8 +32,7 @@ describe('core', async () => {
});
it('writes', async () => {
core.writeContracts(outputDir);
core.writeVerificationInput(outputDir);
core.writeOutput(outputDir);
core.writeRustConfigs(DeployEnvironment.dev, outputDir);
});

@ -54,8 +54,7 @@ describe('governance', async () => {
});
it('writes', async () => {
governance.writeContracts(outputDir);
governance.writeVerificationInput(outputDir);
governance.writeOutput(outputDir);
});
it('reads', async () => {

Loading…
Cancel
Save