Skip to main content

MYTStrategy

Description​

The Alchemix V3 protocol introduces a modular system for yield generation centered around Morpho V2 Vaults. The core of this system is a set of strategies that function as adapters for the Morpho Vault, managing user-deposited assets such as WETH and USDC. These strategies are designed to allocate capital across a diverse range of third-party, yield-bearing DeFi protocols. Users deposit their assets into the Morpho Vault and receive Meta Yield Tokens (MYT), which represent a share of the vault’s underlying assets. The value of an MYT share is designed to increase over time as the strategies accrue yield. The allocation of capital is managed by an Alchemix admin or operator via the AlchemistAllocator contract to optimize returns and manage risk.

This MYTStrategy contract is the base contract from which all individual strategy adapters are derived. Each adapter defines one of the many strategies used by the same MYT. This base contract defines the functions that allow allocation and deallocation into the strategy, in addition to claiming and withdrawing, and other general operations on the strategy. For more specific operations tailored to individual strategies, see the contract specs in /strategies section of the docs. (coming soon)

Variables​

StrategyParams​

A struct defining common properties between MYT strategies that must be set on initialization of the strategy contract. Params can be read by calling the params() function, which will return a tuple containing the value for each in the order they are listed below.

owner
  • Description - The owner of this MYT contract instance.
  • Type - address
  • Used By - none. Set once on contract deployment. NOTE: the param that is used to set this on deployment is also used to set the owner of the contract, which is used to restrict access to certain functions. This property param.owner shares that value, but not it's function.
  • Updated By - none. Set once on contract deployment.
name
  • Description - The name of the MYT strategy
  • Type - string
  • Used By - none. This is just informative metadata
  • Updated By - none. Set once on contract deployment.
protocol
  • Description - The name of the protocol running the underlying strategy.
  • Type - string
  • Used By - none. This is just informative metadata
  • Updated By - none. Set once on contract deployment.
riskClass
  • Description - The risk classification for the underlying strategy. Used
  • Type - RiskClass (an enum with possible values of LOW, MEDIUM, or HIGH)
  • Used By - none. This is informative metadata.
  • Updated By
    • setRiskClass(RiskClass newClass)
  • Notified By
cap
  • Description - TODO unused
  • Type - uint256
  • Used By - none. TODO
  • Updated By - none TODO
  • Read By
    • getCap()
globalCap
  • Description - TODO unused
  • Type - uint256
  • Used By - none. TODO
  • Updated By - none TODO
  • Read By
estimatedYield
  • Description - The estimated yield of the strategy. TODO what is this denominated in?
  • Type - uint256
  • Used By - none. This is informative metadata.
  • Updated By - none. This is informative metatdata. TODO - confirm
  • Read By
additionalIncentives
  • Description - A true/false value indicating whether or not there are additional incentives on top of the base functioning of the strategy
  • Type - bool
  • Used By
  • Updated By
    • setAdditionalIncentives(bool newValue)

Public State​

State that is available and can be read from outside of the contract.

Constants​

SECONDS_PER_YEAR
  • Description - Set to 365 days. Used in yield calculations.
  • Type - uint256
  • Used By
  • Updated By - none. Contant variable
  • Read By
    • SECONDS_PER_YEAR() - will return a uint256 value representing seconds
FIXED_POINT_SCALAR
  • Description - A multiplier that is used to be able to do fixed point math, since solidity does not natively handle decimals. Like ERC20 tokens which typically use 18 decimals, it expresses 1 as 1e18. Anything less is a fraction of 1.
  • Type - uint256
  • Used By
  • Updated By - none. Constant varible.
  • Read By
    • FIXED_POINT_SCALAR()
MIN_SNAPSHOT_INTERVAL
  • Description - A value in seconds set to 1 day.
  • Type - uint256
  • Used By
  • Updated By - none. Constant varible.
  • Read By
    • MIN_SNAPSHOT_INTERVAL() - returns a uint representing seconds

Immutable State​

State that is set once on contract deployment

MYT
  • Description - A Morpho VaultV2 contract which manages and allocates to individual strategies through adapters such as this one.
  • Type - IVault2
  • Used By
  • Updated By - none
  • Read By
    • MYT() - will return the address of the Vault2 contract, since MYT is a contract type.
receiptToken
adapterId

Updateable State​

params
  • Description - The list of params passed at deployment-time describing the strategy. Some can be edited. For more information see the StrategyParams type above.
  • Type - StrategyParams
  • Used By
  • Updated By
    • setRiskClass()
    • setAdditionalIncentives()
  • Read By
    • params() - returns a tuple containing all StrategyParam property values in the order listed in the Struct definition above.
lastSnapshotTime
  • Description - The last time the snapshotYield() function was successfully run.
  • Type - uint256
  • Used By
  • Updated By
  • Read By
    • lastSnapshotTime()
lastIndex
  • Description - The last recorded price-per-share of the underlying strategy. Each time snapshotYield() is called, the strategy implementation (derivation of this base contract) _computeBaseRatePerSecond() is called which calculates the base yield rate, in addition to getting the new price-per-share value for the strategy. That is then recorded as the lastIndex. This value is used to help calculate total yield earned since that last snapshot.
  • Type - uint256
  • Used By
  • Updated By
  • Read By
    • lastIndex()
estApr
  • Description - The last recorded estimated non-compounding APR of the underlying strategy. Scaled by 1e18. (1e18 = 100%, 5e17 = 50%, etc.)
  • Type - uint256
  • Used By
  • Updated By
  • Read By
    • estApr()
estApy
  • Description - The last recorded estimated compounding APY for the underlying strategy. Scaled by 1e18. (1e18 = 100%, 5e17 = 50%, etc.)
  • Type - uint256
  • Used By
  • Updated By
  • Read By
    • estApy()
killswitch
  • Description - A true/false toggle that freezes all fund-moving actions. Vault allocate/deallocate simply exit with no operations done, and operator-initiated moves revert. Nothing is auto-unstaked or withdrawn. It’s a circuit breaker, not an unwinder.
  • Type - bool
  • Used By
  • Updated By
    • setKillswitch(bool value)
  • Read By
    • killswitch()
whitelistedAllocators
  • Description - A mapping of addresses which are allowed to call functions that move funds.
  • Type - mapping(address => bool)
  • Used By
  • Updated By
    • setWhitelistedAllocator(address to, bool val)
  • Read By
    • whitelistedAllocators(address) - returns a true/false value indicating whether or not the address passed is a whitelisted allocator
permit2Address
  • Description - The address of the Permit2 router contract to be used. Permit2 is a universal approval and transfer router that standardizes those processes through one contract.
    Instead of granting separate approvals to each DEX or contract, the strategy grants a single allowance to Permit2, which then validates signed off-chain transfer authorizations.
  • Type - address
  • Used By
  • Updated By
  • Read By
    • permit2Address()

Functions​

User Actions​

Actions that are performed by any external callers. In some cases this may be necessitate elevated permissions or restrict user access, but these are one-offs rather than patterns of actors decsribed by traditional only_ modifiers.

deallocateDex(bytes calldata quote, bool prevSettler)
  • Description - Executes a deallocation through the 0x DEX Settler contract, allowing whitelistedAllocators to move or sell assets directly from the strategy. This bypasses standard withdrawal queue logic and is typically used in emergency or rebalancing scenarios.
    • @param quote - ABI-encoded calldata for a verified 0x swap quote, representing the DEX trade to perform.
    • @param prevSettler - Boolean flag indicating whether to use the previous Settler contract (true) or the current one (false).
  • Visibility Specifier - external
  • State Mutability Specifier - nonpayable
  • Returns - uint256 ret - The amount of receipt tokens deallocated through the DEX trade. (the amount that balance of receipt tokens has increase by)
  • Emits
  • Reverts
    • With "emergency" if killswitch == true
    • With "PD" if msg.sender is not an active whitelistedAllocator
    • With "SF" if the Settler call fails
    • If the 0x swap parameters or slippage creates an invalid swap quote
claimWithdrawalQueue(uint256 positionId)
  • Description - Handles claiming withdrawals from strategies that implement a withdrawal queue system.

    First checks that the caller is a whitelistedAllocator and that the strategy is not in emergency mode, then delegates to the internal function _claimWithdrawalQueue() which is overrideen and defined in derived strategy implementations.
    • @param positionId - The ID of the position to claim for from the underlying protocol.
  • Visibility Specifier - public
  • State Mutability Specifier - nonpayable
  • Returns - uint256 ret - The amount of assets claimed from the withdrawal queue (returned by the strategy-specific implementation).
  • Emits - none
  • Reverts
    • With "PD" if msg.sender is not whitelisted
    • With "emergency" if killSwitch == true
claimRewards()
  • Description - Claims any pending reward tokens from the underlying strategy’s protocol

    First verifies that the strategy is not in emergency mode then delegates to the internal _claimRewards() implementation, which must be overrideen in derived contracts to define protocol-specific claiming logic.
  • Visibility Specifier - public
  • State Mutability Specifier - nonpayable
  • Returns - uint256 - The amount of reward tokens claimed, as defined by the derived implementation.
  • Emits - none
  • Reverts
    • With "emergency" if killSwitch == true
snapshotYield()
  • Description - Recomputes the strategies estimated rates for base yield and incentives yield and returns an aggregate estimated apy scaled by 1e18. (1e18 = 100%)

    First ensures that the MINIMUM_SNAPSHOT_INTERVAL has passed since the last call to prevent griefing, then calls internal functions _computeBaseRatePerSecond() and _computeRewardsRatePerSecond(), both of which are implemented in derived contracts, to calculate the most up-to-date current rates. Then those rates are combined and projected out a year. A smoothign rate of .7 is then applied, and passed with the newly calculated rates to the internal _lerp() function to calculate estimated rates from the new snapshot and the previously snaphshotted rate.
  • Visibility Specifier - public
  • State Mutability Specifier - nonpayable
  • Returns - uint256 estApy
  • Emits
  • Reverts - none

Owner Actions​

Actions guarded by the onlyOwner modifier, which restricts access to the owner set at deployment time

setPermit2Address(address newAddress)
  • Description - Updates the permit2Address used for token transfer approvals through the Permit2 router contract.

    First revokes existing token approvals from the old Permit2 address, grants maximum allowance to the new Permit2 address for the MYT receiptToken, and then updates the stored permit2Address value.
    • @param newAddress - the new Permit2 router contract address
  • Visibility Specifier - public
  • State Mutability Specifier - nonpayable
  • Emits - none
  • Reverts
    • With "Zero address" if newAddress is the zero address
setRiskClass(RiskClass newClass)
  • Description - Updates the params.riskClass to recategorize the strategy under a new risk class
    • @param newClass - new risk category for the strategy (LOW, MEDIUM, HIGH)
  • Visibility Specifier - public
  • State Mutability Specifier - nonpayable
  • Emits
  • Reverts - none
setAdditionalIncentives(bool newValue)
  • Description - Enables or disables tracking of additional incentive tokens earned by the strategy in yield calculations.
    • @param newValue - true or false value to enable or disable
  • Visibility Specifier - public
  • State Mutability Specifier - nonpayable
  • Emits
  • Reverts - none
setWhitelistedAllocator(address to, bool val)
  • Description - Sets or unsets an address as a whitelisted allocator authorized to call various functions listed under UserActions
    • @param to β€” address to set or unset as a whitelisted allocator
    • @param val β€” true or false value to set or unset as a whitelisted alloactor
  • Visibility Specifier - public
  • State Mutability Specifier - nonpayable
  • Emits - none
  • Reverts
    • if to is the zero address
setKillSwitch(bool val)
  • Description - Toggles the emergency stop (killSwitch) for this strategy. When enabled many operations such as allocations, deallocations, and reward claims are halted to prevent further activity.
    • @param val - true to activate emergency mode, false to resume normal operation
  • Visibility Specifier - public
  • State Mutability Specifier - nonpayable
  • Modifiers - onlyOwner
  • Emits
  • Reverts - none

Vault Actions​

Functions guarded by the onlyVault modifier, which restricts access to the vault managed by the MYT contract (Referenced by the MYT variable, not referring to this MYTStrategyContract)

allocate(bytes memory data, uint256 assets, bytes4 selector, address sender)
  • Description - Allocates assets from the vault into the underlying strategy, computes the delta between the new allocation and previous allocation, and reports the change.

    Assets are allocated using an internal call to _allocate() which is overrideen and defined in derived strategy contract implementations. If killSwitch is enabled, the simply exits with a change of 0.
    • @param data - a bytes-encoded representation of the old (current) allocation. Later decoded into an uint256.
    • @param assets - the amount of tokens the vault is requesting to allocated to the strategy.
    • @param selector - TODO unused and not intherited. Do we need?
    • @param sender - TODO unused and not inherited. Do we need?
  • Visibility Specifier - external
  • State Mutability Specifier - nonpayable
  • Returns - (bytes32[] memory strategyIds, int256 change) - A tuple where the first value is an array of size 1 containing the adapterId, and the second value is a signed 256 bit integer containing the difference between the new allocation and the old allocation
  • Emits
  • Reverts - none
deallocate(bytes memory data, uint256 assets, bytes4 selector, address sender)
  • Description - Deallocates assets from the underlying strategy back to the vault, computes the delta between the new allocation and previous allocation, and reports the change.

    Assets are withdrawn using an internal call to _deallocate() which is overridden and defined in derived strategy contract implementations. If killSwitch is enabled, the function exits early with a change of 0.
    • @param data - a bytes-encoded representation of the old (current) allocation. Later decoded into an uint256.
    • @param assets - the amount of tokens the vault is requesting to deallocate from the strategy.
    • @param selector - TODO unused and not inherited. Do we need?
    • @param sender - TODO unused and not inherited. Do we need?
  • Visibility Specifier - external
  • State Mutability Specifier - nonpayable
  • Returns - (bytes32[] memory strategyIds, int256 change) - A tuple where the first value is an array of size 1 containing the adapterId, and the second value is a signed 256 bit integer containing the difference between the new allocation and the old allocation
  • Emits
  • Reverts - none

Internal Operations​

_allocate(uint256 amount)
  • Description - An empty virtual function defining internal logic for how to allocate to a strategy. Must be overridden by derived contracts.
    • @param amount - The amount of assets to allocate into the underlying protocol.
  • Visibility Specifier - internal
  • State Mutability Specifier - nonpayable
  • Returns - uint256 depositReturn - The amount of assets successfully allocated by the protocol.
  • Emits - none
  • Reverts - implementation-dependent
_deallocate(uint256 amount)
  • Description - An empty virtual function defining internal logic for how to deallocate from a strategy. Must be overridden by derived contracts.
    • @param amount - The amount of assets to deallocate or withdraw from the underlying protocol.
  • Visibility Specifier - internal
  • State Mutability Specifier - nonpayable
  • Returns - uint256 withdrawReturn - The amount of assets successfully withdrawn from the protocol.
  • Emits - none
  • Reverts - implmentation-dependent
_claimWithdrawalQueue(uint256 positionId)
  • Description - An empty virtual function defining internal logic for how to claim or withdraw from strategies that utilize a withdrawal queue. Must be overridden by derived contracts.
    • @param positionId - The ID of position to claim or withdraw for from the underlying protocol.
  • Visibility Specifier - internal
  • State Mutability Specifier - nonpayable
  • Returns - uint256 claimAmount - The amount of assets successfully claimed from the withdrawal queue.
  • Emits - none
  • Reverts - implementation-dependent
_claimRewards()
  • Description - An empty virtual function defining internal logic for how to claim from a strategy. Must be overridden by derived contracts.
  • Visibility Specifier - internal
  • State Mutability Specifier - nonpayable
  • Returns - uint256 rewardAmount - The amount of reward tokens claimed from the protocol.
  • Emits - none
  • Reverts - implementation-dependent
_computeBaseRatePerSecond()
  • Description - An empty virtual function defining internal logic for how to compute base per-second yield rate from the underlying protocol. Must be overridden by derived contracts.
  • Visibility Specifier - internal
  • State Mutability Specifier - nonpayable
  • Returns - (uint256 ratePerSec, uint256 newIndex) - a tupe where:
    • The first value ratePerSec is the rate of yield per second scaled to 1e18. (1e18 = 100% per second, 1e16 = 1% per second, etc.)
    • The second value newIndex is the most up-to-date price-per-share value of the MYT shares
  • Emits - none
  • Reverts - implementation-dependent
_computeRewardsRatePerSecond()
  • Description - An empty virtual function defining internal logic for how to compute incentive/reward per-second yield rate from the underlying protocol. Must be overridden by derived contracts.
  • Visibility Specifier - internal
  • State Mutability Specifier - nonpayable
  • Returns - uint256 ratePerSec - the rate of yield per second scaled to 1e18. (1e18 = 100% per second, 1e16 = 1% per second, etc.)
  • Emits - none
  • Reverts - implementation-dependent
_approxAPY(uint256 ratePerSecWad)
  • Description - Approximates the APY from a given per-second WAD-scaled (1e18) rate.


    First multiplies the per-second rate by the number of seconds in a year to estimate APR. Then approxiamtes compounding using a formula of APR^2 / (2 Γ— SECONDS_PER_YEAR)
    • @param ratePerSecWad β€” per-second yield rate (1e18 = 100% per second)
  • Visibility Specifier - internal
  • State Mutability Specifier - pure
  • Returns - uint256 approxApyPercentage - a percentage scaled by 1e18 (1e18 = 100% per year)
  • Emits - none
  • Reverts - none
_lerp(uint256 oldVal, uint256 newVal, uint256 alpha)
  • Description - A smoothing function to blend oldVal and newVal using a weighted average, in order to calculate a new yield rate without sharp differences.

    Uses a factor alpha to determine how much of the previous value to retain vs. how much of the new value to apply. This is currently set to 70% (7e17) in snapshotYield(), the only caller of this function. This means newly calculated results will use approximately 70% of oldVal and 30% of newVal, in order to prevent sudden jumps in estimated APR and APY.
    • @param oldVal β€” previous recorded value (scaled by 1e18)
    • @param newVal β€” new calculated value (scaled by 1e18)
    • @param alpha β€” smoothing factor between 0 and 1e18 (7e17 = 70%)
  • Visibility Specifier - internal
  • State Mutability Specifier - pure
  • Returns - uint256 smoothedYieldRate
  • Emits - none
  • Reverts - none

Reading State​

Reads derived, calculated, or internal state. For getters of public variables see the Variable section.

getEstimatedYield()
  • Description - Returns the last recorded estimated yield value for this strategy. This value may not reflect the most recent on-chain state and could differ from live protocol values.
  • Visibility Specifier - public
  • State Mutability Specifier - view
  • Returns - uint256 estimatedYield - last snapshotted yield value (1e18 = 100%)
  • Emits - none
  • Reverts - none
getCap()
  • Description - Returns the params.cap variable. TODO - not used?
  • Visibility Specifier - external
  • State Mutability Specifier - view
  • Returns - uint256 cap
  • Emits - none
  • Reverts - none
getGlobalCap()
  • Description - Returns the params.globalCap variable. TODO - not used??
  • Visibility Specifier - external
  • State Mutability Specifier - view
  • Returns - uint256 globalCap
  • Emits - none
  • Reverts - none
ids()
  • Description - Returns an array of size 1 where the value at the first index is the adapterId associated with this strategy.
  • Visibility Specifier - public
  • State Mutability Specifier - view
  • Returns - bytes32[] memory ids
  • Emits - none
  • Reverts - none
getIdData()
  • Description - Returns the ABI-encoded protocol identifier and address for this adapter.
  • Visibility Specifier - external
  • State Mutability Specifier - view
  • Returns - bytes memory abiEncodedValue
  • Emits - none
  • Reverts - none
realAssets()
  • Description - An empty virtual function defining internal logic for getting the actual amount of underlying assets currently held or represented by this strategy. Must be overridden by derived contracts.
  • Visibility Specifier - external
  • State Mutability Specifier - view
  • Returns - uint256 assets
  • Emits - none
  • Reverts - implementation-dependent
isValidSignature(bytes32 _hash, bytes memory _signature)
  • Description - Definistion for ERC721 interface for Permit2 signature verification. It allows callers to confirm that this strategy contract has validly authorized a specific operation for permit2Address via signature.
    • @param _hash
    • @param _signature
  • Visibility Specifier - public
  • State Mutability Specifier - view
  • Returns - bytes4 isValid - The ERC721 defined value of 0x1626ba7e to indicated a signature is valid. Any other return value indicates an invalid signature.
  • Emits - none
  • Reverts - none

Errors​

  • CounterfeitSettler(address) - TODO not used anywhere?

Events​

  • Allocate(uint256 indexed amount, address indexed strategy) - emitted when funds have been allocated to the strategy described by this adapter.
  • Deallocate(uint256 indexed amount, address indexed strategy) - emmitted when funds have been de-alloacted or removed from the strategy described by this adapter.
  • DeallocateDex(uint256 indexed amount) - emitted when funds have been deallocated via DEX swap.
  • YieldUpdated(uint256 indexed yield) - emitted after taking a yield snapshot.
  • RiskClassUpdated(RiskClass indexed class) - emitted when updating the params.riskClass to recalify the strategies risk level.
  • IncentivesUpdated(bool indexed enabled) - emitted when the additionalIncentives flag is set.
  • Emergency(bool indexed isEmergency) - emitted after enabling the killswitch on this strategy.
  • MYTLog(string message, uint256 value) - debug logging used to output a message and value from the contract.