Skip to content

Commit

Permalink
refactor(StreamManager): some docs updates, added a new internal fn
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Sep 10, 2024
1 parent f345962 commit a7df8d6
Showing 1 changed file with 11 additions and 6 deletions.
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

0 comments on commit a7df8d6

Please sign in to comment.