-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: extract shared rebase-migration skeleton into RebaseMigratable (#94) #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thedavidmeister
wants to merge
1
commit into
main
Choose a base branch
from
feat/issue-94-rebase-migratable-abstract
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity ^0.8.25; | ||
|
|
||
| /// @title RebaseMigratable | ||
| /// @notice Shared skeleton for the lazy rebase-migration algorithm. Both | ||
| /// `StoxReceiptVault` (share side) and `StoxReceipt` (receipt side) lazily | ||
| /// rasterize each holder's stored balance to the latest completed corporate | ||
| /// action on first touch in `_update`. The orchestration is identical: | ||
| /// | ||
| /// 1. Zero-address short-circuit (mint `from`, burn `to`). | ||
| /// 2. Read the holder's current cursor + stored balance. | ||
| /// 3. Walk the rebase from that cursor forward, returning the rasterized | ||
| /// balance and the advanced cursor. | ||
| /// 4. Early-return if the cursor didn't advance (no completed action newer | ||
| /// than the holder's last touch). | ||
| /// 5. Write the new cursor. | ||
| /// 6. If the balance changed (it can stay equal under the identity bootstrap | ||
| /// or after a truncate-to-zero), write the new stored balance. | ||
| /// 7. Emit the migration event. | ||
| /// 8. Run the post-migrate hook (share side updates the totalSupply pots; | ||
| /// receipt side is a no-op). | ||
| /// | ||
| /// The differences are entirely plug-points (which storage to read/write, | ||
| /// which rebase walk to invoke, which event to emit, whether the post-hook | ||
| /// touches additional state). This abstract owns the orchestration; the | ||
| /// concrete contracts implement the plug-points and the shape stays a | ||
| /// single-source-of-truth instead of being mirrored across two files. | ||
| /// | ||
| /// **`id` parameter.** The receipt side is keyed by `(holder, id)` for the | ||
| /// ERC-1155 token id. The share side has no id concept — its overrides | ||
| /// ignore the parameter, and its `_emitMigrated` hook drops the field | ||
| /// from the event signature. The slight smell of an always-zero `id` on | ||
| /// the share side is the cost of keeping one orchestration; the | ||
| /// alternative (separate `_migrateAccount` / `_migrateHolderId` shapes) | ||
| /// is exactly the duplication this base eliminates. | ||
| abstract contract RebaseMigratable { | ||
| /// @dev Read the holder's current migration cursor. | ||
| /// @param account The holder. | ||
| /// @param id The ERC-1155 token id (ignored by share-side overrides). | ||
| function _readCursor(address account, uint256 id) internal view virtual returns (uint256); | ||
|
|
||
| /// @dev Write the holder's new migration cursor. | ||
| function _writeCursor(address account, uint256 id, uint256 cursor) internal virtual; | ||
|
|
||
| /// @dev Read the holder's raw stored balance (pre-rebase, before any | ||
| /// pending multipliers are applied). | ||
| function _readStoredBalance(address account, uint256 id) internal view virtual returns (uint256); | ||
|
|
||
| /// @dev Write the holder's rasterized stored balance (post-rebase). | ||
| function _writeStoredBalance(address account, uint256 id, uint256 balance) internal virtual; | ||
|
|
||
| /// @dev Walk the rebase from `cursor` forward, returning the rasterized | ||
| /// balance and the advanced cursor. | ||
| function _walkRebase(uint256 storedBalance, uint256 cursor) internal view virtual returns (uint256, uint256); | ||
|
|
||
| /// @dev Emit the migration event with the override's preferred shape. | ||
| /// Share-side overrides drop `id`; receipt-side keeps it. | ||
| function _emitMigrated( | ||
| address account, | ||
| uint256 id, | ||
| uint256 fromActionId, | ||
| uint256 toActionId, | ||
| uint256 oldBalance, | ||
| uint256 newBalance | ||
| ) internal virtual; | ||
|
|
||
| /// @dev Hook called after the migration is fully written. Share side | ||
| /// updates the per-cursor totalSupply pots via | ||
| /// `LibTotalSupply.onAccountMigrated`; receipt side is a no-op. | ||
| function _postMigrate(uint256 fromActionId, uint256 toActionId, uint256 oldBalance, uint256 newBalance) | ||
| internal | ||
| virtual; | ||
|
|
||
| /// @dev Run the lazy rebase migration for `(account, id)`. Idempotent — | ||
| /// calling on an account already at the latest cursor is a no-op. | ||
| function _migrate(address account, uint256 id) internal { | ||
| if (account == address(0)) return; | ||
|
|
||
| uint256 currentCursor = _readCursor(account, id); | ||
| uint256 storedBalance = _readStoredBalance(account, id); | ||
|
|
||
| (uint256 newBalance, uint256 newCursor) = _walkRebase(storedBalance, currentCursor); | ||
|
|
||
| if (newCursor == currentCursor) return; | ||
|
|
||
| _writeCursor(account, id, newCursor); | ||
|
|
||
| // Skip the SSTORE when the rasterized balance is unchanged. Equal | ||
| // balances arise under the identity bootstrap (no real multiplier | ||
| // applied) and when fractional truncation lands on the same | ||
| // integer (e.g. a 1-wei balance at any multiplier). The cursor | ||
| // advancement above is what matters for these cases. | ||
| if (newBalance != storedBalance) { | ||
| _writeStoredBalance(account, id, newBalance); | ||
| } | ||
|
|
||
| _emitMigrated(account, id, currentCursor, newCursor, storedBalance, newBalance); | ||
|
|
||
| _postMigrate(currentCursor, newCursor, storedBalance, newBalance); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: S01-Issuer/st0x.deploy
Length of output: 2998
🏁 Script executed:
Repository: S01-Issuer/st0x.deploy
Length of output: 1099
🏁 Script executed:
sed -n '25,35p' src/abstract/RebaseMigratable.solRepository: S01-Issuer/st0x.deploy
Length of output: 791
🏁 Script executed:
grep -n "^abstract contract\|^contract\|^library" src/abstract/RebaseMigratable.solRepository: S01-Issuer/st0x.deploy
Length of output: 106
Pin this abstract contract to
=0.8.25.This file is a contract under
src/**/*.sol, so leaving it on^0.8.25weakens the repo's exact-compiler guarantee for the shared migration path.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents