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(StreamManager): some docs updates, added a new internal fn #102

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
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
17 changes: 11 additions & 6 deletions contracts/StreamManager.vy
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def create_stream(
start_time: uint256 = block.timestamp,
) -> uint256:
assert self.token_is_accepted[token] # dev: token not accepted
assert start_time <= block.timestamp # dev: start time < block
assert start_time <= block.timestamp # dev: start time in future

funded_amount: uint256 = staticcall token.allowance(msg.sender, self)
if funded_amount == max_value(uint256):
Expand All @@ -132,10 +132,10 @@ def create_stream(
extcall validator.validate(msg.sender, token, amount_per_second, reason),
)

assert max_stream_life >= funded_amount // amount_per_second # dev: max stream life small
assert max_stream_life >= funded_amount // amount_per_second # dev: max stream life too small

prefunded_stream_life: uint256 = max(MIN_STREAM_LIFE, block.timestamp - start_time)
assert max_stream_life >= prefunded_stream_life # dev: prefunded stream life large
assert max_stream_life >= prefunded_stream_life # dev: prefunded stream life too large
assert funded_amount >= prefunded_stream_life * amount_per_second # dev: not enough funds

assert extcall token.transferFrom( # dev: transfer fail
Expand Down Expand Up @@ -207,10 +207,16 @@ def add_funds(creator: address, stream_id: uint256, amount: uint256) -> uint256:
return time_left


@view
def _stream_is_cancelable(creator: address, stream_id: uint256) -> bool:
# Creator needs to wait `MIN_STREAM_LIFE` to cancel a stream
return self.streams[creator][stream_id].start_time + MIN_STREAM_LIFE <= block.timestamp


@view
@external
def stream_is_cancelable(creator: address, stream_id: uint256) -> bool:
return self.streams[creator][stream_id].start_time + MIN_STREAM_LIFE <= block.timestamp
return self._stream_is_cancelable(creator, stream_id)


@external
Expand All @@ -220,8 +226,7 @@ def cancel_stream(
creator: address = msg.sender,
) -> uint256:
if msg.sender == creator:
# Creator needs to wait `MIN_STREAM_LIFE` to cancel a stream
assert self.streams[creator][stream_id].start_time + MIN_STREAM_LIFE <= block.timestamp
assert self._stream_is_cancelable(creator, stream_id)
else:
# Owner can cancel at any time
assert msg.sender == self.owner
Expand Down
Loading