-
Notifications
You must be signed in to change notification settings - Fork 262
Make public and external methods virtual to facilitate creation of custom SuperToken logic #1556
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
Conversation
Changelog ReminderReminder to update the CHANGELOG.md for any of the modified packages in this PR.
|
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## dev #1556 +/- ##
==========================================
+ Coverage 87.53% 96.35% +8.81%
==========================================
Files 91 41 -50
Lines 4389 2139 -2250
Branches 184 0 -184
==========================================
- Hits 3842 2061 -1781
+ Misses 503 78 -425
+ Partials 44 0 -44
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
packages/ethereum-contracts/contracts/superfluid/SuperToken.sol
Outdated
Show resolved
Hide resolved
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.
Code organization principles:
_foointernal function as building blocks for reusability.- they should not be altered by subclasses.
- "private" scope is generally avoided for simplicity, since test-harness may benefit from accessing them directly by subclassing it. This is often the case for our test cases.
- The building blocks become "monadic", if it calls other abstract virtual functions. The naming convention for these functions are "_doSomeDamage".
externalfunctions can be created through assembling these internal logic together.publicfunctions is a shortcut used in code base to combine the definition of_fooandfoo. This style should be gradually rid of from this code base, in favor of separation of definitions from day 0.
There are generally two ways of code logic reassembling:
function foo() external virtual override {
// inject some logic before...
super.foo();
// inject some logic after...
}
or a complete rewrite of foo using _foo etc.
hellwolf
left a comment
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 still find it a bit stinky to be able to override so many things, but it is at least better than being able to override internal logic blocks.
XKCD Comic RelifLink: https://xkcd.com/1556 |

Customized versions of the SuperToken logic currently cannot just inherit
SuperToken.sol, because it doesn't declare its methods asvirtual.Examples:
updateCodechanges.transfer) is changed.In this PR, all public and external methods of SuperToken (and SuperfluidToken which it inherits from) are declared as
virtualin order to facilitate creation of such customizations.Additionally a few internal methods (for mint, burn, transfer, upgrade and downgrade) were also made virtual in order to allow changing the behaviour of that operations with less additional code.