Function: investWithToken(address account, IOrigamiInvestment.InvestQuoteData quoteData)
The function can be called only from the LovToken contract, but the LovToken:investWithToken, which triggers this function, can be called by any user. The global investmentsPaused should not be true.
Inputs
accountConstraints: If the global variable
allowAllis true, theaccountis not validated. Otherwise, if the address is not a contract, theallowedAccountsshould contain theaccountaddress.Impact: The address of the caller of the
LovToken:investWithTokenfunction who initiated the invest process.
quoteData.fromTokenConstraints: The address is validated inside the
_depositIntoReservesfunction. IffromTokenis equal to thedepositAsset, thendepositAssetwill be deposited to the_reserveToken. IffromTokenis equal to the_reserveToken, then its tokens are already deposited for the_managercontract; otherwise, the function will revert.Impact: The token that will be invested.
quoteData.fromTokenAmountConstraints: Cannot be zero.
Impact: If
fromToken==depositAsset, thenfromTokenAmounttokens will be deposited to the_reserveTokencontract usingdeposit(). IffromToken==_reserveTokenand thenfromTokenAmount, then tokens were already deposited.
quoteData.maxSlippageBpsConstraints: Is not used and is not validated.
Impact: The maximum allowed slippage of the
expectedInvestmentAmount.
quoteData.deadlineConstraints: Is not used and is not validated.
Impact: The maximum deadline to execute the transaction.
quoteData.expectedInvestmentAmountConstraints: Is not used and is not validated.
Impact: The expected amount of this lovToken token to receive in return.
quoteData.minInvestmentAmountConstraints: There is a check that
investmentAmountis not less thanquoteData.minInvestmentAmount.Impact: The minimum amount of lovToken to receive.
quoteData.underlyingInvestmentQuoteDataConstraints: Is not used and is not validated.
Impact: Extra quote parameters.
Branches and code coverage
Intended branches
investWithTokenwas successfully completed as expected.
Negative behavior
Caller is not approved lovToken contract.
The
investmentAmountis less thanminInvestmentAmount.fromTokenis not supported.The pause state for invest is true
quoteData.fromTokenAmountis zero
Function call analysis
this.populateCache() -> this.liabilities() -> this.lendingClerk.borrowerDebt(address(this))What is controllable? N/A.
If the return value is controllable, how is it used and how can it go wrong? The value is used to calculate the debt converted to shares, which in turn is used for A/L ratio calculation.
What happens if it reverts, reenters or does other unusual control flow? The function returns current debt of this manager contract. The balance of debt tokens can be changed only over
borrow/repayfunction or by the minter of debt tokens, who can transfer debt tokens between accounts.
this.populateCache() -> this.liabilities() -> this._reserveToken.previewWithdraw(debtInDepositAsset)What is controllable? N/A.
If the return value is controllable, how is it used and how can it go wrong? Returns debt amount converted to the shares. The value is used for
cache.liabilities.What happens if it reverts, reenters or does other unusual control flow? N/A.
this.populateCache() -> this.lovToken.totalSupply()What is controllable? N/A.
If the return value is controllable, how is it used and how can it go wrong? Returns full number of minted lovTokens. The value is used for
cache.totalSupply.What happens if it reverts, reenters or does other unusual control flow? N/A.
this._assetToLiabilityRatio(cache) -> OrigamiMath.mulDiv(cache.assets, OrigamiAbstractLovTokenManager.PRECISION, cache.liabilities, Rounding.ROUND_DOWN)What is controllable? N/A.
If the return value is controllable, how is it used and how can it go wrong? Returns current L/A ratio, which is calculated using total reserves balance
cache.assets, which is equal toreservesBalance(), and debt shares, which is equal to thecache.liabilities.What happens if it reverts, reenters or does other unusual control flow? N/A.
this._depositIntoReserves(quoteData.fromToken, quoteData.fromTokenAmount) -> OrigamiLovTokenErc4626Manager._depositIntoReservesWhat is controllable?
quoteData.fromTokenandquoteData.fromTokenAmount.If the return value is controllable, how is it used and how can it go wrong? Returns the number invested reserves.
What happens if it reverts, reenters or does other unusual control flow? If
fromToken==_reserveToken, the function will returnquoteData.fromTokenAmount. IffromToken==depositAsset, the function will return the result of the_reserveToken.deposit()function; otherwise, this function will revert.
this._reservesToShares(cache, newReservesAmount)What is controllable?
newReservesAmount.If the return value is controllable, how is it used and how can it go wrong? If
cache.totalSupply == 0, the function will returnnewReservesAmount, so_reservesToShareswill be 1:1.What happens if it reverts, reenters or does other unusual control flow? Calculate the number of shares for the corresponding
reserves,cache.totalSupply, and_redeemableReservesamounts.