Naming: FlowALP refers to the protocol. The current Cadence implementation in this repo is the FlowALPv1 contract (plus supporting v1 contracts like FlowALPRebalancerv1, FlowALPRebalancerPaidv1, and FlowALPSupervisorv1).
- Contract: β
Implemented in Cadence (token-agnostic via
FungibleToken.Vault) - Tests: β
Cadence test suite under
cadence/tests/(*_test.cdc) - Coverage: π Run
flow test --coverlocally (coverage artifacts are not committed) - Documentation: β Complete
- Standards: β
Uses
FungibleToken+ integrates withDeFiActions - FlowVault Removal: β
FlowVault is not required by the
FlowALPv1implementation (legacycadence/contracts/AlpenFlow_dete_original.cdcremains for reference)
- β Smart Contract Integration: FlowALPv1 provides sink/source interfaces for token swapping
- β Development & Testing: Automated testing framework for FlowALPv1 and DefiActions
- β
Repository Structure: FlowALPv1 code in this repo; DeFiActions comes from the
FlowActions/submodule - π Test Coverage: Working towards comprehensive test suite
- π AMM Integration: Currently using dummy swapper, real AMM deployment planned
- β Documentation: First pass documentation of FlowALPv1 (this README)
- β Testing: Extensive test suite for FlowALPv1 and DefiActions
- π Sample Code: DefiActions sample code and tutorials needed
- π Advanced Features: Per-user limits and controlled testing capabilities
- β Open Access: Full public access to FlowALPv1 and DefiActions
- π Documentation: Improved documentation and tutorials
- β Sample Code: Complete tutorials for DefiActions integration
FlowALP is a decentralized lending and borrowing protocol built on the Flow blockchain. This repository contains the v1 Cadence implementation deployed as the FlowALPv1 contract. It is token-agnostic (operates over any FungibleToken.Vault) and integrates with DeFi Actions for composability.
- Token Agnostic: Supports any
FungibleToken.Vaultimplementation (noFlowVaultdependency) - DeFi Actions Integration: Composable with other DeFi protocols via Sink/Source interfaces
- Vault Operations: Secure deposit and withdraw functionality
- Position Management: Create and manage lending/borrowing positions
- Interest Mechanics: Compound interest calculations with configurable rates
- Health Monitoring: Real-time position health calculations and overdraft protection
- Access Control: Secure entitlement-based access with proper authorization
- Provides
DeFiActions.SinkandDeFiActions.Sourcefor DeFi composability - Uses scaled balance tracking with
UFix128interest indices for efficient interest accrual - Supports multiple positions per pool with independent tracking
- Includes a deposit-capacity mechanism for rate limiting and fair throughput
The project includes comprehensive tests covering all functionality. IMPORTANT: On a fresh clone, you must install dependencies before running tests.
# First-time setup: Install dependencies
flow deps install
# Run all tests using the test runner script (RECOMMENDED)
./run_tests.sh
# Alternative: Run all tests directly
flow test --cover
# Run specific test file
flow test cadence/tests/position_lifecycle_happy_test.cdcThe suite includes test files under cadence/tests/:
- β Core vault operations and token state management
- β Position lifecycle (creation, deposits, withdrawals, rebalancing)
- β Interest accrual and rate calculations (debit/credit, insurance)
- β Position health constraints and liquidation
- β Governance parameters and access control
- β Stability and insurance collection mechanisms
- β Auto-rebalancing (overcollateralized and undercollateralized)
- β Security tests (type spoofing, recursive withdrawal)
- β Integration tests and platform compatibility
- β Mathematical precision (FlowALPMath, interest curves)
For detailed test running instructions, see TEST_RUNNING_INSTRUCTIONS.md
- Flow CLI installed
- Visual Studio Code with Cadence extension
- Clone the repository:
git clone https://github.com/onflow/FlowALP.git
cd FlowALP
git submodule update --init --recursive- Install dependencies (REQUIRED):
flow deps install- Run tests:
# Recommended: Use the test runner script
./run_tests.sh
# Alternative: Run directly
flow test --cover- Start the Flow emulator:
flow emulator --start- Deploy the contracts:
flow project deploy --network=emulatorFlowALP/
βββ cadence/
β βββ contracts/
β β βββ FlowALPv1.cdc # Main lending protocol contract
β β βββ FlowALPRebalancerv1.cdc # Rebalancer (scheduled/manual)
β β βββ FlowALPRebalancerPaidv1.cdc # Managed rebalancer service
β β βββ FlowALPSupervisorv1.cdc # Supervisor/registry utilities
β β βββ mocks/ # Mock contracts used by tests
β βββ lib/
β β βββ FlowALPMath.cdc # Shared math helpers (UFix128)
β βββ tests/
β β βββ test_helpers.cdc # Shared test utilities
β β βββ position_lifecycle_happy_test.cdc
β β βββ interest_accrual_integration_test.cdc
β β βββ ... # Other test files
β βββ transactions/ # Transaction templates
β βββ scripts/ # Query scripts
βββ FlowActions/
β βββ cadence/contracts/interfaces/
β βββ DeFiActions.cdc # DeFi Actions interface
βββ imports/ # Generated Flow standard contracts (`flow deps install`)
βββ flow.json # Flow configuration
βββ run_tests.sh # Test runner
βββ README.md # This file
- Pool: Main lending pool managing positions and reserves
- Position: User positions tracking deposits and borrows
- TokenState: Per-token state including interest indices
- FlowALPv1Sink/Source: DeFi Actions integration for composability
FungibleToken.Vault: Standard token operationsDeFiActions.Sink/Source: DeFi protocol composability- Entitlements:
FlowALPv1.EParticipant,FlowALPv1.EPosition,FlowALPv1.EGovernance,FlowALPv1.ERebalance
The FlowALPv1 contract uses entitlements and capability-based access. This repo provides transaction templates for common operations:
- Create and store the Pool (admin):
cadence/transactions/flow-alp/pool-factory/create_and_store_pool.cdc - Grant and claim the beta Pool capability (admin/user):
cadence/transactions/flow-alp/beta/publish_beta_cap.cdcandcadence/transactions/flow-alp/beta/claim_and_save_beta_cap.cdc - Create a Position (user):
cadence/transactions/flow-alp/position/create_position.cdc(usespushToDrawDownSinkto control auto-borrowing)
On a fresh clone, always install dependencies first:
# Step 1: Install dependencies (REQUIRED)
flow deps install
# Step 2: Run tests using the test runner script (RECOMMENDED)
./run_tests.sh
# Alternative: Run all tests directly
flow test --cover
# Run specific test file
flow test cadence/tests/interest_accrual_integration_test.cdc
# Run specific test by name
flow test cadence/tests/interest_curve_advanced_test.cdc --name test_exact_compounding_verification_one_year- Test Running Instructions - How to run tests reliably
- Test Coverage Analysis - Test inventory and coverage notes
- TODO and Missing Tests Summary - Outstanding test gaps and follow-ups
- Cadence Testing Best Practices - Testing guidelines
- Future Features - Upcoming development
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.