Verified contractExactUNLICENSED
LzAdapterV4
Address0x2d6333e483098cb8858d85eec03f891ccbeff486
- Balance
0 ETH
- Transactions
4
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- UNLICENSED
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,401,422
- Creation transaction
- 0x15f14da4d6…9b91a8b341
13 files
- src/v4/bridge/transports/LzAdapterV4.solmain12.51 KB
- lib/layerzero/protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol2.59 KB
- lib/layerzero/protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol519 B
- lib/layerzero/protocol-v2/contracts/interfaces/IMessageLibManager.sol2.76 KB
- lib/layerzero/protocol-v2/contracts/interfaces/IMessagingChannel.sol1.54 KB
- lib/layerzero/protocol-v2/contracts/interfaces/IMessagingComposer.sol1.03 KB
- lib/layerzero/protocol-v2/contracts/interfaces/IMessagingContext.sol239 B
- src/lz/GasFloor.sol3.83 KB
- src/lz/Routes.sol5.92 KB
- src/v3/GasFloorV3.sol2.44 KB
- src/v4/bridge/BridgeCodecV4.sol5.82 KB
- src/v4/bridge/ITransportV4.sol1.26 KB
- src/v4/bridge/PangeaDeployerV4.sol2.04 KB
src/v4/bridge/transports/LzAdapterV4.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
import {
ILayerZeroEndpointV2,
MessagingParams,
MessagingReceipt,
MessagingFee,
Origin
} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import {ILayerZeroReceiver} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol";
import {SetConfigParam} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol";
import {RouteConfig, RouteLib, ExecutorConfig, UlnConfig, CONFIG_TYPE_EXECUTOR, CONFIG_TYPE_ULN} from "../../../lz/Routes.sol";
import {GasFloorV3} from "../../../v3/GasFloorV3.sol";
import {ITransportAdapterV4, IBridgeForAdaptersV4} from "../ITransportV4.sol";
import {IPendingConfigV4} from "../PangeaDeployerV4.sol";
import {BridgeCodecV4} from "../BridgeCodecV4.sol";
interface IChainKindLzV4 {
function chainKind(uint32 pcid) external view returns (uint8);
}
/// @title LzAdapterV4 -- the shared bridge's LayerZero V2 OApp (transport 1), V4-INTERFACES §11.2.14
/// @notice One address on every EVM chain (PangeaDeployerV4; endpoint, bridge and the route TABLE read from `pending()`).
/// Its own endpoint delegate (constructor), so nobody else can set its libraries / DVNs / executor or skip /
/// clear / nilify a message. The route table (the live RouteConfig shape: explicit send/receive libraries,
/// ULN configs with 2 required DVNs [ours, LayerZero Labs], executor, lzReceive gas floor) is FIXED at
/// construction; B3-I5: the bridge owner may only APPEND an entry for a NEW eid (a chain pair added later,
/// same checks; an existing entry never changes); `wireRoute(eid)` (anyone) writes one entry to the endpoint,
/// once. Coins stay safe: a coin's rows are fixed by its rowsHash (B1-M2). Peers are the bridge's routes (one
/// source of truth): peers(eid) = bridge.routeOf(pcidOf(eid), 1).peer.
/// A2-D12: toward a KEYS-ONLY destination (the bridge oracle's deliveryCharge(dst, 1) != 0: our delivery keys
/// deliver, the user pays our charge at the bridge) the executor options are the gas floor 1 (as v3), so the
/// user never pays LayerZero's executor for a delivery it will not make. B3-I6: lzReceive refuses msg.value.
/// B4-L1: the chain's REQUIRED DVN pair [ours, LayerZero Labs] (ascending, the local DVN contracts, one pair for
/// every route of this chain) is PINNED by the first table entry (the deploy's, built from chains.json + the
/// DVN allowlist) and never changes: every later entry (constructor or addRoute) must name exactly it, both ways.
/// B4-I2 (parity with C2's A2-R3, err LzValueNotZero): toward an EVM destination every send / quote carries
/// lzReceive value 0 (lzReceive there refuses value); the options shape (GasFloorV3: one lzReceive option)
/// admits no lzCompose option at all.
contract LzAdapterV4 is ITransportAdapterV4, ILayerZeroReceiver {
uint8 public constant TRANSPORT_ID = 1;
ILayerZeroEndpointV2 public immutable endpoint;
address public immutable bridge;
mapping(uint32 => RouteConfig) internal _table;
mapping(uint32 => bool) public wired;
uint32[] internal _eids;
/// @notice B4-L1: the chain's required DVN pair, pinned by the first table entry, never changed.
address[2] internal _pair;
event RouteWired(uint32 indexed eid);
error NotInTable(uint32 eid);
error AlreadyWired(uint32 eid);
error NotWired(uint32 eid);
error DuplicateEid(uint32 eid);
error NoRoute(uint32 pcid);
error NotBridge();
error NotEndpoint();
error NotPeer(uint32 eid, bytes32 sender);
error GasBelowFloor(uint128 gas, uint128 floor);
error MaxMessageSizeTooSmall(uint32 size);
/// @notice A2-D7 (§11.8): every route needs exactly 2 REQUIRED DVNs [ours, LayerZero Labs] and no optional set.
error NotRequiredPair(uint32 eid);
error NotOwner();
error ValueRefused();
/// @notice B4-L1: an entry whose required DVNs are not exactly the pinned pair.
error NotPinnedPair(uint32 eid);
/// @notice GATE-EVM I-6: addRoute before any pair was pinned at construction.
error PairNotPinned();
/// @notice B4-I2: a native lzReceive value toward an EVM destination (C2's 6085 LzValueNotZero).
error LzValueNotZero(uint128 value);
uint8 internal constant KIND_EVM = 1;
/// @notice A2-D12: the executor lzReceive gas toward a keys-only destination (v3 KEYS_ONLY_LZ_RECEIVE_GAS_V3).
uint128 public constant KEYS_ONLY_GAS = 1;
event RouteAdded(uint32 indexed eid);
constructor() {
(address ep, address br, RouteConfig[] memory tbl) =
abi.decode(IPendingConfigV4(msg.sender).pending(), (address, address, RouteConfig[]));
endpoint = ILayerZeroEndpointV2(ep);
bridge = br;
for (uint256 i = 0; i < tbl.length; i++) {
_add(tbl[i]);
}
endpoint.setDelegate(address(this));
}
function _add(RouteConfig memory r) internal {
// the pair first (GATE-EVM M10: its own ascending / duplicate refusal is then what refuses such a pair)
_requirePair(r.eid, r.sendUln);
_requirePair(r.eid, r.receiveUln);
RouteLib.requireExplicit(r);
GasFloorV3.check(r.lzReceiveGas, r.lzReceiveValue);
ExecutorConfig memory e = abi.decode(r.executor, (ExecutorConfig));
if (e.maxMessageSize < BridgeCodecV4.HEADER + BridgeCodecV4.OPEN_AUTH_LEN) revert MaxMessageSizeTooSmall(e.maxMessageSize);
if (_table[r.eid].sendLib != address(0)) revert DuplicateEid(r.eid);
_table[r.eid] = r;
_eids.push(r.eid);
}
/// @notice B3-I5: the bridge owner appends the route of a NEW eid (never replaces one); then wireRoute(eid).
function addRoute(RouteConfig calldata r) external {
if (msg.sender != IBridgeForAdaptersV4(bridge).owner()) revert NotOwner();
// GATE-EVM I-6: the chain's pair is pinned by the deploy's table (construction); an appended route can never
// be the one that pins it (an adapter built with an empty table takes no routes at all)
if (_pair[0] == address(0)) revert PairNotPinned();
_add(r);
emit RouteAdded(r.eid);
}
function transportId() external pure returns (uint8) {
return TRANSPORT_ID;
}
function table(uint32 eid) external view returns (RouteConfig memory) {
return _table[eid];
}
function eids() external view returns (uint32[] memory) {
return _eids;
}
/// @notice Anyone: pins the table's libraries and configs for `eid` on the endpoint, once.
function wireRoute(uint32 eid) external {
RouteConfig memory r = _table[eid];
if (r.sendLib == address(0)) revert NotInTable(eid);
if (wired[eid]) revert AlreadyWired(eid);
wired[eid] = true;
endpoint.setSendLibrary(address(this), eid, r.sendLib);
endpoint.setReceiveLibrary(address(this), eid, r.receiveLib, 0);
SetConfigParam[] memory s = new SetConfigParam[](2);
s[0] = SetConfigParam(eid, CONFIG_TYPE_EXECUTOR, r.executor);
s[1] = SetConfigParam(eid, CONFIG_TYPE_ULN, r.sendUln);
endpoint.setConfig(address(this), r.sendLib, s);
SetConfigParam[] memory v = new SetConfigParam[](1);
v[0] = SetConfigParam(eid, CONFIG_TYPE_ULN, r.receiveUln);
endpoint.setConfig(address(this), r.receiveLib, v);
emit RouteWired(eid);
}
function peers(uint32 eid) public view returns (bytes32) {
uint32 pcid = IBridgeForAdaptersV4(bridge).pcidOf(TRANSPORT_ID, eid);
if (pcid == 0) return bytes32(0);
return IBridgeForAdaptersV4(bridge).routeOf(pcid, TRANSPORT_ID).peer;
}
function _dst(uint32 pcid) internal view returns (uint32 eid, bytes32 peer, RouteConfig storage r) {
IBridgeForAdaptersV4.Route memory rt = IBridgeForAdaptersV4(bridge).routeOf(pcid, TRANSPORT_ID);
if (rt.peer == bytes32(0)) revert NoRoute(pcid);
(eid, peer) = (rt.remoteDomain, rt.peer);
r = _table[eid];
if (!wired[eid]) revert NotWired(eid);
}
/// @dev A2-D12: whether the bridge charges our delivery toward (pcid, LZ): an unreadable figure counts as not
/// keys-only here (the bridge itself refuses such a send).
function keysOnly(uint32 pcid) public view returns (bool) {
(bool ok, bytes memory ret) = bridge.staticcall(abi.encodeWithSignature("oracle()"));
if (!ok || ret.length != 32) return false;
address o = abi.decode(ret, (address));
(ok, ret) = o.staticcall(abi.encodeWithSignature("deliveryCharge(uint32,uint8)", pcid, TRANSPORT_ID));
if (!ok || ret.length != 64) return false;
(uint256 cost,) = abi.decode(ret, (uint256, address));
return cost != 0;
}
function _options(RouteConfig storage r, bytes calldata options, uint32 pcid) internal view returns (bytes memory) {
if (keysOnly(pcid)) return GasFloorV3.encode(KEYS_ONLY_GAS, 0);
(uint128 g, uint128 v) = (r.lzReceiveGas, r.lzReceiveValue);
if (options.length != 0) {
(g, v) = GasFloorV3.decode(options);
if (g < r.lzReceiveGas) revert GasBelowFloor(g, r.lzReceiveGas);
if (v < r.lzReceiveValue) revert GasBelowFloor(v, r.lzReceiveValue);
}
// B4-I2: an EVM lzReceive refuses value; only a non-EVM destination (Solana: the rent) may carry one
if (v != 0 && IChainKindLzV4(bridge).chainKind(pcid) == KIND_EVM) revert LzValueNotZero(v);
return options.length == 0 ? GasFloorV3.encode(g, v) : options;
}
function quote(uint32 dstPcid, bytes calldata message, bytes calldata extraOptions) external view returns (uint256) {
(uint32 eid, bytes32 peer, RouteConfig storage r) = _dst(dstPcid);
MessagingFee memory f = endpoint.quote(MessagingParams(eid, peer, message, _options(r, extraOptions, dstPcid), false), address(this));
return f.nativeFee;
}
function send(uint32 dstPcid, bytes calldata message, bytes calldata extraOptions, address refundTo)
external
payable
returns (bytes32)
{
if (msg.sender != bridge) revert NotBridge();
(uint32 eid, bytes32 peer, RouteConfig storage r) = _dst(dstPcid);
MessagingReceipt memory rc =
endpoint.send{value: msg.value}(MessagingParams(eid, peer, message, _options(r, extraOptions, dstPcid), false), refundTo);
return rc.guid;
}
function allowInitializePath(Origin calldata origin) external view returns (bool) {
bytes32 p = peers(origin.srcEid);
return wired[origin.srcEid] && p != bytes32(0) && p == origin.sender;
}
function nextNonce(uint32, bytes32) external pure returns (uint64) {
return 0;
}
function lzReceive(Origin calldata origin, bytes32 guid, bytes calldata message, address executor, bytes calldata)
external
payable
{
if (msg.sender != address(endpoint)) revert NotEndpoint();
if (msg.value != 0) revert ValueRefused();
// B1-M2: only over an eid whose libraries / DVN config this adapter pinned (wireRoute)
if (!wired[origin.srcEid]) revert NotWired(origin.srcEid);
uint32 pcid = IBridgeForAdaptersV4(bridge).pcidOf(TRANSPORT_ID, origin.srcEid);
if (pcid == 0) revert NotPeer(origin.srcEid, origin.sender);
IBridgeForAdaptersV4(bridge).receiveFromTransport(pcid, origin.sender, message, guid, executor);
}
function _requirePair(uint32 eid, bytes memory uln) private {
UlnConfig memory u = abi.decode(uln, (UlnConfig));
if (u.requiredDVNCount != 2 || u.requiredDVNs.length != 2 || u.optionalDVNCount != type(uint8).max || u.optionalDVNThreshold != 0) {
revert NotRequiredPair(eid);
}
address a = u.requiredDVNs[0];
address b = u.requiredDVNs[1];
if (a == address(0) || uint160(a) >= uint160(b)) revert NotRequiredPair(eid);
if (_pair[0] == address(0)) (_pair[0], _pair[1]) = (a, b); // B4-L1: pinned once, by the first entry
else if (_pair[0] != a || _pair[1] != b) revert NotPinnedPair(eid);
}
/// @notice B4-L1: the chain's pinned required DVN pair (ascending; zero before the first entry).
function requiredPair() external view returns (address, address) {
return (_pair[0], _pair[1]);
}
}
lib/layerzero/protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IMessageLibManager } from "./IMessageLibManager.sol";
import { IMessagingComposer } from "./IMessagingComposer.sol";
import { IMessagingChannel } from "./IMessagingChannel.sol";
import { IMessagingContext } from "./IMessagingContext.sol";
struct MessagingParams {
uint32 dstEid;
bytes32 receiver;
bytes message;
bytes options;
bool payInLzToken;
}
struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}
struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}
struct Origin {
uint32 srcEid;
bytes32 sender;
uint64 nonce;
}
interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);
event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);
event PacketDelivered(Origin origin, address receiver);
event LzReceiveAlert(
address indexed receiver,
address indexed executor,
Origin origin,
bytes32 guid,
uint256 gas,
uint256 value,
bytes message,
bytes extraData,
bytes reason
);
event LzTokenSet(address token);
event DelegateSet(address sender, address delegate);
function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);
function send(
MessagingParams calldata _params,
address _refundAddress
) external payable returns (MessagingReceipt memory);
function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;
function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);
function initializable(Origin calldata _origin, address _receiver) external view returns (bool);
function lzReceive(
Origin calldata _origin,
address _receiver,
bytes32 _guid,
bytes calldata _message,
bytes calldata _extraData
) external payable;
// oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;
function setLzToken(address _lzToken) external;
function lzToken() external view returns (address);
function nativeToken() external view returns (address);
function setDelegate(address _delegate) external;
}
lib/layerzero/protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { Origin } from "./ILayerZeroEndpointV2.sol";
interface ILayerZeroReceiver {
function allowInitializePath(Origin calldata _origin) external view returns (bool);
function nextNonce(uint32 _eid, bytes32 _sender) external view returns (uint64);
function lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) external payable;
}
lib/layerzero/protocol-v2/contracts/interfaces/IMessageLibManager.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
struct SetConfigParam {
uint32 eid;
uint32 configType;
bytes config;
}
interface IMessageLibManager {
struct Timeout {
address lib;
uint256 expiry;
}
event LibraryRegistered(address newLib);
event DefaultSendLibrarySet(uint32 eid, address newLib);
event DefaultReceiveLibrarySet(uint32 eid, address newLib);
event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint256 expiry);
event SendLibrarySet(address sender, uint32 eid, address newLib);
event ReceiveLibrarySet(address receiver, uint32 eid, address newLib);
event ReceiveLibraryTimeoutSet(address receiver, uint32 eid, address oldLib, uint256 timeout);
function registerLibrary(address _lib) external;
function isRegisteredLibrary(address _lib) external view returns (bool);
function getRegisteredLibraries() external view returns (address[] memory);
function setDefaultSendLibrary(uint32 _eid, address _newLib) external;
function defaultSendLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint256 _gracePeriod) external;
function defaultReceiveLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint256 _expiry) external;
function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint256 expiry);
function isSupportedEid(uint32 _eid) external view returns (bool);
function isValidReceiveLibrary(address _receiver, uint32 _eid, address _lib) external view returns (bool);
/// ------------------- OApp interfaces -------------------
function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;
function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);
function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);
function setReceiveLibrary(address _oapp, uint32 _eid, address _newLib, uint256 _gracePeriod) external;
function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);
function setReceiveLibraryTimeout(address _oapp, uint32 _eid, address _lib, uint256 _expiry) external;
function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint256 expiry);
function setConfig(address _oapp, address _lib, SetConfigParam[] calldata _params) external;
function getConfig(
address _oapp,
address _lib,
uint32 _eid,
uint32 _configType
) external view returns (bytes memory config);
}
lib/layerzero/protocol-v2/contracts/interfaces/IMessagingChannel.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingChannel {
event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
event PacketNilified(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
event PacketBurnt(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
function eid() external view returns (uint32);
// this is an emergency function if a message cannot be verified for some reasons
// required to provide _nextNonce to avoid race condition
function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;
function nilify(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
function burn(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);
function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);
function inboundPayloadHash(
address _receiver,
uint32 _srcEid,
bytes32 _sender,
uint64 _nonce
) external view returns (bytes32);
function lazyInboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
}
lib/layerzero/protocol-v2/contracts/interfaces/IMessagingComposer.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingComposer {
event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message);
event ComposeDelivered(address from, address to, bytes32 guid, uint16 index);
event LzComposeAlert(
address indexed from,
address indexed to,
address indexed executor,
bytes32 guid,
uint16 index,
uint256 gas,
uint256 value,
bytes message,
bytes extraData,
bytes reason
);
function composeQueue(
address _from,
address _to,
bytes32 _guid,
uint16 _index
) external view returns (bytes32 messageHash);
function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external;
function lzCompose(
address _from,
address _to,
bytes32 _guid,
uint16 _index,
bytes calldata _message,
bytes calldata _extraData
) external payable;
}
lib/layerzero/protocol-v2/contracts/interfaces/IMessagingContext.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingContext {
function isSendingMessage() external view returns (bool);
function getSendContext() external view returns (uint32 dstEid, address sender);
}
src/lz/GasFloor.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
// The two message types an OFT sends, which are the two keys its enforced options live under.
uint16 constant MSG_TYPE_SEND = 1;
uint16 constant MSG_TYPE_SEND_AND_CALL = 2;
// The most gas a floor may demand for `lzReceive`. An OFT credit costs well under a tenth of this
// on an EVM chain, and on Solana the field is compute units, where a whole transaction is capped
// at 1.4M. So this leaves room for a gas schedule to move a long way, and no room to price
// bridging out of reach.
uint128 constant MAX_LZ_RECEIVE_GAS = 1_000_000;
// The most native value a floor may attach to `lzReceive`, in the destination's smallest unit. It
// exists for Solana, where delivery has to fund the recipient's token account (about 2,040,000
// lamports); 10,000,000 lamports is 0.01 SOL. On an EVM destination the same number is 10^7 wei,
// which is nothing -- so one cap serves every route without knowing which is which.
uint128 constant MAX_LZ_RECEIVE_VALUE = 10_000_000;
/// @title GasFloor
/// @notice The one shape of LayerZero option a Pangea token may enforce: a single executor
/// `lzReceive` option, bounded.
///
/// WHY SO NARROW. Enforced options are prepended to every bridge transfer and paid for by the
/// sender, and LayerZero checks nothing about them beyond a two-byte type. So whoever may set them
/// could attach a native drop to an address of their own -- a toll on every transfer -- or demand
/// gas nobody can pay and stop bridging outright. A gas floor needs neither. What it needs is
/// "give `lzReceive` at least this much gas, and this much value", so that is all that is
/// accepted: no native drop, no compose option, no ordered execution, no second option, no DVN
/// option, and both numbers under hard caps.
///
/// THE ENCODING, from LayerZero's ExecutorOptions and OptionsBuilder:
///
/// uint16 3 options type 3
/// uint8 1 worker id: the executor
/// uint16 size 17 or 33 -- the option type byte plus the option
/// uint8 1 option type: lzReceive
/// uint128 gas
/// uint128 value present only when size is 33
library GasFloor {
error GasFloorOutOfRange(uint128 gas, uint128 value);
error OptionsNotAGasFloor(bytes options);
uint48 private constant HEADER_GAS_ONLY = 0x000301001101;
uint48 private constant HEADER_GAS_AND_VALUE = 0x000301002101;
function check(uint128 gas, uint128 value) internal pure {
if (gas == 0 || gas > MAX_LZ_RECEIVE_GAS || value > MAX_LZ_RECEIVE_VALUE) {
revert GasFloorOutOfRange(gas, value);
}
}
/// @notice The options bytes for a floor. Byte for byte what
/// `OptionsBuilder.newOptions().addExecutorLzReceiveOption(gas, value)` produces.
function encode(uint128 gas, uint128 value) internal pure returns (bytes memory) {
check(gas, value);
return value == 0
? abi.encodePacked(HEADER_GAS_ONLY, gas)
: abi.encodePacked(HEADER_GAS_AND_VALUE, gas, value);
}
/// @notice Read a floor back out of options bytes, refusing anything that is not exactly one.
function decode(bytes memory options) internal pure returns (uint128 gasLimit, uint128 value) {
uint256 n = options.length;
if (n != 22 && n != 38) revert OptionsNotAGasFloor(options);
uint48 header;
assembly {
header := shr(208, mload(add(options, 32)))
gasLimit := shr(128, mload(add(options, 38)))
}
if (header != (n == 22 ? HEADER_GAS_ONLY : HEADER_GAS_AND_VALUE)) revert OptionsNotAGasFloor(options);
if (n == 38) {
assembly {
value := shr(128, mload(add(options, 54)))
}
}
check(gasLimit, value);
}
}
src/lz/Routes.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
/// @notice Everything LayerZero needs to know about one route out of this chain: which message
/// libraries carry it, who executes it, and -- the part that matters -- who verifies it.
///
/// @dev `sendUln` and `receiveUln` are ABI-encoded `UlnConfig`, `executor` an ABI-encoded
/// `ExecutorConfig`, exactly as the libraries' own `setConfig` takes them. They are kept as
/// bytes so what a launch hands to LayerZero is byte for byte what was reviewed at deployment.
struct RouteConfig {
uint32 eid;
address sendLib;
address receiveLib;
bytes sendUln;
bytes executor;
bytes receiveUln;
/// @notice The gas floor every token launched here enforces on a transfer to `eid`: the gas
/// the destination's executor must give `lzReceive`, and the native value it must
/// attach (zero for an EVM destination; a Solana destination needs rent for the
/// recipient's token account). Bounded by GasFloor's caps.
uint128 lzReceiveGas;
uint128 lzReceiveValue;
}
/// @notice LayerZero's ULN verifier config. Mirrors `UlnConfig` in their message library.
struct UlnConfig {
uint64 confirmations;
uint8 requiredDVNCount;
uint8 optionalDVNCount;
uint8 optionalDVNThreshold;
address[] requiredDVNs;
address[] optionalDVNs;
}
/// @notice LayerZero's executor config. Mirrors `ExecutorConfig` in their message library.
struct ExecutorConfig {
uint32 maxMessageSize;
address executor;
}
// The only config types the ULN libraries define.
uint32 constant CONFIG_TYPE_EXECUTOR = 1;
uint32 constant CONFIG_TYPE_ULN = 2;
// What LayerZero writes in a count field to mean "none", as opposed to zero, which means "whatever
// the default is".
uint8 constant NIL_DVN_COUNT = type(uint8).max;
// The fewest independent verifiers a route may be pinned with.
uint8 constant MIN_VERIFIERS = 2;
library RouteLib {
error RouteInheritsDefaults(uint32 eid);
/// @notice The route to `eid` would be verified by fewer than MIN_VERIFIERS independent DVNs:
/// it has `required` required DVNs and an optional threshold of `optionalThreshold`,
/// and neither reaches the floor.
error RouteHasTooFewVerifiers(uint32 eid, uint8 required, uint8 optionalThreshold);
/// @notice A DVN list for the route to `eid` does not match its declared count, names the zero
/// address, or is not strictly ascending (how LayerZero itself rules out a repeat).
error RouteVerifiersMalformed(uint32 eid);
/// @notice Refuse a route that leaves anything to LayerZero's defaults, or that a single
/// verifier could vouch for.
///
/// @dev In a ULN config a zero is not a value, it is "use the default" -- and the defaults
/// belong to whoever administers the endpoint and can be changed at any time. A route
/// that inherits even one field is therefore not pinned at all. Every field must be set
/// explicitly, with `NIL_DVN_COUNT` where the intended answer is "none".
///
/// Explicit is not enough. A verifier is a party able to tell the token to mint, and the
/// set is pinned for the life of every token the factory launches, so a route resting on
/// one DVN rests on one key forever. Each direction must need two: two or more required
/// DVNs, or an optional threshold of two or more. NIL counts as none, not as 255.
function requireExplicit(RouteConfig memory r) internal pure {
if (r.sendLib == address(0) || r.receiveLib == address(0)) revert RouteInheritsDefaults(r.eid);
_requireExplicitUln(r.eid, r.sendUln);
_requireExplicitUln(r.eid, r.receiveUln);
ExecutorConfig memory e = abi.decode(r.executor, (ExecutorConfig));
if (e.maxMessageSize == 0 || e.executor == address(0)) revert RouteInheritsDefaults(r.eid);
}
function _requireExplicitUln(uint32 eid, bytes memory encoded) private pure {
UlnConfig memory u = abi.decode(encoded, (UlnConfig));
if (u.confirmations == 0 || u.requiredDVNCount == 0 || u.optionalDVNCount == 0) {
revert RouteInheritsDefaults(eid);
}
// The largest count is LayerZero's NIL: "none at all", which the library reads as zero
// confirmations. Explicit, and exactly the thing an explicit route must not say.
if (u.confirmations == type(uint64).max) revert RouteInheritsDefaults(eid);
uint8 required = u.requiredDVNCount == NIL_DVN_COUNT ? 0 : u.requiredDVNCount;
uint8 optional = u.optionalDVNCount == NIL_DVN_COUNT ? 0 : u.optionalDVNCount;
// A count that disagrees with its list, or a list naming one DVN twice, would let a
// config claim two verifiers while holding one. LayerZero refuses both when the config is
// set, but that is mid-launch; here it is refused before the factory exists.
if (u.requiredDVNs.length != required || u.optionalDVNs.length != optional) {
revert RouteVerifiersMalformed(eid);
}
_requireAscending(eid, u.requiredDVNs);
_requireAscending(eid, u.optionalDVNs);
// A threshold above the number of optional DVNs can never be met; LayerZero rejects it
// too, and counting it here would pass a route nothing can verify.
uint8 threshold = u.optionalDVNThreshold > optional ? 0 : u.optionalDVNThreshold;
if (required < MIN_VERIFIERS && threshold < MIN_VERIFIERS) {
revert RouteHasTooFewVerifiers(eid, required, threshold);
}
}
function _requireAscending(uint32 eid, address[] memory dvns) private pure {
address last = address(0);
for (uint256 i = 0; i < dvns.length; i++) {
if (dvns[i] <= last) revert RouteVerifiersMalformed(eid);
last = dvns[i];
}
}
}
src/v3/GasFloorV3.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
import {MAX_LZ_RECEIVE_VALUE} from "../lz/GasFloor.sol";
// E6 (audit E5 M-A): the v3 gas floor's cap. A v3 receive priced from the price log (a V1-hook pool)
// needs up to 1,088,036 gas composed on an EVM chain (enforced 1,310,000: GapFloorsV3.sol), above
// GasFloor's 1,000,000. The v1/v2 cap (GasFloor.MAX_LZ_RECEIVE_GAS, used by LaunchOwner,
// LaunchOwnerV2 and the v1/v2 factories) is unchanged; only the v3 factory and LaunchOwnerV3 use this.
// 1,400,000: Solana's per-transaction compute limit (the same field is CU there), so no v3 floor can
// ask for gas no route could deliver.
uint128 constant MAX_LZ_RECEIVE_GAS_V3 = 1_400_000;
/// @title GasFloorV3 -- GasFloor (src/lz/GasFloor.sol) with the v3 gas cap
/// @notice Exactly GasFloor's one accepted option shape (a single executor lzReceive option, gas and
/// optional value, both bounded), byte for byte, and its errors (same selectors), with the gas
/// bounded by MAX_LZ_RECEIVE_GAS_V3 instead of MAX_LZ_RECEIVE_GAS.
library GasFloorV3 {
error GasFloorOutOfRange(uint128 gas, uint128 value);
error OptionsNotAGasFloor(bytes options);
uint48 private constant HEADER_GAS_ONLY = 0x000301001101;
uint48 private constant HEADER_GAS_AND_VALUE = 0x000301002101;
function check(uint128 gas, uint128 value) internal pure {
if (gas == 0 || gas > MAX_LZ_RECEIVE_GAS_V3 || value > MAX_LZ_RECEIVE_VALUE) {
revert GasFloorOutOfRange(gas, value);
}
}
function encode(uint128 gas, uint128 value) internal pure returns (bytes memory) {
check(gas, value);
return value == 0 ? abi.encodePacked(HEADER_GAS_ONLY, gas) : abi.encodePacked(HEADER_GAS_AND_VALUE, gas, value);
}
function decode(bytes memory options) internal pure returns (uint128 gasLimit, uint128 value) {
uint256 n = options.length;
if (n != 22 && n != 38) revert OptionsNotAGasFloor(options);
uint48 header;
assembly {
header := shr(208, mload(add(options, 32)))
gasLimit := shr(128, mload(add(options, 38)))
}
if (header != (n == 22 ? HEADER_GAS_ONLY : HEADER_GAS_AND_VALUE)) revert OptionsNotAGasFloor(options);
if (n == 38) {
assembly {
value := shr(128, mload(add(options, 54)))
}
}
check(gasLimit, value);
}
}
src/v4/bridge/BridgeCodecV4.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
/// @title BridgeCodecV4 -- codec 0x05 (V4-INTERFACES §11.2.5), transport-neutral, big-endian
/// 0 ver 0x05 | 1 mode (0 plain, 1 buy, 2 creator mirror, 3 open authorisation, 0xFF refund) | 2 transportId |
/// 3 priceSource (0 none, 1 signed, 2 on-chain fallback) | 4 srcPcid u32 | 8 dstPcid u32 | 12 coinId | 44 recipient |
/// 76 sender | 108 amountSD u64 (shared decimals 6) | 116 psUsdE18 u128 | 132 p2E18 u128 | 148 bridgeFeePpm u32 |
/// 152 coverSrcMicroUsd u32 | 156 minCreditedSD u64 | 164 priceClass u8 | 165 reserved 3 = 0 | 168 tail
/// tail: mode 0/1 composeMsg (composed iff length > 168); mode 2 creatorEvm 32 | creatorSvm 32 | u64 roleNonce |
/// u8 renounced (241 B); mode 3 opener 32 | u64 deadline | the mode-2 role fields | u64 issuedAt (unix s at the
/// home's authorizeOpen; B4-I1: appended, 289 B); mode 0xFF none.
/// META-OPENLATER (audit G-ROLL 18 M-2): a mode 3's header recipient (44..76, zero before) = uriHash = keccak256 of the
/// home coin's metadataURI at authorizeOpen; the far chain opens the authorised leg only with that URI. The length is
/// unchanged (289 B = the LayerZero maxMessageSize pin toward Solana).
library BridgeCodecV4 {
uint8 internal constant VERSION = 0x05;
uint8 internal constant MODE_PLAIN = 0;
uint8 internal constant MODE_BUY = 1;
uint8 internal constant MODE_ROLE = 2;
uint8 internal constant MODE_OPEN_AUTH = 3;
uint8 internal constant MODE_REFUND = 0xFF;
uint8 internal constant PS_NONE = 0;
uint8 internal constant PS_SIGNED = 1;
uint8 internal constant PS_FALLBACK = 2;
uint256 internal constant HEADER = 168;
uint256 internal constant ROLE_LEN = 73;
uint256 internal constant OPEN_AUTH_LEN = 121;
uint8 internal constant SHARED_DECIMALS = 6;
struct Header {
uint8 mode;
uint8 transportId;
uint8 priceSource;
uint32 srcPcid;
uint32 dstPcid;
bytes32 coinId;
bytes32 recipient;
bytes32 sender;
uint64 amountSD;
uint128 psUsdE18;
uint128 p2E18;
uint32 bridgeFeePpm;
uint32 coverSrcMicroUsd;
uint64 minCreditedSD;
uint8 priceClass;
}
struct Role {
bytes32 creatorEvm;
bytes32 creatorSvm;
uint64 roleNonce;
bool renounced;
}
error BadVersion();
error BadReserved();
error BadMessage(uint8 why);
function encode(Header memory h, bytes memory tail) internal pure returns (bytes memory) {
return abi.encodePacked(
abi.encodePacked(VERSION, h.mode, h.transportId, h.priceSource, h.srcPcid, h.dstPcid, h.coinId, h.recipient, h.sender),
abi.encodePacked(h.amountSD, h.psUsdE18, h.p2E18, h.bridgeFeePpm, h.coverSrcMicroUsd, h.minCreditedSD, h.priceClass),
bytes3(0),
tail
);
}
function encodeRole(Role memory r) internal pure returns (bytes memory) {
return abi.encodePacked(r.creatorEvm, r.creatorSvm, r.roleNonce, r.renounced ? uint8(1) : uint8(0));
}
/// @notice Strict: version, reserved, mode-specific length and fields. why: 1 short, 2 unknown mode, 3 tail length,
/// 4 cover in mode 0, 5 priceSource / class, 6 bridge fee >= 1e6, 7 refund / control fields not zero.
function decode(bytes calldata b) internal pure returns (Header memory h, bytes calldata tail) {
if (b.length < HEADER) revert BadMessage(1);
if (uint8(b[0]) != VERSION) revert BadVersion();
if (bytes3(b[165:168]) != bytes3(0)) revert BadReserved();
h.mode = uint8(b[1]);
h.transportId = uint8(b[2]);
h.priceSource = uint8(b[3]);
h.srcPcid = uint32(bytes4(b[4:8]));
h.dstPcid = uint32(bytes4(b[8:12]));
h.coinId = bytes32(b[12:44]);
h.recipient = bytes32(b[44:76]);
h.sender = bytes32(b[76:108]);
h.amountSD = uint64(bytes8(b[108:116]));
h.psUsdE18 = uint128(bytes16(b[116:132]));
h.p2E18 = uint128(bytes16(b[132:148]));
h.bridgeFeePpm = uint32(bytes4(b[148:152]));
h.coverSrcMicroUsd = uint32(bytes4(b[152:156]));
h.minCreditedSD = uint64(bytes8(b[156:164]));
h.priceClass = uint8(b[164]);
tail = b[168:];
uint8 m = h.mode;
if (m > MODE_OPEN_AUTH && m != MODE_REFUND) revert BadMessage(2);
if (m == MODE_ROLE && tail.length != ROLE_LEN) revert BadMessage(3);
if (m == MODE_OPEN_AUTH && tail.length != OPEN_AUTH_LEN) revert BadMessage(3);
if ((m == MODE_REFUND) && tail.length != 0) revert BadMessage(3);
if (m == MODE_PLAIN && h.coverSrcMicroUsd != 0) revert BadMessage(4);
if (h.priceSource > PS_FALLBACK || (h.priceSource != PS_FALLBACK && h.priceClass != 0)) revert BadMessage(5);
if (h.priceSource == PS_NONE && (h.psUsdE18 != 0 || h.p2E18 != 0)) revert BadMessage(5);
if (h.bridgeFeePpm >= 1_000_000) revert BadMessage(6);
if (m >= MODE_ROLE && (h.priceSource != PS_NONE || h.coverSrcMicroUsd != 0 || h.minCreditedSD != 0)) revert BadMessage(7);
if (m == MODE_ROLE || m == MODE_OPEN_AUTH) {
if (h.amountSD != 0) revert BadMessage(7);
}
}
function decodeRole(bytes calldata t) internal pure returns (Role memory r) {
r.creatorEvm = bytes32(t[0:32]);
r.creatorSvm = bytes32(t[32:64]);
r.roleNonce = uint64(bytes8(t[64:72]));
r.renounced = uint8(t[72]) != 0;
}
/// @notice msgId = keccak256(u8 transportId | bytes32 transportMsgId) (LZ guid / Hyperlane message id).
function msgId(uint8 transportId, bytes32 transportMsgId) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(transportId, transportMsgId));
}
}
src/v4/bridge/ITransportV4.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
/// @title ITransportAdapterV4 -- a transport adapter of the shared bridge (V4-INTERFACES §11.2.14)
interface ITransportAdapterV4 {
function transportId() external view returns (uint8);
function bridge() external view returns (address);
function quote(uint32 dstPcid, bytes calldata message, bytes calldata extraOptions) external view returns (uint256);
/// @notice Bridge only. Returns the transport's own message id (LZ guid / Hyperlane message id).
function send(uint32 dstPcid, bytes calldata message, bytes calldata extraOptions, address refundTo)
external
payable
returns (bytes32 transportMsgId);
}
/// @notice What the adapters read from / call on the bridge.
interface IBridgeForAdaptersV4 {
struct Route {
uint32 remoteDomain;
bytes32 peer;
}
function owner() external view returns (address);
function routeOf(uint32 pcid, uint8 tid) external view returns (Route memory);
function pcidOf(uint8 tid, uint32 remoteDomain) external view returns (uint32);
function receiveFromTransport(uint32 srcPcid, bytes32 srcPeer, bytes calldata message, bytes32 transportMsgId, address executor)
external;
}
src/v4/bridge/PangeaDeployerV4.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
/// @notice What a v4 infra contract reads from its deployer in its constructor (the TokenDeployerV4 pattern, §11.2.1):
/// chain-specific values stay out of the init code, so the address is the same on every EVM chain.
interface IPendingConfigV4 {
function pending() external view returns (bytes memory);
}
/// @title PangeaDeployerV4 -- CREATE2 deployer of the shared-bridge infra (bridge, adapters, coin deployer, core)
/// @notice Itself deployed through the canonical CREATE2 deployer with a fixed salt and `initializer` (the same deploy
/// key / multisig in every config), so it has one address on every EVM chain, and so does everything it deploys
/// with the same salt and init code. Only `initializer` deploys; the per-chain config is handed over through
/// `pending()` for the duration of the constructor only.
contract PangeaDeployerV4 is IPendingConfigV4 {
address public immutable initializer;
bytes internal _pending;
event Deployed(bytes32 indexed salt, address indexed at);
error NotInitializer();
error DeployFailed();
constructor(address initializer_) {
initializer = initializer_;
}
function pending() external view returns (bytes memory) {
return _pending;
}
function predict(bytes32 salt, bytes calldata initcode) external view returns (address) {
return address(uint160(uint256(keccak256(abi.encodePacked(bytes1(0xff), address(this), salt, keccak256(initcode))))));
}
function deploy(bytes32 salt, bytes calldata initcode, bytes calldata config) external returns (address a) {
if (msg.sender != initializer) revert NotInitializer();
_pending = config;
bytes memory code = initcode;
assembly ("memory-safe") {
a := create2(0, add(code, 0x20), mload(code), salt)
}
delete _pending;
if (a == address(0)) revert DeployFailed();
emit Deployed(salt, a);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero/protocol-v2/",
"@layerzerolabs/oapp-evm/=lib/layerzero/oapp-evm/",
"@layerzerolabs/oft-evm/=lib/layerzero/oft-evm/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@uniswap/v4-core/=lib/uniswap-v4-core/",
"ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"layerzero/=lib/layerzero/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solmate/=lib/solmate/",
"uniswap-v4-core/=lib/uniswap-v4-core/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.