Naming: FlowALP refers to the protocol. The current Cadence implementation in this repo is the FlowALPv0 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
FlowALPv0implementation (legacycadence/contracts/AlpenFlow_dete_original.cdcremains for reference)
- ✅ Smart Contract Integration: FlowALP provides sink/source interfaces for token swapping
- ✅ Development & Testing: Automated testing framework for FlowALP and DefiActions
- ✅ Repository Structure: FlowALP 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 FlowALP (this README)
- ✅ Testing: Extensive test suite for FlowALP 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 FlowALP 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 current Cadence implementation deployed as the FlowALPv0 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/
│ │ ├── FlowALPv0.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
- FlowALP Sink/Source: DeFi Actions integration for composability
FungibleToken.Vault: Standard token operationsDeFiActions.Sink/Source: DeFi protocol composability- Entitlements:
FlowALPv0.EParticipant,FlowALPv0.EPosition,FlowALPv0.EGovernance,FlowALPv0.ERebalance
The FlowALPv0 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.