Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

Commit 2b4993c

Browse files
authored
Merge pull request #1666 from morpho-org/fix/indexes-caching-issue
Fix indexes caching issue
2 parents 0df9d1a + 94b2cdc commit 2b4993c

13 files changed

Lines changed: 162 additions & 14 deletions

.github/actions/ci-foundry-upgrade/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ runs:
2525
shell: bash
2626

2727
- name: Install Foundry
28-
uses: onbjerg/foundry-toolchain@v1
28+
uses: foundry-rs/foundry-toolchain@v1
2929
with:
3030
version: nightly
3131

.github/actions/ci-foundry/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ runs:
3333
shell: bash
3434

3535
- name: Install Foundry
36-
uses: onbjerg/foundry-toolchain@v1
36+
uses: foundry-rs/foundry-toolchain@v1
3737
with:
3838
version: nightly
3939

.github/workflows/ci-storage-check-aave-v2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
shell: bash
3434

3535
- name: Install Foundry
36-
uses: onbjerg/foundry-toolchain@v1
36+
uses: foundry-rs/foundry-toolchain@v1
3737
with:
3838
version: nightly
3939

.github/workflows/ci-storage-check-compound.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
shell: bash
3434

3535
- name: Install Foundry
36-
uses: onbjerg/foundry-toolchain@v1
36+
uses: foundry-rs/foundry-toolchain@v1
3737
with:
3838
version: nightly
3939

.github/workflows/ci-storage-snapshot-check-aave-v2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: yarn install --frozen-lockfile
3333

3434
- name: Install Foundry
35-
uses: onbjerg/foundry-toolchain@v1
35+
uses: foundry-rs/foundry-toolchain@v1
3636
with:
3737
version: nightly
3838

.github/workflows/ci-storage-snapshot-check-compound.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: yarn install --frozen-lockfile
3333

3434
- name: Install Foundry
35-
uses: onbjerg/foundry-toolchain@v1
35+
uses: foundry-rs/foundry-toolchain@v1
3636
with:
3737
version: nightly
3838

src/aave-v2/InterestRatesManager.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ contract InterestRatesManager is IInterestRatesManager, MorphoStorage {
5353
function updateIndexes(address _poolToken) external {
5454
Types.PoolIndexes storage marketPoolIndexes = poolIndexes[_poolToken];
5555

56-
if (block.timestamp == marketPoolIndexes.lastUpdateTimestamp) return;
57-
5856
Types.Market storage market = market[_poolToken];
5957
(uint256 newPoolSupplyIndex, uint256 newPoolBorrowIndex) = _getPoolIndexes(
6058
market.underlyingToken

src/compound/InterestRatesManager.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ contract InterestRatesManager is IInterestRatesManager, MorphoStorage {
5252
function updateP2PIndexes(address _poolToken) external {
5353
Types.LastPoolIndexes storage poolIndexes = lastPoolIndexes[_poolToken];
5454

55-
if (block.number == poolIndexes.lastUpdateBlockNumber) return;
56-
5755
Types.MarketParameters memory marketParams = marketParameters[_poolToken];
5856

5957
uint256 poolSupplyIndex = ICToken(_poolToken).exchangeRateCurrent();

src/compound/lens/IndexesLens.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ abstract contract IndexesLens is LensStorage {
179179
{
180180
marketParameters = morpho.marketParameters(_poolToken);
181181

182-
if (!_updated || block.number == _lastPoolIndexes.lastUpdateBlockNumber) {
182+
if (!_updated) {
183183
return (
184184
morpho.p2pSupplyIndex(_poolToken),
185185
morpho.p2pBorrowIndex(_poolToken),

test/aave-v2/TestLens.t.sol

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,4 +1658,40 @@ contract TestLens is TestSetup {
16581658
morpho.setIsLiquidateBorrowPaused(aDai, true);
16591659
assertTrue(lens.getMarketPauseStatus(aDai).isLiquidateBorrowPaused);
16601660
}
1661+
1662+
function testPoolIndexGrowthInsideBlock() public {
1663+
supplier1.approve(dai, type(uint256).max);
1664+
supplier1.supply(aDai, 10 ether);
1665+
1666+
uint256 poolSupplyIndexBefore = lens.getIndexes(aDai).poolSupplyIndex;
1667+
1668+
FlashLoan flashLoan = new FlashLoan(pool);
1669+
vm.prank(address(supplier2));
1670+
ERC20(dai).transfer(address(flashLoan), 10_000 ether); // To pay the premium.
1671+
flashLoan.callFlashLoan(dai, 10_000 ether);
1672+
1673+
uint256 poolSupplyIndexAfter = lens.getIndexes(aDai).poolSupplyIndex;
1674+
1675+
assertGt(poolSupplyIndexAfter, poolSupplyIndexBefore);
1676+
}
1677+
1678+
function testP2PIndexGrowthInsideBlock() public {
1679+
borrower1.approve(dai, type(uint256).max);
1680+
borrower1.supply(aDai, 10 ether);
1681+
borrower1.borrow(aDai, 5 ether);
1682+
setDefaultMaxGasForMatchingHelper(3e6, 3e6, 3e6, 0);
1683+
// Create delta.
1684+
borrower1.repay(aDai, type(uint256).max);
1685+
1686+
uint256 p2pSupplyIndexBefore = lens.getCurrentP2PSupplyIndex(aDai);
1687+
1688+
FlashLoan flashLoan = new FlashLoan(pool);
1689+
vm.prank(address(supplier2));
1690+
ERC20(dai).transfer(address(flashLoan), 10_000 ether); // To pay the premium.
1691+
flashLoan.callFlashLoan(dai, 10_000 ether);
1692+
1693+
uint256 p2pSupplyIndexAfter = lens.getCurrentP2PSupplyIndex(aDai);
1694+
1695+
assertGt(p2pSupplyIndexAfter, p2pSupplyIndexBefore);
1696+
}
16611697
}

0 commit comments

Comments
 (0)