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

refactor(contracts)!: StreamManager upgrades #112

Merged
merged 57 commits into from
Oct 3, 2024

Conversation

fubuloubu
Copy link
Member

@fubuloubu fubuloubu commented Sep 25, 2024

What I did

  • Stream.stream_id -> Stream.id
  • reordering/renaming of some event arguments
  • reordering of create_stream function
  • remove unused functions
  • adds Allowlist/Denylist validators
  • adds PricingExample validator
  • allow StreamManager.controller to transition ownership
  • allow Stream.owner to transition ownership

fixes: #103
fixes: #104
fixes: #105
fixes: #107
partial fix: #72

How I did it

some larger refactors to contracts, examples, py sdk, etc.

NOTE: No update to js-sdk

How to verify it

Checklist

  • All changes are completed
  • New test cases have been added
  • Documentation has been updated

- `Stream.stream_id -> Stream.id`
- reordering/renaming of some event arguments
- reordering of `create_stream` function
- remove unused functions
bigger refactor that computes the streaming rate as the sum of product
validations, instead of requiring an explicit streaming rate

an intent parameter `min_stream_life` can be used to control for any
changes from what the expected stream life may be (but can always be
more)
@fubuloubu
Copy link
Member Author

fubuloubu commented Sep 26, 2024

ca8c85b related: ApeWorX/ape#2277

@fubuloubu fubuloubu marked this pull request as ready for review September 26, 2024 01:09
Copy link
Member

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

approved w/ thoughts

edit: realized i missed a bunch of files in review ,was only looking at latest commit or something, so i added more comments

sdk/py/apepay/manager.py Outdated Show resolved Hide resolved
sdk/py/apepay/manager.py Show resolved Hide resolved
sdk/py/apepay/manager.py Outdated Show resolved Hide resolved
sdk/py/apepay/manager.py Outdated Show resolved Hide resolved
sdk/py/apepay/manager.py Outdated Show resolved Hide resolved
Copy link
Member

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

oops more comments

contracts/StreamManager.vy Outdated Show resolved Hide resolved
contracts/Validator.vyi Outdated Show resolved Hide resolved
contracts/validators/Allowlist.vy Show resolved Hide resolved
sdk/py/apepay/manager.py Outdated Show resolved Hide resolved
sdk/py/apepay/manager.py Outdated Show resolved Hide resolved
sdk/py/apepay/streams.py Outdated Show resolved Hide resolved
sdk/py/apepay/streams.py Outdated Show resolved Hide resolved
sdk/py/apepay/streams.py Outdated Show resolved Hide resolved
@antazoey
Copy link
Member

antazoey commented Sep 26, 2024

something weird I noticed, can't tell if it because of Ape or the ApePay library, but if you run the tests w/o contracts being compiled, it will compile them, but then all tests will fail with 'Project' object has no attribute 'StreamManager'

Edit: ok this hasn't happened in my sample project, hmmm

Copy link
Member

@mikeshultz mikeshultz left a comment

Choose a reason for hiding this comment

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

I did a quick pass. Want to come back and do another a little later.

suggestion: document more. Maybe file-level docstrings in the header, or maybe in the README.

question: What exactly is a product? Are there any constraints? If it's just up to validators what exactly that means to the contract, maybe that should be explained a bit more.

Looking at the demo it leaves me a bit confused:

>>> HashBytes32(b"\x00" * 24 + b"\x01" + b"\x00" * 7)
HexBytes('0x0000000000000000000000000000000000000000000000000100000000000000')
>>> 0x0000000000000000000000000000000000000000000000000100000000000000
72057594037927936
>>> 0x0000000000000000000000000000000000000000000000000100000000000000 // 1e18
0.0

Even if you adjust for different decimals for a token, I'm not sure how this matches the comment of "256 tokens/hour". Feel like I'm missing something.

BLUEPRINT,
msg.sender, # Only caller can create
ONE_HOUR, # Safety parameter (not configurable)
min_stream_time, # Safety parameter for new streams
validators,
accepted_tokens, # whatever caller wants to accept
salt=convert(msg.sender, bytes32), # Ensures unique deployment per caller
Copy link
Member

Choose a reason for hiding this comment

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

question: I know it isn't being changed here, but out of curiosity, why limit one stream manager per sender?

Copy link
Member Author

Choose a reason for hiding this comment

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

originally I was thinking that it would make sense to keep it like that and have per-product validators, but I think what I am gonna do is add a secondary String[32] "product" variable that also gets concatenated to the salt (and to the deployments mapping)

this way, in the StreamFactory Python SDK class I can actually loop through all of the known deployments of the factory (which I want to use the release version identifier as the create2 salt so you can get release by address) and look for the deployments that a particular user has made for a particular product name

contracts/StreamManager.vy Show resolved Hide resolved
contracts/StreamManager.vy Show resolved Hide resolved
@fubuloubu
Copy link
Member Author

fubuloubu commented Sep 26, 2024

question: What exactly is a product? Are there any constraints? If it's just up to validators what exactly that means to the contract, maybe that should be explained a bit more.

Yes, it is up to the validator. 👍 on better docs/explanation there (but right now it's more for us)

Even if you adjust for different decimals for a token, I'm not sure how this matches the comment of "256 tokens/hour". Feel like I'm missing something.

The "TestValidator" in there basically just converts the product code directly into the streaming rate, so that hex number is 0.072057594 tokens/second or 259.4 tokens/hour (my comment is a little bit off)

Our product's pricing algorithm is obviously going to be a lot more specific to how the Silverback product code is structured. Multiple codes are allowed if people want to merge streams together (pay for multiple clusters from the same stream, but not shipping out of the box w/ that). It's a lot easier to upgrade validators than it will be to upgrade the StreamManager, so the logic there is more open since it can change (e.g. as we update our pricing structure all new streams will have to use it, need some code updates to apply to existing streams as well)


>>> 0x0000000000000000000000000000000000000000000000000100000000000000 // 1e18
0.0

Don't forget that the token decimals are really only for display purposes only

>>> 0x0000000000000000000000000000000000000000000000000100000000000000 / 1e18
0.07205759403792794

@fubuloubu
Copy link
Member Author

note: coverage/gas reporting seems to be failing erronously

contracts/StreamManager.vy Outdated Show resolved Hide resolved
contracts/StreamFactory.vy Show resolved Hide resolved
contracts/StreamFactory.vy Outdated Show resolved Hide resolved
contracts/Validator.json Show resolved Hide resolved
contracts/Validator.vyi Show resolved Hide resolved
contracts/Validator.vyi Show resolved Hide resolved
contracts/StreamManager.vy Outdated Show resolved Hide resolved
contracts/StreamManager.vy Outdated Show resolved Hide resolved
contracts/StreamManager.vy Show resolved Hide resolved
sdk/py/apepay/manager.py Outdated Show resolved Hide resolved
def is_accepted(self) -> ContractCallHandler:
return self.contract.token_is_accepted
def is_accepted(self, token: AddressType) -> bool:
return self.contract.token_is_accepted(token)
Copy link
Member

Choose a reason for hiding this comment

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

We could potentially use the ape-extras mechanism and feed into .contract so all pass throughs are automatic.

Copy link
Member Author

Choose a reason for hiding this comment

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

How does that work again?

@fubuloubu fubuloubu enabled auto-merge (squash) October 3, 2024 20:48
@fubuloubu fubuloubu merged commit 71d61d7 into main Oct 3, 2024
8 checks passed
@fubuloubu fubuloubu deleted the refactor/contract/StreamManager branch October 3, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants