|
|
@ -8,8 +8,11 @@ import {ICircleMessageTransmitter} from "../interfaces/circle/ICircleMessageTran |
|
|
|
import {ILiquidityLayerAdapter} from "../interfaces/ILiquidityLayerAdapter.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"; |
|
|
|
|
|
|
|
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; |
|
|
|
|
|
|
|
|
|
|
|
contract CircleBridgeAdapter is ILiquidityLayerAdapter, Router { |
|
|
|
contract CircleBridgeAdapter is ILiquidityLayerAdapter, Router { |
|
|
|
|
|
|
|
using SafeERC20 for IERC20; |
|
|
|
|
|
|
|
|
|
|
|
/// @notice The TokenMessenger contract. |
|
|
|
/// @notice The TokenMessenger contract. |
|
|
|
ITokenMessenger public tokenMessenger; |
|
|
|
ITokenMessenger public tokenMessenger; |
|
|
|
|
|
|
|
|
|
|
@ -22,7 +25,7 @@ contract CircleBridgeAdapter is ILiquidityLayerAdapter, Router { |
|
|
|
/// @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. |
|
|
|
/// Note this could result in ambiguity between the Circle domain being |
|
|
|
/// Note this could result in ambiguity between the Circle domain being |
|
|
|
/// Ethereum or unknown. TODO fix? |
|
|
|
/// Ethereum or unknown. |
|
|
|
mapping(uint32 => uint32) public hyperlaneDomainToCircleDomain; |
|
|
|
mapping(uint32 => uint32) public hyperlaneDomainToCircleDomain; |
|
|
|
|
|
|
|
|
|
|
|
/// @notice Token symbol => address of token on local chain. |
|
|
|
/// @notice Token symbol => address of token on local chain. |
|
|
@ -70,8 +73,8 @@ contract CircleBridgeAdapter is ILiquidityLayerAdapter, Router { |
|
|
|
address _tokenMessenger, |
|
|
|
address _tokenMessenger, |
|
|
|
address _circleMessageTransmitter, |
|
|
|
address _circleMessageTransmitter, |
|
|
|
address _liquidityLayerRouter |
|
|
|
address _liquidityLayerRouter |
|
|
|
) public initializer { |
|
|
|
) external initializer { |
|
|
|
// Transfer ownership of the contract to deployer |
|
|
|
__Ownable_init(); |
|
|
|
_transferOwnership(_owner); |
|
|
|
_transferOwnership(_owner); |
|
|
|
|
|
|
|
|
|
|
|
tokenMessenger = ITokenMessenger(_tokenMessenger); |
|
|
|
tokenMessenger = ITokenMessenger(_tokenMessenger); |
|
|
@ -96,11 +99,7 @@ contract CircleBridgeAdapter is ILiquidityLayerAdapter, Router { |
|
|
|
uint32 _circleDomain = hyperlaneDomainToCircleDomain[ |
|
|
|
uint32 _circleDomain = hyperlaneDomainToCircleDomain[ |
|
|
|
_destinationDomain |
|
|
|
_destinationDomain |
|
|
|
]; |
|
|
|
]; |
|
|
|
bytes32 _remoteRouter = routers(_destinationDomain); |
|
|
|
bytes32 _remoteRouter = _mustHaveRemoteRouter(_destinationDomain); |
|
|
|
require( |
|
|
|
|
|
|
|
_remoteRouter != bytes32(0), |
|
|
|
|
|
|
|
"CircleBridgeAdapter: No router for domain" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Approve the token to Circle. We assume that the LiquidityLayerRouter |
|
|
|
// 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. |
|
|
@ -127,6 +126,7 @@ contract CircleBridgeAdapter is ILiquidityLayerAdapter, Router { |
|
|
|
uint256 _amount, |
|
|
|
uint256 _amount, |
|
|
|
bytes calldata _adapterData // The adapter data from the message |
|
|
|
bytes calldata _adapterData // The adapter data from the message |
|
|
|
) external onlyLiquidityLayerRouter returns (address, uint256) { |
|
|
|
) external onlyLiquidityLayerRouter returns (address, uint256) { |
|
|
|
|
|
|
|
_mustHaveRemoteRouter(_originDomain); |
|
|
|
// The origin Circle domain |
|
|
|
// The origin Circle domain |
|
|
|
uint32 _originCircleDomain = hyperlaneDomainToCircleDomain[ |
|
|
|
uint32 _originCircleDomain = hyperlaneDomainToCircleDomain[ |
|
|
|
_originDomain |
|
|
|
_originDomain |
|
|
@ -151,10 +151,9 @@ contract CircleBridgeAdapter is ILiquidityLayerAdapter, Router { |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Transfer the token out to the recipient |
|
|
|
// Transfer the token out to the recipient |
|
|
|
// TODO: use safeTransfer |
|
|
|
|
|
|
|
// Circle doesn't charge any fee, so we can safely transfer out the |
|
|
|
// Circle doesn't charge any fee, so we can safely transfer out the |
|
|
|
// exact amount that was bridged over. |
|
|
|
// exact amount that was bridged over. |
|
|
|
require(_token.transfer(_recipient, _amount), "!transfer out"); |
|
|
|
_token.safeTransfer(_recipient, _amount); |
|
|
|
|
|
|
|
|
|
|
|
return (address(_token), _amount); |
|
|
|
return (address(_token), _amount); |
|
|
|
} |
|
|
|
} |
|
|
|