# Dew Finance - Testnet Deployment This directory contains scripts for deploying Dew Finance contracts (Kernel + Vault) to NEAR testnet. ## Architecture Dew Finance consists of two main contracts: - **Dew Kernel** (`app/kernel/`) - Governance and policy coordination layer - **Dew Vault** (`app/vault/`) - Asset management and share handling The vault's owner must be the kernel contract for proper integration. ## Prerequisites - [near-cli](https://github.com/near/near-cli) installed and logged in - Docker installed (for builds) - Testnet account with NEAR tokens ## Quick Start ### 1. Configure Environment Edit the signer account in both environment files: ```bash # In app/kernel/0_env.sh SIGNER_ID="your-account.testnet" # In app/vault/0_env.sh DEPOSITOR_ID="your-account.testnet" ``` ### 2. Deploy Kernel ```bash cd app/kernel # Generate account ../../utils/generate_kernel_account.sh # Build contract ./1_build.sh # Deploy contract ./2_deploy.sh # Initialize kernel ./3_init.sh ``` ### 3. Deploy Vault ```bash cd ../vault # Generate account ../../utils/generate_vault_account.sh # Build contract ./1_build_vault.sh # Deploy contract ./2_deploy_vault.sh # Initialize vault (automatically links to kernel as owner) ./3_new_with_config.sh ``` ## Step-by-Step Guide ### Kernel Deployment #### 1. Generate Kernel Account ```bash cd scripts/testnet ./utils/generate_kernel_account.sh ``` This creates `neardev/dev-account` containing the kernel contract ID. #### 2. Build Kernel ```bash cd app/kernel ./1_build.sh ``` Uses Docker to build the kernel contract. #### 3. Deploy Kernel ```bash ./2_deploy.sh ``` Deploys kernel contract to the account created in step 1. #### 4. Initialize Kernel ```bash ./3_init.sh ``` Initializes the kernel with: - Base asset: `wrap.testnet` (wNEAR) - Owner role: Automatically granted to signer account ### Vault Deployment #### 1. Generate Vault Account ```bash cd scripts/testnet ./utils/generate_vault_account.sh ``` This creates `neardev/dev-vault-account` containing the vault contract ID. #### 2. Build Vault ```bash cd app/vault ./1_build_vault.sh ``` Uses Docker to build the vault contract. #### 3. Deploy Vault ```bash ./2_deploy_vault.sh ``` Deploys vault contract to the account created in step 1. #### 4. Initialize Vault ```bash ./3_new_with_config.sh ``` Initializes the vault with: - Owner: Kernel contract (from `neardev/dev-account`) - Base asset: `wrap.testnet` - Share token: `dewNear` with 24 decimals - Fee configuration: 2% management, 20% performance - Protocol fee cuts: 20% of both fees ## Configuration Files ### Kernel Config (`configs/kernel_config.json`) ```json { "base_asset": { "FungibleToken": "wrap.testnet" } } ``` Simple configuration for kernel initialization. For production, consider using custom policies and change controls. ### Vault Config (`configs/vault_config.json`) Key fields (placeholder `KERNEL_CONTRACT_ID` is auto-replaced): - `owner_account_id`: Kernel contract (replaced at init time) - `base_asset`: Asset used for vault accounting - `accepted_deposit_assets`: Assets users can deposit - `available_redeem_assets`: Assets users can redeem - `vault_config`: TVL caps, fees, exchange rate settings - `protocol_account`: Account receiving protocol fees - `protocol_config`: Protocol fee cut percentages ## Verification After deployment, verify the integration: ```bash # Check kernel owner near view $(cat neardev/dev-account) get_owner # Check vault owner (should be kernel contract) near view $(cat neardev/dev-vault-account) get_owner_account_id # Verify they match KERNEL=$(cat neardev/dev-account) VAULT_OWNER=$(near view $(cat neardev/dev-vault-account) get_owner_account_id | tail -1) echo "Kernel: $KERNEL" echo "Vault owner: $VAULT_OWNER" ``` ## Troubleshooting ### Account Already Exists Delete the `neardev/dev-account` or `neardev/dev-vault-account` file and regenerate. ### Build Failures Ensure Docker is running and you're in the correct directory. ### Initialization Failures - Check that account has sufficient balance - Verify config JSON is valid - Ensure kernel is deployed before vault ### Wrong Vault Owner If vault owner isn't the kernel contract, check: - `neardev/dev-account` exists and contains kernel ID - `3_new_with_config.sh` runs after kernel deployment - No typos in account IDs ## File Structure ``` scripts/testnet/ ├── app/ │ ├── kernel/ # Kernel deployment scripts │ │ ├── 0_env.sh # Environment configuration │ │ ├── 1_build.sh # Build kernel │ │ ├── 2_deploy.sh # Deploy kernel │ │ ├── 3_init.sh # Initialize kernel │ │ └── 4_derive_address.sh # Chain signatures │ └── vault/ # Vault deployment scripts │ ├── 0_env.sh # Environment configuration │ ├── 1_build_vault.sh # Build vault │ ├── 2_deploy_vault.sh # Deploy vault │ ├── 3_new_with_config.sh # Initialize vault │ ├── 4_read_preview_deposit.sh │ └── 5_deposit.sh ├── configs/ │ ├── kernel_config.json # Kernel initialization config │ └── vault_config.json # Vault initialization config ├── utils/ │ ├── generate_kernel_account.sh │ ├── generate_vault_account.sh │ └── deploy_mock_tokens.sh ├── neardev/ │ ├── dev-account # Kernel contract ID │ └── dev-vault-account # Vault contract ID └── README.md # This file ``` ## Next Steps After deployment: 1. Set exchange rates for accepted assets 2. Grant additional roles (strategist, agent) via kernel proposals 3. Configure vault policies on kernel 4. Test deposits and withdrawals For more information, see the main project documentation in `/CLAUDE.md`.