Building Your First Strategy

You can start building your first strategy by visiting the Strategy Portal. Fork the starter repo and read through the sample code to get started.

In this section, we explain some core concepts that will help with building your first strategy.

Placing and updating positions

Haiko strategies rely on a push rather than pull architecture for position updates.

Rather than periodically submitting updates to the contract, positions are updated only when a swap is executed (and crucially, before the swap occurs).

The lifecycle of a swap is as follows:

  1. User submits swap via MarketManager

  2. MarketManager calls update_positions() and passes the execution context to the Strategy contract

  3. Strategy executes logic to place, update or withdraw positions

  4. Strategy passes execution context back to MarketManager

  5. MarketManager executes swap

Deploying a strategy

Strategies are deployed by creating a market and registering the strategy to that market upon deployment. At the moment, each market can have at most one strategy to limit the gas costs of swap execution.

Strategies must first be whitelisted by the protocol owner in order to be deployed.

Deposits, withdrawals and fees

Strategy writers are free to implement proprietary logic for enabling third-party LP deposits and withdrawals, and charging associated fees on these actions.

While official Haiko strategies will charge a small fee on withdrawals, this is not prescribed for third party strategies, but rather left at the discretion of strategy builders.

Last updated