-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: principal-based account #102
base: feat/continuous-index
Are you sure you want to change the base?
Conversation
deluca-mike
commented
Jan 13, 2025
- principal-based earner account, instead of last index
- auto and manual migration for existing earners
LCOV of commit
|
09fcec1
to
40784bf
Compare
76f82b0
to
d447ba7
Compare
40784bf
to
323b291
Compare
d447ba7
to
e261b7b
Compare
323b291
to
aa920f6
Compare
e261b7b
to
b27e0af
Compare
aa920f6
to
a021e1a
Compare
b27e0af
to
8c6a412
Compare
8c6a412
to
eba643f
Compare
unchecked { | ||
// Increment the total earning supply and principal proportionally. | ||
totalEarningSupply += amount_; | ||
principalOfTotalEarningSupply += IndexingMath.getPrincipalAmountRoundedUp(amount_, currentIndex_); |
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.
why the was a round up in previous version? Bug? round down makes more sense
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.
Needed to round up because individual account principals were not stored and thus could not be accumulated in a fixed way, so principalOfTotalEarningSupply
needed to be rounded up (inflated) to ensure excess was conservative (deflated).
Now that each earner has a fixed computeed earning principal, totalEarningPrincipal
can simply be added to or subtracted from with these individual account earning principals. It is an exact accumulation.
); | ||
|
||
totalEarningSupply -= amount_; | ||
totalEarningSupply = totalEarningSupply_ - UIntMath.min240(amount_, totalEarningSupply_); |
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.
a lot of checks: this one should have already covered principal https://github.com/m0-foundation/wrapped-m-token/pull/102/files#diff-82f33536a281f203780891834e2f2453a322bed686e89ea9b7171a2d74fc10b9R442-R448
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.
That link does not seem to work so I do not know what you are referring to (but I assume it is the uint112 principal_ = UIntMath.min112
line in _subtractEarningAmount
). In any case, the UIntMath.min240
and UIntMath.min112
here just prevent underflows without the _subtractTotalEarningSupply
function needing to be aware of how its callers operate or what they check. It is a safety measure, especially if this function may be used again later down the road. It is minimal gas for that safety.
But yes, technically it would be impossible to decrement totalEarningSupply
or totalEarningPrincipal
below 0 given any accounts' amount_
or principal_
, since both those totals are already established totals.
We can remove the checks if you prefer.
@@ -205,11 +220,11 @@ interface IWrappedMToken is IMigratable, IERC20Extended { | |||
function balanceWithYieldOf(address account) external view returns (uint256 balance); |
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.
balanceWithUnclaimedYieldOf
or even delete this function
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.
I will handle fucntion renames later on as:
- it is outside the scope of this PR
- they would be applicable and useful even if this pr is not merged
- the rebase(s) would potentially be too tedious at this point
|
||
return; | ||
} | ||
|
||
senderAccountInfo_.isEarning | ||
// TODO: Don't touch globals if both are earning or not earning. |
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.
optimization mentioned in TODO?
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.
In a future PR, if needed at all. May depend on other PRs as well.
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.
great work, things to discuss - simplifying migration strategy / code
by looping over all wM accounts in Migrator contract etc
senderAccountInfo_.balance = senderBalance_ - amount_; | ||
recipientAccountInfo_.balance += amount_; | ||
} | ||
if (balance_ < amount_) revert InsufficientBalance(sender_, balance_, amount_); |
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.
Is this check still relevant?
We are performing no operation once we enter this condition.
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.
Yes, because the event is emitted, and it may break indexers. Plus, you should not be able to transfer yourself a billion dollars if you don't have it.
a021e1a
to
b682915
Compare
eba643f
to
3d3bde5
Compare
b682915
to
dfc2f33
Compare
While it could work, it would mean that the earners list cannot change from the time the Migrator is deployed to the time it is used, which is not that trivial. First the new implementation and migrator are deployed, then the proposals are created to enable the migrator, then they are passed, then they are executed, then the migration can be performed. In that time, other proposals to modify the earners list may come in, which can create gaps in that batch account migration. The "as needed" migration is impossible to break. However, if we did do batch migration (and could guarantee completeness), it would:
Its worth noting that trying to migrate a non-earner results in a no-op, so it is fine. But skipping over an earner and not migrating them is a critical error, and the MIgrate contract process only happens once and cannot be repeated. |
3d3bde5
to
b452ee9
Compare
dfc2f33
to
6f20cbe
Compare
b452ee9
to
0e76045
Compare
6f20cbe
to
7383901
Compare
0e76045
to
8f65b68
Compare
7383901
to
bef592e
Compare
8f65b68
to
7813bef
Compare
bef592e
to
4b1b4b0
Compare
7813bef
to
2a4be08
Compare
4b1b4b0
to
68dc8a4
Compare
2a4be08
to
04502d8
Compare
68dc8a4
to
f048807
Compare
- principal-based earner account, instead of last index - auto and manual migration for existing earners
04502d8
to
b6e8c41
Compare