Vault Lifecycle
This guide walks you through the complete lifecycle of a Flow Yield Vault, from initial setup to closing your position and claiming your accumulated value.
Overview
A YieldVault goes through five main phases:
- Setup - Configure your account for FYV
- Creation - Create a vault with chosen strategy
- Deposit - Add collateral to start yield farming
- Management - Monitor and manage your position
- Closure - Withdraw or liquidate your vault
Phase 1: Account Setup
Before creating your first vault, you need to set up your account with the required resources.
Setup Transaction
_25import FlowYieldVaults from 0xFlowYieldVaults_25import FungibleToken from 0xFungibleToken_25_25transaction {_25 prepare(signer: AuthAccount) {_25 // Check if already set up_25 if signer.borrow<&FlowYieldVaults.YieldVaultManager>(_25 from: FlowYieldVaults.YieldVaultManagerStoragePath_25 ) != nil {_25 return // Already set up_25 }_25_25 // Create YieldVaultManager_25 let manager <- FlowYieldVaults.createYieldVaultManager()_25_25 // Store in account_25 signer.save(<-manager, to: FlowYieldVaults.YieldVaultManagerStoragePath)_25_25 // Create public capability_25 signer.link<&FlowYieldVaults.YieldVaultManager{FlowYieldVaults.YieldVaultManagerPublic}>(_25 FlowYieldVaults.YieldVaultManagerPublicPath,_25 target: FlowYieldVaults.YieldVaultManagerStoragePath_25 )_25 }_25}
What this does: Creates a YieldVaultManager resource in your account, stores it at the designated storage path, and creates a public capability for querying your vaults.
You only need to do this once - the manager persists in your account and can hold multiple vaults.
Phase 2: Vault Creation
Create a new vault with your chosen strategy (TracerStrategy or mUSDCStrategy).
Create Vault Transaction
_25import FlowYieldVaults from 0xFlowYieldVaults_25import FlowToken from 0xFlowToken_25_25transaction(strategyName: String) {_25 prepare(signer: AuthAccount) {_25 // Get your vault manager_25 let manager = signer.borrow<&FlowYieldVaults.YieldVaultManager>(_25 from: FlowYieldVaults.YieldVaultManagerStoragePath_25 ) ?? panic("YieldVaultManager not found")_25_25 // Get strategy factory_25 let factory = FlowYieldVaults.getStrategyFactory()_25_25 // Create strategy instance_25 let strategy <- factory.createStrategy(_25 strategyName: strategyName,_25 collateralType: Type<@FlowToken.Vault>()_25 )_25_25 // Create vault with strategy_25 let vaultID = manager.createVault(strategy: <-strategy)_25_25 log("Created vault #".concat(vaultID.toString()))_25 }_25}
Parameters:
strategyName: "TracerStrategy" or "mUSDCStrategy"
What happens:
- Strategy instance created with configured connectors
- AutoBalancer created and linked to strategy
- ALP Position created (for leveraged strategies)
- Vault registered in SchedulerRegistry
- First rebalance scheduled for T+60 seconds
- Vault ID returned (use this to interact with vault later)
Example:
_10flow transactions send create-vault.cdc "TracerStrategy"_10# Output: Created vault #42
Phase 3: Initial Deposit
Deposit collateral to activate your vault and start yield farming.
Deposit Transaction
_27import FlowYieldVaults from 0xFlowYieldVaults_27import FlowToken from 0xFlowToken_27import FungibleToken from 0xFungibleToken_27_27transaction(vaultID: UInt64, amount: UFix64) {_27 prepare(signer: AuthAccount) {_27 // Get vault manager_27 let manager = signer.borrow<&FlowYieldVaults.YieldVaultManager>(_27 from: FlowYieldVaults.YieldVaultManagerStoragePath_27 ) ?? panic("Manager not found")_27_27 // Get vault_27 let vault = manager.borrowVault(id: vaultID)_27 ?? panic("Vault not found")_27_27 // Withdraw FLOW from account_27 let flowVault = signer.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)_27 ?? panic("Could not borrow FlowToken.Vault")_27_27 let depositVault <- flowVault.withdraw(amount: amount)_27_27 // Deposit to vault_27 vault.deposit(collateralVault: <-depositVault)_27_27 log("Deposited ".concat(amount.toString()).concat(" FLOW to vault #").concat(vaultID.toString()))_27 }_27}
What happens (TracerStrategy example):
_25Your deposit: 1000 FLOW @ $1.00_25_25Step 1: Collateral deposit_25 - Strategy deposits 1000 FLOW to ALP Position_25 - Position calculates: EC = 1000 × $1 × 0.8 = $800_25_25Step 2: Auto-borrowing_25 - Target HF = 1.3_25 - Max borrow = EC / Target HF = 800 / 1.3 = 615.38 MOET_25 - Position borrows 615.38 MOET_25_25Step 3: Swap to yield tokens_25 - SwapConnector converts 615.38 MOET → ~610 YieldToken_25 - Slippage protection ensures minimum output_25_25Step 4: Deposit to yield vault_25 - AutoBalancer deposits 610 YieldToken to ERC4626_25 - Historical value tracked: $610_25 - First rebalance scheduled_25_25Result:_25 - You have leveraged position: $1,000 collateral + $610 yield exposure_25 - Effective leverage: 1.61x_25 - Health factor: 1.30 (safe)_25 - Yield farming begins automatically
Phase 4: Position Management
Once your vault is active, you can monitor its performance and make adjustments.
Monitoring Your Vault
Check vault balance:
_11import FlowYieldVaults from 0xFlowYieldVaults_11_11pub fun main(address: Address, vaultID: UInt64): UFix64 {_11 let managerRef = getAccount(address)_11 .getCapability<&FlowYieldVaults.YieldVaultManager{FlowYieldVaults.YieldVaultManagerPublic}>(_11 FlowYieldVaults.YieldVaultManagerPublicPath_11 )_11 .borrow() ?? panic("Manager not found")_11_11 return managerRef.getVaultBalance(id: vaultID)_11}
Check AutoBalancer ratio:
_15pub fun main(address: Address, vaultID: UInt64): UFix64 {_15 let managerRef = getAccount(address)_15 .getCapability<&FlowYieldVaults.YieldVaultManager{FlowYieldVaults.YieldVaultManagerPublic}>(_15 FlowYieldVaults.YieldVaultManagerPublicPath_15 )_15 .borrow() ?? panic("Manager not found")_15_15 let vault = managerRef.borrowVaultPublic(id: vaultID)_15 let autoBalancer = vault.getAutoBalancer()_15_15 let current = autoBalancer.getCurrentValue()_15 let historical = autoBalancer.getHistoricalValue()_15_15 return current / historical_15}
Check position health (TracerStrategy):
_10pub fun main(address: Address, vaultID: UInt64): UFix64 {_10 // Get vault's ALP position health factor_10 // Returns: 1.30 (safe), < 1.0 (danger)_10}
Additional Deposits
You can add more collateral at any time:
_10// Same as initial deposit transaction_10transaction(vaultID: UInt64, amount: UFix64) {_10 // ... deposit logic_10}
Impact of additional deposits:
- Increases collateral in ALP Position
- Position borrows more MOET to maintain target HF
- Additional MOET swapped to yield tokens
- AutoBalancer tracks new historical baseline
- Leverage ratio maintained
Withdrawals
Withdraw a portion of your vault's value:
_24import FlowYieldVaults from 0xFlowYieldVaults_24import FungibleToken from 0xFungibleToken_24_24transaction(vaultID: UInt64, amount: UFix64) {_24 prepare(signer: AuthAccount) {_24 let manager = signer.borrow<&FlowYieldVaults.YieldVaultManager>(_24 from: FlowYieldVaults.YieldVaultManagerStoragePath_24 ) ?? panic("Manager not found")_24_24 let vault = manager.borrowVault(id: vaultID)_24 ?? panic("Vault not found")_24_24 // Withdraw from vault_24 let withdrawn <- vault.withdraw(amount: amount)_24_24 // Deposit to your account_24 let receiver = signer.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)_24 ?? panic("Could not borrow receiver")_24_24 receiver.deposit(from: <-withdrawn)_24_24 log("Withdrew ".concat(amount.toString()).concat(" FLOW"))_24 }_24}
What happens:
- AutoBalancer withdraws yield tokens from ERC4626
- SwapConnector converts yield tokens → FLOW
- For leveraged positions: may need to repay some debt to maintain health
- FLOW returned to your account
- Historical tracking updated
Force Rebalancing
Manually trigger rebalancing (useful if automated schedule is stuck):
_14transaction(vaultID: UInt64) {_14 prepare(signer: AuthAccount) {_14 let manager = signer.borrow<&FlowYieldVaults.YieldVaultManager>(_14 from: FlowYieldVaults.YieldVaultManagerStoragePath_14 ) ?? panic("Manager not found")_14_14 let vault = manager.borrowVault(id: vaultID)_14 ?? panic("Vault not found")_14_14 vault.forceRebalance()_14_14 log("Manual rebalance triggered for vault #".concat(vaultID.toString()))_14 }_14}
Phase 5: Vault Closure
When you're ready to exit your position, you can liquidate the vault and claim all accumulated value.
Liquidate Vault Transaction
_22import FlowYieldVaults from 0xFlowYieldVaults_22import FungibleToken from 0xFungibleToken_22import FlowToken from 0xFlowToken_22_22transaction(vaultID: UInt64) {_22 prepare(signer: AuthAccount) {_22 let manager = signer.borrow<&FlowYieldVaults.YieldVaultManager>(_22 from: FlowYieldVaults.YieldVaultManagerStoragePath_22 ) ?? panic("Manager not found")_22_22 // Liquidate vault (destroys it and returns all value)_22 let finalValue <- manager.liquidateVault(id: vaultID)_22_22 // Deposit to your account_22 let receiver = signer.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)_22 ?? panic("Could not borrow receiver")_22_22 receiver.deposit(from: <-finalValue)_22_22 log("Liquidated vault #".concat(vaultID.toString()))_22 }_22}
What happens:
- AutoBalancer withdraws all yield tokens from ERC4626
- All yield tokens swapped to collateral (FLOW)
- For leveraged positions:
- All debt repaid to ALP
- Remaining collateral withdrawn
- Vault removed from SchedulerRegistry
- All resources destroyed
- Final value returned to you in FLOW
Example liquidation:
_13Initial deposit: 1000 FLOW_13After 1 year of farming at 10% APY:_13_13Liquidation process:_13 - Withdraw all yield tokens from ERC4626_13 - Yield tokens value: ~$671 (10% growth on $610)_13 - Swap yield tokens → 671 FLOW_13 - Repay debt: 615.38 MOET_13 - After debt: ~55.62 FLOW profit from yield_13 - Withdraw collateral: 1000 FLOW_13 - Total returned: 1000 + 55.62 = 1055.62 FLOW_13_13Your profit: 55.62 FLOW (5.562% return on initial deposit)
Note: Actual returns depend on ERC4626 vault performance, swap slippage, and gas costs.
Complete Lifecycle Example
Let's walk through a full vault lifecycle from start to finish:
Day 1 - Setup and Creation:
_10# Setup account (one-time)_10flow transactions send setup-account.cdc_10_10# Create vault with TracerStrategy_10flow transactions send create-vault.cdc "TracerStrategy"_10# Output: Vault #42 created_10_10# Initial deposit_10flow transactions send deposit.cdc 42 1000.0_10# Deposited 1000 FLOW, now farming with 1.61x leverage
Day 1-365 - Automated Farming:
_10AutoBalancer runs every 60 seconds:_10 - Day 30: Ratio = 102%, no action_10 - Day 60: Ratio = 106%, rebalanced (withdrew 6% excess)_10 - Day 90: Ratio = 104%, no action_10 - Day 120: Ratio = 107%, rebalanced (withdrew 7% excess)_10 ... continues for full year
Day 365 - Closure:
_10# Check final balance_10flow scripts execute get-vault-balance.cdc 0x123... 42_10# Output: 1055.62 FLOW_10_10# Liquidate and withdraw_10flow transactions send liquidate-vault.cdc 42_10# Vault #42 liquidated, 1055.62 FLOW returned
Result: 5.562% annual return through automated leveraged yield farming.
Best Practices
Start Small: Test with a small amount first to understand vault behavior before committing significant capital.
Monitor Regularly: Check your vault's health factor (leveraged positions) and AutoBalancer ratio weekly to ensure healthy performance.
Understand Thresholds: Know when rebalancing triggers (95%-105%). Frequent hits indicate systematic performance.
Plan for Gas: Each rebalance costs gas. Factor this into yield calculations for smaller vaults.
Track Performance: Record deposit amounts and dates to calculate actual returns vs. expectations.
Diversify: Use multiple vaults with different strategies to spread risk across yield sources.
Emergency Withdrawals: Keep some liquid FLOW in your account for emergency deposits if health factor drops unexpectedly.
Troubleshooting
Vault creation fails: Ensure you have set up your account first with the setup transaction, have sufficient FLOW for gas, and hold a beta capability (during closed beta period).
Rebalancing not triggering: Check that vault is registered in SchedulerRegistry, manually trigger with forceRebalance() if needed, and contact support if issue persists.
Health factor dropping (TracerStrategy): Add more collateral via deposit transaction, withdraw some yield to reduce leverage, or monitor collateral price movements.
Cannot withdraw: Ensure vault has sufficient balance, for leveraged positions: check health factor allows withdrawal, and verify no pending rebalances blocking operations.
Next Steps
- Understand leverage: Read Leveraged Farming
- Learn strategies: Explore Strategies
- Master rebalancing: See AutoBalancer
- Cross-chain options: Check Cross-Chain Integration
The vault lifecycle is designed for simplicity: set up once, deposit to start, let AutoBalancer optimize continuously, and liquidate when ready. The system handles all complexity of leveraged borrowing, yield farming, and rebalancing automatically.