Update for SDK 0.2.X and fixup meta files (#14)

* Add license and update deps

* Update template app to build against 0.2.1-alpha11

* Fix deploy tests

* Update to SDK beta1

* Adjust environments usage

Co-authored-by: yorhodes <yorke@useabacus.network>
pull/2435/head
J M Rossy 2 years ago committed by GitHub
parent a80400e6ba
commit b1c826540c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .eslintignore
  2. 31
      .eslintrc
  3. 20
      .eslintrc.json
  4. 13
      .github/workflows/ci.yml
  5. 1
      .gitignore
  6. 195
      LICENSE.md
  7. 16
      contracts/HelloWorld.sol
  8. 67
      package.json
  9. 18
      src/deploy/check.ts
  10. 32
      src/deploy/config.ts
  11. 65
      src/deploy/deploy.ts
  12. 12
      src/deploy/environments/index.ts
  13. 7
      src/deploy/environments/test.ts
  14. 2
      src/deploy/index.ts
  15. 58
      src/deploy/networks.ts
  16. 18
      src/deploy/output/test/addresses.ts
  17. 8
      src/deploy/output/test/verification/alfajores.json
  18. 8
      src/deploy/output/test/verification/fuji.json
  19. 8
      src/deploy/output/test/verification/kovan.json
  20. 8
      src/deploy/output/test/verification/mumbai.json
  21. 24
      src/deploy/scripts/check.ts
  22. 30
      src/deploy/scripts/deploy.ts
  23. 7
      src/deploy/scripts/utils.ts
  24. 4
      src/index.ts
  25. 35
      src/scripts/check.ts
  26. 31
      src/scripts/deploy.ts
  27. 80
      src/sdk/app.ts
  28. 27
      src/sdk/contracts.ts
  29. 5
      src/sdk/environments/index.ts
  30. 11
      src/sdk/environments/test.json
  31. 14
      src/sdk/environments/test.ts
  32. 2
      src/sdk/index.ts
  33. 5
      src/sdk/types.ts
  34. 29
      test/HelloWorldDeploy.ts
  35. 74
      test/deploy.test.ts
  36. 94
      test/helloworld.test.ts
  37. 14
      tsconfig.json
  38. 1753
      yarn.lock

@ -1,3 +1,4 @@
node_modules
dist
coverage
src/types

@ -0,0 +1,31 @@
{
"env": {
"node": true,
"browser": true,
"es2021": true
},
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"no-eval": ["error"],
"no-ex-assign": ["error"],
"no-constant-condition": ["off"],
"@typescript-eslint/ban-ts-comment": ["off"],
"@typescript-eslint/explicit-module-boundary-types": ["off"],
"@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/no-floating-promises": ["error"],
"@typescript-eslint/no-non-null-assertion": ["off"],
"@typescript-eslint/no-require-imports": ["warn"],
}
}

@ -1,20 +0,0 @@
{
"env": {
"node": true
},
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"comma-dangle": ["error", "always-multiline"],
"semi": ["error", "always"],
"@typescript-eslint/explicit-module-boundary-types": ["error"],
"@typescript-eslint/no-non-null-assertion": ["error"],
"@typescript-eslint/no-explicit-any": ["error", { "ignoreRestArgs": true }]
}
}

@ -72,6 +72,19 @@ jobs:
exit 1
fi
lint:
runs-on: ubuntu-latest
needs: [install]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: .//node_modules
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }}
- name: lint
run: yarn run lint
test:
runs-on: ubuntu-latest
needs: [build]

1
.gitignore vendored

@ -5,6 +5,7 @@ coverage.json
dist/
node_modules/
src/types/
src/deploy/output
test/outputs/
*.swp
.yarn/install-state.gz

@ -0,0 +1,195 @@
Apache License
==============
_Version 2.0, January 2004_
_&lt;<http://www.apache.org/licenses/>&gt;_
### Terms and Conditions for use, reproduction, and distribution
#### 1. Definitions
“License” shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.
“Licensor” shall mean the copyright owner or entity authorized by the copyright
owner that is granting the License.
“Legal Entity” shall mean the union of the acting entity and all other entities
that control, are controlled by, or are under common control with that entity.
For the purposes of this definition, “control” means **(i)** the power, direct or
indirect, to cause the direction or management of such entity, whether by
contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
outstanding shares, or **(iii)** beneficial ownership of such entity.
“You” (or “Your”) shall mean an individual or Legal Entity exercising
permissions granted by this License.
“Source” form shall mean the preferred form for making modifications, including
but not limited to software source code, documentation source, and configuration
files.
“Object” form shall mean any form resulting from mechanical transformation or
translation of a Source form, including but not limited to compiled object code,
generated documentation, and conversions to other media types.
“Work” shall mean the work of authorship, whether in Source or Object form, made
available under the License, as indicated by a copyright notice that is included
in or attached to the work (an example is provided in the Appendix below).
“Derivative Works” shall mean any work, whether in Source or Object form, that
is based on (or derived from) the Work and for which the editorial revisions,
annotations, elaborations, or other modifications represent, as a whole, an
original work of authorship. For the purposes of this License, Derivative Works
shall not include works that remain separable from, or merely link (or bind by
name) to the interfaces of, the Work and Derivative Works thereof.
“Contribution” shall mean any work of authorship, including the original version
of the Work and any modifications or additions to that Work or Derivative Works
thereof, that is intentionally submitted to Licensor for inclusion in the Work
by the copyright owner or by an individual or Legal Entity authorized to submit
on behalf of the copyright owner. For the purposes of this definition,
“submitted” means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems, and
issue tracking systems that are managed by, or on behalf of, the Licensor for
the purpose of discussing and improving the Work, but excluding communication
that is conspicuously marked or otherwise designated in writing by the copyright
owner as “Not a Contribution.”
“Contributor” shall mean Licensor and any individual or Legal Entity on behalf
of whom a Contribution has been received by Licensor and subsequently
incorporated within the Work.
#### 2. Grant of Copyright License
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the Work and such
Derivative Works in Source or Object form.
#### 3. Grant of Patent License
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
such license applies only to those patent claims licensable by such Contributor
that are necessarily infringed by their Contribution(s) alone or by combination
of their Contribution(s) with the Work to which such Contribution(s) was
submitted. If You institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
Contribution incorporated within the Work constitutes direct or contributory
patent infringement, then any patent licenses granted to You under this License
for that Work shall terminate as of the date such litigation is filed.
#### 4. Redistribution
You may reproduce and distribute copies of the Work or Derivative Works thereof
in any medium, with or without modifications, and in Source or Object form,
provided that You meet the following conditions:
* **(a)** You must give any other recipients of the Work or Derivative Works a copy of
this License; and
* **(b)** You must cause any modified files to carry prominent notices stating that You
changed the files; and
* **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
all copyright, patent, trademark, and attribution notices from the Source form
of the Work, excluding those notices that do not pertain to any part of the
Derivative Works; and
* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
Derivative Works that You distribute must include a readable copy of the
attribution notices contained within such NOTICE file, excluding those notices
that do not pertain to any part of the Derivative Works, in at least one of the
following places: within a NOTICE text file distributed as part of the
Derivative Works; within the Source form or documentation, if provided along
with the Derivative Works; or, within a display generated by the Derivative
Works, if and wherever such third-party notices normally appear. The contents of
the NOTICE file are for informational purposes only and do not modify the
License. You may add Your own attribution notices within Derivative Works that
You distribute, alongside or as an addendum to the NOTICE text from the Work,
provided that such additional attribution notices cannot be construed as
modifying the License.
You may add Your own copyright statement to Your modifications and may provide
additional or different license terms and conditions for use, reproduction, or
distribution of Your modifications, or for any such Derivative Works as a whole,
provided Your use, reproduction, and distribution of the Work otherwise complies
with the conditions stated in this License.
#### 5. Submission of Contributions
Unless You explicitly state otherwise, any Contribution intentionally submitted
for inclusion in the Work by You to the Licensor shall be under the terms and
conditions of this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify the terms of
any separate license agreement you may have executed with Licensor regarding
such Contributions.
#### 6. Trademarks
This License does not grant permission to use the trade names, trademarks,
service marks, or product names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the NOTICE file.
#### 7. Disclaimer of Warranty
Unless required by applicable law or agreed to in writing, Licensor provides the
Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
including, without limitation, any warranties or conditions of TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
solely responsible for determining the appropriateness of using or
redistributing the Work and assume any risks associated with Your exercise of
permissions under this License.
#### 8. Limitation of Liability
In no event and under no legal theory, whether in tort (including negligence),
contract, or otherwise, unless required by applicable law (such as deliberate
and grossly negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special, incidental,
or consequential damages of any character arising as a result of this License or
out of the use or inability to use the Work (including but not limited to
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
any and all other commercial damages or losses), even if such Contributor has
been advised of the possibility of such damages.
#### 9. Accepting Warranty or Additional Liability
While redistributing the Work or Derivative Works thereof, You may choose to
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
other liability obligations and/or rights consistent with this License. However,
in accepting such obligations, You may act only on Your own behalf and on Your
sole responsibility, not on behalf of any other Contributor, and only if You
agree to indemnify, defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason of your
accepting any such warranty or additional liability.
_END OF TERMS AND CONDITIONS_
### APPENDIX: How to apply the Apache License to your work
To apply the Apache License to your work, attach the following boilerplate
notice, with the fields enclosed by brackets `[]` replaced with your own
identifying information. (Don't include the brackets!) The text should be
enclosed in the appropriate comment syntax for the file format. We also
recommend that a file or class name and description of purpose be included on
the same “printed page” as the copyright notice for easier identification within
third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@ -34,16 +34,6 @@ contract HelloWorld is Router {
string message
);
// ============ Constructor ============
constructor() {}
// ============ Initializer ============
function initialize(address _abacusConnectionManager) external initializer {
__Router_initialize(_abacusConnectionManager);
}
// ============ External functions ============
/**
@ -57,11 +47,7 @@ contract HelloWorld is Router {
{
sent += 1;
sentTo[_destinationDomain] += 1;
_dispatchWithGasAndCheckpoint(
_destinationDomain,
bytes(_message),
msg.value
);
_dispatchWithGas(_destinationDomain, bytes(_message), msg.value);
emit SentHelloWorld(_localDomain(), _destinationDomain, _message);
}

@ -1,56 +1,49 @@
{
"name": "@abacus-network/helloworld",
"version": "0.0.1",
"license": "MIT OR Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"directories": {
"test": "test"
},
"files": [
"src",
"dist"
],
"scripts": {
"build:sol": "hardhat compile && hardhat typechain",
"build:ts": "tsc",
"build": "npm run build:sol && npm run build:ts",
"test:contracts": "hardhat test test/helloworld.test.ts",
"test:sdk": "",
"test:deploy": "hardhat test test/deploy.test.ts",
"test": "npm run test:contracts && npm run test:sdk && npm run test:deploy",
"prettier": "prettier --write ./contracts ./src ./test",
"coverage": "hardhat coverage"
},
"description": "A basic skeleton of an Abacus app",
"version": "0.2.1",
"dependencies": {
"@abacus-network/app": "^0.1.1",
"@abacus-network/sdk": "^0.1.1",
"@ethersproject/bignumber": "^5.5.0",
"@ethersproject/bytes": "^5.5.0",
"@ethersproject/experimental": "^5.6.0",
"@abacus-network/app": "0.2.1-beta1",
"@abacus-network/sdk": "0.2.1-beta1",
"@openzeppelin/contracts-upgradeable": "~4.5.0",
"ethers": "^5.4.7"
},
"devDependencies": {
"@abacus-network/deploy": "^0.1.1",
"@abacus-network/hardhat": "^0.1.1",
"@abacus-network/core": "^0.2.1-beta1",
"@abacus-network/deploy": "0.2.1-beta1",
"@abacus-network/hardhat": "0.2.1-beta1",
"@nomiclabs/hardhat-ethers": "^2.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@typechain/ethers-v5": "~7.0.0",
"@typechain/hardhat": "^2.0.1",
"@typechain/ethers-v5": "^10.0.0",
"@typechain/hardhat": "^6.0.0",
"@types/mocha": "^9.1.0",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"chai": "^4.3.0",
"eslint": "^7.20.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"hardhat": "^2.8.3",
"hardhat-gas-reporter": "^1.0.7",
"prettier": "^2.2.1",
"prettier": "^2.4.1",
"prettier-plugin-solidity": "^1.0.0-beta.5",
"solhint": "^3.3.2",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.7.14",
"ts-node": "^10.7.0",
"typechain": "^5.0.0",
"typescript": "^4.3.5"
"ts-node": "^10.8.0",
"typechain": "^8.0.0",
"typescript": "^4.7.2"
},
"license": "Apache-2.0",
"main": "dist/index.js",
"packageManager": "yarn@3.2.0",
"private": true,
"scripts": {
"clean": "hardhat clean && rm -r dist",
"build": "hardhat compile && tsc",
"test": "hardhat test",
"coverage": "hardhat coverage",
"prettier": "prettier --write ./contracts ./src ./test",
"lint": "eslint . --ext .ts"
},
"packageManager": "yarn@3.2.0"
"types": "dist/index.d.ts"
}

@ -1,16 +1,14 @@
import { AbacusRouterChecker } from '@abacus-network/deploy';
import { ChainName } from '@abacus-network/sdk';
import { HelloWorldApp } from '../sdk';
import { HelloWorldConfig } from '../sdk/types';
import { HelloWorldApp } from '../sdk/app';
import { HelloWorldContracts } from '../sdk/contracts';
import { HelloWorldConfig } from './config';
export class HelloWorldChecker<
Networks extends ChainName,
Chain extends ChainName,
> extends AbacusRouterChecker<
Networks,
HelloWorldApp<Networks>,
Chain,
HelloWorldContracts,
HelloWorldApp<Chain>,
HelloWorldConfig
> {
mustGetRouter(network: Networks) {
return this.app.getContracts(network).router;
}
}
> {}

@ -0,0 +1,32 @@
import { RouterConfig } from '@abacus-network/deploy';
import {
chainConnectionConfigs,
ChainMap,
TestChainNames,
} 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, RouterConfig> {
return {
test1: {
owner: signerAddress,
},
test2: {
owner: signerAddress,
},
test3: {
owner: signerAddress,
},
};
}

@ -1,62 +1,39 @@
import { AbacusRouterDeployer } from '@abacus-network/deploy';
import {
AbacusCore,
ChainName,
ChainMap,
ChainName,
MultiProvider,
} from '@abacus-network/sdk';
import { HelloWorldAddresses } from '../sdk/contracts';
import { HelloWorldConfig } from '../sdk/types';
import { HelloWorld__factory } from '../types';
import {
HelloWorldContracts,
helloWorldFactories,
HelloWorldFactories,
} from '../sdk/contracts';
import { HelloWorldConfig } from './config';
export class HelloWorldDeployer<
Networks extends ChainName,
Chain extends ChainName,
> extends AbacusRouterDeployer<
Networks,
HelloWorldConfig,
HelloWorldAddresses
Chain,
HelloWorldContracts,
HelloWorldFactories,
HelloWorldConfig
> {
constructor(
multiProvider: MultiProvider<Networks>,
config: HelloWorldConfig,
core: AbacusCore<Networks>,
multiProvider: MultiProvider<Chain>,
configMap: ChainMap<Chain, HelloWorldConfig>,
protected core: AbacusCore<Chain>,
) {
const networks = multiProvider.networks();
const crossConfigMap = Object.fromEntries(
networks.map((network) => [network, config]),
) as ChainMap<Networks, HelloWorldConfig>;
super(multiProvider, crossConfigMap, core);
super(multiProvider, configMap, helloWorldFactories, {});
}
async deployContracts(
network: Networks,
config: HelloWorldConfig,
): Promise<HelloWorldAddresses> {
const dc = this.multiProvider.getDomainConnection(network);
const signer = dc.signer!;
const router = await this.deployContract(
network,
'HelloWorld',
new HelloWorld__factory(signer),
[],
);
const abacusConnectionManager =
this.core?.getContracts(network).abacusConnectionManager!;
const initTx = await router.initialize(abacusConnectionManager.address);
await initTx.wait(dc.confirmations);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async deployContracts(chain: Chain, config: HelloWorldConfig) {
const acm = this.core.getContracts(chain).abacusConnectionManager.address;
const router = await this.deployRouter(chain, [], [acm]);
return {
router: router.address,
abacusConnectionManager: abacusConnectionManager.address,
router,
};
}
mustGetRouter(network: Networks, addresses: HelloWorldAddresses) {
return HelloWorld__factory.connect(
addresses.router,
this.multiProvider.getDomainConnection(network).signer!,
);
}
}

@ -1,12 +0,0 @@
import { EnvironmentConfig, RouterConfig } from '@abacus-network/deploy';
import { TemplateNetworks } from '../../deploy/networks';
import { environment as testEnvironment } from './test';
export type HelloWorldEnvironmentConfig =
EnvironmentConfig<TemplateNetworks> & {
config: RouterConfig;
};
export const environments = {
test: testEnvironment,
};

@ -1,7 +0,0 @@
import { configs } from '../networks';
import { HelloWorldEnvironmentConfig } from './index';
export const environment: HelloWorldEnvironmentConfig = {
...configs,
config: {},
};

@ -1,2 +0,0 @@
export { HelloWorldDeployer } from './deploy';
export { HelloWorldChecker } from './check';

@ -1,58 +0,0 @@
import { TransactionConfig } from '@abacus-network/deploy';
import { ChainMap } from '@abacus-network/sdk';
export const alfajores: TransactionConfig = {
confirmations: 1,
overrides: {},
};
export const fuji: TransactionConfig = {
confirmations: 1,
overrides: {},
};
export const mumbai: TransactionConfig = {
confirmations: 3,
overrides: {},
};
export const kovan: TransactionConfig = {
confirmations: 3,
overrides: {},
};
export const test1: TransactionConfig = {
confirmations: 1,
overrides: {},
};
export const test2: TransactionConfig = {
confirmations: 1,
overrides: {},
};
export const test3: TransactionConfig = {
confirmations: 1,
overrides: {},
};
const _configs = {
alfajores,
fuji,
mumbai,
kovan,
test1,
test2,
test3,
};
export type TemplateNetworks = keyof typeof _configs;
export type TestNetworks = 'test1' | 'test2' | 'test3';
export const testConfigs: ChainMap<TestNetworks, TransactionConfig> = {
test1,
test2,
test3,
};
export const configs: ChainMap<keyof typeof _configs, TransactionConfig> =
_configs;

@ -1,18 +0,0 @@
export const addresses = {
alfajores: {
router: '0xCace1b78160AE76398F486c8a18044da0d66d86D',
xAppConnectionManager: '0x610178dA211FEF7D417bC0e6FeD39F05609AD788',
},
kovan: {
router: '0xD5ac451B0c50B9476107823Af206eD814a2e2580',
xAppConnectionManager: '0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690',
},
mumbai: {
router: '0xF8e31cb472bc70500f08Cd84917E5A1912Ec8397',
xAppConnectionManager: '0xb7278A61aa25c888815aFC32Ad3cC52fF24fE575',
},
fuji: {
router: '0xc0F115A19107322cFBf1cDBC7ea011C19EbDB4F8',
xAppConnectionManager: '0xDC11f7E700A4c898AE5CAddB1082cFfa76512aDD',
},
};

@ -1,8 +0,0 @@
[
{
"name": "HelloWorld",
"address": "0xCace1b78160AE76398F486c8a18044da0d66d86D",
"constructorArguments": ["0x610178dA211FEF7D417bC0e6FeD39F05609AD788"],
"isProxy": false
}
]

@ -1,8 +0,0 @@
[
{
"name": "HelloWorld",
"address": "0xc0F115A19107322cFBf1cDBC7ea011C19EbDB4F8",
"constructorArguments": ["0xDC11f7E700A4c898AE5CAddB1082cFfa76512aDD"],
"isProxy": false
}
]

@ -1,8 +0,0 @@
[
{
"name": "HelloWorld",
"address": "0xD5ac451B0c50B9476107823Af206eD814a2e2580",
"constructorArguments": ["0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690"],
"isProxy": false
}
]

@ -1,8 +0,0 @@
[
{
"name": "HelloWorld",
"address": "0xF8e31cb472bc70500f08Cd84917E5A1912Ec8397",
"constructorArguments": ["0xb7278A61aa25c888815aFC32Ad3cC52fF24fE575"],
"isProxy": false
}
]

@ -1,24 +0,0 @@
import { utils } from '@abacus-network/deploy';
import { ethers } from 'hardhat';
import { HelloWorldApp } from '../../sdk';
import { HelloWorldChecker } from '../check';
import { testConfigs } from '../networks';
async function check() {
const [signer] = await ethers.getSigners();
const multiProvider = utils.getMultiProviderFromConfigAndSigner(
testConfigs,
signer,
);
const app = HelloWorldApp.fromEnvironment('test', multiProvider);
const yoChecker = new HelloWorldChecker(multiProvider, app, {
test1: { owner: signer.address },
test2: { owner: signer.address },
test3: { owner: signer.address },
});
await yoChecker.check();
yoChecker.expectEmpty();
}
check().then(console.log).catch(console.error);

@ -1,30 +0,0 @@
import { utils } from '@abacus-network/deploy';
import { AbacusCore } from '@abacus-network/sdk';
import '@nomiclabs/hardhat-ethers';
import { ethers } from 'hardhat';
import path from 'path';
import { HelloWorldDeployer } from '..';
import { testConfigs } from '../networks';
async function main() {
const [signer] = await ethers.getSigners();
const environment = 'test';
const multiProvider = utils.getMultiProviderFromConfigAndSigner(
testConfigs,
signer,
);
const core = AbacusCore.fromEnvironment('test', multiProvider);
const deployer = new HelloWorldDeployer(
multiProvider,
{ owner: signer.address },
core,
);
const addresses = await deployer.deploy();
deployer.writeContracts(
addresses,
path.join('./src/sdk/environments/', environment + '.ts'),
);
}
main().then(console.log).catch(console.error);

@ -1,7 +0,0 @@
import { environments, HelloWorldEnvironmentConfig } from '../environments';
export async function getEnvironmentConfig(
environment: keyof typeof environments,
): Promise<HelloWorldEnvironmentConfig> {
return environments[environment];
}

@ -1,4 +0,0 @@
export { HelloWorldApp, HelloWorldAddresses, HelloWorldContracts } from './sdk';
export * as contracts from './types';
export { HelloWorldDeployer, HelloWorldChecker } from './deploy';

@ -0,0 +1,35 @@
import { utils } from '@abacus-network/deploy';
import { buildContracts, ChainMap, ChainName } from '@abacus-network/sdk';
import { ethers } from 'hardhat';
import { HelloWorldChecker } from '../deploy/check';
import { getConfigMap, testConfigs } from '../deploy/config';
import { HelloWorldApp } from '../sdk/app';
import { HelloWorldContracts, helloWorldFactories } from '../sdk/contracts';
import testEnvironmentAddresses from '../sdk/environments/test.json';
async function check() {
const [signer] = await ethers.getSigners();
const multiProvider = utils.getMultiProviderFromConfigAndSigner(
testConfigs,
signer,
);
const contractsMap = buildContracts(
testEnvironmentAddresses,
helloWorldFactories,
) as ChainMap<ChainName, HelloWorldContracts>;
const app = new HelloWorldApp(contractsMap, multiProvider);
const helloWorldChecker = new HelloWorldChecker(
multiProvider,
app,
getConfigMap(signer.address),
);
await helloWorldChecker.check();
helloWorldChecker.expectEmpty();
}
check()
.then(() => console.info('Check complete'))
.catch(console.error);

@ -0,0 +1,31 @@
import { utils } from '@abacus-network/deploy';
import { TestCoreApp } from '@abacus-network/hardhat/dist/src/TestCoreApp';
import { serializeContracts } from '@abacus-network/sdk';
import '@nomiclabs/hardhat-ethers';
import { ethers } from 'hardhat';
import { getConfigMap, testConfigs } from '../deploy/config';
import { HelloWorldDeployer } from '../deploy/deploy';
async function main() {
const [signer] = await ethers.getSigners();
const multiProvider = utils.getMultiProviderFromConfigAndSigner(
testConfigs,
signer,
);
const core = TestCoreApp.fromEnvironment('test', multiProvider);
const deployer = new HelloWorldDeployer(
multiProvider,
getConfigMap(signer.address),
core,
);
const chainToContracts = await deployer.deploy();
const addresses = serializeContracts(chainToContracts);
console.info('===Contract Addresses===');
console.info(JSON.stringify(addresses));
}
main()
.then(() => console.info('Deploy complete'))
.catch(console.error);

@ -1,80 +1,18 @@
import {
AbacusApp,
AbacusCore,
ChainMap,
ChainName,
ChainNameToDomainId,
InterchainGasCalculator,
MultiProvider,
} from '@abacus-network/sdk';
import { BigNumber, ethers } from 'ethers';
import { HelloWorldAddresses, HelloWorldContracts } from './contracts';
import { environments } from './environments';
type Environments = typeof environments;
type EnvironmentName = keyof Environments;
import { AbacusApp, ChainName, ChainNameToDomainId } from '@abacus-network/sdk';
import { ethers } from 'ethers';
import { HelloWorldContracts } from './contracts';
export class HelloWorldApp<
Networks extends ChainName = ChainName,
> extends AbacusApp<HelloWorldContracts, Networks> {
constructor(
networkAddresses: ChainMap<Networks, HelloWorldAddresses>,
multiProvider: MultiProvider<Networks>,
private interchainGasCalculator: InterchainGasCalculator,
) {
super(HelloWorldContracts, networkAddresses, multiProvider);
}
static fromNetworkAddresses<Networks extends ChainName = ChainName>(
networkAddresses: ChainMap<Networks, HelloWorldAddresses>,
multiProvider: MultiProvider<Networks>,
core: AbacusCore<Networks>,
) {
const interchainGasCalculator = new InterchainGasCalculator(
// TODO remove cast when InterchainGasCalculator is more strongly typed:
// https://github.com/abacus-network/abacus-monorepo/issues/407
multiProvider as MultiProvider<any>,
core as AbacusCore<any>,
);
return new HelloWorldApp(
networkAddresses,
multiProvider,
interchainGasCalculator,
);
}
static fromEnvironment(
name: EnvironmentName,
multiProvider: MultiProvider<keyof Environments[typeof name]>,
) {
const core = AbacusCore.fromEnvironment(name, multiProvider);
return HelloWorldApp.fromNetworkAddresses(
environments[name],
multiProvider,
core,
);
}
Chain extends ChainName = ChainName,
> extends AbacusApp<HelloWorldContracts, Chain> {
async sendHelloWorld(
from: Networks,
to: Networks,
from: Chain,
to: Chain,
message: string,
): Promise<ethers.ContractReceipt> {
const router = this.getContracts(from).router;
const fromDomain = ChainNameToDomainId[from];
const helloWorldContract = this.getContracts(from).router;
const toDomain = ChainNameToDomainId[to];
const interchainGasPayment =
await this.interchainGasCalculator.estimatePaymentForHandleGasAmount(
fromDomain,
toDomain,
// Actual gas costs depend on the size of the message
BigNumber.from('100000'),
);
const tx = await router.sendHelloWorld(toDomain, message, {
value: interchainGasPayment,
});
const tx = await helloWorldContract.sendHelloWorld(toDomain, message);
return tx.wait();
}
}

@ -1,25 +1,10 @@
import {
AbacusContracts,
RouterAddresses,
routerFactories,
} from '@abacus-network/sdk';
import { HelloWorld__factory } from '../types';
import { RouterContracts, RouterFactories } from '@abacus-network/sdk';
import { HelloWorld, HelloWorld__factory } from '../types';
export type HelloWorldAddresses = RouterAddresses;
export type HelloWorldFactories = RouterFactories<HelloWorld>;
export const helloWorldFactories = {
...routerFactories,
router: HelloWorld__factory.connect,
export const helloWorldFactories: HelloWorldFactories = {
router: new HelloWorld__factory(),
};
export type HelloWorldFactories = typeof helloWorldFactories;
export class HelloWorldContracts extends AbacusContracts<
HelloWorldAddresses,
HelloWorldFactories
> {
// necessary for factories be defined in the constructor
factories() {
return helloWorldFactories;
}
}
export type HelloWorldContracts = RouterContracts<HelloWorld>;

@ -1,5 +0,0 @@
import { addresses as test } from './test';
export const environments = {
test,
};

@ -0,0 +1,11 @@
{
"test1": {
"router": "0x5FbDB2315678afecb367f032d93F642f64180aa3"
},
"test2": {
"router": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
},
"test3": {
"router": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9"
}
}

@ -1,14 +0,0 @@
export const addresses = {
test1: {
router: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
abacusConnectionManager: '0x0165878A594ca255338adfa4d48449f69242Eb8F',
},
test2: {
router: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
abacusConnectionManager: '0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44',
},
test3: {
router: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
abacusConnectionManager: '0x70e0bA845a1A0F2DA3359C97E0285013525FFC49',
},
};

@ -1,2 +0,0 @@
export { HelloWorldApp } from './app';
export { HelloWorldAddresses, HelloWorldContracts } from './contracts';

@ -1,5 +0,0 @@
import { RouterConfig } from '@abacus-network/deploy';
export type HelloWorldConfig = RouterConfig & {
owner: string;
};

@ -1,29 +0,0 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { types } from '@abacus-network/utils';
import { TestAbacusDeploy, TestRouterDeploy } from '@abacus-network/hardhat';
import { HelloWorld__factory, HelloWorld } from '../src/types';
type HelloWorldTestConfig = {
signer: SignerWithAddress;
};
export class HelloWorldDeploy extends TestRouterDeploy<
HelloWorld,
HelloWorldTestConfig
> {
async deployInstance(
domain: types.Domain,
abacus: TestAbacusDeploy,
): Promise<HelloWorld> {
const helloWorldFactory = new HelloWorld__factory(this.config.signer);
const router = await helloWorldFactory.deploy();
await router.initialize(abacus.abacusConnectionManager(domain).address);
await router.transferOwnership(this.config.signer.address);
return router;
}
router(domain: types.Domain): HelloWorld {
return this.instances[domain];
}
}

@ -1,69 +1,59 @@
import path from 'path';
import { utils } from '@abacus-network/deploy';
// TODO export TestCoreApp from @abacus-network/hardhat properly
import { TestCoreApp } from '@abacus-network/hardhat/dist/src/TestCoreApp';
// TODO export TestCoreDeploy from @abacus-network/hardhat properly
import { TestCoreDeploy } from '@abacus-network/hardhat/dist/src/TestCoreDeploy';
import { MultiProvider, TestChainNames } from '@abacus-network/sdk';
import '@nomiclabs/hardhat-waffle';
import { ethers } from 'hardhat';
import { utils } from '@abacus-network/deploy';
import { HelloWorldAddresses, HelloWorldApp } from '../src';
import { HelloWorldChecker, HelloWorldDeployer } from '../src/deploy';
import { configs } from '../src/deploy/networks';
import { AbacusCore } from '@abacus-network/sdk';
import { HelloWorldChecker } from '../src/deploy/check';
import { getConfigMap, testConfigs } from '../src/deploy/config';
import { HelloWorldDeployer } from '../src/deploy/deploy';
import { HelloWorldApp } from '../src/sdk/app';
import { HelloWorldContracts } from '../src/sdk/contracts';
describe('deploy', async () => {
type TestNetworks = 'test1' | 'test2' | 'test3';
let deployer: HelloWorldDeployer<TestNetworks>;
let addresses: Record<TestNetworks, HelloWorldAddresses>;
let core: AbacusCore<TestNetworks>;
let multiProvider: MultiProvider<TestChainNames>;
let core: TestCoreApp;
let deployer: HelloWorldDeployer<TestChainNames>;
let contracts: Record<TestChainNames, HelloWorldContracts>;
let app: HelloWorldApp<TestChainNames>;
before(async () => {
const transactionConfigs = {
test1: configs.test1,
test2: configs.test2,
test3: configs.test3,
};
const [signer] = await ethers.getSigners();
const multiProvider = utils.getMultiProviderFromConfigAndSigner(
transactionConfigs,
multiProvider = utils.getMultiProviderFromConfigAndSigner(
testConfigs,
signer,
);
core = AbacusCore.fromEnvironment('test', multiProvider);
const coreDeployer = new TestCoreDeploy(multiProvider);
const coreContractsMaps = await coreDeployer.deploy();
core = new TestCoreApp(coreContractsMaps, multiProvider);
deployer = new HelloWorldDeployer(
multiProvider,
{ owner: signer.address },
getConfigMap(signer.address),
core,
);
});
it('deploys', async () => {
addresses = await deployer.deploy();
contracts = await deployer.deploy();
});
it('writes', async () => {
const base = './test/outputs/yo';
deployer.writeVerification(path.join(base, 'verification'));
deployer.writeContracts(addresses, path.join(base, 'contracts.ts'));
it('builds app', async () => {
contracts = await deployer.deploy();
app = new HelloWorldApp(contracts, multiProvider);
});
it('checks', async () => {
const transactionConfigs = {
test1: configs.test1,
test2: configs.test2,
test3: configs.test3,
};
const [signer] = await ethers.getSigners();
const multiProvider = utils.getMultiProviderFromConfigAndSigner(
transactionConfigs,
signer,
);
const app = HelloWorldApp.fromNetworkAddresses<TestNetworks>(
addresses,
const checker = new HelloWorldChecker(
multiProvider,
core,
app,
getConfigMap(signer.address),
);
const checker = new HelloWorldChecker(multiProvider, app, {
test1: { owner: signer.address },
test2: { owner: signer.address },
test3: { owner: signer.address },
});
await checker.check();
checker.expectEmpty();
});

@ -1,63 +1,79 @@
import { ethers, abacus } from 'hardhat';
import { expect } from 'chai';
import { utils as deployUtils } from '@abacus-network/deploy';
import '@abacus-network/hardhat';
// TODO export TestCoreApp from @abacus-network/hardhat properly
import { TestCoreApp } from '@abacus-network/hardhat/dist/src/TestCoreApp';
// TODO export TestCoreDeploy from @abacus-network/hardhat properly
import { TestCoreDeploy } from '@abacus-network/hardhat/dist/src/TestCoreDeploy';
import { ChainNameToDomainId } from '@abacus-network/sdk';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { HelloWorldDeploy } from './HelloWorldDeploy';
import { expect } from 'chai';
import { ethers } from 'hardhat';
import { getConfigMap, testConfigs } from '../src/deploy/config';
import { HelloWorldDeployer } from '../src/deploy/deploy';
import { HelloWorld } from '../src/types';
import { BigNumber } from 'ethers';
const localDomain = 1000;
const remoteDomain = 2000;
const domains = [localDomain, remoteDomain];
describe('HelloWorld', async () => {
let signer: SignerWithAddress,
router: HelloWorld,
remote: HelloWorld,
helloWorld: HelloWorldDeploy;
const localChain = 'test1';
const remoteChain = 'test2';
const localDomain = ChainNameToDomainId[localChain];
const remoteDomain = ChainNameToDomainId[remoteChain];
let signer: SignerWithAddress;
let local: HelloWorld;
let remote: HelloWorld;
// TODO fix multiProvider type issues
let multiProvider: any; /*MultiProvider<TestChainNames>;*/
let coreApp: TestCoreApp;
before(async () => {
[signer] = await ethers.getSigners();
await abacus.deploy(domains, signer);
multiProvider = deployUtils.getMultiProviderFromConfigAndSigner(
testConfigs,
signer,
);
const coreDeployer = new TestCoreDeploy(multiProvider);
const coreContractsMaps = await coreDeployer.deploy();
coreApp = new TestCoreApp(coreContractsMaps, multiProvider);
});
beforeEach(async () => {
const config = { signer };
helloWorld = new HelloWorldDeploy(config);
await helloWorld.deploy(abacus);
router = helloWorld.router(localDomain);
remote = helloWorld.router(remoteDomain);
expect(await router.sent()).to.equal(0);
expect(await router.received()).to.equal(0);
const helloWorld = new HelloWorldDeployer(
multiProvider,
getConfigMap(signer.address),
coreApp,
);
const contracts = await helloWorld.deploy();
local = contracts[localChain].router;
remote = contracts[remoteChain].router;
// The all counts start empty
expect(await local.sent()).to.equal(0);
expect(await local.received()).to.equal(0);
expect(await remote.sent()).to.equal(0);
expect(await remote.received()).to.equal(0);
});
it('sends a message', async () => {
await expect(router.sendHelloWorld(remoteDomain, 'Hello')).to.emit(
abacus.outbox(localDomain),
'Dispatch',
await expect(local.sendHelloWorld(remoteDomain, 'Hello')).to.emit(
local,
'SentHelloWorld',
);
expect(await router.sent()).to.equal(1);
expect(await router.sentTo(remoteDomain)).to.equal(1);
expect(await router.received()).to.equal(0);
});
it('pays interchain gas', async () => {
const gasPayment = BigNumber.from('1000');
await expect(
router.sendHelloWorld(remoteDomain, 'World', {
value: gasPayment,
}),
).to.emit(abacus.interchainGasPaymaster(localDomain), 'GasPayment');
// The sent counts are correct
expect(await local.sent()).to.equal(1);
expect(await local.sentTo(remoteDomain)).to.equal(1);
// The received counts are correct
expect(await local.received()).to.equal(0);
});
it('handles a message', async () => {
await router.sendHelloWorld(remoteDomain, 'World');
await local.sendHelloWorld(remoteDomain, 'World');
// Mock processing of the message by Abacus
await abacus.processOutboundMessages(localDomain);
await coreApp.processOutboundMessages(localChain);
// The initial message has been dispatched.
expect(await router.sent()).to.equal(1);
expect(await local.sent()).to.equal(1);
// The initial message has been processed.
expect(await remote.received()).to.equal(1);
expect(await remote.receivedFrom(localDomain)).to.equal(1);

@ -20,15 +20,9 @@
"target": "es6",
"strict": true,
"outDir": "./dist/",
"rootDir": "./"
"rootDir": "./",
"resolveJsonModule": true
},
"exclude": [
"./node_modules/",
"./dist/",
"./src/types/hardhat.d.ts"
],
"include": [
"./src/",
"hardhat.config.ts"
]
"exclude": ["./node_modules/", "./dist/", "./src/types/hardhat.d.ts"],
"include": ["./src/", "./test", "hardhat.config.ts"]
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save