Skip to content

Conversation

@nicolad
Copy link

@nicolad nicolad 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.

@nicolad nicolad 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
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.

@nicolad nicolad force-pushed the 1151 branch 3 times, most recently from 823116e to 64ca372 Compare November 13, 2025 13:40
Copy link
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.

}
}

fn on_asset_removed(asset_id: AssetId) {
Copy link
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
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
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
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() {

Revert(sc_cli::RevertCmd),

/// The custom benchmark subcommmand benchmarking runtime pallets.
#[cfg(feature = "runtime-benchmarks")]
Copy link
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
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
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
Member

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

@nicolad
Copy link
Author

nicolad commented Dec 21, 2025

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

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

3 participants