The on-chain implementation of Hakata Finance's perpetual trading protocol on Solana.
Hakata Perpetuals Core is the backbone of our protocol - a non-custodial decentralized exchange that supports leveraged trading of real-world assets on Solana. It provides the foundation for secure, efficient, and transparent on-chain perpetual futures trading.
Built on solana-labs/perpetuals, Solana's official reference implementation for perpetual futures trading. This strategic decision allows us to leverage battle-tested infrastructure while focusing innovation on RWA-specific challenges.
Why solana-labs/perpetuals:
- Official Solana Labs implementation with extensive testing
- Proven handling of complex perpetual mechanics (funding rates, liquidations, margin)
- Reduces security surface area vs. custom implementation
- Allows rapid iteration on RWA-specific features
Our RWA Extensions:
- Custom oracle integration for traditional market hours
- Enhanced position management for TradFi asset volatility
- Synthetic asset mechanisms for stocks/forex/commodities
- Market hours handling logic for global asset classes
- Non-custodial architecture ensuring asset security
- Leveraged trading with configurable positions
- Asset pools with customizable parameters
- Fully on-chain settlement and liquidation mechanics
- Oracle integration for reliable price data
- Risk management systems to maintain protocol stability
- Solana - High-performance blockchain
- Anchor - Framework for Solana program development
- Rust - Systems programming language
- Pyth - Oracle for real-time price data
packages/core/
├─ programs/ # Solana programs (smart contracts)
│ └─ hakata-perpetuals/ # Main protocol program
│ ├─ src/ # Source code for the program
│ ├─ tests/ # Program-specific tests
│ └─ Cargo.toml # Rust dependencies
├─ cli/ # CLI tools for administration
│ ├─ src/ # TypeScript source for CLI
│ └─ package.json # CLI dependencies
├─ migrations/ # Deployment migrations
├─ ARCHITECTURE.md # Technical architecture documentation
├─ Anchor.toml # Anchor configuration
└─ Cargo.toml # Workspace configuration
For detailed information about our architecture decisions and how we extend solana-labs/perpetuals, see ARCHITECTURE.md.
- Solana CLI tools (v2.1.0 or later)
- Rust (latest stable version)
- Anchor Framework (v0.31.1 or later)
- Node.js (v18 or later)
# Clone the repository if you haven't already
git clone https://github.com/hakata-finance/hakata-perps.git
cd hakata-perps/packages/core
# Install dependencies
npm install# Build the program
anchor build# Run Rust unit tests
cargo test -- --nocapture
# Run integration tests (Typescript)
anchor test
# Run integration tests (Rust)
cargo test-bpf -- --nocapture# Deploy to devnet
anchor deploy --provider.cluster devnet
# Upload IDL
anchor idl init --provider.cluster devnet --filepath ./target/idl/perpetuals.json <PROGRAM_ID>For mainnet deployments, we recommend using a multi-signature authority:
# Deploy to mainnet
anchor deploy --provider.cluster mainnet-beta
# Set up authority with multi-sig
npx ts-node cli/src/cli.ts -k <ADMIN_WALLET> init --min-signatures <NUM> <ADMIN_WALLET1> <ADMIN_WALLET2> ...The protocol can be administrated using the CLI tool:
# Add a new trading pool
npx ts-node cli/src/cli.ts -k <ADMIN_WALLET> add-pool <POOL_NAME>
# Add a token custody to a pool
npx ts-node cli/src/cli.ts -k <ADMIN_WALLET> add-custody <POOL_NAME> <TOKEN_MINT> <TOKEN_ORACLE> -s <IS_STABLE>
# View pools
npx ts-node cli/src/cli.ts -k <ADMIN_WALLET> get-pools
# View custodies in a pool
npx ts-node cli/src/cli.ts -k <ADMIN_WALLET> get-custodies <POOL_NAME>- All protocol upgrades should be carefully reviewed and tested
- For mainnet deployments, use multi-signature authorities
- Regular security audits are recommended
- If you discover a security vulnerability, please report it privately to admin@hakata.fi
We welcome contributions to improve the protocol:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: Implement amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request