Skip to content

[midnight adapter] maturity bitmaps - #913

Closed
adhusson wants to merge 8 commits into
feat/adapter-v2from
maturity-array
Closed

[midnight adapter] maturity bitmaps#913
adhusson wants to merge 8 commits into
feat/adapter-v2from
maturity-array

Conversation

@adhusson

@adhusson adhusson commented Apr 20, 2026

Copy link
Copy Markdown
Contributor
  • code slightly easier to underestand
  • buy gas cost is constant excluding accrual (not important)
  • maturities are aligned to the hour
  • prevent DOS with max ttm at buy is 10 years. So max accrual gas is ~1m gas, reached after 10 years without ping & 50 active maturity hours to go through. After 2 months without ping it's 135k gas.

lastUpdate = uint48(block.timestamp);
}
return (firstMaturity, currentGrowth, _totalAssets);
return (currentGrowth, _totalAssets);

@adhusson adhusson Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do this as well (it removes the duplication of accrueInterest logic)

Suggested change
return (currentGrowth, _totalAssets);
function accrueInterest() public returns (uint128, uint256) {
if (lastUpdate != block.timestamp) {
(currentGrowth, _totalAssets) = accrueInterestView();
uint256 lastIndex = block.timestamp.zeroFloorSub(1).bitmapIndex();
for (uint256 index = lastUpdate.bitmapIndex(); index < lastIndex; index++) {
bitmaps[index] = 0;
}
uint256 nowBit = (block.timestamp - 1)/ 1 hours% 256 + 1;
bitmaps[lastIndex] = (bitmaps[lastIndex] >> nowBit) << nowBit;
lastUpdate = uint48(block.timestamp);
}
return (currentGrowth, _totalAssets);
}

Comment on lines +12 to +13
/// @dev Index of the bitmap containing the already aligned maturity.
function bitmapIndex(uint256 alignedMaturity) internal pure returns (uint256) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the index of a bitmap. Small clash with collateralIndex in midnight which is a bit position.

@adhusson adhusson mentioned this pull request May 5, 2026
3 tasks
@adhusson

Copy link
Copy Markdown
Contributor Author

Closing for now as the complexity is not worth it compared to #921, and increase slot opening gas cost make it less interesting. Still in terms of O(n) it is the best on accrual insertion and deletion.

@adhusson adhusson closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant