Verified contractExactMIT
BridgeForwarderFactory
Address0x83e1d7e1e50896dec16f0fb50c9c79c2a0dfa5df
- Balance
0 ETH
- Transactions
9
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,356,544
- Creation transaction
- 0x3cd2a1f6a4…21492ddb6a
6 files
src/BridgeForwarderFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {BridgeForwarder} from "./BridgeForwarder.sol";
import {SwapForwarder} from "./SwapForwarder.sol";
/// @title BridgeForwarderFactory
/// @notice CREATE2 factory for per-recipient BridgeForwarders on a CCTP source chain.
/// @dev salt = bytes32(uint256(uint160(recipient))) — same scheme as SwapForwarderFactory.
/// mintRecipient is the Base SwapForwarder address computed against `baseSwapFactory`
/// using the same init-code as SwapForwarder.sol. There is no owner.
contract BridgeForwarderFactory {
address public immutable usdc;
address public immutable tokenMessenger;
/// @notice Live Base SwapForwarderFactory: 0x83e1d7E1E50896DEc16F0FB50C9C79C2A0dFA5DF
address public immutable baseSwapFactory;
event Deployed(address indexed recipient, address indexed forwarder, bytes32 mintRecipient);
event DeployAndBurned(
address indexed recipient, address indexed forwarder, uint64 nonce, uint256 maxFee, uint32 minFinalityThreshold
);
error ZeroAddress();
constructor(address usdc_, address tokenMessenger_, address baseSwapFactory_) {
if (usdc_ == address(0) || tokenMessenger_ == address(0) || baseSwapFactory_ == address(0)) {
revert ZeroAddress();
}
usdc = usdc_;
tokenMessenger = tokenMessenger_;
baseSwapFactory = baseSwapFactory_;
}
function salt(address recipient) public pure returns (bytes32) {
return bytes32(uint256(uint160(recipient)));
}
/// @notice Counterfactual Base SwapForwarder for `recipient` (must match the live Base factory).
function computeBaseDeposit(address recipient) public view returns (address predicted) {
bytes32 s = salt(recipient);
bytes memory initCode = abi.encodePacked(type(SwapForwarder).creationCode, abi.encode(recipient));
bytes32 digest = keccak256(abi.encodePacked(bytes1(0xff), baseSwapFactory, s, keccak256(initCode)));
predicted = address(uint160(uint256(digest)));
}
function computeAddress(address recipient) public view returns (address predicted) {
bytes32 s = salt(recipient);
bytes32 mintRecipient = bytes32(uint256(uint160(computeBaseDeposit(recipient))));
bytes memory initCode = abi.encodePacked(
type(BridgeForwarder).creationCode, abi.encode(recipient, mintRecipient, usdc, tokenMessenger)
);
bytes32 digest = keccak256(abi.encodePacked(bytes1(0xff), address(this), s, keccak256(initCode)));
predicted = address(uint160(uint256(digest)));
}
function isDeployed(address recipient) public view returns (bool) {
return computeAddress(recipient).code.length > 0;
}
function deploy(address recipient) public returns (address forwarder) {
bytes32 mintRecipient = bytes32(uint256(uint160(computeBaseDeposit(recipient))));
forwarder = address(new BridgeForwarder{salt: salt(recipient)}(recipient, mintRecipient, usdc, tokenMessenger));
emit Deployed(recipient, forwarder, mintRecipient);
}
function deployAndBurn(address recipient, uint256 maxFee, uint32 minFinalityThreshold)
external
returns (address forwarder, uint64 nonce)
{
forwarder = computeAddress(recipient);
if (forwarder.code.length == 0) {
forwarder = deploy(recipient);
}
nonce = BridgeForwarder(forwarder).burn(maxFee, minFinalityThreshold);
emit DeployAndBurned(recipient, forwarder, nonce, maxFee, minFinalityThreshold);
}
}
src/BridgeForwarder.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IERC20} from "./interfaces/IERC20.sol";
import {ITokenMessengerV2} from "./interfaces/ITokenMessengerV2.sol";
/// @title BridgeForwarder
/// @notice Non-custodial USDC hopper on a CCTP V2 *source* chain.
/// @dev Recipient (the user's final EURC address on Base) is immutable.
/// There is no owner. The only CCTP call is TokenMessengerV2.depositForBurn
/// with destinationDomain = 6 (Base) and mintRecipient = this user's
/// Base SwapForwarder (CREATE2). rescue() can only pay the recipient.
///
/// maxFee is capped at MAX_FEE_BPS of the balance so a buggy/malicious
/// relayer cannot donate the deposit to Circle as an oversized Fast Transfer fee.
contract BridgeForwarder {
address public immutable recipient;
/// @notice bytes32-padded Base SwapForwarder address (CCTP mintRecipient).
bytes32 public immutable mintRecipient;
address public immutable usdc;
address public immutable tokenMessenger;
/// @notice Base domain id (Circle docs: https://developers.circle.com/cctp/references/contract-addresses)
uint32 public constant DESTINATION_DOMAIN = 6;
/// @notice Fast = 1000, Standard = 2000 (Circle finality thresholds).
uint32 public constant FAST_FINALITY = 1000;
uint32 public constant STANDARD_FINALITY = 2000;
/// @notice 50 bps = 0.50%. Live Fast Transfer fees to Base are 0–1.4 bps
/// (Iris /v2/burn/USDC/fees, 2026-11-06). Cap leaves headroom if
/// Circle raises fees without letting a relayer drain the user.
uint256 public constant MAX_FEE_BPS = 50;
error ZeroRecipient();
error ZeroMintRecipient();
error ZeroAddress();
error ZeroAmount();
error FeeTooHigh(uint256 maxFee, uint256 cap);
error BadFinality(uint32 minFinalityThreshold);
error ApproveFailed();
error TransferFailed();
event Burned(
address indexed recipient,
bytes32 indexed mintRecipient,
uint256 amount,
uint256 maxFee,
uint32 minFinalityThreshold,
uint64 nonce
);
event Rescued(address indexed token, address indexed recipient, uint256 amount);
constructor(address recipient_, bytes32 mintRecipient_, address usdc_, address tokenMessenger_) {
if (recipient_ == address(0)) revert ZeroRecipient();
if (mintRecipient_ == bytes32(0)) revert ZeroMintRecipient();
if (usdc_ == address(0) || tokenMessenger_ == address(0)) revert ZeroAddress();
recipient = recipient_;
mintRecipient = mintRecipient_;
usdc = usdc_;
tokenMessenger = tokenMessenger_;
}
/// @notice Burn the entire USDC balance via CCTP V2 toward the immutable Base SwapForwarder.
/// @param maxFee Maximum Fast Transfer fee in USDC raw units (deducted at mint). Must be ≤ 0.50% of balance.
/// @param minFinalityThreshold 1000 (Fast) or 2000 (Standard).
function burn(uint256 maxFee, uint32 minFinalityThreshold) external returns (uint64 nonce) {
if (minFinalityThreshold != FAST_FINALITY && minFinalityThreshold != STANDARD_FINALITY) {
revert BadFinality(minFinalityThreshold);
}
uint256 amount = IERC20(usdc).balanceOf(address(this));
if (amount == 0) revert ZeroAmount();
uint256 cap = (amount * MAX_FEE_BPS) / 10_000;
if (maxFee > cap) revert FeeTooHigh(maxFee, cap);
_forceApprove(tokenMessenger, 0);
if (!IERC20(usdc).approve(tokenMessenger, amount)) revert ApproveFailed();
// destinationCaller = 0 → anyone (user or relayer) may call receiveMessage on Base.
// Low-level call: some TokenMessengerV2 proxy paths return empty data even
// though the interface declares uint64 nonce; ABI-decoding that reverts.
(bool ok, bytes memory ret) = tokenMessenger.call(
abi.encodeWithSelector(
ITokenMessengerV2.depositForBurn.selector,
amount,
DESTINATION_DOMAIN,
mintRecipient,
usdc,
bytes32(0),
maxFee,
minFinalityThreshold
)
);
if (!ok) {
if (ret.length > 0) {
assembly {
revert(add(ret, 32), mload(ret))
}
}
revert("depositForBurn failed");
}
if (ret.length >= 32) nonce = uint64(abi.decode(ret, (uint256)));
_forceApprove(tokenMessenger, 0);
emit Burned(recipient, mintRecipient, amount, maxFee, minFinalityThreshold, nonce);
}
/// @notice Send the entire balance of `token` to the immutable recipient. Anyone may call.
function rescue(address token) external {
uint256 bal = IERC20(token).balanceOf(address(this));
if (bal == 0) revert ZeroAmount();
if (!IERC20(token).transfer(recipient, bal)) revert TransferFailed();
emit Rescued(token, recipient, bal);
}
function _forceApprove(address spender, uint256 value) internal {
// Ethereum USDC requires allowance to be reset to 0 before a non-zero change.
(bool ok,) = usdc.call(abi.encodeWithSelector(IERC20.approve.selector, spender, value));
ok;
}
}
src/SwapForwarder.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IERC20} from "./interfaces/IERC20.sol";
import {ISlipstreamRouter} from "./interfaces/ISlipstreamRouter.sol";
/// @title SwapForwarder
/// @notice Minimal non-custodial USDC→EURC forwarder on Base.
/// @dev Recipient is immutable (baked into CREATE2 init code + salt). There is no owner.
/// Anyone may call `swap` or `rescue`. EURC from the swap is sent directly to `recipient`.
/// `rescue` can only send tokens to `recipient` — never elsewhere.
///
/// Security floor (griefing bound):
/// require(minOut >= amountIn * MIN_OUT_BPS / 10_000)
/// MIN_OUT_BPS = 7500 → minOut must be ≥ 75% of amountIn in raw units.
/// USDC and EURC are both 6 decimals and trade near parity, so this blocks a
/// malicious/broken relayer from setting minOut=0 and sandwiching the user to ~0.
/// Relayer target slippage is 0.5%, well above this floor. If USDC/EURC FX ever
/// diverged by >25% in raw units, swaps would fail until a new forwarder bytecode
/// (new factory) is deployed — there is intentionally no admin to lower the floor.
contract SwapForwarder {
address public immutable recipient;
address public constant USDC = 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913;
address public constant EURC = 0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42;
address public constant ROUTER = 0xBE6D8f0d05cC4be24d5167a3eF062215bE6D18a5;
/// @notice 7500 = 75%. See contract natspec.
uint256 public constant MIN_OUT_BPS = 7500;
uint256 public constant DEADLINE_SECS = 300;
error ZeroRecipient();
error ZeroAmount();
error MinOutTooLow(uint256 minOut, uint256 floor);
error ApproveFailed();
error TransferFailed();
event Swapped(address indexed recipient, uint256 amountIn, uint256 amountOut, int24 tickSpacing);
event Rescued(address indexed token, address indexed recipient, uint256 amount);
constructor(address recipient_) {
if (recipient_ == address(0)) revert ZeroRecipient();
recipient = recipient_;
}
/// @notice Swap the entire USDC balance to EURC via Aerodrome Slipstream, sending EURC to `recipient`.
/// @param tickSpacing Pool tick spacing (50 or 1 for the known USDC/EURC pools).
/// @param minOut Relayer-supplied minimum EURC out (also subject to on-chain 75% floor).
function swap(int24 tickSpacing, uint256 minOut) external returns (uint256 amountOut) {
uint256 amountIn = IERC20(USDC).balanceOf(address(this));
if (amountIn == 0) revert ZeroAmount();
uint256 floor = (amountIn * MIN_OUT_BPS) / 10_000;
if (minOut < floor) revert MinOutTooLow(minOut, floor);
if (!IERC20(USDC).approve(ROUTER, amountIn)) revert ApproveFailed();
amountOut = ISlipstreamRouter(ROUTER).exactInputSingle(
ISlipstreamRouter.ExactInputSingleParams({
tokenIn: USDC,
tokenOut: EURC,
tickSpacing: tickSpacing,
recipient: recipient,
deadline: block.timestamp + DEADLINE_SECS,
amountIn: amountIn,
amountOutMinimum: minOut,
sqrtPriceLimitX96: 0
})
);
// Hygiene: clear allowance.
if (!IERC20(USDC).approve(ROUTER, 0)) revert ApproveFailed();
emit Swapped(recipient, amountIn, amountOut, tickSpacing);
}
/// @notice Send the entire balance of `token` to the immutable recipient. Anyone may call.
/// @dev This is the only outflow path besides `swap`. Funds can never leave to a third party.
function rescue(address token) external {
uint256 bal = IERC20(token).balanceOf(address(this));
if (bal == 0) revert ZeroAmount();
if (!IERC20(token).transfer(recipient, bal)) revert TransferFailed();
emit Rescued(token, recipient, bal);
}
}
src/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
src/interfaces/ISlipstreamRouter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @notice Aerodrome Slipstream SwapRouter (legacy factory) exactInputSingle.
interface ISlipstreamRouter {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
int24 tickSpacing;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
function exactInputSingle(ExactInputSingleParams calldata params)
external
payable
returns (uint256 amountOut);
function factory() external view returns (address);
}
src/interfaces/ITokenMessengerV2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @notice CCTP V2 TokenMessenger. Signature from Circle docs:
/// https://developers.circle.com/cctp/migration-from-v1-to-v2
interface ITokenMessengerV2 {
function depositForBurn(
uint256 amount,
uint32 destinationDomain,
bytes32 mintRecipient,
address burnToken,
bytes32 destinationCaller,
uint256 maxFee,
uint32 minFinalityThreshold
) external returns (uint64 nonce);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.