Matrix logo

LayerX SettlementAnchor, LayerXVault, and Deployment Contracts

On-chain contracts for LayerX: SettlementAnchor (immutable root log), LayerXVault (reserve custody, deposits, settlement, force-exit), in-house safety libraries, and the Foundry deployment script.

Overview

The LayerX contract suite is self-contained: production src/ has zero external imports. Safety primitives (ECDSA, EIP-712, SafeERC20, Governed, Pausable) are reimplemented in-house under src/lib. The two primary contracts are LayerXVault (reserve custody and settlement) and SettlementAnchor (immutable root log).

Foundry Configuration

Source: layerx/contracts/foundry.toml

KeyValue
srcsrc
testtest
scriptscript
solc0.8.27
evm_versionshanghai
optimizertrue (200 runs)
[rpc_endpoints].paxeer${PAXEER_RPC_URL}

forge-std is vendored under lib/ for tests only; production src/ never imports it.

Deployment Script

Source: layerx/contracts/script/Deploy.s.sol

Deploy.run reads environment variables, deploys SettlementAnchor first, then LayerXVault, and conditionally wires the anchor writer when the broadcaster matches the governor.

Environment variableRole
LAYERX_GOVERNORProtocol root authority
LAYERX_OPERATOR_ADDRSequencer EVM key
LAYERX_GUARDIANEmergency pause authority
LAYERX_USDL_ADDRUSDL reserve token
LAYERX_DEX_ROUTERPaxeer DEX router
LAYERX_WRAPPED_NATIVEWrapped native asset
LAYERX_EXIT_DELAYForce-exit challenge window (seconds)

SettlementAnchor

Source: layerx/contracts/src/SettlementAnchor.sol

Minimal, append-only registry for settled batch Merkle roots. Never holds funds.

Properties

PropertyTypeDescription
writeraddressAuthorized writer
rootOfmapping(bytes32 => bytes32)Anchored root per batch id
anchoredmapping(bytes32 => bool)Idempotency flag

Methods

MethodAccessDescription
record(batchId, root, totalSettled, count, windowEnd)WriterAnchor one batch root, emit SettlementAnchored
setWriter(newWriter)GovernorRotate authorized writer

Errors

NotWriter, AlreadyAnchored, ZeroRoot

Event

SettlementAnchored(batchId, root, totalSettled, count, windowEnd, anchoredAt)

LayerXVault

Source: layerx/contracts/src/LayerXVault.sol

On-chain custody and settlement contract. Holds the USDL reserve, mints USDX accounting against deposits, executes settlement payouts, and provides the unilateral force-exit escape hatch.

Constructor

ParameterTypeDescription
usdl_addressReserve asset (USDL)
governor_addressProtocol root authority
operator_addressSequencer key
guardian_addressEmergency pause
anchor_addressSettlementAnchor contract
dexRouter_addressPECOR DEX router
wrappedNative_addressWrapped native token
exitDelay_uint64Force-exit challenge window

Deposit methods

MethodDescription
depositUSDL(amount, did)Direct USDL deposit, mints USDX 1:1
depositSwap(tokenIn, amountIn, amountOutMin, deadline, did)Swap allowlisted token to USDL, mint from realized output
depositNative(amountOutMin, deadline, did)Wrap native PAX, swap to USDL, mint

All deposit paths measure token balance deltas before/after transfer (fee-on-transfer safe).

Settlement

settle(batch) anchors the root via SettlementAnchor.record, then pays batch recipients via SafeERC20.safeTransfer. Protected by reentrancy guard. Batch is idempotent via settledBatch[batchId].

Force-exit (L1 escape hatch)

MethodDescription
initiateExit(amount, epoch, operatorSig)Start exit using operator's co-signed balance proof (EIP-712)
challengeExit(amount, epoch, operatorSig)Replace pending exit with strictly newer proof
finalizeExit()Complete matured exit after exitDelay

Admin methods

setOperator, setGuardian, setDexRouter, setAnchor, setWrappedNative, setExitDelay, setMaxSettlementPerBatch, setSwapAllowed, pause, unpause

Key properties

PropertyTypeDescription
usdlIERC20Reserve token
operatoraddressSettlement operator
guardianaddressPause authority
anchorISettlementAnchorRoot log
totalDepositeduint256Cumulative USDL deposited
totalSettledOutuint256Cumulative USDL settled
totalExiteduint256Cumulative USDL exited
exitDelayuint64Force-exit window
maxSettlementPerBatchuint256Per-batch cap (0 = uncapped)

In-House Safety Libraries

ECDSA (src/lib/ECDSA.sol)

secp256k1 signer recovery. Rejects high-s signatures, invalid v values, zero-address recovery.

EIP712 (src/lib/EIP712.sol)

Typed-data domain hashing. Domain separator cached at construction, re-derived on chain ID change (fork-safe).

SafeERC20 (src/lib/SafeERC20.sol)

Token-call wrapper. Tolerates no-boolean-return ERC-20 variants. forceApprove handles USDT-style reset-to-zero.

Governed (src/lib/Governed.sol)

Two-step governance handoff: transferGovernance + acceptGovernance.

Pausable (src/lib/Pausable.sol)

Emergency stop with _pause/_unpause and whenNotPaused/whenPaused modifiers.

Chain Bindings (Go side)

Source: layerx/internal/chain/bindings.go

Minimal inline ABI fragments for the contracts the sequencer touches:

ABIContractMethods
layerXVaultABILayerXVaultsettle, reserveBalance, operator, settledBatch, exited + Deposit/Settled events
settlementAnchorABISettlementAnchorrootOf, anchored, writer + SettlementAnchored event
erc20ABIIERC20balanceOf, decimals
pecorRouterABIIPECORRouterswapBestRoute

PackSettle ABI-encodes a LayerXVault.settle(batch) call.

Paxeer Chain Integration

Source: layerx/internal/chain/settler.go, layerx/internal/chain/watcher.go, layerx/internal/chain/operator.go

The Settler submits settlement batches to the vault contract. The Watcher monitors Deposit events for chain-in crediting. The Operator manages the sequencer's on-chain transactions.