Repository avatar
AI Tools
v0.2.0
active

lockout-mcp

io.github.lockoutgate/lockout-mcp

Read, preview and trade Robinhood Chain stock tokens through one lockout account.

Documentation

lockout. Same lock bit for you and your agent. A silicon die in cross-section: the agent's bus, from lockout-mcp, and the owner's bus run into the same row of 21 buy() gates and stop at gate 03, AccountHalted(), with gate 05 latched beside it. Below them only the owner's sell bus runs on, through gates 06, 07, 09 and 20, to the exit pad.

Let your agent trade, and keep the limits in the contract it trades through.

sourcify npm lockout-mcp license MIT

Site · Bench · Datasheet · npm · Glama · Verify the bytes

lockout is a stock-token account on Robinhood Chain for an owner who lets an AI agent trade. Before a session the owner calls seal() with ten rules, a bell (unlockAt) and a $LOCKOUT bond. Until the bell the rules only tighten, and every buy, the agent's or the owner's own, goes through the same buy() and its 21 gates. The buy that meets the loss limit trades nothing and halts the account; from then until the bell every buy reverts, while the account can still sell: the owner's sells under four checks, the agent's inside the feed band. contracts/ holds the factory, the account and a read-only Lens. mcp/ is lockout-mcp, the MCP server that gives an agent seven tools on one account.

rpc=https://rpc.mainnet.chain.robinhood.com
# the bond floor: $LOCKOUT base units per day sealed
cast call 0xeAD444A07f59C89Fb4454F28854245D5D8E1f456 'minBondPerDay()(uint256)' --rpc-url $rpc
# each listed stock: its feed, its pools, the chain's gates on it now, and whether an agent may buy or sell it
cast call 0xfbCAcd8748a473a4778a43B1bCd2dB3B563daA42 'markets()((address,address,bytes32[],(bool,bool,bool,bool,bool,bool,bool,uint256,uint256),bool,bool)[])' --rpc-url $rpc

Contracts

Robinhood Chain, chain id 4663, deployed in block 123592326.

ContractAddressSource
LockoutFactory0xeAD444A07f59C89Fb4454F28854245D5D8E1f456LockoutFactory.sol
LockoutAccount implementation0x451725A29F3Fa20d075CC171991b746d3406A757LockoutAccount.sol
LockoutLens0xfbCAcd8748a473a4778a43B1bCd2dB3B563daA42LockoutLens.sol

createAccount(agent) clones the implementation (OpenZeppelin Clones) for the caller, who becomes the account's owner, and names the agent key; the agent cannot be the owner. The factory keeps the lists every account reads live: listed stocks, their USDG pools on Uniswap v3, MetaDEX and Uniswap v4, one Chainlink feed per stock, the bond token and its per-day floor. Its usdg, registry, accountImplementation and the three venue addresses are immutable. The account enforces the rules. The Lens only reads: previewBuy and previewSell run the account's own simulateBuy and simulateSell and return the gate that would stop an order, and accountState and markets gather a page's or an agent's reads into one call. Nothing upgrades, and the factory owner has no function that reaches into an account.

The seal

seal(rules, unlockAt, bond) opens a session:

function seal(Rules calldata next, uint64 bell, uint256 bond) external locked onlyOwner {
    if (sealed_) revert AlreadySealed();
    address token = factory.token();
    if (token == address(0)) revert TokenNotSet();
    if (bell < block.timestamp + MIN_SEAL_DURATION || bell > block.timestamp + MAX_SEAL_DURATION) {
        revert BadDuration();
    }
    if (next.maxDailyLossUsdg == 0 || next.maxPerTradeUsdg == 0 || next.maxOpenCostBasisUsdg == 0) {
        revert ZeroLimit();
    }
    if (next.maxDailyLossUsdg > uint256(type(int256).max)) revert LimitTooLarge();
    if (next.maxSlippageBps > MarketChecks.BPS) revert RuleOutOfRange();
    uint256 required = factory.minBondPerDay() * Math.ceilDiv(bell - block.timestamp, 1 days);
    if (bond < required) revert InsufficientBond(bond, required);
    uint256 received = _receive(IERC20(token), bond);
    if (received < required) revert InsufficientBond(received, required);
    ...
}
  • The bell is at least MIN_SEAL_DURATION (1 hours) and at most MAX_SEAL_DURATION (7 days) away.
  • The bond is minBondPerDay × ceil((unlockAt − now) / 1 day) in $LOCKOUT, counted as the balance the account actually received.
  • The session uses the feeds the factory had set when it was sealed; a feed set later counts from the next session (sessionFeed).
  • While sealed, setAgent can only clear the agent, never name a new one.

The ten rules, and what tighten(rules) accepts while sealed. Anything else reverts with CannotLoosenWhileSealed(), and every accepted call runs the halt check at once.

RuleLimits0 meanstighten() accepts
maxDailyLossUsdgrealized loss plus the open positions' mark loss, net of realized gainsrefused by seal (ZeroLimit())equal or lower
maxPerTradeUsdgUSDG spent in one buyrefused (ZeroLimit())equal or lower
maxOpenCostBasisUsdgcost basis of everything heldrefused (ZeroLimit())equal or lower
maxConsecutiveLosseslosing sells in a row before the haltoffswitched on, or lower; never back to 0
maxTradesPerSessionbuys in the session; the last one haltsoffswitched on, or lower; never back to 0
cooldownSecpause on buys after a losing sellno pauseequal or longer
maxFeedAgeSecoldest feed answer a buy acceptsno limit on owner buys; the agent's is 90,000 sswitched on, or lower; never back to 0
maxSlippageBpsfill against the feed price, at most 10,000no band, and the agent cannot tradeequal or lower, never 0
requireLiveFeeda buy of a stock that has a feed needs that feed liveswitched on, never off
blockOutsideMintWindowbuys only from Monday 02:00 to Saturday 02:00 Central European time (MintWindow.isOutside, CET or CEST)switched on, never off

Gates

Every buy runs _buy and _buyOrderChecks: 21 gates, the owner's buys and the agent's alike, in this order: 01 to 05, 06 to 19, the swap, then 20 and 21. Gate 13 applies only to the agent key. A failing gate reverts with its error. The numbers are the @gate tags in the source and contracts/gate-lines.json.

GateStops whenErrorLine
01!sealed_NotSealed()345
02now >= unlockAtSessionEnded()347
03halted || sessionBrokenAccountHalted()348
04trade count reached capAccountHalted()350
05MTM loss reached limit or held mark unavailablethe latch, or MarkUnavailable(address)354, 360
06usdgIn == 0ZeroAmount()376
07usdgIn > trackedUsdgInsufficientTracked()377
08!isListed(stock)AssetNotListed(address)378
09pool.stock != stockPoolNotListed(address,bytes32)380
10now < cooldownUntilCooldownActive(uint64)382
11usdgIn > maxPerTradeUsdgOverPerTradeCap()383
12open cost + usdgIn > maxOpenCostBasisUsdgOverOpenCostCap()386
13agent without eligible live feedAgentNeedsLiveFeed(address)390
14stock.paused()TokenPaused(address)392
15stock.oraclePaused()OracleFlagged(address)394
16registry.isBlocked(account)AccountBlocked()396
17mint window required and outsideOutsideMintWindow()398
18required feed missing or staleFeedRequiredOrStale(address,uint256)400
19no feed && minSharesOut == 0MinOutNotMet()402
20sharesOut == 0 || sharesOut < minSharesOutMinOutNotMet()365
21fill above feed bandSlippageVsFeedExceeded()368

Gate 05 has two outcomes. If the effective loss has reached maxDailyLossUsdg, the buy does not revert: it latches the halt and returns with nothing bought (next section). Otherwise, if a held stock's feed cannot be read, the buy reverts with MarkUnavailable(address).

The agent key's buys and sells also need, for that stock (agentEligible): a feed answer no older than maxFeedAgeSec, capped at AGENT_MAX_FEED_AGE (90,000 s, which also stands in for 0); the token's oracle not paused; and maxSlippageBps above 0. So the agent cannot trade a stock that has no feed.

A sell runs _sell: seven gates. The owner's sells meet four of them: an amount, a tracked balance, a listed pool and the owner's own minimum. The agent's meet all seven: a sealed session, a live feed and a fill inside maxSlippageBps of the feed price.

GateStops whenErrorLineOwner's sells
01sharesIn == 0ZeroAmount()424yes
02sharesIn > trackedSharesInsufficientTracked()425yes
03pool.stock != stockPoolNotListed(address,bytes32)427yes
04agent && !sealed_NotSealed()428no
05agent without eligible live feed or a carried mark is pendingAgentNeedsLiveFeed(address)435no
06usdgOut < minUsdgOutMinOutNotMet()440yes
07agent fill below feed bandSlippageVsFeedExceeded()442no

The latch

FIG. 1. One session as a timing diagram, one row each for the owner, the agent key, the account's sealed_, halted and cooldownUntil, the bond, and anyone. seal() raises sealed_ and takes the bond. Owner and agent buys pass. An agent sell at a loss raises cooldownUntil for cooldownSec, and an agent buy inside it reverts at gate 10. The agent's next buy meets the loss limit: gate 05, no fill, LockoutTriggered, and halted goes high. After that the agent's buy and the owner's buy both revert at gate 03, while an owner sell and an agent sell still go through. anyone can call tripIfBreached() during the session. At unlockAt, the bell, anyone calls release(): sealed_ and halted fall and the bond goes back to the owner. A dashed mark shows the other way out: emergencyWithdraw() before the bell, which burns the bond.

FIG. 1. One session, from the state changes in LockoutAccount.sol. A diagram of the rules: the spacing is not to scale and it shows no amounts.

The loss check runs inside every buy, ahead of the order's own gates (L352-L357):

address unavailable = _rebasePending();
Mark memory mark = _marks();
if (_effectiveLoss(mark.unrealized) >= rules.maxDailyLossUsdg) {
    _halt(REASON_MTM_LOSS, mark.unrealized);
    return (0, 0, REASON_MTM_LOSS);
}
  • The effective loss is the open positions' loss at their feed prices plus any realized loss, less any realized gain (_effectiveLoss).
  • The buy that finds it at the limit trades nothing. Its transaction succeeds, sets halted and emits LockoutTriggered(sessionId, 2, …).
  • From then until the bell every buy, the owner's included, stops at gate 03 with AccountHalted(). Nothing clears halted before release().
  • The same check runs after every trade and every tighten() (_trip). Its reasons: realized loss at the limit (1), effective loss at the limit (2), maxConsecutiveLosses losing sells in a row (3), maxTradesPerSession buys (4). The owner can halt by hand with manualHalt() (5); emergencyWithdraw() halts with 6.
  • tripIfBreached() lets anyone run that check, so a breach left by a price move alone is recorded without waiting for the next trade.

Ending a session

After the bell anyone can call release(). The session ends, halted clears, and the bond goes back to the owner in full, whether or not the account halted.

Before the bell the owner's only way out is emergencyWithdraw(token, amount):

if (!sessionBroken) {
    uint256 amountToBurn = bondAmount;
    bondAmount = 0;
    sessionBroken = true;
    uint256 supply = IERC20(bondToken).totalSupply();
    IBurnable(bondToken).burn(amountToBurn);
    uint256 remaining = IERC20(bondToken).totalSupply();
    if (remaining > supply || supply - remaining != amountToBurn) revert BurnNotVerified();
    emit SessionBrokenAndBurned(sessionId, amountToBurn);
    _halt(REASON_EMERGENCY_BROKEN, _marks().unrealized);
}
_withdraw(token, amount);

The first call burns the whole bond with the $LOCKOUT token's own burn and reverts unless the total supply fell by exactly that amount. It marks the session broken and halts with reason 6. Later calls before the bell only move funds to the owner. withdraw and sweep work only outside a session (SessionNotEnded() while sealed); sweep returns tokens that reached the account outside its ledger.

Who moves what

FIG. 2. Who can move what in one account. In the middle, LockoutAccount, a clone per owner, holding tracked USDG, tracked stock tokens and the bond in $LOCKOUT, under rules that only tighten. The owner calls seal, tighten, manualHalt, setAgent, depositUsdg, buy and sell, and is the only account paid out: withdraw, sweep, emergencyWithdraw, and the bond on release. The agent key calls buy and sell; anything else reverts with NotOwner(). Anyone calls tripIfBreached, and release after the bell. Tokens move out only in swaps with the listed pools, to the owner, or as a burned bond. The account reads Chainlink feeds and the factory live. The factory owner calls setToken, setMinBondPerDay, listAsset, listPool and setFeedOnce: nothing is ever unlisted, setToken and setFeedOnce work once, the bond floor stays at or under supply / 1000 and rises at most 2x per 24 hours. The Lens only reads and previews.

FIG. 2. From the access checks in LockoutAccount.sol and LockoutFactory.sol: solid gold arrows move tokens, thin arrows call, dashed arrows read.

  • Owner (onlyOwner): depositUsdg, seal, tighten, manualHalt, setAgent, buy, sell, emergencyWithdraw, and outside a session withdraw and sweep. The account pays out only to the owner.
  • Agent key: buy and sell. Every other function reverts with NotOwner(), and tokens never move to the agent.
  • Anyone: tripIfBreached(), and release() once the bell has passed.
  • Factory owner (Ownable2Step), on the factory only:
    • setToken, once: the bond token. The bond floor's cap becomes a thousandth of its supply at that moment.
    • setMinBondPerDay: at or under that cap. A raise waits 24 hours after the last raise and at most doubles the floor; a cut takes effect at once. It applies to later seals.
    • listAsset, setFeedOnce and listPool: an 18-decimal stock, at most one 8-decimal feed for it, and USDG pools on Uniswap v3, MetaDEX, or Uniswap v4 without hooks or a dynamic fee. Nothing is ever unlisted or replaced.

Agent tools

mcp/ is lockout-mcp, an MCP server over stdio that trades one account with its agent key. Run npx -y lockout-mcp init to create a local agent key and print client setup and a lock page link that fills in the agent address.

claude mcp add lockout -e LOCKOUT_FACTORY=0xeAD444A07f59C89Fb4454F28854245D5D8E1f456 -e LOCKOUT_LENS=0xfbCAcd8748a473a4778a43B1bCd2dB3B563daA42 \
  -e LOCKOUT_ACCOUNT=<your account> -e LOCKOUT_AGENT_KEY_FILE=<absolute path of the key file> -- npx -y lockout-mcp
ToolDoes
account_statusReads the session's rules, balances and lockout state
marketsReads listed stocks, pools and feed conditions
quoteSimulates an order on every listed pool, best output first
preview_buy, preview_sellReads the account's verdict on one order, with no transaction
buy, sellSends the order with the agent key and reports the verdict from its receipt

config.ts reads LOCKOUT_FACTORY, LOCKOUT_LENS and LOCKOUT_ACCOUNT; LOCKOUT_AGENT_KEY_FILE, an absolute path, is needed only to trade; LOCKOUT_RPC_URL replaces the public endpoint. A trade comes back EXECUTED, REJECTED_HALT_LATCHED or REJECTED_REVERT. mcp/README.md covers the settings, FIG. 3 and how to read the three; mcp/skill/SKILL.md is the procedure for the agent.

Verify the bytes

You need Foundry, Node.js 20 or newer, git, curl and jq.

bash contracts/script/install-deps.sh          # forge-std and OpenZeppelin at the commits it names
(cd contracts && forge build && forge test --no-match-path 'test/fork/*')
(cd mcp && npm ci && npm test)

forge build compiles with solc 0.8.35, Cancun, 200 optimizer runs and no IR (foundry.toml). Sourcify holds the verified source of the three contracts; the bytes forge build writes are the bytes it recompiled:

cd contracts
sourcify=https://sourcify.dev/server/v2/contract/4663
forge inspect LockoutAccount deployedBytecode > account.hex
curl -s "$sourcify/0x451725A29F3Fa20d075CC171991b746d3406A757?fields=runtimeBytecode" \
  | jq -r .runtimeBytecode.recompiledBytecode | cmp - account.hex   # silent if equal
curl -s "$sourcify/0xeAD444A07f59C89Fb4454F28854245D5D8E1f456" | jq '{match, runtimeMatch, creationMatch}'
curl -s "$sourcify/0xfbCAcd8748a473a4778a43B1bCd2dB3B563daA42" | jq '{match, runtimeMatch, creationMatch}'

lockout-mcp is published from this repository by publish.yml, which runs npm ci, the build and the tests before npm publish --provenance. The registry keeps the provenance; this prints the repository, workflow and commit a release was built from:

curl -s "$(npm view lockout-mcp dist.attestations.url)" \
  | jq -r '.attestations[] | select(.predicateType | startswith("https://slsa.dev/provenance")) | .bundle.dsseEnvelope.payload' \
  | base64 -d \
  | jq '.predicate.buildDefinition | {repository: .externalParameters.workflow.repository,
      workflow: .externalParameters.workflow.path, commit: .resolvedDependencies[0].digest.gitCommit}'

What it relies on

You rely onFor
Each listed stock's Chainlink feedThe loss mark, the agent's eligibility and band, and requireLiveFeed. While a held stock's feed cannot be read, buys revert at gate 05 and the agent cannot trade that stock.
Each stock token's issuerpaused, oraclePaused and the registry's isBlocked (gates 14 to 16). While an issuer pauses its token, it cannot be bought or sold anywhere, here included.
The listed poolsFill prices. The feed band bounds a fill; it never sets one. A MetaDEX pool's swap hook can raise that pool's fee, up to 10% on each side, or refuse its swaps; it cannot move the account's tokens.
The factory ownerWhich stocks, pools and feeds are listed (only ever added) and the bond floor for later seals
$LOCKOUT's burnThe emergency burn. The account checks the total supply after the call.
Robinhood Chain's sequencerBlock time: the bell, the cooldown, feed age and the mint window are all measured against it

License

MIT

NPM
lockout-mcp
Install Command
npm install lockout-mcp