22pragma solidity 0.8.10 ;
33
44import {IAToken} from "@aave/core-v3/contracts/interfaces/IAToken.sol " ;
5- import {IPool} from "@contracts/aave-v3/interfaces/aave/IPool.sol " ;
65import {IMorpho} from "@contracts/aave-v3/interfaces/IMorpho.sol " ;
76import {IRewardsController} from "@aave/periphery-v3/contracts/rewards/interfaces/IRewardsController.sol " ;
87
@@ -30,7 +29,6 @@ abstract contract SupplyVaultBase is ERC4626UpgradeableSafe, OwnableUpgradeable
3029 /// STORAGE ///
3130
3231 IMorpho public immutable morpho; // The main Morpho contract.
33- IPool public immutable pool; // The AaveV3 pool.
3432
3533 address public poolToken; // The pool token corresponding to the market to supply to through this vault.
3634
@@ -40,9 +38,7 @@ abstract contract SupplyVaultBase is ERC4626UpgradeableSafe, OwnableUpgradeable
4038 /// @param _morpho The address of the main Morpho contract.
4139 constructor (address _morpho ) {
4240 if (_morpho == address (0 )) revert ZeroAddress ();
43-
4441 morpho = IMorpho (_morpho);
45- pool = morpho.pool ();
4642 }
4743
4844 /// INITIALIZER ///
@@ -91,6 +87,9 @@ abstract contract SupplyVaultBase is ERC4626UpgradeableSafe, OwnableUpgradeable
9187
9288 /// PUBLIC ///
9389
90+ /// @dev The indexes used by this function might not be up-to-date.
91+ /// As a consequence, view functions (like `maxWithdraw`) could underestimate the withdrawable amount.
92+ /// To redeem all their assets, users are encouraged to use the `redeem` function passing their vault tokens balance.
9493 function totalAssets () public view override returns (uint256 ) {
9594 address poolTokenMem = poolToken;
9695 Types.SupplyBalance memory supplyBalance = morpho.supplyBalanceInOf (
@@ -99,10 +98,42 @@ abstract contract SupplyVaultBase is ERC4626UpgradeableSafe, OwnableUpgradeable
9998 );
10099
101100 return
102- supplyBalance.onPool.rayMul (pool. getReserveNormalizedIncome ( asset ()) ) +
101+ supplyBalance.onPool.rayMul (morpho. poolIndexes (poolTokenMem).poolSupplyIndex ) +
103102 supplyBalance.inP2P.rayMul (morpho.p2pSupplyIndex (poolTokenMem));
104103 }
105104
105+ function deposit (uint256 assets , address receiver ) public virtual override returns (uint256 ) {
106+ // Update the indexes to get the most up-to-date total assets balance.
107+ morpho.updateIndexes (poolToken);
108+ return super .deposit (assets, receiver);
109+ }
110+
111+ function mint (uint256 shares , address receiver ) public virtual override returns (uint256 ) {
112+ // Update the indexes to get the most up-to-date total assets balance.
113+ morpho.updateIndexes (poolToken);
114+ return super .mint (shares, receiver);
115+ }
116+
117+ function withdraw (
118+ uint256 assets ,
119+ address receiver ,
120+ address owner
121+ ) public virtual override returns (uint256 ) {
122+ // Update the indexes to get the most up-to-date total assets balance.
123+ morpho.updateIndexes (poolToken);
124+ return super .withdraw (assets, receiver, owner);
125+ }
126+
127+ function redeem (
128+ uint256 shares ,
129+ address receiver ,
130+ address owner
131+ ) public virtual override returns (uint256 ) {
132+ // Update the indexes to get the most up-to-date total assets balance.
133+ morpho.updateIndexes (poolToken);
134+ return super .redeem (shares, receiver, owner);
135+ }
136+
106137 /// INTERNAL ///
107138
108139 function _deposit (
0 commit comments