# Solana MPC Trading Example

## Perform on-chain trading on Solana using Sodot MPC

This example demonstrates how to integrate a Sodot MPC cluster with Solana for secure, distributed key management in an on-chain DeFi trading context. The project showcases 2-of-3 threshold signing using Ed25519 keys distributed across 3 Vertex servers.

The code and full technical details can be found in the [Github repo](https://github.com/sodot-rs/sodot-solana-demo).

## What This Example Shows

* **Distributed Key Generation**: Create an Ed25519 MPC key split across 3 Vertex servers
* **Threshold Signing**: Sign Solana transactions with only 2 of the 3 servers (high-availability)
* **On-Chain Execution**: Build and submit SOL transfer transactions to Solana devnet
* **Key Persistence**: Store key metadata locally to reuse keys across runs of the example

## Architecture

The example uses a 2-of-3 threshold configuration:

1. **Key Generation Phase**
   * All 3 Vertex servers participate in distributed key generation
   * Each server holds a share of the private key
   * The combined public key is derived and converted to a Solana address

2. **Signing Phase**
   * Only 2 of the 3 servers are needed to sign (threshold = 2)
   * Servers coordinate via a relay room to produce a valid Ed25519 signature
   * The transaction is verified locally before submission to Solana

## API Flow

```
1. POST /create-room           → Create coordination room for MPC operation
2. POST /ed25519/create        → Initialize keygen on each Vertex
3. POST /ed25519/keygen        → Perform distributed key generation
4. POST /ed25519/derive-pubkey → Derive Solana public address
5. POST /ed25519/sign          → MPC signing with threshold parties
```

## Use Cases

This pattern is ideal for:

* **DeFi Trading Bots**: Secure key management for automated trading strategies
* **Institutional Custody**: Distributed signing authority across multiple parties
* **Exchange Infrastructure**: Hot wallet security with threshold controls

## Getting Started

1. Clone the repository and configure your Vertex API keys
2. Run `cargo run` to generate an MPC key and Solana address
3. Fund the address on devnet via the [Solana Faucet](https://faucet.solana.com)
4. Run again to execute a signed SOL transfer

See the [README](https://github.com/sodot-rs/sodot-solana-demo?tab=readme-ov-file#sodot-mpc-solana-example) for detailed setup instructions.
