Extending the vault
OrderVault compiles to 24,242 of the 24,576-byte contract limit, so there are 334 bytes of headroom
(forge build --sizes). That is enough for a small change but not a large one, so before adding logic, know how
to make room. In rough order of how much each frees:
- Move logic into an external library. This is the biggest lever and the pattern the vault already uses:
MarketGuard(the Chainlink + TWAP read and bounds) andOrderCollection(the one-time NFT-collection create) areexternallibraries called withdelegatecall, which keeps their bytecode out of the vault. Pricing and cost maths (_gasToTinybar,_reserve, the share calculations) or the scheduling internals are the next candidates to extract the same way. - Move the read-only views to a lens contract. The cost and status views (
checkCost,fillCost,minBudget,sweepStatus,nextCheckDelay) exist for the frontend; a separate read-only "lens" contract can hold them and read the vault's storage, freeing the vault of code it never needs on-chain. - Keep using custom errors and events (the vault has no revert strings) and keep storage structs packed
(
Order,SweepState) — both are already done, and both are cheap ways to stay small.
Once there is room, the usual changes:
- Add a market: add a function to
script/MarketConfig.sollikeusdcDai()(both tokens need Chainlink feeds), calllistMarketfromDeploy.s.sol, and redeploy. The frontend lists every market the vault has. - Tune how often checks run:
SweepParams(minInterval,maxInterval,maxMoveBpsPerHour). LowermaxMoveBpsPerHourcosts less and reacts later. Change a live market withupdateMarket. - Tune the guard:
GuardParams.MarketGuard.paramsValidkeeps it meaningful: TWAP 5 min to 1 day, oracle age 60 s to 26 h, deviation and slippage at most 10%. - Recalibrate costs: measure a few scheduled sweeps on the mirror node (
gas_usedin/api/v1/contracts/{id}/results/{timestamp}) and callsetCosts. The frontend reads costs from the vault, so nothing else changes. - Mainnet: add mainnet addresses to
MarketConfig.sol, allow chain 295 inDeploy.s.sol(it deploys to testnet only), add the network toscaffold.config.ts, and tightenmaxOracleAgeto the mainnet feeds' heartbeat.
From README.md at v1.1 (6ddd9a3) · View source
Pluggable order types
Status: proposal for review. No plug-in code is written yet. This document is the contract for the STEP 2 refactor: it turns the fixed limit/stop logic into…
Go to mainnet
This template ships pointed at Hedera testnet. It is a starting point, not an audited production system. Work through this before putting real value on it.