Repository navigation
Conversation
|
@Emmazlee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
👋 Thanks for the contribution! This repository only accepts contributor pull requests into the Please re-open your PR with base: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR makes
market-coredecimals-aware so it can be deployed against SEP-41 collaterals with anydecimals()in0..=18, not just 7-decimal Stellar Classic USDC. Collateral decimals are read once in__constructor, stored, and exposed viaget_config. The economic bounds (min_seed = 100 * 10^d,max_sets = 1e8 * 10^d) are derived from them. The fixed-point multiply-divide helpers move to 256-bit intermediates so a result that fits ini128is always returned exactly, independent of the old1e30headroom argument. The Python and TypeScript mirrors are kept in lockstep with matching 18-decimal fixtures.Related Issue
Changes
🔢 Decimals-aware market-core
contracts/market-core/src/lib.rsDataKey::Decimals(instance) and a newError::UnsupportedDecimals = 19.__constructornow callstoken::TokenClient::new(&env, &collateral).decimals(), rejects values above 18, and stores the result.pub decimals: u32toConfig(XDR shape change — consumers must regenerate bindings).MIN_SEED/MAX_SETSconstants are no longer used by contract logic;create_marketandbuynow read bounds viaSelf::bounds(&env)?, which readsDataKey::Decimalsthroughinstance_get.settle_valuenow useschecked_addand returnsResult;redeemandclaim_pool_remainderpropagate the error.🧮 256-bit fixed-point helpers
contracts/market-core/src/math.rspub struct Bounds { pub min_seed: i128, pub max_sets: i128 }andpub fn bounds_for_decimals(d: u32) -> Result<Bounds, MathError>usingchecked_pow.mod widewithU256 { hi, lo },mul_u128, anddivrem_u256_by_u128(returnsOverflowwhenn.hi >= dor the quotient exceedsu128::MAX).mul_div_floor/mul_div_ceilto use the 256-bit intermediates. Rounding directions are unchanged;mul_div_ceilstill adds 1 on a non-zero remainder.math::MAX_SETSas a#[deprecated]7-decimal alias for tests only.math.rsstill has nosoroban_sdkimports and its tests run natively.🐍 Python mirror
model/fpmm_model.pybounds_for_decimals._fits_i128assertion inmul_div_*so the model fails where the contract would._check_known_values_18dpusing the 1000/1000 → 190 example scaled by10**11and a seed atmax_sets.🟦 TypeScript mirror
agents/core/fpmm.tsboundsForDecimals(d: number)andI128_MAXchecks inmulDivFloor/mulDivCeil.🚀 Deploy script
scripts/deploy-testnet.shdecimals()cross-contract call succeeds.📚 Docs
README.md,docs/architecture.md,docs/STATUS.mdVerification Results
DataKey::Decimalsset in__constructor,Error::UnsupportedDecimalsexists,Config.decimalsreturned byget_configMIN_SEED/MAX_SETSno longer used by contract logic; bounds come frombounds_for_decimalsmul_div_floor/mul_div_ceiluse 256-bit intermediates with bit-identical results on the legacy domainmath.rsstill has nosoroban_sdkimports and its tests run nativelysettle_valueuses checked addition;redeem/claim_pool_remainderpropagate errorsbuyreported in the PR descriptioncost_buy_7dp_vs_18dpcargo test --workspace,make lint,python3 model/fpmm_model.py,agentsnpm test/npm run buildpassmath.rsheader,docs/architecture.md,docs/STATUS.mdupdatedCloses #3