This document contains research findings for integrating the NeuroWealth Vault with Blend Protocol's Soroban pool contract for on-chain yield generation.
-
Blend Contracts Repository:
blend-capital/blend-contracts-v2- Contains the Soroban implementation of Blend Protocol v2
- Location: https://github.com/blend-capital/blend-contracts-v2
-
Blend Integration Documentation:
- Official integration guide: https://docs.blend.capital/tech-docs/integrations/integrate-pool
- Covers pool selection, configuration, and integration patterns
-
Blend Lending Pool Documentation:
- Core contract interface: https://docs.blend.capital/tech-docs/core-contracts/lending-pool
- Function signatures and usage patterns
-
Blend Utils Repository:
blend-capital/blend-utils- Deployment and utility scripts
- Testnet deployment addresses
Based on typical lending pool patterns and Blend documentation, the following functions are expected:
pub fn supply(
env: Env,
asset: Address,
amount: i128,
to: Address
) -> i128- Supplies assets to the Blend pool
- Returns the amount of pool tokens received
toparameter specifies who receives the pool tokens (vault address)
pub fn withdraw(
env: Env,
asset: Address,
amount: i128,
to: Address
) -> i128- Withdraws assets from the Blend pool
- Returns the amount of assets actually withdrawn
toparameter specifies where withdrawn assets are sent (vault address)
pub fn get_reserve_data(
env: Env,
asset: Address
) -> ReserveData- Returns reserve data including:
- Current balance
- Interest rate
- Liquidity index
- Other reserve metrics
pub fn get_user_account_data(
env: Env,
user: Address,
asset: Address
) -> i128- Returns the user's supplied balance for a specific asset
- Alternative function names may be used (e.g.,
get_balance,get_supply_balance)
The implementation uses Soroban's env.invoke_contract() method for cross-contract calls:
env.invoke_contract::<ReturnType>(
&pool_address,
&function_name,
&arguments_vec
)Before supplying to Blend, the vault must:
- Approve the Blend pool to spend USDC from the vault
- Call Blend's
supply()function - Blend handles the token transfer internally via the approval
To prevent permanent fund lockup:
- Blend call failures are handled gracefully
- If a supply/withdraw fails, the transaction continues where possible
- State is updated atomically to prevent inconsistencies
- Withdrawals check vault balance and pull from Blend if needed
- Function Names: Confirm the exact function names (may be
deposit/redeeminstead ofsupply/withdraw) - Parameter Order: Verify parameter order matches Blend's interface
- Return Types: Confirm return types (may return structs instead of i128)
- Token Transfer Pattern: Verify if Blend requires pre-approval or handles transfers differently
- Error Handling: Understand how Blend handles errors (panics vs. return values)
Testnet deployment addresses should be obtained from:
- Blend's official documentation
blend-utilsrepository deployment scripts- Blend team communication channels
Blend supports both direct pool integration and intermediate contracts (fee vaults). For the NeuroWealth Vault:
- Decision: Direct pool integration (simpler, lower gas costs)
- Rationale: Vault doesn't need fee sharing features initially
- Future Consideration: May migrate to intermediate contract if fee sharing becomes desirable
The vault tracks the current protocol using DataKey::CurrentProtocol:
"none": Funds not deployed"blend": Funds deployed to Blend- Future: Additional protocols can be added
Expected gas costs for operations:
supply_to_blend(): ~50,000-100,000 operations (approval + supply call)withdraw_from_blend(): ~30,000-70,000 operations (withdraw call)rebalance(): ~80,000-150,000 operations (withdraw + supply if switching)withdraw()with Blend pull: ~100,000-200,000 operations (withdraw from Blend + transfer)
Note: Actual gas costs should be measured on testnet and documented in integration tests.
- Reentrancy: Blend calls are made after state updates (CEI pattern)
- Fund Lockup Prevention: Errors in Blend calls don't prevent withdrawals
- Balance Verification: Vault verifies it has sufficient balance before user transfers
- Approval Limits: Token approvals are set with reasonable expiration times
- Unit Tests: Mock Blend pool contract for basic functionality
- Integration Tests: Test against Blend testnet deployment
- Failure Scenarios: Test Blend call failures, insufficient balance, etc.
- Gas Measurement: Document actual gas costs for all operations
- ✅ Research Blend interface (this document)
- ✅ Implement storage keys and configuration
- ✅ Implement Blend client interface
- ✅ Update rebalance() and withdraw() functions
- ⏳ Verify function signatures against actual Blend contract
- ⏳ Write integration tests against testnet
- ⏳ Document actual gas costs
- ⏳ Security review of cross-contract call patterns
- Blend GitHub: https://github.com/blend-capital
- Blend Documentation: https://docs.blend.capital
- Soroban SDK Documentation: https://soroban.stellar.org/docs
- Stellar Testnet: https://developers.stellar.org/docs/encyclopedia/testnet