Rebrand to Hyperlane and update to SDK 0.5.0 (#7)

* Rebrand token to Hyperlane
* Update src and tests to match template app 
* Update for compat with SDK 0.5.0
* Add linting and license
pull/2435/head
J M Rossy 2 years ago committed by GitHub
parent 814a1242c3
commit 70c46dc8a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .eslintignore
  2. 31
      .eslintrc
  3. 20
      .eslintrc.json
  4. 14
      .github/workflows/ci.yml
  5. 2
      .prettierignore
  6. 5
      .prettierrc
  7. 195
      LICENSE.md
  8. 52
      README.md
  9. 26
      contracts/HypERC20.sol
  10. 28
      contracts/HypERC721.sol
  11. 10
      hardhat.config.ts
  12. 84
      package.json
  13. 19
      src/config.ts
  14. 24
      src/contracts.ts
  15. 79
      src/deploy.ts
  16. 32
      test/erc20.deploy.ts
  17. 147
      test/erc20.test.ts
  18. 37
      test/erc721.deploy.ts
  19. 198
      test/erc721.test.ts
  20. 14
      tsconfig.json
  21. 2291
      yarn.lock

@ -1,3 +1,5 @@
node_modules
dist
coverage
coverage
src/types
hardhat.config.ts

@ -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": ["off"],
"@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,20 @@ jobs:
exit 1
fi
lint:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ./*
key: ${{ github.sha }}
- name: lint
run: yarn run lint
test:
runs-on: ubuntu-latest
needs: [build]

@ -0,0 +1,2 @@
src/types
test/outputs

@ -14,5 +14,8 @@
"explicitTypes": "always"
}
}
]
],
"importOrder": ["^@hyperlane-xyz/(.*)$", "^../(.*)$", "^./(.*)$"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}

@ -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.

@ -1,8 +1,6 @@
# Interchain tokens using Hyperlane
## AbcERC20
`AbcERC20` showcases an Abacus Token that extends the ERC20 token with an additional `transferRemote` function.
This repo showcases a Hyperlane ERC20 and ERC721 tokens (HypERC20 and HypERC721). These tokens extend the base standards with an additional `transferRemote` function.
```mermaid
%%{init: {'theme':'base'}}%%
@ -11,55 +9,23 @@ graph TB
Operator((Operator))
subgraph "Ethereum"
ABC_E[(ABC)]
HYP_E[(HYP)]
O_E[/Outbox\]
end
subgraph "Polygon"
ABC_P[(ABC)]
HYP_P[(HYP)]
EthereumInbox[\EthereumInbox/]
end
Bob((Bob))
Alice -- "transferRemote(Polygon, Bob, 5)" --> ABC_E
ABC_E -- "dispatch(Polygon, (Bob, 5))" --> O_E
Alice -- "transferRemote(Polygon, Bob, 5)" --> HYP_E
HYP_E -- "dispatch(Polygon, (Bob, 5))" --> O_E
Operator -- "checkpoint()" --> O_E
O_E-.->EthereumInbox
Operator -- "relay()" --> EthereumInbox
Operator -- "process(Ethereum, (Bob, 5))" --> EthereumInbox
EthereumInbox-->|"handle(Ethereum, (Bob, 5))"|ABC_P
ABC_P-.->Bob
```
## AbcERC721
`AbcERC721` showcases an Abacus Token that extends the ERC721 token with an additional `transferRemote` function.
```mermaid
%%{init: {'theme':'base'}}%%
graph TB
Alice((Alice))
Operator((Operator))
subgraph "Ethereum"
ABC_E[(ABC)]
O_E[/Outbox\]
end
subgraph "Polygon"
ABC_P[(ABC)]
EthereumInbox[\EthereumInbox/]
end
Bob((Bob))
Alice -- "transferRemote(Polygon, Bob, 69)" --> ABC_E
ABC_E -- "dispatch(Polygon, (Bob, 69))" --> O_E
Operator -- "checkpoint()" --> O_E
O_E-.->EthereumInbox
Operator -- "relay()" --> EthereumInbox
Operator -- "process(Ethereum, (Bob, 69))" --> EthereumInbox
EthereumInbox-->|"handle(Ethereum, (Bob, 69))"|ABC_P
ABC_P-.->Bob
```
EthereumInbox-->|"handle(Ethereum, (Bob, 5))"|HYP_P
HYP_P-.->Bob
```

@ -1,16 +1,16 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;
import {Router} from "@abacus-network/app/contracts/Router.sol";
import {Router} from "@hyperlane-xyz/app/contracts/Router.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
/**
* @title Abacus Token that extends the ERC20 token standard to enable native interchain transfers.
* @title Hyperlane Token that extends the ERC20 token standard to enable native interchain transfers.
* @author Abacus Works
* @dev Supply on each chain is not constant but the aggregate supply across all chains is.
*/
contract AbcERC20 is Router, ERC20Upgradeable {
contract HypERC20 is Router, ERC20Upgradeable {
/**
* @dev Emitted on `transferRemote` when a transfer message is dispatched.
* @param destination The identifier of the destination chain.
@ -36,19 +36,27 @@ contract AbcERC20 is Router, ERC20Upgradeable {
);
/**
* @notice Initializes the Abacus router, ERC20 metadata, and mints initial supply to deployer.
* @param _xAppConnectionManager The address of the XAppConnectionManager contract.
* @notice Initializes the Hyperlane router, ERC20 metadata, and mints initial supply to deployer.
* @param _abacusConnectionManager The address of the connection manager contract.
* @param _interchainGasPaymaster The address of the interchain gas paymaster contract.
* @param _totalSupply The initial supply of the token.
* @param _name The name of the token.
* @param _symbol The symbol of the token.
*/
function initialize(
address _xAppConnectionManager,
address _abacusConnectionManager,
address _interchainGasPaymaster,
uint256 _totalSupply,
string memory _name,
string memory _symbol
) external initializer {
__Router_initialize(_xAppConnectionManager);
// Set ownable to sender
_transferOwnership(msg.sender);
// Set ACM contract address
_setAbacusConnectionManager(_abacusConnectionManager);
// Set IGP contract address
_setInterchainGasPaymaster(_interchainGasPaymaster);
__ERC20_init(_name, _symbol);
_mint(msg.sender, _totalSupply);
}
@ -68,7 +76,7 @@ contract AbcERC20 is Router, ERC20Upgradeable {
uint256 _amount
) external payable {
_burn(msg.sender, _amount);
_dispatchWithGasAndCheckpoint(
_dispatchWithGas(
_destination,
abi.encode(_recipient, _amount),
msg.value

@ -1,15 +1,15 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;
import {Router} from "@abacus-network/app/contracts/Router.sol";
import {Router} from "@hyperlane-xyz/app/contracts/Router.sol";
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import {ERC721EnumerableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
/**
* @title Abacus Token that extends the ERC721 token standard to enable native interchain transfers.
* @title Hyperlane Token that extends the ERC721 token standard to enable native interchain transfers.
* @author Abacus Works
*/
contract AbcERC721 is Router, ERC721Upgradeable {
contract HypERC721 is Router, ERC721EnumerableUpgradeable {
/**
* @dev Emitted on `transferRemote` when a transfer message is dispatched.
* @param destination The identifier of the destination chain.
@ -35,19 +35,27 @@ contract AbcERC721 is Router, ERC721Upgradeable {
);
/**
* @notice Initializes the Abacus router, ERC721 metadata, and mints initial supply to deployer.
* @param _xAppConnectionManager The address of the XAppConnectionManager contract.
* @notice Initializes the Hyperlane router, ERC721 metadata, and mints initial supply to deployer.
* @param _abacusConnectionManager The address of the connection manager contract.
* @param _interchainGasPaymaster The address of the interchain gas paymaster contract.
* @param _mintAmount The amount of NFTs to mint to `msg.sender`.
* @param _name The name of the token.
* @param _symbol The symbol of the token.
*/
function initialize(
address _xAppConnectionManager,
address _abacusConnectionManager,
address _interchainGasPaymaster,
uint256 _mintAmount,
string memory _name,
string memory _symbol
) external initializer {
__Router_initialize(_xAppConnectionManager);
// Set ownable to sender
_transferOwnership(msg.sender);
// Set ACM contract address
_setAbacusConnectionManager(_abacusConnectionManager);
// Set IGP contract address
_setInterchainGasPaymaster(_interchainGasPaymaster);
__ERC721_init(_name, _symbol);
for (uint256 i = 0; i < _mintAmount; i++) {
_mint(msg.sender, i);
@ -69,7 +77,7 @@ contract AbcERC721 is Router, ERC721Upgradeable {
uint256 _tokenId
) external payable {
_burn(_tokenId);
_dispatchWithGasAndCheckpoint(
_dispatchWithGas(
_destination,
abi.encode(_recipient, _tokenId),
msg.value

@ -1,4 +1,4 @@
import '@abacus-network/hardhat';
import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-waffle';
import '@typechain/hardhat';
import 'hardhat-gas-reporter';
@ -9,13 +9,17 @@ import 'solidity-coverage';
*/
module.exports = {
solidity: {
version: '0.8.13',
compilers: [
{
version: '0.8.16',
},
],
},
gasReporter: {
currency: 'USD',
},
typechain: {
outDir: './types',
outDir: './src/types',
target: 'ethers-v5',
alwaysGenerateOverloads: false, // should overloads with full signatures like deposit(uint256) be generated always, even if there are no overloads?
},

@ -1,48 +1,60 @@
{
"name": "@abacus-network/token",
"version": "0.0.0",
"license": "MIT OR Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"directories": {
"test": "test"
},
"scripts": {
"build:contracts": "hardhat compile && hardhat typechain",
"build:sdk": "tsc",
"build": "npm run build:contracts",
"test:contracts": "hardhat test",
"test:sdk": "",
"test": "npm run test:contracts",
"prettier": "prettier --write ./contracts ./test",
"coverage": "hardhat coverage"
},
"name": "@hyperlane-xyz/hyperlane-token",
"description": "A template for interchain ERC20 and ERC721 tokens using Hyperlane",
"version": "0.5.0",
"dependencies": {
"@abacus-network/app": "^0.1.1-alpha2",
"@abacus-network/sdk": "^0.1.1-alpha2",
"@ethersproject/bignumber": "^5.5.0",
"@ethersproject/bytes": "^5.5.0",
"@openzeppelin/contracts-upgradeable": "~4.5.0",
"ethers": "^5.4.7"
"@hyperlane-xyz/sdk": "^0.5.0-beta0",
"@openzeppelin/contracts-upgradeable": "^4.6.0",
"ethers": "^5.6.8"
},
"devDependencies": {
"@abacus-network/hardhat": "^0.1.1-alpha2",
"@nomiclabs/hardhat-ethers": "^2.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@typechain/ethers-v5": "~7.0.0",
"@typechain/hardhat": "^2.0.1",
"@nomiclabs/hardhat-ethers": "^2.0.5",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"@trivago/prettier-plugin-sort-imports": "^3.2.0",
"@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",
"hardhat": "^2.8.3",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"ethereum-waffle": "^3.4.4",
"hardhat": "^2.8.4",
"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.1.0",
"typechain": "^5.0.0",
"typescript": "^4.3.5"
}
"ts-node": "^10.8.0",
"typechain": "8.0.0",
"typescript": "^4.7.2"
},
"files": [
"/dist",
"/contracts"
],
"homepage": "https://www.hyperlane.xyz",
"keywords": [
"Hyperlane",
"Solidity",
"Token"
],
"license": "Apache-2.0",
"main": "dist/index.js",
"packageManager": "yarn@3.2.0",
"repository": {
"type": "git",
"url": "https://github.com/hyperlane-xyz/hyperlane-token"
},
"scripts": {
"clean": "hardhat clean && rm -rf dist cache src/types",
"build": "hardhat compile && tsc",
"coverage": "hardhat coverage",
"lint": "eslint . --ext .ts",
"prettier": "prettier --write ./contracts ./test",
"test": "hardhat test ./test/**/*.test.ts"
},
"types": "dist/index.d.ts"
}

@ -0,0 +1,19 @@
import { ethers } from 'ethers';
import { RouterConfig } from '@hyperlane-xyz/sdk';
export type Erc20TokenConfig = {
name: string;
symbol: string;
totalSupply: ethers.BigNumberish;
};
export type HypERC20Config = RouterConfig & Erc20TokenConfig;
export type Erc721TokenConfig = {
name: string;
symbol: string;
mintAmount: ethers.BigNumberish;
};
export type HypERC721Config = RouterConfig & Erc721TokenConfig;

@ -0,0 +1,24 @@
import { RouterContracts, RouterFactories } from '@hyperlane-xyz/sdk';
import {
HypERC20,
HypERC20__factory,
HypERC721,
HypERC721__factory,
} from './types';
export type HypERC20Factories = RouterFactories<HypERC20>;
export const hypERC20Factories: HypERC20Factories = {
router: new HypERC20__factory(),
};
export type HypERC20Contracts = RouterContracts<HypERC20>;
export type HypERC721Factories = RouterFactories<HypERC721>;
export const hypERC721Factories: HypERC721Factories = {
router: new HypERC721__factory(),
};
export type HypERC721Contracts = RouterContracts<HypERC721>;

@ -0,0 +1,79 @@
import {
ChainMap,
ChainName,
HyperlaneCore,
HyperlaneRouterDeployer,
MultiProvider,
} from '@hyperlane-xyz/sdk';
import { HypERC20Config, HypERC721Config } from './config';
import {
HypERC20Contracts,
HypERC20Factories,
HypERC721Contracts,
HypERC721Factories,
hypERC20Factories,
hypERC721Factories,
} from './contracts';
export class HypERC20Deployer<
Chain extends ChainName,
> extends HyperlaneRouterDeployer<
Chain,
HypERC20Config,
HypERC20Contracts,
HypERC20Factories
> {
constructor(
multiProvider: MultiProvider<Chain>,
configMap: ChainMap<Chain, HypERC20Config>,
protected core: HyperlaneCore<Chain>,
) {
super(multiProvider, configMap, hypERC20Factories);
}
async deployContracts(chain: Chain, config: HypERC20Config) {
const router = await this.deployContract(chain, 'router', []);
await router.initialize(
config.connectionManager,
config.interchainGasPaymaster,
config.totalSupply,
config.name,
config.symbol,
);
return {
router,
};
}
}
export class HypERC721Deployer<
Chain extends ChainName,
> extends HyperlaneRouterDeployer<
Chain,
HypERC721Config,
HypERC721Contracts,
HypERC721Factories
> {
constructor(
multiProvider: MultiProvider<Chain>,
configMap: ChainMap<Chain, HypERC721Config>,
protected core: HyperlaneCore<Chain>,
) {
super(multiProvider, configMap, hypERC721Factories);
}
async deployContracts(chain: Chain, config: HypERC721Config) {
const router = await this.deployContract(chain, 'router', []);
await router.initialize(
config.connectionManager,
config.interchainGasPaymaster,
config.mintAmount,
config.name,
config.symbol,
);
return {
router,
};
}
}

@ -1,32 +0,0 @@
import { TestAbacusDeploy, TestRouterDeploy } from '@abacus-network/hardhat';
import { types } from '@abacus-network/utils';
import { ethers } from 'ethers';
import { AbcERC20, AbcERC20__factory } from '../types';
export type TokenConfig = {
signer: ethers.Signer;
name: string;
symbol: string;
totalSupply: ethers.BigNumberish;
};
export class AbcERC20Deploy extends TestRouterDeploy<AbcERC20, TokenConfig> {
async deployInstance(
domain: types.Domain,
abacus: TestAbacusDeploy,
): Promise<AbcERC20> {
const tokenFactory = new AbcERC20__factory(this.config.signer);
const token = await tokenFactory.deploy();
await token.initialize(
abacus.abacusConnectionManager(domain).address,
this.config.totalSupply,
this.config.name,
this.config.symbol,
);
return token;
}
router(domain: types.Domain) {
return this.instances[domain];
}
}

@ -1,107 +1,138 @@
import { InterchainGasPaymaster, Outbox } from '@abacus-network/core';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import '@nomiclabs/hardhat-waffle';
import { expect } from 'chai';
import { abacus, ethers } from 'hardhat';
import { AbcERC20 } from '../types';
import { AbcERC20Deploy, TokenConfig } from './erc20.deploy';
import { ethers } from 'hardhat';
const localDomain = 1000;
const remoteDomain = 2000;
import {
ChainMap,
ChainNameToDomainId,
TestChainNames,
TestCoreApp,
TestCoreDeployer,
getChainToOwnerMap,
getTestMultiProvider,
objMap,
testChainConnectionConfigs,
} from '@hyperlane-xyz/sdk';
import { Erc20TokenConfig, HypERC20Config } from '../src/config';
import { HypERC20Contracts } from '../src/contracts';
import { HypERC20Deployer } from '../src/deploy';
import { HypERC20 } from '../src/types';
const localChain = 'test1';
const remoteChain = 'test2';
const localDomain = ChainNameToDomainId[localChain];
const remoteDomain = ChainNameToDomainId[remoteChain];
const totalSupply = 3000;
const domains = [localDomain, remoteDomain];
describe('AbcERC20', async () => {
let owner: SignerWithAddress,
recipient: SignerWithAddress,
router: AbcERC20,
remote: AbcERC20,
outbox: Outbox,
interchainGasPaymaster: InterchainGasPaymaster,
token: AbcERC20Deploy;
const testInterchainGasPayment = 123456789;
const amount = 10;
const testInterchainGasPayment = 123456789;
const tokenConfig: Erc20TokenConfig = {
name: 'HypERC20',
symbol: 'HYP',
totalSupply,
};
describe('HypERC20', async () => {
let owner: SignerWithAddress;
let recipient: SignerWithAddress;
let core: TestCoreApp;
let deployer: HypERC20Deployer<TestChainNames>;
let contracts: Record<TestChainNames, HypERC20Contracts>;
let local: HypERC20;
let remote: HypERC20;
before(async () => {
[owner, recipient] = await ethers.getSigners();
await abacus.deploy(domains, owner);
});
const multiProvider = getTestMultiProvider(owner);
beforeEach(async () => {
const config: TokenConfig = {
signer: owner,
name: 'AbcERC20',
symbol: 'ABC',
totalSupply,
};
token = new AbcERC20Deploy(config);
await token.deploy(abacus);
router = token.router(localDomain);
remote = token.router(remoteDomain);
outbox = abacus.outbox(localDomain);
interchainGasPaymaster = abacus.interchainGasPaymaster(localDomain);
const coreDeployer = new TestCoreDeployer(multiProvider);
const coreContractsMaps = await coreDeployer.deploy();
core = new TestCoreApp(coreContractsMaps, multiProvider);
const config = core.extendWithConnectionClientConfig(
getChainToOwnerMap(testChainConnectionConfigs, owner.address),
);
const configWithTokenInfo: ChainMap<TestChainNames, HypERC20Config> =
objMap(config, (key) => ({
...config[key],
...tokenConfig,
}));
deployer = new HypERC20Deployer(multiProvider, configWithTokenInfo, core);
contracts = await deployer.deploy();
local = contracts[localChain].router;
remote = contracts[remoteChain].router;
});
const expectBalance = async (
token: AbcERC20,
signer: SignerWithAddress,
balance: number,
) => expect(await token.balanceOf(signer.address)).to.eq(balance);
const amount = 10;
it('should not be initializable again', async () => {
await expect(
router.initialize(ethers.constants.AddressZero, 0, '', ''),
local.initialize(
ethers.constants.AddressZero,
ethers.constants.AddressZero,
0,
'',
'',
),
).to.be.revertedWith('Initializable: contract is already initialized');
});
it('should mint total supply to deployer', async () => {
await expectBalance(router, recipient, 0);
await expectBalance(router, owner, totalSupply);
await expectBalance(local, recipient, 0);
await expectBalance(local, owner, totalSupply);
await expectBalance(remote, recipient, 0);
await expectBalance(remote, owner, totalSupply);
});
it('should allow for local transfers', async () => {
await router.transfer(recipient.address, amount);
await expectBalance(router, recipient, amount);
await expectBalance(router, owner, totalSupply - amount);
await local.transfer(recipient.address, amount);
await expectBalance(local, recipient, amount);
await expectBalance(local, owner, totalSupply - amount);
await expectBalance(remote, recipient, 0);
await expectBalance(remote, owner, totalSupply);
});
it('should allow for remote transfers', async () => {
await router.transferRemote(remoteDomain, recipient.address, amount);
await local.transferRemote(remoteDomain, recipient.address, amount);
await expectBalance(router, recipient, 0);
await expectBalance(router, owner, totalSupply - amount);
await expectBalance(local, recipient, amount);
await expectBalance(local, owner, totalSupply - amount * 2);
await expectBalance(remote, recipient, 0);
await expectBalance(remote, owner, totalSupply);
await abacus.processMessages();
await core.processMessages();
await expectBalance(router, recipient, 0);
await expectBalance(router, owner, totalSupply - amount);
await expectBalance(local, recipient, amount);
await expectBalance(local, owner, totalSupply - amount * 2);
await expectBalance(remote, recipient, amount);
await expectBalance(remote, owner, totalSupply);
});
it('allows interchain gas payment for remote transfers', async () => {
const outbox = core.getMailboxPair(localChain, remoteChain).originOutbox;
const interchainGasPaymaster =
core.contractsMap[localChain].interchainGasPaymaster.contract;
const leafIndex = await outbox.count();
await expect(
router.transferRemote(remoteDomain, recipient.address, amount, {
local.transferRemote(remoteDomain, recipient.address, amount, {
value: testInterchainGasPayment,
}),
)
.to.emit(interchainGasPaymaster, 'GasPayment')
.withArgs(leafIndex, testInterchainGasPayment);
.withArgs(outbox.address, leafIndex, testInterchainGasPayment);
});
it('should emit TransferRemote events', async () => {
expect(await router.transferRemote(remoteDomain, recipient.address, amount))
.to.emit(router, 'SentTransferRemote')
expect(await local.transferRemote(remoteDomain, recipient.address, amount))
.to.emit(local, 'SentTransferRemote')
.withArgs(remoteDomain, recipient.address, amount);
expect(await abacus.processMessages())
.to.emit(router, 'ReceivedTransferRemote')
expect(await core.processMessages())
.to.emit(local, 'ReceivedTransferRemote')
.withArgs(localDomain, recipient.address, amount);
});
});
const expectBalance = async (
token: HypERC20,
signer: SignerWithAddress,
balance: number,
) => expect(await token.balanceOf(signer.address)).to.eq(balance);

@ -1,37 +0,0 @@
import { TestAbacusDeploy, TestRouterDeploy } from '@abacus-network/hardhat';
import { types } from '@abacus-network/utils';
import { ethers } from 'ethers';
import { AbcERC721, AbcERC721__factory } from '../types';
export type TokenConfig = {
signer: ethers.Signer;
name: string;
symbol: string;
mintAmount: ethers.BigNumberish;
};
type ConfigMap = {
[domain: number]: TokenConfig;
};
export class AbcERC721Deploy extends TestRouterDeploy<AbcERC721, ConfigMap> {
async deployInstance(
domain: types.Domain,
abacus: TestAbacusDeploy,
): Promise<AbcERC721> {
const localConfig = this.config[domain];
const tokenFactory = new AbcERC721__factory(localConfig.signer);
const token = await tokenFactory.deploy();
await token.initialize(
abacus.abacusConnectionManager(domain).address,
localConfig.mintAmount,
localConfig.name,
localConfig.symbol,
);
return token;
}
router(domain: types.Domain) {
return this.instances[domain];
}
}

@ -1,132 +1,168 @@
import { InterchainGasPaymaster, Outbox } from '@abacus-network/core';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import '@nomiclabs/hardhat-waffle';
import { expect } from 'chai';
import { abacus, ethers } from 'hardhat';
import { AbcERC721 } from '../types';
import { AbcERC721Deploy } from './erc721.deploy';
const localDomain = 1000;
const remoteDomain = 2000;
import { ethers } from 'hardhat';
import {
ChainMap,
ChainNameToDomainId,
TestChainNames,
TestCoreApp,
TestCoreDeployer,
getChainToOwnerMap,
getTestMultiProvider,
objMap,
testChainConnectionConfigs,
} from '@hyperlane-xyz/sdk';
import { Erc721TokenConfig, HypERC721Config } from '../src/config';
import { HypERC721Contracts } from '../src/contracts';
import { HypERC721Deployer } from '../src/deploy';
import { HypERC721 } from '../src/types';
const localChain = 'test1';
const remoteChain = 'test2';
const localDomain = ChainNameToDomainId[localChain];
const remoteDomain = ChainNameToDomainId[remoteChain];
const mintAmount = 50;
const domains = [localDomain, remoteDomain];
describe('AbcERC721', async () => {
let owner: SignerWithAddress,
recipient: SignerWithAddress,
router: AbcERC721,
remote: AbcERC721,
outbox: Outbox,
interchainGasPaymaster: InterchainGasPaymaster,
token: AbcERC721Deploy;
const testInterchainGasPayment = 123456789;
const tokenId = 10;
const tokenId2 = 20;
const tokenId3 = 30;
const tokenId4 = 40;
const testInterchainGasPayment = 123456789;
const tokenConfig: Erc721TokenConfig = {
name: 'HypERC721',
symbol: 'HYP',
mintAmount,
};
const configMap = {
test1: {
...tokenConfig,
mintAmount,
},
test2: {
...tokenConfig,
mintAmount: 0,
},
test3: {
...tokenConfig,
mintAmount: 0,
},
};
describe('HypERC721', async () => {
let owner: SignerWithAddress;
let recipient: SignerWithAddress;
let core: TestCoreApp;
let deployer: HypERC721Deployer<TestChainNames>;
let contracts: Record<TestChainNames, HypERC721Contracts>;
let local: HypERC721;
let remote: HypERC721;
before(async () => {
[owner, recipient] = await ethers.getSigners();
await abacus.deploy(domains, owner);
});
beforeEach(async () => {
const defaultConfig = {
signer: owner,
name: 'AbcERC721',
symbol: 'ABC',
};
const configMap = {
[localDomain]: {
...defaultConfig,
mintAmount,
},
[remoteDomain]: {
...defaultConfig,
mintAmount: 0,
},
};
token = new AbcERC721Deploy(configMap);
await token.deploy(abacus);
router = token.router(localDomain);
remote = token.router(remoteDomain);
outbox = abacus.outbox(localDomain);
interchainGasPaymaster = abacus.interchainGasPaymaster(localDomain);
const multiProvider = getTestMultiProvider(owner);
const coreDeployer = new TestCoreDeployer(multiProvider);
const coreContractsMaps = await coreDeployer.deploy();
core = new TestCoreApp(coreContractsMaps, multiProvider);
const coreConfig = core.extendWithConnectionClientConfig(
getChainToOwnerMap(testChainConnectionConfigs, owner.address),
);
const configWithTokenInfo: ChainMap<TestChainNames, HypERC721Config> =
objMap(coreConfig, (key) => ({
...coreConfig[key],
...configMap[key],
}));
deployer = new HypERC721Deployer(multiProvider, configWithTokenInfo, core);
contracts = await deployer.deploy();
local = contracts[localChain].router;
remote = contracts[remoteChain].router;
});
const expectBalance = async (
token: AbcERC721,
signer: SignerWithAddress,
balance: number,
) => expect(await token.balanceOf(signer.address)).to.eq(balance);
const tokenId = mintAmount / 2;
it('should not be initializable again', async () => {
await expect(
router.initialize(ethers.constants.AddressZero, 0, '', ''),
local.initialize(
ethers.constants.AddressZero,
ethers.constants.AddressZero,
0,
'',
'',
),
).to.be.revertedWith('Initializable: contract is already initialized');
});
it('should mint total supply to deployer on local domain', async () => {
await expectBalance(router, recipient, 0);
await expectBalance(router, owner, mintAmount);
await expectBalance(local, recipient, 0);
await expectBalance(local, owner, mintAmount);
await expectBalance(remote, recipient, 0);
await expectBalance(remote, owner, 0);
});
it('should allow for local transfers', async () => {
await router.transferFrom(owner.address, recipient.address, tokenId);
await expectBalance(router, recipient, 1);
await expectBalance(router, owner, mintAmount - 1);
await local.transferFrom(owner.address, recipient.address, tokenId);
await expectBalance(local, recipient, 1);
await expectBalance(local, owner, mintAmount - 1);
await expectBalance(remote, recipient, 0);
await expectBalance(remote, owner, 0);
});
it('should not allow transfers of nonexistent identifiers', async () => {
const invalidTokenId = mintAmount + 1;
const invalidTokenId = mintAmount + 10;
await expect(
router.transferFrom(owner.address, recipient.address, invalidTokenId),
).to.be.revertedWith('ERC721: operator query for nonexistent token');
local.transferFrom(owner.address, recipient.address, invalidTokenId),
).to.be.revertedWith('ERC721: invalid token ID');
await expect(
router.transferRemote(remoteDomain, recipient.address, invalidTokenId),
).to.be.revertedWith('ERC721: owner query for nonexistent token');
local.transferRemote(remoteDomain, recipient.address, invalidTokenId),
).to.be.revertedWith('ERC721: invalid token ID');
});
it('should allow for remote transfers', async () => {
const amount = mintAmount / 10;
for (let id = 0; id < amount; id++) {
await router.transferRemote(remoteDomain, recipient.address, id);
}
await local.transferRemote(remoteDomain, recipient.address, tokenId2);
await expectBalance(router, recipient, 0);
await expectBalance(router, owner, mintAmount - amount);
await expectBalance(local, recipient, 1);
await expectBalance(local, owner, mintAmount - 2);
await expectBalance(remote, recipient, 0);
await expectBalance(remote, owner, 0);
await abacus.processMessages();
await core.processMessages();
await expectBalance(router, recipient, 0);
await expectBalance(router, owner, mintAmount - amount);
await expectBalance(remote, recipient, amount);
await expectBalance(local, recipient, 1);
await expectBalance(local, owner, mintAmount - 2);
await expectBalance(remote, recipient, 1);
await expectBalance(remote, owner, 0);
});
it('allows interchain gas payment for remote transfers', async () => {
const outbox = core.getMailboxPair(localChain, remoteChain).originOutbox;
const interchainGasPaymaster =
core.contractsMap[localChain].interchainGasPaymaster.contract;
const leafIndex = await outbox.count();
await expect(
router.transferRemote(remoteDomain, recipient.address, tokenId, {
local.transferRemote(remoteDomain, recipient.address, tokenId3, {
value: testInterchainGasPayment,
}),
)
.to.emit(interchainGasPaymaster, 'GasPayment')
.withArgs(leafIndex, testInterchainGasPayment);
.withArgs(outbox.address, leafIndex, testInterchainGasPayment);
});
it('should emit TransferRemote events', async () => {
expect(
await router.transferRemote(remoteDomain, recipient.address, tokenId),
await local.transferRemote(remoteDomain, recipient.address, tokenId4),
)
.to.emit(router, 'SentTransferRemote')
.withArgs(remoteDomain, recipient.address, tokenId);
expect(await abacus.processMessages())
.to.emit(router, 'ReceivedTransferRemote')
.withArgs(localDomain, recipient.address, tokenId);
.to.emit(local, 'SentTransferRemote')
.withArgs(remoteDomain, recipient.address, tokenId4);
expect(await core.processMessages())
.to.emit(local, 'ReceivedTransferRemote')
.withArgs(localDomain, recipient.address, tokenId4);
});
});
const expectBalance = async (
token: HypERC721,
signer: SignerWithAddress,
balance: number,
) => expect(await token.balanceOf(signer.address)).to.eq(balance);

@ -10,7 +10,7 @@
"moduleResolution": "node",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitAny": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"preserveSymlinks": true,
@ -19,8 +19,9 @@
"sourceMap": true,
"target": "es6",
"strict": true,
"outDir": "./dist/",
"rootDir": "./src/",
"outDir": "./dist",
"rootDir": "./",
"resolveJsonModule": true
},
"exclude": [
"./node_modules/",
@ -28,7 +29,8 @@
"./types/hardhat.d.ts"
],
"include": [
"./types/*.ts",
"./types/factories/*.ts"
]
"./src",
"./test",
],
"files": ["hardhat.config.ts"]
}

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