Skip to content

Restrict trading to a time window

Configure a half-open runtime-clock window and verify its boundary behavior.

Prerequisites: the callback contract and understand configuration. The program is examples/hooks/timelock; its pure policy is TradingWindow in examples/hooks/shared/src/window.rs.

Example hook: trading window. This optional example gates swaps in a configured pool. Trading windows are not a built-in or default protocol requirement.

1. Define the interval

The example policy value is:

HookPolicy::Timelock(TradingWindow {
    opens_at: 100,
    closes_at: 200,
})

These timestamps are illustrative Unix seconds. Setup requires opens_at < closes_at, the PolicyOnly profile, and exactly BeforeSwap. Use the creator-owned setup path; there is no policy-update instruction.

2. Apply execution time, not client time

The callback reads the runtime Clock and evaluates:

opens_at <= now < closes_at
TimeResult for [100, 200)
99Reject: not open
100Allow: opening included
199Allow
200Reject: closing excluded

The hook requires an empty payload and returns fee_ppm: None. It does not let the caller submit an alternative timestamp. A transaction prepared before closing can still reject when executed after closing.

3. Explain what is gated

The policy applies to swaps in either direction in its bound pool. It is not a buy-only rule, a token transfer restriction, an LP vesting schedule, or a liquidity withdrawal lock. The example enables no removal callbacks and leaves fee claims outside hook dispatch.

The name timelock refers to this trading window only. Combining it with dynamic fees would require a deliberately composed policy program and its own tests; a pool cannot attach these two example programs independently.

Next: quote only executable policy paths

A compatible quote adapter must evaluate the same runtime-time snapshot and account for expiration between quote and execution. A successful quote at opening is not an unconditional promise of execution. Continue to Metis compatibility or allowlist membership.