Strategy.sol#Strategy
Inherits: BaseStrategy, Pausable, AccessControl
The TokenizedStrategy
variable can be used to retrieve the strategies specific storage data your contract. i.e. uint256 totalAssets = TokenizedStrategy.totalAssets() This can not be used for write functions. Any TokenizedStrategy variables that need to be updated post deployment will need to come from an external call from the strategies specific management
.
State Variables
GOVERNOR_ROLE
TERM_VAULT_EVENT_EMITTER
PURCHASE_TOKEN_PRECISION
YEARN_VAULT
depositLock
State variables
pendingGovernor
repoTokenListData
termAuctionListData
tokenSymbol
strategyState
repoTokenBlacklist
Functions
notBlacklisted
pauseDeposit
Pause the contract
unpauseDeposit
Unpause the contract
pauseStrategy
Pause the contract
unpauseStrategy
Unpause the contract
setPendingGovernor
acceptGovernor
setTermController
Set the term controller
Parameters
newTermControllerAddr
address
The address of the new term controller
setDiscountRateAdapter
Set the discount rate adapter used to price repoTokens
Parameters
newAdapter
address
The address of the new discount rate adapter
setTimeToMaturityThreshold
Set the weighted time to maturity cap
Parameters
newTimeToMaturityThreshold
uint256
The new weighted time to maturity cap
setRequiredReserveRatio
Set the required reserve ratio
This function can only be called by management
Parameters
newRequiredReserveRatio
uint256
The new required reserve ratio (in 1e18 precision)
setRepoTokenConcentrationLimit
Set the repoToken concentration limit
Parameters
newRepoTokenConcentrationLimit
uint256
The new repoToken concentration limit
setDiscountRateMarkup
Set the markup that the vault will receive in excess of the oracle rate
Parameters
newDiscountRateMarkup
uint256
The new auction rate markup
setCollateralTokenParams
Set the collateral token parameters
Parameters
tokenAddr
address
The address of the collateral token to be accepted
minCollateralRatio
uint256
The minimum collateral ratio accepted by the strategy
setRepoTokenBlacklist
symbol
totalAssetValue
Calculates the total value of all assets managed by the strategy
This function aggregates the total liquid balance, the present value of all repoTokens, and the present value of all pending offers to calculate the total asset value.
Returns
<none>
uint256
The total asset value in the purchase token precision
totalLiquidBalance
Get the total liquid balance of the assets managed by the strategy
This function aggregates the balance of the underlying asset held directly by the strategy and the balance of the asset held in the Yearn Vault to calculate the total liquid balance.
Returns
<none>
uint256
The total liquid balance in the purchase token precision
_liquidReserveRatio
Calculate the liquid reserve ratio
This function calculates the ratio of liquid balance to total asset value. It returns 0 if the total asset value is 0 to avoid division by zero.
Parameters
liquidBalance
uint256
The current liquid balance of the strategy
Returns
<none>
uint256
The liquid reserve ratio in 1e18 precision
liquidReserveRatio
Get the current liquid reserve ratio of the strategy
This function calculates the liquid reserve ratio based on the current total liquid balance of the strategy.
Returns
<none>
uint256
The current liquid reserve ratio in 1e18 precision
repoTokenHoldings
Returns an array of addresses representing the repoTokens currently held by the strategy
This function calls the holdings
function from the RepoTokenList
library to get the list of repoTokens currently held in the RepoTokenListData
structure.
Returns
<none>
address[]
address[] An array of addresses of the repoTokens held by the strategy
pendingOffers
Get an array of pending offers submitted into Term auctions
This function calls the pendingOffers
function from the TermAuctionList
library to get the list of pending offers currently submitted into Term auctions from the TermAuctionListData
structure.
Returns
<none>
bytes32[]
bytes32[] An array of bytes32
values representing the IDs of the pending offers
getRepoTokenConcentrationRatio
Calculate the concentration ratio of a specific repoToken in the strategy
This function computes the current concentration ratio of a specific repoToken in the strategy's portfolio. It reverts if the repoToken address is zero. The calculation is based on the current total asset value and does not consider any additional purchases or removals of the repoToken.
Parameters
repoToken
address
The address of the repoToken to calculate the concentration for
Returns
<none>
uint256
The concentration ratio of the repoToken in the strategy (in 1e18 precision)
simulateTransaction
Simulates the weighted time to maturity for a specified repoToken and amount, including the impact on the entire strategy's holdings
*This function simulates the effects of a potential transaction on the strategy's key metrics. It calculates the new weighted time to maturity and liquidity ratio, considering the specified repoToken and amount. For existing repoTokens, use address(0) as the repoToken parameter. The function performs various checks and calculations, including:
Validating the repoToken (if not address(0))
Calculating the present value of the transaction
Estimating the impact on the strategy's liquid balance
Computing the new weighted maturity and liquidity ratio*
Parameters
repoToken
address
The address of the repoToken to be simulated
amount
uint256
The amount of the repoToken to be simulated
Returns
simulatedWeightedMaturity
uint256
The simulated weighted time to maturity for the entire strategy
simulatedRepoTokenConcentrationRatio
uint256
The concentration ratio of the repoToken in the strategy (in 1e18 precision)
simulatedLiquidityRatio
uint256
The simulated liquidity ratio after the transaction
calculateRepoTokenPresentValue
Calculates the present value of a specified repoToken based on its discount rate, redemption timestamp, and amount
This function retrieves the redemption timestamp, calculates the repoToken precision, normalizes the repoToken amount to base asset precision, and calculates the present value using the provided discount rate and redemption timestamp.
Parameters
repoToken
address
The address of the repoToken
discountRate
uint256
The discount rate to be used in the present value calculation
amount
uint256
The amount of the repoToken to be discounted
Returns
<none>
uint256
uint256 The present value of the specified repoToken and amount
getRepoTokenHoldingValue
Calculates the present value of a specified repoToken held by the strategy
This function calculates the present value of the specified repoToken from both the repoTokenListData
and termAuctionListData
structures, then sums these values to provide a comprehensive valuation.
Parameters
repoToken
address
The address of the repoToken to value
Returns
<none>
uint256
uint256 The present value of the specified repoToken
_withdrawAsset
Withdraw assets from the Yearn vault
Parameters
amount
uint256
The amount to withdraw
_assetBalance
Retrieves the asset balance from the Yearn Vault
Returns
<none>
uint256
The balance of assets in the purchase token precision
_totalLiquidBalance
Calculates the total liquid balance of the assets managed by the strategy
This function aggregates the balance of the underlying asset held directly by the strategy and the balance of the asset held in the Yearn Vault to calculate the total liquid balance.
Returns
<none>
uint256
uint256 The total liquid balance of the assets
_totalAssetValue
Calculates the total value of all assets managed by the strategy (internal function)
This function aggregates the total liquid balance, the present value of all repoTokens, and the present value of all pending offers to calculate the total asset value.
Returns
totalValue
uint256
The total value of all assets
_getRepoTokenConcentrationRatio
Calculates the concentration ratio of a specific repoToken in the strategy
This function computes the concentration ratio of a specific repoToken, considering both existing holdings and a potential new addition. It adjusts the total asset value, normalizes values to 1e18 precision, and handles the case where total asset value might be zero.
Parameters
repoToken
address
The address of the repoToken to calculate the concentration for
repoTokenAmountInBaseAssetPrecision
uint256
The amount of the repoToken in base asset precision to be added
assetValue
uint256
The current total asset value of the strategy
liquidBalanceToRemove
uint256
The amount of liquid balance to be removed from the strategy
Returns
<none>
uint256
The concentration ratio of the repoToken in the strategy (in 1e18 precision)
_validateRepoTokenConcentration
Validate the concentration of a repoToken against the strategy's limit
This function calculates the concentration ratio of the specified repoToken and compares it against the predefined concentration limit. It reverts with a RepoTokenConcentrationTooHigh error if the concentration exceeds the limit.
Parameters
repoToken
address
The address of the repoToken to validate
repoTokenAmountInBaseAssetPrecision
uint256
The amount of the repoToken in base asset precision
assetValue
uint256
The current total asset value of the strategy
liquidBalanceToRemove
uint256
The amount of liquid balance to be removed from the strategy
_calculateWeightedMaturity
Calculates the weighted time to maturity for the strategy's holdings, including the impact of a specified repoToken and amount
This function aggregates the cumulative weighted time to maturity and the cumulative amount of both existing repoTokens and offers, then calculates the weighted time to maturity for the entire strategy. It considers both repoTokens and auction offers. The repoToken
and repoTokenAmount
parameters are optional and provide flexibility to adjust the calculations to include the provided repoToken amount. If repoToken
is set to address(0)
or repoTokenAmount
is 0
, the function calculates the cumulative data without specific token adjustments.
Parameters
repoToken
address
The address of the repoToken (optional)
repoTokenAmount
uint256
The amount of the repoToken to be included in the calculation
liquidBalance
uint256
The liquid balance of the strategy
Returns
<none>
uint256
uint256 The weighted time to maturity in seconds for the entire strategy, including the specified repoToken and amount
_isTermDeployed
Checks if a term contract is marked as deployed in either the current or previous term controller
This function first checks the current term controller, then the previous one if necessary. It handles cases where either controller might be unset (address(0)).
Parameters
termContract
address
The address of the term contract to check
Returns
<none>
bool
bool True if the term contract is deployed, false otherwise
_redeemRepoTokens
Rebalances the strategy's assets by sweeping assets and redeeming matured repoTokens
This function removes completed auction offers, redeems matured repoTokens, and adjusts the underlying balance to maintain the required liquidity. It ensures that the strategy has sufficient liquid assets while optimizing asset allocation.
Parameters
liquidAmountRequired
uint256
The amount of liquid assets required to be maintained by the strategy
_validateAndGetOfferLocker
Validates a term auction and repo token, and retrieves the associated offer locker
This function performs several validation steps: verifying term auction and repo token deployment, matching repo token to auction's term repo ID, validating repo token against strategy requirements, and ensuring the auction is open. It reverts with specific error messages on validation failures.
Parameters
termAuction
ITermAuction
The term auction contract to validate
repoToken
address
The repo token address to validate
Returns
<none>
ITermAuctionOfferLocker
ITermAuctionOfferLocker The offer locker associated with the validated term auction
submitAuctionOffer
Submits an offer into a term auction for a specified repoToken
This function validates the underlying repoToken, checks concentration limits, ensures the auction is open, and rebalances liquidity to support the offer submission. It handles both new offers and edits to existing offers.
Parameters
termAuction
ITermAuction
The address of the term auction
repoToken
address
The address of the repoToken
idHash
bytes32
The hash of the offer ID
offerPriceHash
bytes32
The hash of the offer price
purchaseTokenAmount
uint256
The amount of purchase tokens being offered
Returns
offerIds
bytes32[]
An array of offer IDs for the submitted offers
_submitOffer
Submits an offer to a term auction and locks it using the offer locker.
Parameters
auction
ITermAuction
The term auction contract
offerLocker
ITermAuctionOfferLocker
The offer locker contract
offer
ITermAuctionOfferLocker.TermAuctionOfferSubmission
The offer details
repoToken
address
The address of the repoToken
newOfferAmount
uint256
The amount of the new offer
currentOfferAmount
uint256
The amount of the current offer, if it exists
Returns
offerIds
bytes32[]
An array of offer IDs for the submitted offers
deleteAuctionOffers
Removes specified offers from a term auction and performs related cleanup.
Parameters
termAuction
address
The address of the term auction from which offers will be deleted.
offerIds
bytes32[]
An array of offer IDs to be deleted.
auctionClosed
Required for post-processing after auction clos
sellRepoToken
Allows the sale of a specified amount of a repoToken in exchange for assets.
Parameters
repoToken
address
The address of the repoToken to be sold.
repoTokenAmount
uint256
The amount of the repoToken to be sold.
constructor
Constructor to initialize the Strategy contract
Parameters
_name
string
The name of the strategy
_symbol
string
_params
StrategyParams
_deployFunds
Can deploy up to '_amount' of 'asset' in the yield source. This function is called at the end of a {deposit} or {mint} call. Meaning that unless a whitelist is implemented it will be entirely permissionless and thus can be sandwiched or otherwise manipulated.
Parameters
_amount
uint256
The amount of 'asset' that the strategy can attempt to deposit in the yield source.
_freeFunds
Should attempt to free the '_amount' of 'asset'. NOTE: The amount of 'asset' that is already loose has already been accounted for. This function is called during {withdraw} and {redeem} calls. Meaning that unless a whitelist is implemented it will be entirely permissionless and thus can be sandwiched or otherwise manipulated. Should not rely on asset.balanceOf(address(this)) calls other than for diff accounting purposes. Any difference between _amount
and what is actually freed will be counted as a loss and passed on to the withdrawer. This means care should be taken in times of illiquidity. It may be better to revert if withdraws are simply illiquid so not to realize incorrect losses.
Parameters
_amount
uint256
_harvestAndReport
Internal function to harvest all rewards, redeploy any idle funds and return an accurate accounting of all funds currently held by the Strategy. This should do any needed harvesting, rewards selling, accrual, redepositing etc. to get the most accurate view of current assets. NOTE: All applicable assets including loose assets should be accounted for in this function. Care should be taken when relying on oracles or swap values rather than actual amounts as all Strategy profit/loss accounting will be done based on this returned value. This can still be called post a shutdown, a strategist can check TokenizedStrategy.isShutdown()
to decide if funds should be redeployed or simply realize any profits/losses.
Returns
_totalAssets
uint256
A trusted and accurate account for the total amount of 'asset' the strategy currently holds including idle funds.
availableWithdrawLimit
Gets the max amount of asset
that can be withdrawn.
Defaults to an unlimited amount for any address. But can be overridden by strategists. This function will be called before any withdraw or redeem to enforce any limits desired by the strategist. This can be used for illiquid or sandwichable strategies. EX: return asset.balanceOf(yieldSource); This does not need to take into account the _owner
's share balance or conversion rates from shares to assets.
Parameters
<none>
address
Returns
<none>
uint256
. The available amount that can be withdrawn in terms of asset
Errors
InvalidTermAuction
TimeToMaturityAboveThreshold
BalanceBelowRequiredReserveRatio
InsufficientLiquidBalance
RepoTokenConcentrationTooHigh
RepoTokenBlacklisted
DepositPaused
AuctionNotOpen
ZeroPurchaseTokenAmount
OfferNotFound
Structs
StrategyParams
Constructor to initialize the Strategy contract
Properties
_asset
address
The address of the asset
_yearnVault
address
The address of the Yearn vault
_discountRateAdapter
address
The address of the discount rate adapter
_eventEmitter
address
The address of the event emitter
_governorAddress
address
The address of the governor
_termController
address
The address of the term controller
_repoTokenConcentrationLimit
uint256
The concentration limit for repoTokens
_timeToMaturityThreshold
uint256
The time to maturity threshold
_requiredReserveRatio
uint256
The required reserve ratio
_discountRateMarkup
uint256
The discount rate markup
StrategyState
Last updated