OwlLendingAdapter
OwlLendingAdapter is a middleware contract that enables Owl Smart Wallets to access DeFi lending markets autonomously. It orchestrates multi-step borrowing workflows by chaining operations across Morpho (a lending protocol) and the USDL vault, allowing AI agents to supply collateral, borrow USDC, and mint USDL in atomic transactions.
Overview
This adapter simplifies complex DeFi operations into single-transaction workflows, essential for autonomous AI agent operation:
Supply & Borrow Flow: Deposit collateral (WBTC/WETH) → Borrow USDC from Morpho → Deposit USDC to USDL Vault → Receive USDL
Repay & Withdraw Flow: Burn USDL → Withdraw USDC from USDL Vault → Repay Morpho debt → Withdraw collateral
By bundling these steps, the adapter reduces transaction overhead and enables atomic DeFi operations that can be executed by AI agents through MCP tools without requiring multi-step coordination.
Key Features:
Atomic supply-and-borrow operations
Collateral management through Morpho protocol
USDL minting/burning via vault integration
Authorization-based security model
Gas-optimized single-transaction flows
Architecture
The adapter integrates with four core components:
Morpho
Decentralized lending protocol for collateral supply and USDC borrowing
USDC
Intermediate borrowed asset
USDL Vault
ERC-4626 vault that converts USDC deposits into USDL
USDL Token
Final stablecoin minted to the user
Authorization Model: Users must grant authorization to the adapter via morpho.setAuthorization(adapter, true) before the adapter can manage their positions. This follows Morpho's operator pattern for secure delegation.
State Variables
usdc
The USDC token contract address. USDC is borrowed from Morpho and deposited into the USDL vault.
usdl
The USDL stablecoin token contract address. USDL is minted when USDC is deposited to the vault and burned during repayment.
usdlVault
The USDL vault contract implementing ERC-4626. Handles USDC deposits and USDL minting/redemption.
morpho
The Morpho lending protocol contract. Manages collateral supply, borrowing, and debt repayment.
Constructor
Initializes the adapter with protocol addresses. All addresses are immutable after deployment.
Parameters:
_usdc
address
USDC token contract address
_usdl
address
USDL token contract address
_usdlVault
address
USDL ERC-4626 vault address
_morpho
address
Morpho lending protocol address
Core Functions
supplyAndBorrowUSDL
Executes an atomic supply-and-borrow operation: supplies collateral to Morpho, borrows USDC, deposits USDC to the USDL vault, and mints USDL to the caller.
Prerequisites:
Caller must approve the adapter to spend
collateralAmountofcollateralTokenCaller must authorize the adapter in Morpho:
morpho.setAuthorization(adapter, true)Sufficient collateral ratio to support the borrow amount per Morpho market rules
Parameters:
collateralToken
address
Address of the collateral token (e.g., WBTC, WETH)
collateralAmount
uint256
Amount of collateral to supply to Morpho
borrowAmountUSDC
uint256
Amount of USDC to borrow from Morpho (converted to USDL)
marketParams
MarketParams
Morpho market parameters struct defining the lending market
Flow:
Transfer
collateralAmountfrom caller to adapterSupply collateral to Morpho on behalf of caller
Borrow
borrowAmountUSDCUSDC from MorphoDeposit USDC to USDL vault
Transfer minted USDL to caller
Usage Context: AI agents use this function via MCP tools to establish leveraged positions. The atomic nature ensures the agent doesn't hold intermediate USDC state.
repayDebt
Repays USDL debt to Morpho by burning USDL, withdrawing USDC from the vault, and repaying the Morpho loan.
Prerequisites:
Caller must approve the adapter to spend
usdlAmountToRepayUSDL
Parameters:
usdlAmountToRepay
uint256
Amount of USDL to repay (burned and converted to USDC)
marketParams
MarketParams
Morpho market parameters struct for the loan
Flow:
Transfer USDL from caller to adapter
Withdraw USDC from USDL vault (burning USDL)
Repay USDC debt to Morpho on behalf of caller
Post-Conditions: After repayment, the caller can withdraw collateral directly from Morpho using morpho.withdrawCollateral().
repayAndWithdraw
Atomic repayment and collateral withdrawal: repays USDL debt and withdraws collateral in a single transaction.
Prerequisites:
Caller must approve the adapter to spend
usdlAmountToRepayUSDLCaller must authorize the adapter in Morpho:
morpho.setAuthorization(adapter, true)Remaining collateral after withdrawal must satisfy Morpho's collateralization requirements
Parameters:
unused
address
Collateral token address (inferred from marketParams.collateralToken)
usdlAmountToRepay
uint256
Amount of USDL to repay
collateralAmountToWithdraw
uint256
Amount of collateral to withdraw and return to caller
marketParams
MarketParams
Morpho market parameters struct
Flow:
Transfer USDL from caller to adapter
Withdraw USDC from USDL vault
Repay USDC debt to Morpho
Withdraw collateral from Morpho
Transfer collateral to caller
Usage Context: AI agents use this function to atomically exit positions, ensuring collateral is returned in the same transaction as debt repayment. Critical for liquidation avoidance strategies.
Security Considerations
Authorization Model:
Users must explicitly authorize the adapter in Morpho before it can manage their positions
The adapter never holds user funds beyond the transaction scope
All operations are executed on behalf of
msg.sender, maintaining caller accountability
Collateral Safety:
The adapter does not enforce collateralization ratios — these are handled by Morpho
Users must ensure sufficient collateral before borrowing
Withdrawals that would violate collateral requirements will revert at the Morpho level
Access Control:
Inherits from OpenZeppelin
Ownablefor admin functions (if any)Core functions are permissionless — any authorized user can call them
Integration Guide
For AI Agents (MCP Integration)
AI agents interact with the adapter through MCP tools that wrap these functions:
Example: Borrow USDL via MCP
Example: Repay and Withdraw
For Smart Contract Integrators
Setup Authorization:
Direct Contract Call:
MarketParams Reference
The MarketParams struct is defined by Morpho and contains:
loanToken
address
The token being borrowed (USDC)
collateralToken
address
The token used as collateral (WBTC/WETH)
oracle
address
Price oracle for the market
irm
address
Interest rate model address
lltv
uint256
Liquidation Loan-to-Value ratio
These parameters define the specific Morpho lending market being used and must match an existing market configuration.
Last updated