Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AutopoolCompounder

Git Source

Inherits: BaseStrategy

A Yearn V3 strategy that compounds Tokemak Autopool rewards

Accepts any Tokemak Autopool ERC4626 vault as the asset, stakes it, and compounds rewards. Deployers should seed the underlying Autopool immediately after deployment to avoid the standard first-depositor inflation risk.

Using private RPCs to call report() is recommended to avoid any frontrunning activities when

depositing rewards back into the autopool.

State Variables

baseAsset

CONSTANTS ///

The base asset of the autopool (e.g., USDC for autoUSD)

IERC20 public immutable baseAsset;

rewarder

The Tokemak AutopoolMainRewarder for staking

IAutopoolMainRewarder public immutable rewarder;

milkman

The Milkman contract for async swaps

IMilkman public immutable milkman;

priceCheckerByToken

STATE VARIABLES ///

Mapping from reward token to its price checker

mapping(address => address) public priceCheckerByToken;

_configuredRewardTokens

Set of configured reward tokens

EnumerableSet.AddressSet private _configuredRewardTokens;

maxPriceDeviationBps

Maximum deviation allowed for price checks (in basis points)

uint256 public maxPriceDeviationBps = 500;

Functions

constructor

CONSTRUCTOR ///

Initialize the strategy

constructor(
    address _autopool,
    address _rewarder,
    address _milkman
)
    payable
    BaseStrategy(_autopool, "AutopoolCompounder");

Parameters

NameTypeDescription
_autopooladdressThe Tokemak Autopool vault to manage
_rewarderaddressThe AutopoolMainRewarder contract
_milkmanaddressThe Milkman contract for swaps

updatePriceChecker

MANAGEMENT FUNCTIONS ///

Update the price checker for a reward token

function updatePriceChecker(address rewardToken, address priceChecker) external onlyManagement;

Parameters

NameTypeDescription
rewardTokenaddressThe reward token address
priceCheckeraddressThe price checker contract address

setMaxPriceDeviation

Set the maximum price deviation for swaps

function setMaxPriceDeviation(uint256 maxDeviationBps_) external onlyManagement;

Parameters

NameTypeDescription
maxDeviationBps_uint256The max deviation in basis points

cancelSwap

KEEPER FUNCTIONS ///

Cancel a stuck swap and recover tokens

Only callable by management to recover stuck swaps

function cancelSwap(
    uint256 amountIn,
    address fromToken,
    address toToken,
    address priceChecker,
    bytes calldata priceCheckerData
)
    external
    onlyKeepers;

Parameters

NameTypeDescription
amountInuint256The amount of tokens in the swap
fromTokenaddressThe token being swapped from
toTokenaddressThe token being swapped to
priceCheckeraddressThe price checker used in the swap
priceCheckerDatabytesThe data passed to the price checker

claimRewardsAndSwap

Claim rewards and initiate swaps via Milkman

Initiates async swaps. In-flight assets don't affect reported share balance.

function claimRewardsAndSwap() external onlyKeepers;

_processRewardToken

Process a single reward token for swapping

function _processRewardToken(address token) internal;

_deployFunds

YEARN V3 STRATEGY HOOKS ///

Deploy funds by staking autopool tokens

function _deployFunds(uint256 amount) internal override;

Parameters

NameTypeDescription
amountuint256The amount to deploy

_freeFunds

Free funds by unstaking autopool tokens

function _freeFunds(uint256 amount) internal override;

Parameters

NameTypeDescription
amountuint256The amount to free

_harvestAndReport

Harvest and report strategy performance

Strategy accounts for autopool shares, not base assets. In-flight Milkman swaps do not affect share

balance. Gains are realized in the next report() after swaps settle.

function _harvestAndReport() internal override returns (uint256);

Returns

NameTypeDescription
<none>uint256The total assets under management (in autopool shares)

_emergencyWithdraw

Emergency withdraw function for shutdown scenarios

Allows management to withdraw staked autopool shares when strategy is shutdown

function _emergencyWithdraw(uint256 _amount) internal override;

Parameters

NameTypeDescription
_amountuint256The amount of autopool shares to withdraw

recoverBaseAssets

Recover base assets stuck in the contract

Can only be called when strategy is shutdown to prevent griefing

function recoverBaseAssets() external onlyManagement;

getConfiguredRewardTokens

VIEW FUNCTIONS ///

Get all configured reward tokens

function getConfiguredRewardTokens() external view returns (address[] memory);

Returns

NameTypeDescription
<none>address[]An array of configured reward token addresses

stakedBalance

Get the total staked balance

function stakedBalance() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256The amount staked in the rewarder

pendingRewards

Get pending rewards

function pendingRewards() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The amount of pending main rewards (TOKE)

Events

PriceCheckerUpdated

EVENTS ///

event PriceCheckerUpdated(address indexed rewardToken, address indexed priceChecker);

MaxPriceDeviationUpdated

event MaxPriceDeviationUpdated(uint256 maxDeviationBps);

Errors

ZeroAddress

ERRORS ///

error ZeroAddress();

InvalidAsset

error InvalidAsset();

CannotSetCheckerForAsset

error CannotSetCheckerForAsset();

InvalidPriceChecker

error InvalidPriceChecker();

InvalidMaxDeviation

error InvalidMaxDeviation();

StrategyNotShutdown

error StrategyNotShutdown();