transfer & mint
Overview

updateInterestRates was covered in the common functions section
transfer
This transfers the asset to be supplied from user to the corresponding AToken contract
from:
msg.senderto:
aTokenAddress(aDAI, aWETH...)
User' supplied assets are held on their respective AToken contracts; DAI held on aDAI.
Use of safeTransferFrom
SafeERC20 is a helper to make safe the interaction with someone else’s ERC20 token, in your contracts. What the helper does for you is:
check the boolean return values of ERC20 operations and revert the transaction if they fail,
at the same time allowing you to support some non-standard ERC20 tokens that don’t have boolean return values.
It additionally provides helpers to increase or decrease an allowance, to mitigate an attack 118 possible with vanilla approve.
For more: https://forum.openzeppelin.com/t/making-sure-i-understand-how-safeerc20-works/2940
mint
minting of ATokens corresponding the supplied asset

mintcalls_mintScaled_mintScaledmints tokens in-line with the current liquidity index, as seen byamountScaledamountToMint:amountScaledcast asuint128balanceIncrease: interest accrued from user's last recorded index and current index_userState[onBehalfOf].additionalDatais updated with the latest index.
balanceIncrease is calculated as part of the mint event emission.

On super.BalanceOf and _userState[onBehalfOf].additionalData
super.BalanceOf and _userState[onBehalfOf].additionalDatasuper.BalanceOfcallsbalanceOfdeclared in IncentivizedERC20.solInheritance: ScaledBalanceTokenBase > MintableIncentivizedERC20 > IncentivizedERC20

notice the irregular definition of
balanceOf, it calls out a mapping_userState_userStateis mapping of user addresses toUserStatestructsEach
UserStatestruct stores a user's balance with a wildcard field ofadditionalData
additionalData in the context of Atokens
used to store the index of the user's last "index-sensitive" action: --> last supply/withdrawal/borrow/repayment
Returns
mint returns the bool value of (scaledBalance == 0)
scaledBalanceis the amount of balance a user has of a specific asset pre-dating this supply action(scaledBalance == 0)will return true only if this supply action is the user's very first supply action - specific to said asset.The return bool value is useful to us as explained in the next section.
Visual Aid
Last updated