Rename to LiquidityLayer (#1277)

pull/1285/head
Nam Chu Hoai 2 years ago committed by GitHub
parent 0c6e91b914
commit 58492691c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      solidity/contracts/middleware/liquidity-layer/LiquidityLayerRouter.sol
  2. 24
      solidity/contracts/middleware/liquidity-layer/adapters/CircleBridgeAdapter.sol
  3. 2
      solidity/contracts/middleware/liquidity-layer/interfaces/ILiquidityLayerAdapter.sol
  4. 2
      solidity/contracts/middleware/liquidity-layer/interfaces/ILiquidityLayerMessageRecipient.sol
  5. 0
      solidity/contracts/middleware/liquidity-layer/interfaces/circle/ICircleBridge.sol
  6. 0
      solidity/contracts/middleware/liquidity-layer/interfaces/circle/ICircleMessageTransmitter.sol
  7. 2
      solidity/contracts/mock/MockCircleBridge.sol
  8. 2
      solidity/contracts/mock/MockCircleMessageTransmitter.sol
  9. 4
      solidity/contracts/test/TestLiquidityLayerMessageRecipient.sol
  10. 4
      solidity/contracts/test/TestTokenRecipient.sol
  11. 66
      solidity/test/LiquidityLayerRouter.t.sol
  12. 0
      typescript/infra/config/environments/testnet2/liquidityLayer.ts
  13. 0
      typescript/infra/config/environments/testnet2/middleware/liquidity-layer/addresses.json
  14. 0
      typescript/infra/config/environments/testnet2/middleware/liquidity-layer/verification.json
  15. 14
      typescript/infra/scripts/circle-relayer.ts
  16. 14
      typescript/infra/scripts/middleware/deploy-liquidity-layer.ts
  17. 10
      typescript/sdk/src/deploy/middleware/LiquidityLayerApp.ts
  18. 44
      typescript/sdk/src/deploy/middleware/LiquidityLayerRouterDeployer.ts
  19. 10
      typescript/sdk/src/index.ts
  20. 12
      typescript/sdk/src/middleware.ts
  21. 36
      typescript/sdk/src/middleware/liquidity-layer.hardhat-test.ts

@ -6,18 +6,18 @@ import {Router} from "../../Router.sol";
import {IMessageRecipient} from "../../../interfaces/IMessageRecipient.sol"; import {IMessageRecipient} from "../../../interfaces/IMessageRecipient.sol";
import {ICircleBridge} from "./interfaces/circle/ICircleBridge.sol"; import {ICircleBridge} from "./interfaces/circle/ICircleBridge.sol";
import {ICircleMessageTransmitter} from "./interfaces/circle/ICircleMessageTransmitter.sol"; import {ICircleMessageTransmitter} from "./interfaces/circle/ICircleMessageTransmitter.sol";
import {ITokenBridgeAdapter} from "./interfaces/ITokenBridgeAdapter.sol"; import {ILiquidityLayerAdapter} from "./interfaces/ILiquidityLayerAdapter.sol";
import {ITokenBridgeMessageRecipient} from "./interfaces/ITokenBridgeMessageRecipient.sol"; import {ILiquidityLayerMessageRecipient} from "./interfaces/ILiquidityLayerMessageRecipient.sol";
import {TypeCasts} from "../../libs/TypeCasts.sol"; import {TypeCasts} from "../../libs/TypeCasts.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract TokenBridgeRouter is Router { contract LiquidityLayerRouter is Router {
// Token bridge => adapter address // Token bridge => adapter address
mapping(string => address) public tokenBridgeAdapters; mapping(string => address) public liquidityLayerAdapters;
event TokenBridgeAdapterSet(string indexed bridge, address adapter); event LiquidityLayerAdapterSet(string indexed bridge, address adapter);
function initialize( function initialize(
address _owner, address _owner,
@ -40,7 +40,7 @@ contract TokenBridgeRouter is Router {
uint256 _amount, uint256 _amount,
string calldata _bridge string calldata _bridge
) external payable { ) external payable {
ITokenBridgeAdapter _adapter = _getAdapter(_bridge); ILiquidityLayerAdapter _adapter = _getAdapter(_bridge);
// Transfer the tokens to the adapter // Transfer the tokens to the adapter
// TODO: use safeTransferFrom // TODO: use safeTransferFrom
@ -70,11 +70,11 @@ contract TokenBridgeRouter is Router {
_messageBody // The "user" message _messageBody // The "user" message
); );
// Dispatch the _messageWithMetadata to the destination's TokenBridgeRouter. // Dispatch the _messageWithMetadata to the destination's LiquidityLayerRouter.
_dispatchWithGas(_destinationDomain, _messageWithMetadata, msg.value); _dispatchWithGas(_destinationDomain, _messageWithMetadata, msg.value);
} }
// Handles a message from an enrolled remote TokenBridgeRouter // Handles a message from an enrolled remote LiquidityLayerRouter
function _handle( function _handle(
uint32 _origin, uint32 _origin,
bytes32, // _sender, unused bytes32, // _sender, unused
@ -93,7 +93,7 @@ contract TokenBridgeRouter is Router {
(bytes32, bytes32, uint256, string, bytes, bytes) (bytes32, bytes32, uint256, string, bytes, bytes)
); );
ITokenBridgeMessageRecipient _userRecipient = ITokenBridgeMessageRecipient( ILiquidityLayerMessageRecipient _userRecipient = ILiquidityLayerMessageRecipient(
TypeCasts.bytes32ToAddress(_userRecipientAddress) TypeCasts.bytes32ToAddress(_userRecipientAddress)
); );
@ -115,20 +115,20 @@ contract TokenBridgeRouter is Router {
); );
} }
function setTokenBridgeAdapter(string calldata _bridge, address _adapter) function setLiquidityLayerAdapter(string calldata _bridge, address _adapter)
external external
onlyOwner onlyOwner
{ {
tokenBridgeAdapters[_bridge] = _adapter; liquidityLayerAdapters[_bridge] = _adapter;
emit TokenBridgeAdapterSet(_bridge, _adapter); emit LiquidityLayerAdapterSet(_bridge, _adapter);
} }
function _getAdapter(string memory _bridge) function _getAdapter(string memory _bridge)
internal internal
view view
returns (ITokenBridgeAdapter _adapter) returns (ILiquidityLayerAdapter _adapter)
{ {
_adapter = ITokenBridgeAdapter(tokenBridgeAdapters[_bridge]); _adapter = ILiquidityLayerAdapter(liquidityLayerAdapters[_bridge]);
// Require the adapter to have been set // Require the adapter to have been set
require(address(_adapter) != address(0), "No adapter found for bridge"); require(address(_adapter) != address(0), "No adapter found for bridge");
} }

@ -5,19 +5,19 @@ import {Router} from "../../../Router.sol";
import {ICircleBridge} from "../interfaces/circle/ICircleBridge.sol"; import {ICircleBridge} from "../interfaces/circle/ICircleBridge.sol";
import {ICircleMessageTransmitter} from "../interfaces/circle/ICircleMessageTransmitter.sol"; import {ICircleMessageTransmitter} from "../interfaces/circle/ICircleMessageTransmitter.sol";
import {ITokenBridgeAdapter} from "../interfaces/ITokenBridgeAdapter.sol"; import {ILiquidityLayerAdapter} from "../interfaces/ILiquidityLayerAdapter.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract CircleBridgeAdapter is ITokenBridgeAdapter, Router { contract CircleBridgeAdapter is ILiquidityLayerAdapter, Router {
/// @notice The CircleBridge contract. /// @notice The CircleBridge contract.
ICircleBridge public circleBridge; ICircleBridge public circleBridge;
/// @notice The Circle MessageTransmitter contract. /// @notice The Circle MessageTransmitter contract.
ICircleMessageTransmitter public circleMessageTransmitter; ICircleMessageTransmitter public circleMessageTransmitter;
/// @notice The TokenBridgeRouter contract. /// @notice The LiquidityLayerRouter contract.
address public tokenBridgeRouter; address public liquidityLayerRouter;
/// @notice Hyperlane domain => Circle domain. /// @notice Hyperlane domain => Circle domain.
/// ATM, known Circle domains are Ethereum = 0 and Avalanche = 1. /// ATM, known Circle domains are Ethereum = 0 and Avalanche = 1.
@ -54,8 +54,8 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
*/ */
event TokenRemoved(address indexed token, string indexed symbol); event TokenRemoved(address indexed token, string indexed symbol);
modifier onlyTokenBridgeRouter() { modifier onlyLiquidityLayerRouter() {
require(msg.sender == tokenBridgeRouter, "!tokenBridgeRouter"); require(msg.sender == liquidityLayerRouter, "!liquidityLayerRouter");
_; _;
} }
@ -63,13 +63,13 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
* @param _owner The new owner. * @param _owner The new owner.
* @param _circleBridge The CircleBridge contract. * @param _circleBridge The CircleBridge contract.
* @param _circleMessageTransmitter The Circle MessageTransmitter contract. * @param _circleMessageTransmitter The Circle MessageTransmitter contract.
* @param _tokenBridgeRouter The TokenBridgeRouter contract. * @param _liquidityLayerRouter The LiquidityLayerRouter contract.
*/ */
function initialize( function initialize(
address _owner, address _owner,
address _circleBridge, address _circleBridge,
address _circleMessageTransmitter, address _circleMessageTransmitter,
address _tokenBridgeRouter address _liquidityLayerRouter
) public initializer { ) public initializer {
// Transfer ownership of the contract to deployer // Transfer ownership of the contract to deployer
_transferOwnership(_owner); _transferOwnership(_owner);
@ -82,7 +82,7 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
circleMessageTransmitter = ICircleMessageTransmitter( circleMessageTransmitter = ICircleMessageTransmitter(
_circleMessageTransmitter _circleMessageTransmitter
); );
tokenBridgeRouter = _tokenBridgeRouter; liquidityLayerRouter = _liquidityLayerRouter;
} }
function sendTokens( function sendTokens(
@ -90,7 +90,7 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
bytes32, // _recipientAddress, unused bytes32, // _recipientAddress, unused
address _token, address _token,
uint256 _amount uint256 _amount
) external onlyTokenBridgeRouter returns (bytes memory) { ) external onlyLiquidityLayerRouter returns (bytes memory) {
string memory _tokenSymbol = tokenAddressToSymbol[_token]; string memory _tokenSymbol = tokenAddressToSymbol[_token];
require( require(
bytes(_tokenSymbol).length > 0, bytes(_tokenSymbol).length > 0,
@ -106,7 +106,7 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
"CircleBridgeAdapter: No router for domain" "CircleBridgeAdapter: No router for domain"
); );
// Approve the token to Circle. We assume that the TokenBridgeRouter // Approve the token to Circle. We assume that the LiquidityLayerRouter
// has already transferred the token to this contract. // has already transferred the token to this contract.
require( require(
IERC20(_token).approve(address(circleBridge), _amount), IERC20(_token).approve(address(circleBridge), _amount),
@ -130,7 +130,7 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
address _recipient, address _recipient,
uint256 _amount, uint256 _amount,
bytes calldata _adapterData // The adapter data from the message bytes calldata _adapterData // The adapter data from the message
) external onlyTokenBridgeRouter returns (address, uint256) { ) external onlyLiquidityLayerRouter returns (address, uint256) {
// The origin Circle domain // The origin Circle domain
uint32 _originCircleDomain = hyperlaneDomainToCircleDomain[ uint32 _originCircleDomain = hyperlaneDomainToCircleDomain[
_originDomain _originDomain

@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
interface ITokenBridgeAdapter { interface ILiquidityLayerAdapter {
function sendTokens( function sendTokens(
uint32 _destinationDomain, uint32 _destinationDomain,
bytes32 _recipientAddress, bytes32 _recipientAddress,

@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
interface ITokenBridgeMessageRecipient { interface ILiquidityLayerMessageRecipient {
function handleWithTokens( function handleWithTokens(
uint32 _origin, uint32 _origin,
bytes32 _sender, bytes32 _sender,

@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
import {ICircleBridge} from "../middleware/token-bridge/interfaces/circle/ICircleBridge.sol"; import {ICircleBridge} from "../middleware/liquidity-layer/interfaces/circle/ICircleBridge.sol";
import {MockToken} from "./MockToken.sol"; import {MockToken} from "./MockToken.sol";
contract MockCircleBridge is ICircleBridge { contract MockCircleBridge is ICircleBridge {

@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
import {ICircleMessageTransmitter} from "../middleware/token-bridge/interfaces/circle/ICircleMessageTransmitter.sol"; import {ICircleMessageTransmitter} from "../middleware/liquidity-layer/interfaces/circle/ICircleMessageTransmitter.sol";
import {MockToken} from "./MockToken.sol"; import {MockToken} from "./MockToken.sol";
contract MockCircleMessageTransmitter is ICircleMessageTransmitter { contract MockCircleMessageTransmitter is ICircleMessageTransmitter {

@ -1,9 +1,9 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
import {ITokenBridgeMessageRecipient} from "../middleware/token-bridge/interfaces/ITokenBridgeMessageRecipient.sol"; import {ILiquidityLayerMessageRecipient} from "../middleware/liquidity-layer/interfaces/ILiquidityLayerMessageRecipient.sol";
contract TestTokenBridgeMessageRecipient is ITokenBridgeMessageRecipient { contract TestLiquidityLayerMessageRecipient is ILiquidityLayerMessageRecipient {
event HandledWithTokens( event HandledWithTokens(
uint32 origin, uint32 origin,
bytes32 sender, bytes32 sender,

@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0; pragma solidity >=0.8.0;
import {ITokenBridgeMessageRecipient} from "../middleware/token-bridge/interfaces/ITokenBridgeMessageRecipient.sol"; import {ILiquidityLayerMessageRecipient} from "../middleware/liquidity-layer/interfaces/ILiquidityLayerMessageRecipient.sol";
contract TestTokenRecipient is ITokenBridgeMessageRecipient { contract TestTokenRecipient is ILiquidityLayerMessageRecipient {
bytes32 public lastSender; bytes32 public lastSender;
bytes public lastData; bytes public lastData;
address public lastToken; address public lastToken;

@ -2,8 +2,8 @@
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
import "forge-std/Test.sol"; import "forge-std/Test.sol";
import {TokenBridgeRouter} from "../contracts/middleware/token-bridge/TokenBridgeRouter.sol"; import {LiquidityLayerRouter} from "../contracts/middleware/liquidity-layer/LiquidityLayerRouter.sol";
import {CircleBridgeAdapter} from "../contracts/middleware/token-bridge/adapters/CircleBridgeAdapter.sol"; import {CircleBridgeAdapter} from "../contracts/middleware/liquidity-layer/adapters/CircleBridgeAdapter.sol";
import {MockToken} from "../contracts/mock/MockToken.sol"; import {MockToken} from "../contracts/mock/MockToken.sol";
import {TestTokenRecipient} from "../contracts/test/TestTokenRecipient.sol"; import {TestTokenRecipient} from "../contracts/test/TestTokenRecipient.sol";
import {MockCircleMessageTransmitter} from "../contracts/mock/MockCircleMessageTransmitter.sol"; import {MockCircleMessageTransmitter} from "../contracts/mock/MockCircleMessageTransmitter.sol";
@ -12,11 +12,11 @@ import {MockHyperlaneEnvironment} from "../contracts/mock/MockHyperlaneEnvironme
import {TypeCasts} from "../contracts/libs/TypeCasts.sol"; import {TypeCasts} from "../contracts/libs/TypeCasts.sol";
contract TokenBridgeRouterTest is Test { contract LiquidityLayerRouterTest is Test {
MockHyperlaneEnvironment testEnvironment; MockHyperlaneEnvironment testEnvironment;
TokenBridgeRouter originTokenBridgeRouter; LiquidityLayerRouter originLiquidityLayerRouter;
TokenBridgeRouter destinationTokenBridgeRouter; LiquidityLayerRouter destinationLiquidityLayerRouter;
MockCircleMessageTransmitter messageTransmitter; MockCircleMessageTransmitter messageTransmitter;
MockCircleBridge circleBridge; MockCircleBridge circleBridge;
@ -33,7 +33,7 @@ contract TokenBridgeRouterTest is Test {
bytes messageBody = hex"beefdead"; bytes messageBody = hex"beefdead";
uint256 amount = 420000; uint256 amount = 420000;
event TokenBridgeAdapterSet(string indexed bridge, address adapter); event LiquidityLayerAdapterSet(string indexed bridge, address adapter);
function setUp() public { function setUp() public {
token = new MockToken(); token = new MockToken();
@ -45,8 +45,8 @@ contract TokenBridgeRouterTest is Test {
recipient = new TestTokenRecipient(); recipient = new TestTokenRecipient();
originTokenBridgeRouter = new TokenBridgeRouter(); originLiquidityLayerRouter = new LiquidityLayerRouter();
destinationTokenBridgeRouter = new TokenBridgeRouter(); destinationLiquidityLayerRouter = new LiquidityLayerRouter();
testEnvironment = new MockHyperlaneEnvironment( testEnvironment = new MockHyperlaneEnvironment(
originDomain, originDomain,
@ -54,38 +54,38 @@ contract TokenBridgeRouterTest is Test {
); );
// TODO: set IGP? // TODO: set IGP?
originTokenBridgeRouter.initialize( originLiquidityLayerRouter.initialize(
address(this), address(this),
address(testEnvironment.connectionManager(originDomain)), address(testEnvironment.connectionManager(originDomain)),
address(0) address(0)
); );
destinationTokenBridgeRouter.initialize( destinationLiquidityLayerRouter.initialize(
address(this), address(this),
address(testEnvironment.connectionManager(destinationDomain)), address(testEnvironment.connectionManager(destinationDomain)),
address(0) address(0)
); );
originTokenBridgeRouter.enrollRemoteRouter( originLiquidityLayerRouter.enrollRemoteRouter(
destinationDomain, destinationDomain,
TypeCasts.addressToBytes32(address(destinationTokenBridgeRouter)) TypeCasts.addressToBytes32(address(destinationLiquidityLayerRouter))
); );
destinationTokenBridgeRouter.enrollRemoteRouter( destinationLiquidityLayerRouter.enrollRemoteRouter(
originDomain, originDomain,
TypeCasts.addressToBytes32(address(originTokenBridgeRouter)) TypeCasts.addressToBytes32(address(originLiquidityLayerRouter))
); );
originBridgeAdapter.initialize( originBridgeAdapter.initialize(
address(this), address(this),
address(circleBridge), address(circleBridge),
address(messageTransmitter), address(messageTransmitter),
address(originTokenBridgeRouter) address(originLiquidityLayerRouter)
); );
destinationBridgeAdapter.initialize( destinationBridgeAdapter.initialize(
address(this), address(this),
address(circleBridge), address(circleBridge),
address(messageTransmitter), address(messageTransmitter),
address(destinationTokenBridgeRouter) address(destinationLiquidityLayerRouter)
); );
originBridgeAdapter.addToken(address(token), "USDC"); originBridgeAdapter.addToken(address(token), "USDC");
@ -100,12 +100,12 @@ contract TokenBridgeRouterTest is Test {
TypeCasts.addressToBytes32(address(originBridgeAdapter)) TypeCasts.addressToBytes32(address(originBridgeAdapter))
); );
originTokenBridgeRouter.setTokenBridgeAdapter( originLiquidityLayerRouter.setLiquidityLayerAdapter(
bridge, bridge,
address(originBridgeAdapter) address(originBridgeAdapter)
); );
destinationTokenBridgeRouter.setTokenBridgeAdapter( destinationLiquidityLayerRouter.setLiquidityLayerAdapter(
bridge, bridge,
address(destinationBridgeAdapter) address(destinationBridgeAdapter)
); );
@ -113,21 +113,21 @@ contract TokenBridgeRouterTest is Test {
token.mint(address(this), amount); token.mint(address(this), amount);
} }
function testSetTokenBridgeAdapter() public { function testSetLiquidityLayerAdapter() public {
// Expect the TokenBridgeAdapterSet event. // Expect the LiquidityLayerAdapterSet event.
// Expect topic0 & data to match // Expect topic0 & data to match
vm.expectEmit(true, false, false, true); vm.expectEmit(true, false, false, true);
emit TokenBridgeAdapterSet(bridge, address(originBridgeAdapter)); emit LiquidityLayerAdapterSet(bridge, address(originBridgeAdapter));
// Set the token bridge adapter // Set the token bridge adapter
originTokenBridgeRouter.setTokenBridgeAdapter( originLiquidityLayerRouter.setLiquidityLayerAdapter(
bridge, bridge,
address(originBridgeAdapter) address(originBridgeAdapter)
); );
// Expect the bridge adapter to have been set // Expect the bridge adapter to have been set
assertEq( assertEq(
originTokenBridgeRouter.tokenBridgeAdapters(bridge), originLiquidityLayerRouter.liquidityLayerAdapters(bridge),
address(originBridgeAdapter) address(originBridgeAdapter)
); );
} }
@ -136,7 +136,7 @@ contract TokenBridgeRouterTest is Test {
function testDispatchWithTokensRevertsWithUnkownBridgeAdapter() public { function testDispatchWithTokensRevertsWithUnkownBridgeAdapter() public {
vm.expectRevert("No adapter found for bridge"); vm.expectRevert("No adapter found for bridge");
originTokenBridgeRouter.dispatchWithTokens( originLiquidityLayerRouter.dispatchWithTokens(
destinationDomain, destinationDomain,
TypeCasts.addressToBytes32(address(recipient)), TypeCasts.addressToBytes32(address(recipient)),
messageBody, messageBody,
@ -148,7 +148,7 @@ contract TokenBridgeRouterTest is Test {
function testDispatchWithTokensRevertsWithFailedTransferIn() public { function testDispatchWithTokensRevertsWithFailedTransferIn() public {
vm.expectRevert("ERC20: insufficient allowance"); vm.expectRevert("ERC20: insufficient allowance");
originTokenBridgeRouter.dispatchWithTokens( originLiquidityLayerRouter.dispatchWithTokens(
destinationDomain, destinationDomain,
TypeCasts.addressToBytes32(address(recipient)), TypeCasts.addressToBytes32(address(recipient)),
messageBody, messageBody,
@ -159,8 +159,8 @@ contract TokenBridgeRouterTest is Test {
} }
function testDispatchWithTokenTransfersMovesTokens() public { function testDispatchWithTokenTransfersMovesTokens() public {
token.approve(address(originTokenBridgeRouter), amount); token.approve(address(originLiquidityLayerRouter), amount);
originTokenBridgeRouter.dispatchWithTokens( originLiquidityLayerRouter.dispatchWithTokens(
destinationDomain, destinationDomain,
TypeCasts.addressToBytes32(address(recipient)), TypeCasts.addressToBytes32(address(recipient)),
messageBody, messageBody,
@ -181,8 +181,8 @@ contract TokenBridgeRouterTest is Test {
amount amount
) )
); );
token.approve(address(originTokenBridgeRouter), amount); token.approve(address(originLiquidityLayerRouter), amount);
originTokenBridgeRouter.dispatchWithTokens( originLiquidityLayerRouter.dispatchWithTokens(
destinationDomain, destinationDomain,
TypeCasts.addressToBytes32(address(recipient)), TypeCasts.addressToBytes32(address(recipient)),
messageBody, messageBody,
@ -193,8 +193,8 @@ contract TokenBridgeRouterTest is Test {
} }
function testProcessingRevertsIfBridgeAdapterReverts() public { function testProcessingRevertsIfBridgeAdapterReverts() public {
token.approve(address(originTokenBridgeRouter), amount); token.approve(address(originLiquidityLayerRouter), amount);
originTokenBridgeRouter.dispatchWithTokens( originLiquidityLayerRouter.dispatchWithTokens(
destinationDomain, destinationDomain,
TypeCasts.addressToBytes32(address(recipient)), TypeCasts.addressToBytes32(address(recipient)),
messageBody, messageBody,
@ -208,8 +208,8 @@ contract TokenBridgeRouterTest is Test {
} }
function testDispatchWithTokensTransfersOnDestination() public { function testDispatchWithTokensTransfersOnDestination() public {
token.approve(address(originTokenBridgeRouter), amount); token.approve(address(originLiquidityLayerRouter), amount);
originTokenBridgeRouter.dispatchWithTokens( originLiquidityLayerRouter.dispatchWithTokens(
destinationDomain, destinationDomain,
TypeCasts.addressToBytes32(address(recipient)), TypeCasts.addressToBytes32(address(recipient)),
messageBody, messageBody,

@ -3,13 +3,13 @@ import path from 'path';
import { import {
ChainMap, ChainMap,
Chains, Chains,
TokenBridgeApp, LiquidityLayerApp,
buildContracts, buildContracts,
liquidityLayerFactories,
objMap, objMap,
tokenBridgeFactories,
} from '@hyperlane-xyz/sdk'; } from '@hyperlane-xyz/sdk';
import { circleBridgeAdapterConfig } from '../config/environments/testnet2/token-bridge'; import { circleBridgeAdapterConfig } from '../config/environments/testnet2/liquidityLayer';
import { readJSON, sleep } from '../src/utils/utils'; import { readJSON, sleep } from '../src/utils/utils';
import { import {
@ -26,15 +26,15 @@ async function check() {
__dirname, __dirname,
'../', '../',
getEnvironmentDirectory(environment), getEnvironmentDirectory(environment),
'middleware/token-bridge', 'middleware/liquidity-layer',
); );
const addresses = readJSON(dir, 'addresses.json'); const addresses = readJSON(dir, 'addresses.json');
// @ts-ignore // @ts-ignore
const contracts: ChainMap<any, TokenBridgeContracts> = buildContracts( const contracts: ChainMap<any, LiquidityLayerContracts> = buildContracts(
addresses, addresses,
tokenBridgeFactories, liquidityLayerFactories,
); );
const app = new TokenBridgeApp( const app = new LiquidityLayerApp(
contracts, contracts,
multiProvider, multiProvider,
objMap(circleBridgeAdapterConfig, (_chain, conf) => [conf]), objMap(circleBridgeAdapterConfig, (_chain, conf) => [conf]),

@ -2,12 +2,12 @@ import path from 'path';
import { import {
HyperlaneCore, HyperlaneCore,
TokenBridgeDeployer, LiquidityLayerDeployer,
liquidityLayerFactories,
objMap, objMap,
tokenBridgeFactories,
} from '@hyperlane-xyz/sdk'; } from '@hyperlane-xyz/sdk';
import { circleBridgeAdapterConfig } from '../../config/environments/testnet2/token-bridge'; import { circleBridgeAdapterConfig } from '../../config/environments/testnet2/liquidityLayer';
import { deployWithArtifacts } from '../../src/deploy'; import { deployWithArtifacts } from '../../src/deploy';
import { getConfiguration } from '../helloworld/utils'; import { getConfiguration } from '../helloworld/utils';
import { import {
@ -24,23 +24,23 @@ async function main() {
const dir = path.join( const dir = path.join(
getEnvironmentDirectory(environment), getEnvironmentDirectory(environment),
'middleware/token-bridge', 'middleware/liquidity-layer',
); );
// config gcp deployer key as owner // config gcp deployer key as owner
const ownerConfigMap = await getConfiguration(environment, multiProvider); const ownerConfigMap = await getConfiguration(environment, multiProvider);
const deployer = new TokenBridgeDeployer( const deployer = new LiquidityLayerDeployer(
multiProvider, multiProvider,
objMap(circleBridgeAdapterConfig, (chain, conf) => ({ objMap(circleBridgeAdapterConfig, (chain, conf) => ({
bridgeAdapterConfigs: [conf], bridgeAdapterConfigs: [conf],
...ownerConfigMap[chain], ...ownerConfigMap[chain],
})), })),
core, core,
'TokenBridgeDeploy2', 'LiquidityLayerDeploy2',
); );
await deployWithArtifacts(dir, tokenBridgeFactories, deployer); await deployWithArtifacts(dir, liquidityLayerFactories, deployer);
} }
main() main()

@ -9,7 +9,7 @@ import {
import { HyperlaneApp } from '../../HyperlaneApp'; import { HyperlaneApp } from '../../HyperlaneApp';
import { Chains } from '../../consts/chains'; import { Chains } from '../../consts/chains';
import { TokenBridgeContracts } from '../../middleware'; import { LiquidityLayerContracts } from '../../middleware';
import { MultiProvider } from '../../providers/MultiProvider'; import { MultiProvider } from '../../providers/MultiProvider';
import { ChainMap, ChainName } from '../../types'; import { ChainMap, ChainName } from '../../types';
import { objMap } from '../../utils/objects'; import { objMap } from '../../utils/objects';
@ -18,7 +18,7 @@ import {
BridgeAdapterConfig, BridgeAdapterConfig,
BridgeAdapterType, BridgeAdapterType,
CircleBridgeAdapterConfig, CircleBridgeAdapterConfig,
} from './TokenBridgeRouterDeployer'; } from './LiquidityLayerRouterDeployer';
const CircleBridgeInterface = ICircleBridge__factory.createInterface(); const CircleBridgeInterface = ICircleBridge__factory.createInterface();
const CircleBridgeAdapterInterface = const CircleBridgeAdapterInterface =
@ -37,11 +37,11 @@ interface CircleBridgeMessage<Chain> {
domain: number; domain: number;
nonceHash: string; nonceHash: string;
} }
export class TokenBridgeApp< export class LiquidityLayerApp<
Chain extends ChainName = ChainName, Chain extends ChainName = ChainName,
> extends HyperlaneApp<TokenBridgeContracts, Chain> { > extends HyperlaneApp<LiquidityLayerContracts, Chain> {
constructor( constructor(
public readonly contractsMap: ChainMap<Chain, TokenBridgeContracts>, public readonly contractsMap: ChainMap<Chain, LiquidityLayerContracts>,
public readonly multiProvider: MultiProvider<Chain>, public readonly multiProvider: MultiProvider<Chain>,
public readonly bridgeAdapterConfigs: ChainMap< public readonly bridgeAdapterConfigs: ChainMap<
Chain, Chain,

@ -3,15 +3,15 @@ import { ethers } from 'ethers';
import { import {
CircleBridgeAdapter, CircleBridgeAdapter,
CircleBridgeAdapter__factory, CircleBridgeAdapter__factory,
TokenBridgeRouter, LiquidityLayerRouter,
TokenBridgeRouter__factory, LiquidityLayerRouter__factory,
} from '@hyperlane-xyz/core'; } from '@hyperlane-xyz/core';
import { HyperlaneCore } from '../../core/HyperlaneCore'; import { HyperlaneCore } from '../../core/HyperlaneCore';
import { import {
TokenBridgeContracts, LiquidityLayerContracts,
TokenBridgeFactories, LiquidityLayerFactories,
tokenBridgeFactories, liquidityLayerFactories,
} from '../../middleware'; } from '../../middleware';
import { MultiProvider } from '../../providers/MultiProvider'; import { MultiProvider } from '../../providers/MultiProvider';
import { ChainMap, ChainName } from '../../types'; import { ChainMap, ChainName } from '../../types';
@ -36,31 +36,31 @@ export interface CircleBridgeAdapterConfig {
export type BridgeAdapterConfig = CircleBridgeAdapterConfig; export type BridgeAdapterConfig = CircleBridgeAdapterConfig;
export type TokenBridgeConfig = RouterConfig & { export type LiquidityLayerConfig = RouterConfig & {
bridgeAdapterConfigs: BridgeAdapterConfig[]; bridgeAdapterConfigs: BridgeAdapterConfig[];
}; };
export class TokenBridgeDeployer< export class LiquidityLayerDeployer<
Chain extends ChainName, Chain extends ChainName,
> extends HyperlaneRouterDeployer< > extends HyperlaneRouterDeployer<
Chain, Chain,
TokenBridgeConfig, LiquidityLayerConfig,
TokenBridgeContracts, LiquidityLayerContracts,
TokenBridgeFactories LiquidityLayerFactories
> { > {
constructor( constructor(
multiProvider: MultiProvider<Chain>, multiProvider: MultiProvider<Chain>,
configMap: ChainMap<Chain, TokenBridgeConfig>, configMap: ChainMap<Chain, LiquidityLayerConfig>,
protected core: HyperlaneCore<Chain>, protected core: HyperlaneCore<Chain>,
protected create2salt = 'TokenBridgeDeployerSalt', protected create2salt = 'LiquidityLayerDeployerSalt',
) { ) {
super(multiProvider, configMap, tokenBridgeFactories, {}); super(multiProvider, configMap, liquidityLayerFactories, {});
} }
async enrollRemoteRouters( async enrollRemoteRouters(
contractsMap: ChainMap<Chain, TokenBridgeContracts>, contractsMap: ChainMap<Chain, LiquidityLayerContracts>,
): Promise<void> { ): Promise<void> {
// Enroll the TokenBridgeRouter with each other // Enroll the LiquidityLayerRouter with each other
await super.enrollRemoteRouters(contractsMap); await super.enrollRemoteRouters(contractsMap);
// Enroll the circle adapters with each other // Enroll the circle adapters with each other
@ -75,10 +75,10 @@ export class TokenBridgeDeployer<
// If no custom logic is needed, call deployContract for the router // If no custom logic is needed, call deployContract for the router
async deployContracts( async deployContracts(
chain: Chain, chain: Chain,
config: TokenBridgeConfig, config: LiquidityLayerConfig,
): Promise<TokenBridgeContracts> { ): Promise<LiquidityLayerContracts> {
const initCalldata = const initCalldata =
TokenBridgeRouter__factory.createInterface().encodeFunctionData( LiquidityLayerRouter__factory.createInterface().encodeFunctionData(
'initialize', 'initialize',
[config.owner, config.connectionManager, config.interchainGasPaymaster], [config.owner, config.connectionManager, config.interchainGasPaymaster],
); );
@ -87,7 +87,7 @@ export class TokenBridgeDeployer<
initCalldata, initCalldata,
}); });
const bridgeAdapters: Partial<TokenBridgeContracts> = {}; const bridgeAdapters: Partial<LiquidityLayerContracts> = {};
for (const adapterConfig of config.bridgeAdapterConfigs) { for (const adapterConfig of config.bridgeAdapterConfigs) {
if (adapterConfig.type === BridgeAdapterType.Circle) { if (adapterConfig.type === BridgeAdapterType.Circle) {
@ -111,7 +111,7 @@ export class TokenBridgeDeployer<
chain: Chain, chain: Chain,
adapterConfig: CircleBridgeAdapterConfig, adapterConfig: CircleBridgeAdapterConfig,
owner: string, owner: string,
router: TokenBridgeRouter, router: LiquidityLayerRouter,
): Promise<CircleBridgeAdapter> { ): Promise<CircleBridgeAdapter> {
const cc = this.multiProvider.getChainConnection(chain); const cc = this.multiProvider.getChainConnection(chain);
const initCalldata = const initCalldata =
@ -162,9 +162,9 @@ export class TokenBridgeDeployer<
); );
} }
this.logger('Set CircleTokenBridgeAdapter on Router'); this.logger('Set CircleLiquidityLayerAdapter on Router');
await cc.handleTx( await cc.handleTx(
router.setTokenBridgeAdapter( router.setLiquidityLayerAdapter(
adapterConfig.type, adapterConfig.type,
circleBridgeAdapter.address, circleBridgeAdapter.address,
), ),

@ -121,18 +121,18 @@ export {
InterchainQueryDeployer, InterchainQueryDeployer,
} from './deploy/middleware/deploy'; } from './deploy/middleware/deploy';
export { export {
TokenBridgeDeployer, LiquidityLayerDeployer,
BridgeAdapterType, BridgeAdapterType,
BridgeAdapterConfig, BridgeAdapterConfig,
CircleBridgeAdapterConfig, CircleBridgeAdapterConfig,
} from './deploy/middleware/TokenBridgeRouterDeployer'; } from './deploy/middleware/LiquidityLayerRouterDeployer';
export { TokenBridgeApp } from './deploy/middleware/TokenBridgeApp'; export { LiquidityLayerApp } from './deploy/middleware/LiquidityLayerApp';
export { export {
TokenBridgeContracts, LiquidityLayerContracts,
interchainAccountFactories, interchainAccountFactories,
interchainQueryFactories, interchainQueryFactories,
tokenBridgeFactories, liquidityLayerFactories,
} from './middleware'; } from './middleware';
export { RouterConfig } from './deploy/router/types'; export { RouterConfig } from './deploy/router/types';
export { getTestMultiProvider, getChainToOwnerMap } from './deploy/utils'; export { getTestMultiProvider, getChainToOwnerMap } from './deploy/utils';

@ -5,8 +5,8 @@ import {
InterchainAccountRouter__factory, InterchainAccountRouter__factory,
InterchainQueryRouter, InterchainQueryRouter,
InterchainQueryRouter__factory, InterchainQueryRouter__factory,
TokenBridgeRouter, LiquidityLayerRouter,
TokenBridgeRouter__factory, LiquidityLayerRouter__factory,
} from '@hyperlane-xyz/core'; } from '@hyperlane-xyz/core';
import { RouterContracts, RouterFactories } from './router'; import { RouterContracts, RouterFactories } from './router';
@ -29,15 +29,15 @@ export const interchainQueryFactories: InterchainQueryFactories = {
export type InterchainQueryContracts = RouterContracts<InterchainQueryRouter>; export type InterchainQueryContracts = RouterContracts<InterchainQueryRouter>;
export type TokenBridgeFactories = RouterFactories<TokenBridgeRouter> & { export type LiquidityLayerFactories = RouterFactories<LiquidityLayerRouter> & {
circleBridgeAdapter: CircleBridgeAdapter__factory; circleBridgeAdapter: CircleBridgeAdapter__factory;
}; };
export const tokenBridgeFactories: TokenBridgeFactories = { export const liquidityLayerFactories: LiquidityLayerFactories = {
router: new TokenBridgeRouter__factory(), router: new LiquidityLayerRouter__factory(),
circleBridgeAdapter: new CircleBridgeAdapter__factory(), circleBridgeAdapter: new CircleBridgeAdapter__factory(),
}; };
export type TokenBridgeContracts = RouterContracts<TokenBridgeRouter> & { export type LiquidityLayerContracts = RouterContracts<LiquidityLayerRouter> & {
circleBridgeAdapter?: CircleBridgeAdapter; circleBridgeAdapter?: CircleBridgeAdapter;
}; };

@ -3,46 +3,46 @@ import { expect } from 'chai';
import { ethers } from 'hardhat'; import { ethers } from 'hardhat';
import { import {
LiquidityLayerRouter,
MockCircleBridge, MockCircleBridge,
MockCircleBridge__factory, MockCircleBridge__factory,
MockCircleMessageTransmitter, MockCircleMessageTransmitter,
MockCircleMessageTransmitter__factory, MockCircleMessageTransmitter__factory,
MockToken, MockToken,
MockToken__factory, MockToken__factory,
TestTokenBridgeMessageRecipient__factory, TestLiquidityLayerMessageRecipient__factory,
TokenBridgeRouter,
} from '@hyperlane-xyz/core'; } from '@hyperlane-xyz/core';
import { utils } from '@hyperlane-xyz/utils'; import { utils } from '@hyperlane-xyz/utils';
import { testChainConnectionConfigs } from '../consts/chainConnectionConfigs'; import { testChainConnectionConfigs } from '../consts/chainConnectionConfigs';
import { TestCoreApp } from '../core/TestCoreApp'; import { TestCoreApp } from '../core/TestCoreApp';
import { TestCoreDeployer } from '../core/TestCoreDeployer'; import { TestCoreDeployer } from '../core/TestCoreDeployer';
import { TokenBridgeApp } from '../deploy/middleware/TokenBridgeApp'; import { LiquidityLayerApp } from '../deploy/middleware/LiquidityLayerApp';
import { import {
BridgeAdapterType, BridgeAdapterType,
CircleBridgeAdapterConfig, CircleBridgeAdapterConfig,
TokenBridgeConfig, LiquidityLayerConfig,
TokenBridgeDeployer, LiquidityLayerDeployer,
} from '../deploy/middleware/TokenBridgeRouterDeployer'; } from '../deploy/middleware/LiquidityLayerRouterDeployer';
import { getChainToOwnerMap, getTestMultiProvider } from '../deploy/utils'; import { getChainToOwnerMap, getTestMultiProvider } from '../deploy/utils';
import { ChainNameToDomainId } from '../domains'; import { ChainNameToDomainId } from '../domains';
import { MultiProvider } from '../providers/MultiProvider'; import { MultiProvider } from '../providers/MultiProvider';
import { ChainMap, TestChainNames } from '../types'; import { ChainMap, TestChainNames } from '../types';
import { objMap } from '../utils/objects'; import { objMap } from '../utils/objects';
describe('TokenBridgeRouter', async () => { describe('LiquidityLayerRouter', async () => {
const localChain = 'test1'; const localChain = 'test1';
const remoteChain = 'test2'; const remoteChain = 'test2';
const localDomain = ChainNameToDomainId[localChain]; const localDomain = ChainNameToDomainId[localChain];
const remoteDomain = ChainNameToDomainId[remoteChain]; const remoteDomain = ChainNameToDomainId[remoteChain];
let signer: SignerWithAddress; let signer: SignerWithAddress;
let local: TokenBridgeRouter; let local: LiquidityLayerRouter;
let multiProvider: MultiProvider<TestChainNames>; let multiProvider: MultiProvider<TestChainNames>;
let coreApp: TestCoreApp; let coreApp: TestCoreApp;
let tokenBridgeApp: TokenBridgeApp<TestChainNames>; let liquidityLayerApp: LiquidityLayerApp<TestChainNames>;
let config: ChainMap<TestChainNames, TokenBridgeConfig>; let config: ChainMap<TestChainNames, LiquidityLayerConfig>;
let mockToken: MockToken; let mockToken: MockToken;
let circleBridge: MockCircleBridge; let circleBridge: MockCircleBridge;
let messageTransmitter: MockCircleMessageTransmitter; let messageTransmitter: MockCircleMessageTransmitter;
@ -94,20 +94,24 @@ describe('TokenBridgeRouter', async () => {
}); });
beforeEach(async () => { beforeEach(async () => {
const TokenBridge = new TokenBridgeDeployer(multiProvider, config, coreApp); const LiquidityLayer = new LiquidityLayerDeployer(
const contracts = await TokenBridge.deploy(); multiProvider,
config,
coreApp,
);
const contracts = await LiquidityLayer.deploy();
tokenBridgeApp = new TokenBridgeApp( liquidityLayerApp = new LiquidityLayerApp(
contracts, contracts,
multiProvider, multiProvider,
objMap(config, (_chain, conf) => conf.bridgeAdapterConfigs), objMap(config, (_chain, conf) => conf.bridgeAdapterConfigs),
); );
local = tokenBridgeApp.getContracts(localChain).router; local = liquidityLayerApp.getContracts(localChain).router;
}); });
it('can transfer tokens', async () => { it('can transfer tokens', async () => {
const recipientF = new TestTokenBridgeMessageRecipient__factory(signer); const recipientF = new TestLiquidityLayerMessageRecipient__factory(signer);
const recipient = await recipientF.deploy(); const recipient = await recipientF.deploy();
const amount = 1000; const amount = 1000;
@ -130,7 +134,7 @@ describe('TokenBridgeRouter', async () => {
await messageTransmitter.process( await messageTransmitter.process(
nonceId, nonceId,
tokenBridgeApp.getContracts(remoteChain).circleBridgeAdapter!.address, liquidityLayerApp.getContracts(remoteChain).circleBridgeAdapter!.address,
amount, amount,
); );
await coreApp.processMessages(); await coreApp.processMessages();
Loading…
Cancel
Save