Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support env subset deployments #767

Merged
merged 26 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c14fe62
Use consistent dep versions across packages
jmrossy Jul 7, 2022
7241f36
Add @abacus-network/helloworld back to monorepo
jmrossy Jul 7, 2022
69f39b7
Copy over latest helloworld constructor change
jmrossy Jul 7, 2022
c6bcb18
Minor tweak to readme and package.json deps
jmrossy Jul 8, 2022
3e08879
Fix lint and dockerfile
jmrossy Jul 8, 2022
30e2e50
Merge branch 'main' into rossy/migrate-helloworld
jmrossy Jul 8, 2022
8530de7
Create basic sync script for helloWorld package
jmrossy Jul 8, 2022
70f0298
Add command to run yarn install after copy
jmrossy Jul 8, 2022
8e2c40d
Merge branch 'main' into rossy/migrate-helloworld
jmrossy Jul 11, 2022
ff191f7
Merge branch 'rossy/migrate-helloworld' into rossy/migrate-helloworld…
jmrossy Jul 11, 2022
4cce9df
Add new methods and checks to multiprovider
jmrossy Jul 12, 2022
e7ca656
Merge branch 'main' into rossy/multiprovider-chain-subset
jmrossy Jul 12, 2022
40141c0
Make generic type order consistent across main classes
jmrossy Jul 13, 2022
57f9698
Create basic envSubsetDeployer test app for sdk
jmrossy Jul 13, 2022
90a7d12
Merge branch 'main' into rossy/multiprovider-chain-subset
jmrossy Jul 13, 2022
69749da
Create getChainToOwnerMap util function
jmrossy Jul 13, 2022
dae79c0
Get single chain deployments working
jmrossy Jul 14, 2022
cdbe587
Dedupe deploy code in envSubsetDeployer and AbacusRouterDeployer
jmrossy Jul 14, 2022
c7e49c8
Remove TODO comment
jmrossy Jul 14, 2022
87b8113
Merge branch 'main' into rossy/multiprovider-chain-subset
jmrossy Jul 14, 2022
eebc041
Address some feedback
jmrossy Jul 18, 2022
d9e4cdb
Merge branch 'main' into rossy/multiprovider-chain-subset
jmrossy Jul 18, 2022
5804ae3
Merge branch 'main' into rossy/multiprovider-chain-subset
jmrossy Jul 25, 2022
add3cdc
Replace getMultiProviderFrom* with getTestMultiProvider
jmrossy Jul 27, 2022
8ebec27
Merge branch 'main' into rossy/multiprovider-chain-subset
jmrossy Jul 27, 2022
2b64659
Merge branch 'main' into rossy/multiprovider-chain-subset
jmrossy Jul 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions typescript/helloworld/src/app/environments/test.json

This file was deleted.

4 changes: 2 additions & 2 deletions typescript/helloworld/src/deploy/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class HelloWorldChecker<
Chain extends ChainName,
> extends AbacusRouterChecker<
Chain,
HelloWorldContracts,
HelloWorldApp<Chain>,
HelloWorldConfig
HelloWorldConfig,
HelloWorldContracts
> {}
28 changes: 5 additions & 23 deletions typescript/helloworld/src/deploy/config.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
import {
ChainMap,
RouterConfig,
TestChainNames,
chainConnectionConfigs,
} from '@abacus-network/sdk';
import { RouterConfig, chainConnectionConfigs } from '@abacus-network/sdk';

export type HelloWorldConfig = RouterConfig;

// TODO reduce this config boilerplate

export const testConfigs = {
test1: chainConnectionConfigs.test1,
test2: chainConnectionConfigs.test2,
test3: chainConnectionConfigs.test3,
};

export function getConfigMap(
signerAddress: string,
): ChainMap<TestChainNames, { owner: string }> {
return {
test1: {
owner: signerAddress,
},
test2: {
owner: signerAddress,
},
test3: {
owner: signerAddress,
},
};
}
// SET DESIRED NETWORKS HERE
export const prodConfigs = {
alfajores: chainConnectionConfigs.alfajores,
};
4 changes: 2 additions & 2 deletions typescript/helloworld/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export class HelloWorldDeployer<
Chain extends ChainName,
> extends AbacusRouterDeployer<
Chain,
HelloWorldConfig,
HelloWorldContracts,
HelloWorldFactories,
HelloWorldConfig
HelloWorldFactories
> {
constructor(
multiProvider: MultiProvider<Chain>,
Expand Down
34 changes: 21 additions & 13 deletions typescript/helloworld/src/scripts/check.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
import { ethers } from 'hardhat';
import { providers } from 'ethers';

import {
AbacusCore,
ChainMap,
ChainName,
buildContracts,
getMultiProviderFromConfigAndSigner,
getChainToOwnerMap,
getMultiProviderFromConfigAndProvider,
} from '@abacus-network/sdk';

import { HelloWorldApp } from '../app/app';
import { HelloWorldContracts, helloWorldFactories } from '../app/contracts';
import testEnvironmentAddresses from '../app/environments/test.json';
import { HelloWorldChecker } from '../deploy/check';
import { getConfigMap, testConfigs } from '../deploy/config';
import { prodConfigs } from '../deploy/config';

// COPY FROM OUTPUT OF DEPLOYMENT SCRIPT OR IMPORT FROM ELSEWHERE
const deploymentAddresses = {};

// SET CONTRACT OWNER ADDRESS HERE
const ownerAddress = '0x123...';

async function check() {
const [signer] = await ethers.getSigners();
const multiProvider = getMultiProviderFromConfigAndSigner(
testConfigs,
signer,
);
console.info('Getting provider');
const provider = new providers.JsonRpcProvider('URL_HERE');
jmrossy marked this conversation as resolved.
Show resolved Hide resolved

console.info('Preparing utilities');
const multiProvider = getMultiProviderFromConfigAndProvider(
prodConfigs,
provider,
);
const contractsMap = buildContracts(
testEnvironmentAddresses,
deploymentAddresses,
helloWorldFactories,
) as ChainMap<ChainName, HelloWorldContracts>;

const app = new HelloWorldApp(contractsMap, multiProvider);

const core = AbacusCore.fromEnvironment('test', multiProvider);
const core = AbacusCore.fromEnvironment('testnet2', multiProvider);
const config = core.extendWithConnectionClientConfig(
getConfigMap(signer.address),
getChainToOwnerMap(prodConfigs, ownerAddress),
);

console.info('Starting check');
const helloWorldChecker = new HelloWorldChecker(multiProvider, app, config);
await helloWorldChecker.check();
helloWorldChecker.expectEmpty();
Expand Down
17 changes: 10 additions & 7 deletions typescript/helloworld/src/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import '@nomiclabs/hardhat-ethers';
import { ethers } from 'hardhat';
import { Wallet } from 'ethers';

import {
AbacusCore,
getChainToOwnerMap,
getMultiProviderFromConfigAndSigner,
serializeContracts,
} from '@abacus-network/sdk';

import { getConfigMap, testConfigs } from '../deploy/config';
import { prodConfigs } from '../deploy/config';
import { HelloWorldDeployer } from '../deploy/deploy';

async function main() {
const [signer] = await ethers.getSigners();
console.info('Getting signer');
const signer = new Wallet('SET KEY HERE OR CREATE YOUR OWN SIGNER');

console.info('Preparing utilities');
const multiProvider = getMultiProviderFromConfigAndSigner(
testConfigs,
prodConfigs,
signer,
);

const core = AbacusCore.fromEnvironment('test', multiProvider);
const core = AbacusCore.fromEnvironment('testnet2', multiProvider);
const config = core.extendWithConnectionClientConfig(
getConfigMap(signer.address),
getChainToOwnerMap(prodConfigs, signer.address),
);

const deployer = new HelloWorldDeployer(multiProvider, config, core);
Expand Down
5 changes: 3 additions & 2 deletions typescript/helloworld/src/test/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {
TestChainNames,
TestCoreApp,
TestCoreDeployer,
getChainToOwnerMap,
getMultiProviderFromConfigAndSigner,
} from '@abacus-network/sdk';

import { HelloWorldApp } from '../app/app';
import { HelloWorldContracts } from '../app/contracts';
import { HelloWorldChecker } from '../deploy/check';
import { HelloWorldConfig, getConfigMap, testConfigs } from '../deploy/config';
import { HelloWorldConfig, testConfigs } from '../deploy/config';
import { HelloWorldDeployer } from '../deploy/deploy';

describe('deploy', async () => {
Expand All @@ -32,7 +33,7 @@ describe('deploy', async () => {
const coreContractsMaps = await coreDeployer.deploy();
core = new TestCoreApp(coreContractsMaps, multiProvider);
config = core.extendWithConnectionClientConfig(
getConfigMap(signer.address),
getChainToOwnerMap(testConfigs, signer.address),
);
deployer = new HelloWorldDeployer(multiProvider, config, core);
});
Expand Down
5 changes: 3 additions & 2 deletions typescript/helloworld/src/test/helloworld.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
TestChainNames,
TestCoreApp,
TestCoreDeployer,
getChainToOwnerMap,
getMultiProviderFromConfigAndSigner,
} from '@abacus-network/sdk';

import { HelloWorldConfig, getConfigMap, testConfigs } from '../deploy/config';
import { HelloWorldConfig, testConfigs } from '../deploy/config';
import { HelloWorldDeployer } from '../deploy/deploy';
import { HelloWorld } from '../types';

Expand All @@ -38,7 +39,7 @@ describe('HelloWorld', async () => {
const coreContractsMaps = await coreDeployer.deploy();
coreApp = new TestCoreApp(coreContractsMaps, multiProvider);
config = coreApp.extendWithConnectionClientConfig(
getConfigMap(signer.address),
getChainToOwnerMap(testConfigs, signer.address),
);
});

Expand Down
1 change: 1 addition & 0 deletions typescript/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"mocha": "^9.2.2",
"prettier": "^2.4.1",
"sinon": "^13.0.2",
"ts-node": "^10.8.0",
"typescript": "^4.7.2"
},
"files": [
Expand Down
42 changes: 34 additions & 8 deletions typescript/sdk/src/core/AbacusCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ChainConnection } from '../providers/ChainConnection';
import { MultiProvider } from '../providers/MultiProvider';
import { ConnectionClientConfig } from '../router';
import { ChainMap, ChainName, Remotes } from '../types';
import { objMap } from '../utils';
import { objMap, pick } from '../utils';

import { CoreContracts, coreFactories } from './contracts';

Expand Down Expand Up @@ -46,15 +46,41 @@ export class AbacusCore<Chain extends ChainName = ChainName> extends AbacusApp<
super(contractsMap, multiProvider);
}

static fromEnvironment<Env extends CoreEnvironment>(
env: Env,
multiProvider: MultiProvider<CoreEnvironmentChain<Env>>,
): AbacusCore<CoreEnvironmentChain<Env>> {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
static fromEnvironment<
Env extends CoreEnvironment,
Chain extends ChainName = ChainName,
>(env: Env, multiProvider: MultiProvider<Chain>) {
const envConfig = environments[env];
if (!envConfig) {
throw new Error(`No default env config found for ${env}`);
}

const multiProviderChains = multiProvider.chains();
const envChains = Object.keys(envConfig);
const intersection = multiProviderChains.filter((c) =>
envChains.includes(c),
);

if (!intersection.length) {
throw new Error(`No chains shared between MultiProvider and env ${env}`);
}
jmrossy marked this conversation as resolved.
Show resolved Hide resolved

type EnvChain = keyof typeof envConfig;
type IntersectionChain = EnvChain & Chain;
// Force cast of multiProvider to ensure Core gets correct type later
const intersectionProvider =
multiProvider as unknown as MultiProvider<IntersectionChain>;
jmrossy marked this conversation as resolved.
Show resolved Hide resolved
const intersectionConfig = pick(
envConfig as ChainMap<Chain, any>,
intersection,
);
const contractsMap = buildContracts(
environments[env],
intersectionConfig,
coreFactories,
) as CoreContractsMap<CoreEnvironmentChain<Env>>;
return new AbacusCore(contractsMap, multiProvider);
) as CoreContractsMap<IntersectionChain>;

return new AbacusCore(contractsMap, intersectionProvider);
}

// override type to be derived from chain key
Expand Down
13 changes: 6 additions & 7 deletions typescript/sdk/src/core/TestCoreApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ export type TestCoreContracts<Local extends TestChainNames> = CoreContracts<
inboxes: ChainMap<Remotes<TestChainNames, Local>, TestInboxContracts>;
};

export class TestCoreApp extends AbacusCore<TestChainNames> {
getContracts<Local extends TestChainNames>(
export class TestCoreApp<
TestChain extends TestChainNames = TestChainNames,
jmrossy marked this conversation as resolved.
Show resolved Hide resolved
> extends AbacusCore<TestChain> {
getContracts<Local extends TestChain>(
chain: Local,
): TestCoreContracts<Local> {
return super.getContracts(chain) as TestCoreContracts<Local>;
}

async processMessages(): Promise<
Map<
TestChainNames,
Map<TestChainNames, ethers.providers.TransactionResponse[]>
>
Map<TestChain, Map<TestChain, ethers.providers.TransactionResponse[]>>
> {
const responses = new Map();
for (const origin of this.chains()) {
Expand All @@ -57,7 +56,7 @@ export class TestCoreApp extends AbacusCore<TestChainNames> {
return responses;
}

async processOutboundMessages<Local extends TestChainNames>(
async processOutboundMessages<Local extends TestChain>(
origin: Local,
): Promise<Map<ChainName, any>> {
const responses = new Map<ChainName, any>();
Expand Down
31 changes: 18 additions & 13 deletions typescript/sdk/src/core/TestCoreDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AbacusCoreDeployer } from '../deploy/core/AbacusCoreDeployer';
import { CoreConfig, ValidatorManagerConfig } from '../deploy/core/types';
import { MultiProvider } from '../providers/MultiProvider';
import { ProxiedContract } from '../proxy';
import { Remotes, TestChainNames } from '../types';
import { ChainMap, Remotes, TestChainNames } from '../types';

import {
TestCoreApp,
Expand Down Expand Up @@ -38,21 +38,26 @@ function mockProxy(contract: ethers.Contract) {
});
}

export class TestCoreDeployer extends AbacusCoreDeployer<TestChainNames> {
constructor(public readonly multiProvider: MultiProvider<TestChainNames>) {
super(
multiProvider,
{
export class TestCoreDeployer<
TestChain extends TestChainNames = TestChainNames,
> extends AbacusCoreDeployer<TestChain> {
constructor(
public readonly multiProvider: MultiProvider<TestChain>,
configMap?: ChainMap<TestChain, CoreConfig>,
) {
const configs =
configMap ??
({
test1: testValidatorManagerConfig,
test2: testValidatorManagerConfig,
test3: testValidatorManagerConfig,
},
testCoreFactories,
);
} as ChainMap<TestChain, CoreConfig>); // cast so param can be optional

super(multiProvider, configs, testCoreFactories);
}

// skip proxying
async deployOutbox<LocalChain extends TestChainNames>(
async deployOutbox<LocalChain extends TestChain>(
chain: LocalChain,
config: ValidatorManagerConfig,
): Promise<TestOutboxContracts> {
Expand All @@ -74,9 +79,9 @@ export class TestCoreDeployer extends AbacusCoreDeployer<TestChainNames> {
}

// skip proxying
async deployInbox<LocalChain extends TestChainNames>(
async deployInbox<LocalChain extends TestChain>(
local: LocalChain,
remote: Remotes<TestChainNames, LocalChain>,
remote: Remotes<TestChain, LocalChain>,
config: ValidatorManagerConfig,
): Promise<TestInboxContracts> {
const localDomain = chainMetadata[local].id;
Expand All @@ -96,7 +101,7 @@ export class TestCoreDeployer extends AbacusCoreDeployer<TestChainNames> {
} as TestInboxContracts;
}

async deployApp(): Promise<TestCoreApp> {
async deployApp(): Promise<TestCoreApp<TestChain>> {
return new TestCoreApp(await this.deploy(), this.multiProvider);
}
}
2 changes: 1 addition & 1 deletion typescript/sdk/src/deploy/AbacusDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export interface DeployerOptions {
export abstract class AbacusDeployer<
Chain extends ChainName,
Config,
Factories extends AbacusFactories,
Contracts extends AbacusContracts,
Factories extends AbacusFactories,
> {
public deployedContracts: Partial<Record<Chain, Contracts>> = {};

Expand Down
Loading