Skip to content

Conversation

@ales-otf
Copy link
Contributor

@ales-otf ales-otf commented Sep 2, 2025

Description

This is a refactoring of swap interface and swap pallet to make it have a static dispatch and to be type safe.

Related Issue(s)

  • Closes #[issue number]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run cargo fmt and cargo clippy to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

Please include any relevant screenshots or GIFs that demonstrate the changes made.

Additional Notes

Please provide any additional information or context that may be helpful for reviewers.

@ales-otf ales-otf force-pushed the feat/type-safe-swap branch from a4b5459 to b3be47d Compare September 2, 2025 18:38
@ales-otf ales-otf self-assigned this Sep 3, 2025
@ales-otf ales-otf marked this pull request as ready for review October 3, 2025 15:49
@sam0x17 sam0x17 added apply-benchmark-patch skip-cargo-audit This PR fails cargo audit but needs to be merged anyway labels Oct 3, 2025
sam0x17
sam0x17 previously approved these changes Oct 3, 2025

let result = result.unwrap();

// we don't want to have silent 0 comparissons in tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// we don't want to have silent 0 comparissons in tests
// we don't want to have silent 0 comparisons in tests

Comment on lines 4166 to 4171
// let fee = <Test as Config>::SwapInterface::approx_fee_amount(netuid.into(), (amount as f64 * 0.99) as u64);
// let fee = <Test as Config>::SwapExt::approx_fee_amount(netuid.into(), (amount as f64 * 0.99) as u64);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this suppose to be SwapInterface and not SwapExt ?

let stake_amount = TaoCurrency::from(100_000_000_000);

let default_fee = 0; // FIXME: DefaultStakingFee is deprecated
let default_fee = TaoCurrency::ZERO; // FIXME: DefaultStakingFee is deprecated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this comment still valid?

Suggested change
let default_fee = TaoCurrency::ZERO; // FIXME: DefaultStakingFee is deprecated
let default_fee = TaoCurrency::ZERO;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test still relies on this value. We should probably refactor the test.

l0r1s
l0r1s previously approved these changes Oct 3, 2025
Copy link
Collaborator

@l0r1s l0r1s left a comment

Choose a reason for hiding this comment

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

Well done!

@ales-otf ales-otf dismissed stale reviews from l0r1s and sam0x17 via 8b62e98 October 6, 2025 12:08
l0r1s
l0r1s previously approved these changes Oct 6, 2025
let order = GetAlphaForTao::<T>::with_amount(u64::MAX);
let result = T::SwapInterface::swap(netuid.into(), order, limit_price, false, true)
.map(|r| r.amount_paid_in.saturating_add(r.fee_paid))
.map_err(|_| Error::ZeroMaxStakeAmount)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Someone in the community was complaining about this error. We actually have PriceLimitExceeded, which is much more readable for the end user. I think we can replace it for PriceLimitExceeded because get_max_amount_add is only used for adding or moving stake.

let order = GetTaoForAlpha::<T>::with_amount(u64::MAX);
let result = T::SwapInterface::swap(netuid.into(), order, limit_price.into(), false, true)
.map(|r| r.amount_paid_in.saturating_add(r.fee_paid))
.map_err(|_| Error::ZeroMaxStakeAmount)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here: Consider replacing with PriceLimitExceeded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll do these changes!

@sam0x17 sam0x17 merged commit 6d3ab3a into devnet-ready Oct 7, 2025
55 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants