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

Unify deploy and app abstractions #507

Merged
merged 18 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Add back multiprovider to app builders
  • Loading branch information
yorhodes committed Jun 2, 2022
commit acdbeaa98f93a7a7334043c0aaa83a2854bdbddc
11 changes: 9 additions & 2 deletions typescript/infra/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { task } from 'hardhat/config';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

import { BadRandomRecipient__factory } from '@abacus-network/core';
import { utils as deployUtils } from '@abacus-network/deploy';
import {
AbacusCore,
ChainName,
ChainNameToDomainId,
} from '@abacus-network/sdk';
import { utils } from '@abacus-network/utils';

import { getCoreEnvironmentConfig } from './scripts/utils';
import { sleep } from './src/utils/utils';
import { AbacusContractVerifier } from './src/verify';

Expand Down Expand Up @@ -52,13 +54,18 @@ const chainSummary = async <Chain extends ChainName>(

task('kathy', 'Dispatches random abacus messages').setAction(
async (_, hre: HardhatRuntimeEnvironment) => {
const core = AbacusCore.fromEnvironment('test');
const config = getCoreEnvironmentConfig('test');
const [signer] = await hre.ethers.getSigners();
const multiProvider = deployUtils.getMultiProviderFromConfigAndSigner(
config.transactionConfigs,
signer,
);
const core = AbacusCore.fromEnvironment('test', multiProvider);

const randomElement = <T>(list: T[]) =>
list[Math.floor(Math.random() * list.length)];

// Deploy a recipient
const [signer] = await hre.ethers.getSigners();
const recipientF = new BadRandomRecipient__factory(signer);
const recipient = await recipientF.deploy();
await recipient.deployTransaction.wait();
Expand Down
3 changes: 2 additions & 1 deletion typescript/infra/scripts/check-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ async function check() {
const config = getCoreEnvironmentConfig(environment);
const multiProvider = await config.getMultiProvider();

const core = AbacusCore.fromEnvironment(environment);
// environments union doesn't work well with typescript
const core = AbacusCore.fromEnvironment(environment, multiProvider as any);
const coreChecker = new AbacusCoreChecker<any>(
multiProvider,
core,
Expand Down
2 changes: 1 addition & 1 deletion typescript/infra/test/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('core', async () => {
});

it('transfers ownership', async () => {
core = new AbacusCore(contracts);
core = new AbacusCore(contracts, multiProvider);
await AbacusCoreDeployer.transferOwnership(core, owners, multiProvider);
});

Expand Down
27 changes: 11 additions & 16 deletions typescript/sdk/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
import {
AbacusAddresses,
AbacusContracts,
AbacusFactories,
buildContracts,
connectContracts,
serializeContracts,
} from './contracts';
import { MultiProvider } from './provider';
import { ChainMap, ChainName, Connection } from './types';
import { MultiGeneric, objMap } from './utils';

export class AbacusApp<
Contracts extends AbacusContracts,
Chain extends ChainName = ChainName,
> extends MultiGeneric<Chain, Contracts> {
constructor(public contractsMap: ChainMap<Chain, Contracts>) {
super(contractsMap);
}

static buildContracts<
Contracts extends AbacusContracts,
Chain extends ChainName,
>(
addressesMap: ChainMap<Chain, AbacusAddresses>,
factories: AbacusFactories,
): ChainMap<Chain, Contracts> {
return objMap(
addressesMap,
(_, addresses) => buildContracts(addresses, factories) as Contracts,
constructor(
public contractsMap: ChainMap<Chain, Contracts>,
multiProvider: MultiProvider<Chain>,
) {
const connectedContractsMap = objMap(contractsMap, (chain, contracts) =>
connectContracts(
contracts,
multiProvider.getChainConnection(chain).getConnection(),
),
);
super(connectedContractsMap);
}

getContracts(chain: Chain): Contracts {
Expand Down
27 changes: 14 additions & 13 deletions typescript/sdk/src/core/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Inbox, Outbox } from '@abacus-network/core';

import { AbacusApp } from '../app';
import { AbacusAddresses } from '../contracts';
import { ChainMap, ChainName, Remotes } from '../types';
import { buildContracts } from '../contracts';
import { MultiProvider } from '../provider';
import { ChainName, Remotes } from '../types';

import { CoreContracts, coreFactories } from './contracts';
import { environments } from './environments';
Expand All @@ -21,22 +22,22 @@ export class AbacusCore<Chain extends ChainName = ChainName> extends AbacusApp<
CoreContracts<Chain, Chain>,
Chain
> {
constructor(contractsMap: CoreContractsMap<Chain>) {
super(contractsMap);
constructor(
contractsMap: CoreContractsMap<Chain>,
multiProvider: MultiProvider<Chain>,
) {
super(contractsMap, multiProvider);
}

static fromEnvironment<Env extends CoreEnvironment>(
env: Env,
): AbacusCore<any> {
const addressesMap = environments[env] as ChainMap<
CoreEnvironmentChain<Env>,
AbacusAddresses
>;
const contractsMap: CoreContractsMap<any> = this.buildContracts(
addressesMap,
multiProvider: MultiProvider<CoreEnvironmentChain<Env>>,
): AbacusCore<CoreEnvironmentChain<Env>> {
const contractsMap = buildContracts(
environments[env],
coreFactories,
);
return new AbacusCore(contractsMap);
) as CoreContractsMap<CoreEnvironmentChain<Env>>;
return new AbacusCore(contractsMap, multiProvider);
}

// override type to be derived from chain key
Expand Down
2 changes: 1 addition & 1 deletion typescript/sdk/src/core/environments/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@
}
}
}
}
}
5 changes: 4 additions & 1 deletion typescript/sdk/test/gas/calculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ describe('InterchainGasCalculator', () => {
test2: { provider },
test3: { provider },
});
const core: AbacusCore<TestChainNames> = AbacusCore.fromEnvironment('test');
const core: AbacusCore<TestChainNames> = AbacusCore.fromEnvironment(
'test',
multiProvider,
);
const origin = Chains.test1;
const destination = Chains.test2;

Expand Down