BaseHopStrategy

Overview

The BaseHopStrategy contract serves as the foundation for strategies that interact with Hop Protocol in the MaxAPY ecosystem. It handles deposits into Hop pools, managing LP positions, and executing withdrawals for cross-chain liquidity provision.

Errors

error NotEnoughFundsToInvest();            // Insufficient funds for investment
error InvalidZeroAddress();                 // Zero address provided

Events

event Invested(address indexed strategy, uint256 amountInvested);
event Divested(address indexed strategy, uint256 requestedShares, uint256 amountDivested);
event MinSingleTradeUpdated(uint256 minSingleTrade);
event MaxSingleTradeUpdated(uint256 maxSingleTrade);

State Variables

ISwap public hopPool;                // Hop exchange pool contract
ERC20Burnable public hopLPToken;     // Hop LP token contract
uint256 public maxSingleTrade;       // Maximum size for a single trade
uint256 public minSingleTrade;       // Minimum size for a single trade

Functions

Initialization Functions

initialize

Initializes the strategy with Hop Protocol components.

Parameters:

  • _vault: MaxApy vault address

  • _keepers: Array of keeper addresses

  • _strategyName: Name of the strategy

  • _strategist: Strategist address

  • _hopPool: Hop exchange pool address

  • _hopLPToken: Hop LP token address

Configuration Functions

setMinSingleTrade

Sets minimum trade size for the strategy.

Parameters:

  • _minSingleTrade: New minimum trade size

setMaxSingleTrade

Sets maximum trade size for the strategy.

Parameters:

  • _maxSingleTrade: New maximum trade size

View Functions

previewLiquidate

Calculates expected output for a withdrawal.

Parameters:

  • requestedAmount: Amount requested to withdraw

Returns:

  • Expected liquidated amount

previewLiquidateExact

Calculates input needed for desired withdrawal amount.

Parameters:

  • liquidatedAmount: Desired output amount

Returns:

  • Required input amount

maxLiquidate

Returns maximum amount that can be withdrawn after losses.

Returns:

  • Maximum withdrawable amount

maxLiquidateExact

Returns maximum amount that can be withdrawn before losses.

Returns:

  • Maximum withdrawable amount before losses

Core Internal Functions

_prepareReturn

Prepares strategy returns and handles profits/losses.

Parameters:

  • debtOutstanding: Outstanding debt amount

  • minExpectedBalance: Minimum expected balance after operations

Returns:

  • unrealizedProfit: Unrealized profit amount

  • loss: Loss amount

  • debtPayment: Debt payment amount

_adjustPosition

Adjusts strategy position with available capital.

Parameters:

  • minOutputAfterInvestment: Minimum expected output after investment

_invest

Adds liquidity to Hop pool.

Parameters:

  • amount: Amount to invest

  • minOutputAfterInvestment: Minimum expected LP tokens

Returns:

  • Amount of LP tokens received

_divest

Removes liquidity from Hop pool.

Parameters:

  • shares: Amount of LP tokens to withdraw

Returns:

  • Amount of underlying assets received

Internal View Functions

_shareValue

Calculates underlying value of LP tokens.

Parameters:

  • shares: Amount of LP tokens

Returns:

  • Underlying asset value

_sharesForAmount

Calculates LP tokens needed for given amount.

Parameters:

  • amount: Amount of underlying assets

Returns:

  • Required LP tokens

_shareBalance

Returns strategy's Hop LP token balance.

Returns:

  • Current LP token balance

_estimatedTotalAssets

Calculates total assets under management.

Returns:

  • Total assets value

Last updated