fix: [FIND-033] exclude disabled corporate actions from pending task aggregations#1175
Conversation
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
marcosio
left a comment
There was a problem hiding this comment.
A lot of improvements related with logic reduction, gas and bytecode improvements. Review.
|
|
||
| if (_includeDisabled) { | ||
| uint256 index = ScheduledTasksStorageWrapper.getScheduledCouponListingCount(true) - 1 - pendingIndexOffset; | ||
| return ScheduledTasksStorageWrapper.getScheduledCouponListingIdAtIndex(index); |
There was a problem hiding this comment.
Avoid variable of single use. Remove index and use inline.
| // When excluding disabled, iterate the queue skipping disabled tasks to find the | ||
| // correct coupon at the filtered pending index. | ||
| uint256 queueLen = ScheduledTasksStorageWrapper.getScheduledCouponListingCount(true); | ||
| uint256 seen = 0; |
| // correct coupon at the filtered pending index. | ||
| uint256 queueLen = ScheduledTasksStorageWrapper.getScheduledCouponListingCount(true); | ||
| uint256 seen = 0; | ||
| for (uint256 j = queueLen; j > 0; ) { |
There was a problem hiding this comment.
Remove queueLen and assign to j=ScheduledTasksStorageWrapper.getScheduledCouponListingCount(true).
| } | ||
| } | ||
| } | ||
| return 0; |
There was a problem hiding this comment.
Not needed, couponID_ is 0 jet.
| } | ||
| } | ||
| return active; | ||
| } |
There was a problem hiding this comment.
Perhaps is better this:
function getScheduledSnapshotCount(bool _includeDisabled) internal view returns (uint256 active) {
ScheduledTasksDataStorage storage store = scheduledSnapshotStorage();
uint256 total = ScheduledTasksLib.getScheduledTaskCount(store);
if (_includeDisabled) return total;
for (uint256 i; i < total; ) {
unchecked {
active += CorporateActionsStorageWrapper.isCorporateActionDisabled(
abi.decode(ScheduledTasksLib.getScheduledTasksByIndex(store, i).data, (bytes32))
)
? 0
: 1;
++i;
}
}
}
| if (_includeDisabled) { | ||
| return ScheduledTasksLib.getScheduledTasks(scheduledCouponListingStorage(), _pageIndex, _pageLength); | ||
| } | ||
| return _getFilteredPage(scheduledCouponListingStorage(), _pageIndex, _pageLength); |
There was a problem hiding this comment.
Refactor as getScheduledSnapshots
| ++i; | ||
| } | ||
| } | ||
| return active; |
There was a problem hiding this comment.
Refactor as getScheduledSnapshotCount
| if (_includeDisabled) { | ||
| return ScheduledTasksLib.getScheduledTasks(scheduledBalanceAdjustmentStorage(), _pageIndex, _pageLength); | ||
| } | ||
| return _getFilteredPage(scheduledBalanceAdjustmentStorage(), _pageIndex, _pageLength); |
|
|
||
| pendingABAF_ *= balanceAdjustment.factor; | ||
| pendingDecimals_ += balanceAdjustment.decimals; | ||
| } |
There was a problem hiding this comment.
Better:
function getPendingScheduledBalanceAdjustmentsAt(
uint256 _timestamp,
bool _includeDisabled
) internal view returns (uint256 pendingABAF_, uint8 pendingDecimals_) {
// * Initialization
pendingABAF_ = 1;
ScheduledTasksDataStorage storage scheduledBalanceAdjustments = scheduledBalanceAdjustmentStorage();
uint256 length = ScheduledTasksLib.getScheduledTaskCount(scheduledBalanceAdjustments);
uint256 pos = length;
for (uint256 i; i < length; ) {
unchecked {
--pos;
++i;
}
ScheduledTask memory scheduledTask = ScheduledTasksLib.getScheduledTasksByIndex(
scheduledBalanceAdjustments,
pos
);
if (_timestamp >= scheduledTask.scheduledTimestamp) return (pendingABAF_, pendingDecimals_);
bytes32 actionId = abi.decode(scheduledTask.data, (bytes32));
if (_includeDisabled || !CorporateActionsStorageWrapper.isCorporateActionDisabled(actionId)) {
IScheduledBalanceAdjustment.ScheduledBalanceAdjustment memory balanceAdjustment = abi.decode(
CorporateActionsStorageWrapper.getCorporateActionData(actionId),
(IScheduledBalanceAdjustment.ScheduledBalanceAdjustment)
);
pendingABAF_ *= balanceAdjustment.factor;
pendingDecimals_ += balanceAdjustment.decimals;
}
}
}
| ++i; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Not optimal:
- Don't use PaginationLib
- Remove final for for assembly code to reduce buffer.
- Don't create buffer, result_ is jet created.
- For very complex to follow, is possible reduce jumps.
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
Signed-off-by: jaime-iobermudez <jaime.bermudez@io.builders>
This pull request fixes an issue where cancelled (disabled) corporate actions were incorrectly included in pending task aggregations, affecting coupon listings, balance adjustments, and related queries. The fix ensures that disabled tasks are now properly excluded from all internal calculations, resulting in accurate live values for functions like
getCouponsOrderedList,balanceOfAt, and others. The external API remains unchanged; the changes are internal and transparent to consumers.Bug fix: Exclude disabled corporate actions from pending task aggregations
getPendingScheduledCouponListingTotalAt,getPendingScheduledBalanceAdjustmentsAt) now accept a_includeDisabledflag, allowing them to skip disabled tasks when computing live values. All internal callers that compute live values passfalse, ensuring disabled tasks are excluded. (.changeset/fix-find-033-pending-task-disabled-exclusion.md, [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]Library and function interface changes
_includeDisabledflag was propagated through several internal and library functions, including those inCouponStorageWrapper,ScheduledTasksStorageWrapper, and others, to ensure consistent exclusion of disabled tasks across all relevant queries and calculations. [1] [2] [3] [4] [5] [6]New helper functions
isScheduledCouponListingDisabledAtIndexto efficiently check if a scheduled coupon listing task is related to a disabled corporate action, supporting the correct filtering of tasks.Test coverage
balanceOfAtreturns the unadjusted value after cancellation).These changes collectively resolve the bug (FIND-033) and ensure that disabled corporate actions no longer affect live or projected calculations for coupons and balances.
Type of change
Testing
Node version:
Checklist