Verified contractExactUNLICENSED
PangeaOFTV3
Address0x64f05f29b5d77431dd69a4f5d645f9cc5dd3f6ea
- Balance
0 ETH
- Transactions
86
- Compiler
solc 0.8.30
- Same code
134 more contracts
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,330,192
- Creation transaction
- 0xe391fa6bbe…83cfde8c2b
- Main copy (most transactions)
- 0x19993b3c…5a7526ea
62 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/v3/PangeaOFTV3.solmain35 KB
- lib/layerzero/oapp-evm/contracts/oapp/OApp.sol1.53 KB
- lib/layerzero/oapp-evm/contracts/oapp/OAppCore.sol3.36 KB
- lib/layerzero/oapp-evm/contracts/oapp/OAppReceiver.sol5.41 KB
- lib/layerzero/oapp-evm/contracts/oapp/OAppSender.sol5.63 KB
- lib/layerzero/oapp-evm/contracts/oapp/interfaces/IOAppCore.sol1.86 KB
- lib/layerzero/oapp-evm/contracts/oapp/interfaces/IOAppMsgInspector.sol909 B
- lib/layerzero/oapp-evm/contracts/oapp/interfaces/IOAppOptionsType3.sol1.44 KB
- lib/layerzero/oapp-evm/contracts/oapp/interfaces/IOAppReceiver.sol1.08 KB
- lib/layerzero/oapp-evm/contracts/oapp/libs/OAppOptionsType3.sol4.9 KB
- lib/layerzero/oapp-evm/contracts/precrime/OAppPreCrimeSimulator.sol5.36 KB
- lib/layerzero/oapp-evm/contracts/precrime/interfaces/IOAppPreCrimeSimulator.sol1.92 KB
- lib/layerzero/oapp-evm/contracts/precrime/interfaces/IPreCrime.sol1.11 KB
- lib/layerzero/oapp-evm/contracts/precrime/libs/Packet.sol2.47 KB
- lib/layerzero/oft-evm/contracts/OFT.sol3.4 KB
- lib/layerzero/oft-evm/contracts/OFTCore.sol20.65 KB
- lib/layerzero/oft-evm/contracts/interfaces/IOFT.sol6.28 KB
- lib/layerzero/oft-evm/contracts/libs/OFTComposeMsgCodec.sol2.99 KB
- lib/layerzero/oft-evm/contracts/libs/OFTMsgCodec.sol2.91 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/IMessageLib.sol805 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
- lib/layerzero/protocol-v2/contracts/interfaces/ISendLib.sol923 B
- lib/layerzero/protocol-v2/contracts/libs/AddressCast.sol1.47 KB
- lib/layerzero/protocol-v2/contracts/messagelib/libs/PacketV1Codec.sol3.67 KB
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4.45 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol192 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol181 B
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol10.9 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol9.44 KB
- lib/openzeppelin-contracts/contracts/utils/Address.sol6.03 KB
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/openzeppelin-contracts/contracts/utils/Errors.sol896 B
- lib/openzeppelin-contracts/contracts/utils/Panic.sol1.97 KB
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol870 B
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol28.31 KB
- lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34.94 KB
- src/ITokenParams.sol2.39 KB
- src/lz/GasFloor.sol3.83 KB
- src/v3/GapFloorsV3.sol5.22 KB
- src/v3/GasFloorV3.sol2.44 KB
- src/v3/ITokenParamsV3.sol1.35 KB
- src/v3/gap/GapCoverLib.sol17.57 KB
- src/v3/gap/GapMath.sol25.2 KB
- src/v3/gap/GapModuleBase.sol18.79 KB
- src/v3/gap/GapPriceLib.sol4.26 KB
- src/v3/gap/GapPriceLog.sol31.39 KB
- src/v3/gap/IGapDelivery.sol6.19 KB
- src/v3/gap/IGapReader.sol2.14 KB
- src/v3/gap/IPangeaGapRegistry.sol24.46 KB
- src/v3/gap/IPangeaOFTV3Gap.sol5.77 KB
- src/v3/gap/PangeaOFTV3GapModule.sol63.67 KB
- src/v3/gap/PangeaOFTV3LogModule.sol31.83 KB
- src/v3/gap/PangeaOFTV3Storage.sol5.49 KB
src/v3/PangeaOFTV3.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
import {OFT} from "@layerzerolabs/oft-evm/contracts/OFT.sol";
import {SendParam, OFTReceipt, MessagingFee, MessagingReceipt} from "@layerzerolabs/oft-evm/contracts/interfaces/IOFT.sol";
import {Origin} from "@layerzerolabs/oapp-evm/contracts/oapp/OApp.sol";
import {MessagingParams} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import {IOAppMsgInspector} from "@layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppMsgInspector.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ITokenParamsV3} from "./ITokenParamsV3.sol";
import {PangeaOFTV3Storage as S} from "./gap/PangeaOFTV3Storage.sol";
import {PangeaOFTV3GapModule} from "./gap/PangeaOFTV3GapModule.sol";
import {PangeaOFTV3LogModule} from "./gap/PangeaOFTV3LogModule.sol";
import {IGapDelivery, IGapPrepay} from "./gap/IGapDelivery.sol";
import {GasFloorV3} from "./GasFloorV3.sol";
import {KEYS_ONLY_LZ_RECEIVE_GAS_V3} from "./GapFloorsV3.sol";
/// @title PangeaOFTV3
/// @notice Factory v3's token: PangeaOFTV2 (supply modes, metadata, the 0.2% bridge fee, nine
/// decimals; its notes below still describe all of that) plus the bridge GAP FEE
/// (docs/v3-gap-fee-spec.md, owner-approved 2026-10-28).
///
/// THE GAP FEE. A bridge from a chain where the token is cheap to one where it is dear withholds,
/// at the destination, the price gap minus an allowance (both official pools' fees and a
/// margin), so a bridge arbitrage nets at most the margin. The 0.2% bridge fee is always charged and
/// the gap fee comes on top, charged on the amount before it (owner 2026-10-28; GapMath.gapFee). The withheld part is never
/// minted -- it was burned at the source with the rest -- so it is burned. Dear-to-cheap is free.
///
/// - Prices come from the token's OFFICIAL launch pool only (a Uniswap v4 pool, named once by the
/// factory in the chain's PangeaGapRegistry), times the registry's USD route for the pool's
/// quote. Other pairs of the token are ignored.
/// - The official pool's price: on a recording hook (PangeaFeeHookV2) at SWAP time by its afterSwap
/// -> `recordPrice`; on the live PangeaFeeHook (V1, which records nothing; v3 launches use it, owner
/// 2026-10-30) from the token's PRICE LOG (PangeaOFTV3LogModule: entries written by `poke` and by
/// sends and receives, consumed by sends and receives). Transfers record nothing. Both sides read two closes over
/// RECORDED windows (a block with at least one record; its close is its last record): close1 of
/// the latest recorded window before this block, close2 of the one before that; the pool's
/// opening price stands in while fewer than two windows exist (spec §5.2).
/// - Source (send): Ps = the LOWER of the two closes, rounded up, times the route (and, when the
/// pool's quote has a price class, the lower close in quote units), carried in the message with
/// this pool's fee plus the bridge cost (LayerZero's quote for the token's ENFORCED options; the
/// gas allowance is gone since Amendment 6, whose gas COVER is the registry's live native route),
/// the bridge fee and the sender's minimum credit (codec v3,
/// docs/v3c-gap-spec.md). Neither price readable: the send reverts (GapSourceUnreadable).
/// - Destination (receive): Pd = the HIGHER of the two closes, rounded down -- in quote units when
/// both quotes share a class, else times the route; GapMath. Never fee 0 on an unreadable price:
/// no pool (unless the receiver is a listed seeder), an unreadable fee, price or route REVERTS,
/// retriable (GapNoPool / GapUnreadable), until fixed or the registry owner's per-token escape
/// credits it in full. Too little gas for the reads reverts `GapGasTooLow` (owner Q1).
///
/// @notice One launch's token on one EVM chain. Five of these -- plus the Solana program --
/// make up a single token: a slice minted on each chain, all of it paired at launch.
///
/// SUPPLY IS MINTED AT DEPLOY AND NEVER AGAIN. Each chain's instance mints its own slice in the
/// constructor, and the slices across all chains sum to the launch's total. After that nothing
/// can mint: there is no mint function, no minter role, no owner path to one. Tokens move
/// between chains by burning here and minting there inside LayerZero's OFT machinery, which
/// conserves the global total by construction -- less what the gap fee withholds, which is
/// burned at the source and never minted at the destination.
///
/// `totalSupply()` REPORTS THIS CHAIN'S LAUNCH SLICE (SUPPLY_SLICE, mirrored from Solana by the
/// SupplyReporter) OR THE LAUNCH TOTAL (SUPPLY_TOTAL). What is really on this chain is
/// `localSupply()`. Every tracker computes market cap as price times `totalSupply()`, which is why
/// it does not follow bridging.
///
/// OWNERSHIP IS WHERE THE MINT RISK LIVES, AND THIS CONTRACT DOES NOT CLOSE IT. `setPeer` is
/// owner-only, and a peer is an address allowed to cause mints here. A factory launch wires the
/// peers while the factory owns the token and then transfers ownership, in the same transaction,
/// to a LaunchOwner constructed already sealed. A token deployed any other way has whatever owner
/// it was given.
///
/// THE GAP MODULE (size, owner decision 2026-10-28). Everything of the token that is not on its
/// transfer path -- the gap reads and arithmetic, the gap views, the metadata -- is the code of one
/// PangeaOFTV3GapModule per chain (made by TokenDeployerV3, at one address everywhere, immutable),
/// run by DELEGATECALL: `send` and the receive call it for the source quote and the withholding,
/// and every function this contract does not have itself (`gapSendQuote`, `gapPreview`,
/// `gapRecords`, `gapCloses`, `gapRecordBlocks`, `gapRecordFees`, `recordPrice`, `gapWithheld`, `gapBurnedLD`, `metadataURI` and its authority calls) is
/// answered by it through `fallback`. The ABI is IPangeaOFTV3 (src/v3/IPangeaOFTV3.sol): the
/// same functions and events as before. The state the two share is one ERC-7201 namespace
/// (PangeaOFTV3Storage). The price record is the module's `recordPrice`, called by the official pool's hook.
contract PangeaOFTV3 is OFT {
// =============================================================== PangeaOFTV2, unchanged
/// @notice What every instance of this token across all chains is meant to sum to.
uint256 public immutable launchTotal;
/// @notice What `totalSupply()` reports: `SUPPLY_SLICE` or `SUPPLY_TOTAL`. In the init code.
uint8 public immutable supplyMode;
/// @dev Public through the module (fallback): SUPPLY_SLICE(), SUPPLY_TOTAL().
uint8 internal constant SUPPLY_SLICE = 0;
uint8 internal constant SUPPLY_TOTAL = 1;
/// @notice This chain's slice: what it minted at launch.
uint256 public immutable launchSlice;
/// @notice What `totalSupply()` reports in SUPPLY_SLICE: the supply as read on Solana.
uint256 public reportedSupply;
/// @notice The only address that may change `reportedSupply` (this chain's SupplyReporter).
address public immutable supplyReporter;
address private constant SUPPLY_SIGNAL_TO = 0x000000000000000000000000000000000000dEaD;
/// @notice Who launched this token. Immutable, and part of the token's own address.
/// @dev `metadataURI`, `metadataAuthority` (the creator at first, never the owner) and
/// `pendingMetadataAuthority` are the module's (PangeaOFTV3Storage), as are their setters.
address public immutable creator;
event MetadataURISet(string uri);
/// @notice `totalSupply()` now reports `newSupply` (was `oldSupply`). No balance moved.
event SupplyReported(uint256 oldSupply, uint256 newSupply);
error SliceExceedsLaunchTotal(uint256 slice, uint256 total);
error ZeroAuthority();
error NoBridgeFeeRecipient();
error AmountTooSmallToBridge(uint256 amount);
error NotSupplyReporter();
error UnknownSupplyMode(uint8 supplyMode);
error SupplyIsTheTotal();
/// @notice What is taken on a transfer to another chain (v3c-evm-final): the chain registry's
/// admin bridgeFeeBps() (0..=50 bps, default 20), read at every send under BRIDGE_FEE_READ_GAS;
/// unreadable or out of bounds: 20 bps (never 0 for want of an answer).
/// @dev Public through the module (fallback): BRIDGE_FEE_BPS(), bridgeFeePpm() (both live).
uint16 internal constant BRIDGE_FEE_DEFAULT_BPS = 20;
uint16 internal constant BRIDGE_FEE_MAX_BPS = 50;
uint256 internal constant BRIDGE_FEE_READ_GAS = 10_000;
/// @notice Where that fee goes, on this chain. Fixed at construction.
address public immutable bridgeFeeTo;
// =============================================================== the gap fee
/// @notice This chain's Uniswap v4 PoolManager: transfers to or from it record the official
/// pool's price. From the deployer (ITokenParamsV3), so it does not move the address.
address public immutable poolManager;
/// @notice IPangeaOFTV3Gap.gapRegistry: the registry this token reads (immutable).
address public immutable gapRegistry;
/// @notice The PangeaOFTV3GapModule this token runs its gap reads, gap views and metadata
/// calls in (by DELEGATECALL). From the deployer, like the PoolManager.
address public immutable gapModule;
/// @notice v3c-evm-log: the PangeaOFTV3LogModule (the hook-independent price log) the gap module
/// runs, by DELEGATECALL, for every selector it does not have. From the deployer, whose
/// ADMIN can only name the one code hash TokenDeployerV3 pins.
address public immutable gapLogModule;
uint8 internal constant TOKEN_DECIMALS = 9;
error NoGapModule();
error NoGapRegistry();
error NoPoolManager();
/// @notice Only this token itself (its gap module, running as it) may credit.
error NotSelf();
/// @param name_ Token name, identical on every chain.
/// @param symbol_ Token symbol, identical on every chain.
/// @param launchTotal_ The sum of every chain's slice.
/// @param supplyMode_ SUPPLY_SLICE or SUPPLY_TOTAL.
/// @param creator_ Recorded permanently as `creator`, and the first `metadataAuthority`.
/// @param metadataURI_ Logo, description and links. May be empty and set later.
/// @dev The endpoint, owner, slice, bridge-fee recipient, supply reporter, PoolManager and gap
/// registry differ per chain and are read from the deployer (ITokenParamsV3), keeping
/// them out of the init code so one salt gives one address on every EVM chain.
constructor(
string memory name_,
string memory symbol_,
uint256 launchTotal_,
uint8 supplyMode_,
address creator_,
string memory metadataURI_
)
OFT(name_, symbol_, ITokenParamsV3(msg.sender).pendingEndpoint(), ITokenParamsV3(msg.sender).pendingOwner())
Ownable(ITokenParamsV3(msg.sender).pendingOwner())
{
ITokenParamsV3 d = ITokenParamsV3(msg.sender);
address owner_ = d.pendingOwner();
uint256 slice = d.pendingSlice();
bridgeFeeTo = d.pendingBridgeFeeTo();
if (bridgeFeeTo == address(0)) revert NoBridgeFeeRecipient();
poolManager = d.pendingPoolManager();
if (poolManager == address(0)) revert NoPoolManager();
gapRegistry = d.pendingGapRegistry();
if (gapRegistry == address(0)) revert NoGapRegistry();
gapModule = d.pendingGapModule();
if (gapModule.code.length == 0) revert NoGapModule();
gapLogModule = d.pendingGapLogModule();
if (gapLogModule.code.length == 0) revert NoGapModule();
if (creator_ == address(0)) revert ZeroAuthority();
// A zero slice is a chain joined after launch, which mints nothing.
if (slice > launchTotal_) revert SliceExceedsLaunchTotal(slice, launchTotal_);
if (supplyMode_ > SUPPLY_TOTAL) revert UnknownSupplyMode(supplyMode_);
launchTotal = launchTotal_;
supplyMode = supplyMode_;
launchSlice = slice;
reportedSupply = slice;
supplyReporter = d.pendingSupplyReporter();
creator = creator_;
S.Layout storage l = S.layout();
l.metadataAuthority = creator_;
l.metadataURI = metadataURI_;
if (bytes(metadataURI_).length > 0) emit MetadataURISet(metadataURI_);
if (slice != 0) _mint(owner_, slice);
}
// ------------------------------------------------------------- supply (PangeaOFTV2)
function totalSupply() public view override returns (uint256) {
return supplyMode == SUPPLY_TOTAL ? launchTotal : reportedSupply;
}
function reportSupply(uint256 newSupply) external {
if (supplyReporter == address(0) || msg.sender != supplyReporter) revert NotSupplyReporter();
if (supplyMode == SUPPLY_TOTAL) revert SupplyIsTheTotal();
uint256 old = reportedSupply;
if (newSupply == old) return;
reportedSupply = newSupply;
emit SupplyReported(old, newSupply);
emit Transfer(address(0), SUPPLY_SIGNAL_TO, 0);
}
function localSupply() external view returns (uint256) {
return super.totalSupply();
}
/// @notice Nine on every chain (Solana's u64 amounts; see PangeaOFTV2).
function decimals() public pure override returns (uint8) {
return TOKEN_DECIMALS;
}
// ------------------------------------------------------------- the bridge fee (PangeaOFTV2)
/// @dev The fee is the bridge fee (`_bridgeFeeBps`) of the amount asked for, rounded down; what is
/// delivered is the rest, rounded down to what can cross. An amount so small that nothing would
/// arrive is refused.
function _debitView(uint256 _amountLD, uint256 _minAmountLD, uint32 /*_dstEid*/ )
internal
view
override
returns (uint256 amountSentLD, uint256 amountReceivedLD)
{
return _debitAt(_amountLD, _minAmountLD, _bridgeFeeBps());
}
/// @dev The registry's bridgeFeeBps(), gas-capped; unreadable or above 50: the default 20.
function _bridgeFeeBps() internal view returns (uint16) {
(bool ok, bytes memory ret) =
gapRegistry.staticcall{gas: BRIDGE_FEE_READ_GAS}(abi.encodeWithSelector(BRIDGE_FEE_BPS_SEL));
if (!ok || ret.length != 32) return BRIDGE_FEE_DEFAULT_BPS;
uint256 v = abi.decode(ret, (uint256));
return v <= BRIDGE_FEE_MAX_BPS ? uint16(v) : BRIDGE_FEE_DEFAULT_BPS;
}
/// @dev IPangeaGapRegistry.bridgeFeeBps().
bytes4 internal constant BRIDGE_FEE_BPS_SEL = bytes4(keccak256("bridgeFeeBps()"));
function _debitAt(uint256 _amountLD, uint256 _minAmountLD, uint16 bps)
internal
view
returns (uint256 amountSentLD, uint256 amountReceivedLD)
{
uint256 fee = (_amountLD * bps) / 10_000;
amountReceivedLD = _removeDust(_amountLD - fee);
if (amountReceivedLD == 0) revert AmountTooSmallToBridge(_amountLD);
amountSentLD = amountReceivedLD + fee;
if (amountReceivedLD < _minAmountLD) revert SlippageExceeded(amountReceivedLD, _minAmountLD);
}
/// @dev The fee is MOVED to `bridgeFeeTo`; only the rest is burned. The source's gap price is
/// read in `_buildMsgAndOptions`, which `_send` calls right after this (nothing between
/// them touches the pool, so the price is the same), and which `quoteSend` shares.
function _debit(address _from, uint256 _amountLD, uint256 _minAmountLD, uint32 _dstEid)
internal
override
returns (uint256 amountSentLD, uint256 amountReceivedLD)
{
uint16 bps = _bridgeFeeBps();
(amountSentLD, amountReceivedLD) = _debitAt(_amountLD, _minAmountLD, bps);
uint256 fee = amountSentLD - amountReceivedLD;
// v3c-evm-log: a V1-hook pool's send consumes the price log here (state; its price reaches
// the view `_buildMsgAndOptions` in transient storage) and owes the consumed entries'
// writers their reward, which is paid OUT OF the bridge fee (never on top): it stays in this
// token until claimed (`claimWriterRewards`). AMENDMENT 6: gapDebit also marks the route's
// cover window (the one state write of the gas cover) and hands the send's gapMessage the fee
// charged here (`bps`), so the header carries exactly it.
uint256 reward = abi.decode(
_module(abi.encodeCall(PangeaOFTV3LogModule.gapDebit, (_toSD(amountReceivedLD), fee, _dstEid, bps))), (uint256)
);
if (reward > fee) reward = fee;
if (fee - reward != 0) _transfer(_from, bridgeFeeTo, fee - reward);
if (reward != 0) _transfer(_from, address(this), reward);
_burn(_from, amountReceivedLD);
}
/// @dev The send's transient price word (the module's LOG_T) is cleared once the send is built,
/// so a later quote in the same transaction prices afresh.
function _send(SendParam calldata _sendParam, MessagingFee calldata _fee, address _refundAddress)
internal
override
returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt)
{
(msgReceipt, oftReceipt) = super._send(_sendParam, _fee, _refundAddress);
bytes32 slot = LOG_T;
bytes32 slotC = COVER_T;
assembly ("memory-safe") {
tstore(slot, 0)
tstore(slotC, 0)
}
}
/// @dev PangeaOFTV3GapModule.LOG_T and COVER_T (GapModuleBase).
bytes32 internal constant LOG_T = bytes32(uint256(keccak256("pangea.oft.v3.log.send")) - 1);
bytes32 internal constant COVER_T = bytes32(uint256(keccak256("pangea.oft.v3.cover.send")) - 1);
/// @dev recordPrice(bytes32,uint160,uint160,uint16): the log module's (E5).
bytes4 internal constant RECORD_PRICE_SEL = bytes4(keccak256("recordPrice(bytes32,uint160,uint160,uint16)"));
/// @dev E6 (gas): the log module's plan / consume / quote, which the gap module reaches by calling
/// this token: sent straight to the log module (no gap module hop, no gapLogModule() read).
bytes4 internal constant LOG_PLAN_R_SEL =
bytes4(keccak256("gapLogPlanR(bytes32,address,address,bool,uint32,uint256,uint32)"));
bytes4 internal constant LOG_CONSUME_SEL = bytes4(keccak256("gapLogConsume(uint256[6])"));
bytes4 internal constant LOG_QUOTE_SEL = bytes4(keccak256("gapLogQuote(bool,uint256,uint32)"));
/// @notice v3c-evm-log: pays the caller every price-log writer reward it is owed (out of this
/// token's own balance, where the sends' bridge fees put them). Returns the amount.
function claimWriterRewards() external returns (uint256 amountLD) {
amountLD = abi.decode(_module(abi.encodeCall(PangeaOFTV3LogModule.gapClaimTake, ())), (uint256));
if (amountLD != 0) _transfer(address(this), msg.sender, amountLD);
}
// ------------------------------------------------------------- send: the v3 message
/// @dev Codec v3 (docs/v3c-gap-spec.md §1, AMENDMENT 5): the 96-byte header, then composeFrom | composeMsg
/// when there is a compose message. Reverts GapGasTooLow when the caller left too little
/// gas to price or to quote the bridge cost, GapSourceUnreadable when nothing prices.
/// The bridge cost is quoted for the ENFORCED options only: the `options` built here
/// (with the sender's extraOptions, SEND_AND_CALL when composed) never reach it.
function _buildMsgAndOptions(SendParam calldata _sendParam, uint256 _amountLD)
internal
view
override
returns (bytes memory message, bytes memory options)
{
// Owner Q64: a composed send into Solana prepays P (q7b); it must name a least credited amount >= 1
// (oftCmd's minCreditedLD), so a zero-credit arrival holds (retriable) instead of landing and spending
// the prepay's Y. Checked first (quote and send refuse alike, before any pricing).
if (_sendParam.composeMsg.length > 0 && _isSolanaEid(_sendParam.dstEid) && _noMinimum(_sendParam.oftCmd)) {
revert PrepaidComposeNeedsMinCredited(_sendParam.dstEid);
}
// The v3 message is the module's (the compose cap toward Solana, the source quote, the
// bridge cost, the codec); msg.sender is the sender, its composeFrom.
message = abi.decode(
_moduleView(
abi.encodeCall(
PangeaOFTV3GapModule.gapMessage,
(_sendParam.to, _toSD(_amountLD), _sendParam.dstEid, _sendParam.composeMsg, msg.sender, _sendParam.oftCmd)
)
),
(bytes)
);
bool composed = _sendParam.composeMsg.length > 0;
options = combineOptions(_sendParam.dstEid, composed ? SEND_AND_CALL : SEND, _sendParam.extraOptions);
address inspector = msgInspector;
if (inspector != address(0)) IOAppMsgInspector(inspector).inspect(message, options);
}
// ------------------------------------------------------------- keys-only delivery (eth-fallback)
//
// Owner Q24 fallback (main 2026-10-31, Q34): toward a KEYS-ONLY destination (Ethereum) only our
// delivery keys deliver, so the user pays that delivery here, once: the registry's
// `deliveryCost(dstEid)` (this chain's native wei, owner-set, at most 0.0064 ETH) is added to
// `quoteSend`'s native fee and `send` pays exactly it to the registry's `deliveryFeeTo`; the rest goes
// to the endpoint, which takes LayerZero's fee and refunds any excess to the refund address.
// LayerZero's fee is for the MINIMAL executor gas: while the destination is keys-only,
// `combineOptions` puts KEYS_ONLY_LZ_RECEIVE_GAS_V3 (1) in place of the route's stored enforced floor
// (1,270,000 / 1,310,000, which the factory and LaunchOwnerV3 still set and which applies again the
// moment the registry clears the cost). Zero (every other destination): nothing changes.
// src/v3/gap/IGapDelivery.sol.
/// @notice OApp's combineOptions; toward a keys-only destination with an enforced floor, the floor
/// is the minimal executor option (lzReceive gas KEYS_ONLY_LZ_RECEIVE_GAS_V3, no value) on
/// both message types, the sender's own type-3 extraOptions appended as OApp does.
function combineOptions(uint32 _eid, uint16 _msgType, bytes calldata _extraOptions)
public
view
override
returns (bytes memory)
{
(uint256 costWei,) = _deliveryCharge(_eid);
if (costWei == 0 || enforcedOptions[_eid][_msgType].length == 0) {
return super.combineOptions(_eid, _msgType, _extraOptions);
}
bytes memory enforced = GasFloorV3.encode(KEYS_ONLY_LZ_RECEIVE_GAS_V3, 0);
if (_extraOptions.length == 0) return enforced;
if (_extraOptions.length < 2) revert InvalidOptions(_extraOptions);
_assertOptionsType3(_extraOptions);
return bytes.concat(enforced, _extraOptions[2:]);
}
/// @notice A send paid this token's delivery cost toward a keys-only destination.
event GapDeliveryPaid(bytes32 indexed guid, uint32 indexed dstEid, address indexed to, uint256 costWei);
/// @notice The registry's delivery charge could not be read (the send and the quote refuse: never a
/// keys-only send unpaid).
error DeliveryUnreadable(uint32 dstEid);
/// @notice The send's native fee is below the delivery cost it must carry.
error DeliveryFeeUnpaid(uint256 nativeFee, uint256 costWei);
/// @notice The delivery fee recipient refused the payment.
error DeliveryPayFailed(address to);
/// @dev The delivery read's gas cap (two storage reads and a call).
uint256 internal constant DELIVERY_READ_GAS = 30_000;
/// @dev The registry's `deliveryCharge(dstEid)`, gas-capped; anything but a 64-byte answer, or a
/// non-zero cost with no recipient, reverts DeliveryUnreadable.
function _deliveryCharge(uint32 dstEid) internal view returns (uint256 costWei, address to) {
(bool ok, bytes memory ret) =
gapRegistry.staticcall{gas: DELIVERY_READ_GAS}(abi.encodeCall(IGapDelivery.deliveryCharge, (dstEid)));
if (!ok || ret.length != 64) revert DeliveryUnreadable(dstEid);
(costWei, to) = abi.decode(ret, (uint256, address));
if (costWei != 0 && to == address(0)) revert DeliveryUnreadable(dstEid);
}
/// @dev OApp's quote plus the delivery cost (quoteSend's native fee = what send charges).
function _quote(uint32 _dstEid, bytes memory _message, bytes memory _options, bool _payInLzToken)
internal
view
override
returns (MessagingFee memory fee)
{
fee = super._quote(_dstEid, _message, _options, _payInLzToken);
(uint256 costWei,) = _deliveryCharge(_dstEid);
(, uint256 prepayWei,) = _prepayCharge(_dstEid, _message.length);
fee.nativeFee += costWei + prepayWei;
}
/// @dev OApp's send, the delivery cost first taken out of the native fee: msg.value must equal
/// `_fee.nativeFee` (as OApp requires) and cover the cost; the endpoint gets the rest, the
/// recipient exactly the cost (paid after the endpoint's send).
function _lzSend(
uint32 _dstEid,
bytes memory _message,
bytes memory _options,
MessagingFee memory _fee,
address _refundAddress
) internal override returns (MessagingReceipt memory receipt) {
(uint256 costWei, address to) = _deliveryCharge(_dstEid);
(uint256 prepayLamports, uint256 prepayWei, address prepayTo) = _prepayCharge(_dstEid, _message.length);
uint256 extra = costWei + prepayWei;
if (extra == 0) return super._lzSend(_dstEid, _message, _options, _fee, _refundAddress);
if (msg.value != _fee.nativeFee) revert NotEnoughNative(msg.value);
if (_fee.nativeFee < extra) revert DeliveryFeeUnpaid(_fee.nativeFee, extra);
if (_fee.lzTokenFee > 0) _payLzToken(_fee.lzTokenFee);
receipt = endpoint.send{value: _fee.nativeFee - extra}(
MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _fee.lzTokenFee > 0), _refundAddress
);
if (costWei != 0) {
(bool ok,) = to.call{value: costWei}("");
if (!ok) revert DeliveryPayFailed(to);
emit GapDeliveryPaid(receipt.guid, _dstEid, to, costWei);
}
if (prepayWei != 0) {
(bool ok,) = prepayTo.call{value: prepayWei}("");
if (!ok) revert DeliveryPayFailed(prepayTo);
emit GapPrepayPaid(receipt.guid, _dstEid, prepayTo, prepayLamports, prepayWei);
}
}
// ------------------------------------------------------------- the L4 prepay into Solana (q7b)
//
// Owner Q52 (main 2026-10-31): a composed v3 send INTO Solana prepays its compose's way home, P
// (L4: receipt rent + floor(1.1 x LayerZero's fee home) + the return gas, in lamports), to US, not as
// a LayerZero lzNativeDrop (LayerZero could keep a drop bundled with its execute: oft-q7 Q7-b). The
// registry's `prepayCharge(dstEid, composeLen)` gives P and its cost in this chain's native wei;
// quoteSend adds the cost, send pays exactly it to `deliveryFeeTo` and emits GapPrepayPaid -- the
// delivery bot's signal to fund the guid's GapPrepay PDA with exactly `lamports`, atomically with the
// receive. Unset: the composed send into Solana is refused (PrepayUnset), never unpaid. A plain send
// into Solana and any send elsewhere pay nothing here. src/v3/gap/IGapDelivery.sol.
/// @notice A composed send into Solana paid its L4 prepay: `lamports` for the guid's GapPrepay PDA, as
/// `costWei` of this chain's native coin to `to` (the registry's deliveryFeeTo).
event GapPrepayPaid(bytes32 indexed guid, uint32 indexed dstEid, address indexed to, uint256 lamports, uint256 costWei);
/// @notice The registry has no prepay figures: a composed send into Solana is refused (never unpaid).
error PrepayUnset(uint32 dstEid);
/// @notice Owner Q64: a composed (prepaid) send into Solana with no least credited amount
/// (`SendParam.oftCmd`'s minCreditedLD 0 or no oftCmd): refused at the source, quote and send.
error PrepaidComposeNeedsMinCredited(uint32 dstEid);
/// @dev The registry's `prepayCharge(dstEid, composeLen)` for a composed v3 message (header 96 B, then
/// composeFrom 32 B, then the composeMsg) into Solana, gas-capped; (0, 0, 0) for a plain message
/// or any other destination. Unreadable: DeliveryUnreadable; unset: PrepayUnset.
function _prepayCharge(uint32 dstEid, uint256 messageLen)
internal
view
returns (uint256 lamports, uint256 costWei, address to)
{
if (!_isSolanaEid(dstEid) || messageLen <= PREPAY_HEADER_LEN) return (0, 0, address(0));
uint256 composeLen = messageLen < PREPAY_HEADER_LEN + 32 ? 0 : messageLen - PREPAY_HEADER_LEN - 32;
(bool ok, bytes memory ret) = gapRegistry.staticcall{gas: DELIVERY_READ_GAS}(
abi.encodeCall(IGapPrepay.prepayCharge, (dstEid, composeLen))
);
if (!ok || ret.length != 96) revert DeliveryUnreadable(dstEid);
(lamports, costWei, to) = abi.decode(ret, (uint256, uint256, address));
if (costWei == 0 || to == address(0)) revert PrepayUnset(dstEid);
}
/// @dev The v3 codec's header (GapMath.HEADER_LEN): a message longer than it is composed.
uint256 internal constant PREPAY_HEADER_LEN = 96;
/// @dev The Solana endpoint ids (mainnet, testnet): the only destinations with a prepay.
function _isSolanaEid(uint32 eid) internal pure returns (bool) {
return eid == 30168 || eid == 40168;
}
/// @dev Whether `oftCmd` names no least credited amount: empty, or a first word whose low 248 bits (the
/// minCreditedLD of a plain or a co-signed oftCmd, under its flag byte) are 0. Any other shape is the
/// gap module's to refuse (BadOftCmd).
function _noMinimum(bytes calldata oftCmd) internal pure returns (bool) {
if (oftCmd.length == 0) return true;
if (oftCmd.length < 32) return false;
return uint256(bytes32(oftCmd[0:32])) & ((uint256(1) << 248) - 1) == 0;
}
// ------------------------------------------------------------- receive
/// @dev LayerZero's OFT receive with the gap fee: only `credited` is minted, and a composed
/// message is passed on with amountLD = credited (spec §4, §6.3).
function _lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) internal override {
// OApp has checked the endpoint and the peer. The rest -- the withholding, the credit (only
// `credited` is minted, through `gapCredit`), the events and the onward compose -- is the
// module's `gapReceive` (PangeaOFTV3GapModule), which only this path can run. E5: the
// executor and extra data go with it (the registry owner's admin land path, audit M-3).
_module(
abi.encodeCall(
PangeaOFTV3GapModule.gapReceive, (_origin.srcEid, _origin.nonce, _guid, _message, _executor, _extraData)
)
);
}
/// @notice The credit of a receive: mints `amountLD` to `to` (0xdead for zero), as OFT's
/// `_credit`. Only this token itself may call it -- its gap module's `gapReceive`,
/// running as this token from `_lzReceive`.
function gapCredit(address to, uint256 amountLD, uint32 srcEid) external returns (uint256) {
if (msg.sender != address(this)) revert NotSelf();
return _credit(to, amountLD, srcEid);
}
// ------------------------------------------------------------- the price records
//
// Owner decision 2026-10-28 (the v3 EVM audit, H-1/H-2): the official pool's price is recorded
// at SWAP time only, by the pool's own hook (PangeaFeeHookV2's afterSwap calls `recordPrice`,
// answered by the gap module through `fallback`), never at transfer time -- ERC-6909 claims,
// take/settle ordering and zero transfers to the PoolManager stamp nothing.
// ------------------------------------------------------------- the gap module
/// @dev DELEGATECALL the module with `data`; its revert (GapGasTooLow, or anything else) is
/// passed on whole, its return data returned.
function _module(bytes memory data) internal returns (bytes memory ret) {
bool ok;
(ok, ret) = gapModule.delegatecall(data);
if (!ok) {
assembly ("memory-safe") {
revert(add(ret, 32), mload(ret))
}
}
}
/// @dev The same from a view (OFT's _buildMsgAndOptions, which quoteSend shares): a STATICCALL
/// to this token, whose fallback delegatecalls the module in the static context.
function _moduleView(bytes memory data) internal view returns (bytes memory ret) {
bool ok;
(ok, ret) = address(this).staticcall(data);
if (!ok) {
assembly ("memory-safe") {
revert(add(ret, 32), mload(ret))
}
}
}
/// @notice Every function this contract does not have is the module's, run as this token:
/// the gap views (gapSendQuote, gapPreview, gapRecords, gapCloses, gapRecordBlocks, gapRecordFees, gapWithheld, gapBurnedLD),
/// `recordPrice` (the official pool's hook only) and the metadata (metadataURI, metadataAuthority, pendingMetadataAuthority and
/// their setters). See IPangeaOFTV3.
/// Never `gapReceive`: only `_lzReceive` runs that.
fallback() external {
if (
msg.sig == PangeaOFTV3GapModule.gapReceive.selector || msg.sig == PangeaOFTV3LogModule.gapDebit.selector
|| msg.sig == PangeaOFTV3LogModule.gapClaimTake.selector
) revert NotSelf();
// E5: recordPrice lives in the log module (EIP-170); the hook's record goes there directly,
// so it pays no second delegatecall hop inside the hook's RECORD_GAS.
bytes4 sig = msg.sig;
address m = sig == RECORD_PRICE_SEL || sig == LOG_PLAN_R_SEL || sig == LOG_CONSUME_SEL || sig == LOG_QUOTE_SEL
? gapLogModule
: gapModule;
// Not memory-safe, and it need not be: it copies over memory from 0 and never returns to Solidity.
assembly {
calldatacopy(0, 0, calldatasize())
let ok := delegatecall(gas(), m, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if iszero(ok) { revert(0, returndatasize()) }
return(0, returndatasize())
}
}
}
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.