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
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
715a7f4
WIP
fubuloubu Sep 19, 2024
2117db1
refactor(sdk): check if non-zero factory
fubuloubu Sep 24, 2024
335eaa8
fix(contracts): forgot to update Validator.json interface
fubuloubu Sep 24, 2024
955b367
refactor: larger refactor of stream manager
fubuloubu Sep 25, 2024
a560e63
refactor(contracts): rename pricing example
fubuloubu Sep 25, 2024
2167491
refactor(py-sdk): remove unused exceptions
fubuloubu Sep 25, 2024
8513678
refactor(contracts): remove pricing example
fubuloubu Sep 25, 2024
7a7bd3c
fix(py-sdk): removed wrong exception
fubuloubu Sep 25, 2024
95a8a04
docs(test): add dev comments to token underflows
fubuloubu Sep 26, 2024
4620ddf
refactor(contracts,py-sdk)!: make create_stream use total stream amt
fubuloubu Sep 26, 2024
40e5f5a
refactor(contracts, py-sdk)!: change view function names, claim logic
fubuloubu Sep 26, 2024
ca8c85b
refactor(tests): updated test for contract/sdk changes, more modules
fubuloubu Sep 26, 2024
68c0212
test: add some extra checks
fubuloubu Sep 26, 2024
85b2b40
refactor(demo): upgrade demo script
fubuloubu Sep 26, 2024
c8d838b
docs: update the README
fubuloubu Sep 26, 2024
00c3d7e
refactor(py-sdk): better repr for Validator
fubuloubu Sep 26, 2024
11c499b
fix(scripts): deploy script was in wrong order for tokens/validators
fubuloubu Sep 26, 2024
f102bfc
feat(scripts): allow deploying test validator
fubuloubu Sep 26, 2024
47cd277
feat(py-sdk): display diff for `.set_validators`
fubuloubu Sep 26, 2024
36979e8
feat(py-sdk): allow replacing a validator
fubuloubu Sep 26, 2024
9bbd0e5
refactor(py-sdk): add typing and tests for replace_validator
fubuloubu Sep 27, 2024
080ef47
docs(contracts): add dev comment to two assertions
fubuloubu Sep 27, 2024
d6c76b8
docs(contracts): mis-capitalized
fubuloubu Sep 27, 2024
8627d93
refactor(py-sdk): consistency is key
fubuloubu Sep 27, 2024
cc12a80
refactor(contracts): reset new_controller; reorder a bit
fubuloubu Sep 27, 2024
2b03474
refactor(demo): wrong comments for time
fubuloubu Sep 27, 2024
eb9f34a
refactor(py-sdk): use floor div instead of int cast
fubuloubu Sep 27, 2024
7c25276
docs(contracts): add extensive NatSpec documentation to StreamManager
fubuloubu Sep 27, 2024
b8b07d0
refactor(py-sdk): don't use `args`
fubuloubu Sep 27, 2024
08f993b
style: fix `@return` not `@returns` in NatSpec
fubuloubu Sep 27, 2024
9674830
refactor(contracts,py-sdk,tests,scripts): Major refactor of stream math
fubuloubu Sep 28, 2024
e331306
style(scripts): remove unused imports
fubuloubu Sep 28, 2024
c933607
fix(contract): missing assertion for expiration in `add_funds`
fubuloubu Sep 28, 2024
5571eb3
feat(tests): add test for `add_funds`
fubuloubu Sep 28, 2024
e6a6f8d
refactor(contracts): make `StreamManager.cancel_stream` not do a claim
fubuloubu Sep 28, 2024
fb74988
feat(py-sdk): add helper methods for two timestamp info fields
fubuloubu Sep 28, 2024
18824b8
refactor(tests): remove unnecessary fixture
fubuloubu Sep 28, 2024
e17bb30
refactor(tests): move chain isolation to `stream` fixture
fubuloubu Sep 28, 2024
e37efdf
fix(tests): update `cancel_stream` test to make it work better
fubuloubu Sep 28, 2024
834e626
refactor(tests): remove unused fixture from test
fubuloubu Sep 28, 2024
d4f3c02
chore(config): add ignores for test reporting, display verbose cov
fubuloubu Sep 28, 2024
5d17c1b
refactor(contracts): update controller transfer events for better args
fubuloubu Sep 28, 2024
8cb68c9
refactor(contracts,py-sdk): update `id` -> `stream_id` in Stream events
fubuloubu Sep 28, 2024
dbdd779
refactor(contracts): update new/old arg names in owner transfer event
fubuloubu Sep 28, 2024
9262ad4
style(contracts): put event log emits last
fubuloubu Sep 28, 2024
cd9134c
refactor(contracts): add check of validator set uniqueness
fubuloubu Sep 28, 2024
c516102
docs(cotnracts): apply suggestions from code review
fubuloubu Sep 28, 2024
1f46007
docs(contracts): update `creator` -> `funder` in Validator interface
fubuloubu Sep 28, 2024
f3b133b
refactor(py-sdk): forgot to update event name
fubuloubu Oct 1, 2024
4c9ad42
fix(py-sdk): handle Taskiq dependencies
fubuloubu Oct 3, 2024
d20a794
fix(py-sdk): handle case when function is async
fubuloubu Oct 3, 2024
e6a2d1f
fix(py-sdk): ensure that UTC timestamps are returned
fubuloubu Oct 3, 2024
8084493
refactor(py-sdk): display validator set updates using info log
fubuloubu Oct 3, 2024
3d69bb9
refactor: apply suggestions from code review
fubuloubu Oct 3, 2024
b44eef7
refactor(contract): new_controller_proposed -> control_transfer_proposed
fubuloubu Oct 3, 2024
01b845c
fix(py-sdk): used timezone incorrectly
fubuloubu Oct 3, 2024
d989662
refactor(contracts): make memory var match event for clarity
fubuloubu Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def manager(
project.StreamManager,
owner or account,
min_stream_life,
list(validators),
token_addresses,
list(validators),
publish=publish,
)

Expand All @@ -138,3 +138,10 @@ def manager(
@account_option()
def token(cli_ctx, account):
account.deploy(project.TestToken)


@cli.command(cls=ConnectedProviderCommand, short_help="Deploy a Mock validator")
@ape_cli_context()
@account_option()
def validator(cli_ctx, account):
account.deploy(project.TestValidator)
25 changes: 19 additions & 6 deletions sdk/py/apepay/manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from collections.abc import Iterator
from datetime import timedelta
from difflib import Differ
from functools import partial, wraps
from typing import TYPE_CHECKING, Any, Callable, Union, cast

import click
from ape.api import ReceiptAPI
from ape.contracts.base import ContractEvent, ContractInstance, ContractTransactionHandler
from ape.exceptions import ContractLogicError, DecodingError
Expand Down Expand Up @@ -89,21 +91,32 @@ def _parse_validator(self) -> Callable[[_ValidatorItem], Validator]:
def set_validators(self) -> ContractTransactionHandler:

@wraps(self.contract.set_validators)
def order_validators(*validators: _ValidatorItem, **txn_kwargs) -> ReceiptAPI:
def set_validators(*validators: _ValidatorItem, **txn_kwargs) -> ReceiptAPI:
# NOTE: Always keep sets sorted, ensure no duplicates
return self.contract.set_validators(
sorted(v.address for v in set(map(self._parse_validator, validators))),
**txn_kwargs,
)
new_validators = sorted(v.address for v in set(map(self._parse_validator, validators)))
# NOTE: Okay to use Click here, intended primarily to support interactive features
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved
click.echo("Validators update:")
for line in Differ().compare(tuple(v.address for v in self.validators), new_validators):
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved
click.echo(line)
return self.contract.set_validators(new_validators, **txn_kwargs)

return cast(ContractTransactionHandler, order_validators)
return cast(ContractTransactionHandler, set_validators)

def add_validators(self, *new_validators: _ValidatorItem, **txn_kwargs) -> ReceiptAPI:
return self.set_validators(
*(set(self.validators) | set(map(self._parse_validator, new_validators))),
**txn_kwargs,
)

def replace_validator(self, old_validator, new_validator, **txn_kwargs) -> ReceiptAPI:
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved
return self.set_validators(
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved
*(
(set(self.validators) - set([self._parse_validator(old_validator)]))
| set([self._parse_validator(new_validator)])
),
**txn_kwargs,
)

def remove_validators(self, *old_validators: _ValidatorItem, **txn_kwargs) -> ReceiptAPI:
return self.set_validators(
*(set(self.validators) - set(map(self._parse_validator, old_validators))),
Expand Down
3 changes: 3 additions & 0 deletions sdk/py/apepay/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __init__(self, address: str | AddressType, /, *args, **kwargs):
kwargs["address"] = address
super().__init__(*args, **kwargs)

def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.address})"

@field_validator("address", mode="before")
def normalize_address(cls, value: Any) -> AddressType:
if isinstance(value, Validator):
Expand Down
Loading