Skip to content

Repository files navigation

FlowShield

FlowShield is a conversational, inventory-based trading agent for HashKey Chain Seoul, Track 1 — AI Agent Trading. It watches ETH and BTC on HSKSwap and HashKey Global, prices both legs at the same quantity, and decides whether the spread survives fees, slippage and gas. Ask about a position, inspect the decision behind it, or change a risk limit and replay the same market window.

Open the workspace  |  Watch the 1:36 demo  |  Read the interactive guide

Start with the judge walkthrough and submission links. The public app uses real market feeds and labels paper execution. On HashKey public testnet, FlowShield bought and sold test BTC in one transaction and test ETH in another. Both used two HSKSwap pools. The team set the exit price and supplied the tokens that paid for each sale. BTC receipt and ETH receipt. The Solidity executor also completed a separate WHSK swap. Confirmed HSKSwap transaction

It opens without a login or wallet. The screen below shows a recorded BTC position and a proposed change to the order cap. The user can review the change before it takes effect.

FlowShield workspace answering a BTC inventory question and asking the user to confirm a 25 USDT position cap

Three minutes with the agent

Time Action What to look for
0:00–0:45 Open Overview and select Check live market for BTC or ETH. Market dashboard The live panel shows buy and sell totals on both venues for one quantity, the book time and a HashKey Chain block link. If a feed is stale, the panel shows the reason. The recording stays available.
0:45–1:45 Open Decision ledger and select BTC / ccf3267. Recorded ledger Follow the AI-selected 50 USDT candidate from its initial quote through the block recheck, simulated DEX sale and CEX buy. Compare expected net with settled P&L.
1:45–3:00 Open the hedge lab. Ask Set position size to 25 USDT, select Confirm change, then Replay with settings. Hedge lab workspace The settings version advances. The replay applies the new cap to the same inputs. The lab uses synthetic shocks so reviewers can also inspect partial hedges, stops and unknown outcomes.

Other supported requests include Show BTC positions and P&L, Set trade cooldown to 20 seconds, Set risk appetite to 0.5 USDT and Target ETH only. Chat history is private to the browser visitor within the run. Confirmed paper settings are shared by participants in that run. Chat guide

One decision, down to the cash flows

In the bundled mainnet recording, the BTC AI ladder, zero added hedge delay, selected a DEX sale of 0.00083 BTC. It checked the trade again at block 30,929,504. In the paper ledger, the DEX leg received 50.151566 USDT and the CEX hedge spent 49.715622 USDT, including its fee. After 0.010000 USDT of modeled gas, the pair settled at +0.425943 USDT. The 0.05 USDT planning reserve is reported separately. Full plan and chronological events and recheck block on HashKey Chain

The fixed-100 control illustrates why the two assets behaved differently. Across the recorded window, the BTC sell-on-DEX edge cleared the 30 bps floor at every valid observation. ETH stayed below it, and two ETH reads were rejected as stale. Seven qualifying BTC quotes still yielded only one completed pair in that control. Inventory, rechecks and the consumed pool state constrain entries.

Net executable edge for selling on HSKSwap in the fixed-100 control. BTC observations range from about 92 to 95 bps. ETH ranges from about 23 to 28 bps, below the 30 bps floor, with two stale observations.

At zero added delay the independent BTC accounts settled at +0.425943 USDT for the AI ladder, +0.525930 for the highest-edge ladder, and +0.966715 for fixed-100. Each started with its own inventory. This window provides a reproducible comparison. Establishing a sustained return or a model advantage requires additional out-of-sample runs. Strategy comparison and figure source

How the agent trades

flowchart TD
    A["HSKSwap on chain 177<br/>Block-pinned quotes"] --> C["Price identical base quantities<br/>at the 25 / 50 / 100 USDT ladder"]
    B["HashKey Global spot<br/>Timestamped WebSocket depth"] --> C
    C --> D{"Fresh data, inventory<br/>and at least 30 bps after costs?"}
    D -->|No| W["Record WAIT and the reason"]
    D -->|Yes| E["Selector returns an eligible ID or WAIT"]
    E -->|Candidate| F{"Recheck quantity, risk settings,<br/>new book and new block"}
    E -->|WAIT| W
    F -->|Fails| W
    F -->|Passes| G["Paper DEX fill"]
    G --> H["Hedge the filled base quantity<br/>using a later CEX book"]
    H -->|Complete| I["Settle cash flows and P&L"]
    H -->|Partial or unknown| J["Track residual exposure<br/>and apply stop or pause rules"]
Loading

The built-in selector learns the historical difference between rechecked and settled outcomes from earlier baseline trades for each asset and direction. On a cold start it can wait. The deterministic risk engine owns quantities, inventory checks and execution limits. The ledger keeps the selected candidate and its later recheck together. Engine and selector

The public deployment runs a TypeScript Next.js frontend on Vercel and FastAPI on Railway. One persistent SQLite WAL volume supports a single application instance. Dashboard opens the active live-data PAPER window while the collector is running. Its independent Funded results view serves receipt-verified team executions when published. In Workspace ask Show funded P&L to read the same evidence. The private operator CLI uses a separate journal and signer. Mainnet executor deployment, a funded swap receipt and an authenticated Global hedge fill are pending. The signing path was exercised on local Anvil and on public testnet. The testnet dashboard links both two-pool trades, the standalone WHSK swap and the two strategy executor deployments. Operator guide, step-by-step funded setup, private execution guide and acceptance review

Run the demo locally

Install Python 3.12, uv and Node.js 20.9 or later. From the repository root, start the API in one terminal.

uv sync --locked
uv run python -m flowshield.v3_runner seed
uv run flowshield serve

Start the web app in a second terminal.

npm --prefix frontend ci
npm --prefix frontend run dev

Open the local workspace. Seeding creates the recorded market run and the synthetic hedge lab. To collect fresh public quotes and observe the agent while it runs, start a 60-second paper session in another terminal and open its dashboard. Local live-demo dashboard

uv run python -m flowshield.v3_runner paper --session live-demo --seconds 60 --interval 5

For another window using the same inventory, add --continue-from live-demo and a new session ID. Continuous collection, restart recovery and the disk budget are described in the operator guide. Reusing the ID of a completed run returns its existing ledger. A completed collection window can contain unsettled trades. Check the open position and residual before reading settled P&L. Session modes

Verify the build and replay

Install Foundry, including Forge and Anvil, for the contract and local signing checks.

uv run --locked pytest -q
forge test
npm --prefix frontend run build
npm --prefix frontend run typecheck
npm --prefix frontend run check:copy

The recording and its digest are checked in. Rebuild the chart with uv run docs/figures/recorded_edges.py. To run the legacy WHSK/Gate experiment, seed it with uv run flowshield replay --session demo and open the legacy workspace. Recording manifest

Documentation

For Start here
Judges Demo walkthrough, Track 1 evidence, requirements and remaining gaps
Developers Architecture and implementation plan, original WHSK/Gate design, English web guides
Operators Deployment, persistence and recovery, funded execution prerequisites

The app ships in English. UI text, accessibility labels and metadata use typed message keys. Assistant reply templates and public API messages use a server catalog. Each web guide has a stable slug and a locale-specific Markdown file. Screenshots and diagrams open at full size from the hosted guides.

For a rehearsal with test tokens, open the Testnet dashboard and follow the chain 133 and Global SIM operator guide.

Releases

Packages

Contributors

Languages