Maple Protocol Adapter

The Maple adapter enables the Yieldinator Facet to integrate with Maple Finance's undercollateralized lending protocol, allowing vaults to earn fixed-income yields by providing liquidity to Maple's lending pools.

Overview

Maple Finance is a decentralized corporate credit market that connects institutional borrowers with lenders through a DAO-managed infrastructure. The Maple adapter facilitates deposits into Maple's lending pools, manages liquidity positions, and harvests yield from loan interest payments and MPL rewards.

Implementation Details

Contract: MapleAdapter.sol

The adapter implements the standard YieldinatorAdapter interface with Maple-specific functionality:

contract MapleAdapter is YieldinatorAdapter {
    using SafeERC20 for IERC20;
    
    // Maple contracts
    address public mplToken; // Maple governance token
    address public xMPL; // Staked MPL token
    IMapleStaking public mapleStaking; // MPL staking contract
    
    // Pool configuration
    struct PoolConfig {
        address pool; // Maple pool address
        address poolToken; // Pool token (LP token)
        bool stakeMPL; // Whether to stake MPL rewards
        bool active; // Whether the pool is active
    }
    
    // Mapping from token to pool configuration
    mapping(address => PoolConfig) public tokenToPool;
    
    // Deposited amounts per token
    mapping(address => uint256) public depositedAmount;
    
    // Constructor
    constructor(
        address _admin,
        address _mplToken,
        address _xMPL,
        address _mapleStaking
    ) YieldinatorAdapter("Maple Finance", _admin) {
        require(_mplToken != address(0), "MapleAdapter: MPL token cannot be zero address");
        require(_xMPL != address(0), "MapleAdapter: xMPL token cannot be zero address");
        require(_mapleStaking != address(0), "MapleAdapter: staking contract cannot be zero address");
        
        mplToken = _mplToken;
        xMPL = _xMPL;
        mapleStaking = IMapleStaking(_mapleStaking);
    }
}

Key Functions

Pool Registration

Before using the adapter for a specific token, the pool must be registered:

Deposit

The deposit function handles depositing assets into Maple's lending pools:

Withdraw

The withdraw function handles withdrawing assets from Maple's lending pools:

Harvest Yield

The harvestYield function collects MPL rewards and optionally stakes them:

Emergency Withdraw

The emergencyWithdraw function provides a safety mechanism to withdraw all funds:

APY Calculation

The getCurrentAPY function calculates the current APY for a token in the Maple pool:

Get Total Deposited

The getTotalDeposited function returns the total amount of tokens deposited:

Usage Example

Here's an example of how to use the Maple adapter with the Yieldinator Facet:

Security Considerations

  • Credit Risk: Maple Finance pools involve undercollateralized lending to institutional borrowers, which carries inherent credit risk.

  • Liquidity Risk: Withdrawals from Maple pools are subject to liquidity availability and may be delayed if the pool has insufficient funds.

  • Pool Delegate Risk: Maple pools are managed by Pool Delegates who make lending decisions, introducing potential governance risks.

  • Smart Contract Risk: The adapter interacts with multiple external contracts which may have vulnerabilities.

Risk Mitigation

  • The adapter implements strict access controls to prevent unauthorized access.

  • Emergency withdrawal functionality is available to recover funds in case of critical issues.

  • The adapter validates all inputs and handles edge cases to prevent unexpected behavior.

  • Integration with Maple's risk assessment framework to evaluate borrower creditworthiness.

Gas Optimization

  • The adapter minimizes gas usage by batching operations when possible.

  • For harvesting rewards, users can choose whether to stake MPL rewards based on gas costs and expected returns.

  • The adapter avoids unnecessary approvals by only approving tokens when needed.

Future Improvements

  • Support for Maple's credit default swaps (CDS) to hedge against default risk

  • Integration with Maple's governance system for participating in protocol decisions

  • Support for multiple pool delegates to diversify lending risk

  • Automated reinvestment of interest payments for compounding returns