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 {ICircleBridge} from "./interfaces/circle/ICircleBridge.sol";
import {ICircleMessageTransmitter} from "./interfaces/circle/ICircleMessageTransmitter.sol";
import {ITokenBridgeAdapter} from "./interfaces/ITokenBridgeAdapter.sol";
import {ITokenBridgeMessageRecipient} from "./interfaces/ITokenBridgeMessageRecipient.sol";
import {ILiquidityLayerAdapter} from "./interfaces/ILiquidityLayerAdapter.sol";
import {ILiquidityLayerMessageRecipient} from "./interfaces/ILiquidityLayerMessageRecipient.sol";
import {TypeCasts} from "../../libs/TypeCasts.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract TokenBridgeRouter is Router {
contract LiquidityLayerRouter is Router {
// 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(
address _owner,
@ -40,7 +40,7 @@ contract TokenBridgeRouter is Router {
uint256 _amount,
string calldata _bridge
) external payable {
ITokenBridgeAdapter _adapter = _getAdapter(_bridge);
ILiquidityLayerAdapter _adapter = _getAdapter(_bridge);
// Transfer the tokens to the adapter
// TODO: use safeTransferFrom
@ -70,11 +70,11 @@ contract TokenBridgeRouter is Router {
_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);
}
// Handles a message from an enrolled remote TokenBridgeRouter
// Handles a message from an enrolled remote LiquidityLayerRouter
function _handle(
uint32 _origin,
bytes32, // _sender, unused
@ -93,7 +93,7 @@ contract TokenBridgeRouter is Router {
(bytes32, bytes32, uint256, string, bytes, bytes)
);
ITokenBridgeMessageRecipient _userRecipient = ITokenBridgeMessageRecipient(
ILiquidityLayerMessageRecipient _userRecipient = ILiquidityLayerMessageRecipient(
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
onlyOwner
{
tokenBridgeAdapters[_bridge] = _adapter;
emit TokenBridgeAdapterSet(_bridge, _adapter);
liquidityLayerAdapters[_bridge] = _adapter;
emit LiquidityLayerAdapterSet(_bridge, _adapter);
}
function _getAdapter(string memory _bridge)
internal
view
returns (ITokenBridgeAdapter _adapter)
returns (ILiquidityLayerAdapter _adapter)
{
_adapter = ITokenBridgeAdapter(tokenBridgeAdapters[_bridge]);
_adapter = ILiquidityLayerAdapter(liquidityLayerAdapters[_bridge]);
// Require the adapter to have been set
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 {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";
contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
contract CircleBridgeAdapter is ILiquidityLayerAdapter, Router {
/// @notice The CircleBridge contract.
ICircleBridge public circleBridge;
/// @notice The Circle MessageTransmitter contract.
ICircleMessageTransmitter public circleMessageTransmitter;
/// @notice The TokenBridgeRouter contract.
address public tokenBridgeRouter;
/// @notice The LiquidityLayerRouter contract.
address public liquidityLayerRouter;
/// @notice Hyperlane domain => Circle domain.
/// 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);
modifier onlyTokenBridgeRouter() {
require(msg.sender == tokenBridgeRouter, "!tokenBridgeRouter");
modifier onlyLiquidityLayerRouter() {
require(msg.sender == liquidityLayerRouter, "!liquidityLayerRouter");
_;
}
@ -63,13 +63,13 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
* @param _owner The new owner.
* @param _circleBridge The CircleBridge contract.
* @param _circleMessageTransmitter The Circle MessageTransmitter contract.
* @param _tokenBridgeRouter The TokenBridgeRouter contract.
* @param _liquidityLayerRouter The LiquidityLayerRouter contract.
*/
function initialize(
address _owner,
address _circleBridge,
address _circleMessageTransmitter,
address _tokenBridgeRouter
address _liquidityLayerRouter
) public initializer {
// Transfer ownership of the contract to deployer
_transferOwnership(_owner);
@ -82,7 +82,7 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
circleMessageTransmitter = ICircleMessageTransmitter(
_circleMessageTransmitter
);
tokenBridgeRouter = _tokenBridgeRouter;
liquidityLayerRouter = _liquidityLayerRouter;
}
function sendTokens(
@ -90,7 +90,7 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
bytes32, // _recipientAddress, unused
address _token,
uint256 _amount
) external onlyTokenBridgeRouter returns (bytes memory) {
) external onlyLiquidityLayerRouter returns (bytes memory) {
string memory _tokenSymbol = tokenAddressToSymbol[_token];
require(
bytes(_tokenSymbol).length > 0,
@ -106,7 +106,7 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
"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.
require(
IERC20(_token).approve(address(circleBridge), _amount),
@ -130,7 +130,7 @@ contract CircleBridgeAdapter is ITokenBridgeAdapter, Router {
address _recipient,
uint256 _amount,
bytes calldata _adapterData // The adapter data from the message
) external onlyTokenBridgeRouter returns (address, uint256) {
) external onlyLiquidityLayerRouter returns (address, uint256) {
// The origin Circle domain
uint32 _originCircleDomain = hyperlaneDomainToCircleDomain[
_originDomain

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

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

@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
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";
contract MockCircleBridge is ICircleBridge {

@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
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";
contract MockCircleMessageTransmitter is ICircleMessageTransmitter {

@ -1,9 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
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(
uint32 origin,
bytes32 sender,

@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT OR Apache-2.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;
bytes public lastData;
address public lastToken;

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

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

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

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

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

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

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

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