Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/chaos-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
node-version-file: '.nvmrc'
cache: 'npm'
cache-dependency-path: package-lock.json

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
node-version-file: '.nvmrc'
cache: "npm"
cache-dependency-path: package-lock.json

Expand Down Expand Up @@ -155,7 +155,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
node-version-file: '.nvmrc'
cache: "npm"
cache-dependency-path: package-lock.json

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/db-backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
node-version-file: '.nvmrc'

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: '.nvmrc'

# No lockfile is committed for the portal yet; once one lands, add
# `cache: npm` + `cache-dependency-path: docs-site/package-lock.json`
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
node-version-file: '.nvmrc'
cache: npm
cache-dependency-path: package-lock.json

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
node-version-file: '.nvmrc'
cache: "npm"
cache-dependency-path: package-lock.json

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.19.0'
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testnet-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
node-version-file: '.nvmrc'
cache: "npm"
cache-dependency-path: package-lock.json

Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ cd flowfi

Make sure you have the following installed:

- Node.js (LTS recommended)
- Node.js 22 (`^22.22.1`) — the version is pinned in `.nvmrc` and enforced via `engines` + `engine-strict`; run `nvm use` in the repo root
- npm
- Rust & Cargo
- Docker & Docker Compose
Expand Down
4 changes: 2 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Full Node toolchain (devDependencies incl. tsc + prisma CLI) compiles the
# TypeScript and generates the Prisma client. Discarded from the final image.
# ============================================================================
FROM node:20-alpine@sha256:fb4cd12c85ee03686f6af5362a0b0d56d50c58a04632e6c0fb8363f609372293 AS builder
FROM node:22-alpine@sha256:1314fb30ec37592d5845e5a160d522c0e680972aa534549940b8d73bde88481a AS builder

WORKDIR /app

Expand All @@ -28,7 +28,7 @@ RUN npm run build
# Stage 2 — production runner
# Minimal Alpine base, production-only dependencies, non-root `node` user.
# ============================================================================
FROM node:20-alpine@sha256:fb4cd12c85ee03686f6af5362a0b0d56d50c58a04632e6c0fb8363f609372293 AS runner
FROM node:22-alpine@sha256:1314fb30ec37592d5845e5a160d522c0e680972aa534549940b8d73bde88481a AS runner

WORKDIR /app

Expand Down
3 changes: 3 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"prisma:studio": "prisma studio",
"codegen:openapi": "tsx scripts/export-openapi.mts"
},
"engines": {
"node": "^22.22.1"
},
"prisma": {
"seed": "tsx prisma/seed.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion docs-site/docs/contracts/soroban-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ Most authorization errors (#3, #6, #24, #32, #43) mean you're calling from the w
:::

:::note
For detailed error handling examples, see the [SDK Integration Guide](../sdk/overview.md) and [Testing Patterns](../development/testing.md).
For detailed error handling examples, see the [TypeScript SDK guide](../sdks/typescript.md) and [Running Tests](https://github.com/LabsCrypt/flowfi/blob/main/docs/DEVELOPMENT.md#running-tests).
:::
4 changes: 2 additions & 2 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ npm run dev:mock
### Prerequisites for the sandbox

- Docker & Docker Compose (for Postgres, Redis, mock RPC)
- Node.js 20+ and npm (for backend, frontend, seed script)
- Node.js 22 (see `.nvmrc`) and npm (for backend, frontend, seed script)

No Rust, no Stellar CLI, no testnet account needed.

Expand All @@ -94,7 +94,7 @@ No Rust, no Stellar CLI, no testnet account needed.
Required:

- Rust toolchain (stable via rustup)
- Node.js 20+
- Node.js 22 (`^22.22.1`) — the version is pinned in `.nvmrc` and enforced via `engines` + `engine-strict`; run `nvm use` in the repo root
- npm
- PostgreSQL 16 (matches the version pinned in `docker-compose.yml` and CI)
- Docker & Docker Compose (recommended for local infra)
Expand Down
44 changes: 42 additions & 2 deletions docs/DISASTER_RECOVERY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,55 @@ FlowFi stores encrypted PostgreSQL backups in Amazon S3. The backup includes a p

## Restore a backup

Restore to an empty PostgreSQL database. The script authenticates and decompresses the full archive before submitting SQL, then compares the restored count of every recorded public table to the manifest. It exits nonzero on decryption, archive, SQL, or row-count errors.
Restore into a freshly provisioned, empty PostgreSQL database whenever possible.

```sh
export DATABASE_URL='postgresql://user:password@localhost:5432/flowfi_recovery'
export BACKUP_ENCRYPTION_KEY='<64 hex characters from the secret store>'

# 1. Rehearse first: decrypts and validates the backup, inspects the target,
# prints the plan, and changes nothing.
bash scripts/db-restore.sh --dry-run /secure/path/flowfi-<timestamp>-<run-id>.tar.gz.enc

# 2. Restore.
bash scripts/db-restore.sh /secure/path/flowfi-<timestamp>-<run-id>.tar.gz.enc
```

For S3, download the selected object to a protected temporary location with `aws s3 cp`, then pass its path to the restore script. Restrict access to both the encrypted object and the key; encryption does not replace access controls.
For S3, download the selected object to a protected temporary location with `aws s3 cp`, then pass its path to the restore script. Restrict access to both the encrypted object and the key; encryption does not replace access controls. Run `bash scripts/db-restore.sh --help` for every option.

### What the script does

1. **Validates the backup before touching the database.** The archive is authenticated (AES-256-GCM), decompressed and checked for its dump and row-count manifest before any SQL is sent. A wrong key, tampered file or malformed manifest exits with code `1` and no changes.
2. **Checks that the target is empty.** If the target database contains any user tables, views, sequences, types or functions, the restore is **refused with exit code `3`** unless `--force` is given.
3. **Restores in a single transaction.** The SQL dump and the row-count verification for every recorded `public` table run inside one transaction (`psql --single-transaction`). If any statement fails or any count differs from the manifest, PostgreSQL rolls back the entire restore.

### Replacing a non-empty database (`--force`)

`--force` replaces the contents of a non-empty database. Use it only when restoring into a fresh database is impossible.

```sh
bash scripts/db-restore.sh --dry-run --force <backup> # review the plan
bash scripts/db-restore.sh --force <backup> # asks you to type the database name
bash scripts/db-restore.sh --force --yes <backup> # non-interactive (automation only)
```

With `--force` the script:

1. asks the operator to type the database name to confirm (skipped only with `--yes`; without a TTY `--yes` is mandatory);
2. writes an encrypted **pre-restore snapshot** of the current database, in the same format as regular backups, to `--snapshot-dir` (default `$RESTORE_SNAPSHOT_DIR` or `./restore-snapshots`). The snapshot is encrypted with the same `BACKUP_ENCRYPTION_KEY`; store it as carefully as a production backup;
3. drops every user schema and restores the backup, all in the same transaction as the verification.

### Failure and recovery states

| Failure point | State of the target database | What to do |
| --- | --- | --- |
| Decryption, archive or manifest validation | Untouched | Check the key and backup file, then retry. |
| Target not empty (exit `3`) | Untouched | Use a fresh database, or re-run with `--force`. |
| Snapshot fails (`--force`) | Untouched | Fix the cause (disk space, `pg_dump` version) and retry; no restore was attempted. |
| SQL error or row-count mismatch during restore | **Unchanged**: the transaction is rolled back, including the `--force` schema wipe | Read the error printed by the script, fix the cause and retry. |
| Connection lost mid-restore | Unchanged: PostgreSQL aborts the uncommitted transaction | Retry. |

A successful run ends with `Restore completed and all N recorded public table row counts matched.` If a forced restore succeeded but the old data is needed again, restore the snapshot with `bash scripts/db-restore.sh --force <snapshot file>`.

## Weekly disaster-recovery verification

Expand Down
4 changes: 2 additions & 2 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# emits a self-contained server bundle (`output: "standalone"` in
# frontend/next.config.ts) instead of the full `.next` tree + node_modules.
# ============================================================================
FROM node:20-alpine@sha256:fb4cd12c85ee03686f6af5362a0b0d56d50c58a04632e6c0fb8363f609372293 AS builder
FROM node:22-alpine@sha256:1314fb30ec37592d5845e5a160d522c0e680972aa534549940b8d73bde88481a AS builder

WORKDIR /app

Expand Down Expand Up @@ -41,7 +41,7 @@ RUN npm run build --workspace frontend
# Copies only the traced standalone output (never the workspace node_modules)
# and runs as the non-root `node` user that ships with the Alpine base image.
# ============================================================================
FROM node:20-alpine@sha256:fb4cd12c85ee03686f6af5362a0b0d56d50c58a04632e6c0fb8363f609372293 AS runner
FROM node:22-alpine@sha256:1314fb30ec37592d5845e5a160d522c0e680972aa534549940b8d73bde88481a AS runner

WORKDIR /app

Expand Down
3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"test:e2e:headed": "playwright test --headed",
"codegen:api-types": "openapi-typescript ../backend/swagger/flowfi.openapi.json -o src/lib/api-types.generated.ts"
},
"engines": {
"node": "^22.22.1"
},
"dependencies": {
"@stellar/freighter-api": "^6.0.1",
"@stellar/stellar-sdk": "^17.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const { mockToast, mockSoroban, mockTracker, mockUseStreamingAmount, mockTransac
resumeStream: vi.fn(),
toBaseUnits: vi.fn((v: string) => BigInt(Math.round(parseFloat(v)) * 10_000_000)),
toSorobanErrorMessage: vi.fn((e: unknown) => (e instanceof Error ? e.message : String(e))),
// Consumed by the shared token resolver in `@/lib/tokens`.
TOKEN_ADDRESSES: {
USDC: "CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA",
XLM: "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCN",
EURC: "CCWAMYJME4YOIUNAKVYEBYOG5I65QMKEX2NMN4OJAPXRPIF24ONPSHY",
},
};
const mockTracker = {
status: "idle" as string,
Expand Down
9 changes: 2 additions & 7 deletions frontend/src/app/streams/[id]/stream-details-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { formatAmount, streamProgressPercent, validateAmountInput } from "@/util
import { shortenPublicKey } from "@/lib/wallet";
import { LiquidStreamVisualizer } from "@/components/LiquidStreamVisualizer";
import { TokenAvatar } from "@/components/TokenAvatar";
import { resolveTokenSymbol } from "@/lib/tokens";

interface StreamDetail {
id: string;
Expand All @@ -56,12 +57,6 @@ interface StreamDetail {
const API_BASE_URL = `${getApiBaseUrl()}/v1`;
const EVENTS_PER_PAGE = 10;

const TOKEN_SYMBOLS: Record<string, string> = {
"CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCN": "XLM",
"CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA": "USDC",
"CCWAMYJME4YOIUNAKVYEBYOG5I65QMKEX2NMN4OJAPXRPIF24ONPSHY": "EURC",
};

const EVENT_STYLES: Record<string, { color: string; icon: string; label: string }> = {
CREATED: { color: "#22c55e", icon: "✓", label: "Created" },
TOPPED_UP: { color: "#3b82f6", icon: "+", label: "Topped Up" },
Expand Down Expand Up @@ -224,7 +219,7 @@ export default function StreamDetailsContent({ streamId }: { streamId: string })

const tokenSymbol = useMemo(() => {
if (!stream) return "??";
return (stream.tokenAddress && TOKEN_SYMBOLS[stream.tokenAddress]) || stream.tokenAddress?.slice(0, 4) || "??";
return resolveTokenSymbol(stream.tokenAddress) || stream.tokenAddress?.slice(0, 4) || "??";
}, [stream]);

const { data: tokenPrice } = useTokenPrice({ tokenSymbol, enabled: Boolean(stream) });
Expand Down
10 changes: 1 addition & 9 deletions frontend/src/lib/api/streams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BackendStream } from "@/lib/api-types";
import { TOKEN_ADDRESSES } from "@/lib/soroban";
import { resolveTokenLabel } from "@/lib/tokens";
import { shortenPublicKey } from "@/lib/wallet";
import {
DEFAULT_FETCH_TIMEOUT_MS,
Expand Down Expand Up @@ -33,14 +33,6 @@ interface StreamListResponse {
data?: BackendStream[];
}

function resolveTokenLabel(tokenAddress: string): string {
const entry = Object.entries(TOKEN_ADDRESSES).find(
([, address]) => address === tokenAddress,
);

return entry?.[0] ?? `${tokenAddress.slice(0, 6)}...${tokenAddress.slice(-4)}`;
}

function toIncomingStreamStatus(stream: BackendStream): IncomingStreamStatus {
if (stream.isPaused) return "Paused";
if (stream.isActive) return "Active";
Expand Down
14 changes: 1 addition & 13 deletions frontend/src/lib/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from "@tanstack/react-query";
import type { BackendStream } from "./api-types";
import { getStreamsEndpointCandidates, toTokenAmount } from "./api/_shared";
import { TOKEN_ADDRESSES } from "./soroban";
import { resolveTokenLabel } from "./tokens";
import { logger } from "./logger";

export interface ActivityItem {
Expand Down Expand Up @@ -64,18 +64,6 @@ function shortenAddress(address: string): string {
return `${address.slice(0, 6)}...${address.slice(-4)}`;
}

/**
* Resolves a token contract address to its symbol (XLM/USDC/EURC), falling
* back to a shortened address when the token is unknown.
*/
function resolveTokenLabel(tokenAddress: string): string {
const entry = Object.entries(TOKEN_ADDRESSES).find(
([, address]) => address === tokenAddress,
);

return entry?.[0] ?? shortenAddress(tokenAddress);
}

/**
* Derives the display status from the backend flags. A paused stream reads
* "Paused"; an active one "Active". An inactive stream is "Cancelled" when a
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/lib/tokens.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { TOKEN_ADDRESSES } from "./soroban";
import { resolveTokenLabel, resolveTokenSymbol } from "./tokens";

describe("token symbol resolution", () => {
it("resolves every address in TOKEN_ADDRESSES to its symbol", () => {
for (const [symbol, address] of Object.entries(TOKEN_ADDRESSES)) {
expect(resolveTokenSymbol(address)).toBe(symbol);
expect(resolveTokenLabel(address)).toBe(symbol);
}
});

it("returns undefined for unknown or empty addresses", () => {
expect(resolveTokenSymbol("CUNKNOWNTOKENADDRESS000000000000")).toBeUndefined();
expect(resolveTokenSymbol(undefined)).toBeUndefined();
expect(resolveTokenSymbol("")).toBeUndefined();
});

it("falls back to a shortened address label for unknown tokens", () => {
expect(resolveTokenLabel("CUNKNOWNTOKENADDRESS0000000000WXYZ")).toBe("CUNKNO...WXYZ");
});
});
33 changes: 33 additions & 0 deletions frontend/src/lib/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { TOKEN_ADDRESSES } from "@/lib/soroban";

/**
* Single source of truth for token contract address → symbol resolution.
*
* Everything is derived from `TOKEN_ADDRESSES` in `lib/soroban.ts`, so adding a
* new token there (or overriding an address via `NEXT_PUBLIC_*_ADDRESS`) is
* picked up by every surface that renders a token symbol.
*/

/** Returns the symbol (e.g. "XLM", "USDC") for a known token address, else `undefined`. */
export function resolveTokenSymbol(
tokenAddress: string | null | undefined,
): string | undefined {
if (!tokenAddress) return undefined;
const entry = Object.entries(TOKEN_ADDRESSES).find(
([, address]) => address === tokenAddress,
);
return entry?.[0];
}

function shortenTokenAddress(address: string): string {
if (!address || address.length < 10) return address;
return `${address.slice(0, 6)}...${address.slice(-4)}`;
}

/**
* Resolves a token address to its symbol, falling back to a shortened address
* (e.g. "CABCDE...WXYZ") when the token is unknown.
*/
export function resolveTokenLabel(tokenAddress: string): string {
return resolveTokenSymbol(tokenAddress) ?? shortenTokenAddress(tokenAddress);
}
Loading
Loading