Protocol
Phase 2 contracts
MontraSwapAdapter and NavReporter, written and tested but not deployed yet.
Two contracts in contracts/ prepare live trading. Both are written and tested (31 tests) but not deployed. Toolchain: Hardhat 3, viem, solc 0.8.24, optimizer on (200 runs), EVM cancun, OpenZeppelin 5.
MontraSwapAdapter
Why it exists
The Treasury's execute checks only the target and the function selector. Allow-listing Montra's Universal Router directly would let a stolen keeper key encode a swap whose output goes to the thief. Instead the Safe allow-lists the adapter's buy and sell. The adapter has no recipient argument: it always pays the Treasury.
Functions
| Function | Access | Behaviour |
|---|---|---|
buy(token, minOut, deadline) payable | Treasury only | Swaps exactly msg.value HYPE for the token. Forwards every token received and any HYPE refund to the Treasury. tokensOut is the increase in the Treasury's balance; reverts InsufficientOutput if below minOut. Selector 0xa59ac6dd |
sell(token, amountIn, minOut, deadline) | Treasury only | Pulls amountIn tokens from the Treasury (needs Treasury.approveToken), capped by the token's maxSellPerCall. Sets exact, single-block allowances (ERC20 → Permit2 → router), swaps, clears leftover allowances, returns unsold tokens and all HYPE to the Treasury. Selector 0x92cdbac5 |
setToken(token, allowed, maxSellPerCall) | owner (Safe) | maxSellPerCall = 0 disables selling |
setPoolConfig(fee, tickSpacing, hooks) | owner | Montra pool parameters |
poolKey(token), poolId(token) | view | poolId matches Montra's |
Both trade functions check the deadline, that the token is allow-listed and that the amount is non-zero, and are nonReentrant. The adapter rejects HYPE sent outside a trade (UnexpectedHype). Ownership uses Ownable2Step.
Errors: NotTreasury, TokenNotAllowed, ZeroAmount, ZeroAddress, DeadlineExpired, SellLimitExceeded, InsufficientOutput, UnexpectedHype, HypeTransferFailed.
Router encoding
Verified against the live Universal Router: execute(bytes commands, bytes[] inputs, uint256 deadline) (0x3593564c). Buy uses commands 0x1004 (V4_SWAP + SWEEP), sell 0x10. The swap input encodes actions 0x060c0f: SWAP_EXACT_IN_SINGLE, SETTLE_ALL, TAKE_ALL. HYPE is currency0, so a buy is zeroForOne = true. The live router rejects the legacy action numbering, and the fork check asserts it.
What it does not protect against
A stolen keeper key could still trade allow-listed tokens at a bad price (low minOut), up to the Treasury's HYPE limits and maxSellPerCall. Value can be lost to slippage or MEV; it cannot be redirected. To stop trading: setToken(token, false, 0) on the adapter, setAllowedCall(adapter, selector, false) on the Treasury, or the guardian's pause().
NavReporter
An on-chain record of the vault's self-reported value.
report(timestamp, navUsd, hypeUsd, pnlUsd, reportHash)byREPORTER_ROLE(the engine's wallet). Timestamps must strictly increase and cannot be in the future. Only the latest report is stored;reportCountincrements andNavReportedis emitted.- Units:
navUsdandpnlUsdin USD with 6 decimals (pnlUsdsigned, cumulative),hypeUsdwith 8 decimals. reportHashcommits to the full off-chain report (for example the keccak256 of a canonical JSON).- Values are not verified on chain. The reporter cannot rewrite or pre-date history.
Warning
The engine does not call report() yet. NAV_REPORTER_ADDRESS is read and shown by /api/v1/config, but no NAV is posted on chain today.
Tests and fork check
| Command | What |
|---|---|
npm test | 31 tests: 25 for the adapter (deployment and config, buy, sell, through the real Treasury.execute), 6 for NavReporter. Uses a mock router that decodes the real encoding |
npm run fork-check | Deploys the adapter on an in-process fork of Elysium mainnet, impersonates the real admin and keeper, buys then sells a real token, and checks balances, events, zero leftover allowances and that bad calls revert. Nothing is broadcast |
Sample fork result (block 14815370): buy 1 HYPE → 4,390,243.49 CEDENT (gas 244,875); sell half → 0.4728 HYPE (gas 245,054).
Deploying
cp .env.example .env # TREASURY, ADMIN (the Safe), REPORTER (engine wallet), optional TOKENS
npx hardhat keystore set DEPLOYER_PRIVATE_KEY # a throwaway deployer
npm run deploy:testnet # chain 99801
CONFIRM_MAINNET_DEPLOY=yes npm run deploy:mainnet # chain 99901 refuses without itThe Safe is passed straight into the constructors, so the deployer keeps no rights. The script prints every transaction the Safe must then make, and writes a Safe Transaction Builder batch to deployments/<network>-<chainId>.json:
| # | To | Call |
|---|---|---|
| 1 | Treasury | setAllowedCall(adapter, 0xa59ac6dd, true) (buy) |
| 2 | Treasury | setAllowedCall(adapter, 0x92cdbac5, true) (sell) |
| 3 | Adapter | setToken(token, true, maxSellPerCall) per token |
| 4 | Treasury | approveToken(token, adapter, amount) per token the keeper may sell |
| 5 | Treasury | setAllowedCall(router, 0x3593564c, false), only if the router had been allow-listed directly |
Defaults: MAX_SELL_PER_CALL 1 000 000 tokens, APPROVE_AMOUNT 10 000 000 tokens, Montra pool fee 0x800000, tick spacing 200.