FlowYieldVaults
Smart contracts used in the Flow Yield Vaults platform
Install / Use
/learn @onflow/FlowYieldVaultsREADME
FlowYieldVaults Smart Contracts
FlowYieldVaults is a yield farming platform built on the Flow blockchain using Cadence. The platform enables users to deposit tokens to supported DeFi strategies such as collateralized borrowing via FlowALP's Active Lending Platform. FlowYieldVaults aims to support yield-generating strategies, automatically optimizing returns through DeFi Actions components and auto-balancing mechanisms.
System Architecture
The FlowYieldVaults platform consists of several interconnected components:
Core Contracts
1. FlowYieldVaults.cdc - Main Platform Contract
The main contract that orchestrates the entire yield farming system:
- Strategy Interface: Defines yield-generating strategies that can deposit/withdraw tokens
- StrategyComposer: Creates and manages different strategy implementations
- StrategyFactory: Manages multiple strategy composers and creates strategy instances
- YieldVault Resource: Represents a user's position in a specific strategy
- YieldVaultManager: Manages multiple YieldVault positions for a user account
2. MockStrategies.cdc - Strategy Implementations
Implements specific yield strategies:
- TracerStrategy: A strategy that uses FlowALP lending positions with auto-balancing
- TracerStrategyComposer: Creates TracerStrategy instances with complex DeFi Actions stacking
- StrategyComposerIssuer: Controls access to strategy composer creation
3. FlowYieldVaultsAutoBalancers.cdc - Auto-Balancing System
Manages automated rebalancing of positions:
- Stores AutoBalancer instances in contract storage
- Automatically rebalances positions when they move outside configured thresholds
- Cleans up AutoBalancers when strategies are closed
Token Contracts
YieldToken.cdc & MOET.cdc
Mock FungibleToken implementations representing:
- YieldToken: Receipt tokens for yield-bearing positions
- MOET: FlowALP's synthetic stablecoin
Mock Infrastructure
MockOracle.cdc
- Provides price feeds for testing and demonstrations
- Supports price manipulation for testing scenarios
- Implements DeFiActions.PriceOracle interface
MockSwapper.cdc
- Simulates token swapping functionality
- Uses oracle prices to calculate swap rates
- Manages liquidity connectors for different token pairs
Contract Deployments
Testnet
| Asset Name | Cadence Address | Cadence Contract Name | EVM | |---|---|---|---| | FlowActions | 0xd27920b6384e2a78 | DeFiActions | TBD | | FlowALPv0 | 0xd27920b6384e2a78 | FlowALPv0 | TBD | | FlowYieldVaults | 0xd27920b6384e2a78 | FlowYieldVaults | TBD | | FlowYieldVaultsStrategiesV2 | 0xd27920b6384e2a78 | FlowYieldVaultsStrategiesV2 | TBD | | PMStrategiesV1 | 0xd27920b6384e2a78 | PMStrategiesV1 | TBD | | MOET | 0xd27920b6384e2a78 | MOET | 0x51f5cc5f50afb81e8f23c926080fa38c3024b238 | | USDC | 0xdfc20aee650fcbdf | EVMVMBridgedToken_d431955d55a99ef69beb96ba34718d0f9fbc91b1 | 0xd431955D55a99EF69BEb96BA34718d0f9fBc91b1 | | PYUSD0 | 0xdfc20aee650fcbdf | EVMVMBridgedToken_d7d43ab7b365f0d0789ae83f4385fa710ffdc98f | 0xd7d43ab7b365f0d0789aE83F4385fA710FfdC98F | | wBTC | 0xdfc20aee650fcbdf | EVMVMBridgedToken_208d09d2a6dd176e3e95b3f0de172a7471c5b2d6 | 0x208d09d2a6Dd176e3e95b3F0DE172A7471C5B2d6 | | wETH | 0xdfc20aee650fcbdf | EVMVMBridgedToken_059a77239dafa770977dd9f1e98632c3e4559848 | 0x059A77239daFa770977DD9f1E98632C3E4559848 | | FUSDEV (ERC4626) | 0xdfc20aee650fcbdf | EVMVMBridgedToken_61b44d19486ee492449e83c1201581c754e9e1e1 | 0x61b44D19486EE492449E83C1201581C754e9e1E1 |
Mainnet
| Asset Name | Cadence Address | Cadence Contract Name | EVM | |---|---|---|---| | FlowActions | 0x6d888f175c158410 | DeFiActions | TBD | | FlowALPv0 | 0x6b00ff876c299c61 | FlowALPv0 | TBD | | FlowYieldVaults | 0xb1d63873c3cc9f79 | FlowYieldVaults | TBD | | FlowYieldVaultsStrategiesV2 | 0xb1d63873c3cc9f79 | FlowYieldVaultsStrategiesV2 | TBD | | PMStrategiesV1 | 0xb1d63873c3cc9f79 | PMStrategiesV1 | TBD | | MOET | 0x6b00ff876c299c61 | MOET | 0x213979bB8A9A86966999b3AA797C1fcf3B967ae2 | | USDC | 0x1e4aa0b87d10b141 | EVMVMBridgedToken_f1815bd50389c46847f0bda824ec8da914045d14 | 0xF1815bd50389c46847f0Bda824eC8da914045D14 | | USDF | 0x1e4aa0b87d10b141 | EVMVMBridgedToken_2aabea2058b5ac2d339b163c6ab6f2b6d53aabed | 0x2aabea2058b5ac2d339b163c6ab6f2b6d53aabed | | PYUSD0 | 0x1e4aa0b87d10b141 | EVMVMBridgedToken_99af3eea856556646c98c8b9b2548fe815240750 | 0x99aF3EeA856556646C98c8B9b2548Fe815240750 | | WBTC | 0x1e4aa0b87d10b141 | EVMVMBridgedToken_717dae2baf7656be9a9b01dee31d571a9d4c9579 | 0x717DAE2BaF7656BE9a9B01deE31d571a9d4c9579 | | wETH | 0x1e4aa0b87d10b141 | EVMVMBridgedToken_2f6f07cdcf3588944bf4c42ac74ff24bf56e7590 | 0x2F6F07CDcf3588944Bf4C42aC74ff24bF56e7590 | | FUSDEV (ERC4626) | 0x1e4aa0b87d10b141 | EVMVMBridgedToken_d069d989e2f44b70c65347d1853c0c67e10a9f8d | 0xd069d989e2F44B70c65347d1853C0c67e10a9F8D |
How the System Works
Below is an overview of the initial prototype Tracer Strategy in the broader context of FlowALP and the FlowYieldVaults platform.
1. Strategy Architecture
The TracerStrategy demonstrates the power of DeFi Actions composition:
User Deposit (FLOW) → FlowALP Position → MOET Issuance → Swap to YieldToken → AutoBalancer
↑
YieldToken → Swap to FLOW → Recollateralize Position
2. Auto-Balancing Mechanism
- AutoBalancers monitor the value of deposits vs. current token holdings
- When balance moves outside configured thresholds (±5%), automatic rebalancing occurs
- Excess value flows into position recollateralization
- Insufficient value triggers position adjustments
3. DeFi Actions Integration
The system heavily uses DeFi Actions components:
- Sinks: Accept token deposits
- Sources: Provide token withdrawals
- Swappers: Handle token conversions
- AutoBalancers: Maintain optimal position ratios
User Interactions
Scripts (Read Operations)
Cadence Scripts are written in Cadence and take advantage of Native Data Availability read and format any public data on the blockchain in the way the developer needs it, without relying on pre-existing view functions in the contract.
scripts/flow-yield-vaults/get_yield_vault_ids.cdc
// Returns all YieldVault IDs for a given user address
access(all) fun main(address: Address): [UInt64]?
scripts/tokens/get_balance.cdc
// Get token balance for an account
access(all) fun main(account: Address, vaultPath: StoragePath): UFix64
Transactions (Write Operations)
Cadence Transactions are written in Cadence and allow you to compose several function calls to several contracts within a single user approval.
Setup
// Setup user account for FlowYieldVaults platform
transaction setup()
Creating YieldVaults
// Create a new yield position
transaction create_yield_vault(strategyIdentifier: String, vaultIdentifier: String, amount: UFix64)
Managing Positions
// Deposit additional funds to existing YieldVault
transaction deposit_to_yield_vault(id: UInt64, amount: UFix64)
// Withdraw funds from a YieldVault
transaction withdraw_from_yield_vault(id: UInt64, amount: UFix64)
// Close a YieldVault and withdraw all funds
transaction close_yield_vault(id: UInt64)
Development Environment
Local Setup
The local/setup_emulator.sh script provides emulator configuration for local development and testing.
Flow Configuration
flow.json contains network configurations and contract deployment settings. It is created and managed with the Flow CLI.
Rebalancing and Recollateralizing
The FlowYieldVaults platform implements sophisticated automatic rebalancing and recollateralizing mechanisms to maintain healthy loan positions and optimize yield generation.
Important Distinction: The system has TWO different rebalancing mechanisms:
- AutoBalancer Rebalancing (DFB): Maintains optimal ratio between YieldToken holdings and expected deposit value
- Position Rebalancing (FlowALP): Maintains healthy collateralization ratios for lending positions
These work together but serve different purposes and can trigger independently based on market conditions.
How Auto-Balancing Works
Each TracerStrategy includes an AutoBalancer with configured thresholds:
- Lower Threshold: 0.95 (5% below target)
- Upper Threshold: 1.05 (5% above target)
The AutoBalancer continuously monitors the value ratio between:
- Current YieldToken holdings (actual balance)
- Expected value based on initial deposits (target balance)
Rebalancing Scenarios
1. Overflown AutoBalancer Value (Upper Threshold Exceeded)
When: Current YieldToken value > 105% historical value of deposits Cause: YieldToken price has increased OR position became over-collateralized leading to excess token holdings Action: AutoBalancer deposits excess YieldToken to the rebalanceSink, swapping to FLOW and recollateralizing the FlowALP position.
Automated Flow:
YieldToken (excess) → Swap to FLOW → Deposit to FlowALP Position (recollateralization)
Result:
- Excess value moved from YieldToken holdings back to collateral
- Position health improved through additional collateralization
- Maintained optimal balance betw
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
