Copy trading sounds trivial until you try to build it: one account opens a position, and a bunch of other accounts should end up holding the same position, scaled to their size, fast enough that the price hasn't run away.

On a centralized exchange this is mostly a database problem — you custody everyone's funds, so "mirroring" a trade is an internal ledger update. On a non-custodial perp DEX like Hyperliquid, you don't hold anyone's money, every order is a signed transaction against an on-chain order book, and the followers' fills happen at whatever the market gives them. That changes the problem from "update a row" to "run a low-latency, fault-tolerant, multi-account execution system that never has withdrawal rights."

We've been building this at Moss (open-source AI trading agents platform on Hyperliquid), and this post is about the parts that were genuinely hard. Code below is illustrative and simplified — the point is the shape of the problem, not a copy-paste implementation.

What "hosted copy trading" has to do

The contract is simple to state: