A chain-agnostic stablecoin protocol with personalized AI guidance. Built by degens, for degens. Your terminally online goddess of gains awaits.
This monorepo follows a functional architecture approach where:
- Pure Functions: All business logic is implemented as pure functions without side effects
- Immutable Data: State transformations use immutable data structures
- Type Safety: Leverages TypeScript's strict mode with comprehensive type definitions
- Composability: Small, focused functions that compose into larger operations
- Error Handling: Uses functional error handling patterns (Either, Option types)
nyxusd/
├── packages/ # Applications and services
│ ├── cdp-engine/ # Core CDP management engine
│ ├── oracle-service/ # Price oracle aggregation
│ ├── liquidation-engine/ # Liquidation logic
│ ├── governance/ # Governance mechanisms
│ ├── api/ # REST API service
│ └── cli/ # Command-line interface
├── libs/ # Shared libraries
│ ├── core/ # Core business logic
│ ├── types/ # Type definitions
│ ├── utils/ # Utility functions
│ ├── validators/ # Input validation
│ ├── crypto/ # Cryptographic operations
│ ├── contracts/ # Smart contract interfaces
│ ├── midnight-integration/ # Midnight Protocol integration
│ └── functional-utils/ # FP utility functions
└── tools/ # Build and development tools
- Chain-Agnostic: Seamlessly operates across all major blockchains
- AI-Powered: Personalized strategies adapted to your degen level
- Nyx-chan Approved: Guided by your favorite terminally online goddess
- Touch Grass Optional: Built for those who live in the charts
- WAGMI Technology: We're all gonna make it (probably)
- Based AF: No normie energy allowed
All core business logic is implemented as pure functions:
// Example: CDP ratio calculation
const calculateCollateralizationRatio = (
collateralValue: CollateralValue,
debtAmount: DebtAmount,
): CollateralizationRatio => {
return pipe(
collateralValue,
multiply(PRECISION_FACTOR),
divide(debtAmount),
CollateralizationRatio.of,
);
};State changes are modeled as transformations:
// Example: CDP state transition
const updateCdpCollateral = (
cdp: Cdp,
additionalCollateral: CollateralAmount,
): Either<CdpError, Cdp> => {
return pipe(
cdp,
addCollateral(additionalCollateral),
validateMinimumRatio,
map(recalculateHealth),
);
};Uses functional error handling patterns:
// Example: Validation chain
const validateCdpOperation = (
operation: CdpOperation,
): Either<ValidationError, ValidatedOperation> => {
return pipe(
operation,
validateCollateralAmount,
chain(validateDebtAmount),
chain(validateRatioRequirements),
map(ValidatedOperation.of),
);
};- Node.js >= 18.0.0
- npm >= 8.0.0
- Git
-
Clone the repository
git clone https://github.com/your-org/nyxusd.git cd nyxusd -
Install dependencies
npm install
-
Build all packages
npm run build
-
Run tests
npm run test -
Start development environment
npm run dev
-
Create a new library
nx generate @nrwl/node:library my-lib --directory=libs
-
Create a new package
nx generate @nrwl/node:application my-app --directory=packages
-
Run specific package/library
nx serve my-app nx test my-lib nx lint my-lib -
Build affected packages
npm run build:affected
-
Run tests for affected packages
npm run test:affected
| Script | Description |
|---|---|
npm run build |
Build all packages and libraries |
npm run test |
Run all tests |
npm run lint |
Lint all code |
npm run type-check |
TypeScript type checking |
npm run format |
Format code with Prettier |
npm run validate |
Run full validation (lint + type-check + test) |
npm run dev |
Start development servers |
npm run graph |
View dependency graph |
The project uses TypeScript path mappings for clean imports:
// Instead of relative imports
import { CdpEngine } from "../../../packages/cdp-engine/src";
// Use path mappings
import { CdpEngine } from "@nyxusd/cdp-engine";Available path mappings:
@nyxusd/core- Core business logic@nyxusd/types- Type definitions@nyxusd/utils- Utility functions@nyxusd/validators- Input validation@nyxusd/crypto- Cryptographic operations@nyxusd/contracts- Smart contract interfaces@nyxusd/midnight-integration- Midnight Protocol integration@nyxusd/functional-utils- Functional programming utilities@nyxusd/cdp-engine- CDP management engine@nyxusd/oracle-service- Price oracle service@nyxusd/liquidation-engine- Liquidation engine@nyxusd/governance- Governance mechanisms@nyxusd/api- REST API service@nyxusd/cli- Command-line interface
- Functions:
camelCasewith descriptive verbs (calculateRatio,validateInput) - Types:
PascalCase(CollateralAmount,CdpState) - Constants:
SCREAMING_SNAKE_CASE(MIN_COLLATERAL_RATIO) - Modules:
kebab-case(cdp-engine,oracle-service)
Use pipe for sequential operations:
const processTransaction = (tx: Transaction) =>
pipe(
tx,
validateTransaction,
chain(executeTransaction),
chain(updateState),
fold(handleError, handleSuccess),
);Define explicit types for all data:
interface Cdp {
readonly id: CdpId;
readonly owner: Address;
readonly collateral: CollateralAmount;
readonly debt: DebtAmount;
readonly createdAt: Timestamp;
}- Unit Tests: Test pure functions in isolation
- Integration Tests: Test component interactions
- Property Tests: Use property-based testing for mathematical operations
- Type Tests: Verify TypeScript type correctness
- Follow functional programming principles
- Write pure functions where possible
- Use immutable data structures
- Include comprehensive type definitions
- Write tests for all new functionality
- Follow the established naming conventions
MIT License - see LICENSE file for details.