Repository navigation
feat(math): shared 1e7 fixed-point and basis-point math library (#235) - #506
Merged
techisigu merged 5 commits intoOct 24, 2026
Conversation
…act-Protocol#235) Extend refract-math with SCALE_1E7, MAX_BPS, Rounding::{Floor, Ceil}, mul_div_ceil, apply_bps, ratio_bps, to_1e7/from_1e7, and checked/saturating arithmetic helpers; include math in workspace members and migrate backstop, bounty, grants, and treasury.\n\nCloses Refract-Protocol#235
…licts (Simple agent) - backstop/src/lib.rs: merged [markers] — model resolved the conflict markers Co-authored-by: Simple Agent <agent@simple.dev>
…licts (Simple agent) - backstop/src/lib.rs: merged [markers] — model resolved the conflict markers Co-authored-by: Simple Agent <agent@simple.dev>
…licts (Simple agent) - backstop/src/lib.rs: merged [markers] — model resolved the conflict markers Co-authored-by: Simple Agent <agent@simple.dev>
…licts (Simple agent) - backstop/src/lib.rs: merged [markers] — model resolved the conflict markers - bounty/src/lib.rs: merged [markers] — model resolved the conflict markers Co-authored-by: Simple Agent <agent@simple.dev>
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.
Summary
Implements a shared
#![no_std]fixed-point (1e7) and basis-point (10_000) checked-math library inrefract-math(math/) and migrates the four governance-adjacent contracts (backstop,bounty,grants, andtreasury) onto it.Key Changes
Cargo.toml,coverage-floor.toml):mathfromexcludeinto workspacememberssocargo test --workspaceand CI coverage gates executerefract-math's unit andproptestsuites on every PR.[math]floor (lines = 95.00,branches = 90.00) tocoverage-floor.toml.1e7), Basis-Point (10_000), and Checked-Math Primitives (math/src/lib.rs,math/src/tests.rs):SCALE_1E7: i128 = 10_000_000,MAX_BPS: u32 = 10_000, andRounding::{Floor, Ceil}.mul_div(a, b, c, rounding)andmul_div_ceil(a, b, c)backed by 256-bitmul_wide/div_wideintermediates so intermediate products never overflow when the quotient fits ini128.apply_bps,apply_bps_floor,apply_bps_ceil, andratio_bpswith explicit validation (bps <= 10_000,0 <= part <= whole).to_1e7andfrom_1e7scale conversion helpers pluschecked_add,checked_sub,checked_mul,saturating_add, andsaturating_sub.proptestcoverage for floor/ceil invariants,apply_bps_floor(x, bps) + apply_bps_ceil(x, 10_000 - bps) == x, andto_1e7/from_1e7round-trips across[0, i128::MAX].backstop: Usesrefract_math::{mul_div_floor, split_bps, saturating_add, saturating_sub, BPS_DENOM, SCALE_1E7}for share minting/redemption (calc_shares,quote_withdrawal),tranche_share_price,senior_coverage_ratio, andreceive_premium.bounty: Usesrefract_math::{checked_add, checked_sub}for balance and reservation accounting infund,award,create_payout,claim,sweep_expired, andavailable_balance_inner.grants: Usesrefract_math::{checked_add, checked_sub, saturating_add}for milestone sum checks, claimable balance accumulation, liability accounting, andrescueexcess checks.treasury: Usesrefract_math::{apply_bps_floor, saturating_add, saturating_sub, MAX_BPS}inReservetarget calculation and inflow routing.Closes #235