Skip to content

Commit

Permalink
Merge branch 'v3' into nambrot/default-gas-policy-2
Browse files Browse the repository at this point in the history
  • Loading branch information
tkporter authored Nov 21, 2023
2 parents c254139 + 874f366 commit e66dbee
Show file tree
Hide file tree
Showing 56 changed files with 720 additions and 388 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

Note this is the branch for Hyperlane v3.

V2 is on the main branch but is eventually being phased out.
V2 is still in operation but is not being actively developed. The code for V2 can be found in the [v2](https://github.com/hyperlane-xyz/hyperlane-monorepo/tree/v2) branch.

V1 has since been deprecated in favor of V2, but if you are looking for code relating to the existing V1 deployments of the `testnet2` or `mainnet` environments, refer to the [v1](https://github.com/hyperlane-xyz/hyperlane-monorepo/tree/v1) branch.
V1 has since been deprecated in favor of V2, but if you are looking for code relating to the existing V1 deployments, refer to the [v1](https://github.com/hyperlane-xyz/hyperlane-monorepo/tree/v1) branch.

## Overview

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"lodash": "^4.17.21",
"recursive-readdir": "^2.2.3",
"underscore": "^1.13",
"undici": "^5.11"
"undici": "^5.11",
"@trivago/prettier-plugin-sort-imports/@babel/parser": "^7.22.7"
}
}
62 changes: 62 additions & 0 deletions solidity/contracts/token/FastHypERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0;

import {HypERC20} from "./HypERC20.sol";

import {TokenRouter} from "./libs/TokenRouter.sol";
import {FastTokenRouter} from "./libs/FastTokenRouter.sol";
import {TokenMessage} from "./libs/TokenMessage.sol";

import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";

/**
* @title Hyperlane ERC20 Token Router that extends ERC20 with remote transfer functionality.
* @author Abacus Works
* @dev Supply on each chain is not constant but the aggregate supply across all chains is.
*/
contract FastHypERC20 is FastTokenRouter, HypERC20 {
constructor(
uint8 __decimals,
address _mailbox
) HypERC20(__decimals, _mailbox) {}

/**
* @dev delegates transfer logic to `_transferTo`.
* @inheritdoc TokenRouter
*/
function _handle(
uint32 _origin,
bytes32 _sender,
bytes calldata _message
) internal virtual override(FastTokenRouter, TokenRouter) {
FastTokenRouter._handle(_origin, _sender, _message);
}

/**
* @dev Mints `_amount` of tokens to `_recipient`.
* @inheritdoc FastTokenRouter
*/
function _fastTransferTo(
address _recipient,
uint256 _amount
) internal override {
_mint(_recipient, _amount);
}

/**
* @dev Burns `_amount` of tokens from `_recipient`.
* @inheritdoc FastTokenRouter
*/
function _fastRecieveFrom(
address _sender,
uint256 _amount
) internal override {
_burn(_sender, _amount);
}

function balanceOf(
address _account
) public view virtual override(TokenRouter, HypERC20) returns (uint256) {
return HypERC20.balanceOf(_account);
}
}
61 changes: 61 additions & 0 deletions solidity/contracts/token/FastHypERC20Collateral.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0;

import {HypERC20Collateral} from "./HypERC20Collateral.sol";
import {TokenRouter} from "./libs/TokenRouter.sol";
import {FastTokenRouter} from "./libs/FastTokenRouter.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/**
* @title Hyperlane ERC20 Token Collateral that wraps an existing ERC20 with remote transfer functionality.
* @author Abacus Works
*/
contract FastHypERC20Collateral is FastTokenRouter, HypERC20Collateral {
using SafeERC20 for IERC20;

/**
* @notice Constructor
* @param erc20 Address of the token to keep as collateral
* @param _mailbox Address of the mailbox address
*/
constructor(
address erc20,
address _mailbox
) HypERC20Collateral(erc20, _mailbox) {}

/**
* @dev delegates transfer logic to `_transferTo`.
* @inheritdoc FastTokenRouter
*/
function _handle(
uint32 _origin,
bytes32 _sender,
bytes calldata _message
) internal virtual override(FastTokenRouter, TokenRouter) {
FastTokenRouter._handle(_origin, _sender, _message);
}

/**
* @dev Transfers `_amount` of `wrappedToken` to `_recipient`.
* @inheritdoc FastTokenRouter
*/
function _fastTransferTo(
address _recipient,
uint256 _amount
) internal override {
wrappedToken.safeTransfer(_recipient, _amount);
}

/**
* @dev Transfers in `_amount` of `wrappedToken` from `_recipient`.
* @inheritdoc FastTokenRouter
*/
function _fastRecieveFrom(
address _sender,
uint256 _amount
) internal override {
wrappedToken.safeTransferFrom(_sender, address(this), _amount);
}
}
4 changes: 2 additions & 2 deletions solidity/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@hyperlane-xyz/core",
"description": "Core solidity contracts for Hyperlane",
"version": "3.1.2",
"version": "3.1.3",
"dependencies": {
"@eth-optimism/contracts": "^0.6.0",
"@hyperlane-xyz/utils": "3.1.2",
"@hyperlane-xyz/utils": "3.1.3",
"@openzeppelin/contracts": "^4.9.3",
"@openzeppelin/contracts-upgradeable": "^v4.9.3"
},
Expand Down
6 changes: 3 additions & 3 deletions typescript/cli/ci-test-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export DEBUG=hyperlane:*

echo "Deploying contracts to anvil1 and anvil2"
yarn workspace @hyperlane-xyz/cli run hyperlane deploy core \
--chain-configs ./examples/anvil-chains.yaml \
--chains anvil1,anvil2 \
--targets anvil1,anvil2 \
--chains ./examples/anvil-chains.yaml \
--artifacts /tmp/empty-artifacts.json \
--out /tmp \
--ism ./examples/multisig-ism.yaml \
--hook ./examples/hook-config.yaml \
--out /tmp \
--key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
--yes

Expand Down
28 changes: 23 additions & 5 deletions typescript/cli/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ do
chmod -R 777 /tmp/relayer /tmp/$CHAIN
done

anvil --chain-id 31337 -p 8545 --state /tmp/anvil1/state > /dev/null &
anvil --chain-id 31338 -p 8555 --state /tmp/anvil2/state > /dev/null &
anvil --chain-id 31337 -p 8545 --state /tmp/anvil1/state --gas-price 1 > /dev/null &
anvil --chain-id 31338 -p 8555 --state /tmp/anvil2/state --gas-price 1 > /dev/null &
sleep 1

set -e
Expand All @@ -28,17 +28,25 @@ echo "{}" > /tmp/empty-artifacts.json

export DEBUG=hyperlane:*

DEPLOYER=$(cast rpc eth_accounts | jq -r '.[0]')
BEFORE=$(cast balance $DEPLOYER --rpc-url http://localhost:8545)

echo "Deploying contracts to anvil1 and anvil2"
yarn workspace @hyperlane-xyz/cli run hyperlane deploy core \
--chain-configs ./examples/anvil-chains.yaml \
--chains anvil1,anvil2 \
--targets anvil1,anvil2 \
--chains ./examples/anvil-chains.yaml \
--artifacts /tmp/empty-artifacts.json \
--out /tmp \
--ism ./examples/multisig-ism.yaml \
--hook ./examples/hook-config.yaml \
--out /tmp \
--key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
--yes

AFTER_CORE=$(cast balance $DEPLOYER --rpc-url http://localhost:8545)
GAS_PRICE=$(cast gas-price --rpc-url http://localhost:8545)
CORE_MIN_GAS=$(bc <<< "($BEFORE - $AFTER_CORE) / $GAS_PRICE")
echo "Gas used: $CORE_MIN_GAS"

CORE_ARTIFACTS_PATH=`find /tmp/core-deployment* -type f -exec ls -t1 {} + | head -1`
echo "Core artifacts:"
echo $CORE_ARTIFACTS_PATH
Expand All @@ -54,6 +62,11 @@ yarn workspace @hyperlane-xyz/cli run hyperlane deploy warp \
--key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
--yes

AFTER_WARP=$(cast balance $DEPLOYER --rpc-url http://localhost:8545)
GAS_PRICE=$(cast gas-price --rpc-url http://localhost:8545)
WARP_MIN_GAS=$(bc <<< "($AFTER_CORE - $AFTER_WARP) / $GAS_PRICE")
echo "Gas used: $WARP_MIN_GAS"

echo "Sending test message"
yarn workspace @hyperlane-xyz/cli run hyperlane send message \
--origin anvil1 \
Expand All @@ -64,6 +77,11 @@ yarn workspace @hyperlane-xyz/cli run hyperlane send message \
--key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
| tee /tmp/message1

AFTER_MSG=$(cast balance $DEPLOYER --rpc-url http://localhost:8545)
GAS_PRICE=$(cast gas-price --rpc-url http://localhost:8545)
MSG_MIN_GAS=$(bc <<< "($AFTER_WARP - $AFTER_MSG) / $GAS_PRICE")
echo "Gas used: $MSG_MIN_GAS"

MESSAGE1_ID=`cat /tmp/message1 | grep "Message ID" | grep -E -o '0x[0-9a-f]+'`
echo "Message 1 ID: $MESSAGE1_ID"

Expand Down
9 changes: 5 additions & 4 deletions typescript/cli/examples/multisig-ism.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
# Valid module types:
# routing
# aggregation
# legacy_multisig
# merkle_root_multisig
# message_id_multisig
# merkleRootMultisig
# messageIdMultisigIsm

# ism type don't work currently (sets to messageIdMultisigIsm for all)
---
anvil1:
type: 'merkleRootMultisigIsm'
type: 'messageIdMultisigIsm'
threshold: 1 # Number: Signatures required to approve a message
validators: # Array: List of validator addresses
- '0xa0ee7a142d267c1f36714e4a8f75612f20a79720'
Expand Down
4 changes: 2 additions & 2 deletions typescript/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@hyperlane-xyz/cli",
"version": "3.1.2",
"version": "3.1.3",
"description": "A command-line utility for common Hyperlane operations",
"dependencies": {
"@hyperlane-xyz/sdk": "3.1.2",
"@hyperlane-xyz/sdk": "3.1.3",
"@inquirer/prompts": "^3.0.0",
"bignumber.js": "^9.1.1",
"chalk": "^5.3.0",
Expand Down
20 changes: 10 additions & 10 deletions typescript/cli/src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommandModule } from 'yargs';

import { log, logGreen } from '../../logger.js';
import { createChainConfig, readChainConfig } from '../config/chain.js';
import { createChainConfig, readChainConfigs } from '../config/chain.js';
import { createHookConfig } from '../config/hooks.js';
import {
createMultisigConfig,
Expand Down Expand Up @@ -39,21 +39,21 @@ const createCommand: CommandModule = {
describe: 'Create a new Hyperlane config',
builder: (yargs) =>
yargs
.command(createChainCommand)
.command(createMultisigCommand)
.command(createChainConfigCommand)
.command(createMultisigConfigCommand)
.command(createHookConfigCommand)
.command(createWarpCommand)
.command(createWarpConfigCommand)
.version(false)
.demandCommand(),
handler: () => log('Command required'),
};

const createChainCommand: CommandModule = {
const createChainConfigCommand: CommandModule = {
command: 'chain',
describe: 'Create a new, minimal Hyperlane chain config (aka chain metadata)',
builder: (yargs) =>
yargs.options({
output: outputFileOption('./configs/chain-config.yaml'),
output: outputFileOption('./configs/chains.yaml'),
format: fileFormatOption,
}),
handler: async (argv: any) => {
Expand All @@ -64,7 +64,7 @@ const createChainCommand: CommandModule = {
},
};

const createMultisigCommand: CommandModule = {
const createMultisigConfigCommand: CommandModule = {
command: 'multisig',
describe: 'Create a new Multisig ISM config',
builder: (yargs) =>
Expand All @@ -87,7 +87,7 @@ const createHookConfigCommand: CommandModule = {
describe: 'Create a new Hook config',
builder: (yargs) =>
yargs.options({
output: outputFileOption('./configs/hook-config.yaml'),
output: outputFileOption('./configs/hooks.yaml'),
format: fileFormatOption,
chains: chainsCommandOption,
}),
Expand All @@ -100,7 +100,7 @@ const createHookConfigCommand: CommandModule = {
},
};

const createWarpCommand: CommandModule = {
const createWarpConfigCommand: CommandModule = {
command: 'warp',
describe: 'Create a new Warp Route tokens config',
builder: (yargs) =>
Expand Down Expand Up @@ -147,7 +147,7 @@ const validateChainCommand: CommandModule = {
}),
handler: async (argv) => {
const path = argv.path as string;
readChainConfig(path);
readChainConfigs(path);
process.exit(0);
},
};
Expand Down
21 changes: 11 additions & 10 deletions typescript/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ const coreCommand: CommandModule = {
describe: 'Deploy core Hyperlane contracts',
builder: (yargs) =>
yargs.options({
key: keyCommandOption,
'chain-configs': chainsCommandOption,
chains: {
targets: {
type: 'string',
description:
'Comma separated list of chain names to which contracts will be deployed',
},
out: outDirCommandOption,
chains: chainsCommandOption,
artifacts: coreArtifactsOption,
ism: {
type: 'string',
Expand All @@ -54,15 +52,17 @@ const coreCommand: CommandModule = {
description:
'A path to a JSON or YAML file with Hook configs (for every chain)',
},
out: outDirCommandOption,
key: keyCommandOption,
yes: skipConfirmationOption,
}),
handler: async (argv: any) => {
logGray('Hyperlane permissionless core deployment');
logGray('----------------------------------------');
const key: string = argv.key || process.env.HYP_KEY;
const chainConfigPath: string = argv['chain-configs'];
const chainConfigPath: string = argv.chains;
const outPath: string = argv.out;
const chains: string[] | undefined = argv.chains
const chains: string[] | undefined = argv.targets
?.split(',')
.map((r: string) => r.trim());
const artifactsPath: string = argv.artifacts;
Expand Down Expand Up @@ -91,14 +91,15 @@ const warpCommand: CommandModule = {
describe: 'Deploy Warp Route contracts',
builder: (yargs) =>
yargs.options({
key: keyCommandOption,
chains: chainsCommandOption,
out: outDirCommandOption,
core: coreArtifactsOption,
config: {
type: 'string',
description: 'A path to a JSON or YAML file with a warp config.',
default: './configs/warp-tokens.yaml',
},
core: coreArtifactsOption,
chains: chainsCommandOption,
out: outDirCommandOption,
key: keyCommandOption,
yes: skipConfirmationOption,
}),
handler: async (argv: any) => {
Expand Down
Loading

0 comments on commit e66dbee

Please sign in to comment.