LLM Notice: This documentation site supports content negotiation for AI agents. Request any page with Accept: text/markdown or Accept: text/plain header to receive Markdown instead of HTML. Alternatively, append ?format=md to any URL. All markdown files are available at /md/ prefix paths. For all content in one file, visit /llms-full.txt
Skip to main content

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:

  1. Setup - Configure your account for FYV
  2. Creation - Create a vault with chosen strategy
  3. Deposit - Add collateral to start yield farming
  4. Management - Monitor and manage your position
  5. 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


_25
import FlowYieldVaults from 0xFlowYieldVaults
_25
import FungibleToken from 0xFungibleToken
_25
_25
transaction {
_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


_25
import FlowYieldVaults from 0xFlowYieldVaults
_25
import FlowToken from 0xFlowToken
_25
_25
transaction(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:

  1. Strategy instance created with configured connectors
  2. AutoBalancer created and linked to strategy
  3. ALP Position created (for leveraged strategies)
  4. Vault registered in SchedulerRegistry
  5. First rebalance scheduled for T+60 seconds
  6. Vault ID returned (use this to interact with vault later)

Example:


_10
flow 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


_27
import FlowYieldVaults from 0xFlowYieldVaults
_27
import FlowToken from 0xFlowToken
_27
import FungibleToken from 0xFungibleToken
_27
_27
transaction(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):


_25
Your deposit: 1000 FLOW @ $1.00
_25
_25
Step 1: Collateral deposit
_25
- Strategy deposits 1000 FLOW to ALP Position
_25
- Position calculates: EC = 1000 × $1 × 0.8 = $800
_25
_25
Step 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
_25
Step 3: Swap to yield tokens
_25
- SwapConnector converts 615.38 MOET → ~610 YieldToken
_25
- Slippage protection ensures minimum output
_25
_25
Step 4: Deposit to yield vault
_25
- AutoBalancer deposits 610 YieldToken to ERC4626
_25
- Historical value tracked: $610
_25
- First rebalance scheduled
_25
_25
Result:
_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:


_11
import FlowYieldVaults from 0xFlowYieldVaults
_11
_11
pub 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:


_15
pub 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):


_10
pub 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
_10
transaction(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:


_24
import FlowYieldVaults from 0xFlowYieldVaults
_24
import FungibleToken from 0xFungibleToken
_24
_24
transaction(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:

  1. AutoBalancer withdraws yield tokens from ERC4626
  2. SwapConnector converts yield tokens → FLOW
  3. For leveraged positions: may need to repay some debt to maintain health
  4. FLOW returned to your account
  5. Historical tracking updated

Force Rebalancing

Manually trigger rebalancing (useful if automated schedule is stuck):


_14
transaction(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


_22
import FlowYieldVaults from 0xFlowYieldVaults
_22
import FungibleToken from 0xFungibleToken
_22
import FlowToken from 0xFlowToken
_22
_22
transaction(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:

  1. AutoBalancer withdraws all yield tokens from ERC4626
  2. All yield tokens swapped to collateral (FLOW)
  3. For leveraged positions:
    • All debt repaid to ALP
    • Remaining collateral withdrawn
  4. Vault removed from SchedulerRegistry
  5. All resources destroyed
  6. Final value returned to you in FLOW

Example liquidation:


_13
Initial deposit: 1000 FLOW
_13
After 1 year of farming at 10% APY:
_13
_13
Liquidation 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
_13
Your 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)
_10
flow transactions send setup-account.cdc
_10
_10
# Create vault with TracerStrategy
_10
flow transactions send create-vault.cdc "TracerStrategy"
_10
# Output: Vault #42 created
_10
_10
# Initial deposit
_10
flow transactions send deposit.cdc 42 1000.0
_10
# Deposited 1000 FLOW, now farming with 1.61x leverage

Day 1-365 - Automated Farming:


_10
AutoBalancer 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
_10
flow scripts execute get-vault-balance.cdc 0x123... 42
_10
# Output: 1055.62 FLOW
_10
_10
# Liquidate and withdraw
_10
flow 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


Key Takeaway

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.