Skip to content

docs: document every public contract function - #68

Merged
codemagician1949 merged 4 commits into
IntensifierLab:mainfrom
definurse13:docs/3-public-fn-doc-comments
Aug 25, 2026
Merged

codemagician1949 merged 4 commits into
IntensifierLab:mainfrom
definurse13:docs/3-public-fn-doc-comments

Conversation

@definurse13

Copy link
Copy Markdown
Contributor

Closes #3

Adds /// documentation to the public items that were missing it across all four crates — 47 of the 182 public items — and makes cargo doc warning-free, which it was not before this change.

Every added comment states what the function returns, what its arguments mean where it takes any, and whether it can fail.

The part worth reviewing: what zero means

Most of the gap was view helpers, and for nearly all of them the ambiguous case is the zero value. Documenting "returns the buyer limit" would have been useless; documenting what 0 means is the thing a caller actually needs:

  • buyer_limit_bps, sme_limit_bps, min_deposit, max_deposit, reserve_ratio_bps return 0 when create_pool has not run. That is unconfigured, not a limit of zero — a caller reading it as the latter draws exactly the wrong conclusion.
  • withdraw_util_threshold defaults to BPS_SCALE, not 0, because the permissive default is the one where utilisation never blocks a withdrawal.
  • nav defaults to NAV_SCALE — parity — not zero.
  • is_upgrade_paused returning true does not mean nothing is pending: queueing and cancelling still work while paused, and only the Wasm swap is held back.
  • invoice_due_at returning None means the grace-period clock has never started, so the invoice cannot be defaulted at all — a materially different state from "due, but not yet".

Fixing cargo doc (acceptance criterion 3)

cargo doc was emitting 10 unresolved-link warnings before this change, so the criterion could not be met just by adding comments.

All ten were [`Self::foo`] references inside #[contractimpl] blocks. The macro expands each function into its own __foo module, so Self does not resolve to the contract type from inside the generated docs, and every such link silently breaks — they render as plain text rather than links, which is why this went unnoticed.

Rewriting them as fully-qualified paths (PoolManager::foo, InvoiceRegistry::foo, and so on) resolves them against the contract struct, so the links now actually work rather than being dropped. New doc comments use the same form for the same reason.

cargo doc --workspace --no-deps is now clean: 0 warnings.

Also

Public struct fields on WaterfallTier, WaterfallResult and QueuedUpgrade are documented, and QueuedUpgrade's header was // rather than /// — so it never reached the docs at all. That is now fixed.

Acceptance criteria

  • Parameters and return values described
  • Errors/panics documented
  • cargo doc warning-free (was 10 warnings, now 0)

No behaviour change

Comments only, plus one doc comment split so two storage constants each carry their own rather than sharing one. No signature, no logic, no manifest touched.

Verification

cargo check --workspace, cargo test --workspace, cargo doc --workspace --no-deps (0 warnings), and cargo build --release --target wasm32-unknown-unknown --workspace all pass.

This PR and #7 are conflict-free in either merge order. They touch disjoint file sets by construction — this one only .rs files, #7 only Cargo.toml files. I merged them both ways locally against main to confirm rather than assume: zero conflicts each way, both orders produce an identical tree, and the merged result passes the full gate. Whichever you merge first, the other needs no rebase.

Adds `///` documentation to the public items that were missing it across
all four crates - 47 of the 182 public items - and makes cargo doc
warning-free, which it was not before this change.

Every added comment states what the function returns, what its arguments
mean where it takes any, and whether it can fail. For the view helpers
that make up most of the gap, the part worth writing down is what the
zero value means, because in almost every case it is ambiguous:

- buyer_limit_bps, sme_limit_bps, min_deposit, max_deposit and
  reserve_ratio_bps return 0 when create_pool has not run. That is
  "unconfigured", not "a limit of zero", and a caller that reads it as
  the latter draws exactly the wrong conclusion.
- withdraw_util_threshold defaults to BPS_SCALE rather than 0, because
  the permissive default is the one where utilisation never blocks a
  withdrawal.
- nav defaults to NAV_SCALE, ie parity, not zero.
- is_upgrade_paused being true does not mean nothing is pending; queueing
  and cancelling still work while paused and only the Wasm swap is held
  back.
- invoice_due_at returning None means the grace-period clock has never
  started, so the invoice cannot be defaulted at all.

cargo doc was emitting 10 unresolved-link warnings before this change,
all of them [`Self::foo`] references inside #[contractimpl] blocks. The
macro expands each function into its own __foo module, so Self does not
resolve to the contract type from inside the generated docs and every
such link silently breaks. Rewriting them as fully-qualified paths
(PoolManager::foo, InvoiceRegistry::foo, and so on) resolves them
against the contract struct, so the links now work rather than being
dropped. New doc comments use the same form for the same reason.

Public struct fields on WaterfallTier, WaterfallResult and QueuedUpgrade
are documented too, and QueuedUpgrade's `//` header became `///` so it
actually reaches the docs.

No behaviour changes: comments, plus one doc comment split so that two
storage constants each carry their own rather than sharing one.

Closes IntensifierLab#3
@codemagician1949

Copy link
Copy Markdown
Contributor

@definurse13 please fix failing ci

The WASM size job was failing with pool_manager.wasm at 68,161 bytes
against the 65,536-byte ceiling.

The cause is not obvious from the diff, so worth stating: Soroban's
#[contractimpl] embeds `///` doc comments into the contract spec that
ships inside the .wasm. Documentation added to entrypoints is therefore
paid for in on-chain artifact size. Confirmed directly - the added text
is greppable in the built binary.

That alone did not create the problem. There was no [profile.release] in
the workspace at all, so contracts were built with the default release
profile: optimised for speed, symbols retained. On pristine main
pool_manager was 65,502 bytes, i.e. 34 bytes under the limit. Any change
to that crate, documentation or code, would have broken the size check.

Adding the standard Soroban contract profile fixes it with room to
spare:

  governance            30,005 -> 27,074
  invoice_registry      53,565 -> 47,563
  pool_manager          65,502 -> 61,041   (was 68,161 on this branch)
  repayment_waterfall   45,385 -> 41,145

pool_manager now has ~4.5KB of headroom rather than 34 bytes, and that
is with this branch's documentation included. overflow-checks stays on
deliberately: silent wrapping in financial arithmetic is worth more than
the bytes it costs.

Two further fixes for regressions that arrived with main and would fail
this PR's own acceptance criteria:

- cargo fmt --all --check was failing on tests/create_invoice.rs and
  tests/events.rs. Neither is touched by this PR; both arrived in recent
  merges and main's own CI is currently red for this reason. Applied
  cargo fmt to them.
- Two new [`Self::foo`] doc links in invoice-registry reintroduced the
  unresolved-link warnings this PR exists to remove. Rewritten as
  qualified paths like the rest, so cargo doc is warning-free again.
The Formatting and Clippy job was still failing, now on Clippy rather
than rustfmt: tests/events.rs imports Symbol without using it, and the
repo runs clippy --all-targets -D warnings.

The error is not new. That job previously exited at the formatting step,
so Clippy never ran on this file; fixing the formatting in the previous
commit let the job get far enough to reach it. Neither the import nor
the file belongs to this PR - both arrived with recent merges to main -
but the job cannot go green while it is there.

Verified with the exact CI invocations this time rather than a filtered
subset: cargo fmt --all -- --check, cargo clippy --workspace
--all-targets -- -D warnings, cargo test --workspace --no-fail-fast,
cargo doc (0 warnings), and the release wasm build with per-crate sizes
checked against the 64KB ceiling.
@codemagician1949
codemagician1949 merged commit 2fcc735 into IntensifierLab:main Aug 25, 2026
4 checks passed
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.

docs: add doc comments to all public contract functions

2 participants