-
Notifications
You must be signed in to change notification settings - Fork 100
Open
Description
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
- User initiates a trade (sell or buy) swapping H2O for another asset
- The corresponding asset subpool is updated:
- Hub reserve (H2O) increases
- Asset reserve decreases
New Behavior
- Update the asset subpool as before, but do not increase its hub reserve
- Transfer the H2O amount to the treasury account
- 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_assetbuy_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)
- Around line 1793 — where we calculate the new asset state after the trade
- Before creating the new asset state:
- Store the
delta_hub_reservevalue - Replace
delta_hub_reserveinstate_changeswithIncrease(0)
- Store the
- Create the new asset state as before (now with zero hub reserve change)
- Transfer the stored
delta_hub_reserveamount of H2O from the Omnipool account to the treasury account - Call
on_hub_asset_tradehook 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_tradeis 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels