Overview
This guide covers the complete deployment process for BTCVault smart contracts, from local development to mainnet deployment. The contracts are built using Scarb (Cairo’s package manager) and deployed to StarkNet using thestarkli CLI tool.
Prerequisites
Before deploying contracts, ensure you have the following tools installed:- Scarb 2.14.0: Cairo package manager (installation guide)
- Cairo 2.14.0: Automatically installed with Scarb
- Starkli: StarkNet CLI tool for deployment (installation guide)
- StarkNet wallet: ArgentX or Braavos browser extension
- Funds: ETH on StarkNet for deployment gas fees
Environment Setup
1. Verify Installation
Confirm your development environment is configured correctly:2. Configure StarkNet Account
Export your StarkNet account credentials:If you haven’t created a StarkNet account yet, follow the Starkli account setup guide.
3. Project Structure
The contract source files are organized as follows:Building Contracts
Build Contracts
Compile all contracts to Sierra and CASM bytecode:This generates two files per contract:
- Sierra JSON (
target/dev/btcvault_BTCVault.contract_class.json): High-level intermediate representation - CASM JSON (
target/dev/btcvault_BTCVault.compiled_contract_class.json): Low-level Cairo Assembly
Deployment Process
Deploying a contract to StarkNet is a two-step process:- Declare: Upload the contract class to the network (one-time per class)
- Deploy: Instantiate the contract class with constructor arguments
Declare Contract Class
Upload the contract class to StarkNet and obtain a class hash:Save the class hash—you’ll need it for deployment and upgrades.
If the contract class has already been declared, Starkli will return the existing class hash without submitting a new transaction.
Prepare Constructor Arguments
BTCVault contracts require several constructor parameters. Prepare them as hex-encoded StarkNet addresses:See
src/strategy.cairo for additional mainnet addresses.Deploy Contract Instance
Deploy the contract using the class hash and constructor arguments:Save the contract address—this is your deployed vault instance.
Contract Upgrades
BTCVault contracts are upgradeable using StarkNet’sreplace_class_syscall mechanism. This allows the curator to update contract logic without migrating user funds.
Storage Compatibility: When upgrading contracts, ensure the new version maintains storage layout compatibility. Adding new storage variables at the end is safe, but reordering or removing variables will corrupt state.
Testing on Mainnet
Before deploying user funds, test vault operations on mainnet with small amounts:Deployment Checklist
Before mainnet deployment, verify:- All contract addresses are correct for mainnet (not testnet)
- Curator wallet has sufficient ETH for gas fees
- Contract has been audited by a reputable security firm
- Emergency pause mechanism is functional
- Upgrade mechanism is tested on testnet
- Oracle feeds (Pragma) are active and returning valid prices
- Integration protocols (Vesu, AVNU) are operational
- Minimum deposit thresholds meet Vesu dust requirements
- Flash loan callback security is verified (sender == self)
- Constructor parameters are documented for reproducibility
Common Issues
Error: 'Vault: zero shares' when depositing
Error: 'Vault: zero shares' when depositing
Error: 'Deposit below minimum' during strategy deployment
Error: 'Deposit below minimum' during strategy deployment
Vesu enforces minimum position values (dust thresholds). The minimum is calculated as
(floor * scale) / price + 1. For WBTC, this is typically ~$10-20 worth. Ensure deposits exceed this threshold.Error: 'Only pool can callback' during flash_unwind
Error: 'Only pool can callback' during flash_unwind
The flash loan callback is reverting due to security checks. Verify:
senderinon_flash_loanequals the vault contract addressget_caller_address()in callback equals the Vesu pool address- Pool ID is correctly configured in vault storage
Transaction reverts with 'ERC20: insufficient allowance'
Transaction reverts with 'ERC20: insufficient allowance'
The vault needs approval to spend tokens. Ensure:
- WBTC approval is granted before depositing
- USDC approval is sufficient for debt repayment (with buffer for rounding)
- Vesu pool and singleton addresses are both approved for debt operations
Upgrade fails with 'Caller is not owner'
Upgrade fails with 'Caller is not owner'
Only the current owner can upgrade contracts. Verify:
- You’re using the correct account (matches
get_owner()return value) - Ownership transfer completed if recently transferred
- Account JSON and keystore are correctly configured in environment variables
Next Steps
Smart Contracts Overview
Learn about contract architecture and design patterns
API Reference
Explore detailed contract interfaces and functions