Skip to content

nufi-official/zcash-router-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

138 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Zcash Router SDK Monorepo

A monorepo containing TypeScript SDKs for routing assets to and from Zcash. Built with pnpm workspaces, supporting both ESM and CommonJS, and compatible with Node.js and browsers.

🎯 Production-Grade Mainnet Demo

Live demos:

These are fully functional, production-grade implementations:

  • βœ… Live blockchain integration - Real swaps on Solana and Zcash mainnet
  • βœ… End-to-end transactions - Complete deposit to withdrawal flow
  • βœ… Professional UI - Modern interface with real-time status tracking

πŸ—οΈ Architecture

The SDK is designed with a modular architecture that separates concerns and makes it easy to extend support for new assets and wallet types:

Core Package

The @zcash-router-sdk/core package handles all the logic for managing swaps to and from Zcash. Built on NEAR intents, it provides:

  • Swap orchestration and state management
  • Integration with swap APIs
  • Quote fetching and execution tracking
  • Status monitoring and event callbacks

Account Packages

Account packages implement the AccountFull and AccountAddressOnly interfaces defined in the core package, providing blockchain-specific functionality:

Extensibility

The architecture makes it easy to add new packages for:

  • Other blockchain assets (Ethereum, Bitcoin, etc.)
  • Hardware wallets (Ledger, Trezor, etc.)
  • Extension wallets (MetaMask, Phantom, etc.)
  • Other key management methods (WIF, private keys, etc.)

Simply implement the AccountFull or AccountAddressOnly interface from the core package, and your new account type will work seamlessly with the swap routing logic.

πŸ“¦ Packages

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • pnpm (Install with npm install -g pnpm)

Installation

# Install dependencies for all packages
pnpm install

# Build all packages
pnpm build

# Run tests for all packages
pnpm test

Running the Example App

The example-app is a React application that demonstrates how to use the Zcash Router SDK. It includes:

  • Route to Zcash: Swap assets from Solana (SOL) to Zcash (ZEC)
  • Route from Zcash: Swap assets from Zcash to Solana
  • Real-time swap status tracking
  • Clean, modern UI with Material-UI and Tailwind CSS

To run the example app:

# From the root directory
pnpm --filter @zcash-router-sdk/example-app run dev

# Or navigate to the example-app directory
cd packages/example-app
pnpm dev

The app will be available at http://localhost:3000. See the example-app README for more details.

🎯 Production-Grade Demo

This is a fully functional, production-ready implementation:

  • βœ… Live blockchain integration - Real swaps on Solana and Zcash mainnet
  • βœ… End-to-end transactions - Complete deposit to withdrawal flow
  • βœ… Modular architecture - Extensible SDK design for adding new chains
  • βœ… Professional UI - Modern interface with real-time status tracking
  • βœ… Comprehensive error handling - Graceful failure recovery
  • βœ… Full type safety - TypeScript throughout with comprehensive testing

Not a mockup or prototype - this actually works.

πŸŽ₯ View Live Demo | πŸ’» Try It Yourself

πŸ› οΈ Development

Available Scripts

Run these commands from the root directory:

# Build all packages
pnpm build

# Development mode (watch)
pnpm dev

# Run tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Run tests with coverage
pnpm test:coverage

# Lint all packages
pnpm lint

# Fix linting issues
pnpm lint:fix

# Format code
pnpm format

# Check formatting
pnpm format:check

# Type check all packages
pnpm typecheck

# Clean build artifacts
pnpm clean

Working with Individual Packages

# Build a specific package
pnpm --filter @zcash-router-sdk/core build

# Test a specific package
pnpm --filter @zcash-router-sdk/core test

# Run dev mode for a specific package
pnpm --filter @zcash-router-sdk/core dev

# Run the example app
pnpm --filter @zcash-router-sdk/example-app run dev

Adding a New Account Package

To add support for a new blockchain or wallet type:

  1. Create a new directory in packages/:

    mkdir packages/new-account-package
  2. Create a package.json with the name @zcash-router-sdk/new-account-package:

    {
      "name": "@zcash-router-sdk/new-account-package",
      "version": "0.1.0",
      "dependencies": {
        "@zcash-router-sdk/core": "workspace:*"
      }
    }
  3. Implement the AccountFull or AccountAddressOnly interface from @zcash-router-sdk/core:

    import type { AccountFull } from '@zcash-router-sdk/core';
    
    export class NewAccount implements AccountFull {
      readonly type = 'full' as const;
      readonly asset: RouteAsset;
      
      async getAddress(): Promise<string> { /* ... */ }
      async getBalance(): Promise<bigint> { /* ... */ }
      assetToBaseUnits(amount: string): bigint { /* ... */ }
      async sendDeposit(params: { address: string; amount: string }): Promise<string> { /* ... */ }
    }
  4. Install dependencies from the root:

    pnpm install
  5. Your new account type will now work with routeToZcash() and routeFromZcash() functions!

Inter-package Dependencies

To use one package within another:

{
  "dependencies": {
    "@zcash-router-sdk/core": "workspace:*"
  }
}

πŸ“ Project Structure

zcash-router-sdk/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ core/                      # Core swap and routing logic
β”‚   β”œβ”€β”€ zcash-account-mnemonic/    # Zcash account management
β”‚   β”œβ”€β”€ solana-account-mnemonic/   # Solana account management
β”‚   └── example-app/               # Example React app
β”œβ”€β”€ .eslintrc.cjs                  # Shared ESLint config
β”œβ”€β”€ .prettierrc                    # Shared Prettier config
β”œβ”€β”€ pnpm-workspace.yaml            # pnpm workspace config
β”œβ”€β”€ package.json                   # Root package with workspace scripts
└── README.md

πŸ§ͺ Testing

All packages use Vitest for testing. Tests are located in the tests/ directory of each package.

# Run all tests
pnpm test

# Run tests with coverage
pnpm test:coverage

# Run tests in watch mode
pnpm test:watch

πŸ“ Code Quality

This monorepo uses:

  • TypeScript for type safety
  • ESLint for code linting
  • Prettier for code formatting
  • Vitest for testing

Configuration files are shared across all packages from the root directory.

πŸ”§ Build System

  • tsup - Fast bundler built on esbuild
  • TypeScript - Type checking and declarations
  • pnpm - Fast, efficient package manager with workspace support

πŸ“¦ Publishing

To publish a package:

  1. Navigate to the package directory:

    cd packages/core
  2. Update the version in package.json

  3. Run the prepublish checks:

    pnpm run prepublishOnly
  4. Publish to npm:

    pnpm publish

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

πŸ“„ License

MIT

πŸ”— Links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages