Skip to content

Add python implementation of QuantAmm #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 23, 2025
Merged

Conversation

brunoguerios
Copy link
Member

Closes #118

Main:

  • Add python implementation of QuantAmm maths

Extra:

  • Refactor integer division so it follows TS and Solidity behavior (rounding towards zero)

@brunoguerios brunoguerios self-assigned this Jun 17, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a Python implementation of the QuantAMM pool and ensures integer division matches TypeScript and Solidity (round‐towards‐zero) behavior.

  • Added QuantAMM math, data mapping, and pool logic
  • Registered QuantAMM in pool‐state mapper and vault
  • Introduced BigInt for zero‐towards‐zero division and updated log‐exp math

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
testData/testData/1-22524240-QuantAMM.json New QuantAMM test vectors
testData/config.json Updated config to use new QuantAMM pool
python/test/utils/map_pool_state.py Registered QUANT_AMM_WEIGHTED in mapper
python/test/test_remove_liquidity.py Imported price‐tolerance helper
python/test/test_add_liquidity.py Imported price‐tolerance helper (and unused sys)
python/src/vault/vault.py Added QuantAmm to vault’s pool classes
python/src/pools/weighted/weighted_math.py Updated imports to src-based paths
python/src/pools/reclamm/reclamm_math.py Minor formatting fixes
python/src/pools/quantamm/quantamm_math.py Implemented block‐normalised weight and unpacking
python/src/pools/quantamm/quantamm_data.py Defined QuantAmmState and mapping from JSON
python/src/pools/quantamm/quantamm.py Implemented QuantAmm pool logic
python/src/pools/quantamm/init.py Added module docstring
python/src/common/types.py Registered QuantAmmState in type unions
python/src/common/log_exp_math.py Wrapped fixed‐point ops with BigInt for rounding
python/src/common/bigint.py Custom BigInt class for truncating division
Comments suppressed due to low confidence (6)

python/src/pools/quantamm/quantamm.py:24

  • [nitpick] Add a docstring for the QuantAmm class to explain its purpose and public API usage.
class QuantAmm(PoolBase):

python/src/pools/quantamm/quantamm_math.py:6

  • [nitpick] Function name uses British spelling (normalised) while other parts use American (normalized); consider unifying spelling for consistency.
def calculate_block_normalised_weight(

python/src/pools/quantamm/quantamm.py:47

  • The new on_swap logic for QuantAmm isn't covered by unit tests; consider adding tests for both GIVEN_IN and GIVEN_OUT swap scenarios.
    def on_swap(self, swap_params: SwapParams) -> int:

python/test/utils/map_pool_state.py:11

  • The module no longer defines or exports transform_strings_to_ints, but some tests import it. Either add transform_strings_to_ints here or remove its import in tests.
def map_pool_state(pool_state: dict) -> PoolState | BufferState:

python/test/test_add_liquidity.py:4

  • [nitpick] The sys import is unused in this test file; consider removing it to keep imports clean.
import sys

python/src/common/log_exp_math.py:2

  • [nitpick] Wrapping every division in BigInt can add significant overhead; consider minimizing conversions or optimizing critical loops.
from common.bigint import BigInt

Add python implementation of LBPs
@brunoguerios brunoguerios merged commit fb35337 into refactor-python Jun 23, 2025
2 checks passed
@brunoguerios brunoguerios deleted the quant-amm-python branch June 23, 2025 12:57
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.

2 participants