dimension

Financial arithmetic for Fe, where the meaning of every number is part of its type. Amounts know their token and which way they move; their rounding follows from that, always against the trader. Prices know their pair. External numbers become trusted only at a boundary that checks them. Mistakes that cost real protocols nine figures are rejected when your contract compiles.

use dimension::{Asset, In, Out, Quantity, Settled, admit, given, owed, scaling_factor, settle}

pub struct USDC {}

impl Asset for USDC {
    const DECIMALS: u256 = 6
}

/// Internal units credited for a deposit of `raw` USDC. Value arriving is counted down.
pub fn credit(_ raw: u256) -> u256 {
    admit(given<USDC, In>(raw), scaling_factor<USDC>()).value()
}

/// USDC paid out for `internal` units owed. Value leaving is paid down.
pub fn payout(_ internal: u256) -> Quantity<USDC, Out, Settled> {
    settle(owed<USDC, Out>(internal), scaling_factor<USDC>())
}

No line above names a rounding, and none can name the wrong one. Writing a payout where a charge is expected is a compile error, not an audit finding.

Install

Requires Fe 26.6.0 or 26.7.0. CI pins 26.6.0, and also runs every ingot, test suite and compile-fail case on 26.7.0 (make compat). Install Fe with its installer:

curl -fsSL https://raw.githubusercontent.com/argotorg/fe/master/feup/feup.sh | bash -s -- --version v26.6.0

Add the dependency to your ingot's fe.toml, pinned to a release commit:

[dependencies.dimension]
source = "https://github.com/Femtech-web/Dimension"
rev = "5a1aafe80e2f9034242fb6f5ada9b2495685d2ac"   # v0.3.1
name = "dimension"
version = "0.3.1"
  • Fe resolves rev as a full commit hash, not a tag. Each release's commit is listed in the changelog.
  • name selects this ingot inside the repository's workspace.
  • A local checkout works as a path dependency, relative to your project (Fe rejects absolute paths): dimension = { path = "../Dimension/ingots/dimension" }.

Or let the command line write it. Installed with pipx install "git+https://github.com/Femtech-web/Dimension#subdirectory=cli", dimension new ../my-protocol creates the quickstart with this dependency, and dimension check ../my-protocol --strict runs the checklist before deploying (cli).

CI checks this exact setup on every change (make consumer). The quickstart is built as a fresh project taking Dimension by git. It must pass its tests, and a misuse must be rejected.

Start from the quickstart

examples/quickstart is a complete project: a deposit desk contract, its tests, and the dependency already declared. Copy it, switch the dependency to the git form above, and run:

fe check                     # type-check, including every Dimension rule
fe test                      # run the tests on the EVM
fe test --backend native     # and natively (Linux x86-64 and Apple silicon)
fe build                     # bytecode and ABI in out/

What is in it

Module Provides
asset Asset: a token type and its decimals
flow, rounding In and Out, the stages Given, Admitted, Owed, Settled (TokenUnits: the two in token units), the valuation sides Collateral and Debt. Sealed: Floor and Ceil are the only roundings
value Quantity, ScalingFactor, Rate, Price, Amount, Value, and the only functions that produce the trusted ones: admit, settle, exchange, value_of. Held<T> (credit, debit) and Supply<T> (issue, retire) move a balance held or a supply issued, only by their own token, in the direction it is labelled
value::oracle EVM only. Feed<B, Q> and RateSource<T> declarations; verify at deployment; read and read_rate with freshness and band checks
policy RiskPolicy, with borrow_capacity and is_healthy checked by compile-time predicates
invariant Backing and preserves_share_value, an exact runtime share-value check
value::testing unsafe test constructors for prices and rates

Everything compiles for the EVM. Everything except value::oracle, which calls other contracts, also compiles natively. The type machinery costs nothing at run time. Typed and hand-written code produce byte-identical bytecode at -O1, -O2 and -Os in the probes (make probes). On this library itself (make evm), its four roundings do too, and an ERC-4626 vault built on it costs the same gas as the hand-written one on every call.

  • The guide: each concept, with code from the tests.
  • The API reference, generated by fe doc from these sources: on the project site at /api, or locally with make apidoc (writes web/public/api/index.html).

Safety model

  • Trusted values have private fields. A Price, a Rate, or an Admitted or Settled quantity exists only if the function that checks it produced it.
  • Test constructors are unsafe. assume_price and assume_rate can only be called from an ingot that sets allow_unsafe = true on this dependency. Set it only in test roots, never in an ingot you deploy. dimension check fails a project that sets it, or that contains unsafe code.
  • Boundaries check what the chain can show, not what it cannot. A feed's decimals, freshness and band are checked. That an address is the feed it is declared to be, the chain cannot show. For Chainlink feeds, feed_check.py checks it against Chainlink's directory before you deploy.
  • What each layer guarantees, and what it does not: docs/guarantees.md.

Status and versioning

Built for the Fe Builders Challenge 2026. It is not audited: audit a protocol built on it as you would any other. Versions follow semantic versioning; before 1.0, a minor version may change the API. Every release, its commit and its changes are in the changelog. Report vulnerabilities privately, as described in SECURITY.md.

License

Apache-2.0.

Source: ingots/dimension/README.md