{"id":24066302,"url":"https://github.com/rainlanguage/rain.math.fixedpoint","last_synced_at":"2026-05-15T06:11:38.050Z","repository":{"id":152462726,"uuid":"618344930","full_name":"rainlanguage/rain.math.fixedpoint","owner":"rainlanguage","description":"18 decimal fixed point math in solidity","archived":false,"fork":false,"pushed_at":"2024-12-07T12:04:44.000Z","size":1228,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-09T11:46:01.247Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rainlanguage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-24T09:15:05.000Z","updated_at":"2024-12-07T12:04:49.000Z","dependencies_parsed_at":"2025-01-09T11:40:13.644Z","dependency_job_id":"7cd5ebd6-efcb-4f77-b176-54c8876fe173","html_url":"https://github.com/rainlanguage/rain.math.fixedpoint","commit_stats":null,"previous_names":["rainlanguage/rain.math.fixedpoint"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainlanguage%2Frain.math.fixedpoint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainlanguage%2Frain.math.fixedpoint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainlanguage%2Frain.math.fixedpoint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rainlanguage%2Frain.math.fixedpoint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rainlanguage","download_url":"https://codeload.github.com/rainlanguage/rain.math.fixedpoint/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240919217,"owners_count":19878551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-09T11:39:58.358Z","updated_at":"2026-05-15T06:11:38.045Z","avatar_url":"https://github.com/rainlanguage.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rain.math.fixedpoint\n\nDocs at https://rainprotocol.github.io/rain.math.fixedpoint\n\n## Goals\n\nIdeally we'd not need this library as math primitives are probably best handled\nin some upstream library.\n\nWhat we need:\n\n- 18 decimal fixed point math\n- handle rounding directions explicitly\n- rescale non-18 decimal fixed point values (e.g. ERC20 token amounts) to/from\n  18 decimals so that we can do math on them\n- avoid code bloat in an interpreter due to importing several libs with heavily\n  overlapping scope\n- open source license, but not forcing ppl to jump on the GPL crusade\n- minimal surface area so we can gracefully deprecate this lib if all the above\n  is provided elsewhere someday\n- works on simple `uint256` values\n\nUpstream candidates:\n\n- Open Zeppelin\n  - Has implementations that include rounding direction 👍\n  - Audited code due to recent ERC4626 implementation 👍\n  - Only includes math needed by the specs implemented, not general purpose 👎\n- PRB math\n  - General purpose fixed point math 👍\n  - Where the scope overlaps OZ the logic is similar or identical 👍\n  - No ability to specify rounding or to rescale outside 18 decimals 👎\n  - Never audited 👎\n- Others\n  - Either wrong license or issues as pointed out on PRB math repo\n\nSince we need math that isn't provided by Open Zeppelin, and we aren't going to\nwrite it ourselves, PRB math seems to be the most reasonable foundation. At the\nsame time, Open Zeppelin may already be a dependency for other reasons, such as\nsome token implementation, so including both OZ and PRB in a single contract can\nbloat code.\n\n## Non-goals\n\nNone of this is supported/needed:\n\n- Signed math\n- Non-18 decimal fixed point math (other than rescaling)\n- One size fits all solution\n\n## Approach\n\n- Provide a base repo (this one) that has zero dependencies, to focus on the\n  logic required to rescale between decimals, that are lib agnostic.\n- Provide supporting repos to normalise Open Zeppelin and PRB math\n  - OZ includes `muldiv` but doesn't have an opinion on decimals, so caller is\n    forced to provide \"one\" at every step and mentally balance multiplication\n    and division\n  - PRB is opinionated with sane defaults for 18 decimal math but provides no\n    rounding or rescaling support\n\nDownstream consumers are advised to select _one_ of either OZ or PRB to compile\ninto their contracts, using the relevant supporting libs only, to minimise\ndependencies and potential code bloat, or even inconsistent behaviours between\nlibs.\n\n## Install\n\nVia [soldeer](https://soldeer.xyz):\n\n```sh\nforge soldeer install rain-math-fixedpoint~\u003cversion\u003e\n```\n\n## Develop\n\nThis repo uses [nix](https://nixos.org/download.html). The default shell is the\nslim `sol-shell` from [rainix](https://github.com/rainlanguage/rainix).\n\n```sh\nnix develop          # enter the shell\nforge soldeer install # install deps declared in foundry.toml\nforge test\n```\n\nTasks:\n\n- `rainix-sol-test` — `forge test`\n- `rainix-sol-static` — slither\n- `rainix-sol-legal` — `reuse lint`\n\nUse the nix-pinned `forge` for all development.\n\n## Publish\n\nTag `v\u003cx.y.z\u003e` on `main`. The\n[`Publish to Soldeer`](.github/workflows/publish-soldeer.yaml) wrapper delegates\nto rainix's reusable workflow, which derives the package name from the repo name\n(`rain.math.fixedpoint` → `rain-math-fixedpoint`).\n\n## License\n\nDecentraLicense 1.0 (DCL-1.0) — full text in\n[`LICENSES/`](LICENSES/LicenseRef-DCL-1.0.txt). Roughly `CAL-1.0`\n([opensource.org](https://opensource.org/license/cal-1-0)) plus user-data\ndisclosure obligations consistent with permissionless-blockchain assumptions.\n\nThis repo is [REUSE 3.2](https://reuse.software/spec-3.2/) compliant. Verify\nlocally:\n\n```sh\nnix develop -c rainix-sol-legal\n```\n\n## Contributions\n\nWelcome under the same license. Contributors warrant that their contributions\nare compliant.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainlanguage%2Frain.math.fixedpoint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frainlanguage%2Frain.math.fixedpoint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainlanguage%2Frain.math.fixedpoint/lists"}