Introduction
Protocol reference for the LayerSub stack.
Contracts, solvency model, API and deployed addresses for $SUB and the LayerSub-Staking vault.
The two contracts
LayerSub-Staking is deliberately small: one token and one vault, both at pragma 0.8.24. Everything else in the stack — the indexer, the API, the dApp — only reads from these.
$SUB is the core utility token of the LayerSub ecosystem: a standard 18-decimal ERC-20 with burn mechanics, EIP-2612 permits, and an open faucet so anyone can self-serve testnet tokens for the staking demo.
src/LayerSubToken.sol · pragma 0.8.24LayerSubStakingVaultYield engine — Synthetix-style per-second reward accountingStakers deposit $SUB and accrue rewards per staked token per second, following the Synthetix StakingRewards accounting model with 1e18 fixed-point math.
src/LayerSubStakingVault.sol · pragma 0.8.24Why solvency is the hard part
Because LayerSub uses one token for both staking and rewards, the vault must never pay staked principal out as yield. Rewards therefore come from an explicit budget the owner funds, and emission stops the moment that budget would run out.
rewardPerToken() = rewardPerTokenStored + (elapsed × rewardRate × 1e18) / totalStakedelapsed = lastTimeRewardApplicable() − lastUpdateTime. Returns the stored value unchanged while totalStaked is zero.
earned(a) = balanceOf(a) × (rewardPerToken() − userRewardPerTokenPaid[a]) / 1e18 + rewards[a]Two floor divisions sit between the budget and the payout, which is where the vault's rounding surplus comes from.
Live deployment
Ethereum Sepolia (chain 11155111) is the only network with bytecode on chain. The other 2 entries are planned.
- $SUB token
- 0xaa3b5cDF3a315158d8cC6621Eb7d7a3E095fADf9
- Staking vault
- 0x32720d8C06C24751dd1DFF4e3940D58f1f5bd0F6
- Initial $SUB supply
- 1,000,000 $SUBMinted to the deployer at construction.
- Reward budget
- 100,000 $SUBFunded into the vault via fundRewards.
- Emission rate
- 1,000 $SUB / day11574074074074074 wei per second, as set by setRewardRate.
Integrating
The backend exposes 7 read-only endpoints over the indexed chain state. Two conventions catch most integrations out:
- Amounts are decimal strings
$SUB is an 18-decimal token, so amounts routinely exceed Number.MAX_SAFE_INTEGER. Every uint256 is serialised as a decimal string and never as a JSON number. Parse with BigInt(value), or viem's formatUnits(value, 18) for display.
- Unknown query parameters are rejected
A typo such as ?limitt=10 returns 400 rather than being silently ignored, so a mistake in an integration surfaces immediately instead of looking like a backend bug.