Tenor Adapter
The TenorAdapter is a Bundler3 adapter that enables batching multiple Tenor and Morpho V2 operations into a single atomic transaction. It extends CoreAdapter from Morpho's Bundler3 system and provides passthrough functions for rolling positions, managing roll parameters, and executing Morpho V2 operations.
How It Works
1. Bundler3 Integration
The TenorAdapter acts as a bridge between the Bundler3 contract and Tenor's roller contracts:
- Passthrough Functions: All operations go through the adapter rather than calling contracts directly. This ensures the Bundler3's callback mechanism works correctly, as callbacks must come from the same address that was called.
- Authorization: Users only need to authorize the adapter, not the Bundler3 contract, simplifying permission management.
- Atomic Execution: Multiple operations can be batched into a single transaction, ensuring all-or-nothing execution.
2. Rolling Operations
The adapter provides passthrough functions for both roller contracts:
Morpho V2 to V2 Rolling:
morphoV2ToV2RollPosition: Rolls a position to another Morpho V2 termmorphoV2ToV2SetUserParams: Sets roll parameters on behalf of the initiatormorphoV2ToV2ClearUserParams: Clears roll parameters
Morpho V2 to V1 Rolling:
morphoV2ToV1RollPosition: Rolls a position to a Morpho V1 variable-rate marketmorphoV2ToV1SetUserParams: Sets roll parameters on behalf of the initiatormorphoV2ToV1ClearUserParams: Clears roll parameters
3. Morpho V2 Operations
The adapter provides functions for core Morpho V2 operations:
- morphoV2Take: Accept lending offers with optional callbacks
- morphoV2Repay: Repay debt (supports
type(uint256).maxto repay full debt) - morphoV2SupplyCollateral: Add collateral to positions (supports
type(uint256).maxto use adapter's full balance) - morphoV2WithdrawCollateral: Remove collateral (supports
type(uint256).maxto withdraw full balance) - morphoV2Withdraw: Withdraw from obligations (supports
type(uint256).maxto withdraw all shares)
4. Callback Handling
The adapter implements callback interfaces to enable reentering the Bundler3 during operations:
Callback Sources:
onTake: Called by Morpho V2 during offer executiononLiquidate: Called by Morpho V2 during liquidationsonRollPosition: Called by roller contracts during position rolls (two overloaded versions for V2→V2 and V2→V1)
Security:
- All callbacks validate the sender address to ensure they only accept calls from authorized contracts (MORPHOV2, V2_TO_V2_ROLLER, V2_TO_V1_ROLLER)