Skip to content

fix: clear dynamic fees and oracle storage when removing token from omnipool#1262

Closed
v9ai wants to merge 8 commits intogalacticcouncil:masterfrom
v9ai:1151
Closed

fix: clear dynamic fees and oracle storage when removing token from omnipool#1262
v9ai wants to merge 8 commits intogalacticcouncil:masterfrom
v9ai:1151

Conversation

@v9ai
Copy link
Copy Markdown

@v9ai v9ai commented Nov 13, 2025

Description

This PR adds storage cleanup functionality when removing a token from the omnipool.

When an asset is removed from the omnipool via remove_token extrinsic, the following related storage entries are now cleared:

  • Dynamic fees - Removes AssetFee and AssetFeeConfiguration entries
  • Oracle entries - Removes oracle data for all supported periods, accumulator entries, and whitelist entries

The implementation uses two new trait abstractions:

  • AssetFeesRemover - for clearing dynamic fee storage
  • OracleAssetRemover - for clearing oracle-related storage

Related Issue

Closes #1151

Motivation and Context

Previously, when an asset was removed from the omnipool, related storage entries in other pallets (dynamic fees and oracle) were not being cleaned up. This could lead to stale data accumulating in storage.

How Has This Been Tested?

  • Existing test remove_token_should_clear_related_storage validates the removal functionality
  • Runtime adapters implement the cleanup logic for both dynamic fees and oracle entries
  • Integration tests confirm proper cleanup of all related storage

Checklist

  • I have updated the documentation if necessary.
  • I have added tests to cover my changes, regression test if fixing an issue.
  • This is a breaking change.

@v9ai v9ai changed the title Clear dynamic fees and oracle storage when removing token from omnipool fix: clear dynamic fees and oracle storage when removing token from omnipool Nov 13, 2025
@enthusiastmartin
Copy link
Copy Markdown
Member

Thanks for your contribution.

Idea is good, but it is unnecessary explicit.

let me write some detailed "spec" in the issue. so if you want, you can rework it.

@v9ai v9ai force-pushed the 1151 branch 3 times, most recently from 823116e to 64ca372 Compare November 13, 2025 13:40
Copy link
Copy Markdown
Member

@enthusiastmartin enthusiastmartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. looks good.

few minor comments .

and we also need to bump crate versions.

Comment thread runtime/hydradx/src/assets.rs Outdated
Comment thread pallets/omnipool/src/lib.rs Outdated
Comment thread pallets/omnipool/src/lib.rs Outdated
Comment thread pallets/omnipool/src/traits.rs Outdated
Comment thread runtime/adapters/src/lib.rs Outdated
}
}

fn on_asset_removed(asset_id: AssetId) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to create 2 new functions for this in the corresponding pallets and benchmark it there. @enthusiastmartin WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions should also emit relevant events: RemovedFromWhitelist and AssetFeeConfigRemoved

}

#[test]
fn remove_token_should_call_on_asset_removed_hook() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to use the AAA pattern (arrange, act, assert) in our test. At least in new tests. Example can be found here


Just add these 3 comments.

}

#[test]
fn remove_token_should_clear_related_storage() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can be removed. It's already tested here

fn remove_token_should_remove_asset_from_omnipool() {

Comment thread node/src/cli.rs
Revert(sc_cli::RevertCmd),

/// The custom benchmark subcommmand benchmarking runtime pallets.
#[cfg(feature = "runtime-benchmarks")]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also bump the version of all the crates that has been changed + runtime version.

}

// Verify whitelist entry is removed
let whitelist = pallet_ema_oracle::WhitelistedAssets::<hydradx_runtime::Runtime>::get();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for Accumulator storage is missing

}

#[test]
fn remove_token_should_clear_both_fees_and_oracle_entries() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would merge remove_token_should_clear_dynamic_fees_storage and remove_token_should_clear_dynamic_fees_storage into this one test

@enthusiastmartin
Copy link
Copy Markdown
Member

@NicolaD can you address the review comments and resolve some merge conflicts ?

@v9ai
Copy link
Copy Markdown
Author

v9ai commented Dec 21, 2025

@NicolaD can you address the review comments and resolve some merge conflicts ?

Co-authored-by: openhands <openhands@all-hands.dev>
@v9ai v9ai closed this by deleting the head repository Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clear related asset storage when asset is removed from omnipool

4 participants