Skip to content

feat: improve stableswap pool share mint/burn process#1482

Merged
enthusiastmartin merged 5 commits into
masterfrom
feat/stable-shares
Jul 16, 2026
Merged

feat: improve stableswap pool share mint/burn process#1482
enthusiastmartin merged 5 commits into
masterfrom
feat/stable-shares

Conversation

@enthusiastmartin

@enthusiastmartin enthusiastmartin commented Jul 13, 2026

Copy link
Copy Markdown
Member

This PR reworks stable pool shares mint and burn process.

instead of relying on total issuance - stableswap tracks issuance of each pool separately.

The goal of this rework is to harden security of the stableswap implementation, despite the need of extra storage.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.

Tip: disable this comment in your organization's Code Review settings.

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

Crate versions that have been updated:

  • runtime-integration-tests: v1.101.1 -> v1.103.0
  • pallet-stableswap: v7.4.1 -> v7.5.0
  • hydradx-runtime: v430.0.0 -> v431.0.0

Runtime version has been increased.

@github-actions

Copy link
Copy Markdown

Weight Diff Report

⚠️ 2 pallet(s) have changes exceeding ±10% threshold

35 extrinsic(s) changed across 2 pallet(s). New: 0. Removed: 0.

pallet_omnipool_liquidity_mining

Extrinsic RefTime Proof Size Reads Writes
create_global_farm +0.1% (118.9M → 119.1M) 7 → 8 (+1)
update_global_farm -0.8% (165.6M → 164.2M) 8 → 9 (+1)
terminate_global_farm -1.5% (139.6M → 137.6M) 7 → 8 (+1)
create_yield_farm +0.6% (185.5M → 186.5M) 11 → 12 (+1)
update_yield_farm +0.1% (191.6M → 191.7M) 11 → 12 (+1)
stop_yield_farm +0.1% (184.4M → 184.5M) 10 → 11 (+1)
resume_yield_farm -0.2% (188.9M → 188.5M) 11 → 12 (+1)
terminate_yield_farm +0.9% (134.6M → 135.8M) 8 → 9 (+1)
deposit_shares +0.3% (281.3M → 282.1M) 19 → 20 (+1)
redeposit_shares +0.1% (242.3M → 242.5M) 17 → 18 (+1)
claim_rewards -1.4% (248.5M → 244.9M) 13 → 14 (+1)
withdraw_shares -0.2% (337.0M → 336.4M) 18 → 19 (+1)
join_farms +2.4% (168.4M → 172.4M) 15 → 16 (+1)
add_liquidity_and_join_farms +2.3% (506.5M → 517.9M) 45 → 46 (+1) 26 → 25 (-1)
exit_farms -0.8% (108.6M → 107.7M) 12 → 13 (+1)
add_liquidity_stableswap_omnipool_and_join_farms ⚠️ +29.1% (2.1B → 2.7B) 77 → 80 (+3)
remove_liquidity_stableswap_omnipool_and_exit_farms ⚠️ +54.4% (1.1B → 1.7B) 63 → 64 (+1)
price_adjustment_get +1.8% (174.2M → 177.3M)

pallet_stableswap

Extrinsic RefTime Proof Size Reads Writes
create_pool -0.6% (54.7M → 54.4M)
create_pool_with_pegs +0.8% (99.4M → 100.2M)
add_assets_liquidity +0.5% (2.8B → 2.8B) 53 → 54 (+1) 17 → 18 (+1)
add_liquidity_shares +1.1% (2.1B → 2.1B) 37 → 38 (+1) 9 → 10 (+1)
remove_liquidity_one_asset +1.3% (2.1B → 2.1B) 34 → 35 (+1) 8 → 9 (+1)
remove_liquidity +0.4% (1.7B → 1.7B) 55 → 56 (+1) 13 → 14 (+1)
withdraw_asset_amount +4.5% (2.5B → 2.6B) 35 → 36 (+1) 7 → 8 (+1)
sell +1.0% (2.1B → 2.1B)
buy +1.1% (2.0B → 2.0B)
set_asset_tradable_state -6.1% (24.6M → 23.1M) 2 → 1 (-1)
update_pool_fee +2.1% (21.0M → 21.4M)
update_amplification +2.3% (21.9M → 22.4M)
update_asset_peg_source +3.0% (27.9M → 28.7M)
update_pool_max_peg_update +1.8% (25.6M → 26.1M)
router_execution_sell -0.2% (1.2B → 1.2B) ⚠️ -15.7% (16590 → 13990) 19 → 18 (-1)
router_execution_buy +0.5% (585.6M → 588.8M)
calculate_spot_price_with_fee -3.4% (511.8M → 494.3M) ⚠️ -15.7% (16590 → 13990) 18 → 17 (-1)

Threshold: ±10%. Base Weight::from_parts(ref_time, proof_size) compared; per-unit components ignored.

@cl0w5 cl0w5 left a comment

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.

Can you add an end-to-end regression / integration test covering the whole flow?

placeOrder → settleOtcOrder → router → StableSwap → OTC cleanup

Comment thread pallets/stableswap/src/lib.rs Outdated
T::Currency::withdraw(pool_id, who, amount, ExistenceRequirement::AllowDeath)
}

fn debug_assert_issuance_in_sync(pool_id: T::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.

This will still trigger as a false positive (?) during OTC settlement:

  1. OTC temporarily mints M LP tokens.
  2. The token system’s total issuance increases by M.
  3. StableSwap’s new internal ShareIssuance intentionally does not increase.
  4. OTC routes the received assets through StableSwap to buy LP tokens.
  5. StableSwap checks this debug assertion which fails because: total_issuance = ShareIssuance + M

Only later would OTC burn the temporary M tokens and bring both counters back into sync. The assertion runs before that cleanup can happen.

The panic from the debug assert will also prevent an end-to-end regression test

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i have prepare a change in the settlemtn to not use mint at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mby this should be real assert, not just debug

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.

Tip: disable this comment in your organization's Code Review settings.

@enthusiastmartin
enthusiastmartin merged commit 889486b into master Jul 16, 2026
10 of 11 checks passed
@github-actions

Copy link
Copy Markdown

Quick benchmark at commit 9fe44b6 has been executed successfully.
View results

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.

3 participants