Skip to content

Omnipool - H2O Sell Routing Change #1336

@enthusiastmartin

Description

@enthusiastmartin

H2O Sell Routing — Route to Treasury Account

Overview

When a user sells H2O (hub asset) to the Omnipool, instead of adding the H2O amount to the traded asset's subpool hub reserve, send the entire H2O amount to a designated treasury account.

Note: H2O can only be sold to the Omnipool, not bought from it.

Current Behavior

  1. User initiates a trade (sell or buy) swapping H2O for another asset
  2. The corresponding asset subpool is updated:
    • Hub reserve (H2O) increases
    • Asset reserve decreases

New Behavior

  1. Update the asset subpool as before, but do not increase its hub reserve
  2. Transfer the H2O amount to the treasury account
  3. The H2O leaves the Omnipool's hub reserve accounting entirely

Implementation

Affected functions

Selling H2O is handled in a separate code path. When the sell side of a trade is H2O (hub asset), one of these functions is called:

  • sell_hub_asset
  • buy_asset_for_hub_asset

Configuration

Add a new config parameter to the Omnipool pallet:

/// Destination account when hub asset is sold
type HubDestination: Get<Self::AccountId>;

Changes required (sell side)

  1. Around line 1793 — where we calculate the new asset state after the trade
  2. Before creating the new asset state:
    • Store the delta_hub_reserve value
    • Replace delta_hub_reserve in state_changes with Increase(0)
  3. Create the new asset state as before (now with zero hub reserve change)
  4. Transfer the stored delta_hub_reserve amount of H2O from the Omnipool account to the treasury account
  5. Call on_hub_asset_trade hook with accurate pool change information:
    • For the traded asset subpool: report hub reserve change as 0

Similar approach for the buy side.

Note: The trade event does not change and still includes the full H2O amount traded.

Testing

Unit tests

  • Verify H2O is transferred to the treasury account, not added to any subpool
  • Verify asset subpool reserve changes correctly (asset decreases, hub reserve unchanged)
  • Verify the Omnipool account's H2O balance decreases by the correct amount
  • Verify the treasury account's H2O balance increases by the correct amount
  • Verify on_hub_asset_trade is called with correct parameters (zero hub change for traded asset)

Integration tests

  • End-to-end H2O sell trades
  • Verify treasury account receives the correct H2O amount
  • Verify traded asset subpool hub reserve remains unchanged

Invariant

  • The Omnipool account's H2O token balance must equal the sum of all subpool hub reserves

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions