Skip to content

Latest commit

 

History

History
493 lines (340 loc) · 23.1 KB

CONTRIBUTING.md

File metadata and controls

493 lines (340 loc) · 23.1 KB

Contributing to Meridian

Thank you for considering a contribution to Meridian. Meridian is an open-source stablecoin yield aggregator on Stellar and Soroban, and contributions across TypeScript, Rust, and frontend UI are welcome.

This document is the single source of truth for contributing. Please read it in full before opening an issue or pull request.


Table of Contents


Code of Conduct

Participation in this project is governed by the Meridian Code of Conduct. By contributing, you agree to uphold it. Violations may be reported via GitHub Discussions (select the Q&A category and mark it private if needed).


Ways to Contribute

In scope:

  • Bug reports and bug fixes
  • Features that have been discussed and approved in a GitHub Discussion
  • Documentation -- README, JSDoc, guides, inline comments
  • Additional test coverage for any package
  • Performance improvements with benchmarks
  • Dependency updates and CI improvements

Not accepted:

  • Unsolicited refactors of code you did not introduce -- if cleanup is needed, open a [Chore] issue first
  • Features that have not been approved in a GitHub Discussion -- PRs for unapproved features will be closed without review
  • PRs that bundle multiple unrelated changes -- one PR per issue, always
  • Changes to formatting or naming conventions that contradict the existing code style

If you are unsure whether a contribution fits, open a GitHub Discussion before writing any code.


First-Time Contributors

If this is your first open-source contribution, start here:

  1. Filter issues by good first issue -- these are fully isolated tasks that do not require deep knowledge of Stellar or Soroban.
  2. Comment on the issue to signal you are picking it up before starting.
  3. Follow the Getting Started guide below to set up the project.
  4. When your PR is ready, follow the Pull Request Process section exactly.

Prerequisites

Before cloning, confirm you have the required tools installed:

Tool Required version Check
Node.js 22.x node --version
pnpm 9.x pnpm --version
Rust toolchain stable (latest) rustc --version
Stellar CLI latest stellar --version

Rust and the Stellar CLI (cargo install stellar-cli; the binary is stellar, the older soroban-cli is deprecated) are only required if you are working on the smart contracts in packages/contracts. TypeScript-only contributors can skip them.

To install pnpm at the correct version:

npm install -g pnpm@9

Toolchain Version Pinning

Meridian pins its supported Node.js and pnpm versions to ensure consistent local development and CI environments:

  • Node.js: The supported Node.js major version is pinned in .node-version and .nvmrc (22). CI workflows (.github/workflows/ci.yml and .github/workflows/verify-contract-addresses.yml) read .node-version via actions/setup-node's node-version-file input.
  • pnpm: The package manager is declared in package.json under "packageManager" (pnpm@9.0.0) and enforced in "engines".
  • Preinstall Enforcement: A preinstall check (scripts/check-version.js) runs before pnpm install to verify that the active Node.js and package manager versions match the repository pins. If an unsupported version is detected, it fails with a clear error message.

Updating the Version Pins

When upgrading the repository toolchain (e.g. migrating to a newer Node.js LTS or pnpm major version):

  1. Update .node-version and .nvmrc: Update the major version number (e.g., 22) in both .node-version and .nvmrc.
  2. Update package.json:
    • Update "packageManager" with the new target version (e.g., "pnpm@10.0.0").
    • Update the "engines" field ("node" and "pnpm") to reflect the supported ranges.
  3. Update Documentation: Update the versions listed in the Prerequisites table in this file.
  4. Verify: Run pnpm install, pnpm lint, and pnpm typecheck to confirm the new versions pass all checks.

Getting Started

  1. Fork the repo on GitHub, then clone your fork:

    git clone https://github.com/<your-username>/meridian.git
    cd meridian
  2. Add the upstream remote so you can keep your fork in sync:

    git remote add upstream https://github.com/drydocs/meridian.git
  3. Before starting any work, sync your fork with upstream:

    git fetch upstream
    git checkout main
    git rebase upstream/main
  4. Install dependencies:

    pnpm install
  5. Copy and configure your environment:

    cp .env.example .env

    Edit .env and set the values you need:

    Variable Required for Description
    PORT API Port for the Fastify API server. Default 3001.
    ALLOWED_ORIGIN API CORS allowed origin. Default https://usemeridian.vercel.app.
    STELLAR_NETWORK API, SDK Target network: testnet or mainnet. Default mainnet; .env.example sets testnet for local dev.
    DEFINDEX_VAULT_ID API DeFindex vault contract address (C-address). Leave empty to disable DeFindex; only Blend positions are returned.
    VITE_API_URL Web URL the web app uses to reach the API. Default http://localhost:3001.
    VITE_BLEND_FAUCET_URL Web Overrides Blend's testnet faucet endpoint. Leave empty to use the default.
  6. Start the development servers:

    pnpm dev
    # Web:    http://localhost:3000
    # API:    http://localhost:3001
    # Health: http://localhost:3001/health
  7. Confirm the full check suite passes before making any changes:

    pnpm lint && pnpm typecheck && pnpm test

    Note: generated Soroban contract test snapshots under packages/contracts/**/test_snapshots are ignored by Git and should not be committed manually.


Project Structure

Meridian is a pnpm monorepo managed with Turborepo:

meridian/
  apps/
    web/        -- Vite + React frontend (Freighter wallet, yield dashboard)
    api-local/  -- Fastify API, local dev only (yield aggregation, Soroban tx building)
    docs/       -- Documentation site (VitePress)
    landing/    -- Landing page
    strategies/ -- Strategies simulation and visualization dashboard
  api/          -- Vercel serverless functions (api/v1/...), the production API
  packages/
    api-core/   -- Framework-agnostic route handlers shared by both servers
    contracts/  -- Soroban smart contracts (Rust)
    sdk/        -- Public TypeScript SDK (@meridian/sdk)
    shared/     -- Shared utilities used by both api and web
    stellar-sdk-helpers/ -- Typed wrappers around @stellar/stellar-sdk
    strategies/ -- Strategy engine and simulation library (@meridian/strategies)

Changes to packages/ affect multiple apps. If you modify a shared package, run the full check suite from the repo root.


Opening Issues

Use one of the two GitHub issue templates. Blank issues are disabled.

Title format

Every issue title must use the bracket prefix format:

[Type] Short imperative description
Prefix When to use
[Bug] or [Fix] Something is broken or behaving incorrectly
[Feature] New capability or significant enhancement
[Frontend] Frontend-scoped work (React, UI, Tailwind)
[Test] Adds or improves test coverage
[Docs] Documentation, README, JSDoc, guides
[Chore] Refactor, cleanup, dependency update, CI

Which template to use

  • Bug Report -- for anything broken, incorrect, or behaving unexpectedly
  • Feature Request -- for features, frontend tasks, tests, docs, and chores

Labels

Apply labels from all three categories before submitting. PRs linked to unlabelled issues will be asked to add labels before review begins.

Category Pick Options
Purpose one bug, enhancement, docs, testing, chore, security
Area all that apply frontend, api, sdk, contracts, ci, ui, i18n, stellar, soroban
Complexity one trivial, medium, hard

Use good first issue in place of a complexity label for tasks that are fully isolated and require no Stellar or Soroban knowledge.


Security Vulnerabilities

Do not open a public GitHub issue for security vulnerabilities.

Report security issues via GitHub's private vulnerability reporting. Include:

  • A description of the vulnerability
  • Steps to reproduce
  • Potential impact
  • Any suggested fix (optional)

You will receive a response within 72 hours. Please allow time for the issue to be triaged and patched before public disclosure.


Branch Naming

All branches must follow this pattern:

<type>/<short-description>

Types: feat, fix, docs, chore, refactor, test, ci

Examples:

feat/freighter-wallet-integration
fix/apy-cache-stale-data
docs/blend-integration-guide
test/yield-routing-edge-cases

Branches that do not match this pattern will fail the branch naming ruleset and cannot be merged.


Commit Convention

Meridian uses Conventional Commits. Every commit must follow this format:

<type>[(<scope>)]: <subject>

Types: feat, fix, test, docs, refactor, perf, chore, ci

Scopes (optional): Use the relevant package or app: api, web, contracts, sdk, shared, ci, docs

Rules:

  • Subject line under 72 characters
  • Use imperative mood: "add" not "added" or "adds"
  • No period at the end of the subject

Examples:

feat(api): add Blend pool APY aggregation endpoint
fix(sdk): handle Soroban RPC timeout on testnet
test(api): add edge case coverage for empty pool response
docs: update CONTRIBUTING with Soroban contract standards
chore: pin Node.js to v20 in GitHub Actions workflow

Issue references (Closes #N) go in the PR body, not in commit messages. Squash merge is enforced -- the PR title becomes the squash commit, so issue refs in individual commits are discarded.

Commits that do not match the ^(feat|fix|docs|chore|refactor|test|style|ci|perf)(\(.+\))?: .{1,72}$ pattern will be blocked by the commit message ruleset.


Code Standards

Architecture Decision Records

When a change alters an accepted architectural decision, update the relevant ADR or add a new one in apps/docs/architecture/adr/. Use the ADR template, update the index, and link the record from the affected architecture documentation. Routine changes that do not alter an architectural decision do not need an ADR.

TypeScript (apps/web, apps/api-local, packages/*)

  • Formatting: Run pnpm format before committing. Prettier with default settings.
  • Linting: Must pass pnpm lint with zero errors.
  • Types: No any. Use unknown and narrow explicitly. Zod schemas are the source of truth for all external data shapes.
  • Naming:
    • PascalCase for types, interfaces, classes, and React components
    • camelCase for variables, functions, and object keys
    • UPPER_SNAKE_CASE for module-level constants
    • kebab-case for filenames
  • Error handling: Never swallow errors silently. Log with context and re-throw or return a typed error result.
  • No side effects at module load time. Protocol clients must be instantiated inside functions, not at the top level of a module. Module-level localStorage, navigator, or SDK .init() calls are violations.
  • Comments: Only comment on WHY, not what the code does. If the code needs a what-comment, the code should be rewritten.

Rust / Soroban (packages/contracts)

  • Formatting: Run cargo fmt --all before committing.
  • Linting: Must pass cargo clippy --all-targets -- -D warnings with zero warnings.
  • Naming:
    • snake_case for functions and variables
    • PascalCase for types and traits
    • UPPER_SNAKE_CASE for constants
  • Error handling: Use Result<T, E> everywhere. No .unwrap() in contract code except on values that are provably infallible; explain why in an inline comment.
  • Adding a ContractError variant: When adding a new variant to ContractError in any contract crate (vault, blend-adapter, defindex-adapter, or musdc-token), assign the next unused u32 discriminant (never reuse or renumber existing codes), add a /// doc comment explaining when it is raised, and document the variant with its cause and recommended client/operator response in apps/docs/architecture/contract-errors.md. Run pnpm --filter @meridian/docs test (included in pnpm test) to verify every variant is cataloged.
  • Documentation: All public functions must have doc comments (///). Include a one-line summary and a note on any panics or preconditions.
  • Security: Validate all inputs. Assume callers are adversarial. Never read from storage without checking the key exists first.

Contract WASM size budgets

Each contract's release WASM has a size budget in packages/contracts/wasm-size-budgets.json, keyed by the WASM file name (meridian_vault, meridian_blend_adapter, ...). The Soroban Contract Tests CI job builds the contracts, then runs pnpm check:wasm-size, which prints each contract's size, budget, share of the budget used and the delta from the PR's base commit (also shown in the job summary). It fails when a contract is over its budget, when a newly built contract has no budget, or when a budgeted contract was not built. The job only runs when contract sources, build settings or the check itself change.

To check locally (needs the wasm32v1-none target; uses stellar contract build when the Stellar CLI is installed, cargo build --target wasm32v1-none --release otherwise):

pnpm check:wasm-size -- --build                  # sizes vs budgets
pnpm check:wasm-size -- --build --base-ref main  # plus the delta from main

Updating a budget. When a contract grows on purpose, raise its number in wasm-size-budgets.json in the same PR and say in the PR description what grew and why; reviewers treat the budget change as an explicit sign-off on the larger binary. For a new contract, add an entry. Budgets are set to roughly the current size plus 10%, rounded up to a whole KiB, so routine changes don't need an update but significant growth gets a deliberate review.


Pull Request Process

PR body format

Every PR must use this structure (the GitHub PR template pre-fills it):

## Summary

- What changed and why (bullet points, not a list of files touched)

## Test plan

- [ ] `pnpm lint && pnpm typecheck && pnpm test` pass locally
- [ ] What you manually verified

Closes #N

Closes #N must reference the issue this PR resolves. PRs with no linked issue will not be reviewed.

Changelog

Maintainers own the changelog. Contributors do not need to update it.

Rules

  1. One PR per issue. Do not bundle multiple issues into a single PR.
  2. Keep PRs small. A PR that changes more than 400 lines of non-test code will be asked to split.
  3. Fill out the PR template fully. Incomplete templates will be closed without review.
  4. All CI checks must pass before a review will begin. Do not open a PR with known failures.
  5. Resolve all review comments before requesting a re-review. Mark a thread as resolved only after you have addressed it.
  6. Do not force-push after a review has started. Add new commits to address feedback so the reviewer can see what changed.
  7. Squash on merge is enforced. Your commit history inside the branch does not need to be clean, but your PR title must follow the commit convention -- it becomes the squash commit message.

What to expect

Pull requests are reviewed within 72 hours of submission. You will receive one of:

  • Approved -- the PR will be merged promptly
  • Changes requested -- address the comments and request a re-review
  • Closed -- the PR is out of scope, a duplicate, or does not meet the standards in this guide; the closing comment will explain why

CI Concurrency and Timeouts

All GitHub Actions workflows under .github/workflows/ define explicit concurrency groups and per-job timeouts:

  • Concurrency groups are keyed by workflow and ref (${{ github.workflow }}-${{ github.ref }}).
  • Pull request workflows (ci.yml, pr-title.yml, verify-contract-addresses.yml) set cancel-in-progress for pull request runs so pushing a new commit cancels superseded runs on the same ref.
  • Default branch and keeper runs are never cancelled by concurrency (cancel-in-progress is disabled for pushes to main and for keepers.yml), ensuring scheduled keeper runs and main-branch checks run to completion.
  • Job timeouts (timeout-minutes) are set explicitly on every job, sized above observed runtimes so hung installs, builds, or tests fail promptly instead of waiting for the default 6-hour limit. When adding a new job or workflow, always include both a concurrency block and an explicit timeout-minutes value.

Running Checks Locally

Run all checks before pushing. CI will catch failures, but fixing them locally is faster.

# Full check suite (run this before every push)
pnpm lint && pnpm typecheck && pnpm test

# Individual checks
pnpm lint          # ESLint across all packages
pnpm typecheck     # tsc --noEmit across all packages
pnpm test          # Vitest across all packages
pnpm coverage      # Vitest with coverage thresholds across all packages
pnpm format        # Prettier (auto-fix)
pnpm lint:md       # markdownlint (config: .markdownlint.json)
pnpm check:links   # Internal links and heading anchors in all Markdown (needs lychee)

# Run tests for a single package
pnpm --filter @meridian/stellar-sdk-helpers test

# Run a single test file
pnpm --filter @meridian/stellar-sdk-helpers exec vitest run src/tx.test.ts

# Soroban contract checks (only needed when modifying packages/contracts)
cargo fmt --all
cargo clippy --all-targets -- -D warnings
cargo test --all

Adding a new API error code

When introducing a new error code or status mapping in packages/api-core:

  1. Define the error code string and handler response shape in packages/api-core.
  2. Add the code, status, trigger condition, retry guidance, and recommended client action to the catalog in apps/docs/architecture/api-errors.md.
  3. If introducing a new user-fixable Soroban contract error mapping, add it to USER_FIXABLE_CONTRACT_ERRORS in packages/api-core/src/tx.ts and document it in the Contract Simulation Errors table.
  4. Run pnpm --filter @meridian/docs test to verify the catalog is complete.

Docs checks

The Docs Lint & Links CI job runs when a pull request (or a push to main) touches Markdown, apps/docs, or the checker configs. It runs pnpm lint:md and pnpm check:links, which are strict: a broken relative link, root-relative VitePress link, or heading anchor fails the job. External links are checked with pnpm check:links:external, which only warns on pull requests. Install the link checker locally with brew install lychee (or cargo install lychee).

Hosts that block or rate-limit CI runners, and GitHub-relative links such as ../../issues, are allowlisted in lychee.toml; add a comment explaining any new entry. Heading anchors must resolve on both GitHub and VitePress, so avoid apostrophes and other punctuation in headings that are linked to.

End-to-end tests

The e2e suite (apps/web/e2e/) drives the real apps/web and apps/api-local dev servers with a real headless browser via Playwright. It hits the real API and real Stellar testnet RPC end to end; only Freighter's wallet-signing step is mocked (see apps/web/e2e/fixtures.ts), since a real browser extension can't run in CI. Only needed when modifying apps/web, apps/api-local, or anything the deposit/withdraw/vault-list flows depend on.

# One-time: install the browser binary
pnpm --filter @meridian/web exec playwright install chromium

# Run the full suite (boots both dev servers automatically)
pnpm --filter @meridian/web test:e2e

# Interactive UI mode, useful for debugging a failing spec
pnpm --filter @meridian/web test:e2e:ui

This suite is a blocking CI check. Tests that depend on live testnet RPC or other external services (such as the vault-list APY/TVL/route assertions) stub the API with page.route() to keep the suite deterministic. Real testnet RPC is still exercised in the deposit/withdraw tx-build specs, which accept valid RPC failure states as expected outcomes. Before merging a PR, this job must pass (see #535).


Getting Help

  • Questions about an issue? Comment on the issue directly.
  • Dev setup broken? Open a GitHub Discussion under the Q&A category.
  • Found a bug not covered by an existing issue? Open a new issue using the Bug Report template before starting any work.
  • Have a feature idea? Open a Discussion first. Do not open a PR for a feature that has not been discussed and approved.
  • Security issue? Use GitHub private vulnerability reporting -- do not open a public issue.

By contributing to Meridian, you agree that your contributions will be licensed under the project's MIT License.