Skip to content

feat: integrate Anchor program for deposits#30

Merged
aayusha59 merged 1 commit into
mainfrom
anchor-vault
Jan 18, 2026
Merged

feat: integrate Anchor program for deposits#30
aayusha59 merged 1 commit into
mainfrom
anchor-vault

Conversation

@aayusha59
Copy link
Copy Markdown
Owner

@aayusha59 aayusha59 commented Jan 18, 2026

  • Replace direct USDC transfers with proper Anchor program calls
  • Add vault initialization on first deposit
  • Support both TOKEN_PROGRAM_ID and TOKEN_2022_PROGRAM_ID
  • Add error handling for vault initialization
  • Update deposit flow to call program instruction
  • Track deposits in UserDeposit PDA
  • Update VaultState with total deposits

Summary by CodeRabbit

  • New Features

    • Added automatic vault initialization that runs before deposits, ensuring readiness without manual setup.
    • Enhanced support for different token standards through dynamic token program detection.
  • Improvements

    • Refined deposit transaction flow for better reliability and compatibility.

✏️ Tip: You can customize this high-level summary in your review settings.

- Replace direct USDC transfers with proper Anchor program calls
- Add vault initialization on first deposit
- Support both TOKEN_PROGRAM_ID and TOKEN_2022_PROGRAM_ID
- Add error handling for vault initialization
- Update deposit flow to call program instruction
- Track deposits in UserDeposit PDA
- Update VaultState with total deposits
@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
polyield Ready Ready Preview, Comment Jan 18, 2026 4:39pm
v0-skal-ventures-template-hm Building Building Preview, Comment Jan 18, 2026 4:39pm

@aayusha59 aayusha59 merged commit d20e112 into main Jan 18, 2026
2 of 3 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 18, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The changes add a pre-deposit vault initialization check to the deposit hook that automatically initializes the vault if not already initialized, and introduce dynamic SPL Token program detection to automatically select between TOKEN_PROGRAM_ID and TOKEN_2022 based on the USDC mint configuration. Helper functions are exposed for vault addresses and token program resolution.

Changes

Cohort / File(s) Change Summary
Pre-deposit initialization hook
hooks/use-deposit.ts
Adds vault readiness check before deposit that calls isVaultInitialized(), builds and sends initialization transaction via buildInitializeTransaction() if needed, signs with keypair, awaits confirmation, and throws on failure. Includes logging for each initialization step.
Solana deposit module enhancements
lib/solana/deposit.ts
Introduces getTokenProgramForMint() for dynamic token program detection (TOKEN_2022 vs TOKEN_PROGRAM_ID). Refactors encoding functions (getDepositDiscriminator, encodePosition, encodeString, encodeU64) to return number arrays instead of Buffers. Adds new public functions: buildInitializeTransaction(), getVaultAddress(), getVaultStateAddress(), and getTokenProgramForMint(). Updates deposit flow to use dynamically-resolved token program in associated token address resolution and instruction composition.

Sequence Diagram

sequenceDiagram
    participant Hook as Deposit Hook
    participant Conn as Solana Connection
    participant Vault as Vault Program
    participant Tx as Transaction

    Hook->>Conn: isVaultInitialized(connection)
    Conn-->>Hook: false (not initialized)
    
    Hook->>Conn: buildInitializeTransaction(connection, admin)
    Conn->>Conn: getTokenProgramForMint(USDC mint)
    Conn-->>Hook: Initialize Tx (with correct token program)
    
    Hook->>Hook: Sign transaction with keypair
    Hook->>Conn: Send raw transaction
    Conn->>Vault: Process initialization
    Vault-->>Conn: Confirmation
    Conn-->>Hook: tx confirmed
    
    Hook->>Hook: Proceed with deposit flow
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • PR #5: Adds the initial Anchor-backed deposit/vault logic and core helpers that this PR extends with vault pre-initialization checks and dynamic token program selection.

Poem

🐰 A vault needs preparing before coins arrive,
Token programs dance—twenty-two thrives!
Dynamic, eager, with checks held tight,
Initialize, deposit, all working right! ✨

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel vercel Bot temporarily deployed to Preview – v0-skal-ventures-template-hm January 18, 2026 16:39 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant