Skip to content

fiamma-chain/bitvm-bridge-contracts-solana

Repository files navigation

BitVM Bridge - Solana Smart Contract

A Solana smart contract for managing BTC cross-chain assets through BitVM protocol.

Overview

The BitVM Bridge smart contract enables:

  • Minting wrapped BTC tokens on Solana
  • Burning tokens for BTC redemption
  • Configurable parameters for pegin/pegout amounts
  • Admin controls for emergency pause and parameter updates

Prerequisites

  • Rust 1.70.0+
  • Solana CLI 1.17.0+
  • Node.js 18.0.0+
  • Anchor Framework 0.30.1+
  • Yarn

Development Setup

  1. Install dependencies
yarn install
  1. Create .env file from template
cp .env.example .env

Update the following values in .env:

SOLANA_PRIVATE_KEY=your_base58_private_key
RPC_URL=https://api.devnet.solana.com
  1. Build the program
anchor build

Testing

Local Testing

  1. Start local validator with required programs
solana-test-validator \
  --clone metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s \
  --clone PwDiXFxQsGra4sFFTT8r1QWRMd4vfumiWC1jfWNfdYT \
  --url https://api.mainnet-beta.solana.com \
  --reset
  1. Run tests
anchor test

Deployment

Local Deployment

anchor deploy

Devnet Deployment

  1. Configure Solana CLI for devnet
solana config set --url devnet
  1. Get devnet SOL
solana airdrop 2
  1. Deploy
anchor deploy

Initialize Contract

After deployment, initialize the contract:

yarn initialize

Program Upgrade

# Build program
anchor build

# Create upgrade buffer
solana program write-buffer ./target/deploy/bitvm_bridge.so

# Deploy upgrade
solana program deploy --buffer <BUFFER_ADDRESS> --program-id <PROGRAM_ID>

Cleanup

Close deploy buffer account:

solana program close --buffers

Deploy to New Address

First generate a new keypair

solana-keygen new -o target/deploy/bitvm_bridge-keypair.json --force

solana-keygen new -o target/deploy/btc_light_client-keypair.json --force

Then update the Anchor.toml file with the new program id

anchor keys sync

Then build the program and deploy the programs

anchor build 
anchor deploy

Contract Parameters

The bridge contract includes configurable parameters:

  • max_btc_per_mint: Maximum BTC amount per mint
  • min_btc_per_mint: Minimum BTC amount per mint
  • max_btc_per_burn: Maximum BTC amount per burn
  • min_btc_per_burn: Minimum BTC amount per burn
  • skip_tx_verification: Enable/disable transaction verification

Project Structure

├── programs/
│   ├── bitvm-bridge/       # Bridge program
│   └── btc-light-client/   # BTC Light Client program
├── tests/                  # Integration tests
├── cli/                    # CLI tools
│   └── src/
│       ├── commands/       # CLI commands
│       └── utils.ts        # Utility functions
└── Anchor.toml            # Project configuration

License

ISC

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published