Skip to content

onflow/FlowALP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

812 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

FlowALP (FlowALPv1) - DeFi Lending Protocol on Flow

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).

πŸ“Š Project Status

  • Contract: βœ… Implemented in Cadence (token-agnostic via FungibleToken.Vault)
  • Tests: βœ… Cadence test suite under cadence/tests/ (*_test.cdc)
  • Coverage: πŸ”Ž Run flow test --cover locally (coverage artifacts are not committed)
  • Documentation: βœ… Complete
  • Standards: βœ… Uses FungibleToken + integrates with DeFiActions
  • FlowVault Removal: βœ… FlowVault is not required by the FlowALPv1 implementation (legacy cadence/contracts/AlpenFlow_dete_original.cdc remains for reference)

🎯 Integration Milestones

Current Status (Tracer Bullet Phase)

  • βœ… 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

Upcoming (Limited Beta)

  • βœ… 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

Future (Open Beta)

  • βœ… Open Access: Full public access to FlowALPv1 and DefiActions
  • πŸ’› Documentation: Improved documentation and tutorials
  • βœ… Sample Code: Complete tutorials for DefiActions integration

🏦 About FlowALP

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.

Key Features

  • Token Agnostic: Supports any FungibleToken.Vault implementation (no FlowVault dependency)
  • 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

Technical Highlights

  • Provides DeFiActions.Sink and DeFiActions.Source for DeFi composability
  • Uses scaled balance tracking with UFix128 interest indices for efficient interest accrual
  • Supports multiple positions per pool with independent tracking
  • Includes a deposit-capacity mechanism for rate limiting and fair throughput

πŸ§ͺ Test Suite

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.cdc

Test Results Summary

The 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

πŸš€ Quick Start

Prerequisites

Installation

  1. Clone the repository:
git clone https://github.com/onflow/FlowALP.git
cd FlowALP
git submodule update --init --recursive
  1. Install dependencies (REQUIRED):
flow deps install
  1. Run tests:
# Recommended: Use the test runner script
./run_tests.sh

# Alternative: Run directly
flow test --cover

Deploy to Emulator

  1. Start the Flow emulator:
flow emulator --start
  1. Deploy the contracts:
flow project deploy --network=emulator

πŸ“¦ Project Structure

FlowALP/
β”œβ”€β”€ 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

πŸ”§ Contract Architecture

Core Components

  1. Pool: Main lending pool managing positions and reserves
  2. Position: User positions tracking deposits and borrows
  3. TokenState: Per-token state including interest indices
  4. FlowALPv1Sink/Source: DeFi Actions integration for composability

Key Interfaces

  • FungibleToken.Vault: Standard token operations
  • DeFiActions.Sink/Source: DeFi protocol composability
  • Entitlements: FlowALPv1.EParticipant, FlowALPv1.EPosition, FlowALPv1.EGovernance, FlowALPv1.ERebalance

πŸ› οΈ Development

Creating a Position

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.cdc and cadence/transactions/flow-alp/beta/claim_and_save_beta_cap.cdc
  • Create a Position (user): cadence/transactions/flow-alp/position/create_position.cdc (uses pushToDrawDownSink to control auto-borrowing)

Running Tests

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

πŸ“š Documentation

Current Documentation

Planning & Roadmap

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the MIT License.

πŸ”— Resources

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 18