Skip to content
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

Make public and external methods virtual to facilitate creation of custom SuperToken logic #1556

Merged
merged 5 commits into from
Aug 7, 2023

Conversation

d10r
Copy link
Collaborator

@d10r d10r commented Aug 3, 2023

Customized versions of the SuperToken logic currently cannot just inherit SuperToken.sol, because it doesn't declare its methods as virtual.

Examples:

In this PR, all public and external methods of SuperToken (and SuperfluidToken which it inherits from) are declared as virtual in 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.

@github-actions
Copy link

github-actions bot commented Aug 3, 2023

Changelog Reminder

Reminder to update the CHANGELOG.md for any of the modified packages in this PR.

  • CHANGELOG.md modified
  • Double check before merge

@codecov
Copy link

codecov bot commented Aug 3, 2023

Codecov Report

Patch coverage has no change and project coverage change: +8.81% 🎉

Comparison is base (dae8ea5) 87.53% compared to head (688f7d1) 96.35%.

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     
Flag Coverage Δ
ethereum-contracts 96.35% <0.00%> (ø)
sdk-core ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
...reum-contracts/contracts/superfluid/SuperToken.sol 98.58% <0.00%> (ø)
...contracts/contracts/superfluid/SuperfluidToken.sol 98.76% <ø> (ø)

... and 50 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@hellwolf hellwolf left a comment

Choose a reason for hiding this comment

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

Code organization principles:

  • _foo internal 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".
  • external functions can be created through assembling these internal logic together.
    • public functions is a shortcut used in code base to combine the definition of _foo and foo. 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.

Copy link
Contributor

@hellwolf hellwolf left a 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.

@hellwolf hellwolf merged commit 9ef597b into dev Aug 7, 2023
15 of 16 checks passed
@hellwolf hellwolf deleted the customizable_supertoken branch August 7, 2023 10:36
@github-actions
Copy link

github-actions bot commented Aug 7, 2023

XKCD Comic Relif

Link: https://xkcd.com/1556
https://xkcd.com/1556

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.

None yet

2 participants